From 4f12463c733b98421847fb0319080ac0a65feae2 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Fri, 15 Dec 2017 21:46:45 +0000 Subject: [PATCH] Added function to reset radio buttons --- locale/ExpCore/GuiParts/inputs.lua | 29 ++++++++++++++++++++++++++++- locale/ExpCore/ranking.lua | 1 + 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/locale/ExpCore/GuiParts/inputs.lua b/locale/ExpCore/GuiParts/inputs.lua index 582969a6..7433d8ea 100644 --- a/locale/ExpCore/GuiParts/inputs.lua +++ b/locale/ExpCore/GuiParts/inputs.lua @@ -170,7 +170,7 @@ function inputs.add_elem_button(name,elem_type,tooltip,callback) end --- Used to define a checkbox callback only on state_changed --- @usage Gui.inputs.add_checkbox('test','Test','Just for testing',function) +-- @usage Gui.inputs.add_checkbox('test',false,'Just for testing',function,function,funvtion) -- @tparam string name the name of this button -- @tparam string the display for this button, either text or sprite path -- @tparam string tooltip the tooltip to show on the button @@ -206,6 +206,33 @@ function inputs.add_checkbox(name,radio,display,default,callback_true,callback_f return checkbox end +--- Used to reset the state of radio buttons, recomened to be called on_state_change to reset any radio buttons it is ment to work with. +-- @usage Gui.inputs.reset_radio{radio1,radio2,...} +-- @param elements can be a list of elements or a single element +function inputs.reset_radio(elements) + if #elements > 0 then + for _,element in pairs(elements) do + if element.valid then + local _elements = Gui._get_data('inputs_'..element.type) or {} + local _element = _elements[element.name] + local state = false + local success, err = pcall(_element.data._state,element.parent) + if success then state = err else error(err) end + element.state = state + end + end + else + if elements.valid then + local _elements = Gui._get_data('inputs_'..elements.type) or {} + local _element = _elements[elements.name] + local state = false + local success, err = pcall(_element.data._state,elements.parent) + if success then state = err else error(err) end + element.state = state + end + end +end + return inputs --[[ diff --git a/locale/ExpCore/ranking.lua b/locale/ExpCore/ranking.lua index 561c44f8..6f4a11e9 100644 --- a/locale/ExpCore/ranking.lua +++ b/locale/ExpCore/ranking.lua @@ -125,6 +125,7 @@ function Ranking.give_rank(player,rank,by_player,tick) if not old_rank.group.name == 'Jail' then Ranking._presets().old[player.index] = rank.name end if defines.events.rank_change then script.raise_event(defines.events.rank_change,{ + name=defines.events.rank_change, tick=tick, player_index=player.index, by_player_name=by_player_name,