[GUI] spinner and repeating button

Discussion of Lua and LuaWML support, development, and ideas.

Moderator: Forum Moderators

Post Reply
white_haired_uncle
Posts: 1187
Joined: August 26th, 2018, 11:46 pm
Location: A country place, far outside the Wire

[GUI] spinner and repeating button

Post by white_haired_uncle »

I'm trying to create an example of using a spinner, since I can't find one. I had a hard time figuring out how to get the value out of it, and while it works, I'm not really happy what I did. So, what is the right way to do this? It seems like there should be a spinner.text, not spinner._text.text.

Also, I want to change the speed of the repeating buttons, both here and for any repeating button. Docs say 'every x' ms, but I don't see where to set x.

Code: Select all

function wesnoth.wml_actions.slider_and_textbox()
        local dialogDefinition = {
                wml.tag.tooltip { id = "tooltip_large" },
                wml.tag.helptip { id = "helptip_large" },
                wml.tag.grid {
                        wml.tag.row {
                                wml.tag.column {
                                        wml.tag.label { label = _"How much gold will you pay for this old rusty sword?" }
                                }
                        },
                        wml.tag.row {
                                wml.tag.column {
                                        horizontal_grow = true,
                                        grow_factor = 1,
                                        wml.tag.slider {
                                                id = "gold_sl", 
                                                minimum_value = 0,
                                                maximum_value = wesnoth.sides[wesnoth.current.side].gold,
                                                value = math.floor(wesnoth.sides[wesnoth.current.side].gold/2)
                                        }
                                }
                        },
                        wml.tag.row {
                                wml.tag.column {
                                        wml.tag.text_box {
                                                id = "gold_tb",
                                                --hint_text = _"Enter a number",
                                                --hint_image =  "icons/action/zoomdefault_25.png~FL(horiz)",
                                                label = tostring(math.floor(wesnoth.sides[wesnoth.current.side].gold/2))
                                        }
                                }
                        },
                        wml.tag.row {
                                wml.tag.column {
                                        wml.tag.spinner {
                                                id = "gold_sp"
                                        }
                                }
                        },
                        wml.tag.row {
                                wml.tag.column {
                                        wml.tag.button {
                                                id = "ok",
                                                label = _"OK"
                                        }
                                }
                        }
                }
        }
        local function preshow(dialog)
                local function show_input()
                        wesnoth.interface.add_chat_message(_"You chose " .. dialog.gold_sl.value .. _" with the slider")
                        wesnoth.interface.add_chat_message(_"You entered <<" .. tostring(dialog.gold_tb.text) .. _">> in the text_box")
                        wesnoth.interface.add_chat_message(_"You chose " .. tostring(dialog.gold_sp._text.text) .. _" with the spinner")
                end
                dialog.ok.on_button_click = show_input

                dialog.gold_sl.on_modified=function()
                        dialog.gold_tb.text = tostring(dialog.gold_sl.value)
                        dialog.gold_sp._text.text = tostring(dialog.gold_sl.value)
                end

        end

        gui.show_dialog(dialogDefinition,preshow)
end

Speak softly, and carry Doombringer.
User avatar
Celtic_Minstrel
Developer
Posts: 2222
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: [GUI] spinner and repeating button

Post by Celtic_Minstrel »

The spinner is a very new widget, so it's possible that some essential parts of interacting with it in Lua just haven't been implemented yet. I don't know any details about it.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Post Reply