libsota - a helper library in lua for Shroud in lua.

Discussion in 'Lua Discussions' started by CatweazleX, Nov 14, 2019.

Thread Status:
Not open for further replies.
  1. tervalas

    tervalas Avatar

    Messages:
    50
    Likes Received:
    9
    Trophy Points:
    8
    Oops...i had meant to put buttonTable in the first one.....but I will take a look at what you came up with to see if that improves it.
     
  2. tervalas

    tervalas Avatar

    Messages:
    50
    Likes Received:
    9
    Trophy Points:
    8
    Thank you for the tips. Part of my struggles with Lua over the years when I've tried any game scripting is table insertion. I like being able to access any 'array' type structure with the array notation, but keep forgetting that Lua doesn't like this for more complex insertions.

    But your advice has been helpful for resolving a couple other issues that came up. I've got most of it working. Now I can work on eliminating inefficiencies and modifications.
     
    Last edited: Sep 26, 2021
  3. Tirrag

    Tirrag Avatar

    Messages:
    853
    Likes Received:
    1,820
    Trophy Points:
    93
    Location:
    Iowa, USA
    excellent! happy i was able to help you a bit :)

    @CatweazleX i am to the part of a new mod i am working on where i am building out the interface. i created my own window system but would rather use an official one from libsota. was curious if you decided to pick up the library again and progress it? if not that is fine, i can move forward with what i have.
     
    Last edited: Sep 28, 2021
  4. Archer

    Archer Avatar

    Messages:
    285
    Likes Received:
    196
    Trophy Points:
    40
    Location:
    UK, EU, Terra
    Another thought, it would be really useful to put the parts of libSota on shroudmods.com to make it easier to use them as dependencies for projects.
     
  5. tervalas

    tervalas Avatar

    Messages:
    50
    Likes Received:
    9
    Trophy Points:
    8
    Figured I'd move this over here since it is more about libsota than your addon. :)

    I was definitely looking for something more like the first example, just took me some time to figure out that using things like ui.onMouseMove actually works when called inside another ui object in libsota. But now I'm wondering if I've caused a hitching issue or if hitching caused by something else is my new problem. It will display my test window, but even if I just sit there eventually my other addons using libsota start to disappear.
     
  6. Archer

    Archer Avatar

    Messages:
    285
    Likes Received:
    196
    Trophy Points:
    40
    Location:
    UK, EU, Terra
    Have you tried it out on QA using the new Update method instead of OnGUI. According to Atos, this greatly improves performance for UI so it would indicate whether it is an performance issue you have introduced. It would also let you know if it is fixable in the future when this becomes mainstream.
     
    Anpu likes this.
  7. tervalas

    tervalas Avatar

    Messages:
    50
    Likes Received:
    9
    Trophy Points:
    8
    Not on QA and not sure I have the time to try. But as I'm extending libsota for this that may require a bunch of changes. Not sure if CatweazleX is looking at that.

    Though I know how to eliminate the game or my system as the cause, so at least I can start narrowing.
     
  8. tervalas

    tervalas Avatar

    Messages:
    50
    Likes Received:
    9
    Trophy Points:
    8
    Dang....it's something with how I implemented adding children to the window. Which is the most important piece I need to get right.

    Or more specifically how I'm drawing them.

    So this is how I add a child:
    Code:
    addChild = function(w, childObj, left, top)
                local index = #w.children + 1
                w.children[index] = {
                    object = childObj,
                    left = left,
                    top = top,
                }
                setmetatable(w.children[index], {__index = ui.window})
            end,
    And I display it in my draw function with:
    Code:
    for _,v in ipairs (w.children) do
                    v.object:moveTo(w.rect.left + v.left, w.rect.top + v.top)
                    v.object:visible(true)
                end
    It seems like it doesn't like doing that loop.
     
    Last edited: Oct 16, 2021
  9. Archer

    Archer Avatar

    Messages:
    285
    Likes Received:
    196
    Trophy Points:
    40
    Location:
    UK, EU, Terra
    Is that loop implemented in ShroudOnGUI(), if so that will likely be the problem... Doing too much in a single frame. Look at the ShroudOnGUI in libsota.lua where the code breaks from the loop if the time interval is greater than a predetermined limit. Presumably to continue from that point on the next frame.
     
  10. tervalas

    tervalas Avatar

    Messages:
    50
    Likes Received:
    9
    Trophy Points:
    8
    Not technically. It's implemented in a window object that is a guiObject. guiObjects are drawn during ShroudOnGUI so in the end that is still controlling the display and why it's hitching checks are preventing things from being drawn.

    I'm thinking about changing it up a little bit based on some input Tirrag had.
     
  11. Tirrag

    Tirrag Avatar

    Messages:
    853
    Likes Received:
    1,820
    Trophy Points:
    93
    Location:
    Iowa, USA
    @CatweazleX just drawing your attention to the updates coming to Lua. would be great to see your wonderful library updated with the new GUI functions :)
     
    FrostII and Archer like this.
  12. tervalas

    tervalas Avatar

    Messages:
    50
    Likes Received:
    9
    Trophy Points:
    8
    So I've been messing with re-implementing my window in libsota using the new GUI functions and....yay....I've managed to get it working on it's own outside of using the libsota ui calls. I think the new system, getting everything out of ShroudOnGUI, may actually be good for hitching (though I've only built two test windows so not the largest amount of objects).

    One thing I am hanging on is how to implement ShroudOnMouseClick into my window functions. The demo file does this as a separate function to cover any button but I'd like to restrict it to an individual button kind of like how we use to use onClick events through libsota. Is this even possible with the new implementation?
     
  13. tervalas

    tervalas Avatar

    Messages:
    50
    Likes Received:
    9
    Trophy Points:
    8
    So this is what I've tried so far:


    Code:
    onMouseClick = function(callback) return ui.handler.add("_mouseClick", callback) end
    Later:
    Code:
    function ShroudOnMouseClick(objectID, objectKind)
        ui.handler.invoke("_mouseClick", objectID, objectKind)
    end
    Then in my window class:
    Code:
    ui.onMouseClick(function(objectID, objectKind)
            if (objectKind == UI.Button) then
                for next, obj in pairs(self.objectList) do
                    print("TEST")
                end
            end
        end)
    Now I've done other tests and seen that my handler works and does send objectID and objectKind correctly to my ui.onMouseClick function. However, it doesn't like me trying to refer to the current window in this function as self.

    Should note that
    Code:
    window.objectList[index] = {
                obj = object,
                type = type
            }
     
  14. Tirrag

    Tirrag Avatar

    Messages:
    853
    Likes Received:
    1,820
    Trophy Points:
    93
    Location:
    Iowa, USA
    self will only exist if the function it is used in is called with a semicolon vs period (ui.function vs ui:function). in this specific situation you will need to pull the window object you are looking for from within your handler or if window.objectList is global then you can just use window. instead of self.
     
  15. tervalas

    tervalas Avatar

    Messages:
    50
    Likes Received:
    9
    Trophy Points:
    8
    Okay, making a global table seemed to do the trick (so far). I just added all the objectIDs along with the window, then had the click handler loop through the global table looking for the buttonID so that the window associated could be returned to the ui.onMouseClick function.

    But....and this is something I noticed before adding anything about trying to figure out what window it was....why does it fire 5 times for one click?
     
  16. Tirrag

    Tirrag Avatar

    Messages:
    853
    Likes Received:
    1,820
    Trophy Points:
    93
    Location:
    Iowa, USA
    if your seeing 5 "TEST" messages it may be because of the below code is not limiting using the objectID, just the kind. so fi there are 5 buttons you will see 5 TEST messages. would have to see a sample to know for sure.

     
  17. tervalas

    tervalas Avatar

    Messages:
    50
    Likes Received:
    9
    Trophy Points:
    8
    That would seem odd since objectID from ShroudOnMouseClick should only be returning the objectID of the button clicked which is then passed on by the handler.

    For my current purposes I add in a check for the ID also. Still does the same thing.

    Adding in something to the ShroudOnMouseClick function before any processing, it is triggering five times on a click.
     
  18. Tirrag

    Tirrag Avatar

    Messages:
    853
    Likes Received:
    1,820
    Trophy Points:
    93
    Location:
    Iowa, USA
    maybe i am misunderstanding but your code:

    for next, obj in pairs(self.objectList) do

    is looping each time a button is clicked and firing the code within for as many objects as you have. try updating the code to just be:

    Code:
    ui.onMouseClick(function(objectID, objectKind)
           if (objectKind == UI.Button) then
                   print("TEST")
           end
       end)
    
     
  19. tervalas

    tervalas Avatar

    Messages:
    50
    Likes Received:
    9
    Trophy Points:
    8
    okay.....what I'm saying is this still give 5 iterations:

    Code:
    function ShroudOnMouseClick(objectID, objectKind)
       print("TEST")
    end
    That's the actual built-in function from SOTA, so my code doesn't affect it one way or the other. It could very well be that it may be an issue with my mouse, which is why I'm wondering if something like it has happened with anyone else who has used the new built-in mouse functions.

    UPDATE: I disable all my mouse click code and put the demo file as the only one that creates a window. I switched the code to once again print TEST if the button is clicked. It is registering two clicks. Now, I did also discover I need to account for other windows than those created with my code lol.
     
    Last edited: Nov 4, 2021
  20. tervalas

    tervalas Avatar

    Messages:
    50
    Likes Received:
    9
    Trophy Points:
    8
    https://imgur.com/a/VVXMST5

    So I added a line to my ShroudOnMouseClick function
    Code:
    ui.consoleLog(string.format("Clicked on ID: %d", objectID))
    When I click on the + sign button on the left window (which has objectID of 0 for UI.Button), you can see it prints 5 times. When I click on the right menu one (which has objectID of 1 for UI.Button), it prints that 5 times.

    For my purposes so far, this isn't yet an issue. But considering my last post registered 2 clicks without any of my own code involved, I'm just hoping it is a me issue.
     
Thread Status:
Not open for further replies.