Skip to content

SMODS.CardButton, universal approach to adding buttons to cards#930

Open
bepisfever wants to merge 8 commits intoSteamodded:mainfrom
bepisfever:patch-12
Open

SMODS.CardButton, universal approach to adding buttons to cards#930
bepisfever wants to merge 8 commits intoSteamodded:mainfrom
bepisfever:patch-12

Conversation

@bepisfever
Copy link
Contributor

@bepisfever bepisfever commented Aug 28, 2025

Adding SMODS.CardButton, which allows you to add buttons to cards much more easily. It also auto-aligns added buttons.

Code example:

function G.FUNCS.test_button(e)
    print("yeah")
end

SMODS.CardButton{
    key = "test",
    button_apply = function(self, ui_buttons, card, button_context, new_uibox)
        if button_context.highlight then
            new_uibox[#new_uibox+1] = {
                definition = {
                    n=G.UIT.ROOT, config = {padding = 0, colour = G.C.CLEAR}, nodes={
                        {n=G.UIT.R, config={ref_table = card, r = 0.08, padding = 0.1, align = "bm", minw = 0.5*card.T.w - 0.15, maxw = 0.9*card.T.w - 0.15, minh = 0.3*card.T.h, hover = true, shadow = true, colour = G.C.RED, button = 'test_button'}, nodes={
                            {n=G.UIT.T, config={text = localize('b_select'),colour = G.C.UI.TEXT_LIGHT, scale = 0.45, shadow = true}}
                        }},
                    }}, 
                config = {align= "bmi", offset = {x=0,y=0.65}, parent = card}
            }

            return{
                buttons = {
                    {text = {"hi", "help me"}, text_scale = 0.5, button = "test_button"}
                },
                remove_buttons = {
                    "vanilla_buttons"
                },
            }
        end
        if button_context.select_booster then
            return{
                buttons = {
                    {text = {"hi", "help me"}, text_scale = 0.5, button = "test_button"},
                    {text = {"hi", "help me"}, text_scale = 0.5, button = "test_button", dir = "l"},
                },
                remove_buttons = {
                    "b_select_button"
                },
            }
        end
    end,
}

SMODS.CardButton{
    key = "test2",
    button_apply = function(self, ui_buttons, card, button_context, new_uibox)
        if button_context.select_booster then
            return{
                buttons = {
                    {text = {"im", "dying"}, text_scale = 0.5, button = "test_button", dir = "l"},
                },
                remove_buttons = {
                    "sell_button"
                }
            }
        end
    end,
}

SMODS.CardButton{
    key = "fym this shit is profitable",
    button_apply = function(self, ui_buttons, card, button_context, new_uibox)
        if button_context.shop then
            return{
                buttons = {
                    {text = {"buy and", "sell :3"}, text_scale = 0.5, button = "test_button"},
                },
            }
        end
    end,
}

Additional Info:

  • I didn't modify api's or I've made a PR to the wiki repo.
  • I didn't modify api's or I've updated lsp definitions.
  • I didn't make new lovely files or all new lovely files have appropriate priority.

@english5040
Copy link
Collaborator

This is a very large amount of code. I'm concerned just on those grounds, simplifying it will help this PR the most I think

This PR is undeniably useful, I like it. Integrating DrawStep in is solid work, logic there looks clear.

Code review: Unfortunately I cannot check the correctness of the code easily, I'll just have to take your word for it. The rest of the code is difficult to read.

Also, could you add quick comments on each function and some comments inside functions to summarize what the code in there is doing. that should help this PR, being able to skip over the dense ui tables

More comments:
Really don't like "calculate_button", I think that functionality sounds more natural as a function on the consumable/whatever card it is

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants