mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-29 20:16:38 +09:00
Added text inputs
This commit is contained in:
@@ -74,5 +74,7 @@ Gui.require_concept('dropdown')
|
||||
Gui.require_concept('elem_button')
|
||||
Gui.require_concept('progress_bar')
|
||||
Gui.require_concept('slider')
|
||||
Gui.require_concept('textfield')
|
||||
Gui.require_concept('textbox')
|
||||
|
||||
return Gui
|
||||
@@ -10,7 +10,7 @@ local Gui = require 'expcore.gui.core'
|
||||
@param on_value_changed fired when the value of the slider is changed
|
||||
@tparam number value_step the minimum amount by which the value of the slider can be changed
|
||||
@tparam ?number|function default the default value of the slider or a function which returns the default value
|
||||
@tparam boolean discrete_slider makes this slider a discrete slider (at time of writing unsure what this is)
|
||||
@tparam boolean discrete_slider makes this slider a discrete slider, this means that the slider button will stop at the same interval as the values do
|
||||
@tparam ?number|function range accepts two params the minimum and the maximum for this slider, or a single function to return both
|
||||
@usage-- Making a basic slider
|
||||
local basic_slider =
|
||||
|
||||
60
expcore/gui/concepts/textbox.lua
Normal file
60
expcore/gui/concepts/textbox.lua
Normal file
@@ -0,0 +1,60 @@
|
||||
--[[-- Core Module - Gui
|
||||
@module Gui
|
||||
@alias Gui
|
||||
]]
|
||||
|
||||
local Gui = require 'expcore.gui.core'
|
||||
|
||||
--[[-- The text box element
|
||||
@element text_box
|
||||
@param on_text_changed fired when the text within the text box is changed
|
||||
@tparam ?string|Concepts.LocalisedString tooltip the tooltip that shows when a player hovers over the text box
|
||||
@tparam ?string|function default the default text that will appear in the text box, or a function that returns it
|
||||
@tparam boolean clear_on_rmb if the text box will be cleared and forcused on a right click
|
||||
@tparam boolean is_selectable when true the text inside the box can be selected
|
||||
@tparam boolean has_word_wrap when true the text will wrap onto the next line if it reachs the end
|
||||
@tparam boolean is_read_only when true the text inside the box can not be edited by the player
|
||||
@usage-- Making a text box
|
||||
local basic_text_box =
|
||||
Gui.clone_concept('text_box','basic_text_box')
|
||||
:set_default('I am the text that will show in the text box')
|
||||
@usage-- Making a text box which can be edited
|
||||
local editible_text_box =
|
||||
Gui.clone_concept('text_box','editible_text_box')
|
||||
:set_is_read_only(false)
|
||||
:set_default('I am the text that will show in the text box')
|
||||
:on_confirmation(function(event)
|
||||
event.player.print('Editible text box is now: '..event.element.text)
|
||||
end)
|
||||
]]
|
||||
Gui.new_concept('text_box')
|
||||
:new_event('on_text_changed',defines.events.on_gui_text_changed)
|
||||
:new_property('tooltip')
|
||||
:new_property('default')
|
||||
:new_property('clear_on_rmb',false)
|
||||
:new_property('is_selectable',true)
|
||||
:new_property('has_word_wrap',true)
|
||||
:new_property('is_read_only',true)
|
||||
:define_draw(function(properties,parent,element)
|
||||
local default = properties.default
|
||||
local text = type(default) == 'string' and default or nil
|
||||
|
||||
element = parent.add{
|
||||
name = properties.name,
|
||||
type = 'text-box',
|
||||
tooltip = properties.tooltip,
|
||||
clear_and_focus_on_right_click = properties.clear_on_rmb,
|
||||
text = text
|
||||
}
|
||||
|
||||
element.selectable = properties.is_selectable
|
||||
element.word_wrap = properties.has_word_wrap
|
||||
element.read_only = properties.is_read_only
|
||||
|
||||
default = Gui.resolve_property(default,element)
|
||||
if default and default ~= text then
|
||||
element.text = default
|
||||
end
|
||||
|
||||
return element
|
||||
end)
|
||||
76
expcore/gui/concepts/textfield.lua
Normal file
76
expcore/gui/concepts/textfield.lua
Normal file
@@ -0,0 +1,76 @@
|
||||
--[[-- Core Module - Gui
|
||||
@module Gui
|
||||
@alias Gui
|
||||
]]
|
||||
|
||||
local Gui = require 'expcore.gui.core'
|
||||
|
||||
--[[-- The text field element
|
||||
@element text_field
|
||||
@param on_text_changed fired when the text within the text field is changed
|
||||
@param on_confirmation fired when the player presses enter with the text field forcused
|
||||
@tparam ?string|Concepts.LocalisedString tooltip the tooltip that shows when a player hovers over the text field
|
||||
@tparam ?string|function default the default text that will appear in the text field, or a function that returns it
|
||||
@tparam boolean clear_on_rmb if the text field will be cleared and forcused on a right click
|
||||
@tparam boolean lose_forcus if the text field will lose forcus after the confirmation event
|
||||
@tparam boolean is_number if this text field contains a number value, can be ignored if is_decimal or is_negitive is used
|
||||
@tparam boolean is_decimal if this text field contains a decimal value
|
||||
@tparam boolean is_negative if this text field contains a negative value
|
||||
@tparam boolean is_password if this text field contains a password value
|
||||
@usage-- Making a text field
|
||||
local basic_text_field =
|
||||
Gui.clone_concept('text_field','basic_text_field')
|
||||
:on_confirmation(function(event)
|
||||
event.player.print('Basic text field is now: '..event.element.text)
|
||||
end)
|
||||
@usage-- Making a text field which will clear on right click and un forcus on confirmation
|
||||
local better_text_field =
|
||||
Gui.clone_concept('text_field','better_text_field')
|
||||
:set_clear_on_rmb(true)
|
||||
:set_lose_forcus(true)
|
||||
:on_confirmation(function(event)
|
||||
event.player.print('Better text field is now: '..event.element.text)
|
||||
end)
|
||||
@usage-- Making a decimal input
|
||||
local decimal_text_field =
|
||||
Gui.clone_concept('text_field','decimal_text_field')
|
||||
:set_is_decimal(true)
|
||||
:on_confirmation(function(event)
|
||||
event.player.print('Decimal text field is now: '..event.element.text)
|
||||
end)
|
||||
]]
|
||||
Gui.new_concept('text_field')
|
||||
:new_event('on_text_changed',defines.events.on_gui_text_changed)
|
||||
:new_event('on_confirmation',defines.events.on_gui_confirmed)
|
||||
:new_property('tooltip')
|
||||
:new_property('default')
|
||||
:new_property('clear_on_rmb',false)
|
||||
:new_property('lose_forcus',false)
|
||||
:new_property('is_number',false)
|
||||
:new_property('is_decimal',false)
|
||||
:new_property('is_negative',false)
|
||||
:new_property('is_password',false)
|
||||
:define_draw(function(properties,parent,element)
|
||||
local default = properties.default
|
||||
local text = type(default) == 'string' and default or nil
|
||||
|
||||
element = parent.add{
|
||||
name = properties.name,
|
||||
type = 'textfield',
|
||||
tooltip = properties.tooltip,
|
||||
clear_and_focus_on_right_click = properties.clear_on_rmb,
|
||||
lose_focus_on_confirm = properties.lose_forcus,
|
||||
numeric = properties.is_number or properties.is_decimal or properties.is_negative,
|
||||
allow_decimal = properties.is_decimal,
|
||||
allow_negative = properties.is_negative,
|
||||
is_password = properties.is_password,
|
||||
text = text
|
||||
}
|
||||
|
||||
default = Gui.resolve_property(default,element)
|
||||
if default and default ~= text then
|
||||
element.text = default
|
||||
end
|
||||
|
||||
return element
|
||||
end)
|
||||
@@ -514,4 +514,98 @@ tests.Sliders = {
|
||||
['Discrete Slider'] = discrete_slider,
|
||||
['Dynamic Slider'] = dynamic_slider,
|
||||
['Player Stored Slider'] = player_slider
|
||||
}
|
||||
|
||||
--[[
|
||||
Text Fields
|
||||
> Basic Text Field -- Just a text field which text can be entered into
|
||||
> Better Text Field -- Same as above but will clear on rmb and un forcus on confirmation
|
||||
> Decimal Text Field -- Text field which accepts decimal values
|
||||
> Password Text Field -- Text field which stars out the typed characters
|
||||
> Player Stored Text Field - Same as basic but will store value per player
|
||||
]]
|
||||
|
||||
-- Making a text field
|
||||
local basic_text_field =
|
||||
Gui.clone_concept('text_field',TEST 'basic_text_field')
|
||||
:set_tooltip('Basic text field')
|
||||
:on_confirmation(function(event)
|
||||
event.player.print('Basic text field is now: '..event.element.text)
|
||||
end)
|
||||
|
||||
local better_text_field =
|
||||
Gui.clone_concept('text_field',TEST 'better_text_field')
|
||||
:set_tooltip('Better text field')
|
||||
:set_clear_on_rmb(true)
|
||||
:set_lose_forcus(true)
|
||||
:on_confirmation(function(event)
|
||||
event.player.print('Better text field is now: '..event.element.text)
|
||||
end)
|
||||
|
||||
local decimal_text_field =
|
||||
Gui.clone_concept('text_field',TEST 'decimal_text_field')
|
||||
:set_tooltip('Decimal text field')
|
||||
:set_is_decimal(true)
|
||||
:on_confirmation(function(event)
|
||||
event.player.print('Decimal text field is now: '..event.element.text)
|
||||
end)
|
||||
|
||||
local password_text_field =
|
||||
Gui.clone_concept('text_field',TEST 'password_text_field')
|
||||
:set_tooltip('Password text field')
|
||||
:set_is_password(true)
|
||||
:on_confirmation(function(event)
|
||||
event.player.print('Password text field is now: '..event.element.text)
|
||||
end)
|
||||
|
||||
local player_text_field =
|
||||
Gui.clone_concept('text_field',TEST 'player_text_field')
|
||||
:set_tooltip('Player stored text field')
|
||||
:on_confirmation(function(event)
|
||||
local element = event.element
|
||||
local text = element.text
|
||||
event.concept.set_data(element,text)
|
||||
event.player.print('Player stored text field is now: '..text)
|
||||
end)
|
||||
:define_combined_store(Gui.categorize_by_player, function(element,value)
|
||||
element.text = value or ''
|
||||
end)
|
||||
|
||||
tests['Text Fields'] = {
|
||||
['Basic Text Field'] = basic_text_field,
|
||||
['Better Text Field'] = better_text_field,
|
||||
['Decimal Text Field'] = decimal_text_field,
|
||||
['Password Text Field'] = password_text_field,
|
||||
['Player Stored Text Field'] = player_text_field
|
||||
}
|
||||
|
||||
--[[
|
||||
Text Boxs
|
||||
> Basic Text Box -- A text box that can not be edited
|
||||
> Editible Text Box -- A text box that can be edited
|
||||
]]
|
||||
|
||||
local basic_text_box =
|
||||
Gui.clone_concept('text_box',TEST 'basic_text_box')
|
||||
:set_tooltip('Basic text box')
|
||||
:set_default('I am the text that will show in the text box')
|
||||
:define_draw(function(properties,parent,element)
|
||||
element.style.height = 75
|
||||
end)
|
||||
|
||||
local editible_text_box =
|
||||
Gui.clone_concept('text_box',TEST 'editible_text_box')
|
||||
:set_tooltip('Editible text box')
|
||||
:set_is_read_only(false)
|
||||
:set_default('I am the text that will show in the text box')
|
||||
:on_text_changed(function(event)
|
||||
event.player.print('Editible text box is now: '..event.element.text)
|
||||
end)
|
||||
:define_draw(function(properties,parent,element)
|
||||
element.style.height = 75
|
||||
end)
|
||||
|
||||
tests['Text Boxs'] = {
|
||||
['Basic Text Box'] = basic_text_box,
|
||||
['Editible Text Box'] = editible_text_box
|
||||
}
|
||||
Reference in New Issue
Block a user