mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 04:21:41 +09:00
Added elem buttons
This commit is contained in:
@@ -9,7 +9,7 @@ local array_insert = ext_require('expcore.common','array_insert')
|
||||
--[[-- The basic dropdown element
|
||||
@element dropdown
|
||||
@param on_selection_change fired when the selected value is changed
|
||||
@tparam ?string|Conepts.LocalisedString default_selection the option which is selected by default
|
||||
@tparam ?string|Concepts.LocalisedString|function default_selection the option which is selected by default, or a function which returns the default
|
||||
@tparam boolean use_list_box when true a list box will be used rather than a dropdown menu
|
||||
@tparam ?nil|table static_items when called with a table the values will be added as items for the dropdown, if called with nil then all items are cleared
|
||||
@tparam function dynamic_items the given function will be called to return a list of items and optional start index to add items to the dropdown when it is first drawn
|
||||
@@ -26,11 +26,9 @@ local dynamic_dropdown =
|
||||
Gui.clone_concept('dropdown','dynamic_dropdown')
|
||||
:set_dynamic_items(function(element)
|
||||
local items = {}
|
||||
|
||||
for _,player in pairs(game.connected_players) do
|
||||
items[#items+1] = player.name
|
||||
end
|
||||
|
||||
return items
|
||||
end)
|
||||
:on_selection_change(function(event)
|
||||
@@ -107,7 +105,7 @@ end)
|
||||
|
||||
--[[-- Selects the index of a dropdown with this value
|
||||
@tparam LuaGuiElement element the dropdown that you want to set the selection for
|
||||
@tparam ?string|Conepts.LocalisedString value the value that you want selected
|
||||
@tparam ?string|Concepts.LocalisedString value the value that you want selected
|
||||
@treturn boolean if an item with this value was found
|
||||
@usage-- Selecting the item with the value 'foo'
|
||||
Gui.set_dropdown_value(element,'foo')
|
||||
@@ -124,7 +122,7 @@ end
|
||||
|
||||
--[[-- Gets the selected item value of a dropdown
|
||||
@tparam LuaGuiElement element the dropdown that you want the selected value of
|
||||
@treturn ?string|Conepts.LocalisedString the value that is currently selected
|
||||
@treturn ?string|Concepts.LocalisedString the value that is currently selected
|
||||
@usage-- Getting the selected value
|
||||
local selected_value = Gui.get_dropdown_value(element)
|
||||
]]
|
||||
|
||||
49
expcore/gui/concepts/elem_button.lua
Normal file
49
expcore/gui/concepts/elem_button.lua
Normal file
@@ -0,0 +1,49 @@
|
||||
--[[-- Core Module - Gui
|
||||
@module Gui
|
||||
@alias Gui
|
||||
]]
|
||||
|
||||
local Gui = require 'expcore.gui.core'
|
||||
|
||||
--[[-- The basic dropdown element
|
||||
@element elem_button
|
||||
@param on_selection_change fired when the selected value is changed
|
||||
@tparam ?string|Concepts.SignalID|function default_selection the option which is selected by default, or a function which returns the default
|
||||
@tparam string elem_type the type of elem selection that this is, default is item selection
|
||||
@usage-- Making a basic elem button
|
||||
local basic_elem_button =
|
||||
Gui.clone_concept('elem_button',TEST 'basic_elembutton')
|
||||
:on_selection_change(function(event)
|
||||
event.player.print('Basic elem button is now: '..event.element.elem_value)
|
||||
end)
|
||||
]]
|
||||
Gui.new_concept('elem_button')
|
||||
:new_event('on_selection_change',defines.events.on_gui_elem_changed)
|
||||
:new_property('default_selection')
|
||||
:new_property('elem_type','item')
|
||||
:define_draw(function(properties,parent,element,selection)
|
||||
element = parent.add{
|
||||
name = properties.name,
|
||||
type = 'choose-elem-button',
|
||||
elem_type = properties.elem_type
|
||||
}
|
||||
|
||||
if properties.default_selection and not selection then
|
||||
local default = properties.default_selection
|
||||
if type(default) == 'function' then
|
||||
default = default(element)
|
||||
end
|
||||
|
||||
element.elem_value = default
|
||||
|
||||
elseif selection then
|
||||
if type(selection) == 'function' then
|
||||
selection = selection(element)
|
||||
end
|
||||
|
||||
element.elem_value = selection
|
||||
|
||||
end
|
||||
|
||||
return element
|
||||
end)
|
||||
Reference in New Issue
Block a user