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
    Understandable. However, my code doesn't create the objects on ShroudOnUpdate, it simply uses ShroudHideObject and ShroudShowObject calls.

    I'm still thinking about going back and removing it from ShroudOnUpdate anyway. This was sort of a stop-gap measure, as explained above, to potentially handle display order. Just haven't made it that far in testing. :)

    This is the basics right now:

    Code:
    for _,o in next, list do
            if o.visible and o.shownInScene then
                ds[#ds + 1] = o
            elseif o.visible and o.shownInLoadScreen then
                dl[#dl + 1] = o
            else
                ShroudHideObject(o.objId, o.objKind)
            end
        end
    and later on ds or dl

    Code:
    for _,o in next, list do
                ShroudShowObject(o.objId, o.objKind)
                if os.time() - ts > 0.01 then break end
            end
     
    Last edited: Nov 14, 2021
  2. tervalas

    tervalas Avatar

    Messages:
    50
    Likes Received:
    9
    Trophy Points:
    8
    Pulled object display out of ShroudOnUpdate. Made many....many....changes to mouse click handling to ignore clicks generated from draggable objects and to ensure only the function for the button clicked fires. Also added a check for an object parent for the anchor and pivot functions.
     
  3. tervalas

    tervalas Avatar

    Messages:
    50
    Likes Received:
    9
    Trophy Points:
    8
    API document was updated with things on QA/live(?)....

    Resizable objects using the mouse
    Button changes based on state (highlighted, pressed, etc) including color and image changes
    Child Object Masking
    GetPosition (with a new vector object as the returnable)
    Input and Toggle Objects - input objects will also allow the content type to be predefined to specific categories as well as events to handle changes to them.
     
  4. tervalas

    tervalas Avatar

    Messages:
    50
    Likes Received:
    9
    Trophy Points:
    8
    Okay, I've been trying to figure out this bug for a while.

    I've been working on converting the libsota.util.lua label functions to use the changes I made to the main library.

    With the understanding that I can create a label, here is my code to change the text of a label object:
    Code:
    caption = function(label, caption)
          ShroudModifyText(label.objId, caption)
          label.caption = caption
    end,
    Changed createLabelWithShadow to:
    Code:
    function createLabelWithShadow(caption, font, left, top, width, height, parentID, parentKind)
        --local r = rect(left, top, width, height)
        local l = ui.label.add(caption, font, left, top, width, height, parentID, parentKind)
        local s = ui.label.add(caption, font, left+1, top+1, width, height, l.objId, l.objKind)  
        l.shadow = s
        return l
    end
    And then...and this is where errors occur..setLabelCaption:
    Code:
    function setLabelCaption(label, caption)
        if label.shadow then
            local c = caption:gsub("<color=.->", "<color=black>")
            label.shadow:caption("<color=black>"..c.."</color>")
        end
        label:caption(caption)
    end
    The test code that is throwing it is from the clock example for libsota:
    Code:
    clock.label = createLabelWithShadow(nil, 20, 5, 0)
    .
    .
    setLabelCaption(clock.label, caption:style{ color="#c4a000" })
    where caption is the current time information (ie Thursday, November 18, 2021 10:31 PM).

    When I load it up, I'm getting an 'attempt to call a string value' error on both the label.shadow:caption call and label:caption(caption) call. I'm getting proper objId numbers if I test them in the setLabelCaption function on both the argument and it's .shadow object.
     
  5. Archer

    Archer Avatar

    Messages:
    285
    Likes Received:
    196
    Trophy Points:
    40
    Location:
    UK, EU, Terra
    I'm not sure this is the thread to be posting such questions, even if it is kinda libsota related. Probably best to create a new thread about your changes and post a link here.

    As for your error, I suggest changing to use the ShroudSetColor(objectID, UI, hexcolor) separately from the setting of the text itself.
     
  6. tervalas

    tervalas Avatar

    Messages:
    50
    Likes Received:
    9
    Trophy Points:
    8
    ShroudSetColor kind of came in after this, and the old method was working at the time. I have added it to my changes though so it will bleed back in. But it turns out that isn't the problem and I'll start a new thread
     
  7. tervalas

    tervalas Avatar

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

    Here's a test look at using my changes so far, starting from TEST LABEL.

    That's a label, colored yellow. To it's right (the first arrow image) is an image with 0.5 transparency.
    Then a button (I didn't do the click on this one but it works). Then more to the right is another button with the same image.
    The white box to the right of that is the placeholder for a toggle (I don't have an image I want to use for that yet). Then lastly there is an input box with it's background yellow and placeholder text of TESTING

    Below that is my current implementation of a window. It has a caption TESTWINDOW in yellow. The button on the far right is the hide button for the whole window. I added the six buttons to the left of the hide button and clicked them left to right and you can see the results in my chat box. The whole window is draggable by the top portion that the buttons and caption are on.

    Still to implement is the handler code for the toggle and input box as well as more of their functions. I also need to implement ShroudMinMaxSize and GetPosition.
     
    Archer likes this.
  8. ngavarta

    ngavarta Avatar

    Messages:
    81
    Likes Received:
    60
    Trophy Points:
    8
    This download link is broken, I'm still interested in the lua script, someone please help to upload somewhere in github.
     
  9. Archer

    Archer Avatar

    Messages:
    285
    Likes Received:
    196
    Trophy Points:
    40
    Location:
    UK, EU, Terra
    I have a fork of libsota on github - https://github.com/niel/alibSotA . Current release is 0.4.8 with a couple of fixes. I'm working on a bigger update to make use of the newer features, before embarking on a more major rework to include the GUI changes.

    Please note: Because of the addition of the UI enum for UI types, 0.4.8 is essentially broken as the interpreter is case-insensitive, so that clashes with libsota's ui class. If you look at the develop branch, it has been refactored to put all of the libsota classes under als {} (so als.ui, als.player, etc.) hence the forking. Other than that it is basically a drop in replacement.
     
    Last edited: Dec 18, 2021
    ngavarta likes this.
  10. Archer

    Archer Avatar

    Messages:
    285
    Likes Received:
    196
    Trophy Points:
    40
    Location:
    UK, EU, Terra
    How is this going? Will you be sharing the code back?
     
  11. ngavarta

    ngavarta Avatar

    Messages:
    81
    Likes Received:
    60
    Trophy Points:
    8
    Thanks, appreciated that.
     
  12. tervalas

    tervalas Avatar

    Messages:
    50
    Likes Received:
    9
    Trophy Points:
    8
    I may share it soon. December is a bad month for me to spend time on things. But I will say that some of the things I haven't tested yet and there are a couple things I'm not sure if I implemented correctly.
     
    Archer likes this.
  13. tervalas

    tervalas Avatar

    Messages:
    50
    Likes Received:
    9
    Trophy Points:
    8
    First go with it. I didn't include everything with this just the two main files. I'm thinking about updating the help docs but that will come after.

    libsota fork
     
  14. Archer

    Archer Avatar

    Messages:
    285
    Likes Received:
    196
    Trophy Points:
    40
    Location:
    UK, EU, Terra
    As it is currently, I don't think that will work. SotA's implementation of Lua is case insensitive for naming, the ui table is superceded by SotA's UI enum. You should put each table into another (take a look at my fork if you need an example, https://github.com/niel/alibSotA).
    Also, trying to access a global variable created in one script from a second, as libsota.util.lua does, will not work either. Those globals are not available to other scripts until the system has finished initialising the scripts. That's why my fork went back to the single main script. I haven't decided what to do about libsota.utils.lua yet, but it will probably be integrated into the single script as well.
     
  15. tervalas

    tervalas Avatar

    Messages:
    50
    Likes Received:
    9
    Trophy Points:
    8
    I'll recheck again, but this code works for me despite this. This is almost the exact code I used in my example.
     
  16. tervalas

    tervalas Avatar

    Messages:
    50
    Likes Received:
    9
    Trophy Points:
    8
    I believe libsota was designed to be the first one called before as I really didn't change about how it worked before other than to point to the new functions. Maybe I'm misunderstanding what you are pointing out as the global variable.

    I normally don't use these shortcuts but I redid them just for compatibility sake. The only thing I really tested it with so far is the example clock script (which simply calls a Label with Shadow). But I think I did make a couple tweaks to things that didn't work properly with the new items. too.

    And yes, I feel these will just be merged in eventually. But as I said, I don't use them much. :)
     
  17. tervalas

    tervalas Avatar

    Messages:
    50
    Likes Received:
    9
    Trophy Points:
    8
    So I proved to myself this is mistaken. Renamed the file to alibsota.util.lua.

    Oddly....despite SOTA showing it load first....I'm getting no errors with calling libsota items.

    Checked again. Working for me still.
     
    Last edited: Dec 30, 2021
  18. craftymethod

    craftymethod Avatar

    Messages:
    1,133
    Likes Received:
    2,001
    Trophy Points:
    113
    Evening/morning guys, im loading
    Code:
    libsota.lua (0.4.8)
     and
    libsota_util.lua
    and getting error:

    Code:
    error loading file... \Lua\libsota.util.lua:(263,0-24): attempt to index a nil value
    With inspection of code it appears to be related to this line:
    Code:
    loadfile = ui.module.add
    Is this a known bug or user error?
    (LUA Version:5.2)
     
    Last edited: Apr 25, 2022
  19. Tirrag

    Tirrag Avatar

    Messages:
    853
    Likes Received:
    1,820
    Trophy Points:
    93
    Location:
    Iowa, USA
    hi @craftymethod. its a known issue. the newer SotA UI Lua functionality is using "ui." to prefix some constants and conflict with that line in libSota.
     
Thread Status:
Not open for further replies.