diff --git a/docs/addons/Advanced-Start.html b/docs/addons/Advanced-Start.html index faf5372f..73fbfff1 100644 --- a/docs/addons/Advanced-Start.html +++ b/docs/addons/Advanced-Start.html @@ -349,7 +349,7 @@ generated by LDoc
diff --git a/docs/addons/Chat-Popups.html b/docs/addons/Chat-Popups.html index 1cb898d6..775e8d48 100644 --- a/docs/addons/Chat-Popups.html +++ b/docs/addons/Chat-Popups.html @@ -350,7 +350,7 @@ generated by LDoc diff --git a/docs/addons/Chat-Reply.html b/docs/addons/Chat-Reply.html index be26fd7b..e782e0bd 100644 --- a/docs/addons/Chat-Reply.html +++ b/docs/addons/Chat-Reply.html @@ -377,7 +377,7 @@ generated by LDoc diff --git a/docs/addons/Compilatron.html b/docs/addons/Compilatron.html index c1102fc7..5fd8782d 100644 --- a/docs/addons/Compilatron.html +++ b/docs/addons/Compilatron.html @@ -586,7 +586,7 @@ generated by LDoc diff --git a/docs/addons/Damage-Popups.html b/docs/addons/Damage-Popups.html index 10d6f5e9..7cfdaca2 100644 --- a/docs/addons/Damage-Popups.html +++ b/docs/addons/Damage-Popups.html @@ -350,7 +350,7 @@ generated by LDoc diff --git a/docs/addons/Death-Logger.html b/docs/addons/Death-Logger.html index a58f573c..970adce4 100644 --- a/docs/addons/Death-Logger.html +++ b/docs/addons/Death-Logger.html @@ -405,7 +405,7 @@ generated by LDoc diff --git a/docs/addons/Discord-Alerts.html b/docs/addons/Discord-Alerts.html index bec86481..5e0947dc 100644 --- a/docs/addons/Discord-Alerts.html +++ b/docs/addons/Discord-Alerts.html @@ -461,7 +461,7 @@ generated by LDoc diff --git a/docs/addons/Player-Colours.html b/docs/addons/Player-Colours.html index dc617ebf..d7b1e361 100644 --- a/docs/addons/Player-Colours.html +++ b/docs/addons/Player-Colours.html @@ -405,7 +405,7 @@ generated by LDoc diff --git a/docs/addons/Pollution-Grading.html b/docs/addons/Pollution-Grading.html index 5cc620da..c4a517fb 100644 --- a/docs/addons/Pollution-Grading.html +++ b/docs/addons/Pollution-Grading.html @@ -321,7 +321,7 @@ generated by LDoc diff --git a/docs/addons/Scorched-Earth.html b/docs/addons/Scorched-Earth.html index 3132f77a..57b0ab74 100644 --- a/docs/addons/Scorched-Earth.html +++ b/docs/addons/Scorched-Earth.html @@ -405,7 +405,7 @@ generated by LDoc diff --git a/docs/addons/Spawn-Area.html b/docs/addons/Spawn-Area.html index 5f29f43e..be2099ef 100644 --- a/docs/addons/Spawn-Area.html +++ b/docs/addons/Spawn-Area.html @@ -377,7 +377,7 @@ generated by LDoc diff --git a/docs/commands/Admin-Chat.html b/docs/commands/Admin-Chat.html index 3f32bbfe..6025ff68 100644 --- a/docs/commands/Admin-Chat.html +++ b/docs/commands/Admin-Chat.html @@ -389,7 +389,7 @@ generated by LDoc diff --git a/docs/commands/Bonus.html b/docs/commands/Bonus.html index 72e63565..0598e87c 100644 --- a/docs/commands/Bonus.html +++ b/docs/commands/Bonus.html @@ -501,7 +501,7 @@ generated by LDoc diff --git a/docs/commands/Cheat-Mode.html b/docs/commands/Cheat-Mode.html index e3d0fe61..cfd66e8b 100644 --- a/docs/commands/Cheat-Mode.html +++ b/docs/commands/Cheat-Mode.html @@ -362,7 +362,7 @@ generated by LDoc diff --git a/docs/commands/Clear-Inventory.html b/docs/commands/Clear-Inventory.html index cf5e879b..8981f9dc 100644 --- a/docs/commands/Clear-Inventory.html +++ b/docs/commands/Clear-Inventory.html @@ -389,7 +389,7 @@ generated by LDoc diff --git a/docs/commands/Debug.html b/docs/commands/Debug.html index 943927e9..b205bdb0 100644 --- a/docs/commands/Debug.html +++ b/docs/commands/Debug.html @@ -366,7 +366,7 @@ generated by LDoc diff --git a/docs/commands/Find.html b/docs/commands/Find.html index eade86b7..7336767c 100644 --- a/docs/commands/Find.html +++ b/docs/commands/Find.html @@ -361,7 +361,7 @@ generated by LDoc diff --git a/docs/commands/Help.html b/docs/commands/Help.html index ba5015dd..67979913 100644 --- a/docs/commands/Help.html +++ b/docs/commands/Help.html @@ -405,7 +405,7 @@ generated by LDoc diff --git a/docs/commands/Home.html b/docs/commands/Home.html index 2be91e72..c864e5c7 100644 --- a/docs/commands/Home.html +++ b/docs/commands/Home.html @@ -459,7 +459,7 @@ generated by LDoc diff --git a/docs/commands/Interface.html b/docs/commands/Interface.html index 9f411202..e730c1b9 100644 --- a/docs/commands/Interface.html +++ b/docs/commands/Interface.html @@ -417,7 +417,7 @@ generated by LDoc diff --git a/docs/commands/Jail.html b/docs/commands/Jail.html index fdef4831..a968ac2f 100644 --- a/docs/commands/Jail.html +++ b/docs/commands/Jail.html @@ -612,7 +612,7 @@ generated by LDoc diff --git a/docs/commands/Kill.html b/docs/commands/Kill.html index 6c3d62f5..554c9a5b 100644 --- a/docs/commands/Kill.html +++ b/docs/commands/Kill.html @@ -390,7 +390,7 @@ generated by LDoc diff --git a/docs/commands/Me.html b/docs/commands/Me.html index ddb01af6..0ae4db9f 100644 --- a/docs/commands/Me.html +++ b/docs/commands/Me.html @@ -361,7 +361,7 @@ generated by LDoc diff --git a/docs/commands/Rainbow.html b/docs/commands/Rainbow.html index beb18d54..90df5f7a 100644 --- a/docs/commands/Rainbow.html +++ b/docs/commands/Rainbow.html @@ -389,7 +389,7 @@ generated by LDoc diff --git a/docs/commands/Repair.html b/docs/commands/Repair.html index 8cb83cdf..aafce3f8 100644 --- a/docs/commands/Repair.html +++ b/docs/commands/Repair.html @@ -322,7 +322,7 @@ generated by LDoc diff --git a/docs/commands/Reports.html b/docs/commands/Reports.html index f5464b40..e799ff0d 100644 --- a/docs/commands/Reports.html +++ b/docs/commands/Reports.html @@ -586,7 +586,7 @@ generated by LDoc diff --git a/docs/commands/Roles.html b/docs/commands/Roles.html index 30cdb86f..c7a69793 100644 --- a/docs/commands/Roles.html +++ b/docs/commands/Roles.html @@ -558,7 +558,7 @@ generated by LDoc diff --git a/docs/commands/Spawn.html b/docs/commands/Spawn.html index b8135072..f30178d8 100644 --- a/docs/commands/Spawn.html +++ b/docs/commands/Spawn.html @@ -390,7 +390,7 @@ generated by LDoc diff --git a/docs/commands/Tag.html b/docs/commands/Tag.html index 650b981d..00709274 100644 --- a/docs/commands/Tag.html +++ b/docs/commands/Tag.html @@ -444,7 +444,7 @@ generated by LDoc diff --git a/docs/commands/Teleport.html b/docs/commands/Teleport.html index d4b5c5c0..791563c0 100644 --- a/docs/commands/Teleport.html +++ b/docs/commands/Teleport.html @@ -485,7 +485,7 @@ generated by LDoc diff --git a/docs/commands/Warnings.html b/docs/commands/Warnings.html index 79b3982a..7efc06e3 100644 --- a/docs/commands/Warnings.html +++ b/docs/commands/Warnings.html @@ -570,7 +570,7 @@ generated by LDoc diff --git a/docs/configs/Advanced-Start.html b/docs/configs/Advanced-Start.html index 3ee81b26..dea46b30 100644 --- a/docs/configs/Advanced-Start.html +++ b/docs/configs/Advanced-Start.html @@ -507,7 +507,7 @@ generated by LDoc diff --git a/docs/configs/Bonuses.html b/docs/configs/Bonuses.html index 4f24d85e..9f5b1760 100644 --- a/docs/configs/Bonuses.html +++ b/docs/configs/Bonuses.html @@ -238,7 +238,7 @@ generated by LDoc diff --git a/docs/configs/Chat-Reply.html b/docs/configs/Chat-Reply.html index dc328519..518eb631 100644 --- a/docs/configs/Chat-Reply.html +++ b/docs/configs/Chat-Reply.html @@ -486,7 +486,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Admin.html b/docs/configs/Commands-Auth-Admin.html index 93162e2f..7b7427da 100644 --- a/docs/configs/Commands-Auth-Admin.html +++ b/docs/configs/Commands-Auth-Admin.html @@ -295,7 +295,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Roles.html b/docs/configs/Commands-Auth-Roles.html index 33fae8e3..c30819c2 100644 --- a/docs/configs/Commands-Auth-Roles.html +++ b/docs/configs/Commands-Auth-Roles.html @@ -321,7 +321,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Runtime-Disable.html b/docs/configs/Commands-Auth-Runtime-Disable.html index 8f244e55..33386c16 100644 --- a/docs/configs/Commands-Auth-Runtime-Disable.html +++ b/docs/configs/Commands-Auth-Runtime-Disable.html @@ -443,7 +443,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Parse-Roles.html b/docs/configs/Commands-Parse-Roles.html index c190f4f7..71c1c783 100644 --- a/docs/configs/Commands-Parse-Roles.html +++ b/docs/configs/Commands-Parse-Roles.html @@ -355,7 +355,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Parse.html b/docs/configs/Commands-Parse.html index 11843168..3987c8d6 100644 --- a/docs/configs/Commands-Parse.html +++ b/docs/configs/Commands-Parse.html @@ -339,7 +339,7 @@ see ./expcore/commands.lua for more details generated by LDoc diff --git a/docs/configs/Compilatron.html b/docs/configs/Compilatron.html index f509d0f0..75d2f5bf 100644 --- a/docs/configs/Compilatron.html +++ b/docs/configs/Compilatron.html @@ -355,7 +355,7 @@ generated by LDoc diff --git a/docs/configs/Death-Logger.html b/docs/configs/Death-Logger.html index ee2283be..a6af1f2c 100644 --- a/docs/configs/Death-Logger.html +++ b/docs/configs/Death-Logger.html @@ -417,7 +417,7 @@ generated by LDoc diff --git a/docs/configs/Discord-Alerts.html b/docs/configs/Discord-Alerts.html index 18a6d7a5..2c4725b0 100644 --- a/docs/configs/Discord-Alerts.html +++ b/docs/configs/Discord-Alerts.html @@ -238,7 +238,7 @@ generated by LDoc diff --git a/docs/configs/File-Loader.html b/docs/configs/File-Loader.html index 2944ffe3..98a8d207 100644 --- a/docs/configs/File-Loader.html +++ b/docs/configs/File-Loader.html @@ -241,7 +241,7 @@ generated by LDoc diff --git a/docs/configs/Permission-Groups.html b/docs/configs/Permission-Groups.html index 0fc205fb..74c617c3 100644 --- a/docs/configs/Permission-Groups.html +++ b/docs/configs/Permission-Groups.html @@ -296,7 +296,7 @@ generated by LDoc diff --git a/docs/configs/Player-List.html b/docs/configs/Player-List.html index e94579ed..3a63165b 100644 --- a/docs/configs/Player-List.html +++ b/docs/configs/Player-List.html @@ -813,7 +813,7 @@ generated by LDoc diff --git a/docs/configs/Pollution-Grading.html b/docs/configs/Pollution-Grading.html index bf22c696..99d328d6 100644 --- a/docs/configs/Pollution-Grading.html +++ b/docs/configs/Pollution-Grading.html @@ -385,7 +385,7 @@ generated by LDoc diff --git a/docs/configs/Popup-Messages.html b/docs/configs/Popup-Messages.html index 3e57f2a9..1679f71e 100644 --- a/docs/configs/Popup-Messages.html +++ b/docs/configs/Popup-Messages.html @@ -415,7 +415,7 @@ generated by LDoc diff --git a/docs/configs/Preset-Player-Colours.html b/docs/configs/Preset-Player-Colours.html index c81608c3..897866a4 100644 --- a/docs/configs/Preset-Player-Colours.html +++ b/docs/configs/Preset-Player-Colours.html @@ -325,7 +325,7 @@ generated by LDoc diff --git a/docs/configs/Repair.html b/docs/configs/Repair.html index 59645f20..14d48983 100644 --- a/docs/configs/Repair.html +++ b/docs/configs/Repair.html @@ -415,7 +415,7 @@ generated by LDoc diff --git a/docs/configs/Rockets.html b/docs/configs/Rockets.html index c41acf9c..d43a33c0 100644 --- a/docs/configs/Rockets.html +++ b/docs/configs/Rockets.html @@ -835,7 +835,7 @@ generated by LDoc diff --git a/docs/configs/Roles.html b/docs/configs/Roles.html index 43545c64..b311ca00 100644 --- a/docs/configs/Roles.html +++ b/docs/configs/Roles.html @@ -293,7 +293,7 @@ generated by LDoc diff --git a/docs/configs/Science.html b/docs/configs/Science.html index 1b4dd89a..8feb5039 100644 --- a/docs/configs/Science.html +++ b/docs/configs/Science.html @@ -355,7 +355,7 @@ generated by LDoc diff --git a/docs/configs/Scorched-Earth.html b/docs/configs/Scorched-Earth.html index 77513933..44241b1e 100644 --- a/docs/configs/Scorched-Earth.html +++ b/docs/configs/Scorched-Earth.html @@ -389,7 +389,7 @@ generated by LDoc diff --git a/docs/configs/Spawn-Area.html b/docs/configs/Spawn-Area.html index 9b34fe0d..7de1ef89 100644 --- a/docs/configs/Spawn-Area.html +++ b/docs/configs/Spawn-Area.html @@ -745,7 +745,7 @@ generated by LDoc diff --git a/docs/configs/Tasks.html b/docs/configs/Tasks.html index 57848caa..a3054273 100644 --- a/docs/configs/Tasks.html +++ b/docs/configs/Tasks.html @@ -385,7 +385,7 @@ generated by LDoc diff --git a/docs/configs/Warnings.html b/docs/configs/Warnings.html index 4da0c948..10d950d3 100644 --- a/docs/configs/Warnings.html +++ b/docs/configs/Warnings.html @@ -356,7 +356,7 @@ generated by LDoc diff --git a/docs/configs/Warps.html b/docs/configs/Warps.html index a6c100b1..a5d78060 100644 --- a/docs/configs/Warps.html +++ b/docs/configs/Warps.html @@ -685,7 +685,7 @@ generated by LDoc diff --git a/docs/control/Jail.html b/docs/control/Jail.html index 340552b7..761008db 100644 --- a/docs/control/Jail.html +++ b/docs/control/Jail.html @@ -1209,7 +1209,7 @@ generated by LDoc diff --git a/docs/control/Production.html b/docs/control/Production.html index 1c4aaf2d..b4134490 100644 --- a/docs/control/Production.html +++ b/docs/control/Production.html @@ -1330,7 +1330,7 @@ generated by LDoc diff --git a/docs/control/Reports.html b/docs/control/Reports.html index 8751f13d..4e7b0d49 100644 --- a/docs/control/Reports.html +++ b/docs/control/Reports.html @@ -1111,7 +1111,7 @@ generated by LDoc diff --git a/docs/control/Rockets.html b/docs/control/Rockets.html index 95acf774..337ee3a5 100644 --- a/docs/control/Rockets.html +++ b/docs/control/Rockets.html @@ -985,7 +985,7 @@ generated by LDoc diff --git a/docs/control/Tasks.html b/docs/control/Tasks.html index ae05745d..753dc6dc 100644 --- a/docs/control/Tasks.html +++ b/docs/control/Tasks.html @@ -1040,7 +1040,7 @@ generated by LDoc diff --git a/docs/control/Warnings.html b/docs/control/Warnings.html index d20d5fca..04d31e52 100644 --- a/docs/control/Warnings.html +++ b/docs/control/Warnings.html @@ -1466,7 +1466,7 @@ generated by LDoc diff --git a/docs/control/Warps.html b/docs/control/Warps.html index 54cdd303..cbf6f350 100644 --- a/docs/control/Warps.html +++ b/docs/control/Warps.html @@ -1414,7 +1414,7 @@ generated by LDoc diff --git a/docs/core/Commands.html b/docs/core/Commands.html index d20487b8..303654a1 100644 --- a/docs/core/Commands.html +++ b/docs/core/Commands.html @@ -1973,7 +1973,7 @@ generated by LDoc diff --git a/docs/core/Common-Library.html b/docs/core/Common-Library.html index d2ca792f..b1578aa4 100644 --- a/docs/core/Common-Library.html +++ b/docs/core/Common-Library.html @@ -2747,7 +2747,7 @@ Common.table_insert(tbl,50,tbl2) generated by LDoc diff --git a/docs/core/Gui.html b/docs/core/Gui.html index ee72f51c..b348ff81 100644 --- a/docs/core/Gui.html +++ b/docs/core/Gui.html @@ -253,22 +253,24 @@-- Making the base button concept
local button =
-Gui.new_concept('Button')
-:new_event('on_click',defines.events.on_gui_click)
-:new_property('tooltip')
-:new_property('caption',nil,function(properties,value)
- properties.caption = value
+Gui.new_concept() -- Make a new empty concept
+:save_as('button') -- Save it as Gui.concepts.button so it can be used in other files
+:new_event('on_click',defines.events.on_gui_click) -- Add an on click event for this concept
+:new_property('tooltip') -- Add a property with the default setter method called tooltip
+:new_property('caption',function(properties,value) -- Add a property with a custom setter method called caption
+ properties.caption = value
properties.sprite = nil
properties.type = 'button'
end)
-:new_property('sprite',nil,function(properties,value)
- properties.image = value
+:new_property('sprite',function(properties,value) -- Add a property with a custom setter method called sprite
+ properties.image = value
properties.caption = nil
properties.type = 'sprite-button'
end)
-:define_draw(function(properties,parent,element)
- -- Note that element might be nil if this is the first draw function
- -- in this case button is a new concept so we know this is the first function and element is nil
+:define_draw(function(properties,parent,element) -- Add the draw function to create the element from the concept
+ -- Properties will include all the information that you need to draw the element
+ -- Parent is the parent element for the element, this may have been altered by previous draw functions
+ -- Element is the current element being made, this may have a nil value, if it is nil then this is the first draw function
if properties.type == 'button' then
element = parent.add{
type = properties.type,
@@ -287,25 +289,26 @@ Gui.new_concept('Button')
end
- -- We must return the element or what we want to be seen as the instance, this is so other draw functions have access to it
- -- for example if our custom button defined a draw function to change the font color to red
- return element
+ -- If you return element or parent then their values will be updated for the next draw function in the chain
+ -- It is best practice to always return the values if you have made any changes to them
+ return element, parent
end)
- -- Makeing a alternative button based on the first
+ -- Making a new button which has a custom style
local custom_button =
-button:clone('CustomButton')
-:new_event('on_admin_clicked',defines.events.on_gui_click,function(event)
- return event.player.admin -- only raise custom event when an admin clicks the button
-end)
-:set_caption('Custom Button')
-:set_tooltip('Only admins can press this button')
-:on_click(function(event)
- if not event.player.admin then
+Gui.new_concept('button') -- We can use button here since we used save as on the concept
+-- button:clone() -- If we had not used save as then this is how we would use it as a base
+:set_caption('Custom Button') -- Set the caption of the concept, this is possible as we added caption as a property
+:set_tooltip('Only admins can press this button') -- Set the tooltip of the concept, this is possible as we added tooltip as a property
+:on_click(function(event) -- Register a handler to the click event we added with new event
+ if not event.player.admin then
event.player.print('You must be admin to use this button')
end
end)
-:on_admin_clicked(function(event)
- -- Yes i know this can just be an if else but its an example
+:new_event('on_admin_clicked',defines.events.on_gui_click,function(event) -- Add a click event which has a filter function
+ return event.player.admin -- Check if the player is admin
+end)
+:on_admin_clicked(function(event) -- Register a handler to the admin click event we have just created
+ -- The admin click event is only an example, because of how sinmple the filter is we could have just used an if else statement
game.print(event.player.name..' pressed my admin button')
end)
-- Drawing a concept
@@ -438,27 +441,27 @@ button:clone('CustomButton')
- require_concept(concept)
- Loads a concept from the concepts file, used internally
+ require_concept(concept_name)
+ Loads a concept from the concepts file
+
+
+ require_style(style_name)
+ Loads a set of concepts from the styles file
get_concept(name)
- Gets the gui concept with this name
+ Gets a gui concept from name, id, or its self
- Prototype:change_name([new_name=self.name])
- Used internally to save concept names to the core gui module
+ Prototype:save_as(save_name)
+ Used to save the concept to the main gui module to allow access from other files
- new_concept(name)
- Returns a new gui concept with no properties or events
+ new_concept([base_concept])
+ Returns a new gui concept, option to provide a base concept to copy properties and draw functions from
- clone_concept(name, new_name)
- Make a new concept based on the properties and drawing of another
-
-
- draw_concept(name, parent)
+ draw_concept(concept, parent)
Used to draw a concept to a parent element
@@ -530,8 +533,12 @@ button:clone('CustomButton')
Use to add your own callbacks to the clone function, for example adding to a local table
- Prototype:change_name([new_name=self.name])
- Used internally to save concept names to the core gui module
+ Prototype:save_as(save_name)
+ Used to save the concept to the main gui module to allow access from other files
+
+
+ Prototype:debug(name)
+ Sets a debug name that can be used with error handlers
Prototype:new_event(event_name[, factorio_event][, event_condition])
@@ -546,7 +553,7 @@ button:clone('CustomButton')
Raises a custom event, folowing keys included automaticlly: concept, event name, game tick, player from player_index, element if valid
- Prototype:new_property(property_name, default[, setter_callback])
+ Prototype:new_property(property_name[, setter_callback][, default])
Adds a new property to the concept, such as caption, tooltip, or some custom property you want to control
@@ -777,7 +784,7 @@ button:clone('CustomButton')
Usage:
-- Making a basic button
local basic_button =
-Gui.clone_concept('button','basic_button')
+Gui.new_concept('button')
:set_caption('Basic Button')
:set_tooltip('Basic button')
:on_click(function(event)
@@ -785,7 +792,7 @@ Gui.clone_concept('button','bas
end)
-- Making a sprite button
local sprite_button =
-Gui.clone_concept('button','sprite_button')
+Gui.new_concept('button')
:set_sprite('utility/warning_icon')
:set_tooltip('Sprite button')
:on_click(function(event)
@@ -907,7 +914,7 @@ Gui.clone_concept('button','spr
Usage:
-- Making a basic checkbox
local basic_checkbox =
-Gui.clone_concept('checkbox','basic_checkbox')
+Gui.new_concept('checkbox')
:set_caption('Basic Checkbox')
:set_tooltip('Basic checkbox')
:on_state_changed(function(event)
@@ -1029,7 +1036,7 @@ Gui.clone_concept('checkbox','b
Usage:
-- Making a basic dropdown
local static_dropdown =
-Gui.clone_concept('dropdown','static_dropdown')
+Gui.new_concept('dropdown')
:set_static_items{'Option 1','Option 2','Option 3'}
:on_selection_changed(function(event)
local value = Gui.get_dropdown_value(event.element)
@@ -1037,7 +1044,7 @@ Gui.clone_concept('dropdown','s
end)
-- Making a dropdown with dynamic items, example is name of online players
local dynamic_dropdown =
-Gui.clone_concept('dropdown','dynamic_dropdown')
+Gui.new_concept('dropdown')
:set_dynamic_items(function(element)
local items = {}
for _,player in pairs(game.connected_players) do
@@ -1133,7 +1140,7 @@ Gui.clone_concept('dropdown','d
Usage:
-- Making a basic elem button
local basic_elem_button =
-Gui.clone_concept('elem_button','basic_elembutton')
+Gui.new_concept('elem_button')
:on_selection_changed(function(event)
event.player.print('Basic elem button is now: '..event.element.elem_value)
end)
@@ -1190,7 +1197,7 @@ Gui.clone_concept('elem_button',Usage:
-- Making a draggable space styled widget
local draggable_space =
-Gui.clone_concept('empty','draggable_space')
+Gui.new_concept('empty')
:set_style('draggable_space')
@@ -1245,7 +1252,7 @@ Gui.clone_concept('empty','drag
Usage:
-- Making a basic flow, contains a label with hello world
local basic_flow =
-Gui.clone_concept('flow','basic_flow')
+Gui.new_concept('flow')
:define_draw(function(properties,parent,element)
element.add{
type = 'label',
@@ -1321,7 +1328,7 @@ Gui.clone_concept('flow','basic
Usage:
-- Making a basic frame, contains a label with hello world
local basic_frame =
-Gui.clone_concept('frame','basic_frame')
+Gui.new_concept('frame')
:set_title('Basic Frame')
:define_draw(function(properties,parent,element)
element.add{
@@ -1383,6 +1390,22 @@ Gui.clone_concept('frame','basi
+
+
+
+
+
+ rich_text
+
+ :
+
+ (defines.rich_text_setting)
+
+ how this element handles rich text
+
+
+
+
@@ -1398,7 +1421,7 @@ Gui.clone_concept('frame','basi
Usage:
-- Making a basic label
local basic_label =
-Gui.clone_concept('label','basic_label')
+Gui.new_concept('label')
:set_caption('Hello, World!')
@@ -1453,7 +1476,7 @@ Gui.clone_concept('label','basi
Usage:
-- Making a basic frame, contains a label with hello world
local basic_line =
-Gui.clone_concept('line','basic_line')
+Gui.new_concept('line')
@@ -1570,7 +1593,7 @@ Gui.clone_concept('line','basic
Usage:
-- Making a basic progress bar, will increase when pressed then will reset when full
local basic_progress_bar =
-Gui.clone_concept('progress_bar','basic_progress_bar')
+Gui.new_concept('progress_bar')
:set_tooltip('Basic progress bar')
:set_maximum(5)
:new_event('on_click',defines.events.on_gui_click)
@@ -1650,7 +1673,7 @@ Gui.clone_concept('progress_bar',-- Making a basic flow, contains a label with hello world
local basic_scroll =
-Gui.clone_concept('scroll','basic_scroll')
+Gui.new_concept('scroll')
:define_draw(function(properties,parent,element)
element.style.hieght = 50
for i = 1,10 do
@@ -1776,14 +1799,14 @@ Gui.clone_concept('scroll','bas
Usage:
-- Making a basic slider
local basic_slider =
-Gui.clone_concept('slider','basic_slider')
+Gui.new_concept('slider')
:set_range(1,10)
:on_value_changed(function(event)
event.player.print('Basic slider is now: '..event.element.slider_value)
end)
-- Making a discrete_slider
local discrete_slider =
-Gui.clone_concept('slider','discrete_slider')
+Gui.new_concept('slider')
:set_range(1,10)
:set_value_step(1)
:set_discrete_slider(true)
@@ -1907,7 +1930,7 @@ Gui.clone_concept('slider','dis
Usage:
-- Making a basic table, contains 25 labels
local basic_table =
-Gui.clone_concept('table','basic_table')
+Gui.new_concept('table')
:set_column_count(5)
:define_draw(function(properties,parent,element)
for i = 1,25 do
@@ -1989,6 +2012,22 @@ Gui.clone_concept('table','basi
+
+
+ rich_text
+
+ :
+
+ (defines.rich_text_setting)
+
+ how this element handles rich text
+
+
+
+
+
+
+
clear_on_rmb
@@ -2065,11 +2104,11 @@ Gui.clone_concept('table','basi
Usage:
-- Making a text box
local basic_text_box =
-Gui.clone_concept('text_box','basic_text_box')
+Gui.new_concept('text_box')
:set_default('I am the text that will show in the text box')
-- Making a text box which can be edited
local editible_text_box =
-Gui.clone_concept('text_box','editible_text_box')
+Gui.new_concept('text_box')
:set_is_read_only(false)
:set_default('I am the text that will show in the text box')
:on_confirmation(function(event)
@@ -2162,6 +2201,22 @@ Gui.clone_concept('text_box','e
+
+
+ rich_text
+
+ :
+
+ (defines.rich_text_setting)
+
+ how this element handles rich text
+
+
+
+
+
+
+
clear_on_rmb
@@ -2270,13 +2325,13 @@ Gui.clone_concept('text_box','e
Usage:
-- Making a text field
local basic_text_field =
-Gui.clone_concept('text_field','basic_text_field')
+Gui.new_concept('text_field')
:on_confirmation(function(event)
event.player.print('Basic text field is now: '..event.element.text)
end)
-- 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')
+Gui.new_concept('text_field')
:set_clear_on_rmb(true)
:set_lose_forcus(true)
:on_confirmation(function(event)
@@ -2284,7 +2339,7 @@ Gui.clone_concept('text_field',
end)
-- Making a decimal input
local decimal_text_field =
-Gui.clone_concept('text_field','decimal_text_field')
+Gui.new_concept('text_field')
:set_is_decimal(true)
:on_confirmation(function(event)
event.player.print('Decimal text field is now: '..event.element.text)
@@ -2910,13 +2965,13 @@ Gui.clone_concept('text_field',
- Loads a concept from the concepts file, used internally
+ Loads a concept from the concepts file
@@ -2930,7 +2985,7 @@ Gui.clone_concept('text_field',
- concept
+ concept_name
:
@@ -2955,7 +3010,60 @@ Gui.clone_concept('text_field',
Usage:
-- Load a base concept
-Gui.require_concept('frame')
+Gui.require_concept('frame') --- @dep Gui.concept.frame
+
+
+
+
+
+
+ #
+ require_style(style_name)
+
+
+
+
+
+ Loads a set of concepts from the styles file
+
+
+
+ Parameters:
+
+
+
+
+
+
+
+ -
+
+ style_name
+
+ :
+
+ (string)
+
+ the name of the style to require
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Usage:
+ -- Load a base style
+Gui.require_concept('expgaming') --- @dep Gui.style.frame
@@ -2969,7 +3077,7 @@ Gui.clone_concept('text_field',
- Gets the gui concept with this name
+ Gets a gui concept from name, id, or its self
@@ -2987,9 +3095,9 @@ Gui.clone_concept('text_field',
:
- (string)
+ (string, number or table)
- the name of the concept that you want to get
+ the name, id, or the concept you want to get
@@ -3015,14 +3123,14 @@ Gui.clone_concept('text_field',
- Used internally to save concept names to the core gui module
+ Used to save the concept to the main gui module to allow access from other files
@@ -3036,7 +3144,7 @@ Gui.clone_concept('text_field',
- new_name
+ save_name
:
@@ -3044,7 +3152,6 @@ Gui.clone_concept('text_field',
the new name of the concept
- (default: self.name)
@@ -3061,10 +3168,11 @@ Gui.clone_concept('text_field',
Usage:
- -- Internal Saving
--- this is never needed to be done, internal use only!
-local button = Gui.get_concept('Button')
-button:change_name('Not Button')
+ -- Save a concept to allow access in another file
+button:save_as('button')
+ -- Access concept after being saved
+Gui.concepts.button
+Gui.get_concept('button')
@@ -3072,13 +3180,13 @@ button:change_name('Not Button')
- Returns a new gui concept with no properties or events
+ Returns a new gui concept, option to provide a base concept to copy properties and draw functions from
@@ -3092,14 +3200,15 @@ button:change_name('Not Button')
- name
+ base_concept
:
- (string)
+ (string, number or table)
- the name that you want this concept to have
+ the concept that you want to copy the details of
+ (optional)
@@ -3116,85 +3225,16 @@ button:change_name('Not Button')
Usage:
- -- Making a new concept, see module usage
+ -- Making a new button, see module usage
local button = Gui.new_concept('Button')
-
-
-
-
- #
- clone_concept(name, new_name)
-
-
-
-
-
- Make a new concept based on the properties and drawing of another
-
-
-
- Parameters:
-
-
-
-
-
-
-
- -
-
- name
-
- :
-
- (string)
-
- the name of the concept that you want as the base
-
-
-
-
-
-
-
- -
-
- new_name
-
- :
-
- (string)
-
- the name that you want the new concept to have
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Usage:
- -- Making a new concept from another, see module usage
-local custom_button = Gui.clone_concept('Button','CustomButton')
-
-
@@ -3214,11 +3254,11 @@ button:change_name('Not Button')
- name
+ concept
:
- (string)
+ (string, number or table)
the name of the concept that you want to draw
@@ -3940,7 +3980,7 @@ button:change_name('Not Button')
Usage:
-- Clones the base Button concept to make a alternative button
local custom_button =
-Gui.get_concept('Button'):clone('CustomButton')
+Gui.get_concept(Gui.concepts.button):clone()
@@ -4012,14 +4052,14 @@ Gui.get_concept('Button')
- Used internally to save concept names to the core gui module
+ Used to save the concept to the main gui module to allow access from other files
@@ -4033,7 +4073,7 @@ Gui.get_concept('Button')
- new_name
+ save_name
:
@@ -4041,7 +4081,6 @@ Gui.get_concept('Button')
the new name of the concept
- (default: self.name)
@@ -4058,10 +4097,71 @@ Gui.get_concept('Button')
Usage:
- -- Internal Saving
--- this is never needed to be done, internal use only!
-local button = Gui.get_concept('Button')
-button:change_name('Not Button')
+ -- Save a concept to allow access in another file
+button:save_as('button')
+ -- Access concept after being saved
+Gui.concepts.button
+Gui.get_concept('button')
+
+
+
+
+
+
+ #
+ Prototype:debug(name)
+
+
+
+
+
+ Sets a debug name that can be used with error handlers
+
+
+
+ Parameters:
+
+
+
+
+
+
+
+ -
+
+ name
+
+ :
+
+ (string)
+
+ the name that will be used in error messages
+
+
+
+
+
+
+
+
+
+ Returns:
+
+ -
+ (self)
+ to allow chaining
+
+
+
+
+
+
+
+
+
+ Usage:
+ -- Set the debug name
+unsaved_concept:debug('Example button')
@@ -4325,7 +4425,7 @@ Gui.get_concept('CustomButton')
#
- Prototype:new_property(property_name, default[, setter_callback])
+ Prototype:new_property(property_name[, setter_callback][, default])
@@ -4361,14 +4461,15 @@ Gui.get_concept('CustomButton')
- default
+ setter_callback
:
- (any)
+ (function)
- the default value for this property, although not strictly required is is strongly recomented
+ this function is called when set is called, if not provided then key in concept.properties is updated to new value
+ (optional)
@@ -4377,13 +4478,13 @@ Gui.get_concept('CustomButton')
- setter_callback
+ default
:
- (function)
+ (any)
- this function is called when set is called, if not provided then key in concept.properties is updated to new value
+ use this as the default value, will call the setter callback if defined
(optional)
@@ -4552,12 +4653,12 @@ Gui.get_concept('CustomButton')
local button =
Gui.get_concept('Button')
:define_draw(function(properties,parent,element)
- -- Note that element might be nil if this is the first draw function
- -- for this example we assume button was cloned from Prototype and so has no other draw functions defined
- -- this means that there is no element yet and what we return will be the first time the element is returned
- -- although not shown here you also can recive any extra arguments here from the call to draw
+ -- Properties will include all the information that you need to draw the element
+ -- Parent is the parent element for the element, this may have been altered by previous draw functions
+ -- Element is the current element being made, this may have a nil value, if it is nil then this is the first draw function
+ -- You can also pass any other arguments that you want to this function from the draw call
if properties.type == 'button' then
- element = parent.draw{
+ element = parent.add{
type = properties.type,
name = properties.name,
caption = properties.caption,
@@ -4565,7 +4666,7 @@ Gui.get_concept('Button')
}
else
- element = parent.draw{
+ element = parent.add{
type = properties.type,
name = properties.name,
sprite = properties.sprite,
@@ -4574,9 +4675,9 @@ Gui.get_concept('Button')
end
- -- We must return the element or what we want to be seen as the instance, this is so other draw functions have access to it
- -- for example if our custom button defined a draw function to change the font color to red
- return element
+ -- If you return element or parent then their values will be updated for the next draw function in the chain
+ -- It is best practice to always return the values if you have made any changes to them
+ return element, parent
end)
@@ -5510,7 +5611,7 @@ Gui.get_concept('CustomButton')
generated by LDoc
diff --git a/docs/core/Permissions-Groups.html b/docs/core/Permissions-Groups.html
index dca3001a..81649b1b 100644
--- a/docs/core/Permissions-Groups.html
+++ b/docs/core/Permissions-Groups.html
@@ -1433,7 +1433,7 @@
generated by LDoc
diff --git a/docs/core/Roles.html b/docs/core/Roles.html
index 8e43f424..7edbaf8f 100644
--- a/docs/core/Roles.html
+++ b/docs/core/Roles.html
@@ -3153,7 +3153,7 @@
generated by LDoc
diff --git a/docs/core/Store.html b/docs/core/Store.html
index 43bad538..f5a25b75 100644
--- a/docs/core/Store.html
+++ b/docs/core/Store.html
@@ -1146,7 +1146,7 @@ Store.register(team_scores,function(value,key)
generated by LDoc
diff --git a/docs/core/Sudo.html b/docs/core/Sudo.html
index d62ac99e..2b9a66e1 100644
--- a/docs/core/Sudo.html
+++ b/docs/core/Sudo.html
@@ -545,7 +545,7 @@
generated by LDoc
diff --git a/docs/core/Toolbar.html b/docs/core/Toolbar.html
index 5cbcc8c2..0bcff3f0 100644
--- a/docs/core/Toolbar.html
+++ b/docs/core/Toolbar.html
@@ -264,6 +264,9 @@
mod-gui
+
+ Gui.concept.button
+
@@ -495,6 +498,31 @@
+
+
+
+
+
+
+
+
+
+
+ #
+ Gui.concept.button
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -703,7 +731,7 @@
Usage:
-- Adding a basic button to the toolbar
local new_button =
-Gui.clone_concept('button','new-button')
+Gui.new_concept('button')
:set_caption('Click Me')
:on_click(function(event)
event.player.print('You Clicked Me!!')
@@ -875,7 +903,7 @@ Toolbar.add_button_concept(new_button)
Usage:
-- Adding a basic button to the toolbar, note no need to call Toolbar.add_button_concept
-Gui.clone_concept('toolbar-button','new-button')
+Gui.new_concept('toolbar-button')
:set_caption('Click Me')
:on_click(function(event)
event.player.print('You Clicked Me!!')
@@ -936,7 +964,7 @@ Toolbar.add_button_concept(new_button)
Usage:
-- Adding a basic frame to the frame area
local new_frame =
-Gui.clone_concept('frame','new_frame')
+Gui.new_concept('frame')
:set_title('Test')
Toolbar.add_frame_concept(new_frame)
@@ -1153,7 +1181,7 @@ Toolbar.add_frame_concept(new_frame)
Usage:
-- Adding a basic player list
local player_list =
-Gui.clone_concept('toolbar-frame','player_list')
+Gui.new_concept('toolbar-frame')
:set_permission_alias('player_list')
:set_caption('Player List')
:toggle_with_click()
@@ -1630,7 +1658,7 @@ Gui.clone_concept('toolbar-frame',LDoc
diff --git a/docs/guis/Player-List.html b/docs/guis/Player-List.html
index a54cf7a5..51a5f3f6 100644
--- a/docs/guis/Player-List.html
+++ b/docs/guis/Player-List.html
@@ -627,7 +627,7 @@
generated by LDoc
diff --git a/docs/guis/Rocket-Info.html b/docs/guis/Rocket-Info.html
index ac686677..5411b5a9 100644
--- a/docs/guis/Rocket-Info.html
+++ b/docs/guis/Rocket-Info.html
@@ -630,7 +630,7 @@
generated by LDoc
diff --git a/docs/guis/Science-Info.html b/docs/guis/Science-Info.html
index b0c720f8..84d8d3c0 100644
--- a/docs/guis/Science-Info.html
+++ b/docs/guis/Science-Info.html
@@ -450,7 +450,7 @@
generated by LDoc
diff --git a/docs/guis/Task-List.html b/docs/guis/Task-List.html
index 80723b00..576dcf2c 100644
--- a/docs/guis/Task-List.html
+++ b/docs/guis/Task-List.html
@@ -633,7 +633,7 @@
generated by LDoc
diff --git a/docs/guis/Warps-List.html b/docs/guis/Warps-List.html
index 3a5ec1ac..a0ee7c7d 100644
--- a/docs/guis/Warps-List.html
+++ b/docs/guis/Warps-List.html
@@ -838,7 +838,7 @@
generated by LDoc
diff --git a/docs/index.html b/docs/index.html
index f233e4a5..2e6ac538 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -514,7 +514,7 @@ see ./expcore/commands.lua for more details
generated by LDoc
diff --git a/docs/modules/control.html b/docs/modules/control.html
index 7295da0f..b3ca5cec 100644
--- a/docs/modules/control.html
+++ b/docs/modules/control.html
@@ -352,7 +352,7 @@
generated by LDoc
diff --git a/docs/modules/utils.alien_evolution_progress.html b/docs/modules/utils.alien_evolution_progress.html
index 2fa36dc8..974e41a8 100644
--- a/docs/modules/utils.alien_evolution_progress.html
+++ b/docs/modules/utils.alien_evolution_progress.html
@@ -420,7 +420,7 @@ fraction will decide a chance to spawn. 1 alien for 2 spawner's will have 50% on
generated by LDoc
diff --git a/docs/modules/utils.core.html b/docs/modules/utils.core.html
index ef39ec65..b5e42e86 100644
--- a/docs/modules/utils.core.html
+++ b/docs/modules/utils.core.html
@@ -1165,7 +1165,7 @@
generated by LDoc
diff --git a/docs/modules/utils.debug.html b/docs/modules/utils.debug.html
index 5304675f..e41f95c7 100644
--- a/docs/modules/utils.debug.html
+++ b/docs/modules/utils.debug.html
@@ -655,7 +655,7 @@
generated by LDoc
diff --git a/docs/modules/utils.dump_env.html b/docs/modules/utils.dump_env.html
index 598d76da..1de42342 100644
--- a/docs/modules/utils.dump_env.html
+++ b/docs/modules/utils.dump_env.html
@@ -324,7 +324,7 @@
generated by LDoc
diff --git a/docs/modules/utils.event.html b/docs/modules/utils.event.html
index fc1ddfad..fd2fb48b 100644
--- a/docs/modules/utils.event.html
+++ b/docs/modules/utils.event.html
@@ -1293,7 +1293,7 @@
generated by LDoc
diff --git a/docs/modules/utils.event_core.html b/docs/modules/utils.event_core.html
index c5782040..c23f367c 100644
--- a/docs/modules/utils.event_core.html
+++ b/docs/modules/utils.event_core.html
@@ -435,7 +435,7 @@
generated by LDoc
diff --git a/docs/modules/utils.math.html b/docs/modules/utils.math.html
index fada2288..38b0f253 100644
--- a/docs/modules/utils.math.html
+++ b/docs/modules/utils.math.html
@@ -354,7 +354,7 @@
generated by LDoc
diff --git a/docs/modules/utils.recipe_locker.html b/docs/modules/utils.recipe_locker.html
index 8f6f7dbd..2900f85f 100644
--- a/docs/modules/utils.recipe_locker.html
+++ b/docs/modules/utils.recipe_locker.html
@@ -442,7 +442,7 @@
generated by LDoc
diff --git a/docs/modules/utils.state_machine.html b/docs/modules/utils.state_machine.html
index 17e16970..28ec9697 100644
--- a/docs/modules/utils.state_machine.html
+++ b/docs/modules/utils.state_machine.html
@@ -753,7 +753,7 @@
generated by LDoc
diff --git a/docs/modules/utils.table.html b/docs/modules/utils.table.html
index 6c672172..5be2d399 100644
--- a/docs/modules/utils.table.html
+++ b/docs/modules/utils.table.html
@@ -1419,7 +1419,7 @@
generated by LDoc
diff --git a/docs/modules/utils.task.html b/docs/modules/utils.task.html
index e84592f2..35fb4414 100644
--- a/docs/modules/utils.task.html
+++ b/docs/modules/utils.task.html
@@ -652,7 +652,7 @@
generated by LDoc
diff --git a/docs/modules/utils.timestamp.html b/docs/modules/utils.timestamp.html
index 0d1c8dd5..f85b4c01 100644
--- a/docs/modules/utils.timestamp.html
+++ b/docs/modules/utils.timestamp.html
@@ -443,7 +443,7 @@
generated by LDoc
diff --git a/docs/topics/license.html b/docs/topics/license.html
index dd724347..7d2d1e66 100644
--- a/docs/topics/license.html
+++ b/docs/topics/license.html
@@ -790,7 +790,7 @@ Public License instead of this License. But first, please read
generated by LDoc
diff --git a/docs/topics/readme.md.html b/docs/topics/readme.md.html
index 08252a53..6257b341 100644
--- a/docs/topics/readme.md.html
+++ b/docs/topics/readme.md.html
@@ -240,7 +240,7 @@
5) Once you have made any config changes that you wish to make open factorio, select play, then start scenario (or host scenario from within multiplayer tab), and select the scenario which will be called `scenario-master` if you have downloaded the latest stable release and have not changed the folder name.
6) The scenario will now load all the selected modules and start the map, any errors or exceptions raised in the scenario should not cause a game/server crash so if any features don't work as expected then it may be returning an error in the log, please report these errors to [the issues page](issues).
## Contributing
-
All are welcome to make pull requests and issues for this scenario, if you are in any doubt please ask someone in our [discord]. If you do not know lua and don't feel like learning you can always make a [feature request]. Please keep in mind while making code changes:
+
All are welcome to make pull requests and issues for this scenario, if you are in any doubt please ask someone in our [discord]. If you do not know lua and don't feel like learning you can always make a [feature request]. All our docs can be found [here][docs]. Please keep in mind while making code changes:
* New features should have the branch names: `feature/feature-name`
* New features are merged into `dev` after it has been completed.
* After a number of features have been added a release branch is made: `release/X.Y.0`; this branch should have no new features and only bug fixes or localization.
@@ -297,7 +297,8 @@
[f0.14]: https://wiki.factorio.com/Version_history/0.14.0
## License
The Explosive Gaming codebase is licensed under the [GNU General Public License v3.0](LICENSE)
-
[issues]: https://github.com/explosivegaming/scenario/issues/new/choose
+
[docs]: https://explosivegaming.github.io/scenario/
+[issues]: https://github.com/explosivegaming/scenario/issues/new/choose
[website]: https://explosivegaming.nl
[discord]: https://discord.explosivegaming.nl
[wiki]: https://wiki.explosivegaming.nl
@@ -333,7 +334,7 @@
generated by LDoc
diff --git a/expcore/common.lua b/expcore/common.lua
index 81192344..1d9ebef0 100644
--- a/expcore/common.lua
+++ b/expcore/common.lua
@@ -640,7 +640,7 @@ function Common.array_insert(tbl,start_index,values)
local starting_length = #tbl
local adding_length = #values
local move_to = start_index+adding_length+1
- for offset = 0, starting_length-start_index do
+ for offset = starting_length-start_index, 0, -1 do
tbl[move_to+offset] = tbl[starting_length+offset]
end
start_index = start_index-1
diff --git a/expcore/gui.lua b/expcore/gui.lua
index 50bcce3b..18584b47 100644
--- a/expcore/gui.lua
+++ b/expcore/gui.lua
@@ -4,22 +4,24 @@
@usage-- Making the base button concept
local button =
-Gui.new_concept('Button')
-:new_event('on_click',defines.events.on_gui_click)
-:new_property('tooltip')
-:new_property('caption',nil,function(properties,value)
+Gui.new_concept() -- Make a new empty concept
+:save_as('button') -- Save it as Gui.concepts.button so it can be used in other files
+:new_event('on_click',defines.events.on_gui_click) -- Add an on click event for this concept
+:new_property('tooltip') -- Add a property with the default setter method called tooltip
+:new_property('caption',function(properties,value) -- Add a property with a custom setter method called caption
properties.caption = value
properties.sprite = nil
properties.type = 'button'
end)
-:new_property('sprite',nil,function(properties,value)
+:new_property('sprite',function(properties,value) -- Add a property with a custom setter method called sprite
properties.image = value
properties.caption = nil
properties.type = 'sprite-button'
end)
-:define_draw(function(properties,parent,element)
- -- Note that element might be nil if this is the first draw function
- -- in this case button is a new concept so we know this is the first function and element is nil
+:define_draw(function(properties,parent,element) -- Add the draw function to create the element from the concept
+ -- Properties will include all the information that you need to draw the element
+ -- Parent is the parent element for the element, this may have been altered by previous draw functions
+ -- Element is the current element being made, this may have a nil value, if it is nil then this is the first draw function
if properties.type == 'button' then
element = parent.add{
type = properties.type,
@@ -38,26 +40,27 @@ end)
end
- -- We must return the element or what we want to be seen as the instance, this is so other draw functions have access to it
- -- for example if our custom button defined a draw function to change the font color to red
- return element
+ -- If you return element or parent then their values will be updated for the next draw function in the chain
+ -- It is best practice to always return the values if you have made any changes to them
+ return element, parent
end)
-@usage-- Makeing a alternative button based on the first
+@usage-- Making a new button which has a custom style
local custom_button =
-button:clone('CustomButton')
-:new_event('on_admin_clicked',defines.events.on_gui_click,function(event)
- return event.player.admin -- only raise custom event when an admin clicks the button
-end)
-:set_caption('Custom Button')
-:set_tooltip('Only admins can press this button')
-:on_click(function(event)
+Gui.new_concept('button') -- We can use button here since we used save as on the concept
+-- button:clone() -- If we had not used save as then this is how we would use it as a base
+:set_caption('Custom Button') -- Set the caption of the concept, this is possible as we added caption as a property
+:set_tooltip('Only admins can press this button') -- Set the tooltip of the concept, this is possible as we added tooltip as a property
+:on_click(function(event) -- Register a handler to the click event we added with new event
if not event.player.admin then
event.player.print('You must be admin to use this button')
end
end)
-:on_admin_clicked(function(event)
- -- Yes i know this can just be an if else but its an example
+:new_event('on_admin_clicked',defines.events.on_gui_click,function(event) -- Add a click event which has a filter function
+ return event.player.admin -- Check if the player is admin
+end)
+:on_admin_clicked(function(event) -- Register a handler to the admin click event we have just created
+ -- The admin click event is only an example, because of how sinmple the filter is we could have just used an if else statement
game.print(event.player.name..' pressed my admin button')
end)
@@ -65,23 +68,4 @@ end)
custom_button:draw(game.player.gui.left)
]]
-local Gui = require 'expcore.gui.core'
-
-Gui.require_concept('frame')
-Gui.require_concept('flow')
-Gui.require_concept('table')
-Gui.require_concept('label')
-Gui.require_concept('line')
-Gui.require_concept('scroll')
-Gui.require_concept('empty')
-
-Gui.require_concept('button')
-Gui.require_concept('checkbox')
-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
\ No newline at end of file
+return require 'expcore.gui.core'
\ No newline at end of file
diff --git a/expcore/gui/concepts/button.lua b/expcore/gui/concepts/button.lua
index a23fd3e4..604e30c2 100644
--- a/expcore/gui/concepts/button.lua
+++ b/expcore/gui/concepts/button.lua
@@ -7,30 +7,39 @@ local Gui = require 'expcore.gui.core'
--[[-- Clickable elements that fire on_gui_click when clicked.
@element button
+
@param on_click fired when the player clicks the button
@param on_left_click fired when the player clicks with the left mouse button
@param on_left_click fired when the player clicks with the right mouse button
+
@tparam ?string|Concepts.LocalisedString caption the message that is shown on the button
@tparam ?string|Concepts.LocalisedString tooltip the tooltip that shows when a player hovers over the button
@tparam SpritePath sprite upto three sprites in the order: default, hovered, clicked
+
@usage-- Making a basic button
local basic_button =
-Gui.clone_concept('button','basic_button')
+Gui.new_concept('button')
:set_caption('Basic Button')
:set_tooltip('Basic button')
:on_click(function(event)
event.player.print('You pressed basic button!')
end)
+
@usage-- Making a sprite button
local sprite_button =
-Gui.clone_concept('button','sprite_button')
+Gui.new_concept('button')
:set_sprite('utility/warning_icon')
:set_tooltip('Sprite button')
:on_click(function(event)
event.player.print('You pressed sprite button!')
end)
+
]]
-Gui.new_concept('button')
+
+Gui.new_concept()
+:save_as('button')
+
+-- Events
:new_event('on_click',defines.events.on_gui_click)
:new_event('on_left_click',defines.events.on_gui_click,function(event)
return event.mouse_button == defines.mouse_button_type.left
@@ -38,19 +47,25 @@ end)
:new_event('on_right_click',defines.events.on_gui_click,function(event)
return event.mouse_button == defines.mouse_button_type.right
end)
+
+-- Properties
:new_property('tooltip')
-:new_property('caption',nil,function(properties,value)
+:new_property('caption',function(properties,value)
properties.caption = value
properties.type = 'button'
end)
-:new_property('sprite',nil,function(properties,value,hovered_sprite,clicked_sprite)
+:new_property('sprite',function(properties,value,hovered_sprite,clicked_sprite)
properties.sprite = value
properties.hovered_sprite = hovered_sprite
properties.clicked_sprite = clicked_sprite
properties.type = 'sprite-button'
end)
+
+-- Draw
:define_draw(function(properties,parent,element)
+ -- Check if it should be a sprite button
if properties.type == 'sprite-button' then
+ -- Draw a sprite button
element = parent.add{
name = properties.name,
type = 'sprite-button',
@@ -61,6 +76,7 @@ end)
}
else
+ -- Draw a button
element = parent.add{
name = properties.name,
type = 'button',
diff --git a/expcore/gui/concepts/checkbox.lua b/expcore/gui/concepts/checkbox.lua
index cf24f231..364d9624 100644
--- a/expcore/gui/concepts/checkbox.lua
+++ b/expcore/gui/concepts/checkbox.lua
@@ -7,30 +7,43 @@ local Gui = require 'expcore.gui.core'
--[[-- Clickable elements with a cross in the middle that can be turned off or on.
@element checkbox
+
@param on_state_changed fired when the state of the element is changed
+
@tparam ?string|Concepts.LocalisedString caption the message that is shown next to the checkbox
@tparam ?string|Concepts.LocalisedString tooltip the tooltip that shows when a player hovers over the checkbox
@tparam ?boolean|function default the default state of this checkbox, or a function which returns the default state
@tparam boolean use_radio setting to true will use radio buttons rather than checkboxs
+
@usage-- Making a basic checkbox
local basic_checkbox =
-Gui.clone_concept('checkbox','basic_checkbox')
+Gui.new_concept('checkbox')
:set_caption('Basic Checkbox')
:set_tooltip('Basic checkbox')
:on_state_changed(function(event)
event.player.print('Basic checkbox is now: '..tostring(event.element.state))
end)
+
]]
-Gui.new_concept('checkbox')
+
+Gui.new_concept()
+:save_as('checkbox')
+
+-- Events
:new_event('on_state_changed',defines.events.on_gui_checked_state_changed)
+
+-- Properties
:new_property('tooltip')
:new_property('caption')
-:new_property('default',false)
-:new_property('use_radio',false)
+:new_property('default',nil,false)
+:new_property('use_radio',nil,false)
+
+-- Draw
:define_draw(function(properties,parent,element)
local default = properties.default
local state = type(default) == 'boolean' and default
+ -- Draw a checkbox
element = parent.add{
name = properties.name,
type = properties.use_radio and 'radiobutton' or 'checkbox',
@@ -39,6 +52,7 @@ Gui.new_concept('checkbox')
state = state
}
+ -- Set the default state
default = Gui.resolve_property(default,element)
if default and default ~= state then
element.state = default
diff --git a/expcore/gui/concepts/dropdown.lua b/expcore/gui/concepts/dropdown.lua
index 646fdd5e..40e10afc 100644
--- a/expcore/gui/concepts/dropdown.lua
+++ b/expcore/gui/concepts/dropdown.lua
@@ -8,22 +8,26 @@ local array_insert = ext_require('expcore.common','array_insert')
--[[-- A drop down list of other elements.
@element dropdown
+
@param on_selection_changed fired when the selected value is changed
+
@tparam ?string|Concepts.LocalisedString|function default 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
-@usage-- Making a basic dropdown
+
+ @usage-- Making a basic dropdown
local static_dropdown =
-Gui.clone_concept('dropdown','static_dropdown')
+Gui.new_concept('dropdown')
:set_static_items{'Option 1','Option 2','Option 3'}
:on_selection_changed(function(event)
local value = Gui.get_dropdown_value(event.element)
event.player.print('Static dropdown is now: '..value)
end)
+
@usage-- Making a dropdown with dynamic items, example is name of online players
local dynamic_dropdown =
-Gui.clone_concept('dropdown','dynamic_dropdown')
+Gui.new_concept('dropdown')
:set_dynamic_items(function(element)
local items = {}
for _,player in pairs(game.connected_players) do
@@ -35,51 +39,66 @@ end)
local value = Gui.get_dropdown_value(event.element)
event.player.print('Dynamic dropdown is now: '..value)
end)
+
]]
-Gui.new_concept('dropdown')
+
+Gui.new_concept()
+:save_as('dropdown')
+
+-- Events
:new_event('on_selection_changed',defines.events.on_gui_selection_state_changed)
+
+-- Properties
:new_property('default')
-:new_property('use_list_box',false)
-:new_property('static_items',nil,function(properties,value,start_index)
+:new_property('use_list_box',nil,false)
+:new_property('static_items',function(properties,value,start_index)
+ -- Clear all items if value is nil
if not value then
properties.items = {}
end
+ -- Convert value to a table
if type(value) ~= 'table' then
value = {value}
end
+ -- If there are no items then set and return
local items = properties.items
if not items then
properties.items = value
return
end
+ -- Otherwise insert into the array
array_insert(items,start_index,value)
end)
-:new_property('dynamic_items',nil,function(properties,value)
+:new_property('dynamic_items',function(properties,value)
+ -- Check that a function value was given
if type(value) ~= 'function' then
error('Dynamic items must be a function')
end
+ -- If no dynamic items then set and return
local items = properties.dynamic_items
if not items then
properties.dynamic_items = {value}
return
end
+ -- Otherwise append to the end
items[#items+1] = value
end)
-:define_draw(function(properties,parent,element,new_items)
- local items = new_items or {}
- array_insert(items,1,properties.items or {})
+-- Draw
+:define_draw(function(properties,parent,element)
+ -- Draw a dropdown
element = parent.add{
name = properties.name,
type = properties.use_list_box and 'list-box' or 'drop-down',
- items = items
+ items = properties.items
}
+ -- If there are dynamic items then add them
if properties.dynamic_items then
for _,callback in pairs(properties.dynamic_items) do
local dynamic_items, start_index = callback(element)
@@ -87,6 +106,7 @@ end)
end
end
+ -- If there is a default, select it
local default = Gui.resolve_property(properties.default,element)
if default then
Gui.set_dropdown_value(element,default)
diff --git a/expcore/gui/concepts/elem_button.lua b/expcore/gui/concepts/elem_button.lua
index 5e711369..4318b181 100644
--- a/expcore/gui/concepts/elem_button.lua
+++ b/expcore/gui/concepts/elem_button.lua
@@ -7,27 +7,41 @@ local Gui = require 'expcore.gui.core'
--[[-- A button that lets the player pick one of an: item, entity, tile, or signal similar to the filter-select window.
@element elem_button
+
@param on_selection_changed fired when the selected value is changed
+
@tparam ?string|Concepts.SignalID|function default 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','basic_elembutton')
+Gui.new_concept('elem_button')
:on_selection_changed(function(event)
event.player.print('Basic elem button is now: '..event.element.elem_value)
end)
+
]]
-Gui.new_concept('elem_button')
+
+Gui.new_concept()
+:save_as('elem_button')
+
+-- Events
:new_event('on_selection_changed',defines.events.on_gui_elem_changed)
+
+-- Properties
:new_property('default')
-:new_property('elem_type','item')
+:new_property('elem_type',nil,'item')
+
+-- Draw
:define_draw(function(properties,parent,element)
+ -- Draw a chose elem button
element = parent.add{
name = properties.name,
type = 'choose-elem-button',
elem_type = properties.elem_type
}
+ -- If there is a default, select it
local default = Gui.resolve_property(properties.default,element)
if default then
element.elem_value = default
diff --git a/expcore/gui/concepts/empty.lua b/expcore/gui/concepts/empty.lua
index 61cda963..46c0233a 100644
--- a/expcore/gui/concepts/empty.lua
+++ b/expcore/gui/concepts/empty.lua
@@ -7,15 +7,25 @@ local Gui = require 'expcore.gui.core'
--[[-- A empty widget that just exists. The root GUI element screen is an empty-widget.
@element empty
+
@tparam string style the style that the element will have
+
@usage-- Making a draggable space styled widget
local draggable_space =
-Gui.clone_concept('empty','draggable_space')
-:set_style('draggable_space')
-]]
Gui.new_concept('empty')
+:set_style('draggable_space')
+
+]]
+
+Gui.new_concept()
+:save_as('empty')
+
+-- Properties
:new_property('style')
+
+-- Draw
:define_draw(function(properties,parent,element)
+ -- Draw an empty widget
element = parent.add{
name = properties.name,
type = 'empty-widget',
diff --git a/expcore/gui/concepts/flow.lua b/expcore/gui/concepts/flow.lua
index e8ecdce2..b4af20d4 100644
--- a/expcore/gui/concepts/flow.lua
+++ b/expcore/gui/concepts/flow.lua
@@ -7,20 +7,30 @@ local Gui = require 'expcore.gui.core'
--[[-- Invisible containers that lay out children either horizontally or vertically. The root GUI elements (top, left and center; see LuaGui) are flows.
@element flow
+
@tparam string direction the direction that children will be added
+
@usage-- Making a basic flow, contains a label with hello world
local basic_flow =
-Gui.clone_concept('flow','basic_flow')
+Gui.new_concept('flow')
:define_draw(function(properties,parent,element)
element.add{
type = 'label',
caption = 'Hello, World!'
}
end)
+
]]
-Gui.new_concept('flow')
+
+Gui.new_concept()
+:save_as('flow')
+
+-- Properties
:new_property('direction')
+
+-- Draw
:define_draw(function(properties,parent,element)
+ -- Draw a flow
element = parent.add{
name = properties.name,
type = 'flow',
diff --git a/expcore/gui/concepts/frame.lua b/expcore/gui/concepts/frame.lua
index e3598778..6a216353 100644
--- a/expcore/gui/concepts/frame.lua
+++ b/expcore/gui/concepts/frame.lua
@@ -7,11 +7,13 @@ local Gui = require 'expcore.gui.core'
--[[-- Grey semi-transparent boxes that contain other elements. They have a caption, and, just like flows, they lay out children either horizontally or vertically.
@element frame
+
@tparam ?string|Concepts.LocalisedString title the title that will show in the frame
@tparam string direction the direction that children will be added
+
@usage-- Making a basic frame, contains a label with hello world
local basic_frame =
-Gui.clone_concept('frame','basic_frame')
+Gui.new_concept('frame')
:set_title('Basic Frame')
:define_draw(function(properties,parent,element)
element.add{
@@ -19,11 +21,19 @@ Gui.clone_concept('frame','basic_frame')
caption = 'Hello, World!'
}
end)
+
]]
-Gui.new_concept('frame')
+
+Gui.new_concept()
+:save_as('frame')
+
+-- Properties
:new_property('title')
:new_property('direction')
+
+-- Draw
:define_draw(function(properties,parent,element)
+ -- Draw a frame
element = parent.add{
name = properties.name,
type = 'frame',
diff --git a/expcore/gui/concepts/label.lua b/expcore/gui/concepts/label.lua
index 692192c5..1cf70eac 100644
--- a/expcore/gui/concepts/label.lua
+++ b/expcore/gui/concepts/label.lua
@@ -7,17 +7,28 @@ local Gui = require 'expcore.gui.core'
--[[-- A piece of text.
@element frame
+
@tparam ?string|Concepts.LocalisedString caption the caption that will show in the label
@tparam ?string|Concepts.LocalisedString description the description that will show on the label
+@tparam defines.rich_text_setting rich_text how this element handles rich text
+
@usage-- Making a basic label
local basic_label =
-Gui.clone_concept('label','basic_label')
-:set_caption('Hello, World!')
-]]
Gui.new_concept('label')
+:set_caption('Hello, World!')
+
+]]
+Gui.new_concept()
+:save_as('label')
+
+-- Properties
:new_property('caption')
:new_property('description')
+:new_property('rich_text')
+
+-- Draw
:define_draw(function(properties,parent,element)
+ -- Draw a label
element = parent.add{
name = properties.name,
type = 'label',
@@ -25,5 +36,11 @@ Gui.new_concept('label')
description = properties.description
}
+ -- Change rich text setting if present
+ local rich_text = properties.rich_text
+ if rich_text then
+ element.style.rich_text_setting = rich_text
+ end
+
return element
end)
\ No newline at end of file
diff --git a/expcore/gui/concepts/line.lua b/expcore/gui/concepts/line.lua
index 2ff4544b..28f41cc7 100644
--- a/expcore/gui/concepts/line.lua
+++ b/expcore/gui/concepts/line.lua
@@ -7,14 +7,24 @@ local Gui = require 'expcore.gui.core'
--[[-- A vertical or horizontal line.
@element line
+
@tparam string direction the direction that children will be added
+
@usage-- Making a basic frame, contains a label with hello world
local basic_line =
-Gui.clone_concept('line','basic_line')
-]]
Gui.new_concept('line')
+
+]]
+
+Gui.new_concept()
+:save_as('line')
+
+-- Properties
:new_property('direction')
+
+-- Draw
:define_draw(function(properties,parent,element)
+ -- Draw a line
element = parent.add{
name = properties.name,
type = 'line',
diff --git a/expcore/gui/concepts/progress_bar.lua b/expcore/gui/concepts/progress_bar.lua
index 384c90cb..4bcb0b8a 100644
--- a/expcore/gui/concepts/progress_bar.lua
+++ b/expcore/gui/concepts/progress_bar.lua
@@ -7,14 +7,17 @@ local Gui = require 'expcore.gui.core'
--[[-- Indicate progress by displaying a partially filled bar.
@element progress_bar
+
@param on_completion fired when increment reaches the maxium value set by set_maximum
+
@tparam ?string|Concepts.LocalisedString tooltip the tooltip that will show for this element
@tparam number maximum the maxium amount an instance can be increased, default 100
@tparam boolean delay_completion when true the progress will be completed untill after the maximum rather than at the maximum
@tparam boolean inverted although this will NOT effect how you use the functions it will make the element start full and reduce as you call increase, note issues with 0 detections
+
@usage-- Making a basic progress bar, will increase when pressed then will reset when full
local basic_progress_bar =
-Gui.clone_concept('progress_bar','basic_progress_bar')
+Gui.new_concept('progress_bar')
:set_tooltip('Basic progress bar')
:set_maximum(5)
:new_event('on_click',defines.events.on_gui_click)
@@ -25,15 +28,25 @@ end)
:on_completion(function(event)
event.concept:reset(event.element)
end)
+
]]
+
local progress_bar =
-Gui.new_concept('progress_bar')
+Gui.new_concept()
+:save_as('progress_bar')
+
+-- Events
:new_event('on_completion')
+
+-- Properties
:new_property('tooltip')
-:new_property('maximum',100)
-:new_property('delay_completion',false)
-:new_property('inverted',false)
+:new_property('maximum',nil,100)
+:new_property('delay_completion',nil,false)
+:new_property('inverted',nil,false)
+
+-- Draw
:define_draw(function(properties,parent,element)
+ -- Draw a progress bar
element = parent.add{
name = properties.name,
tooltip = properties.tooltip,
diff --git a/expcore/gui/concepts/scroll.lua b/expcore/gui/concepts/scroll.lua
index 5a6cb8f2..034766f7 100644
--- a/expcore/gui/concepts/scroll.lua
+++ b/expcore/gui/concepts/scroll.lua
@@ -7,11 +7,13 @@ local Gui = require 'expcore.gui.core'
--[[-- Similar to a flow but includes the ability to show and use scroll bars.
@element scroll
+
@tparam string horizontal_scroll the horizontal scroll policy for this scroll pane
@tparam string vertical_scroll the vertical scroll policy for this scroll pane
+
@usage-- Making a basic flow, contains a label with hello world
local basic_scroll =
-Gui.clone_concept('scroll','basic_scroll')
+Gui.new_concept('scroll')
:define_draw(function(properties,parent,element)
element.style.hieght = 50
for i = 1,10 do
@@ -21,11 +23,19 @@ Gui.clone_concept('scroll','basic_scroll')
}
end
end)
+
]]
-Gui.new_concept('scroll')
+
+Gui.new_concept()
+:save_as('scroll')
+
+-- Properties
:new_property('horizontal_scroll')
:new_property('vertical_scroll')
+
+-- Draw
:define_draw(function(properties,parent,element)
+ -- Draw a scroll pane
element = parent.add{
name = properties.name,
type = 'scroll-pane',
diff --git a/expcore/gui/concepts/slider.lua b/expcore/gui/concepts/slider.lua
index 51ff9153..703fe102 100644
--- a/expcore/gui/concepts/slider.lua
+++ b/expcore/gui/concepts/slider.lua
@@ -7,34 +7,45 @@ local Gui = require 'expcore.gui.core'
--[[-- A number picker.
@element slider
+
@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, 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 =
-Gui.clone_concept('slider','basic_slider')
+Gui.new_concept('slider')
:set_range(1,10)
:on_value_changed(function(event)
event.player.print('Basic slider is now: '..event.element.slider_value)
end)
+
@usage-- Making a discrete_slider
local discrete_slider =
-Gui.clone_concept('slider','discrete_slider')
+Gui.new_concept('slider')
:set_range(1,10)
:set_value_step(1)
:set_discrete_slider(true)
:on_value_changed(function(event)
event.player.print('Interval slider is now: '..event.element.slider_value)
end)
+
]]
-Gui.new_concept('slider')
+
+Gui.new_concept()
+:save_as('slider')
+
+-- Events
:new_event('on_value_changed',defines.events.on_gui_value_changed)
+
+-- Properties
:new_property('value_step')
:new_property('default')
-:new_property('discrete_slider',false)
-:new_property('range',nil,function(properties,minimum,maximum)
+:new_property('discrete_slider',nil,false)
+:new_property('range',function(properties,minimum,maximum)
if type(minimum) == 'function' then
properties.range = minimum
else
@@ -42,11 +53,14 @@ Gui.new_concept('slider')
properties.maximum = maximum
end
end)
+
+-- Draw
:define_draw(function(properties,parent,element)
local default = properties.default
local value = type(default) == 'number' and default
local value_step = properties.value_step
+ -- Draw a slider
element = parent.add{
name = properties.name,
type = 'slider',
@@ -59,6 +73,7 @@ end)
value = value
}
+ -- Find the range for the slider and set it
local min, max = Gui.resolve_property(properties.range,element)
if min or max then
min = min or element.get_slider_minimum()
@@ -66,6 +81,7 @@ end)
element.set_slider_minimum_maximum(min,max)
end
+ -- If there is a default, select it
default = Gui.resolve_property(default,element)
if default and default ~= value then
element.slider_value = default
diff --git a/expcore/gui/concepts/table.lua b/expcore/gui/concepts/table.lua
index 20474951..3a7ae3bf 100644
--- a/expcore/gui/concepts/table.lua
+++ b/expcore/gui/concepts/table.lua
@@ -7,14 +7,16 @@ local Gui = require 'expcore.gui.core'
--[[-- An invisible container that lays out children in a specific number of columns. Column width is given by the largest element contained in that row.
@element table
+
@tparam ?number|function column_count the column count of the table or a function that returns the count being given then parent element
@tparam boolean vertical_lines when true vertical lines will be drawn on the table
@tparam boolean horizontal_lines when true horizontal lines will be drawn on the table
@tparam boolean header_lines when true horizontal lines will be drawn under the first row
@tparam boolean vertical_centering when true element will be vertically centered with in the table
+
@usage-- Making a basic table, contains 25 labels
local basic_table =
-Gui.clone_concept('table','basic_table')
+Gui.new_concept('table')
:set_column_count(5)
:define_draw(function(properties,parent,element)
for i = 1,25 do
@@ -24,16 +26,24 @@ Gui.clone_concept('table','basic_table')
}
end
end)
+
]]
-Gui.new_concept('table')
+
+Gui.new_concept()
+:save_as('table')
+
+-- Properties
:new_property('column_count')
:new_property('vertical_lines')
:new_property('horizontal_lines')
:new_property('header_lines')
:new_property('vertical_centering')
+
+-- Draw
:define_draw(function(properties,parent,element)
local column_count = Gui.resolve_property(properties.column_count,parent)
+ -- Draw a table
element = parent.add{
name = properties.name,
type = 'table',
diff --git a/expcore/gui/concepts/textbox.lua b/expcore/gui/concepts/text_box.lua
similarity index 76%
rename from expcore/gui/concepts/textbox.lua
rename to expcore/gui/concepts/text_box.lua
index 8b8863ec..122ba17f 100644
--- a/expcore/gui/concepts/textbox.lua
+++ b/expcore/gui/concepts/text_box.lua
@@ -7,38 +7,54 @@ local Gui = require 'expcore.gui.core'
--[[-- A multi-line text box that supports selection and copy-paste.
@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 defines.rich_text_setting rich_text how this element handles rich text
@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')
+Gui.new_concept('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')
+Gui.new_concept('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')
+
+Gui.new_concept()
+:save_as('text_box')
+
+-- Events
:new_event('on_text_changed',defines.events.on_gui_text_changed)
+
+-- Properties
: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)
+:new_property('rich_text')
+:new_property('clear_on_rmb',nil,false)
+:new_property('is_selectable',nil,true)
+:new_property('has_word_wrap',nil,true)
+:new_property('is_read_only',nil,true)
+
+-- Draw
:define_draw(function(properties,parent,element)
local default = properties.default
local text = type(default) == 'string' and default or nil
+ -- Draw a text box
element = parent.add{
name = properties.name,
type = 'text-box',
@@ -47,14 +63,22 @@ Gui.new_concept('text_box')
text = text
}
+ -- Set options for text box
element.selectable = properties.is_selectable
element.word_wrap = properties.has_word_wrap
element.read_only = properties.is_read_only
+ -- If there is a default, set it
default = Gui.resolve_property(default,element)
if default and default ~= text then
element.text = default
end
+ -- Change rich text setting if present
+ local rich_text = properties.rich_text
+ if rich_text then
+ element.style.rich_text_setting = rich_text
+ end
+
return element
end)
\ No newline at end of file
diff --git a/expcore/gui/concepts/textfield.lua b/expcore/gui/concepts/text_field.lua
similarity index 79%
rename from expcore/gui/concepts/textfield.lua
rename to expcore/gui/concepts/text_field.lua
index 4275ee21..dd8f862d 100644
--- a/expcore/gui/concepts/textfield.lua
+++ b/expcore/gui/concepts/text_field.lua
@@ -7,53 +7,70 @@ local Gui = require 'expcore.gui.core'
--[[-- Boxes of text the user can type in.
@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 defines.rich_text_setting rich_text how this element handles rich text
@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')
+Gui.new_concept('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')
+Gui.new_concept('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')
+Gui.new_concept('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')
+
+Gui.new_concept()
+:save_as('text_field')
+
+-- Events
:new_event('on_text_changed',defines.events.on_gui_text_changed)
:new_event('on_confirmation',defines.events.on_gui_confirmed)
+
+-- Properties
: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)
+:new_property('rich_text')
+:new_property('clear_on_rmb',nil,false)
+:new_property('lose_forcus',nil,false)
+:new_property('is_number',nil,false)
+:new_property('is_decimal',nil,false)
+:new_property('is_negative',nil,false)
+:new_property('is_password',nil,false)
+
+-- Draw
:define_draw(function(properties,parent,element)
local default = properties.default
local text = type(default) == 'string' and default or nil
+ -- Draw a text field
element = parent.add{
name = properties.name,
type = 'textfield',
@@ -67,10 +84,17 @@ Gui.new_concept('text_field')
text = text
}
+ -- If there is a default, set it
default = Gui.resolve_property(default,element)
if default and default ~= text then
element.text = default
end
+ -- Change rich text setting if present
+ local rich_text = properties.rich_text
+ if rich_text then
+ element.style.rich_text_setting = rich_text
+ end
+
return element
end)
\ No newline at end of file
diff --git a/expcore/gui/core.lua b/expcore/gui/core.lua
index e45101f9..1edcd0b3 100644
--- a/expcore/gui/core.lua
+++ b/expcore/gui/core.lua
@@ -15,82 +15,89 @@ local Gui = {
-- Functions that act as a landing point for the other funtions
-- @section concept-control
---[[-- Loads a concept from the concepts file, used internally
-@tparam string concept the name of the concept to require
+--[[-- Loads a concept from the concepts file
+@tparam string concept_name the name of the concept to require
@usage-- Load a base concept
-Gui.require_concept('frame')
+Gui.require_concept('frame') --- @dep Gui.concept.frame
]]
-function Gui.require_concept(concept)
- require('expcore.gui.concepts.'..concept)
+function Gui.require_concept(concept_name)
+ require('expcore.gui.concepts.'..concept_name)
end
---[[-- Gets the gui concept with this name
-@tparam string name the name of the concept that you want to get
+--[[-- Loads a set of concepts from the styles file
+@tparam string style_name the name of the style to require
+@usage-- Load a base style
+Gui.require_concept('expgaming') --- @dep Gui.style.frame
+]]
+function Gui.require_style(style_name)
+ require('expcore.gui.styles.'..style_name)
+end
+
+--[[-- Gets a gui concept from name, id, or its self
+@tparam ?string|number|table name the name, id, or the concept you want to get
@usage-- Getting a gui concept
local button = Gui.get_concept('Button')
]]
function Gui.get_concept(name)
- return Gui.concepts[name] or error('Gui concept "'..name..'" is not defind',2)
-end
+ if not name then return end
+ local vtype = type(name)
+
+ if vtype == 'string' then
+ return Gui.concepts[name]
+
+ elseif vtype == 'table' then
+ if name.draw_callbacks then
+ return name
+ end
+
+ elseif vtype == 'number' then
+ for _,concept in pairs(Gui.concepts) do
+ if concept.name == name then
+ return concept
+ end
+ end
---[[-- Used internally to save concept names to the core gui module
-@function Prototype:change_name
-@tparam[opt=self.name] string new_name the new name of the concept
-@usage-- Internal Saving
--- this is never needed to be done, internal use only!
-local button = Gui.get_concept('Button')
-button:change_name('Not Button')
-]]
-function Prototype:change_name(new_name)
- if new_name then
- Gui.concepts[self.name] = nil
- self.name = new_name
- self.properties.name = new_name
end
- Gui.concepts[self.name] = self
+end
+
+--[[-- Used to save the concept to the main gui module to allow access from other files
+@function Prototype:save_as
+@tparam string save_name the new name of the concept
+@usage-- Save a concept to allow access in another file
+button:save_as('button')
+@usage-- Access concept after being saved
+Gui.concepts.button
+Gui.get_concept('button')
+]]
+function Prototype:save_as(save_name)
+ Gui.concepts[save_name] = self
return self
end
---[[-- Returns a new gui concept with no properties or events
-@tparam string name the name that you want this concept to have
-@usage-- Making a new concept, see module usage
+--[[-- Returns a new gui concept, option to provide a base concept to copy properties and draw functions from
+@tparam[opt] ?string|number|table base_concept the concept that you want to copy the details of
+@usage-- Making a new button, see module usage
local button = Gui.new_concept('Button')
]]
-function Gui.new_concept(name)
- if Gui.concepts[name] then
- error('Gui concept "'..name..'" is already defind',2)
+function Gui.new_concept(base_concept)
+ if base_concept then
+ base_concept = Gui.get_concept(base_concept) or error('Invalid gui concept "'..tostring(base_concept)..'"',2)
+ return base_concept:clone()
+ else
+ return Prototype:clone()
end
-
- return Prototype:clone(name)
-end
-
---[[-- Make a new concept based on the properties and drawing of another
-@tparam string name the name of the concept that you want as the base
-@tparam string new_name the name that you want the new concept to have
-@usage-- Making a new concept from another, see module usage
-local custom_button = Gui.clone_concept('Button','CustomButton')
-]]
-function Gui.clone_concept(name,new_name)
- local concept = Gui.concepts[name] or error('Gui concept "'..name..'" is not defind',2)
-
- if Gui.concepts[new_name] then
- error('Gui concept "'..new_name..'" is already defind',2)
- end
-
- return concept:clone(new_name)
end
--[[-- Used to draw a concept to a parent element
-@tparam string name the name of the concept that you want to draw
+@tparam ?string|number|table concept the name of the concept that you want to draw
@tparam LuaGuiElement parent the element that will act as a parent for the new element
@treturn LuaGuiElement the element that was created
@usage-- Drawing a new element
Gui.draw_concept('Button',element)
]]
-function Gui.draw_concept(name,parent,...)
- local concept = Gui.concepts[name] or error('Gui concept "'..name..'" is not defind',2)
-
+function Gui.draw_concept(concept,parent,...)
+ concept = Gui.get_concept(concept) or error('Invalid gui concept "'..tostring(concept)..'"',2)
return concept:draw(parent,...)
end
diff --git a/expcore/gui/prototype.lua b/expcore/gui/prototype.lua
index d1e32306..902aa4dc 100644
--- a/expcore/gui/prototype.lua
+++ b/expcore/gui/prototype.lua
@@ -1,67 +1,6 @@
--[[-- Core Module - Gui
@module Gui
@alias Prototype
-
-@usage DX note - chaning this doc string has no effect on the docs
-
-local button =
-Gui.new_concept('Button')
-:new_event('on_click',defines.events.on_gui_click)
-:new_property('tooltip')
-:new_property('caption',nil,function(properties,value)
- properties.caption = value
- properties.sprite = nil
- properties.type = 'button'
-end)
-:new_property('sprite',nil,function(properties,value)
- properties.image = value
- properties.caption = nil
- properties.type = 'sprite-button'
-end)
-:define_draw(function(properties,parent,element)
- -- Note that element might be nil if this is the first draw function
- -- in this case button is a new concept so we know this is the first function and element is nil
- if properties.type == 'button' then
- element = parent.draw{
- type = properties.type,
- name = properties.name,
- caption = properties.caption,
- tooltip = properties.tooltip
- }
-
- else
- element = parent.draw{
- type = properties.type,
- name = properties.name,
- sprite = properties.sprite,
- tooltip = properties.tooltip
- }
-
- end
-
- -- We must return the element or what we want to be seen as the instance, this is so other draw functions have access to it
- -- for example if our custom button defined a draw function to change the font color to red
- return element
-end)
-
-local custom_button =
-button:clone('CustomButton')
-:new_event('on_admin_clicked',defines.events.on_gui_click,function(event)
- return event.player.admin -- only raise custom event when an admin clicks the button
-end)
-:set_caption('Custom Button')
-:set_tooltip('Only admins can press this button')
-:on_click(function(event)
- if not event.player.admin then
- event.player.print('You must be admin to use this button')
- end
-end)
-:on_admin_clicked(function(event)
- -- Yes i know this can just be an if else but its an example
- game.print(event.player.name..' pressed my admin button')
-end)
-
-custom_button:draw(game.player.gui.left)
]]
--- Concept Base.
@@ -71,6 +10,7 @@ custom_button:draw(game.player.gui.left)
local Event = require 'utils.event' -- @dep utils.event
local Store = require 'expcore.store' -- @dep expcore.store
local Game = require 'utils.game' -- @dep utils.game
+local Token = require 'utils.token' -- @dep utils.token
local Factorio_Events = {}
local Prototype = {
@@ -114,15 +54,16 @@ end
@treturn GuiConcept the base for building a custom gui
@usage-- Clones the base Button concept to make a alternative button
local custom_button =
-Gui.get_concept('Button'):clone('CustomButton')
+Gui.get_concept(Gui.concepts.button):clone()
]]
-function Prototype:clone(concept_name)
+function Prototype:clone()
local concept = table.deep_copy(self)
-- Replace name of the concept
- concept.name = concept_name
- concept.properties.name = concept_name
- concept:change_name()
+ local uid = tostring(Token.uid())
+ concept.name = uid
+ concept.debug_name = uid
+ concept.properties.name = uid
-- Remove all event handlers that were copied
concept.events = {}
@@ -164,7 +105,7 @@ function Prototype:clone(concept_name)
for _,clone_callback in pairs(concept.clone_callbacks) do
local success, rtn = pcall(clone_callback,concept)
if not success then
- error('Gui clone handler error with '..concept.name..':\n\t'..rtn)
+ error('Gui clone handler error with '..concept.debug_name..':\n\t'..rtn)
end
end
@@ -194,18 +135,28 @@ function Prototype:define_clone(clone_callback)
return self
end
---[[-- Used internally to save concept names to the core gui module
-@function Prototype:change_name
-@tparam[opt=self.name] string new_name the new name of the concept
-@usage-- Internal Saving
--- this is never needed to be done, internal use only!
-local button = Gui.get_concept('Button')
-button:change_name('Not Button')
+--[[-- Used to save the concept to the main gui module to allow access from other files
+@function Prototype:save_as
+@tparam string save_name the new name of the concept
+@usage-- Save a concept to allow access in another file
+button:save_as('button')
+@usage-- Access concept after being saved
+Gui.concepts.button
+Gui.get_concept('button')
]]
-function Prototype:change_name(new_name)
+function Prototype:save_as(save_name)
-- over writen in core file
- self.name = new_name or self.name
- self.properties.name = self.name
+ return self
+end
+
+--[[-- Sets a debug name that can be used with error handlers
+@tparam string name the name that will be used in error messages
+@treturn self to allow chaining
+@usage-- Set the debug name
+unsaved_concept:debug('Example button')
+]]
+function Prototype:debug(name)
+ self.debug_name = name
return self
end
@@ -312,15 +263,15 @@ function Prototype:raise_event(event_name,event,from_factorio)
for _,handler in ipairs(handlers) do
local success, err = pcall(handler,event)
if not success then
- error('Gui event handler error with '..self.name..'/'..event_name..':\n\t'..err)
+ error('Gui event handler error with '..self.debug_name..'/'..event_name..':\n\t'..err)
end
end
end
--[[-- Adds a new property to the concept, such as caption, tooltip, or some custom property you want to control
@tparam string property_name the name of the new property, must be unique
-@tparam any default the default value for this property, although not strictly required is is strongly recomented
@tparam[opt] function setter_callback this function is called when set is called, if not provided then key in concept.properties is updated to new value
+@tparam[opt] any default use this as the default value, will call the setter callback if defined
@treturn GuiConcept to allow chaining of functions
@usage-- Adding caption, sprite, and tooltip to the base button concept
local button =
@@ -337,14 +288,16 @@ end)
properties.type = 'sprite-button'
end)
]]
-function Prototype:new_property(property_name,default,setter_callback)
+function Prototype:new_property(property_name,setter_callback,default,...)
-- Check that the property does not already exist
if self.properties[property_name] then
error('Property is already defined',2)
end
- -- Set the property to its default
- self.properties[property_name] = default
+ -- Check that setter is a function if present
+ if setter_callback and not type(setter_callback) == 'function' then
+ error('Setter callback must be a function')
+ end
--[[-- Sets a new value for a property, triggers setter method if provided, replace with property name
@function Prototype:set_custom_property
@@ -354,7 +307,6 @@ function Prototype:new_property(property_name,default,setter_callback)
local custom_button =
Gui.get_concept('Button')
:set_caption('Default Button')
-
@usage-- In our examples CustomButton is cloned from Button, this means the caption property already exists
-- note that what ever values that properties have at the time of cloning are also copied
local custom_button =
@@ -367,7 +319,7 @@ Gui.get_concept('CustomButton')
-- Call the setter method to update values if present
local success, err = pcall(setter_callback,concept.properties,value,...)
if not success then
- error('Gui property handler error with '..concept.name..'/'..property_name..':\n\t'..err)
+ error('Gui property handler error with '..concept.debug_name..'/'..property_name..':\n\t'..err)
end
else
-- Otherwise just update the key
@@ -377,6 +329,11 @@ Gui.get_concept('CustomButton')
return concept
end
+ -- If a default value if given then set the default value
+ if default ~= nil then
+ self['set_'..property_name](self,default,...)
+ end
+
return self
end
@@ -387,12 +344,12 @@ end
local button =
Gui.get_concept('Button')
:define_draw(function(properties,parent,element)
- -- Note that element might be nil if this is the first draw function
- -- for this example we assume button was cloned from Prototype and so has no other draw functions defined
- -- this means that there is no element yet and what we return will be the first time the element is returned
- -- although not shown here you also can recive any extra arguments here from the call to draw
+ -- Properties will include all the information that you need to draw the element
+ -- Parent is the parent element for the element, this may have been altered by previous draw functions
+ -- Element is the current element being made, this may have a nil value, if it is nil then this is the first draw function
+ -- You can also pass any other arguments that you want to this function from the draw call
if properties.type == 'button' then
- element = parent.draw{
+ element = parent.add{
type = properties.type,
name = properties.name,
caption = properties.caption,
@@ -400,7 +357,7 @@ Gui.get_concept('Button')
}
else
- element = parent.draw{
+ element = parent.add{
type = properties.type,
name = properties.name,
sprite = properties.sprite,
@@ -409,9 +366,9 @@ Gui.get_concept('Button')
end
- -- We must return the element or what we want to be seen as the instance, this is so other draw functions have access to it
- -- for example if our custom button defined a draw function to change the font color to red
- return element
+ -- If you return element or parent then their values will be updated for the next draw function in the chain
+ -- It is best practice to always return the values if you have made any changes to them
+ return element, parent
end)
]]
function Prototype:define_draw(draw_callback)
@@ -433,12 +390,16 @@ end
local button =
Gui.get_concept('Button')
:define_pre_draw(function(properties,parent,element)
- -- Here we set the lcoal parent to a new flow, to set this as the new parent we must return it below
+ -- Properties will include all the information that you need to draw the element
+ -- Parent is the parent element for the element, this may have been altered by previous draw functions
+ -- Element is the current element being made, this may have a nil value, if it is nil then this is the first draw function
+ -- You can also pass any other arguments that you want to this function from the draw call
parent = parent.add{
type = 'flow'
}
- -- We must return the element here but we can also return a new parent instance that all other draw functions will see as the parent
+ -- If you return element or parent then their values will be updated for the next draw function in the chain
+ -- It is best practice to always return the values if you have made any changes to them
return element, parent
end)
]]
@@ -475,7 +436,7 @@ function Prototype:draw(parent_element,...)
if _element then element = _element end
if _parent then parent = _parent end
elseif not success then
- error('Gui draw handler error with '..self.name..':\n\t'.._element)
+ error('Gui draw handler error with '..self.debug_name..':\n\t'.._element)
end
end
diff --git a/expcore/gui/test.lua b/expcore/gui/test.lua
index 776bfa59..e57b7ece 100644
--- a/expcore/gui/test.lua
+++ b/expcore/gui/test.lua
@@ -12,17 +12,16 @@ local Game = require 'utils.game'
local Event = require 'utils.event'
require 'expcore.toolbar'
-local test_prefix = '__GUI_TEST_'
local tests = {}
-local function TEST(str) return test_prefix..str end
-
--[[
The main test frame
]]
+Gui.require_concept('frame')
+
local test_frame =
-Gui.clone_concept('frame',TEST 'test_frame')
+Gui.new_concept('frame')
:set_title('Gui Tests')
:define_draw(function(properties,parent,element)
for category, _ in pairs(tests) do
@@ -34,7 +33,7 @@ Gui.clone_concept('frame',TEST 'test_frame')
end
end)
-Gui.clone_concept('toolbar-button',TEST 'run_test_button')
+Gui.new_concept('toolbar-button')
:set_permission_alias('gui-test')
:set_caption('Element Tests')
:on_click(function(event)
@@ -45,7 +44,7 @@ Gui.clone_concept('toolbar-button',TEST 'run_test_button')
end)
local test_left_frame =
-Gui.clone_concept('toolbar-frame',TEST 'player_list')
+Gui.new_concept('toolbar-frame')
:set_permission_alias('gui-test')
:set_caption('Frame Test Left')
:define_draw(function(properties,parent,element)
@@ -61,6 +60,7 @@ Gui.clone_concept('toolbar-frame',TEST 'player_list')
list_area.style.horizontally_stretchable = true
list_area.style.maximal_height = 200
+ -- Add player names
for _,player in pairs(game.connected_players) do
list_area.add{
type='label',
@@ -72,6 +72,7 @@ end)
local list_area = event.element.scroll
list_area.clear()
+ -- Add player names
for _,player in pairs(game.connected_players) do
list_area.add{
type='label',
@@ -154,8 +155,11 @@ Buttons
> Admin Button -- Button which is disabled if the player is not an admin
]]
+Gui.require_concept('button')
+
local basic_button =
-Gui.clone_concept('button',TEST 'basic_button')
+Gui.new_concept('button')
+:debug('basic_button')
:set_caption('Basic Button')
:set_tooltip('Basic button')
:on_click(function(event)
@@ -163,7 +167,8 @@ Gui.clone_concept('button',TEST 'basic_button')
end)
local sprite_button =
-Gui.clone_concept('button',TEST 'sprite_button')
+Gui.new_concept('button')
+:debug('sprite_button')
:set_sprite('utility/warning_icon')
:set_tooltip('Sprite button')
:on_click(function(event)
@@ -171,7 +176,8 @@ Gui.clone_concept('button',TEST 'sprite_button')
end)
local multi_sprite_button =
-Gui.clone_concept('button',TEST 'multi_sprite_button')
+Gui.new_concept('button')
+:debug('multi_sprite_button')
:set_sprite('utility/warning_icon','utility/warning','utility/warning_white')
:set_tooltip('Multi-sprite button')
:on_click(function(event)
@@ -179,7 +185,8 @@ Gui.clone_concept('button',TEST 'multi_sprite_button')
end)
local admin_button =
-Gui.clone_concept('button',TEST 'admin_button')
+Gui.new_concept('button')
+:debug('admin_button')
:set_caption('Admin Button')
:set_tooltip('Admin button')
:define_draw(function(properties,parent,element)
@@ -208,8 +215,11 @@ Checkboxs
> Player Stored Checkbox -- Checkbox that stores its state between re-draws
]]
+Gui.require_concept('checkbox')
+
local basic_checkbox =
-Gui.clone_concept('checkbox',TEST 'basic_checkbox')
+Gui.new_concept('checkbox')
+:debug('basic_checkbox')
:set_caption('Basic Checkbox')
:set_tooltip('Basic checkbox')
:on_state_changed(function(event)
@@ -217,7 +227,8 @@ Gui.clone_concept('checkbox',TEST 'basic_checkbox')
end)
local game_checkbox =
-Gui.clone_concept('checkbox',TEST 'game_checkbox')
+Gui.new_concept('checkbox')
+:debug('game_checkbox')
:set_caption('Game Stored Checkbox')
:set_tooltip('Game stored checkbox')
:on_state_changed(function(event)
@@ -230,7 +241,8 @@ end)
end)
local force_checkbox =
-Gui.clone_concept('checkbox',TEST 'force_checkbox')
+Gui.new_concept('checkbox')
+:debug('force_checkbox')
:set_caption('Force Stored Checkbox')
:set_tooltip('Force stored checkbox')
:on_state_changed(function(event)
@@ -243,7 +255,8 @@ end)
end)
local player_checkbox =
-Gui.clone_concept('checkbox',TEST 'player_checkbox')
+Gui.new_concept('checkbox')
+:debug('player_checkbox')
:set_caption('Player Stored Checkbox')
:set_tooltip('Player stored checkbox')
:on_state_changed(function(event)
@@ -270,8 +283,11 @@ Dropdowns
> Dynamic Player Stored Dropdown -- Same as above but now with dynamic options
]]
+Gui.require_concept('dropdown')
+
local static_dropdown =
-Gui.clone_concept('dropdown',TEST 'static_dropdown')
+Gui.new_concept('dropdown')
+:debug('static_dropdown')
:set_static_items{'Option 1','Option 2','Option 3'}
:on_selection_changed(function(event)
local value = Gui.get_dropdown_value(event.element)
@@ -279,7 +295,8 @@ Gui.clone_concept('dropdown',TEST 'static_dropdown')
end)
local dynamic_dropdown =
-Gui.clone_concept('dropdown',TEST 'dynamic_dropdown')
+Gui.new_concept('dropdown')
+:debug('dynamic_dropdown')
:set_dynamic_items(function(element)
local items = {}
for concept_name,_ in pairs(Gui.concepts) do
@@ -295,7 +312,8 @@ end)
end)
local static_player_dropdown =
-Gui.clone_concept('dropdown',TEST 'static_player_dropdown')
+Gui.new_concept('dropdown')
+:debug('static_player_dropdown')
:set_static_items{'Option 1','Option 2','Option 3'}
:on_selection_changed(function(event)
local element = event.element
@@ -308,7 +326,8 @@ end)
end)
local dynamic_player_dropdown =
-Gui.clone_concept('dropdown',TEST 'dynamic_player_dropdown')
+Gui.new_concept('dropdown')
+:debug('dynamic_player_dropdown')
:set_dynamic_items(function(element)
local items = {}
for concept_name,_ in pairs(Gui.concepts) do
@@ -342,7 +361,8 @@ Listboxs
]]
local static_listbox =
-Gui.clone_concept('dropdown',TEST 'static_listbox')
+Gui.new_concept('dropdown')
+:debug('static_listbox')
:set_use_list_box(true)
:set_static_items{'Option 1','Option 2','Option 3'}
:on_selection_changed(function(event)
@@ -351,7 +371,8 @@ Gui.clone_concept('dropdown',TEST 'static_listbox')
end)
local static_player_listbox =
-Gui.clone_concept('dropdown',TEST 'static_player_listbox')
+Gui.new_concept('dropdown')
+:debug('static_player_listbox')
:set_use_list_box(true)
:set_static_items{'Option 1','Option 2','Option 3'}
:on_selection_changed(function(event)
@@ -376,14 +397,18 @@ Elem Buttons
> Player Stored Elem Button -- Same as above but is stored per player
]]
+Gui.require_concept('elem_button')
+
local basic_elem_button =
-Gui.clone_concept('elem_button',TEST 'basic_elembutton')
+Gui.new_concept('elem_button')
+:debug('basic_elem_button')
:on_selection_changed(function(event)
event.player.print('Basic elem button is now: '..event.element.elem_value)
end)
local default_selection_elem_button =
-Gui.clone_concept('elem_button',TEST 'default_selection_elem_button')
+Gui.new_concept('elem_button')
+:debug('default_selection_elem_button')
:set_elem_type('signal')
:set_default{type='virtual',name='signal-info'}
:on_selection_changed(function(event)
@@ -392,7 +417,8 @@ Gui.clone_concept('elem_button',TEST 'default_selection_elem_button')
end)
local player_elem_button =
-Gui.clone_concept('elem_button',TEST 'player_elem_button')
+Gui.new_concept('elem_button')
+:debug('player_elem_button')
:set_elem_type('technology')
:on_selection_changed(function(event)
local element = event.element
@@ -419,8 +445,11 @@ Progress Bars
> Force Stored Progress Bar -- will increse when pressed, unlike above all will increse at same time and will have the same value
]]
+Gui.require_concept('progress_bar')
+
local basic_progress_bar =
-Gui.clone_concept('progress_bar',TEST 'basic_progress_bar')
+Gui.new_concept('progress_bar')
+:debug('basic_progress_bar')
:set_tooltip('Basic progress bar')
:set_maximum(5)
:new_event('on_click',defines.events.on_gui_click)
@@ -433,7 +462,8 @@ end)
end)
local inverted_progress_bar =
-Gui.clone_concept('progress_bar',TEST 'inverted_progress_bar')
+Gui.new_concept('progress_bar')
+:debug('inverted_progress_bar')
:set_tooltip('Inverted progress bar')
:set_inverted(true)
:set_maximum(5)
@@ -446,7 +476,8 @@ end)
end)
local game_progress_bar =
-Gui.clone_concept('progress_bar',TEST 'game_progress_bar')
+Gui.new_concept('progress_bar')
+:debug('game_progress_bar')
:set_tooltip('Game progress bar')
:set_maximum(300)
:new_event('on_tick',defines.events.on_tick)
@@ -460,7 +491,8 @@ end)
:define_instance_store()
local force_instance_progress_bar =
-Gui.clone_concept('progress_bar',TEST 'force_instance_progress_bar')
+Gui.new_concept('progress_bar')
+:debug('force_instance_progress_bar')
:set_tooltip('Force instance progress bar')
:set_maximum(5)
:new_event('on_click',defines.events.on_gui_click)
@@ -474,7 +506,8 @@ end)
:define_instance_store(Gui.categorize_by_force)
local force_stored_progress_bar =
-Gui.clone_concept('progress_bar',TEST 'force_stored_progress_bar')
+Gui.new_concept('progress_bar')
+:debug('force_stored_progress_bar')
:set_tooltip('Force stored progress bar')
:set_maximum(5)
:new_event('on_click',defines.events.on_gui_click)
@@ -512,15 +545,19 @@ Sliders
> Player Stored Slider -- Slider which stores the value per player, also goes 1 to 10
]]
+Gui.require_concept('slider')
+
local basic_slider =
-Gui.clone_concept('slider',TEST 'basic_slider')
+Gui.new_concept('slider')
+:debug('basic_slider')
:set_range(1,10)
:on_value_changed(function(event)
event.player.print('Basic slider is now: '..event.element.slider_value)
end)
local interval_slider =
-Gui.clone_concept('slider',TEST 'interval_slider')
+Gui.new_concept('slider')
+:debug('interval_slider')
:set_range(1,10)
:set_value_step(1)
:on_value_changed(function(event)
@@ -528,7 +565,8 @@ Gui.clone_concept('slider',TEST 'interval_slider')
end)
local discrete_slider =
-Gui.clone_concept('slider',TEST 'discrete_slider')
+Gui.new_concept('slider')
+:debug('discrete_slider')
:set_range(1,10)
:set_value_step(1)
:set_discrete_slider(true)
@@ -537,7 +575,8 @@ Gui.clone_concept('slider',TEST 'discrete_slider')
end)
local dynamic_slider =
-Gui.clone_concept('slider',TEST 'dynamic_slider')
+Gui.new_concept('slider')
+:debug('dynamic_slider')
:set_range(function(element)
local player = Gui.get_player_from_element(element)
return 1, player.name:len()
@@ -549,7 +588,8 @@ end)
end)
local player_slider =
-Gui.clone_concept('slider',TEST 'player_slider')
+Gui.new_concept('slider')
+:debug('player_slider')
:set_range(1,10)
:set_value_step(1)
:set_discrete_slider(true)
@@ -580,16 +620,20 @@ Text Fields
> Player Stored Text Field - Same as basic but will store value per player
]]
+Gui.require_concept('text_field')
+
-- Making a text field
local basic_text_field =
-Gui.clone_concept('text_field',TEST 'basic_text_field')
+Gui.new_concept('text_field')
+:debug('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')
+Gui.new_concept('text_field')
+:debug('better_text_field')
:set_tooltip('Better text field')
:set_clear_on_rmb(true)
:set_lose_forcus(true)
@@ -598,7 +642,8 @@ Gui.clone_concept('text_field',TEST 'better_text_field')
end)
local decimal_text_field =
-Gui.clone_concept('text_field',TEST 'decimal_text_field')
+Gui.new_concept('text_field')
+:debug('decimal_text_field')
:set_tooltip('Decimal text field')
:set_is_decimal(true)
:on_confirmation(function(event)
@@ -606,7 +651,8 @@ Gui.clone_concept('text_field',TEST 'decimal_text_field')
end)
local password_text_field =
-Gui.clone_concept('text_field',TEST 'password_text_field')
+Gui.new_concept('text_field')
+:debug('password_text_field')
:set_tooltip('Password text field')
:set_is_password(true)
:on_confirmation(function(event)
@@ -614,7 +660,8 @@ Gui.clone_concept('text_field',TEST 'password_text_field')
end)
local player_text_field =
-Gui.clone_concept('text_field',TEST 'player_text_field')
+Gui.new_concept('text_field')
+:debug('player_text_field')
:set_tooltip('Player stored text field')
:on_confirmation(function(event)
local element = event.element
@@ -640,8 +687,11 @@ Text Boxs
> Editible Text Box -- A text box that can be edited
]]
+Gui.require_concept('text_box')
+
local basic_text_box =
-Gui.clone_concept('text_box',TEST 'basic_text_box')
+Gui.new_concept('text_box')
+:debug('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)
@@ -649,7 +699,8 @@ Gui.clone_concept('text_box',TEST 'basic_text_box')
end)
local editible_text_box =
-Gui.clone_concept('text_box',TEST 'editible_text_box')
+Gui.new_concept('text_box')
+:debug('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')
diff --git a/expcore/toolbar.lua b/expcore/toolbar.lua
index a601a7ab..d30ee06f 100644
--- a/expcore/toolbar.lua
+++ b/expcore/toolbar.lua
@@ -9,6 +9,8 @@ local Event = require 'utils.event' --- @dep utils.event
local Game = require 'utils.game' --- @dep utils.game
local mod_gui = require 'mod-gui' --- @dep mod-gui
+Gui.require_concept('button') --- @dep Gui.concept.button
+
local toolbar_toggle_concept
local toolbar_hide_concept
local toolbar_concept
@@ -54,7 +56,7 @@ end
@tparam table concept the gui concept that you want to add to the button area
@usage-- Adding a basic button to the toolbar
local new_button =
-Gui.clone_concept('button','new-button')
+Gui.new_concept('button')
:set_caption('Click Me')
:on_click(function(event)
event.player.print('You Clicked Me!!')
@@ -102,17 +104,20 @@ end
@element toolbar-button
@tparam string permission_alias the alias used with Toolbar.allowed
@usage-- Adding a basic button to the toolbar, note no need to call Toolbar.add_button_concept
-Gui.clone_concept('toolbar-button','new-button')
+Gui.new_concept('toolbar-button')
:set_caption('Click Me')
:on_click(function(event)
event.player.print('You Clicked Me!!')
end)
]]
Toolbar.button =
-Gui.clone_concept('button','toolbar-button')
+Gui.new_concept('button')
+:save_as('toolbar-button')
+
:new_property('permission_alias',nil,function(properties,value)
Toolbar.set_permission_alias(properties.name,value)
end)
+
:define_clone(Toolbar.add_button_concept)
:define_draw(function(properties,parent,element)
element.style = mod_gui.button_style
@@ -126,7 +131,7 @@ end)
@tparam table concept the gui concept that you want to add to the toolbar frame area
@usage-- Adding a basic frame to the frame area
local new_frame =
-Gui.clone_concept('frame','new_frame')
+Gui.new_concept('frame')
:set_title('Test')
Toolbar.add_frame_concept(new_frame)
@@ -177,7 +182,7 @@ end
@tparam string direction the direction that the items in the frame are added
@usage-- Adding a basic player list
local player_list =
-Gui.clone_concept('toolbar-frame','player_list')
+Gui.new_concept('toolbar-frame')
:set_permission_alias('player_list')
:set_caption('Player List')
:toggle_with_click()
@@ -214,17 +219,24 @@ end)
end)
]]
Toolbar.frame =
-Gui.clone_concept('toolbar-button','toolbar-frame')
+Gui.new_concept('toolbar-button')
+:save_as('toolbar-frame')
+
+-- Properties
:new_property('open_by_default',false)
:new_property('use_container',true)
:new_property('direction','horizontal')
:new_event('on_update')
+
+-- Clone
:define_clone(function(concept)
Toolbar.add_frame_concept(concept)
concept:on_click(function(event)
event.concept:toggle_visible_state(event.player)
end)
end)
+
+-- Draw
:define_draw(function(properties,parent,element)
-- Add the base frame element, the button is already drawn to parent
local player = Gui.get_player_from_element(element)
@@ -332,7 +344,8 @@ end
@param on_hide_frames fired when the frames are hidden for a player
]]
toolbar_concept =
-Gui.new_concept('toolbar')
+Gui.new_concept()
+:debug('toolbar')
:define_draw(function(properties,player)
-- Get the main flows
local top_flow = mod_gui.get_button_flow(player)
@@ -372,6 +385,8 @@ Gui.new_concept('toolbar')
Toolbar.get_visible_frames(player)
end)
+
+-- When the buttons are updated
:new_event('on_button_update')
:on_button_update(function(event)
-- Get the top flow
@@ -389,6 +404,8 @@ end)
end
end)
+
+-- When frames are hidden
:new_event('on_hide_frames')
:on_hide_frames(function(event)
-- Get the left flow
@@ -419,7 +436,7 @@ end
@element toolbar-toggle
]]
toolbar_toggle_concept =
-Gui.clone_concept('button','toolbar-toggle')
+Gui.new_concept('button')
:set_caption('<')
:set_tooltip{'gui_util.button_tooltip'}
:define_draw(toolbar_button_draw)
@@ -435,7 +452,7 @@ end)
@element toolbar-clear
]]
toolbar_hide_concept =
-Gui.clone_concept('button','toolbar-clear')
+Gui.new_concept('button')
:set_caption('<')
:set_tooltip{'expcore-gui.left-button-tooltip'}
:define_draw(toolbar_button_draw)