diff --git a/ExpCore/GuiParts/inputs.lua b/ExpCore/GuiParts/inputs.lua index 7433d8ea..ef82bbb2 100644 --- a/ExpCore/GuiParts/inputs.lua +++ b/ExpCore/GuiParts/inputs.lua @@ -233,6 +233,33 @@ function inputs.reset_radio(elements) end end +--- Used to define a text callback only on text_changed +-- @usage Gui.inputs.add_text('test',false,'Just for testing',function) +-- @tparam string name the name of this button +-- @tparam boolean box is it a text box rather than a text field +-- @tparam string text the starting text +-- @tparam function the callback to call on change function(player,text,element) +-- @treturn table the text object that was made, to allow a custom error event if wanted +function inputs.add_text(name,box,text,callback) + local type = 'textfield'; if box then type='text-box' end + local textbox = inputs.add{ + type=type, + name=name, + text=text + } + textbox.data._callback = callback + textbox:on_event('text',function(event) + local player = Game.get_player(event) + local element = event.element + local callback = textbox.data._callback + if is_type(callback,'function') then + local success, err = pcall(callback,player,element.text,element) + if not success then error(err) end + else error('Invalid Callback Condition Format') end + end) + return textbox +end + return inputs --[[ diff --git a/control.lua b/control.lua index 6dad031b..3acd3866 100644 --- a/control.lua +++ b/control.lua @@ -101,4 +101,12 @@ radio_test = Gui.inputs.add_checkbox('test-radio',true,'Kill Self',function(pare return game.players[parent.player_index].in_combat end,function(player,element) if player.character then player.character.die() end +end) + +text_test = Gui.inputs.add_text('test-text',false,'default text',function(player,text,element) + player_return(text,nil,player) +end) + +box_test = Gui.inputs.add_text('test-box',true,'default text but a box',function(player,text,element) + player_return(text,nil,player) end) \ No newline at end of file