From 5e1be09b3c50fae3eb8f121801b538660aa5bcd6 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Fri, 23 Aug 2019 21:41:43 +0100 Subject: [PATCH 01/26] Renames in Store --- config/_file_loader.lua | 14 +- docs/addons/Advanced-Start.html | 2 +- docs/addons/Chat-Popups.html | 2 +- docs/addons/Chat-Reply.html | 2 +- docs/addons/Compilatron.html | 2 +- docs/addons/Damage-Popups.html | 2 +- docs/addons/Death-Logger.html | 2 +- docs/addons/Discord-Alerts.html | 2 +- docs/addons/Player-Colours.html | 2 +- docs/addons/Pollution-Grading.html | 2 +- docs/addons/Scorched-Earth.html | 2 +- docs/addons/Spawn-Area.html | 2 +- docs/commands/Admin-Chat.html | 2 +- docs/commands/Bonus.html | 2 +- docs/commands/Cheat-Mode.html | 2 +- docs/commands/Clear-Inventory.html | 2 +- docs/commands/Debug.html | 2 +- docs/commands/Find.html | 2 +- docs/commands/Help.html | 2 +- docs/commands/Home.html | 2 +- docs/commands/Interface.html | 2 +- docs/commands/Jail.html | 2 +- docs/commands/Kill.html | 2 +- docs/commands/Me.html | 2 +- docs/commands/Rainbow.html | 2 +- docs/commands/Repair.html | 2 +- docs/commands/Reports.html | 2 +- docs/commands/Roles.html | 2 +- docs/commands/Spawn.html | 2 +- docs/commands/Tag.html | 2 +- docs/commands/Teleport.html | 2 +- docs/commands/Warnings.html | 2 +- docs/config.ld | 6 +- docs/configs/Advanced-Start.html | 2 +- docs/configs/Bonuses.html | 2 +- docs/configs/Chat-Reply.html | 2 +- docs/configs/Commands-Auth-Admin.html | 2 +- docs/configs/Commands-Auth-Roles.html | 2 +- .../Commands-Auth-Runtime-Disable.html | 2 +- docs/configs/Commands-Parse-Roles.html | 2 +- docs/configs/Commands-Parse.html | 2 +- docs/configs/Compilatron.html | 2 +- docs/configs/Death-Logger.html | 2 +- docs/configs/Discord-Alerts.html | 2 +- docs/configs/File-Loader.html | 2 +- docs/configs/Permission-Groups.html | 2 +- docs/configs/Player-List.html | 2 +- docs/configs/Pollution-Grading.html | 2 +- docs/configs/Popup-Messages.html | 2 +- docs/configs/Preset-Player-Colours.html | 2 +- docs/configs/Repair.html | 2 +- docs/configs/Rockets.html | 2 +- docs/configs/Roles.html | 2 +- docs/configs/Science.html | 2 +- docs/configs/Scorched-Earth.html | 2 +- docs/configs/Spawn-Area.html | 2 +- docs/configs/Tasks.html | 2 +- docs/configs/Warnings.html | 2 +- docs/configs/Warps.html | 2 +- docs/control/Jail.html | 2 +- docs/control/Production.html | 2 +- docs/control/Reports.html | 2 +- docs/control/Rockets.html | 2 +- docs/control/Tasks.html | 2 +- docs/control/Warnings.html | 2 +- docs/control/Warps.html | 2 +- docs/core/Commands.html | 2 +- docs/core/Common-Library.html | 64 +- docs/core/Gui.html | 2 +- docs/core/Permissions-Groups.html | 2 +- docs/core/Roles.html | 2 +- docs/core/Store.html | 1064 +++++++++-------- docs/core/Sudo.html | 2 +- docs/guis/Player-List.html | 2 +- docs/guis/Rocket-Info.html | 2 +- docs/guis/Science-Info.html | 2 +- docs/guis/Task-List.html | 2 +- docs/guis/Warps-List.html | 2 +- docs/index.html | 2 +- docs/modules/control.html | 2 +- .../utils.alien_evolution_progress.html | 2 +- docs/modules/utils.core.html | 2 +- docs/modules/utils.debug.html | 2 +- docs/modules/utils.dump_env.html | 2 +- docs/modules/utils.event.html | 2 +- docs/modules/utils.event_core.html | 2 +- docs/modules/utils.math.html | 2 +- docs/modules/utils.recipe_locker.html | 2 +- docs/modules/utils.state_machine.html | 2 +- docs/modules/utils.table.html | 2 +- docs/modules/utils.task.html | 2 +- docs/modules/utils.timestamp.html | 2 +- docs/topics/license.html | 2 +- docs/topics/readme.md.html | 11 +- expcore/common.lua | 8 + expcore/gui/test.lua | 2 +- expcore/store.lua | 224 ++-- modules/commands/interface.lua | 2 +- modules/gui/warp-list.lua | 2 +- 99 files changed, 820 insertions(+), 755 deletions(-) diff --git a/config/_file_loader.lua b/config/_file_loader.lua index c4a5bba6..ab0c84e4 100644 --- a/config/_file_loader.lua +++ b/config/_file_loader.lua @@ -39,17 +39,17 @@ return { 'modules.addons.discord-alerts', 'modules.addons.chat-reply', -- GUI - 'modules.gui.rocket-info', - 'modules.gui.science-info', - 'modules.gui.warp-list', - 'modules.gui.task-list', - 'modules.gui.player-list', - 'modules.commands.debug', + --'modules.gui.rocket-info', + --'modules.gui.science-info', + --'modules.gui.warp-list', + --'modules.gui.task-list', + --'modules.gui.player-list', + --'modules.commands.debug', -- Config Files 'config.expcore-commands.auth_admin', -- commands tagged with admin_only are blocked for non admins 'config.expcore-commands.auth_roles', -- commands must be allowed via the role config 'config.expcore-commands.auth_runtime_disable', -- allows commands to be enabled and disabled during runtime 'config.permission_groups', -- loads some predefined permission groups 'config.roles', -- loads some predefined roles - 'expcore.gui.test' -- loads multiple gui defines to test the gui system + --'expcore.gui.test' -- loads multiple gui defines to test the gui system } \ No newline at end of file diff --git a/docs/addons/Advanced-Start.html b/docs/addons/Advanced-Start.html index 0b56fc11..b51f20a5 100644 --- a/docs/addons/Advanced-Start.html +++ b/docs/addons/Advanced-Start.html @@ -348,7 +348,7 @@ generated by LDoc diff --git a/docs/addons/Chat-Popups.html b/docs/addons/Chat-Popups.html index 75114dcc..fdb6a24b 100644 --- a/docs/addons/Chat-Popups.html +++ b/docs/addons/Chat-Popups.html @@ -349,7 +349,7 @@ generated by LDoc diff --git a/docs/addons/Chat-Reply.html b/docs/addons/Chat-Reply.html index be18394a..91b5fa1d 100644 --- a/docs/addons/Chat-Reply.html +++ b/docs/addons/Chat-Reply.html @@ -376,7 +376,7 @@ generated by LDoc diff --git a/docs/addons/Compilatron.html b/docs/addons/Compilatron.html index 3ad91922..889058f8 100644 --- a/docs/addons/Compilatron.html +++ b/docs/addons/Compilatron.html @@ -585,7 +585,7 @@ generated by LDoc diff --git a/docs/addons/Damage-Popups.html b/docs/addons/Damage-Popups.html index 42cd4094..99fe3f44 100644 --- a/docs/addons/Damage-Popups.html +++ b/docs/addons/Damage-Popups.html @@ -349,7 +349,7 @@ generated by LDoc diff --git a/docs/addons/Death-Logger.html b/docs/addons/Death-Logger.html index 01b1f797..590c7e4b 100644 --- a/docs/addons/Death-Logger.html +++ b/docs/addons/Death-Logger.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/addons/Discord-Alerts.html b/docs/addons/Discord-Alerts.html index cce518e8..3e22e16a 100644 --- a/docs/addons/Discord-Alerts.html +++ b/docs/addons/Discord-Alerts.html @@ -460,7 +460,7 @@ generated by LDoc diff --git a/docs/addons/Player-Colours.html b/docs/addons/Player-Colours.html index d17bb676..94b6590b 100644 --- a/docs/addons/Player-Colours.html +++ b/docs/addons/Player-Colours.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/addons/Pollution-Grading.html b/docs/addons/Pollution-Grading.html index bfc08f0d..ed128319 100644 --- a/docs/addons/Pollution-Grading.html +++ b/docs/addons/Pollution-Grading.html @@ -320,7 +320,7 @@ generated by LDoc diff --git a/docs/addons/Scorched-Earth.html b/docs/addons/Scorched-Earth.html index 09d37fe9..16ca5e5a 100644 --- a/docs/addons/Scorched-Earth.html +++ b/docs/addons/Scorched-Earth.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/addons/Spawn-Area.html b/docs/addons/Spawn-Area.html index 3ba5ee0d..d708d75a 100644 --- a/docs/addons/Spawn-Area.html +++ b/docs/addons/Spawn-Area.html @@ -376,7 +376,7 @@ generated by LDoc diff --git a/docs/commands/Admin-Chat.html b/docs/commands/Admin-Chat.html index e8b3303d..7dc05f4a 100644 --- a/docs/commands/Admin-Chat.html +++ b/docs/commands/Admin-Chat.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Bonus.html b/docs/commands/Bonus.html index 4b41076e..58ab06cc 100644 --- a/docs/commands/Bonus.html +++ b/docs/commands/Bonus.html @@ -500,7 +500,7 @@ generated by LDoc diff --git a/docs/commands/Cheat-Mode.html b/docs/commands/Cheat-Mode.html index cb0d0a09..6873b6fd 100644 --- a/docs/commands/Cheat-Mode.html +++ b/docs/commands/Cheat-Mode.html @@ -361,7 +361,7 @@ generated by LDoc diff --git a/docs/commands/Clear-Inventory.html b/docs/commands/Clear-Inventory.html index 27f45940..c280d9eb 100644 --- a/docs/commands/Clear-Inventory.html +++ b/docs/commands/Clear-Inventory.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Debug.html b/docs/commands/Debug.html index e2f78d24..6ebb7007 100644 --- a/docs/commands/Debug.html +++ b/docs/commands/Debug.html @@ -365,7 +365,7 @@ generated by LDoc diff --git a/docs/commands/Find.html b/docs/commands/Find.html index c727cd0e..e2cd0dcc 100644 --- a/docs/commands/Find.html +++ b/docs/commands/Find.html @@ -360,7 +360,7 @@ generated by LDoc diff --git a/docs/commands/Help.html b/docs/commands/Help.html index d5178346..cece090c 100644 --- a/docs/commands/Help.html +++ b/docs/commands/Help.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/commands/Home.html b/docs/commands/Home.html index a1ba8bce..3c7a8205 100644 --- a/docs/commands/Home.html +++ b/docs/commands/Home.html @@ -458,7 +458,7 @@ generated by LDoc diff --git a/docs/commands/Interface.html b/docs/commands/Interface.html index c38850c0..bba2600b 100644 --- a/docs/commands/Interface.html +++ b/docs/commands/Interface.html @@ -416,7 +416,7 @@ generated by LDoc diff --git a/docs/commands/Jail.html b/docs/commands/Jail.html index 2f087f4c..43f5e5e8 100644 --- a/docs/commands/Jail.html +++ b/docs/commands/Jail.html @@ -611,7 +611,7 @@ generated by LDoc diff --git a/docs/commands/Kill.html b/docs/commands/Kill.html index 33cd787e..fa88b477 100644 --- a/docs/commands/Kill.html +++ b/docs/commands/Kill.html @@ -389,7 +389,7 @@ generated by LDoc diff --git a/docs/commands/Me.html b/docs/commands/Me.html index ee42acca..6865f47d 100644 --- a/docs/commands/Me.html +++ b/docs/commands/Me.html @@ -360,7 +360,7 @@ generated by LDoc diff --git a/docs/commands/Rainbow.html b/docs/commands/Rainbow.html index b7f2a851..4a57c50a 100644 --- a/docs/commands/Rainbow.html +++ b/docs/commands/Rainbow.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Repair.html b/docs/commands/Repair.html index 19e506ca..0bce4305 100644 --- a/docs/commands/Repair.html +++ b/docs/commands/Repair.html @@ -321,7 +321,7 @@ generated by LDoc diff --git a/docs/commands/Reports.html b/docs/commands/Reports.html index c0f17772..cfe0a159 100644 --- a/docs/commands/Reports.html +++ b/docs/commands/Reports.html @@ -585,7 +585,7 @@ generated by LDoc diff --git a/docs/commands/Roles.html b/docs/commands/Roles.html index d9a1f285..cc0ee869 100644 --- a/docs/commands/Roles.html +++ b/docs/commands/Roles.html @@ -557,7 +557,7 @@ generated by LDoc diff --git a/docs/commands/Spawn.html b/docs/commands/Spawn.html index bb58d8a9..859247a4 100644 --- a/docs/commands/Spawn.html +++ b/docs/commands/Spawn.html @@ -389,7 +389,7 @@ generated by LDoc diff --git a/docs/commands/Tag.html b/docs/commands/Tag.html index 43fab495..dfdcbf48 100644 --- a/docs/commands/Tag.html +++ b/docs/commands/Tag.html @@ -443,7 +443,7 @@ generated by LDoc diff --git a/docs/commands/Teleport.html b/docs/commands/Teleport.html index 42089cc1..1848f1a0 100644 --- a/docs/commands/Teleport.html +++ b/docs/commands/Teleport.html @@ -484,7 +484,7 @@ generated by LDoc diff --git a/docs/commands/Warnings.html b/docs/commands/Warnings.html index 0bb7d855..eb9dd3ff 100644 --- a/docs/commands/Warnings.html +++ b/docs/commands/Warnings.html @@ -569,7 +569,7 @@ generated by LDoc diff --git a/docs/config.ld b/docs/config.ld index f5a7a308..7573fa6d 100644 --- a/docs/config.ld +++ b/docs/config.ld @@ -1,5 +1,5 @@ file = '../' -dir = '../doc' +dir = '../docs' project = 'ExpGaming Scenario' title = 'ExpGaming Scenario' description = 'Explosive Gaming\'s server scenario for 0.17' @@ -10,8 +10,8 @@ not_luadoc = true no_lua_ref = true template_escape = ">" topics = {"../README.md", "../LICENSE"} -style = '../doc' -template = '../doc' +style = '../docs' +template = '../docs' no_space_before_args = true merge=true diff --git a/docs/configs/Advanced-Start.html b/docs/configs/Advanced-Start.html index 46ef69a1..0c5783c8 100644 --- a/docs/configs/Advanced-Start.html +++ b/docs/configs/Advanced-Start.html @@ -506,7 +506,7 @@ generated by LDoc diff --git a/docs/configs/Bonuses.html b/docs/configs/Bonuses.html index e1806bce..52c1dcc5 100644 --- a/docs/configs/Bonuses.html +++ b/docs/configs/Bonuses.html @@ -237,7 +237,7 @@ generated by LDoc diff --git a/docs/configs/Chat-Reply.html b/docs/configs/Chat-Reply.html index c8ef6dfa..6594a2c5 100644 --- a/docs/configs/Chat-Reply.html +++ b/docs/configs/Chat-Reply.html @@ -485,7 +485,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Admin.html b/docs/configs/Commands-Auth-Admin.html index ffc290aa..d02099b4 100644 --- a/docs/configs/Commands-Auth-Admin.html +++ b/docs/configs/Commands-Auth-Admin.html @@ -294,7 +294,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Roles.html b/docs/configs/Commands-Auth-Roles.html index 1f3c18d9..45cda632 100644 --- a/docs/configs/Commands-Auth-Roles.html +++ b/docs/configs/Commands-Auth-Roles.html @@ -320,7 +320,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Runtime-Disable.html b/docs/configs/Commands-Auth-Runtime-Disable.html index f68dc361..1e2b5098 100644 --- a/docs/configs/Commands-Auth-Runtime-Disable.html +++ b/docs/configs/Commands-Auth-Runtime-Disable.html @@ -442,7 +442,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Parse-Roles.html b/docs/configs/Commands-Parse-Roles.html index d18424fa..47d2034e 100644 --- a/docs/configs/Commands-Parse-Roles.html +++ b/docs/configs/Commands-Parse-Roles.html @@ -354,7 +354,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Parse.html b/docs/configs/Commands-Parse.html index 2f413722..a1895ddb 100644 --- a/docs/configs/Commands-Parse.html +++ b/docs/configs/Commands-Parse.html @@ -338,7 +338,7 @@ see ./expcore/commands.lua for more details

generated by LDoc diff --git a/docs/configs/Compilatron.html b/docs/configs/Compilatron.html index 5bf4b1ba..64adcfc4 100644 --- a/docs/configs/Compilatron.html +++ b/docs/configs/Compilatron.html @@ -354,7 +354,7 @@ generated by LDoc diff --git a/docs/configs/Death-Logger.html b/docs/configs/Death-Logger.html index 76aec8f5..74805d6c 100644 --- a/docs/configs/Death-Logger.html +++ b/docs/configs/Death-Logger.html @@ -416,7 +416,7 @@ generated by LDoc diff --git a/docs/configs/Discord-Alerts.html b/docs/configs/Discord-Alerts.html index 03ca2c6d..07cba503 100644 --- a/docs/configs/Discord-Alerts.html +++ b/docs/configs/Discord-Alerts.html @@ -237,7 +237,7 @@ generated by LDoc diff --git a/docs/configs/File-Loader.html b/docs/configs/File-Loader.html index 58c755b1..58ae563e 100644 --- a/docs/configs/File-Loader.html +++ b/docs/configs/File-Loader.html @@ -240,7 +240,7 @@ generated by LDoc diff --git a/docs/configs/Permission-Groups.html b/docs/configs/Permission-Groups.html index 7043ae72..87281de1 100644 --- a/docs/configs/Permission-Groups.html +++ b/docs/configs/Permission-Groups.html @@ -295,7 +295,7 @@ generated by LDoc diff --git a/docs/configs/Player-List.html b/docs/configs/Player-List.html index c6e1c748..a64923b7 100644 --- a/docs/configs/Player-List.html +++ b/docs/configs/Player-List.html @@ -812,7 +812,7 @@ generated by LDoc diff --git a/docs/configs/Pollution-Grading.html b/docs/configs/Pollution-Grading.html index 9eb9892f..bb836f8f 100644 --- a/docs/configs/Pollution-Grading.html +++ b/docs/configs/Pollution-Grading.html @@ -384,7 +384,7 @@ generated by LDoc diff --git a/docs/configs/Popup-Messages.html b/docs/configs/Popup-Messages.html index 39690dd2..8834a58c 100644 --- a/docs/configs/Popup-Messages.html +++ b/docs/configs/Popup-Messages.html @@ -414,7 +414,7 @@ generated by LDoc diff --git a/docs/configs/Preset-Player-Colours.html b/docs/configs/Preset-Player-Colours.html index 9d37a9a8..d5e06589 100644 --- a/docs/configs/Preset-Player-Colours.html +++ b/docs/configs/Preset-Player-Colours.html @@ -324,7 +324,7 @@ generated by LDoc diff --git a/docs/configs/Repair.html b/docs/configs/Repair.html index 8625da88..741a2beb 100644 --- a/docs/configs/Repair.html +++ b/docs/configs/Repair.html @@ -414,7 +414,7 @@ generated by LDoc diff --git a/docs/configs/Rockets.html b/docs/configs/Rockets.html index 9be2580d..35e5d51b 100644 --- a/docs/configs/Rockets.html +++ b/docs/configs/Rockets.html @@ -834,7 +834,7 @@ generated by LDoc diff --git a/docs/configs/Roles.html b/docs/configs/Roles.html index c1aebec6..2fc9736f 100644 --- a/docs/configs/Roles.html +++ b/docs/configs/Roles.html @@ -292,7 +292,7 @@ generated by LDoc diff --git a/docs/configs/Science.html b/docs/configs/Science.html index d279267e..65bcb95e 100644 --- a/docs/configs/Science.html +++ b/docs/configs/Science.html @@ -354,7 +354,7 @@ generated by LDoc diff --git a/docs/configs/Scorched-Earth.html b/docs/configs/Scorched-Earth.html index 508bde53..9de50ddf 100644 --- a/docs/configs/Scorched-Earth.html +++ b/docs/configs/Scorched-Earth.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/configs/Spawn-Area.html b/docs/configs/Spawn-Area.html index 9b9a9a5a..d72010dc 100644 --- a/docs/configs/Spawn-Area.html +++ b/docs/configs/Spawn-Area.html @@ -744,7 +744,7 @@ generated by LDoc diff --git a/docs/configs/Tasks.html b/docs/configs/Tasks.html index 6072ae03..50107b1f 100644 --- a/docs/configs/Tasks.html +++ b/docs/configs/Tasks.html @@ -384,7 +384,7 @@ generated by LDoc diff --git a/docs/configs/Warnings.html b/docs/configs/Warnings.html index f3edf5aa..d02fb163 100644 --- a/docs/configs/Warnings.html +++ b/docs/configs/Warnings.html @@ -355,7 +355,7 @@ generated by LDoc diff --git a/docs/configs/Warps.html b/docs/configs/Warps.html index 8800c822..76a67c3e 100644 --- a/docs/configs/Warps.html +++ b/docs/configs/Warps.html @@ -684,7 +684,7 @@ generated by LDoc diff --git a/docs/control/Jail.html b/docs/control/Jail.html index 5f68c34b..8bf0dabd 100644 --- a/docs/control/Jail.html +++ b/docs/control/Jail.html @@ -1208,7 +1208,7 @@ generated by LDoc diff --git a/docs/control/Production.html b/docs/control/Production.html index ccfd8f5f..48c4e2d0 100644 --- a/docs/control/Production.html +++ b/docs/control/Production.html @@ -1329,7 +1329,7 @@ generated by LDoc diff --git a/docs/control/Reports.html b/docs/control/Reports.html index ddcdfb3e..ec69b942 100644 --- a/docs/control/Reports.html +++ b/docs/control/Reports.html @@ -1110,7 +1110,7 @@ generated by LDoc diff --git a/docs/control/Rockets.html b/docs/control/Rockets.html index 431f9815..cc03876e 100644 --- a/docs/control/Rockets.html +++ b/docs/control/Rockets.html @@ -984,7 +984,7 @@ generated by LDoc diff --git a/docs/control/Tasks.html b/docs/control/Tasks.html index 7fa706cc..c4ff0bac 100644 --- a/docs/control/Tasks.html +++ b/docs/control/Tasks.html @@ -1039,7 +1039,7 @@ generated by LDoc diff --git a/docs/control/Warnings.html b/docs/control/Warnings.html index c1ac81e7..09e669fd 100644 --- a/docs/control/Warnings.html +++ b/docs/control/Warnings.html @@ -1465,7 +1465,7 @@ generated by LDoc diff --git a/docs/control/Warps.html b/docs/control/Warps.html index 5fa18a14..1edc8de5 100644 --- a/docs/control/Warps.html +++ b/docs/control/Warps.html @@ -1413,7 +1413,7 @@ generated by LDoc diff --git a/docs/core/Commands.html b/docs/core/Commands.html index 683bf908..652d0f97 100644 --- a/docs/core/Commands.html +++ b/docs/core/Commands.html @@ -1972,7 +1972,7 @@ generated by LDoc diff --git a/docs/core/Common-Library.html b/docs/core/Common-Library.html index 44c6136e..f5b36e19 100644 --- a/docs/core/Common-Library.html +++ b/docs/core/Common-Library.html @@ -357,6 +357,10 @@ format_chat_player_name(player[, raw_string=false]) Returns the players name in the players color + + get_file_path([offset=0]) + Returns a desync safe file path for the current file + @@ -2396,6 +2400,64 @@ + + + + + + + +
+
+
+ # + get_file_path([offset=0]) +
+
+
+
+ +

Returns a desync safe file path for the current file

+

+ + + Parameters: + +
    + + + + + +
  • + + offset + + : + + (number) + + the offset in the stack to get, 0 is current file + + (default: 0) +
  • + + +
+ + + + + Returns: +
    +
  • + (string) + the file path +
  • +
+ + + @@ -2418,7 +2480,7 @@ generated by LDoc
diff --git a/docs/core/Gui.html b/docs/core/Gui.html index cc61f4e7..7377280e 100644 --- a/docs/core/Gui.html +++ b/docs/core/Gui.html @@ -10987,7 +10987,7 @@ generated by LDoc diff --git a/docs/core/Permissions-Groups.html b/docs/core/Permissions-Groups.html index f2878f57..28fee091 100644 --- a/docs/core/Permissions-Groups.html +++ b/docs/core/Permissions-Groups.html @@ -1432,7 +1432,7 @@ generated by LDoc diff --git a/docs/core/Roles.html b/docs/core/Roles.html index a6a994fb..0c417381 100644 --- a/docs/core/Roles.html +++ b/docs/core/Roles.html @@ -3152,7 +3152,7 @@ generated by LDoc diff --git a/docs/core/Store.html b/docs/core/Store.html index eb815f53..e9fb83db 100644 --- a/docs/core/Store.html +++ b/docs/core/Store.html @@ -234,73 +234,37 @@

Usage


----- Basic Use
-    -- At the most basic level this allows for the naming of locations to store in the global table, the second feature is that you are
-    -- able to listen for updates of this value, which means that when ever the set function is called it will trigger the update callback.
-
-    -- This may be useful when storing config values and when they get set you want to make sure it is taken care of, or maybe you want
-    -- to have a value that you can trigger an update of from different places.
-
-    -- This will register a new location called 'scenario.difficulty'
-    -- note that setting a start value is optional and we could take nil to mean normal
-    Store.register('scenario.difficulty',function(value)
-        game.print('The scenario difficulty has be set to: '..value)
-    end)
+-- The data store module is designed to be an alterative way to store data in the global table
+-- each piece of data is stored at a location and optional key of that location
+-- it is recomented that you use a local varible to store the location
+local scenario_difficuly = Store.uid_location()
+local team_scores = 'team-scores'
 
-    -- This will set the value in the store to 'hard' and will trigger the update callback which will print a message to the game
-    Store.set('scenario.difficulty','hard')
+-- Setting and getting data is then as simple as
+Store.set(scenario_difficuly,'Hard')
+Store.set(team_scores,game.player.force.name,20)
 
-    -- This will return 'hard'
-    Store.get('scenario.difficulty')
-

----- Using Children
-    -- One limitation of store is that all locations must be registered to avoid desyncs, to get round this issue "children" can be used.
-    -- When you set the value of a child it does not have its own update callback so rather the "parent" location which has been registered
-    -- will have its update value called with a second param of the name of that child.
+Store.get(scenario_difficuly) -- returns 'Hard'
+Store.get(team_scores,game.player.force.name) -- returns 20
 
-    -- This may be useful when you want a value of each player or force and since you cant register every player at the start you must use
-    -- the players name as the child name.
-
-    -- This will register the location 'scenario.score' where we plan to use force names as the child
-    Store.register('scenario.score',function(value,child)
-        game.print(child..' now has a score of '..value)
-    end)
+-- The reason for using stores over global is the abilty to watch for updates
+-- for stores to work you must register them, often at the end of the file
+-- note that storing a table value may cause issues as a key changing does not cause the set function to trigger
+Store.register(scenario_difficuly,function(value)
+    game.print('Scenario difficulty has been set to: '..value)
+end)
 
-    -- This will return nil, but will not error as children don't need to be registered
-    Store.get('scenario.score','player')
+Store.register(team_scores,function(value,key)
+    game.print('Team '..key..' now has a score of '..value)
+end)
 
-    -- This will set 'player' to have a value of 10 for 'scenario.score' and trigger the game message print
-    Store.set('scenario.score','player',10)
-
-    -- This would be the similar to Store.get however this will return the names of all the children
-    Store.get_children('scenario.score')
-

----- Using Sync
-    -- There is the option to use synced values which is the same as a normal value however you can combine this with an external script
-    -- which can read the output from 'script-output/log/store.log' and have it send rcon commands back to the game allowing for cross instance
-    -- syncing of values.
-
-    -- This may be useful when you want to have a value change effect multiple instances or even if you just want a database to store values so
-    -- you can sync data between map resets.
-
-    -- This example will register the location 'statistics.total-play-time' where we plan to use plan names as the child
-    -- note that the location must be the same across instances
-    Store.register('statistics.total-play-time',true,function(value,child)
-        game.print(child..' now has now played for '..value)
-    end)
-
-    -- Use of set and are all the same as non synced but you should include from_sync as true
-
-

----- Alternative method
-    -- Some people may prefer to use a variable rather than a string for formating reasons here is an example. Also for any times when
-    -- there will be little external input Store.uid_location() can be used to generate non conflicting locations, uid_location will also
-    -- be used if you give a nil location.
-
-    local store_game_speed =
-    Store.register(function(value)
-        game.print('The game speed has been set to: '..value)
-    end)
+-- This can be very powerful when working with data that can be changed for a number of locations +-- with this module you can enable any location to output its changes to a file +-- say we wanted team scores to be synced across servers or between saves +-- although you will need to set up a method of storing the data outside the game +Store.register(team_scores,true,function(value,key) + game.print('Team '..key..' now has a score of '..value) +end) @@ -333,33 +297,37 @@ + register([location][, synced=false][, callback]) + Registers a new location with an update callback which is triggered when the value updates + + + get(location[, key]) + Gets the value stored at a location, this location must be registered + + + set(location[, key], value[, from_sync=false]) + Sets the value at a location, this location must be registered + + + update(location[, key]) + Triggers the change handler manually + + + clear(location[, key][, from_sync=false]) + Sets the value at a location to nil, this location must be registered + + + get_keys(location) + Gets all non nil keys at a location, keys can be added and removed during runtime + this is similar to Store.get but will always return a table even if it is empty + + is_registered(location) Check for if a location is registered uid_location() Returns a unique name that can be used for a store - - - register([location][, synced][, callback]) - Registers a new location with an update callback which is triggered when the value updates - - - get(location[, child][, allow_unregistered=false]) - Gets the value stored at a location, this location must be registered - - - set(location[, child], value[, from_sync]) - Sets the value at a location, this location must be registered - - - clear(location[, child][, from_sync]) - Sets the value at a location to nil, this location must be registered - - - get_children(location) - Gets all non nil children at a location, children can be added and removed during runtime - this is similar to Store.get but will always return a table even if it is empty @@ -476,6 +444,495 @@
+ # + register([location][, synced=false][, callback]) +
+
+
+
+ +

Registers a new location with an update callback which is triggered when the value updates

+

+ + + Parameters: + +
    + + + + + +
  • + + location + + : + + (string) + + string a unique that points to the data, string used rather than token to allow migration + + (optional) +
  • + + + + + +
  • + + synced + + : + + (boolean) + + when true will output changes to a file so it can be synced + + (default: false) +
  • + + + + + +
  • + + callback + + : + + (function) + + when given the callback will be automatically registered to the update of the value + + (optional) +
  • + + +
+ + + + + Returns: +
    +
  • + (string) + the location that is being used +
  • +
+ + + + + + + + + +
+
+
+
+ # + get(location[, key]) +
+
+
+
+ +

Gets the value stored at a location, this location must be registered

+

+ + + Parameters: + +
    + + + + + +
  • + + location + + : + + (string) + + the location to get the data from + +
  • + + + + + +
  • + + key + + : + + (string) + + the key location if used + + (optional) +
  • + + +
+ + + + + Returns: +
    +
  • + (any) + the data which was stored at the location +
  • +
+ + + + + + + + + +
+
+
+
+ # + set(location[, key], value[, from_sync=false]) +
+
+
+
+ +

Sets the value at a location, this location must be registered

+

+ + + Parameters: + +
    + + + + + +
  • + + location + + : + + (string) + + the location to set the data to + +
  • + + + + + +
  • + + key + + : + + (string) + + the key location if used + + (optional) +
  • + + + + + +
  • + + value + + : + + (any) + + the new value to set at the location, value may be reverted if there is a watch callback, cant be nil + +
  • + + + + + +
  • + + from_sync + + : + + (boolean) + + set this true to avoid an output to the sync file + + (default: false) +
  • + + +
+ + + + + Returns: +
    +
  • + (boolean) + true if it was successful +
  • +
+ + + + + + + + + +
+
+
+
+ # + update(location[, key]) +
+
+
+
+ +

Triggers the change handler manually

+

+ + + Parameters: + +
    + + + + + +
  • + + location + + : + + (string) + + the location to set the data to + +
  • + + + + + +
  • + + key + + : + + (string) + + the key location if required + + (optional) +
  • + + +
+ + + + + + + + + + + + + +
+
+
+
+ # + clear(location[, key][, from_sync=false]) +
+
+
+
+ +

Sets the value at a location to nil, this location must be registered

+

+ + + Parameters: + +
    + + + + + +
  • + + location + + : + + (string) + + the location to set the data to + +
  • + + + + + +
  • + + key + + : + + (string) + + the key location if used + + (optional) +
  • + + + + + +
  • + + from_sync + + : + + (boolean) + + set this true to avoid an output to the sync file + + (default: false) +
  • + + +
+ + + + + Returns: +
    +
  • + (boolean) + true if it was successful +
  • +
+ + + + + + + + + +
+
+
+
+ # + get_keys(location) +
+
+
+
+ +

Gets all non nil keys at a location, keys can be added and removed during runtime + this is similar to Store.get but will always return a table even if it is empty

+

+ + + Parameters: + +
    + + + + + +
  • + + location + + : + + (string) + + the location to get the keys of + +
  • + + +
+ + + + + Returns: +
    +
  • + (table) + a table containing all the keys names +
  • +
+ + + + + + + + + +
+
+
+
# is_registered(location)
@@ -557,445 +1014,6 @@ - - - - - - - -
-
-
- # - register([location][, synced][, callback]) -
-
-
-
- -

Registers a new location with an update callback which is triggered when the value updates

-

- - - Parameters: - -
    - - - - - -
  • - - location - - : - - (string) - - string a unique that points to the data, string used rather than token to allow migration - - (optional) -
  • - - - - - -
  • - - synced - - : - - (boolean) - - when true will output changes to a file so it can be synced - - (optional) -
  • - - - - - -
  • - - callback - - : - - (function) - - when given the callback will be automatically registered to the update of the value - - (optional) -
  • - - -
- - - - - Returns: -
    -
  • - (string) - the location that is being used -
  • -
- - - - - - - - - -
-
-
-
- # - get(location[, child][, allow_unregistered=false]) -
-
-
-
- -

Gets the value stored at a location, this location must be registered

-

- - - Parameters: - -
    - - - - - -
  • - - location - - : - - (string) - - the location to get the data from - -
  • - - - - - -
  • - - child - - : - - (string) - - the child location if required - - (optional) -
  • - - - - - -
  • - - allow_unregistered - - : - - (boolean) - - when true no error is returned if the location is not registered - - (default: false) -
  • - - -
- - - - - Returns: -
    -
  • - (any) - the data which was stored at the location -
  • -
- - - - - - - - - -
-
-
-
- # - set(location[, child], value[, from_sync]) -
-
-
-
- -

Sets the value at a location, this location must be registered

-

- - - Parameters: - -
    - - - - - -
  • - - location - - : - - (string) - - the location to set the data to - -
  • - - - - - -
  • - - child - - : - - (string) - - the child location if required - - (optional) -
  • - - - - - -
  • - - value - - : - - (any) - - the new value to set at the location, value may be reverted if there is a watch callback, cant be nil - -
  • - - - - - -
  • - - from_sync - - : - - (boolean) - - set this true to avoid an output to the sync file - - (optional) -
  • - - -
- - - - - Returns: -
    -
  • - (boolean) - true if it was successful -
  • -
- - - - - - - - - -
-
-
-
- # - clear(location[, child][, from_sync]) -
-
-
-
- -

Sets the value at a location to nil, this location must be registered

-

- - - Parameters: - -
    - - - - - -
  • - - location - - : - - (string) - - the location to set the data to - -
  • - - - - - -
  • - - child - - : - - (string) - - the child location if required - - (optional) -
  • - - - - - -
  • - - from_sync - - : - - (boolean) - - set this true to avoid an output to the sync file - - (optional) -
  • - - -
- - - - - Returns: -
    -
  • - (boolean) - true if it was successful -
  • -
- - - - - - - - - -
-
-
-
- # - get_children(location) -
-
-
-
- -

Gets all non nil children at a location, children can be added and removed during runtime - this is similar to Store.get but will always return a table even if it is empty

-

- - - Parameters: - -
    - - - - - -
  • - - location - - : - - (string) - - the location to get the children of - -
  • - - -
- - - - - Returns: -
    -
  • - (table) - a table containing all the children names -
  • -
- - - @@ -1018,7 +1036,7 @@ generated by LDoc
diff --git a/docs/core/Sudo.html b/docs/core/Sudo.html index b57f5340..f1b715fc 100644 --- a/docs/core/Sudo.html +++ b/docs/core/Sudo.html @@ -544,7 +544,7 @@ generated by LDoc diff --git a/docs/guis/Player-List.html b/docs/guis/Player-List.html index 15f04345..36ffe125 100644 --- a/docs/guis/Player-List.html +++ b/docs/guis/Player-List.html @@ -626,7 +626,7 @@ generated by LDoc diff --git a/docs/guis/Rocket-Info.html b/docs/guis/Rocket-Info.html index a0c8e321..626e32c8 100644 --- a/docs/guis/Rocket-Info.html +++ b/docs/guis/Rocket-Info.html @@ -629,7 +629,7 @@ generated by LDoc diff --git a/docs/guis/Science-Info.html b/docs/guis/Science-Info.html index 46a7c6ba..7f36a267 100644 --- a/docs/guis/Science-Info.html +++ b/docs/guis/Science-Info.html @@ -449,7 +449,7 @@ generated by LDoc diff --git a/docs/guis/Task-List.html b/docs/guis/Task-List.html index 044ce929..bb449941 100644 --- a/docs/guis/Task-List.html +++ b/docs/guis/Task-List.html @@ -632,7 +632,7 @@ generated by LDoc diff --git a/docs/guis/Warps-List.html b/docs/guis/Warps-List.html index 70ad4fae..c015334b 100644 --- a/docs/guis/Warps-List.html +++ b/docs/guis/Warps-List.html @@ -837,7 +837,7 @@ generated by LDoc diff --git a/docs/index.html b/docs/index.html index 8d881fce..29d95487 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 2e7d23d6..be3816d0 100644 --- a/docs/modules/control.html +++ b/docs/modules/control.html @@ -351,7 +351,7 @@ generated by LDoc diff --git a/docs/modules/utils.alien_evolution_progress.html b/docs/modules/utils.alien_evolution_progress.html index 511ede25..e4509aa0 100644 --- a/docs/modules/utils.alien_evolution_progress.html +++ b/docs/modules/utils.alien_evolution_progress.html @@ -419,7 +419,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 415f1982..fd537648 100644 --- a/docs/modules/utils.core.html +++ b/docs/modules/utils.core.html @@ -1164,7 +1164,7 @@ generated by LDoc diff --git a/docs/modules/utils.debug.html b/docs/modules/utils.debug.html index 126749ed..498ae103 100644 --- a/docs/modules/utils.debug.html +++ b/docs/modules/utils.debug.html @@ -654,7 +654,7 @@ generated by LDoc diff --git a/docs/modules/utils.dump_env.html b/docs/modules/utils.dump_env.html index a4994d60..10112456 100644 --- a/docs/modules/utils.dump_env.html +++ b/docs/modules/utils.dump_env.html @@ -323,7 +323,7 @@ generated by LDoc diff --git a/docs/modules/utils.event.html b/docs/modules/utils.event.html index 7043beae..dfe1b7a1 100644 --- a/docs/modules/utils.event.html +++ b/docs/modules/utils.event.html @@ -1292,7 +1292,7 @@ generated by LDoc diff --git a/docs/modules/utils.event_core.html b/docs/modules/utils.event_core.html index 2fc2bf78..8f1b30ef 100644 --- a/docs/modules/utils.event_core.html +++ b/docs/modules/utils.event_core.html @@ -434,7 +434,7 @@ generated by LDoc diff --git a/docs/modules/utils.math.html b/docs/modules/utils.math.html index 3f4d0920..51094ba3 100644 --- a/docs/modules/utils.math.html +++ b/docs/modules/utils.math.html @@ -338,7 +338,7 @@ generated by LDoc diff --git a/docs/modules/utils.recipe_locker.html b/docs/modules/utils.recipe_locker.html index 45474def..0c008edd 100644 --- a/docs/modules/utils.recipe_locker.html +++ b/docs/modules/utils.recipe_locker.html @@ -441,7 +441,7 @@ generated by LDoc diff --git a/docs/modules/utils.state_machine.html b/docs/modules/utils.state_machine.html index b15d99e6..675a9678 100644 --- a/docs/modules/utils.state_machine.html +++ b/docs/modules/utils.state_machine.html @@ -752,7 +752,7 @@ generated by LDoc diff --git a/docs/modules/utils.table.html b/docs/modules/utils.table.html index 499ad887..4d606241 100644 --- a/docs/modules/utils.table.html +++ b/docs/modules/utils.table.html @@ -1382,7 +1382,7 @@ generated by LDoc diff --git a/docs/modules/utils.task.html b/docs/modules/utils.task.html index e84aa88a..b1ec35f6 100644 --- a/docs/modules/utils.task.html +++ b/docs/modules/utils.task.html @@ -651,7 +651,7 @@ generated by LDoc diff --git a/docs/modules/utils.timestamp.html b/docs/modules/utils.timestamp.html index 201f2509..0cedb708 100644 --- a/docs/modules/utils.timestamp.html +++ b/docs/modules/utils.timestamp.html @@ -442,7 +442,7 @@ generated by LDoc diff --git a/docs/topics/license.html b/docs/topics/license.html index 7843e890..fe2b756b 100644 --- a/docs/topics/license.html +++ b/docs/topics/license.html @@ -789,7 +789,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 31de4f66..89cfb497 100644 --- a/docs/topics/readme.md.html +++ b/docs/topics/readme.md.html @@ -248,7 +248,8 @@

## Releases

| Scenario Version* | Version Name | Factorio Version** | |---|---|---| -| [v5.7][s5.8] | Home and Chat Bot | [v0.17.47][f0.17.49] | +| [v5.9][s5.9] | Control Modules and Documentation | [v0.17.63][f0.17.63] | +| [v5.8][s5.8] | Home and Chat Bot | [v0.17.47][f0.17.49] | | [v5.7][s5.7] | Warp System | [v0.17.47][f0.17.47] | | [v5.6][s5.6] | Information Guis | [v0.17.44][f0.17.44] | | [v5.5][s5.5] | Gui System | [v0.17.43][f0.17.43] | @@ -264,7 +265,8 @@ | [v0.1][s0.1] | First Tracked Version | [v0.14][f0.14] |

\* Scenario patch versions have been omitted.

\*\* Factorio versions show the version they were made for, often the minimum requirement. -

[s5.8]: https://github.com/explosivegaming/scenario/releases/tag/5.8.0 +

[s5.9]: https://github.com/explosivegaming/scenario/releases/tag/5.9.0 +[s5.8]: https://github.com/explosivegaming/scenario/releases/tag/5.8.0 [s5.7]: https://github.com/explosivegaming/scenario/releases/tag/5.7.0 [s5.6]: https://github.com/explosivegaming/scenario/releases/tag/5.6.0 [s5.5]: https://github.com/explosivegaming/scenario/releases/tag/5.5.0 @@ -278,7 +280,8 @@ [s2.0]: https://github.com/explosivegaming/scenario/releases/tag/v2.0 [s1.0]: https://github.com/explosivegaming/scenario/releases/tag/v1.0 [s0.1]: https://github.com/explosivegaming/scenario/releases/tag/v0.1 -

[f0.17.49]: https://wiki.factorio.com/Version_history/0.17.0#0.17.49 +

[f0.17.63]: https://wiki.factorio.com/Version_history/0.17.0#0.17.63 +[f0.17.49]: https://wiki.factorio.com/Version_history/0.17.0#0.17.49 [f0.17.47]: https://wiki.factorio.com/Version_history/0.17.0#0.17.47 [f0.17.44]: https://wiki.factorio.com/Version_history/0.17.0#0.17.44 [f0.17.43]: https://wiki.factorio.com/Version_history/0.17.0#0.17.43 @@ -329,7 +332,7 @@ generated by LDoc

diff --git a/expcore/common.lua b/expcore/common.lua index 19cd711b..8efb7d1b 100644 --- a/expcore/common.lua +++ b/expcore/common.lua @@ -611,4 +611,12 @@ function Common.format_chat_player_name(player,raw_string) end end +--- Returns a desync safe file path for the current file +-- @tparam[opt=0] number offset the offset in the stack to get, 0 is current file +-- @treturn string the file path +function Common.get_file_path(offset) + offset = offset or 0 + return debug.getinfo(offset+2, 'S').source:match('^.+/currently%-playing/(.+)$'):sub(1, -5) +end + return Common \ No newline at end of file diff --git a/expcore/gui/test.lua b/expcore/gui/test.lua index 2e25c61b..38319c3f 100644 --- a/expcore/gui/test.lua +++ b/expcore/gui/test.lua @@ -650,7 +650,7 @@ end) Event.add(defines.events.on_tick,function() progressbar_one:increment() progressbar_three:decrement() - local categories = Store.get_children(progressbar_two.store) + local categories = Store.get_keys(progressbar_two.store) for _,category in pairs(categories) do progressbar_two:increment(1,category) end diff --git a/expcore/store.lua b/expcore/store.lua index 83d2ed26..6bc00f4b 100644 --- a/expcore/store.lua +++ b/expcore/store.lua @@ -4,119 +4,68 @@ @alias Store @usage ----- Basic Use - -- At the most basic level this allows for the naming of locations to store in the global table, the second feature is that you are - -- able to listen for updates of this value, which means that when ever the set function is called it will trigger the update callback. +-- The data store module is designed to be an alterative way to store data in the global table +-- each piece of data is stored at a location and optional key of that location +-- it is recomented that you use a local varible to store the location +local scenario_difficuly = Store.uid_location() +local team_scores = 'team-scores' - -- This may be useful when storing config values and when they get set you want to make sure it is taken care of, or maybe you want - -- to have a value that you can trigger an update of from different places. +-- Setting and getting data is then as simple as +Store.set(scenario_difficuly,'Hard') +Store.set(team_scores,game.player.force.name,20) - -- This will register a new location called 'scenario.difficulty' - -- note that setting a start value is optional and we could take nil to mean normal - Store.register('scenario.difficulty',function(value) - game.print('The scenario difficulty has be set to: '..value) - end) +Store.get(scenario_difficuly) -- returns 'Hard' +Store.get(team_scores,game.player.force.name) -- returns 20 - -- This will set the value in the store to 'hard' and will trigger the update callback which will print a message to the game - Store.set('scenario.difficulty','hard') +-- The reason for using stores over global is the abilty to watch for updates +-- for stores to work you must register them, often at the end of the file +-- note that storing a table value may cause issues as a key changing does not cause the set function to trigger +Store.register(scenario_difficuly,function(value) + game.print('Scenario difficulty has been set to: '..value) +end) - -- This will return 'hard' - Store.get('scenario.difficulty') +Store.register(team_scores,function(value,key) + game.print('Team '..key..' now has a score of '..value) +end) - @usage ----- Using Children - -- One limitation of store is that all locations must be registered to avoid desyncs, to get round this issue "children" can be used. - -- When you set the value of a child it does not have its own update callback so rather the "parent" location which has been registered - -- will have its update value called with a second param of the name of that child. - - -- This may be useful when you want a value of each player or force and since you cant register every player at the start you must use - -- the players name as the child name. - - -- This will register the location 'scenario.score' where we plan to use force names as the child - Store.register('scenario.score',function(value,child) - game.print(child..' now has a score of '..value) - end) - - -- This will return nil, but will not error as children don't need to be registered - Store.get('scenario.score','player') - - -- This will set 'player' to have a value of 10 for 'scenario.score' and trigger the game message print - Store.set('scenario.score','player',10) - - -- This would be the similar to Store.get however this will return the names of all the children - Store.get_children('scenario.score') - - @usage ----- Using Sync - -- There is the option to use synced values which is the same as a normal value however you can combine this with an external script - -- which can read the output from 'script-output/log/store.log' and have it send rcon commands back to the game allowing for cross instance - -- syncing of values. - - -- This may be useful when you want to have a value change effect multiple instances or even if you just want a database to store values so - -- you can sync data between map resets. - - -- This example will register the location 'statistics.total-play-time' where we plan to use plan names as the child - -- note that the location must be the same across instances - Store.register('statistics.total-play-time',true,function(value,child) - game.print(child..' now has now played for '..value) - end) - - -- Use of set and are all the same as non synced but you should include from_sync as true - - @usage ----- Alternative method - -- Some people may prefer to use a variable rather than a string for formating reasons here is an example. Also for any times when - -- there will be little external input Store.uid_location() can be used to generate non conflicting locations, uid_location will also - -- be used if you give a nil location. - - local store_game_speed = - Store.register(function(value) - game.print('The game speed has been set to: '..value) - end) +-- This can be very powerful when working with data that can be changed for a number of locations +-- with this module you can enable any location to output its changes to a file +-- say we wanted team scores to be synced across servers or between saves +-- although you will need to set up a method of storing the data outside the game +Store.register(team_scores,true,function(value,key) + game.print('Team '..key..' now has a score of '..value) +end) ]] local Global = require 'utils.global' --- @dep utils.global local Event = require 'utils.event' --- @dep utils.event -local table_keys,write_json = ext_require('expcore.common','table_keys','write_json') --- @dep expcore.common +local table_keys,write_json,get_file_path = ext_require('expcore.common','table_keys','write_json','get_file_path') --- @dep expcore.common local Token = require 'utils.token' --- @dep utils.token local Store = { - data={}, registered={}, synced={}, callbacks={}, events = { - on_value_update=script.generate_event_name() + on_value_changed=script.generate_event_name() } } +local store_data = {} Global.register(Store.data,function(tbl) - Store.data = tbl + store_data = tbl end) local function error_not_table(value) if type(value) ~= 'table' then - error('Location is not a table can not use child locations',3) + error('Location is not a table can not use key locations',3) end end ---- Check for if a location is registered --- @tparam string location the location to test for --- @treturn boolean true if registered -function Store.is_registered(location) - return Store.registered[location] -end - ---- Returns a unique name that can be used for a store --- @treturn string a unique name -function Store.uid_location() - return tostring(Token.uid()) -end - --- Registers a new location with an update callback which is triggered when the value updates -- @tparam[opt] string location string a unique that points to the data, string used rather than token to allow migration --- @tparam[opt] boolean synced when true will output changes to a file so it can be synced +-- @tparam[opt=false] boolean synced when true will output changes to a file so it can be synced -- @tparam[opt] function callback when given the callback will be automatically registered to the update of the value -- @treturn string the location that is being used function Store.register(location,synced,callback) @@ -136,10 +85,10 @@ function Store.register(location,synced,callback) location = type(location) == 'string' and location or Store.uid_location() if Store.registered[location] then - return error('Location is already registered', 2) + return error('Location '..location..' is already registered by '..Store.registered[location], 2) end - Store.registered[location] = true + Store.registered[location] = get_file_path(1) Store.synced[location] = synced and true or nil Store.callbacks[location] = callback or nil @@ -148,18 +97,17 @@ end --- Gets the value stored at a location, this location must be registered -- @tparam string location the location to get the data from --- @tparam[opt] string child the child location if required --- @tparam[opt=false] boolean allow_unregistered when true no error is returned if the location is not registered +-- @tparam[opt] string key the key location if used -- @treturn any the data which was stored at the location -function Store.get(location,child,allow_unregistered) - if not Store.callbacks[location] and not allow_unregistered then +function Store.get(location,key) + if not Store.registered[location] then return error('Location is not registered', 2) end - local data = Store.data[location] - if child and data then + local data = store_data[location] + if key and data then error_not_table(data) - return data[child] + return data[key] end return data @@ -167,94 +115,120 @@ end --- Sets the value at a location, this location must be registered -- @tparam string location the location to set the data to --- @tparam[opt] string child the child location if required +-- @tparam[opt] string key the key location if used -- @tparam any value the new value to set at the location, value may be reverted if there is a watch callback, cant be nil --- @tparam[opt] boolean from_sync set this true to avoid an output to the sync file +-- @tparam[opt=false] boolean from_sync set this true to avoid an output to the sync file -- @treturn boolean true if it was successful -function Store.set(location,child,value,from_sync) +function Store.set(location,key,value,from_sync) if not Store.callbacks[location] then return error('Location is not registered', 2) end - if child == nil or value == nil then - value = child or value - child = nil + if key == nil or value == nil then + value = key or value + key = nil end - local data = Store.data - if child then - data = data[location] + if key then + local data = store_data[location] if not data then data = {} - Store.data[location] = data + store_data[location] = data end error_not_table(data) - data[child] = value + data[key] = value else - data[location] = value + store_data[location] = value end - script.raise_event(Store.events.on_value_update,{ + script.raise_event(Store.events.on_value_changed,{ tick=game.tick, location=location, - child=child, + key=key, value=value, - from_sync=from_sync + from_sync=from_sync or false }) return true end +--- Triggers the change handler manually +-- @tparam string location the location to set the data to +-- @tparam[opt] string key the key location if required +function Store.update(location,key) + local value = Store.get(location,key) + script.raise_event(Store.events.on_value_changed,{ + tick=game.tick, + location=location, + key=key, + value=value, + from_sync=false + }) +end + + --- Sets the value at a location to nil, this location must be registered -- @tparam string location the location to set the data to --- @tparam[opt] string child the child location if required --- @tparam[opt] boolean from_sync set this true to avoid an output to the sync file +-- @tparam[opt] string key the key location if used +-- @tparam[opt=false] boolean from_sync set this true to avoid an output to the sync file -- @treturn boolean true if it was successful -function Store.clear(location,child,from_sync) +function Store.clear(location,key,from_sync) if not Store.callbacks[location] then return error('Location is not registered', 2) end - local data = Store.data - if child then - data = data[location] + if key then + local data = store_data[location] if not data then return end error_not_table(data) - data[child] = nil + data[key] = nil else - data[location] = nil + store_data[location] = nil end - script.raise_event(Store.events.on_value_update,{ + script.raise_event(Store.events.on_value_changed,{ tick=game.tick, location=location, - child=child, - from_sync=from_sync + key=key, + from_sync=from_sync or false }) return true end ---- Gets all non nil children at a location, children can be added and removed during runtime +--- Gets all non nil keys at a location, keys can be added and removed during runtime -- this is similar to Store.get but will always return a table even if it is empty --- @tparam string location the location to get the children of --- @treturn table a table containing all the children names -function Store.get_children(location) +-- @tparam string location the location to get the keys of +-- @treturn table a table containing all the keys names +function Store.get_keys(location) local data = Store.get(location) return type(data) == 'table' and table_keys(data) or {} end +--- Check for if a location is registered +-- @tparam string location the location to test for +-- @treturn boolean true if registered +function Store.is_registered(location) + return Store.registered[location] +end + +--- Returns a unique name that can be used for a store +-- @treturn string a unique name +function Store.uid_location() + return tostring(Token.uid()) +end + -- Handles syncing -Event.add(Store.events.on_value_update,function(event) +Event.add(Store.events.on_value_changed,function(event) if Store.callbacks[event.location] then - Store.callbacks[event.location](event.value,event.child) + Store.callbacks[event.location](event.value,event.key) end if not event.from_sync and Store.synced[event.location] then write_json('log/store.log',{ tick=event.tick, location=event.location, - child=event.child, + key=event.key, value=event.value, }) end diff --git a/modules/commands/interface.lua b/modules/commands/interface.lua index 51b20ebf..cd6263b1 100644 --- a/modules/commands/interface.lua +++ b/modules/commands/interface.lua @@ -16,7 +16,7 @@ local interface_modules = { ['Group']='expcore.permission_groups', ['Roles']='expcore.roles', ['Store']='expcore.store', - ['Gui']='expcore.gui', + --['Gui']='expcore.gui', ['Sudo']='expcore.sudo' } diff --git a/modules/gui/warp-list.lua b/modules/gui/warp-list.lua index 4e06b335..9fb9e390 100644 --- a/modules/gui/warp-list.lua +++ b/modules/gui/warp-list.lua @@ -478,7 +478,7 @@ end) local r2 = config.activation_range^2 local rs2 = config.spawn_activation_range^2 Event.on_nth_tick(math.floor(60/config.update_smoothing),function() - local categories = Store.get_children(warp_timer.store) + local categories = Store.get_keys(warp_timer.store) for _,category in pairs(categories) do warp_timer:increment(1,category) end From e05edf5fefee6969a2c42d1a506e4c5f61f41b6a Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sat, 24 Aug 2019 00:02:41 +0100 Subject: [PATCH 02/26] Prototype Done? --- expcore/gui.lua | 283 +---------- expcore/gui/concepts/center.lua | 198 -------- expcore/gui/concepts/left.lua | 322 ------------- expcore/gui/concepts/popups.lua | 230 --------- expcore/gui/concepts/toolbar.lua | 114 ----- expcore/gui/core.lua | 368 +------------- expcore/gui/elements/buttons.lua | 128 ----- expcore/gui/elements/checkbox.lua | 252 ---------- expcore/gui/elements/dropdown.lua | 187 -------- expcore/gui/elements/elem-button.lua | 99 ---- expcore/gui/elements/progress-bar.lua | 390 --------------- expcore/gui/elements/slider.lua | 177 ------- expcore/gui/elements/text.lua | 149 ------ expcore/gui/instances.lua | 235 --------- expcore/gui/prototype.lua | 475 +++++++----------- expcore/gui/test.lua | 663 -------------------------- 16 files changed, 196 insertions(+), 4074 deletions(-) delete mode 100644 expcore/gui/concepts/center.lua delete mode 100644 expcore/gui/concepts/left.lua delete mode 100644 expcore/gui/concepts/popups.lua delete mode 100644 expcore/gui/concepts/toolbar.lua delete mode 100644 expcore/gui/elements/buttons.lua delete mode 100644 expcore/gui/elements/checkbox.lua delete mode 100644 expcore/gui/elements/dropdown.lua delete mode 100644 expcore/gui/elements/elem-button.lua delete mode 100644 expcore/gui/elements/progress-bar.lua delete mode 100644 expcore/gui/elements/slider.lua delete mode 100644 expcore/gui/elements/text.lua delete mode 100644 expcore/gui/instances.lua delete mode 100644 expcore/gui/test.lua diff --git a/expcore/gui.lua b/expcore/gui.lua index 6cf395f1..80b400b3 100644 --- a/expcore/gui.lua +++ b/expcore/gui.lua @@ -1,284 +1,5 @@ ---[[-- Core Module - Gui - - This file is used to require all the different elements of the gui module - - each module has an outline here but for more details see their separate files in ./gui - - please read the files for more documentation that cant be shown here - - please note there is a rework planned but not started - @core Gui - @alias Gui -]] +--- This file combines all the other gui files -local Gui = require 'expcore.gui.core' --- @dep expcore.gui.core - ---[[ - Core - - Gui.new_define(prototype) --- Used internally to create new element defines from a class prototype - Gui.draw(name,element) --- Draws a copy of the element define to the parent element, see draw_to - - Gui.categorize_by_player(element) --- A categorize function to be used with add_store, each player has their own value - Gui.categorize_by_force(element) --- A categorize function to be used with add_store, each force has its own value - Gui.categorize_by_surface(element) --- A categorize function to be used with add_store, each surface has its own value - - Gui.toggle_enabled(element) --- Will toggle the enabled state of an element - Gui.toggle_visible(element) --- Will toggle the visibility of an element - Gui.set_padding(element,up,down,left,right) --- Sets the padding for a gui element - Gui.set_padding_style(style,up,down,left,right) --- Sets the padding for a gui style - Gui.create_alignment(element,flow_name) --- Allows the creation of a right align flow to place elements into - Gui.destroy_if_valid(element) --- Destroys an element but tests for it being present and valid first - Gui.create_scroll_table(element,table_size,maximal_height,name) --- Creates a scroll area with a table inside, table can be any size - Gui.create_header(element,caption,tooltip,right_align,name) --- Creates a header section with a label and button area - - Prototype Constructor - - Constructor.event(event_name) --- Creates a new function to add functions to an event handler - Constructor.extend(new_prototype) --- Extents a prototype with the base functions of all gui prototypes, no metatables - Constructor.store(sync,callback) --- Creates a new function which adds a store to a gui define - Constructor.setter(value_type,key,second_key) --- Creates a setter function that checks the type when a value is set - - Base Prototype - - Prototype:uid() --- Gets the uid for the element define - Prototype:debug_name(value) --- Sets a debug alias for the define - Prototype:set_caption(value) --- Sets the caption for the element define - Prototype:set_tooltip(value) --- Sets the tooltip for the element define - Prototype:set_style(style,callback) --- Sets the style for the element define - Prototype:set_embedded_flow(state) --- Sets the element to be drawn inside a nameless flow, can be given a name using a function - - Prototype:set_pre_authenticator --- Sets an authenticator that blocks the draw function if check fails - Prototype:set_post_authenticator --- Sets an authenticator that disables the element if check fails - - Prototype:raise_event(event_name,...) --- Raises a custom event for this define, any number of params can be given - Prototype:draw_to(element,...) --- The main function for defines, when called will draw an instance of this define to the given element - - Prototype:get_store(category) --- Gets the value in this elements store, category needed if categorize function used - Prototype:set_store(category,value) --- Sets the value in this elements store, category needed if categorize function used - Prototype:clear_store(category) --- Sets the value in this elements store to nil, category needed if categorize function used -]] - -local Instances = require 'expcore.gui.instances' --- @dep expcore.gui.instances -Gui.new_instance_group = Instances.registers -Gui.get_instances = Instances.get_elements -Gui.add_instance = Instances.get_elements -Gui.update_instances = Instances.apply_to_elements -Gui.classes.instances = Instances ---[[ - Instances.has_categories(name) --- Returns if a instance group has a categorise function; must be registered - Instances.is_registered(name) --- Returns if the given name is a registered instance group - Instances.register(name,categorise) --- Registers the name of an instance group to allow for storing element instances - - Instances.add_element(name,element) --- Adds an element to the instance group under the correct category; must be registered - Instances.get_elements_raw(name,category) --- Gets all element instances without first removing any invalid ones; used internally and must be registered - Instances.get_valid_elements(name,category,callback) --- Gets all valid element instances and has the option of running a callback on those that are valid - - Instances.unregistered_add_element(name,category,element) --- A version of add_element that does not require the group to be registered - Instances.unregistered_get_elements(name,category,callback) --- A version of get_elements that does not require the group to be registered -]] - -local Button = require 'expcore.gui.elements.buttons' --- @dep expcore.gui.elements.buttons -Gui.new_button = Button.new_button -Gui.classes.button = Button ---[[ - Button.new_button(name) --- Creates a new button element define - - Button._prototype:on_click(player,element) --- Registers a handler for when the button is clicked - Button._prototype:on_left_click(player,element) --- Registers a handler for when the button is clicked with the left mouse button - Button._prototype:on_right_click(player,element) --- Registers a handler for when the button is clicked with the right mouse button - - Button._prototype:set_sprites(sprite,hovered_sprite,clicked_sprite) --- Adds sprites to a button making it a sprite button - Button._prototype:set_click_filter(filter,...) --- Adds a click / mouse button filter to the button - Button._prototype:set_key_filter(filter,...) --- Adds a control key filter to the button -]] - -local Checkbox = require 'expcore.gui.elements.checkbox' --- @dep expcore.gui.elements.checkbox -Gui.new_checkbox = Checkbox.new_checkbox -Gui.new_radiobutton = Checkbox.new_radiobutton -Gui.new_radiobutton_option_set = Checkbox.new_option_set -Gui.draw_option_set = Checkbox.draw_option_set -Gui.classes.checkbox = Checkbox ---[[ - Checkbox.new_checkbox(name) --- Creates a new checkbox element define - Checkbox._prototype_checkbox:on_element_update(callback) --- Registers a handler for when an element instance updates - Checkbox._prototype_checkbox:on_store_update(callback) --- Registers a handler for when the stored value updates - - Checkbox.new_radiobutton(name) --- Creates a new radiobutton element define - Checkbox._prototype_radiobutton:on_element_update(callback) --- Registers a handler for when an element instance updates - Checkbox._prototype_radiobutton:on_store_update(callback) --- Registers a handler for when the stored value updates - Checkbox._prototype_radiobutton:add_as_option(option_set,option_name) --- Adds this radiobutton to be an option in the given option set (only one can be true at a time) - - Checkbox.new_option_set(name,callback,categorize) --- Registers a new option set that can be linked to radiobuttons (only one can be true at a time) - Checkbox.draw_option_set(name,element) --- Draws all radiobuttons that are part of an option set at once (Gui.draw will not work) - - Checkbox.reset_radiobutton(element,exclude,recursive) --- Sets all radiobuttons in a element to false (unless excluded) and can act recursively -]] - -local Dropdown = require 'expcore.gui.elements.dropdown' --- @dep expcore.gui.elements.dropdown -Gui.new_dropdown = Dropdown.new_dropdown -Gui.new_list_box = Dropdown.new_list_box -Gui.classes.dropdown = Dropdown ---[[ - Dropdown.new_dropdown(name) --- Creates a new dropdown element define - Dropdown.new_list_box(name) --- Creates a new list box element define - - Dropdown._prototype:on_element_update(callback) --- Registers a handler for when an element instance updates - Dropdown._prototype:on_store_update(callback) --- Registers a handler for when the stored value updates - - Dropdown._prototype:new_static_options(options,...) --- Adds new static options to the dropdown which will trigger the general callback - Dropdown._prototype:new_dynamic_options(callback) --- Adds a callback which should return a table of values to be added as options for the dropdown (appended after static options) - Dropdown._prototype:add_option_callback(option,callback) --- Adds a case specific callback which will only run when that option is selected (general case still triggered) - - Dropdown.select_value(element,value) --- Selects the option from a dropdown or list box given the value rather than key - Dropdown.get_selected_value(element) --- Returns the currently selected value rather than index -]] - -local Slider = require 'expcore.gui.elements.slider' --- @dep expcore.gui.elements.slider -Gui.new_slider = Slider.new_slider -Gui.classes.slider = Slider ---[[ - Slider.new_slider(name) --- Creates a new slider element define - - Slider._prototype:on_element_update(callback) --- Registers a handler for when an element instance updates - Slider._prototype:on_store_update(callback) --- Registers a handler for when the stored value updates - - Slider._prototype:set_range(min,max) --- Sets the range of a slider, if not used will use default values for a slider - Slider._prototype:draw_label(element) --- Draws a new label and links its value to the value of this slider, if no store then it will only show one value per player - Slider._prototype:enable_auto_draw_label(state) --- Enables auto draw of the label, the label will share the same parent element as the slider -]] - -local Text = require 'expcore.gui.elements.text' --- @dep expcore.gui.elements.text -Gui.new_text_filed = Text.new_text_field -Gui.new_text_box = Text.new_text_box -Gui.classes.text = Text ---[[ - Text.new_text_field(name) --- Creates a new text field element define - Text._prototype_field:on_element_update(callback) --- Registers a handler for when an element instance updates - Text._prototype_field:on_store_update(callback) --- Registers a handler for when the stored value updates - - Text.new_text_box(name) --- Creates a new text box element define - Text._prototype_field:on_element_update(callback) --- Registers a handler for when an element instance updates - Text._prototype_field:on_store_update(callback) --- Registers a handler for when the stored value updates - Text._prototype_box:set_selectable(state) --- Sets the text box to be selectable - Text._prototype_box:set_word_wrap(state) --- Sets the text box to have word wrap - Text._prototype_box:set_read_only(state) --- Sets the text box to be read only -]] - -local ElemButton = require 'expcore.gui.elements.elem-button' --- @dep expcore.gui.elements.elem-button -Gui.new_elem_button = ElemButton.new_elem_button -Gui.classes.elem_button = ElemButton ---[[ - ElemButton.new_elem_button(name) --- Creates a new elem button element define - - ElemButton._prototype:on_element_update(callback) --- Registers a handler for when an element instance updates - ElemButton._prototype:on_store_update(callback) --- Registers a handler for when the stored value updates - - ElemButton._prototype:set_type(type) --- Sets the type of the elem button, the type is required so this must be called at least once - ElemButton._prototype:set_default(value) --- Sets the default value for the elem button, this may be a function or a string -]] - -local ProgressBar = require 'expcore.gui.elements.progress-bar' --- @dep expcore.gui.elements.progress-bar -Gui.new_progressbar = ProgressBar.new_progressbar -Gui.set_progressbar_maximum = ProgressBar.set_maximum -Gui.increment_progressbar = ProgressBar.increment -Gui.decrement_progressbar = ProgressBar.decrement -Gui.classes.progressbar = ProgressBar ---[[ - ProgressBar.set_maximum(element,amount,count_down) --- Sets the maximum value that represents the end value of the progress bar - ProgressBar.increment(element,amount) --- Increases the value of the progressbar, if a define is given all of its instances are incremented - ProgressBar.decrement(element,amount) --- Decreases the value of the progressbar, if a define is given all of its instances are decreased - - ProgressBar.new_progressbar(name) --- Creates a new progressbar element define - ProgressBar._prototype:set_maximum(amount,count_down) --- Sets the maximum value that represents the end value of the progress bar - ProgressBar._prototype:use_count_down(state) --- Will set the progress bar to start at 1 and trigger when it hits 0 - ProgressBar._prototype:increment(amount,category) --- Increases the value of the progressbar - ProgressBar._prototype:increment_filtered(amount,filter) --- Increases the value of the progressbar, if the filter condition is met, does not work with store - ProgressBar._prototype:decrement(amount,category) --- Decreases the value of the progressbar - ProgressBar._prototype:decrement_filtered(amount,filter) --- Decreases the value of the progressbar, if the filter condition is met, does not work with store - ProgressBar._prototype:add_element(element,maximum) --- Adds an element into the list of instances that will are waiting to complete, does not work with store - ProgressBar._prototype:reset_element(element) --- Resets an element, or its store, to be back at the start, either 1 or 0 - - ProgressBar._prototype:on_complete(callback) --- Triggers when a progress bar element completes (hits 0 or 1) - ProgressBar._prototype:on_complete(callback) --- Triggers when a store value completes (hits 0 or 1) - ProgressBar._prototype:event_counter(filter) --- Event handler factory that counts up by 1 every time the event triggers, can filter which elements are incremented - ProgressBar._prototype:event_countdown(filter) --- Event handler factory that counts down by 1 every time the event triggers, can filter which elements are decremented -]] - -local Toolbar = require 'expcore.gui.concepts.toolbar' --- @dep expcore.gui.concepts.toolbar -Gui.new_toolbar_button = Toolbar.new_button -Gui.add_button_to_toolbar = Toolbar.add_button -Gui.update_toolbar = Toolbar.update -Gui.classes.toolbar = Toolbar ---[[ - Toolbar.new_button(name) --- Adds a new button to the toolbar - Toolbar.add_button(button) --- Adds an existing buttton to the toolbar - Toolbar.update(player) --- Updates the player's toolbar with an new buttons or expected change in auth return -]] - -local LeftFrames = require 'expcore.gui.concepts.left' --- @dep expcore.gui.concepts.left -Gui.get_left_frame_flow = LeftFrames.get_flow -Gui.toggle_left_frame = LeftFrames.toggle_frame -Gui.new_left_frame = LeftFrames.new_frame -Gui.classes.left_frames = LeftFrames ---[[ - LeftFrames.get_flow(player) --- Gets the left frame flow for a player - LeftFrames.get_frame(name,player) --- Gets one frame from the left flow by its name - LeftFrames.get_open(player) --- Gets all open frames for a player, if non are open it will remove the close all button - LeftFrames.toggle_frame(name,player,state) --- Toggles the visibility of a left frame, or sets its visibility state - - LeftFrames.new_frame(permission_name) --- Creates a new left frame define - LeftFrames._prototype:set_open_by_default(state) --- Sets if the frame is visible when a player joins, can also be a function to return a boolean - LeftFrames._prototype:set_direction(direction) --- Sets the direction of the frame, either vertical or horizontal - LeftFrames._prototype:get_frame(player) --- Gets the frame for this define from the left frame flow - LeftFrames._prototype:is_open(player) --- Returns if the player currently has this define visible - LeftFrames._prototype:toggle(player) --- Toggles the visibility of the left frame - - LeftFrames._prototype:update(player) --- Updates the contents of the left frame, first tries update callback, other wise will clear and redraw - LeftFrames._prototype:update_all(update_offline) --- Updates the frame for all players, see update - LeftFrames._prototype:redraw(player) --- Redraws the frame by calling on_draw, will always clear the frame - LeftFrames._prototype:redraw_all(update_offline) --- Redraws the frame for all players, see redraw - - LeftFrames._prototype:on_draw(player,frame) --- Use to draw your elements to the new frame - LeftFrames._prototype:on_update(player,frame) --- Use to edit your frame when there is no need to redraw it - LeftFrames._prototype:on_player_toggle(player,frame) --- Triggered when the player toggle the left frame - LeftFrames._prototype:event_handler(action) --- Creates an event handler that will trigger one of its functions, use with Event.add -]] - -local CenterFrames = require 'expcore.gui.concepts.center' --- @dep expcore.gui.concepts.center -Gui.get_center_flow = CenterFrames.get_flow -Gui.toggle_center_frame = CenterFrames.toggle_frame -Gui.draw_center_frame = CenterFrames.draw_frame -Gui.redraw_center_frame = CenterFrames.redraw_frames -Gui.new_center_frame = CenterFrames.new_frame -Gui.classes.center_frames = CenterFrames ---[[ - CenterFrames.get_flow(player) --- Gets the center flow for a player - CenterFrames.clear_flow(player) --- Clears the center flow for a player - CenterFrames.draw_frame(player,name) --- Draws the center frame for a player, if already open then will do nothing - CenterFrames.redraw_frame(player,name) --- Draws the center frame for a player, if already open then will destroy it and redraw - CenterFrames.toggle_frame(player,name,state) --- Toggles if the frame is currently open or not, will open if closed and close if open - - CenterFrames.new_frame(permission_name) --- Sets the frame to be the current active gui when opened and closes all other frames - CenterFrames._prototype:on_draw(player,frame) --- Use to draw your elements onto the new frame - CenterFrames._prototype:set_auto_focus(state) --- Sets the frame to be the current active gui when opened and closes all other frames - CenterFrames._prototype:draw_frame(player) --- Draws this frame to the player, if already open does nothing (will call on_draw to draw to the frame) - CenterFrames._prototype:redraw_frame(player) --- Draws this frame to the player, if already open it will remove it and redraw it (will call on_draw to draw to the frame) - CenterFrames._prototype:toggle_frame(player) --- Toggles if the frame is open, if open it will close it and if closed it will open it - CenterFrames._prototype:event_handler(action) --- Creates an event handler that will trigger one of its functions, use with Event.add -]] - -local PopupFrames = require 'expcore.gui.concepts.popups' --- @dep expcore.gui.concepts.popups -Gui.get_popup_flow = PopupFrames.get_flow -Gui.open_popup = PopupFrames.open -Gui.new_popup = PopupFrames.new_popup -Gui.classes.popup_frames = PopupFrames ---[[ - PopupFrames.get_flow(player) --- Gets the left flow that contains the popup frames - PopupFrames.open(define_name,player,open_time,...) --- Opens a popup for the player, can give the amount of time it is open as well as params for the draw function - - PopupFrames.close_progress --- Progress bar which when depleted will close the popup frame - PopupFrames.close_button --- A button which can be used to close the gui before the timer runs out - - PopupFrames.new_popup(name) --- Creates a new popup frame define - PopupFrames._prototype:set_default_open_time(amount) --- Sets the default open time for the popup, will be used if non is provided with open - PopupFrames._prototype:open(player,open_time,...) --- Opens this define for a player, can be given open time and any other params for the draw function -]] +local Gui = require 'expcore.gui.core' return Gui \ No newline at end of file diff --git a/expcore/gui/concepts/center.lua b/expcore/gui/concepts/center.lua deleted file mode 100644 index ffbc3f9f..00000000 --- a/expcore/gui/concepts/center.lua +++ /dev/null @@ -1,198 +0,0 @@ ---[[-- Core Module - Gui - @module Gui - @alias Prototype -]] - ---- Center Guis. --- Gui structure define for center gui frames --- @section center - ---[[ ->>>> Functions - CenterFrames.get_flow(player) --- Gets the center flow for a player - CenterFrames.clear_flow(player) --- Clears the center flow for a player - CenterFrames.draw_frame(player,name) --- Draws the center frame for a player, if already open then will do nothing - CenterFrames.redraw_frame(player,name) --- Draws the center frame for a player, if already open then will destroy it and redraw - CenterFrames.toggle_frame(player,name,state) --- Toggles if the frame is currently open or not, will open if closed and close if open - - CenterFrames.new_frame(permission_name) --- Sets the frame to be the current active gui when opened and closes all other frames - CenterFrames._prototype:on_draw(player,frame) --- Use to draw your elements onto the new frame - CenterFrames._prototype:set_auto_focus(state) --- Sets the frame to be the current active gui when opened and closes all other frames - CenterFrames._prototype:draw_frame(player) --- Draws this frame to the player, if already open does nothing (will call on_draw to draw to the frame) - CenterFrames._prototype:redraw_frame(player) --- Draws this frame to the player, if already open it will remove it and redraw it (will call on_draw to draw to the frame) - CenterFrames._prototype:toggle_frame(player) --- Toggles if the frame is open, if open it will close it and if closed it will open it - CenterFrames._prototype:event_handler(action) --- Creates an event handler that will trigger one of its functions, use with Event.add -]] -local Gui = require 'expcore.gui.core' --- @dep expcore.gui.core -local Prototype = require 'expcore.gui.prototype' --- @dep expcore.gui.prototype -local Toolbar = require 'expcore.gui.concepts.toolbar' --- @dep expcore.gui.concepts.toolbar -local Game = require 'utils.game' --- @dep utils.game - -local CenterFrames = { - _prototype = Prototype.extend{ - on_creation = Prototype.event - } -} - ---- Gets the center flow for a player --- @tparam LuaPlayer player the player to get the flow for --- @treturn LuaGuiElement the center flow -function CenterFrames.get_flow(player) - player = Game.get_player_from_any(player) - return player.gui.center -end - ---- Clears the center flow for a player --- @tparam LuaPlayer player the player to clear the flow for -function CenterFrames.clear_flow(player) - local flow = CenterFrames.get_flow(player) - flow.clear() -end - ---- Draws the center frame for a player, if already open then will do nothing --- @tparam LuaPlayer player the player that will have the frame drawn --- @tparam string name the name of the hui that will drawn --- @treturn LuaGuiElement the new frame that was made -function CenterFrames.draw_frame(player,name) - local define = Gui.get_define(name,true) - if define then - return define:draw_frame(player) - end -end - ---- Draws the center frame for a player, if already open then will destroy it and redraw --- @tparam LuaPlayer player the player that will have the frame drawn --- @tparam string name the name of the hui that will drawn --- @treturn LuaGuiElement the new frame that was made -function CenterFrames.redraw_frame(player,name) - local define = Gui.get_define(name,true) - if define then - return define:draw_frame(player) - end -end - ---- Toggles if the frame is currently open or not, will open if closed and close if open --- @tparam LuaPlayer player the player that will have the frame toggled --- @tparam string name the name of the hui that will be toggled --- @tparam[opt] boolean state when set will force a state for the frame --- @treturn boolean if the frame if no open or closed -function CenterFrames.toggle_frame(player,name,state) - local define = Gui.get_define(name,true) - if define then - if state == true then - define:draw_frame(player) - return true - elseif state == false then - local flow = CenterFrames.get_flow(player) - if flow[define.name..'-frame'] then - flow[define.name..'-frame'].destroy() - end - return false - else - return define:toggle_frame(player) - end - end -end - ---- Creates a new center frame define --- @tparam string permission_name the name that can be used with the permission system --- @treturn table the new center frame define -function CenterFrames.new_frame(permission_name) - local self = Toolbar.new_button(permission_name) - - self:on_click(function(player,element) - self:toggle_frame(player) - end) - - local mt = getmetatable(self) - mt.__index = CenterFrames._prototype - mt.__call = self.event_handler - - Gui.on_custom_close(self.name..'-frame',function(event) - local element = event.element - if element and element.valid then element.destroy() end - end) - - return self -end - ---- Sets the frame to be the current active gui when opened and closes all other frames --- @tparam[opt=true] boolean state when true will auto close other frames and set this frame as player.opened -function CenterFrames._prototype:set_auto_focus(state) - if state == false then - self.auto_focus = false - else - self.auto_focus = true - end -end - ---- Draws this frame to the player, if already open does nothing (will call on_draw to draw to the frame) --- @tparam LuaPlayer player the player to draw the frame for --- @treturn LuaGuiElement the new frame that was drawn -function CenterFrames._prototype:draw_frame(player) - player = Game.get_player_from_any(player) - local flow = CenterFrames.get_flow(player) - - if flow[self.name..'-frame'] then - return flow[self.name..'-frame'] - end - - if self.auto_focus then - flow.clear() - end - - local frame = flow.add{ - type='frame', - name=self.name..'-frame' - } - - if self.auto_focus then - player.opened = frame - end - - self:raise_event('on_creation',player,frame) - - return frame -end - ---- Draws this frame to the player, if already open it will remove it and redraw it (will call on_draw to draw to the frame) --- @tparam LuaPlayer player the player to draw the frame for --- @treturn LuaGuiElement the new frame that was drawn -function CenterFrames._prototype:redraw_frame(player) - player = Game.get_player_from_any(player) - local flow = CenterFrames.get_flow(player) - - if flow[self.name..'-frame'] then - flow[self.name..'-frame'].destroy() - end - - return self:draw_frame(player) -end - ---- Toggles if the frame is open, if open it will close it and if closed it will open it --- @tparam LuaPlayer player the player to draw the frame for --- @treturn boolean with the gui frame is now open -function CenterFrames._prototype:toggle_frame(player) - player = Game.get_player_from_any(player) - local flow = CenterFrames.get_flow(player) - - if flow[self.name..'-frame'] then - flow[self.name..'-frame'].destroy() - return false - else - self:draw_frame(player) - return true - end -end - ---- Creates an event handler that will trigger one of its functions, use with Event.add --- @tparam[opt=update] string action the action to take on this event -function CenterFrames._prototype:event_handler(action) - action = action or 'update' - return function(event) - local player = Game.get_player_by_index(event.player_index) - self[action](self,player) - end -end - -return CenterFrames \ No newline at end of file diff --git a/expcore/gui/concepts/left.lua b/expcore/gui/concepts/left.lua deleted file mode 100644 index e827f36a..00000000 --- a/expcore/gui/concepts/left.lua +++ /dev/null @@ -1,322 +0,0 @@ ---[[-- Core Module - Gui - @module Gui - @alias Prototype -]] - ---- Left Guis. --- Gui structure define for left frames --- @section left - ---[[ ->>>> Example formating - - -- first we add config that relates to the button on the toolbar, all normal button functions are present - local left_frame = - Gui.new_left_frame('test-left-frame') - :set_caption('Test Left Gui') - :set_post_authenticator(function(player,button_name) - return global.show_test_gui - end) - - -- then we add the config for the left frame, on_draw should draw the gui from an empty frame, on_update should take a frame from on_draw on edit it - :set_open_by_default() - :on_draw(function(_player,frame) - for _,player in pairs(game.connected_players) do - frame.add{ - type='label', - caption=player.name - } - end - end) - - -- now we can use the action factory to call events on the gui, actions are: 'update', 'update_all', 'redraw', 'redraw_all' - Event.add(defines.events.on_player_joined_game,left_frame 'update_all') - Event.add(defines.events.on_player_left_game,left_frame 'update_all') - ->>>> Functions - LeftFrames.get_flow(player) --- Gets the left frame flow for a player - LeftFrames.get_frame(name,player) --- Gets one frame from the left flow by its name - LeftFrames.get_open(player) --- Gets all open frames for a player, if non are open it will remove the close all button - LeftFrames.toggle_frame(name,player,state) --- Toggles the visibility of a left frame, or sets its visibility state - - LeftFrames.new_frame(permission_name) --- Creates a new left frame define - LeftFrames._prototype:set_open_by_default(state) --- Sets if the frame is visible when a player joins, can also be a function to return a boolean - LeftFrames._prototype:set_direction(direction) --- Sets the direction of the frame, either vertical or horizontal - LeftFrames._prototype:get_frame(player) --- Gets the frame for this define from the left frame flow - LeftFrames._prototype:is_open(player) --- Returns if the player currently has this define visible - LeftFrames._prototype:toggle(player) --- Toggles the visibility of the left frame - - LeftFrames._prototype:update(player) --- Updates the contents of the left frame, first tries update callback, other wise will clear and redraw - LeftFrames._prototype:update_all(update_offline) --- Updates the frame for all players, see update - LeftFrames._prototype:redraw(player) --- Redraws the frame by calling on_draw, will always clear the frame - LeftFrames._prototype:redraw_all(update_offline) --- Redraws the frame for all players, see redraw - - LeftFrames._prototype:on_draw(player,frame) --- Use to draw your elements to the new frame - LeftFrames._prototype:on_update(player,frame) --- Use to edit your frame when there is no need to redraw it - LeftFrames._prototype:on_player_toggle(player,frame) --- Is triggered when the player presses the toggle button - LeftFrames._prototype:event_handler(action) --- Creates an event handler that will trigger one of its functions, use with Event.add -]] -local Gui = require 'expcore.gui.core' --- @dep expcore.gui.core -local Prototype = require 'expcore.gui.prototype' --- @dep expcore.gui.prototype -local Toolbar = require 'expcore.gui.concepts.toolbar' --- @dep expcore.gui.concepts.toolbar -local Buttons = require 'expcore.gui.elements.buttons' --- @dep expcore.gui.elements.buttons -local mod_gui = require 'mod-gui' --- @dep mod-gui -local Game = require 'utils.game' --- @dep utils.game -local Event = require 'utils.event' --- @dep utils.event - -local LeftFrames = { - frames={}, - _prototype=Prototype.extend{ - on_creation = Prototype.event, - on_update = Prototype.event, - on_player_toggle = Prototype.event - } -} -setmetatable(LeftFrames._prototype, { - __index = Buttons._prototype -}) - ---- Gets the left frame flow for a player --- @tparam LuaPlayer player the player to get the flow of --- @treturn LuaGuiElement the left frame flow for the player -function LeftFrames.get_flow(player) - player = Game.get_player_from_any(player) - return mod_gui.get_frame_flow(player) -end - ---- Gets one frame from the left flow by its name --- @tparam string name the name of the gui frame to get --- @tparam LuaPlayer player the player to get the frame of --- @treturn LuaGuiElement the frame in the left frame flow with that name -function LeftFrames.get_frame(name,player) - local define = LeftFrames.frames[name] - if not define then - return error('Left Frame '..name..' is not defined.',2) - end - return define:get_frame(player) -end - ---- Gets all open frames for a player, if non are open it will remove the close all button --- @tparam LuaPlayer player the player to get the flow of --- @treturn table contains all the open (and registered) frames for the player -function LeftFrames.get_open(player) - local open = {} - local flow = LeftFrames.get_flow(player) - - for _,define in pairs(LeftFrames.frames) do - if define:is_open(player) then - table.insert(open,define) - end - end - - flow[LeftFrames.toggle_button.name].visible = #open ~= 0 - - return open -end - ---- Toggles the visibility of a left frame, or sets its visibility state --- @tparam string name the name of the gui frame to toggle --- @tparam LuaPlayer player the player to get the frame of --- @tparam[opt] boolean state when given will be the state that the visibility is set to --- @treturn boolean the new state of the visibility -function LeftFrames.toggle_frame(name,player,state) - local define = LeftFrames.frames[name] - if not define then - return error('Left Frame '..name..' is not defined.',2) - end - - local frame = LeftFrames.get_frame(name,player) - if state ~= nil then - frame.visible = state - else - Gui.toggle_visible(frame) - end - - LeftFrames.get_open(player) - - return frame.visible -end - ---- Creates a new left frame define --- @tparam string permission_name the name that can be used with the permission system --- @treturn table the new left frame define -function LeftFrames.new_frame(permission_name) - local self = Toolbar.new_button(permission_name) - - local mt = getmetatable(self) - mt.__index = LeftFrames._prototype - mt.__call = self.event_handler - - self:on_click(function(player,_element) - local visible = self:toggle(player) - local frame = self:get_frame(player) - self:raise_event('on_player_toggle',player,frame,visible) - end) - - LeftFrames.frames[self.name] = self - - return self -end - ---- Sets if the frame is visible when a player joins, can also be a function to return a boolean --- @tparam[opt=true] ?boolean|function state the default state of the visibility, can be a function --- state param - player LuaPlayer - the player that has joined the game --- state param - define_name string - the define name for the frame --- state return - boolean - false will hide the frame -function LeftFrames._prototype:set_open_by_default(state) - if state == false then - self.open_by_default = false - elseif state == nil then - self.open_by_default = true - else - self.open_by_default = state - end - return self -end - ---- Sets the direction of the frame, either vertical or horizontal --- @tparam string direction the direction to have the elements be added to the frame -function LeftFrames._prototype:set_direction(direction) - self.direction = direction - return self -end - ---- Creates the gui for the first time, used internally --- @tparam LuaPlayer player the player to draw the frame to --- @treturn LuaGuiElement the frame that was made -function LeftFrames._prototype:_internal_draw(player) - local flow = LeftFrames.get_flow(player) - local frame = flow.add{ - type='frame', - name=self.name..'-frame', - direction=self.direction - } - - self:raise_event('on_creation',player,frame) - - if not self.open_by_default then - frame.visible = false - elseif type(self.open_by_default) == 'function' then - if not self.open_by_default(player,self.name) then - frame.visible = false - end - end - - if not Toolbar.allowed(player,self.name) then - frame.visible = false - end - - return frame -end - ---- Gets the frame for this define from the left frame flow --- @tparam LuaPlayer player the player to get the frame of --- @treturn LuaGuiElement the frame in the left frame flow for this define -function LeftFrames._prototype:get_frame(player) - local flow = LeftFrames.get_flow(player) - if flow[self.name..'-frame'] and flow[self.name..'-frame'].valid then - return flow[self.name..'-frame'] - else - return self:_internal_draw(player) - end -end - ---- Returns if the player currently has this define visible --- @tparam LuaPlayer player the player to get the frame of --- @treturn boolean true if it is open/visible -function LeftFrames._prototype:is_open(player) - local frame = self:get_frame(player) - return frame and frame.visible or false -end - ---- Toggles the visibility of the left frame --- @tparam LuaPlayer player the player to toggle the frame of --- @treturn boolean the new state of the visibility -function LeftFrames._prototype:toggle(player) - local frame = self:get_frame(player) - Gui.toggle_visible(frame) - LeftFrames.get_open(player) - return frame.visible -end - ---- Updates the contents of the left frame, first tries update callback, other wise will clear and redraw --- @tparam LuaPlayer player the player to update the frame of -function LeftFrames._prototype:update(player) - local frame = self:get_frame(player) - if self:raise_event('on_update',player,frame) == 0 then - frame.clear() - self:raise_event('on_creation',player,frame) - end -end - ---- Updates the frame for all players, see update --- @tparam[opt=false] boolean update_offline when true will update the frame for offline players -function LeftFrames._prototype:update_all(update_offline) - local players = update_offline == true and game.players or game.connected_players - for _,player in pairs(players) do - self:update(player) - end -end - ---- Redraws the frame by calling on_draw, will always clear the frame --- @tparam LuaPlayer player the player to update the frame of -function LeftFrames._prototype:redraw(player) - local frame = self:get_frame(player) - frame.clear() - self:raise_event('on_creation',player,frame) -end - ---- Redraws the frame for all players, see redraw --- @tparam[opt=false] boolean update_offline when true will update the frame for offline players -function LeftFrames._prototype:redraw_all(update_offline) - local players = update_offline == true and game.players or game.connected_players - for _,player in pairs(players) do - self:redraw(player) - end -end - ---- Creates an event handler that will trigger one of its functions, use with Event.add --- @tparam[opt=update] string action the action to take on this event -function LeftFrames._prototype:event_handler(action) - action = action or 'update' - return function(event) - local player - if event and event.player_index then - player = Game.get_player_by_index(event.player_index) - end - self[action](self,player) - end -end - -LeftFrames.toggle_button = -Buttons.new_button() -:set_tooltip{'expcore-gui.left-button-tooltip'} -:set_caption('<') -:on_click(function(player,element) - for _,define in pairs(LeftFrames.frames) do - local frame = LeftFrames.get_frame(define.name,player) - frame.visible = false - define:raise_event('on_player_toggle',player,frame,false) - end - element.visible = false -end) - -Event.add(defines.events.on_player_created,function(event) - local player = Game.get_player_by_index(event.player_index) - local flow = LeftFrames.get_flow(player) - - local close_button = LeftFrames.toggle_button(flow) - Gui.set_padding(close_button) - local style = close_button.style - style.width = 18 - style.height = 36 - style.font = 'default-small-bold' - - for _,define in pairs(LeftFrames.frames) do - define:_internal_draw(player) - end - - LeftFrames.get_open(player) -end) - -return LeftFrames \ No newline at end of file diff --git a/expcore/gui/concepts/popups.lua b/expcore/gui/concepts/popups.lua deleted file mode 100644 index bda932b3..00000000 --- a/expcore/gui/concepts/popups.lua +++ /dev/null @@ -1,230 +0,0 @@ ---[[-- Core Module - Gui - @module Gui - @alias Prototype -]] - ---- Popups. --- Gui structure define for popup gui --- @section popups - ---[[ ->>>> Functions - PopupFrames.get_flow(player) --- Gets the left flow that contains the popup frames - PopupFrames.open(define_name,player,open_time,...) --- Opens a popup for the player, can give the amount of time it is open as well as params for the draw function - - PopupFrames.close_progress --- Progress bar which when depleted will close the popup frame - PopupFrames.close_button --- A button which can be used to close the gui before the timer runs out - - PopupFrames.new_popup(name) --- Creates a new popup frame define - PopupFrames._prototype:set_default_open_time(amount) --- Sets the default open time for the popup, will be used if non is provided with open - PopupFrames._prototype:open(player,open_time,...) --- Opens this define for a player, can be given open time and any other params for the draw function -]] -local Gui = require 'expcore.gui.core' --- @dep expcore.gui.core -local Prototype = require 'expcore.gui.prototype' --- @dep expcore.gui.prototype -local Game = require 'utils.game' --- @dep utils.game -local Event = require 'utils.event' --- @dep utils.event -local ProgressBar = require 'expcore.gui.elements.progress-bar' --- @dep expcore.gui.elements.progress-bar -local Button = require 'expcore.gui.elements.buttons' --- @dep expcore.gui.elements.buttons -local mod_gui = require 'mod-gui' --- @dep mod-gui -local Color = require 'resources.color_presets' --- @dep resources.color_presets -local Global = require 'utils.global' --- @dep utils.global - -local PopupFrames = { - paused_popups={}, - popup_flow_name = Gui.uid_name(), - main_frame_name = Gui.uid_name(), - close_frame_name = Gui.uid_name(), - _prototype = Prototype.extend{ - on_creation = Prototype.event - } -} -Global.register(PopupFrames.paused_popups,function(tbl) - PopupFrames.paused_popups = tbl -end) - ---- Sets the state of the element in the paused list, nil or true --- @tparam LuaGuiElement element the element to set the state of --- @tparam[opt] boolean state the state to set it to, true will pause the the progress bar -local function set_paused_state(element,state) - local name = element.player_index..':'..element.index - PopupFrames.paused_popups[name] = state -end - ---- Gets the state of the element in the paused list, nil or true --- @tparam LuaGuiElement element the element to get the state of -local function get_paused_state(element) - local name = element.player_index..':'..element.index - return PopupFrames.paused_popups[name] -end - ---- Gets the left flow that contains the popup frames --- @tparam LuaPlayer player the player to get the flow for --- @treturn LuaGuiElement the left flow that contains the popup frames -function PopupFrames.get_flow(player) - player = Game.get_player_from_any(player) - local flow = mod_gui.get_frame_flow(player) - return flow[PopupFrames.popup_flow_name] -end - ---- Opens a popup for the player, can give the amount of time it is open as well as params for the draw function --- @tparam string define_name the name of the define that you want to open for the player --- @tparam LuaPlayer player the player to open the popup for --- @tparam[opt] number open_time the minimum number of ticks you want the popup open for, 0 means no limit, nil will take default --- @tparam any ... the other params that you want to pass to your on_draw event --- @treturn LuaGuiElement the frame that was drawn, the inner gui flow which contains the content -function PopupFrames.open(define_name,player,open_time,...) - local define = Gui.get_define(define_name,true) - player = Game.get_player_from_any(player) - return define:open(player,open_time,...) -end - ---- Closes the popup, is called by progress bar and close button --- @tparam LuaGuiElement element either the progress bar or the close button -local function close_popup(element) - local frame = element.parent.parent.parent - if not frame or not frame.valid then return end - set_paused_state(element.parent[PopupFrames.close_progress:uid()]) - frame.destroy() -end - ---- Progress bar which when depleted will close the popup frame -PopupFrames.close_progress = -ProgressBar.new_progressbar() -:use_count_down() -:set_tooltip('Pause/Resume Auto-close') -:on_complete(function(player,element) - close_popup(element) -end) - ---- A button which can be used to close the gui before the timer runs out -PopupFrames.close_button = -Button.new_button() -:set_sprites('utility/close_white') -:set_tooltip('Close Popup') -:on_click(function(player,element) - close_popup(element) -end) - ---- When the progress bar is clicked it will pause its progress, or resume if previously paused -Gui.on_click(PopupFrames.close_progress:uid(),function(event) - local element = event.element - if get_paused_state(element) then - set_paused_state(element) - else - set_paused_state(element,true) - end -end) - ---- When the parent flow of the progress bar is clicked it will pause its progress, or resume if previously paused -Gui.on_click(PopupFrames.close_frame_name,function(event) - local element = event.element[PopupFrames.close_progress:uid()] - if get_paused_state(element) then - set_paused_state(element) - else - set_paused_state(element,true) - end -end) - ---- Creates a new popup frame define --- @tparam[opt] string name the optional debug name that can be added --- @treturn table the new popup frame define -function PopupFrames.new_popup(name) - local self = Gui.new_define(PopupFrames._prototype,name) - self.draw_data.type = 'flow' - self.draw_data.direction = 'vertical' - - local mt = getmetatable(self) - mt.__call = function(tbl,player,open_time,...) - return tbl:open(player,open_time,...) - end - - self:on_draw(function(player,element,maximum,...) - -- main content frame - local frame = element.add{ - type='flow', - name=PopupFrames.main_frame_name - } - frame.style.horizontally_stretchable = true - - -- flow for progress bar and close button - local close_flow = element.add{ - type='flow', - name=PopupFrames.close_frame_name - } - close_flow.style.horizontally_stretchable = true - - -- progress bar, when 0 then a static full one is drawn - local progress_style - if maximum == 0 then - progress_style = close_flow.add{ - type='progressbar', - tooltip='No Auto-close', - value=1 - }.style - else - progress_style = PopupFrames.close_progress(close_flow,maximum).style - end - progress_style.top_padding = 6 - progress_style.bottom_padding = 3 - progress_style.height = 11 - progress_style.color = Color.grey - - -- close button, will close the popup when clicked - local close_button = PopupFrames.close_button(close_flow) - Gui.set_padding(close_button) - local close_button_style = close_button.style - close_button_style.width = 20 - close_button_style.height = 20 - - -- event trigger to draw the gui content - self:raise_event('on_creation',player,frame,...) - end) - - return self -end - ---- Sets the default open time for the popup, will be used if non is provided with open --- @tparam number amount the number of ticks, by default, the popup will be open for --- @treturn table the define to allow for chaining -function PopupFrames._prototype:set_default_open_time(amount) - self.default_open_time = amount - return self -end - ---- Opens this define for a player, can be given open time and any other params for the draw function --- @tparam LuaPlayer player the player to open the popup for --- @tparam[opt] number open_time the minimum number of ticks you want the popup open for, 0 means no limit, nil will take default --- @tparam any ... the other params that you want to pass to your on_draw event --- @treturn LuaGuiElement the frame that was drawn, the inner gui flow which contains the content -function PopupFrames._prototype:open(player,open_time,...) - open_time = open_time or self.default_open_time or 0 - player = Game.get_player_from_any(player) - - local flow = PopupFrames.get_flow(player) - local frame = flow.add{ - type='frame', - style='blurry_frame' - } - - Gui.set_padding(frame,3,3,4,4) - return self:draw_to(frame,open_time,...)[PopupFrames.main_frame_name] -end - ---- When player is first created the popup flow is added to they left flow -Event.add(defines.events.on_player_created,function(event) - local player = Game.get_player_by_index(event.player_index) - local flow = mod_gui.get_frame_flow(player) - - flow.add{ - type='flow', - direction='vertical', - name=PopupFrames.popup_flow_name - } -end) - ---- Every tick any, not paused, progress bars will go down by one tick -Event.add(defines.events.on_tick,PopupFrames.close_progress:event_countdown(function(element) - return not get_paused_state(element) -end)) - -return PopupFrames \ No newline at end of file diff --git a/expcore/gui/concepts/toolbar.lua b/expcore/gui/concepts/toolbar.lua deleted file mode 100644 index 10a8d971..00000000 --- a/expcore/gui/concepts/toolbar.lua +++ /dev/null @@ -1,114 +0,0 @@ ---[[-- Core Module - Gui - @module Gui - @alias Prototype -]] - ---- Toolbar. --- Gui structure for the toolbar (top left) --- @section toolbar - ---[[ ->>>> Example format - -- this is the same as any other button define, this just automatically draws it - -- you can use add_button if you already defined the button - local toolbar_button = - Toolbar.new_button('print-click') - :on_click(function(player,_element) - player.print('You clicked a button!') - end) - ->>>> Functions - Toolbar.new_button(name) --- Adds a new button to the toolbar - Toolbar.add_button(button) --- Adds an existing buttton to the toolbar - Toolbar.update(player) --- Updates the player's toolbar with an new buttons or expected change in auth return -]] -local Gui = require 'expcore.gui.core' --- @dep expcore.gui.core -local Buttons = require 'expcore.gui.elements.buttons' --- @dep expcore.gui.elements.buttons -local Roles = require 'expcore.roles' --- @dep expcore.roles -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 - -local Toolbar = { - permission_names = {}, - buttons = {} -} - -function Toolbar.allowed(player,define_name) - local permission_name = Toolbar.permission_names[define_name] or define_name - return Roles.player_allowed(player,permission_name) -end - -function Toolbar.permission_alias(define_name,permission_name) - Toolbar.permission_names[define_name] = permission_name -end - ---- Adds a new button to the toolbar --- @tparam[opt] string name when given allows an alias to the button for the permission system --- @treturn table the button define -function Toolbar.new_button(name) - local button = - Buttons.new_button() - :set_post_authenticator(Toolbar.allowed) - :set_style(mod_gui.button_style,function(style) - Gui.set_padding_style(style,-2,-2,-2,-2) - end) - Toolbar.add_button(button) - Toolbar.permission_alias(button.name,name) - return button -end - ---- Adds an existing buttton to the toolbar --- @tparam table button the button define for the button to be added -function Toolbar.add_button(button) - table.insert(Toolbar.buttons,button) - Gui.allow_player_to_toggle_top_element_visibility(button.name) - Gui.on_player_show_top(button.name,function(event) - if not button.post_authenticator(event.player,button.name) then - event.element.visible = false - end - end) - if not button.post_authenticator then - button:set_post_authenticator(function() return true end) - end -end - ---- Updates the player's toolbar with an new buttons or expected change in auth return --- @tparam LuaPlayer player the player to update the toolbar for -function Toolbar.update(player) - local top = Gui.get_top_element_flow(player) - if not top then return end - local visible = top[Gui.top_toggle_button_name].caption == '<' - for _,button in pairs(Toolbar.buttons) do - local element - if top[button.name] then element = top[button.name] - else element = button:draw_to(top) end - if button.post_authenticator(player,button.name) then - element.visible = visible - element.enabled = true - else - element.visible = false - element.enabled = false - end - end -end - ---- When there is a new player they will have the toolbar update -Event.add(defines.events.on_player_created,function(event) - local player = Game.get_player_by_index(event.player_index) - Toolbar.update(player) -end) - ---- When a player gets a new role they will have the toolbar updated -Event.add(Roles.events.on_role_assigned,function(event) - local player = Game.get_player_by_index(event.player_index) - Toolbar.update(player) -end) - ---- When a player loses a role they will have the toolbar updated -Event.add(Roles.events.on_role_unassigned,function(event) - local player = Game.get_player_by_index(event.player_index) - Toolbar.update(player) -end) - -return Toolbar \ No newline at end of file diff --git a/expcore/gui/core.lua b/expcore/gui/core.lua index 1fd93480..e514d30a 100644 --- a/expcore/gui/core.lua +++ b/expcore/gui/core.lua @@ -1,368 +1,28 @@ --[[-- Core Module - Gui @module Gui - @alias Prototype + @alias Gui ]] ---- Core. --- Core gui file for making element defines and element classes (use require 'expcore.gui') --- see utils.gui for event handlering --- see expcore.gui.test for examples for element defines --- @section core +local Event = require 'utils.event' -- @dep utils.event +local Prototype = require 'expcore.gui.prototype' ---[[ ->>>> Basic useage with no defines - This module can be igroned if you are only wanting only event handlers as utils.gui adds the following: +local Gui = { + concepts = {} +} - Gui.uid_name() --- Generates a unqiue name to register events to - Gui.on_checked_state_changed(callback) --- Register a handler for the on_gui_checked_state_changed event - Gui.on_click(callback) --- Register a handler for the on_gui_click event - Gui.on_elem_changed(callback) --- Register a handler for the on_gui_elem_changed - Gui.on_selection_state_changed(callback) --- Register a handler for the on_gui_selection_state_changed event - Gui.on_text_changed(callback) --- Register a handler for the on_gui_text_changed event - Gui.on_value_changed(callback) --- Register a handler for the on_gui_value_changed event - - Note that all event handlers will include event.player as a valid player and that if the player or the - element is not valid then the callback will not be run. - ->>>> Basic prototype functions (see expcore.gui.prototype) - Using a class defination you can create a new element dinfation in our examples we will be using the checkbox. - - local checkbox_example = Gui.new_checkbox() - - Although all class definations are stored in Gui.classes the main function used to make new element defination are - made aviable in the top level gui module. All functions which return a new element defination will accept a name argument - which is a name which is used while debuging and is not required to be used (has not been used in examples) - - Every element define will accept a caption and tooltip (although some may not show) and to do this you would use the two - set function provided for the element defines: - - checkbox_example:set_caption('Example Checkbox') - checkbox_example:set_tooltip('Example checkbox') - - Each element define can have event handlers set, for our example checkbox we only have access to on_change which will trigger - when the state of the checkbox changes; if we want to assign handlers using the utils.gui methods then we can get the uid by calling - the uid function on the element define; however, each element can only have one handler (of each event) so it is not possible to use - Gui.on_checked_state_changed and on_change at the same time in our example. - - checkbox_example:on_change(function(player,element,value) - player.print('Example checkbox is now: '..tostring(value)) - end) - - local checkbox_example_uid = checkbox_example:uid() - Gui.on_click(checkbox_example_uid,function(event) - event.player.print('You clicked the example checkbox!') - end) - - Finally you will want to draw your element defines for which you can call deirectly on the deinfe or use Gui.draw to do; when Gui.draw is - used it can be given either the element define, the define's uid or the debug name of the define (if set): - - checkbox_example:draw_to(parent_element) - Gui.draw(checkbox_example_uid,parent_element) - ->>>> Using authenticators with draw - When an element is drawn to its parent it can always be used but if you want to limit who can use it then you can use an authenticator. There - are two types which can be used: post and pre; using a pre authenticator will mean that the draw function is stoped before the element is added - to the parent element while using a post authenticator will draw the element to the parent but will disable the element from interaction. Both may - be used if you have use for such. - - -- unless global.checkbox_example_allow_pre_auth is true then the checkbox will not be drawn - checkbox_example:set_pre_authenticator(function(player,define_name) - player.print('Example checkbox pre auth callback ran') - return global.checkbox_example_allow_pre_auth - end) - - -- unless global.checkbox_example_allow_post_auth is true then the checkbox will be drawn but deactiveated (provided pre auth returns true) - checkbox_example:set_post_authenticator(function(player,define_name) - player.print('Example checkbox pre auth callback ran') - return global.checkbox_example_allow_post_auth - end) - ->>>> Using store (see expcore.gui.prototype and expcore.gui.instances) - A powerful assept of this gui system is allowing an automatic store for the state of a gui element, this means that when a gui is closed and re-opened - the elements which have a store will retain they value even if the element was previously destroied. The store is not limited to only per player and can - be catergorised by any method you want such as one that is shared between all players or by all players on a force. Using a method that is not limited to - one player means that when one player changes the state of the element it will be automaticlly updated for all other player (even if the element is already drawn) - and so this is a powerful and easy way to sync gui elements. - - -- note the example below is the same as checkbox_example:add_store(Gui.categorize_by_player) - checkbox_example:add_store(function(element) - local player = Game.get_player_by_index(element.player_index) - return player.force.name - end) - - Of course this tool is not limited to only player interactions; the current satate of a define can be gotten using a number of methods and the value can - even be updated by the script and have all instances of the element define be updated. When you use a category then we must give a category to the get - and set functions; in our case we used Gui.categorize_by_player which uses the player's name as the category which is why 'Cooldude2606' is given as a argument, - if we did not set a function for add_store then all instances for all players have the same value and so a category is not required. - - checkbox_example:get_store('Cooldude2606') - Gui.get_store(name,'Cooldude2606') - - checkbox_example:set_store('Cooldude2606',true) - Gui.set_store(name,'Cooldude2606',true) - - These methods use the Store module which means that if you have the need to access these sotre location (for example if you want to add a watch function) then - you can get the store location of any define using checkbox_example.store - - Important note about event handlers: when the store is updated it will also trigger the event handlers (such as on_element_update) for that define but only - for the valid instances of the define which means if a player does not have the element drawn on a gui then it will not trigger the events; if you want a - trigger for all updates then you can use on_store_update however you will be required to parse the category which may or may not be a - player name (depends what store categorize function you use) - ->>>> Example formating - - local checkbox_example = - Gui.new_checkbox() - :set_caption('Example Checkbox') - :set_tooltip('Example checkbox') - :add_store(Gui.categorize_by_player) - :on_element_update(function(player,element,value) - player.print('Example checkbox is now: '..tostring(value)) - end) - ->>>> Functions - Gui.new_define(prototype) --- Used internally to create new element defines from a class prototype - Gui.draw(name,element) --- Draws a copy of the element define to the parent element, see draw_to - - Gui.categorize_by_player(element) --- A categorize function to be used with add_store, each player has their own value - Gui.categorize_by_force(element) --- A categorize function to be used with add_store, each force has its own value - Gui.categorize_by_surface(element) --- A categorize function to be used with add_store, each surface has its own value - - Gui.toggle_enabled(element) --- Will toggle the enabled state of an element - Gui.toggle_visible(element) --- Will toggle the visiblity of an element - Gui.set_padding(element,up,down,left,right) --- Sets the padding for a gui element - Gui.set_padding_style(style,up,down,left,right) --- Sets the padding for a gui style - Gui.create_alignment(element,flow_name) --- Allows the creation of a right align flow to place elements into - Gui.destroy_if_valid(element) --- Destroies an element but tests for it being present and valid first - Gui.create_scroll_table(element,table_size,maximal_height,name) --- Creates a scroll area with a table inside, table can be any size - Gui.create_header(element,caption,tooltip,right_align,name) --- Creates a header section with a label and button area -]] -local Gui = require 'utils.gui' --- @dep utils.gui -local Game = require 'utils.game' --- @dep utils.game - -Gui.classes = {} -- Stores the class definations used to create element defines -Gui.defines = {} -- Stores the indivdual element definations -Gui.names = {} -- Stores debug names to link to gui uids - ---- Used to create new element defines from a class prototype, please use the own given by the class --- @tparam table prototype the class prototype that will be used for the element define --- @tparam[opt] string debug_name the name that you want to see while debuging --- @treturn table the new element define with all functions accessed via __index metamethod -function Gui.new_define(prototype,debug_name) - local name = Gui.uid_name() - local define = setmetatable({ - debug_name = debug_name, - name = name, - events = {}, - draw_data = { - name = name - } - },{ - __index = prototype, - __call = function(self,...) - return self:draw_to(...) - end - }) - Gui.defines[define.name] = define - return define -end - ---- Gets an element define give the uid, debug name or a copy of the element define --- @tparam ?string|table name the uid, debug name or define for the element define to get --- @tparam[opt] boolean internal when true the error trace is one level higher (used internally) --- @treturn table the element define that was found or an error -function Gui.get_define(name,internal) - if type(name) == 'table' then - if name.name and Gui.defines[name.name] then - return Gui.defines[name.name] - end +function Gui.new_concept(name) + if Gui.concepts[name] then + error('Gui concept "'..name..'" is already defind',2) end - local define = Gui.defines[name] + local concept = Prototype:clone(name) + Gui.concepts[name] = concept - if not define and Gui.names[name] then - return Gui.defines[Gui.names[name]] - - elseif not define then - return error('Invalid name for element define, name not found.',internal and 3 or 2) or nil - - end - - return define + return concept end ---- A categorize function to be used with add_store, each player has their own value --- @tparam LuaGuiElement element the element that will be converted to a string --- @treturn string the player's name who owns this element -function Gui.categorize_by_player(element) - local player = Game.get_player_by_index(element.player_index) - return player.name -end - ---- A categorize function to be used with add_store, each force has its own value --- @tparam LuaGuiElement element the element that will be converted to a string --- @treturn string the player's force name who owns this element -function Gui.categorize_by_force(element) - local player = Game.get_player_by_index(element.player_index) - return player.force.name -end - ---- A categorize function to be used with add_store, each surface has its own value --- @tparam LuaGuiElement element the element that will be converted to a string --- @treturn string the player's surface name who owns this element -function Gui.categorize_by_surface(element) - local player = Game.get_player_by_index(element.player_index) - return player.surface.name -end - ---- Draws a copy of the element define to the parent element, see draw_to --- @tparam ?string|table name the uid, debug name or define for the element define to draw --- @tparam LuaGuiEelement element the parent element that it the define will be drawn to --- @treturn LuaGuiElement the new element that was created -function Gui.draw(name,element,...) - local define = Gui.get_define(name,true) - return define:draw_to(element,...) -end - ---- Will toggle the enabled state of an element --- @tparam LuaGuiElement element the gui element to toggle --- @treturn boolean the new state that the element has -function Gui.toggle_enabled(element) - if not element or not element.valid then return end - if not element.enabled then - element.enabled = true - else - element.enabled = false - end - return element.enabled -end - ---- Will toggle the visiblity of an element --- @tparam LuaGuiElement element the gui element to toggle --- @treturn boolean the new state that the element has -function Gui.toggle_visible(element) - if not element or not element.valid then return end - if not element.visible then - element.visible = true - else - element.visible = false - end - return element.visible -end - ---- Sets the padding for a gui element --- @tparam LuaGuiElement element the element to set the padding for --- @tparam[opt=0] number up the amount of padding on the top --- @tparam[opt=0] number down the amount of padding on the bottom --- @tparam[opt=0] number left the amount of padding on the left --- @tparam[opt=0] number right the amount of padding on the right -function Gui.set_padding(element,up,down,left,right) - local style = element.style - style.top_padding = up or 0 - style.bottom_padding = down or 0 - style.left_padding = left or 0 - style.right_padding = right or 0 -end - ---- Sets the padding for a gui style --- @tparam LuaStyle style the element to set the padding for --- @tparam[opt=0] number up the amount of padding on the top --- @tparam[opt=0] number down the amount of padding on the bottom --- @tparam[opt=0] number left the amount of padding on the left --- @tparam[opt=0] number right the amount of padding on the right -function Gui.set_padding_style(style,up,down,left,right) - style.top_padding = up or 0 - style.bottom_padding = down or 0 - style.left_padding = left or 0 - style.right_padding = right or 0 -end - ---- Allows the creation of an alignment flow to place elements into --- @tparam LuaGuiElement element the element to add this alignment into --- @tparam[opt] string name the name to use for the alignment --- @tparam[opt='right'] string horizontal_align the horizontal alignment of the elements in this flow --- @tparam[opt='center'] string vertical_align the vertical alignment of the elements in this flow --- @treturn LuaGuiElement the new flow that was created -function Gui.create_alignment(element,name,horizontal_align,vertical_align) - local flow = element.add{name=name,type='flow'} - local style = flow.style - Gui.set_padding(flow,1,1,2,2) - style.horizontal_align = horizontal_align or 'right' - style.vertical_align = vertical_align or 'center' - style.horizontally_stretchable =style.horizontal_align ~= 'center' - style.vertically_stretchable = style.vertical_align ~= 'center' - return flow -end - ---- Destroies an element but tests for it being present and valid first --- @tparam LuaGuiElement element the element to be destroied --- @treturn boolean true if it was destoried -function Gui.destroy_if_valid(element) - if element and element.valid then - element.destroy() - return true - end -end - ---- Creates a scroll area with a table inside, table can be any size --- @tparam LuaGuiElement element the element to add this scroll into --- @tparam number table_size the number of columns in the table --- @tparam number maximal_height the max hieght of the scroll --- @tparam[opt='scroll'] string name the name of the scoll element --- @treturn LuaGuiElement the table that was made -function Gui.create_scroll_table(element,table_size,maximal_height,name) - local list_scroll = - element.add{ - name=name or 'scroll', - type='scroll-pane', - direction='vertical', - horizontal_scroll_policy='never', - vertical_scroll_policy='auto-and-reserve-space' - } - Gui.set_padding(list_scroll,1,1,2,2) - list_scroll.style.horizontally_stretchable = true - list_scroll.style.maximal_height = maximal_height - - local list_table = - list_scroll.add{ - name='table', - type='table', - column_count=table_size - } - Gui.set_padding(list_table) - list_table.style.horizontally_stretchable = true - list_table.style.vertical_align = 'center' - list_table.style.cell_padding = 0 - - return list_table -end - ---- Creates a header section with a label and button area --- @tparam LuaGuiElement element the element to add this header into --- @tparam localeString caption the caption that is used as the title --- @tparam[opt] localeString tooltip the tooltip that is shown on the caption --- @tparam[opt] boolean right_align when true will include the right align area --- @tparam[opt='header'] string name the name of the header area --- @treturn LuaGuiElement the header that was made, or the align area if that was created -function Gui.create_header(element,caption,tooltip,right_align,name) - local header = - element.add{ - name=name or 'header', - type='frame', - style='subheader_frame' - } - Gui.set_padding(header,2,2,4,4) - header.style.horizontally_stretchable = true - header.style.use_header_filler = false - - header.add{ - type='label', - style='heading_1_label', - caption=caption, - tooltip=tooltip - } - - return right_align and Gui.create_alignment(header,'header-align') or header +function Gui.get_concept(name) + return Gui.concepts[name] or error('Gui concept "'..name..'" is not defind',2) end return Gui \ No newline at end of file diff --git a/expcore/gui/elements/buttons.lua b/expcore/gui/elements/buttons.lua deleted file mode 100644 index aa06f58b..00000000 --- a/expcore/gui/elements/buttons.lua +++ /dev/null @@ -1,128 +0,0 @@ ---[[-- Core Module - Gui - @module Gui - @alias Prototype -]] - ---- Buttons. --- Gui class define for buttons and sprite buttons --- @section Buttons - ---[[ ->>>> Functions - Button.new_button(name) --- Creates a new button element define - - Button._prototype:on_click(player,element) --- Registers a handler for when the button is clicked - Button._prototype:on_left_click(player,element) --- Registers a handler for when the button is clicked with the left mouse button - Button._prototype:on_right_click(player,element) --- Registers a handler for when the button is clicked with the right mouse button - - Button._prototype:set_sprites(sprite,hovered_sprite,clicked_sprite) --- Adds sprites to a button making it a sprite button - Button._prototype:set_click_filter(filter,...) --- Adds a click / mouse button filter to the button - Button._prototype:set_key_filter(filter,...) --- Adds a control key filter to the button - - Other functions present from expcore.gui.core -]] -local mod_gui = require 'mod-gui' --- @dep mod-gui -local Gui = require 'expcore.gui.core' --- @dep expcore.gui.core -local Prototype = require 'expcore.gui.prototype' --- @dep expcore.gui.prototype - -local Button = { - _prototype=Prototype.extend{ - on_raw_click = Prototype.event, - on_click = Prototype.event, - on_left_click = Prototype.event, - on_right_click = Prototype.event, - } -} - ---- Creates a new button element define --- @tparam[opt] string name the optional debug name that can be added --- @treturn table the new button element define -function Button.new_button(name) - - local self = Gui.new_define(Button._prototype,name) - self.draw_data.type = 'button' - self.draw_data.style = mod_gui.button_style - - Gui.on_click(self.name,function(event) - local mouse_button = event.button - local keys = {alt=event.alt,control=event.control,shift=event.shift} - local player,element = event.player,event.element - event.keys = keys - - self:raise_event('on_raw_click',event) - - if self.post_authenticator then - if not self.post_authenticator(event.player,self.name) then return end - end - - if mouse_button == defines.mouse_button_type.left then - self:raise_event('on_left_click',player,element) - elseif mouse_button == defines.mouse_button_type.right and self.events.on_right_click then - self:raise_event('on_right_click',player,element) - end - - if self.mouse_button_filter and not self.mouse_button_filter[mouse_button] then return end - if self.key_button_filter then - for key,state in pairs(self.key_button_filter) do - if state and not keys[key] then return end - end - end - - self:raise_event('on_click',player,element) - end) - - return self -end - ---- Adds sprites to a button making it a sprite button --- @tparam SpritePath sprite the sprite path for the default sprite for the button --- @tparam[opt] SpritePath hovered_sprite the sprite path for the sprite when the player hovers over the button --- @tparam[opt] SpritePath clicked_sprite the sprite path for the sprite when the player clicks the button --- @treturn self returns the button define to allow chaining -function Button._prototype:set_sprites(sprite,hovered_sprite,clicked_sprite) - self.draw_data.type = 'sprite-button' - self.draw_data.sprite = sprite - self.draw_data.hovered_sprite = hovered_sprite - self.draw_data.clicked_sprite = clicked_sprite - return self -end - ---- Adds a click / mouse button filter to the button --- @tparam table filter ?string|table either a of mouse buttons or the first mouse button to filter, with a table true means allowed --- @tparam[opt] table ... when filter is not a you can add the mouse buttons one after each other --- @treturn self returns the button define to allow chaining -function Button._prototype:set_click_filter(filter,...) - if type(filter) == 'string' then - filter = {[filter]=true} - for _,v in pairs({...}) do - filter[v] = true - end - end - - for k,v in pairs(filter) do - if type(v) == 'string' then - filter[k] = defines.mouse_button_type[v] - end - end - - self.mouse_button_filter = filter - return self -end - ---- Adds a control key filter to the button --- @tparam table filter ?string|table either a of control keys or the first control keys to filter, with a table true means allowed --- @tparam[opt] table ... when filter is not a you can add the control keys one after each other --- @treturn self returns the button define to allow chaining -function Button._prototype:set_key_filter(filter,...) - if type(filter) == 'string' then - filter = {[filter]=true} - for _,v in pairs({...}) do - filter[v] = true - end - end - - self.key_button_filter = filter - return self -end - -return Button \ No newline at end of file diff --git a/expcore/gui/elements/checkbox.lua b/expcore/gui/elements/checkbox.lua deleted file mode 100644 index 98f50811..00000000 --- a/expcore/gui/elements/checkbox.lua +++ /dev/null @@ -1,252 +0,0 @@ ---[[-- Core Module - Gui - @module Gui - @alias Prototype -]] - ---- Checkboxs. --- Gui class define for checkbox and radiobuttons --- @section checkboxs - ---[[ ->>>> Using an option set - An option set is a set of radio buttons where only one of them can be active at a time, this means that when one - is clicked all the other ones are set to false, an option set must be defined before hand and will always store - its state but is not limited by how it can categorize the store. - - First you must register the store with a name and a update callback, and an optional function for categorize: - - local example_option_set = - Gui.new_option_set('example-option-set',function(value,category) - game.print('Example options set '..category..' is now: '..tostring(value)) - end,Gui.categorize_by_player) - - Then you must register some radiobutton defines and include them in the option set: - - local example_option_one = - Gui.new_radiobutton() - :set_caption('Option One') - :add_as_option(example_option_set,'One') - - local example_option_two = - Gui.new_radiobutton() - :set_caption('Option Two') - :add_as_option(example_option_set,'Two') - - Note that these radiobuttons can still have on_element_update events but this may result in a double trigger of events as - the option set update is always triggered; also add_store cant be used as the option set acts as the store however get - and set store will still work but will effect the option set rather than the individual radiobuttons. - ->>>> Functions - Checkbox.new_checkbox(name) --- Creates a new checkbox element define - Checkbox._prototype_checkbox:on_element_update(callback) --- Registers a handler for when an element instance updates - Checkbox._prototype_checkbox:on_store_update(callback) --- Registers a handler for when the stored value updates - - Checkbox.new_radiobutton(name) --- Creates a new radiobutton element define - Checkbox._prototype_radiobutton:on_element_update(callback) --- Registers a handler for when an element instance updates - Checkbox._prototype_radiobutton:on_store_update(callback) --- Registers a handler for when the stored value updates - Checkbox._prototype_radiobutton:add_as_option(option_set,option_name) --- Adds this radiobutton to be an option in the given option set (only one can be true at a time) - - Checkbox.new_option_set(name,callback,categorize) --- Registers a new option set that can be linked to radiobutton (only one can be true at a time) - Checkbox.draw_option_set(name,element) --- Draws all radiobuttons that are part of an option set at once (Gui.draw will not work) - - Checkbox.reset_radiobutton(element,exclude,recursive) --- Sets all radiobutton in a element to false (unless excluded) and can act recursively - - Other functions present from expcore.gui.core -]] -local Gui = require 'expcore.gui.core' --- @dep expcore.gui.core -local Prototype = require 'expcore.gui.prototype' --- @dep expcore.gui.prototype -local Store = require 'expcore.store' --- @dep expcore.store -local Game = require 'utils.game' --- @dep utils.game - ---- Store call for store update --- @tparam table define the define that this is acting on --- @tparam LuaGuiElement element the element that triggered the event --- @tparam boolean value the new state of the checkbox -local function store_update(define,element,value) - element.state = value - local player = Game.get_player_by_index(element.player_index) - define:raise_event('on_element_update',player,element,value) -end - -local Checkbox = { - option_sets={}, - option_categorize={}, - _prototype_checkbox=Prototype.extend{ - on_element_update = Prototype.event, - on_store_update = Prototype.event, - add_store = Prototype.store(false,store_update), - add_sync_store = Prototype.store(true,store_update) - }, - _prototype_radiobutton=Prototype.extend{ - on_element_update = Prototype.event, - on_store_update = Prototype.event, - add_store = Prototype.store(false,store_update), - add_sync_store = Prototype.store(true,store_update) - } -} - ---- Creates a new checkbox element define --- @tparam[opt] string name the optional debug name that can be added --- @treturn table the new checkbox element define -function Checkbox.new_checkbox(name) - - local self = Gui.new_define(Checkbox._prototype_checkbox,name) - self.draw_data.type = 'checkbox' - self.draw_data.state = false - - self:on_draw(function(player,element) - if self.store then - local category = self.categorize and self.categorize(element) or nil - local state = self:get_store(category,true) - if state then element.state = true end - end - end) - - Gui.on_checked_state_changed(self.name,function(event) - local element = event.element - - if self.option_set then - local value = Checkbox.option_sets[self.option_set][element.name] - local category = self.categorize and self.categorize(element) - self:set_store(category,value) - - elseif self.store then - local value = element.state - local category = self.categorize and self.categorize(element) - self:set_store(category,value) - - else - self:raise_event('on_element_update',event.player,element,element.state) - - end - end) - - return self -end - ---- Creates a new radiobutton element define, has all functions checkbox has --- @tparam[opt] string name the optional debug name that can be added --- @treturn table the new button element define -function Checkbox.new_radiobutton(name) - local self = Checkbox.new_checkbox(name) - self.draw_data.type = 'radiobutton' - - local mt = getmetatable(self) - mt.__index = Checkbox._prototype_radiobutton - - return self -end - ---- Adds this radiobutton to be an option in the given option set (only one can be true at a time) --- @tparam string option_set the name of the option set to add this element to --- @tparam string option_name the name of this option that will be used to identify it --- @treturn self the define to allow chaining -function Checkbox._prototype_radiobutton:add_as_option(option_set,option_name) - self.option_set = option_set - self.option_name = option_name or self.name - - Checkbox.option_sets[option_set][self.option_name] = self.name - Checkbox.option_sets[option_set][self.name] = self.option_name - - self:add_store(Checkbox.option_categorize[option_set]) - - return self -end - ---- Gets the stored value of the radiobutton or the option set if present --- @tparam string category[opt] the category to get such as player name or force name --- @tparam boolean internal used to prevent stackover flow --- @treturn any the value that is stored for this define -function Checkbox._prototype_radiobutton:get_store(category,internal) - if not self.store then return end - local location = not internal and self.option_set or self.store - return Store.get(location,category) -end - ---- Sets the stored value of the radiobutton or the option set if present --- @tparam string category[opt] the category to get such as player name or force name --- @tparam boolean value the value to set for this define, must be valid for its type ie for checkbox etc --- @tparam boolean internal used to prevent stackover flow --- @treturn boolean true if the value was set -function Checkbox._prototype_radiobutton:set_store(category,value,internal) - if not self.store then return end - local location = not internal and self.option_set or self.store - return Store.set(location,category,value) -end - ---- Registers a new option set that can be linked to radiobuttons (only one can be true at a time) --- @tparam string name the name of the option set, must be unique --- @tparam function callback the update callback when the value of the option set changes --- callback param - value string - the new selected option for this option set --- callback param - category string - the category that updated if categorize was used --- @tparam function categorize the function used to convert an element into a string --- @treturn string the name of this option set to be passed to add_as_option -function Checkbox.new_option_set(name,callback,categorize) - - Store.register(name,function(value,category) - local options = Checkbox.option_sets[name] - for opt_name,define_name in pairs(options) do - if Gui.defines[define_name] then - local define = Gui.get_define(define_name) - local state = opt_name == value - define:set_store(category,state,true) - end - end - callback(value,category) - end) - - Checkbox.option_categorize[name] = categorize - Checkbox.option_sets[name] = {} - - return name -end - ---- Draws all radiobuttons that are part of an option set at once (Gui.draw will not work) --- @tparam string name the name of the option set to draw the radiobuttons of --- @tparam LuaGuiElement element the parent element that the radiobuttons will be drawn to -function Checkbox.draw_option_set(name,element) - if not Checkbox.option_sets[name] then return end - local options = Checkbox.option_sets[name] - - for _,option in pairs(options) do - if Gui.defines[option] then - Gui.defines[option]:draw_to(element) - end - end - -end - ---- Sets all radiobutton in a element to false (unless excluded) and can act recursively --- @tparam LuaGuiElement element the root gui element to start setting radio buttons from --- @tparam[opt] table exclude ?string|table the name of the radiobutton to exclude or a of radiobuttons where true will set the state true --- @tparam[opt=false] ?number|boolean recursive if true will recur as much as possible, if a will recur that number of times --- @treturn boolean true if successful -function Checkbox.reset_radiobuttons(element,exclude,recursive) - if not element or not element.valid then return end - exclude = type(exclude) == 'table' and exclude or exclude ~= nil and {[exclude]=true} or {} - recursive = type(recursive) == 'number' and recursive-1 or recursive - - for _,child in pairs(element.children) do - if child and child.valid and child.type == 'radiobutton' then - local state = exclude[child.name] or false - local define = Gui.defines[child.name] - - if define then - local category = define.categorize and define.categorize(child) or state - define:set_store(category,state) - - else - child.state = state - - end - - elseif child.children and (type(recursive) == 'number' and recursive >= 0 or recursive == true) then - Checkbox.reset_radiobutton(child,exclude,recursive) - - end - end - - return true -end - -return Checkbox \ No newline at end of file diff --git a/expcore/gui/elements/dropdown.lua b/expcore/gui/elements/dropdown.lua deleted file mode 100644 index c56eb960..00000000 --- a/expcore/gui/elements/dropdown.lua +++ /dev/null @@ -1,187 +0,0 @@ ---[[-- Core Module - Gui - @module Gui - @alias Prototype -]] - ---- Dropdowns. --- Gui class define for dropdowns and list box --- @section dropdowns - ---[[ ->>>> Functions - Dropdown.new_dropdown(name) --- Creates a new dropdown element define - Dropdown.new_list_box(name) --- Creates a new list box element define - - Dropdown._prototype:on_element_update(callback) --- Registers a handler for when an element instance updates - Dropdown._prototype:on_store_update(callback) --- Registers a handler for when the stored value updates - - Dropdown._prototype:new_static_options(options,...) --- Adds new static options to the dropdown which will trigger the general callback - Dropdown._prototype:new_dynamic_options(callback) --- Adds a callback which should return a table of values to be added as options for the dropdown (appended after static options) - Dropdown._prototype:add_option_callback(option,callback) --- Adds a case specific callback which will only run when that option is selected (general case still triggered) - - Dropdown.select_value(element,value) --- Selects the option from a dropdown or list box given the value rather than key - Dropdown.get_selected_value(element) --- Returns the currently selected value rather than index - - Other functions present from expcore.gui.core -]] -local Gui = require 'expcore.gui.core' --- @dep expcore.gui.core -local Prototype = require 'expcore.gui.prototype' --- @dep expcore.gui.prototype -local Game = require 'utils.game' --- @dep utils.game - -local select_value ---- Store call for store update --- @tparam table define the define that this is acting on --- @tparam LuaGuiElement element the element that triggered the event --- @tparam string value the new option for the dropdown -local function store_update(define,element,value) - select_value(element,value) - local player = Game.get_player_by_index(element.player_index) - define:raise_event('on_element_update',player,element,value) - - if define.option_callbacks and define.option_callbacks[value] then - define.option_callbacks[value](player,element,value) - end -end - -local Dropdown = { - _prototype=Prototype.extend{ - on_element_update = Prototype.event, - on_store_update = Prototype.event, - add_store = Prototype.store(false,store_update), - add_sync_store = Prototype.store(true,store_update) - } -} - ---- Creates a new dropdown element define --- @tparam[opt] string name the optional debug name that can be added --- @treturn table the new dropdown element define -function Dropdown.new_dropdown(name) - - local self = Gui.new_define(Dropdown._prototype,name) - self.draw_data.type = 'drop-down' - - self:on_draw(function(player,element) - if self.dynamic_options then - local dynamic_options = self.dynamic_options(player,element) - local items = element.items - for _,v in pairs(dynamic_options) do - table.insert(items,v) - end - element.items = items - end - - if self.store then - local category = self.categorize and self.categorize(element) or nil - local value = self:get_store(category) - if value then Dropdown.select_value(element,value) end - end - end) - - Gui.on_selection_state_changed(self.name,function(event) - local element = event.element - local value = Dropdown.get_selected_value(element) - - if self.store then - local category = self.categorize and self.categorize(element) or value - self:set_store(category,value) - - else - local player = event.player - local option_callbacks = self.option_callbacks - self:raise_event('on_element_update',player,element,value) - if option_callbacks and option_callbacks[value] then - option_callbacks[value](player,element,value) - end - - end - - end) - - return self -end - ---- Creates a new list box element define --- @tparam[opt] string name the optional debug name that can be added --- @treturn table the new list box element define -function Dropdown.new_list_box(name) - local self = Dropdown.new_dropdown(name) - self.draw_data.type = 'list-box' - - return self -end - ---- Adds new static options to the dropdown which will trigger the general callback --- @tparam table options ?string|table either a of option strings or the first option string, with a table values are the options --- @tparam[opt] table ... when options is not a you can add the options one after each other --- @tparam self the define to allow chaining -function Dropdown._prototype:new_static_options(options,...) - if type(options) == 'string' then - options = {options} - for _,v in pairs({...}) do - table.insert(options,v) - end - end - - self.options = options - self.draw_data.items = options - return self -end -Dropdown._prototype.add_options = Dropdown._prototype.new_static_options - ---- Adds a callback which should return a table of values to be added as options for the dropdown (appended after static options) --- @tparam function callback the function that will run to get the options for the dropdown --- callback param - player LuaPlayer - the player that the element is being drawn to --- callback param - element LuaGuiElement - the element that is being drawn --- callback return - table - the values of this table will be appended to the static options of the dropdown --- @treturn self the define to allow chaining -function Dropdown._prototype:new_dynamic_options(callback) - if type(callback) ~= 'function' then - return error('Dynamic options callback must be a function',2) - end - self.dynamic_options = callback - return self -end -Dropdown._prototype.add_dynamic = Dropdown._prototype.new_dynamic_options - ---- Adds a case specific callback which will only run when that option is selected (general case still triggered) --- @tparam string option the name of the option to trigger the callback on; if not already added then will be added as an option --- @tparam function callback the function that will be called when that option is selected --- callback param - player LuaPlayer - the player who owns the gui element --- callback param - element LuaGuiElement - the element which is being effected --- callback param - value string - the new option that has been selected --- @treturn self the define to allow chaining -function Dropdown._prototype:add_option_callback(option,callback) - if not self.option_callbacks then self.option_callbacks = {} end - if not self.options then self.options = {} end - - self.option_callbacks[option] = callback - if not table.contains(self.options,option) then - table.insert(self.options,option) - end - - return self -end - ---- Selects the option from a dropdown or list box given the value rather than key --- @tparam LuaGuiElement element the element that contains the option --- @tparam string value the option to select from the dropdown --- @treturn number the key where the value was -function Dropdown.select_value(element,value) - for k,item in pairs(element.items) do - if item == value then - element.selected_index = k - return k - end - end -end -select_value = Dropdown.select_value - ---- Returns the currently selected value rather than index --- @tparam LuaGuiElement element the gui element that you want to get the value of --- @treturn string the value that is currently selected -function Dropdown.get_selected_value(element) - local index = element.selected_index - return element.items[index] -end - -return Dropdown \ No newline at end of file diff --git a/expcore/gui/elements/elem-button.lua b/expcore/gui/elements/elem-button.lua deleted file mode 100644 index e61859bf..00000000 --- a/expcore/gui/elements/elem-button.lua +++ /dev/null @@ -1,99 +0,0 @@ ---[[-- Core Module - Gui - @module Gui - @alias Prototype -]] - ---- Elem Buttons. --- Gui class defines for elem buttons --- @section elem-buttons - ---[[ ->>>> Functions - ElemButton.new_elem_button(name) --- Creates a new elem button element define - - ElemButton._prototype:on_element_update(callback) --- Registers a handler for when an element instance updates - ElemButton._prototype:on_store_update(callback) --- Registers a handler for when the stored value updates - - ElemButton._prototype:set_type(type) --- Sets the type of the elem button, the type is required so this must be called at least once - ElemButton._prototype:set_default(value) --- Sets the default value for the elem button, this may be a function or a string - - Other functions present from expcore.gui.core -]] -local Gui = require 'expcore.gui.core' --- @dep expcore.gui.core -local Prototype = require 'expcore.gui.prototype' --- @dep expcore.gui.prototype -local Game = require 'utils.game' --- @dep utils.game - ---- Store call for store update --- @tparam table define the define that this is acting on --- @tparam LuaGuiElement element the element that triggered the event --- @tparam string value the new value for the elem button -local function store_update(define,element,value) - element.elem_value = value - local player = Game.get_player_by_index(element.player_index) - define:raise_event('on_element_update',player,element,value) -end - -local ElemButton = { - _prototype=Prototype.extend{ - on_element_update = Prototype.event, - on_store_update = Prototype.event, - add_store = Prototype.store(false,store_update), - add_sync_store = Prototype.store(true,store_update) - } -} - ---- Creates a new elem button element define --- @tparam[opt] string name the optional debug name that can be added --- @treturn table the new elem button element define -function ElemButton.new_elem_button(name) - - local self = Gui.new_define(ElemButton._prototype,name) - self.draw_data.type = 'choose-elem-button' - - self:on_draw(function(player,element) - if type(self.default) == 'function' then - element.elem_value = self.default(player,element) - end - - if self.store then - local category = self.categorize and self.categorize(element) or nil - local value = self:get_store(category) - if value then element.elem_value = value end - end - end) - - Gui.on_elem_changed(self.name,function(event) - local element = event.element - local value = element.elem_value - - if self.store then - local category = self.categorize and self.categorize(element) or value - self:set_store(category,value) - - else - self:raise_event('on_element_update',event.player,element,value) - - end - - end) - - return self -end - ---- Sets the type of the elem button, the type is required so this must be called at least once --- @tparam string type the type that this elem button is see factorio api --- @treturn the element define to allow for chaining -ElemButton._prototype.set_type = Prototype.setter('string','draw_data','elem_type') - ---- Sets the default value for the elem button, this may be a function or a string --- @tparam ?string|function value string a will be a static default and a function will be called when drawn to get the default --- @treturn the element define to allow for chaining -function ElemButton._prototype:set_default(value) - self.default = value - if type(value) ~= 'function' then - self.draw_data[self.draw_data.elem_type] = value - end - return self -end - -return ElemButton \ No newline at end of file diff --git a/expcore/gui/elements/progress-bar.lua b/expcore/gui/elements/progress-bar.lua deleted file mode 100644 index 671f11cb..00000000 --- a/expcore/gui/elements/progress-bar.lua +++ /dev/null @@ -1,390 +0,0 @@ ---[[-- Core Module - Gui - @module Gui - @alias Prototype -]] - ---- Progress Bars. --- Gui element define for progress bars --- @section progress-bars - ---[[ ->>>> Functions - ProgressBar.set_maximum(element,amount,count_down) --- Sets the maximum value that represents the end value of the progress bar - ProgressBar.increment(element,amount) --- Increases the value of the progressbar, if a define is given all of its instances have incremented - ProgressBar.decrement(element,amount) --- Decreases the value of the progressbar, if a define is given all of its instances have decremented - - ProgressBar.new_progressbar(name) --- Creates a new progressbar element define - ProgressBar._prototype:set_maximum(amount,count_down) --- Sets the maximum value that represents the end value of the progress bar - ProgressBar._prototype:use_count_down(state) --- Will set the progress bar to start at 1 and trigger when it hits 0 - ProgressBar._prototype:increment(amount,category) --- Increases the value of the progressbar - ProgressBar._prototype:increment_filtered(amount,filter) --- Increases the value of the progressbar, if the filter condition is met, does not work with store - ProgressBar._prototype:decrement(amount,category) --- Decreases the value of the progressbar - ProgressBar._prototype:decrement_filtered(amount,filter) --- Decreases the value of the progressbar, if the filter condition is met, does not work with store - ProgressBar._prototype:add_element(element,maximum) --- Adds an element into the list of instances that will are waiting to complete, does not work with store - ProgressBar._prototype:reset_element(element) --- Resets an element, or its store, to be back at the start, either 1 or 0 - - ProgressBar._prototype:on_complete(callback) --- Triggers when a progress bar element completes (hits 0 or 1) - ProgressBar._prototype:on_complete(callback) --- Triggers when a store value completes (hits 0 or 1) - ProgressBar._prototype:event_counter(filter) --- Event handler factory that counts up by 1 every time the event triggers, can filter which elements have incremented - ProgressBar._prototype:event_countdown(filter) --- Event handler factory that counts down by 1 every time the event triggers, can filter which elements have decremented -]] -local Gui = require 'expcore.gui.core' --- @dep expcore.gui.core -local Prototype = require 'expcore.gui.prototype' --- @dep expcore.gui.prototype -local Global = require 'utils.global' --- @dep utils.global -local Game = require 'utils.game' --- @dep utils.game - ---- Event call for when the value is outside the range 0-1 --- @tparam table define the define that this is acting on --- @tparam LuaGuiElement element the element that triggered the event -local function event_call(define,element) - local player = Game.get_player_by_index(element.player_index) - define:raise_event('on_complete',player,element,function() - define:add_element(element) - define:reset_element(element) - end) -end - ---- Store call for store update --- @tparam table define the define that this is acting on --- @tparam LuaGuiElement element the element that triggered the event --- @tparam number value the new value for the progress bar -local function store_update(define,element,value) - if value then - element.value = value - if define.count_down and value <= 0 - or not define.count_down and value >= 1 then - event_call(define,element) - end - end -end - -local ProgressBar = { - unregistered={}, -- elements with no callbacks - independent={}, -- elements with a link to a define - _prototype=Prototype.extend{ - on_complete = Prototype.event, - on_store_complete = Prototype.event, - add_store = Prototype.store(false,store_update), - add_sync_store = Prototype.store(true,store_update) - } -} - -Global.register({ - unregistered = ProgressBar.unregistered, - independent = ProgressBar.independent -},function(tbl) - ProgressBar.unregistered = tbl.unregistered - ProgressBar.independent = tbl.independent -end) - ---- Gets the define data, cant use Gui.get_define as it would error --- @tparam ?table|string define the define to get --- @treturn table the define or nil -local function get_define(define) - if type(define) == 'table' then - if define.name and Gui.defines[define.name] then - return Gui.defines[define.name] - end - end - - return Gui.defines[define] -end - ---- Gets the element data, used when there is no define --- @tparam LuaGuiElement element the element to get the data of --- @treturn table the element data similar to define -local function get_element(element) - if not element.valid then return end - local name = element.player_index..':'..element.index - - if ProgressBar.unregistered[name] then - return ProgressBar.unregistered[name] - end -end - ---- Sets the maximum value that represents the end value of the progress bar --- @tparam ?LuaGuiElement|string element either a gui element or a registered define --- @tparam number amount the amount to have set as the maximum -function ProgressBar.set_maximum(element,amount) - amount = amount > 0 and amount or error('amount must be greater than 0') - - local define = get_define(element) - if define then - define:set_default_maximum(amount) - - else - local element_data = get_element(element) - - if element_data then - element_data.maximum = amount - - else - local name = element.player_index..':'..element.index - ProgressBar.unregistered[name] = { - element=element, - maximum=amount or 1 - } - - end - - end -end - ---- Increases the value of the progressbar, if a define is given all of its instances have incremented --- @tparam ?LuaGuiElement|string element either a gui element or a registered define --- @tparam[opt=1] number amount the amount to increase the progressbar by -function ProgressBar.increment(element,amount) - amount = type(amount) == 'number' and amount or 1 - - local define = get_define(element) - if define then - define:increment(amount) - - else - local element_data = get_element(element) - - if element_data then - local real_amount = amount/element_data.maximum - element.value = element.value + real_amount - - if element.value >= 1 then - local name = element.player_index..':'..element.index - ProgressBar.unregistered[name] = nil - return true - end - end - - end -end - ---- Decreases the value of the progressbar, if a define is given all of its instances have decremented --- @tparam ?LuaGuiElement|string element either a gui element or a registered define --- @tparam[opt=1] number amount the amount to decrease the progressbar by -function ProgressBar.decrement(element,amount) - amount = type(amount) == 'number' and amount or 1 - - local define = get_define(element) - if define then - define:decrement(amount) - - else - local element_data = get_element(element) - - if element_data then - local real_amount = amount/element_data.maximum - element.value = element.value - real_amount - - if element.value <= 0 then - local name = element.player_index..':'..element.index - ProgressBar.unregistered[name] = nil - return true - end - end - - end -end - ---- Creates a new progressbar element define --- @tparam[opt] string name the optional debug name that can be added --- @treturn table the new progressbar element define -function ProgressBar.new_progressbar(name) - - local self = Gui.new_define(ProgressBar._prototype,name) - self.draw_data.type = 'progressbar' - - self:on_draw(function(player,element,maximum) - if self.store then - local category = self.categorize and self.categorize(element) or nil - local value = self:get_store(category) - if not value then - value = self.count_down and 1 or 0 - self:set_store(category,value) - end - element.value = value - - else - if self.count_down then - element.value = 1 - end - - if not ProgressBar.independent[self.name] then - ProgressBar.independent[self.name] = {} - end - - table.insert(ProgressBar.independent[self.name],{ - element = element, - maximum = maximum - }) - - end - - end) - - return self -end - ---- Sets the maximum value that represents the end value of the progress bar --- @tparam number amount the amount to have set as the maximum --- @treturn table the define to allow chaining -function ProgressBar._prototype:set_default_maximum(amount) - amount = amount > 0 and amount or error('amount must be greater than 0') - self.default_maximum = amount - return self -end - ---- Will set the progress bar to start at 1 and trigger when it hits 0 --- @tparam[opt=true] boolean state when true the bar will start filled, to be used with decrease --- @treturn table the define to allow chaining -function ProgressBar._prototype:use_count_down(state) - if state == false then - self.count_down = false - else - self.count_down = true - end - return self -end - ---- Main logic for changing the value of a progress bar, this only applies when its a registered define --- @tparam table self the define that is being changed --- @tparam number amount the amount which it is being changed by, may be negative --- @tparam[opt] string category the category to use with store --- @tparam[opt] function filter when given the filter must return true for the value of the element to be changed -local function change_value_prototype(self,amount,category,filter) - - local function reset_store() - local value = self.count_down and 1 or 0 - self:set_store(category,value) - end - - if self.store then - local value = self:get_store(category) or self.count_down and 1 or 0 - local maximum = self.default_maximum or 1 - local new_value = value + (amount/maximum) - - self:set_store(category,new_value) - - if self.count_down and new_value <= 0 - or not self.count_down and new_value >= 1 then - self:clear_store(category) - self:raise_event('on_store_complete',category,reset_store) - return - end - - return - end - - if ProgressBar.independent[self.name] then - for key,element_data in pairs(ProgressBar.independent[self.name]) do - local element = element_data.element - if not element or not element.valid then - ProgressBar.independent[self.name][key] = nil - - else - if not filter or filter(element) then - local maximum = element_data.maximum or self.default_maximum or 1 - element.value = element.value + (amount/maximum) - - if self.count_down and element.value <= 0 - or not self.count_down and element.value >= 1 then - ProgressBar.independent[self.name][key] = nil - event_call(self,element) - end - end - - end - end - end - -end - ---- Increases the value of the progressbar --- @tparam[opt=1] number amount the amount to increase the progressbar by --- @tparam[opt] string category the category that is used with a store -function ProgressBar._prototype:increment(amount,category) - amount = type(amount) == 'number' and amount or 1 - change_value_prototype(self,amount,category) -end - ---- Increases the value of the progressbar, if the filter condition is met, does not work with store --- @tparam[opt=1] number amount the amount to increase the progressbar by --- @tparam function filter the filter to be used -function ProgressBar._prototype:increment_filtered(amount,filter) - amount = type(amount) == 'number' and amount or 1 - change_value_prototype(self,amount,nil,filter) -end - ---- Decreases the value of the progressbar --- @tparam[opt=1] number amount the amount to decrease the progressbar by --- @tparam[opt] string category the category that is used with a store -function ProgressBar._prototype:decrement(amount,category) - amount = type(amount) == 'number' and amount or 1 - change_value_prototype(self,-amount,category) -end - ---- Decreases the value of the progressbar, if the filter condition is met, does not work with store --- @tparam[opt=1] number amount the amount to decrease the progressbar by --- @tparam function filter the filter to be used -function ProgressBar._prototype:decrement_filtered(amount,filter) - amount = type(amount) == 'number' and amount or 1 - change_value_prototype(self,-amount,nil,filter) -end - ---- Adds an element into the list of instances that will are waiting to complete, does not work with store --- note use store if you want persistent data, this only stores the elements not the values which they have --- @tparam LuaGuiElement element the element that you want to add into the waiting to complete list --- @tparam[opt] number maximum the maximum for this element if not given the default for this define is used -function ProgressBar._prototype:add_element(element,maximum) - if self.store then return end - if not ProgressBar.independent[self.name] then - ProgressBar.independent[self.name] = {} - end - table.insert(ProgressBar.independent[self.name],{ - element = element, - maximum = maximum - }) -end - ---- Resets an element, or its store, to be back at the start, either 1 or 0 --- @tparam LuaGuiElement element the element that you want to reset the progress of -function ProgressBar._prototype:reset_element(element) - if not element or not element.valid then return end - local value = self.count_down and 1 or 0 - if self.store then - local category = self.categorize and self.categorize(element) or value - self:set_store(category,value) - else - element.value = value - end -end - ---- Event handler factory that counts up by 1 every time the event triggers, can filter which elements have incremented --- @tparam[opt] function filter when given will use filtered increment --- @treturn function the event handler -function ProgressBar._prototype:event_counter(filter) - if type(filter) == 'function' then - return function() - self:increment_filtered(1,filter) - end - else - return function() - self:increment() - end - end -end - ---- Event handler factory that counts down by 1 every time the event triggers, can filter which elements have decremented --- @tparam[opt] function filter when given will use filtered decrement --- @treturn function the event handler -function ProgressBar._prototype:event_countdown(filter) - if type(filter) == 'function' then - return function() - self:decrement_filtered(1,filter) - end - else - return function() - self:decrement() - end - end -end - -return ProgressBar \ No newline at end of file diff --git a/expcore/gui/elements/slider.lua b/expcore/gui/elements/slider.lua deleted file mode 100644 index 110dd1bd..00000000 --- a/expcore/gui/elements/slider.lua +++ /dev/null @@ -1,177 +0,0 @@ ---[[-- Core Module - Gui - @module Gui - @alias Prototype -]] - ---- Sliders. --- Gui class define for sliders --- @section sliders - ---[[ ->>>> Functions - Slider.new_slider(name) --- Creates a new slider element define - - Slider._prototype:on_element_update(callback) --- Registers a handler for when an element instance updates - Slider._prototype:on_store_update(callback) --- Registers a handler for when the stored value updates - - Slider._prototype:set_range(min,max) --- Sets the range of a slider, if not used will use default values for a slider - Slider._prototype:draw_label(element) --- Draws a new label and links its value to the value of this slider, if no store then it will only show one value per player - Slider._prototype:enable_auto_draw_label(state) --- Enables auto draw of the label, the label will share the same parent element as the slider - - Other functions present from expcore.gui.core -]] -local Gui = require 'expcore.gui.core' --- @dep expcore.gui.core -local Prototype = require 'expcore.gui.prototype' --- @dep expcore.gui.prototype -local Instances = require 'expcore.gui.instances' --- @dep expcore.gui.instances -local Game = require 'utils.game' --- @dep utils.game - ---- Event call for on_value_changed and store update --- @tparam table define the define that this is acting on --- @tparam LuaGuiElement element the element that triggered the event --- @tparam number value the new value for the slider -local function event_call(define,element,value) - local player = Game.get_player_by_index(element.player_index) - - local min,max = element.get_slider_minimum(),element.get_slider_maximum() - local delta = max-min - local percent = delta == 0 and 0 or (value-min)/delta - - define:raise_event('on_element_update',player,element,value,percent) - - local category = player.name - if define.categorize then - category = define.categorize(element) - end - - Instances.unregistered_get_elements(define.name..'-label',category,function(label) - label.caption = tostring(math.round(value,2)) - end) -end - ---- Store call for store update --- @tparam table define the define that this is acting on --- @tparam LuaGuiElement element the element that triggered the event --- @tparam number value the new value for the slider -local function store_update(define,element,value) - element.slider_value = value - event_call(define,element,value) -end - -local Slider = { - _prototype=Prototype.extend{ - on_element_update = Prototype.event, - on_store_update = Prototype.event, - add_store = Prototype.store(false,store_update), - add_sync_store = Prototype.store(true,store_update) - } -} - ---- Creates a new slider element define --- @tparam[opt] string name the optional debug name that can be added --- @treturn table the new slider element define -function Slider.new_slider(name) - - local self = Gui.new_define(Slider._prototype,name) - self.draw_data.type = 'slider' - - self:on_draw(function(player,element) - local min,max = element.get_slider_minimum(),element.get_slider_maximum() - - if type(self.min) == 'function' then - min = self.min(player,element) - end - - if type(self.max) == 'function' then - max = self.max(player,element) - end - - element.set_slider_minimum_maximum(min,max) - - if self.store then - local category = self.categorize and self.categorize(element) or nil - local value = self:get_store(category) - if value then element.slider_value = value end - end - - if self.auto_label then - self:draw_label(element.parent) - end - end) - - Gui.on_value_changed(self.name,function(event) - local element = event.element - local value = element.slider_value - - if self.store then - local category = self.categorize and self.categorize(element) or value - self:set_store(category,value) - - else - event_call(self,element,value) - - end - - end) - - return self -end - ---- Sets the range of a slider, if not used will use default values for a slider --- @tparam[opt] number min the minimum value that the slider can take --- @tparam[opt] number max the maximum value that the slider can take --- @treturn self the define to allow chaining -function Slider._prototype:set_range(min,max) - self.min = min - self.max = max - - if type(min) == 'number' then - self.draw_data.minimum_value = min - end - - if type(max) == 'number' then - self.draw_data.maximum_value = max - end - - return self -end - ---- Draws a new label and links its value to the value of this slider, if no store then it will only show one value per player --- @tparam LuaGuiElement element the parent element that the label will be drawn to --- @treturn LuaGuiElement the new label element so that styles can be applied -function Slider._prototype:draw_label(element) - local name = self.name..'-label' - if element[name] then return end - - local value = 0 - if self.store then - local category = self.categorize and self.categorize(element) or value - value = self:get_store(category) or 0 - end - - local new_element = element.add{ - name=name, - type='label', - caption=tostring(math.round(value,2)) - } - - local categorise = self.categorise or Gui.categorize_by_player - local category = categorise(new_element) - - Instances.unregistered_add_element(name,category,new_element) - - return new_element -end - ---- Enables auto draw of the label, the label will share the same parent element as the slider --- @tparam[opt=true] boolean state when false will disable the auto draw of the label --- @treturn self the define to allow chaining -function Slider._prototype:enable_auto_draw_label(state) - if state == false then - self.auto_label = false - else - self.auto_label = true - end - return self -end - -return Slider \ No newline at end of file diff --git a/expcore/gui/elements/text.lua b/expcore/gui/elements/text.lua deleted file mode 100644 index 406c4ea0..00000000 --- a/expcore/gui/elements/text.lua +++ /dev/null @@ -1,149 +0,0 @@ ---[[-- Core Module - Gui - @module Gui - @alias Prototype -]] - ---- Text. --- Gui class define for text fields and text boxes --- @section text - ---[[ ->>>> Functions - Text.new_text_field(name) --- Creates a new text field element define - Text._prototype_field:on_element_update(callback) --- Registers a handler for when an element instance updates - Text._prototype_field:on_store_update(callback) --- Registers a handler for when the stored value updates - - Text.new_text_box(name) --- Creates a new text box element define - Text._prototype_field:on_element_update(callback) --- Registers a handler for when an element instance updates - Text._prototype_field:on_store_update(callback) --- Registers a handler for when the stored value updates - Text._prototype_box:set_selectable(state) --- Sets the text box to be selectable - Text._prototype_box:set_word_wrap(state) --- Sets the text box to have word wrap - Text._prototype_box:set_read_only(state) --- Sets the text box to be read only - - Other functions present from expcore.gui.core -]] -local Gui = require 'expcore.gui.core' --- @dep expcore.gui.core -local Prototype = require 'expcore.gui.prototype' --- @dep expcore.gui.prototype -local Game = require 'utils.game' --- @dep utils.game - ---- Store call for store update --- @tparam table define the define that this is acting on --- @tparam LuaGuiElement element the element that triggered the event --- @tparam string value the new text for the text field -local function store_update(define,element,value) - element.text = value - local player = Game.get_player_by_index(element.player_index) - define:raise_event('on_element_update',player,element,value) -end - -local Text = { - _prototype_field=Prototype.extend{ - on_element_update = Prototype.event, - on_store_update = Prototype.event, - add_store = Prototype.store(false,store_update), - add_sync_store = Prototype.store(true,store_update) - }, - _prototype_box=Prototype.extend{ - on_element_update = Prototype.event, - on_store_update = Prototype.event, - add_store = Prototype.store(false,store_update), - add_sync_store = Prototype.store(true,store_update) - } -} - ---- Creates a new text field element define --- @tparam[opt] string name the optional debug name that can be added --- @treturn table the new text field element define -function Text.new_text_field(name) - - local self = Gui.new_define(Text._prototype_field,name) - self.draw_data.type = 'textfield' - - self:on_draw(function(player,element) - if self.selectable then - element.selectable = true - end - - if self.word_wrap then - element.word_wrap = true - end - - if self.read_only then - element.read_only = true - end - - if self.store then - local category = self.categorize and self.categorize(element) or nil - local value = self:get_store(category) - if value then element.text = value end - end - end) - - Gui.on_text_changed(self.name,function(event) - local element = event.element - local value = element.text - - if self.store then - local category = self.categorize and self.categorize(element) or value - self:set_store(category,value) - - else - self:raise_event('on_element_update',event.player,element,value) - - end - - end) - - return self -end - ---- Creates a new text box element define --- @tparam[opt] string name the optional debug name that can be added --- @treturn table the new text box element define -function Text.new_text_box(name) - local self = Text.new_text_field(name) - self.draw_data.type = 'text-box' - - local mt = getmetatable(self) - mt.__index = Text._prototype_box - - return self -end - ---- Sets the text box to be selectable --- @tparam[opt=true] boolean state when false will set the state to false --- @treturn self table the define to allow for chaining -function Text._prototype_box:set_selectable(state) - if state == false then - self.selectable = false - else - self.selectable = true - end - return self -end - ---- Sets the text box to have word wrap --- @tparam[opt=true] boolean state when false will set the state to false --- @treturn self table the define to allow for chaining -function Text._prototype_box:set_word_wrap(state) - if state == false then - self.word_wrap = false - else - self.word_wrap = true - end - return self -end - ---- Sets the text box to be read only --- @tparam[opt=true] boolean state when false will set the state to false --- @treturn self table the define to allow for chaining -function Text._prototype_box:set_read_only(state) - if state == false then - self.read_only = false - else - self.read_only = true - end - return self -end - -return Text \ No newline at end of file diff --git a/expcore/gui/instances.lua b/expcore/gui/instances.lua deleted file mode 100644 index 86fcd11f..00000000 --- a/expcore/gui/instances.lua +++ /dev/null @@ -1,235 +0,0 @@ ---[[-- Core Module - Gui - @module Gui - @alias Prototype -]] - ---- Instances. --- This file is a breakout from core which forcues on instance management of defines --- @section instances - ---[[ ->>>> Using registered instance groups - The main use of this module is to register a group of elements referred here as "instances of an element define" in which - is meant that you define the name of a group of drawn elements that are really just multiple versions of a single element. - For example this might be that you have one label in multiple places (either for one player or many) and you want to update - the caption of all of them at once; this is where this module comes it. - - First you must register the way that the instances are stored and under what name, using Instances.register you will give the - name of the collective group of instances followed by an optional categorise function which allows variants to be stored under one - name (like one for each force or player) - - -- categorise works in the same way as store categorise - -- so the function will world here but no value is stored only gui elements - Instances.register('score',Gui.categorize_by_force) - - Then when you draw the new element to a gui you will want to add the element to the group: - - Instances.add_element('score',new_element) - - Then when you want to get the instances you have two options; Instances.get_elements or Instances.apply_to_elements when you want loop - over the elements it is more efficient to use apply_to_elements: - - Instances.get_elements('score','player') -- returns all elements that were added with the 'player' category - Instances.apply_to_elements('score','player',function(element) -- runs the function on every valid element - element.caption = 0 - end) - - Note that if you don't give a categorise function then you don't need to give a category when getting the elements. - ->>>> Using unregistered instance groups - When using a registered group and the functions that go with them it is much simpler to use and more importantly includes error checking - for valid instance group names; the down side is that the group must be registered which can only be done during start-up and not during runtime. - To counter this there are two functions similar to those above in order to add and get instances but may lead to errors not being noticed due to - the error internal error checking being skipped to allow it to work. - - The main difference between the two groups of functions is that the category must always be present even if is nil; example below shows how a - instance group would work when registered vs unregistered: - - -- Registered with category - Instances.register('score',Gui.categorize_by_force) -- force_store will return the force name of an element - Instances.add_element('score',new_element) -- the new element is added to the category based on in force - Instances.apply_to_elements('score','player',function(element) - element.caption = '0' - end) -- gets all instances from the player force and sets the caption to 0 - - -- Unregistered with category - Instances.unregistered_add_element('score','player',new_element) -- adds the new element to the player category - Instances.unregistered_apply_to_elements('score','player',function(element) - element.caption = '0' - end) -- gets all instances from the player force and sets the caption to 0 - - -- Registered without category; note that category can just be ignored - Instances.register('score') -- all instances will be under one group with no categories - Instances.add_element('score',new_element) -- adds the new element to the instance list - Instances.apply_to_elements('score',function(element) - element.caption = '0' - end) -- gets all instances and sets the element caption to 0 - - -- Unregistered without category; note that category must be given as nil - Instances.unregistered_add_element('score',nil,new_element) -- adds the new element to a single group with no categories - Instances.unregistered_apply_to_elements('score',nil,function(element) - element.caption = '0' - end) -- gets all instances and sets the element caption to 0 - ->>>> Functions - Instances.has_categories(name) --- Returns if a instance group has a categorise function; must be registered - Instances.is_registered(name) --- Returns if the given name is a registered instance group - Instances.register(name,categorise) --- Registers the name of an instance group to allow for storing element instances - - Instances.add_element(name,element) --- Adds an element to the instance group under the correct category; must be registered - Instances.get_elements_raw(name,category) --- Gets all element instances without first removing any invalid ones; used internally and must be registered - Instances.get_valid_elements(name,category,callback) --- Gets all valid element instances and has the option of running a callback on those that are valid - - Instances.unregistered_add_element(name,category,element) --- A version of add_element that does not require the group to be registered - Instances.unregistered_get_elements(name,category,callback) --- A version of get_elements that does not require the group to be registered -]] -local Global = require 'utils.global' --- @dep utils.global - -local Instances = { - categorise={}, - data={} -} -Global.register(Instances.data,function(tbl) - Instances.data = tbl -end) - ---- Returns if a instance group has a categorise function; must be registered --- @tparam string name the name of the instance group --- @treturn boolean true if there is a categorise function -function Instances.has_categories(name) - return type(Instances.categorise[name]) == 'function' -end - ---- Returns if the given name is a registered instance group --- @tparam string name the name of the instance group you are testing --- @treturn boolean true if the name is registered -function Instances.is_registered(name) - return Instances.categorise[name] ~= nil -end - ---- Registers the name of an instance group to allow for storing element instances --- @tparam string name the name of the instance group; must to unique --- @tparam[opt] function categorise function used to turn the element into a string --- categorise param - element LuaGuiElement - the gui element to be turned into a string --- categorise return - string - the category that the element will be added to like the player's name or force's name --- @treturn string the name that was added so it can be used as a variable -function Instances.register(name,categorise) - if _LIFECYCLE ~= _STAGE.control then - return error('Can only be called during the control stage', 2) - end - - if Instances.categorise[name] then - return error('Instances for '..name..' already exist.',2) - end - - categorise = type(categorise) == 'function' and categorise or true - - Instances.data[name] = {} - Instances.categorise[name] = categorise - - return name -end - ---- Adds an element to the instance group under the correct category; must be registered --- @tparam string name the name of the instance group to add the element to --- @tparam LuaGuiElement element the element to add the the instance group -function Instances.add_element(name,element) - if not Instances.categorise[name] then - return error('Invalid name for instance group: '..name,2) - end - - if Instances.has_categories(name) then - local category = Instances.categorise[name](element) - if not Instances.data[name][category] then Instances.data[name][category] = {} end - table.insert(Instances.data[name][category],element) - else - table.insert(Instances.data[name],element) - end -end - ---- Gets all element instances without first removing any invalid ones; used internally and must be registered --- @tparam string name the name of the instance group to get the instances of --- @tparam[opt] string category the category to get the instance from, not needed when no categorise function --- @treturn table the table of element instances of which some may be invalid -function Instances.get_elements_raw(name,category) - if not Instances.categorise[name] then - return error('Invalid name for instance group: '..name,2) - end - - if Instances.has_categories(name) then - return Instances.data[name][category] or {} - else - return Instances.data[name] - end -end - ---- Gets all valid element instances and has the option of running a callback on those that are valid --- @tparam string name the name of the instance group to get the instances of --- @tparam[opt] string category the category to get the instances of, not needed when no categorise function --- @tparam[opt] function callback when given the callback will be ran on all valid elements --- callback param - element LuaGuiElement - the current valid element --- @treturn table the table of element instances with all invalid ones removed -function Instances.get_valid_elements(name,category,callback) - if not Instances.categorise[name] then - return error('Invalid name for instance group: '..name,2) - end - - category = category or callback - local elements = Instances.get_elements_raw(name,category) - local categorise = Instances.has_categories(name) - - for key,element in pairs(elements) do - if not element or not element.valid then - elements[key] = nil - else - if categorise and callback then callback(element) - elseif category then category(element) end - end - end - - return elements -end -Instances.get_elements = Instances.get_valid_elements -Instances.apply_to_elements = Instances.get_valid_elements - ---- A version of add_element that does not require the group to be registered --- @tparam string name the name of the instance group to add the element to --- @tparam ?string|nil category the category to add the element to, can be nil but must still be given --- @tparam LuaGuiElement element the element to add to the instance group -function Instances.unregistered_add_element(name,category,element) - if not Instances.data[name] then Instances.data[name] = {} end - if category then - if not Instances.data[name][category] then Instances.data[name][category] = {} end - table.insert(Instances.data[name][category],element) - else - table.insert(Instances.data[name],element) - end -end - ---- A version of get_elements that does not require the group to be registered --- @tparam string name the name of the instance group to get the instances of --- @tparam ?string|nil category the category to get the instances of, can be nil but must still be given --- @tparam[opt] function callback when given will be called on all valid instances --- callback param - element LuaGuiElement - the current valid element --- @treturn table the table of element instances with all invalid ones removed -function Instances.unregistered_get_elements(name,category,callback) - local elements = Instances.data[name] - if elements and category then - elements = elements[category] - end - - if not elements then return {} end - - for key,element in pairs(elements) do - if not element or not element.valid then - elements[key] = nil - else - if callback then callback(element) end - end - end - - return elements -end -Instances.unregistered_apply_to_elements = Instances.runtime_get_elements - -return Instances \ No newline at end of file diff --git a/expcore/gui/prototype.lua b/expcore/gui/prototype.lua index 20624583..5c9dd9f3 100644 --- a/expcore/gui/prototype.lua +++ b/expcore/gui/prototype.lua @@ -1,311 +1,196 @@ --[[-- Core Module - Gui @module Gui @alias Prototype + + readme define + + local button = + -- starts the defination of a new concept + Gui.new_concept('button') + -- event linked to a factorio event + :new_event('on_click',defines.events.on_gui_click) + -- event linked conditionaly to a factorio event + :new_event('on_admin_click',defines.events.on_gui_click,function(event) + return event.player.admin + end) + -- a property which can be set + :new_property('caption',function(concept,value,...) + concept.draw_data.caption = value + end,"Change Me") + -- the draw function for this concept + :define_draw(function(concept,parent,element,...) + element = + parent.draw{ + name=concept.name, + type='button', + caption=concept.caption + } + + return element + end) + + local toggle_cheat_mode = + -- starts the defination of a new concept based on "button" + button:clone('toggle_cheat_mode') + -- sets the already existing property of "caption" + :set_caption('Toggle Cheat Mode') + -- using the admin click event toggle cheat mode + :on_admin_click(function(event) + event.player.cheat_mode = not event.player.cheat_mode + end) + -- adds a draw event on top of the button draw event, element is now defined + :define_draw(function(concept,parent,element,...) + element.style.font_color = {r=1,g=0,b=0} + end) + + -- draws the toggle cheat mode button, extra arguments can be passed + toggle_cheat_mode:draw(game.player.gui.left,...) ]] ---- Prototype. --- Used to create new gui prototypes see elements and concepts --- @section prototype +local Event = require 'utils.event' -- @dep utils.event +local Game = require 'utils.game' -- @dep utils.game ---[[ - >>>> Functions - Constructor.event(event_name) --- Creates a new function to add functions to an event handler - Constructor.extend(new_prototype) --- Extents a prototype with the base functions of all gui prototypes, no metatables - Constructor.store(sync,callback) --- Creates a new function which adds a store to a gui define - Constructor.setter(value_type,key,second_key) --- Creates a setter function that checks the type when a value is set +local Factorio_Events = {} +local Prototype = { + draw_callbacks = {}, + properties = {}, + events = {} +} - Prototype:uid() --- Gets the uid for the element define - Prototype:debug_name(value) --- Sets a debug alias for the define - Prototype:set_caption(value) --- Sets the caption for the element define - Prototype:set_tooltip(value) --- Sets the tooltip for the element define - Prototype:set_style(style,callback) --- Sets the style for the element define - Prototype:set_embedded_flow(state) --- Sets the element to be drawn inside a nameless flow, can be given a name using a function - - Prototype:set_pre_authenticator --- Sets an authenticator that blocks the draw function if check fails - Prototype:set_post_authenticator --- Sets an authenticator that disables the element if check fails - - Prototype:raise_event(event_name,...) --- Raises a custom event for this define, any number of params can be given - Prototype:draw_to(element,...) --- The main function for defines, when called will draw an instance of this define to the given element - - Prototype:get_store(category) --- Gets the value in this elements store, category needed if categorize function used - Prototype:set_store(category,value) --- Sets the value in this elements store, category needed if categorize function used - Prototype:clear_store(category) --- Sets the value in this elements store to nil, category needed if categorize function used -]] -local Game = require 'utils.game' --- @dep utils.game -local Store = require 'expcore.store' --- @dep expcore.store -local Instances = require 'expcore.gui.instances' --- @dep expcore.gui.instances - -local Constructor = {} -local Prototype = {} - ---- Creates a new function to add functions to an event handler --- @tparam string event_name the name of the event that callbacks will be added to --- @treturn function the function used to register handlers -function Constructor.event(event_name) - --- Adds a callback as a handler for an event - -- @tparam table self the gui define being acted on - -- @tparam function callback the function that will be added as a handler for the event - -- @treturn table self returned to allowing chaining of functions - return function(self,callback) - if type(callback) ~= 'function' then - return error('Event callback for '..event_name..' must be a function',2) - end - - local handlers = self.events[event_name] - if not handlers then - handlers = {} - self.events[event_name] = handlers - end - - handlers[#handlers+1] = callback - return self - end -end - ---- Extents a prototype with the base functions of all gui prototypes, no metatables --- @tparam table new_prototype the prototype that you want to add the functions to --- @treturn table the same prototype but with the new functions added -function Constructor.extend(new_prototype) - for key,value in pairs(Prototype) do - if type(value) == 'table' then - new_prototype[key] = table.deepcopy(value) - else - new_prototype[key] = value - end - end - for key,value in pairs(new_prototype) do - if value == Constructor.event then - new_prototype[key] = Constructor.event(key) - end - end - return new_prototype -end - ---- Creates a new function which adds a store to a gui define --- @tparam boolean sync if the function should create a synced store --- @tparam function callback the function called when needing to update the value of an element --- @treturn function the function that will add a store for this define -function Constructor.store(sync,callback) - --- Adds a store for the define that is shared between all instances of the define in the same category, categorize is a function that returns a string - -- @tparam self table the gui define being acted on - -- @tparam[opt] string location a unique location identifier, when omitted a uid location will be used, use when sync is set to true - -- @tparam[opt] function categorize function used to determine the category of a LuaGuiElement, when omitted all share one single category - -- categorize param - LuaGuiElement element - the element that needs to be converted - -- categorize return - string - a deterministic string that references to a category such as player name or force name - -- @treturn self the element define to allow chaining - return function(self,location,categorize) - if self.store then return end - - if not sync then - categorize = location - location = Store.uid_location() - end - - if Store.is_registered(location) then - return error('Location for store is already registered: '..location,2) - end - - self.store = location - self.categorize = categorize - - Instances.register(self.name,self.categorize) - - Store.register(self.store,sync,function(value,category) - self:raise_event('on_store_update',value,category) - - if Instances.is_registered(self.name) then - Instances.apply_to_elements(self.name,category,function(element) - callback(self,element,value) - end) - end - end) - - return self - end -end - ---- Creates a setter function that checks the type when a value is set --- @tparam string value_type the type that the value should be when it is set --- @tparam string key the key of the define that will be set --- @tparam[opt] string second_key allows for setting of a key in a sub table --- @treturn function the function that will check the type and set the value -function Constructor.setter(value_type,key,second_key) - local display_message = 'Gui define '..key..' must be of type '..value_type - if second_key then - display_message = 'Gui define '..second_key..' must be of type '..value_type - end - - local locale = false - if value_type == 'locale-string' then - locale = true - value_type = 'table' - end - - return function(self,value) - local v_type = type(value) - if v_type ~= value_type and (not locale or v_type ~= 'string') then - error(display_message,2) - end - - if second_key then - self[key][second_key] = value - else - self[key] = value - end - - return self - end -end - ---- Gets the uid for the element define --- @treturn string the uid of this element define -function Prototype:uid() - return self.name -end - ---- Sets a debug alias for the define --- @tparam string name the debug name for the element define that can be used to get this element define --- @treturn self the element define to allow chaining -Prototype.debug_name = Constructor.setter('string','debug_name') - ---- Sets the caption for the element define --- @tparam string caption the caption that will be drawn with the element --- @treturn self the element define to allow chaining -Prototype.set_caption = Constructor.setter('locale-string','draw_data','caption') - ---- Sets the tooltip for the element define --- @tparam string tooltip the tooltip that will be displayed for this element when drawn --- @treturn self the element define to allow chaining -Prototype.set_tooltip = Constructor.setter('locale-string','draw_data','tooltip') - ---- Sets an authenticator that blocks the draw function if check fails --- @tparam function callback the function that will be ran to test if the element should be drawn or not --- callback param - LuaPlayer player - the player that the element is being drawn to --- callback param - string define_name - the name of the define that is being drawn --- callback return - boolean - false will stop the element from being drawn --- @treturn self the element define to allow chaining -Prototype.set_pre_authenticator = Constructor.setter('function','pre_authenticator') - ---- Sets an authenticator that disables the element if check fails --- @tparam function callback the function that will be ran to test if the element should be enabled or not --- callback param - LuaPlayer player - the player that the element is being drawn to --- callback param - string define_name - the name of the define that is being drawn --- callback return - boolean - false will disable the element --- @treturn self the element define to allow chaining -Prototype.set_post_authenticator = Constructor.setter('function','post_authenticator') - ---- Registers a callback to the on_draw event --- @tparam function callback --- callback param - LuaPlayer player - the player that the element was drawn to --- callback param - LuaGuiElement element - the element that was drawn --- callback param - any ... - any other params passed by the draw_to function -Prototype.on_draw = Constructor.event('on_draw') - ---- Registers a callback to the on_style_update event --- @tparam function callback --- callback param - LuaStyle style - the style that was changed and/or needs changing -Prototype.on_style_update = Constructor.event('on_style_update') - ---- Sets the style for the element define --- @tparam string style the style that will be used for this element when drawn --- @tparam[opt] function callback function is called when element is drawn to alter its style --- @treturn self the element define to allow chaining -function Prototype:set_style(style,callback) - self.draw_data.style = style - if callback then - self:on_style_update(callback) - end - return self -end - ---- Sets the element to be drawn inside a nameless flow, can be given a name using a function --- @tparam ?boolean|function state when true a padless flow is created to contain the element --- @treturn self the element define to allow chaining -function Prototype:set_embedded_flow(state) - if state == false or type(state) == 'function' then - self.embedded_flow = state +local function factorio_event_handler(event) + local element = event.element + if element then + if not element.valid then return end + local concept_name = element.name + local concept_event = Factorio_Events[event.name][concept_name] + concept_event[1]:raise_event(concept_event[2],event,true) else - self.embedded_flow = true + local events_handlers = Factorio_Events[event.name] + for _,concept_event in pairs(events_handlers) do + concept_event[1]:raise_event(concept_event[2],event,true) + end end +end + +function Prototype:clone(concept_name) + local concept = { + name = concept_name, + events = {} + } + + for event_name,_ in pairs(self.events) do + concept.events[event_name] = {} + end + + for key,value in pairs(self) do + if not concept[key] then + concept[key] = table.deep_copy(value) + end + end + + return concept + +end + +function Prototype:new_event(event_name,factorio_event,event_condition) + if self.events[event_name] then + error('Event is already defined',2) + end + + local handlers = {} + self.events[event_name] = handlers + self[event_name] = function(handler) + if type(handler) ~= 'function' then + error('Event handler must be a function',2) + end + + handlers[#handlers] = handler + + return self + end + + if factorio_event then + handlers.factorio_handler = event_condition + if not Factorio_Events[factorio_event] then + Factorio_Events[factorio_event] = {} + Event.add(factorio_event,factorio_event_handler) + end + Factorio_Events[factorio_event][self.name] = {self,event_name} + end + + return self + +end + +function Prototype:raise_event(event_name,event,from_factorio) + if not self.events[event_name] then + error('Event is not defined',2) + end + + event.concept = self + event.name = event.name or event_name + event.tick = event.tick or game.tick + event.player = event.player_index and Game.get_player_by_index(event.player_index) or nil + if event.element and not event.element.valid then return end + + local handlers = self.events[event_name] + + if from_factorio and handlers.factorio_handler and not handlers.factorio_handler(event) then + return + end + + for _,handler in ipairs(handlers) do + local success, err = pcall(handler,event) + if not success then + print('Gui event handler error with '..self.name..'/'..event_name..': '..err) + end + end +end + +function Prototype:new_property(property_name,default,setter_callback) + if self.properties[property_name] then + error('Property is already defined',2) + end + + self.properties[property_name] = default + + self['set_'..property_name] = function(value,...) + if setter_callback then + local success, err = pcall(setter_callback,value,...) + if not success then + print('Gui property handler error with '..self.name..'/'..property_name..': '..err) + end + else + self.properties[property_name] = value + end + + return self + end + + return self + +end + +function Prototype:define_draw(draw_callback) + if type(draw_callback) ~= 'function' then + error('Draw define must be a function',2) + end + + self.draw_callbacks[#self.draw_callbacks+1] = draw_callback + return self end ---- Raises a custom event for this define, any number of params can be given --- @tparam string event_name the name of the event that you want to raise --- @tparam any ... any params that you want to pass to the event --- @treturn number the number of handlers that were registered -function Prototype:raise_event(event_name,...) - local handlers = self.events[event_name] - if handlers then - for _,handler in pairs(handlers) do - handler(...) +function Prototype:draw(parent_element,...) + local element + for _,draw_callback in pairs(self.draw_callbacks) do + local success, rtn = pcall(draw_callback,concept,parent_element,element,...) + if success and rtn then + element = rtn + elseif not success then + print('Gui draw handler error with '..self.name..': '..rtn) end end - return handlers and #handlers or 0 end ---- The main function for defines, when called will draw an instance of this define to the given element --- what is drawn is based on the data in draw_data which is set using other functions --- @tparam LuaGuiElement element the element that the define will draw a instance of its self onto --- @treturn LuaGuiElement the new element that was drawn -function Prototype:draw_to(element,...) - local name = self.name - if element[name] then return end - local player = Game.get_player_by_index(element.player_index) - - if self.pre_authenticator then - if not self.pre_authenticator(player,self.name) then return end - end - - if self.embedded_flow then - local embedded_name - if type(self.embedded_flow) == 'function' then - embedded_name = self.embedded_flow(element,...) - end - element = element.add{type='flow',name=embedded_name} - element.style.padding = 0 - end - - local new_element = element.add(self.draw_data) - - self:raise_event('on_style_update',new_element.style) - - if self.post_authenticator then - new_element.enabled = self.post_authenticator(player,self.name) - end - - if Instances.is_registered(self.name) then - Instances.add_element(self.name,new_element) - end - - self:raise_event('on_draw',player,new_element) - - return new_element -end - ---- Gets the value in this elements store, category needed if categorize function used --- @tparam string category[opt] the category to get such as player name or force name --- @treturn any the value that is stored for this define -function Prototype:get_store(category) - if not self.store then return end - return Store.get(self.store,category) -end - ---- Sets the value in this elements store, category needed if categorize function used --- @tparam string category[opt] the category to get such as player name or force name --- @tparam any value the value to set for this define, must be valid for its type ie for checkbox etc --- @treturn boolean true if the value was set -function Prototype:set_store(category,value) - if not self.store then return end - return Store.set(self.store,category,value) -end - ---- Sets the value in this elements store to nil, category needed if categorize function used --- @tparam[opt] string category the category to get such as player name or force name --- @treturn boolean true if the value was set -function Prototype:clear_store(category) - if not self.store then return end - return Store.clear(self.store,category) -end - -return Constructor \ No newline at end of file +return Prototype \ No newline at end of file diff --git a/expcore/gui/test.lua b/expcore/gui/test.lua deleted file mode 100644 index 38319c3f..00000000 --- a/expcore/gui/test.lua +++ /dev/null @@ -1,663 +0,0 @@ ---[[-- Core Module - Gui - @module Gui - @alias tests -]] - ---- Test. --- This file creates a test gui that is used to test every input method --- note that this does not cover every permutation only features in independence --- for example store in most cases is just by player name, but other store methods are tested with checkbox --- @section test - -local Gui = require 'expcore.gui' --- @dep expcore.gui -local format_chat_colour,table_keys = ext_require('expcore.common','format_chat_colour','table_keys') --- @dep expcore.common -local Colors = require 'resources.color_presets' --- @dep resources.color_presets -local Event = require 'utils.event' --- @dep utils.event -local Store = require 'expcore.store' --- @dep expcore.store - -local tests = {} - ---[[ - Toolbar Tests - > No display - Toolbar button with no display - > With caption - Toolbar button with a caption display - > With icons - Toolbar button with an icon -]] - -Gui.new_toolbar_button('click-1') -:set_post_authenticator(function(player,button_name) - return global.click_one -end) -:on_click(function(player,element) - player.print('CLICK 1') -end) - -Gui.new_toolbar_button('click-2') -:set_caption('Click Two') -:set_post_authenticator(function(player,button_name) - return global.click_two -end) -:on_click(function(player,element) - player.print('CLICK 2') -end) - -Gui.new_toolbar_button('click-3') -:set_sprites('utility/questionmark') -:set_post_authenticator(function(player,button_name) - return global.click_three -end) -:on_click(function(player,element) - player.print('CLICK 3') -end) - ---[[ - Center Frame Tests - > Main test gui - Main test gui triggers all other tests -]] - -local test_gui = -Gui.new_center_frame('gui-test-open') -:set_caption('Open Test Gui') -:set_tooltip('Main test gui triggers all other tests') -:set_post_authenticator(function(player,button_name) - return global.show_test_gui -end) - -:on_creation(function(player,frame) - for test_group_name,test_group in pairs(tests) do - - player.print('Starting tests for: '..format_chat_colour(test_group_name,Colors.cyan)) - - local pass_count = 0 - local test_count = 0 - - local flow = frame.add{ - type='flow', - name=test_group_name, - direction='vertical' - } - - for test_name,test in pairs(test_group) do - local test_function = type(test) == 'function' and test or test.draw_to - test_count = test_count+1 - - local success,err = pcall(test_function,test,flow) - if success then - pass_count = pass_count+1 - else - player.print('Failed Test: '..format_chat_colour(test_name,Colors.red)) - log('Gui Test Failed: '..test_name..' stacktrace:\n'..err) - end - - end - - if pass_count == test_count then - player.print('All tests '..format_chat_colour('passed',Colors.green)..' ('..test_group_name..')') - else - player.print('Passed '..format_chat_colour(pass_count..'/'..test_count,Colors.cyan)..' ('..test_group_name..')') - end - - end -end) - ---[[ - Left Frame Test - > Left frame which holds all online player names, updates when player leaves or joins -]] - -local left_frame = -Gui.new_left_frame('test-left-frame') -:set_caption('Test Left Gui') -:set_tooltip('Left frame which holds all online player names, updates when player leaves or joins') -:set_post_authenticator(function(player,button_name) - return global.show_test_gui -end) - -:set_open_by_default() -:on_creation(function(_player,frame) - for _,player in pairs(game.connected_players) do - frame.add{ - type='label', - caption=player.name - } - end -end) - -Event.add(defines.events.on_player_joined_game,left_frame 'update_all') -Event.add(defines.events.on_player_left_game,left_frame 'update_all') - ---[[ - Popup Test - > Allows opening a popup which contains the players name and tick it was opened -]] - -local test_popup = -Gui.new_popup('test-popup') -:on_creation(function(player,frame) - frame.add{ - type='label', - caption=player.name - } - frame.add{ - type='label', - caption=game.tick - } -end) - -Gui.new_toolbar_button('test-popup-open') -:set_caption('Test Popup') -:set_tooltip('Allows opening a popup which contains the players name and tick it was opened') -:set_post_authenticator(function(player,button_name) - return global.show_test_gui -end) -:on_click(function(player,element) - test_popup(player,300) -end) - ---[[ - Button Tests - > No display - Simple button which has no display - > Caption - Simple button but has a caption on it - > Icons - Button with an icon display plus two icons for hover and select - > Auth - Button which can only be passed when auth is true (press no display to toggle; needs reopen) -]] - -local button_no_display = -Gui.new_button('test-button-no-display') -:set_tooltip('Button no display') -:on_click(function(player,element) - player.print('Button no display') - global.test_auth_button = not global.test_auth_button - player.print('Auth Button auth state: '..tostring(global.test_auth_button)) -end) - -local button_with_caption = -Gui.new_button('test-button-with-caption') -:set_tooltip('Button with caption') -:set_caption('Button Caption') -:on_click(function(player,element) - player.print('Button with caption') -end) - -local button_with_icon = -Gui.new_button('test-button-with-icon') -:set_tooltip('Button with icons') -:set_sprites('utility/warning_icon','utility/warning','utility/warning_white') -:on_click(function(player,element) - player.print('Button with icons') -end) - -local button_with_auth = -Gui.new_button('test-button-with-auth') -:set_tooltip('Button with auth') -:set_post_authenticator(function(player,button_name) - return global.test_auth_button -end) -:on_click(function(player,element) - player.print('Button with auth') -end) - -tests.Buttons = { - ['No display']=button_no_display, - ['Caption']=button_with_caption, - ['Icons']=button_with_icon, - ['Auth']=button_with_auth -} - ---[[ - Checkbox Test - > Local -- Simple checkbox that can toggle - > Game store -- Checkbox which syncs its state between all players - > Force store -- Checkbox which syncs its state with all players on the same force - > Player store -- Checkbox that stores its state between re-draws -]] - -local checkbox_local = -Gui.new_checkbox('test-checkbox-local') -:set_tooltip('Checkbox local') -:set_caption('Checkbox Local') -:on_element_update(function(player,element,state) - player.print('Checkbox local: '..tostring(state)) -end) - -local checkbox_game = -Gui.new_checkbox('test-checkbox-store-game') -:set_tooltip('Checkbox store game') -:set_caption('Checkbox Store Game') -:add_store() -:on_element_update(function(player,element,state) - player.print('Checkbox store game: '..tostring(state)) -end) - -local checkbox_force = -Gui.new_checkbox('test-checkbox-store-force') -:set_tooltip('Checkbox store force') -:set_caption('Checkbox Store Force') -:add_store(Gui.categorize_by_force) -:on_element_update(function(player,element,state) - player.print('Checkbox store force: '..tostring(state)) -end) - -local checkbox_player = -Gui.new_checkbox('test-checkbox-store-player') -:set_tooltip('Checkbox store player') -:set_caption('Checkbox Store Player') -:add_store(Gui.categorize_by_player) -:on_element_update(function(player,element,state) - player.print('Checkbox store player: '..tostring(state)) -end) - -tests.Checkboxes = { - ['Local']=checkbox_local, - ['Game store']=checkbox_game, - ['Force store']=checkbox_force, - ['Player store']=checkbox_player -} - ---[[ - Radiobutton Tests - > Local -- Simple radiobutton that can only be toggled true - > Player store -- Radio button that saves its state between re-draws - > Option set -- A set of radio buttons where only one can be true at a time -]] - -local radiobutton_local = -Gui.new_radiobutton('test-radiobutton-local') -:set_tooltip('Radiobutton local') -:set_caption('Radiobutton Local') -:on_element_update(function(player,element,state) - player.print('Radiobutton local: '..tostring(state)) -end) - -local radiobutton_player = -Gui.new_radiobutton('test-radiobutton-store') -:set_tooltip('Radiobutton store') -:set_caption('Radiobutton Store') -:add_store(Gui.categorize_by_player) -:on_element_update(function(player,element,state) - player.print('Radiobutton store: '..tostring(state)) -end) - -local radiobutton_option_set = -Gui.new_radiobutton_option_set('gui.test.share',function(value,category) - game.print('Radiobutton option set for: '..category..' is now: '..tostring(value)) -end,Gui.categorize_by_player) - -local radiobutton_option_one = -Gui.new_radiobutton('test-radiobutton-option-one') -:set_tooltip('Radiobutton option set') -:set_caption('Radiobutton Option One') -:add_as_option(radiobutton_option_set,'One') -:on_element_update(function(player,element,state) - player.print('Radiobutton option one: '..tostring(state)) -end) - -local radiobutton_option_two = -Gui.new_radiobutton('test-radiobutton-option-two') -:set_tooltip('Radiobutton option set') -:set_caption('Radiobutton Option Two') -:add_as_option(radiobutton_option_set,'Two') -:on_element_update(function(player,element,state) - player.print('Radiobutton option two: '..tostring(state)) -end) - -local radiobutton_option_three = -Gui.new_radiobutton('test-radiobutton-option-three') -:set_tooltip('Radiobutton option set') -:set_caption('Radiobutton Option Three') -:add_as_option(radiobutton_option_set,'Three') -:on_element_update(function(player,element,state) - player.print('Radiobutton option three: '..tostring(state)) -end) - -tests.Radiobuttons = { - ['Local']=radiobutton_local, - ['Player store']=radiobutton_player, - ['Option set']=function(self,frame) - Gui.draw_option_set(radiobutton_option_set,frame) - end -} - ---[[ - Dropdown Test - > Local static general -- Simple dropdown with all static options and general handler - > Player startic general -- Dropdown with all static options and general handler and stores option between re-draws - > Local static case -- Dropdown with all static options but case handlers and a general handler - > Player static case -- Dropdown with all static options but case handlers and a general handler and stores option between re-draws - > Local dynamic -- Dropdown with one static option with the reset generated by a function - > Player dynamic -- Dropdown with one static option with the reset generated by a function and stores option between re-draws -]] - -local dropdown_local_static_general = -Gui.new_dropdown('test-dropdown-local-static-general') -:set_tooltip('Dropdown local static general') -:add_options('One','Two','Three','Four') -:on_element_update(function(player,element,value) - player.print('Dropdown local static general: '..tostring(value)) -end) - -local dropdown_player_static_general = -Gui.new_dropdown('test-dropdown-store-static-general') -:set_tooltip('Dropdown store static general') -:add_options('One','Two','Three','Four') -:add_store(Gui.categorize_by_player) -:on_element_update(function(player,element,value) - player.print('Dropdown store static general: '..tostring(value)) -end) - -local function print_option_selected_1(player,element,value) - player.print('Dropdown local static case (case): '..tostring(value)) -end - -local dropdown_local_static_case = -Gui.new_dropdown('test-dropdown-local-static-case') -:set_tooltip('Dropdown local static case') -:add_options('One','Two') -:add_option_callback('One',print_option_selected_1) -:add_option_callback('Two',print_option_selected_1) -:add_option_callback('Three',print_option_selected_1) -:add_option_callback('Four',print_option_selected_1) -:on_element_update(function(player,element,value) - player.print('Dropdown local static case (general): '..tostring(value)) -end) - -local function print_option_selected_2(player,element,value) - player.print('Dropdown store static case (case): '..tostring(value)) -end - -local dropdown_player_static_case = -Gui.new_dropdown('test-dropdown-store-static-case') -:set_tooltip('Dropdown store static case') -:add_store(Gui.categorize_by_player) -:add_options('One','Two') -:add_option_callback('One',print_option_selected_2) -:add_option_callback('Two',print_option_selected_2) -:add_option_callback('Three',print_option_selected_2) -:add_option_callback('Four',print_option_selected_2) -:on_element_update(function(player,element,value) - player.print('Dropdown store static case (general): '..tostring(value)) -end) - -local dropdown_local_dynamic = -Gui.new_dropdown('test-dropdown-local-dynamic') -:set_tooltip('Dropdown local dynamic') -:add_options('Static') -:add_dynamic(function(player,element) - return table_keys(Colors) -end) -:on_element_update(function(player,element,value) - player.print('Dropdown local dynamic: '..tostring(value)) -end) - -local dropdown_player_dynamic = -Gui.new_dropdown('test-dropdown-store-dynamic') -:set_tooltip('Dropdown store dynamic') -:add_options('Static') -:add_dynamic(function(player,element) - return table_keys(Colors) -end) -:add_store(Gui.categorize_by_player) -:on_element_update(function(player,element,value) - player.print('Dropdown store dynamic: '..tostring(value)) -end) - -tests.Dropdowns = { - ['Local static general']=dropdown_local_static_general, - ['Player startic general']=dropdown_player_static_general, - ['Local static case']=dropdown_local_static_case, - ['Player static case']=dropdown_player_static_case, - ['Local dynamic general']=dropdown_local_dynamic, - ['Player dynamic general']=dropdown_player_dynamic -} - ---[[ - List Box Tests - > Local -- A list box with all static options and general handler - > Store -- A list box with all static options and general handler and stores options between re-draws -]] - -local list_box_local = -Gui.new_list_box('test-list-box-local') -:set_tooltip('List box local') -:add_options('One','Two','Three','Four') -:on_element_update(function(player,element,value) - player.print('Dropdown local: '..tostring(value)) -end) - -local list_box_player = -Gui.new_list_box('test-list-box-store') -:set_tooltip('List box store') -:add_options('One','Two','Three','Four') -:add_store(Gui.categorize_by_player) -:on_element_update(function(player,element,value) - player.print('Dropdown store: '..tostring(value)) -end) - -tests["List Boxes"] = { - ['Local']=list_box_local, - ['Player']=list_box_player -} - ---[[ - Slider Tests - > Local default -- Simple slider with default range - > Store default -- Slider with default range that stores value between re-draws - > Static range -- Simple slider with a static range - > Dynamic range -- Slider with a dynamic range - > Local label -- Simple slider with default range which has a label - > Store label -- Slider with default range which has a label and stores value between re-draws -]] - -local slider_local_default = -Gui.new_slider('test-slider-local-default') -:set_tooltip('Slider local default') -:on_element_update(function(player,element,value,percent) - player.print('Slider local default: '..tostring(math.round(value))..' '..tostring(math.round(percent,1))) -end) - - -local slider_player_default = -Gui.new_slider('test-slider-store-default') -:set_tooltip('Slider store default') -:add_store(Gui.categorize_by_player) -:on_element_update(function(player,element,value,percent) - player.print('Slider store default: '..tostring(math.round(value))..' '..tostring(math.round(percent,1))) -end) - -local slider_static = -Gui.new_slider('test-slider-static-range') -:set_tooltip('Slider static range') -:set_range(5,50) -:on_element_update(function(player,element,value,percent) - player.print('Slider static range: '..tostring(math.round(value))..' '..tostring(math.round(percent,1))) -end) - -local slider_dynamic = -Gui.new_slider('test-slider-dynamic-range') -:set_tooltip('Slider dynamic range') -:set_range(function(player,element) - return player.index - 5 -end,function(player,element) - return player.index + 4 -end) -:on_element_update(function(player,element,value,percent) - player.print('Slider dynamic range: '..tostring(math.round(value))..' '..tostring(math.round(percent,1))) -end) - -local label_slider_local = -Gui.new_slider('test-slider-local-label') -:set_tooltip('Slider local label') -:enable_auto_draw_label() -:on_element_update(function(player,element,value,percent) - player.print('Slider local label: '..tostring(math.round(value))..' '..tostring(math.round(percent,1))) -end) - -local label_slider_player = -Gui.new_slider('test-slider-store-label') -:set_tooltip('Slider store label') -:enable_auto_draw_label() -:add_store(Gui.categorize_by_player) -:on_element_update(function(player,element,value,percent) - player.print('Slider store label: '..tostring(math.round(value))..' '..tostring(math.round(percent,1))) -end) - -tests.Sliders = { - ['Local default']=slider_local_default, - ['Player default']=slider_player_default, - ['Static range']=slider_static, - ['Dynamic range']=slider_dynamic, - ['Local label']=function(self,frame) - local flow = frame.add{type='flow'} - label_slider_local:draw_to(flow) - end, - ['Player label']=function(self,frame) - local flow = frame.add{type='flow'} - label_slider_player:draw_to(flow) - end -} - ---[[ - Text Tests - > Local field -- Simple text field - > Store field -- Test field that stores text between re-draws - > Local box -- Simple text box - > Wrap box -- Text box which has word wrap and selection disabled -]] - -local text_filed_local = -Gui.new_text_filed('test-text-field-local') -:set_tooltip('Text field local') -:on_element_update(function(player,element,value) - player.print('Text field local: '..value) -end) - -local text_filed_store = -Gui.new_text_filed('test-text-field-store') -:set_tooltip('Text field store') -:add_store(Gui.categorize_by_player) -:on_element_update(function(player,element,value) - player.print('Text field store: '..value) -end) - -local text_box_local = -Gui.new_text_box('test-text-box-local') -:set_tooltip('Text box local') -:on_element_update(function(player,element,value) - player.print('Text box local: '..value) -end) - -local text_box_wrap = -Gui.new_text_box('test-text-box-wrap') -:set_tooltip('Text box wrap') -:set_selectable(false) -:set_word_wrap() -:on_element_update(function(player,element,value) - player.print('Text box wrap: '..value) -end) - -tests.Texts = { - ['Local field']=text_filed_local, - ['Store field']=text_filed_store, - ['Local box']=text_box_local, - ['Wrap box']=text_box_wrap -} - ---[[ - Elem Button Tests - > Local -- Simple elem button - > Default -- Simple elem button which has a default value - > Function -- Elem button which has a dynamic default - > Store -- Elem button which stores its value between re-draws -]] - -local elem_local = -Gui.new_elem_button('test-elem-local') -:set_tooltip('Elem') -:set_type('item') -:on_element_update(function(player,element,value) - player.print('Elem: '..value) -end) - -local elem_default = -Gui.new_elem_button('test-elem-default') -:set_tooltip('Elem default') -:set_type('item') -:set_default('iron-plate') -:on_element_update(function(player,element,value) - player.print('Elem default: '..value) -end) - -local elem_function = -Gui.new_elem_button('test-elem-function') -:set_tooltip('Elem function') -:set_type('item') -:set_default(function(player,element) - return 'iron-plate' -end) -:on_element_update(function(player,element,value) - player.print('Elem function: '..value) -end) - -local elem_store = -Gui.new_elem_button('test-elem-store') -:set_tooltip('Elem store') -:set_type('item') -:add_store(Gui.categorize_by_player) -:on_element_update(function(player,element,value) - player.print('Elem store: '..value) -end) - -tests["Elem Buttons"] = { - ['Local']=elem_local, - ['Default']=elem_default, - ['Function']=elem_function, - ['Store']=elem_store -} - ---[[ - Progress bar tests - > Simple -- Progress bar that fills every 2 seconds - > Store -- Progress bar that fills every 5 seconds with synced value - > Reverse -- Progress bar that decreases every 2 seconds -]] - -local progressbar_one = -Gui.new_progressbar('test-prog-one') -:set_default_maximum(120) -:on_complete(function(player,element,reset_element) - reset_element() -end) - -local progressbar_two = -Gui.new_progressbar('test-prog-one') -:set_default_maximum(300) -:add_store(Gui.categorize_by_force) -:on_complete(function(player,element,reset_element) - reset_element() -end) -:on_store_complete(function(category,reset_store) - reset_store() -end) - -local progressbar_three = -Gui.new_progressbar('test-prog-one') -:set_default_maximum(120) -:use_count_down() -:on_complete(function(player,element,reset_element) - reset_element() -end) - -Event.add(defines.events.on_tick,function() - progressbar_one:increment() - progressbar_three:decrement() - local categories = Store.get_keys(progressbar_two.store) - for _,category in pairs(categories) do - progressbar_two:increment(1,category) - end -end) - -tests["Progress Bars"] = { - ['Simple']=progressbar_one, - ['Store']=progressbar_two, - ['Reverse']=progressbar_three -} \ No newline at end of file From a749c905299019bdb830a4582b99aea5226fd1d7 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sun, 25 Aug 2019 00:50:42 +0100 Subject: [PATCH 03/26] Prototype Done with docs --- docs/addons/Advanced-Start.html | 2 +- docs/addons/Chat-Popups.html | 2 +- docs/addons/Chat-Reply.html | 2 +- docs/addons/Compilatron.html | 2 +- docs/addons/Damage-Popups.html | 2 +- docs/addons/Death-Logger.html | 2 +- docs/addons/Discord-Alerts.html | 2 +- docs/addons/Player-Colours.html | 2 +- docs/addons/Pollution-Grading.html | 2 +- docs/addons/Scorched-Earth.html | 2 +- docs/addons/Spawn-Area.html | 2 +- docs/commands/Admin-Chat.html | 2 +- docs/commands/Bonus.html | 2 +- docs/commands/Cheat-Mode.html | 2 +- docs/commands/Clear-Inventory.html | 2 +- docs/commands/Debug.html | 2 +- docs/commands/Find.html | 2 +- docs/commands/Help.html | 2 +- docs/commands/Home.html | 2 +- docs/commands/Interface.html | 2 +- docs/commands/Jail.html | 2 +- docs/commands/Kill.html | 2 +- docs/commands/Me.html | 2 +- docs/commands/Rainbow.html | 2 +- docs/commands/Repair.html | 2 +- docs/commands/Reports.html | 2 +- docs/commands/Roles.html | 2 +- docs/commands/Spawn.html | 2 +- docs/commands/Tag.html | 2 +- docs/commands/Teleport.html | 2 +- docs/commands/Warnings.html | 2 +- docs/configs/Advanced-Start.html | 2 +- docs/configs/Bonuses.html | 2 +- docs/configs/Chat-Reply.html | 2 +- docs/configs/Commands-Auth-Admin.html | 2 +- docs/configs/Commands-Auth-Roles.html | 2 +- .../Commands-Auth-Runtime-Disable.html | 2 +- docs/configs/Commands-Parse-Roles.html | 2 +- docs/configs/Commands-Parse.html | 2 +- docs/configs/Compilatron.html | 2 +- docs/configs/Death-Logger.html | 2 +- docs/configs/Discord-Alerts.html | 2 +- docs/configs/File-Loader.html | 2 +- docs/configs/Permission-Groups.html | 2 +- docs/configs/Player-List.html | 2 +- docs/configs/Pollution-Grading.html | 2 +- docs/configs/Popup-Messages.html | 2 +- docs/configs/Preset-Player-Colours.html | 2 +- docs/configs/Repair.html | 2 +- docs/configs/Rockets.html | 2 +- docs/configs/Roles.html | 2 +- docs/configs/Science.html | 2 +- docs/configs/Scorched-Earth.html | 2 +- docs/configs/Spawn-Area.html | 2 +- docs/configs/Tasks.html | 2 +- docs/configs/Warnings.html | 2 +- docs/configs/Warps.html | 2 +- docs/control/Jail.html | 2 +- docs/control/Production.html | 2 +- docs/control/Reports.html | 2 +- docs/control/Rockets.html | 2 +- docs/control/Tasks.html | 2 +- docs/control/Warnings.html | 2 +- docs/control/Warps.html | 2 +- docs/core/Commands.html | 2 +- docs/core/Common-Library.html | 2 +- docs/core/Gui.html | 11216 ++-------------- docs/core/Permissions-Groups.html | 2 +- docs/core/Roles.html | 2 +- docs/core/Store.html | 104 +- docs/core/Sudo.html | 2 +- docs/guis/Player-List.html | 2 +- docs/guis/Rocket-Info.html | 2 +- docs/guis/Science-Info.html | 2 +- docs/guis/Task-List.html | 2 +- docs/guis/Warps-List.html | 2 +- docs/index.html | 8 +- docs/modules/Gui.html | 569 +- docs/modules/control.html | 2 +- docs/modules/expcore.gui.html | 415 +- .../utils.alien_evolution_progress.html | 2 +- docs/modules/utils.core.html | 2 +- docs/modules/utils.debug.html | 2 +- docs/modules/utils.dump_env.html | 2 +- docs/modules/utils.event.html | 2 +- docs/modules/utils.event_core.html | 2 +- docs/modules/utils.math.html | 2 +- docs/modules/utils.recipe_locker.html | 2 +- docs/modules/utils.state_machine.html | 2 +- docs/modules/utils.table.html | 2 +- docs/modules/utils.task.html | 2 +- docs/modules/utils.timestamp.html | 2 +- docs/topics/license.html | 2 +- docs/topics/readme.md.html | 2 +- expcore/gui.lua | 5 +- expcore/gui/core.lua | 17 + expcore/gui/prototype.lua | 557 +- expcore/store.lua | 71 +- 98 files changed, 1890 insertions(+), 11250 deletions(-) diff --git a/docs/addons/Advanced-Start.html b/docs/addons/Advanced-Start.html index b51f20a5..f1689524 100644 --- a/docs/addons/Advanced-Start.html +++ b/docs/addons/Advanced-Start.html @@ -348,7 +348,7 @@ generated by LDoc diff --git a/docs/addons/Chat-Popups.html b/docs/addons/Chat-Popups.html index fdb6a24b..e6749dcd 100644 --- a/docs/addons/Chat-Popups.html +++ b/docs/addons/Chat-Popups.html @@ -349,7 +349,7 @@ generated by LDoc diff --git a/docs/addons/Chat-Reply.html b/docs/addons/Chat-Reply.html index 91b5fa1d..bf0b3043 100644 --- a/docs/addons/Chat-Reply.html +++ b/docs/addons/Chat-Reply.html @@ -376,7 +376,7 @@ generated by LDoc diff --git a/docs/addons/Compilatron.html b/docs/addons/Compilatron.html index 889058f8..a0e1cfcf 100644 --- a/docs/addons/Compilatron.html +++ b/docs/addons/Compilatron.html @@ -585,7 +585,7 @@ generated by LDoc diff --git a/docs/addons/Damage-Popups.html b/docs/addons/Damage-Popups.html index 99fe3f44..d0a30aa0 100644 --- a/docs/addons/Damage-Popups.html +++ b/docs/addons/Damage-Popups.html @@ -349,7 +349,7 @@ generated by LDoc diff --git a/docs/addons/Death-Logger.html b/docs/addons/Death-Logger.html index 590c7e4b..1eefd356 100644 --- a/docs/addons/Death-Logger.html +++ b/docs/addons/Death-Logger.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/addons/Discord-Alerts.html b/docs/addons/Discord-Alerts.html index 3e22e16a..42c5fbd8 100644 --- a/docs/addons/Discord-Alerts.html +++ b/docs/addons/Discord-Alerts.html @@ -460,7 +460,7 @@ generated by LDoc diff --git a/docs/addons/Player-Colours.html b/docs/addons/Player-Colours.html index 94b6590b..3081c6fa 100644 --- a/docs/addons/Player-Colours.html +++ b/docs/addons/Player-Colours.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/addons/Pollution-Grading.html b/docs/addons/Pollution-Grading.html index ed128319..9cca3b35 100644 --- a/docs/addons/Pollution-Grading.html +++ b/docs/addons/Pollution-Grading.html @@ -320,7 +320,7 @@ generated by LDoc diff --git a/docs/addons/Scorched-Earth.html b/docs/addons/Scorched-Earth.html index 16ca5e5a..7024e35e 100644 --- a/docs/addons/Scorched-Earth.html +++ b/docs/addons/Scorched-Earth.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/addons/Spawn-Area.html b/docs/addons/Spawn-Area.html index d708d75a..8b23f8b4 100644 --- a/docs/addons/Spawn-Area.html +++ b/docs/addons/Spawn-Area.html @@ -376,7 +376,7 @@ generated by LDoc diff --git a/docs/commands/Admin-Chat.html b/docs/commands/Admin-Chat.html index 7dc05f4a..50386c57 100644 --- a/docs/commands/Admin-Chat.html +++ b/docs/commands/Admin-Chat.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Bonus.html b/docs/commands/Bonus.html index 58ab06cc..99979a83 100644 --- a/docs/commands/Bonus.html +++ b/docs/commands/Bonus.html @@ -500,7 +500,7 @@ generated by LDoc diff --git a/docs/commands/Cheat-Mode.html b/docs/commands/Cheat-Mode.html index 6873b6fd..05be743e 100644 --- a/docs/commands/Cheat-Mode.html +++ b/docs/commands/Cheat-Mode.html @@ -361,7 +361,7 @@ generated by LDoc diff --git a/docs/commands/Clear-Inventory.html b/docs/commands/Clear-Inventory.html index c280d9eb..2632583e 100644 --- a/docs/commands/Clear-Inventory.html +++ b/docs/commands/Clear-Inventory.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Debug.html b/docs/commands/Debug.html index 6ebb7007..18b07c71 100644 --- a/docs/commands/Debug.html +++ b/docs/commands/Debug.html @@ -365,7 +365,7 @@ generated by LDoc diff --git a/docs/commands/Find.html b/docs/commands/Find.html index e2cd0dcc..9dcfd43f 100644 --- a/docs/commands/Find.html +++ b/docs/commands/Find.html @@ -360,7 +360,7 @@ generated by LDoc diff --git a/docs/commands/Help.html b/docs/commands/Help.html index cece090c..b7a7c97e 100644 --- a/docs/commands/Help.html +++ b/docs/commands/Help.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/commands/Home.html b/docs/commands/Home.html index 3c7a8205..2eaa26e9 100644 --- a/docs/commands/Home.html +++ b/docs/commands/Home.html @@ -458,7 +458,7 @@ generated by LDoc diff --git a/docs/commands/Interface.html b/docs/commands/Interface.html index bba2600b..36f1fa37 100644 --- a/docs/commands/Interface.html +++ b/docs/commands/Interface.html @@ -416,7 +416,7 @@ generated by LDoc diff --git a/docs/commands/Jail.html b/docs/commands/Jail.html index 43f5e5e8..0ef7ecfc 100644 --- a/docs/commands/Jail.html +++ b/docs/commands/Jail.html @@ -611,7 +611,7 @@ generated by LDoc diff --git a/docs/commands/Kill.html b/docs/commands/Kill.html index fa88b477..186c5ea4 100644 --- a/docs/commands/Kill.html +++ b/docs/commands/Kill.html @@ -389,7 +389,7 @@ generated by LDoc diff --git a/docs/commands/Me.html b/docs/commands/Me.html index 6865f47d..3157f4bb 100644 --- a/docs/commands/Me.html +++ b/docs/commands/Me.html @@ -360,7 +360,7 @@ generated by LDoc diff --git a/docs/commands/Rainbow.html b/docs/commands/Rainbow.html index 4a57c50a..6a569356 100644 --- a/docs/commands/Rainbow.html +++ b/docs/commands/Rainbow.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Repair.html b/docs/commands/Repair.html index 0bce4305..e4b1efd1 100644 --- a/docs/commands/Repair.html +++ b/docs/commands/Repair.html @@ -321,7 +321,7 @@ generated by LDoc diff --git a/docs/commands/Reports.html b/docs/commands/Reports.html index cfe0a159..baeb2896 100644 --- a/docs/commands/Reports.html +++ b/docs/commands/Reports.html @@ -585,7 +585,7 @@ generated by LDoc diff --git a/docs/commands/Roles.html b/docs/commands/Roles.html index cc0ee869..63985463 100644 --- a/docs/commands/Roles.html +++ b/docs/commands/Roles.html @@ -557,7 +557,7 @@ generated by LDoc diff --git a/docs/commands/Spawn.html b/docs/commands/Spawn.html index 859247a4..0e9f0d69 100644 --- a/docs/commands/Spawn.html +++ b/docs/commands/Spawn.html @@ -389,7 +389,7 @@ generated by LDoc diff --git a/docs/commands/Tag.html b/docs/commands/Tag.html index dfdcbf48..b811ef43 100644 --- a/docs/commands/Tag.html +++ b/docs/commands/Tag.html @@ -443,7 +443,7 @@ generated by LDoc diff --git a/docs/commands/Teleport.html b/docs/commands/Teleport.html index 1848f1a0..37c1228c 100644 --- a/docs/commands/Teleport.html +++ b/docs/commands/Teleport.html @@ -484,7 +484,7 @@ generated by LDoc diff --git a/docs/commands/Warnings.html b/docs/commands/Warnings.html index eb9dd3ff..09a0bc29 100644 --- a/docs/commands/Warnings.html +++ b/docs/commands/Warnings.html @@ -569,7 +569,7 @@ generated by LDoc diff --git a/docs/configs/Advanced-Start.html b/docs/configs/Advanced-Start.html index 0c5783c8..d384d219 100644 --- a/docs/configs/Advanced-Start.html +++ b/docs/configs/Advanced-Start.html @@ -506,7 +506,7 @@ generated by LDoc diff --git a/docs/configs/Bonuses.html b/docs/configs/Bonuses.html index 52c1dcc5..0917c4d5 100644 --- a/docs/configs/Bonuses.html +++ b/docs/configs/Bonuses.html @@ -237,7 +237,7 @@ generated by LDoc diff --git a/docs/configs/Chat-Reply.html b/docs/configs/Chat-Reply.html index 6594a2c5..ea3028b1 100644 --- a/docs/configs/Chat-Reply.html +++ b/docs/configs/Chat-Reply.html @@ -485,7 +485,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Admin.html b/docs/configs/Commands-Auth-Admin.html index d02099b4..7bd92c05 100644 --- a/docs/configs/Commands-Auth-Admin.html +++ b/docs/configs/Commands-Auth-Admin.html @@ -294,7 +294,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Roles.html b/docs/configs/Commands-Auth-Roles.html index 45cda632..da7c62d3 100644 --- a/docs/configs/Commands-Auth-Roles.html +++ b/docs/configs/Commands-Auth-Roles.html @@ -320,7 +320,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Runtime-Disable.html b/docs/configs/Commands-Auth-Runtime-Disable.html index 1e2b5098..b4d1c559 100644 --- a/docs/configs/Commands-Auth-Runtime-Disable.html +++ b/docs/configs/Commands-Auth-Runtime-Disable.html @@ -442,7 +442,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Parse-Roles.html b/docs/configs/Commands-Parse-Roles.html index 47d2034e..fa0b0c81 100644 --- a/docs/configs/Commands-Parse-Roles.html +++ b/docs/configs/Commands-Parse-Roles.html @@ -354,7 +354,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Parse.html b/docs/configs/Commands-Parse.html index a1895ddb..4da164e4 100644 --- a/docs/configs/Commands-Parse.html +++ b/docs/configs/Commands-Parse.html @@ -338,7 +338,7 @@ see ./expcore/commands.lua for more details

generated by LDoc diff --git a/docs/configs/Compilatron.html b/docs/configs/Compilatron.html index 64adcfc4..9e941609 100644 --- a/docs/configs/Compilatron.html +++ b/docs/configs/Compilatron.html @@ -354,7 +354,7 @@ generated by LDoc diff --git a/docs/configs/Death-Logger.html b/docs/configs/Death-Logger.html index 74805d6c..4bc70ffb 100644 --- a/docs/configs/Death-Logger.html +++ b/docs/configs/Death-Logger.html @@ -416,7 +416,7 @@ generated by LDoc diff --git a/docs/configs/Discord-Alerts.html b/docs/configs/Discord-Alerts.html index 07cba503..07f576a8 100644 --- a/docs/configs/Discord-Alerts.html +++ b/docs/configs/Discord-Alerts.html @@ -237,7 +237,7 @@ generated by LDoc diff --git a/docs/configs/File-Loader.html b/docs/configs/File-Loader.html index 58ae563e..b17c2ac5 100644 --- a/docs/configs/File-Loader.html +++ b/docs/configs/File-Loader.html @@ -240,7 +240,7 @@ generated by LDoc diff --git a/docs/configs/Permission-Groups.html b/docs/configs/Permission-Groups.html index 87281de1..d8d2b6e5 100644 --- a/docs/configs/Permission-Groups.html +++ b/docs/configs/Permission-Groups.html @@ -295,7 +295,7 @@ generated by LDoc diff --git a/docs/configs/Player-List.html b/docs/configs/Player-List.html index a64923b7..7767e286 100644 --- a/docs/configs/Player-List.html +++ b/docs/configs/Player-List.html @@ -812,7 +812,7 @@ generated by LDoc diff --git a/docs/configs/Pollution-Grading.html b/docs/configs/Pollution-Grading.html index bb836f8f..9dc1dde3 100644 --- a/docs/configs/Pollution-Grading.html +++ b/docs/configs/Pollution-Grading.html @@ -384,7 +384,7 @@ generated by LDoc diff --git a/docs/configs/Popup-Messages.html b/docs/configs/Popup-Messages.html index 8834a58c..f7509b4e 100644 --- a/docs/configs/Popup-Messages.html +++ b/docs/configs/Popup-Messages.html @@ -414,7 +414,7 @@ generated by LDoc diff --git a/docs/configs/Preset-Player-Colours.html b/docs/configs/Preset-Player-Colours.html index d5e06589..ebaf5a99 100644 --- a/docs/configs/Preset-Player-Colours.html +++ b/docs/configs/Preset-Player-Colours.html @@ -324,7 +324,7 @@ generated by LDoc diff --git a/docs/configs/Repair.html b/docs/configs/Repair.html index 741a2beb..e25605ab 100644 --- a/docs/configs/Repair.html +++ b/docs/configs/Repair.html @@ -414,7 +414,7 @@ generated by LDoc diff --git a/docs/configs/Rockets.html b/docs/configs/Rockets.html index 35e5d51b..6d00c415 100644 --- a/docs/configs/Rockets.html +++ b/docs/configs/Rockets.html @@ -834,7 +834,7 @@ generated by LDoc diff --git a/docs/configs/Roles.html b/docs/configs/Roles.html index 2fc9736f..f068d198 100644 --- a/docs/configs/Roles.html +++ b/docs/configs/Roles.html @@ -292,7 +292,7 @@ generated by LDoc diff --git a/docs/configs/Science.html b/docs/configs/Science.html index 65bcb95e..70d9b4bf 100644 --- a/docs/configs/Science.html +++ b/docs/configs/Science.html @@ -354,7 +354,7 @@ generated by LDoc diff --git a/docs/configs/Scorched-Earth.html b/docs/configs/Scorched-Earth.html index 9de50ddf..7b59c252 100644 --- a/docs/configs/Scorched-Earth.html +++ b/docs/configs/Scorched-Earth.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/configs/Spawn-Area.html b/docs/configs/Spawn-Area.html index d72010dc..22399910 100644 --- a/docs/configs/Spawn-Area.html +++ b/docs/configs/Spawn-Area.html @@ -744,7 +744,7 @@ generated by LDoc diff --git a/docs/configs/Tasks.html b/docs/configs/Tasks.html index 50107b1f..d4eabb34 100644 --- a/docs/configs/Tasks.html +++ b/docs/configs/Tasks.html @@ -384,7 +384,7 @@ generated by LDoc diff --git a/docs/configs/Warnings.html b/docs/configs/Warnings.html index d02fb163..fdf89564 100644 --- a/docs/configs/Warnings.html +++ b/docs/configs/Warnings.html @@ -355,7 +355,7 @@ generated by LDoc diff --git a/docs/configs/Warps.html b/docs/configs/Warps.html index 76a67c3e..8fb76e39 100644 --- a/docs/configs/Warps.html +++ b/docs/configs/Warps.html @@ -684,7 +684,7 @@ generated by LDoc diff --git a/docs/control/Jail.html b/docs/control/Jail.html index 8bf0dabd..6280d0cf 100644 --- a/docs/control/Jail.html +++ b/docs/control/Jail.html @@ -1208,7 +1208,7 @@ generated by LDoc diff --git a/docs/control/Production.html b/docs/control/Production.html index 48c4e2d0..5d253abf 100644 --- a/docs/control/Production.html +++ b/docs/control/Production.html @@ -1329,7 +1329,7 @@ generated by LDoc diff --git a/docs/control/Reports.html b/docs/control/Reports.html index ec69b942..d8056fbf 100644 --- a/docs/control/Reports.html +++ b/docs/control/Reports.html @@ -1110,7 +1110,7 @@ generated by LDoc diff --git a/docs/control/Rockets.html b/docs/control/Rockets.html index cc03876e..6a64ec4b 100644 --- a/docs/control/Rockets.html +++ b/docs/control/Rockets.html @@ -984,7 +984,7 @@ generated by LDoc diff --git a/docs/control/Tasks.html b/docs/control/Tasks.html index c4ff0bac..e0504c47 100644 --- a/docs/control/Tasks.html +++ b/docs/control/Tasks.html @@ -1039,7 +1039,7 @@ generated by LDoc diff --git a/docs/control/Warnings.html b/docs/control/Warnings.html index 09e669fd..b981575f 100644 --- a/docs/control/Warnings.html +++ b/docs/control/Warnings.html @@ -1465,7 +1465,7 @@ generated by LDoc diff --git a/docs/control/Warps.html b/docs/control/Warps.html index 1edc8de5..0abafcc4 100644 --- a/docs/control/Warps.html +++ b/docs/control/Warps.html @@ -1413,7 +1413,7 @@ generated by LDoc diff --git a/docs/core/Commands.html b/docs/core/Commands.html index 652d0f97..1fdcc0fb 100644 --- a/docs/core/Commands.html +++ b/docs/core/Commands.html @@ -1972,7 +1972,7 @@ generated by LDoc diff --git a/docs/core/Common-Library.html b/docs/core/Common-Library.html index f5b36e19..79f75a57 100644 --- a/docs/core/Common-Library.html +++ b/docs/core/Common-Library.html @@ -2480,7 +2480,7 @@ generated by LDoc diff --git a/docs/core/Gui.html b/docs/core/Gui.html index 7377280e..b0e22e17 100644 --- a/docs/core/Gui.html +++ b/docs/core/Gui.html @@ -41,22 +41,9 @@ @@ -216,22 +203,9 @@ @@ -251,11 +225,7 @@

Gui core

-

Core Module - Gui - - This file is used to require all the different elements of the gui module - - each module has an outline here but for more details see their separate files in ./gui - - please read the files for more documentation that cant be shown here - - please note there is a rework planned but not started

+

Core Module - Gui

@@ -270,845 +240,105 @@ -

Dependencies

+

Concept Base

- + + - + + - + + - + + - + + - + + - + + - - - - - - - - - - - - - - - - + +
expcore.gui.corePrototype:clone(concept_name)Used to copy all the settings from one concept to another and removing links to the orginal
expcore.gui.instancesPrototype:new_event(event_name[, factorio_event][, event_condition])Adds a new event trigger to the concept which can be linked to a factorio event
expcore.gui.elements.buttonsPrototype:on_custom_event(handler)Adds a custom event handler, replace with the name of the event
expcore.gui.elements.checkboxPrototype:raise_event(event_name[, event={}][, from_factorio=false])Raises a custom event, folowing keys included automaticlly: concept, event name, game tick, player from player_index, element if valid
expcore.gui.elements.dropdownPrototype:new_property(property_name, default[, setter_callback])Adds a new property to the concept, such as caption, tooltip, or some custom property you want to control
expcore.gui.elements.sliderPrototype:set_custom_property(value)Sets a new value for a property, triggers setter method if provided, replace with property name
expcore.gui.elements.textPrototype:define_draw(draw_callback)Used to define how the concept is turned into an ingame element or "instance" as we may refer to them
expcore.gui.elements.elem-button
expcore.gui.elements.progress-bar
expcore.gui.concepts.toolbar
expcore.gui.concepts.left
expcore.gui.concepts.center
expcore.gui.concepts.popupsPrototype:draw(parent_element)Calls all the draw functions in order to create this concept in game; will also store and sync the instance if stores are used
-

Center Guis

+

Concept Instances

- + + - + + - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +
expcore.gui.corePrototype:define_instance_store([category_callback])Adds an instance store to the concept; when a new instance is made it is stored so you can access it later
expcore.gui.prototypePrototype.get_instances([category])Gets all insatnces in a category, category may be nil to return all
expcore.gui.concepts.toolbarPrototype.add_instance(element[, category])Adds an instance to this concept, used automatically during concept:draw
utils.game
CenterFrames.get_flow(player)Gets the center flow for a player
CenterFrames.clear_flow(player)Clears the center flow for a player
CenterFrames.draw_frame(player, name)Draws the center frame for a player, if already open then will do nothing
CenterFrames.redraw_frame(player, name)Draws the center frame for a player, if already open then will destroy it and redraw
CenterFrames.toggle_frame(player, name[, state])Toggles if the frame is currently open or not, will open if closed and close if open
CenterFrames.new_frame(permission_name)Creates a new center frame define
CenterFrames._prototype:set_auto_focus([state=true])Sets the frame to be the current active gui when opened and closes all other frames
CenterFrames._prototype:draw_frame(player)Draws this frame to the player, if already open does nothing (will call on_draw to draw to the frame)
CenterFrames._prototype:redraw_frame(player)Draws this frame to the player, if already open it will remove it and redraw it (will call on_draw to draw to the frame)
CenterFrames._prototype:toggle_frame(player)Toggles if the frame is open, if open it will close it and if closed it will open it
CenterFrames._prototype:event_handler([action=update])Creates an event handler that will trigger one of its functions, use with Event.addPrototype.update_instances([category], update_callback)Applies an update function to all instances, simialr use to what table.forEach would be
-

Left Guis

+

Concept Data

- + + - + + - + + - + + - + + - + + - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
expcore.gui.corePrototype:define_data_store([category_callback])Adds a data store to this concept which allows you to store synced/percistent data between instances
expcore.gui.prototypePrototype.get_data([category])Gets the data that is stored for this category
expcore.gui.concepts.toolbarPrototype.set_data([category], value)Sets the data that is stored for this category
expcore.gui.elements.buttonsPrototype.clear_data([category])Clears the data that is stored for this category
mod-guiPrototype.update_data([category], update_callback)Updates the data that is stored for this category
utils.gamePrototype:define_combined_store([category_callback], get_callback, set_callback)Used to add a both instance and data stores which are linked together, new instances are synced to current value, changing one instances changes them all
utils.eventPrototype.set_instance_from_store(the)Will set the state of an instance based on the value in the store
LeftFrames.get_flow(player)Gets the left frame flow for a player
LeftFrames.get_frame(name, player)Gets one frame from the left flow by its name
LeftFrames.get_open(player)Gets all open frames for a player, if non are open it will remove the close all button
LeftFrames.toggle_frame(name, player[, state])Toggles the visibility of a left frame, or sets its visibility state
LeftFrames.new_frame(permission_name)Creates a new left frame define
LeftFrames._prototype:set_open_by_default([state=true])Sets if the frame is visible when a player joins, can also be a function to return a boolean
LeftFrames._prototype:set_direction(direction)Sets the direction of the frame, either vertical or horizontal
LeftFrames._prototype:_internal_draw(player)Creates the gui for the first time, used internally
LeftFrames._prototype:get_frame(player)Gets the frame for this define from the left frame flow
LeftFrames._prototype:is_open(player)Returns if the player currently has this define visible
LeftFrames._prototype:toggle(player)Toggles the visibility of the left frame
LeftFrames._prototype:update(player)Updates the contents of the left frame, first tries update callback, other wise will clear and redraw
LeftFrames._prototype:update_all([update_offline=false])Updates the frame for all players, see update
LeftFrames._prototype:redraw(player)Redraws the frame by calling on_draw, will always clear the frame
LeftFrames._prototype:redraw_all([update_offline=false])Redraws the frame for all players, see redraw
LeftFrames._prototype:event_handler([action=update])Creates an event handler that will trigger one of its functions, use with Event.add
- - -

Popups

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
expcore.gui.core
expcore.gui.prototype
utils.game
utils.event
expcore.gui.elements.progress-bar
expcore.gui.elements.buttons
mod-gui
resources.color_presets
utils.global
PopupFrames.get_flow(player)Gets the left flow that contains the popup frames
PopupFrames.open(define_name, player[, open_time], ...)Opens a popup for the player, can give the amount of time it is open as well as params for the draw function
PopupFrames.close_progressProgress bar which when depleted will close the popup frame
PopupFrames.close_buttonA button which can be used to close the gui before the timer runs out
PopupFrames.new_popup([name])Creates a new popup frame define
PopupFrames._prototype:set_default_open_time(amount)Sets the default open time for the popup, will be used if non is provided with open
PopupFrames._prototype:open(player[, open_time], ...)Opens this define for a player, can be given open time and any other params for the draw function
- - -

Toolbar

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
expcore.gui.core
expcore.gui.elements.buttons
expcore.roles
utils.event
utils.game
mod-gui
Toolbar.new_button([name])Adds a new button to the toolbar
Toolbar.add_button(button)Adds an existing buttton to the toolbar
Toolbar.update(player)Updates the player's toolbar with an new buttons or expected change in auth return
- - -

Core

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
utils.gui
utils.game
new_define(prototype[, debug_name])Used to create new element defines from a class prototype, please use the own given by the class
get_define(name[, internal])Gets an element define give the uid, debug name or a copy of the element define
categorize_by_player(element)A categorize function to be used with add_store, each player has their own value
categorize_by_force(element)A categorize function to be used with add_store, each force has its own value
categorize_by_surface(element)A categorize function to be used with add_store, each surface has its own value
draw(name, element)Draws a copy of the element define to the parent element, see draw_to
toggle_enabled(element)Will toggle the enabled state of an element
toggle_visible(element)Will toggle the visiblity of an element
set_padding(element[, up=0][, down=0][, left=0][, right=0])Sets the padding for a gui element
set_padding_style(style[, up=0][, down=0][, left=0][, right=0])Sets the padding for a gui style
create_alignment(element[, name][, horizontal_align='right'][, vertical_align='center'])Allows the creation of an alignment flow to place elements into
destroy_if_valid(element)Destroies an element but tests for it being present and valid first
create_scroll_table(element, table_size, maximal_height[, name='scroll'])Creates a scroll area with a table inside, table can be any size
create_header(element, caption[, tooltip][, right_align][, name='header'])Creates a header section with a label and button area
- - -

Buttons

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
mod-gui
expcore.gui.core
expcore.gui.prototype
Button.new_button([name])Creates a new button element define
Button._prototype:set_sprites(sprite[, hovered_sprite][, clicked_sprite])Adds sprites to a button making it a sprite button
Button._prototype:set_click_filter(filter[, ...])Adds a click / mouse button filter to the button
Button._prototype:set_key_filter(filter[, ...])Adds a control key filter to the button
- - -

Checkboxs

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
expcore.gui.core
expcore.gui.prototype
expcore.store
utils.game
Checkbox.new_checkbox([name])Creates a new checkbox element define
Checkbox.new_radiobutton([name])Creates a new radiobutton element define, has all functions checkbox has
Checkbox._prototype_radiobutton:add_as_option(option_set, option_name)Adds this radiobutton to be an option in the given option set (only one can be true at a time)
Checkbox._prototype_radiobutton:get_store(category, internal)Gets the stored value of the radiobutton or the option set if present
Checkbox._prototype_radiobutton:set_store(category, value, internal)Sets the stored value of the radiobutton or the option set if present
Checkbox.new_option_set(name, callback, categorize)Registers a new option set that can be linked to radiobuttons (only one can be true at a time)
Checkbox.draw_option_set(name, element)Draws all radiobuttons that are part of an option set at once (Gui.draw will not work)
Checkbox.reset_radiobuttons(element[, exclude][, recursive=false])Sets all radiobutton in a element to false (unless excluded) and can act recursively
- - -

Dropdowns

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
expcore.gui.core
expcore.gui.prototype
utils.game
Dropdown.new_dropdown([name])Creates a new dropdown element define
Dropdown.new_list_box([name])Creates a new list box element define
Dropdown._prototype:new_static_options(options[, ...], the)Adds new static options to the dropdown which will trigger the general callback
Dropdown._prototype:new_dynamic_options(callback)Adds a callback which should return a table of values to be added as options for the dropdown (appended after static options)
Dropdown._prototype:add_option_callback(option, callback)Adds a case specific callback which will only run when that option is selected (general case still triggered)
Dropdown.select_value(element, value)Selects the option from a dropdown or list box given the value rather than key
Dropdown.get_selected_value(element)Returns the currently selected value rather than index
- - -

Elem Buttons

- - - - - - - - - - - - - - - - - - - - - - - - - -
expcore.gui.core
expcore.gui.prototype
utils.game
ElemButton.new_elem_button([name])Creates a new elem button element define
ElemButton._prototype.set_typeSets the type of the elem button, the type is required so this must be called at least once
ElemButton._prototype:set_default(value)Sets the default value for the elem button, this may be a function or a string
- - -

Progress Bars

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
expcore.gui.core
expcore.gui.prototype
utils.global
utils.game
ProgressBar.set_maximum(element, amount)Sets the maximum value that represents the end value of the progress bar
ProgressBar.increment(element[, amount=1])Increases the value of the progressbar, if a define is given all of its instances have incremented
ProgressBar.decrement(element[, amount=1])Decreases the value of the progressbar, if a define is given all of its instances have decremented
ProgressBar.new_progressbar([name])Creates a new progressbar element define
ProgressBar._prototype:set_default_maximum(amount)Sets the maximum value that represents the end value of the progress bar
ProgressBar._prototype:use_count_down([state=true])Will set the progress bar to start at 1 and trigger when it hits 0
ProgressBar._prototype:increment([amount=1][, category])Increases the value of the progressbar
ProgressBar._prototype:increment_filtered([amount=1], filter)Increases the value of the progressbar, if the filter condition is met, does not work with store
ProgressBar._prototype:decrement([amount=1][, category])Decreases the value of the progressbar
ProgressBar._prototype:decrement_filtered([amount=1], filter)Decreases the value of the progressbar, if the filter condition is met, does not work with store
ProgressBar._prototype:add_element(element[, maximum])Adds an element into the list of instances that will are waiting to complete, does not work with store - note use store if you want persistent data, this only stores the elements not the values which they have
ProgressBar._prototype:reset_element(element)Resets an element, or its store, to be back at the start, either 1 or 0
ProgressBar._prototype:event_counter([filter])Event handler factory that counts up by 1 every time the event triggers, can filter which elements have incremented
ProgressBar._prototype:event_countdown([filter])Event handler factory that counts down by 1 every time the event triggers, can filter which elements have decremented
- - -

Sliders

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
expcore.gui.core
expcore.gui.prototype
expcore.gui.instances
utils.game
Slider.new_slider([name])Creates a new slider element define
Slider._prototype:set_range([min][, max])Sets the range of a slider, if not used will use default values for a slider
Slider._prototype:draw_label(element)Draws a new label and links its value to the value of this slider, if no store then it will only show one value per player
Slider._prototype:enable_auto_draw_label([state=true])Enables auto draw of the label, the label will share the same parent element as the slider
- - -

Text

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
expcore.gui.core
expcore.gui.prototype
utils.game
Text.new_text_field([name])Creates a new text field element define
Text.new_text_box([name])Creates a new text box element define
Text._prototype_box:set_selectable([state=true])Sets the text box to be selectable
Text._prototype_box:set_word_wrap([state=true])Sets the text box to have word wrap
Text._prototype_box:set_read_only([state=true])Sets the text box to be read only
- - -

Instances

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
utils.global
Instances.has_categories(name)Returns if a instance group has a categorise function; must be registered
Instances.is_registered(name)Returns if the given name is a registered instance group
Instances.register(name[, categorise])Registers the name of an instance group to allow for storing element instances
Instances.add_element(name, element)Adds an element to the instance group under the correct category; must be registered
Instances.get_elements_raw(name[, category])Gets all element instances without first removing any invalid ones; used internally and must be registered
Instances.get_valid_elements(name[, category][, callback])Gets all valid element instances and has the option of running a callback on those that are valid
Instances.unregistered_add_element(name, category, element)A version of add_element that does not require the group to be registered
Instances.unregistered_get_elements(name, category[, callback])A version of get_elements that does not require the group to be registered
- - -

Prototype

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
utils.game
expcore.store
expcore.gui.instances
Constructor.event(event_name)Creates a new function to add functions to an event handler
Constructor.extend(new_prototype)Extents a prototype with the base functions of all gui prototypes, no metatables
Constructor.store(sync, callback)Creates a new function which adds a store to a gui define
Constructor.setter(value_type, key[, second_key])Creates a setter function that checks the type when a value is set
Prototype:uid()Gets the uid for the element define
Prototype.debug_nameSets a debug alias for the define
Prototype.set_captionSets the caption for the element define
Prototype.set_tooltipSets the tooltip for the element define
Prototype.set_pre_authenticatorSets an authenticator that blocks the draw function if check fails
Prototype.set_post_authenticatorSets an authenticator that disables the element if check fails
Prototype.on_drawRegisters a callback to the on_draw event
Prototype.on_style_updateRegisters a callback to the on_style_update event
Prototype:set_style(style[, callback])Sets the style for the element define
Prototype:set_embedded_flow(state)Sets the element to be drawn inside a nameless flow, can be given a name using a function
Prototype:raise_event(event_name, ...)Raises a custom event for this define, any number of params can be given
Prototype:draw_to(element)The main function for defines, when called will draw an instance of this define to the given element - what is drawn is based on the data in draw_data which is set using other functions
Prototype:get_store(category)Gets the value in this elements store, category needed if categorize function used
Prototype:set_store(category, value)Sets the value in this elements store, category needed if categorize function used
Prototype:clear_store([category])Sets the value in this elements store to nil, category needed if categorize function used
- - -

Test

- - - - - - - - - - - - - - - - - + +
expcore.gui
expcore.common
resources.color_presets
utils.event
expcore.storePrototype.set_store_from_instance(the)Will set the value in the store and update the other instances based on the instance given
@@ -1117,447 +347,19 @@
-

Dependencies

+

Concept Base

- # - expcore.gui.core + # + Prototype:clone(concept_name)
- - - - - - - - - - - - - - -
-
-
-
- # - expcore.gui.instances -
-
-
-
- - - - - - - - - - - - - - - -
-
-
-
- # - expcore.gui.elements.buttons -
-
-
-
- - - - - - - - - - - - - - - -
-
-
-
- # - expcore.gui.elements.checkbox -
-
-
-
- - - - - - - - - - - - - - - -
-
-
-
- # - expcore.gui.elements.dropdown -
-
-
-
- - - - - - - - - - - - - - - -
-
-
-
- # - expcore.gui.elements.slider -
-
-
-
- - - - - - - - - - - - - - - -
-
-
-
- # - expcore.gui.elements.text -
-
-
-
- - - - - - - - - - - - - - - -
-
-
-
- # - expcore.gui.elements.elem-button -
-
-
-
- - - - - - - - - - - - - - - -
-
-
-
- # - expcore.gui.elements.progress-bar -
-
-
-
- - - - - - - - - - - - - - - -
-
-
-
- # - expcore.gui.concepts.toolbar -
-
-
-
- - - - - - - - - - - - - - - -
-
-
-
- # - expcore.gui.concepts.left -
-
-
-
- - - - - - - - - - - - - - - -
-
-
-
- # - expcore.gui.concepts.center -
-
-
-
- - - - - - - - - - - - - - - -
-
-
-
- # - expcore.gui.concepts.popups -
-
-
-
- - - - - - - - - - - - - - - -
-
-

Center Guis

-
-
-
-
- # - expcore.gui.core -
-
-
-
- - - - - - - - - - - - - - - -
-
-
-
- # - expcore.gui.prototype -
-
-
-
- - - - - - - - - - - - - - - -
-
-
-
- # - expcore.gui.concepts.toolbar -
-
-
-
- - - - - - - - - - - - - - - -
-
-
-
- # - utils.game -
-
-
-
- - - - - - - - - - - - - - - -
-
-
-
- # - CenterFrames.get_flow(player) -
-
-
-
- -

Gets the center flow for a player

+

Used to copy all the settings from one concept to another and removing links to the orginal

@@ -1571,136 +373,13 @@
  • - player - - : - - (LuaPlayer) - - the player to get the flow for - -
  • - - - - - - - - Returns: - - - - - - - - - - -
    -
    -
    -
    - # - CenterFrames.clear_flow(player) -
    -
    -
    -
    - -

    Clears the center flow for a player

    -

    - - - Parameters: - -
      - - - - - -
    • - - player - - : - - (LuaPlayer) - - the player to clear the flow for - -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - CenterFrames.draw_frame(player, name) -
    -
    -
    -
    - -

    Draws the center frame for a player, if already open then will do nothing

    -

    - - - Parameters: - -
      - - - - - -
    • - - player - - : - - (LuaPlayer) - - the player that will have the frame drawn - -
    • - - - - - -
    • - - name + concept_name : (string) - the name of the hui that will drawn + the name of the new concept; must be unique
    • @@ -1713,8 +392,8 @@ Returns:
      • - (LuaGuiElement) - the new frame that was made + (GuiConcept) + the base for building a custom gui
      @@ -1724,8023 +403,24 @@ + Usage: +
      
      +local custom_button =
      +Gui.get_concept('Button'):clone('CustomButton')
    - # - CenterFrames.redraw_frame(player, name) + # + Prototype:new_event(event_name[, factorio_event][, event_condition])
    -

    Draws the center frame for a player, if already open then will destroy it and redraw

    -

    - - - Parameters: - -
      - - - - - -
    • - - player - - : - - (LuaPlayer) - - the player that will have the frame drawn - -
    • - - - - - -
    • - - name - - : - - (string) - - the name of the hui that will drawn - -
    • - - -
    - - - - - Returns: - - - - - - - - - - -
    -
    -
    -
    - # - CenterFrames.toggle_frame(player, name[, state]) -
    -
    -
    -
    - -

    Toggles if the frame is currently open or not, will open if closed and close if open

    -

    - - - Parameters: - -
      - - - - - -
    • - - player - - : - - (LuaPlayer) - - the player that will have the frame toggled - -
    • - - - - - -
    • - - name - - : - - (string) - - the name of the hui that will be toggled - -
    • - - - - - -
    • - - state - - : - - (boolean) - - when set will force a state for the frame - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (boolean) - if the frame if no open or closed -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - CenterFrames.new_frame(permission_name) -
    -
    -
    -
    - -

    Creates a new center frame define

    -

    - - - Parameters: - -
      - - - - - -
    • - - permission_name - - : - - (string) - - the name that can be used with the permission system - -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - the new center frame define -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - CenterFrames._prototype:set_auto_focus([state=true]) -
    -
    -
    -
    - -

    Sets the frame to be the current active gui when opened and closes all other frames

    -

    - - - Parameters: - -
      - - - - - -
    • - - state - - : - - (boolean) - - when true will auto close other frames and set this frame as player.opened - - (default: true) -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - CenterFrames._prototype:draw_frame(player) -
    -
    -
    -
    - -

    Draws this frame to the player, if already open does nothing (will call on_draw to draw to the frame)

    -

    - - - Parameters: - -
      - - - - - -
    • - - player - - : - - (LuaPlayer) - - the player to draw the frame for - -
    • - - -
    - - - - - Returns: - - - - - - - - - - -
    -
    -
    -
    - # - CenterFrames._prototype:redraw_frame(player) -
    -
    -
    -
    - -

    Draws this frame to the player, if already open it will remove it and redraw it (will call on_draw to draw to the frame)

    -

    - - - Parameters: - -
      - - - - - -
    • - - player - - : - - (LuaPlayer) - - the player to draw the frame for - -
    • - - -
    - - - - - Returns: - - - - - - - - - - -
    -
    -
    -
    - # - CenterFrames._prototype:toggle_frame(player) -
    -
    -
    -
    - -

    Toggles if the frame is open, if open it will close it and if closed it will open it

    -

    - - - Parameters: - -
      - - - - - -
    • - - player - - : - - (LuaPlayer) - - the player to draw the frame for - -
    • - - -
    - - - - - Returns: -
      -
    • - (boolean) - with the gui frame is now open -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - CenterFrames._prototype:event_handler([action=update]) -
    -
    -
    -
    - -

    Creates an event handler that will trigger one of its functions, use with Event.add

    -

    - - - Parameters: - -
      - - - - - -
    • - - action - - : - - (string) - - the action to take on this event - - (default: update) -
    • - - -
    - - - - - - - - - - - - - -
    -
    -

    Left Guis

    -
    -
    -
    -
    - # - expcore.gui.core -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.gui.prototype -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.gui.concepts.toolbar -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.gui.elements.buttons -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - mod-gui -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - utils.game -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - utils.event -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - LeftFrames.get_flow(player) -
    -
    -
    -
    - -

    Gets the left frame flow for a player

    -

    - - - Parameters: - -
      - - - - - -
    • - - player - - : - - (LuaPlayer) - - the player to get the flow of - -
    • - - -
    - - - - - Returns: - - - - - - - - - - -
    -
    -
    -
    - # - LeftFrames.get_frame(name, player) -
    -
    -
    -
    - -

    Gets one frame from the left flow by its name

    -

    - - - Parameters: - -
      - - - - - -
    • - - name - - : - - (string) - - the name of the gui frame to get - -
    • - - - - - -
    • - - player - - : - - (LuaPlayer) - - the player to get the frame of - -
    • - - -
    - - - - - Returns: -
      -
    • - (LuaGuiElement) - the frame in the left frame flow with that name -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - LeftFrames.get_open(player) -
    -
    -
    -
    - -

    Gets all open frames for a player, if non are open it will remove the close all button

    -

    - - - Parameters: - -
      - - - - - -
    • - - player - - : - - (LuaPlayer) - - the player to get the flow of - -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - contains all the open (and registered) frames for the player -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - LeftFrames.toggle_frame(name, player[, state]) -
    -
    -
    -
    - -

    Toggles the visibility of a left frame, or sets its visibility state

    -

    - - - Parameters: - -
      - - - - - -
    • - - name - - : - - (string) - - the name of the gui frame to toggle - -
    • - - - - - -
    • - - player - - : - - (LuaPlayer) - - the player to get the frame of - -
    • - - - - - -
    • - - state - - : - - (boolean) - - when given will be the state that the visibility is set to - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (boolean) - the new state of the visibility -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - LeftFrames.new_frame(permission_name) -
    -
    -
    -
    - -

    Creates a new left frame define

    -

    - - - Parameters: - -
      - - - - - -
    • - - permission_name - - : - - (string) - - the name that can be used with the permission system - -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - the new left frame define -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - LeftFrames._prototype:set_open_by_default([state=true]) -
    -
    -
    -
    - -

    Sets if the frame is visible when a player joins, can also be a function to return a boolean

    -

    - - - Parameters: - -
      - - - - - -
    • - - state - - : - - (boolean or function) - - the default state of the visibility, can be a function - state param - player LuaPlayer - the player that has joined the game - state param - define_name string - the define name for the frame - state return - boolean - false will hide the frame - - (default: true) -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - LeftFrames._prototype:set_direction(direction) -
    -
    -
    -
    - -

    Sets the direction of the frame, either vertical or horizontal

    -

    - - - Parameters: - -
      - - - - - -
    • - - direction - - : - - (string) - - the direction to have the elements be added to the frame - -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - LeftFrames._prototype:_internal_draw(player) -
    -
    -
    -
    - -

    Creates the gui for the first time, used internally

    -

    - - - Parameters: - -
      - - - - - -
    • - - player - - : - - (LuaPlayer) - - the player to draw the frame to - -
    • - - -
    - - - - - Returns: - - - - - - - - - - -
    -
    -
    -
    - # - LeftFrames._prototype:get_frame(player) -
    -
    -
    -
    - -

    Gets the frame for this define from the left frame flow

    -

    - - - Parameters: - -
      - - - - - -
    • - - player - - : - - (LuaPlayer) - - the player to get the frame of - -
    • - - -
    - - - - - Returns: -
      -
    • - (LuaGuiElement) - the frame in the left frame flow for this define -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - LeftFrames._prototype:is_open(player) -
    -
    -
    -
    - -

    Returns if the player currently has this define visible

    -

    - - - Parameters: - -
      - - - - - -
    • - - player - - : - - (LuaPlayer) - - the player to get the frame of - -
    • - - -
    - - - - - Returns: -
      -
    • - (boolean) - true if it is open/visible -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - LeftFrames._prototype:toggle(player) -
    -
    -
    -
    - -

    Toggles the visibility of the left frame

    -

    - - - Parameters: - -
      - - - - - -
    • - - player - - : - - (LuaPlayer) - - the player to toggle the frame of - -
    • - - -
    - - - - - Returns: -
      -
    • - (boolean) - the new state of the visibility -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - LeftFrames._prototype:update(player) -
    -
    -
    -
    - -

    Updates the contents of the left frame, first tries update callback, other wise will clear and redraw

    -

    - - - Parameters: - -
      - - - - - -
    • - - player - - : - - (LuaPlayer) - - the player to update the frame of - -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - LeftFrames._prototype:update_all([update_offline=false]) -
    -
    -
    -
    - -

    Updates the frame for all players, see update

    -

    - - - Parameters: - -
      - - - - - -
    • - - update_offline - - : - - (boolean) - - when true will update the frame for offline players - - (default: false) -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - LeftFrames._prototype:redraw(player) -
    -
    -
    -
    - -

    Redraws the frame by calling on_draw, will always clear the frame

    -

    - - - Parameters: - -
      - - - - - -
    • - - player - - : - - (LuaPlayer) - - the player to update the frame of - -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - LeftFrames._prototype:redraw_all([update_offline=false]) -
    -
    -
    -
    - -

    Redraws the frame for all players, see redraw

    -

    - - - Parameters: - -
      - - - - - -
    • - - update_offline - - : - - (boolean) - - when true will update the frame for offline players - - (default: false) -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - LeftFrames._prototype:event_handler([action=update]) -
    -
    -
    -
    - -

    Creates an event handler that will trigger one of its functions, use with Event.add

    -

    - - - Parameters: - -
      - - - - - -
    • - - action - - : - - (string) - - the action to take on this event - - (default: update) -
    • - - -
    - - - - - - - - - - - - - -
    -
    -

    Popups

    -
    -
    -
    -
    - # - expcore.gui.core -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.gui.prototype -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - utils.game -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - utils.event -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.gui.elements.progress-bar -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.gui.elements.buttons -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - mod-gui -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - resources.color_presets -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - utils.global -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - PopupFrames.get_flow(player) -
    -
    -
    -
    - -

    Gets the left flow that contains the popup frames

    -

    - - - Parameters: - -
      - - - - - -
    • - - player - - : - - (LuaPlayer) - - the player to get the flow for - -
    • - - -
    - - - - - Returns: -
      -
    • - (LuaGuiElement) - the left flow that contains the popup frames -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - PopupFrames.open(define_name, player[, open_time], ...) -
    -
    -
    -
    - -

    Opens a popup for the player, can give the amount of time it is open as well as params for the draw function

    -

    - - - Parameters: - -
      - - - - - -
    • - - define_name - - : - - (string) - - the name of the define that you want to open for the player - -
    • - - - - - -
    • - - player - - : - - (LuaPlayer) - - the player to open the popup for - -
    • - - - - - -
    • - - open_time - - : - - (number) - - the minimum number of ticks you want the popup open for, 0 means no limit, nil will take default - - (optional) -
    • - - - - - -
    • - - ... - - : - - (any) - - the other params that you want to pass to your on_draw event - -
    • - - -
    - - - - - Returns: -
      -
    • - (LuaGuiElement) - the frame that was drawn, the inner gui flow which contains the content -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - PopupFrames.close_progress -
    -
    -
    -
    - -

    Progress bar which when depleted will close the popup frame

    -

    - - - - - - - - - - - - - - -
    -
    -
    -
    - # - PopupFrames.close_button -
    -
    -
    -
    - -

    A button which can be used to close the gui before the timer runs out

    -

    - - - - - - - - - - - - - - -
    -
    -
    -
    - # - PopupFrames.new_popup([name]) -
    -
    -
    -
    - -

    Creates a new popup frame define

    -

    - - - Parameters: - -
      - - - - - -
    • - - name - - : - - (string) - - the optional debug name that can be added - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - the new popup frame define -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - PopupFrames._prototype:set_default_open_time(amount) -
    -
    -
    -
    - -

    Sets the default open time for the popup, will be used if non is provided with open

    -

    - - - Parameters: - -
      - - - - - -
    • - - amount - - : - - (number) - - the number of ticks, by default, the popup will be open for - -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - the define to allow for chaining -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - PopupFrames._prototype:open(player[, open_time], ...) -
    -
    -
    -
    - -

    Opens this define for a player, can be given open time and any other params for the draw function

    -

    - - - Parameters: - -
      - - - - - -
    • - - player - - : - - (LuaPlayer) - - the player to open the popup for - -
    • - - - - - -
    • - - open_time - - : - - (number) - - the minimum number of ticks you want the popup open for, 0 means no limit, nil will take default - - (optional) -
    • - - - - - -
    • - - ... - - : - - (any) - - the other params that you want to pass to your on_draw event - -
    • - - -
    - - - - - Returns: -
      -
    • - (LuaGuiElement) - the frame that was drawn, the inner gui flow which contains the content -
    • -
    - - - - - - - - - -
    -
    -

    Toolbar

    -
    -
    -
    -
    - # - expcore.gui.core -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.gui.elements.buttons -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.roles -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - utils.event -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - utils.game -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - mod-gui -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - Toolbar.new_button([name]) -
    -
    -
    -
    - -

    Adds a new button to the toolbar

    -

    - - - Parameters: - -
      - - - - - -
    • - - name - - : - - (string) - - when given allows an alias to the button for the permission system - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - the button define -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - Toolbar.add_button(button) -
    -
    -
    -
    - -

    Adds an existing buttton to the toolbar

    -

    - - - Parameters: - -
      - - - - - -
    • - - button - - : - - (table) - - the button define for the button to be added - -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - Toolbar.update(player) -
    -
    -
    -
    - -

    Updates the player's toolbar with an new buttons or expected change in auth return

    -

    - - - Parameters: - -
      - - - - - -
    • - - player - - : - - (LuaPlayer) - - the player to update the toolbar for - -
    • - - -
    - - - - - - - - - - - - - -
    -
    -

    Core

    -
    -
    -
    -
    - # - utils.gui -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - utils.game -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - new_define(prototype[, debug_name]) -
    -
    -
    -
    - -

    Used to create new element defines from a class prototype, please use the own given by the class

    -

    - - - Parameters: - -
      - - - - - -
    • - - prototype - - : - - (table) - - the class prototype that will be used for the element define - -
    • - - - - - -
    • - - debug_name - - : - - (string) - - the name that you want to see while debuging - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - the new element define with all functions accessed via __index metamethod -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - get_define(name[, internal]) -
    -
    -
    -
    - -

    Gets an element define give the uid, debug name or a copy of the element define

    -

    - - - Parameters: - -
      - - - - - -
    • - - name - - : - - (string or table) - - the uid, debug name or define for the element define to get - -
    • - - - - - -
    • - - internal - - : - - (boolean) - - when true the error trace is one level higher (used internally) - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - the element define that was found or an error -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - categorize_by_player(element) -
    -
    -
    -
    - -

    A categorize function to be used with add_store, each player has their own value

    -

    - - - Parameters: - -
      - - - - - -
    • - - element - - : - - (LuaGuiElement) - - the element that will be converted to a string - -
    • - - -
    - - - - - Returns: -
      -
    • - (string) - the player's name who owns this element -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - categorize_by_force(element) -
    -
    -
    -
    - -

    A categorize function to be used with add_store, each force has its own value

    -

    - - - Parameters: - -
      - - - - - -
    • - - element - - : - - (LuaGuiElement) - - the element that will be converted to a string - -
    • - - -
    - - - - - Returns: -
      -
    • - (string) - the player's force name who owns this element -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - categorize_by_surface(element) -
    -
    -
    -
    - -

    A categorize function to be used with add_store, each surface has its own value

    -

    - - - Parameters: - -
      - - - - - -
    • - - element - - : - - (LuaGuiElement) - - the element that will be converted to a string - -
    • - - -
    - - - - - Returns: -
      -
    • - (string) - the player's surface name who owns this element -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - draw(name, element) -
    -
    -
    -
    - -

    Draws a copy of the element define to the parent element, see draw_to

    -

    - - - Parameters: - -
      - - - - - -
    • - - name - - : - - (string or table) - - the uid, debug name or define for the element define to draw - -
    • - - - - - -
    • - - element - - : - - (LuaGuiEelement) - - the parent element that it the define will be drawn to - -
    • - - -
    - - - - - Returns: - - - - - - - - - - -
    -
    -
    -
    - # - toggle_enabled(element) -
    -
    -
    -
    - -

    Will toggle the enabled state of an element

    -

    - - - Parameters: - -
      - - - - - -
    • - - element - - : - - (LuaGuiElement) - - the gui element to toggle - -
    • - - -
    - - - - - Returns: -
      -
    • - (boolean) - the new state that the element has -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - toggle_visible(element) -
    -
    -
    -
    - -

    Will toggle the visiblity of an element

    -

    - - - Parameters: - -
      - - - - - -
    • - - element - - : - - (LuaGuiElement) - - the gui element to toggle - -
    • - - -
    - - - - - Returns: -
      -
    • - (boolean) - the new state that the element has -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - set_padding(element[, up=0][, down=0][, left=0][, right=0]) -
    -
    -
    -
    - -

    Sets the padding for a gui element

    -

    - - - Parameters: - -
      - - - - - -
    • - - element - - : - - (LuaGuiElement) - - the element to set the padding for - -
    • - - - - - -
    • - - up - - : - - (number) - - the amount of padding on the top - - (default: 0) -
    • - - - - - -
    • - - down - - : - - (number) - - the amount of padding on the bottom - - (default: 0) -
    • - - - - - -
    • - - left - - : - - (number) - - the amount of padding on the left - - (default: 0) -
    • - - - - - -
    • - - right - - : - - (number) - - the amount of padding on the right - - (default: 0) -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - set_padding_style(style[, up=0][, down=0][, left=0][, right=0]) -
    -
    -
    -
    - -

    Sets the padding for a gui style

    -

    - - - Parameters: - -
      - - - - - -
    • - - style - - : - - (LuaStyle) - - the element to set the padding for - -
    • - - - - - -
    • - - up - - : - - (number) - - the amount of padding on the top - - (default: 0) -
    • - - - - - -
    • - - down - - : - - (number) - - the amount of padding on the bottom - - (default: 0) -
    • - - - - - -
    • - - left - - : - - (number) - - the amount of padding on the left - - (default: 0) -
    • - - - - - -
    • - - right - - : - - (number) - - the amount of padding on the right - - (default: 0) -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - create_alignment(element[, name][, horizontal_align='right'][, vertical_align='center']) -
    -
    -
    -
    - -

    Allows the creation of an alignment flow to place elements into

    -

    - - - Parameters: - -
      - - - - - -
    • - - element - - : - - (LuaGuiElement) - - the element to add this alignment into - -
    • - - - - - -
    • - - name - - : - - (string) - - the name to use for the alignment - - (optional) -
    • - - - - - -
    • - - horizontal_align - - : - - (string) - - the horizontal alignment of the elements in this flow - - (default: 'right') -
    • - - - - - -
    • - - vertical_align - - : - - (string) - - the vertical alignment of the elements in this flow - - (default: 'center') -
    • - - -
    - - - - - Returns: - - - - - - - - - - -
    -
    -
    -
    - # - destroy_if_valid(element) -
    -
    -
    -
    - -

    Destroies an element but tests for it being present and valid first

    -

    - - - Parameters: - -
      - - - - - -
    • - - element - - : - - (LuaGuiElement) - - the element to be destroied - -
    • - - -
    - - - - - Returns: -
      -
    • - (boolean) - true if it was destoried -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - create_scroll_table(element, table_size, maximal_height[, name='scroll']) -
    -
    -
    -
    - -

    Creates a scroll area with a table inside, table can be any size

    -

    - - - Parameters: - -
      - - - - - -
    • - - element - - : - - (LuaGuiElement) - - the element to add this scroll into - -
    • - - - - - -
    • - - table_size - - : - - (number) - - the number of columns in the table - -
    • - - - - - -
    • - - maximal_height - - : - - (number) - - the max hieght of the scroll - -
    • - - - - - -
    • - - name - - : - - (string) - - the name of the scoll element - - (default: 'scroll') -
    • - - -
    - - - - - Returns: - - - - - - - - - - -
    -
    -
    -
    - # - create_header(element, caption[, tooltip][, right_align][, name='header']) -
    -
    -
    -
    - -

    Creates a header section with a label and button area

    -

    - - - Parameters: - -
      - - - - - -
    • - - element - - : - - (LuaGuiElement) - - the element to add this header into - -
    • - - - - - -
    • - - caption - - : - - (localeString) - - the caption that is used as the title - -
    • - - - - - -
    • - - tooltip - - : - - (localeString) - - the tooltip that is shown on the caption - - (optional) -
    • - - - - - -
    • - - right_align - - : - - (boolean) - - when true will include the right align area - - (optional) -
    • - - - - - -
    • - - name - - : - - (string) - - the name of the header area - - (default: 'header') -
    • - - -
    - - - - - Returns: -
      -
    • - (LuaGuiElement) - the header that was made, or the align area if that was created -
    • -
    - - - - - - - - - -
    -
    -

    Buttons

    -
    -
    -
    -
    - # - mod-gui -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.gui.core -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.gui.prototype -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - Button.new_button([name]) -
    -
    -
    -
    - -

    Creates a new button element define

    -

    - - - Parameters: - -
      - - - - - -
    • - - name - - : - - (string) - - the optional debug name that can be added - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - the new button element define -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - Button._prototype:set_sprites(sprite[, hovered_sprite][, clicked_sprite]) -
    -
    -
    -
    - -

    Adds sprites to a button making it a sprite button

    -

    - - - Parameters: - -
      - - - - - -
    • - - sprite - - : - - (SpritePath) - - the sprite path for the default sprite for the button - -
    • - - - - - -
    • - - hovered_sprite - - : - - (SpritePath) - - the sprite path for the sprite when the player hovers over the button - - (optional) -
    • - - - - - -
    • - - clicked_sprite - - : - - (SpritePath) - - the sprite path for the sprite when the player clicks the button - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (self) - returns the button define to allow chaining -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - Button._prototype:set_click_filter(filter[, ...]) -
    -
    -
    -
    - -

    Adds a click / mouse button filter to the button

    -

    - - - Parameters: - -
      - - - - - -
    • - - filter - - : - - (table) - - ?string|table either a of mouse buttons or the first mouse button to filter, with a table true means allowed - -
    • - - - - - -
    • - - ... - - : - - (table) - - when filter is not a you can add the mouse buttons one after each other - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (self) - returns the button define to allow chaining -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - Button._prototype:set_key_filter(filter[, ...]) -
    -
    -
    -
    - -

    Adds a control key filter to the button

    -

    - - - Parameters: - -
      - - - - - -
    • - - filter - - : - - (table) - - ?string|table either a of control keys or the first control keys to filter, with a table true means allowed - -
    • - - - - - -
    • - - ... - - : - - (table) - - when filter is not a you can add the control keys one after each other - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (self) - returns the button define to allow chaining -
    • -
    - - - - - - - - - -
    -
    -

    Checkboxs

    -
    -
    -
    -
    - # - expcore.gui.core -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.gui.prototype -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.store -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - utils.game -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - Checkbox.new_checkbox([name]) -
    -
    -
    -
    - -

    Creates a new checkbox element define

    -

    - - - Parameters: - -
      - - - - - -
    • - - name - - : - - (string) - - the optional debug name that can be added - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - the new checkbox element define -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - Checkbox.new_radiobutton([name]) -
    -
    -
    -
    - -

    Creates a new radiobutton element define, has all functions checkbox has

    -

    - - - Parameters: - -
      - - - - - -
    • - - name - - : - - (string) - - the optional debug name that can be added - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - the new button element define -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - Checkbox._prototype_radiobutton:add_as_option(option_set, option_name) -
    -
    -
    -
    - -

    Adds this radiobutton to be an option in the given option set (only one can be true at a time)

    -

    - - - Parameters: - -
      - - - - - -
    • - - option_set - - : - - (string) - - the name of the option set to add this element to - -
    • - - - - - -
    • - - option_name - - : - - (string) - - the name of this option that will be used to identify it - -
    • - - -
    - - - - - Returns: -
      -
    • - (self) - the define to allow chaining -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - Checkbox._prototype_radiobutton:get_store(category, internal) -
    -
    -
    -
    - -

    Gets the stored value of the radiobutton or the option set if present

    -

    - - - Parameters: - -
      - - - - - -
    • - - category - - : - - (string) - - [opt] the category to get such as player name or force name - -
    • - - - - - -
    • - - internal - - : - - (boolean) - - used to prevent stackover flow - -
    • - - -
    - - - - - Returns: -
      -
    • - (any) - the value that is stored for this define -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - Checkbox._prototype_radiobutton:set_store(category, value, internal) -
    -
    -
    -
    - -

    Sets the stored value of the radiobutton or the option set if present

    -

    - - - Parameters: - -
      - - - - - -
    • - - category - - : - - (string) - - [opt] the category to get such as player name or force name - -
    • - - - - - -
    • - - value - - : - - (boolean) - - the value to set for this define, must be valid for its type ie for checkbox etc - -
    • - - - - - -
    • - - internal - - : - - (boolean) - - used to prevent stackover flow - -
    • - - -
    - - - - - Returns: -
      -
    • - (boolean) - true if the value was set -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - Checkbox.new_option_set(name, callback, categorize) -
    -
    -
    -
    - -

    Registers a new option set that can be linked to radiobuttons (only one can be true at a time)

    -

    - - - Parameters: - -
      - - - - - -
    • - - name - - : - - (string) - - the name of the option set, must be unique - -
    • - - - - - -
    • - - callback - - : - - (function) - - the update callback when the value of the option set changes - callback param - value string - the new selected option for this option set - callback param - category string - the category that updated if categorize was used - -
    • - - - - - -
    • - - categorize - - : - - (function) - - the function used to convert an element into a string - -
    • - - -
    - - - - - Returns: -
      -
    • - (string) - the name of this option set to be passed to add_as_option -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - Checkbox.draw_option_set(name, element) -
    -
    -
    -
    - -

    Draws all radiobuttons that are part of an option set at once (Gui.draw will not work)

    -

    - - - Parameters: - -
      - - - - - -
    • - - name - - : - - (string) - - the name of the option set to draw the radiobuttons of - -
    • - - - - - -
    • - - element - - : - - (LuaGuiElement) - - the parent element that the radiobuttons will be drawn to - -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - Checkbox.reset_radiobuttons(element[, exclude][, recursive=false]) -
    -
    -
    -
    - -

    Sets all radiobutton in a element to false (unless excluded) and can act recursively

    -

    - - - Parameters: - -
      - - - - - -
    • - - element - - : - - (LuaGuiElement) - - the root gui element to start setting radio buttons from - -
    • - - - - - -
    • - - exclude - - : - - (table) - - ?string|table the name of the radiobutton to exclude or a of radiobuttons where true will set the state true - - (optional) -
    • - - - - - -
    • - - recursive - - : - - (number or boolean) - - if true will recur as much as possible, if a will recur that number of times - - (default: false) -
    • - - -
    - - - - - Returns: -
      -
    • - (boolean) - true if successful -
    • -
    - - - - - - - - - -
    -
    -

    Dropdowns

    -
    -
    -
    -
    - # - expcore.gui.core -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.gui.prototype -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - utils.game -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - Dropdown.new_dropdown([name]) -
    -
    -
    -
    - -

    Creates a new dropdown element define

    -

    - - - Parameters: - -
      - - - - - -
    • - - name - - : - - (string) - - the optional debug name that can be added - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - the new dropdown element define -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - Dropdown.new_list_box([name]) -
    -
    -
    -
    - -

    Creates a new list box element define

    -

    - - - Parameters: - -
      - - - - - -
    • - - name - - : - - (string) - - the optional debug name that can be added - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - the new list box element define -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - Dropdown._prototype:new_static_options(options[, ...], the) -
    -
    -
    -
    - -

    Adds new static options to the dropdown which will trigger the general callback

    -

    - - - Parameters: - -
      - - - - - -
    • - - options - - : - - (table) - - ?string|table either a of option strings or the first option string, with a table values are the options - -
    • - - - - - -
    • - - ... - - : - - (table) - - when options is not a you can add the options one after each other - - (optional) -
    • - - - - - -
    • - - the - - : - - (self) - - define to allow chaining - -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - Dropdown._prototype:new_dynamic_options(callback) -
    -
    -
    -
    - -

    Adds a callback which should return a table of values to be added as options for the dropdown (appended after static options)

    -

    - - - Parameters: - -
      - - - - - -
    • - - callback - - : - - (function) - - the function that will run to get the options for the dropdown - callback param - player LuaPlayer - the player that the element is being drawn to - callback param - element LuaGuiElement - the element that is being drawn - callback return - table - the values of this table will be appended to the static options of the dropdown - -
    • - - -
    - - - - - Returns: -
      -
    • - (self) - the define to allow chaining -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - Dropdown._prototype:add_option_callback(option, callback) -
    -
    -
    -
    - -

    Adds a case specific callback which will only run when that option is selected (general case still triggered)

    -

    - - - Parameters: - -
      - - - - - -
    • - - option - - : - - (string) - - the name of the option to trigger the callback on; if not already added then will be added as an option - -
    • - - - - - -
    • - - callback - - : - - (function) - - the function that will be called when that option is selected - callback param - player LuaPlayer - the player who owns the gui element - callback param - element LuaGuiElement - the element which is being effected - callback param - value string - the new option that has been selected - -
    • - - -
    - - - - - Returns: -
      -
    • - (self) - the define to allow chaining -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - Dropdown.select_value(element, value) -
    -
    -
    -
    - -

    Selects the option from a dropdown or list box given the value rather than key

    -

    - - - Parameters: - -
      - - - - - -
    • - - element - - : - - (LuaGuiElement) - - the element that contains the option - -
    • - - - - - -
    • - - value - - : - - (string) - - the option to select from the dropdown - -
    • - - -
    - - - - - Returns: -
      -
    • - (number) - the key where the value was -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - Dropdown.get_selected_value(element) -
    -
    -
    -
    - -

    Returns the currently selected value rather than index

    -

    - - - Parameters: - -
      - - - - - -
    • - - element - - : - - (LuaGuiElement) - - the gui element that you want to get the value of - -
    • - - -
    - - - - - Returns: -
      -
    • - (string) - the value that is currently selected -
    • -
    - - - - - - - - - -
    -
    -

    Elem Buttons

    -
    -
    -
    -
    - # - expcore.gui.core -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.gui.prototype -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - utils.game -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - ElemButton.new_elem_button([name]) -
    -
    -
    -
    - -

    Creates a new elem button element define

    -

    - - - Parameters: - -
      - - - - - -
    • - - name - - : - - (string) - - the optional debug name that can be added - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - the new elem button element define -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - ElemButton._prototype.set_type -
    -
    -
    -
    - -

    Sets the type of the elem button, the type is required so this must be called at least once

    -

    - - - -
      - - - - - -
    • - - type - - : - - (string) - - the type that this elem button is see factorio api - -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - ElemButton._prototype:set_default(value) -
    -
    -
    -
    - -

    Sets the default value for the elem button, this may be a function or a string

    -

    - - - Parameters: - -
      - - - - - -
    • - - value - - : - - (string or function) - - string a will be a static default and a function will be called when drawn to get the default - -
    • - - -
    - - - - - Returns: -
      -
    • - (the) - element define to allow for chaining -
    • -
    - - - - - - - - - -
    -
    -

    Progress Bars

    -
    -
    -
    -
    - # - expcore.gui.core -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.gui.prototype -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - utils.global -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - utils.game -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - ProgressBar.set_maximum(element, amount) -
    -
    -
    -
    - -

    Sets the maximum value that represents the end value of the progress bar

    -

    - - - Parameters: - -
      - - - - - -
    • - - element - - : - - (LuaGuiElement or string) - - either a gui element or a registered define - -
    • - - - - - -
    • - - amount - - : - - (number) - - the amount to have set as the maximum - -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - ProgressBar.increment(element[, amount=1]) -
    -
    -
    -
    - -

    Increases the value of the progressbar, if a define is given all of its instances have incremented

    -

    - - - Parameters: - -
      - - - - - -
    • - - element - - : - - (LuaGuiElement or string) - - either a gui element or a registered define - -
    • - - - - - -
    • - - amount - - : - - (number) - - the amount to increase the progressbar by - - (default: 1) -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - ProgressBar.decrement(element[, amount=1]) -
    -
    -
    -
    - -

    Decreases the value of the progressbar, if a define is given all of its instances have decremented

    -

    - - - Parameters: - -
      - - - - - -
    • - - element - - : - - (LuaGuiElement or string) - - either a gui element or a registered define - -
    • - - - - - -
    • - - amount - - : - - (number) - - the amount to decrease the progressbar by - - (default: 1) -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - ProgressBar.new_progressbar([name]) -
    -
    -
    -
    - -

    Creates a new progressbar element define

    -

    - - - Parameters: - -
      - - - - - -
    • - - name - - : - - (string) - - the optional debug name that can be added - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - the new progressbar element define -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - ProgressBar._prototype:set_default_maximum(amount) -
    -
    -
    -
    - -

    Sets the maximum value that represents the end value of the progress bar

    -

    - - - Parameters: - -
      - - - - - -
    • - - amount - - : - - (number) - - the amount to have set as the maximum - -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - the define to allow chaining -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - ProgressBar._prototype:use_count_down([state=true]) -
    -
    -
    -
    - -

    Will set the progress bar to start at 1 and trigger when it hits 0

    -

    - - - Parameters: - -
      - - - - - -
    • - - state - - : - - (boolean) - - when true the bar will start filled, to be used with decrease - - (default: true) -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - the define to allow chaining -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - ProgressBar._prototype:increment([amount=1][, category]) -
    -
    -
    -
    - -

    Increases the value of the progressbar

    -

    - - - Parameters: - -
      - - - - - -
    • - - amount - - : - - (number) - - the amount to increase the progressbar by - - (default: 1) -
    • - - - - - -
    • - - category - - : - - (string) - - the category that is used with a store - - (optional) -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - ProgressBar._prototype:increment_filtered([amount=1], filter) -
    -
    -
    -
    - -

    Increases the value of the progressbar, if the filter condition is met, does not work with store

    -

    - - - Parameters: - -
      - - - - - -
    • - - amount - - : - - (number) - - the amount to increase the progressbar by - - (default: 1) -
    • - - - - - -
    • - - filter - - : - - (function) - - the filter to be used - -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - ProgressBar._prototype:decrement([amount=1][, category]) -
    -
    -
    -
    - -

    Decreases the value of the progressbar

    -

    - - - Parameters: - -
      - - - - - -
    • - - amount - - : - - (number) - - the amount to decrease the progressbar by - - (default: 1) -
    • - - - - - -
    • - - category - - : - - (string) - - the category that is used with a store - - (optional) -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - ProgressBar._prototype:decrement_filtered([amount=1], filter) -
    -
    -
    -
    - -

    Decreases the value of the progressbar, if the filter condition is met, does not work with store

    -

    - - - Parameters: - -
      - - - - - -
    • - - amount - - : - - (number) - - the amount to decrease the progressbar by - - (default: 1) -
    • - - - - - -
    • - - filter - - : - - (function) - - the filter to be used - -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - ProgressBar._prototype:add_element(element[, maximum]) -
    -
    -
    -
    - -

    Adds an element into the list of instances that will are waiting to complete, does not work with store - note use store if you want persistent data, this only stores the elements not the values which they have

    -

    - - - Parameters: - -
      - - - - - -
    • - - element - - : - - (LuaGuiElement) - - the element that you want to add into the waiting to complete list - -
    • - - - - - -
    • - - maximum - - : - - (number) - - the maximum for this element if not given the default for this define is used - - (optional) -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - ProgressBar._prototype:reset_element(element) -
    -
    -
    -
    - -

    Resets an element, or its store, to be back at the start, either 1 or 0

    -

    - - - Parameters: - -
      - - - - - -
    • - - element - - : - - (LuaGuiElement) - - the element that you want to reset the progress of - -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - ProgressBar._prototype:event_counter([filter]) -
    -
    -
    -
    - -

    Event handler factory that counts up by 1 every time the event triggers, can filter which elements have incremented

    -

    - - - Parameters: - -
      - - - - - -
    • - - filter - - : - - (function) - - when given will use filtered increment - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (function) - the event handler -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - ProgressBar._prototype:event_countdown([filter]) -
    -
    -
    -
    - -

    Event handler factory that counts down by 1 every time the event triggers, can filter which elements have decremented

    -

    - - - Parameters: - -
      - - - - - -
    • - - filter - - : - - (function) - - when given will use filtered decrement - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (function) - the event handler -
    • -
    - - - - - - - - - -
    -
    -

    Sliders

    -
    -
    -
    -
    - # - expcore.gui.core -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.gui.prototype -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.gui.instances -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - utils.game -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - Slider.new_slider([name]) -
    -
    -
    -
    - -

    Creates a new slider element define

    -

    - - - Parameters: - -
      - - - - - -
    • - - name - - : - - (string) - - the optional debug name that can be added - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - the new slider element define -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - Slider._prototype:set_range([min][, max]) -
    -
    -
    -
    - -

    Sets the range of a slider, if not used will use default values for a slider

    -

    - - - Parameters: - -
      - - - - - -
    • - - min - - : - - (number) - - the minimum value that the slider can take - - (optional) -
    • - - - - - -
    • - - max - - : - - (number) - - the maximum value that the slider can take - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (self) - the define to allow chaining -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - Slider._prototype:draw_label(element) -
    -
    -
    -
    - -

    Draws a new label and links its value to the value of this slider, if no store then it will only show one value per player

    -

    - - - Parameters: - -
      - - - - - -
    • - - element - - : - - (LuaGuiElement) - - the parent element that the label will be drawn to - -
    • - - -
    - - - - - Returns: -
      -
    • - (LuaGuiElement) - the new label element so that styles can be applied -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - Slider._prototype:enable_auto_draw_label([state=true]) -
    -
    -
    -
    - -

    Enables auto draw of the label, the label will share the same parent element as the slider

    -

    - - - Parameters: - -
      - - - - - -
    • - - state - - : - - (boolean) - - when false will disable the auto draw of the label - - (default: true) -
    • - - -
    - - - - - Returns: -
      -
    • - (self) - the define to allow chaining -
    • -
    - - - - - - - - - -
    -
    -

    Text

    -
    -
    -
    -
    - # - expcore.gui.core -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.gui.prototype -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - utils.game -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - Text.new_text_field([name]) -
    -
    -
    -
    - -

    Creates a new text field element define

    -

    - - - Parameters: - -
      - - - - - -
    • - - name - - : - - (string) - - the optional debug name that can be added - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - the new text field element define -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - Text.new_text_box([name]) -
    -
    -
    -
    - -

    Creates a new text box element define

    -

    - - - Parameters: - -
      - - - - - -
    • - - name - - : - - (string) - - the optional debug name that can be added - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - the new text box element define -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - Text._prototype_box:set_selectable([state=true]) -
    -
    -
    -
    - -

    Sets the text box to be selectable

    -

    - - - Parameters: - -
      - - - - - -
    • - - state - - : - - (boolean) - - when false will set the state to false - - (default: true) -
    • - - -
    - - - - - Returns: -
      -
    • - (self) - table the define to allow for chaining -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - Text._prototype_box:set_word_wrap([state=true]) -
    -
    -
    -
    - -

    Sets the text box to have word wrap

    -

    - - - Parameters: - -
      - - - - - -
    • - - state - - : - - (boolean) - - when false will set the state to false - - (default: true) -
    • - - -
    - - - - - Returns: -
      -
    • - (self) - table the define to allow for chaining -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - Text._prototype_box:set_read_only([state=true]) -
    -
    -
    -
    - -

    Sets the text box to be read only

    -

    - - - Parameters: - -
      - - - - - -
    • - - state - - : - - (boolean) - - when false will set the state to false - - (default: true) -
    • - - -
    - - - - - Returns: -
      -
    • - (self) - table the define to allow for chaining -
    • -
    - - - - - - - - - -
    -
    -

    Instances

    -
    -
    -
    -
    - # - utils.global -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - Instances.has_categories(name) -
    -
    -
    -
    - -

    Returns if a instance group has a categorise function; must be registered

    -

    - - - Parameters: - -
      - - - - - -
    • - - name - - : - - (string) - - the name of the instance group - -
    • - - -
    - - - - - Returns: -
      -
    • - (boolean) - true if there is a categorise function -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - Instances.is_registered(name) -
    -
    -
    -
    - -

    Returns if the given name is a registered instance group

    -

    - - - Parameters: - -
      - - - - - -
    • - - name - - : - - (string) - - the name of the instance group you are testing - -
    • - - -
    - - - - - Returns: -
      -
    • - (boolean) - true if the name is registered -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - Instances.register(name[, categorise]) -
    -
    -
    -
    - -

    Registers the name of an instance group to allow for storing element instances

    -

    - - - Parameters: - -
      - - - - - -
    • - - name - - : - - (string) - - the name of the instance group; must to unique - -
    • - - - - - -
    • - - categorise - - : - - (function) - - function used to turn the element into a string - categorise param - element LuaGuiElement - the gui element to be turned into a string - categorise return - string - the category that the element will be added to like the player's name or force's name - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (string) - the name that was added so it can be used as a variable -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - Instances.add_element(name, element) -
    -
    -
    -
    - -

    Adds an element to the instance group under the correct category; must be registered

    -

    - - - Parameters: - -
      - - - - - -
    • - - name - - : - - (string) - - the name of the instance group to add the element to - -
    • - - - - - -
    • - - element - - : - - (LuaGuiElement) - - the element to add the the instance group - -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - Instances.get_elements_raw(name[, category]) -
    -
    -
    -
    - -

    Gets all element instances without first removing any invalid ones; used internally and must be registered

    -

    - - - Parameters: - -
      - - - - - -
    • - - name - - : - - (string) - - the name of the instance group to get the instances of - -
    • - - - - - -
    • - - category - - : - - (string) - - the category to get the instance from, not needed when no categorise function - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - the table of element instances of which some may be invalid -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - Instances.get_valid_elements(name[, category][, callback]) -
    -
    -
    -
    - -

    Gets all valid element instances and has the option of running a callback on those that are valid

    -

    - - - Parameters: - -
      - - - - - -
    • - - name - - : - - (string) - - the name of the instance group to get the instances of - -
    • - - - - - -
    • - - category - - : - - (string) - - the category to get the instances of, not needed when no categorise function - - (optional) -
    • - - - - - -
    • - - callback - - : - - (function) - - when given the callback will be ran on all valid elements - callback param - element LuaGuiElement - the current valid element - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - the table of element instances with all invalid ones removed -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - Instances.unregistered_add_element(name, category, element) -
    -
    -
    -
    - -

    A version of add_element that does not require the group to be registered

    -

    - - - Parameters: - -
      - - - - - -
    • - - name - - : - - (string) - - the name of the instance group to add the element to - -
    • - - - - - -
    • - - category - - : - - (string or nil) - - the category to add the element to, can be nil but must still be given - -
    • - - - - - -
    • - - element - - : - - (LuaGuiElement) - - the element to add to the instance group - -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - Instances.unregistered_get_elements(name, category[, callback]) -
    -
    -
    -
    - -

    A version of get_elements that does not require the group to be registered

    -

    - - - Parameters: - -
      - - - - - -
    • - - name - - : - - (string) - - the name of the instance group to get the instances of - -
    • - - - - - -
    • - - category - - : - - (string or nil) - - the category to get the instances of, can be nil but must still be given - -
    • - - - - - -
    • - - callback - - : - - (function) - - when given will be called on all valid instances - callback param - element LuaGuiElement - the current valid element - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - the table of element instances with all invalid ones removed -
    • -
    - - - - - - - - - -
    -
    -

    Prototype

    -
    -
    -
    -
    - # - utils.game -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.store -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.gui.instances -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - Constructor.event(event_name) -
    -
    -
    -
    - -

    Creates a new function to add functions to an event handler

    +

    Adds a new event trigger to the concept which can be linked to a factorio event

    @@ -9760,122 +440,25 @@ (string) - the name of the event that callbacks will be added to + the name of the event to add, must be unique, recomented to start with "on_" - - - - - - Returns: -
      -
    • - (function) - the function used to register handlers -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - Constructor.extend(new_prototype) -
    -
    -
    -
    - -

    Extents a prototype with the base functions of all gui prototypes, no metatables

    -

    - - - Parameters: - -
      - -
    • - new_prototype + factorio_event : - (table) + (defines.events) - the prototype that you want to add the functions to - -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - the same prototype but with the new functions added -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - Constructor.store(sync, callback) -
    -
    -
    -
    - -

    Creates a new function which adds a store to a gui define

    -

    - - - Parameters: - -
      - - - - - -
    • - - sync - - : - - (boolean) - - if the function should create a synced store + when given will fire the custom event when the factorio event is raised + (optional)
    • @@ -9884,102 +467,13 @@
    • - callback + event_condition : (function) - the function called when needing to update the value of an element - -
    • - - -
    - - - - - Returns: -
      -
    • - (function) - the function that will add a store for this define -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - Constructor.setter(value_type, key[, second_key]) -
    -
    -
    -
    - -

    Creates a setter function that checks the type when a value is set

    -

    - - - Parameters: - -
      - - - - - -
    • - - value_type - - : - - (string) - - the type that the value should be when it is set - -
    • - - - - - -
    • - - key - - : - - (string) - - the key of the define that will be set - -
    • - - - - - -
    • - - second_key - - : - - (string) - - allows for setting of a key in a sub table + used to filter when a factorio event triggers the custom event; if the event contains a reference to an element then names are automatically filtered (optional)
    • @@ -9993,8 +487,8 @@ Returns:
      • - (function) - the function that will check the type and set the value + (GuiConcept) + to allow chaing of functions
      @@ -10004,407 +498,27 @@ + Usage: +
      
      +local custom_button =
      +Gui.get_concept('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)
    - # - Prototype:uid() + # + Prototype:on_custom_event(handler)
    -

    Gets the uid for the element define

    -

    - - - - - - Returns: -
      -
    • - (string) - the uid of this element define -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - Prototype.debug_name -
    -
    -
    -
    - -

    Sets a debug alias for the define

    -

    - - - -
      - - - - - -
    • - - name - - : - - (string) - - the debug name for the element define that can be used to get this element define - -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - Prototype.set_caption -
    -
    -
    -
    - -

    Sets the caption for the element define

    -

    - - - -
      - - - - - -
    • - - caption - - : - - (string) - - the caption that will be drawn with the element - -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - Prototype.set_tooltip -
    -
    -
    -
    - -

    Sets the tooltip for the element define

    -

    - - - -
      - - - - - -
    • - - tooltip - - : - - (string) - - the tooltip that will be displayed for this element when drawn - -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - Prototype.set_pre_authenticator -
    -
    -
    -
    - -

    Sets an authenticator that blocks the draw function if check fails

    -

    - - - -
      - - - - - -
    • - - callback - - : - - (function) - - the function that will be ran to test if the element should be drawn or not - callback param - LuaPlayer player - the player that the element is being drawn to - callback param - string define_name - the name of the define that is being drawn - callback return - boolean - false will stop the element from being drawn - -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - Prototype.set_post_authenticator -
    -
    -
    -
    - -

    Sets an authenticator that disables the element if check fails

    -

    - - - -
      - - - - - -
    • - - callback - - : - - (function) - - the function that will be ran to test if the element should be enabled or not - callback param - LuaPlayer player - the player that the element is being drawn to - callback param - string define_name - the name of the define that is being drawn - callback return - boolean - false will disable the element - -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - Prototype.on_draw -
    -
    -
    -
    - -

    Registers a callback to the on_draw event

    -

    - - - -
      - - - - - -
    • - - callback - - : - - (function) - - - callback param - LuaPlayer player - the player that the element was drawn to - callback param - LuaGuiElement element - the element that was drawn - callback param - any ... - any other params passed by the draw_to function - -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - Prototype.on_style_update -
    -
    -
    -
    - -

    Registers a callback to the on_style_update event

    -

    - - - -
      - - - - - -
    • - - callback - - : - - (function) - - - callback param - LuaStyle style - the style that was changed and/or needs changing - -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - Prototype:set_style(style[, callback]) -
    -
    -
    -
    - -

    Sets the style for the element define

    +

    Adds a custom event handler, replace with the name of the event

    @@ -10418,87 +532,13 @@
  • - style - - : - - (string) - - the style that will be used for this element when drawn - -
  • - - - - - -
  • - - callback + handler : (function) - function is called when element is drawn to alter its style - - (optional) -
  • - - - - - - - - Returns: -
      -
    • - (self) - the element define to allow chaining -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - Prototype:set_embedded_flow(state) -
    -
    -
    -
    - -

    Sets the element to be drawn inside a nameless flow, can be given a name using a function

    -

    - - - Parameters: - -
      - - - - - -
    • - - state - - : - - (boolean or function) - - when true a padless flow is created to contain the element + the function which will recive the event
    • @@ -10511,8 +551,8 @@ Returns:
      • - (self) - the element define to allow chaining + (GuiConcept) + to allow chaing of functions
      @@ -10522,6 +562,13 @@ + Usage: +
      
      +local custom_button =
      +Gui.get_concept('CustomButton'):clone('MyCustomButton')
      +:on_admin_clicked(function(event)
      +    game.print(event.player.name..' pressed my admin button')
      +end)
    @@ -10529,13 +576,13 @@
    # - Prototype:raise_event(event_name, ...) + Prototype:raise_event(event_name[, event={}][, from_factorio=false])
    -

    Raises a custom event for this define, any number of params can be given

    +

    Raises a custom event, folowing keys included automaticlly: concept, event name, game tick, player from player_index, element if valid

    @@ -10565,13 +612,196 @@
  • - ... + event + + : + + (table) + + table containg data you want to send with the event, some keys already included + + (default: {}) +
  • + + + + + +
  • + + from_factorio + + : + + (boolean) + + internal use, if the raise came from the factorio event handler + + (default: false) +
  • + + + + + + + + + + + + + + + Usage: +
    
    +local custom_button =
    +Gui.get_concept('CustomButton')
    +
    +-- Note that this is an example and would not work due it expecting a valid element for event.element
    +-- this will however work fine if you can provide all expected keys, or its not linked to any factorio event
    +custom_button:raise_event('on_admin_clicked',{
    +    player_index = game.player.index
    +})
    + + +
    +
    +
    +
    + # + Prototype:new_property(property_name, default[, setter_callback]) +
    +
    +
    +
    + +

    Adds a new property to the concept, such as caption, tooltip, or some custom property you want to control

    +

    + + + Parameters: + +
      + + + + + +
    • + + property_name + + : + + (string) + + the name of the new property, must be unique + +
    • + + + + + +
    • + + default : (any) - any params that you want to pass to the event + the default value for this property, although not strictly required is is strongly recomented + +
    • + + + + + +
    • + + setter_callback + + : + + (function) + + this function is called when set is called, if not provided then key in concept.properties is updated to new value + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (GuiConcept) + to allow chaing of functions +
    • +
    + + + + + + + + Usage: +
    
    +local button =
    +Gui.get_concept('Button')
    +: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)
    + + +
    +
    +
    +
    + # + Prototype:set_custom_property(value) +
    +
    +
    +
    + +

    Sets a new value for a property, triggers setter method if provided, replace with property name

    +

    + + + Parameters: + +
      + + + + + +
    • + + value + + : + + (any) + + the value that you want to set for this property
    • @@ -10584,8 +814,8 @@ Returns:
      • - (number) - the number of handlers that were registered + (GuiConcept) + to allow chaing of functions
      @@ -10595,21 +825,315 @@ + Usage: +
      
      +local custom_button =
      +Gui.get_concept('Button')
      +:set_caption('Default Button')
      +
      
      +-- 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 =
      +Gui.get_concept('CustomButton')
      +:set_caption('Custom Button')
    - # - Prototype:draw_to(element) + # + Prototype:define_draw(draw_callback)
    -

    The main function for defines, when called will draw an instance of this define to the given element - what is drawn is based on the data in draw_data which is set using other functions

    +

    Used to define how the concept is turned into an ingame element or "instance" as we may refer to them

    +

    + + + Parameters: + +
      + + + + + +
    • + + draw_callback + + : + + (function) + + the function that will be called to draw/update the instance; this function must return the instance or the new acting instance + +
    • + + +
    + + + + + Returns: +
      +
    • + (GuiConcept) + to allow chaing of functions +
    • +
    + + + + + + + + Usage: +
    
    +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
    +    -- although not shown here you also can recive any extra arguments here from the call to draw
    +    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, say if our custom button defined a draw function to change the font color to red
    +    return element
    +end)
    + + +
    +
    +
    +
    + # + Prototype:draw(parent_element) +
    +
    +
    +
    + +

    Calls all the draw functions in order to create this concept in game; will also store and sync the instance if stores are used

    +

    + + + Parameters: + +
      + + + + + +
    • + + parent_element + + : + + (LuaGuiElement) + + the element that the concept will use as a base + +
    • + + +
    + + + + + Returns: +
      +
    • + (LuaGuiElement) + the element that was created and then passed though and returned by the draw functions +
    • +
    + + + + + + + + Usage: +
    
    +local custom_button =
    +Gui.get_concept('CustomButton')
    +
    +-- Note that the draw function from button was cloned, so unless we want to alter the base button we dont need a new draw define
    +custom_button:draw(game.player.gui.left)
    + + +
    +
    +

    Concept Instances

    +
    +
    +
    +
    + # + Prototype:define_instance_store([category_callback]) +
    +
    +
    +
    + +

    Adds an instance store to the concept; when a new instance is made it is stored so you can access it later

    +

    + + + Parameters: + +
      + + + + + +
    • + + category_callback + + : + + (function) + + when given will act as a way to turn an element into a string to act as a key; keys returned can over lap + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (GuiConcept) + to allow chaing of functions +
    • +
    + + + + + + + + Usage: +
    
    +-- Note even thou this is a copy of Button; if Button had an instance store it would not be cloned over
    +local custom_button =
    +Gui.get_concept('CustomButton')
    +:define_instance_store(function(element)
    +    return element.player_index -- The instances are stored based on player id
    +end)
    + + +
    +
    +
    +
    + # + Prototype.get_instances([category]) +
    +
    +
    +
    + +

    Gets all insatnces in a category, category may be nil to return all

    +

    + + + Parameters: + +
      + + + + + +
    • + + category + + : + + (string or LuaGuiElement) + + the category to get, can only be nil if categories are not used + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + a table which contains all the instances +
    • +
    + + + + + + + + Usage: +
    
    +local custom_button =
    +Gui.get_concept('CustomButton')
    +
    +custom_button.get_instances(1) -- player index 1
    + + +
    +
    +
    +
    + # + Prototype.add_instance(element[, category]) +
    +
    +
    +
    + +

    Adds an instance to this concept, used automatically during concept:draw

    @@ -10629,23 +1153,33 @@ (LuaGuiElement) - the element that the define will draw a instance of its self onto + the element that will be added as an instance + + + +
  • + + category + + : + + (string) + + the category to add this element under, if nil the category callback is used to assign one + + (optional) +
  • + + - Returns: - @@ -10653,20 +1187,26 @@ + Usage: +
    
    +local custom_button =
    +Gui.get_concept('CustomButton')
    +
    +custom_button.add_instance(element) -- normally not needed due to use in concept:draw
    - # - Prototype:get_store(category) + # + Prototype.update_instances([category], update_callback)
    -

    Gets the value in this elements store, category needed if categorize function used

    +

    Applies an update function to all instances, simialr use to what table.forEach would be

    @@ -10684,10 +1224,156 @@ : - (string) + (string or LuaGuiElement) - [opt] the category to get such as player name or force name + the category to get, can only be nil if categories are not used + (optional) + + + + + + +
  • + + update_callback + + : + + (function) + + the function which is called on each instance, recives other args passed to update_instances + +
  • + + + + + + + + + + + + + + + Usage: +
    
    +local custom_button =
    +Gui.get_concept('CustomButton')
    +
    +-- Change all the instances to have red text for player 1
    +custom_button.update_instances(1,function(element)
    +    element.style.font_color = {r=1,g=0,b=0}
    +end)
    + + +
    +
    +

    Concept Data

    +
    +
    +
    +
    + # + Prototype:define_data_store([category_callback]) +
    +
    +
    +
    + +

    Adds a data store to this concept which allows you to store synced/percistent data between instances

    +

    + + + Parameters: + +
      + + + + + +
    • + + category_callback + + : + + (function) + + when given will act as a way to turn an element into a string to act as a key; keys returned can over lap + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (GuiConcept) + to allow chaing of functions +
    • +
    + + + + + + + + Usage: +
    
    +-- Note even thou this is a copy of Button; if Button had an data store it would not be cloned over
    +local custom_button =
    +Gui.get_concept('CustomButton')
    +:define_data_store(function(element)
    +    return element.player_index -- The data is stored based on player id
    +end)
    + + +
    +
    +
    +
    + # + Prototype.get_data([category]) +
    +
    +
    +
    + +

    Gets the data that is stored for this category

    +

    + + + Parameters: + +
      + + + + + +
    • + + category + + : + + (string or LuaGuiElement) + + the category to get, can only be nil if categories are not used + + (optional)
    • @@ -10700,7 +1386,7 @@
      • (any) - the value that is stored for this define + the data that you had stored in this location
      @@ -10710,20 +1396,26 @@ + Usage: +
      
      +local custom_button =
      +Gui.get_concept('CustomButton')
      +
      +custom_button.get_data(1) -- player index 1
    - # - Prototype:set_store(category, value) + # + Prototype.set_data([category], value)
    -

    Sets the value in this elements store, category needed if categorize function used

    +

    Sets the data that is stored for this category

    @@ -10741,10 +1433,11 @@ : - (string) + (string or LuaGuiElement) - [opt] the category to get such as player name or force name + the category to set, can only be nil if categories are not used + (optional) @@ -10759,7 +1452,7 @@ (any) - the value to set for this define, must be valid for its type ie for checkbox etc + the data that you want to stored in this location @@ -10769,13 +1462,6 @@ - Returns: -
      -
    • - (boolean) - true if the value was set -
    • -
    @@ -10783,20 +1469,31 @@ + Usage: +
    
    +local custom_button =
    +Gui.get_concept('CustomButton')
    +
    +-- A table is used to show correct way to use a table with self.update_data
    +-- but a table is not required and can be any data, however upvalues may cause desyncs
    +custom_button.set_data(1,{
    +    clicks = 0,
    +    required_clicks = 100
    +}) -- player index 1
    - # - Prototype:clear_store([category]) + # + Prototype.clear_data([category])
    -

    Sets the value in this elements store to nil, category needed if categorize function used

    +

    Clears the data that is stored for this category

    @@ -10814,14 +1511,185 @@ : - (string) + (string or LuaGuiElement) - the category to get such as player name or force name + the category to clear, can only be nil if categories are not used (optional) + + + + + + + + + + + + + Usage: +
    
    +local custom_button =
    +Gui.get_concept('CustomButton')
    +
    +custom_button.clear_data(1) -- player index 1
    + + +
    +
    +
    +
    + # + Prototype.update_data([category], update_callback) +
    +
    +
    +
    + +

    Updates the data that is stored for this category

    +

    + + + Parameters: + +
      + + + + + +
    • + + category + + : + + (string or LuaGuiElement) + + the category to clear, can only be nil if categories are not used + + (optional) +
    • + + + + + +
    • + + update_callback + + : + + (function) + + the function which is called to update the data + +
    • + + +
    + + + + + + + + + + + + Usage: +
    
    +local custom_button =
    +Gui.get_concept('CustomButton')
    +
    +custom_button.update_data(1,function(tbl)
    +    tbl.clicks = tbl.clicks + 1 -- here we are incrementing the clicks by 1
    +end) -- player index 1
    +
    +
    
    +-- Alterative method more useful when not using a table
    +-- so for this example assume that we did custom_button.set_data(1,0)
    +custom_button.update_data(1,function(value)
    +    return value + 1 -- here we are incrementing the value by 1, we may only be tracking clicks
    +end) -- player index 1
    + + +
    +
    +
    +
    + # + Prototype:define_combined_store([category_callback], get_callback, set_callback) +
    +
    +
    +
    + +

    Used to add a both instance and data stores which are linked together, new instances are synced to current value, changing one instances changes them all

    +

    + + + Parameters: + +
      + + + + + +
    • + + category_callback + + : + + (function) + + when given will act as a way to turn an element into a string to act as a key; keys returned can over lap + + (optional) +
    • + + + + + +
    • + + get_callback + + : + + (function) + + the function which is called when you set the store from an instance + +
    • + + + + + +
    • + + set_callback + + : + + (function) + + the function which is called when you update an instance using the value in the store + +
    • + +
    @@ -10830,8 +1698,8 @@ Returns:
    • - (boolean) - true if the value was set + (GuiConcept) + to allow chaing of functions
    @@ -10841,24 +1709,60 @@ + Usage: +
    
    +local custom_button =
    +Gui.get_concept('CustomButton')
    +:define_combined_store(
    +function(element)
    +    return element.player_index -- The data is stored based on player id
    +end,
    +function(element)
    +   return element.caption -- We want to store the caption
    +end,
    +function(element,value)
    +    element.caption = value -- This is the inverse of above
    +end)
    -
    -

    Test

    -
    - # - expcore.gui + # + Prototype.set_instance_from_store(the)
    +

    Will set the state of an instance based on the value in the store

    +

    + Parameters: + +
      + + + + + +
    • + + the + + : + + (LuaGuiElement) + + element that you want to have update + +
    • + + +
    + @@ -10869,21 +1773,53 @@ + Usage: +
    
    +local custom_button =
    +Gui.get_concept('CustomButton')
    +
    +-- Used internally when first draw and automatically when the store updates
    +custom_button.set_instance_from_store(element)
    - # - expcore.common + # + Prototype.set_store_from_instance(the)
    +

    Will set the value in the store and update the other instances based on the instance given

    +

    + Parameters: + +
      + + + + + +
    • + + the + + : + + (LuaGuiElement) + + element that you want to use to update the store + +
    • + + +
    + @@ -10894,81 +1830,13 @@ - + Usage: +
    
    +local custom_button =
    +Gui.get_concept('CustomButton')
     
    -    
    -
    -
    -
    - # - resources.color_presets -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - utils.event -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.store -
    -
    -
    -
    - - - - - - - - - - - - - +-- You may want to use this with gui events +custom_button.set_store_from_instance(element)
    @@ -10987,7 +1855,7 @@ generated by LDoc diff --git a/docs/core/Permissions-Groups.html b/docs/core/Permissions-Groups.html index 28fee091..3a4c5455 100644 --- a/docs/core/Permissions-Groups.html +++ b/docs/core/Permissions-Groups.html @@ -1432,7 +1432,7 @@ generated by LDoc diff --git a/docs/core/Roles.html b/docs/core/Roles.html index 0c417381..3354671f 100644 --- a/docs/core/Roles.html +++ b/docs/core/Roles.html @@ -3152,7 +3152,7 @@ generated by LDoc diff --git a/docs/core/Store.html b/docs/core/Store.html index e9fb83db..56ffe579 100644 --- a/docs/core/Store.html +++ b/docs/core/Store.html @@ -241,15 +241,19 @@ local team_scores = 'team-scores' -- Setting and getting data is then as simple as +-- note that when storing a table you must use Store.update Store.set(scenario_difficuly,'Hard') Store.set(team_scores,game.player.force.name,20) Store.get(scenario_difficuly) -- returns 'Hard' Store.get(team_scores,game.player.force.name) -- returns 20 +Store.update(team_scores,game.player.force.name,function(value,key) + return value + 10 -- add 10 to the score +end) + -- The reason for using stores over global is the abilty to watch for updates -- for stores to work you must register them, often at the end of the file --- note that storing a table value may cause issues as a key changing does not cause the set function to trigger Store.register(scenario_difficuly,function(value) game.print('Scenario difficulty has been set to: '..value) end) @@ -309,8 +313,12 @@ Store.register(team_scores,function(value,key) Sets the value at a location, this location must be registered - update(location[, key]) - Triggers the change handler manually + update(location[, key][, update_callback]) + Allows for updating a value based on the current value; only valid way to change tables in a store + + + update_all(location[, update_callback]) + Allows for updating all values at a location based on the current value; only valid way to change tables in a store clear(location[, key][, from_sync=false]) @@ -718,13 +726,13 @@ Store.register(team_scores,function(value,key)
    # - update(location[, key]) + update(location[, key][, update_callback])
    -

    Triggers the change handler manually

    +

    Allows for updating a value based on the current value; only valid way to change tables in a store

    @@ -766,6 +774,90 @@ Store.register(team_scores,function(value,key) + + + +
  • + + update_callback + + : + + (function) + + the function called to update the value stored, rtn value to set new value + + (optional) +
  • + + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + update_all(location[, update_callback]) +
    +
    +
    +
    + +

    Allows for updating all values at a location based on the current value; only valid way to change tables in a store

    +

    + + + Parameters: + +
      + + + + + +
    • + + location + + : + + (string) + + the location to set the data to + +
    • + + + + + +
    • + + update_callback + + : + + (function) + + the function called to update the value stored + + (optional) +
    • + +
    @@ -1036,7 +1128,7 @@ Store.register(team_scores,function(value,key) generated by LDoc
    diff --git a/docs/core/Sudo.html b/docs/core/Sudo.html index f1b715fc..75ba5a96 100644 --- a/docs/core/Sudo.html +++ b/docs/core/Sudo.html @@ -544,7 +544,7 @@ generated by LDoc diff --git a/docs/guis/Player-List.html b/docs/guis/Player-List.html index 36ffe125..5f4b98d8 100644 --- a/docs/guis/Player-List.html +++ b/docs/guis/Player-List.html @@ -626,7 +626,7 @@ generated by LDoc diff --git a/docs/guis/Rocket-Info.html b/docs/guis/Rocket-Info.html index 626e32c8..4419add4 100644 --- a/docs/guis/Rocket-Info.html +++ b/docs/guis/Rocket-Info.html @@ -629,7 +629,7 @@ generated by LDoc diff --git a/docs/guis/Science-Info.html b/docs/guis/Science-Info.html index 7f36a267..bb73a355 100644 --- a/docs/guis/Science-Info.html +++ b/docs/guis/Science-Info.html @@ -449,7 +449,7 @@ generated by LDoc diff --git a/docs/guis/Task-List.html b/docs/guis/Task-List.html index bb449941..076de4f3 100644 --- a/docs/guis/Task-List.html +++ b/docs/guis/Task-List.html @@ -632,7 +632,7 @@ generated by LDoc diff --git a/docs/guis/Warps-List.html b/docs/guis/Warps-List.html index c015334b..ba48ab73 100644 --- a/docs/guis/Warps-List.html +++ b/docs/guis/Warps-List.html @@ -837,7 +837,7 @@ generated by LDoc diff --git a/docs/index.html b/docs/index.html index 29d95487..2c08495e 100644 --- a/docs/index.html +++ b/docs/index.html @@ -56,11 +56,7 @@ Gui - Core Module - Gui - - This file is used to require all the different elements of the gui module - - each module has an outline here but for more details see their separate files in ./gui - - please read the files for more documentation that cant be shown here - - please note there is a rework planned but not started + Core Module - Gui Permissions-Groups @@ -514,7 +510,7 @@ see ./expcore/commands.lua for more details generated by LDoc diff --git a/docs/modules/Gui.html b/docs/modules/Gui.html index 493c008e..7f2d9a40 100644 --- a/docs/modules/Gui.html +++ b/docs/modules/Gui.html @@ -41,8 +41,7 @@ @@ -52,20 +51,6 @@ @@ -237,9 +221,7 @@

    Gui module

    -

    Core Module - Gui - - This file is used to require all the different elements of the gui module - - each module has an outline here but for more details see their separate files in ./gui

    +

    Core Module - Gui

    @@ -254,71 +236,17 @@ -

    Dependencies

    +

    Functions

    - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    expcore.gui.coreon_custom_event(handler)Adds a custom event handler, replace with the name of the event
    expcore.gui.instances
    expcore.gui.elements.buttons
    expcore.gui.elements.checkbox
    expcore.gui.elements.dropdown
    expcore.gui.elements.slider
    expcore.gui.elements.text
    expcore.gui.elements.elem-button
    expcore.gui.elements.progress-bar
    expcore.gui.concepts.toolbar
    expcore.gui.concepts.left
    expcore.gui.concepts.center
    expcore.gui.concepts.popups
    - - -

    Test

    - - - - - - - - - - - - - - - - - + +
    expcore.gui
    expcore.common
    resources.color_presets
    utils.event
    expcore.storeset_custom_property(value)Sets a new value for a property, triggers setter method if provided, replace with property name
    @@ -327,23 +255,56 @@
    -

    Dependencies

    +

    Functions

    - # - expcore.gui.core + # + on_custom_event(handler)
    +

    Adds a custom event handler, replace with the name of the event

    +

    + Parameters: + +
      + + + + + +
    • + + handler + + : + + (function) + + the function which will recive the event + +
    • + + +
    + + Returns: +
      +
    • + (GuiConcept) + to allow chaing of functions +[[@usage +
    • +
    @@ -357,421 +318,51 @@
    - # - expcore.gui.instances -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.gui.elements.buttons -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.gui.elements.checkbox -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.gui.elements.dropdown -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.gui.elements.slider -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.gui.elements.text -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.gui.elements.elem-button -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.gui.elements.progress-bar -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.gui.concepts.toolbar -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.gui.concepts.left -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.gui.concepts.center -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.gui.concepts.popups -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -

    Test

    -
    -
    -
    -
    - # - expcore.gui -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.common -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - resources.color_presets -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - utils.event -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.store + # + set_custom_property(value)
    +

    Sets a new value for a property, triggers setter method if provided, replace with property name

    +

    + Parameters: + +
      + + + + + +
    • + + value + + : + + (any) + + the value that you want to set for this property + +
    • + + +
    + + Returns: +
      +
    • + (GuiConcept) + to allow chaing of functions +[[@usage +
    • +
    @@ -797,7 +388,7 @@ generated by LDoc
    diff --git a/docs/modules/control.html b/docs/modules/control.html index be3816d0..5fa17272 100644 --- a/docs/modules/control.html +++ b/docs/modules/control.html @@ -351,7 +351,7 @@ generated by LDoc diff --git a/docs/modules/expcore.gui.html b/docs/modules/expcore.gui.html index 580de83b..78739a7f 100644 --- a/docs/modules/expcore.gui.html +++ b/docs/modules/expcore.gui.html @@ -37,35 +37,13 @@ - @@ -248,6 +254,31 @@ Gui.new_concept('Button') 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.add{ + type = properties.type, + name = properties.name, + caption = properties.caption, + tooltip = properties.tooltip + } + + else + element = parent.add{ + 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)
    -- Makeing a alternative button based on the first
     local custom_button =
    @@ -275,6 +306,50 @@ button:clone('CustomButton')
         
         
    +    

    Elements

    + + + + + + + + + + + + +
    buttonThe basic button element
    frameThe basic frame element
    + + +

    Core

    + + + + + + + + + + + + + + + + + + + + + + + + +
    require_concept(concept)Loads a concept from the concepts file, used internally
    get_concept(name)Gets the gui concept with this name
    Prototype:change_name([new_name=self.name])Used internally to save concept names to the core gui module
    new_concept(name)Returns a new gui concept with no properties or events
    clone_concept(name, new_name)Making anew concept based on the properties and drawing of another
    + +

    Concept Base

    @@ -284,6 +359,10 @@ button:clone('CustomButton') + + + + @@ -377,11 +456,490 @@ button:clone('CustomButton')
    Used to copy all the settings from one concept to another and removing links to the orginal
    Prototype:change_name([new_name=self.name])Used internally to save concept names to the core gui module
    Prototype:new_event(event_name[, factorio_event][, event_condition]) Adds a new event trigger to the concept which can be linked to a factorio event
    + + +

    Tests

    + + + + + + + + +
    run_tests(player[, category])Runs a set of gui tests to ensure that the system is working

    +

    Elements

    +
    +
    +
    +
    + # + button +
    +
    +
    +
    + +

    The basic button element

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + on_click + + : + + + fired when the player clicks the button + +
    • + + + + + +
    • + + on_left_click + + : + + + fired when the player clicks with the right mouse button + +
    • + + + + + +
    • + + on_left_click + + : + + + fired when the player clicks with the right mouse button + +
    • + + + + + +
    • + + caption + + : + + (string or LocalisedString) + + the message that is shown on the button + +
    • + + + + + +
    • + + tooltip + + : + + (string or LocalisedString) + + the tooltip that shows when a player hovers over the button + +
    • + + + + + +
    • + + sprite + + : + + (SpritePath) + + upto three sprites in the order: default, hovered, clicked + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + frame +
    +
    +
    +
    + +

    The basic frame element

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + title + + : + + (string or LocalisedString) + + the title that will show in the frame + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +

    Core

    +
    +
    +
    +
    + # + require_concept(concept) +
    +
    +
    +
    + +

    Loads a concept from the concepts file, used internally

    +

    + + + Parameters: + +
      + + + + + +
    • + + concept + + : + + (string) + + the name of the concept to require + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Load a base concept
    +Gui.require_concept('frame')
    + + +
    +
    +
    +
    + # + get_concept(name) +
    +
    +
    +
    + +

    Gets the gui concept with this name

    +

    + + + Parameters: + +
      + + + + + +
    • + + name + + : + + (string) + + the name of the concept that you want to get + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Getting a gui concept
    +local button = Gui.get_concept('Button')
    + + +
    +
    +
    +
    + # + Prototype:change_name([new_name=self.name]) +
    +
    +
    +
    + +

    Used internally to save concept names to the core gui module

    +

    + + + Parameters: + +
      + + + + + +
    • + + new_name + + : + + (string) + + the new name of the concept + + (default: self.name) +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Internal Saving
    +-- this is never needed to be done, internal use only!
    +local button = Gui.get_concept('Button')
    +button:change_name('Not Button')
    + + +
    +
    +
    +
    + # + new_concept(name) +
    +
    +
    +
    + +

    Returns a new gui concept with no properties or events

    +

    + + + Parameters: + +
      + + + + + +
    • + + name + + : + + (string) + + the name that you want this concept to have + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Making a new concept, see module usage
    +local button = Gui.new_concept('Button')
    + + +
    +
    +
    +
    + # + clone_concept(name, new_name) +
    +
    +
    +
    + +

    Making anew 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')
    + + +
    +

    Concept Base

    @@ -444,6 +1002,62 @@ button:clone('CustomButton') Gui.get_concept('Button'):clone('CustomButton')
    +
    +
    +
    +
    + # + Prototype:change_name([new_name=self.name]) +
    +
    +
    +
    + +

    Used internally to save concept names to the core gui module

    +

    + + + Parameters: + +
      + + + + + +
    • + + new_name + + : + + (string) + + the new name of the concept + + (default: self.name) +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Internal Saving
    +-- this is never needed to be done, internal use only!
    +local button = Gui.get_concept('Button')
    +button:change_name('Not Button')
    + +
    @@ -934,6 +1548,7 @@ 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 if properties.type == 'button' then element = parent.draw{ @@ -953,8 +1568,8 @@ 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, say if our custom button defined a draw function to change the font color to red + -- 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)
    @@ -1871,6 +2486,79 @@ Gui.get_concept('CustomButton') custom_button.set_store_from_instance(element) +
    +
    +

    Tests

    +
    +
    +
    +
    + # + run_tests(player[, category]) +
    +
    +
    +
    + +

    Runs a set of gui tests to ensure that the system is working

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player that the guis are made for and who recives the results + +
    • + + + + + +
    • + + category + + : + + (string) + + when given only tests in this category are ran + + (optional) +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Run all gui tests
    +Gui.run_tests(game.player)
    + +
    @@ -1887,7 +2575,7 @@ Gui.get_concept('CustomButton') generated by LDoc diff --git a/docs/core/Permissions-Groups.html b/docs/core/Permissions-Groups.html index 4befca44..e05ed687 100644 --- a/docs/core/Permissions-Groups.html +++ b/docs/core/Permissions-Groups.html @@ -1432,7 +1432,7 @@ generated by LDoc diff --git a/docs/core/Roles.html b/docs/core/Roles.html index a2bef34f..5b989791 100644 --- a/docs/core/Roles.html +++ b/docs/core/Roles.html @@ -3152,7 +3152,7 @@ generated by LDoc diff --git a/docs/core/Store.html b/docs/core/Store.html index 6026f246..937ec539 100644 --- a/docs/core/Store.html +++ b/docs/core/Store.html @@ -1128,7 +1128,7 @@ Store.register(team_scores,function(value,key) generated by LDoc diff --git a/docs/core/Sudo.html b/docs/core/Sudo.html index b037fbf6..aabdfb54 100644 --- a/docs/core/Sudo.html +++ b/docs/core/Sudo.html @@ -544,7 +544,7 @@ generated by LDoc diff --git a/docs/guis/Player-List.html b/docs/guis/Player-List.html index 8aa3ef94..3a76fdcc 100644 --- a/docs/guis/Player-List.html +++ b/docs/guis/Player-List.html @@ -626,7 +626,7 @@ generated by LDoc diff --git a/docs/guis/Rocket-Info.html b/docs/guis/Rocket-Info.html index 49db82bf..d5144327 100644 --- a/docs/guis/Rocket-Info.html +++ b/docs/guis/Rocket-Info.html @@ -629,7 +629,7 @@ generated by LDoc diff --git a/docs/guis/Science-Info.html b/docs/guis/Science-Info.html index 1d910135..2e733887 100644 --- a/docs/guis/Science-Info.html +++ b/docs/guis/Science-Info.html @@ -449,7 +449,7 @@ generated by LDoc diff --git a/docs/guis/Task-List.html b/docs/guis/Task-List.html index 8b3221fb..a3fa28cb 100644 --- a/docs/guis/Task-List.html +++ b/docs/guis/Task-List.html @@ -632,7 +632,7 @@ generated by LDoc diff --git a/docs/guis/Warps-List.html b/docs/guis/Warps-List.html index 0a12a90f..4d84021e 100644 --- a/docs/guis/Warps-List.html +++ b/docs/guis/Warps-List.html @@ -837,7 +837,7 @@ generated by LDoc diff --git a/docs/index.html b/docs/index.html index bd8cb83a..d55abbff 100644 --- a/docs/index.html +++ b/docs/index.html @@ -510,7 +510,7 @@ see ./expcore/commands.lua for more details generated by LDoc diff --git a/docs/modules/control.html b/docs/modules/control.html index c79d10b4..b1e1a273 100644 --- a/docs/modules/control.html +++ b/docs/modules/control.html @@ -351,7 +351,7 @@ generated by LDoc diff --git a/docs/modules/utils.alien_evolution_progress.html b/docs/modules/utils.alien_evolution_progress.html index a8dd8517..e70f53cf 100644 --- a/docs/modules/utils.alien_evolution_progress.html +++ b/docs/modules/utils.alien_evolution_progress.html @@ -419,7 +419,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 d3329c77..2eafdc25 100644 --- a/docs/modules/utils.core.html +++ b/docs/modules/utils.core.html @@ -1164,7 +1164,7 @@ generated by LDoc diff --git a/docs/modules/utils.debug.html b/docs/modules/utils.debug.html index 5e50472a..e5bab76d 100644 --- a/docs/modules/utils.debug.html +++ b/docs/modules/utils.debug.html @@ -654,7 +654,7 @@ generated by LDoc diff --git a/docs/modules/utils.dump_env.html b/docs/modules/utils.dump_env.html index ef683374..f86ef92c 100644 --- a/docs/modules/utils.dump_env.html +++ b/docs/modules/utils.dump_env.html @@ -323,7 +323,7 @@ generated by LDoc diff --git a/docs/modules/utils.event.html b/docs/modules/utils.event.html index 9f27e495..edf052c2 100644 --- a/docs/modules/utils.event.html +++ b/docs/modules/utils.event.html @@ -1292,7 +1292,7 @@ generated by LDoc diff --git a/docs/modules/utils.event_core.html b/docs/modules/utils.event_core.html index d369a623..74fd5324 100644 --- a/docs/modules/utils.event_core.html +++ b/docs/modules/utils.event_core.html @@ -434,7 +434,7 @@ generated by LDoc diff --git a/docs/modules/utils.math.html b/docs/modules/utils.math.html index 78cd66e7..8898c3e4 100644 --- a/docs/modules/utils.math.html +++ b/docs/modules/utils.math.html @@ -338,7 +338,7 @@ generated by LDoc diff --git a/docs/modules/utils.recipe_locker.html b/docs/modules/utils.recipe_locker.html index dc87e650..b3a13c92 100644 --- a/docs/modules/utils.recipe_locker.html +++ b/docs/modules/utils.recipe_locker.html @@ -441,7 +441,7 @@ generated by LDoc diff --git a/docs/modules/utils.state_machine.html b/docs/modules/utils.state_machine.html index 394ccfb3..a780a4d1 100644 --- a/docs/modules/utils.state_machine.html +++ b/docs/modules/utils.state_machine.html @@ -752,7 +752,7 @@ generated by LDoc diff --git a/docs/modules/utils.table.html b/docs/modules/utils.table.html index 406abc06..6c086a80 100644 --- a/docs/modules/utils.table.html +++ b/docs/modules/utils.table.html @@ -1382,7 +1382,7 @@ generated by LDoc diff --git a/docs/modules/utils.task.html b/docs/modules/utils.task.html index e70b97ec..b6ca1a92 100644 --- a/docs/modules/utils.task.html +++ b/docs/modules/utils.task.html @@ -651,7 +651,7 @@ generated by LDoc diff --git a/docs/modules/utils.timestamp.html b/docs/modules/utils.timestamp.html index 54faeee6..46b83cfd 100644 --- a/docs/modules/utils.timestamp.html +++ b/docs/modules/utils.timestamp.html @@ -442,7 +442,7 @@ generated by LDoc diff --git a/docs/topics/license.html b/docs/topics/license.html index 79b030c8..beee1b37 100644 --- a/docs/topics/license.html +++ b/docs/topics/license.html @@ -789,7 +789,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 419754b9..8c8c821c 100644 --- a/docs/topics/readme.md.html +++ b/docs/topics/readme.md.html @@ -332,7 +332,7 @@ generated by LDoc diff --git a/expcore/gui.lua b/expcore/gui.lua index 7ab0bdd3..a384e8bd 100644 --- a/expcore/gui.lua +++ b/expcore/gui.lua @@ -21,7 +21,7 @@ end) -- 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{ + element = parent.add{ type = properties.type, name = properties.name, caption = properties.caption, @@ -29,7 +29,7 @@ end) } else - element = parent.draw{ + element = parent.add{ type = properties.type, name = properties.name, sprite = properties.sprite, @@ -67,4 +67,7 @@ custom_button:draw(game.player.gui.left) local Gui = require 'expcore.gui.core' +Gui.require_concept('frame') +Gui.require_concept('button') + return Gui \ No newline at end of file diff --git a/expcore/gui/concepts/button.lua b/expcore/gui/concepts/button.lua new file mode 100644 index 00000000..cecc257c --- /dev/null +++ b/expcore/gui/concepts/button.lua @@ -0,0 +1,58 @@ +--[[-- Core Module - Gui + @module Gui + @alias Gui +]] + +local Gui = require 'expcore.gui.core' + +--[[-- The basic button element +@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 +]] +Gui.new_concept('button') +: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 +end) +:new_event('on_right_click',defines.events.on_gui_click,function(event) + return event.mouse_button == defines.mouse_button_type.right +end) +:new_property('tooltip') +:new_property('caption',nil,function(properties,value) + properties.caption = value + properties.type = 'button' +end) +:new_property('sprite',nil,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) +:define_draw(function(properties,parent,element) + if properties.type == 'button' then + element = parent.add{ + name = properties.name, + type = properties.type, + caption = properties.caption, + tooltip = properties.tooltip + } + + else + element = parent.add{ + name = properties.name, + type = properties.type, + sprite = properties.sprite, + hovered_sprite = properties.hovered_sprite, + clicked_sprite = properties.clicked_sprite, + tooltip = properties.tooltip + } + + end + + return element +end) \ No newline at end of file diff --git a/expcore/gui/concepts/frame.lua b/expcore/gui/concepts/frame.lua new file mode 100644 index 00000000..c484cbe8 --- /dev/null +++ b/expcore/gui/concepts/frame.lua @@ -0,0 +1,24 @@ +--[[-- Core Module - Gui + @module Gui + @alias Gui +]] + +local Gui = require 'expcore.gui.core' + +--[[-- The basic frame element +@element frame +@tparam ?string|Concepts.LocalisedString title the title that will show in the frame +]] +Gui.new_concept('frame') +:new_property('title',function(properties,value) + properties.title = value +end) +:define_draw(function(properties,parent,element) + element = parent.add{ + name = properties.name, + type = 'frame', + caption = properties.title + } + + return element +end) \ No newline at end of file diff --git a/expcore/gui/core.lua b/expcore/gui/core.lua index 07a69097..5ce2ec2a 100644 --- a/expcore/gui/core.lua +++ b/expcore/gui/core.lua @@ -14,6 +14,15 @@ local Gui = { concepts = {} } +--[[-- Loads a concept from the concepts file, used internally +@tparam string concept the name of the concept to require +@usage-- Load a base concept +Gui.require_concept('frame') +]] +function Gui.require_concept(concept) + require('expcore.gui.concepts.'..concept) +end + --[[-- Gets the gui concept with this name @tparam string name the name of the concept that you want to get @usage-- Getting a gui concept @@ -64,8 +73,8 @@ 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[name] then - error('Gui concept "'..name..'" is already defind',2) + if Gui.concepts[new_name] then + error('Gui concept "'..new_name..'" is already defind',2) end return concept:clone(new_name) diff --git a/expcore/gui/prototype.lua b/expcore/gui/prototype.lua index 79128ef8..575ae9b6 100644 --- a/expcore/gui/prototype.lua +++ b/expcore/gui/prototype.lua @@ -76,22 +76,24 @@ local Factorio_Events = {} local Prototype = { draw_callbacks = {}, properties = {}, + factorio_events = {}, events = {} } --- Acts as a gernal handler for any factorio event local function factorio_event_handler(event) local element = event.element + local event_handlers = Factorio_Events[event.name] if element then if not element.valid then return end - local concept_name = element.name - local concept_event = Factorio_Events[event.name][concept_name] - concept_event[1]:raise_event(concept_event[2],event,true) + local concept_event_raise = event_handlers[element.name] + if concept_event_raise then + concept_event_raise(event) + end else - local events_handlers = Factorio_Events[event.name] - for _,concept_event in pairs(events_handlers) do - concept_event[1]:raise_event(concept_event[2],event,true) + for _,concept_event_raise in pairs(event_handlers) do + concept_event_raise(event) end end @@ -110,6 +112,7 @@ function Prototype:clone(concept_name) -- Replace name of the concept concept.name = concept_name concept.properties.name = concept_name + concept:change_name() -- Remove all event handlers that were copied concept.events = {} @@ -117,6 +120,14 @@ function Prototype:clone(concept_name) concept.events[event_name] = {} end + -- Remakes even handlers for factorio + concept.factorio_events = {} + for event_name,factorio_event in pairs(self.factorio_events) do + Factorio_Events[factorio_event][concept.name] = function(event) + concept:raise_event(event_name,event,true) + end + end + -- Remove all refrences to an instance store if concept.instance_store then concept.instance_store = nil @@ -142,9 +153,6 @@ function Prototype:clone(concept_name) concept.set_store_from_instance = nil end - -- Sets the concept name - concept:change_name() - return concept end @@ -201,19 +209,24 @@ end) end local handlers = concept.events[event_name] - handlers[#handlers] = handler + handlers[#handlers+1] = handler return concept end -- Adds the factorio event handler if this event is linked to one if factorio_event then + self.factorio_events[event_name] = factorio_event self.events[event_name].factorio_handler = event_condition + if not Factorio_Events[factorio_event] then Factorio_Events[factorio_event] = {} Event.add(factorio_event,factorio_event_handler) end - Factorio_Events[factorio_event][self.name] = {self,event_name} + + Factorio_Events[factorio_event][self.name] = function(event) + self:raise_event(event_name,event,true) + end end return self @@ -259,7 +272,7 @@ 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 - print('Gui event handler error with '..self.name..'/'..event_name..': '..err) + error('Gui event handler error with '..self.name..'/'..event_name..': '..err) end end end @@ -314,7 +327,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 - print('Gui property handler error with '..concept.name..'/'..property_name..': '..err) + error('Gui property handler error with '..concept.name..'/'..property_name..': '..err) end else -- Otherwise just update the key @@ -392,7 +405,7 @@ function Prototype:draw(parent_element,...) if success and rtn then element = rtn elseif not success then - print('Gui draw handler error with '..self.name..': '..rtn) + error('Gui draw handler error with '..self.name..': '..rtn) end end diff --git a/expcore/gui/test.lua b/expcore/gui/test.lua index fd6d6796..a4b8f56a 100644 --- a/expcore/gui/test.lua +++ b/expcore/gui/test.lua @@ -3,15 +3,40 @@ @alias Gui ]] -local Gui = require 'expcore.gui' +--- Tests. +-- functions used to test +-- @section tests +local Gui = require 'expcore.gui' +local Game = require 'utils.game' -- @dep utils.game + +local test_prefix = '__GUI_TEST_' local tests = {} +local function TEST(str) return test_prefix..str end + +--[[ +The main test frame +]] + +local test_frame = +Gui.clone_concept('frame',TEST 'test_frame') +:set_title('Gui Tests') +:define_draw(function(properties,parent,element) + for category, _ in pairs(tests) do + element.add{ + type = 'flow', + name = category, + direction = 'vertical' + } + end +end) + --[[-- Runs a set of gui tests to ensure that the system is working @tparam LuaPlayer player the player that the guis are made for and who recives the results @tparam[opt] string category when given only tests in this category are ran @usage-- Run all gui tests -Gui.run_tests(Gui.test_string_return(game.print)) +Gui.run_tests(game.player) ]] function Gui.run_tests(player,category) local results = { @@ -42,18 +67,20 @@ function Gui.run_tests(player,category) return results end + local frame = player.gui.center[test_frame.name] or test_frame:draw(player.gui.center) local cat_tests = tests[category] results.total = #cat_tests local output = player.print - for test_name, callback in pairs(cat_tests) do - local success, err = pcall(callback,player) + for test_name, concept in pairs(cat_tests) do + local success, err = pcall(concept.draw,concept,frame[category]) if success then results.passed = results.passed + 1 else - results.erorrs[test_name] = err + results.errors[test_name] = err + results.failed = results.failed + 1 output(string.format('Test "%s / %s" failed:\n%s',category,test_name,err)) end @@ -65,29 +92,51 @@ function Gui.run_tests(player,category) end --[[ -Basic frame creation +Buttons ]] -local test_frame = -Gui.new_concept('test_frame') -:define_draw(function(properties,parent,element) - element = - parent.add{ - name = properties.name, - type = 'frame', - caption = 'Gui Tests' - } - - element.add{ - type = 'label', - caption = 'Hello, World!' - } - - return element +local basic_button = +Gui.clone_concept('button',TEST 'basic_button') +:set_caption('Basic Button') +:set_tooltip('Basic button') +:on_click(function(event) + event.player.print('You pressed basic button!') end) -tests.Frame = { - ['Draw Frame'] = function(player) - test_frame:draw(player.gui.center) +local sprite_button = +Gui.clone_concept('button',TEST 'sprite_button') +:set_sprite('utility/warning_icon') +:set_tooltip('Sprite button') +:on_click(function(event) + event.player.print('You pressed sprite button!') +end) + +local multi_sprite_button = +Gui.clone_concept('button',TEST 'multi_sprite_button') +:set_sprite('utility/warning_icon','utility/warning','utility/warning_white') +:set_tooltip('Multi-sprite button') +:on_click(function(event) + event.player.print('You pressed multi sprite button!') +end) + +local admin_button = +Gui.clone_concept('button',TEST 'admin_button') +:set_caption('Admin Button') +:set_tooltip('Admin button') +:define_draw(function(properties,parent,element) + local player = Game.get_player_by_index(element.player_index) + if not player.admin then + element.enabled = false + element.tooltip = 'You must be admin to press this button' end +end) +:on_click(function(event) + event.player.print('You pressed admin button!') +end) + +tests.Buttons = { + ['Basic Button'] = basic_button, + ['Sprite Button'] = sprite_button, + ['Multi Sprite Button'] = multi_sprite_button, + ['Admin Button'] = admin_button, } \ No newline at end of file From b6311724874de7a4c131dce8ff0ca286fdfd041c Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Thu, 29 Aug 2019 18:20:44 +0100 Subject: [PATCH 07/26] Added checkboxs --- docs/addons/Advanced-Start.html | 2 +- docs/addons/Chat-Popups.html | 2 +- docs/addons/Chat-Reply.html | 2 +- docs/addons/Compilatron.html | 2 +- docs/addons/Damage-Popups.html | 2 +- docs/addons/Death-Logger.html | 2 +- docs/addons/Discord-Alerts.html | 2 +- docs/addons/Player-Colours.html | 2 +- docs/addons/Pollution-Grading.html | 2 +- docs/addons/Scorched-Earth.html | 2 +- docs/addons/Spawn-Area.html | 2 +- docs/commands/Admin-Chat.html | 2 +- docs/commands/Bonus.html | 2 +- docs/commands/Cheat-Mode.html | 2 +- docs/commands/Clear-Inventory.html | 2 +- docs/commands/Debug.html | 2 +- docs/commands/Find.html | 2 +- docs/commands/Help.html | 2 +- docs/commands/Home.html | 2 +- docs/commands/Interface.html | 2 +- docs/commands/Jail.html | 2 +- docs/commands/Kill.html | 2 +- docs/commands/Me.html | 2 +- docs/commands/Rainbow.html | 2 +- docs/commands/Repair.html | 2 +- docs/commands/Reports.html | 2 +- docs/commands/Roles.html | 2 +- docs/commands/Spawn.html | 2 +- docs/commands/Tag.html | 2 +- docs/commands/Teleport.html | 2 +- docs/commands/Warnings.html | 2 +- docs/configs/Advanced-Start.html | 2 +- docs/configs/Bonuses.html | 2 +- docs/configs/Chat-Reply.html | 2 +- docs/configs/Commands-Auth-Admin.html | 2 +- docs/configs/Commands-Auth-Roles.html | 2 +- .../Commands-Auth-Runtime-Disable.html | 2 +- docs/configs/Commands-Parse-Roles.html | 2 +- docs/configs/Commands-Parse.html | 2 +- docs/configs/Compilatron.html | 2 +- docs/configs/Death-Logger.html | 2 +- docs/configs/Discord-Alerts.html | 2 +- docs/configs/File-Loader.html | 2 +- docs/configs/Permission-Groups.html | 2 +- docs/configs/Player-List.html | 2 +- docs/configs/Pollution-Grading.html | 2 +- docs/configs/Popup-Messages.html | 2 +- docs/configs/Preset-Player-Colours.html | 2 +- docs/configs/Repair.html | 2 +- docs/configs/Rockets.html | 2 +- docs/configs/Roles.html | 2 +- docs/configs/Science.html | 2 +- docs/configs/Scorched-Earth.html | 2 +- docs/configs/Spawn-Area.html | 2 +- docs/configs/Tasks.html | 2 +- docs/configs/Warnings.html | 2 +- docs/configs/Warps.html | 2 +- docs/control/Jail.html | 2 +- docs/control/Production.html | 2 +- docs/control/Reports.html | 2 +- docs/control/Rockets.html | 2 +- docs/control/Tasks.html | 2 +- docs/control/Warnings.html | 2 +- docs/control/Warps.html | 2 +- docs/core/Commands.html | 2 +- docs/core/Common-Library.html | 2 +- docs/core/Gui.html | 426 +++++++++++++----- docs/core/Permissions-Groups.html | 2 +- docs/core/Roles.html | 2 +- docs/core/Store.html | 23 +- docs/core/Sudo.html | 2 +- docs/guis/Player-List.html | 2 +- docs/guis/Rocket-Info.html | 2 +- docs/guis/Science-Info.html | 2 +- docs/guis/Task-List.html | 2 +- docs/guis/Warps-List.html | 2 +- docs/index.html | 2 +- docs/modules/control.html | 2 +- .../utils.alien_evolution_progress.html | 2 +- docs/modules/utils.core.html | 2 +- docs/modules/utils.debug.html | 2 +- docs/modules/utils.dump_env.html | 2 +- docs/modules/utils.event.html | 2 +- docs/modules/utils.event_core.html | 2 +- docs/modules/utils.math.html | 2 +- docs/modules/utils.recipe_locker.html | 2 +- docs/modules/utils.state_machine.html | 2 +- docs/modules/utils.table.html | 2 +- docs/modules/utils.task.html | 2 +- docs/modules/utils.timestamp.html | 2 +- docs/topics/license.html | 2 +- docs/topics/readme.md.html | 2 +- expcore/gui.lua | 1 + expcore/gui/concepts/checkbox.lua | 31 ++ expcore/gui/concepts/frame.lua | 4 +- expcore/gui/core.lua | 38 +- expcore/gui/prototype.lua | 95 ++-- expcore/gui/test.lua | 66 +++ expcore/store.lua | 25 +- 99 files changed, 626 insertions(+), 263 deletions(-) create mode 100644 expcore/gui/concepts/checkbox.lua diff --git a/docs/addons/Advanced-Start.html b/docs/addons/Advanced-Start.html index 9bfb5db8..d6ab1816 100644 --- a/docs/addons/Advanced-Start.html +++ b/docs/addons/Advanced-Start.html @@ -348,7 +348,7 @@ generated by LDoc diff --git a/docs/addons/Chat-Popups.html b/docs/addons/Chat-Popups.html index ef85f4de..8c885493 100644 --- a/docs/addons/Chat-Popups.html +++ b/docs/addons/Chat-Popups.html @@ -349,7 +349,7 @@ generated by LDoc diff --git a/docs/addons/Chat-Reply.html b/docs/addons/Chat-Reply.html index e234a42b..50dfd2ad 100644 --- a/docs/addons/Chat-Reply.html +++ b/docs/addons/Chat-Reply.html @@ -376,7 +376,7 @@ generated by LDoc diff --git a/docs/addons/Compilatron.html b/docs/addons/Compilatron.html index 5e3e8756..e4eab2e0 100644 --- a/docs/addons/Compilatron.html +++ b/docs/addons/Compilatron.html @@ -585,7 +585,7 @@ generated by LDoc diff --git a/docs/addons/Damage-Popups.html b/docs/addons/Damage-Popups.html index f344f291..e50155aa 100644 --- a/docs/addons/Damage-Popups.html +++ b/docs/addons/Damage-Popups.html @@ -349,7 +349,7 @@ generated by LDoc diff --git a/docs/addons/Death-Logger.html b/docs/addons/Death-Logger.html index 1bab19c6..8970acbb 100644 --- a/docs/addons/Death-Logger.html +++ b/docs/addons/Death-Logger.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/addons/Discord-Alerts.html b/docs/addons/Discord-Alerts.html index 46d083f3..b05ac7c8 100644 --- a/docs/addons/Discord-Alerts.html +++ b/docs/addons/Discord-Alerts.html @@ -460,7 +460,7 @@ generated by LDoc diff --git a/docs/addons/Player-Colours.html b/docs/addons/Player-Colours.html index 2864df66..ed5370b4 100644 --- a/docs/addons/Player-Colours.html +++ b/docs/addons/Player-Colours.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/addons/Pollution-Grading.html b/docs/addons/Pollution-Grading.html index d9dbd853..f1d7bf9b 100644 --- a/docs/addons/Pollution-Grading.html +++ b/docs/addons/Pollution-Grading.html @@ -320,7 +320,7 @@ generated by LDoc diff --git a/docs/addons/Scorched-Earth.html b/docs/addons/Scorched-Earth.html index 76fb3326..23b5351c 100644 --- a/docs/addons/Scorched-Earth.html +++ b/docs/addons/Scorched-Earth.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/addons/Spawn-Area.html b/docs/addons/Spawn-Area.html index 249c3594..93872520 100644 --- a/docs/addons/Spawn-Area.html +++ b/docs/addons/Spawn-Area.html @@ -376,7 +376,7 @@ generated by LDoc diff --git a/docs/commands/Admin-Chat.html b/docs/commands/Admin-Chat.html index 62b42001..40edeb39 100644 --- a/docs/commands/Admin-Chat.html +++ b/docs/commands/Admin-Chat.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Bonus.html b/docs/commands/Bonus.html index 1bcd987d..0deb5862 100644 --- a/docs/commands/Bonus.html +++ b/docs/commands/Bonus.html @@ -500,7 +500,7 @@ generated by LDoc diff --git a/docs/commands/Cheat-Mode.html b/docs/commands/Cheat-Mode.html index 3bacbf7a..6c005bbc 100644 --- a/docs/commands/Cheat-Mode.html +++ b/docs/commands/Cheat-Mode.html @@ -361,7 +361,7 @@ generated by LDoc diff --git a/docs/commands/Clear-Inventory.html b/docs/commands/Clear-Inventory.html index 1d6df6d3..64d9dfec 100644 --- a/docs/commands/Clear-Inventory.html +++ b/docs/commands/Clear-Inventory.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Debug.html b/docs/commands/Debug.html index 9bde1796..06376fb9 100644 --- a/docs/commands/Debug.html +++ b/docs/commands/Debug.html @@ -365,7 +365,7 @@ generated by LDoc diff --git a/docs/commands/Find.html b/docs/commands/Find.html index cf16472c..f42df5a9 100644 --- a/docs/commands/Find.html +++ b/docs/commands/Find.html @@ -360,7 +360,7 @@ generated by LDoc diff --git a/docs/commands/Help.html b/docs/commands/Help.html index 2ae4c965..7e82f0a8 100644 --- a/docs/commands/Help.html +++ b/docs/commands/Help.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/commands/Home.html b/docs/commands/Home.html index f2daf409..7c80c5c3 100644 --- a/docs/commands/Home.html +++ b/docs/commands/Home.html @@ -458,7 +458,7 @@ generated by LDoc diff --git a/docs/commands/Interface.html b/docs/commands/Interface.html index f6338385..1f44c8dd 100644 --- a/docs/commands/Interface.html +++ b/docs/commands/Interface.html @@ -416,7 +416,7 @@ generated by LDoc diff --git a/docs/commands/Jail.html b/docs/commands/Jail.html index 022cbac6..ff0aecf6 100644 --- a/docs/commands/Jail.html +++ b/docs/commands/Jail.html @@ -611,7 +611,7 @@ generated by LDoc diff --git a/docs/commands/Kill.html b/docs/commands/Kill.html index c23a8a8f..38fb1fe0 100644 --- a/docs/commands/Kill.html +++ b/docs/commands/Kill.html @@ -389,7 +389,7 @@ generated by LDoc diff --git a/docs/commands/Me.html b/docs/commands/Me.html index 8bba6d29..8cc80724 100644 --- a/docs/commands/Me.html +++ b/docs/commands/Me.html @@ -360,7 +360,7 @@ generated by LDoc diff --git a/docs/commands/Rainbow.html b/docs/commands/Rainbow.html index 026f097c..1927d1ac 100644 --- a/docs/commands/Rainbow.html +++ b/docs/commands/Rainbow.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Repair.html b/docs/commands/Repair.html index 54cd982c..3660e26e 100644 --- a/docs/commands/Repair.html +++ b/docs/commands/Repair.html @@ -321,7 +321,7 @@ generated by LDoc diff --git a/docs/commands/Reports.html b/docs/commands/Reports.html index 708e8b36..c49f3872 100644 --- a/docs/commands/Reports.html +++ b/docs/commands/Reports.html @@ -585,7 +585,7 @@ generated by LDoc diff --git a/docs/commands/Roles.html b/docs/commands/Roles.html index d19f1fbe..9707b658 100644 --- a/docs/commands/Roles.html +++ b/docs/commands/Roles.html @@ -557,7 +557,7 @@ generated by LDoc diff --git a/docs/commands/Spawn.html b/docs/commands/Spawn.html index 4a8091cc..397f2426 100644 --- a/docs/commands/Spawn.html +++ b/docs/commands/Spawn.html @@ -389,7 +389,7 @@ generated by LDoc diff --git a/docs/commands/Tag.html b/docs/commands/Tag.html index 8301531e..2c1ba971 100644 --- a/docs/commands/Tag.html +++ b/docs/commands/Tag.html @@ -443,7 +443,7 @@ generated by LDoc diff --git a/docs/commands/Teleport.html b/docs/commands/Teleport.html index eb3517a2..553f1e62 100644 --- a/docs/commands/Teleport.html +++ b/docs/commands/Teleport.html @@ -484,7 +484,7 @@ generated by LDoc diff --git a/docs/commands/Warnings.html b/docs/commands/Warnings.html index 7413701a..1125bfad 100644 --- a/docs/commands/Warnings.html +++ b/docs/commands/Warnings.html @@ -569,7 +569,7 @@ generated by LDoc diff --git a/docs/configs/Advanced-Start.html b/docs/configs/Advanced-Start.html index 288e352a..849de043 100644 --- a/docs/configs/Advanced-Start.html +++ b/docs/configs/Advanced-Start.html @@ -506,7 +506,7 @@ generated by LDoc diff --git a/docs/configs/Bonuses.html b/docs/configs/Bonuses.html index 38426477..620c2178 100644 --- a/docs/configs/Bonuses.html +++ b/docs/configs/Bonuses.html @@ -237,7 +237,7 @@ generated by LDoc diff --git a/docs/configs/Chat-Reply.html b/docs/configs/Chat-Reply.html index 5e821e91..3ef52e69 100644 --- a/docs/configs/Chat-Reply.html +++ b/docs/configs/Chat-Reply.html @@ -485,7 +485,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Admin.html b/docs/configs/Commands-Auth-Admin.html index 90881d2b..e1920f1b 100644 --- a/docs/configs/Commands-Auth-Admin.html +++ b/docs/configs/Commands-Auth-Admin.html @@ -294,7 +294,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Roles.html b/docs/configs/Commands-Auth-Roles.html index 3222992f..4f971a75 100644 --- a/docs/configs/Commands-Auth-Roles.html +++ b/docs/configs/Commands-Auth-Roles.html @@ -320,7 +320,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Runtime-Disable.html b/docs/configs/Commands-Auth-Runtime-Disable.html index 9b18b862..0f55e71e 100644 --- a/docs/configs/Commands-Auth-Runtime-Disable.html +++ b/docs/configs/Commands-Auth-Runtime-Disable.html @@ -442,7 +442,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Parse-Roles.html b/docs/configs/Commands-Parse-Roles.html index 646e2983..1c0ba9d7 100644 --- a/docs/configs/Commands-Parse-Roles.html +++ b/docs/configs/Commands-Parse-Roles.html @@ -354,7 +354,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Parse.html b/docs/configs/Commands-Parse.html index 884ccbb3..f8330810 100644 --- a/docs/configs/Commands-Parse.html +++ b/docs/configs/Commands-Parse.html @@ -338,7 +338,7 @@ see ./expcore/commands.lua for more details

    generated by LDoc diff --git a/docs/configs/Compilatron.html b/docs/configs/Compilatron.html index 763a5a9c..26f9f2db 100644 --- a/docs/configs/Compilatron.html +++ b/docs/configs/Compilatron.html @@ -354,7 +354,7 @@ generated by LDoc diff --git a/docs/configs/Death-Logger.html b/docs/configs/Death-Logger.html index b7f20311..9aaf420f 100644 --- a/docs/configs/Death-Logger.html +++ b/docs/configs/Death-Logger.html @@ -416,7 +416,7 @@ generated by LDoc diff --git a/docs/configs/Discord-Alerts.html b/docs/configs/Discord-Alerts.html index 2f153869..99074842 100644 --- a/docs/configs/Discord-Alerts.html +++ b/docs/configs/Discord-Alerts.html @@ -237,7 +237,7 @@ generated by LDoc diff --git a/docs/configs/File-Loader.html b/docs/configs/File-Loader.html index ac84fc48..ea16c004 100644 --- a/docs/configs/File-Loader.html +++ b/docs/configs/File-Loader.html @@ -240,7 +240,7 @@ generated by LDoc diff --git a/docs/configs/Permission-Groups.html b/docs/configs/Permission-Groups.html index 30cf06a8..8157e15b 100644 --- a/docs/configs/Permission-Groups.html +++ b/docs/configs/Permission-Groups.html @@ -295,7 +295,7 @@ generated by LDoc diff --git a/docs/configs/Player-List.html b/docs/configs/Player-List.html index 4c029621..61c55556 100644 --- a/docs/configs/Player-List.html +++ b/docs/configs/Player-List.html @@ -812,7 +812,7 @@ generated by LDoc diff --git a/docs/configs/Pollution-Grading.html b/docs/configs/Pollution-Grading.html index 0e254751..de328a2d 100644 --- a/docs/configs/Pollution-Grading.html +++ b/docs/configs/Pollution-Grading.html @@ -384,7 +384,7 @@ generated by LDoc diff --git a/docs/configs/Popup-Messages.html b/docs/configs/Popup-Messages.html index 7071d49f..e6732afc 100644 --- a/docs/configs/Popup-Messages.html +++ b/docs/configs/Popup-Messages.html @@ -414,7 +414,7 @@ generated by LDoc diff --git a/docs/configs/Preset-Player-Colours.html b/docs/configs/Preset-Player-Colours.html index 410b72ab..684fb639 100644 --- a/docs/configs/Preset-Player-Colours.html +++ b/docs/configs/Preset-Player-Colours.html @@ -324,7 +324,7 @@ generated by LDoc diff --git a/docs/configs/Repair.html b/docs/configs/Repair.html index 10368fd8..f75f6df3 100644 --- a/docs/configs/Repair.html +++ b/docs/configs/Repair.html @@ -414,7 +414,7 @@ generated by LDoc diff --git a/docs/configs/Rockets.html b/docs/configs/Rockets.html index 7744dcc6..35a10a75 100644 --- a/docs/configs/Rockets.html +++ b/docs/configs/Rockets.html @@ -834,7 +834,7 @@ generated by LDoc diff --git a/docs/configs/Roles.html b/docs/configs/Roles.html index 7153c5fa..3be5369a 100644 --- a/docs/configs/Roles.html +++ b/docs/configs/Roles.html @@ -292,7 +292,7 @@ generated by LDoc diff --git a/docs/configs/Science.html b/docs/configs/Science.html index 2a2736dc..c06b2601 100644 --- a/docs/configs/Science.html +++ b/docs/configs/Science.html @@ -354,7 +354,7 @@ generated by LDoc diff --git a/docs/configs/Scorched-Earth.html b/docs/configs/Scorched-Earth.html index 3208835a..e930a001 100644 --- a/docs/configs/Scorched-Earth.html +++ b/docs/configs/Scorched-Earth.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/configs/Spawn-Area.html b/docs/configs/Spawn-Area.html index e12a5a6e..cb2aaf64 100644 --- a/docs/configs/Spawn-Area.html +++ b/docs/configs/Spawn-Area.html @@ -744,7 +744,7 @@ generated by LDoc diff --git a/docs/configs/Tasks.html b/docs/configs/Tasks.html index 9cc43e14..154b9675 100644 --- a/docs/configs/Tasks.html +++ b/docs/configs/Tasks.html @@ -384,7 +384,7 @@ generated by LDoc diff --git a/docs/configs/Warnings.html b/docs/configs/Warnings.html index 9320be9a..f7f4798f 100644 --- a/docs/configs/Warnings.html +++ b/docs/configs/Warnings.html @@ -355,7 +355,7 @@ generated by LDoc diff --git a/docs/configs/Warps.html b/docs/configs/Warps.html index 16a4f5b8..4c1fae81 100644 --- a/docs/configs/Warps.html +++ b/docs/configs/Warps.html @@ -684,7 +684,7 @@ generated by LDoc diff --git a/docs/control/Jail.html b/docs/control/Jail.html index 9fdc593a..3bb24976 100644 --- a/docs/control/Jail.html +++ b/docs/control/Jail.html @@ -1208,7 +1208,7 @@ generated by LDoc diff --git a/docs/control/Production.html b/docs/control/Production.html index 0a7c702f..bf1ddd05 100644 --- a/docs/control/Production.html +++ b/docs/control/Production.html @@ -1329,7 +1329,7 @@ generated by LDoc diff --git a/docs/control/Reports.html b/docs/control/Reports.html index 995f2cdd..e05e2c9e 100644 --- a/docs/control/Reports.html +++ b/docs/control/Reports.html @@ -1110,7 +1110,7 @@ generated by LDoc diff --git a/docs/control/Rockets.html b/docs/control/Rockets.html index 1d7bb90c..150aa0cd 100644 --- a/docs/control/Rockets.html +++ b/docs/control/Rockets.html @@ -984,7 +984,7 @@ generated by LDoc diff --git a/docs/control/Tasks.html b/docs/control/Tasks.html index 749a9d9e..688c1ffb 100644 --- a/docs/control/Tasks.html +++ b/docs/control/Tasks.html @@ -1039,7 +1039,7 @@ generated by LDoc diff --git a/docs/control/Warnings.html b/docs/control/Warnings.html index 795dc72e..aaaf4a61 100644 --- a/docs/control/Warnings.html +++ b/docs/control/Warnings.html @@ -1465,7 +1465,7 @@ generated by LDoc diff --git a/docs/control/Warps.html b/docs/control/Warps.html index 0c606d3e..feb78238 100644 --- a/docs/control/Warps.html +++ b/docs/control/Warps.html @@ -1413,7 +1413,7 @@ generated by LDoc diff --git a/docs/core/Commands.html b/docs/core/Commands.html index 0acf379e..973cd124 100644 --- a/docs/core/Commands.html +++ b/docs/core/Commands.html @@ -1972,7 +1972,7 @@ generated by LDoc diff --git a/docs/core/Common-Library.html b/docs/core/Common-Library.html index 49ed7f75..864a3443 100644 --- a/docs/core/Common-Library.html +++ b/docs/core/Common-Library.html @@ -2480,7 +2480,7 @@ generated by LDoc diff --git a/docs/core/Gui.html b/docs/core/Gui.html index 62ed7797..d5aa237e 100644 --- a/docs/core/Gui.html +++ b/docs/core/Gui.html @@ -315,6 +315,10 @@ button:clone('CustomButton') The basic button element + checkbox + The basic checkbox element + + frame The basic frame element @@ -346,6 +350,18 @@ button:clone('CustomButton') clone_concept(name, new_name) Making anew concept based on the properties and drawing of another + + categorize_by_player(element) + A categorize function to be used with add_store, each player has their own category + + + categorize_by_force(element) + A categorize function to be used with add_store, each force has its own category + + + categorize_by_surface(element) + A categorize function to be used with add_store, each surface has its own category + @@ -443,16 +459,12 @@ button:clone('CustomButton') - - + + - - - - - - + +
    Updates the data that is stored for this category
    Prototype:define_combined_store([category_callback], get_callback, set_callback)Used to add a both instance and data stores which are linked together, new instances are synced to current value, changing one instances changes them allPrototype:define_combined_store([category_callback], sync_callback)Used to add a both instance and data stores which are linked together, new instances are synced to current value, changing one instance changes them all
    Prototype.set_instance_from_store(the)Will set the state of an instance based on the value in the store
    Prototype.set_store_from_instance(the)Will set the value in the store and update the other instances based on the instance givenPrototype.sync_instance(element)Will sync an instance to match the stored value based on the given sync callback
    @@ -595,6 +607,103 @@ button:clone('CustomButton') + + + + + + +
    +
    +
    +
    + # + checkbox +
    +
    +
    +
    + +

    The basic checkbox element

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + on_state_change + + : + + + fired when the state of the element is changed + +
    • + + + + + +
    • + + caption + + : + + (string or LocalisedString) + + the message that is shown next to the checkbox + +
    • + + + + + +
    • + + tooltip + + : + + (string or LocalisedString) + + the tooltip that shows when a player hovers over the checkbox + +
    • + + + + + +
    • + + use_radio + + : + + (boolean) + + setting to true will use radio buttons rather than checkboxs + +
    • + + +
    + + + + + + + @@ -938,6 +1047,189 @@ button:change_name('Not Button') local custom_button = Gui.clone_concept('Button','CustomButton') +
    +
    +
    +
    + # + categorize_by_player(element) +
    +
    +
    +
    + +

    A categorize function to be used with add_store, each player has their own category

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the element that will be converted to a string + +
    • + + +
    + + + + + Returns: +
      +
    • + (string) + the player's name who owns this element +
    • +
    + + + + + + + + Usage: +
    -- Storing data on a per player basis, can be used with instances
    +Gui.get_concept('CustomButton')
    +:define_data_store(Gui.categorize_by_player)
    + + +
    +
    +
    +
    + # + categorize_by_force(element) +
    +
    +
    +
    + +

    A categorize function to be used with add_store, each force has its own category

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the element that will be converted to a string + +
    • + + +
    + + + + + Returns: +
      +
    • + (string) + the player's force name who owns this element +
    • +
    + + + + + + + + Usage: +
    -- Storing data on a per force basis, can be used with instances
    +Gui.get_concept('CustomButton')
    +:define_data_store(Gui.categorize_by_force)
    + + +
    +
    +
    +
    + # + categorize_by_surface(element) +
    +
    +
    +
    + +

    A categorize function to be used with add_store, each surface has its own category

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the element that will be converted to a string + +
    • + + +
    + + + + + Returns: +
      +
    • + (string) + the player's surface name who owns this element +
    • +
    + + + + + + + + Usage: +
    -- Storing data on a per surface basis, can be used with instances
    +Gui.get_concept('CustomButton')
    +:define_data_store(Gui.categorize_by_surface)
    + +

    Concept Base

    @@ -1137,7 +1429,7 @@ button:change_name('Not Button') @@ -1201,7 +1493,7 @@ Gui.get_concept('Button'):clone(
  • (GuiConcept) - to allow chaing of functions + to allow chaining of functions
  • @@ -1392,7 +1684,7 @@ Gui.get_concept('CustomButton') @@ -1464,7 +1756,7 @@ Gui.get_concept('Button') @@ -1531,7 +1823,7 @@ Gui.get_concept('CustomButton') @@ -1687,7 +1979,7 @@ Gui.get_concept('CustomButton') @@ -1968,7 +2260,7 @@ custom_button.update_instances(1,GuiConcept) - to allow chaing of functions + to allow chaining of functions @@ -2273,13 +2565,13 @@ custom_button.update_data(1,fu
    # - Prototype:define_combined_store([category_callback], get_callback, set_callback) + Prototype:define_combined_store([category_callback], sync_callback)
    -

    Used to add a both instance and data stores which are linked together, new instances are synced to current value, changing one instances changes them all

    +

    Used to add a both instance and data stores which are linked together, new instances are synced to current value, changing one instance changes them all

    @@ -2310,29 +2602,13 @@ custom_button.update_data(1,fu
  • - get_callback + sync_callback : (function) - the function which is called when you set the store from an instance - -
  • - - - - - -
  • - - set_callback - - : - - (function) - - the function which is called when you update an instance using the value in the store + the function which is called to update an instance to match the store
  • @@ -2346,7 +2622,7 @@ custom_button.update_data(1,fu
    • (GuiConcept) - to allow chaing of functions + to allow chaining of functions
    @@ -2357,18 +2633,15 @@ custom_button.update_data(1,fu Usage: -
    -- Adding a way to sync captions bettween all instances, more useful for things that arnt buttons
    +    
    -- Adding a way to sync enabled state bettween all instances, more useful for things that arnt buttons
     local custom_button =
     Gui.get_concept('CustomButton')
     :define_combined_store(
     function(element)
         return element.player_index -- The data is stored based on player id
     end,
    -function(element)
    -   return element.caption -- We want to store the caption
    -end,
     function(element,value)
    -    element.caption = value -- This is the inverse of above
    +    element.enabled = value -- We will use custom_button.set_data(element,value) to trigger this
     end)
    @@ -2376,14 +2649,14 @@ Gui.get_concept('CustomButton')
    - # - Prototype.set_instance_from_store(the) + # + Prototype.sync_instance(element)
    -

    Will set the state of an instance based on the value in the store

    +

    Will sync an instance to match the stored value based on the given sync callback

    @@ -2397,13 +2670,13 @@ Gui.get_concept('CustomButton')
  • - the + element : (LuaGuiElement) - element that you want to have update + the element that you want to have update
  • @@ -2426,64 +2699,7 @@ Gui.get_concept('CustomButton') Gui.get_concept('CustomButton') -- Used internally when first draw and automatically when the store updates -custom_button.set_instance_from_store(element)
    - - -
    -
    -
    -
    - # - Prototype.set_store_from_instance(the) -
    -
    -
    -
    - -

    Will set the value in the store and update the other instances based on the instance given

    -

    - - - Parameters: - -
      - - - - - -
    • - - the - - : - - (LuaGuiElement) - - element that you want to use to update the store - -
    • - - -
    - - - - - - - - - - - - Usage: -
    -- Setting the stored value to be the same as the caption for this element
    -local custom_button =
    -Gui.get_concept('CustomButton')
    -
    --- You may want to use this with gui events
    -custom_button.set_store_from_instance(element)
    +custom_button.sync_instance(element)
    @@ -2575,7 +2791,7 @@ Gui.get_concept('CustomButton') generated by LDoc diff --git a/docs/core/Permissions-Groups.html b/docs/core/Permissions-Groups.html index e05ed687..8ce273b6 100644 --- a/docs/core/Permissions-Groups.html +++ b/docs/core/Permissions-Groups.html @@ -1432,7 +1432,7 @@ generated by LDoc diff --git a/docs/core/Roles.html b/docs/core/Roles.html index 5b989791..5b5c68f6 100644 --- a/docs/core/Roles.html +++ b/docs/core/Roles.html @@ -3152,7 +3152,7 @@ generated by LDoc diff --git a/docs/core/Store.html b/docs/core/Store.html index 937ec539..63540b54 100644 --- a/docs/core/Store.html +++ b/docs/core/Store.html @@ -309,7 +309,7 @@ Store.register(team_scores,function(value,key) Gets the value stored at a location, this location must be registered - set(location[, key], value[, from_sync=false]) + set(location[, key], value[, from_sync=false][, from_internal=false]) Sets the value at a location, this location must be registered @@ -619,7 +619,7 @@ Store.register(team_scores,function(value,key)
    # - set(location[, key], value[, from_sync=false]) + set(location[, key], value[, from_sync=false][, from_internal=false])
    @@ -700,6 +700,23 @@ Store.register(team_scores,function(value,key) + + + +
  • + + from_internal + + : + + (boolean) + + set this true to add one to the error stack offset + + (default: false) +
  • + + @@ -1128,7 +1145,7 @@ Store.register(team_scores,function(value,key) generated by LDoc diff --git a/docs/core/Sudo.html b/docs/core/Sudo.html index aabdfb54..57736aad 100644 --- a/docs/core/Sudo.html +++ b/docs/core/Sudo.html @@ -544,7 +544,7 @@ generated by LDoc diff --git a/docs/guis/Player-List.html b/docs/guis/Player-List.html index 3a76fdcc..8d4129f6 100644 --- a/docs/guis/Player-List.html +++ b/docs/guis/Player-List.html @@ -626,7 +626,7 @@ generated by LDoc diff --git a/docs/guis/Rocket-Info.html b/docs/guis/Rocket-Info.html index d5144327..23ed9247 100644 --- a/docs/guis/Rocket-Info.html +++ b/docs/guis/Rocket-Info.html @@ -629,7 +629,7 @@ generated by LDoc diff --git a/docs/guis/Science-Info.html b/docs/guis/Science-Info.html index 2e733887..f4127fd6 100644 --- a/docs/guis/Science-Info.html +++ b/docs/guis/Science-Info.html @@ -449,7 +449,7 @@ generated by LDoc diff --git a/docs/guis/Task-List.html b/docs/guis/Task-List.html index a3fa28cb..305f0f51 100644 --- a/docs/guis/Task-List.html +++ b/docs/guis/Task-List.html @@ -632,7 +632,7 @@ generated by LDoc diff --git a/docs/guis/Warps-List.html b/docs/guis/Warps-List.html index 4d84021e..b61a8cca 100644 --- a/docs/guis/Warps-List.html +++ b/docs/guis/Warps-List.html @@ -837,7 +837,7 @@ generated by LDoc diff --git a/docs/index.html b/docs/index.html index d55abbff..1889fd98 100644 --- a/docs/index.html +++ b/docs/index.html @@ -510,7 +510,7 @@ see ./expcore/commands.lua for more details generated by LDoc diff --git a/docs/modules/control.html b/docs/modules/control.html index b1e1a273..ffd338ea 100644 --- a/docs/modules/control.html +++ b/docs/modules/control.html @@ -351,7 +351,7 @@ generated by LDoc diff --git a/docs/modules/utils.alien_evolution_progress.html b/docs/modules/utils.alien_evolution_progress.html index e70f53cf..05bd835e 100644 --- a/docs/modules/utils.alien_evolution_progress.html +++ b/docs/modules/utils.alien_evolution_progress.html @@ -419,7 +419,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 2eafdc25..7f806539 100644 --- a/docs/modules/utils.core.html +++ b/docs/modules/utils.core.html @@ -1164,7 +1164,7 @@ generated by LDoc diff --git a/docs/modules/utils.debug.html b/docs/modules/utils.debug.html index e5bab76d..9f62d759 100644 --- a/docs/modules/utils.debug.html +++ b/docs/modules/utils.debug.html @@ -654,7 +654,7 @@ generated by LDoc diff --git a/docs/modules/utils.dump_env.html b/docs/modules/utils.dump_env.html index f86ef92c..598c3b07 100644 --- a/docs/modules/utils.dump_env.html +++ b/docs/modules/utils.dump_env.html @@ -323,7 +323,7 @@ generated by LDoc diff --git a/docs/modules/utils.event.html b/docs/modules/utils.event.html index edf052c2..3a7dfed7 100644 --- a/docs/modules/utils.event.html +++ b/docs/modules/utils.event.html @@ -1292,7 +1292,7 @@ generated by LDoc diff --git a/docs/modules/utils.event_core.html b/docs/modules/utils.event_core.html index 74fd5324..128f1be8 100644 --- a/docs/modules/utils.event_core.html +++ b/docs/modules/utils.event_core.html @@ -434,7 +434,7 @@ generated by LDoc diff --git a/docs/modules/utils.math.html b/docs/modules/utils.math.html index 8898c3e4..cede62e3 100644 --- a/docs/modules/utils.math.html +++ b/docs/modules/utils.math.html @@ -338,7 +338,7 @@ generated by LDoc diff --git a/docs/modules/utils.recipe_locker.html b/docs/modules/utils.recipe_locker.html index b3a13c92..7b96850e 100644 --- a/docs/modules/utils.recipe_locker.html +++ b/docs/modules/utils.recipe_locker.html @@ -441,7 +441,7 @@ generated by LDoc diff --git a/docs/modules/utils.state_machine.html b/docs/modules/utils.state_machine.html index a780a4d1..a8970284 100644 --- a/docs/modules/utils.state_machine.html +++ b/docs/modules/utils.state_machine.html @@ -752,7 +752,7 @@ generated by LDoc diff --git a/docs/modules/utils.table.html b/docs/modules/utils.table.html index 6c086a80..c531c9d0 100644 --- a/docs/modules/utils.table.html +++ b/docs/modules/utils.table.html @@ -1382,7 +1382,7 @@ generated by LDoc diff --git a/docs/modules/utils.task.html b/docs/modules/utils.task.html index b6ca1a92..ab702921 100644 --- a/docs/modules/utils.task.html +++ b/docs/modules/utils.task.html @@ -651,7 +651,7 @@ generated by LDoc diff --git a/docs/modules/utils.timestamp.html b/docs/modules/utils.timestamp.html index 46b83cfd..5ed19e98 100644 --- a/docs/modules/utils.timestamp.html +++ b/docs/modules/utils.timestamp.html @@ -442,7 +442,7 @@ generated by LDoc diff --git a/docs/topics/license.html b/docs/topics/license.html index beee1b37..b04afc2a 100644 --- a/docs/topics/license.html +++ b/docs/topics/license.html @@ -789,7 +789,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 8c8c821c..d7486452 100644 --- a/docs/topics/readme.md.html +++ b/docs/topics/readme.md.html @@ -332,7 +332,7 @@ generated by LDoc diff --git a/expcore/gui.lua b/expcore/gui.lua index a384e8bd..af80dc5b 100644 --- a/expcore/gui.lua +++ b/expcore/gui.lua @@ -69,5 +69,6 @@ local Gui = require 'expcore.gui.core' Gui.require_concept('frame') Gui.require_concept('button') +Gui.require_concept('checkbox') return Gui \ No newline at end of file diff --git a/expcore/gui/concepts/checkbox.lua b/expcore/gui/concepts/checkbox.lua new file mode 100644 index 00000000..050887ab --- /dev/null +++ b/expcore/gui/concepts/checkbox.lua @@ -0,0 +1,31 @@ +--[[-- Core Module - Gui + @module Gui + @alias Gui +]] + +local Gui = require 'expcore.gui.core' + +--[[-- The basic checkbox element +@element checkbox +@param on_state_change 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 use_radio setting to true will use radio buttons rather than checkboxs +]] +Gui.new_concept('checkbox') +:new_event('on_state_change',defines.events.on_gui_checked_state_changed) +:new_property('tooltip') +:new_property('caption') +:new_property('default_state',false) +:new_property('use_radio',false) +:define_draw(function(properties,parent,element) + element = parent.add{ + name = properties.name, + type = properties.use_radio and 'radiobutton' or 'checkbox', + caption = properties.caption, + tooltip = properties.tooltip, + state = properties.default_state + } + + return element +end) \ No newline at end of file diff --git a/expcore/gui/concepts/frame.lua b/expcore/gui/concepts/frame.lua index c484cbe8..87c649ac 100644 --- a/expcore/gui/concepts/frame.lua +++ b/expcore/gui/concepts/frame.lua @@ -10,9 +10,7 @@ local Gui = require 'expcore.gui.core' @tparam ?string|Concepts.LocalisedString title the title that will show in the frame ]] Gui.new_concept('frame') -:new_property('title',function(properties,value) - properties.title = value -end) +:new_property('title') :define_draw(function(properties,parent,element) element = parent.add{ name = properties.name, diff --git a/expcore/gui/core.lua b/expcore/gui/core.lua index 5ce2ec2a..03a50a2e 100644 --- a/expcore/gui/core.lua +++ b/expcore/gui/core.lua @@ -7,7 +7,7 @@ -- Functions that act as a landing point for the other funtions -- @section core -local Event = require 'utils.event' -- @dep utils.event +local Game = require 'utils.game' -- @dep utils.game local Prototype = require 'expcore.gui.prototype' local Gui = { @@ -80,4 +80,40 @@ function Gui.clone_concept(name,new_name) return concept:clone(new_name) end +--[[-- A categorize function to be used with add_store, each player has their own category +@tparam LuaGuiElement element the element that will be converted to a string +@treturn string the player's name who owns this element +@usage-- Storing data on a per player basis, can be used with instances +Gui.get_concept('CustomButton') +:define_data_store(Gui.categorize_by_player) +]] +function Gui.categorize_by_player(element) + local player = Game.get_player_by_index(element.player_index) + return player.name +end + +--[[-- A categorize function to be used with add_store, each force has its own category +@tparam LuaGuiElement element the element that will be converted to a string +@treturn string the player's force name who owns this element +@usage-- Storing data on a per force basis, can be used with instances +Gui.get_concept('CustomButton') +:define_data_store(Gui.categorize_by_force) +]] +function Gui.categorize_by_force(element) + local player = Game.get_player_by_index(element.player_index) + return player.force.name +end + +--[[-- A categorize function to be used with add_store, each surface has its own category +@tparam LuaGuiElement element the element that will be converted to a string +@treturn string the player's surface name who owns this element +@usage-- Storing data on a per surface basis, can be used with instances +Gui.get_concept('CustomButton') +:define_data_store(Gui.categorize_by_surface) +]] +function Gui.categorize_by_surface(element) + local player = Game.get_player_by_index(element.player_index) + return player.surface.name +end + return Gui \ No newline at end of file diff --git a/expcore/gui/prototype.lua b/expcore/gui/prototype.lua index 575ae9b6..6e4f94b5 100644 --- a/expcore/gui/prototype.lua +++ b/expcore/gui/prototype.lua @@ -148,8 +148,8 @@ function Prototype:clone(concept_name) end -- Remove all refrences to a combined store - if concept.set_instance_from_store then - concept.set_instance_from_store = nil + if concept.sync_instance then + concept.sync_instance = nil concept.set_store_from_instance = nil end @@ -175,7 +175,7 @@ end @tparam string event_name the name of the event to add, must be unique, recomented to start with "on_" @tparam[opt] defines.events factorio_event when given will fire the custom event when the factorio event is raised @tparam[opt] function event_condition used to filter when a factorio event triggers the custom event; if the event contains a reference to an element then names are automatically filtered -@treturn GuiConcept to allow chaing of functions +@treturn GuiConcept to allow chaining of functions @usage-- Adds an on_admin_clicked event to fire when ever an admin clicks the button local custom_button = Gui.get_concept('Button'):clone('CustomButton') @@ -192,7 +192,7 @@ function Prototype:new_event(event_name,factorio_event,event_condition) --[[-- Adds a custom event handler, replace with the name of the event @function Prototype:on_custom_event @tparam function handler the function which will recive the event -@treturn GuiConcept to allow chaing of functions +@treturn GuiConcept to allow chaining of functions @usage-- When an admin clicks the button a message is printed local custom_button = Gui.get_concept('CustomButton') @@ -281,7 +281,7 @@ end @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 -@treturn GuiConcept to allow chaing of functions +@treturn GuiConcept to allow chaining of functions @usage-- Adding caption, sprite, and tooltip to the base button concept local button = Gui.get_concept('Button') @@ -309,7 +309,7 @@ function Prototype:new_property(property_name,default,setter_callback) --[[-- Sets a new value for a property, triggers setter method if provided, replace with property name @function Prototype:set_custom_property @tparam any value the value that you want to set for this property -@treturn GuiConcept to allow chaing of functions +@treturn GuiConcept to allow chaining of functions @usage-- Setting the caption on the base button concept after a cloning local custom_button = Gui.get_concept('Button') @@ -342,7 +342,7 @@ end --[[-- Used to define how the concept is turned into an ingame element or "instance" as we may refer to them @tparam function draw_callback the function that will be called to draw/update the instance; this function must return the instance or the new acting instance -@treturn GuiConcept to allow chaing of functions +@treturn GuiConcept to allow chaining of functions @usage-- Adding the draw define for the base button concept, we then return the element local button = Gui.get_concept('Button') @@ -415,8 +415,8 @@ function Prototype:draw(parent_element,...) end -- Syncs the instance if there is a combined store - if self.set_instance_from_store then - self.set_instance_from_store(element) + if self.sync_instance then + self.sync_instance(element) end return element @@ -428,7 +428,7 @@ end --[[-- Adds an instance store to the concept; when a new instance is made it is stored so you can access it later @tparam[opt] function category_callback when given will act as a way to turn an element into a string to act as a key; keys returned can over lap -@treturn GuiConcept to allow chaing of functions +@treturn GuiConcept to allow chaining of functions @usage-- Allowing storing instances of the custom button; stored by the players index -- Note even thou this is a copy of Button; if Button had an instance store it would not be cloned over local custom_button = @@ -442,7 +442,11 @@ function Prototype:define_instance_store(category_callback) local valid_category = category_callback and type(category_callback) == 'function' local function get_category(category) - return valid_category and type(category) == 'table' and category_callback(category) or category + if type(category) == 'table' and type(category.__self) == 'userdata' then + return valid_category and category_callback(category) or nil + else + return category + end end --[[-- Gets all insatnces in a category, category may be nil to return all @@ -494,9 +498,9 @@ custom_button.update_instances(1,function(element) end) ]] function self.update_instances(category,update_callback,...) - local arg1 + local args if type(category) == 'function' then - arg1 = update_callback + args = {update_callback,...} update_callback = category category = nil end @@ -507,7 +511,11 @@ end) instances[key] = nil end - update_callback(instance,arg1,...) + if args then + update_callback(instance,unpack(args)) + else + update_callback(instance,...) + end end end @@ -520,7 +528,7 @@ end --[[-- Adds a data store to this concept which allows you to store synced/percistent data between instances @tparam[opt] function category_callback when given will act as a way to turn an element into a string to act as a key; keys returned can over lap -@treturn GuiConcept to allow chaing of functions +@treturn GuiConcept to allow chaining of functions @usage-- Adding a way to store data for this concept; each player has their own store -- Note even thou this is a copy of Button; if Button had an data store it would not be cloned over local custom_button = @@ -540,7 +548,11 @@ function Prototype:define_data_store(category_callback) local valid_category = category_callback and type(category_callback) == 'function' local function get_category(category) - return valid_category and type(category) == 'table' and category_callback(category) or category + if type(category) == 'table' and type(category.__self) == 'userdata' then + return valid_category and category_callback(category) or nil + else + return category + end end --[[-- Gets the data that is stored for this category @@ -614,66 +626,47 @@ end) -- player index 1 return self end ---[[-- Used to add a both instance and data stores which are linked together, new instances are synced to current value, changing one instances changes them all +--[[-- Used to add a both instance and data stores which are linked together, new instances are synced to current value, changing one instance changes them all @tparam[opt] function category_callback when given will act as a way to turn an element into a string to act as a key; keys returned can over lap -@tparam function get_callback the function which is called when you set the store from an instance -@tparam function set_callback the function which is called when you update an instance using the value in the store -@treturn GuiConcept to allow chaing of functions -@usage-- Adding a way to sync captions bettween all instances, more useful for things that arnt buttons +@tparam function sync_callback the function which is called to update an instance to match the store +@treturn GuiConcept to allow chaining of functions +@usage-- Adding a way to sync enabled state bettween all instances, more useful for things that arnt buttons local custom_button = Gui.get_concept('CustomButton') :define_combined_store( function(element) return element.player_index -- The data is stored based on player id end, -function(element) - return element.caption -- We want to store the caption -end, function(element,value) - element.caption = value -- This is the inverse of above + element.enabled = value -- We will use custom_button.set_data(element,value) to trigger this end) ]] -function Prototype:define_combined_store(category_callback,get_callback,set_callback) - if set_callback == nil then - set_callback = get_callback - get_callback = category_callback +function Prototype:define_combined_store(category_callback,sync_callback) + if sync_callback == nil then + sync_callback = category_callback category_callback = nil end self:define_data_store(category_callback) - self:define_instance_Store(category_callback) + self:define_instance_store(category_callback) -- Will update all instances when the data store updates self:on_data_store_update(function(event) - self.update_instances(event.category,set_callback,event.value) + self.update_instances(event.category,sync_callback,event.value) end) ---[[-- Will set the state of an instance based on the value in the store -@function Prototype.set_instance_from_store -@tparam LuaGuiElement the element that you want to have update +--[[-- Will sync an instance to match the stored value based on the given sync callback +@function Prototype.sync_instance +@tparam LuaGuiElement element the element that you want to have update @usage-- Setting the caption of this element to be the same as the stored value local custom_button = Gui.get_concept('CustomButton') -- Used internally when first draw and automatically when the store updates -custom_button.set_instance_from_store(element) +custom_button.sync_instance(element) ]] - function self.set_instance_from_store(element) - set_callback(element,self.get_data(element)) - end - ---[[-- Will set the value in the store and update the other instances based on the instance given -@function Prototype.set_store_from_instance -@tparam LuaGuiElement the element that you want to use to update the store -@usage-- Setting the stored value to be the same as the caption for this element -local custom_button = -Gui.get_concept('CustomButton') - --- You may want to use this with gui events -custom_button.set_store_from_instance(element) -]] - function self.set_store_from_instance(element) - self.set_data(element,get_callback(element)) + function self.sync_instance(element) + sync_callback(element,self.get_data(element)) end return self diff --git a/expcore/gui/test.lua b/expcore/gui/test.lua index a4b8f56a..77877f95 100644 --- a/expcore/gui/test.lua +++ b/expcore/gui/test.lua @@ -93,6 +93,10 @@ end --[[ Buttons +> Basic Button -- Button with a caption and a tooltip +> Sprite Button -- Button with a single sprite and a tooltip +> Multi Sprite Button -- Button with three sprites and a tooltip +> Admin Button -- Button which is disabled if the player is not an admin ]] local basic_button = @@ -139,4 +143,66 @@ tests.Buttons = { ['Sprite Button'] = sprite_button, ['Multi Sprite Button'] = multi_sprite_button, ['Admin Button'] = admin_button, +} + +--[[ +Checkboxs +> Basic Checkbox -- Simple checkbox that can be toggled +> Game Stored Checkbox -- Checkbox which syncs its state between all players +> Force Stored Checkbox -- Checkbox which syncs its state with all players on the same force +> Player Stored Checkbox -- Checkbox that stores its state between re-draws +]] + +local basic_checkbox = +Gui.clone_concept('checkbox',TEST 'basic_checkbox') +:set_caption('Basic Checkbox') +:set_tooltip('Basic checkbox') +:on_state_change(function(event) + event.player.print('Basic checkbox is now: '..tostring(event.element.state)) +end) + +local game_checkbox = +Gui.clone_concept('checkbox',TEST 'game_checkbox') +:set_caption('Game Stored Checkbox') +:set_tooltip('Game stored checkbox') +:on_state_change(function(event) + local element = event.element + event.concept.set_data(element,element.state) -- Update other instances + event.player.print('Game stored checkbox is now: '..tostring(element.state)) +end) +:define_combined_store(function(element,state) + element.state = state or false +end) + +local force_checkbox = +Gui.clone_concept('checkbox',TEST 'force_checkbox') +:set_caption('Force Stored Checkbox') +:set_tooltip('Force stored checkbox') +:on_state_change(function(event) + local element = event.element + event.concept.set_data(element,element.state) -- Update other instances + event.player.print('Force stored checkbox is now: '..tostring(element.state)) +end) +:define_combined_store(function(element,state) + element.state = state or false +end) + +local player_checkbox = +Gui.clone_concept('checkbox',TEST 'player_checkbox') +:set_caption('Player Stored Checkbox') +:set_tooltip('Player stored checkbox') +:on_state_change(function(event) + local element = event.element + event.concept.set_data(element,element.state) -- Update other instances + event.player.print('Player stored checkbox is now: '..tostring(element.state)) +end) +:define_combined_store(function(element,state) + element.state = state or false +end) + +tests.Checkboxs = { + ['Basic Checkbox'] = basic_checkbox, + ['Game Stored Checkbox'] = game_checkbox, + ['Force Stored Checkbox'] = force_checkbox, + ['Player Stored Checkbox'] = player_checkbox } \ No newline at end of file diff --git a/expcore/store.lua b/expcore/store.lua index 44f29767..9358f0e3 100644 --- a/expcore/store.lua +++ b/expcore/store.lua @@ -122,14 +122,15 @@ end -- @tparam[opt] string key the key location if used -- @tparam any value the new value to set at the location, value may be reverted if there is a watch callback, cant be nil -- @tparam[opt=false] boolean from_sync set this true to avoid an output to the sync file +-- @tparam[opt=false] boolean from_internal set this true to add one to the error stack offset -- @treturn boolean true if it was successful -function Store.set(location,key,value,from_sync) - if not Store.callbacks[location] then - return error('Location is not registered', 2) +function Store.set(location,key,value,from_sync,from_internal) + if not Store.registered[location] then + return error('Location is not registered', from_internal and 3 or 2) end - if key == nil or value == nil then - value = key or value + if value == nil then + value = key key = nil end @@ -163,20 +164,24 @@ end function Store.update(location,key,update_callback,...) local value = Store.get(location,key) - local arg1 + local args if type(key) == 'function' then - arg1 = update_callback + args = {update_callback,...} update_callback = key key = nil end local rtn if update_callback and type(update_callback) == 'function' then - rtn = update_callback(value,key,arg1,...) + if args then + rtn = udpate_callback(value,key,unpack(args)) + else + rtn = update_callback(value,key,...) + end end if rtn then - Store.set(location,key,rtn) + Store.set(location,key,rtn,nil,true) else script.raise_event(Store.events.on_value_changed,{ tick=game.tick, @@ -204,7 +209,7 @@ function Store.update_all(location,update_callback,...) end if rtn then - Store.set(location,key,rtn) + Store.set(location,key,rtn,nil,true) else script.raise_event(Store.events.on_value_changed,{ tick=game.tick, From 38f0413b31daccf5d8fc6aaa1398fcc04b26ccba Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Thu, 29 Aug 2019 18:49:43 +0100 Subject: [PATCH 08/26] Fixed gui events --- expcore/gui/prototype.lua | 42 +++++++++++++++++++++++---------------- expcore/gui/test.lua | 4 ++-- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/expcore/gui/prototype.lua b/expcore/gui/prototype.lua index 6e4f94b5..29426934 100644 --- a/expcore/gui/prototype.lua +++ b/expcore/gui/prototype.lua @@ -83,17 +83,26 @@ local Prototype = { --- Acts as a gernal handler for any factorio event local function factorio_event_handler(event) local element = event.element - local event_handlers = Factorio_Events[event.name] + local rasied_event = event.name + local factorio_event_concepts = Factorio_Events[rasied_event] if element then if not element.valid then return end - local concept_event_raise = event_handlers[element.name] - if concept_event_raise then - concept_event_raise(event) + local concept = factorio_event_concepts[element.name] + if concept then + for event_name, factorio_event in pairs(concept.factorio_events) do + if rasied_event == factorio_event then + concept:raise_event(event_name,event,true) + end + end end else - for _,concept_event_raise in pairs(event_handlers) do - concept_event_raise(event) + for _,concept in pairs(factorio_event_concepts) do + for event_name, factorio_event in pairs(concept.factorio_events) do + if rasied_event == factorio_event then + concept:raise_event(event_name,event,true) + end + end end end @@ -121,11 +130,8 @@ function Prototype:clone(concept_name) end -- Remakes even handlers for factorio - concept.factorio_events = {} - for event_name,factorio_event in pairs(self.factorio_events) do - Factorio_Events[factorio_event][concept.name] = function(event) - concept:raise_event(event_name,event,true) - end + for _,factorio_event in pairs(concept.factorio_events) do + Factorio_Events[factorio_event][concept.name] = concept end -- Remove all refrences to an instance store @@ -217,15 +223,17 @@ end) -- Adds the factorio event handler if this event is linked to one if factorio_event then self.factorio_events[event_name] = factorio_event - self.events[event_name].factorio_handler = event_condition + self.events[event_name].factorio_event_condition = event_condition - if not Factorio_Events[factorio_event] then - Factorio_Events[factorio_event] = {} + local factorio_event_concepts = Factorio_Events[factorio_event] + if not factorio_event_concepts then + factorio_event_concepts = {} + Factorio_Events[factorio_event] = factorio_event_concepts Event.add(factorio_event,factorio_event_handler) end - Factorio_Events[factorio_event][self.name] = function(event) - self:raise_event(event_name,event,true) + if not factorio_event_concepts[self.name] then + factorio_event_concepts[self.name] = self end end @@ -264,7 +272,7 @@ function Prototype:raise_event(event_name,event,from_factorio) local handlers = self.events[event_name] -- If it is from factorio and the filter fails - if from_factorio and handlers.factorio_handler and not handlers.factorio_handler(event) then + if from_factorio and handlers.factorio_event_condition and not handlers.factorio_event_condition(event) then return end diff --git a/expcore/gui/test.lua b/expcore/gui/test.lua index 77877f95..f246cd70 100644 --- a/expcore/gui/test.lua +++ b/expcore/gui/test.lua @@ -183,7 +183,7 @@ Gui.clone_concept('checkbox',TEST 'force_checkbox') event.concept.set_data(element,element.state) -- Update other instances event.player.print('Force stored checkbox is now: '..tostring(element.state)) end) -:define_combined_store(function(element,state) +:define_combined_store(Gui.categorize_by_force,function(element,state) element.state = state or false end) @@ -196,7 +196,7 @@ Gui.clone_concept('checkbox',TEST 'player_checkbox') event.concept.set_data(element,element.state) -- Update other instances event.player.print('Player stored checkbox is now: '..tostring(element.state)) end) -:define_combined_store(function(element,state) +:define_combined_store(Gui.categorize_by_player,function(element,state) element.state = state or false end) From a80d0bf99dca5efbd0838aecf3a6ce6c80323d08 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Fri, 30 Aug 2019 17:13:22 +0100 Subject: [PATCH 09/26] Added dropboxs --- docs/addons/Advanced-Start.html | 2 +- docs/addons/Chat-Popups.html | 2 +- docs/addons/Chat-Reply.html | 2 +- docs/addons/Compilatron.html | 2 +- docs/addons/Damage-Popups.html | 2 +- docs/addons/Death-Logger.html | 2 +- docs/addons/Discord-Alerts.html | 2 +- docs/addons/Player-Colours.html | 2 +- docs/addons/Pollution-Grading.html | 2 +- docs/addons/Scorched-Earth.html | 2 +- docs/addons/Spawn-Area.html | 2 +- docs/commands/Admin-Chat.html | 2 +- docs/commands/Bonus.html | 2 +- docs/commands/Cheat-Mode.html | 2 +- docs/commands/Clear-Inventory.html | 2 +- docs/commands/Debug.html | 2 +- docs/commands/Find.html | 2 +- docs/commands/Help.html | 2 +- docs/commands/Home.html | 2 +- docs/commands/Interface.html | 2 +- docs/commands/Jail.html | 2 +- docs/commands/Kill.html | 2 +- docs/commands/Me.html | 2 +- docs/commands/Rainbow.html | 2 +- docs/commands/Repair.html | 2 +- docs/commands/Reports.html | 2 +- docs/commands/Roles.html | 2 +- docs/commands/Spawn.html | 2 +- docs/commands/Tag.html | 2 +- docs/commands/Teleport.html | 2 +- docs/commands/Warnings.html | 2 +- docs/configs/Advanced-Start.html | 2 +- docs/configs/Bonuses.html | 2 +- docs/configs/Chat-Reply.html | 2 +- docs/configs/Commands-Auth-Admin.html | 2 +- docs/configs/Commands-Auth-Roles.html | 2 +- .../Commands-Auth-Runtime-Disable.html | 2 +- docs/configs/Commands-Parse-Roles.html | 2 +- docs/configs/Commands-Parse.html | 2 +- docs/configs/Compilatron.html | 2 +- docs/configs/Death-Logger.html | 2 +- docs/configs/Discord-Alerts.html | 2 +- docs/configs/File-Loader.html | 2 +- docs/configs/Permission-Groups.html | 2 +- docs/configs/Player-List.html | 2 +- docs/configs/Pollution-Grading.html | 2 +- docs/configs/Popup-Messages.html | 2 +- docs/configs/Preset-Player-Colours.html | 2 +- docs/configs/Repair.html | 2 +- docs/configs/Rockets.html | 2 +- docs/configs/Roles.html | 2 +- docs/configs/Science.html | 2 +- docs/configs/Scorched-Earth.html | 2 +- docs/configs/Spawn-Area.html | 2 +- docs/configs/Tasks.html | 2 +- docs/configs/Warnings.html | 2 +- docs/configs/Warps.html | 2 +- docs/control/Jail.html | 2 +- docs/control/Production.html | 2 +- docs/control/Reports.html | 2 +- docs/control/Rockets.html | 2 +- docs/control/Tasks.html | 2 +- docs/control/Warnings.html | 2 +- docs/control/Warps.html | 2 +- docs/core/Commands.html | 2 +- docs/core/Common-Library.html | 202 +++- docs/core/Gui.html | 979 +++++++++++++++++- docs/core/Permissions-Groups.html | 2 +- docs/core/Roles.html | 2 +- docs/core/Store.html | 2 +- docs/core/Sudo.html | 2 +- docs/guis/Player-List.html | 2 +- docs/guis/Rocket-Info.html | 2 +- docs/guis/Science-Info.html | 2 +- docs/guis/Task-List.html | 2 +- docs/guis/Warps-List.html | 2 +- docs/index.html | 2 +- docs/modules/control.html | 2 +- .../utils.alien_evolution_progress.html | 2 +- docs/modules/utils.core.html | 2 +- docs/modules/utils.debug.html | 2 +- docs/modules/utils.dump_env.html | 2 +- docs/modules/utils.event.html | 2 +- docs/modules/utils.event_core.html | 2 +- docs/modules/utils.math.html | 2 +- docs/modules/utils.recipe_locker.html | 2 +- docs/modules/utils.state_machine.html | 2 +- docs/modules/utils.table.html | 2 +- docs/modules/utils.task.html | 2 +- docs/modules/utils.timestamp.html | 2 +- docs/topics/license.html | 2 +- docs/topics/readme.md.html | 2 +- expcore/common.lua | 63 ++ expcore/gui.lua | 1 + expcore/gui/concepts/dropdown.lua | 131 +++ expcore/gui/core.lua | 120 ++- expcore/gui/prototype.lua | 26 +- expcore/gui/test.lua | 73 ++ 98 files changed, 1651 insertions(+), 124 deletions(-) create mode 100644 expcore/gui/concepts/dropdown.lua diff --git a/docs/addons/Advanced-Start.html b/docs/addons/Advanced-Start.html index d6ab1816..92c6497c 100644 --- a/docs/addons/Advanced-Start.html +++ b/docs/addons/Advanced-Start.html @@ -348,7 +348,7 @@ generated by LDoc diff --git a/docs/addons/Chat-Popups.html b/docs/addons/Chat-Popups.html index 8c885493..42997dda 100644 --- a/docs/addons/Chat-Popups.html +++ b/docs/addons/Chat-Popups.html @@ -349,7 +349,7 @@ generated by LDoc diff --git a/docs/addons/Chat-Reply.html b/docs/addons/Chat-Reply.html index 50dfd2ad..0a6b6ddc 100644 --- a/docs/addons/Chat-Reply.html +++ b/docs/addons/Chat-Reply.html @@ -376,7 +376,7 @@ generated by LDoc diff --git a/docs/addons/Compilatron.html b/docs/addons/Compilatron.html index e4eab2e0..2cc828e8 100644 --- a/docs/addons/Compilatron.html +++ b/docs/addons/Compilatron.html @@ -585,7 +585,7 @@ generated by LDoc diff --git a/docs/addons/Damage-Popups.html b/docs/addons/Damage-Popups.html index e50155aa..69ec2d40 100644 --- a/docs/addons/Damage-Popups.html +++ b/docs/addons/Damage-Popups.html @@ -349,7 +349,7 @@ generated by LDoc diff --git a/docs/addons/Death-Logger.html b/docs/addons/Death-Logger.html index 8970acbb..056e1548 100644 --- a/docs/addons/Death-Logger.html +++ b/docs/addons/Death-Logger.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/addons/Discord-Alerts.html b/docs/addons/Discord-Alerts.html index b05ac7c8..afaf1aa9 100644 --- a/docs/addons/Discord-Alerts.html +++ b/docs/addons/Discord-Alerts.html @@ -460,7 +460,7 @@ generated by LDoc diff --git a/docs/addons/Player-Colours.html b/docs/addons/Player-Colours.html index ed5370b4..96e16e4e 100644 --- a/docs/addons/Player-Colours.html +++ b/docs/addons/Player-Colours.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/addons/Pollution-Grading.html b/docs/addons/Pollution-Grading.html index f1d7bf9b..25c8042d 100644 --- a/docs/addons/Pollution-Grading.html +++ b/docs/addons/Pollution-Grading.html @@ -320,7 +320,7 @@ generated by LDoc diff --git a/docs/addons/Scorched-Earth.html b/docs/addons/Scorched-Earth.html index 23b5351c..c539351c 100644 --- a/docs/addons/Scorched-Earth.html +++ b/docs/addons/Scorched-Earth.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/addons/Spawn-Area.html b/docs/addons/Spawn-Area.html index 93872520..c6d8352f 100644 --- a/docs/addons/Spawn-Area.html +++ b/docs/addons/Spawn-Area.html @@ -376,7 +376,7 @@ generated by LDoc diff --git a/docs/commands/Admin-Chat.html b/docs/commands/Admin-Chat.html index 40edeb39..66ef4df0 100644 --- a/docs/commands/Admin-Chat.html +++ b/docs/commands/Admin-Chat.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Bonus.html b/docs/commands/Bonus.html index 0deb5862..41475286 100644 --- a/docs/commands/Bonus.html +++ b/docs/commands/Bonus.html @@ -500,7 +500,7 @@ generated by LDoc diff --git a/docs/commands/Cheat-Mode.html b/docs/commands/Cheat-Mode.html index 6c005bbc..54cb0aae 100644 --- a/docs/commands/Cheat-Mode.html +++ b/docs/commands/Cheat-Mode.html @@ -361,7 +361,7 @@ generated by LDoc diff --git a/docs/commands/Clear-Inventory.html b/docs/commands/Clear-Inventory.html index 64d9dfec..2225157c 100644 --- a/docs/commands/Clear-Inventory.html +++ b/docs/commands/Clear-Inventory.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Debug.html b/docs/commands/Debug.html index 06376fb9..4c0cd4d9 100644 --- a/docs/commands/Debug.html +++ b/docs/commands/Debug.html @@ -365,7 +365,7 @@ generated by LDoc diff --git a/docs/commands/Find.html b/docs/commands/Find.html index f42df5a9..4080a3bf 100644 --- a/docs/commands/Find.html +++ b/docs/commands/Find.html @@ -360,7 +360,7 @@ generated by LDoc diff --git a/docs/commands/Help.html b/docs/commands/Help.html index 7e82f0a8..513a6f82 100644 --- a/docs/commands/Help.html +++ b/docs/commands/Help.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/commands/Home.html b/docs/commands/Home.html index 7c80c5c3..a9874512 100644 --- a/docs/commands/Home.html +++ b/docs/commands/Home.html @@ -458,7 +458,7 @@ generated by LDoc diff --git a/docs/commands/Interface.html b/docs/commands/Interface.html index 1f44c8dd..5d1c33ce 100644 --- a/docs/commands/Interface.html +++ b/docs/commands/Interface.html @@ -416,7 +416,7 @@ generated by LDoc diff --git a/docs/commands/Jail.html b/docs/commands/Jail.html index ff0aecf6..bc53ef73 100644 --- a/docs/commands/Jail.html +++ b/docs/commands/Jail.html @@ -611,7 +611,7 @@ generated by LDoc diff --git a/docs/commands/Kill.html b/docs/commands/Kill.html index 38fb1fe0..3939bda4 100644 --- a/docs/commands/Kill.html +++ b/docs/commands/Kill.html @@ -389,7 +389,7 @@ generated by LDoc diff --git a/docs/commands/Me.html b/docs/commands/Me.html index 8cc80724..96da4255 100644 --- a/docs/commands/Me.html +++ b/docs/commands/Me.html @@ -360,7 +360,7 @@ generated by LDoc diff --git a/docs/commands/Rainbow.html b/docs/commands/Rainbow.html index 1927d1ac..581d5060 100644 --- a/docs/commands/Rainbow.html +++ b/docs/commands/Rainbow.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Repair.html b/docs/commands/Repair.html index 3660e26e..45930e07 100644 --- a/docs/commands/Repair.html +++ b/docs/commands/Repair.html @@ -321,7 +321,7 @@ generated by LDoc diff --git a/docs/commands/Reports.html b/docs/commands/Reports.html index c49f3872..56c18b1c 100644 --- a/docs/commands/Reports.html +++ b/docs/commands/Reports.html @@ -585,7 +585,7 @@ generated by LDoc diff --git a/docs/commands/Roles.html b/docs/commands/Roles.html index 9707b658..43a2dbe2 100644 --- a/docs/commands/Roles.html +++ b/docs/commands/Roles.html @@ -557,7 +557,7 @@ generated by LDoc diff --git a/docs/commands/Spawn.html b/docs/commands/Spawn.html index 397f2426..fbbfe78a 100644 --- a/docs/commands/Spawn.html +++ b/docs/commands/Spawn.html @@ -389,7 +389,7 @@ generated by LDoc diff --git a/docs/commands/Tag.html b/docs/commands/Tag.html index 2c1ba971..01adb40e 100644 --- a/docs/commands/Tag.html +++ b/docs/commands/Tag.html @@ -443,7 +443,7 @@ generated by LDoc diff --git a/docs/commands/Teleport.html b/docs/commands/Teleport.html index 553f1e62..8ae94c19 100644 --- a/docs/commands/Teleport.html +++ b/docs/commands/Teleport.html @@ -484,7 +484,7 @@ generated by LDoc diff --git a/docs/commands/Warnings.html b/docs/commands/Warnings.html index 1125bfad..b557bcae 100644 --- a/docs/commands/Warnings.html +++ b/docs/commands/Warnings.html @@ -569,7 +569,7 @@ generated by LDoc diff --git a/docs/configs/Advanced-Start.html b/docs/configs/Advanced-Start.html index 849de043..0932b727 100644 --- a/docs/configs/Advanced-Start.html +++ b/docs/configs/Advanced-Start.html @@ -506,7 +506,7 @@ generated by LDoc diff --git a/docs/configs/Bonuses.html b/docs/configs/Bonuses.html index 620c2178..d382d1cd 100644 --- a/docs/configs/Bonuses.html +++ b/docs/configs/Bonuses.html @@ -237,7 +237,7 @@ generated by LDoc diff --git a/docs/configs/Chat-Reply.html b/docs/configs/Chat-Reply.html index 3ef52e69..fd54f747 100644 --- a/docs/configs/Chat-Reply.html +++ b/docs/configs/Chat-Reply.html @@ -485,7 +485,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Admin.html b/docs/configs/Commands-Auth-Admin.html index e1920f1b..cd9471b3 100644 --- a/docs/configs/Commands-Auth-Admin.html +++ b/docs/configs/Commands-Auth-Admin.html @@ -294,7 +294,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Roles.html b/docs/configs/Commands-Auth-Roles.html index 4f971a75..fe734ead 100644 --- a/docs/configs/Commands-Auth-Roles.html +++ b/docs/configs/Commands-Auth-Roles.html @@ -320,7 +320,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Runtime-Disable.html b/docs/configs/Commands-Auth-Runtime-Disable.html index 0f55e71e..27b6926f 100644 --- a/docs/configs/Commands-Auth-Runtime-Disable.html +++ b/docs/configs/Commands-Auth-Runtime-Disable.html @@ -442,7 +442,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Parse-Roles.html b/docs/configs/Commands-Parse-Roles.html index 1c0ba9d7..8dcd4f0d 100644 --- a/docs/configs/Commands-Parse-Roles.html +++ b/docs/configs/Commands-Parse-Roles.html @@ -354,7 +354,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Parse.html b/docs/configs/Commands-Parse.html index f8330810..a97660c0 100644 --- a/docs/configs/Commands-Parse.html +++ b/docs/configs/Commands-Parse.html @@ -338,7 +338,7 @@ see ./expcore/commands.lua for more details

    generated by LDoc diff --git a/docs/configs/Compilatron.html b/docs/configs/Compilatron.html index 26f9f2db..a9868baf 100644 --- a/docs/configs/Compilatron.html +++ b/docs/configs/Compilatron.html @@ -354,7 +354,7 @@ generated by LDoc diff --git a/docs/configs/Death-Logger.html b/docs/configs/Death-Logger.html index 9aaf420f..8963df56 100644 --- a/docs/configs/Death-Logger.html +++ b/docs/configs/Death-Logger.html @@ -416,7 +416,7 @@ generated by LDoc diff --git a/docs/configs/Discord-Alerts.html b/docs/configs/Discord-Alerts.html index 99074842..e1a09d00 100644 --- a/docs/configs/Discord-Alerts.html +++ b/docs/configs/Discord-Alerts.html @@ -237,7 +237,7 @@ generated by LDoc diff --git a/docs/configs/File-Loader.html b/docs/configs/File-Loader.html index ea16c004..14fbb6ac 100644 --- a/docs/configs/File-Loader.html +++ b/docs/configs/File-Loader.html @@ -240,7 +240,7 @@ generated by LDoc diff --git a/docs/configs/Permission-Groups.html b/docs/configs/Permission-Groups.html index 8157e15b..d94d6f00 100644 --- a/docs/configs/Permission-Groups.html +++ b/docs/configs/Permission-Groups.html @@ -295,7 +295,7 @@ generated by LDoc diff --git a/docs/configs/Player-List.html b/docs/configs/Player-List.html index 61c55556..6d8cb490 100644 --- a/docs/configs/Player-List.html +++ b/docs/configs/Player-List.html @@ -812,7 +812,7 @@ generated by LDoc diff --git a/docs/configs/Pollution-Grading.html b/docs/configs/Pollution-Grading.html index de328a2d..aa41c026 100644 --- a/docs/configs/Pollution-Grading.html +++ b/docs/configs/Pollution-Grading.html @@ -384,7 +384,7 @@ generated by LDoc diff --git a/docs/configs/Popup-Messages.html b/docs/configs/Popup-Messages.html index e6732afc..2779dde6 100644 --- a/docs/configs/Popup-Messages.html +++ b/docs/configs/Popup-Messages.html @@ -414,7 +414,7 @@ generated by LDoc diff --git a/docs/configs/Preset-Player-Colours.html b/docs/configs/Preset-Player-Colours.html index 684fb639..80d4629f 100644 --- a/docs/configs/Preset-Player-Colours.html +++ b/docs/configs/Preset-Player-Colours.html @@ -324,7 +324,7 @@ generated by LDoc diff --git a/docs/configs/Repair.html b/docs/configs/Repair.html index f75f6df3..6d9511ad 100644 --- a/docs/configs/Repair.html +++ b/docs/configs/Repair.html @@ -414,7 +414,7 @@ generated by LDoc diff --git a/docs/configs/Rockets.html b/docs/configs/Rockets.html index 35a10a75..de5e9399 100644 --- a/docs/configs/Rockets.html +++ b/docs/configs/Rockets.html @@ -834,7 +834,7 @@ generated by LDoc diff --git a/docs/configs/Roles.html b/docs/configs/Roles.html index 3be5369a..a3da2d55 100644 --- a/docs/configs/Roles.html +++ b/docs/configs/Roles.html @@ -292,7 +292,7 @@ generated by LDoc diff --git a/docs/configs/Science.html b/docs/configs/Science.html index c06b2601..9b681ba8 100644 --- a/docs/configs/Science.html +++ b/docs/configs/Science.html @@ -354,7 +354,7 @@ generated by LDoc diff --git a/docs/configs/Scorched-Earth.html b/docs/configs/Scorched-Earth.html index e930a001..22567624 100644 --- a/docs/configs/Scorched-Earth.html +++ b/docs/configs/Scorched-Earth.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/configs/Spawn-Area.html b/docs/configs/Spawn-Area.html index cb2aaf64..7909f109 100644 --- a/docs/configs/Spawn-Area.html +++ b/docs/configs/Spawn-Area.html @@ -744,7 +744,7 @@ generated by LDoc diff --git a/docs/configs/Tasks.html b/docs/configs/Tasks.html index 154b9675..ac93d06c 100644 --- a/docs/configs/Tasks.html +++ b/docs/configs/Tasks.html @@ -384,7 +384,7 @@ generated by LDoc diff --git a/docs/configs/Warnings.html b/docs/configs/Warnings.html index f7f4798f..2930dbb9 100644 --- a/docs/configs/Warnings.html +++ b/docs/configs/Warnings.html @@ -355,7 +355,7 @@ generated by LDoc diff --git a/docs/configs/Warps.html b/docs/configs/Warps.html index 4c1fae81..f27de952 100644 --- a/docs/configs/Warps.html +++ b/docs/configs/Warps.html @@ -684,7 +684,7 @@ generated by LDoc diff --git a/docs/control/Jail.html b/docs/control/Jail.html index 3bb24976..8efd8a05 100644 --- a/docs/control/Jail.html +++ b/docs/control/Jail.html @@ -1208,7 +1208,7 @@ generated by LDoc diff --git a/docs/control/Production.html b/docs/control/Production.html index bf1ddd05..923cd2c3 100644 --- a/docs/control/Production.html +++ b/docs/control/Production.html @@ -1329,7 +1329,7 @@ generated by LDoc diff --git a/docs/control/Reports.html b/docs/control/Reports.html index e05e2c9e..776785df 100644 --- a/docs/control/Reports.html +++ b/docs/control/Reports.html @@ -1110,7 +1110,7 @@ generated by LDoc diff --git a/docs/control/Rockets.html b/docs/control/Rockets.html index 150aa0cd..47f09a09 100644 --- a/docs/control/Rockets.html +++ b/docs/control/Rockets.html @@ -984,7 +984,7 @@ generated by LDoc diff --git a/docs/control/Tasks.html b/docs/control/Tasks.html index 688c1ffb..e5b584bc 100644 --- a/docs/control/Tasks.html +++ b/docs/control/Tasks.html @@ -1039,7 +1039,7 @@ generated by LDoc diff --git a/docs/control/Warnings.html b/docs/control/Warnings.html index aaaf4a61..778c0d42 100644 --- a/docs/control/Warnings.html +++ b/docs/control/Warnings.html @@ -1465,7 +1465,7 @@ generated by LDoc diff --git a/docs/control/Warps.html b/docs/control/Warps.html index feb78238..5a77b232 100644 --- a/docs/control/Warps.html +++ b/docs/control/Warps.html @@ -1413,7 +1413,7 @@ generated by LDoc diff --git a/docs/core/Commands.html b/docs/core/Commands.html index 973cd124..d6d5eead 100644 --- a/docs/core/Commands.html +++ b/docs/core/Commands.html @@ -1972,7 +1972,7 @@ generated by LDoc diff --git a/docs/core/Common-Library.html b/docs/core/Common-Library.html index 864a3443..402b618c 100644 --- a/docs/core/Common-Library.html +++ b/docs/core/Common-Library.html @@ -361,6 +361,14 @@ get_file_path([offset=0]) Returns a desync safe file path for the current file + + array_insert(tbl[, start_index], values) + Much faster method for inserting items into an array + + + table_insert(tbl[, start_index], tbl2) + Much faster method for inserting keys into a table + @@ -2464,6 +2472,198 @@ +
    +
    +
    +
    + # + array_insert(tbl[, start_index], values) +
    +
    +
    +
    + +

    Much faster method for inserting items into an array

    +

    + + + Parameters: + +
      + + + + + +
    • + + tbl + + : + + (table) + + the table that will have the values added to it + +
    • + + + + + +
    • + + start_index + + : + + (number) + + the index at which values will be added, nil means end of the array + + (optional) +
    • + + + + + +
    • + + values + + : + + (table) + + the new values that will be added to the table + +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the table that was passed as the first argument +
    • +
    + + + + + + + + Usage: +
    -- Adding 1000 values into the middle of the array
    +local tbl = {}
    +local values = {}
    +for i = 1,1000 do tbl[i] = i values[i] = i end
    +Common.array_insert(tbl,500,values) -- around 0.4ms
    + + +
    +
    +
    +
    + # + table_insert(tbl[, start_index], tbl2) +
    +
    +
    +
    + +

    Much faster method for inserting keys into a table

    +

    + + + Parameters: + +
      + + + + + +
    • + + tbl + + : + + (table) + + the table that will have keys added to it + +
    • + + + + + +
    • + + start_index + + : + + (number) + + the index at which values will be added, nil means end of the array, numbered indexs only + + (optional) +
    • + + + + + +
    • + + tbl2 + + : + + (table) + + the table that may contain both string and numbered keys + +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the table passed as the first argument +
    • +
    + + + + + + + + Usage: +
    -- Merging two tables
    +local tbl = {}
    +local tbl2 = {}
    +for i = 1,100 do tbl[i] = i tbl['_'..i] = i tbl2[i] = i tbl2['__'..i] = i end
    +Common.table_insert(tbl,50,tbl2)
    + +
    @@ -2480,7 +2680,7 @@ generated by LDoc diff --git a/docs/core/Gui.html b/docs/core/Gui.html index d5aa237e..7fd92d98 100644 --- a/docs/core/Gui.html +++ b/docs/core/Gui.html @@ -42,10 +42,14 @@

    Sections

    @@ -207,10 +211,14 @@

    Jump to Section

    @@ -319,6 +327,10 @@ button:clone('CustomButton') The basic checkbox element + dropdown + The basic dropdown element + + frame The basic frame element @@ -326,7 +338,27 @@ button:clone('CustomButton') -

    Core

    +

    Dropdowns

    + + + + + + + + + + + + + + + + +
    set_dropdown_value(element, value)Selects the index of a dropdown with this value
    get_dropdown_value(element)Gets the selected item value of a dropdown
    add_dropdown_items(element[, start_index], new_items)Adds the given items into the list of items for this dropdown
    + + +

    Concept Control

    @@ -348,9 +380,53 @@ button:clone('CustomButton') - + + + + + +
    clone_concept(name, new_name)Making anew concept based on the properties and drawing of anotherMake a new concept based on the properties and drawing of another
    draw_concept(name, parent)Used to draw a concept to a parent element
    + + +

    Element Control

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    get_player_from_element(element)Gets the player who owns this element
    valid(element)Simple check for if an element is valid
    destroy(element)Destroies and element if it is valid
    toggle_enabled(element)Toggles the enabled state of an element
    toggle_visible(element)Toggles the visible state of an element
    set_padding(element[, up=0][, down=0][, left=0][, right=0])Sets the padding for a gui element
    + + +

    Store Categories

    + + + + @@ -458,9 +534,17 @@ button:clone('CustomButton') + +
    categorize_by_player(element) A categorize function to be used with add_store, each player has their own category
    Prototype.update_data([category], update_callback) Updates the data that is stored for this category
    + + +

    Concept Combined Instances

    + + + - + @@ -704,6 +788,119 @@ button:clone('CustomButton') + + + + + + + +
    +
    +
    + # + dropdown +
    +
    +
    +
    + +

    The basic dropdown element

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + on_selection_change + + : + + + fired when the selected value is changed + +
    • + + + + + +
    • + + default_selection + + : + + (string or Conepts.LocalisedString) + + the option which is selected by default + +
    • + + + + + +
    • + + use_list_box + + : + + (boolean) + + when true a list box will be used rather than a dropdown menu + +
    • + + + + + +
    • + + static_items + + : + + (nil or table) + + when called with a table the values will be added as items for the dropdown, if called with nil then all items are cleared + +
    • + + + + + +
    • + + dynamic_items + + : + + (function) + + 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 + +
    • + + +
    + + + + + + + @@ -762,7 +959,241 @@ button:clone('CustomButton')
    -

    Core

    +

    Dropdowns

    +
    +
    +
    +
    + # + set_dropdown_value(element, value) +
    +
    +
    +
    + +

    Selects the index of a dropdown with this value

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the dropdown that you want to set the selection for + +
    • + + + + + +
    • + + value + + : + + (string or Conepts.LocalisedString) + + the value that you want selected + +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + if an item with this value was found +
    • +
    + + + + + + + + Usage: +
    -- Selecting the item with the value 'foo'
    +Gui.set_dropdown_value(element,'foo')
    + + +
    +
    +
    +
    + # + get_dropdown_value(element) +
    +
    +
    +
    + +

    Gets the selected item value of a dropdown

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the dropdown that you want the selected value of + +
    • + + +
    + + + + + Returns: +
      +
    • + (string or Conepts.LocalisedString) + the value that is currently selected +
    • +
    + + + + + + + + Usage: +
    -- Getting the selected value
    +local selected_value = Gui.get_dropdown_value(element)
    + + +
    +
    +
    +
    + # + add_dropdown_items(element[, start_index], new_items) +
    +
    +
    +
    + +

    Adds the given items into the list of items for this dropdown

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the dropdown that you want to add the items to + +
    • + + + + + +
    • + + start_index + + : + + (number) + + the index at which the items will be added, if not given appened to the end + + (optional) +
    • + + + + + +
    • + + new_items + + : + + (table) + + the list of new items that you want to add + +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the list of items that the element now has +
    • +
    + + + + + + + + Usage: +
    -- Add the items 'foo' and 'bar' to the end
    +Gui.add_dropdown_items(element,{'foo','bar'})
    +
    -- Add the items 'foo' and 'bar' to the start
    +Gui.add_dropdown_items(element,1,{'foo','bar'})
    + + +
    +
    +

    Concept Control

    @@ -989,7 +1420,7 @@ button:change_name('Not Button')
    -

    Making anew concept based on the properties and drawing of another

    +

    Make a new concept based on the properties and drawing of another

    @@ -1051,6 +1482,513 @@ button:change_name('Not Button')
    + # + draw_concept(name, parent) +
    +
    +
    +
    + +

    Used to draw a concept to a parent element

    +

    + + + Parameters: + +
      + + + + + +
    • + + name + + : + + (string) + + the name of the concept that you want to draw + +
    • + + + + + +
    • + + parent + + : + + (LuaGuiElement) + + the element that will act as a parent for the new element + +
    • + + +
    + + + + + Returns: + + + + + + + + + Usage: +
    -- Drawing a new element
    +Gui.draw_concept('Button',element)
    + + +
    +
    +

    Element Control

    +
    +
    +
    +
    + # + get_player_from_element(element) +
    +
    +
    +
    + +

    Gets the player who owns this element

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the element that you want to get the player of + +
    • + + +
    + + + + + Returns: +
      +
    • + (LuaPlayer) + the player who owns this element +
    • +
    + + + + + + + + Usage: +
    -- Getting the player of an element
    +local player = Gui.get_player_from_element(element)
    + + +
    +
    +
    +
    + # + valid(element) +
    +
    +
    +
    + +

    Simple check for if an element is valid

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the element that you want to check is valid + +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + true if the element is valid +
    • +
    + + + + + + + + Usage: +
    -- Return if not valid
    +if not Gui.valid(element) then return end
    + + +
    +
    +
    +
    + # + destroy(element) +
    +
    +
    +
    + +

    Destroies and element if it is valid

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the element that you want to destroy + +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + true if the element was valid and was destoried +
    • +
    + + + + + + + + Usage: +
    -- Destoring an element
    +Gui.destroy(element)
    + + +
    +
    +
    +
    + # + toggle_enabled(element) +
    +
    +
    +
    + +

    Toggles the enabled state of an element

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the element that you want to toggle the enabled state of + +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + the new enabled state of the element +
    • +
    + + + + + + + + Usage: +
    -- Toggle the enabled state of an element
    +Gui.toggle_enabled(element)
    + + +
    +
    +
    +
    + # + toggle_visible(element) +
    +
    +
    +
    + +

    Toggles the visible state of an element

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the element that you want to toggle the visible state of + +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + the new visible state of the element +
    • +
    + + + + + + + + Usage: +
    -- Toggle the visible state of an element
    +Gui.toggle_visible(element)
    + + +
    +
    +
    +
    + # + set_padding(element[, up=0][, down=0][, left=0][, right=0]) +
    +
    +
    +
    + +

    Sets the padding for a gui element

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the element to set the padding for + +
    • + + + + + +
    • + + up + + : + + (number or boolean) + + the amount of padding on the top, true leaves unchanged + + (default: 0) +
    • + + + + + +
    • + + down + + : + + (number or boolean) + + the amount of padding on the bottom, true leaves unchanged + + (default: 0) +
    • + + + + + +
    • + + left + + : + + (number or boolean) + + the amount of padding on the left, true leaves unchanged + + (default: 0) +
    • + + + + + +
    • + + right + + : + + (number or boolean) + + the amount of padding on the right, true leaves unchanged + + (default: 0) +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Remove all padding of an element
    +Gui.set_padding(element)
    +
    -- Remove side padding but keep vertical padding
    +Gui.set_padding(element,true,true)
    +
    -- Remove all padding but set right to 2
    +Gui.set_padding(element,false,false,false,2)
    + + +
    +
    +

    Store Categories

    +
    +
    +
    +
    # categorize_by_player(element)
    @@ -2561,6 +3499,9 @@ custom_button.update_data(1,fu +
    +

    Concept Combined Instances

    +
    @@ -2571,7 +3512,7 @@ custom_button.update_data(1,fu
    -

    Used to add a both instance and data stores which are linked together, new instances are synced to current value, changing one instance changes them all

    +

    Used to add a both instance and data store which are linked together, new instances are synced to the current value, changing the stored value will change all instances

    @@ -2608,7 +3549,7 @@ custom_button.update_data(1,fu (function) - the function which is called to update an instance to match the store + the function which is called to update an instance to match the store, this is called on all instances when concept.set_data or update_data is used @@ -2633,15 +3574,17 @@ custom_button.update_data(1,fu Usage: -
    -- Adding a way to sync enabled state bettween all instances, more useful for things that arnt buttons
    +    
    -- Adding a check box which is a "global setting" synced between all players
     local custom_button =
    -Gui.get_concept('CustomButton')
    -:define_combined_store(
    -function(element)
    -    return element.player_index -- The data is stored based on player id
    -end,
    -function(element,value)
    -    element.enabled = value -- We will use custom_button.set_data(element,value) to trigger this
    +Gui.get_concept('checkbox'):clone('my_checkbox')
    +:set_caption('My Checkbox')
    +:set_tooltip('Clicking this check box will change it for everyone')
    +:on_state_change(function(event)
    +    local element = event.element
    +    event.concept.set_data(element,element.state) -- Update the stored data to trigger an update of all other instances
    +end)
    +:define_combined_store(function(element,state) -- We could add a category function here if we wanted to
    +    element.state = state or false -- When you sync an instance this is what is called
     end)
    @@ -2791,7 +3734,7 @@ Gui.get_concept('CustomButton') generated by LDoc
    diff --git a/docs/core/Permissions-Groups.html b/docs/core/Permissions-Groups.html index 8ce273b6..321c7219 100644 --- a/docs/core/Permissions-Groups.html +++ b/docs/core/Permissions-Groups.html @@ -1432,7 +1432,7 @@ generated by LDoc diff --git a/docs/core/Roles.html b/docs/core/Roles.html index 5b5c68f6..f051b7ee 100644 --- a/docs/core/Roles.html +++ b/docs/core/Roles.html @@ -3152,7 +3152,7 @@ generated by LDoc diff --git a/docs/core/Store.html b/docs/core/Store.html index 63540b54..64239e4a 100644 --- a/docs/core/Store.html +++ b/docs/core/Store.html @@ -1145,7 +1145,7 @@ Store.register(team_scores,function(value,key) generated by LDoc diff --git a/docs/core/Sudo.html b/docs/core/Sudo.html index 57736aad..36408431 100644 --- a/docs/core/Sudo.html +++ b/docs/core/Sudo.html @@ -544,7 +544,7 @@ generated by LDoc diff --git a/docs/guis/Player-List.html b/docs/guis/Player-List.html index 8d4129f6..4b079ad5 100644 --- a/docs/guis/Player-List.html +++ b/docs/guis/Player-List.html @@ -626,7 +626,7 @@ generated by LDoc diff --git a/docs/guis/Rocket-Info.html b/docs/guis/Rocket-Info.html index 23ed9247..a18b977b 100644 --- a/docs/guis/Rocket-Info.html +++ b/docs/guis/Rocket-Info.html @@ -629,7 +629,7 @@ generated by LDoc diff --git a/docs/guis/Science-Info.html b/docs/guis/Science-Info.html index f4127fd6..096a9a61 100644 --- a/docs/guis/Science-Info.html +++ b/docs/guis/Science-Info.html @@ -449,7 +449,7 @@ generated by LDoc diff --git a/docs/guis/Task-List.html b/docs/guis/Task-List.html index 305f0f51..adee14e8 100644 --- a/docs/guis/Task-List.html +++ b/docs/guis/Task-List.html @@ -632,7 +632,7 @@ generated by LDoc diff --git a/docs/guis/Warps-List.html b/docs/guis/Warps-List.html index b61a8cca..9908cbc0 100644 --- a/docs/guis/Warps-List.html +++ b/docs/guis/Warps-List.html @@ -837,7 +837,7 @@ generated by LDoc diff --git a/docs/index.html b/docs/index.html index 1889fd98..bd77e448 100644 --- a/docs/index.html +++ b/docs/index.html @@ -510,7 +510,7 @@ see ./expcore/commands.lua for more details generated by LDoc diff --git a/docs/modules/control.html b/docs/modules/control.html index ffd338ea..c3f18211 100644 --- a/docs/modules/control.html +++ b/docs/modules/control.html @@ -351,7 +351,7 @@ generated by LDoc diff --git a/docs/modules/utils.alien_evolution_progress.html b/docs/modules/utils.alien_evolution_progress.html index 05bd835e..46a4497e 100644 --- a/docs/modules/utils.alien_evolution_progress.html +++ b/docs/modules/utils.alien_evolution_progress.html @@ -419,7 +419,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 7f806539..e7420999 100644 --- a/docs/modules/utils.core.html +++ b/docs/modules/utils.core.html @@ -1164,7 +1164,7 @@ generated by LDoc diff --git a/docs/modules/utils.debug.html b/docs/modules/utils.debug.html index 9f62d759..0f4c0a43 100644 --- a/docs/modules/utils.debug.html +++ b/docs/modules/utils.debug.html @@ -654,7 +654,7 @@ generated by LDoc diff --git a/docs/modules/utils.dump_env.html b/docs/modules/utils.dump_env.html index 598c3b07..2c13b76c 100644 --- a/docs/modules/utils.dump_env.html +++ b/docs/modules/utils.dump_env.html @@ -323,7 +323,7 @@ generated by LDoc diff --git a/docs/modules/utils.event.html b/docs/modules/utils.event.html index 3a7dfed7..6a9981fa 100644 --- a/docs/modules/utils.event.html +++ b/docs/modules/utils.event.html @@ -1292,7 +1292,7 @@ generated by LDoc diff --git a/docs/modules/utils.event_core.html b/docs/modules/utils.event_core.html index 128f1be8..d52e1d2c 100644 --- a/docs/modules/utils.event_core.html +++ b/docs/modules/utils.event_core.html @@ -434,7 +434,7 @@ generated by LDoc diff --git a/docs/modules/utils.math.html b/docs/modules/utils.math.html index cede62e3..46f3910a 100644 --- a/docs/modules/utils.math.html +++ b/docs/modules/utils.math.html @@ -338,7 +338,7 @@ generated by LDoc diff --git a/docs/modules/utils.recipe_locker.html b/docs/modules/utils.recipe_locker.html index 7b96850e..29e7512b 100644 --- a/docs/modules/utils.recipe_locker.html +++ b/docs/modules/utils.recipe_locker.html @@ -441,7 +441,7 @@ generated by LDoc diff --git a/docs/modules/utils.state_machine.html b/docs/modules/utils.state_machine.html index a8970284..fe3678b5 100644 --- a/docs/modules/utils.state_machine.html +++ b/docs/modules/utils.state_machine.html @@ -752,7 +752,7 @@ generated by LDoc diff --git a/docs/modules/utils.table.html b/docs/modules/utils.table.html index c531c9d0..d48d0e5a 100644 --- a/docs/modules/utils.table.html +++ b/docs/modules/utils.table.html @@ -1382,7 +1382,7 @@ generated by LDoc diff --git a/docs/modules/utils.task.html b/docs/modules/utils.task.html index ab702921..1a27b68d 100644 --- a/docs/modules/utils.task.html +++ b/docs/modules/utils.task.html @@ -651,7 +651,7 @@ generated by LDoc diff --git a/docs/modules/utils.timestamp.html b/docs/modules/utils.timestamp.html index 5ed19e98..ee47361f 100644 --- a/docs/modules/utils.timestamp.html +++ b/docs/modules/utils.timestamp.html @@ -442,7 +442,7 @@ generated by LDoc diff --git a/docs/topics/license.html b/docs/topics/license.html index b04afc2a..1d25c8c5 100644 --- a/docs/topics/license.html +++ b/docs/topics/license.html @@ -789,7 +789,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 d7486452..f68e0370 100644 --- a/docs/topics/readme.md.html +++ b/docs/topics/readme.md.html @@ -332,7 +332,7 @@ generated by LDoc diff --git a/expcore/common.lua b/expcore/common.lua index 8efb7d1b..d465e4d8 100644 --- a/expcore/common.lua +++ b/expcore/common.lua @@ -619,4 +619,67 @@ function Common.get_file_path(offset) return debug.getinfo(offset+2, 'S').source:match('^.+/currently%-playing/(.+)$'):sub(1, -5) end +--[[-- Much faster method for inserting items into an array +@tparam table tbl the table that will have the values added to it +@tparam[opt] number start_index the index at which values will be added, nil means end of the array +@tparam table values the new values that will be added to the table +@treturn table the table that was passed as the first argument +@usage-- Adding 1000 values into the middle of the array +local tbl = {} +local values = {} +for i = 1,1000 do tbl[i] = i values[i] = i end +Common.array_insert(tbl,500,values) -- around 0.4ms +]] +function Common.array_insert(tbl,start_index,values) + if not values then + values = start_index + start_index = nil + end + + if start_index then + local starting_length = #tbl + local adding_length = #values + local move_to = start_index+adding_length+1 + for offset = 0, starting_length-start_index do + tbl[move_to+offset] = tbl[starting_length+offset] + end + start_index = start_index-1 + else + start_index = #tbl + end + + for offset, item in ipairs(values) do + tbl[start_index+offset] = item + end + + return tbl +end + +--[[-- Much faster method for inserting keys into a table +@tparam table tbl the table that will have keys added to it +@tparam[opt] number start_index the index at which values will be added, nil means end of the array, numbered indexs only +@tparam table tbl2 the table that may contain both string and numbered keys +@treturn table the table passed as the first argument +@usage-- Merging two tables +local tbl = {} +local tbl2 = {} +for i = 1,100 do tbl[i] = i tbl['_'..i] = i tbl2[i] = i tbl2['__'..i] = i end +Common.table_insert(tbl,50,tbl2) +]] +function Common.table_insert(tbl,start_index,tbl2) + if not tbl2 then + tbl2 = start_index + start_index = nil + end + + Common.array_insert(tbl,start_index,tbl2) + for key, value in pairs(tbl2) do + if not tonumber(key) then + tbl[key] = value + end + end + + return tbl +end + return Common \ No newline at end of file diff --git a/expcore/gui.lua b/expcore/gui.lua index af80dc5b..4777854e 100644 --- a/expcore/gui.lua +++ b/expcore/gui.lua @@ -70,5 +70,6 @@ local Gui = require 'expcore.gui.core' Gui.require_concept('frame') Gui.require_concept('button') Gui.require_concept('checkbox') +Gui.require_concept('dropdown') return Gui \ No newline at end of file diff --git a/expcore/gui/concepts/dropdown.lua b/expcore/gui/concepts/dropdown.lua new file mode 100644 index 00000000..39064587 --- /dev/null +++ b/expcore/gui/concepts/dropdown.lua @@ -0,0 +1,131 @@ +--[[-- Core Module - Gui + @module Gui + @alias Gui +]] + +local Gui = require 'expcore.gui.core' +local array_insert = ext_require('expcore.common','array_insert') + +--[[-- The basic dropdown element +@element dropdown +@param on_selection_change fired when the selected value is changed +@tparam ?string|Conepts.LocalisedString default_selection the option which is selected by default +@tparam 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 +]] +Gui.new_concept('dropdown') +:new_event('on_selection_change',defines.events.on_gui_selection_state_changed) +:new_property('default_selection') +:new_property('use_list_box',false) +:new_property('static_items',nil,function(properties,value,start_index) + if not value then + properties.items = {} + end + + if type(value) ~= 'table' then + value = {value} + end + + local items = properties.items + if not items then + properties.items = value + return + end + + array_insert(items,start_index,value) +end) +:new_property('dynamic_items',nil,function(properties,value) + if type(value) ~= 'function' then + error('Dynamic items must be a function') + end + + local items = properties.dynamic_items + if not items then + properties.dynamic_items = {value} + return + 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 {}) + + element = parent.add{ + name = properties.name, + type = properties.use_list_box and 'list-box' or 'drop-down', + items = items + } + + if properties.dynamic_items then + for _,callback in pairs(properties.dynamic_items) do + local dynamic_items, start_index = callback(element) + Gui.add_dropdown_items(element,start_index,dynamic_items) + end + end + + if properties.default_selection then + local default = properties.default_selection + if type(default) == 'function' then + default = default(element) + end + + Gui.set_dropdown_value(element,default) + end + + return element +end) + +--- Dropdowns. +-- functions used with dropdowns +-- @section dropdowns + +--[[-- Selects the index of a dropdown with this value +@tparam LuaGuiElement element the dropdown that you want to set the selection for +@tparam ?string|Conepts.LocalisedString value the value that you want selected +@treturn boolean if an item with this value was found +@usage-- Selecting the item with the value 'foo' +Gui.set_dropdown_value(element,'foo') +]] +function Gui.set_dropdown_value(element,value) + for index, item in pairs(element.items) do + if item == value then + element.selected_index = index + return true + end + end + return false +end + +--[[-- Gets the selected item value of a dropdown +@tparam LuaGuiElement element the dropdown that you want the selected value of +@treturn ?string|Conepts.LocalisedString the value that is currently selected +@usage-- Getting the selected value +local selected_value = Gui.get_dropdown_value(element) +]] +function Gui.get_dropdown_value(element) + return element.items[element.selected_index] +end + +--[[-- Adds the given items into the list of items for this dropdown +@tparam LuaGuiElement element the dropdown that you want to add the items to +@tparam[opt] number start_index the index at which the items will be added, if not given appened to the end +@tparam table new_items the list of new items that you want to add +@treturn table the list of items that the element now has +@usage-- Add the items 'foo' and 'bar' to the end +Gui.add_dropdown_items(element,{'foo','bar'}) +@usage-- Add the items 'foo' and 'bar' to the start +Gui.add_dropdown_items(element,1,{'foo','bar'}) +]] +function Gui.add_dropdown_items(element,start_index,new_items) + if not new_items then + new_items = start_index + start_index = nil + end + + local items = element.items + element.items = array_insert(items,start_index,new_items) + + return items +end \ No newline at end of file diff --git a/expcore/gui/core.lua b/expcore/gui/core.lua index 03a50a2e..6329550f 100644 --- a/expcore/gui/core.lua +++ b/expcore/gui/core.lua @@ -3,10 +3,6 @@ @alias Gui ]] ---- Core. --- Functions that act as a landing point for the other funtions --- @section core - local Game = require 'utils.game' -- @dep utils.game local Prototype = require 'expcore.gui.prototype' @@ -14,6 +10,10 @@ local Gui = { concepts = {} } +--- Concept Control. +-- 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 @usage-- Load a base concept @@ -64,7 +64,7 @@ function Gui.new_concept(name) return Prototype:clone(name) end ---[[-- Making anew concept based on the properties and drawing of another +--[[-- 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 @@ -80,6 +80,116 @@ function Gui.clone_concept(name,new_name) 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 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) + + return concept:draw(parent,...) +end + +--- Element Control. +-- Functions that aim to making working with gui elements easier +-- @section element-control + +--[[-- Gets the player who owns this element +@tparam LuaGuiElement element the element that you want to get the player of +@treturn LuaPlayer the player who owns this element +@usage-- Getting the player of an element +local player = Gui.get_player_from_element(element) +]] +function Gui.get_player_from_element(element) + return Game.get_player_by_index(element.player_index) +end + +--[[-- Simple check for if an element is valid +@tparam LuaGuiElement element the element that you want to check is valid +@treturn boolean true if the element is valid +@usage-- Return if not valid +if not Gui.valid(element) then return end +]] +function Gui.valid(element) + return element and element.valid or false +end + +--[[-- Destroies and element if it is valid +@tparam LuaGuiElement element the element that you want to destroy +@treturn boolean true if the element was valid and was destoried +@usage-- Destoring an element +Gui.destroy(element) +]] +function Gui.destroy(element) + if element and element.valid then + element.destroy() + return true + end + return false +end + +--[[-- Toggles the enabled state of an element +@tparam LuaGuiElement element the element that you want to toggle the enabled state of +@treturn boolean the new enabled state of the element +@usage-- Toggle the enabled state of an element +Gui.toggle_enabled(element) +]] +function Gui.toggle_enabled(element) + if not element or not element.valid then return end + if not element.enabled then + element.enabled = true + return true + else + element.enabled = false + return false + end +end + +--[[-- Toggles the visible state of an element +@tparam LuaGuiElement element the element that you want to toggle the visible state of +@treturn boolean the new visible state of the element +@usage-- Toggle the visible state of an element +Gui.toggle_visible(element) +]] +function Gui.toggle_visible(element) + if not element or not element.valid then return end + if not element.visible then + element.visible = true + return true + else + element.visible = false + return false + end +end + +--[[-- Sets the padding for a gui element +@tparam LuaGuiElement element the element to set the padding for +@tparam[opt=0] ?number|boolean up the amount of padding on the top, true leaves unchanged +@tparam[opt=0] ?number|boolean down the amount of padding on the bottom, true leaves unchanged +@tparam[opt=0] ?number|boolean left the amount of padding on the left, true leaves unchanged +@tparam[opt=0] ?number|boolean right the amount of padding on the right, true leaves unchanged +@usage-- Remove all padding of an element +Gui.set_padding(element) +@usage-- Remove side padding but keep vertical padding +Gui.set_padding(element,true,true) +@usage-- Remove all padding but set right to 2 +Gui.set_padding(element,false,false,false,2) +]] +function Gui.set_padding(element,up,down,left,right) + local style = element.style + style.top_padding = up == true and style.top_padding or up or 0 + style.bottom_padding = down == true and style.top_padding or down or 0 + style.left_padding = left == true and style.top_padding or left or 0 + style.right_padding = right == true and style.top_padding or right or 0 +end + +--- Store Categories. +-- Functions that are common types of categories +-- @section store-categories + --[[-- A categorize function to be used with add_store, each player has their own category @tparam LuaGuiElement element the element that will be converted to a string @treturn string the player's name who owns this element diff --git a/expcore/gui/prototype.lua b/expcore/gui/prototype.lua index 29426934..ee3db3c5 100644 --- a/expcore/gui/prototype.lua +++ b/expcore/gui/prototype.lua @@ -634,19 +634,25 @@ end) -- player index 1 return self end ---[[-- Used to add a both instance and data stores which are linked together, new instances are synced to current value, changing one instance changes them all +--- Concept Combined Instances. +-- Functions that are used to make store concept instances and data +-- @section concept-instances + +--[[-- Used to add a both instance and data store which are linked together, new instances are synced to the current value, changing the stored value will change all instances @tparam[opt] function category_callback when given will act as a way to turn an element into a string to act as a key; keys returned can over lap -@tparam function sync_callback the function which is called to update an instance to match the store +@tparam function sync_callback the function which is called to update an instance to match the store, this is called on all instances when concept.set_data or update_data is used @treturn GuiConcept to allow chaining of functions -@usage-- Adding a way to sync enabled state bettween all instances, more useful for things that arnt buttons +@usage-- Adding a check box which is a "global setting" synced between all players local custom_button = -Gui.get_concept('CustomButton') -:define_combined_store( -function(element) - return element.player_index -- The data is stored based on player id -end, -function(element,value) - element.enabled = value -- We will use custom_button.set_data(element,value) to trigger this +Gui.get_concept('checkbox'):clone('my_checkbox') +:set_caption('My Checkbox') +:set_tooltip('Clicking this check box will change it for everyone') +:on_state_change(function(event) + local element = event.element + event.concept.set_data(element,element.state) -- Update the stored data to trigger an update of all other instances +end) +:define_combined_store(function(element,state) -- We could add a category function here if we wanted to + element.state = state or false -- When you sync an instance this is what is called end) ]] function Prototype:define_combined_store(category_callback,sync_callback) diff --git a/expcore/gui/test.lua b/expcore/gui/test.lua index f246cd70..b1f0aa25 100644 --- a/expcore/gui/test.lua +++ b/expcore/gui/test.lua @@ -205,4 +205,77 @@ tests.Checkboxs = { ['Game Stored Checkbox'] = game_checkbox, ['Force Stored Checkbox'] = force_checkbox, ['Player Stored Checkbox'] = player_checkbox +} + +--[[ +Dropdowns +> Static Dropdown -- Simple dropdown with all options being static +> Dynamic Dropdown -- Dropdown which has items based on when it is drawn +> Static Player Stored Dropdown -- Dropdown where the values is synced for each player +> Dynamic Player Stored Dropdown -- Same as above but now with dynamic options +]] + +local static_dropdown = +Gui.clone_concept('dropdown',TEST 'static_dropdown') +:set_static_items{'Option 1','Option 2','Option 3'} +:on_selection_change(function(event) + local value = Gui.get_dropdown_value(event.element) + event.player.print('Static dropdown is now: '..value) +end) + +local dynamic_dropdown = +Gui.clone_concept('dropdown',TEST 'dynamic_dropdown') +:set_dynamic_items(function(element) + local items = {} + for concept_name,_ in pairs(Gui.concepts) do + if concept_name:len() < 16 then + items[#items+1] = concept_name + end + end + return items +end) +:on_selection_change(function(event) + local value = Gui.get_dropdown_value(event.element) + event.player.print('Dynamic dropdown is now: '..value) +end) + +local static_player_dropdown = +Gui.clone_concept('dropdown',TEST 'static_player_dropdown') +:set_static_items{'Option 1','Option 2','Option 3'} +:on_selection_change(function(event) + local element = event.element + local value = Gui.get_dropdown_value(element) + event.concept.set_data(element,value) + event.player.print('Static player stored dropdown is now: '..value) +end) +:define_combined_store(Gui.categorize_by_player,function(element,value) + Gui.set_dropdown_value(element,value) +end) + +local dynamic_player_dropdown = +Gui.clone_concept('dropdown',TEST 'dynamic_player_dropdown') +:set_dynamic_items(function(element) + local items = {} + for concept_name,_ in pairs(Gui.concepts) do + if concept_name:len() < 16 then + items[#items+1] = concept_name + end + end + return items +end) +:on_selection_change(function(event) + local element = event.element + local value = Gui.get_dropdown_value(element) + event.concept.set_data(element,value) + event.player.print('Dynamic player dropdown is now: '..value) +end) +:define_combined_store(Gui.categorize_by_player,function(element,value) + Gui.set_dropdown_value(element,value) +end) + +tests.Dropdowns = { + ['Static Dropdown'] = static_dropdown, + ['Dynamic Dropdown'] = dynamic_dropdown, + ['Static Player Stored Dropdown'] = static_player_dropdown, + ['Dynamic Player Stored Dropdown'] = dynamic_player_dropdown } \ No newline at end of file From 361f9adc4e990eae2080373b719ed670680a8d3f Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Fri, 30 Aug 2019 23:04:54 +0100 Subject: [PATCH 10/26] Doc Changes --- docs/addons/Advanced-Start.html | 2 +- docs/addons/Chat-Popups.html | 2 +- docs/addons/Chat-Reply.html | 2 +- docs/addons/Compilatron.html | 2 +- docs/addons/Damage-Popups.html | 2 +- docs/addons/Death-Logger.html | 2 +- docs/addons/Discord-Alerts.html | 2 +- docs/addons/Player-Colours.html | 2 +- docs/addons/Pollution-Grading.html | 2 +- docs/addons/Scorched-Earth.html | 2 +- docs/addons/Spawn-Area.html | 2 +- docs/commands/Admin-Chat.html | 2 +- docs/commands/Bonus.html | 2 +- docs/commands/Cheat-Mode.html | 2 +- docs/commands/Clear-Inventory.html | 2 +- docs/commands/Debug.html | 2 +- docs/commands/Find.html | 2 +- docs/commands/Help.html | 2 +- docs/commands/Home.html | 2 +- docs/commands/Interface.html | 2 +- docs/commands/Jail.html | 2 +- docs/commands/Kill.html | 2 +- docs/commands/Me.html | 2 +- docs/commands/Rainbow.html | 2 +- docs/commands/Repair.html | 2 +- docs/commands/Reports.html | 2 +- docs/commands/Roles.html | 2 +- docs/commands/Spawn.html | 2 +- docs/commands/Tag.html | 2 +- docs/commands/Teleport.html | 2 +- docs/commands/Warnings.html | 2 +- docs/configs/Advanced-Start.html | 2 +- docs/configs/Bonuses.html | 2 +- docs/configs/Chat-Reply.html | 2 +- docs/configs/Commands-Auth-Admin.html | 2 +- docs/configs/Commands-Auth-Roles.html | 2 +- .../Commands-Auth-Runtime-Disable.html | 2 +- docs/configs/Commands-Parse-Roles.html | 2 +- docs/configs/Commands-Parse.html | 2 +- docs/configs/Compilatron.html | 2 +- docs/configs/Death-Logger.html | 2 +- docs/configs/Discord-Alerts.html | 2 +- docs/configs/File-Loader.html | 2 +- docs/configs/Permission-Groups.html | 2 +- docs/configs/Player-List.html | 2 +- docs/configs/Pollution-Grading.html | 2 +- docs/configs/Popup-Messages.html | 2 +- docs/configs/Preset-Player-Colours.html | 2 +- docs/configs/Repair.html | 2 +- docs/configs/Rockets.html | 2 +- docs/configs/Roles.html | 2 +- docs/configs/Science.html | 2 +- docs/configs/Scorched-Earth.html | 2 +- docs/configs/Spawn-Area.html | 2 +- docs/configs/Tasks.html | 2 +- docs/configs/Warnings.html | 2 +- docs/configs/Warps.html | 2 +- docs/control/Jail.html | 2 +- docs/control/Production.html | 2 +- docs/control/Reports.html | 2 +- docs/control/Rockets.html | 2 +- docs/control/Tasks.html | 2 +- docs/control/Warnings.html | 2 +- docs/control/Warps.html | 2 +- docs/core/Commands.html | 2 +- docs/core/Common-Library.html | 2 +- docs/core/Gui.html | 64 ++++++++++++++++++- docs/core/Permissions-Groups.html | 2 +- docs/core/Roles.html | 2 +- docs/core/Store.html | 2 +- docs/core/Sudo.html | 2 +- docs/guis/Player-List.html | 2 +- docs/guis/Rocket-Info.html | 2 +- docs/guis/Science-Info.html | 2 +- docs/guis/Task-List.html | 2 +- docs/guis/Warps-List.html | 2 +- docs/index.html | 2 +- docs/modules/control.html | 2 +- .../utils.alien_evolution_progress.html | 2 +- docs/modules/utils.core.html | 2 +- docs/modules/utils.debug.html | 2 +- docs/modules/utils.dump_env.html | 2 +- docs/modules/utils.event.html | 2 +- docs/modules/utils.event_core.html | 2 +- docs/modules/utils.math.html | 2 +- docs/modules/utils.recipe_locker.html | 2 +- docs/modules/utils.state_machine.html | 2 +- docs/modules/utils.table.html | 2 +- docs/modules/utils.task.html | 2 +- docs/modules/utils.timestamp.html | 2 +- docs/topics/license.html | 2 +- docs/topics/readme.md.html | 2 +- expcore/gui/concepts/button.lua | 16 +++++ expcore/gui/concepts/checkbox.lua | 8 +++ expcore/gui/concepts/dropdown.lua | 24 +++++++ expcore/gui/concepts/frame.lua | 10 +++ 96 files changed, 212 insertions(+), 92 deletions(-) diff --git a/docs/addons/Advanced-Start.html b/docs/addons/Advanced-Start.html index 92c6497c..3d4c3734 100644 --- a/docs/addons/Advanced-Start.html +++ b/docs/addons/Advanced-Start.html @@ -348,7 +348,7 @@ generated by LDoc diff --git a/docs/addons/Chat-Popups.html b/docs/addons/Chat-Popups.html index 42997dda..9cd4a94f 100644 --- a/docs/addons/Chat-Popups.html +++ b/docs/addons/Chat-Popups.html @@ -349,7 +349,7 @@ generated by LDoc diff --git a/docs/addons/Chat-Reply.html b/docs/addons/Chat-Reply.html index 0a6b6ddc..ebbfd73f 100644 --- a/docs/addons/Chat-Reply.html +++ b/docs/addons/Chat-Reply.html @@ -376,7 +376,7 @@ generated by LDoc diff --git a/docs/addons/Compilatron.html b/docs/addons/Compilatron.html index 2cc828e8..67b29137 100644 --- a/docs/addons/Compilatron.html +++ b/docs/addons/Compilatron.html @@ -585,7 +585,7 @@ generated by LDoc diff --git a/docs/addons/Damage-Popups.html b/docs/addons/Damage-Popups.html index 69ec2d40..81e0c2e7 100644 --- a/docs/addons/Damage-Popups.html +++ b/docs/addons/Damage-Popups.html @@ -349,7 +349,7 @@ generated by LDoc diff --git a/docs/addons/Death-Logger.html b/docs/addons/Death-Logger.html index 056e1548..c6cd6ad5 100644 --- a/docs/addons/Death-Logger.html +++ b/docs/addons/Death-Logger.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/addons/Discord-Alerts.html b/docs/addons/Discord-Alerts.html index afaf1aa9..3faee111 100644 --- a/docs/addons/Discord-Alerts.html +++ b/docs/addons/Discord-Alerts.html @@ -460,7 +460,7 @@ generated by LDoc diff --git a/docs/addons/Player-Colours.html b/docs/addons/Player-Colours.html index 96e16e4e..b9e1c3ab 100644 --- a/docs/addons/Player-Colours.html +++ b/docs/addons/Player-Colours.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/addons/Pollution-Grading.html b/docs/addons/Pollution-Grading.html index 25c8042d..47bcd776 100644 --- a/docs/addons/Pollution-Grading.html +++ b/docs/addons/Pollution-Grading.html @@ -320,7 +320,7 @@ generated by LDoc diff --git a/docs/addons/Scorched-Earth.html b/docs/addons/Scorched-Earth.html index c539351c..76b4b241 100644 --- a/docs/addons/Scorched-Earth.html +++ b/docs/addons/Scorched-Earth.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/addons/Spawn-Area.html b/docs/addons/Spawn-Area.html index c6d8352f..b1e70e46 100644 --- a/docs/addons/Spawn-Area.html +++ b/docs/addons/Spawn-Area.html @@ -376,7 +376,7 @@ generated by LDoc diff --git a/docs/commands/Admin-Chat.html b/docs/commands/Admin-Chat.html index 66ef4df0..5b548d8e 100644 --- a/docs/commands/Admin-Chat.html +++ b/docs/commands/Admin-Chat.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Bonus.html b/docs/commands/Bonus.html index 41475286..989cd718 100644 --- a/docs/commands/Bonus.html +++ b/docs/commands/Bonus.html @@ -500,7 +500,7 @@ generated by LDoc diff --git a/docs/commands/Cheat-Mode.html b/docs/commands/Cheat-Mode.html index 54cb0aae..d5b4d67d 100644 --- a/docs/commands/Cheat-Mode.html +++ b/docs/commands/Cheat-Mode.html @@ -361,7 +361,7 @@ generated by LDoc diff --git a/docs/commands/Clear-Inventory.html b/docs/commands/Clear-Inventory.html index 2225157c..c5bbd056 100644 --- a/docs/commands/Clear-Inventory.html +++ b/docs/commands/Clear-Inventory.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Debug.html b/docs/commands/Debug.html index 4c0cd4d9..fa9b156c 100644 --- a/docs/commands/Debug.html +++ b/docs/commands/Debug.html @@ -365,7 +365,7 @@ generated by LDoc diff --git a/docs/commands/Find.html b/docs/commands/Find.html index 4080a3bf..b2f3c1b6 100644 --- a/docs/commands/Find.html +++ b/docs/commands/Find.html @@ -360,7 +360,7 @@ generated by LDoc diff --git a/docs/commands/Help.html b/docs/commands/Help.html index 513a6f82..6e926e3a 100644 --- a/docs/commands/Help.html +++ b/docs/commands/Help.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/commands/Home.html b/docs/commands/Home.html index a9874512..94912d71 100644 --- a/docs/commands/Home.html +++ b/docs/commands/Home.html @@ -458,7 +458,7 @@ generated by LDoc diff --git a/docs/commands/Interface.html b/docs/commands/Interface.html index 5d1c33ce..664677d5 100644 --- a/docs/commands/Interface.html +++ b/docs/commands/Interface.html @@ -416,7 +416,7 @@ generated by LDoc diff --git a/docs/commands/Jail.html b/docs/commands/Jail.html index bc53ef73..2d9bf3d2 100644 --- a/docs/commands/Jail.html +++ b/docs/commands/Jail.html @@ -611,7 +611,7 @@ generated by LDoc diff --git a/docs/commands/Kill.html b/docs/commands/Kill.html index 3939bda4..0593ed7b 100644 --- a/docs/commands/Kill.html +++ b/docs/commands/Kill.html @@ -389,7 +389,7 @@ generated by LDoc diff --git a/docs/commands/Me.html b/docs/commands/Me.html index 96da4255..4cb2155b 100644 --- a/docs/commands/Me.html +++ b/docs/commands/Me.html @@ -360,7 +360,7 @@ generated by LDoc diff --git a/docs/commands/Rainbow.html b/docs/commands/Rainbow.html index 581d5060..1c98f116 100644 --- a/docs/commands/Rainbow.html +++ b/docs/commands/Rainbow.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Repair.html b/docs/commands/Repair.html index 45930e07..3c64fe5c 100644 --- a/docs/commands/Repair.html +++ b/docs/commands/Repair.html @@ -321,7 +321,7 @@ generated by LDoc diff --git a/docs/commands/Reports.html b/docs/commands/Reports.html index 56c18b1c..c99884e7 100644 --- a/docs/commands/Reports.html +++ b/docs/commands/Reports.html @@ -585,7 +585,7 @@ generated by LDoc diff --git a/docs/commands/Roles.html b/docs/commands/Roles.html index 43a2dbe2..6fcce0c6 100644 --- a/docs/commands/Roles.html +++ b/docs/commands/Roles.html @@ -557,7 +557,7 @@ generated by LDoc diff --git a/docs/commands/Spawn.html b/docs/commands/Spawn.html index fbbfe78a..57ccc41a 100644 --- a/docs/commands/Spawn.html +++ b/docs/commands/Spawn.html @@ -389,7 +389,7 @@ generated by LDoc diff --git a/docs/commands/Tag.html b/docs/commands/Tag.html index 01adb40e..b84c0861 100644 --- a/docs/commands/Tag.html +++ b/docs/commands/Tag.html @@ -443,7 +443,7 @@ generated by LDoc diff --git a/docs/commands/Teleport.html b/docs/commands/Teleport.html index 8ae94c19..3a5a47eb 100644 --- a/docs/commands/Teleport.html +++ b/docs/commands/Teleport.html @@ -484,7 +484,7 @@ generated by LDoc diff --git a/docs/commands/Warnings.html b/docs/commands/Warnings.html index b557bcae..7ca3110c 100644 --- a/docs/commands/Warnings.html +++ b/docs/commands/Warnings.html @@ -569,7 +569,7 @@ generated by LDoc diff --git a/docs/configs/Advanced-Start.html b/docs/configs/Advanced-Start.html index 0932b727..37bffff8 100644 --- a/docs/configs/Advanced-Start.html +++ b/docs/configs/Advanced-Start.html @@ -506,7 +506,7 @@ generated by LDoc diff --git a/docs/configs/Bonuses.html b/docs/configs/Bonuses.html index d382d1cd..ee42480a 100644 --- a/docs/configs/Bonuses.html +++ b/docs/configs/Bonuses.html @@ -237,7 +237,7 @@ generated by LDoc diff --git a/docs/configs/Chat-Reply.html b/docs/configs/Chat-Reply.html index fd54f747..9028f366 100644 --- a/docs/configs/Chat-Reply.html +++ b/docs/configs/Chat-Reply.html @@ -485,7 +485,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Admin.html b/docs/configs/Commands-Auth-Admin.html index cd9471b3..963ddbe0 100644 --- a/docs/configs/Commands-Auth-Admin.html +++ b/docs/configs/Commands-Auth-Admin.html @@ -294,7 +294,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Roles.html b/docs/configs/Commands-Auth-Roles.html index fe734ead..e38df53c 100644 --- a/docs/configs/Commands-Auth-Roles.html +++ b/docs/configs/Commands-Auth-Roles.html @@ -320,7 +320,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Runtime-Disable.html b/docs/configs/Commands-Auth-Runtime-Disable.html index 27b6926f..0ed24222 100644 --- a/docs/configs/Commands-Auth-Runtime-Disable.html +++ b/docs/configs/Commands-Auth-Runtime-Disable.html @@ -442,7 +442,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Parse-Roles.html b/docs/configs/Commands-Parse-Roles.html index 8dcd4f0d..e39ebf73 100644 --- a/docs/configs/Commands-Parse-Roles.html +++ b/docs/configs/Commands-Parse-Roles.html @@ -354,7 +354,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Parse.html b/docs/configs/Commands-Parse.html index a97660c0..1011011c 100644 --- a/docs/configs/Commands-Parse.html +++ b/docs/configs/Commands-Parse.html @@ -338,7 +338,7 @@ see ./expcore/commands.lua for more details

    generated by LDoc diff --git a/docs/configs/Compilatron.html b/docs/configs/Compilatron.html index a9868baf..9f8ce2fa 100644 --- a/docs/configs/Compilatron.html +++ b/docs/configs/Compilatron.html @@ -354,7 +354,7 @@ generated by LDoc diff --git a/docs/configs/Death-Logger.html b/docs/configs/Death-Logger.html index 8963df56..a449f6d1 100644 --- a/docs/configs/Death-Logger.html +++ b/docs/configs/Death-Logger.html @@ -416,7 +416,7 @@ generated by LDoc diff --git a/docs/configs/Discord-Alerts.html b/docs/configs/Discord-Alerts.html index e1a09d00..91e5d9e8 100644 --- a/docs/configs/Discord-Alerts.html +++ b/docs/configs/Discord-Alerts.html @@ -237,7 +237,7 @@ generated by LDoc diff --git a/docs/configs/File-Loader.html b/docs/configs/File-Loader.html index 14fbb6ac..de492fac 100644 --- a/docs/configs/File-Loader.html +++ b/docs/configs/File-Loader.html @@ -240,7 +240,7 @@ generated by LDoc diff --git a/docs/configs/Permission-Groups.html b/docs/configs/Permission-Groups.html index d94d6f00..1218f72a 100644 --- a/docs/configs/Permission-Groups.html +++ b/docs/configs/Permission-Groups.html @@ -295,7 +295,7 @@ generated by LDoc diff --git a/docs/configs/Player-List.html b/docs/configs/Player-List.html index 6d8cb490..b26e51d7 100644 --- a/docs/configs/Player-List.html +++ b/docs/configs/Player-List.html @@ -812,7 +812,7 @@ generated by LDoc diff --git a/docs/configs/Pollution-Grading.html b/docs/configs/Pollution-Grading.html index aa41c026..eb69b09a 100644 --- a/docs/configs/Pollution-Grading.html +++ b/docs/configs/Pollution-Grading.html @@ -384,7 +384,7 @@ generated by LDoc diff --git a/docs/configs/Popup-Messages.html b/docs/configs/Popup-Messages.html index 2779dde6..3f2d93b2 100644 --- a/docs/configs/Popup-Messages.html +++ b/docs/configs/Popup-Messages.html @@ -414,7 +414,7 @@ generated by LDoc diff --git a/docs/configs/Preset-Player-Colours.html b/docs/configs/Preset-Player-Colours.html index 80d4629f..3ea83a45 100644 --- a/docs/configs/Preset-Player-Colours.html +++ b/docs/configs/Preset-Player-Colours.html @@ -324,7 +324,7 @@ generated by LDoc diff --git a/docs/configs/Repair.html b/docs/configs/Repair.html index 6d9511ad..f0def66d 100644 --- a/docs/configs/Repair.html +++ b/docs/configs/Repair.html @@ -414,7 +414,7 @@ generated by LDoc diff --git a/docs/configs/Rockets.html b/docs/configs/Rockets.html index de5e9399..16cca0e3 100644 --- a/docs/configs/Rockets.html +++ b/docs/configs/Rockets.html @@ -834,7 +834,7 @@ generated by LDoc diff --git a/docs/configs/Roles.html b/docs/configs/Roles.html index a3da2d55..34a42438 100644 --- a/docs/configs/Roles.html +++ b/docs/configs/Roles.html @@ -292,7 +292,7 @@ generated by LDoc diff --git a/docs/configs/Science.html b/docs/configs/Science.html index 9b681ba8..8cadcfc0 100644 --- a/docs/configs/Science.html +++ b/docs/configs/Science.html @@ -354,7 +354,7 @@ generated by LDoc diff --git a/docs/configs/Scorched-Earth.html b/docs/configs/Scorched-Earth.html index 22567624..703ee5b6 100644 --- a/docs/configs/Scorched-Earth.html +++ b/docs/configs/Scorched-Earth.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/configs/Spawn-Area.html b/docs/configs/Spawn-Area.html index 7909f109..30ec85a5 100644 --- a/docs/configs/Spawn-Area.html +++ b/docs/configs/Spawn-Area.html @@ -744,7 +744,7 @@ generated by LDoc diff --git a/docs/configs/Tasks.html b/docs/configs/Tasks.html index ac93d06c..d318130f 100644 --- a/docs/configs/Tasks.html +++ b/docs/configs/Tasks.html @@ -384,7 +384,7 @@ generated by LDoc diff --git a/docs/configs/Warnings.html b/docs/configs/Warnings.html index 2930dbb9..68d59a5a 100644 --- a/docs/configs/Warnings.html +++ b/docs/configs/Warnings.html @@ -355,7 +355,7 @@ generated by LDoc diff --git a/docs/configs/Warps.html b/docs/configs/Warps.html index f27de952..e86fbb96 100644 --- a/docs/configs/Warps.html +++ b/docs/configs/Warps.html @@ -684,7 +684,7 @@ generated by LDoc diff --git a/docs/control/Jail.html b/docs/control/Jail.html index 8efd8a05..9bcebaa0 100644 --- a/docs/control/Jail.html +++ b/docs/control/Jail.html @@ -1208,7 +1208,7 @@ generated by LDoc diff --git a/docs/control/Production.html b/docs/control/Production.html index 923cd2c3..3cbacd64 100644 --- a/docs/control/Production.html +++ b/docs/control/Production.html @@ -1329,7 +1329,7 @@ generated by LDoc diff --git a/docs/control/Reports.html b/docs/control/Reports.html index 776785df..ecd87fb0 100644 --- a/docs/control/Reports.html +++ b/docs/control/Reports.html @@ -1110,7 +1110,7 @@ generated by LDoc diff --git a/docs/control/Rockets.html b/docs/control/Rockets.html index 47f09a09..89000802 100644 --- a/docs/control/Rockets.html +++ b/docs/control/Rockets.html @@ -984,7 +984,7 @@ generated by LDoc diff --git a/docs/control/Tasks.html b/docs/control/Tasks.html index e5b584bc..75165013 100644 --- a/docs/control/Tasks.html +++ b/docs/control/Tasks.html @@ -1039,7 +1039,7 @@ generated by LDoc diff --git a/docs/control/Warnings.html b/docs/control/Warnings.html index 778c0d42..e7e3d72d 100644 --- a/docs/control/Warnings.html +++ b/docs/control/Warnings.html @@ -1465,7 +1465,7 @@ generated by LDoc diff --git a/docs/control/Warps.html b/docs/control/Warps.html index 5a77b232..4505c21e 100644 --- a/docs/control/Warps.html +++ b/docs/control/Warps.html @@ -1413,7 +1413,7 @@ generated by LDoc diff --git a/docs/core/Commands.html b/docs/core/Commands.html index d6d5eead..fc6c5e2d 100644 --- a/docs/core/Commands.html +++ b/docs/core/Commands.html @@ -1972,7 +1972,7 @@ generated by LDoc diff --git a/docs/core/Common-Library.html b/docs/core/Common-Library.html index 402b618c..448be51d 100644 --- a/docs/core/Common-Library.html +++ b/docs/core/Common-Library.html @@ -2680,7 +2680,7 @@ Common.table_insert(tbl,50,tbl2)
    generated by LDoc diff --git a/docs/core/Gui.html b/docs/core/Gui.html index 7fd92d98..9d24b6c7 100644 --- a/docs/core/Gui.html +++ b/docs/core/Gui.html @@ -695,6 +695,23 @@ button:clone('CustomButton') + Usage: +
    -- Making a basic button
    +local basic_button =
    +Gui.clone_concept('button','basic_button')
    +:set_caption('Basic Button')
    +:set_tooltip('Basic button')
    +:on_click(function(event)
    +    event.player.print('You pressed basic button!')
    +end)
    +
    -- Making a sprite button
    +local sprite_button =
    +Gui.clone_concept('button','sprite_button')
    +:set_sprite('utility/warning_icon')
    +:set_tooltip('Sprite button')
    +:on_click(function(event)
    +    event.player.print('You pressed sprite button!')
    +end)
    @@ -792,6 +809,15 @@ button:clone('CustomButton') + Usage: +
    -- Making a basic checkbox
    +local basic_checkbox =
    +Gui.clone_concept('checkbox','basic_checkbox')
    +:set_caption('Basic Checkbox')
    +:set_tooltip('Basic checkbox')
    +:on_state_change(function(event)
    +    event.player.print('Basic checkbox is now: '..tostring(event.element.state))
    +end)
    @@ -905,6 +931,31 @@ button:clone('CustomButton') + Usage: +
    -- Making a basic dropdown
    +local static_dropdown =
    +Gui.clone_concept('dropdown','static_dropdown')
    +:set_static_items{'Option 1','Option 2','Option 3'}
    +:on_selection_change(function(event)
    +    local value = Gui.get_dropdown_value(event.element)
    +    event.player.print('Static dropdown is now: '..value)
    +end)
    +
    -- Making a dropdown with dynamic items, example is name of online players
    +local dynamic_dropdown =
    +Gui.clone_concept('dropdown','dynamic_dropdown')
    +:set_dynamic_items(function(element)
    +    local items = {}
    +
    +    for _,player in pairs(game.connected_players) do
    +        items[#items+1] = player.name
    +    end
    +
    +    return items
    +end)
    +:on_selection_change(function(event)
    +    local value = Gui.get_dropdown_value(event.element)
    +    event.player.print('Dynamic dropdown is now: '..value)
    +end)
    @@ -955,6 +1006,17 @@ button:clone('CustomButton') + Usage: +
    -- Making a basic frame, contains a label with hello world
    +local basic_frame =
    +Gui.clone_concept('dropdown','basic_frame')
    +:set_title('Basic Frame')
    +:define_draw(function(properties,parent,element)
    +    element.add{
    +        type = 'label',
    +        caption = 'Hello, World!'
    +    }
    +end)
    @@ -3734,7 +3796,7 @@ Gui.get_concept('CustomButton') generated by LDoc diff --git a/docs/core/Permissions-Groups.html b/docs/core/Permissions-Groups.html index 321c7219..352e04a9 100644 --- a/docs/core/Permissions-Groups.html +++ b/docs/core/Permissions-Groups.html @@ -1432,7 +1432,7 @@ generated by LDoc diff --git a/docs/core/Roles.html b/docs/core/Roles.html index f051b7ee..24b1abfe 100644 --- a/docs/core/Roles.html +++ b/docs/core/Roles.html @@ -3152,7 +3152,7 @@ generated by LDoc diff --git a/docs/core/Store.html b/docs/core/Store.html index 64239e4a..54d14e4c 100644 --- a/docs/core/Store.html +++ b/docs/core/Store.html @@ -1145,7 +1145,7 @@ Store.register(team_scores,function(value,key) generated by LDoc diff --git a/docs/core/Sudo.html b/docs/core/Sudo.html index 36408431..0db70797 100644 --- a/docs/core/Sudo.html +++ b/docs/core/Sudo.html @@ -544,7 +544,7 @@ generated by LDoc diff --git a/docs/guis/Player-List.html b/docs/guis/Player-List.html index 4b079ad5..11b66c26 100644 --- a/docs/guis/Player-List.html +++ b/docs/guis/Player-List.html @@ -626,7 +626,7 @@ generated by LDoc diff --git a/docs/guis/Rocket-Info.html b/docs/guis/Rocket-Info.html index a18b977b..04d9371f 100644 --- a/docs/guis/Rocket-Info.html +++ b/docs/guis/Rocket-Info.html @@ -629,7 +629,7 @@ generated by LDoc diff --git a/docs/guis/Science-Info.html b/docs/guis/Science-Info.html index 096a9a61..e91df5cc 100644 --- a/docs/guis/Science-Info.html +++ b/docs/guis/Science-Info.html @@ -449,7 +449,7 @@ generated by LDoc diff --git a/docs/guis/Task-List.html b/docs/guis/Task-List.html index adee14e8..92239b49 100644 --- a/docs/guis/Task-List.html +++ b/docs/guis/Task-List.html @@ -632,7 +632,7 @@ generated by LDoc diff --git a/docs/guis/Warps-List.html b/docs/guis/Warps-List.html index 9908cbc0..93c944d7 100644 --- a/docs/guis/Warps-List.html +++ b/docs/guis/Warps-List.html @@ -837,7 +837,7 @@ generated by LDoc diff --git a/docs/index.html b/docs/index.html index bd77e448..d100c277 100644 --- a/docs/index.html +++ b/docs/index.html @@ -510,7 +510,7 @@ see ./expcore/commands.lua for more details generated by LDoc diff --git a/docs/modules/control.html b/docs/modules/control.html index c3f18211..e8471167 100644 --- a/docs/modules/control.html +++ b/docs/modules/control.html @@ -351,7 +351,7 @@ generated by LDoc diff --git a/docs/modules/utils.alien_evolution_progress.html b/docs/modules/utils.alien_evolution_progress.html index 46a4497e..7d715e83 100644 --- a/docs/modules/utils.alien_evolution_progress.html +++ b/docs/modules/utils.alien_evolution_progress.html @@ -419,7 +419,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 e7420999..b2ee81b5 100644 --- a/docs/modules/utils.core.html +++ b/docs/modules/utils.core.html @@ -1164,7 +1164,7 @@ generated by LDoc diff --git a/docs/modules/utils.debug.html b/docs/modules/utils.debug.html index 0f4c0a43..27a4a673 100644 --- a/docs/modules/utils.debug.html +++ b/docs/modules/utils.debug.html @@ -654,7 +654,7 @@ generated by LDoc diff --git a/docs/modules/utils.dump_env.html b/docs/modules/utils.dump_env.html index 2c13b76c..9e53d53d 100644 --- a/docs/modules/utils.dump_env.html +++ b/docs/modules/utils.dump_env.html @@ -323,7 +323,7 @@ generated by LDoc diff --git a/docs/modules/utils.event.html b/docs/modules/utils.event.html index 6a9981fa..75e4d32d 100644 --- a/docs/modules/utils.event.html +++ b/docs/modules/utils.event.html @@ -1292,7 +1292,7 @@ generated by LDoc diff --git a/docs/modules/utils.event_core.html b/docs/modules/utils.event_core.html index d52e1d2c..58d5a991 100644 --- a/docs/modules/utils.event_core.html +++ b/docs/modules/utils.event_core.html @@ -434,7 +434,7 @@ generated by LDoc diff --git a/docs/modules/utils.math.html b/docs/modules/utils.math.html index 46f3910a..5a3a0ade 100644 --- a/docs/modules/utils.math.html +++ b/docs/modules/utils.math.html @@ -338,7 +338,7 @@ generated by LDoc diff --git a/docs/modules/utils.recipe_locker.html b/docs/modules/utils.recipe_locker.html index 29e7512b..ff689105 100644 --- a/docs/modules/utils.recipe_locker.html +++ b/docs/modules/utils.recipe_locker.html @@ -441,7 +441,7 @@ generated by LDoc diff --git a/docs/modules/utils.state_machine.html b/docs/modules/utils.state_machine.html index fe3678b5..eaa58bd4 100644 --- a/docs/modules/utils.state_machine.html +++ b/docs/modules/utils.state_machine.html @@ -752,7 +752,7 @@ generated by LDoc diff --git a/docs/modules/utils.table.html b/docs/modules/utils.table.html index d48d0e5a..7fe9c053 100644 --- a/docs/modules/utils.table.html +++ b/docs/modules/utils.table.html @@ -1382,7 +1382,7 @@ generated by LDoc diff --git a/docs/modules/utils.task.html b/docs/modules/utils.task.html index 1a27b68d..56d53890 100644 --- a/docs/modules/utils.task.html +++ b/docs/modules/utils.task.html @@ -651,7 +651,7 @@ generated by LDoc diff --git a/docs/modules/utils.timestamp.html b/docs/modules/utils.timestamp.html index ee47361f..04820ce8 100644 --- a/docs/modules/utils.timestamp.html +++ b/docs/modules/utils.timestamp.html @@ -442,7 +442,7 @@ generated by LDoc diff --git a/docs/topics/license.html b/docs/topics/license.html index 1d25c8c5..de3e1c46 100644 --- a/docs/topics/license.html +++ b/docs/topics/license.html @@ -789,7 +789,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 f68e0370..62cf868e 100644 --- a/docs/topics/readme.md.html +++ b/docs/topics/readme.md.html @@ -332,7 +332,7 @@ generated by LDoc diff --git a/expcore/gui/concepts/button.lua b/expcore/gui/concepts/button.lua index cecc257c..ce79e6a6 100644 --- a/expcore/gui/concepts/button.lua +++ b/expcore/gui/concepts/button.lua @@ -13,6 +13,22 @@ local Gui = require 'expcore.gui.core' @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') +: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') +: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') :new_event('on_click',defines.events.on_gui_click) diff --git a/expcore/gui/concepts/checkbox.lua b/expcore/gui/concepts/checkbox.lua index 050887ab..a9f43a1f 100644 --- a/expcore/gui/concepts/checkbox.lua +++ b/expcore/gui/concepts/checkbox.lua @@ -11,6 +11,14 @@ local Gui = require 'expcore.gui.core' @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 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') +:set_caption('Basic Checkbox') +:set_tooltip('Basic checkbox') +:on_state_change(function(event) + event.player.print('Basic checkbox is now: '..tostring(event.element.state)) +end) ]] Gui.new_concept('checkbox') :new_event('on_state_change',defines.events.on_gui_checked_state_changed) diff --git a/expcore/gui/concepts/dropdown.lua b/expcore/gui/concepts/dropdown.lua index 39064587..9fe0f59d 100644 --- a/expcore/gui/concepts/dropdown.lua +++ b/expcore/gui/concepts/dropdown.lua @@ -13,6 +13,30 @@ local array_insert = ext_require('expcore.common','array_insert') @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 +local static_dropdown = +Gui.clone_concept('dropdown','static_dropdown') +:set_static_items{'Option 1','Option 2','Option 3'} +:on_selection_change(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') +:set_dynamic_items(function(element) + local items = {} + + for _,player in pairs(game.connected_players) do + items[#items+1] = player.name + end + + return items +end) +:on_selection_change(function(event) + local value = Gui.get_dropdown_value(event.element) + event.player.print('Dynamic dropdown is now: '..value) +end) ]] Gui.new_concept('dropdown') :new_event('on_selection_change',defines.events.on_gui_selection_state_changed) diff --git a/expcore/gui/concepts/frame.lua b/expcore/gui/concepts/frame.lua index 87c649ac..746aae50 100644 --- a/expcore/gui/concepts/frame.lua +++ b/expcore/gui/concepts/frame.lua @@ -8,6 +8,16 @@ local Gui = require 'expcore.gui.core' --[[-- The basic frame element @element frame @tparam ?string|Concepts.LocalisedString title the title that will show in the frame +@usage-- Making a basic frame, contains a label with hello world +local basic_frame = +Gui.clone_concept('dropdown','basic_frame') +:set_title('Basic Frame') +:define_draw(function(properties,parent,element) + element.add{ + type = 'label', + caption = 'Hello, World!' + } +end) ]] Gui.new_concept('frame') :new_property('title') From b385cd64a59d2279d9cbb040ef6f119ba8549641 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sat, 31 Aug 2019 15:14:23 +0100 Subject: [PATCH 11/26] Added elem buttons --- docs/addons/Advanced-Start.html | 2 +- docs/addons/Chat-Popups.html | 2 +- docs/addons/Chat-Reply.html | 2 +- docs/addons/Compilatron.html | 2 +- docs/addons/Damage-Popups.html | 2 +- docs/addons/Death-Logger.html | 2 +- docs/addons/Discord-Alerts.html | 2 +- docs/addons/Player-Colours.html | 2 +- docs/addons/Pollution-Grading.html | 2 +- docs/addons/Scorched-Earth.html | 2 +- docs/addons/Spawn-Area.html | 2 +- docs/commands/Admin-Chat.html | 2 +- docs/commands/Bonus.html | 2 +- docs/commands/Cheat-Mode.html | 2 +- docs/commands/Clear-Inventory.html | 2 +- docs/commands/Debug.html | 2 +- docs/commands/Find.html | 2 +- docs/commands/Help.html | 2 +- docs/commands/Home.html | 2 +- docs/commands/Interface.html | 2 +- docs/commands/Jail.html | 2 +- docs/commands/Kill.html | 2 +- docs/commands/Me.html | 2 +- docs/commands/Rainbow.html | 2 +- docs/commands/Repair.html | 2 +- docs/commands/Reports.html | 2 +- docs/commands/Roles.html | 2 +- docs/commands/Spawn.html | 2 +- docs/commands/Tag.html | 2 +- docs/commands/Teleport.html | 2 +- docs/commands/Warnings.html | 2 +- docs/configs/Advanced-Start.html | 2 +- docs/configs/Bonuses.html | 2 +- docs/configs/Chat-Reply.html | 2 +- docs/configs/Commands-Auth-Admin.html | 2 +- docs/configs/Commands-Auth-Roles.html | 2 +- .../Commands-Auth-Runtime-Disable.html | 2 +- docs/configs/Commands-Parse-Roles.html | 2 +- docs/configs/Commands-Parse.html | 2 +- docs/configs/Compilatron.html | 2 +- docs/configs/Death-Logger.html | 2 +- docs/configs/Discord-Alerts.html | 2 +- docs/configs/File-Loader.html | 2 +- docs/configs/Permission-Groups.html | 2 +- docs/configs/Player-List.html | 2 +- docs/configs/Pollution-Grading.html | 2 +- docs/configs/Popup-Messages.html | 2 +- docs/configs/Preset-Player-Colours.html | 2 +- docs/configs/Repair.html | 2 +- docs/configs/Rockets.html | 2 +- docs/configs/Roles.html | 2 +- docs/configs/Science.html | 2 +- docs/configs/Scorched-Earth.html | 2 +- docs/configs/Spawn-Area.html | 2 +- docs/configs/Tasks.html | 2 +- docs/configs/Warnings.html | 2 +- docs/configs/Warps.html | 2 +- docs/control/Jail.html | 2 +- docs/control/Production.html | 2 +- docs/control/Reports.html | 2 +- docs/control/Rockets.html | 2 +- docs/control/Tasks.html | 2 +- docs/control/Warnings.html | 2 +- docs/control/Warps.html | 2 +- docs/core/Commands.html | 2 +- docs/core/Common-Library.html | 2 +- docs/core/Gui.html | 104 ++++++++++++++++-- docs/core/Permissions-Groups.html | 2 +- docs/core/Roles.html | 2 +- docs/core/Store.html | 2 +- docs/core/Sudo.html | 2 +- docs/guis/Player-List.html | 2 +- docs/guis/Rocket-Info.html | 2 +- docs/guis/Science-Info.html | 2 +- docs/guis/Task-List.html | 2 +- docs/guis/Warps-List.html | 2 +- docs/index.html | 2 +- docs/modules/control.html | 2 +- .../utils.alien_evolution_progress.html | 2 +- docs/modules/utils.core.html | 2 +- docs/modules/utils.debug.html | 2 +- docs/modules/utils.dump_env.html | 2 +- docs/modules/utils.event.html | 2 +- docs/modules/utils.event_core.html | 2 +- docs/modules/utils.math.html | 2 +- docs/modules/utils.recipe_locker.html | 2 +- docs/modules/utils.state_machine.html | 2 +- docs/modules/utils.table.html | 2 +- docs/modules/utils.task.html | 2 +- docs/modules/utils.timestamp.html | 2 +- docs/topics/license.html | 2 +- docs/topics/readme.md.html | 2 +- expcore/gui.lua | 1 + expcore/gui/concepts/dropdown.lua | 8 +- expcore/gui/concepts/elem_button.lua | 49 +++++++++ expcore/gui/test.lua | 75 +++++++++++++ 96 files changed, 316 insertions(+), 103 deletions(-) create mode 100644 expcore/gui/concepts/elem_button.lua diff --git a/docs/addons/Advanced-Start.html b/docs/addons/Advanced-Start.html index 3d4c3734..bd36c9e1 100644 --- a/docs/addons/Advanced-Start.html +++ b/docs/addons/Advanced-Start.html @@ -348,7 +348,7 @@ generated by LDoc diff --git a/docs/addons/Chat-Popups.html b/docs/addons/Chat-Popups.html index 9cd4a94f..479610b9 100644 --- a/docs/addons/Chat-Popups.html +++ b/docs/addons/Chat-Popups.html @@ -349,7 +349,7 @@ generated by LDoc diff --git a/docs/addons/Chat-Reply.html b/docs/addons/Chat-Reply.html index ebbfd73f..76c57702 100644 --- a/docs/addons/Chat-Reply.html +++ b/docs/addons/Chat-Reply.html @@ -376,7 +376,7 @@ generated by LDoc diff --git a/docs/addons/Compilatron.html b/docs/addons/Compilatron.html index 67b29137..a2c3181a 100644 --- a/docs/addons/Compilatron.html +++ b/docs/addons/Compilatron.html @@ -585,7 +585,7 @@ generated by LDoc diff --git a/docs/addons/Damage-Popups.html b/docs/addons/Damage-Popups.html index 81e0c2e7..e0f4ca89 100644 --- a/docs/addons/Damage-Popups.html +++ b/docs/addons/Damage-Popups.html @@ -349,7 +349,7 @@ generated by LDoc diff --git a/docs/addons/Death-Logger.html b/docs/addons/Death-Logger.html index c6cd6ad5..f20331ff 100644 --- a/docs/addons/Death-Logger.html +++ b/docs/addons/Death-Logger.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/addons/Discord-Alerts.html b/docs/addons/Discord-Alerts.html index 3faee111..bde7543f 100644 --- a/docs/addons/Discord-Alerts.html +++ b/docs/addons/Discord-Alerts.html @@ -460,7 +460,7 @@ generated by LDoc diff --git a/docs/addons/Player-Colours.html b/docs/addons/Player-Colours.html index b9e1c3ab..a30f16fb 100644 --- a/docs/addons/Player-Colours.html +++ b/docs/addons/Player-Colours.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/addons/Pollution-Grading.html b/docs/addons/Pollution-Grading.html index 47bcd776..a97f5329 100644 --- a/docs/addons/Pollution-Grading.html +++ b/docs/addons/Pollution-Grading.html @@ -320,7 +320,7 @@ generated by LDoc diff --git a/docs/addons/Scorched-Earth.html b/docs/addons/Scorched-Earth.html index 76b4b241..043de6a1 100644 --- a/docs/addons/Scorched-Earth.html +++ b/docs/addons/Scorched-Earth.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/addons/Spawn-Area.html b/docs/addons/Spawn-Area.html index b1e70e46..9bdb2207 100644 --- a/docs/addons/Spawn-Area.html +++ b/docs/addons/Spawn-Area.html @@ -376,7 +376,7 @@ generated by LDoc diff --git a/docs/commands/Admin-Chat.html b/docs/commands/Admin-Chat.html index 5b548d8e..290d196a 100644 --- a/docs/commands/Admin-Chat.html +++ b/docs/commands/Admin-Chat.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Bonus.html b/docs/commands/Bonus.html index 989cd718..64f67823 100644 --- a/docs/commands/Bonus.html +++ b/docs/commands/Bonus.html @@ -500,7 +500,7 @@ generated by LDoc diff --git a/docs/commands/Cheat-Mode.html b/docs/commands/Cheat-Mode.html index d5b4d67d..2e5d4d77 100644 --- a/docs/commands/Cheat-Mode.html +++ b/docs/commands/Cheat-Mode.html @@ -361,7 +361,7 @@ generated by LDoc diff --git a/docs/commands/Clear-Inventory.html b/docs/commands/Clear-Inventory.html index c5bbd056..aa7e882e 100644 --- a/docs/commands/Clear-Inventory.html +++ b/docs/commands/Clear-Inventory.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Debug.html b/docs/commands/Debug.html index fa9b156c..8957b0bc 100644 --- a/docs/commands/Debug.html +++ b/docs/commands/Debug.html @@ -365,7 +365,7 @@ generated by LDoc diff --git a/docs/commands/Find.html b/docs/commands/Find.html index b2f3c1b6..47e49267 100644 --- a/docs/commands/Find.html +++ b/docs/commands/Find.html @@ -360,7 +360,7 @@ generated by LDoc diff --git a/docs/commands/Help.html b/docs/commands/Help.html index 6e926e3a..ed4208d0 100644 --- a/docs/commands/Help.html +++ b/docs/commands/Help.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/commands/Home.html b/docs/commands/Home.html index 94912d71..e08e5ea5 100644 --- a/docs/commands/Home.html +++ b/docs/commands/Home.html @@ -458,7 +458,7 @@ generated by LDoc diff --git a/docs/commands/Interface.html b/docs/commands/Interface.html index 664677d5..f5c672f5 100644 --- a/docs/commands/Interface.html +++ b/docs/commands/Interface.html @@ -416,7 +416,7 @@ generated by LDoc diff --git a/docs/commands/Jail.html b/docs/commands/Jail.html index 2d9bf3d2..2b88c16f 100644 --- a/docs/commands/Jail.html +++ b/docs/commands/Jail.html @@ -611,7 +611,7 @@ generated by LDoc diff --git a/docs/commands/Kill.html b/docs/commands/Kill.html index 0593ed7b..5ade1288 100644 --- a/docs/commands/Kill.html +++ b/docs/commands/Kill.html @@ -389,7 +389,7 @@ generated by LDoc diff --git a/docs/commands/Me.html b/docs/commands/Me.html index 4cb2155b..a396bdd9 100644 --- a/docs/commands/Me.html +++ b/docs/commands/Me.html @@ -360,7 +360,7 @@ generated by LDoc diff --git a/docs/commands/Rainbow.html b/docs/commands/Rainbow.html index 1c98f116..78b3a6ab 100644 --- a/docs/commands/Rainbow.html +++ b/docs/commands/Rainbow.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Repair.html b/docs/commands/Repair.html index 3c64fe5c..ae84d625 100644 --- a/docs/commands/Repair.html +++ b/docs/commands/Repair.html @@ -321,7 +321,7 @@ generated by LDoc diff --git a/docs/commands/Reports.html b/docs/commands/Reports.html index c99884e7..b161ceac 100644 --- a/docs/commands/Reports.html +++ b/docs/commands/Reports.html @@ -585,7 +585,7 @@ generated by LDoc diff --git a/docs/commands/Roles.html b/docs/commands/Roles.html index 6fcce0c6..255aa570 100644 --- a/docs/commands/Roles.html +++ b/docs/commands/Roles.html @@ -557,7 +557,7 @@ generated by LDoc diff --git a/docs/commands/Spawn.html b/docs/commands/Spawn.html index 57ccc41a..a368c0b5 100644 --- a/docs/commands/Spawn.html +++ b/docs/commands/Spawn.html @@ -389,7 +389,7 @@ generated by LDoc diff --git a/docs/commands/Tag.html b/docs/commands/Tag.html index b84c0861..165ffd2a 100644 --- a/docs/commands/Tag.html +++ b/docs/commands/Tag.html @@ -443,7 +443,7 @@ generated by LDoc diff --git a/docs/commands/Teleport.html b/docs/commands/Teleport.html index 3a5a47eb..61c9bce6 100644 --- a/docs/commands/Teleport.html +++ b/docs/commands/Teleport.html @@ -484,7 +484,7 @@ generated by LDoc diff --git a/docs/commands/Warnings.html b/docs/commands/Warnings.html index 7ca3110c..db4a29aa 100644 --- a/docs/commands/Warnings.html +++ b/docs/commands/Warnings.html @@ -569,7 +569,7 @@ generated by LDoc diff --git a/docs/configs/Advanced-Start.html b/docs/configs/Advanced-Start.html index 37bffff8..b9c394c4 100644 --- a/docs/configs/Advanced-Start.html +++ b/docs/configs/Advanced-Start.html @@ -506,7 +506,7 @@ generated by LDoc diff --git a/docs/configs/Bonuses.html b/docs/configs/Bonuses.html index ee42480a..66a28a9f 100644 --- a/docs/configs/Bonuses.html +++ b/docs/configs/Bonuses.html @@ -237,7 +237,7 @@ generated by LDoc diff --git a/docs/configs/Chat-Reply.html b/docs/configs/Chat-Reply.html index 9028f366..25085c59 100644 --- a/docs/configs/Chat-Reply.html +++ b/docs/configs/Chat-Reply.html @@ -485,7 +485,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Admin.html b/docs/configs/Commands-Auth-Admin.html index 963ddbe0..84bb6c48 100644 --- a/docs/configs/Commands-Auth-Admin.html +++ b/docs/configs/Commands-Auth-Admin.html @@ -294,7 +294,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Roles.html b/docs/configs/Commands-Auth-Roles.html index e38df53c..e50c4466 100644 --- a/docs/configs/Commands-Auth-Roles.html +++ b/docs/configs/Commands-Auth-Roles.html @@ -320,7 +320,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Runtime-Disable.html b/docs/configs/Commands-Auth-Runtime-Disable.html index 0ed24222..147b5499 100644 --- a/docs/configs/Commands-Auth-Runtime-Disable.html +++ b/docs/configs/Commands-Auth-Runtime-Disable.html @@ -442,7 +442,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Parse-Roles.html b/docs/configs/Commands-Parse-Roles.html index e39ebf73..379dd604 100644 --- a/docs/configs/Commands-Parse-Roles.html +++ b/docs/configs/Commands-Parse-Roles.html @@ -354,7 +354,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Parse.html b/docs/configs/Commands-Parse.html index 1011011c..12051041 100644 --- a/docs/configs/Commands-Parse.html +++ b/docs/configs/Commands-Parse.html @@ -338,7 +338,7 @@ see ./expcore/commands.lua for more details

    generated by LDoc diff --git a/docs/configs/Compilatron.html b/docs/configs/Compilatron.html index 9f8ce2fa..17533a11 100644 --- a/docs/configs/Compilatron.html +++ b/docs/configs/Compilatron.html @@ -354,7 +354,7 @@ generated by LDoc diff --git a/docs/configs/Death-Logger.html b/docs/configs/Death-Logger.html index a449f6d1..a77eddd3 100644 --- a/docs/configs/Death-Logger.html +++ b/docs/configs/Death-Logger.html @@ -416,7 +416,7 @@ generated by LDoc diff --git a/docs/configs/Discord-Alerts.html b/docs/configs/Discord-Alerts.html index 91e5d9e8..1b262704 100644 --- a/docs/configs/Discord-Alerts.html +++ b/docs/configs/Discord-Alerts.html @@ -237,7 +237,7 @@ generated by LDoc diff --git a/docs/configs/File-Loader.html b/docs/configs/File-Loader.html index de492fac..56af4b90 100644 --- a/docs/configs/File-Loader.html +++ b/docs/configs/File-Loader.html @@ -240,7 +240,7 @@ generated by LDoc diff --git a/docs/configs/Permission-Groups.html b/docs/configs/Permission-Groups.html index 1218f72a..7a1cde25 100644 --- a/docs/configs/Permission-Groups.html +++ b/docs/configs/Permission-Groups.html @@ -295,7 +295,7 @@ generated by LDoc diff --git a/docs/configs/Player-List.html b/docs/configs/Player-List.html index b26e51d7..62676d41 100644 --- a/docs/configs/Player-List.html +++ b/docs/configs/Player-List.html @@ -812,7 +812,7 @@ generated by LDoc diff --git a/docs/configs/Pollution-Grading.html b/docs/configs/Pollution-Grading.html index eb69b09a..857acf8e 100644 --- a/docs/configs/Pollution-Grading.html +++ b/docs/configs/Pollution-Grading.html @@ -384,7 +384,7 @@ generated by LDoc diff --git a/docs/configs/Popup-Messages.html b/docs/configs/Popup-Messages.html index 3f2d93b2..806575da 100644 --- a/docs/configs/Popup-Messages.html +++ b/docs/configs/Popup-Messages.html @@ -414,7 +414,7 @@ generated by LDoc diff --git a/docs/configs/Preset-Player-Colours.html b/docs/configs/Preset-Player-Colours.html index 3ea83a45..81761726 100644 --- a/docs/configs/Preset-Player-Colours.html +++ b/docs/configs/Preset-Player-Colours.html @@ -324,7 +324,7 @@ generated by LDoc diff --git a/docs/configs/Repair.html b/docs/configs/Repair.html index f0def66d..918196b3 100644 --- a/docs/configs/Repair.html +++ b/docs/configs/Repair.html @@ -414,7 +414,7 @@ generated by LDoc diff --git a/docs/configs/Rockets.html b/docs/configs/Rockets.html index 16cca0e3..360875bd 100644 --- a/docs/configs/Rockets.html +++ b/docs/configs/Rockets.html @@ -834,7 +834,7 @@ generated by LDoc diff --git a/docs/configs/Roles.html b/docs/configs/Roles.html index 34a42438..16206a78 100644 --- a/docs/configs/Roles.html +++ b/docs/configs/Roles.html @@ -292,7 +292,7 @@ generated by LDoc diff --git a/docs/configs/Science.html b/docs/configs/Science.html index 8cadcfc0..140a3c6c 100644 --- a/docs/configs/Science.html +++ b/docs/configs/Science.html @@ -354,7 +354,7 @@ generated by LDoc diff --git a/docs/configs/Scorched-Earth.html b/docs/configs/Scorched-Earth.html index 703ee5b6..e07eac6f 100644 --- a/docs/configs/Scorched-Earth.html +++ b/docs/configs/Scorched-Earth.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/configs/Spawn-Area.html b/docs/configs/Spawn-Area.html index 30ec85a5..ba44a6bf 100644 --- a/docs/configs/Spawn-Area.html +++ b/docs/configs/Spawn-Area.html @@ -744,7 +744,7 @@ generated by LDoc diff --git a/docs/configs/Tasks.html b/docs/configs/Tasks.html index d318130f..8eb4fc0a 100644 --- a/docs/configs/Tasks.html +++ b/docs/configs/Tasks.html @@ -384,7 +384,7 @@ generated by LDoc diff --git a/docs/configs/Warnings.html b/docs/configs/Warnings.html index 68d59a5a..9e4a11b2 100644 --- a/docs/configs/Warnings.html +++ b/docs/configs/Warnings.html @@ -355,7 +355,7 @@ generated by LDoc diff --git a/docs/configs/Warps.html b/docs/configs/Warps.html index e86fbb96..ca467866 100644 --- a/docs/configs/Warps.html +++ b/docs/configs/Warps.html @@ -684,7 +684,7 @@ generated by LDoc diff --git a/docs/control/Jail.html b/docs/control/Jail.html index 9bcebaa0..067ebc0d 100644 --- a/docs/control/Jail.html +++ b/docs/control/Jail.html @@ -1208,7 +1208,7 @@ generated by LDoc diff --git a/docs/control/Production.html b/docs/control/Production.html index 3cbacd64..9545db59 100644 --- a/docs/control/Production.html +++ b/docs/control/Production.html @@ -1329,7 +1329,7 @@ generated by LDoc diff --git a/docs/control/Reports.html b/docs/control/Reports.html index ecd87fb0..0b8e6efc 100644 --- a/docs/control/Reports.html +++ b/docs/control/Reports.html @@ -1110,7 +1110,7 @@ generated by LDoc diff --git a/docs/control/Rockets.html b/docs/control/Rockets.html index 89000802..4b3c9f31 100644 --- a/docs/control/Rockets.html +++ b/docs/control/Rockets.html @@ -984,7 +984,7 @@ generated by LDoc diff --git a/docs/control/Tasks.html b/docs/control/Tasks.html index 75165013..d484ec72 100644 --- a/docs/control/Tasks.html +++ b/docs/control/Tasks.html @@ -1039,7 +1039,7 @@ generated by LDoc diff --git a/docs/control/Warnings.html b/docs/control/Warnings.html index e7e3d72d..bb21eb87 100644 --- a/docs/control/Warnings.html +++ b/docs/control/Warnings.html @@ -1465,7 +1465,7 @@ generated by LDoc diff --git a/docs/control/Warps.html b/docs/control/Warps.html index 4505c21e..3d7f786d 100644 --- a/docs/control/Warps.html +++ b/docs/control/Warps.html @@ -1413,7 +1413,7 @@ generated by LDoc diff --git a/docs/core/Commands.html b/docs/core/Commands.html index fc6c5e2d..7bfe081a 100644 --- a/docs/core/Commands.html +++ b/docs/core/Commands.html @@ -1972,7 +1972,7 @@ generated by LDoc diff --git a/docs/core/Common-Library.html b/docs/core/Common-Library.html index 448be51d..bff67067 100644 --- a/docs/core/Common-Library.html +++ b/docs/core/Common-Library.html @@ -2680,7 +2680,7 @@ Common.table_insert(tbl,50,tbl2) generated by LDoc diff --git a/docs/core/Gui.html b/docs/core/Gui.html index 9d24b6c7..66b0e63d 100644 --- a/docs/core/Gui.html +++ b/docs/core/Gui.html @@ -331,6 +331,10 @@ button:clone('CustomButton')
    + + + + @@ -864,9 +868,9 @@ Gui.clone_concept('checkbox','b : - (string or Conepts.LocalisedString) + (string, LocalisedString or function) - the option which is selected by default + the option which is selected by default, or a function which returns the default @@ -945,11 +949,9 @@ Gui.clone_concept('dropdown','s Gui.clone_concept('dropdown','dynamic_dropdown') :set_dynamic_items(function(element) local items = {} - for _,player in pairs(game.connected_players) do items[#items+1] = player.name end - return items end) :on_selection_change(function(event) @@ -958,6 +960,94 @@ Gui.clone_concept('dropdown','d end) + +
    +
    +
    + # + elem_button +
    +
    +
    +
    + +

    The basic dropdown element

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + on_selection_change + + : + + + fired when the selected value is changed + +
    • + + + + + +
    • + + default_selection + + : + + (string, SignalID or function) + + the option which is selected by default, or a function which returns the default + +
    • + + + + + +
    • + + elem_type + + : + + (string) + + the type of elem selection that this is, default is item selection + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Making a basic elem button
    +local basic_elem_button =
    +Gui.clone_concept('elem_button',TEST 'basic_elembutton')
    +:on_selection_change(function(event)
    +    event.player.print('Basic elem button is now: '..event.element.elem_value)
    +end)
    + +
    @@ -1067,7 +1157,7 @@ Gui.clone_concept('dropdown','b : - (string or Conepts.LocalisedString) + (string or LocalisedString) the value that you want selected @@ -1142,7 +1232,7 @@ Gui.clone_concept('dropdown','b Returns: @@ -3796,7 +3886,7 @@ Gui.get_concept('CustomButton') generated by LDoc diff --git a/docs/core/Permissions-Groups.html b/docs/core/Permissions-Groups.html index 352e04a9..effd0630 100644 --- a/docs/core/Permissions-Groups.html +++ b/docs/core/Permissions-Groups.html @@ -1432,7 +1432,7 @@ generated by LDoc diff --git a/docs/core/Roles.html b/docs/core/Roles.html index 24b1abfe..5827dcf1 100644 --- a/docs/core/Roles.html +++ b/docs/core/Roles.html @@ -3152,7 +3152,7 @@ generated by LDoc diff --git a/docs/core/Store.html b/docs/core/Store.html index 54d14e4c..42eb1aed 100644 --- a/docs/core/Store.html +++ b/docs/core/Store.html @@ -1145,7 +1145,7 @@ Store.register(team_scores,function(value,key) generated by LDoc diff --git a/docs/core/Sudo.html b/docs/core/Sudo.html index 0db70797..53ff468c 100644 --- a/docs/core/Sudo.html +++ b/docs/core/Sudo.html @@ -544,7 +544,7 @@ generated by LDoc diff --git a/docs/guis/Player-List.html b/docs/guis/Player-List.html index 11b66c26..54e5156c 100644 --- a/docs/guis/Player-List.html +++ b/docs/guis/Player-List.html @@ -626,7 +626,7 @@ generated by LDoc diff --git a/docs/guis/Rocket-Info.html b/docs/guis/Rocket-Info.html index 04d9371f..4d20398c 100644 --- a/docs/guis/Rocket-Info.html +++ b/docs/guis/Rocket-Info.html @@ -629,7 +629,7 @@ generated by LDoc diff --git a/docs/guis/Science-Info.html b/docs/guis/Science-Info.html index e91df5cc..f2e103f9 100644 --- a/docs/guis/Science-Info.html +++ b/docs/guis/Science-Info.html @@ -449,7 +449,7 @@ generated by LDoc diff --git a/docs/guis/Task-List.html b/docs/guis/Task-List.html index 92239b49..172a8c6d 100644 --- a/docs/guis/Task-List.html +++ b/docs/guis/Task-List.html @@ -632,7 +632,7 @@ generated by LDoc diff --git a/docs/guis/Warps-List.html b/docs/guis/Warps-List.html index 93c944d7..b97332f0 100644 --- a/docs/guis/Warps-List.html +++ b/docs/guis/Warps-List.html @@ -837,7 +837,7 @@ generated by LDoc diff --git a/docs/index.html b/docs/index.html index d100c277..acabe123 100644 --- a/docs/index.html +++ b/docs/index.html @@ -510,7 +510,7 @@ see ./expcore/commands.lua for more details generated by LDoc diff --git a/docs/modules/control.html b/docs/modules/control.html index e8471167..5aff8205 100644 --- a/docs/modules/control.html +++ b/docs/modules/control.html @@ -351,7 +351,7 @@ generated by LDoc diff --git a/docs/modules/utils.alien_evolution_progress.html b/docs/modules/utils.alien_evolution_progress.html index 7d715e83..4dd24a85 100644 --- a/docs/modules/utils.alien_evolution_progress.html +++ b/docs/modules/utils.alien_evolution_progress.html @@ -419,7 +419,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 b2ee81b5..de6f9d77 100644 --- a/docs/modules/utils.core.html +++ b/docs/modules/utils.core.html @@ -1164,7 +1164,7 @@ generated by LDoc diff --git a/docs/modules/utils.debug.html b/docs/modules/utils.debug.html index 27a4a673..6ff655be 100644 --- a/docs/modules/utils.debug.html +++ b/docs/modules/utils.debug.html @@ -654,7 +654,7 @@ generated by LDoc diff --git a/docs/modules/utils.dump_env.html b/docs/modules/utils.dump_env.html index 9e53d53d..ad4d89c4 100644 --- a/docs/modules/utils.dump_env.html +++ b/docs/modules/utils.dump_env.html @@ -323,7 +323,7 @@ generated by LDoc diff --git a/docs/modules/utils.event.html b/docs/modules/utils.event.html index 75e4d32d..97b00a74 100644 --- a/docs/modules/utils.event.html +++ b/docs/modules/utils.event.html @@ -1292,7 +1292,7 @@ generated by LDoc diff --git a/docs/modules/utils.event_core.html b/docs/modules/utils.event_core.html index 58d5a991..ab5335ee 100644 --- a/docs/modules/utils.event_core.html +++ b/docs/modules/utils.event_core.html @@ -434,7 +434,7 @@ generated by LDoc diff --git a/docs/modules/utils.math.html b/docs/modules/utils.math.html index 5a3a0ade..ed30683c 100644 --- a/docs/modules/utils.math.html +++ b/docs/modules/utils.math.html @@ -338,7 +338,7 @@ generated by LDoc diff --git a/docs/modules/utils.recipe_locker.html b/docs/modules/utils.recipe_locker.html index ff689105..a94f5916 100644 --- a/docs/modules/utils.recipe_locker.html +++ b/docs/modules/utils.recipe_locker.html @@ -441,7 +441,7 @@ generated by LDoc diff --git a/docs/modules/utils.state_machine.html b/docs/modules/utils.state_machine.html index eaa58bd4..2d3c8396 100644 --- a/docs/modules/utils.state_machine.html +++ b/docs/modules/utils.state_machine.html @@ -752,7 +752,7 @@ generated by LDoc diff --git a/docs/modules/utils.table.html b/docs/modules/utils.table.html index 7fe9c053..d548fc6f 100644 --- a/docs/modules/utils.table.html +++ b/docs/modules/utils.table.html @@ -1382,7 +1382,7 @@ generated by LDoc diff --git a/docs/modules/utils.task.html b/docs/modules/utils.task.html index 56d53890..b467f3f1 100644 --- a/docs/modules/utils.task.html +++ b/docs/modules/utils.task.html @@ -651,7 +651,7 @@ generated by LDoc diff --git a/docs/modules/utils.timestamp.html b/docs/modules/utils.timestamp.html index 04820ce8..77d371b1 100644 --- a/docs/modules/utils.timestamp.html +++ b/docs/modules/utils.timestamp.html @@ -442,7 +442,7 @@ generated by LDoc diff --git a/docs/topics/license.html b/docs/topics/license.html index de3e1c46..e260d7f0 100644 --- a/docs/topics/license.html +++ b/docs/topics/license.html @@ -789,7 +789,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 62cf868e..4e38c52a 100644 --- a/docs/topics/readme.md.html +++ b/docs/topics/readme.md.html @@ -332,7 +332,7 @@ generated by LDoc diff --git a/expcore/gui.lua b/expcore/gui.lua index 4777854e..d066a2dc 100644 --- a/expcore/gui.lua +++ b/expcore/gui.lua @@ -71,5 +71,6 @@ Gui.require_concept('frame') Gui.require_concept('button') Gui.require_concept('checkbox') Gui.require_concept('dropdown') +Gui.require_concept('elem_button') return Gui \ No newline at end of file diff --git a/expcore/gui/concepts/dropdown.lua b/expcore/gui/concepts/dropdown.lua index 9fe0f59d..ee3f8346 100644 --- a/expcore/gui/concepts/dropdown.lua +++ b/expcore/gui/concepts/dropdown.lua @@ -9,7 +9,7 @@ local array_insert = ext_require('expcore.common','array_insert') --[[-- The basic dropdown element @element dropdown @param on_selection_change fired when the selected value is changed -@tparam ?string|Conepts.LocalisedString default_selection the option which is selected by default +@tparam ?string|Concepts.LocalisedString|function default_selection the option which is selected by default, or a function which returns the default @tparam boolean use_list_box when true a list box will be used rather than a dropdown menu @tparam ?nil|table static_items when called with a table the values will be added as items for the dropdown, if called with nil then all items are cleared @tparam function dynamic_items the given function will be called to return a list of items and optional start index to add items to the dropdown when it is first drawn @@ -26,11 +26,9 @@ local dynamic_dropdown = Gui.clone_concept('dropdown','dynamic_dropdown') :set_dynamic_items(function(element) local items = {} - for _,player in pairs(game.connected_players) do items[#items+1] = player.name end - return items end) :on_selection_change(function(event) @@ -107,7 +105,7 @@ end) --[[-- Selects the index of a dropdown with this value @tparam LuaGuiElement element the dropdown that you want to set the selection for -@tparam ?string|Conepts.LocalisedString value the value that you want selected +@tparam ?string|Concepts.LocalisedString value the value that you want selected @treturn boolean if an item with this value was found @usage-- Selecting the item with the value 'foo' Gui.set_dropdown_value(element,'foo') @@ -124,7 +122,7 @@ end --[[-- Gets the selected item value of a dropdown @tparam LuaGuiElement element the dropdown that you want the selected value of -@treturn ?string|Conepts.LocalisedString the value that is currently selected +@treturn ?string|Concepts.LocalisedString the value that is currently selected @usage-- Getting the selected value local selected_value = Gui.get_dropdown_value(element) ]] diff --git a/expcore/gui/concepts/elem_button.lua b/expcore/gui/concepts/elem_button.lua new file mode 100644 index 00000000..ec8b09ef --- /dev/null +++ b/expcore/gui/concepts/elem_button.lua @@ -0,0 +1,49 @@ +--[[-- Core Module - Gui + @module Gui + @alias Gui +]] + +local Gui = require 'expcore.gui.core' + +--[[-- The basic dropdown element +@element elem_button +@param on_selection_change fired when the selected value is changed +@tparam ?string|Concepts.SignalID|function default_selection the option which is selected by default, or a function which returns the default +@tparam string elem_type the type of elem selection that this is, default is item selection +@usage-- Making a basic elem button +local basic_elem_button = +Gui.clone_concept('elem_button',TEST 'basic_elembutton') +:on_selection_change(function(event) + event.player.print('Basic elem button is now: '..event.element.elem_value) +end) +]] +Gui.new_concept('elem_button') +:new_event('on_selection_change',defines.events.on_gui_elem_changed) +:new_property('default_selection') +:new_property('elem_type','item') +:define_draw(function(properties,parent,element,selection) + element = parent.add{ + name = properties.name, + type = 'choose-elem-button', + elem_type = properties.elem_type + } + + if properties.default_selection and not selection then + local default = properties.default_selection + if type(default) == 'function' then + default = default(element) + end + + element.elem_value = default + + elseif selection then + if type(selection) == 'function' then + selection = selection(element) + end + + element.elem_value = selection + + end + + return element +end) \ No newline at end of file diff --git a/expcore/gui/test.lua b/expcore/gui/test.lua index b1f0aa25..c853f709 100644 --- a/expcore/gui/test.lua +++ b/expcore/gui/test.lua @@ -278,4 +278,79 @@ tests.Dropdowns = { ['Dynamic Dropdown'] = dynamic_dropdown, ['Static Player Stored Dropdown'] = static_player_dropdown, ['Dynamic Player Stored Dropdown'] = dynamic_player_dropdown +} + +--[[ +Listboxs +> Static Listbox -- Simple Listbox with all options being static +> Static Player Stored Listbox -- Listbox where the values is synced for each player +]] + +local static_listbox = +Gui.clone_concept('dropdown',TEST 'static_listbox') +:set_use_list_box(true) +:set_static_items{'Option 1','Option 2','Option 3'} +:on_selection_change(function(event) + local value = Gui.get_dropdown_value(event.element) + event.player.print('Static listbox is now: '..value) +end) + +local static_player_listbox = +Gui.clone_concept('dropdown',TEST 'static_player_listbox') +:set_use_list_box(true) +:set_static_items{'Option 1','Option 2','Option 3'} +:on_selection_change(function(event) + local element = event.element + local value = Gui.get_dropdown_value(element) + event.concept.set_data(element,value) + event.player.print('Static player stored listbox is now: '..value) +end) +:define_combined_store(Gui.categorize_by_player,function(element,value) + Gui.set_dropdown_value(element,value) +end) + +tests.Listboxs = { + ['Static Listbox'] = static_listbox, + ['Static Player Stored Listbox'] = static_player_listbox +} + +--[[ +Elem Buttons +> Basic Elem Button -- Basic elem button +> Defaut Selection Elem Button -- Same as above but has a default selection +> Player Stored Elem Button -- Same as above but is stored per player +]] + +local basic_elem_button = +Gui.clone_concept('elem_button',TEST 'basic_elembutton') +:on_selection_change(function(event) + event.player.print('Basic elem button is now: '..event.element.elem_value) +end) + +local default_selection_elem_button = +Gui.clone_concept('elem_button',TEST 'default_selection_elem_button') +:set_elem_type('signal') +:set_default_selection{type='virtual',name='signal-info'} +:on_selection_change(function(event) + local value = event.element.elem_value + event.player.print('Default selection elem button is now: '..value.type..'/'..value.name) +end) + +local player_elem_button = +Gui.clone_concept('elem_button',TEST 'player_elem_button') +:set_elem_type('technology') +:on_selection_change(function(event) + local element = event.element + local value = element.elem_value + event.concept.set_data(element,value) + event.player.print('Player stored elem button is now: '..value) +end) +:define_combined_store(Gui.categorize_by_player,function(element,value) + element.elem_value = value +end) + +tests['Elem Buttons'] = { + ['Basic Elem Button'] = basic_elem_button, + ['Defaut Selection Elem Button'] = default_selection_elem_button, + ['Player Stored Elem Button'] = player_elem_button } \ No newline at end of file From 129610679e53f6b5626ae81b83382e5ccf1cff01 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sat, 31 Aug 2019 17:46:19 +0100 Subject: [PATCH 12/26] Added progress bar --- docs/addons/Advanced-Start.html | 2 +- docs/addons/Chat-Popups.html | 2 +- docs/addons/Chat-Reply.html | 2 +- docs/addons/Compilatron.html | 2 +- docs/addons/Damage-Popups.html | 2 +- docs/addons/Death-Logger.html | 2 +- docs/addons/Discord-Alerts.html | 2 +- docs/addons/Player-Colours.html | 2 +- docs/addons/Pollution-Grading.html | 2 +- docs/addons/Scorched-Earth.html | 2 +- docs/addons/Spawn-Area.html | 2 +- docs/commands/Admin-Chat.html | 2 +- docs/commands/Bonus.html | 2 +- docs/commands/Cheat-Mode.html | 2 +- docs/commands/Clear-Inventory.html | 2 +- docs/commands/Debug.html | 2 +- docs/commands/Find.html | 2 +- docs/commands/Help.html | 2 +- docs/commands/Home.html | 2 +- docs/commands/Interface.html | 2 +- docs/commands/Jail.html | 2 +- docs/commands/Kill.html | 2 +- docs/commands/Me.html | 2 +- docs/commands/Rainbow.html | 2 +- docs/commands/Repair.html | 2 +- docs/commands/Reports.html | 2 +- docs/commands/Roles.html | 2 +- docs/commands/Spawn.html | 2 +- docs/commands/Tag.html | 2 +- docs/commands/Teleport.html | 2 +- docs/commands/Warnings.html | 2 +- docs/configs/Advanced-Start.html | 2 +- docs/configs/Bonuses.html | 2 +- docs/configs/Chat-Reply.html | 2 +- docs/configs/Commands-Auth-Admin.html | 2 +- docs/configs/Commands-Auth-Roles.html | 2 +- .../Commands-Auth-Runtime-Disable.html | 2 +- docs/configs/Commands-Parse-Roles.html | 2 +- docs/configs/Commands-Parse.html | 2 +- docs/configs/Compilatron.html | 2 +- docs/configs/Death-Logger.html | 2 +- docs/configs/Discord-Alerts.html | 2 +- docs/configs/File-Loader.html | 2 +- docs/configs/Permission-Groups.html | 2 +- docs/configs/Player-List.html | 2 +- docs/configs/Pollution-Grading.html | 2 +- docs/configs/Popup-Messages.html | 2 +- docs/configs/Preset-Player-Colours.html | 2 +- docs/configs/Repair.html | 2 +- docs/configs/Rockets.html | 2 +- docs/configs/Roles.html | 2 +- docs/configs/Science.html | 2 +- docs/configs/Scorched-Earth.html | 2 +- docs/configs/Spawn-Area.html | 2 +- docs/configs/Tasks.html | 2 +- docs/configs/Warnings.html | 2 +- docs/configs/Warps.html | 2 +- docs/control/Jail.html | 2 +- docs/control/Production.html | 2 +- docs/control/Reports.html | 2 +- docs/control/Rockets.html | 2 +- docs/control/Tasks.html | 2 +- docs/control/Warnings.html | 2 +- docs/control/Warps.html | 2 +- docs/core/Commands.html | 2 +- docs/core/Common-Library.html | 2 +- docs/core/Gui.html | 558 +++++++++++++++++- docs/core/Permissions-Groups.html | 2 +- docs/core/Roles.html | 2 +- docs/core/Store.html | 2 +- docs/core/Sudo.html | 2 +- docs/guis/Player-List.html | 2 +- docs/guis/Rocket-Info.html | 2 +- docs/guis/Science-Info.html | 2 +- docs/guis/Task-List.html | 2 +- docs/guis/Warps-List.html | 2 +- docs/index.html | 2 +- docs/modules/control.html | 2 +- .../utils.alien_evolution_progress.html | 2 +- docs/modules/utils.core.html | 2 +- docs/modules/utils.debug.html | 2 +- docs/modules/utils.dump_env.html | 2 +- docs/modules/utils.event.html | 2 +- docs/modules/utils.event_core.html | 2 +- docs/modules/utils.math.html | 2 +- docs/modules/utils.recipe_locker.html | 2 +- docs/modules/utils.state_machine.html | 2 +- docs/modules/utils.table.html | 2 +- docs/modules/utils.task.html | 2 +- docs/modules/utils.timestamp.html | 2 +- docs/topics/license.html | 2 +- docs/topics/readme.md.html | 2 +- expcore/gui.lua | 1 + expcore/gui/concepts/elem_button.lua | 2 +- expcore/gui/concepts/frame.lua | 5 +- expcore/gui/concepts/progress_bar.lua | 155 +++++ expcore/gui/prototype.lua | 2 +- expcore/gui/test.lua | 93 +++ expcore/store.lua | 2 +- 99 files changed, 903 insertions(+), 97 deletions(-) create mode 100644 expcore/gui/concepts/progress_bar.lua diff --git a/docs/addons/Advanced-Start.html b/docs/addons/Advanced-Start.html index bd36c9e1..fac87435 100644 --- a/docs/addons/Advanced-Start.html +++ b/docs/addons/Advanced-Start.html @@ -348,7 +348,7 @@ generated by LDoc diff --git a/docs/addons/Chat-Popups.html b/docs/addons/Chat-Popups.html index 479610b9..fb1aed14 100644 --- a/docs/addons/Chat-Popups.html +++ b/docs/addons/Chat-Popups.html @@ -349,7 +349,7 @@ generated by LDoc diff --git a/docs/addons/Chat-Reply.html b/docs/addons/Chat-Reply.html index 76c57702..f67c7100 100644 --- a/docs/addons/Chat-Reply.html +++ b/docs/addons/Chat-Reply.html @@ -376,7 +376,7 @@ generated by LDoc diff --git a/docs/addons/Compilatron.html b/docs/addons/Compilatron.html index a2c3181a..1867f7c4 100644 --- a/docs/addons/Compilatron.html +++ b/docs/addons/Compilatron.html @@ -585,7 +585,7 @@ generated by LDoc diff --git a/docs/addons/Damage-Popups.html b/docs/addons/Damage-Popups.html index e0f4ca89..669a44a1 100644 --- a/docs/addons/Damage-Popups.html +++ b/docs/addons/Damage-Popups.html @@ -349,7 +349,7 @@ generated by LDoc diff --git a/docs/addons/Death-Logger.html b/docs/addons/Death-Logger.html index f20331ff..a54f6e89 100644 --- a/docs/addons/Death-Logger.html +++ b/docs/addons/Death-Logger.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/addons/Discord-Alerts.html b/docs/addons/Discord-Alerts.html index bde7543f..cdfd6557 100644 --- a/docs/addons/Discord-Alerts.html +++ b/docs/addons/Discord-Alerts.html @@ -460,7 +460,7 @@ generated by LDoc diff --git a/docs/addons/Player-Colours.html b/docs/addons/Player-Colours.html index a30f16fb..cbadfe62 100644 --- a/docs/addons/Player-Colours.html +++ b/docs/addons/Player-Colours.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/addons/Pollution-Grading.html b/docs/addons/Pollution-Grading.html index a97f5329..48e68d6e 100644 --- a/docs/addons/Pollution-Grading.html +++ b/docs/addons/Pollution-Grading.html @@ -320,7 +320,7 @@ generated by LDoc diff --git a/docs/addons/Scorched-Earth.html b/docs/addons/Scorched-Earth.html index 043de6a1..fea61aeb 100644 --- a/docs/addons/Scorched-Earth.html +++ b/docs/addons/Scorched-Earth.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/addons/Spawn-Area.html b/docs/addons/Spawn-Area.html index 9bdb2207..cdc65900 100644 --- a/docs/addons/Spawn-Area.html +++ b/docs/addons/Spawn-Area.html @@ -376,7 +376,7 @@ generated by LDoc diff --git a/docs/commands/Admin-Chat.html b/docs/commands/Admin-Chat.html index 290d196a..02095229 100644 --- a/docs/commands/Admin-Chat.html +++ b/docs/commands/Admin-Chat.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Bonus.html b/docs/commands/Bonus.html index 64f67823..2c7f2f13 100644 --- a/docs/commands/Bonus.html +++ b/docs/commands/Bonus.html @@ -500,7 +500,7 @@ generated by LDoc diff --git a/docs/commands/Cheat-Mode.html b/docs/commands/Cheat-Mode.html index 2e5d4d77..5167e8a3 100644 --- a/docs/commands/Cheat-Mode.html +++ b/docs/commands/Cheat-Mode.html @@ -361,7 +361,7 @@ generated by LDoc diff --git a/docs/commands/Clear-Inventory.html b/docs/commands/Clear-Inventory.html index aa7e882e..add5b72a 100644 --- a/docs/commands/Clear-Inventory.html +++ b/docs/commands/Clear-Inventory.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Debug.html b/docs/commands/Debug.html index 8957b0bc..aed6e1cd 100644 --- a/docs/commands/Debug.html +++ b/docs/commands/Debug.html @@ -365,7 +365,7 @@ generated by LDoc diff --git a/docs/commands/Find.html b/docs/commands/Find.html index 47e49267..83f04b51 100644 --- a/docs/commands/Find.html +++ b/docs/commands/Find.html @@ -360,7 +360,7 @@ generated by LDoc diff --git a/docs/commands/Help.html b/docs/commands/Help.html index ed4208d0..1ce2c9c7 100644 --- a/docs/commands/Help.html +++ b/docs/commands/Help.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/commands/Home.html b/docs/commands/Home.html index e08e5ea5..620a6927 100644 --- a/docs/commands/Home.html +++ b/docs/commands/Home.html @@ -458,7 +458,7 @@ generated by LDoc diff --git a/docs/commands/Interface.html b/docs/commands/Interface.html index f5c672f5..a8be6f65 100644 --- a/docs/commands/Interface.html +++ b/docs/commands/Interface.html @@ -416,7 +416,7 @@ generated by LDoc diff --git a/docs/commands/Jail.html b/docs/commands/Jail.html index 2b88c16f..e7baa4a2 100644 --- a/docs/commands/Jail.html +++ b/docs/commands/Jail.html @@ -611,7 +611,7 @@ generated by LDoc diff --git a/docs/commands/Kill.html b/docs/commands/Kill.html index 5ade1288..01af9a7b 100644 --- a/docs/commands/Kill.html +++ b/docs/commands/Kill.html @@ -389,7 +389,7 @@ generated by LDoc diff --git a/docs/commands/Me.html b/docs/commands/Me.html index a396bdd9..a566461f 100644 --- a/docs/commands/Me.html +++ b/docs/commands/Me.html @@ -360,7 +360,7 @@ generated by LDoc diff --git a/docs/commands/Rainbow.html b/docs/commands/Rainbow.html index 78b3a6ab..528dcb0a 100644 --- a/docs/commands/Rainbow.html +++ b/docs/commands/Rainbow.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Repair.html b/docs/commands/Repair.html index ae84d625..379eb796 100644 --- a/docs/commands/Repair.html +++ b/docs/commands/Repair.html @@ -321,7 +321,7 @@ generated by LDoc diff --git a/docs/commands/Reports.html b/docs/commands/Reports.html index b161ceac..823053bd 100644 --- a/docs/commands/Reports.html +++ b/docs/commands/Reports.html @@ -585,7 +585,7 @@ generated by LDoc diff --git a/docs/commands/Roles.html b/docs/commands/Roles.html index 255aa570..f4b345cc 100644 --- a/docs/commands/Roles.html +++ b/docs/commands/Roles.html @@ -557,7 +557,7 @@ generated by LDoc diff --git a/docs/commands/Spawn.html b/docs/commands/Spawn.html index a368c0b5..fa096552 100644 --- a/docs/commands/Spawn.html +++ b/docs/commands/Spawn.html @@ -389,7 +389,7 @@ generated by LDoc diff --git a/docs/commands/Tag.html b/docs/commands/Tag.html index 165ffd2a..490b4d15 100644 --- a/docs/commands/Tag.html +++ b/docs/commands/Tag.html @@ -443,7 +443,7 @@ generated by LDoc diff --git a/docs/commands/Teleport.html b/docs/commands/Teleport.html index 61c9bce6..cbf8bca6 100644 --- a/docs/commands/Teleport.html +++ b/docs/commands/Teleport.html @@ -484,7 +484,7 @@ generated by LDoc diff --git a/docs/commands/Warnings.html b/docs/commands/Warnings.html index db4a29aa..4cf981c7 100644 --- a/docs/commands/Warnings.html +++ b/docs/commands/Warnings.html @@ -569,7 +569,7 @@ generated by LDoc diff --git a/docs/configs/Advanced-Start.html b/docs/configs/Advanced-Start.html index b9c394c4..42e2964c 100644 --- a/docs/configs/Advanced-Start.html +++ b/docs/configs/Advanced-Start.html @@ -506,7 +506,7 @@ generated by LDoc diff --git a/docs/configs/Bonuses.html b/docs/configs/Bonuses.html index 66a28a9f..0537a1ae 100644 --- a/docs/configs/Bonuses.html +++ b/docs/configs/Bonuses.html @@ -237,7 +237,7 @@ generated by LDoc diff --git a/docs/configs/Chat-Reply.html b/docs/configs/Chat-Reply.html index 25085c59..78489463 100644 --- a/docs/configs/Chat-Reply.html +++ b/docs/configs/Chat-Reply.html @@ -485,7 +485,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Admin.html b/docs/configs/Commands-Auth-Admin.html index 84bb6c48..b5d967a2 100644 --- a/docs/configs/Commands-Auth-Admin.html +++ b/docs/configs/Commands-Auth-Admin.html @@ -294,7 +294,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Roles.html b/docs/configs/Commands-Auth-Roles.html index e50c4466..e7b05121 100644 --- a/docs/configs/Commands-Auth-Roles.html +++ b/docs/configs/Commands-Auth-Roles.html @@ -320,7 +320,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Runtime-Disable.html b/docs/configs/Commands-Auth-Runtime-Disable.html index 147b5499..1efdf6ee 100644 --- a/docs/configs/Commands-Auth-Runtime-Disable.html +++ b/docs/configs/Commands-Auth-Runtime-Disable.html @@ -442,7 +442,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Parse-Roles.html b/docs/configs/Commands-Parse-Roles.html index 379dd604..9a3828fe 100644 --- a/docs/configs/Commands-Parse-Roles.html +++ b/docs/configs/Commands-Parse-Roles.html @@ -354,7 +354,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Parse.html b/docs/configs/Commands-Parse.html index 12051041..96d3023d 100644 --- a/docs/configs/Commands-Parse.html +++ b/docs/configs/Commands-Parse.html @@ -338,7 +338,7 @@ see ./expcore/commands.lua for more details

    generated by LDoc diff --git a/docs/configs/Compilatron.html b/docs/configs/Compilatron.html index 17533a11..df1dfd7c 100644 --- a/docs/configs/Compilatron.html +++ b/docs/configs/Compilatron.html @@ -354,7 +354,7 @@ generated by LDoc diff --git a/docs/configs/Death-Logger.html b/docs/configs/Death-Logger.html index a77eddd3..05bd91dd 100644 --- a/docs/configs/Death-Logger.html +++ b/docs/configs/Death-Logger.html @@ -416,7 +416,7 @@ generated by LDoc diff --git a/docs/configs/Discord-Alerts.html b/docs/configs/Discord-Alerts.html index 1b262704..a917fb49 100644 --- a/docs/configs/Discord-Alerts.html +++ b/docs/configs/Discord-Alerts.html @@ -237,7 +237,7 @@ generated by LDoc diff --git a/docs/configs/File-Loader.html b/docs/configs/File-Loader.html index 56af4b90..63292dc1 100644 --- a/docs/configs/File-Loader.html +++ b/docs/configs/File-Loader.html @@ -240,7 +240,7 @@ generated by LDoc diff --git a/docs/configs/Permission-Groups.html b/docs/configs/Permission-Groups.html index 7a1cde25..34f79892 100644 --- a/docs/configs/Permission-Groups.html +++ b/docs/configs/Permission-Groups.html @@ -295,7 +295,7 @@ generated by LDoc diff --git a/docs/configs/Player-List.html b/docs/configs/Player-List.html index 62676d41..51bae4fd 100644 --- a/docs/configs/Player-List.html +++ b/docs/configs/Player-List.html @@ -812,7 +812,7 @@ generated by LDoc diff --git a/docs/configs/Pollution-Grading.html b/docs/configs/Pollution-Grading.html index 857acf8e..94422ee0 100644 --- a/docs/configs/Pollution-Grading.html +++ b/docs/configs/Pollution-Grading.html @@ -384,7 +384,7 @@ generated by LDoc diff --git a/docs/configs/Popup-Messages.html b/docs/configs/Popup-Messages.html index 806575da..16b8eff8 100644 --- a/docs/configs/Popup-Messages.html +++ b/docs/configs/Popup-Messages.html @@ -414,7 +414,7 @@ generated by LDoc diff --git a/docs/configs/Preset-Player-Colours.html b/docs/configs/Preset-Player-Colours.html index 81761726..b8ca80a1 100644 --- a/docs/configs/Preset-Player-Colours.html +++ b/docs/configs/Preset-Player-Colours.html @@ -324,7 +324,7 @@ generated by LDoc diff --git a/docs/configs/Repair.html b/docs/configs/Repair.html index 918196b3..d0bf54de 100644 --- a/docs/configs/Repair.html +++ b/docs/configs/Repair.html @@ -414,7 +414,7 @@ generated by LDoc diff --git a/docs/configs/Rockets.html b/docs/configs/Rockets.html index 360875bd..3bd16022 100644 --- a/docs/configs/Rockets.html +++ b/docs/configs/Rockets.html @@ -834,7 +834,7 @@ generated by LDoc diff --git a/docs/configs/Roles.html b/docs/configs/Roles.html index 16206a78..7c8665c8 100644 --- a/docs/configs/Roles.html +++ b/docs/configs/Roles.html @@ -292,7 +292,7 @@ generated by LDoc diff --git a/docs/configs/Science.html b/docs/configs/Science.html index 140a3c6c..4a829958 100644 --- a/docs/configs/Science.html +++ b/docs/configs/Science.html @@ -354,7 +354,7 @@ generated by LDoc diff --git a/docs/configs/Scorched-Earth.html b/docs/configs/Scorched-Earth.html index e07eac6f..3ee50e94 100644 --- a/docs/configs/Scorched-Earth.html +++ b/docs/configs/Scorched-Earth.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/configs/Spawn-Area.html b/docs/configs/Spawn-Area.html index ba44a6bf..a320c897 100644 --- a/docs/configs/Spawn-Area.html +++ b/docs/configs/Spawn-Area.html @@ -744,7 +744,7 @@ generated by LDoc diff --git a/docs/configs/Tasks.html b/docs/configs/Tasks.html index 8eb4fc0a..e3b6d034 100644 --- a/docs/configs/Tasks.html +++ b/docs/configs/Tasks.html @@ -384,7 +384,7 @@ generated by LDoc diff --git a/docs/configs/Warnings.html b/docs/configs/Warnings.html index 9e4a11b2..2e3b3df7 100644 --- a/docs/configs/Warnings.html +++ b/docs/configs/Warnings.html @@ -355,7 +355,7 @@ generated by LDoc diff --git a/docs/configs/Warps.html b/docs/configs/Warps.html index ca467866..f32aafed 100644 --- a/docs/configs/Warps.html +++ b/docs/configs/Warps.html @@ -684,7 +684,7 @@ generated by LDoc diff --git a/docs/control/Jail.html b/docs/control/Jail.html index 067ebc0d..a5cfdf31 100644 --- a/docs/control/Jail.html +++ b/docs/control/Jail.html @@ -1208,7 +1208,7 @@ generated by LDoc diff --git a/docs/control/Production.html b/docs/control/Production.html index 9545db59..07b51b32 100644 --- a/docs/control/Production.html +++ b/docs/control/Production.html @@ -1329,7 +1329,7 @@ generated by LDoc diff --git a/docs/control/Reports.html b/docs/control/Reports.html index 0b8e6efc..677291b4 100644 --- a/docs/control/Reports.html +++ b/docs/control/Reports.html @@ -1110,7 +1110,7 @@ generated by LDoc diff --git a/docs/control/Rockets.html b/docs/control/Rockets.html index 4b3c9f31..e765ea4d 100644 --- a/docs/control/Rockets.html +++ b/docs/control/Rockets.html @@ -984,7 +984,7 @@ generated by LDoc diff --git a/docs/control/Tasks.html b/docs/control/Tasks.html index d484ec72..f7d7e25b 100644 --- a/docs/control/Tasks.html +++ b/docs/control/Tasks.html @@ -1039,7 +1039,7 @@ generated by LDoc diff --git a/docs/control/Warnings.html b/docs/control/Warnings.html index bb21eb87..9109db95 100644 --- a/docs/control/Warnings.html +++ b/docs/control/Warnings.html @@ -1465,7 +1465,7 @@ generated by LDoc diff --git a/docs/control/Warps.html b/docs/control/Warps.html index 3d7f786d..e40b5944 100644 --- a/docs/control/Warps.html +++ b/docs/control/Warps.html @@ -1413,7 +1413,7 @@ generated by LDoc diff --git a/docs/core/Commands.html b/docs/core/Commands.html index 7bfe081a..552f913d 100644 --- a/docs/core/Commands.html +++ b/docs/core/Commands.html @@ -1972,7 +1972,7 @@ generated by LDoc diff --git a/docs/core/Common-Library.html b/docs/core/Common-Library.html index bff67067..fd82f345 100644 --- a/docs/core/Common-Library.html +++ b/docs/core/Common-Library.html @@ -2680,7 +2680,7 @@ Common.table_insert(tbl,50,tbl2) generated by LDoc diff --git a/docs/core/Gui.html b/docs/core/Gui.html index 66b0e63d..23c3bc23 100644 --- a/docs/core/Gui.html +++ b/docs/core/Gui.html @@ -43,6 +43,7 @@
    + + + +
    Prototype:define_combined_store([category_callback], sync_callback)Used to add a both instance and data stores which are linked together, new instances are synced to current value, changing one instance changes them allUsed to add a both instance and data store which are linked together, new instances are synced to the current value, changing the stored value will change all instances
    Prototype.sync_instance(element) The basic dropdown element
    elem_buttonThe basic dropdown element
    frame The basic frame element
    frame The basic frame element
    progress_barThe basic checkbox element
    @@ -362,6 +368,34 @@ button:clone('CustomButton')
    +

    Progress Bars

    + + + + + + + + + + + + + + + + + + + + + + + + +
    progress_bar:increment(element[, amount=1])Will increase the progress of a progress bar based on this concept, if the concept has an instance store then element acts as the category, if you have a combined store it will NOT update all instances
    progress_bar:decrement(element[, amount=1])Will decrease the progress of a progress bar based on this concept, if the concept has an instance store then element acts as the category, if you have a combined store it will NOT update all instances
    progress_bar:reset(element)Resets the progress back to 0% for this element, if the concept has an instance store then element acts as the category, if you have a combined store it will NOT update all instances
    increment_progress_bar(element[, amount=0.01])Increment any progress bar by the given percentage
    decrement_progress_bar(element[, amount=0.01])Decrement any progress bar by the given percentage
    + +

    Concept Control

    @@ -1042,7 +1076,7 @@ Gui.clone_concept('dropdown','d Usage:
    -- Making a basic elem button
     local basic_elem_button =
    -Gui.clone_concept('elem_button',TEST 'basic_elembutton')
    +Gui.clone_concept('elem_button','basic_elembutton')
     :on_selection_change(function(event)
         event.player.print('Basic elem button is now: '..event.element.elem_value)
     end)
    @@ -1084,6 +1118,22 @@ Gui.clone_concept('elem_button',TEST + + direction + + : + + (string) + + the direction that children will be added + + + + @@ -1109,6 +1159,133 @@ Gui.clone_concept('dropdown','b end) + +
    +
    +
    + # + progress_bar +
    +
    +
    +
    + +

    The basic checkbox element

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + on_completion + + : + + + fired when increment reaches the maxium value set by set_maximum + +
    • + + + + + +
    • + + tooltip + + : + + (string or LocalisedString) + + the tooltip that will show for this element + +
    • + + + + + +
    • + + maximum + + : + + (number) + + the maxium amount an instance can be increased, default 100 + +
    • + + + + + +
    • + + delay_completion + + : + + (boolean) + + when true the progress will be completed untill after the maximum rather than at the maximum + +
    • + + + + + +
    • + + inverted + + : + + (boolean) + + 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')
    +:set_tooltip('Basic progress bar')
    +:set_maximum(5)
    +:new_event('on_click',defines.events.on_gui_click)
    +:on_click(function(event)
    +    event.concept:increment(event.element)
    +end)
    +:set_delay_completion(true)
    +:on_completion(function(event)
    +    event.concept:reset(event.element)
    +end)
    + +

    Dropdowns

    @@ -1343,6 +1520,383 @@ Gui.clone_concept('dropdown','b Gui.add_dropdown_items(element,1,{'foo','bar'}) + + +

    Progress Bars

    +
    +
    +
    +
    + # + progress_bar:increment(element[, amount=1]) +
    +
    +
    +
    + +

    Will increase the progress of a progress bar based on this concept, if the concept has an instance store then element acts as the category, if you have a combined store it will NOT update all instances

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement or string) + + either the element that is changed or the category that is being changed (only if an instance store is defined) + +
    • + + + + + +
    • + + amount + + : + + (number) + + the amount that will bar will increase, note that this amount must be less than the max + + (default: 1) +
    • + + +
    + + + + + Returns: +
      +
    • + (number or nil) + the new value of the element, use this to sync a data store, if the return is nil then either a instance store was used or the new value may have changed +
    • +
    + + + + + + + + Usage: +
    -- Incrementing progress bar with no instance store
    +local new_value = progress_bar:increment(element)
    +
    -- Incrementing progress bar with an instance store
    +progress_bar:increment(category)
    + + +
    +
    +
    +
    + # + progress_bar:decrement(element[, amount=1]) +
    +
    +
    +
    + +

    Will decrease the progress of a progress bar based on this concept, if the concept has an instance store then element acts as the category, if you have a combined store it will NOT update all instances

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement or string) + + either the element that is changed or the category that is being changed (only if an instance store is defined) + +
    • + + + + + +
    • + + amount + + : + + (number) + + the amount that will bar will decrease, note that this amount must be less than the max + + (default: 1) +
    • + + +
    + + + + + Returns: +
      +
    • + (number) + the new value of the element, use this to sync a data store, if the return is nil then either a instance store was used or the new value may have changed +
    • +
    + + + + + + + + Usage: +
    -- Decrementing progress bar with no instance store
    +local new_value = progress_bar:decrement(element)
    +
    -- Decrementing progress bar with an instance store
    +progress_bar:decrement(category)
    + + +
    +
    +
    +
    + # + progress_bar:reset(element) +
    +
    +
    +
    + +

    Resets the progress back to 0% for this element, if the concept has an instance store then element acts as the category, if you have a combined store it will NOT update all instances

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement or string) + + either the element that is changed or the category that is being changed (only if an instance store is defined) + +
    • + + +
    + + + + + Returns: +
      +
    • + (number or nil) + the new value of the element, use this to sync a data store, if the return is nil then either a instance store was used or the new value may have changed +
    • +
    + + + + + + + + Usage: +
    -- Reseting a progress bar with no instance store
    +local new_value = progress_bar:reset(element)
    +
    -- Reseting a progress bar with an instance store
    +progress_bar:reset(category)
    + + +
    +
    +
    +
    + # + increment_progress_bar(element[, amount=0.01]) +
    +
    +
    +
    + +

    Increment any progress bar by the given percentage

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the progress bar that you want to update + +
    • + + + + + +
    • + + amount + + : + + (number) + + the percentage that you want to increment the progress bar by + + (default: 0.01) +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + true if the bar is now full +
    • +
    + + + + + + + + Usage: +
    -- Increment any progress bar by 10%
    +Gui.increment_progress_bar(element,0.1)
    + + +
    +
    +
    +
    + # + decrement_progress_bar(element[, amount=0.01]) +
    +
    +
    +
    + +

    Decrement any progress bar by the given percentage

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the progress bar that you want to update + +
    • + + + + + +
    • + + amount + + : + + (number) + + the percentage that you want to decrement the progress bar by + + (default: 0.01) +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + true if the bar is now empty +
    • +
    + + + + + + + + Usage: +
    -- Decrement any progress bar by 10%
    +Gui.decrement_progress_bar(element,0.1)
    + +

    Concept Control

    @@ -3886,7 +4440,7 @@ Gui.get_concept('CustomButton') generated by LDoc diff --git a/docs/core/Permissions-Groups.html b/docs/core/Permissions-Groups.html index effd0630..71ae873e 100644 --- a/docs/core/Permissions-Groups.html +++ b/docs/core/Permissions-Groups.html @@ -1432,7 +1432,7 @@ generated by LDoc diff --git a/docs/core/Roles.html b/docs/core/Roles.html index 5827dcf1..86992767 100644 --- a/docs/core/Roles.html +++ b/docs/core/Roles.html @@ -3152,7 +3152,7 @@ generated by LDoc diff --git a/docs/core/Store.html b/docs/core/Store.html index 42eb1aed..7efa78fb 100644 --- a/docs/core/Store.html +++ b/docs/core/Store.html @@ -1145,7 +1145,7 @@ Store.register(team_scores,function(value,key) generated by LDoc diff --git a/docs/core/Sudo.html b/docs/core/Sudo.html index 53ff468c..b05c3b4d 100644 --- a/docs/core/Sudo.html +++ b/docs/core/Sudo.html @@ -544,7 +544,7 @@ generated by LDoc diff --git a/docs/guis/Player-List.html b/docs/guis/Player-List.html index 54e5156c..e12e78e5 100644 --- a/docs/guis/Player-List.html +++ b/docs/guis/Player-List.html @@ -626,7 +626,7 @@ generated by LDoc diff --git a/docs/guis/Rocket-Info.html b/docs/guis/Rocket-Info.html index 4d20398c..43160544 100644 --- a/docs/guis/Rocket-Info.html +++ b/docs/guis/Rocket-Info.html @@ -629,7 +629,7 @@ generated by LDoc diff --git a/docs/guis/Science-Info.html b/docs/guis/Science-Info.html index f2e103f9..1a8c6e7c 100644 --- a/docs/guis/Science-Info.html +++ b/docs/guis/Science-Info.html @@ -449,7 +449,7 @@ generated by LDoc diff --git a/docs/guis/Task-List.html b/docs/guis/Task-List.html index 172a8c6d..224ac51e 100644 --- a/docs/guis/Task-List.html +++ b/docs/guis/Task-List.html @@ -632,7 +632,7 @@ generated by LDoc diff --git a/docs/guis/Warps-List.html b/docs/guis/Warps-List.html index b97332f0..099c1978 100644 --- a/docs/guis/Warps-List.html +++ b/docs/guis/Warps-List.html @@ -837,7 +837,7 @@ generated by LDoc diff --git a/docs/index.html b/docs/index.html index acabe123..6a63a39c 100644 --- a/docs/index.html +++ b/docs/index.html @@ -510,7 +510,7 @@ see ./expcore/commands.lua for more details
    generated by LDoc diff --git a/docs/modules/control.html b/docs/modules/control.html index 5aff8205..e147afc2 100644 --- a/docs/modules/control.html +++ b/docs/modules/control.html @@ -351,7 +351,7 @@ generated by LDoc diff --git a/docs/modules/utils.alien_evolution_progress.html b/docs/modules/utils.alien_evolution_progress.html index 4dd24a85..6d93ca08 100644 --- a/docs/modules/utils.alien_evolution_progress.html +++ b/docs/modules/utils.alien_evolution_progress.html @@ -419,7 +419,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 de6f9d77..702fd931 100644 --- a/docs/modules/utils.core.html +++ b/docs/modules/utils.core.html @@ -1164,7 +1164,7 @@ generated by LDoc diff --git a/docs/modules/utils.debug.html b/docs/modules/utils.debug.html index 6ff655be..56614959 100644 --- a/docs/modules/utils.debug.html +++ b/docs/modules/utils.debug.html @@ -654,7 +654,7 @@ generated by LDoc diff --git a/docs/modules/utils.dump_env.html b/docs/modules/utils.dump_env.html index ad4d89c4..4b36cbfc 100644 --- a/docs/modules/utils.dump_env.html +++ b/docs/modules/utils.dump_env.html @@ -323,7 +323,7 @@ generated by LDoc diff --git a/docs/modules/utils.event.html b/docs/modules/utils.event.html index 97b00a74..71a4e2ad 100644 --- a/docs/modules/utils.event.html +++ b/docs/modules/utils.event.html @@ -1292,7 +1292,7 @@ generated by LDoc diff --git a/docs/modules/utils.event_core.html b/docs/modules/utils.event_core.html index ab5335ee..3eeb9117 100644 --- a/docs/modules/utils.event_core.html +++ b/docs/modules/utils.event_core.html @@ -434,7 +434,7 @@ generated by LDoc diff --git a/docs/modules/utils.math.html b/docs/modules/utils.math.html index ed30683c..69f8200f 100644 --- a/docs/modules/utils.math.html +++ b/docs/modules/utils.math.html @@ -338,7 +338,7 @@ generated by LDoc diff --git a/docs/modules/utils.recipe_locker.html b/docs/modules/utils.recipe_locker.html index a94f5916..bbc2686b 100644 --- a/docs/modules/utils.recipe_locker.html +++ b/docs/modules/utils.recipe_locker.html @@ -441,7 +441,7 @@ generated by LDoc diff --git a/docs/modules/utils.state_machine.html b/docs/modules/utils.state_machine.html index 2d3c8396..7a91a65a 100644 --- a/docs/modules/utils.state_machine.html +++ b/docs/modules/utils.state_machine.html @@ -752,7 +752,7 @@ generated by LDoc diff --git a/docs/modules/utils.table.html b/docs/modules/utils.table.html index d548fc6f..5952d586 100644 --- a/docs/modules/utils.table.html +++ b/docs/modules/utils.table.html @@ -1382,7 +1382,7 @@ generated by LDoc diff --git a/docs/modules/utils.task.html b/docs/modules/utils.task.html index b467f3f1..9f7f258d 100644 --- a/docs/modules/utils.task.html +++ b/docs/modules/utils.task.html @@ -651,7 +651,7 @@ generated by LDoc diff --git a/docs/modules/utils.timestamp.html b/docs/modules/utils.timestamp.html index 77d371b1..d0cb161c 100644 --- a/docs/modules/utils.timestamp.html +++ b/docs/modules/utils.timestamp.html @@ -442,7 +442,7 @@ generated by LDoc diff --git a/docs/topics/license.html b/docs/topics/license.html index e260d7f0..1c917750 100644 --- a/docs/topics/license.html +++ b/docs/topics/license.html @@ -789,7 +789,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 4e38c52a..abe6555d 100644 --- a/docs/topics/readme.md.html +++ b/docs/topics/readme.md.html @@ -332,7 +332,7 @@ generated by LDoc diff --git a/expcore/gui.lua b/expcore/gui.lua index d066a2dc..ae17446b 100644 --- a/expcore/gui.lua +++ b/expcore/gui.lua @@ -72,5 +72,6 @@ Gui.require_concept('button') Gui.require_concept('checkbox') Gui.require_concept('dropdown') Gui.require_concept('elem_button') +Gui.require_concept('progress_bar') return Gui \ No newline at end of file diff --git a/expcore/gui/concepts/elem_button.lua b/expcore/gui/concepts/elem_button.lua index ec8b09ef..cbbd0753 100644 --- a/expcore/gui/concepts/elem_button.lua +++ b/expcore/gui/concepts/elem_button.lua @@ -12,7 +12,7 @@ local Gui = require 'expcore.gui.core' @tparam string elem_type the type of elem selection that this is, default is item selection @usage-- Making a basic elem button local basic_elem_button = -Gui.clone_concept('elem_button',TEST 'basic_elembutton') +Gui.clone_concept('elem_button','basic_elembutton') :on_selection_change(function(event) event.player.print('Basic elem button is now: '..event.element.elem_value) end) diff --git a/expcore/gui/concepts/frame.lua b/expcore/gui/concepts/frame.lua index 746aae50..a7b69f93 100644 --- a/expcore/gui/concepts/frame.lua +++ b/expcore/gui/concepts/frame.lua @@ -8,6 +8,7 @@ local Gui = require 'expcore.gui.core' --[[-- The basic frame element @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('dropdown','basic_frame') @@ -21,11 +22,13 @@ end) ]] Gui.new_concept('frame') :new_property('title') +:new_property('direction') :define_draw(function(properties,parent,element) element = parent.add{ name = properties.name, type = 'frame', - caption = properties.title + caption = properties.title, + direction = properties.direction } return element diff --git a/expcore/gui/concepts/progress_bar.lua b/expcore/gui/concepts/progress_bar.lua new file mode 100644 index 00000000..b85e9500 --- /dev/null +++ b/expcore/gui/concepts/progress_bar.lua @@ -0,0 +1,155 @@ +--[[-- Core Module - Gui + @module Gui + @alias Gui +]] + +local Gui = require 'expcore.gui.core' + +--[[-- The basic checkbox element +@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') +:set_tooltip('Basic progress bar') +:set_maximum(5) +:new_event('on_click',defines.events.on_gui_click) +:on_click(function(event) + event.concept:increment(event.element) +end) +:set_delay_completion(true) +:on_completion(function(event) + event.concept:reset(event.element) +end) +]] +local progress_bar = +Gui.new_concept('progress_bar') +:new_event('on_completion') +:new_property('tooltip') +:new_property('maximum',100) +:new_property('delay_completion',false) +:new_property('inverted',false) +:define_draw(function(properties,parent,element) + element = parent.add{ + name = properties.name, + tooltip = properties.tooltip, + type = 'progressbar', + value = properties.inverted and 1 or 0 + } + + return element +end) + +--- Progress Bars. +-- functions used with progress bars +-- @section progress_bars + +-- logic for changing the value of a progress bar +local function raw_update(concept,element,amount) + local old_value = element.value + local new_value = old_value + amount + element.value = new_value + + local check_value = concept.properties.delay_completion and old_value or new_value + if amount < 0 and check_value <= 0 or amount > 0 and check_value >= 1 then + concept:raise_event('on_completion',{ + element = element + }) + else + return new_value + + end + +end + +--[[-- Will increase the progress of a progress bar based on this concept, if the concept has an instance store then element acts as the category, if you have a combined store it will NOT update all instances +@tparam ?LuaGuiElement|string element either the element that is changed or the category that is being changed (only if an instance store is defined) +@tparam[opt=1] number amount the amount that will bar will increase, note that this amount must be less than the max +@treturn ?number|nil the new value of the element, use this to sync a data store, if the return is nil then either a instance store was used or the new value may have changed +@usage-- Incrementing progress bar with no instance store +local new_value = progress_bar:increment(element) +@usage-- Incrementing progress bar with an instance store +progress_bar:increment(category) +]] +function progress_bar:increment(element,amount) + local properties = self.properties + local inverted = properties.inverted + local maximum = properties.maximum + amount = amount and amount/maximum or 1/maximum + amount = inverted and -amount or amount + + if self.instance_store and not self.sync_instance then + self.update_instances(element,function(next_element) + raw_update(self,next_element,amount) + end) + + else + return raw_update(self,element,amount) + + end +end + +--[[-- Will decrease the progress of a progress bar based on this concept, if the concept has an instance store then element acts as the category, if you have a combined store it will NOT update all instances +@tparam ?LuaGuiElement|string element either the element that is changed or the category that is being changed (only if an instance store is defined) +@tparam[opt=1] number amount the amount that will bar will decrease, note that this amount must be less than the max +@treturn number the new value of the element, use this to sync a data store, if the return is nil then either a instance store was used or the new value may have changed +@usage-- Decrementing progress bar with no instance store +local new_value = progress_bar:decrement(element) +@usage-- Decrementing progress bar with an instance store +progress_bar:decrement(category) +]] +function progress_bar:decrement(element,amount) + self:increment(element,-amount) +end + +--[[-- Resets the progress back to 0% for this element, if the concept has an instance store then element acts as the category, if you have a combined store it will NOT update all instances +@tparam ?LuaGuiElement|string element either the element that is changed or the category that is being changed (only if an instance store is defined) +@treturn ?number|nil the new value of the element, use this to sync a data store, if the return is nil then either a instance store was used or the new value may have changed +@usage-- Reseting a progress bar with no instance store +local new_value = progress_bar:reset(element) +@usage-- Reseting a progress bar with an instance store +progress_bar:reset(category) +]] +function progress_bar:reset(element) + local new_value = self.properties.inverted and 1 or 0 + if self.instacne_store and not self.sync_instance then + self.update_instances(element,function(next_element) + next_element.value = new_value + end) + + else + element.value = new_value + return new_value + + end +end + +--[[-- Increment any progress bar by the given percentage +@tparam LuaGuiElement element the progress bar that you want to update +@tparam[opt=0.01] number amount the percentage that you want to increment the progress bar by +@treturn boolean true if the bar is now full +@usage-- Increment any progress bar by 10% +Gui.increment_progress_bar(element,0.1) +]] +function Gui.increment_progress_bar(element,amount) + amount = amount or 0.01 + element.value = element.value + amount + return element.value >= 1 +end + +--[[-- Decrement any progress bar by the given percentage +@tparam LuaGuiElement element the progress bar that you want to update +@tparam[opt=0.01] number amount the percentage that you want to decrement the progress bar by +@treturn boolean true if the bar is now empty +@usage-- Decrement any progress bar by 10% +Gui.decrement_progress_bar(element,0.1) +]] +function Gui.decrement_progress_bar(element,amount) + amount = amount or 0.01 + element.value = element.value - amount + return element.value <= 0 +end \ No newline at end of file diff --git a/expcore/gui/prototype.lua b/expcore/gui/prototype.lua index ee3db3c5..2f08e255 100644 --- a/expcore/gui/prototype.lua +++ b/expcore/gui/prototype.lua @@ -513,7 +513,7 @@ end) category = nil end - local instances = Store.get(self.instance_store,get_category(category)) + local instances = Store.get(self.instance_store,get_category(category)) or {} for key,instance in pairs(instances) do if not instance or not instance.valid then instances[key] = nil diff --git a/expcore/gui/test.lua b/expcore/gui/test.lua index c853f709..f28b4e93 100644 --- a/expcore/gui/test.lua +++ b/expcore/gui/test.lua @@ -353,4 +353,97 @@ tests['Elem Buttons'] = { ['Basic Elem Button'] = basic_elem_button, ['Defaut Selection Elem Button'] = default_selection_elem_button, ['Player Stored Elem Button'] = player_elem_button +} + +--[[ +Progress Bars +> Basic Progress Bar -- will increse when pressed, when full then it will reset +> Inverted Progress Bar -- will increse when pressed, when empty then it will reset +> Game Instance Progress Bar -- will take 5 seconds to fill, when full it will reset, note instances are required due to on_tick +> Force Instance Progress Bar -- will increse when pressed, instance only means all instances will increse at same time but may not have the same value +> Force Stored Progress Bar -- will increse when pressed, unlike above all will increse at same time and will have the same value +]] + +local basic_progress_bar = +Gui.clone_concept('progress_bar',TEST 'basic_progress_bar') +:set_tooltip('Basic progress bar') +:set_maximum(5) +:new_event('on_click',defines.events.on_gui_click) +:on_click(function(event) + event.concept:increment(event.element) +end) +:set_delay_completion(true) +:on_completion(function(event) + event.concept:reset(event.element) +end) + +local inverted_progress_bar = +Gui.clone_concept('progress_bar',TEST 'inverted_progress_bar') +:set_tooltip('Inverted progress bar') +:set_inverted(true) +:set_maximum(5) +:new_event('on_click',defines.events.on_gui_click) +:on_click(function(event) + event.concept:increment(event.element) +end) +:on_completion(function(event) + event.concept:reset(event.element) +end) + +local game_progress_bar = +Gui.clone_concept('progress_bar',TEST 'game_progress_bar') +:set_tooltip('Game progress bar') +:set_maximum(300) +:new_event('on_tick',defines.events.on_tick) +:on_tick(function(event) + event.concept:increment(event.element) +end) +:set_delay_completion(true) +:on_completion(function(event) + event.concept:reset(event.element) +end) +:define_instance_store() + +local force_instance_progress_bar = +Gui.clone_concept('progress_bar',TEST 'force_instance_progress_bar') +:set_tooltip('Force instance progress bar') +:set_maximum(5) +:new_event('on_click',defines.events.on_gui_click) +:on_click(function(event) + event.concept:increment(event.element) +end) +:set_delay_completion(true) +:on_completion(function(event) + event.concept:reset(event.element) +end) +:define_instance_store(Gui.categorize_by_force) + +local force_stored_progress_bar = +Gui.clone_concept('progress_bar',TEST 'force_stored_progress_bar') +:set_tooltip('Force stored progress bar') +:set_maximum(5) +:new_event('on_click',defines.events.on_gui_click) +:on_click(function(event) + local element = event.element + local concept = event.concept + local new_value = concept:increment(element) + if new_value then concept.set_data(element,new_value) end +end) +:set_delay_completion(true) +:on_completion(function(event) + local element = event.element + local concept = event.concept + local new_value = concept:reset(element) + concept.set_data(element,new_value) +end) +:define_combined_store(Gui.categorize_by_force,function(element,value) + element.value = value or 0 +end) + +tests['Progress Bars'] = { + ['Basic Progress Bar'] = basic_progress_bar, + ['Inverted Progress Bar'] = inverted_progress_bar, + ['Game Instance Progress Bar'] = game_progress_bar, + ['Force Instance Progress Bar'] = force_instance_progress_bar, + ['Force Stored Progress Bar'] = force_stored_progress_bar } \ No newline at end of file diff --git a/expcore/store.lua b/expcore/store.lua index 9358f0e3..d0b4dcbd 100644 --- a/expcore/store.lua +++ b/expcore/store.lua @@ -174,7 +174,7 @@ function Store.update(location,key,update_callback,...) local rtn if update_callback and type(update_callback) == 'function' then if args then - rtn = udpate_callback(value,key,unpack(args)) + rtn = update_callback(value,key,unpack(args)) else rtn = update_callback(value,key,...) end From 71b0e16bd03ab4b9d73410c8b80141d79b36473d Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sun, 1 Sep 2019 17:18:19 +0100 Subject: [PATCH 13/26] Added sliders --- docs/addons/Advanced-Start.html | 2 +- docs/addons/Chat-Popups.html | 2 +- docs/addons/Chat-Reply.html | 2 +- docs/addons/Compilatron.html | 2 +- docs/addons/Damage-Popups.html | 2 +- docs/addons/Death-Logger.html | 2 +- docs/addons/Discord-Alerts.html | 2 +- docs/addons/Player-Colours.html | 2 +- docs/addons/Pollution-Grading.html | 2 +- docs/addons/Scorched-Earth.html | 2 +- docs/addons/Spawn-Area.html | 2 +- docs/commands/Admin-Chat.html | 2 +- docs/commands/Bonus.html | 2 +- docs/commands/Cheat-Mode.html | 2 +- docs/commands/Clear-Inventory.html | 2 +- docs/commands/Debug.html | 2 +- docs/commands/Find.html | 2 +- docs/commands/Help.html | 2 +- docs/commands/Home.html | 2 +- docs/commands/Interface.html | 2 +- docs/commands/Jail.html | 2 +- docs/commands/Kill.html | 2 +- docs/commands/Me.html | 2 +- docs/commands/Rainbow.html | 2 +- docs/commands/Repair.html | 2 +- docs/commands/Reports.html | 2 +- docs/commands/Roles.html | 2 +- docs/commands/Spawn.html | 2 +- docs/commands/Tag.html | 2 +- docs/commands/Teleport.html | 2 +- docs/commands/Warnings.html | 2 +- docs/configs/Advanced-Start.html | 2 +- docs/configs/Bonuses.html | 2 +- docs/configs/Chat-Reply.html | 2 +- docs/configs/Commands-Auth-Admin.html | 2 +- docs/configs/Commands-Auth-Roles.html | 2 +- .../Commands-Auth-Runtime-Disable.html | 2 +- docs/configs/Commands-Parse-Roles.html | 2 +- docs/configs/Commands-Parse.html | 2 +- docs/configs/Compilatron.html | 2 +- docs/configs/Death-Logger.html | 2 +- docs/configs/Discord-Alerts.html | 2 +- docs/configs/File-Loader.html | 2 +- docs/configs/Permission-Groups.html | 2 +- docs/configs/Player-List.html | 2 +- docs/configs/Pollution-Grading.html | 2 +- docs/configs/Popup-Messages.html | 2 +- docs/configs/Preset-Player-Colours.html | 2 +- docs/configs/Repair.html | 2 +- docs/configs/Rockets.html | 2 +- docs/configs/Roles.html | 2 +- docs/configs/Science.html | 2 +- docs/configs/Scorched-Earth.html | 2 +- docs/configs/Spawn-Area.html | 2 +- docs/configs/Tasks.html | 2 +- docs/configs/Warnings.html | 2 +- docs/configs/Warps.html | 2 +- docs/control/Jail.html | 2 +- docs/control/Production.html | 2 +- docs/control/Reports.html | 2 +- docs/control/Rockets.html | 2 +- docs/control/Tasks.html | 2 +- docs/control/Warnings.html | 2 +- docs/control/Warps.html | 2 +- docs/core/Commands.html | 2 +- docs/core/Common-Library.html | 68 ++++++- docs/core/Gui.html | 174 ++++++++++++++++-- docs/core/Permissions-Groups.html | 2 +- docs/core/Roles.html | 2 +- docs/core/Store.html | 2 +- docs/core/Sudo.html | 2 +- docs/guis/Player-List.html | 2 +- docs/guis/Rocket-Info.html | 2 +- docs/guis/Science-Info.html | 2 +- docs/guis/Task-List.html | 2 +- docs/guis/Warps-List.html | 2 +- docs/index.html | 2 +- docs/modules/control.html | 2 +- .../utils.alien_evolution_progress.html | 2 +- docs/modules/utils.core.html | 2 +- docs/modules/utils.debug.html | 2 +- docs/modules/utils.dump_env.html | 2 +- docs/modules/utils.event.html | 2 +- docs/modules/utils.event_core.html | 2 +- docs/modules/utils.math.html | 2 +- docs/modules/utils.recipe_locker.html | 2 +- docs/modules/utils.state_machine.html | 2 +- docs/modules/utils.table.html | 2 +- docs/modules/utils.task.html | 2 +- docs/modules/utils.timestamp.html | 2 +- docs/topics/license.html | 2 +- docs/topics/readme.md.html | 2 +- expcore/common.lua | 18 ++ expcore/gui.lua | 1 + expcore/gui/concepts/checkbox.lua | 19 +- expcore/gui/concepts/dropdown.lua | 20 +- expcore/gui/concepts/elem_button.lua | 28 +-- expcore/gui/concepts/slider.lua | 75 ++++++++ expcore/gui/core.lua | 13 ++ expcore/gui/prototype.lua | 18 +- expcore/gui/test.lua | 96 ++++++++-- 101 files changed, 549 insertions(+), 161 deletions(-) create mode 100644 expcore/gui/concepts/slider.lua diff --git a/docs/addons/Advanced-Start.html b/docs/addons/Advanced-Start.html index fac87435..db08d972 100644 --- a/docs/addons/Advanced-Start.html +++ b/docs/addons/Advanced-Start.html @@ -348,7 +348,7 @@ generated by LDoc diff --git a/docs/addons/Chat-Popups.html b/docs/addons/Chat-Popups.html index fb1aed14..0dab0ebb 100644 --- a/docs/addons/Chat-Popups.html +++ b/docs/addons/Chat-Popups.html @@ -349,7 +349,7 @@ generated by LDoc diff --git a/docs/addons/Chat-Reply.html b/docs/addons/Chat-Reply.html index f67c7100..319b02b1 100644 --- a/docs/addons/Chat-Reply.html +++ b/docs/addons/Chat-Reply.html @@ -376,7 +376,7 @@ generated by LDoc diff --git a/docs/addons/Compilatron.html b/docs/addons/Compilatron.html index 1867f7c4..b91ba11d 100644 --- a/docs/addons/Compilatron.html +++ b/docs/addons/Compilatron.html @@ -585,7 +585,7 @@ generated by LDoc diff --git a/docs/addons/Damage-Popups.html b/docs/addons/Damage-Popups.html index 669a44a1..2fc16b82 100644 --- a/docs/addons/Damage-Popups.html +++ b/docs/addons/Damage-Popups.html @@ -349,7 +349,7 @@ generated by LDoc diff --git a/docs/addons/Death-Logger.html b/docs/addons/Death-Logger.html index a54f6e89..cd75a0ba 100644 --- a/docs/addons/Death-Logger.html +++ b/docs/addons/Death-Logger.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/addons/Discord-Alerts.html b/docs/addons/Discord-Alerts.html index cdfd6557..2b7b0567 100644 --- a/docs/addons/Discord-Alerts.html +++ b/docs/addons/Discord-Alerts.html @@ -460,7 +460,7 @@ generated by LDoc diff --git a/docs/addons/Player-Colours.html b/docs/addons/Player-Colours.html index cbadfe62..d2bfde6a 100644 --- a/docs/addons/Player-Colours.html +++ b/docs/addons/Player-Colours.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/addons/Pollution-Grading.html b/docs/addons/Pollution-Grading.html index 48e68d6e..e7098e3f 100644 --- a/docs/addons/Pollution-Grading.html +++ b/docs/addons/Pollution-Grading.html @@ -320,7 +320,7 @@ generated by LDoc diff --git a/docs/addons/Scorched-Earth.html b/docs/addons/Scorched-Earth.html index fea61aeb..e0ffa93c 100644 --- a/docs/addons/Scorched-Earth.html +++ b/docs/addons/Scorched-Earth.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/addons/Spawn-Area.html b/docs/addons/Spawn-Area.html index cdc65900..bd36335a 100644 --- a/docs/addons/Spawn-Area.html +++ b/docs/addons/Spawn-Area.html @@ -376,7 +376,7 @@ generated by LDoc diff --git a/docs/commands/Admin-Chat.html b/docs/commands/Admin-Chat.html index 02095229..ab42bec5 100644 --- a/docs/commands/Admin-Chat.html +++ b/docs/commands/Admin-Chat.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Bonus.html b/docs/commands/Bonus.html index 2c7f2f13..14323d1e 100644 --- a/docs/commands/Bonus.html +++ b/docs/commands/Bonus.html @@ -500,7 +500,7 @@ generated by LDoc diff --git a/docs/commands/Cheat-Mode.html b/docs/commands/Cheat-Mode.html index 5167e8a3..083b32fe 100644 --- a/docs/commands/Cheat-Mode.html +++ b/docs/commands/Cheat-Mode.html @@ -361,7 +361,7 @@ generated by LDoc diff --git a/docs/commands/Clear-Inventory.html b/docs/commands/Clear-Inventory.html index add5b72a..e5998899 100644 --- a/docs/commands/Clear-Inventory.html +++ b/docs/commands/Clear-Inventory.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Debug.html b/docs/commands/Debug.html index aed6e1cd..290d58a9 100644 --- a/docs/commands/Debug.html +++ b/docs/commands/Debug.html @@ -365,7 +365,7 @@ generated by LDoc diff --git a/docs/commands/Find.html b/docs/commands/Find.html index 83f04b51..e466bfd8 100644 --- a/docs/commands/Find.html +++ b/docs/commands/Find.html @@ -360,7 +360,7 @@ generated by LDoc diff --git a/docs/commands/Help.html b/docs/commands/Help.html index 1ce2c9c7..f7e4975b 100644 --- a/docs/commands/Help.html +++ b/docs/commands/Help.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/commands/Home.html b/docs/commands/Home.html index 620a6927..067a4076 100644 --- a/docs/commands/Home.html +++ b/docs/commands/Home.html @@ -458,7 +458,7 @@ generated by LDoc diff --git a/docs/commands/Interface.html b/docs/commands/Interface.html index a8be6f65..d280a73d 100644 --- a/docs/commands/Interface.html +++ b/docs/commands/Interface.html @@ -416,7 +416,7 @@ generated by LDoc diff --git a/docs/commands/Jail.html b/docs/commands/Jail.html index e7baa4a2..93a8b942 100644 --- a/docs/commands/Jail.html +++ b/docs/commands/Jail.html @@ -611,7 +611,7 @@ generated by LDoc diff --git a/docs/commands/Kill.html b/docs/commands/Kill.html index 01af9a7b..50690c73 100644 --- a/docs/commands/Kill.html +++ b/docs/commands/Kill.html @@ -389,7 +389,7 @@ generated by LDoc diff --git a/docs/commands/Me.html b/docs/commands/Me.html index a566461f..5b167987 100644 --- a/docs/commands/Me.html +++ b/docs/commands/Me.html @@ -360,7 +360,7 @@ generated by LDoc diff --git a/docs/commands/Rainbow.html b/docs/commands/Rainbow.html index 528dcb0a..ead5dc2e 100644 --- a/docs/commands/Rainbow.html +++ b/docs/commands/Rainbow.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Repair.html b/docs/commands/Repair.html index 379eb796..f363411e 100644 --- a/docs/commands/Repair.html +++ b/docs/commands/Repair.html @@ -321,7 +321,7 @@ generated by LDoc diff --git a/docs/commands/Reports.html b/docs/commands/Reports.html index 823053bd..d234cfa7 100644 --- a/docs/commands/Reports.html +++ b/docs/commands/Reports.html @@ -585,7 +585,7 @@ generated by LDoc diff --git a/docs/commands/Roles.html b/docs/commands/Roles.html index f4b345cc..32d24195 100644 --- a/docs/commands/Roles.html +++ b/docs/commands/Roles.html @@ -557,7 +557,7 @@ generated by LDoc diff --git a/docs/commands/Spawn.html b/docs/commands/Spawn.html index fa096552..a88bdecf 100644 --- a/docs/commands/Spawn.html +++ b/docs/commands/Spawn.html @@ -389,7 +389,7 @@ generated by LDoc diff --git a/docs/commands/Tag.html b/docs/commands/Tag.html index 490b4d15..9438cddc 100644 --- a/docs/commands/Tag.html +++ b/docs/commands/Tag.html @@ -443,7 +443,7 @@ generated by LDoc diff --git a/docs/commands/Teleport.html b/docs/commands/Teleport.html index cbf8bca6..9478e557 100644 --- a/docs/commands/Teleport.html +++ b/docs/commands/Teleport.html @@ -484,7 +484,7 @@ generated by LDoc diff --git a/docs/commands/Warnings.html b/docs/commands/Warnings.html index 4cf981c7..2e0a0c76 100644 --- a/docs/commands/Warnings.html +++ b/docs/commands/Warnings.html @@ -569,7 +569,7 @@ generated by LDoc diff --git a/docs/configs/Advanced-Start.html b/docs/configs/Advanced-Start.html index 42e2964c..cbb5cc3d 100644 --- a/docs/configs/Advanced-Start.html +++ b/docs/configs/Advanced-Start.html @@ -506,7 +506,7 @@ generated by LDoc diff --git a/docs/configs/Bonuses.html b/docs/configs/Bonuses.html index 0537a1ae..eecdb55b 100644 --- a/docs/configs/Bonuses.html +++ b/docs/configs/Bonuses.html @@ -237,7 +237,7 @@ generated by LDoc diff --git a/docs/configs/Chat-Reply.html b/docs/configs/Chat-Reply.html index 78489463..77eac0c3 100644 --- a/docs/configs/Chat-Reply.html +++ b/docs/configs/Chat-Reply.html @@ -485,7 +485,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Admin.html b/docs/configs/Commands-Auth-Admin.html index b5d967a2..f84fb637 100644 --- a/docs/configs/Commands-Auth-Admin.html +++ b/docs/configs/Commands-Auth-Admin.html @@ -294,7 +294,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Roles.html b/docs/configs/Commands-Auth-Roles.html index e7b05121..dbe34891 100644 --- a/docs/configs/Commands-Auth-Roles.html +++ b/docs/configs/Commands-Auth-Roles.html @@ -320,7 +320,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Runtime-Disable.html b/docs/configs/Commands-Auth-Runtime-Disable.html index 1efdf6ee..1531abfd 100644 --- a/docs/configs/Commands-Auth-Runtime-Disable.html +++ b/docs/configs/Commands-Auth-Runtime-Disable.html @@ -442,7 +442,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Parse-Roles.html b/docs/configs/Commands-Parse-Roles.html index 9a3828fe..877f1556 100644 --- a/docs/configs/Commands-Parse-Roles.html +++ b/docs/configs/Commands-Parse-Roles.html @@ -354,7 +354,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Parse.html b/docs/configs/Commands-Parse.html index 96d3023d..aedabc41 100644 --- a/docs/configs/Commands-Parse.html +++ b/docs/configs/Commands-Parse.html @@ -338,7 +338,7 @@ see ./expcore/commands.lua for more details

    generated by LDoc diff --git a/docs/configs/Compilatron.html b/docs/configs/Compilatron.html index df1dfd7c..49196ffd 100644 --- a/docs/configs/Compilatron.html +++ b/docs/configs/Compilatron.html @@ -354,7 +354,7 @@ generated by LDoc diff --git a/docs/configs/Death-Logger.html b/docs/configs/Death-Logger.html index 05bd91dd..6696e94b 100644 --- a/docs/configs/Death-Logger.html +++ b/docs/configs/Death-Logger.html @@ -416,7 +416,7 @@ generated by LDoc diff --git a/docs/configs/Discord-Alerts.html b/docs/configs/Discord-Alerts.html index a917fb49..28f5b906 100644 --- a/docs/configs/Discord-Alerts.html +++ b/docs/configs/Discord-Alerts.html @@ -237,7 +237,7 @@ generated by LDoc diff --git a/docs/configs/File-Loader.html b/docs/configs/File-Loader.html index 63292dc1..1a46e4cf 100644 --- a/docs/configs/File-Loader.html +++ b/docs/configs/File-Loader.html @@ -240,7 +240,7 @@ generated by LDoc diff --git a/docs/configs/Permission-Groups.html b/docs/configs/Permission-Groups.html index 34f79892..22eb6228 100644 --- a/docs/configs/Permission-Groups.html +++ b/docs/configs/Permission-Groups.html @@ -295,7 +295,7 @@ generated by LDoc diff --git a/docs/configs/Player-List.html b/docs/configs/Player-List.html index 51bae4fd..cf496eff 100644 --- a/docs/configs/Player-List.html +++ b/docs/configs/Player-List.html @@ -812,7 +812,7 @@ generated by LDoc diff --git a/docs/configs/Pollution-Grading.html b/docs/configs/Pollution-Grading.html index 94422ee0..a82ddebe 100644 --- a/docs/configs/Pollution-Grading.html +++ b/docs/configs/Pollution-Grading.html @@ -384,7 +384,7 @@ generated by LDoc diff --git a/docs/configs/Popup-Messages.html b/docs/configs/Popup-Messages.html index 16b8eff8..659d3f76 100644 --- a/docs/configs/Popup-Messages.html +++ b/docs/configs/Popup-Messages.html @@ -414,7 +414,7 @@ generated by LDoc diff --git a/docs/configs/Preset-Player-Colours.html b/docs/configs/Preset-Player-Colours.html index b8ca80a1..5e487dad 100644 --- a/docs/configs/Preset-Player-Colours.html +++ b/docs/configs/Preset-Player-Colours.html @@ -324,7 +324,7 @@ generated by LDoc diff --git a/docs/configs/Repair.html b/docs/configs/Repair.html index d0bf54de..2fcc9ed7 100644 --- a/docs/configs/Repair.html +++ b/docs/configs/Repair.html @@ -414,7 +414,7 @@ generated by LDoc diff --git a/docs/configs/Rockets.html b/docs/configs/Rockets.html index 3bd16022..58b57990 100644 --- a/docs/configs/Rockets.html +++ b/docs/configs/Rockets.html @@ -834,7 +834,7 @@ generated by LDoc diff --git a/docs/configs/Roles.html b/docs/configs/Roles.html index 7c8665c8..55823fe3 100644 --- a/docs/configs/Roles.html +++ b/docs/configs/Roles.html @@ -292,7 +292,7 @@ generated by LDoc diff --git a/docs/configs/Science.html b/docs/configs/Science.html index 4a829958..1d26d319 100644 --- a/docs/configs/Science.html +++ b/docs/configs/Science.html @@ -354,7 +354,7 @@ generated by LDoc diff --git a/docs/configs/Scorched-Earth.html b/docs/configs/Scorched-Earth.html index 3ee50e94..424aec99 100644 --- a/docs/configs/Scorched-Earth.html +++ b/docs/configs/Scorched-Earth.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/configs/Spawn-Area.html b/docs/configs/Spawn-Area.html index a320c897..5f2d3c3a 100644 --- a/docs/configs/Spawn-Area.html +++ b/docs/configs/Spawn-Area.html @@ -744,7 +744,7 @@ generated by LDoc diff --git a/docs/configs/Tasks.html b/docs/configs/Tasks.html index e3b6d034..a2e222bc 100644 --- a/docs/configs/Tasks.html +++ b/docs/configs/Tasks.html @@ -384,7 +384,7 @@ generated by LDoc diff --git a/docs/configs/Warnings.html b/docs/configs/Warnings.html index 2e3b3df7..a8ffe551 100644 --- a/docs/configs/Warnings.html +++ b/docs/configs/Warnings.html @@ -355,7 +355,7 @@ generated by LDoc diff --git a/docs/configs/Warps.html b/docs/configs/Warps.html index f32aafed..cb16c531 100644 --- a/docs/configs/Warps.html +++ b/docs/configs/Warps.html @@ -684,7 +684,7 @@ generated by LDoc diff --git a/docs/control/Jail.html b/docs/control/Jail.html index a5cfdf31..7af5c571 100644 --- a/docs/control/Jail.html +++ b/docs/control/Jail.html @@ -1208,7 +1208,7 @@ generated by LDoc diff --git a/docs/control/Production.html b/docs/control/Production.html index 07b51b32..def7e25c 100644 --- a/docs/control/Production.html +++ b/docs/control/Production.html @@ -1329,7 +1329,7 @@ generated by LDoc diff --git a/docs/control/Reports.html b/docs/control/Reports.html index 677291b4..822446ea 100644 --- a/docs/control/Reports.html +++ b/docs/control/Reports.html @@ -1110,7 +1110,7 @@ generated by LDoc diff --git a/docs/control/Rockets.html b/docs/control/Rockets.html index e765ea4d..f8ca492e 100644 --- a/docs/control/Rockets.html +++ b/docs/control/Rockets.html @@ -984,7 +984,7 @@ generated by LDoc diff --git a/docs/control/Tasks.html b/docs/control/Tasks.html index f7d7e25b..c9a71a5d 100644 --- a/docs/control/Tasks.html +++ b/docs/control/Tasks.html @@ -1039,7 +1039,7 @@ generated by LDoc diff --git a/docs/control/Warnings.html b/docs/control/Warnings.html index 9109db95..4b8ebd2d 100644 --- a/docs/control/Warnings.html +++ b/docs/control/Warnings.html @@ -1465,7 +1465,7 @@ generated by LDoc diff --git a/docs/control/Warps.html b/docs/control/Warps.html index e40b5944..f0a6938d 100644 --- a/docs/control/Warps.html +++ b/docs/control/Warps.html @@ -1413,7 +1413,7 @@ generated by LDoc diff --git a/docs/core/Commands.html b/docs/core/Commands.html index 552f913d..fb2c4ff5 100644 --- a/docs/core/Commands.html +++ b/docs/core/Commands.html @@ -1972,7 +1972,7 @@ generated by LDoc diff --git a/docs/core/Common-Library.html b/docs/core/Common-Library.html index fd82f345..1f26b637 100644 --- a/docs/core/Common-Library.html +++ b/docs/core/Common-Library.html @@ -369,6 +369,10 @@
    + + + +
    table_insert(tbl[, start_index], tbl2) Much faster method for inserting keys into a table
    resolve_value(value)Used to resolve a value that could also be a function returning that value
    @@ -2664,6 +2668,68 @@ Common.array_insert(tbl,500,values) -- around 50,tbl2) + +
    +
    +
    + # + resolve_value(value) +
    +
    +
    +
    + +

    Used to resolve a value that could also be a function returning that value

    +

    + + + Parameters: + +
      + + + + + +
    • + + value + + : + + (any) + + the value which you want to test is not nil and if it is a function then call the function + +
    • + + +
    + + + + + Returns: +
      +
    • + (any) + the value given or returned by value if it is a function +
    • +
    + + + + + + + + Usage: +
    -- Default value handling
    +-- if default value is not a function then it is returned
    +-- if it is a function then it is called with the first argument being self
    +local value = Common.resolve_value(self.defaut_value,self)
    + +
    @@ -2680,7 +2746,7 @@ Common.table_insert(tbl,50,tbl2) generated by LDoc diff --git a/docs/core/Gui.html b/docs/core/Gui.html index 23c3bc23..55190867 100644 --- a/docs/core/Gui.html +++ b/docs/core/Gui.html @@ -344,6 +344,10 @@ button:clone('CustomButton') progress_bar The basic checkbox element + + slider + The basic slider element + @@ -777,7 +781,7 @@ Gui.clone_concept('button','spr
  • - on_state_change + on_state_changed : @@ -822,6 +826,22 @@ Gui.clone_concept('button','spr +
  • + + default + + : + + (boolean or function) + + the default state of this checkbox, or a function which returns the default state + +
  • + + + + +
  • use_radio @@ -853,7 +873,7 @@ Gui.clone_concept('button','spr Gui.clone_concept('checkbox','basic_checkbox') :set_caption('Basic Checkbox') :set_tooltip('Basic checkbox') -:on_state_change(function(event) +:on_state_changed(function(event) event.player.print('Basic checkbox is now: '..tostring(event.element.state)) end) @@ -883,7 +903,7 @@ Gui.clone_concept('checkbox','b
  • - on_selection_change + on_selection_changed : @@ -898,7 +918,7 @@ Gui.clone_concept('checkbox','b
  • - default_selection + default : @@ -974,7 +994,7 @@ Gui.clone_concept('checkbox','b local static_dropdown = Gui.clone_concept('dropdown','static_dropdown') :set_static_items{'Option 1','Option 2','Option 3'} -:on_selection_change(function(event) +:on_selection_changed(function(event) local value = Gui.get_dropdown_value(event.element) event.player.print('Static dropdown is now: '..value) end) @@ -988,7 +1008,7 @@ Gui.clone_concept('dropdown','d end return items end) -:on_selection_change(function(event) +:on_selection_changed(function(event) local value = Gui.get_dropdown_value(event.element) event.player.print('Dynamic dropdown is now: '..value) end) @@ -1019,7 +1039,7 @@ Gui.clone_concept('dropdown','d
  • - on_selection_change + on_selection_changed : @@ -1034,7 +1054,7 @@ Gui.clone_concept('dropdown','d
  • - default_selection + default : @@ -1077,7 +1097,7 @@ Gui.clone_concept('dropdown','d
    -- Making a basic elem button
     local basic_elem_button =
     Gui.clone_concept('elem_button','basic_elembutton')
    -:on_selection_change(function(event)
    +:on_selection_changed(function(event)
         event.player.print('Basic elem button is now: '..event.element.elem_value)
     end)
    @@ -1286,6 +1306,136 @@ Gui.clone_concept('progress_bar',end) + +
    +
    +
    + # + slider +
    +
    +
    +
    + +

    The basic slider element

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + on_value_changed + + : + + + fired when the value of the slider is changed + +
    • + + + + + +
    • + + value_step + + : + + (number) + + the minimum amount by which the value of the slider can be changed + +
    • + + + + + +
    • + + default + + : + + (number or function) + + the default value of the slider or a function which returns the default value + +
    • + + + + + +
    • + + discrete_slider + + : + + (boolean) + + makes this slider a discrete slider (at time of writing unsure what this is) + +
    • + + + + + +
    • + + range + + : + + (number or function) + + 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')
    +: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')
    +: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)
    + +

    Dropdowns

    @@ -4285,12 +4435,12 @@ custom_button.update_data(1,fu Gui.get_concept('checkbox'):clone('my_checkbox') :set_caption('My Checkbox') :set_tooltip('Clicking this check box will change it for everyone') -:on_state_change(function(event) +:on_state_changed(function(event) local element = event.element event.concept.set_data(element,element.state) -- Update the stored data to trigger an update of all other instances end) :define_combined_store(function(element,state) -- We could add a category function here if we wanted to - element.state = state or false -- When you sync an instance this is what is called + element.state = state or false -- Note that the value passed may be nil if there is no stored value and no default set end) @@ -4440,7 +4590,7 @@ Gui.get_concept('CustomButton') generated by LDoc diff --git a/docs/core/Permissions-Groups.html b/docs/core/Permissions-Groups.html index 71ae873e..88c9d301 100644 --- a/docs/core/Permissions-Groups.html +++ b/docs/core/Permissions-Groups.html @@ -1432,7 +1432,7 @@ generated by LDoc diff --git a/docs/core/Roles.html b/docs/core/Roles.html index 86992767..939c59a1 100644 --- a/docs/core/Roles.html +++ b/docs/core/Roles.html @@ -3152,7 +3152,7 @@ generated by LDoc diff --git a/docs/core/Store.html b/docs/core/Store.html index 7efa78fb..e518d5a6 100644 --- a/docs/core/Store.html +++ b/docs/core/Store.html @@ -1145,7 +1145,7 @@ Store.register(team_scores,function(value,key) generated by LDoc diff --git a/docs/core/Sudo.html b/docs/core/Sudo.html index b05c3b4d..36b4a432 100644 --- a/docs/core/Sudo.html +++ b/docs/core/Sudo.html @@ -544,7 +544,7 @@ generated by LDoc diff --git a/docs/guis/Player-List.html b/docs/guis/Player-List.html index e12e78e5..6c70132d 100644 --- a/docs/guis/Player-List.html +++ b/docs/guis/Player-List.html @@ -626,7 +626,7 @@ generated by LDoc diff --git a/docs/guis/Rocket-Info.html b/docs/guis/Rocket-Info.html index 43160544..ab679073 100644 --- a/docs/guis/Rocket-Info.html +++ b/docs/guis/Rocket-Info.html @@ -629,7 +629,7 @@ generated by LDoc diff --git a/docs/guis/Science-Info.html b/docs/guis/Science-Info.html index 1a8c6e7c..c59424c9 100644 --- a/docs/guis/Science-Info.html +++ b/docs/guis/Science-Info.html @@ -449,7 +449,7 @@ generated by LDoc diff --git a/docs/guis/Task-List.html b/docs/guis/Task-List.html index 224ac51e..bb660351 100644 --- a/docs/guis/Task-List.html +++ b/docs/guis/Task-List.html @@ -632,7 +632,7 @@ generated by LDoc diff --git a/docs/guis/Warps-List.html b/docs/guis/Warps-List.html index 099c1978..66885bbe 100644 --- a/docs/guis/Warps-List.html +++ b/docs/guis/Warps-List.html @@ -837,7 +837,7 @@ generated by LDoc diff --git a/docs/index.html b/docs/index.html index 6a63a39c..7ed6c8dd 100644 --- a/docs/index.html +++ b/docs/index.html @@ -510,7 +510,7 @@ see ./expcore/commands.lua for more details generated by LDoc diff --git a/docs/modules/control.html b/docs/modules/control.html index e147afc2..5723e3d4 100644 --- a/docs/modules/control.html +++ b/docs/modules/control.html @@ -351,7 +351,7 @@ generated by LDoc diff --git a/docs/modules/utils.alien_evolution_progress.html b/docs/modules/utils.alien_evolution_progress.html index 6d93ca08..8de5f2be 100644 --- a/docs/modules/utils.alien_evolution_progress.html +++ b/docs/modules/utils.alien_evolution_progress.html @@ -419,7 +419,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 702fd931..738a0e75 100644 --- a/docs/modules/utils.core.html +++ b/docs/modules/utils.core.html @@ -1164,7 +1164,7 @@ generated by LDoc diff --git a/docs/modules/utils.debug.html b/docs/modules/utils.debug.html index 56614959..c560bc9d 100644 --- a/docs/modules/utils.debug.html +++ b/docs/modules/utils.debug.html @@ -654,7 +654,7 @@ generated by LDoc diff --git a/docs/modules/utils.dump_env.html b/docs/modules/utils.dump_env.html index 4b36cbfc..74e7ec8a 100644 --- a/docs/modules/utils.dump_env.html +++ b/docs/modules/utils.dump_env.html @@ -323,7 +323,7 @@ generated by LDoc diff --git a/docs/modules/utils.event.html b/docs/modules/utils.event.html index 71a4e2ad..0f324e4b 100644 --- a/docs/modules/utils.event.html +++ b/docs/modules/utils.event.html @@ -1292,7 +1292,7 @@ generated by LDoc diff --git a/docs/modules/utils.event_core.html b/docs/modules/utils.event_core.html index 3eeb9117..c2a42b72 100644 --- a/docs/modules/utils.event_core.html +++ b/docs/modules/utils.event_core.html @@ -434,7 +434,7 @@ generated by LDoc diff --git a/docs/modules/utils.math.html b/docs/modules/utils.math.html index 69f8200f..b53b1a2c 100644 --- a/docs/modules/utils.math.html +++ b/docs/modules/utils.math.html @@ -338,7 +338,7 @@ generated by LDoc diff --git a/docs/modules/utils.recipe_locker.html b/docs/modules/utils.recipe_locker.html index bbc2686b..6ba6a2cc 100644 --- a/docs/modules/utils.recipe_locker.html +++ b/docs/modules/utils.recipe_locker.html @@ -441,7 +441,7 @@ generated by LDoc diff --git a/docs/modules/utils.state_machine.html b/docs/modules/utils.state_machine.html index 7a91a65a..a7c7ae1c 100644 --- a/docs/modules/utils.state_machine.html +++ b/docs/modules/utils.state_machine.html @@ -752,7 +752,7 @@ generated by LDoc diff --git a/docs/modules/utils.table.html b/docs/modules/utils.table.html index 5952d586..71fdfc28 100644 --- a/docs/modules/utils.table.html +++ b/docs/modules/utils.table.html @@ -1382,7 +1382,7 @@ generated by LDoc diff --git a/docs/modules/utils.task.html b/docs/modules/utils.task.html index 9f7f258d..c5a2596d 100644 --- a/docs/modules/utils.task.html +++ b/docs/modules/utils.task.html @@ -651,7 +651,7 @@ generated by LDoc diff --git a/docs/modules/utils.timestamp.html b/docs/modules/utils.timestamp.html index d0cb161c..2a54826a 100644 --- a/docs/modules/utils.timestamp.html +++ b/docs/modules/utils.timestamp.html @@ -442,7 +442,7 @@ generated by LDoc diff --git a/docs/topics/license.html b/docs/topics/license.html index 1c917750..927f857f 100644 --- a/docs/topics/license.html +++ b/docs/topics/license.html @@ -789,7 +789,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 abe6555d..9ced810b 100644 --- a/docs/topics/readme.md.html +++ b/docs/topics/readme.md.html @@ -332,7 +332,7 @@ generated by LDoc diff --git a/expcore/common.lua b/expcore/common.lua index d465e4d8..81192344 100644 --- a/expcore/common.lua +++ b/expcore/common.lua @@ -682,4 +682,22 @@ function Common.table_insert(tbl,start_index,tbl2) return tbl end +--[[-- Used to resolve a value that could also be a function returning that value +@tparam any value the value which you want to test is not nil and if it is a function then call the function +@treturn any the value given or returned by value if it is a function +@usage-- Default value handling +-- if default value is not a function then it is returned +-- if it is a function then it is called with the first argument being self +local value = Common.resolve_value(self.defaut_value,self) +]] +function Common.resolve_value(value,...) + if value then + if type(value) == 'function' then + return value(...) + else + return value + end + end +end + return Common \ No newline at end of file diff --git a/expcore/gui.lua b/expcore/gui.lua index ae17446b..7f28c635 100644 --- a/expcore/gui.lua +++ b/expcore/gui.lua @@ -73,5 +73,6 @@ Gui.require_concept('checkbox') Gui.require_concept('dropdown') Gui.require_concept('elem_button') Gui.require_concept('progress_bar') +Gui.require_concept('slider') return Gui \ No newline at end of file diff --git a/expcore/gui/concepts/checkbox.lua b/expcore/gui/concepts/checkbox.lua index a9f43a1f..0de6befc 100644 --- a/expcore/gui/concepts/checkbox.lua +++ b/expcore/gui/concepts/checkbox.lua @@ -7,33 +7,42 @@ local Gui = require 'expcore.gui.core' --[[-- The basic checkbox element @element checkbox -@param on_state_change fired when the state of the element is changed +@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') :set_caption('Basic Checkbox') :set_tooltip('Basic checkbox') -:on_state_change(function(event) +:on_state_changed(function(event) event.player.print('Basic checkbox is now: '..tostring(event.element.state)) end) ]] Gui.new_concept('checkbox') -:new_event('on_state_change',defines.events.on_gui_checked_state_changed) +:new_event('on_state_changed',defines.events.on_gui_checked_state_changed) :new_property('tooltip') :new_property('caption') -:new_property('default_state',false) +:new_property('default',false) :new_property('use_radio',false) :define_draw(function(properties,parent,element) + local default = properties.default + local state = type(default) == 'boolean' and default + element = parent.add{ name = properties.name, type = properties.use_radio and 'radiobutton' or 'checkbox', caption = properties.caption, tooltip = properties.tooltip, - state = properties.default_state + state = state } + default = Gui.resolve_property(default,element) + if default and default ~= state then + element.state = default + end + return element end) \ No newline at end of file diff --git a/expcore/gui/concepts/dropdown.lua b/expcore/gui/concepts/dropdown.lua index ee3f8346..c4e651df 100644 --- a/expcore/gui/concepts/dropdown.lua +++ b/expcore/gui/concepts/dropdown.lua @@ -8,8 +8,8 @@ local array_insert = ext_require('expcore.common','array_insert') --[[-- The basic dropdown element @element dropdown -@param on_selection_change fired when the selected value is changed -@tparam ?string|Concepts.LocalisedString|function default_selection the option which is selected by default, or a function which returns the default +@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 @@ -17,7 +17,7 @@ local array_insert = ext_require('expcore.common','array_insert') local static_dropdown = Gui.clone_concept('dropdown','static_dropdown') :set_static_items{'Option 1','Option 2','Option 3'} -:on_selection_change(function(event) +:on_selection_changed(function(event) local value = Gui.get_dropdown_value(event.element) event.player.print('Static dropdown is now: '..value) end) @@ -31,14 +31,14 @@ Gui.clone_concept('dropdown','dynamic_dropdown') end return items end) -:on_selection_change(function(event) +:on_selection_changed(function(event) local value = Gui.get_dropdown_value(event.element) event.player.print('Dynamic dropdown is now: '..value) end) ]] Gui.new_concept('dropdown') -:new_event('on_selection_change',defines.events.on_gui_selection_state_changed) -:new_property('default_selection') +:new_event('on_selection_changed',defines.events.on_gui_selection_state_changed) +:new_property('default') :new_property('use_list_box',false) :new_property('static_items',nil,function(properties,value,start_index) if not value then @@ -87,12 +87,8 @@ end) end end - if properties.default_selection then - local default = properties.default_selection - if type(default) == 'function' then - default = default(element) - end - + local default = Gui.resolve_property(properties.default,element) + if default then Gui.set_dropdown_value(element,default) end diff --git a/expcore/gui/concepts/elem_button.lua b/expcore/gui/concepts/elem_button.lua index cbbd0753..6b51fbf1 100644 --- a/expcore/gui/concepts/elem_button.lua +++ b/expcore/gui/concepts/elem_button.lua @@ -7,42 +7,30 @@ local Gui = require 'expcore.gui.core' --[[-- The basic dropdown element @element elem_button -@param on_selection_change fired when the selected value is changed -@tparam ?string|Concepts.SignalID|function default_selection the option which is selected by default, or a function which returns the default +@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') -:on_selection_change(function(event) +:on_selection_changed(function(event) event.player.print('Basic elem button is now: '..event.element.elem_value) end) ]] Gui.new_concept('elem_button') -:new_event('on_selection_change',defines.events.on_gui_elem_changed) -:new_property('default_selection') +:new_event('on_selection_changed',defines.events.on_gui_elem_changed) +:new_property('default') :new_property('elem_type','item') -:define_draw(function(properties,parent,element,selection) +:define_draw(function(properties,parent,element) element = parent.add{ name = properties.name, type = 'choose-elem-button', elem_type = properties.elem_type } - if properties.default_selection and not selection then - local default = properties.default_selection - if type(default) == 'function' then - default = default(element) - end - + local default = Gui.resolve_property(properties.default,element) + if default then element.elem_value = default - - elseif selection then - if type(selection) == 'function' then - selection = selection(element) - end - - element.elem_value = selection - end return element diff --git a/expcore/gui/concepts/slider.lua b/expcore/gui/concepts/slider.lua new file mode 100644 index 00000000..b58792d3 --- /dev/null +++ b/expcore/gui/concepts/slider.lua @@ -0,0 +1,75 @@ +--[[-- Core Module - Gui + @module Gui + @alias Gui +]] + +local Gui = require 'expcore.gui.core' + +--[[-- The basic slider element +@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 (at time of writing unsure what this is) +@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') +: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') +: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') +:new_event('on_value_changed',defines.events.on_gui_value_changed) +:new_property('value_step') +:new_property('default') +:new_property('discrete_slider',false) +:new_property('range',nil,function(properties,minimum,maximum) + if type(minimum) == 'function' then + properties.range = minimum + else + properties.minimum = minimum + properties.maximum = maximum + end +end) +:define_draw(function(properties,parent,element) + local default = properties.default + local value = type(default) == 'number' and default + local value_step = properties.value_step + + element = parent.add{ + name = properties.name, + type = 'slider', + caption = properties.caption, + minimum_value = properties.minimum, + maximum_value = properties.maximum, + discrete_slider = properties.discrete_slider, + discrete_values = value_step ~= nil, + value_step = value_step, + value = value + } + + local min, max = Gui.resolve_property(properties.range,element) + if min or max then + min = min or element.get_slider_minimum() + max = max or element.get_slider_maximum() + element.set_slider_minimum_maximum(min,max) + end + + default = Gui.resolve_property(default,element) + if default and default ~= value then + element.slider_value = default + end + + return element +end) \ No newline at end of file diff --git a/expcore/gui/core.lua b/expcore/gui/core.lua index 6329550f..08bec3d2 100644 --- a/expcore/gui/core.lua +++ b/expcore/gui/core.lua @@ -4,6 +4,7 @@ ]] local Game = require 'utils.game' -- @dep utils.game +local resolve_value = ext_require('expcore.common','resolve_value') -- @dep expcore.common local Prototype = require 'expcore.gui.prototype' local Gui = { @@ -186,6 +187,18 @@ function Gui.set_padding(element,up,down,left,right) style.right_padding = right == true and style.top_padding or right or 0 end +--[[ Used to check a property exists and if it is a function then call the function +@tparam any value the value that you are testing exists and call if its a function +@tparam LuaGuiElement element the element that is passed to the function if it is a function +@treturn any the value or what it returns if it is a function +@usage-- Getting the default value +local default = Gui.resolve_property(properties.default,element) +if default then + element.value = default +end +]] +Gui.resolve_property = resolve_value + --- Store Categories. -- Functions that are common types of categories -- @section store-categories diff --git a/expcore/gui/prototype.lua b/expcore/gui/prototype.lua index 2f08e255..5fb2629e 100644 --- a/expcore/gui/prototype.lua +++ b/expcore/gui/prototype.lua @@ -517,12 +517,13 @@ end) for key,instance in pairs(instances) do if not instance or not instance.valid then instances[key] = nil - end - if args then - update_callback(instance,unpack(args)) else - update_callback(instance,...) + if args then + update_callback(instance,unpack(args)) + else + update_callback(instance,...) + end end end end @@ -647,12 +648,12 @@ local custom_button = Gui.get_concept('checkbox'):clone('my_checkbox') :set_caption('My Checkbox') :set_tooltip('Clicking this check box will change it for everyone') -:on_state_change(function(event) +:on_state_changed(function(event) local element = event.element event.concept.set_data(element,element.state) -- Update the stored data to trigger an update of all other instances end) :define_combined_store(function(element,state) -- We could add a category function here if we wanted to - element.state = state or false -- When you sync an instance this is what is called + element.state = state or false -- Note that the value passed may be nil if there is no stored value and no default set end) ]] function Prototype:define_combined_store(category_callback,sync_callback) @@ -679,8 +680,11 @@ Gui.get_concept('CustomButton') -- Used internally when first draw and automatically when the store updates custom_button.sync_instance(element) ]] + local properties = self.properties function self.sync_instance(element) - sync_callback(element,self.get_data(element)) + local default = properties.default + local value = self.get_data(element) or type(default) == 'function' and default(element) or default + sync_callback(element,value) end return self diff --git a/expcore/gui/test.lua b/expcore/gui/test.lua index f28b4e93..f6d74988 100644 --- a/expcore/gui/test.lua +++ b/expcore/gui/test.lua @@ -157,7 +157,7 @@ local basic_checkbox = Gui.clone_concept('checkbox',TEST 'basic_checkbox') :set_caption('Basic Checkbox') :set_tooltip('Basic checkbox') -:on_state_change(function(event) +:on_state_changed(function(event) event.player.print('Basic checkbox is now: '..tostring(event.element.state)) end) @@ -165,7 +165,7 @@ local game_checkbox = Gui.clone_concept('checkbox',TEST 'game_checkbox') :set_caption('Game Stored Checkbox') :set_tooltip('Game stored checkbox') -:on_state_change(function(event) +:on_state_changed(function(event) local element = event.element event.concept.set_data(element,element.state) -- Update other instances event.player.print('Game stored checkbox is now: '..tostring(element.state)) @@ -178,7 +178,7 @@ local force_checkbox = Gui.clone_concept('checkbox',TEST 'force_checkbox') :set_caption('Force Stored Checkbox') :set_tooltip('Force stored checkbox') -:on_state_change(function(event) +:on_state_changed(function(event) local element = event.element event.concept.set_data(element,element.state) -- Update other instances event.player.print('Force stored checkbox is now: '..tostring(element.state)) @@ -191,7 +191,7 @@ local player_checkbox = Gui.clone_concept('checkbox',TEST 'player_checkbox') :set_caption('Player Stored Checkbox') :set_tooltip('Player stored checkbox') -:on_state_change(function(event) +:on_state_changed(function(event) local element = event.element event.concept.set_data(element,element.state) -- Update other instances event.player.print('Player stored checkbox is now: '..tostring(element.state)) @@ -218,7 +218,7 @@ Dropdowns local static_dropdown = Gui.clone_concept('dropdown',TEST 'static_dropdown') :set_static_items{'Option 1','Option 2','Option 3'} -:on_selection_change(function(event) +:on_selection_changed(function(event) local value = Gui.get_dropdown_value(event.element) event.player.print('Static dropdown is now: '..value) end) @@ -234,7 +234,7 @@ Gui.clone_concept('dropdown',TEST 'dynamic_dropdown') end return items end) -:on_selection_change(function(event) +:on_selection_changed(function(event) local value = Gui.get_dropdown_value(event.element) event.player.print('Dynamic dropdown is now: '..value) end) @@ -242,7 +242,7 @@ end) local static_player_dropdown = Gui.clone_concept('dropdown',TEST 'static_player_dropdown') :set_static_items{'Option 1','Option 2','Option 3'} -:on_selection_change(function(event) +:on_selection_changed(function(event) local element = event.element local value = Gui.get_dropdown_value(element) event.concept.set_data(element,value) @@ -263,7 +263,7 @@ Gui.clone_concept('dropdown',TEST 'dynamic_player_dropdown') end return items end) -:on_selection_change(function(event) +:on_selection_changed(function(event) local element = event.element local value = Gui.get_dropdown_value(element) event.concept.set_data(element,value) @@ -290,7 +290,7 @@ local static_listbox = Gui.clone_concept('dropdown',TEST 'static_listbox') :set_use_list_box(true) :set_static_items{'Option 1','Option 2','Option 3'} -:on_selection_change(function(event) +:on_selection_changed(function(event) local value = Gui.get_dropdown_value(event.element) event.player.print('Static listbox is now: '..value) end) @@ -299,7 +299,7 @@ local static_player_listbox = Gui.clone_concept('dropdown',TEST 'static_player_listbox') :set_use_list_box(true) :set_static_items{'Option 1','Option 2','Option 3'} -:on_selection_change(function(event) +:on_selection_changed(function(event) local element = event.element local value = Gui.get_dropdown_value(element) event.concept.set_data(element,value) @@ -323,15 +323,15 @@ Elem Buttons local basic_elem_button = Gui.clone_concept('elem_button',TEST 'basic_elembutton') -:on_selection_change(function(event) +: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') :set_elem_type('signal') -:set_default_selection{type='virtual',name='signal-info'} -:on_selection_change(function(event) +:set_default{type='virtual',name='signal-info'} +:on_selection_changed(function(event) local value = event.element.elem_value event.player.print('Default selection elem button is now: '..value.type..'/'..value.name) end) @@ -339,7 +339,7 @@ end) local player_elem_button = Gui.clone_concept('elem_button',TEST 'player_elem_button') :set_elem_type('technology') -:on_selection_change(function(event) +:on_selection_changed(function(event) local element = event.element local value = element.elem_value event.concept.set_data(element,value) @@ -446,4 +446,72 @@ tests['Progress Bars'] = { ['Game Instance Progress Bar'] = game_progress_bar, ['Force Instance Progress Bar'] = force_instance_progress_bar, ['Force Stored Progress Bar'] = force_stored_progress_bar +} + +--[[ +Sliders +> Basic Slider -- Just a basic slider with range 1 to 10 +> Interval Slider -- Same as above but can only be intergers +> Discrete Slider -- A discrete slider +> Dynamic Slider -- A slider which has a dynamic range +> Player Stored Slider -- Slider which stores the value per player, also goes 1 to 10 +]] + +local basic_slider = +Gui.clone_concept('slider',TEST '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') +:set_range(1,10) +:set_value_step(1) +:on_value_changed(function(event) + event.player.print('Interval slider is now: '..event.element.slider_value) +end) + +local discrete_slider = +Gui.clone_concept('slider',TEST 'discrete_slider') +:set_range(1,10) +:set_value_step(1) +:set_discrete_slider(true) +:on_value_changed(function(event) + event.player.print('Discrete slider is now: '..event.element.slider_value) +end) + +local dynamic_slider = +Gui.clone_concept('slider',TEST 'dynamic_slider') +:set_range(function(element) + local player = Gui.get_player_from_element(element) + return 1, player.name:len() +end) +:set_value_step(1) +:set_discrete_slider(true) +:on_value_changed(function(event) + event.player.print('Dynamic slider is now: '..event.element.slider_value) +end) + +local player_slider = +Gui.clone_concept('slider',TEST 'player_slider') +:set_range(1,10) +:set_value_step(1) +:set_discrete_slider(true) +:on_value_changed(function(event) + local element = event.element + local value = element.slider_value + event.concept.set_data(element,value) + event.player.print('Player stored slider is now: '..value) +end) +:define_combined_store(Gui.categorize_by_player,function(element,value) + element.slider_value = value or 0 +end) + +tests.Sliders = { + ['Basic Slider'] = basic_slider, + ['Interval Slider'] = interval_slider, + ['Discrete Slider'] = discrete_slider, + ['Dynamic Slider'] = dynamic_slider, + ['Player Stored Slider'] = player_slider } \ No newline at end of file From c67ccaddea842bf832702bb9d616891e2421bf16 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sun, 1 Sep 2019 19:16:08 +0100 Subject: [PATCH 14/26] Added text inputs --- docs/addons/Advanced-Start.html | 2 +- docs/addons/Chat-Popups.html | 2 +- docs/addons/Chat-Reply.html | 2 +- docs/addons/Compilatron.html | 2 +- docs/addons/Damage-Popups.html | 2 +- docs/addons/Death-Logger.html | 2 +- docs/addons/Discord-Alerts.html | 2 +- docs/addons/Player-Colours.html | 2 +- docs/addons/Pollution-Grading.html | 2 +- docs/addons/Scorched-Earth.html | 2 +- docs/addons/Spawn-Area.html | 2 +- docs/commands/Admin-Chat.html | 2 +- docs/commands/Bonus.html | 2 +- docs/commands/Cheat-Mode.html | 2 +- docs/commands/Clear-Inventory.html | 2 +- docs/commands/Debug.html | 2 +- docs/commands/Find.html | 2 +- docs/commands/Help.html | 2 +- docs/commands/Home.html | 2 +- docs/commands/Interface.html | 2 +- docs/commands/Jail.html | 2 +- docs/commands/Kill.html | 2 +- docs/commands/Me.html | 2 +- docs/commands/Rainbow.html | 2 +- docs/commands/Repair.html | 2 +- docs/commands/Reports.html | 2 +- docs/commands/Roles.html | 2 +- docs/commands/Spawn.html | 2 +- docs/commands/Tag.html | 2 +- docs/commands/Teleport.html | 2 +- docs/commands/Warnings.html | 2 +- docs/configs/Advanced-Start.html | 2 +- docs/configs/Bonuses.html | 2 +- docs/configs/Chat-Reply.html | 2 +- docs/configs/Commands-Auth-Admin.html | 2 +- docs/configs/Commands-Auth-Roles.html | 2 +- .../Commands-Auth-Runtime-Disable.html | 2 +- docs/configs/Commands-Parse-Roles.html | 2 +- docs/configs/Commands-Parse.html | 2 +- docs/configs/Compilatron.html | 2 +- docs/configs/Death-Logger.html | 2 +- docs/configs/Discord-Alerts.html | 2 +- docs/configs/File-Loader.html | 2 +- docs/configs/Permission-Groups.html | 2 +- docs/configs/Player-List.html | 2 +- docs/configs/Pollution-Grading.html | 2 +- docs/configs/Popup-Messages.html | 2 +- docs/configs/Preset-Player-Colours.html | 2 +- docs/configs/Repair.html | 2 +- docs/configs/Rockets.html | 2 +- docs/configs/Roles.html | 2 +- docs/configs/Science.html | 2 +- docs/configs/Scorched-Earth.html | 2 +- docs/configs/Spawn-Area.html | 2 +- docs/configs/Tasks.html | 2 +- docs/configs/Warnings.html | 2 +- docs/configs/Warps.html | 2 +- docs/control/Jail.html | 2 +- docs/control/Production.html | 2 +- docs/control/Reports.html | 2 +- docs/control/Rockets.html | 2 +- docs/control/Tasks.html | 2 +- docs/control/Warnings.html | 2 +- docs/control/Warps.html | 2 +- docs/core/Commands.html | 2 +- docs/core/Common-Library.html | 2 +- docs/core/Gui.html | 384 +++++++++++++++++- docs/core/Permissions-Groups.html | 2 +- docs/core/Roles.html | 2 +- docs/core/Store.html | 2 +- docs/core/Sudo.html | 2 +- docs/guis/Player-List.html | 2 +- docs/guis/Rocket-Info.html | 2 +- docs/guis/Science-Info.html | 2 +- docs/guis/Task-List.html | 2 +- docs/guis/Warps-List.html | 2 +- docs/index.html | 2 +- docs/modules/control.html | 2 +- .../utils.alien_evolution_progress.html | 2 +- docs/modules/utils.core.html | 2 +- docs/modules/utils.debug.html | 2 +- docs/modules/utils.dump_env.html | 2 +- docs/modules/utils.event.html | 2 +- docs/modules/utils.event_core.html | 2 +- docs/modules/utils.math.html | 2 +- docs/modules/utils.recipe_locker.html | 2 +- docs/modules/utils.state_machine.html | 2 +- docs/modules/utils.table.html | 2 +- docs/modules/utils.task.html | 2 +- docs/modules/utils.timestamp.html | 2 +- docs/topics/license.html | 2 +- docs/topics/readme.md.html | 2 +- expcore/gui.lua | 2 + expcore/gui/concepts/slider.lua | 2 +- expcore/gui/concepts/textbox.lua | 60 +++ expcore/gui/concepts/textfield.lua | 76 ++++ expcore/gui/test.lua | 94 +++++ 97 files changed, 706 insertions(+), 94 deletions(-) create mode 100644 expcore/gui/concepts/textbox.lua create mode 100644 expcore/gui/concepts/textfield.lua diff --git a/docs/addons/Advanced-Start.html b/docs/addons/Advanced-Start.html index db08d972..31d501d2 100644 --- a/docs/addons/Advanced-Start.html +++ b/docs/addons/Advanced-Start.html @@ -348,7 +348,7 @@ generated by LDoc diff --git a/docs/addons/Chat-Popups.html b/docs/addons/Chat-Popups.html index 0dab0ebb..0b71ec19 100644 --- a/docs/addons/Chat-Popups.html +++ b/docs/addons/Chat-Popups.html @@ -349,7 +349,7 @@ generated by LDoc diff --git a/docs/addons/Chat-Reply.html b/docs/addons/Chat-Reply.html index 319b02b1..0f83ae72 100644 --- a/docs/addons/Chat-Reply.html +++ b/docs/addons/Chat-Reply.html @@ -376,7 +376,7 @@ generated by LDoc diff --git a/docs/addons/Compilatron.html b/docs/addons/Compilatron.html index b91ba11d..6340ad99 100644 --- a/docs/addons/Compilatron.html +++ b/docs/addons/Compilatron.html @@ -585,7 +585,7 @@ generated by LDoc diff --git a/docs/addons/Damage-Popups.html b/docs/addons/Damage-Popups.html index 2fc16b82..cf61c396 100644 --- a/docs/addons/Damage-Popups.html +++ b/docs/addons/Damage-Popups.html @@ -349,7 +349,7 @@ generated by LDoc diff --git a/docs/addons/Death-Logger.html b/docs/addons/Death-Logger.html index cd75a0ba..58ecdcf1 100644 --- a/docs/addons/Death-Logger.html +++ b/docs/addons/Death-Logger.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/addons/Discord-Alerts.html b/docs/addons/Discord-Alerts.html index 2b7b0567..62e674db 100644 --- a/docs/addons/Discord-Alerts.html +++ b/docs/addons/Discord-Alerts.html @@ -460,7 +460,7 @@ generated by LDoc diff --git a/docs/addons/Player-Colours.html b/docs/addons/Player-Colours.html index d2bfde6a..9fdcc3ea 100644 --- a/docs/addons/Player-Colours.html +++ b/docs/addons/Player-Colours.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/addons/Pollution-Grading.html b/docs/addons/Pollution-Grading.html index e7098e3f..05cfe35c 100644 --- a/docs/addons/Pollution-Grading.html +++ b/docs/addons/Pollution-Grading.html @@ -320,7 +320,7 @@ generated by LDoc diff --git a/docs/addons/Scorched-Earth.html b/docs/addons/Scorched-Earth.html index e0ffa93c..13a983b4 100644 --- a/docs/addons/Scorched-Earth.html +++ b/docs/addons/Scorched-Earth.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/addons/Spawn-Area.html b/docs/addons/Spawn-Area.html index bd36335a..6a4b845e 100644 --- a/docs/addons/Spawn-Area.html +++ b/docs/addons/Spawn-Area.html @@ -376,7 +376,7 @@ generated by LDoc diff --git a/docs/commands/Admin-Chat.html b/docs/commands/Admin-Chat.html index ab42bec5..0dac6823 100644 --- a/docs/commands/Admin-Chat.html +++ b/docs/commands/Admin-Chat.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Bonus.html b/docs/commands/Bonus.html index 14323d1e..e208eee3 100644 --- a/docs/commands/Bonus.html +++ b/docs/commands/Bonus.html @@ -500,7 +500,7 @@ generated by LDoc diff --git a/docs/commands/Cheat-Mode.html b/docs/commands/Cheat-Mode.html index 083b32fe..10c20a38 100644 --- a/docs/commands/Cheat-Mode.html +++ b/docs/commands/Cheat-Mode.html @@ -361,7 +361,7 @@ generated by LDoc diff --git a/docs/commands/Clear-Inventory.html b/docs/commands/Clear-Inventory.html index e5998899..6cf02737 100644 --- a/docs/commands/Clear-Inventory.html +++ b/docs/commands/Clear-Inventory.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Debug.html b/docs/commands/Debug.html index 290d58a9..5f227660 100644 --- a/docs/commands/Debug.html +++ b/docs/commands/Debug.html @@ -365,7 +365,7 @@ generated by LDoc diff --git a/docs/commands/Find.html b/docs/commands/Find.html index e466bfd8..9cfff9a3 100644 --- a/docs/commands/Find.html +++ b/docs/commands/Find.html @@ -360,7 +360,7 @@ generated by LDoc diff --git a/docs/commands/Help.html b/docs/commands/Help.html index f7e4975b..31462e7e 100644 --- a/docs/commands/Help.html +++ b/docs/commands/Help.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/commands/Home.html b/docs/commands/Home.html index 067a4076..e1982d23 100644 --- a/docs/commands/Home.html +++ b/docs/commands/Home.html @@ -458,7 +458,7 @@ generated by LDoc diff --git a/docs/commands/Interface.html b/docs/commands/Interface.html index d280a73d..524a642d 100644 --- a/docs/commands/Interface.html +++ b/docs/commands/Interface.html @@ -416,7 +416,7 @@ generated by LDoc diff --git a/docs/commands/Jail.html b/docs/commands/Jail.html index 93a8b942..f2dd5d21 100644 --- a/docs/commands/Jail.html +++ b/docs/commands/Jail.html @@ -611,7 +611,7 @@ generated by LDoc diff --git a/docs/commands/Kill.html b/docs/commands/Kill.html index 50690c73..75caf805 100644 --- a/docs/commands/Kill.html +++ b/docs/commands/Kill.html @@ -389,7 +389,7 @@ generated by LDoc diff --git a/docs/commands/Me.html b/docs/commands/Me.html index 5b167987..254bda70 100644 --- a/docs/commands/Me.html +++ b/docs/commands/Me.html @@ -360,7 +360,7 @@ generated by LDoc diff --git a/docs/commands/Rainbow.html b/docs/commands/Rainbow.html index ead5dc2e..cbd8265f 100644 --- a/docs/commands/Rainbow.html +++ b/docs/commands/Rainbow.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Repair.html b/docs/commands/Repair.html index f363411e..8d24324b 100644 --- a/docs/commands/Repair.html +++ b/docs/commands/Repair.html @@ -321,7 +321,7 @@ generated by LDoc diff --git a/docs/commands/Reports.html b/docs/commands/Reports.html index d234cfa7..e5a9c808 100644 --- a/docs/commands/Reports.html +++ b/docs/commands/Reports.html @@ -585,7 +585,7 @@ generated by LDoc diff --git a/docs/commands/Roles.html b/docs/commands/Roles.html index 32d24195..d49d1007 100644 --- a/docs/commands/Roles.html +++ b/docs/commands/Roles.html @@ -557,7 +557,7 @@ generated by LDoc diff --git a/docs/commands/Spawn.html b/docs/commands/Spawn.html index a88bdecf..f1204717 100644 --- a/docs/commands/Spawn.html +++ b/docs/commands/Spawn.html @@ -389,7 +389,7 @@ generated by LDoc diff --git a/docs/commands/Tag.html b/docs/commands/Tag.html index 9438cddc..d9c0085b 100644 --- a/docs/commands/Tag.html +++ b/docs/commands/Tag.html @@ -443,7 +443,7 @@ generated by LDoc diff --git a/docs/commands/Teleport.html b/docs/commands/Teleport.html index 9478e557..51598a49 100644 --- a/docs/commands/Teleport.html +++ b/docs/commands/Teleport.html @@ -484,7 +484,7 @@ generated by LDoc diff --git a/docs/commands/Warnings.html b/docs/commands/Warnings.html index 2e0a0c76..d9581ee8 100644 --- a/docs/commands/Warnings.html +++ b/docs/commands/Warnings.html @@ -569,7 +569,7 @@ generated by LDoc diff --git a/docs/configs/Advanced-Start.html b/docs/configs/Advanced-Start.html index cbb5cc3d..af6026bb 100644 --- a/docs/configs/Advanced-Start.html +++ b/docs/configs/Advanced-Start.html @@ -506,7 +506,7 @@ generated by LDoc diff --git a/docs/configs/Bonuses.html b/docs/configs/Bonuses.html index eecdb55b..5c009894 100644 --- a/docs/configs/Bonuses.html +++ b/docs/configs/Bonuses.html @@ -237,7 +237,7 @@ generated by LDoc diff --git a/docs/configs/Chat-Reply.html b/docs/configs/Chat-Reply.html index 77eac0c3..b23c07d5 100644 --- a/docs/configs/Chat-Reply.html +++ b/docs/configs/Chat-Reply.html @@ -485,7 +485,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Admin.html b/docs/configs/Commands-Auth-Admin.html index f84fb637..73b6cd28 100644 --- a/docs/configs/Commands-Auth-Admin.html +++ b/docs/configs/Commands-Auth-Admin.html @@ -294,7 +294,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Roles.html b/docs/configs/Commands-Auth-Roles.html index dbe34891..b23d64fe 100644 --- a/docs/configs/Commands-Auth-Roles.html +++ b/docs/configs/Commands-Auth-Roles.html @@ -320,7 +320,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Runtime-Disable.html b/docs/configs/Commands-Auth-Runtime-Disable.html index 1531abfd..7f3c116b 100644 --- a/docs/configs/Commands-Auth-Runtime-Disable.html +++ b/docs/configs/Commands-Auth-Runtime-Disable.html @@ -442,7 +442,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Parse-Roles.html b/docs/configs/Commands-Parse-Roles.html index 877f1556..5a0b454f 100644 --- a/docs/configs/Commands-Parse-Roles.html +++ b/docs/configs/Commands-Parse-Roles.html @@ -354,7 +354,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Parse.html b/docs/configs/Commands-Parse.html index aedabc41..66516970 100644 --- a/docs/configs/Commands-Parse.html +++ b/docs/configs/Commands-Parse.html @@ -338,7 +338,7 @@ see ./expcore/commands.lua for more details

    generated by LDoc diff --git a/docs/configs/Compilatron.html b/docs/configs/Compilatron.html index 49196ffd..e636d935 100644 --- a/docs/configs/Compilatron.html +++ b/docs/configs/Compilatron.html @@ -354,7 +354,7 @@ generated by LDoc diff --git a/docs/configs/Death-Logger.html b/docs/configs/Death-Logger.html index 6696e94b..63adb104 100644 --- a/docs/configs/Death-Logger.html +++ b/docs/configs/Death-Logger.html @@ -416,7 +416,7 @@ generated by LDoc diff --git a/docs/configs/Discord-Alerts.html b/docs/configs/Discord-Alerts.html index 28f5b906..cb86d84e 100644 --- a/docs/configs/Discord-Alerts.html +++ b/docs/configs/Discord-Alerts.html @@ -237,7 +237,7 @@ generated by LDoc diff --git a/docs/configs/File-Loader.html b/docs/configs/File-Loader.html index 1a46e4cf..e3cb46f4 100644 --- a/docs/configs/File-Loader.html +++ b/docs/configs/File-Loader.html @@ -240,7 +240,7 @@ generated by LDoc diff --git a/docs/configs/Permission-Groups.html b/docs/configs/Permission-Groups.html index 22eb6228..8dfe6166 100644 --- a/docs/configs/Permission-Groups.html +++ b/docs/configs/Permission-Groups.html @@ -295,7 +295,7 @@ generated by LDoc diff --git a/docs/configs/Player-List.html b/docs/configs/Player-List.html index cf496eff..0027c816 100644 --- a/docs/configs/Player-List.html +++ b/docs/configs/Player-List.html @@ -812,7 +812,7 @@ generated by LDoc diff --git a/docs/configs/Pollution-Grading.html b/docs/configs/Pollution-Grading.html index a82ddebe..14621d46 100644 --- a/docs/configs/Pollution-Grading.html +++ b/docs/configs/Pollution-Grading.html @@ -384,7 +384,7 @@ generated by LDoc diff --git a/docs/configs/Popup-Messages.html b/docs/configs/Popup-Messages.html index 659d3f76..65851fdb 100644 --- a/docs/configs/Popup-Messages.html +++ b/docs/configs/Popup-Messages.html @@ -414,7 +414,7 @@ generated by LDoc diff --git a/docs/configs/Preset-Player-Colours.html b/docs/configs/Preset-Player-Colours.html index 5e487dad..b8e9a7f2 100644 --- a/docs/configs/Preset-Player-Colours.html +++ b/docs/configs/Preset-Player-Colours.html @@ -324,7 +324,7 @@ generated by LDoc diff --git a/docs/configs/Repair.html b/docs/configs/Repair.html index 2fcc9ed7..d8468dde 100644 --- a/docs/configs/Repair.html +++ b/docs/configs/Repair.html @@ -414,7 +414,7 @@ generated by LDoc diff --git a/docs/configs/Rockets.html b/docs/configs/Rockets.html index 58b57990..4d7c8aa1 100644 --- a/docs/configs/Rockets.html +++ b/docs/configs/Rockets.html @@ -834,7 +834,7 @@ generated by LDoc diff --git a/docs/configs/Roles.html b/docs/configs/Roles.html index 55823fe3..0414689b 100644 --- a/docs/configs/Roles.html +++ b/docs/configs/Roles.html @@ -292,7 +292,7 @@ generated by LDoc diff --git a/docs/configs/Science.html b/docs/configs/Science.html index 1d26d319..2c7f4bf0 100644 --- a/docs/configs/Science.html +++ b/docs/configs/Science.html @@ -354,7 +354,7 @@ generated by LDoc diff --git a/docs/configs/Scorched-Earth.html b/docs/configs/Scorched-Earth.html index 424aec99..7b1c22e4 100644 --- a/docs/configs/Scorched-Earth.html +++ b/docs/configs/Scorched-Earth.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/configs/Spawn-Area.html b/docs/configs/Spawn-Area.html index 5f2d3c3a..a7012781 100644 --- a/docs/configs/Spawn-Area.html +++ b/docs/configs/Spawn-Area.html @@ -744,7 +744,7 @@ generated by LDoc diff --git a/docs/configs/Tasks.html b/docs/configs/Tasks.html index a2e222bc..5b9b0515 100644 --- a/docs/configs/Tasks.html +++ b/docs/configs/Tasks.html @@ -384,7 +384,7 @@ generated by LDoc diff --git a/docs/configs/Warnings.html b/docs/configs/Warnings.html index a8ffe551..3db69aec 100644 --- a/docs/configs/Warnings.html +++ b/docs/configs/Warnings.html @@ -355,7 +355,7 @@ generated by LDoc diff --git a/docs/configs/Warps.html b/docs/configs/Warps.html index cb16c531..afe2df6d 100644 --- a/docs/configs/Warps.html +++ b/docs/configs/Warps.html @@ -684,7 +684,7 @@ generated by LDoc diff --git a/docs/control/Jail.html b/docs/control/Jail.html index 7af5c571..2bf7eb2b 100644 --- a/docs/control/Jail.html +++ b/docs/control/Jail.html @@ -1208,7 +1208,7 @@ generated by LDoc diff --git a/docs/control/Production.html b/docs/control/Production.html index def7e25c..389e1d52 100644 --- a/docs/control/Production.html +++ b/docs/control/Production.html @@ -1329,7 +1329,7 @@ generated by LDoc diff --git a/docs/control/Reports.html b/docs/control/Reports.html index 822446ea..8c602cfd 100644 --- a/docs/control/Reports.html +++ b/docs/control/Reports.html @@ -1110,7 +1110,7 @@ generated by LDoc diff --git a/docs/control/Rockets.html b/docs/control/Rockets.html index f8ca492e..549afdb6 100644 --- a/docs/control/Rockets.html +++ b/docs/control/Rockets.html @@ -984,7 +984,7 @@ generated by LDoc diff --git a/docs/control/Tasks.html b/docs/control/Tasks.html index c9a71a5d..c6c98a92 100644 --- a/docs/control/Tasks.html +++ b/docs/control/Tasks.html @@ -1039,7 +1039,7 @@ generated by LDoc diff --git a/docs/control/Warnings.html b/docs/control/Warnings.html index 4b8ebd2d..f13263e7 100644 --- a/docs/control/Warnings.html +++ b/docs/control/Warnings.html @@ -1465,7 +1465,7 @@ generated by LDoc diff --git a/docs/control/Warps.html b/docs/control/Warps.html index f0a6938d..7a808d9e 100644 --- a/docs/control/Warps.html +++ b/docs/control/Warps.html @@ -1413,7 +1413,7 @@ generated by LDoc diff --git a/docs/core/Commands.html b/docs/core/Commands.html index fb2c4ff5..b7665406 100644 --- a/docs/core/Commands.html +++ b/docs/core/Commands.html @@ -1972,7 +1972,7 @@ generated by LDoc diff --git a/docs/core/Common-Library.html b/docs/core/Common-Library.html index 1f26b637..704bb0b4 100644 --- a/docs/core/Common-Library.html +++ b/docs/core/Common-Library.html @@ -2746,7 +2746,7 @@ Common.table_insert(tbl,50,tbl2) generated by LDoc diff --git a/docs/core/Gui.html b/docs/core/Gui.html index 55190867..7001ba8e 100644 --- a/docs/core/Gui.html +++ b/docs/core/Gui.html @@ -348,6 +348,14 @@ button:clone('CustomButton')
  • + + + + + + + +
    slider The basic slider element
    text_boxThe text box element
    text_fieldThe text field element
    @@ -1384,7 +1392,7 @@ Gui.clone_concept('progress_bar',boolean) - makes this slider a discrete slider (at time of writing unsure what this is) + makes this slider a discrete slider, this means that the slider button will stop at the same interval as the values do @@ -1436,6 +1444,378 @@ Gui.clone_concept('slider','dis end) + +
    +
    +
    + # + text_box +
    +
    +
    +
    + +

    The text box element

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + on_text_changed + + : + + + fired when the text within the text box is changed + +
    • + + + + + +
    • + + tooltip + + : + + (string or LocalisedString) + + the tooltip that shows when a player hovers over the text box + +
    • + + + + + +
    • + + default + + : + + (string or function) + + the default text that will appear in the text box, or a function that returns it + +
    • + + + + + +
    • + + clear_on_rmb + + : + + (boolean) + + if the text box will be cleared and forcused on a right click + +
    • + + + + + +
    • + + is_selectable + + : + + (boolean) + + when true the text inside the box can be selected + +
    • + + + + + +
    • + + has_word_wrap + + : + + (boolean) + + when true the text will wrap onto the next line if it reachs the end + +
    • + + + + + +
    • + + is_read_only + + : + + (boolean) + + when true the text inside the box can not be edited by the player + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Making a text box
    +local basic_text_box =
    +Gui.clone_concept('text_box','basic_text_box')
    +:set_default('I am the text that will show in the text box')
    +
    -- Making a text box which can be edited
    +local editible_text_box =
    +Gui.clone_concept('text_box','editible_text_box')
    +:set_is_read_only(false)
    +:set_default('I am the text that will show in the text box')
    +:on_confirmation(function(event)
    +    event.player.print('Editible text box is now: '..event.element.text)
    +end)
    + + +
    +
    +
    +
    + # + text_field +
    +
    +
    +
    + +

    The text field element

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + on_text_changed + + : + + + fired when the text within the text field is changed + +
    • + + + + + +
    • + + on_confirmation + + : + + + fired when the player presses enter with the text field forcused + +
    • + + + + + +
    • + + tooltip + + : + + (string or LocalisedString) + + the tooltip that shows when a player hovers over the text field + +
    • + + + + + +
    • + + default + + : + + (string or function) + + the default text that will appear in the text field, or a function that returns it + +
    • + + + + + +
    • + + clear_on_rmb + + : + + (boolean) + + if the text field will be cleared and forcused on a right click + +
    • + + + + + +
    • + + lose_forcus + + : + + (boolean) + + if the text field will lose forcus after the confirmation event + +
    • + + + + + +
    • + + is_number + + : + + (boolean) + + if this text field contains a number value, can be ignored if is_decimal or is_negitive is used + +
    • + + + + + +
    • + + is_decimal + + : + + (boolean) + + if this text field contains a decimal value + +
    • + + + + + +
    • + + is_negative + + : + + (boolean) + + if this text field contains a negative value + +
    • + + + + + +
    • + + is_password + + : + + (boolean) + + if this text field contains a password value + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Making a text field
    +local basic_text_field =
    +Gui.clone_concept('text_field','basic_text_field')
    +:on_confirmation(function(event)
    +    event.player.print('Basic text field is now: '..event.element.text)
    +end)
    +
    -- Making a text field which will clear on right click and un forcus on confirmation
    +local better_text_field =
    +Gui.clone_concept('text_field','better_text_field')
    +:set_clear_on_rmb(true)
    +:set_lose_forcus(true)
    +:on_confirmation(function(event)
    +    event.player.print('Better text field is now: '..event.element.text)
    +end)
    +
    -- Making a decimal input
    +local decimal_text_field =
    +Gui.clone_concept('text_field','decimal_text_field')
    +:set_is_decimal(true)
    +:on_confirmation(function(event)
    +    event.player.print('Decimal text field is now: '..event.element.text)
    +end)
    + +

    Dropdowns

    @@ -4590,7 +4970,7 @@ Gui.get_concept('CustomButton') generated by LDoc diff --git a/docs/core/Permissions-Groups.html b/docs/core/Permissions-Groups.html index 88c9d301..d6cfd67e 100644 --- a/docs/core/Permissions-Groups.html +++ b/docs/core/Permissions-Groups.html @@ -1432,7 +1432,7 @@ generated by LDoc diff --git a/docs/core/Roles.html b/docs/core/Roles.html index 939c59a1..90aaa30a 100644 --- a/docs/core/Roles.html +++ b/docs/core/Roles.html @@ -3152,7 +3152,7 @@ generated by LDoc diff --git a/docs/core/Store.html b/docs/core/Store.html index e518d5a6..c426c2a9 100644 --- a/docs/core/Store.html +++ b/docs/core/Store.html @@ -1145,7 +1145,7 @@ Store.register(team_scores,function(value,key) generated by LDoc diff --git a/docs/core/Sudo.html b/docs/core/Sudo.html index 36b4a432..cb87e968 100644 --- a/docs/core/Sudo.html +++ b/docs/core/Sudo.html @@ -544,7 +544,7 @@ generated by LDoc diff --git a/docs/guis/Player-List.html b/docs/guis/Player-List.html index 6c70132d..85e9bd5b 100644 --- a/docs/guis/Player-List.html +++ b/docs/guis/Player-List.html @@ -626,7 +626,7 @@ generated by LDoc diff --git a/docs/guis/Rocket-Info.html b/docs/guis/Rocket-Info.html index ab679073..4f70f60a 100644 --- a/docs/guis/Rocket-Info.html +++ b/docs/guis/Rocket-Info.html @@ -629,7 +629,7 @@ generated by LDoc diff --git a/docs/guis/Science-Info.html b/docs/guis/Science-Info.html index c59424c9..db01d658 100644 --- a/docs/guis/Science-Info.html +++ b/docs/guis/Science-Info.html @@ -449,7 +449,7 @@ generated by LDoc diff --git a/docs/guis/Task-List.html b/docs/guis/Task-List.html index bb660351..da16f049 100644 --- a/docs/guis/Task-List.html +++ b/docs/guis/Task-List.html @@ -632,7 +632,7 @@ generated by LDoc diff --git a/docs/guis/Warps-List.html b/docs/guis/Warps-List.html index 66885bbe..293094c5 100644 --- a/docs/guis/Warps-List.html +++ b/docs/guis/Warps-List.html @@ -837,7 +837,7 @@ generated by LDoc diff --git a/docs/index.html b/docs/index.html index 7ed6c8dd..2d5a06dd 100644 --- a/docs/index.html +++ b/docs/index.html @@ -510,7 +510,7 @@ see ./expcore/commands.lua for more details
    generated by LDoc diff --git a/docs/modules/control.html b/docs/modules/control.html index 5723e3d4..377e2e4d 100644 --- a/docs/modules/control.html +++ b/docs/modules/control.html @@ -351,7 +351,7 @@ generated by LDoc diff --git a/docs/modules/utils.alien_evolution_progress.html b/docs/modules/utils.alien_evolution_progress.html index 8de5f2be..cb214d8e 100644 --- a/docs/modules/utils.alien_evolution_progress.html +++ b/docs/modules/utils.alien_evolution_progress.html @@ -419,7 +419,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 738a0e75..4f6a5936 100644 --- a/docs/modules/utils.core.html +++ b/docs/modules/utils.core.html @@ -1164,7 +1164,7 @@ generated by LDoc diff --git a/docs/modules/utils.debug.html b/docs/modules/utils.debug.html index c560bc9d..967c465d 100644 --- a/docs/modules/utils.debug.html +++ b/docs/modules/utils.debug.html @@ -654,7 +654,7 @@ generated by LDoc diff --git a/docs/modules/utils.dump_env.html b/docs/modules/utils.dump_env.html index 74e7ec8a..5d97b286 100644 --- a/docs/modules/utils.dump_env.html +++ b/docs/modules/utils.dump_env.html @@ -323,7 +323,7 @@ generated by LDoc diff --git a/docs/modules/utils.event.html b/docs/modules/utils.event.html index 0f324e4b..ef1fb0ef 100644 --- a/docs/modules/utils.event.html +++ b/docs/modules/utils.event.html @@ -1292,7 +1292,7 @@ generated by LDoc diff --git a/docs/modules/utils.event_core.html b/docs/modules/utils.event_core.html index c2a42b72..c7c8acd0 100644 --- a/docs/modules/utils.event_core.html +++ b/docs/modules/utils.event_core.html @@ -434,7 +434,7 @@ generated by LDoc diff --git a/docs/modules/utils.math.html b/docs/modules/utils.math.html index b53b1a2c..c653377a 100644 --- a/docs/modules/utils.math.html +++ b/docs/modules/utils.math.html @@ -338,7 +338,7 @@ generated by LDoc diff --git a/docs/modules/utils.recipe_locker.html b/docs/modules/utils.recipe_locker.html index 6ba6a2cc..0a43c0e9 100644 --- a/docs/modules/utils.recipe_locker.html +++ b/docs/modules/utils.recipe_locker.html @@ -441,7 +441,7 @@ generated by LDoc diff --git a/docs/modules/utils.state_machine.html b/docs/modules/utils.state_machine.html index a7c7ae1c..fc44bc7b 100644 --- a/docs/modules/utils.state_machine.html +++ b/docs/modules/utils.state_machine.html @@ -752,7 +752,7 @@ generated by LDoc diff --git a/docs/modules/utils.table.html b/docs/modules/utils.table.html index 71fdfc28..1a9ef65d 100644 --- a/docs/modules/utils.table.html +++ b/docs/modules/utils.table.html @@ -1382,7 +1382,7 @@ generated by LDoc diff --git a/docs/modules/utils.task.html b/docs/modules/utils.task.html index c5a2596d..3d86cca1 100644 --- a/docs/modules/utils.task.html +++ b/docs/modules/utils.task.html @@ -651,7 +651,7 @@ generated by LDoc diff --git a/docs/modules/utils.timestamp.html b/docs/modules/utils.timestamp.html index 2a54826a..e5be71ff 100644 --- a/docs/modules/utils.timestamp.html +++ b/docs/modules/utils.timestamp.html @@ -442,7 +442,7 @@ generated by LDoc diff --git a/docs/topics/license.html b/docs/topics/license.html index 927f857f..2e77eb29 100644 --- a/docs/topics/license.html +++ b/docs/topics/license.html @@ -789,7 +789,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 9ced810b..50cc7c47 100644 --- a/docs/topics/readme.md.html +++ b/docs/topics/readme.md.html @@ -332,7 +332,7 @@ generated by LDoc diff --git a/expcore/gui.lua b/expcore/gui.lua index 7f28c635..54c8d512 100644 --- a/expcore/gui.lua +++ b/expcore/gui.lua @@ -74,5 +74,7 @@ Gui.require_concept('dropdown') Gui.require_concept('elem_button') Gui.require_concept('progress_bar') Gui.require_concept('slider') +Gui.require_concept('textfield') +Gui.require_concept('textbox') return Gui \ No newline at end of file diff --git a/expcore/gui/concepts/slider.lua b/expcore/gui/concepts/slider.lua index b58792d3..3cc90dbd 100644 --- a/expcore/gui/concepts/slider.lua +++ b/expcore/gui/concepts/slider.lua @@ -10,7 +10,7 @@ local Gui = require 'expcore.gui.core' @param on_value_changed fired when the value of the slider is changed @tparam number value_step the minimum amount by which the value of the slider can be changed @tparam ?number|function default the default value of the slider or a function which returns the default value -@tparam boolean discrete_slider makes this slider a discrete slider (at time of writing unsure what this is) +@tparam boolean discrete_slider makes this slider a discrete slider, this means that the slider button will stop at the same interval as the values do @tparam ?number|function range accepts two params the minimum and the maximum for this slider, or a single function to return both @usage-- Making a basic slider local basic_slider = diff --git a/expcore/gui/concepts/textbox.lua b/expcore/gui/concepts/textbox.lua new file mode 100644 index 00000000..3c3945eb --- /dev/null +++ b/expcore/gui/concepts/textbox.lua @@ -0,0 +1,60 @@ +--[[-- Core Module - Gui + @module Gui + @alias Gui +]] + +local Gui = require 'expcore.gui.core' + +--[[-- The text box element +@element text_box +@param on_text_changed fired when the text within the text box is changed +@tparam ?string|Concepts.LocalisedString tooltip the tooltip that shows when a player hovers over the text box +@tparam ?string|function default the default text that will appear in the text box, or a function that returns it +@tparam boolean clear_on_rmb if the text box will be cleared and forcused on a right click +@tparam boolean is_selectable when true the text inside the box can be selected +@tparam boolean has_word_wrap when true the text will wrap onto the next line if it reachs the end +@tparam boolean is_read_only when true the text inside the box can not be edited by the player +@usage-- Making a text box +local basic_text_box = +Gui.clone_concept('text_box','basic_text_box') +:set_default('I am the text that will show in the text box') +@usage-- Making a text box which can be edited +local editible_text_box = +Gui.clone_concept('text_box','editible_text_box') +:set_is_read_only(false) +:set_default('I am the text that will show in the text box') +:on_confirmation(function(event) + event.player.print('Editible text box is now: '..event.element.text) +end) +]] +Gui.new_concept('text_box') +:new_event('on_text_changed',defines.events.on_gui_text_changed) +:new_property('tooltip') +:new_property('default') +:new_property('clear_on_rmb',false) +:new_property('is_selectable',true) +:new_property('has_word_wrap',true) +:new_property('is_read_only',true) +:define_draw(function(properties,parent,element) + local default = properties.default + local text = type(default) == 'string' and default or nil + + element = parent.add{ + name = properties.name, + type = 'text-box', + tooltip = properties.tooltip, + clear_and_focus_on_right_click = properties.clear_on_rmb, + text = text + } + + element.selectable = properties.is_selectable + element.word_wrap = properties.has_word_wrap + element.read_only = properties.is_read_only + + default = Gui.resolve_property(default,element) + if default and default ~= text then + element.text = default + end + + return element +end) \ No newline at end of file diff --git a/expcore/gui/concepts/textfield.lua b/expcore/gui/concepts/textfield.lua new file mode 100644 index 00000000..717fe55c --- /dev/null +++ b/expcore/gui/concepts/textfield.lua @@ -0,0 +1,76 @@ +--[[-- Core Module - Gui + @module Gui + @alias Gui +]] + +local Gui = require 'expcore.gui.core' + +--[[-- The text field element +@element text_field +@param on_text_changed fired when the text within the text field is changed +@param on_confirmation fired when the player presses enter with the text field forcused +@tparam ?string|Concepts.LocalisedString tooltip the tooltip that shows when a player hovers over the text field +@tparam ?string|function default the default text that will appear in the text field, or a function that returns it +@tparam boolean clear_on_rmb if the text field will be cleared and forcused on a right click +@tparam boolean lose_forcus if the text field will lose forcus after the confirmation event +@tparam boolean is_number if this text field contains a number value, can be ignored if is_decimal or is_negitive is used +@tparam boolean is_decimal if this text field contains a decimal value +@tparam boolean is_negative if this text field contains a negative value +@tparam boolean is_password if this text field contains a password value +@usage-- Making a text field +local basic_text_field = +Gui.clone_concept('text_field','basic_text_field') +:on_confirmation(function(event) + event.player.print('Basic text field is now: '..event.element.text) +end) +@usage-- Making a text field which will clear on right click and un forcus on confirmation +local better_text_field = +Gui.clone_concept('text_field','better_text_field') +:set_clear_on_rmb(true) +:set_lose_forcus(true) +:on_confirmation(function(event) + event.player.print('Better text field is now: '..event.element.text) +end) +@usage-- Making a decimal input +local decimal_text_field = +Gui.clone_concept('text_field','decimal_text_field') +:set_is_decimal(true) +:on_confirmation(function(event) + event.player.print('Decimal text field is now: '..event.element.text) +end) +]] +Gui.new_concept('text_field') +:new_event('on_text_changed',defines.events.on_gui_text_changed) +:new_event('on_confirmation',defines.events.on_gui_confirmed) +:new_property('tooltip') +:new_property('default') +:new_property('clear_on_rmb',false) +:new_property('lose_forcus',false) +:new_property('is_number',false) +:new_property('is_decimal',false) +:new_property('is_negative',false) +:new_property('is_password',false) +:define_draw(function(properties,parent,element) + local default = properties.default + local text = type(default) == 'string' and default or nil + + element = parent.add{ + name = properties.name, + type = 'textfield', + tooltip = properties.tooltip, + clear_and_focus_on_right_click = properties.clear_on_rmb, + lose_focus_on_confirm = properties.lose_forcus, + numeric = properties.is_number or properties.is_decimal or properties.is_negative, + allow_decimal = properties.is_decimal, + allow_negative = properties.is_negative, + is_password = properties.is_password, + text = text + } + + default = Gui.resolve_property(default,element) + if default and default ~= text then + element.text = default + end + + return element +end) \ No newline at end of file diff --git a/expcore/gui/test.lua b/expcore/gui/test.lua index f6d74988..afee4f8f 100644 --- a/expcore/gui/test.lua +++ b/expcore/gui/test.lua @@ -514,4 +514,98 @@ tests.Sliders = { ['Discrete Slider'] = discrete_slider, ['Dynamic Slider'] = dynamic_slider, ['Player Stored Slider'] = player_slider +} + +--[[ +Text Fields +> Basic Text Field -- Just a text field which text can be entered into +> Better Text Field -- Same as above but will clear on rmb and un forcus on confirmation +> Decimal Text Field -- Text field which accepts decimal values +> Password Text Field -- Text field which stars out the typed characters +> Player Stored Text Field - Same as basic but will store value per player +]] + +-- Making a text field +local basic_text_field = +Gui.clone_concept('text_field',TEST 'basic_text_field') +:set_tooltip('Basic text field') +:on_confirmation(function(event) + event.player.print('Basic text field is now: '..event.element.text) +end) + +local better_text_field = +Gui.clone_concept('text_field',TEST 'better_text_field') +:set_tooltip('Better text field') +:set_clear_on_rmb(true) +:set_lose_forcus(true) +:on_confirmation(function(event) + event.player.print('Better text field is now: '..event.element.text) +end) + +local decimal_text_field = +Gui.clone_concept('text_field',TEST 'decimal_text_field') +:set_tooltip('Decimal text field') +:set_is_decimal(true) +:on_confirmation(function(event) + event.player.print('Decimal text field is now: '..event.element.text) +end) + +local password_text_field = +Gui.clone_concept('text_field',TEST 'password_text_field') +:set_tooltip('Password text field') +:set_is_password(true) +:on_confirmation(function(event) + event.player.print('Password text field is now: '..event.element.text) +end) + +local player_text_field = +Gui.clone_concept('text_field',TEST 'player_text_field') +:set_tooltip('Player stored text field') +:on_confirmation(function(event) + local element = event.element + local text = element.text + event.concept.set_data(element,text) + event.player.print('Player stored text field is now: '..text) +end) +:define_combined_store(Gui.categorize_by_player, function(element,value) + element.text = value or '' +end) + +tests['Text Fields'] = { + ['Basic Text Field'] = basic_text_field, + ['Better Text Field'] = better_text_field, + ['Decimal Text Field'] = decimal_text_field, + ['Password Text Field'] = password_text_field, + ['Player Stored Text Field'] = player_text_field +} + +--[[ +Text Boxs +> Basic Text Box -- A text box that can not be edited +> Editible Text Box -- A text box that can be edited +]] + +local basic_text_box = +Gui.clone_concept('text_box',TEST 'basic_text_box') +:set_tooltip('Basic text box') +:set_default('I am the text that will show in the text box') +:define_draw(function(properties,parent,element) + element.style.height = 75 +end) + +local editible_text_box = +Gui.clone_concept('text_box',TEST 'editible_text_box') +:set_tooltip('Editible text box') +:set_is_read_only(false) +:set_default('I am the text that will show in the text box') +:on_text_changed(function(event) + event.player.print('Editible text box is now: '..event.element.text) +end) +:define_draw(function(properties,parent,element) + element.style.height = 75 +end) + +tests['Text Boxs'] = { + ['Basic Text Box'] = basic_text_box, + ['Editible Text Box'] = editible_text_box } \ No newline at end of file From 06e6ccd60bb8206bb0f456d598cf6a4d5b638dc4 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Fri, 6 Sep 2019 21:13:00 +0100 Subject: [PATCH 15/26] Added toolbar --- docs/addons/Advanced-Start.html | 3 +- docs/addons/Chat-Popups.html | 3 +- docs/addons/Chat-Reply.html | 3 +- docs/addons/Compilatron.html | 3 +- docs/addons/Damage-Popups.html | 3 +- docs/addons/Death-Logger.html | 3 +- docs/addons/Discord-Alerts.html | 3 +- docs/addons/Player-Colours.html | 3 +- docs/addons/Pollution-Grading.html | 3 +- docs/addons/Scorched-Earth.html | 3 +- docs/addons/Spawn-Area.html | 3 +- docs/commands/Admin-Chat.html | 3 +- docs/commands/Bonus.html | 3 +- docs/commands/Cheat-Mode.html | 3 +- docs/commands/Clear-Inventory.html | 3 +- docs/commands/Debug.html | 3 +- docs/commands/Find.html | 3 +- docs/commands/Help.html | 3 +- docs/commands/Home.html | 3 +- docs/commands/Interface.html | 3 +- docs/commands/Jail.html | 3 +- docs/commands/Kill.html | 3 +- docs/commands/Me.html | 3 +- docs/commands/Rainbow.html | 3 +- docs/commands/Repair.html | 3 +- docs/commands/Reports.html | 3 +- docs/commands/Roles.html | 3 +- docs/commands/Spawn.html | 3 +- docs/commands/Tag.html | 3 +- docs/commands/Teleport.html | 3 +- docs/commands/Warnings.html | 3 +- docs/configs/Advanced-Start.html | 3 +- docs/configs/Bonuses.html | 3 +- docs/configs/Chat-Reply.html | 3 +- docs/configs/Commands-Auth-Admin.html | 3 +- docs/configs/Commands-Auth-Roles.html | 3 +- .../Commands-Auth-Runtime-Disable.html | 3 +- docs/configs/Commands-Parse-Roles.html | 3 +- docs/configs/Commands-Parse.html | 3 +- docs/configs/Compilatron.html | 3 +- docs/configs/Death-Logger.html | 3 +- docs/configs/Discord-Alerts.html | 3 +- docs/configs/File-Loader.html | 3 +- docs/configs/Permission-Groups.html | 3 +- docs/configs/Player-List.html | 3 +- docs/configs/Pollution-Grading.html | 3 +- docs/configs/Popup-Messages.html | 3 +- docs/configs/Preset-Player-Colours.html | 3 +- docs/configs/Repair.html | 3 +- docs/configs/Rockets.html | 3 +- docs/configs/Roles.html | 3 +- docs/configs/Science.html | 3 +- docs/configs/Scorched-Earth.html | 3 +- docs/configs/Spawn-Area.html | 3 +- docs/configs/Tasks.html | 3 +- docs/configs/Warnings.html | 3 +- docs/configs/Warps.html | 3 +- docs/control/Jail.html | 3 +- docs/control/Production.html | 3 +- docs/control/Reports.html | 3 +- docs/control/Rockets.html | 3 +- docs/control/Tasks.html | 3 +- docs/control/Warnings.html | 3 +- docs/control/Warps.html | 3 +- docs/core/Commands.html | 3 +- docs/core/Common-Library.html | 3 +- docs/core/Gui.html | 72 +- docs/core/Permissions-Groups.html | 3 +- docs/core/Roles.html | 3 +- docs/core/Store.html | 3 +- docs/core/Sudo.html | 3 +- docs/core/Toolbar.html | 1638 +++++++++++++++++ docs/guis/Player-List.html | 3 +- docs/guis/Rocket-Info.html | 3 +- docs/guis/Science-Info.html | 3 +- docs/guis/Task-List.html | 3 +- docs/guis/Warps-List.html | 3 +- docs/index.html | 6 +- docs/modules/control.html | 3 +- .../utils.alien_evolution_progress.html | 3 +- docs/modules/utils.core.html | 3 +- docs/modules/utils.debug.html | 3 +- docs/modules/utils.dump_env.html | 3 +- docs/modules/utils.event.html | 3 +- docs/modules/utils.event_core.html | 3 +- docs/modules/utils.math.html | 3 +- docs/modules/utils.recipe_locker.html | 3 +- docs/modules/utils.state_machine.html | 3 +- docs/modules/utils.table.html | 3 +- docs/modules/utils.task.html | 3 +- docs/modules/utils.timestamp.html | 3 +- docs/topics/license.html | 3 +- docs/topics/readme.md.html | 3 +- expcore/gui/concepts/button.lua | 14 +- expcore/gui/core.lua | 1 + expcore/gui/prototype.lua | 38 +- expcore/gui/test.lua | 57 +- expcore/toolbar.lua | 469 +++++ utils/event_core.lua | 2 +- 99 files changed, 2463 insertions(+), 104 deletions(-) create mode 100644 docs/core/Toolbar.html create mode 100644 expcore/toolbar.lua diff --git a/docs/addons/Advanced-Start.html b/docs/addons/Advanced-Start.html index 31d501d2..355bc495 100644 --- a/docs/addons/Advanced-Start.html +++ b/docs/addons/Advanced-Start.html @@ -74,6 +74,7 @@ + @@ -348,7 +349,7 @@ generated by LDoc diff --git a/docs/addons/Chat-Popups.html b/docs/addons/Chat-Popups.html index 0b71ec19..6a9a5437 100644 --- a/docs/addons/Chat-Popups.html +++ b/docs/addons/Chat-Popups.html @@ -74,6 +74,7 @@ + @@ -349,7 +350,7 @@ generated by LDoc diff --git a/docs/addons/Chat-Reply.html b/docs/addons/Chat-Reply.html index 0f83ae72..ba20d5c1 100644 --- a/docs/addons/Chat-Reply.html +++ b/docs/addons/Chat-Reply.html @@ -74,6 +74,7 @@ + @@ -376,7 +377,7 @@ generated by LDoc diff --git a/docs/addons/Compilatron.html b/docs/addons/Compilatron.html index 6340ad99..c9aa9a5a 100644 --- a/docs/addons/Compilatron.html +++ b/docs/addons/Compilatron.html @@ -75,6 +75,7 @@ + @@ -585,7 +586,7 @@ generated by LDoc diff --git a/docs/addons/Damage-Popups.html b/docs/addons/Damage-Popups.html index cf61c396..9768b669 100644 --- a/docs/addons/Damage-Popups.html +++ b/docs/addons/Damage-Popups.html @@ -74,6 +74,7 @@ + @@ -349,7 +350,7 @@ generated by LDoc diff --git a/docs/addons/Death-Logger.html b/docs/addons/Death-Logger.html index 58ecdcf1..781142d9 100644 --- a/docs/addons/Death-Logger.html +++ b/docs/addons/Death-Logger.html @@ -74,6 +74,7 @@ + @@ -404,7 +405,7 @@ generated by LDoc diff --git a/docs/addons/Discord-Alerts.html b/docs/addons/Discord-Alerts.html index 62e674db..7a218c04 100644 --- a/docs/addons/Discord-Alerts.html +++ b/docs/addons/Discord-Alerts.html @@ -74,6 +74,7 @@ + @@ -460,7 +461,7 @@ generated by LDoc diff --git a/docs/addons/Player-Colours.html b/docs/addons/Player-Colours.html index 9fdcc3ea..6ef982b9 100644 --- a/docs/addons/Player-Colours.html +++ b/docs/addons/Player-Colours.html @@ -74,6 +74,7 @@ + @@ -404,7 +405,7 @@ generated by LDoc diff --git a/docs/addons/Pollution-Grading.html b/docs/addons/Pollution-Grading.html index 05cfe35c..46544811 100644 --- a/docs/addons/Pollution-Grading.html +++ b/docs/addons/Pollution-Grading.html @@ -74,6 +74,7 @@ + @@ -320,7 +321,7 @@ generated by LDoc diff --git a/docs/addons/Scorched-Earth.html b/docs/addons/Scorched-Earth.html index 13a983b4..88da4c0a 100644 --- a/docs/addons/Scorched-Earth.html +++ b/docs/addons/Scorched-Earth.html @@ -74,6 +74,7 @@ + @@ -404,7 +405,7 @@ generated by LDoc diff --git a/docs/addons/Spawn-Area.html b/docs/addons/Spawn-Area.html index 6a4b845e..2faa81dc 100644 --- a/docs/addons/Spawn-Area.html +++ b/docs/addons/Spawn-Area.html @@ -74,6 +74,7 @@ + @@ -376,7 +377,7 @@ generated by LDoc diff --git a/docs/commands/Admin-Chat.html b/docs/commands/Admin-Chat.html index 0dac6823..54195af8 100644 --- a/docs/commands/Admin-Chat.html +++ b/docs/commands/Admin-Chat.html @@ -84,6 +84,7 @@ + @@ -388,7 +389,7 @@ generated by LDoc diff --git a/docs/commands/Bonus.html b/docs/commands/Bonus.html index e208eee3..450e04f6 100644 --- a/docs/commands/Bonus.html +++ b/docs/commands/Bonus.html @@ -84,6 +84,7 @@ + @@ -500,7 +501,7 @@ generated by LDoc diff --git a/docs/commands/Cheat-Mode.html b/docs/commands/Cheat-Mode.html index 10c20a38..7a662f0a 100644 --- a/docs/commands/Cheat-Mode.html +++ b/docs/commands/Cheat-Mode.html @@ -84,6 +84,7 @@ + @@ -361,7 +362,7 @@ generated by LDoc diff --git a/docs/commands/Clear-Inventory.html b/docs/commands/Clear-Inventory.html index 6cf02737..62f59464 100644 --- a/docs/commands/Clear-Inventory.html +++ b/docs/commands/Clear-Inventory.html @@ -84,6 +84,7 @@ + @@ -388,7 +389,7 @@ generated by LDoc diff --git a/docs/commands/Debug.html b/docs/commands/Debug.html index 5f227660..74239e71 100644 --- a/docs/commands/Debug.html +++ b/docs/commands/Debug.html @@ -84,6 +84,7 @@ + @@ -365,7 +366,7 @@ generated by LDoc diff --git a/docs/commands/Find.html b/docs/commands/Find.html index 9cfff9a3..84387d0a 100644 --- a/docs/commands/Find.html +++ b/docs/commands/Find.html @@ -84,6 +84,7 @@ + @@ -360,7 +361,7 @@ generated by LDoc diff --git a/docs/commands/Help.html b/docs/commands/Help.html index 31462e7e..21b3aeaa 100644 --- a/docs/commands/Help.html +++ b/docs/commands/Help.html @@ -84,6 +84,7 @@ + @@ -404,7 +405,7 @@ generated by LDoc diff --git a/docs/commands/Home.html b/docs/commands/Home.html index e1982d23..d8637e6f 100644 --- a/docs/commands/Home.html +++ b/docs/commands/Home.html @@ -84,6 +84,7 @@ + @@ -458,7 +459,7 @@ generated by LDoc diff --git a/docs/commands/Interface.html b/docs/commands/Interface.html index 524a642d..224c35ee 100644 --- a/docs/commands/Interface.html +++ b/docs/commands/Interface.html @@ -84,6 +84,7 @@ + @@ -416,7 +417,7 @@ generated by LDoc diff --git a/docs/commands/Jail.html b/docs/commands/Jail.html index f2dd5d21..432028b8 100644 --- a/docs/commands/Jail.html +++ b/docs/commands/Jail.html @@ -84,6 +84,7 @@ + @@ -611,7 +612,7 @@ generated by LDoc diff --git a/docs/commands/Kill.html b/docs/commands/Kill.html index 75caf805..1d35117f 100644 --- a/docs/commands/Kill.html +++ b/docs/commands/Kill.html @@ -84,6 +84,7 @@ + @@ -389,7 +390,7 @@ generated by LDoc diff --git a/docs/commands/Me.html b/docs/commands/Me.html index 254bda70..aebe8ab4 100644 --- a/docs/commands/Me.html +++ b/docs/commands/Me.html @@ -84,6 +84,7 @@ + @@ -360,7 +361,7 @@ generated by LDoc diff --git a/docs/commands/Rainbow.html b/docs/commands/Rainbow.html index cbd8265f..37baf73b 100644 --- a/docs/commands/Rainbow.html +++ b/docs/commands/Rainbow.html @@ -84,6 +84,7 @@ + @@ -388,7 +389,7 @@ generated by LDoc diff --git a/docs/commands/Repair.html b/docs/commands/Repair.html index 8d24324b..8b302752 100644 --- a/docs/commands/Repair.html +++ b/docs/commands/Repair.html @@ -83,6 +83,7 @@ + @@ -321,7 +322,7 @@ generated by LDoc diff --git a/docs/commands/Reports.html b/docs/commands/Reports.html index e5a9c808..dc80bff6 100644 --- a/docs/commands/Reports.html +++ b/docs/commands/Reports.html @@ -84,6 +84,7 @@ + @@ -585,7 +586,7 @@ generated by LDoc diff --git a/docs/commands/Roles.html b/docs/commands/Roles.html index d49d1007..da4ffc81 100644 --- a/docs/commands/Roles.html +++ b/docs/commands/Roles.html @@ -84,6 +84,7 @@ + @@ -557,7 +558,7 @@ generated by LDoc diff --git a/docs/commands/Spawn.html b/docs/commands/Spawn.html index f1204717..738a91ee 100644 --- a/docs/commands/Spawn.html +++ b/docs/commands/Spawn.html @@ -84,6 +84,7 @@ + @@ -389,7 +390,7 @@ generated by LDoc diff --git a/docs/commands/Tag.html b/docs/commands/Tag.html index d9c0085b..eb224a4e 100644 --- a/docs/commands/Tag.html +++ b/docs/commands/Tag.html @@ -84,6 +84,7 @@ + @@ -443,7 +444,7 @@ generated by LDoc diff --git a/docs/commands/Teleport.html b/docs/commands/Teleport.html index 51598a49..0641f54e 100644 --- a/docs/commands/Teleport.html +++ b/docs/commands/Teleport.html @@ -84,6 +84,7 @@ + @@ -484,7 +485,7 @@ generated by LDoc diff --git a/docs/commands/Warnings.html b/docs/commands/Warnings.html index d9581ee8..33a5203a 100644 --- a/docs/commands/Warnings.html +++ b/docs/commands/Warnings.html @@ -84,6 +84,7 @@ + @@ -569,7 +570,7 @@ generated by LDoc diff --git a/docs/configs/Advanced-Start.html b/docs/configs/Advanced-Start.html index af6026bb..054b7703 100644 --- a/docs/configs/Advanced-Start.html +++ b/docs/configs/Advanced-Start.html @@ -89,6 +89,7 @@ + @@ -506,7 +507,7 @@ generated by LDoc diff --git a/docs/configs/Bonuses.html b/docs/configs/Bonuses.html index 5c009894..a11c7015 100644 --- a/docs/configs/Bonuses.html +++ b/docs/configs/Bonuses.html @@ -81,6 +81,7 @@ + @@ -237,7 +238,7 @@ generated by LDoc diff --git a/docs/configs/Chat-Reply.html b/docs/configs/Chat-Reply.html index b23c07d5..9ffe93c5 100644 --- a/docs/configs/Chat-Reply.html +++ b/docs/configs/Chat-Reply.html @@ -90,6 +90,7 @@ + @@ -485,7 +486,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Admin.html b/docs/configs/Commands-Auth-Admin.html index 73b6cd28..dea29ffd 100644 --- a/docs/configs/Commands-Auth-Admin.html +++ b/docs/configs/Commands-Auth-Admin.html @@ -89,6 +89,7 @@ + @@ -294,7 +295,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Roles.html b/docs/configs/Commands-Auth-Roles.html index b23d64fe..a344862c 100644 --- a/docs/configs/Commands-Auth-Roles.html +++ b/docs/configs/Commands-Auth-Roles.html @@ -89,6 +89,7 @@ + @@ -320,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 7f3c116b..dff32e2e 100644 --- a/docs/configs/Commands-Auth-Runtime-Disable.html +++ b/docs/configs/Commands-Auth-Runtime-Disable.html @@ -90,6 +90,7 @@ + @@ -442,7 +443,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Parse-Roles.html b/docs/configs/Commands-Parse-Roles.html index 5a0b454f..60343ebc 100644 --- a/docs/configs/Commands-Parse-Roles.html +++ b/docs/configs/Commands-Parse-Roles.html @@ -89,6 +89,7 @@ + @@ -354,7 +355,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Parse.html b/docs/configs/Commands-Parse.html index 66516970..1361775e 100644 --- a/docs/configs/Commands-Parse.html +++ b/docs/configs/Commands-Parse.html @@ -89,6 +89,7 @@ + @@ -338,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 e636d935..37ca361d 100644 --- a/docs/configs/Compilatron.html +++ b/docs/configs/Compilatron.html @@ -89,6 +89,7 @@ + @@ -354,7 +355,7 @@ generated by LDoc diff --git a/docs/configs/Death-Logger.html b/docs/configs/Death-Logger.html index 63adb104..c8c36fab 100644 --- a/docs/configs/Death-Logger.html +++ b/docs/configs/Death-Logger.html @@ -89,6 +89,7 @@ + @@ -416,7 +417,7 @@ generated by LDoc diff --git a/docs/configs/Discord-Alerts.html b/docs/configs/Discord-Alerts.html index cb86d84e..233d45df 100644 --- a/docs/configs/Discord-Alerts.html +++ b/docs/configs/Discord-Alerts.html @@ -81,6 +81,7 @@ + @@ -237,7 +238,7 @@ generated by LDoc diff --git a/docs/configs/File-Loader.html b/docs/configs/File-Loader.html index e3cb46f4..aba7b05d 100644 --- a/docs/configs/File-Loader.html +++ b/docs/configs/File-Loader.html @@ -81,6 +81,7 @@ + @@ -240,7 +241,7 @@ generated by LDoc diff --git a/docs/configs/Permission-Groups.html b/docs/configs/Permission-Groups.html index 8dfe6166..8656a1f1 100644 --- a/docs/configs/Permission-Groups.html +++ b/docs/configs/Permission-Groups.html @@ -89,6 +89,7 @@ + @@ -295,7 +296,7 @@ generated by LDoc diff --git a/docs/configs/Player-List.html b/docs/configs/Player-List.html index 0027c816..239f7169 100644 --- a/docs/configs/Player-List.html +++ b/docs/configs/Player-List.html @@ -90,6 +90,7 @@ + @@ -812,7 +813,7 @@ generated by LDoc diff --git a/docs/configs/Pollution-Grading.html b/docs/configs/Pollution-Grading.html index 14621d46..3603fe03 100644 --- a/docs/configs/Pollution-Grading.html +++ b/docs/configs/Pollution-Grading.html @@ -89,6 +89,7 @@ + @@ -384,7 +385,7 @@ generated by LDoc diff --git a/docs/configs/Popup-Messages.html b/docs/configs/Popup-Messages.html index 65851fdb..be1095c3 100644 --- a/docs/configs/Popup-Messages.html +++ b/docs/configs/Popup-Messages.html @@ -89,6 +89,7 @@ + @@ -414,7 +415,7 @@ generated by LDoc diff --git a/docs/configs/Preset-Player-Colours.html b/docs/configs/Preset-Player-Colours.html index b8e9a7f2..133879c0 100644 --- a/docs/configs/Preset-Player-Colours.html +++ b/docs/configs/Preset-Player-Colours.html @@ -89,6 +89,7 @@ + @@ -324,7 +325,7 @@ generated by LDoc diff --git a/docs/configs/Repair.html b/docs/configs/Repair.html index d8468dde..88f593ff 100644 --- a/docs/configs/Repair.html +++ b/docs/configs/Repair.html @@ -89,6 +89,7 @@ + @@ -414,7 +415,7 @@ generated by LDoc diff --git a/docs/configs/Rockets.html b/docs/configs/Rockets.html index 4d7c8aa1..35df56b4 100644 --- a/docs/configs/Rockets.html +++ b/docs/configs/Rockets.html @@ -89,6 +89,7 @@ + @@ -834,7 +835,7 @@ generated by LDoc diff --git a/docs/configs/Roles.html b/docs/configs/Roles.html index 0414689b..c57368c1 100644 --- a/docs/configs/Roles.html +++ b/docs/configs/Roles.html @@ -89,6 +89,7 @@ + @@ -292,7 +293,7 @@ generated by LDoc diff --git a/docs/configs/Science.html b/docs/configs/Science.html index 2c7f4bf0..f52b2fbe 100644 --- a/docs/configs/Science.html +++ b/docs/configs/Science.html @@ -89,6 +89,7 @@ + @@ -354,7 +355,7 @@ generated by LDoc diff --git a/docs/configs/Scorched-Earth.html b/docs/configs/Scorched-Earth.html index 7b1c22e4..b7af3a39 100644 --- a/docs/configs/Scorched-Earth.html +++ b/docs/configs/Scorched-Earth.html @@ -89,6 +89,7 @@ + @@ -388,7 +389,7 @@ generated by LDoc diff --git a/docs/configs/Spawn-Area.html b/docs/configs/Spawn-Area.html index a7012781..6853d015 100644 --- a/docs/configs/Spawn-Area.html +++ b/docs/configs/Spawn-Area.html @@ -89,6 +89,7 @@ + @@ -744,7 +745,7 @@ generated by LDoc diff --git a/docs/configs/Tasks.html b/docs/configs/Tasks.html index 5b9b0515..cd84fc0c 100644 --- a/docs/configs/Tasks.html +++ b/docs/configs/Tasks.html @@ -89,6 +89,7 @@ + @@ -384,7 +385,7 @@ generated by LDoc diff --git a/docs/configs/Warnings.html b/docs/configs/Warnings.html index 3db69aec..d298e402 100644 --- a/docs/configs/Warnings.html +++ b/docs/configs/Warnings.html @@ -89,6 +89,7 @@ + @@ -355,7 +356,7 @@ generated by LDoc diff --git a/docs/configs/Warps.html b/docs/configs/Warps.html index afe2df6d..ccdb5910 100644 --- a/docs/configs/Warps.html +++ b/docs/configs/Warps.html @@ -89,6 +89,7 @@ + @@ -684,7 +685,7 @@ generated by LDoc diff --git a/docs/control/Jail.html b/docs/control/Jail.html index 2bf7eb2b..3858e706 100644 --- a/docs/control/Jail.html +++ b/docs/control/Jail.html @@ -73,6 +73,7 @@ + @@ -1208,7 +1209,7 @@ generated by LDoc diff --git a/docs/control/Production.html b/docs/control/Production.html index 389e1d52..9eab886b 100644 --- a/docs/control/Production.html +++ b/docs/control/Production.html @@ -73,6 +73,7 @@ + @@ -1329,7 +1330,7 @@ generated by LDoc diff --git a/docs/control/Reports.html b/docs/control/Reports.html index 8c602cfd..d7397705 100644 --- a/docs/control/Reports.html +++ b/docs/control/Reports.html @@ -73,6 +73,7 @@ + @@ -1110,7 +1111,7 @@ generated by LDoc diff --git a/docs/control/Rockets.html b/docs/control/Rockets.html index 549afdb6..9f196c46 100644 --- a/docs/control/Rockets.html +++ b/docs/control/Rockets.html @@ -72,6 +72,7 @@ + @@ -984,7 +985,7 @@ generated by LDoc diff --git a/docs/control/Tasks.html b/docs/control/Tasks.html index c6c98a92..fb62ed5f 100644 --- a/docs/control/Tasks.html +++ b/docs/control/Tasks.html @@ -72,6 +72,7 @@ + @@ -1039,7 +1040,7 @@ generated by LDoc diff --git a/docs/control/Warnings.html b/docs/control/Warnings.html index f13263e7..0343a416 100644 --- a/docs/control/Warnings.html +++ b/docs/control/Warnings.html @@ -72,6 +72,7 @@ + @@ -1465,7 +1466,7 @@ generated by LDoc diff --git a/docs/control/Warps.html b/docs/control/Warps.html index 7a808d9e..b11de74d 100644 --- a/docs/control/Warps.html +++ b/docs/control/Warps.html @@ -73,6 +73,7 @@ + @@ -1413,7 +1414,7 @@ generated by LDoc diff --git a/docs/core/Commands.html b/docs/core/Commands.html index b7665406..e72da3ba 100644 --- a/docs/core/Commands.html +++ b/docs/core/Commands.html @@ -61,6 +61,7 @@ + @@ -1972,7 +1973,7 @@ generated by LDoc diff --git a/docs/core/Common-Library.html b/docs/core/Common-Library.html index 704bb0b4..5d3f775f 100644 --- a/docs/core/Common-Library.html +++ b/docs/core/Common-Library.html @@ -57,6 +57,7 @@ + @@ -2746,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 7001ba8e..861627e8 100644 --- a/docs/core/Gui.html +++ b/docs/core/Gui.html @@ -66,6 +66,7 @@ + @@ -501,6 +502,10 @@ button:clone('CustomButton')
    + + + + @@ -3468,6 +3473,71 @@ button:change_name('Not Button') Gui.get_concept('Button'):clone('CustomButton') + +
    +
    +
    + # + Prototype:define_clone(clone_callback) +
    +
    +
    +
    + +

    Use to add your own callbacks to the clone function, for example adding to a local table

    +

    + + + Parameters: + +
      + + + + + +
    • + + clone_callback + + : + + (function) + + the function which is called with the concept to have something done to it + +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + self to allow chaining +
    • +
    + + + + + + + + Usage: +
    -- Adding concept to a local table
    +local buttons = {}
    +local button =
    +Gui.get_concept('Button')
    +:define_clone(function(concept)
    +    buttons[concept.name] = concept
    +end)
    + +
    @@ -4970,7 +5040,7 @@ Gui.get_concept('CustomButton') generated by LDoc diff --git a/docs/core/Permissions-Groups.html b/docs/core/Permissions-Groups.html index d6cfd67e..e10f905a 100644 --- a/docs/core/Permissions-Groups.html +++ b/docs/core/Permissions-Groups.html @@ -60,6 +60,7 @@ + @@ -1432,7 +1433,7 @@ generated by LDoc diff --git a/docs/core/Roles.html b/docs/core/Roles.html index 90aaa30a..40948b8d 100644 --- a/docs/core/Roles.html +++ b/docs/core/Roles.html @@ -64,6 +64,7 @@ + @@ -3152,7 +3153,7 @@ generated by LDoc diff --git a/docs/core/Store.html b/docs/core/Store.html index c426c2a9..e56e6911 100644 --- a/docs/core/Store.html +++ b/docs/core/Store.html @@ -57,6 +57,7 @@ + @@ -1145,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 cb87e968..4f88af42 100644 --- a/docs/core/Sudo.html +++ b/docs/core/Sudo.html @@ -57,6 +57,7 @@ + @@ -544,7 +545,7 @@ generated by LDoc diff --git a/docs/core/Toolbar.html b/docs/core/Toolbar.html new file mode 100644 index 00000000..0da30385 --- /dev/null +++ b/docs/core/Toolbar.html @@ -0,0 +1,1638 @@ + + + + + + + + Toolbar core + + + + + + + +
    +
    + + + + + + + +
    + + + + + + + + +

    Toolbar core

    +

    Core Module - Toolbar

    +

    + + + + + + + + + + + +
    Used to copy all the settings from one concept to another and removing links to the orginal
    Prototype:define_clone(clone_callback)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
    + +

    Dependencies

    + + + + + + + + + + + + + + + + + + + +
    expcore.gui
    expcore.roles
    utils.event
    utils.game
    mod-gui
    + + +

    Permissions

    + + + + + + + + + + + + +
    allowed(player, concept_name)Used to test if a player is allowed to use a button on the toolbar, if you are not using expcore.roles then change this function
    set_permission_alias(concept_name, alias)Use to add an alias for the allowed test, alias is what is tested for rather than the concept name
    + + +

    Buttons

    + + + + + + + + + + + + + + + + + + + + +
    add_button_concept(concept)Adds a concept to be drawn to the button area and allows it to be toggled with the toggle toolbar button
    update_buttons(player)Updates all the buttons for a player, this means hide and show buttons based on permissions
    get_visible_buttons(player)Returns an array of buttons names that the given player is able to see, returns none if toolbar hidden
    toolbar-buttonThe base element to be used with the toolbar, others can be used but this is recomented
    + + +

    Frames

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    add_frame_concept(concept)Adds a frame concept to the toolbar frame area, this will not add a button to the toolbar
    hide_frames(player)Hides all the frames for a player
    get_visible_frames(player)Gets an array of the names of all the visible frames for a player
    toolbar-frameThe base toolbar frame, others can be used but this is recomented
    Toolbar.frame:get_content(player)Gets the content area of the frame concept for this player, each player only has one area
    Toolbar.frame:toggle_visible_state(player)Toggles the visibilty of this concept for the given player
    Toolbar.frame:get_visible_state(player)Gets the current visibilty state of this conept for this player
    Toolbar.frame:update(player[, event])Triggers an update of the content within the concept for this player, uses on_update handlers
    Toolbar.frame:update_all([event])Triggers an update of the content with in this frame for all players
    + + +

    Other Elements

    + + + + + + + + + + + + + + + + +
    toolbarThe main toolbar element, draws, updates, and controls the other concepts
    toolbar-toggleButton which toggles the the visible state of all toolbar buttons, triggers on_button_update
    toolbar-clearButton which hides all visible toolbar frames, triggers on_hide_frames
    + + +
    + + +

    Dependencies

    +
    +
    +
    +
    + # + expcore.gui +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.roles +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + utils.event +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + utils.game +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + mod-gui +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +

    Permissions

    +
    +
    +
    +
    + # + allowed(player, concept_name) +
    +
    +
    +
    + +

    Used to test if a player is allowed to use a button on the toolbar, if you are not using expcore.roles then change this function

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player you want ot test is allowed to use this button + +
    • + + + + + +
    • + + concept_name + + : + + (string) + + the name of the button concept that you want to see if the player is allowed to use + +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + true if the player is allowed to use it +
    • +
    + + + + + + + + Usage: +
    -- Test if a player can use 'test-player-list'
    +local allowed = Toolbar.allowed(game.player,'test-player-list')
    + + +
    +
    +
    +
    + # + set_permission_alias(concept_name, alias) +
    +
    +
    +
    + +

    Use to add an alias for the allowed test, alias is what is tested for rather than the concept name

    +

    + + + Parameters: + +
      + + + + + +
    • + + concept_name + + : + + (string) + + the name of the concept that will point to this alias + +
    • + + + + + +
    • + + alias + + : + + (string) + + the permission string that will be tested when this concept is used with Toolbar.allowed + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Adding an alias for the 'test-player-list' concept
    +Toolbar.set_permission_alias('test-player-list','gui/player-list')
    + + +
    +
    +

    Buttons

    +
    +
    +
    +
    + # + add_button_concept(concept) +
    +
    +
    +
    + +

    Adds a concept to be drawn to the button area and allows it to be toggled with the toggle toolbar button

    +

    + + + Parameters: + +
      + + + + + +
    • + + concept + + : + + (table) + + 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')
    +:set_caption('Click Me')
    +:on_click(function(event)
    +    event.player.print('You Clicked Me!!')
    +end)
    +
    +Toolbar.add_button_concept(new_button)
    + + +
    +
    +
    +
    + # + update_buttons(player) +
    +
    +
    +
    + +

    Updates all the buttons for a player, this means hide and show buttons based on permissions

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player to update the toolbar buttons for + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Updating your toolbar
    +Toolbar.update_buttons(player)
    + + +
    +
    +
    +
    + # + get_visible_buttons(player) +
    +
    +
    +
    + +

    Returns an array of buttons names that the given player is able to see, returns none if toolbar hidden

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player you want to get the visible buttons of + +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + an array of names of the visible buttons +
    • +
    + + + + + + + + Usage: +
    -- Get a list of all your visible buttons
    +Toolbar.get_visible_buttons(game.player)
    + + +
    +
    +
    +
    + # + toolbar-button +
    +
    +
    +
    + +

    The base element to be used with the toolbar, others can be used but this is recomented

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + permission_alias + + : + + (string) + + 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')
    +:set_caption('Click Me')
    +:on_click(function(event)
    +    event.player.print('You Clicked Me!!')
    +end)
    + + +
    +
    +

    Frames

    +
    +
    +
    +
    + # + add_frame_concept(concept) +
    +
    +
    +
    + +

    Adds a frame concept to the toolbar frame area, this will not add a button to the toolbar

    +

    + + + Parameters: + +
      + + + + + +
    • + + concept + + : + + (table) + + 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')
    +:set_title('Test')
    +
    +Toolbar.add_frame_concept(new_frame)
    + + +
    +
    +
    +
    + # + hide_frames(player) +
    +
    +
    +
    + +

    Hides all the frames for a player

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player to hide the frames for + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Hiding all your frames
    +Toolbar.hide_frames(game.player)
    + + +
    +
    +
    +
    + # + get_visible_frames(player) +
    +
    +
    +
    + +

    Gets an array of the names of all the visible frames for a player

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player that you want to get the visible frames of + +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + an array of names of the visible frames for the given player +
    • +
    + + + + + + + + Usage: +
    -- Get all your visible frames
    +Toolbar.get_visible_frames(game.player)
    + + +
    +
    +
    +
    + # + toolbar-frame +
    +
    +
    +
    + +

    The base toolbar frame, others can be used but this is recomented

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + on_update + + : + + + fired when the frame is to have its content updated + +
    • + + + + + +
    • + + open_by_default + + : + + (boolean) + + weather the frame should be open when a player first joins + +
    • + + + + + +
    • + + use_container + + : + + (boolean) + + true by default and will place a container inside the frame for content + +
    • + + + + + +
    • + + direction + + : + + (string) + + 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')
    +:set_permission_alias('player_list')
    +:set_caption('Player List')
    +:toggle_with_click()
    +:define_draw(function(properties,parent,element)
    +    local list_area =
    +    element.add{
    +        name = 'scroll',
    +        type = 'scroll-pane',
    +        direction = 'vertical',
    +        horizontal_scroll_policy = 'never',
    +        vertical_scroll_policy = 'auto-and-reserve-space'
    +    }
    +    Gui.set_padding(list_area,1,1,2,2)
    +    list_area.style.horizontally_stretchable = true
    +    list_area.style.maximal_height = 200
    +
    +    for _,player in pairs(game.connected_players) do
    +        list_area.add{
    +            type='label',
    +            caption=player.name
    +        }
    +    end
    +end)
    +:on_update(function(event)
    +    local list_area = event.element.scroll
    +    list_area.clear()
    +
    +    for _,player in pairs(game.connected_players) do
    +        list_area.add{
    +            type='label',
    +            caption=player.name
    +        }
    +    end
    +end)
    + + +
    +
    +
    +
    + # + Toolbar.frame:get_content(player) +
    +
    +
    +
    + +

    Gets the content area of the frame concept for this player, each player only has one area

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player that you want to get the frame content for + +
    • + + +
    + + + + + Returns: +
      +
    • + (LuaGuiElement) + the content area of this concept for this player +
    • +
    + + + + + + + + Usage: +
    -- Get the content area of a concept
    +local frame = player_list:get_content(game.player)
    + + +
    +
    +
    +
    + # + Toolbar.frame:toggle_visible_state(player) +
    +
    +
    +
    + +

    Toggles the visibilty of this concept for the given player

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player that you want to toggle the frame for + +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + the new state of the visibilty of this concept for the player +
    • +
    + + + + + + + + Usage: +
    -- Toggle the frame for your self
    +player_list:toggle_visible_state(game.player)
    + + +
    +
    +
    +
    + # + Toolbar.frame:get_visible_state(player) +
    +
    +
    +
    + +

    Gets the current visibilty state of this conept for this player

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player that you want the visibilty state for + +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + the current visiblity state of this concept to the player +
    • +
    + + + + + + + + Usage: +
    -- Getting the current visiblity state
    + + +
    +
    +
    +
    + # + Toolbar.frame:update(player[, event]) +
    +
    +
    +
    + +

    Triggers an update of the content within the concept for this player, uses on_update handlers

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player to update the concept content for + +
    • + + + + + +
    • + + event + + : + + (table) + + the event data that you want to pass to the update handlers + + (optional) +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Updating the frame for your player
    +player_list:update(game.player)
    + + +
    +
    +
    +
    + # + Toolbar.frame:update_all([event]) +
    +
    +
    +
    + +

    Triggers an update of the content with in this frame for all players

    +

    + + + Parameters: + +
      + + + + + +
    • + + event + + : + + (table) + + the event data that you want to pass to the update handlers + + (optional) +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Update the grame for all players
    +player_list:update_all()
    + + +
    +
    +

    Other Elements

    +
    +
    +
    +
    + # + toolbar +
    +
    +
    +
    + +

    The main toolbar element, draws, updates, and controls the other concepts

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + on_button_update + + : + + + fired when the buttons are updated for a player + +
    • + + + + + +
    • + + on_hide_frames + + : + + + fired when the frames are hidden for a player + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + toolbar-toggle +
    +
    +
    +
    + +

    Button which toggles the the visible state of all toolbar buttons, triggers on_button_update

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + toolbar-clear +
    +
    +
    +
    + +

    Button which hides all visible toolbar frames, triggers on_hide_frames

    +

    + + + + + + + + + + + + + + +
    +
    + + + + + + + + + + diff --git a/docs/guis/Player-List.html b/docs/guis/Player-List.html index 85e9bd5b..439db206 100644 --- a/docs/guis/Player-List.html +++ b/docs/guis/Player-List.html @@ -69,6 +69,7 @@ + @@ -626,7 +627,7 @@ generated by LDoc diff --git a/docs/guis/Rocket-Info.html b/docs/guis/Rocket-Info.html index 4f70f60a..0f113473 100644 --- a/docs/guis/Rocket-Info.html +++ b/docs/guis/Rocket-Info.html @@ -69,6 +69,7 @@ + @@ -629,7 +630,7 @@ generated by LDoc diff --git a/docs/guis/Science-Info.html b/docs/guis/Science-Info.html index db01d658..b26e1560 100644 --- a/docs/guis/Science-Info.html +++ b/docs/guis/Science-Info.html @@ -69,6 +69,7 @@ + @@ -449,7 +450,7 @@ generated by LDoc diff --git a/docs/guis/Task-List.html b/docs/guis/Task-List.html index da16f049..f6d43bb5 100644 --- a/docs/guis/Task-List.html +++ b/docs/guis/Task-List.html @@ -69,6 +69,7 @@ + @@ -632,7 +633,7 @@ generated by LDoc diff --git a/docs/guis/Warps-List.html b/docs/guis/Warps-List.html index 293094c5..545bb8b4 100644 --- a/docs/guis/Warps-List.html +++ b/docs/guis/Warps-List.html @@ -69,6 +69,7 @@ + @@ -837,7 +838,7 @@ generated by LDoc diff --git a/docs/index.html b/docs/index.html index 2d5a06dd..372ce97b 100644 --- a/docs/index.html +++ b/docs/index.html @@ -78,6 +78,10 @@ Core Module - Sudo - An extention of task and token to allow a single require to register and run functions bypassing all permissions. + + Toolbar + Core Module - Toolbar +

    Addons

    @@ -510,7 +514,7 @@ see ./expcore/commands.lua for more detailsgenerated by LDoc diff --git a/docs/modules/control.html b/docs/modules/control.html index 377e2e4d..6d625e00 100644 --- a/docs/modules/control.html +++ b/docs/modules/control.html @@ -76,6 +76,7 @@ + @@ -351,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 cb214d8e..1cfaeb22 100644 --- a/docs/modules/utils.alien_evolution_progress.html +++ b/docs/modules/utils.alien_evolution_progress.html @@ -77,6 +77,7 @@ + @@ -419,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 4f6a5936..9dda491f 100644 --- a/docs/modules/utils.core.html +++ b/docs/modules/utils.core.html @@ -78,6 +78,7 @@ + @@ -1164,7 +1165,7 @@ generated by LDoc diff --git a/docs/modules/utils.debug.html b/docs/modules/utils.debug.html index 967c465d..b3c9bca3 100644 --- a/docs/modules/utils.debug.html +++ b/docs/modules/utils.debug.html @@ -76,6 +76,7 @@ + @@ -654,7 +655,7 @@ generated by LDoc diff --git a/docs/modules/utils.dump_env.html b/docs/modules/utils.dump_env.html index 5d97b286..b4da436e 100644 --- a/docs/modules/utils.dump_env.html +++ b/docs/modules/utils.dump_env.html @@ -76,6 +76,7 @@ + @@ -323,7 +324,7 @@ generated by LDoc diff --git a/docs/modules/utils.event.html b/docs/modules/utils.event.html index ef1fb0ef..13a7680e 100644 --- a/docs/modules/utils.event.html +++ b/docs/modules/utils.event.html @@ -77,6 +77,7 @@ + @@ -1292,7 +1293,7 @@ generated by LDoc diff --git a/docs/modules/utils.event_core.html b/docs/modules/utils.event_core.html index c7c8acd0..90ced63a 100644 --- a/docs/modules/utils.event_core.html +++ b/docs/modules/utils.event_core.html @@ -76,6 +76,7 @@ + @@ -434,7 +435,7 @@ generated by LDoc diff --git a/docs/modules/utils.math.html b/docs/modules/utils.math.html index c653377a..b4f8fd77 100644 --- a/docs/modules/utils.math.html +++ b/docs/modules/utils.math.html @@ -76,6 +76,7 @@ + @@ -338,7 +339,7 @@ generated by LDoc diff --git a/docs/modules/utils.recipe_locker.html b/docs/modules/utils.recipe_locker.html index 0a43c0e9..34d5d12a 100644 --- a/docs/modules/utils.recipe_locker.html +++ b/docs/modules/utils.recipe_locker.html @@ -77,6 +77,7 @@ + @@ -441,7 +442,7 @@ generated by LDoc diff --git a/docs/modules/utils.state_machine.html b/docs/modules/utils.state_machine.html index fc44bc7b..d3325639 100644 --- a/docs/modules/utils.state_machine.html +++ b/docs/modules/utils.state_machine.html @@ -77,6 +77,7 @@ + @@ -752,7 +753,7 @@ generated by LDoc diff --git a/docs/modules/utils.table.html b/docs/modules/utils.table.html index 1a9ef65d..c76d0411 100644 --- a/docs/modules/utils.table.html +++ b/docs/modules/utils.table.html @@ -78,6 +78,7 @@ + @@ -1382,7 +1383,7 @@ generated by LDoc diff --git a/docs/modules/utils.task.html b/docs/modules/utils.task.html index 3d86cca1..ce165620 100644 --- a/docs/modules/utils.task.html +++ b/docs/modules/utils.task.html @@ -77,6 +77,7 @@ + @@ -651,7 +652,7 @@ generated by LDoc diff --git a/docs/modules/utils.timestamp.html b/docs/modules/utils.timestamp.html index e5be71ff..5c227954 100644 --- a/docs/modules/utils.timestamp.html +++ b/docs/modules/utils.timestamp.html @@ -76,6 +76,7 @@ + @@ -442,7 +443,7 @@ generated by LDoc diff --git a/docs/topics/license.html b/docs/topics/license.html index 2e77eb29..757e9dcd 100644 --- a/docs/topics/license.html +++ b/docs/topics/license.html @@ -57,6 +57,7 @@ + @@ -789,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 50cc7c47..1d767ad7 100644 --- a/docs/topics/readme.md.html +++ b/docs/topics/readme.md.html @@ -57,6 +57,7 @@ + @@ -332,7 +333,7 @@ generated by LDoc diff --git a/expcore/gui/concepts/button.lua b/expcore/gui/concepts/button.lua index ce79e6a6..196cc117 100644 --- a/expcore/gui/concepts/button.lua +++ b/expcore/gui/concepts/button.lua @@ -50,21 +50,21 @@ end) properties.type = 'sprite-button' end) :define_draw(function(properties,parent,element) - if properties.type == 'button' then + if properties.type == 'sprite-button' then element = parent.add{ name = properties.name, - type = properties.type, - caption = properties.caption, + type = 'sprite-button', + sprite = properties.sprite, + hovered_sprite = properties.hovered_sprite, + clicked_sprite = properties.clicked_sprite, tooltip = properties.tooltip } else element = parent.add{ name = properties.name, - type = properties.type, - sprite = properties.sprite, - hovered_sprite = properties.hovered_sprite, - clicked_sprite = properties.clicked_sprite, + type = 'button', + caption = properties.caption, tooltip = properties.tooltip } diff --git a/expcore/gui/core.lua b/expcore/gui/core.lua index 08bec3d2..e45101f9 100644 --- a/expcore/gui/core.lua +++ b/expcore/gui/core.lua @@ -188,6 +188,7 @@ function Gui.set_padding(element,up,down,left,right) end --[[ Used to check a property exists and if it is a function then call the function +@function Gui.resolve_property @tparam any value the value that you are testing exists and call if its a function @tparam LuaGuiElement element the element that is passed to the function if it is a function @treturn any the value or what it returns if it is a function diff --git a/expcore/gui/prototype.lua b/expcore/gui/prototype.lua index 5fb2629e..cac0d37e 100644 --- a/expcore/gui/prototype.lua +++ b/expcore/gui/prototype.lua @@ -75,6 +75,7 @@ local Game = require 'utils.game' -- @dep utils.game local Factorio_Events = {} local Prototype = { draw_callbacks = {}, + clone_callbacks = {}, properties = {}, factorio_events = {}, events = {} @@ -159,9 +160,40 @@ function Prototype:clone(concept_name) concept.set_store_from_instance = nil end + -- Loop over all the clone defines, element is updated when a value is returned + 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) + end + end + return concept end +--[[-- Use to add your own callbacks to the clone function, for example adding to a local table +@tparam function clone_callback the function which is called with the concept to have something done to it +@treturn table self to allow chaining +@usage-- Adding concept to a local table +local buttons = {} +local button = +Gui.get_concept('Button') +:define_clone(function(concept) + buttons[concept.name] = concept +end) +]] +function Prototype:define_clone(clone_callback) + -- Check that it is a function that is being added + if type(clone_callback) ~= 'function' then + error('Draw define must be a function',2) + end + + -- Add the draw function + self.clone_callbacks[#self.clone_callbacks+1] = 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 @@ -280,7 +312,7 @@ 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..': '..err) + error('Gui event handler error with '..self.name..'/'..event_name..':\n\t'..err) end end end @@ -335,7 +367,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..': '..err) + error('Gui property handler error with '..concept.name..'/'..property_name..':\n\t'..err) end else -- Otherwise just update the key @@ -413,7 +445,7 @@ function Prototype:draw(parent_element,...) if success and rtn then element = rtn elseif not success then - error('Gui draw handler error with '..self.name..': '..rtn) + error('Gui draw handler error with '..self.name..':\n\t'..rtn) end end diff --git a/expcore/gui/test.lua b/expcore/gui/test.lua index afee4f8f..776bfa59 100644 --- a/expcore/gui/test.lua +++ b/expcore/gui/test.lua @@ -8,7 +8,9 @@ -- @section tests local Gui = require 'expcore.gui' -local Game = require 'utils.game' -- @dep utils.game +local Game = require 'utils.game' +local Event = require 'utils.event' +require 'expcore.toolbar' local test_prefix = '__GUI_TEST_' local tests = {} @@ -32,6 +34,59 @@ Gui.clone_concept('frame',TEST 'test_frame') end end) +Gui.clone_concept('toolbar-button',TEST 'run_test_button') +:set_permission_alias('gui-test') +:set_caption('Element Tests') +:on_click(function(event) + local player = event.player + if not Gui.destroy(player.gui.center[test_frame.name]) then + Gui.run_tests(event.player) + end +end) + +local test_left_frame = +Gui.clone_concept('toolbar-frame',TEST 'player_list') +:set_permission_alias('gui-test') +:set_caption('Frame Test Left') +:define_draw(function(properties,parent,element) + local list_area = + element.add{ + name = 'scroll', + type = 'scroll-pane', + direction = 'vertical', + horizontal_scroll_policy = 'never', + vertical_scroll_policy = 'auto-and-reserve-space' + } + Gui.set_padding(list_area,1,1,2,2) + list_area.style.horizontally_stretchable = true + list_area.style.maximal_height = 200 + + for _,player in pairs(game.connected_players) do + list_area.add{ + type='label', + caption=player.name + } + end +end) +:on_update(function(event) + local list_area = event.element.scroll + list_area.clear() + + for _,player in pairs(game.connected_players) do + list_area.add{ + type='label', + caption=player.name + } + end +end) + +Event.add(defines.events.on_player_joined_game,function(event) + test_left_frame:update_all(event) +end) +Event.add(defines.events.on_player_left_game,function(event) + test_left_frame:update_all(event) +end) + --[[-- Runs a set of gui tests to ensure that the system is working @tparam LuaPlayer player the player that the guis are made for and who recives the results @tparam[opt] string category when given only tests in this category are ran diff --git a/expcore/toolbar.lua b/expcore/toolbar.lua new file mode 100644 index 00000000..a601a7ab --- /dev/null +++ b/expcore/toolbar.lua @@ -0,0 +1,469 @@ +--[[-- Core Module - Toolbar + @core Toolbar + @alias Toolbar +]] + +local Gui = require 'expcore.gui' --- @dep expcore.gui +local Roles = require 'expcore.roles' --- @dep expcore.roles +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 + +local toolbar_toggle_concept +local toolbar_hide_concept +local toolbar_concept +local Toolbar = { + button_concepts = {}, + frame_concepts = {}, + permissions = {} +} + +Gui.Toolbar = Toolbar + +--- Permissions. +-- Functions to do with deciding which player can do what +-- @section permissions + +--[[-- Used to test if a player is allowed to use a button on the toolbar, if you are not using expcore.roles then change this function +@tparam LuaPlayer player the player you want ot test is allowed to use this button +@tparam string concept_name the name of the button concept that you want to see if the player is allowed to use +@treturn boolean true if the player is allowed to use it +@usage-- Test if a player can use 'test-player-list' +local allowed = Toolbar.allowed(game.player,'test-player-list') +]] +function Toolbar.allowed(player,concept_name) + local permission = Toolbar.permissions[concept_name] or concept_name + return Roles.player_allowed(player,permission) +end + +--[[-- Use to add an alias for the allowed test, alias is what is tested for rather than the concept name +@tparam string concept_name the name of the concept that will point to this alias +@tparam string alias the permission string that will be tested when this concept is used with Toolbar.allowed +@usage-- Adding an alias for the 'test-player-list' concept +Toolbar.set_permission_alias('test-player-list','gui/player-list') +]] +function Toolbar.set_permission_alias(concept_name,alias) + Toolbar.permissions[concept_name] = alias +end + +--- Buttons. +-- All function to do with the toolbar buttons +-- @section buttons + +--[[-- Adds a concept to be drawn to the button area and allows it to be toggled with the toggle toolbar button +@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') +:set_caption('Click Me') +:on_click(function(event) + event.player.print('You Clicked Me!!') +end) + +Toolbar.add_button_concept(new_button) +]] +function Toolbar.add_button_concept(concept) + local concepts = Toolbar.button_concepts + concepts[#concepts+1] = concept +end + +--[[-- Updates all the buttons for a player, this means hide and show buttons based on permissions +@tparam LuaPlayer player the player to update the toolbar buttons for +@usage-- Updating your toolbar +Toolbar.update_buttons(player) +]] +function Toolbar.update_buttons(player) + toolbar_concept:raise_event('on_button_update',{ + player_index = player.index + }) +end + +--[[-- Returns an array of buttons names that the given player is able to see, returns none if toolbar hidden +@tparam LuaPlayer player the player you want to get the visible buttons of +@treturn table an array of names of the visible buttons +@usage-- Get a list of all your visible buttons +Toolbar.get_visible_buttons(game.player) +]] +function Toolbar.get_visible_buttons(player) + local rtn = {} + local top_flow = mod_gui.get_button_flow(player) + + for _,concept in pairs(Toolbar.button_concepts) do + local element = top_flow[concept.name] + if element.visible then + rtn[#rtn+1] = element.name + end + end + + return rtn +end + +--[[-- The base element to be used with the toolbar, others can be used but this is recomented +@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') +:set_caption('Click Me') +:on_click(function(event) + event.player.print('You Clicked Me!!') +end) +]] +Toolbar.button = +Gui.clone_concept('button','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 +end) + +--- Frames. +-- Functions to do with the toolbar frames +-- @section frames + +--[[-- Adds a frame concept to the toolbar frame area, this will not add a button to the toolbar +@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') +:set_title('Test') + +Toolbar.add_frame_concept(new_frame) +]] +function Toolbar.add_frame_concept(concept) + local concepts = Toolbar.frame_concepts + concepts[#concepts+1] = concept +end + +--[[-- Hides all the frames for a player +@tparam LuaPlayer player the player to hide the frames for +@usage-- Hiding all your frames +Toolbar.hide_frames(game.player) +]] +function Toolbar.hide_frames(player) + toolbar_concept:raise_event('on_hide_frames',{ + player_index = player.index + }) +end + +--[[-- Gets an array of the names of all the visible frames for a player +@tparam LuaPlayer player the player that you want to get the visible frames of +@treturn table an array of names of the visible frames for the given player +@usage-- Get all your visible frames +Toolbar.get_visible_frames(game.player) +]] +function Toolbar.get_visible_frames(player) + local rtn = {} + local left_flow = mod_gui.get_frame_flow(player) + + for _,concept in pairs(Toolbar.frame_concepts) do + local element = left_flow[concept.name..'-frame'] + if element.visible then + rtn[#rtn+1] = element.name + end + end + + left_flow[toolbar_hide_concept.name].visible = #rtn > 0 + + return rtn +end + +--[[-- The base toolbar frame, others can be used but this is recomented +@element toolbar-frame +@param on_update fired when the frame is to have its content updated +@tparam boolean open_by_default weather the frame should be open when a player first joins +@tparam boolean use_container true by default and will place a container inside the frame for content +@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') +:set_permission_alias('player_list') +:set_caption('Player List') +:toggle_with_click() +:define_draw(function(properties,parent,element) + local list_area = + element.add{ + name = 'scroll', + type = 'scroll-pane', + direction = 'vertical', + horizontal_scroll_policy = 'never', + vertical_scroll_policy = 'auto-and-reserve-space' + } + Gui.set_padding(list_area,1,1,2,2) + list_area.style.horizontally_stretchable = true + list_area.style.maximal_height = 200 + + for _,player in pairs(game.connected_players) do + list_area.add{ + type='label', + caption=player.name + } + end +end) +:on_update(function(event) + local list_area = event.element.scroll + list_area.clear() + + for _,player in pairs(game.connected_players) do + list_area.add{ + type='label', + caption=player.name + } + end +end) +]] +Toolbar.frame = +Gui.clone_concept('toolbar-button','toolbar-frame') +:new_property('open_by_default',false) +:new_property('use_container',true) +:new_property('direction','horizontal') +:new_event('on_update') +:define_clone(function(concept) + Toolbar.add_frame_concept(concept) + concept:on_click(function(event) + event.concept:toggle_visible_state(event.player) + end) +end) +: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) + local left_flow = mod_gui.get_frame_flow(player) + local frame = left_flow.add{ + name = properties.name..'-frame', + type = 'frame', + direction = properties.direction + } + + frame.style.padding = 2 + + -- Add and return the container if a container is used + if properties.use_container then + local container = + frame.add{ + name = 'container', + type = 'frame', + direction = properties.direction, + style = 'window_content_frame_packed' + } + Gui.set_padding(container) + + return container + + end + + return frame +end) + +--[[-- Gets the content area of the frame concept for this player, each player only has one area +@tparam LuaPlayer player the player that you want to get the frame content for +@treturn LuaGuiElement the content area of this concept for this player +@usage-- Get the content area of a concept +local frame = player_list:get_content(game.player) +]] +function Toolbar.frame:get_content(player) + local left_flow = mod_gui.get_frame_flow(player) + local frame = left_flow[self.name..'-frame'] + return frame.container or frame +end + +--[[-- Toggles the visibilty of this concept for the given player +@tparam LuaPlayer player the player that you want to toggle the frame for +@treturn boolean the new state of the visibilty of this concept for the player +@usage-- Toggle the frame for your self +player_list:toggle_visible_state(game.player) +]] +function Toolbar.frame:toggle_visible_state(player) + local left_flow = mod_gui.get_frame_flow(player) + local frame = left_flow[self.name..'-frame'] + if frame.visible then + frame.visible = false + Toolbar.get_visible_frames(player) + return false + else + frame.visible = true + Toolbar.get_visible_frames(player) + return true + end +end + +--[[-- Gets the current visibilty state of this conept for this player +@tparam LuaPlayer player the player that you want the visibilty state for +@treturn boolean the current visiblity state of this concept to the player +@usage-- Getting the current visiblity state +player_list:get_visible_state(player)]] +function Toolbar.frame:get_visible_state(player) + local left_flow = mod_gui.get_frame_flow(player) + return left_flow[self.name..'-frame'].visible +end + +--[[-- Triggers an update of the content within the concept for this player, uses on_update handlers +@tparam LuaPlayer player the player to update the concept content for +@tparam[opt] table event the event data that you want to pass to the update handlers +@usage-- Updating the frame for your player +player_list:update(game.player) +]] +function Toolbar.frame:update(player,event) + event = event or {} + event.player_index = player.index + event.element = self:get_content(player) + self:raise_event('on_update',event) +end + +--[[-- Triggers an update of the content with in this frame for all players +@tparam[opt] table event the event data that you want to pass to the update handlers +@usage-- Update the grame for all players +player_list:update_all() +]] +function Toolbar.frame:update_all(event) + local players = event.update_offline == true and game.players or game.connected_players + for _,player in pairs(players) do + self:update(player) + end +end + +--- Other Elements. +-- All the other elements that are used to make this work +-- @section elements + +--[[-- The main toolbar element, draws, updates, and controls the other concepts +@element toolbar +@param on_button_update fired when the buttons are updated for a player +@param on_hide_frames fired when the frames are hidden for a player +]] +toolbar_concept = +Gui.new_concept('toolbar') +:define_draw(function(properties,player) + -- Get the main flows + local top_flow = mod_gui.get_button_flow(player) + if not top_flow then return end + local left_flow = mod_gui.get_frame_flow(player) + if not left_flow then return end + + -- Draw toggle buttons first + toolbar_toggle_concept:draw(top_flow) + toolbar_hide_concept:draw(left_flow) + + -- Draw all the buttons and frames + local done = {} + for _,concept in pairs(Toolbar.button_concepts) do + done[concept.name] = true + concept:draw(top_flow) + top_flow[concept.name].visible = Toolbar.allowed(player,concept.name) + + local frame = left_flow[concept.name..'-frame'] + if frame then + frame.visible = Gui.resolve_property(concept.properties.open_by_default,frame) + end + end + + -- Draws frames that did not have buttons + for _,concept in pairs(Toolbar.frame_concepts) do + if not done[concept.name] then + concept:draw(left_flow) + local frame = left_flow[concept.name..'-frame'] + if frame then + frame.visible = Gui.resolve_property(concept.properties.open_by_default,frame) + end + end + end + + -- Toggle the clear toobar if needed + Toolbar.get_visible_frames(player) + +end) +:new_event('on_button_update') +:on_button_update(function(event) + -- Get the top flow + local player = event.player + local top_flow = mod_gui.get_button_flow(player) + if not top_flow then return end + + -- Set the visiblity of the elements + local visible = top_flow[toolbar_toggle_concept.name].caption == '<' + for _,concept in pairs(Toolbar.button_concepts) do + local element = top_flow[concept.name] + if Gui.valid(element) then + element.visible = visible and Toolbar.allowed(player,concept.name) + end + end + +end) +:new_event('on_hide_frames') +:on_hide_frames(function(event) + -- Get the left flow + local player = event.player + local left_flow = mod_gui.get_frame_flow(player) + if not left_flow then return end + + -- Set the visiblity of the elements + left_flow[toolbar_hide_concept.name].visible = false + for _,concept in pairs(Toolbar.frame_concepts) do + local element = left_flow[concept.name..'-frame'] + if Gui.valid(element) then element.visible = false end + end +end) + +--- Used so toggle and hide can have the same look as each other +local function toolbar_button_draw(properties,parent,element) + element.style = mod_gui.button_style + local style = element.style + style.width = 18 + style.height = 36 + style.padding = 0 + style.left_padding = 1 + style.font = 'default-small-bold' +end + +--[[-- Button which toggles the the visible state of all toolbar buttons, triggers on_button_update +@element toolbar-toggle +]] +toolbar_toggle_concept = +Gui.clone_concept('button','toolbar-toggle') +:set_caption('<') +:set_tooltip{'gui_util.button_tooltip'} +:define_draw(toolbar_button_draw) +:on_click(function(event) + local element = event.element + element.caption = element.caption == '<' and '>' or '<' + toolbar_concept:raise_event('on_button_update',{ + player_index = event.player_index + }) +end) + +--[[-- Button which hides all visible toolbar frames, triggers on_hide_frames +@element toolbar-clear +]] +toolbar_hide_concept = +Gui.clone_concept('button','toolbar-clear') +:set_caption('<') +:set_tooltip{'expcore-gui.left-button-tooltip'} +:define_draw(toolbar_button_draw) +:on_click(function(event) + event.element.visible = false + toolbar_concept:raise_event('on_hide_frames',{ + player_index = event.player_index + }) +end) + +--- When there is a new player they will have the toolbar update +Event.add(defines.events.on_player_created,function(event) + local player = Game.get_player_by_index(event.player_index) + toolbar_concept:draw(player) +end) + +--- When a player gets a new role they will have the toolbar updated +Event.add(Roles.events.on_role_assigned,function(event) + toolbar_concept:raise_event('on_button_update',{ + player_index = event.player_index + }) +end) + +--- When a player loses a role they will have the toolbar updated +Event.add(Roles.events.on_role_unassigned,function(event) + toolbar_concept:raise_event('on_button_update',{ + player_index = event.player_index + }) +end) + +return Toolbar \ No newline at end of file diff --git a/utils/event_core.lua b/utils/event_core.lua index 364e3134..b34715e1 100644 --- a/utils/event_core.lua +++ b/utils/event_core.lua @@ -27,7 +27,7 @@ local function call_handlers(handlers, event) local handler = handlers[i] local success, error = pcall(handler, event) if not success then - log(error) + log('\n\t'..error) end end end From d40f0f142fa84d58c593ccbe0148e2da7b5c9cab Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Tue, 17 Sep 2019 19:54:34 +0100 Subject: [PATCH 16/26] Added define_pre_draw --- expcore/gui/prototype.lua | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/expcore/gui/prototype.lua b/expcore/gui/prototype.lua index cac0d37e..d1e32306 100644 --- a/expcore/gui/prototype.lua +++ b/expcore/gui/prototype.lua @@ -426,6 +426,34 @@ function Prototype:define_draw(draw_callback) return self end +--[[ Used to define a draw callback that is ran before any other draw callbacks, see define_draw +@tparam function draw_callback the function that will be called to draw/update the instance; this function must return the instance or the new acting instance +@treturn GuiConcept to allow chaining of functions +@usage-- Placing a button into a flow +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 + 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 + return element, parent +end) +]] +function Prototype:define_pre_draw(draw_callback) + -- Check that it is a function that is being added + if type(draw_callback) ~= 'function' then + error('Draw define must be a function',2) + end + + -- Add the draw function + table.insert(self.draw_callbacks,1,draw_callback) + + return self +end + --[[-- Calls all the draw functions in order to create this concept in game; will also store and sync the instance if stores are used @tparam LuaGuiElement parent_element the element that the concept will use as a base @treturn LuaGuiElement the element that was created and then passed though and returned by the draw functions @@ -437,15 +465,17 @@ Gui.get_concept('CustomButton') custom_button:draw(game.player.gui.left) ]] function Prototype:draw(parent_element,...) + local parent = parent_element local element -- Loop over all the draw defines, element is updated when a value is returned for _,draw_callback in pairs(self.draw_callbacks) do - local success, rtn = pcall(draw_callback,self.properties,parent_element,element,...) - if success and rtn then - element = rtn + local success, _element, _parent = pcall(draw_callback,self.properties,parent,element,...) + if success then + 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'..rtn) + error('Gui draw handler error with '..self.name..':\n\t'.._element) end end From 1f204c6dac0978d9f5ec547390b188c58c14846a Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Tue, 17 Sep 2019 21:09:15 +0100 Subject: [PATCH 17/26] Added some structor concepts --- README.md | 3 +- docs/addons/Advanced-Start.html | 2 +- docs/addons/Chat-Popups.html | 2 +- docs/addons/Chat-Reply.html | 2 +- docs/addons/Compilatron.html | 2 +- docs/addons/Damage-Popups.html | 2 +- docs/addons/Death-Logger.html | 2 +- docs/addons/Discord-Alerts.html | 2 +- docs/addons/Player-Colours.html | 2 +- docs/addons/Pollution-Grading.html | 2 +- docs/addons/Scorched-Earth.html | 2 +- docs/addons/Spawn-Area.html | 2 +- docs/commands/Admin-Chat.html | 2 +- docs/commands/Bonus.html | 2 +- docs/commands/Cheat-Mode.html | 2 +- docs/commands/Clear-Inventory.html | 2 +- docs/commands/Debug.html | 2 +- docs/commands/Find.html | 2 +- docs/commands/Help.html | 2 +- docs/commands/Home.html | 2 +- docs/commands/Interface.html | 2 +- docs/commands/Jail.html | 2 +- docs/commands/Kill.html | 2 +- docs/commands/Me.html | 2 +- docs/commands/Rainbow.html | 2 +- docs/commands/Repair.html | 2 +- docs/commands/Reports.html | 2 +- docs/commands/Roles.html | 2 +- docs/commands/Spawn.html | 2 +- docs/commands/Tag.html | 2 +- docs/commands/Teleport.html | 2 +- docs/commands/Warnings.html | 2 +- docs/configs/Advanced-Start.html | 2 +- docs/configs/Bonuses.html | 2 +- docs/configs/Chat-Reply.html | 2 +- docs/configs/Commands-Auth-Admin.html | 2 +- docs/configs/Commands-Auth-Roles.html | 2 +- .../Commands-Auth-Runtime-Disable.html | 2 +- docs/configs/Commands-Parse-Roles.html | 2 +- docs/configs/Commands-Parse.html | 2 +- docs/configs/Compilatron.html | 2 +- docs/configs/Death-Logger.html | 2 +- docs/configs/Discord-Alerts.html | 2 +- docs/configs/File-Loader.html | 2 +- docs/configs/Permission-Groups.html | 2 +- docs/configs/Player-List.html | 2 +- docs/configs/Pollution-Grading.html | 2 +- docs/configs/Popup-Messages.html | 2 +- docs/configs/Preset-Player-Colours.html | 2 +- docs/configs/Repair.html | 2 +- docs/configs/Rockets.html | 2 +- docs/configs/Roles.html | 2 +- docs/configs/Science.html | 2 +- docs/configs/Scorched-Earth.html | 2 +- docs/configs/Spawn-Area.html | 2 +- docs/configs/Tasks.html | 2 +- docs/configs/Warnings.html | 2 +- docs/configs/Warps.html | 2 +- docs/control/Jail.html | 2 +- docs/control/Production.html | 2 +- docs/control/Reports.html | 2 +- docs/control/Rockets.html | 2 +- docs/control/Tasks.html | 2 +- docs/control/Warnings.html | 2 +- docs/control/Warps.html | 2 +- docs/core/Commands.html | 2 +- docs/core/Common-Library.html | 2 +- docs/core/Gui.html | 512 +++++++++++++++++- docs/core/Permissions-Groups.html | 2 +- docs/core/Roles.html | 2 +- docs/core/Store.html | 2 +- docs/core/Sudo.html | 2 +- docs/core/Toolbar.html | 2 +- docs/guis/Player-List.html | 2 +- docs/guis/Rocket-Info.html | 2 +- docs/guis/Science-Info.html | 2 +- docs/guis/Task-List.html | 2 +- docs/guis/Warps-List.html | 2 +- docs/index.html | 2 +- docs/modules/control.html | 2 +- .../utils.alien_evolution_progress.html | 2 +- docs/modules/utils.core.html | 2 +- docs/modules/utils.debug.html | 8 +- docs/modules/utils.dump_env.html | 2 +- docs/modules/utils.event.html | 2 +- docs/modules/utils.event_core.html | 2 +- docs/modules/utils.math.html | 23 +- docs/modules/utils.recipe_locker.html | 2 +- docs/modules/utils.state_machine.html | 12 +- docs/modules/utils.table.html | 54 +- docs/modules/utils.task.html | 2 +- docs/modules/utils.timestamp.html | 2 +- docs/topics/license.html | 2 +- docs/topics/readme.md.html | 2 +- expcore/gui.lua | 7 + expcore/gui/concepts/button.lua | 2 +- expcore/gui/concepts/checkbox.lua | 2 +- expcore/gui/concepts/dropdown.lua | 2 +- expcore/gui/concepts/elem_button.lua | 2 +- expcore/gui/concepts/empty.lua | 26 + expcore/gui/concepts/flow.lua | 32 ++ expcore/gui/concepts/frame.lua | 4 +- expcore/gui/concepts/label.lua | 29 + expcore/gui/concepts/line.lua | 25 + expcore/gui/concepts/progress_bar.lua | 2 +- expcore/gui/concepts/scroll.lua | 37 ++ expcore/gui/concepts/slider.lua | 2 +- expcore/gui/concepts/table.lua | 48 ++ expcore/gui/concepts/textbox.lua | 2 +- expcore/gui/concepts/textfield.lua | 2 +- utils/debug.lua | 2 +- utils/math.lua | 3 +- utils/state_machine.lua | 4 +- utils/table.lua | 12 +- 114 files changed, 880 insertions(+), 153 deletions(-) create mode 100644 expcore/gui/concepts/empty.lua create mode 100644 expcore/gui/concepts/flow.lua create mode 100644 expcore/gui/concepts/label.lua create mode 100644 expcore/gui/concepts/line.lua create mode 100644 expcore/gui/concepts/scroll.lua create mode 100644 expcore/gui/concepts/table.lua diff --git a/README.md b/README.md index 2c9d02e7..8ff71f05 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ Explosive Gaming (often ExpGaming) is a server hosting community with a strong f ## 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. @@ -111,6 +111,7 @@ All are welcome to make pull requests and issues for this scenario, if you are i The Explosive Gaming codebase is licensed under the [GNU General Public License v3.0](LICENSE) +[docs]: https://explosivegaming.github.io/scenario/ [issues]: https://github.com/explosivegaming/scenario/issues/new/choose [website]: https://explosivegaming.nl [discord]: https://discord.explosivegaming.nl diff --git a/docs/addons/Advanced-Start.html b/docs/addons/Advanced-Start.html index 355bc495..faf5372f 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 6a9a5437..1cb898d6 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 ba20d5c1..be26fd7b 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 c9aa9a5a..c1102fc7 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 9768b669..10d6f5e9 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 781142d9..a58f573c 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 7a218c04..bec86481 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 6ef982b9..dc617ebf 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 46544811..5cc620da 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 88da4c0a..3132f77a 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 2faa81dc..5f29f43e 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 54195af8..3f32bbfe 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 450e04f6..72e63565 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 7a662f0a..e3d0fe61 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 62f59464..cf5e879b 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 74239e71..943927e9 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 84387d0a..eade86b7 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 21b3aeaa..ba5015dd 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 d8637e6f..2be91e72 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 224c35ee..9f411202 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 432028b8..fdef4831 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 1d35117f..6c3d62f5 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 aebe8ab4..ddb01af6 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 37baf73b..beb18d54 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 8b302752..8cb83cdf 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 dc80bff6..f5464b40 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 da4ffc81..30cdb86f 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 738a91ee..b8135072 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 eb224a4e..650b981d 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 0641f54e..d4b5c5c0 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 33a5203a..79b3982a 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 054b7703..3ee81b26 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 a11c7015..4f24d85e 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 9ffe93c5..dc328519 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 dea29ffd..93162e2f 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 a344862c..33fae8e3 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 dff32e2e..8f244e55 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 60343ebc..c190f4f7 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 1361775e..11843168 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 37ca361d..f509d0f0 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 c8c36fab..ee2283be 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 233d45df..18a6d7a5 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 aba7b05d..2944ffe3 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 8656a1f1..0fc205fb 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 239f7169..e94579ed 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 3603fe03..bf22c696 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 be1095c3..3e57f2a9 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 133879c0..c81608c3 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 88f593ff..59645f20 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 35df56b4..c41acf9c 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 c57368c1..43545c64 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 f52b2fbe..1b4dd89a 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 b7af3a39..77513933 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 6853d015..9b34fe0d 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 cd84fc0c..57848caa 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 d298e402..4da0c948 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 ccdb5910..a6c100b1 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 3858e706..340552b7 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 9eab886b..1c4aaf2d 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 d7397705..8751f13d 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 9f196c46..95acf774 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 fb62ed5f..ae05745d 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 0343a416..d20d5fca 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 b11de74d..54cdd303 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 e72da3ba..d20487b8 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 5d3f775f..d2ca792f 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 861627e8..ee72f51c 100644 --- a/docs/core/Gui.html +++ b/docs/core/Gui.html @@ -323,39 +323,63 @@ button:clone('CustomButton')
    - + - + - + - + + + + + + + + + - + + + + + + + + + - + + + + + - + + + + + - + - +
    buttonThe basic button elementClickable elements that fire on_gui_click when clicked.
    checkboxThe basic checkbox elementClickable elements with a cross in the middle that can be turned off or on.
    dropdownThe basic dropdown elementA drop down list of other elements.
    elem_buttonThe basic dropdown elementA button that lets the player pick one of an: item, entity, tile, or signal similar to the filter-select window.
    emptyA empty widget that just exists.
    flowInvisible containers that lay out children either horizontally or vertically.
    frameThe basic frame elementGrey semi-transparent boxes that contain other elements.
    frameA piece of text.
    lineA vertical or horizontal line.
    progress_barThe basic checkbox elementIndicate progress by displaying a partially filled bar.
    scrollSimilar to a flow but includes the ability to show and use scroll bars.
    sliderThe basic slider elementA number picker.
    tableAn invisible container that lays out children in a specific number of columns.
    text_boxThe text box elementA multi-line text box that supports selection and copy-paste.
    text_fieldThe text field elementBoxes of text the user can type in.
    @@ -636,7 +660,7 @@ button:clone('CustomButton')
    -

    The basic button element

    +

    Clickable elements that fire on_gui_click when clicked.

    @@ -780,7 +804,7 @@ Gui.clone_concept('button','spr
    -

    The basic checkbox element

    +

    Clickable elements with a cross in the middle that can be turned off or on.

    @@ -902,7 +926,7 @@ Gui.clone_concept('checkbox','b
    -

    The basic dropdown element

    +

    A drop down list of other elements.

    @@ -1038,7 +1062,7 @@ Gui.clone_concept('dropdown','d
    -

    The basic dropdown element

    +

    A button that lets the player pick one of an: item, entity, tile, or signal similar to the filter-select window.

    @@ -1115,6 +1139,121 @@ Gui.clone_concept('elem_button',end) +
    +
    +
    +
    + # + empty +
    +
    +
    +
    + +

    A empty widget that just exists.

    +

    The root GUI element screen is an empty-widget.

    + + + Properties / Events: + +
      + + + + + +
    • + + style + + : + + (string) + + 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')
    + + +
    +
    +
    +
    + # + flow +
    +
    +
    +
    + +

    Invisible containers that lay out children either horizontally or vertically.

    +

    The root GUI elements (top, left and center; see LuaGui) are flows.

    + + + Properties / Events: + +
      + + + + + +
    • + + direction + + : + + (string) + + 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')
    +:define_draw(function(properties,parent,element)
    +    element.add{
    +        type = 'label',
    +        caption = 'Hello, World!'
    +    }
    +end)
    + +
    @@ -1126,8 +1265,8 @@ Gui.clone_concept('elem_button',
    -

    The basic frame element

    -

    +

    Grey semi-transparent boxes that contain other elements.

    +

    They have a caption, and, just like flows, they lay out children either horizontally or vertically.

    Properties / Events: @@ -1182,7 +1321,7 @@ Gui.clone_concept('elem_button',Usage:
    -- Making a basic frame, contains a label with hello world
     local basic_frame =
    -Gui.clone_concept('dropdown','basic_frame')
    +Gui.clone_concept('frame','basic_frame')
     :set_title('Basic Frame')
     :define_draw(function(properties,parent,element)
         element.add{
    @@ -1192,6 +1331,131 @@ Gui.clone_concept('dropdown','b
     end)
    + +
    +
    +
    + # + frame +
    +
    +
    +
    + +

    A piece of text.

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + caption + + : + + (string or LocalisedString) + + the caption that will show in the label + +
    • + + + + + +
    • + + description + + : + + (string or LocalisedString) + + the description that will show on the label + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Making a basic label
    +local basic_label =
    +Gui.clone_concept('label','basic_label')
    +:set_caption('Hello, World!')
    + + +
    +
    +
    +
    + # + line +
    +
    +
    +
    + +

    A vertical or horizontal line.

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + direction + + : + + (string) + + 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')
    + +
    @@ -1203,7 +1467,7 @@ Gui.clone_concept('dropdown','b
    -

    The basic checkbox element

    +

    Indicate progress by displaying a partially filled bar.

    @@ -1319,6 +1583,85 @@ Gui.clone_concept('progress_bar',end) +
    +
    +
    +
    + # + scroll +
    +
    +
    +
    + +

    Similar to a flow but includes the ability to show and use scroll bars.

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + horizontal_scroll + + : + + (string) + + the horizontal scroll policy for this scroll pane + +
    • + + + + + +
    • + + vertical_scroll + + : + + (string) + + 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')
    +:define_draw(function(properties,parent,element)
    +    element.style.hieght = 50
    +    for i = 1,10 do
    +        element.add{
    +            type = 'label',
    +            caption = i
    +        }
    +    end
    +end)
    + +
    @@ -1330,7 +1673,7 @@ Gui.clone_concept('progress_bar', -

    The basic slider element

    +

    A number picker.

    @@ -1449,6 +1792,133 @@ Gui.clone_concept('slider','dis end) + +
    +
    +
    + # + table +
    +
    +
    +
    + +

    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.

    + + + Properties / Events: + +
      + + + + + +
    • + + column_count + + : + + (number or function) + + the column count of the table or a function that returns the count being given then parent element + +
    • + + + + + +
    • + + vertical_lines + + : + + (boolean) + + when true vertical lines will be drawn on the table + +
    • + + + + + +
    • + + horizontal_lines + + : + + (boolean) + + when true horizontal lines will be drawn on the table + +
    • + + + + + +
    • + + header_lines + + : + + (boolean) + + when true horizontal lines will be drawn under the first row + +
    • + + + + + +
    • + + vertical_centering + + : + + (boolean) + + 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')
    +:set_column_count(5)
    +:define_draw(function(properties,parent,element)
    +    for i = 1,25 do
    +        element.add{
    +            type = 'lable',
    +            caption = i
    +        }
    +    end
    +end)
    + +
    @@ -1460,7 +1930,7 @@ Gui.clone_concept('slider','dis
    -

    The text box element

    +

    A multi-line text box that supports selection and copy-paste.

    @@ -1618,7 +2088,7 @@ Gui.clone_concept('text_box','e
    -

    The text field element

    +

    Boxes of text the user can type in.

    @@ -5040,7 +5510,7 @@ Gui.get_concept('CustomButton') generated by LDoc
    diff --git a/docs/core/Permissions-Groups.html b/docs/core/Permissions-Groups.html index e10f905a..dca3001a 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 40948b8d..8e43f424 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 e56e6911..43bad538 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 4f88af42..d62ac99e 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 0da30385..5cbcc8c2 100644 --- a/docs/core/Toolbar.html +++ b/docs/core/Toolbar.html @@ -1630,7 +1630,7 @@ Gui.clone_concept('toolbar-frame',LDoc diff --git a/docs/guis/Player-List.html b/docs/guis/Player-List.html index 439db206..a54cf7a5 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 0f113473..ac686677 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 b26e1560..b0c720f8 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 f6d43bb5..80723b00 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 545bb8b4..3a5ec1ac 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 372ce97b..f233e4a5 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 6d625e00..7295da0f 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 1cfaeb22..2fa36dc8 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 9dda491f..ef39ec65 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 b3c9bca3..5304675f 100644 --- a/docs/modules/utils.debug.html +++ b/docs/modules/utils.debug.html @@ -242,7 +242,7 @@ - Debug.print(message, stack_traceback) + Debug.print(message, trace_levels) Shows the given message if debug is enabled. @@ -281,7 +281,7 @@
    # - Debug.print(message, stack_traceback) + Debug.print(message, trace_levels)
    @@ -316,7 +316,7 @@
  • - stack_traceback + trace_levels : @@ -655,7 +655,7 @@ generated by LDoc diff --git a/docs/modules/utils.dump_env.html b/docs/modules/utils.dump_env.html index b4da436e..598d76da 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 13a7680e..fc1ddfad 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 90ced63a..c5782040 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 b4f8fd77..fada2288 100644 --- a/docs/modules/utils.math.html +++ b/docs/modules/utils.math.html @@ -242,7 +242,7 @@ - calculate_y_intercept(x, slope) + calculate_y_intercept(x, y, slope) Calculates the y-intercept of a line @@ -258,7 +258,7 @@
    # - calculate_y_intercept(x, slope) + calculate_y_intercept(x, y, slope)
    @@ -283,7 +283,22 @@ : - , y numbers - coordinates of point on line + number - coordinates of point on line + +
  • + + + + + +
  • + + y + + : + + + number - coordinates of point on line
  • @@ -339,7 +354,7 @@ generated by LDoc diff --git a/docs/modules/utils.recipe_locker.html b/docs/modules/utils.recipe_locker.html index 34d5d12a..8f6f7dbd 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 d3325639..17e16970 100644 --- a/docs/modules/utils.state_machine.html +++ b/docs/modules/utils.state_machine.html @@ -277,7 +277,7 @@ NOTICE: This function will invoke an error if called after init. - Module.register_transition_callback(self, state, state, callback) + Module.register_transition_callback(self, old, new, callback) Register a handler that will be invoked by StateMachine.transition You may register multiple handlers for the same transition NOTICE: This function will invoke an error if called after init. @@ -591,7 +591,7 @@
    # - Module.register_transition_callback(self, state, state, callback) + Module.register_transition_callback(self, old, new, callback)
    @@ -628,12 +628,12 @@
  • - state + old : - number/string entering state + number/string exiting state
  • @@ -643,7 +643,7 @@
  • - state + new : @@ -753,7 +753,7 @@ generated by LDoc diff --git a/docs/modules/utils.table.html b/docs/modules/utils.table.html index c76d0411..6c672172 100644 --- a/docs/modules/utils.table.html +++ b/docs/modules/utils.table.html @@ -290,12 +290,12 @@ because this uses math.random, it cannot be used outside of events - get_random_weighted(weight_table, item_index, weight_index) + get_random_weighted(weighted_table, item_index, weight_index) Chooses a random entry from a weighted table because this uses math.random, it cannot be used outside of events - shuffle_table(t) + shuffle_table(t, rng) Creates a fisher-yates shuffle of a sequential number-indexed table because this uses math.random, it cannot be used outside of events if no rng is supplied from: http://www.sdknews.com/cross-platform/corona/tutorial-how-to-shuffle-table-items @@ -552,6 +552,12 @@ + Returns: +
      +
    • + the index of the element or nil +
    • +
    @@ -616,6 +622,12 @@ + Returns: +
      +
    • + the index of the element or nil +
    • +
    @@ -680,6 +692,12 @@ + Returns: +
      +
    • + indicating success +
    • +
    @@ -744,6 +762,12 @@ + Returns: +
      +
    • + indicating success +
    • +
    @@ -908,7 +932,7 @@
    # - get_random_weighted(weight_table, item_index, weight_index) + get_random_weighted(weighted_table, item_index, weight_index)
    @@ -929,7 +953,7 @@
  • - weight_table + weighted_table : @@ -984,9 +1008,6 @@ - See also: -
      -
    @@ -997,7 +1018,7 @@
    # - shuffle_table(t) + shuffle_table(t, rng)
    @@ -1029,6 +1050,21 @@
  • + + + +
  • + + rng + + : + + + to provide random numbers + +
  • + + @@ -1383,7 +1419,7 @@ generated by LDoc diff --git a/docs/modules/utils.task.html b/docs/modules/utils.task.html index ce165620..e84592f2 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 5c227954..0d1c8dd5 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 757e9dcd..dd724347 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 1d767ad7..08252a53 100644 --- a/docs/topics/readme.md.html +++ b/docs/topics/readme.md.html @@ -333,7 +333,7 @@ generated by LDoc diff --git a/expcore/gui.lua b/expcore/gui.lua index 54c8d512..50bcce3b 100644 --- a/expcore/gui.lua +++ b/expcore/gui.lua @@ -68,6 +68,13 @@ 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') diff --git a/expcore/gui/concepts/button.lua b/expcore/gui/concepts/button.lua index 196cc117..a23fd3e4 100644 --- a/expcore/gui/concepts/button.lua +++ b/expcore/gui/concepts/button.lua @@ -5,7 +5,7 @@ local Gui = require 'expcore.gui.core' ---[[-- The basic button element +--[[-- 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 diff --git a/expcore/gui/concepts/checkbox.lua b/expcore/gui/concepts/checkbox.lua index 0de6befc..cf24f231 100644 --- a/expcore/gui/concepts/checkbox.lua +++ b/expcore/gui/concepts/checkbox.lua @@ -5,7 +5,7 @@ local Gui = require 'expcore.gui.core' ---[[-- The basic checkbox element +--[[-- 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 diff --git a/expcore/gui/concepts/dropdown.lua b/expcore/gui/concepts/dropdown.lua index c4e651df..646fdd5e 100644 --- a/expcore/gui/concepts/dropdown.lua +++ b/expcore/gui/concepts/dropdown.lua @@ -6,7 +6,7 @@ local Gui = require 'expcore.gui.core' local array_insert = ext_require('expcore.common','array_insert') ---[[-- The basic dropdown element +--[[-- 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 diff --git a/expcore/gui/concepts/elem_button.lua b/expcore/gui/concepts/elem_button.lua index 6b51fbf1..5e711369 100644 --- a/expcore/gui/concepts/elem_button.lua +++ b/expcore/gui/concepts/elem_button.lua @@ -5,7 +5,7 @@ local Gui = require 'expcore.gui.core' ---[[-- The basic dropdown element +--[[-- 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 diff --git a/expcore/gui/concepts/empty.lua b/expcore/gui/concepts/empty.lua new file mode 100644 index 00000000..61cda963 --- /dev/null +++ b/expcore/gui/concepts/empty.lua @@ -0,0 +1,26 @@ +--[[-- Core Module - Gui + @module Gui + @alias Gui +]] + +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') +:new_property('style') +:define_draw(function(properties,parent,element) + element = parent.add{ + name = properties.name, + type = 'empty-widget', + style = properties.style + } + + return element +end) \ No newline at end of file diff --git a/expcore/gui/concepts/flow.lua b/expcore/gui/concepts/flow.lua new file mode 100644 index 00000000..e8ecdce2 --- /dev/null +++ b/expcore/gui/concepts/flow.lua @@ -0,0 +1,32 @@ +--[[-- Core Module - Gui + @module Gui + @alias Gui +]] + +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') +:define_draw(function(properties,parent,element) + element.add{ + type = 'label', + caption = 'Hello, World!' + } +end) +]] +Gui.new_concept('flow') +:new_property('direction') +:define_draw(function(properties,parent,element) + element = parent.add{ + name = properties.name, + type = 'flow', + caption = properties.title, + direction = properties.direction + } + + return element +end) \ No newline at end of file diff --git a/expcore/gui/concepts/frame.lua b/expcore/gui/concepts/frame.lua index a7b69f93..e3598778 100644 --- a/expcore/gui/concepts/frame.lua +++ b/expcore/gui/concepts/frame.lua @@ -5,13 +5,13 @@ local Gui = require 'expcore.gui.core' ---[[-- The basic frame element +--[[-- 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('dropdown','basic_frame') +Gui.clone_concept('frame','basic_frame') :set_title('Basic Frame') :define_draw(function(properties,parent,element) element.add{ diff --git a/expcore/gui/concepts/label.lua b/expcore/gui/concepts/label.lua new file mode 100644 index 00000000..692192c5 --- /dev/null +++ b/expcore/gui/concepts/label.lua @@ -0,0 +1,29 @@ +--[[-- Core Module - Gui + @module Gui + @alias Gui +]] + +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 +@usage-- Making a basic label +local basic_label = +Gui.clone_concept('label','basic_label') +:set_caption('Hello, World!') +]] +Gui.new_concept('label') +:new_property('caption') +:new_property('description') +:define_draw(function(properties,parent,element) + element = parent.add{ + name = properties.name, + type = 'label', + caption = properties.caption, + description = properties.description + } + + return element +end) \ No newline at end of file diff --git a/expcore/gui/concepts/line.lua b/expcore/gui/concepts/line.lua new file mode 100644 index 00000000..2ff4544b --- /dev/null +++ b/expcore/gui/concepts/line.lua @@ -0,0 +1,25 @@ +--[[-- Core Module - Gui + @module Gui + @alias Gui +]] + +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') +:new_property('direction') +:define_draw(function(properties,parent,element) + element = parent.add{ + name = properties.name, + type = 'line', + direction = properties.direction + } + + return element +end) \ No newline at end of file diff --git a/expcore/gui/concepts/progress_bar.lua b/expcore/gui/concepts/progress_bar.lua index b85e9500..384c90cb 100644 --- a/expcore/gui/concepts/progress_bar.lua +++ b/expcore/gui/concepts/progress_bar.lua @@ -5,7 +5,7 @@ local Gui = require 'expcore.gui.core' ---[[-- The basic checkbox element +--[[-- 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 diff --git a/expcore/gui/concepts/scroll.lua b/expcore/gui/concepts/scroll.lua new file mode 100644 index 00000000..5a6cb8f2 --- /dev/null +++ b/expcore/gui/concepts/scroll.lua @@ -0,0 +1,37 @@ +--[[-- Core Module - Gui + @module Gui + @alias Gui +]] + +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') +:define_draw(function(properties,parent,element) + element.style.hieght = 50 + for i = 1,10 do + element.add{ + type = 'label', + caption = i + } + end +end) +]] +Gui.new_concept('scroll') +:new_property('horizontal_scroll') +:new_property('vertical_scroll') +:define_draw(function(properties,parent,element) + element = parent.add{ + name = properties.name, + type = 'scroll-pane', + horizontal_scroll_policy = properties.horizontal_scroll, + vertical_scroll_policy = properties.vertical_scroll + } + + return element +end) \ No newline at end of file diff --git a/expcore/gui/concepts/slider.lua b/expcore/gui/concepts/slider.lua index 3cc90dbd..51ff9153 100644 --- a/expcore/gui/concepts/slider.lua +++ b/expcore/gui/concepts/slider.lua @@ -5,7 +5,7 @@ local Gui = require 'expcore.gui.core' ---[[-- The basic slider element +--[[-- 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 diff --git a/expcore/gui/concepts/table.lua b/expcore/gui/concepts/table.lua new file mode 100644 index 00000000..20474951 --- /dev/null +++ b/expcore/gui/concepts/table.lua @@ -0,0 +1,48 @@ +--[[-- Core Module - Gui + @module Gui + @alias Gui +]] + +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') +:set_column_count(5) +:define_draw(function(properties,parent,element) + for i = 1,25 do + element.add{ + type = 'lable', + caption = i + } + end +end) +]] +Gui.new_concept('table') +:new_property('column_count') +:new_property('vertical_lines') +:new_property('horizontal_lines') +:new_property('header_lines') +:new_property('vertical_centering') +:define_draw(function(properties,parent,element) + local column_count = Gui.resolve_property(properties.column_count,parent) + + element = parent.add{ + name = properties.name, + type = 'table', + column_count = column_count, + draw_vertical_lines = properties.vertical_lines, + draw_horizontal_lines = properties.horizontal_lines, + draw_horizontal_line_after_headers = properties.header_lines, + vertical_centering = properties.vertical_centering + } + + return element +end) \ No newline at end of file diff --git a/expcore/gui/concepts/textbox.lua b/expcore/gui/concepts/textbox.lua index 3c3945eb..8b8863ec 100644 --- a/expcore/gui/concepts/textbox.lua +++ b/expcore/gui/concepts/textbox.lua @@ -5,7 +5,7 @@ local Gui = require 'expcore.gui.core' ---[[-- The text box element +--[[-- 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 diff --git a/expcore/gui/concepts/textfield.lua b/expcore/gui/concepts/textfield.lua index 717fe55c..4275ee21 100644 --- a/expcore/gui/concepts/textfield.lua +++ b/expcore/gui/concepts/textfield.lua @@ -5,7 +5,7 @@ local Gui = require 'expcore.gui.core' ---[[-- The text field element +--[[-- 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 diff --git a/utils/debug.lua b/utils/debug.lua index 1c1a3633..98f85a28 100644 --- a/utils/debug.lua +++ b/utils/debug.lua @@ -31,7 +31,7 @@ end ---Shows the given message if debug is enabled. Uses serpent to print non scalars. -- @param message --- @param stack_traceback levels of stack trace to give, defaults to 1 level if nil +-- @param trace_levels levels of stack trace to give, defaults to 1 level if nil function Debug.print(message, trace_levels) if not _DEBUG then return diff --git a/utils/math.lua b/utils/math.lua index 6876f1c5..179005c9 100644 --- a/utils/math.lua +++ b/utils/math.lua @@ -39,7 +39,8 @@ math.calculate_slope = function(x1, y1, x2, y2) end --- Calculates the y-intercept of a line --- @param x, y numbers - coordinates of point on line +-- @param x number - coordinates of point on line +-- @param y number - coordinates of point on line -- @param slope number - the slope of a line -- @return number - the y-intercept of a line math.calculate_y_intercept = function(x, y, slope) diff --git a/utils/state_machine.lua b/utils/state_machine.lua index 7db455ab..9d298a52 100644 --- a/utils/state_machine.lua +++ b/utils/state_machine.lua @@ -87,8 +87,8 @@ end -- You may register multiple handlers for the same transition -- NOTICE: This function will invoke an error if called after init. Dynamic machine changes are currently unsupported -- @param self StateMachine the machine --- @param state number/string exiting state --- @param state number/string entering state +-- @param old number/string exiting state +-- @param new number/string entering state -- @param callback function function Module.register_transition_callback(self, old, new, callback) if _LIFECYCLE ~= control_stage then diff --git a/utils/table.lua b/utils/table.lua index ea69bbd7..4b1973e2 100644 --- a/utils/table.lua +++ b/utils/table.lua @@ -49,7 +49,7 @@ end --- Checks if a table contains an element -- @param t -- @param e table element --- @returns the index of the element or nil +-- @return the index of the element or nil function table.index_of(t, e) for k, v in pairs(t) do if v == e then @@ -62,7 +62,7 @@ end --- Checks if the arrayed portion of a table contains an element -- @param t
    -- @param e table element --- @returns the index of the element or nil +-- @return the index of the element or nil function table.index_of_in_array(t, e) for i = 1, #t do if t[i] == e then @@ -76,7 +76,7 @@ local index_of = table.index_of --- Checks if a table contains an element -- @param t
    -- @param e table element --- @returns indicating success +-- @return indicating success function table.contains(t, e) return index_of(t, e) and true or false end @@ -85,7 +85,7 @@ local index_of_in_array = table.index_of_in_array --- Checks if the arrayed portion of a table contains an element -- @param t
    -- @param e table element --- @returns indicating success +-- @return indicating success function table.array_contains(t, e) return index_of_in_array(t, e) and true or false end @@ -128,11 +128,10 @@ end --- Chooses a random entry from a weighted table -- because this uses math.random, it cannot be used outside of events --- @param weight_table
    of tables with items and their weights +-- @param weighted_table
    of tables with items and their weights -- @param item_index of the index of items, defaults to 1 -- @param weight_index of the index of the weights, defaults to 2 -- @return table element --- @see features.chat_triggers::hodor function table.get_random_weighted(weighted_table, item_index, weight_index) local total_weight = 0 item_index = item_index or 1 @@ -156,6 +155,7 @@ end -- because this uses math.random, it cannot be used outside of events if no rng is supplied -- from: http://www.sdknews.com/cross-platform/corona/tutorial-how-to-shuffle-table-items -- @param t
    to shuffle +-- @param rng to provide random numbers function table.shuffle_table(t, rng) local rand = rng or math.random local iterations = #t From ce88e0a296401bc63cd58f437dcccbcb8586495b Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sun, 22 Sep 2019 17:08:43 +0100 Subject: [PATCH 18/26] Cleaner Code --- docs/addons/Advanced-Start.html | 2 +- docs/addons/Chat-Popups.html | 2 +- docs/addons/Chat-Reply.html | 2 +- docs/addons/Compilatron.html | 2 +- docs/addons/Damage-Popups.html | 2 +- docs/addons/Death-Logger.html | 2 +- docs/addons/Discord-Alerts.html | 2 +- docs/addons/Player-Colours.html | 2 +- docs/addons/Pollution-Grading.html | 2 +- docs/addons/Scorched-Earth.html | 2 +- docs/addons/Spawn-Area.html | 2 +- docs/commands/Admin-Chat.html | 2 +- docs/commands/Bonus.html | 2 +- docs/commands/Cheat-Mode.html | 2 +- docs/commands/Clear-Inventory.html | 2 +- docs/commands/Debug.html | 2 +- docs/commands/Find.html | 2 +- docs/commands/Help.html | 2 +- docs/commands/Home.html | 2 +- docs/commands/Interface.html | 2 +- docs/commands/Jail.html | 2 +- docs/commands/Kill.html | 2 +- docs/commands/Me.html | 2 +- docs/commands/Rainbow.html | 2 +- docs/commands/Repair.html | 2 +- docs/commands/Reports.html | 2 +- docs/commands/Roles.html | 2 +- docs/commands/Spawn.html | 2 +- docs/commands/Tag.html | 2 +- docs/commands/Teleport.html | 2 +- docs/commands/Warnings.html | 2 +- docs/configs/Advanced-Start.html | 2 +- docs/configs/Bonuses.html | 2 +- docs/configs/Chat-Reply.html | 2 +- docs/configs/Commands-Auth-Admin.html | 2 +- docs/configs/Commands-Auth-Roles.html | 2 +- .../Commands-Auth-Runtime-Disable.html | 2 +- docs/configs/Commands-Parse-Roles.html | 2 +- docs/configs/Commands-Parse.html | 2 +- docs/configs/Compilatron.html | 2 +- docs/configs/Death-Logger.html | 2 +- docs/configs/Discord-Alerts.html | 2 +- docs/configs/File-Loader.html | 2 +- docs/configs/Permission-Groups.html | 2 +- docs/configs/Player-List.html | 2 +- docs/configs/Pollution-Grading.html | 2 +- docs/configs/Popup-Messages.html | 2 +- docs/configs/Preset-Player-Colours.html | 2 +- docs/configs/Repair.html | 2 +- docs/configs/Rockets.html | 2 +- docs/configs/Roles.html | 2 +- docs/configs/Science.html | 2 +- docs/configs/Scorched-Earth.html | 2 +- docs/configs/Spawn-Area.html | 2 +- docs/configs/Tasks.html | 2 +- docs/configs/Warnings.html | 2 +- docs/configs/Warps.html | 2 +- docs/control/Jail.html | 2 +- docs/control/Production.html | 2 +- docs/control/Reports.html | 2 +- docs/control/Rockets.html | 2 +- docs/control/Tasks.html | 2 +- docs/control/Warnings.html | 2 +- docs/control/Warps.html | 2 +- docs/core/Commands.html | 2 +- docs/core/Common-Library.html | 2 +- docs/core/Gui.html | 463 +++++++++++------- docs/core/Permissions-Groups.html | 2 +- docs/core/Roles.html | 2 +- docs/core/Store.html | 2 +- docs/core/Sudo.html | 2 +- docs/core/Toolbar.html | 38 +- docs/guis/Player-List.html | 2 +- docs/guis/Rocket-Info.html | 2 +- docs/guis/Science-Info.html | 2 +- docs/guis/Task-List.html | 2 +- docs/guis/Warps-List.html | 2 +- docs/index.html | 2 +- docs/modules/control.html | 2 +- .../utils.alien_evolution_progress.html | 2 +- docs/modules/utils.core.html | 2 +- docs/modules/utils.debug.html | 2 +- docs/modules/utils.dump_env.html | 2 +- docs/modules/utils.event.html | 2 +- docs/modules/utils.event_core.html | 2 +- docs/modules/utils.math.html | 2 +- docs/modules/utils.recipe_locker.html | 2 +- docs/modules/utils.state_machine.html | 2 +- docs/modules/utils.table.html | 2 +- docs/modules/utils.task.html | 2 +- docs/modules/utils.timestamp.html | 2 +- docs/topics/license.html | 2 +- docs/topics/readme.md.html | 7 +- expcore/common.lua | 2 +- expcore/gui.lua | 66 +-- expcore/gui/concepts/button.lua | 26 +- expcore/gui/concepts/checkbox.lua | 22 +- expcore/gui/concepts/dropdown.lua | 42 +- expcore/gui/concepts/elem_button.lua | 20 +- expcore/gui/concepts/empty.lua | 16 +- expcore/gui/concepts/flow.lua | 14 +- expcore/gui/concepts/frame.lua | 14 +- expcore/gui/concepts/label.lua | 23 +- expcore/gui/concepts/line.lua | 14 +- expcore/gui/concepts/progress_bar.lua | 23 +- expcore/gui/concepts/scroll.lua | 14 +- expcore/gui/concepts/slider.lua | 26 +- expcore/gui/concepts/table.lua | 14 +- .../concepts/{textbox.lua => text_box.lua} | 38 +- .../{textfield.lua => text_field.lua} | 44 +- expcore/gui/core.lua | 109 +++-- expcore/gui/prototype.lua | 153 +++--- expcore/gui/test.lua | 131 +++-- expcore/toolbar.lua | 35 +- 114 files changed, 951 insertions(+), 583 deletions(-) rename expcore/gui/concepts/{textbox.lua => text_box.lua} (76%) rename expcore/gui/concepts/{textfield.lua => text_field.lua} (79%) 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 @@

    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)
    -    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')
         
         
    - - + + + + + + - + - - + + - - + + - - - - - + @@ -530,8 +533,12 @@ button:clone('CustomButton') - - + + + + + + @@ -546,7 +553,7 @@ button:clone('CustomButton') - + @@ -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',
         
    # - require_concept(concept) + require_concept(concept_name)
    -

    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',
    - # - Prototype:change_name([new_name=self.name]) + # + Prototype:save_as(save_name)
    -

    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')
    # - new_concept(name) + new_concept([base_concept])
    -

    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')
    - -
    # - draw_concept(name, parent) + draw_concept(concept, parent)
    @@ -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')
    - # - Prototype:change_name([new_name=self.name]) + # + Prototype:save_as(save_name)
    -

    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 @@
    + + +
    require_concept(concept)Loads a concept from the concepts file, used internallyrequire_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 nameGets 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 modulePrototype: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 eventsnew_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
    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 modulePrototype: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])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
    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) From 4f4d8d9bd5fde7c4746ed5ca4787dc49a95a5c7a Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sun, 22 Sep 2019 17:35:32 +0100 Subject: [PATCH 19/26] Better docs for store --- docs/addons/Advanced-Start.html | 2 +- docs/addons/Chat-Popups.html | 2 +- docs/addons/Chat-Reply.html | 2 +- docs/addons/Compilatron.html | 2 +- docs/addons/Damage-Popups.html | 2 +- docs/addons/Death-Logger.html | 2 +- docs/addons/Discord-Alerts.html | 2 +- docs/addons/Player-Colours.html | 2 +- docs/addons/Pollution-Grading.html | 2 +- docs/addons/Scorched-Earth.html | 2 +- docs/addons/Spawn-Area.html | 2 +- docs/commands/Admin-Chat.html | 2 +- docs/commands/Bonus.html | 2 +- docs/commands/Cheat-Mode.html | 2 +- docs/commands/Clear-Inventory.html | 2 +- docs/commands/Debug.html | 2 +- docs/commands/Find.html | 2 +- docs/commands/Help.html | 2 +- docs/commands/Home.html | 2 +- docs/commands/Interface.html | 2 +- docs/commands/Jail.html | 2 +- docs/commands/Kill.html | 2 +- docs/commands/Me.html | 2 +- docs/commands/Rainbow.html | 2 +- docs/commands/Repair.html | 2 +- docs/commands/Reports.html | 2 +- docs/commands/Roles.html | 2 +- docs/commands/Spawn.html | 2 +- docs/commands/Tag.html | 2 +- docs/commands/Teleport.html | 2 +- docs/commands/Warnings.html | 2 +- docs/configs/Advanced-Start.html | 2 +- docs/configs/Bonuses.html | 2 +- docs/configs/Chat-Reply.html | 2 +- docs/configs/Commands-Auth-Admin.html | 2 +- docs/configs/Commands-Auth-Roles.html | 2 +- .../Commands-Auth-Runtime-Disable.html | 2 +- docs/configs/Commands-Parse-Roles.html | 2 +- docs/configs/Commands-Parse.html | 2 +- docs/configs/Compilatron.html | 2 +- docs/configs/Death-Logger.html | 2 +- docs/configs/Discord-Alerts.html | 2 +- docs/configs/File-Loader.html | 2 +- docs/configs/Permission-Groups.html | 2 +- docs/configs/Player-List.html | 2 +- docs/configs/Pollution-Grading.html | 2 +- docs/configs/Popup-Messages.html | 2 +- docs/configs/Preset-Player-Colours.html | 2 +- docs/configs/Repair.html | 2 +- docs/configs/Rockets.html | 2 +- docs/configs/Roles.html | 2 +- docs/configs/Science.html | 2 +- docs/configs/Scorched-Earth.html | 2 +- docs/configs/Spawn-Area.html | 2 +- docs/configs/Tasks.html | 2 +- docs/configs/Warnings.html | 2 +- docs/configs/Warps.html | 2 +- docs/control/Jail.html | 2 +- docs/control/Production.html | 2 +- docs/control/Reports.html | 2 +- docs/control/Rockets.html | 2 +- docs/control/Tasks.html | 2 +- docs/control/Warnings.html | 2 +- docs/control/Warps.html | 2 +- docs/core/Commands.html | 2 +- docs/core/Common-Library.html | 2 +- docs/core/Gui.html | 4 +- docs/core/Permissions-Groups.html | 2 +- docs/core/Roles.html | 2 +- docs/core/Store.html | 64 ++++++++- docs/core/Sudo.html | 2 +- docs/core/Toolbar.html | 4 +- docs/guis/Player-List.html | 2 +- docs/guis/Rocket-Info.html | 2 +- docs/guis/Science-Info.html | 2 +- docs/guis/Task-List.html | 2 +- docs/guis/Warps-List.html | 2 +- docs/index.html | 2 +- docs/modules/control.html | 2 +- .../utils.alien_evolution_progress.html | 2 +- docs/modules/utils.core.html | 2 +- docs/modules/utils.debug.html | 2 +- docs/modules/utils.dump_env.html | 2 +- docs/modules/utils.event.html | 2 +- docs/modules/utils.event_core.html | 2 +- docs/modules/utils.math.html | 2 +- docs/modules/utils.recipe_locker.html | 2 +- docs/modules/utils.state_machine.html | 2 +- docs/modules/utils.table.html | 2 +- docs/modules/utils.task.html | 2 +- docs/modules/utils.timestamp.html | 2 +- docs/topics/license.html | 2 +- docs/topics/readme.md.html | 2 +- expcore/gui/concepts/button.lua | 2 +- expcore/store.lua | 132 +++++++++++++----- expcore/toolbar.lua | 9 ++ 96 files changed, 261 insertions(+), 134 deletions(-) diff --git a/docs/addons/Advanced-Start.html b/docs/addons/Advanced-Start.html index 73fbfff1..99ffc5b4 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 775e8d48..b06d2672 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 e782e0bd..d45ea3c6 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 5fd8782d..6eb7d3fe 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 7cfdaca2..95607966 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 970adce4..3ab0419f 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 5e0947dc..7e7065bc 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 d7b1e361..e2995d38 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 c4a517fb..f257ab61 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 57b0ab74..6f6fc337 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 be2099ef..b2b11a94 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 6025ff68..aafc0e4e 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 0598e87c..9db97cf7 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 cfd66e8b..1e4cc198 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 8981f9dc..03e6c886 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 b205bdb0..edfcdbb1 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 7336767c..586d8d34 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 67979913..25a8f115 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 c864e5c7..e88d2da7 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 e730c1b9..2cf6091a 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 a968ac2f..1d41e418 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 554c9a5b..6b7e21d8 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 0ae4db9f..a071c0c1 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 90df5f7a..dc82cc79 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 aafce3f8..29437a17 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 e799ff0d..65f2d825 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 c7a69793..e0d338c1 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 f30178d8..f8ef4787 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 00709274..ac1dd9e2 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 791563c0..efe6fe04 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 7efc06e3..4d8a95a6 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 dea46b30..981debc7 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 9f5b1760..f42ddc42 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 518eb631..37c2a42d 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 7b7427da..48724dfc 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 c30819c2..dc9614f2 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 33386c16..c68b216a 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 71c1c783..f432ec70 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 3987c8d6..d3c7c295 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 75d2f5bf..daeb3b5e 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 a6af1f2c..60c66414 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 2c4725b0..6cbff49c 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 98a8d207..f83ad879 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 74c617c3..8a41a0bb 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 3a63165b..abbd67bc 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 99d328d6..55ce2814 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 1679f71e..2a98b0b2 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 897866a4..5933597f 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 14d48983..1c90a44e 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 d43a33c0..4478572f 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 b311ca00..f503d293 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 8feb5039..fc973191 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 44241b1e..b8e6ad74 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 7de1ef89..8ac57876 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 a3054273..44ef1e74 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 10d950d3..1a874b76 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 a5d78060..a8b05959 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 761008db..4e10b7c8 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 b4134490..115f41c1 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 4e7b0d49..f8c8e04b 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 337ee3a5..9c23440e 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 753dc6dc..b09d725e 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 04d31e52..e2f72325 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 cbf6f350..1a650f00 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 303654a1..37d28eb4 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 b1578aa4..e4c5c30d 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 b348ff81..67827252 100644 --- a/docs/core/Gui.html +++ b/docs/core/Gui.html @@ -762,7 +762,7 @@ Gui.new_concept('button') -- W : - (SpritePath) + (SpritePath) upto three sprites in the order: default, hovered, clicked @@ -5611,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 81649b1b..6095d508 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 7edbaf8f..3e6a7fa4 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 f5a25b75..6fd3ab97 100644 --- a/docs/core/Store.html +++ b/docs/core/Store.html @@ -269,6 +269,11 @@ Store.register(team_scores,function(value,key) -- although you will need to set up a method of storing the data outside the game Store.register(team_scores,true,function(value,key) game.print('Team '..key..' now has a score of '..value) +end) + +-- If you want multiple handlers on one store location then you can register to the raw event +Event.add(Store.events.on_value_changed,function(event) + game.print('Store '..event.location..'/'..event.key..' was updated to: '..event.value) end) @@ -328,7 +333,7 @@ Store.register(team_scores,function(value,key)
    +this is similar to Store.get but will always return a table even if it is empty @@ -539,6 +544,14 @@ Store.register(team_scores,function(value,key) + Usage: +
    -- Registering a new store location
    +local store_id = Store.register()
    +
    -- Registering a new store location, with custom update callback
    +local store_id = Store.uid_location()
    +Store.register(store_id,function(value,key)
    +    game.print('Store '..store_id..'/'..key..' was updated to: '..value)
    +end)
    @@ -613,6 +626,10 @@ Store.register(team_scores,function(value,key) + Usage: +
    -- Getting the data at a store location
    +local data = Store.get(store_id_no_keys)
    +local data = Store.get(store_id_with_keys,'key_one')
    @@ -737,6 +754,10 @@ Store.register(team_scores,function(value,key) + Usage: +
    -- Setting the data at a store location
    +Store.set(store_id_no_keys,'Hello, World!')
    +Store.set(store_id_with_keys,'key_one','Hello, World!')
    @@ -821,6 +842,21 @@ Store.register(team_scores,function(value,key) + Usage: +
    -- Updating a value stored at a location
    +Store.update(store_id_no_keys,function(value)
    +    return value + 1
    +end)
    +Store.update(store_id_with_keys,'key_one',function(value)
    +    return value + 1
    +end)
    +
    -- Updating a table stored at a location
    +Store.update(store_id_no_keys,function(value)
    +    value.ctn = value.ctn + 1
    +end)
    +Store.update(store_id_with_keys,'key_one',function(value)
    +    value.ctn = value.ctn + 1
    +end)
    @@ -888,6 +924,15 @@ Store.register(team_scores,function(value,key) + Usage: +
    -- Updating all values at a location
    +Store.update(store_id_with_keys,function(value)
    +    return value + 1
    +end)
    +
    -- Updating all tables at a location
    +Store.update(store_id_with_keys,function(value)
    +    value.ctn = value.ctn + 1
    +end)
    @@ -979,6 +1024,10 @@ Store.register(team_scores,function(value,key) + Usage: +
    -- Clear the data at a location
    +Store.clear(store_id_no_keys)
    +Store.clear(store_id_with_keys,'key_one')
    @@ -993,7 +1042,7 @@ Store.register(team_scores,function(value,key)

    Gets all non nil keys at a location, keys can be added and removed during runtime - this is similar to Store.get but will always return a table even if it is empty

    +this is similar to Store.get but will always return a table even if it is empty

    @@ -1037,6 +1086,9 @@ Store.register(team_scores,function(value,key) + Usage: +
    -- Get all keys at a store location
    +local keys = Store.get_keys(store_id_with_keys)
    @@ -1094,6 +1146,9 @@ Store.register(team_scores,function(value,key) + Usage: +
    -- Check that a store is registered
    +local registerd = Store.is_registered(store_id)
    @@ -1128,6 +1183,9 @@ Store.register(team_scores,function(value,key) + Usage: +
    -- Get a new unique store id
    +local store_id = Store.uid_location()
    @@ -1146,7 +1204,7 @@ Store.register(team_scores,function(value,key) generated by LDoc
    diff --git a/docs/core/Sudo.html b/docs/core/Sudo.html index 2b9a66e1..9f4c83f9 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 0bcff3f0..2db838da 100644 --- a/docs/core/Toolbar.html +++ b/docs/core/Toolbar.html @@ -1185,6 +1185,7 @@ Gui.new_concept('toolbar-frame') :set_permission_alias('player_list') :set_caption('Player List') :toggle_with_click() + :define_draw(function(properties,parent,element) local list_area = element.add{ @@ -1205,6 +1206,7 @@ Gui.new_concept('toolbar-frame') } endend) + :on_update(function(event) local list_area = event.element.scroll list_area.clear() @@ -1658,7 +1660,7 @@ Gui.new_concept('toolbar-frame') generated by LDoc diff --git a/docs/guis/Player-List.html b/docs/guis/Player-List.html index 51a5f3f6..e80e3022 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 5411b5a9..65b15a82 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 84d8d3c0..567731c0 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 576dcf2c..28d1ef22 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 a0ee7c7d..91e2640e 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 2e6ac538..a2c82dd5 100644 --- a/docs/index.html +++ b/docs/index.html @@ -514,7 +514,7 @@ see ./expcore/commands.lua for more detailsgenerated by LDoc diff --git a/docs/modules/control.html b/docs/modules/control.html index b3ca5cec..4fb5d84e 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 974e41a8..de092da3 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 b5e42e86..7087a571 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 e41f95c7..1d9e7fdc 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 1de42342..c4da3636 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 fd2fb48b..bc1f5698 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 c23f367c..b53537ea 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 38b0f253..b74b9490 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 2900f85f..59449178 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 28ec9697..9a60f448 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 5be2d399..eaec6291 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 35fb4414..e853536f 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 f85b4c01..97e2409e 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 7d2d1e66..219ecba4 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 6257b341..24b2d167 100644 --- a/docs/topics/readme.md.html +++ b/docs/topics/readme.md.html @@ -334,7 +334,7 @@ generated by LDoc diff --git a/expcore/gui/concepts/button.lua b/expcore/gui/concepts/button.lua index 604e30c2..4cbcc6cd 100644 --- a/expcore/gui/concepts/button.lua +++ b/expcore/gui/concepts/button.lua @@ -14,7 +14,7 @@ local Gui = require 'expcore.gui.core' @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 +@tparam Concepts.SpritePath sprite upto three sprites in the order: default, hovered, clicked @usage-- Making a basic button local basic_button = diff --git a/expcore/store.lua b/expcore/store.lua index d0b4dcbd..5d3f80ce 100644 --- a/expcore/store.lua +++ b/expcore/store.lua @@ -40,6 +40,11 @@ Store.register(team_scores,true,function(value,key) game.print('Team '..key..' now has a score of '..value) end) +-- If you want multiple handlers on one store location then you can register to the raw event +Event.add(Store.events.on_value_changed,function(event) + game.print('Store '..event.location..'/'..event.key..' was updated to: '..event.value) +end) + ]] local Global = require 'utils.global' --- @dep utils.global @@ -67,11 +72,19 @@ local function error_not_table(value) end end ---- Registers a new location with an update callback which is triggered when the value updates --- @tparam[opt] string location string a unique that points to the data, string used rather than token to allow migration --- @tparam[opt=false] boolean synced when true will output changes to a file so it can be synced --- @tparam[opt] function callback when given the callback will be automatically registered to the update of the value --- @treturn string the location that is being used +--[[-- Registers a new location with an update callback which is triggered when the value updates +@tparam[opt] string location string a unique that points to the data, string used rather than token to allow migration +@tparam[opt=false] boolean synced when true will output changes to a file so it can be synced +@tparam[opt] function callback when given the callback will be automatically registered to the update of the value +@treturn string the location that is being used +@usage-- Registering a new store location +local store_id = Store.register() +@usage-- Registering a new store location, with custom update callback +local store_id = Store.uid_location() +Store.register(store_id,function(value,key) + game.print('Store '..store_id..'/'..key..' was updated to: '..value) +end) +]] function Store.register(location,synced,callback) if _LIFECYCLE ~= _STAGE.control then return error('Can only be called during the control stage', 2) @@ -99,10 +112,14 @@ function Store.register(location,synced,callback) return location end ---- Gets the value stored at a location, this location must be registered --- @tparam string location the location to get the data from --- @tparam[opt] string key the key location if used --- @treturn any the data which was stored at the location +--[[-- Gets the value stored at a location, this location must be registered +@tparam string location the location to get the data from +@tparam[opt] string key the key location if used +@treturn any the data which was stored at the location +@usage-- Getting the data at a store location +local data = Store.get(store_id_no_keys) +local data = Store.get(store_id_with_keys,'key_one') +]] function Store.get(location,key) if not Store.registered[location] then return error('Location is not registered', 2) @@ -117,13 +134,17 @@ function Store.get(location,key) return data end ---- Sets the value at a location, this location must be registered --- @tparam string location the location to set the data to --- @tparam[opt] string key the key location if used --- @tparam any value the new value to set at the location, value may be reverted if there is a watch callback, cant be nil --- @tparam[opt=false] boolean from_sync set this true to avoid an output to the sync file --- @tparam[opt=false] boolean from_internal set this true to add one to the error stack offset --- @treturn boolean true if it was successful +--[[-- Sets the value at a location, this location must be registered +@tparam string location the location to set the data to +@tparam[opt] string key the key location if used +@tparam any value the new value to set at the location, value may be reverted if there is a watch callback, cant be nil +@tparam[opt=false] boolean from_sync set this true to avoid an output to the sync file +@tparam[opt=false] boolean from_internal set this true to add one to the error stack offset +@treturn boolean true if it was successful +@usage-- Setting the data at a store location +Store.set(store_id_no_keys,'Hello, World!') +Store.set(store_id_with_keys,'key_one','Hello, World!') +]] function Store.set(location,key,value,from_sync,from_internal) if not Store.registered[location] then return error('Location is not registered', from_internal and 3 or 2) @@ -157,10 +178,25 @@ function Store.set(location,key,value,from_sync,from_internal) return true end ---- Allows for updating a value based on the current value; only valid way to change tables in a store --- @tparam string location the location to set the data to --- @tparam[opt] string key the key location if required --- @tparam[opt] function update_callback the function called to update the value stored, rtn value to set new value +--[[-- Allows for updating a value based on the current value; only valid way to change tables in a store +@tparam string location the location to set the data to +@tparam[opt] string key the key location if required +@tparam[opt] function update_callback the function called to update the value stored, rtn value to set new value +@usage-- Updating a value stored at a location +Store.update(store_id_no_keys,function(value) + return value + 1 +end) +Store.update(store_id_with_keys,'key_one',function(value) + return value + 1 +end) +@usage-- Updating a table stored at a location +Store.update(store_id_no_keys,function(value) + value.ctn = value.ctn + 1 +end) +Store.update(store_id_with_keys,'key_one',function(value) + value.ctn = value.ctn + 1 +end) +]] function Store.update(location,key,update_callback,...) local value = Store.get(location,key) @@ -194,9 +230,18 @@ function Store.update(location,key,update_callback,...) end ---- Allows for updating all values at a location based on the current value; only valid way to change tables in a store --- @tparam string location the location to set the data to --- @tparam[opt] function update_callback the function called to update the value stored +--[[-- Allows for updating all values at a location based on the current value; only valid way to change tables in a store +@tparam string location the location to set the data to +@tparam[opt] function update_callback the function called to update the value stored +@usage-- Updating all values at a location +Store.update(store_id_with_keys,function(value) + return value + 1 +end) +@usage-- Updating all tables at a location +Store.update(store_id_with_keys,function(value) + value.ctn = value.ctn + 1 +end) +]] function Store.update_all(location,update_callback,...) local data = Store.get(location) @@ -223,11 +268,15 @@ function Store.update_all(location,update_callback,...) end ---- Sets the value at a location to nil, this location must be registered --- @tparam string location the location to set the data to --- @tparam[opt] string key the key location if used --- @tparam[opt=false] boolean from_sync set this true to avoid an output to the sync file --- @treturn boolean true if it was successful +--[[-- Sets the value at a location to nil, this location must be registered +@tparam string location the location to set the data to +@tparam[opt] string key the key location if used +@tparam[opt=false] boolean from_sync set this true to avoid an output to the sync file +@treturn boolean true if it was successful +@usage-- Clear the data at a location +Store.clear(store_id_no_keys) +Store.clear(store_id_with_keys,'key_one') +]] function Store.clear(location,key,from_sync) if not Store.callbacks[location] then return error('Location is not registered', 2) @@ -252,24 +301,33 @@ function Store.clear(location,key,from_sync) return true end ---- Gets all non nil keys at a location, keys can be added and removed during runtime --- this is similar to Store.get but will always return a table even if it is empty --- @tparam string location the location to get the keys of --- @treturn table a table containing all the keys names +--[[-- Gets all non nil keys at a location, keys can be added and removed during runtime +this is similar to Store.get but will always return a table even if it is empty +@tparam string location the location to get the keys of +@treturn table a table containing all the keys names +@usage-- Get all keys at a store location +local keys = Store.get_keys(store_id_with_keys) +]] function Store.get_keys(location) local data = Store.get(location) return type(data) == 'table' and table_keys(data) or {} end ---- Check for if a location is registered --- @tparam string location the location to test for --- @treturn boolean true if registered +--[[-- Check for if a location is registered +@tparam string location the location to test for +@treturn boolean true if registered +@usage-- Check that a store is registered +local registerd = Store.is_registered(store_id) +]] function Store.is_registered(location) return Store.registered[location] end ---- Returns a unique name that can be used for a store --- @treturn string a unique name +--[[-- Returns a unique name that can be used for a store +@treturn string a unique name +@usage-- Get a new unique store id +local store_id = Store.uid_location() +]] function Store.uid_location() return tostring(Token.uid()) end diff --git a/expcore/toolbar.lua b/expcore/toolbar.lua index d30ee06f..da1b5d16 100644 --- a/expcore/toolbar.lua +++ b/expcore/toolbar.lua @@ -102,13 +102,16 @@ end --[[-- The base element to be used with the toolbar, others can be used but this is recomented @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.new_concept('toolbar-button') :set_caption('Click Me') :on_click(function(event) event.player.print('You Clicked Me!!') end) + ]] Toolbar.button = Gui.new_concept('button') @@ -176,16 +179,20 @@ end --[[-- The base toolbar frame, others can be used but this is recomented @element toolbar-frame + @param on_update fired when the frame is to have its content updated + @tparam boolean open_by_default weather the frame should be open when a player first joins @tparam boolean use_container true by default and will place a container inside the frame for content @tparam string direction the direction that the items in the frame are added + @usage-- Adding a basic player list local player_list = Gui.new_concept('toolbar-frame') :set_permission_alias('player_list') :set_caption('Player List') :toggle_with_click() + :define_draw(function(properties,parent,element) local list_area = element.add{ @@ -206,6 +213,7 @@ Gui.new_concept('toolbar-frame') } end end) + :on_update(function(event) local list_area = event.element.scroll list_area.clear() @@ -217,6 +225,7 @@ end) } end end) + ]] Toolbar.frame = Gui.new_concept('toolbar-button') From ad4b870b59a27b5de0641b460d32eb27a7e58aa7 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sun, 22 Sep 2019 19:21:21 +0100 Subject: [PATCH 20/26] Added some elements to expstyle --- expcore/gui/concepts/label.lua | 2 +- expcore/gui/core.lua | 2 +- expcore/gui/prototype.lua | 9 +- expcore/gui/styles/expstyle/alignment.lua | 47 +++++++++++ expcore/gui/styles/expstyle/container.lua | 36 ++++++++ expcore/gui/styles/expstyle/header.lua | 49 +++++++++++ expcore/gui/styles/expstyle/index.lua | 13 +++ expcore/gui/styles/expstyle/scroll_table.lua | 56 +++++++++++++ expcore/gui/styles/expstyle/time_label.lua | 86 ++++++++++++++++++++ 9 files changed, 297 insertions(+), 3 deletions(-) create mode 100644 expcore/gui/styles/expstyle/alignment.lua create mode 100644 expcore/gui/styles/expstyle/container.lua create mode 100644 expcore/gui/styles/expstyle/header.lua create mode 100644 expcore/gui/styles/expstyle/index.lua create mode 100644 expcore/gui/styles/expstyle/scroll_table.lua create mode 100644 expcore/gui/styles/expstyle/time_label.lua diff --git a/expcore/gui/concepts/label.lua b/expcore/gui/concepts/label.lua index 1cf70eac..9c2df448 100644 --- a/expcore/gui/concepts/label.lua +++ b/expcore/gui/concepts/label.lua @@ -6,7 +6,7 @@ local Gui = require 'expcore.gui.core' --[[-- A piece of text. -@element frame +@element label @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 diff --git a/expcore/gui/core.lua b/expcore/gui/core.lua index 1edcd0b3..5365d54a 100644 --- a/expcore/gui/core.lua +++ b/expcore/gui/core.lua @@ -30,7 +30,7 @@ end Gui.require_concept('expgaming') --- @dep Gui.style.frame ]] function Gui.require_style(style_name) - require('expcore.gui.styles.'..style_name) + require('expcore.gui.styles.'..style_name..'.index') end --[[-- Gets a gui concept from name, id, or its self diff --git a/expcore/gui/prototype.lua b/expcore/gui/prototype.lua index 902aa4dc..269b4023 100644 --- a/expcore/gui/prototype.lua +++ b/expcore/gui/prototype.lua @@ -417,6 +417,7 @@ end --[[-- Calls all the draw functions in order to create this concept in game; will also store and sync the instance if stores are used @tparam LuaGuiElement parent_element the element that the concept will use as a base +@tparam[opt] string override_name when given this will be the name of the element rather than the concept id @treturn LuaGuiElement the element that was created and then passed though and returned by the draw functions @usage-- Drawing the custom button concept local custom_button = @@ -425,10 +426,12 @@ Gui.get_concept('CustomButton') -- Note that the draw function from button was cloned, so unless we want to alter the base button we dont need a new draw define custom_button:draw(game.player.gui.left) ]] -function Prototype:draw(parent_element,...) +function Prototype:draw(parent_element,override_name,...) + local old_name = self.properties.name local parent = parent_element local element + if override_name then self.properties.name = override_name end -- Loop over all the draw defines, element is updated when a value is returned for _,draw_callback in pairs(self.draw_callbacks) do local success, _element, _parent = pcall(draw_callback,self.properties,parent,element,...) @@ -436,10 +439,14 @@ function Prototype:draw(parent_element,...) if _element then element = _element end if _parent then parent = _parent end elseif not success then + self.properties.name = old_name error('Gui draw handler error with '..self.debug_name..':\n\t'.._element) end end + -- Return the name back to its previous value + self.properties.name = old_name + -- Adds the instance if instance store is used if self.add_instance then self.add_instance(element) diff --git a/expcore/gui/styles/expstyle/alignment.lua b/expcore/gui/styles/expstyle/alignment.lua new file mode 100644 index 00000000..a00c325f --- /dev/null +++ b/expcore/gui/styles/expstyle/alignment.lua @@ -0,0 +1,47 @@ +--[[-- Core Module - ExpStyle + @module ExpStyle +]] + +local Gui = require 'expcore.gui' --- @dep expcore.gui + +Gui.require_concept 'flow' --- @dep gui.concept.flow + +--[[-- A flow which can be used to align text and other elements +@element alignment +@usage-- Concept Structure +-- Root +--> [alignment] - the alignment area +Gui.new_concept('alignment') +:set_horizontal_align('center') +]] + +Gui.new_concept('flow') +:save_as('alignment') + +:new_property('horizontal_align',nil,'right') +:new_property('vertical_align',nil,'center') +:new_property('width') +:new_property('height') + +:define_draw(function(properties,parent,element) + local style = element.style + Gui.set_padding(element,1,1,2,2) + + -- Set the alignment of the flow + style.horizontal_align = properties.horizontal_align + style.vertical_align = properties.vertical_align + + -- Set the stretchablity based on the alignment + style.horizontally_stretchable = style.horizontal_align ~= 'center' + style.vertically_stretchable = style.vertical_align ~= 'center' + + -- Set the width if given + local width = properties.width + if width then style.width = width end + + -- Set the hieght if given + local height = properties.height + if height then style.height = height end + + return element +end) \ No newline at end of file diff --git a/expcore/gui/styles/expstyle/container.lua b/expcore/gui/styles/expstyle/container.lua new file mode 100644 index 00000000..c475c95d --- /dev/null +++ b/expcore/gui/styles/expstyle/container.lua @@ -0,0 +1,36 @@ +--[[-- Core Module - ExpStyle + @module ExpStyle +]] + +local Gui = require 'expcore.gui' --- @dep expcore.gui + +Gui.require_concept 'frame' --- @dep gui.concept.frame + +--[[-- A container frame that can be used to add a boader around your content +@element container +@usage-- Concept Structure +-- Root +--> [container] - the outer frame +-->> container - the content area +Gui.new_concept('container') +]] + +Gui.new_concept('frame') +:save_as('container') +:define_draw(function(properties,parent,element) + -- Update the outter frame padding + element.style.padding = 2 + + -- Add the inner frame + element = element.add{ + name = 'container', + type = 'frame', + direction = properties.direction, + style = 'window_content_frame_packed' + } + + -- Update the inner frame padding + element.style.padding = 0 + + return element +end) \ No newline at end of file diff --git a/expcore/gui/styles/expstyle/header.lua b/expcore/gui/styles/expstyle/header.lua new file mode 100644 index 00000000..c5699fb5 --- /dev/null +++ b/expcore/gui/styles/expstyle/header.lua @@ -0,0 +1,49 @@ +--[[-- Core Module - ExpStyle + @module ExpStyle +]] + +local Gui = require 'expcore.gui' --- @dep expcore.gui + +Gui.require_concept 'frame' --- @dep gui.concept.table + +local right_align = +Gui.new_concept('alignment') + +--[[-- A frame that acts as a header to a section of content +@element header +@tparam string tooltip the tooltip to show on the title +@usage-- Concept Structure +-- Root +--> [header] - the header frame +-->> header_caption - the lable with the title in it +-->> header_content - the area to contain butons +]] + +Gui.new_concept('frame') +:save_as('header') +:new_property('tooltip') + +-- Draw +:define_draw(function(properties,parent,element) + -- Update the table style + Gui.set_padding(element,2,2,4,4) + element.style = 'subheader_frame' + element.caption = nil + + local style = element.style + style.horizontally_stretchable = true + style.use_header_filler = false + + -- Add the caption to the frame + element.add{ + type = 'label', + name = 'header_caption', + caption = properties.title, + tooltip = properties.tooltip + } + + -- Add the right align area + local align = right_align:draw(element,'header_content') + + return align +end) \ No newline at end of file diff --git a/expcore/gui/styles/expstyle/index.lua b/expcore/gui/styles/expstyle/index.lua new file mode 100644 index 00000000..aa8afa39 --- /dev/null +++ b/expcore/gui/styles/expstyle/index.lua @@ -0,0 +1,13 @@ +--[[-- Core Module - ExpStyle + @core ExpStyle +]] + +local function r(name) + require('expcore.gui.styles.expstyle.'..name) +end + +r 'container' +r 'alignment' +r 'header' +r 'scroll_table' +r 'time_label' \ No newline at end of file diff --git a/expcore/gui/styles/expstyle/scroll_table.lua b/expcore/gui/styles/expstyle/scroll_table.lua new file mode 100644 index 00000000..0c1473d5 --- /dev/null +++ b/expcore/gui/styles/expstyle/scroll_table.lua @@ -0,0 +1,56 @@ +--[[-- Core Module - ExpStyle + @module ExpStyle +]] + +local Gui = require 'expcore.gui' --- @dep expcore.gui + +Gui.require_concept 'table' --- @dep gui.concept.table +Gui.require_concept 'scroll' --- @dep gui.concept.scroll + +local scroll_area = +Gui.new_concept('scroll') +:set_vertical_scroll('auto-and-reserve-space') +:set_horizontal_scroll('never') + +--[[-- A table that is inside a vertical scroll area +@element scroll_table +@tparam number hight the max hight of the scroll area +@usage-- Concept Structure +-- Root +--> [scroll_table] - the scroll area +-->> table - the table area +]] + +Gui.new_concept('table') +:save_as('scroll_table') +:new_property('hight',nil,100) + +-- Add a scroll before the table is drawn +:define_pre_draw(function(properties,parent,element) + local scroll = scroll_area:draw(parent,properties.name) + + -- Set the scroll style + Gui.set_padding(scroll,1,1,2,2) + scroll.style.horizontally_stretchable = true + scroll.style.maximal_height = properties.hight + + -- Change the name of the element to table before it is drawn + properties.name = 'table' + + return element, scroll +end) + +-- Draw +:define_draw(function(properties,parent,element) + -- Update the table style + local style = element.style + style.padding = 0 + style.horizontally_stretchable = true + style.vertical_align = 'center' + style.cell_padding = 0 + + -- Change the stored name back to the actual name + properties.name = element.parent.name + + return element +end) \ No newline at end of file diff --git a/expcore/gui/styles/expstyle/time_label.lua b/expcore/gui/styles/expstyle/time_label.lua new file mode 100644 index 00000000..efa7fd1f --- /dev/null +++ b/expcore/gui/styles/expstyle/time_label.lua @@ -0,0 +1,86 @@ +--[[-- Core Module - ExpStyle + @module ExpStyle +]] + +local Gui = require 'expcore.gui' --- @dep expcore.gui +local format_time = ext_require('expcore.common','format_time') --- @dep expcore.common + +--- Converts a tick into string format with workds and symbols +local function get_format(properties,time) + local caption, tooltip + + -- Check if a custom format is wanted + if properties.time_format then + -- Get the caption + local format = table.deep_copy(properties.time_format) + caption = format_time(time,format) + + -- Get the tooltip, always long format + format.long = true + tooltip = format_time(time,format) + + else + -- Get the caption + caption = format_time(time,{ + hours = properties.use_hours, + minutes = true, + seconds = true + }) + + -- Get the tooltip, same as the caption but long format + tooltip = format_time(time,{ + hours = properties.use_hours, + minutes = true, + seconds = true, + long = true + }) + + end + + return caption, tooltip +end + +--[[-- A label that show time in a nice, user friendly way +@element time_label +@tparam number time the time to display in tick +@usage-- Concept Structure +-- Root +--> [time_label] - the label with the time +]] + +local time_label = +Gui.new_concept() +:save_as('time_label') + +-- Properties +:new_property('time') +:new_property('use_hours',nil,false) +:new_property('time_format') + +-- Draw +:define_draw(function(properties,parent,element,time) + -- Get the caption and tooltip + local caption, tooltip = get_format(properties,time or properties.time) + + -- Draw a label + element = parent.add{ + name = properties.name, + type = 'label', + caption = caption, + tooltip = tooltip + } + + return element +end) + +--[[-- Updates the time that is on a label +@tparam LuaGuiElement element the label that you want to update +@tparam number time the number of tick you want it to show +@usage-- Update the time to show game time +time_label:update_time(element,game.time) +]] +function time_label:update_time(element,time) + local caption, tooltip = get_format(self.properties,time) + element.caption = caption + element.tooltip = tooltip +end \ No newline at end of file From 2cd9c80804c7b3291f1aaa3bbb29af354d47ed3d Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Tue, 24 Sep 2019 18:43:19 +0100 Subject: [PATCH 21/26] Added more styles --- expcore/gui/styles/expstyle/header.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/expcore/gui/styles/expstyle/header.lua b/expcore/gui/styles/expstyle/header.lua index c5699fb5..94991865 100644 --- a/expcore/gui/styles/expstyle/header.lua +++ b/expcore/gui/styles/expstyle/header.lua @@ -10,6 +10,7 @@ local right_align = Gui.new_concept('alignment') --[[-- A frame that acts as a header to a section of content +@see frame @element header @tparam string tooltip the tooltip to show on the title @usage-- Concept Structure @@ -17,6 +18,8 @@ Gui.new_concept('alignment') --> [header] - the header frame -->> header_caption - the lable with the title in it -->> header_content - the area to contain butons +Gui.new_concept('header') +:set_title('Example Header') ]] Gui.new_concept('frame') From 3609d07504cf35175f3df7b1873f8882fdcbae02 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Tue, 24 Sep 2019 18:43:32 +0100 Subject: [PATCH 22/26] Added more styles --- expcore/gui/styles/expstyle/alignment.lua | 1 + expcore/gui/styles/expstyle/container.lua | 1 + expcore/gui/styles/expstyle/data_label.lua | 89 +++++++++++++++++ expcore/gui/styles/expstyle/footer.lua | 52 ++++++++++ expcore/gui/styles/expstyle/scroll_table.lua | 4 + expcore/gui/styles/expstyle/time_label.lua | 6 ++ expcore/gui/styles/expstyle/toggle_button.lua | 49 ++++++++++ expcore/gui/styles/expstyle/unit_label.lua | 95 +++++++++++++++++++ 8 files changed, 297 insertions(+) create mode 100644 expcore/gui/styles/expstyle/data_label.lua create mode 100644 expcore/gui/styles/expstyle/footer.lua create mode 100644 expcore/gui/styles/expstyle/toggle_button.lua create mode 100644 expcore/gui/styles/expstyle/unit_label.lua diff --git a/expcore/gui/styles/expstyle/alignment.lua b/expcore/gui/styles/expstyle/alignment.lua index a00c325f..23477684 100644 --- a/expcore/gui/styles/expstyle/alignment.lua +++ b/expcore/gui/styles/expstyle/alignment.lua @@ -7,6 +7,7 @@ local Gui = require 'expcore.gui' --- @dep expcore.gui Gui.require_concept 'flow' --- @dep gui.concept.flow --[[-- A flow which can be used to align text and other elements +@see flow @element alignment @usage-- Concept Structure -- Root diff --git a/expcore/gui/styles/expstyle/container.lua b/expcore/gui/styles/expstyle/container.lua index c475c95d..ca1a62bb 100644 --- a/expcore/gui/styles/expstyle/container.lua +++ b/expcore/gui/styles/expstyle/container.lua @@ -7,6 +7,7 @@ local Gui = require 'expcore.gui' --- @dep expcore.gui Gui.require_concept 'frame' --- @dep gui.concept.frame --[[-- A container frame that can be used to add a boader around your content +@see frame @element container @usage-- Concept Structure -- Root diff --git a/expcore/gui/styles/expstyle/data_label.lua b/expcore/gui/styles/expstyle/data_label.lua new file mode 100644 index 00000000..c6ca002c --- /dev/null +++ b/expcore/gui/styles/expstyle/data_label.lua @@ -0,0 +1,89 @@ +--[[-- Core Module - ExpStyle + @module ExpStyle +]] + +local Gui = require 'expcore.gui' --- @dep expcore.gui + +Gui.require_concept 'label' --- @dep gui.concept.frame + +local right_align = +Gui.new_concept('alignment') + +--[[-- A label pair which has a static label and a data label which can be changed +@see label +@element data_label +@usage-- Concept Structure +-- Root +--> [data_label] - the static label +--> [properties.data_name] - the data label which can be updated +Gui.new_concept('data_label') +:set_data_label_name('game_ticks') +:set_data_caption('0') +:set_data_format(function(concept,element,data,...) + -- This is used with update_data_element and update_from_parent + local caption = tostirng('data') + local tooltip = 'This game has beeing running for: '..caption..' ticks' + return caption, tooltip +end) +]] + +local data_label = +Gui.new_concept('label') +:save_as('data_label') +:new_property('data_label_name') +:new_property('data_caption') +:new_property('data_tooltip') +:new_property('data_format',nil,function(concept,element,data,...) + return tostring(data) +end) + +-- Draw +:define_draw(function(properties,parent,element) + -- Make the label right aligned + local data_name = properties.data_label_name or properties.name..'_data' + local right_align_element = right_align:draw(parent,data_name) + + -- Add a new label + local data_label_element = + right_align_element.add{ + name = 'data_label' + } + + -- Get the data caption + local caption = Gui.resolve_property(properties.data_caption,element) + if caption then + data_label_element.caption = caption + end + + -- Get the data tooltip + local tooltip = Gui.resolve_property(properties.data_tooltip,element) + if tooltip then + data_label_element.tooltip = tooltip + end + + return data_label_element +end) + +function data_label:update_data_element(element,data,...) + local caption, tooltip = self.properties.data_format(self,element,data,...) + if caption then + element.caption = caption + end + if tooltip then + element.tooltip = tooltip + end +end + +function data_label:update_from_parent(parent,data,...) + local properties = self.properties + local data_name = properties.data_label_name or properties.name..'_data' + local element = parent[data_name] and parent[data_name].data_label or error('Data label is not a child of this element element',2) + + local caption, tooltip = properties.data_format(self,element,data,...) + if caption then + element.caption = caption + end + if tooltip then + element.tooltip = tooltip + end +end \ No newline at end of file diff --git a/expcore/gui/styles/expstyle/footer.lua b/expcore/gui/styles/expstyle/footer.lua new file mode 100644 index 00000000..3497832b --- /dev/null +++ b/expcore/gui/styles/expstyle/footer.lua @@ -0,0 +1,52 @@ +--[[-- Core Module - ExpStyle + @module ExpStyle +]] + +local Gui = require 'expcore.gui' --- @dep expcore.gui + +Gui.require_concept 'frame' --- @dep gui.concept.table + +local right_align = +Gui.new_concept('alignment') + +--[[-- A frame that acts as a footer to a section of content +@see frame +@element footer +@tparam string tooltip the tooltip to show on the title +@usage-- Concept Structure +-- Root +--> [footer] - the footer frame +-->> footer_caption - the lable with the title in it +-->> footer_content - the area to contain butons +Gui.new_concept('footer') +:set_title('Example Footer') +]] + +Gui.new_concept('frame') +:save_as('footer') +:new_property('tooltip') + +-- Draw +:define_draw(function(properties,parent,element) + -- Update the table style + Gui.set_padding(element,2,2,4,4) + element.style = 'subfooter_frame' + element.caption = nil + + local style = element.style + style.horizontally_stretchable = true + style.use_header_filler = false + + -- Add the caption to the frame + element.add{ + type = 'label', + name = 'footer_caption', + caption = properties.title, + tooltip = properties.tooltip + } + + -- Add the right align area + local align = right_align:draw(element,'footer_content') + + return align +end) \ No newline at end of file diff --git a/expcore/gui/styles/expstyle/scroll_table.lua b/expcore/gui/styles/expstyle/scroll_table.lua index 0c1473d5..411851b7 100644 --- a/expcore/gui/styles/expstyle/scroll_table.lua +++ b/expcore/gui/styles/expstyle/scroll_table.lua @@ -13,12 +13,16 @@ Gui.new_concept('scroll') :set_horizontal_scroll('never') --[[-- A table that is inside a vertical scroll area +@see table @element scroll_table @tparam number hight the max hight of the scroll area @usage-- Concept Structure -- Root --> [scroll_table] - the scroll area -->> table - the table area +Gui.new_concept('scroll_table') +:set_height(200) +:set_column_count(2) ]] Gui.new_concept('table') diff --git a/expcore/gui/styles/expstyle/time_label.lua b/expcore/gui/styles/expstyle/time_label.lua index efa7fd1f..64f5f6b7 100644 --- a/expcore/gui/styles/expstyle/time_label.lua +++ b/expcore/gui/styles/expstyle/time_label.lua @@ -46,6 +46,12 @@ end @usage-- Concept Structure -- Root --> [time_label] - the label with the time +local time_label = +Gui.new_concept('time_label') +:set_use_hours(true) +:set_time(game.tick) + +time_label:update_time(element,game.tick) ]] local time_label = diff --git a/expcore/gui/styles/expstyle/toggle_button.lua b/expcore/gui/styles/expstyle/toggle_button.lua new file mode 100644 index 00000000..06adc602 --- /dev/null +++ b/expcore/gui/styles/expstyle/toggle_button.lua @@ -0,0 +1,49 @@ +--[[-- Core Module - ExpStyle + @module ExpStyle +]] + +local Gui = require 'expcore.gui' --- @dep expcore.gui + +Gui.require_concept 'button' --- @dep gui.concept.table + +--[[-- A button that will toggle its caption each time it is pressed +@see button +@element toggle_button +@tparam string alt_caption the caption to show on the button in its true state +@tparam string alt_tooltip the tooltip to show on the button in its true state +@usage-- Concept Structure +-- Root +--> [toggle_button] - the header button +Gui.new_concept('toggle_button') +:set_caption('<') +:set_tooltip('Press to close.') +:set_alt_caption('>') +:set_alt_tooltip('Press to open.') +:on_click(function(event) + local state = event.state and 'close' or 'open' + event.player.print('Toggle button is now: '..state) +end) +]] + +Gui.new_concept('button') +:save_as('toggle_button') +:new_property('alt_caption') +:new_property('alt_tooltip') + +-- Events +:on_click(function(event) + local concept = event.concept + local properties = concept.properties + local element = event.element + if element.caption == properties.caption then + element.caption = properties.alt_caption + element.tooltip = properties.alt_tooltip or properties.tooltip + event.state = true + + else + element.caption = properties.caption + element.tooltip = properties.tooltip or properties.alt_tooltip + event.state = false + + end +end) \ No newline at end of file diff --git a/expcore/gui/styles/expstyle/unit_label.lua b/expcore/gui/styles/expstyle/unit_label.lua new file mode 100644 index 00000000..3295997a --- /dev/null +++ b/expcore/gui/styles/expstyle/unit_label.lua @@ -0,0 +1,95 @@ +--[[-- Core Module - ExpStyle + @module ExpStyle +]] + +local Gui = require 'expcore.gui' --- @dep expcore.gui + +Gui.require_concept 'label' --- @dep gui.concept.frame + +local right_align = +Gui.new_concept('alignment') + +--[[-- A label triplet which has a static label, a data label which can be changed, and a unit label +@see label +@see data_label +@element unit_label +@usage-- Concept Structure +-- Root +--> [unit_label] - the static label +--> [properties.data_name] - the data label which can be updated +--> [properties.data_name..'_unit'] - the data label unit which can be updated +Gui.new_concept('unit_label') +:set_data_label_name('game_ticks') +:set_data_caption('0') +:set_data_unit('ticks') +:set_data_format(function(concept,element,data,...) + -- This is used with update_data_element and update_from_parent + local caption = tostirng(data) + local unit = data > 1 and 'ticks' or 'tick' + local tooltip = 'This game has beeing running for: '..caption..' ticks' + return caption, unit, tooltip +end) +]] + +local unit_label = +Gui.new_concept('data_label') +:save_as('unit_label') +:new_property('data_label_name') +:new_property('data_caption') +:new_property('data_tooltip') +:new_property('data_unit') +:new_property('data_format',nil,function(concept,element,data,...) + local base_unit = concept.properties.data_unit + local caption = tostring(data) + local unit = data == 1 and base_unit or base_unit..'s' + return caption, unit +end) + +-- Draw +:define_draw(function(properties,parent,element) + -- Get the unit data + local unit = Gui.resolve_property(properties.data_unit,element) + + -- Add the unit label + parent.add{ + name = element.name..'_unit', + caption = unit or '', + tooltip = element.tooltip + } + + return element +end) + +function unit_label:update_data_element(element,data,...) + local caption, unit, tooltip = self.properties.data_format(self,element,data,...) + local unit_element = element.parent.parent[element.name..'_unit'] + if caption then + element.caption = caption + end + if tooltip then + element.tooltip = tooltip + unit_element.tooltip = tooltip + end + if unit then + unit_element.caption = unit + end +end + +function unit_label:update_from_parent(parent,data,...) + local properties = self.properties + local data_name = properties.data_label_name or properties.name..'_data' + local element = parent[data_name] and parent[data_name].data_label or error('Data label is not a child of this element element',2) + local unit_element = parent[data_name..'_unit'] + + local caption, unit, tooltip = properties.data_format(self,element,data,...) + if caption then + element.caption = caption + end + if tooltip then + element.tooltip = tooltip + unit_element.tooltip = tooltip + end + if unit then + unit_element.caption = unit + end +end \ No newline at end of file From 2f1e22edd297ced59d344d680b36eee030e256ad Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Tue, 24 Sep 2019 19:28:22 +0100 Subject: [PATCH 23/26] Updated docs --- docs/addons/Advanced-Start.html | 3 +- docs/addons/Chat-Popups.html | 3 +- docs/addons/Chat-Reply.html | 3 +- docs/addons/Compilatron.html | 3 +- docs/addons/Damage-Popups.html | 3 +- docs/addons/Death-Logger.html | 3 +- docs/addons/Discord-Alerts.html | 3 +- docs/addons/Player-Colours.html | 3 +- docs/addons/Pollution-Grading.html | 3 +- docs/addons/Scorched-Earth.html | 3 +- docs/addons/Spawn-Area.html | 3 +- docs/commands/Admin-Chat.html | 3 +- docs/commands/Bonus.html | 3 +- docs/commands/Cheat-Mode.html | 3 +- docs/commands/Clear-Inventory.html | 3 +- docs/commands/Debug.html | 3 +- docs/commands/Find.html | 3 +- docs/commands/Help.html | 3 +- docs/commands/Home.html | 3 +- docs/commands/Interface.html | 3 +- docs/commands/Jail.html | 3 +- docs/commands/Kill.html | 3 +- docs/commands/Me.html | 3 +- docs/commands/Rainbow.html | 3 +- docs/commands/Repair.html | 3 +- docs/commands/Reports.html | 3 +- docs/commands/Roles.html | 3 +- docs/commands/Spawn.html | 3 +- docs/commands/Tag.html | 3 +- docs/commands/Teleport.html | 3 +- docs/commands/Warnings.html | 3 +- docs/configs/Advanced-Start.html | 3 +- docs/configs/Bonuses.html | 3 +- docs/configs/Chat-Reply.html | 3 +- docs/configs/Commands-Auth-Admin.html | 3 +- docs/configs/Commands-Auth-Roles.html | 3 +- .../Commands-Auth-Runtime-Disable.html | 3 +- docs/configs/Commands-Parse-Roles.html | 3 +- docs/configs/Commands-Parse.html | 3 +- docs/configs/Compilatron.html | 3 +- docs/configs/Death-Logger.html | 3 +- docs/configs/Discord-Alerts.html | 3 +- docs/configs/File-Loader.html | 3 +- docs/configs/Permission-Groups.html | 3 +- docs/configs/Player-List.html | 3 +- docs/configs/Pollution-Grading.html | 3 +- docs/configs/Popup-Messages.html | 3 +- docs/configs/Preset-Player-Colours.html | 3 +- docs/configs/Repair.html | 3 +- docs/configs/Rockets.html | 3 +- docs/configs/Roles.html | 3 +- docs/configs/Science.html | 3 +- docs/configs/Scorched-Earth.html | 3 +- docs/configs/Spawn-Area.html | 3 +- docs/configs/Tasks.html | 3 +- docs/configs/Warnings.html | 3 +- docs/configs/Warps.html | 3 +- docs/control/Jail.html | 3 +- docs/control/Production.html | 3 +- docs/control/Reports.html | 3 +- docs/control/Rockets.html | 3 +- docs/control/Tasks.html | 3 +- docs/control/Warnings.html | 3 +- docs/control/Warps.html | 3 +- docs/core/Commands.html | 3 +- docs/core/Common-Library.html | 3 +- docs/core/ExpStyle.html | 1366 +++++++++++++++++ docs/core/Gui.html | 201 ++- docs/core/Permissions-Groups.html | 3 +- docs/core/Roles.html | 3 +- docs/core/Store.html | 3 +- docs/core/Sudo.html | 3 +- docs/core/Toolbar.html | 3 +- docs/guis/Player-List.html | 3 +- docs/guis/Rocket-Info.html | 3 +- docs/guis/Science-Info.html | 3 +- docs/guis/Task-List.html | 3 +- docs/guis/Warps-List.html | 3 +- docs/index.html | 6 +- docs/modules/ExpStyle.html | 1343 ++++++++++++++++ docs/modules/control.html | 3 +- docs/modules/tesrt.html | 386 +++++ .../utils.alien_evolution_progress.html | 3 +- docs/modules/utils.core.html | 3 +- docs/modules/utils.debug.html | 3 +- docs/modules/utils.dump_env.html | 3 +- docs/modules/utils.event.html | 3 +- docs/modules/utils.event_core.html | 3 +- docs/modules/utils.math.html | 3 +- docs/modules/utils.recipe_locker.html | 3 +- docs/modules/utils.state_machine.html | 3 +- docs/modules/utils.table.html | 3 +- docs/modules/utils.task.html | 3 +- docs/modules/utils.timestamp.html | 3 +- docs/topics/license.html | 3 +- docs/topics/readme.md.html | 3 +- expcore/gui/core.lua | 39 + expcore/gui/styles/expstyle/alignment.lua | 9 +- expcore/gui/styles/expstyle/container.lua | 6 +- expcore/gui/styles/expstyle/data_label.lua | 18 +- expcore/gui/styles/expstyle/footer.lua | 6 +- expcore/gui/styles/expstyle/header.lua | 6 +- expcore/gui/styles/expstyle/index.lua | 19 +- expcore/gui/styles/expstyle/scroll_table.lua | 8 +- expcore/gui/styles/expstyle/time_label.lua | 2 +- expcore/gui/styles/expstyle/toggle_button.lua | 6 +- expcore/gui/styles/expstyle/unit_label.lua | 18 +- 107 files changed, 3585 insertions(+), 127 deletions(-) create mode 100644 docs/core/ExpStyle.html create mode 100644 docs/modules/ExpStyle.html create mode 100644 docs/modules/tesrt.html diff --git a/docs/addons/Advanced-Start.html b/docs/addons/Advanced-Start.html index 99ffc5b4..7eff9ff1 100644 --- a/docs/addons/Advanced-Start.html +++ b/docs/addons/Advanced-Start.html @@ -70,6 +70,7 @@ + @@ -349,7 +350,7 @@ generated by LDoc diff --git a/docs/addons/Chat-Popups.html b/docs/addons/Chat-Popups.html index b06d2672..b7f62e7a 100644 --- a/docs/addons/Chat-Popups.html +++ b/docs/addons/Chat-Popups.html @@ -70,6 +70,7 @@ + @@ -350,7 +351,7 @@ generated by LDoc diff --git a/docs/addons/Chat-Reply.html b/docs/addons/Chat-Reply.html index d45ea3c6..461b1085 100644 --- a/docs/addons/Chat-Reply.html +++ b/docs/addons/Chat-Reply.html @@ -70,6 +70,7 @@ + @@ -377,7 +378,7 @@ generated by LDoc diff --git a/docs/addons/Compilatron.html b/docs/addons/Compilatron.html index 6eb7d3fe..69e05991 100644 --- a/docs/addons/Compilatron.html +++ b/docs/addons/Compilatron.html @@ -71,6 +71,7 @@ + @@ -586,7 +587,7 @@ generated by LDoc diff --git a/docs/addons/Damage-Popups.html b/docs/addons/Damage-Popups.html index 95607966..b23f36ff 100644 --- a/docs/addons/Damage-Popups.html +++ b/docs/addons/Damage-Popups.html @@ -70,6 +70,7 @@ + @@ -350,7 +351,7 @@ generated by LDoc diff --git a/docs/addons/Death-Logger.html b/docs/addons/Death-Logger.html index 3ab0419f..970986a7 100644 --- a/docs/addons/Death-Logger.html +++ b/docs/addons/Death-Logger.html @@ -70,6 +70,7 @@ + @@ -405,7 +406,7 @@ generated by LDoc diff --git a/docs/addons/Discord-Alerts.html b/docs/addons/Discord-Alerts.html index 7e7065bc..ce786d86 100644 --- a/docs/addons/Discord-Alerts.html +++ b/docs/addons/Discord-Alerts.html @@ -70,6 +70,7 @@ + @@ -461,7 +462,7 @@ generated by LDoc diff --git a/docs/addons/Player-Colours.html b/docs/addons/Player-Colours.html index e2995d38..be4036df 100644 --- a/docs/addons/Player-Colours.html +++ b/docs/addons/Player-Colours.html @@ -70,6 +70,7 @@ + @@ -405,7 +406,7 @@ generated by LDoc diff --git a/docs/addons/Pollution-Grading.html b/docs/addons/Pollution-Grading.html index f257ab61..9c0a334d 100644 --- a/docs/addons/Pollution-Grading.html +++ b/docs/addons/Pollution-Grading.html @@ -70,6 +70,7 @@ + @@ -321,7 +322,7 @@ generated by LDoc diff --git a/docs/addons/Scorched-Earth.html b/docs/addons/Scorched-Earth.html index 6f6fc337..69be957b 100644 --- a/docs/addons/Scorched-Earth.html +++ b/docs/addons/Scorched-Earth.html @@ -70,6 +70,7 @@ + @@ -405,7 +406,7 @@ generated by LDoc diff --git a/docs/addons/Spawn-Area.html b/docs/addons/Spawn-Area.html index b2b11a94..7be892ff 100644 --- a/docs/addons/Spawn-Area.html +++ b/docs/addons/Spawn-Area.html @@ -70,6 +70,7 @@ + @@ -377,7 +378,7 @@ generated by LDoc diff --git a/docs/commands/Admin-Chat.html b/docs/commands/Admin-Chat.html index aafc0e4e..59344610 100644 --- a/docs/commands/Admin-Chat.html +++ b/docs/commands/Admin-Chat.html @@ -80,6 +80,7 @@ + @@ -389,7 +390,7 @@ generated by LDoc diff --git a/docs/commands/Bonus.html b/docs/commands/Bonus.html index 9db97cf7..fc584a2e 100644 --- a/docs/commands/Bonus.html +++ b/docs/commands/Bonus.html @@ -80,6 +80,7 @@ + @@ -501,7 +502,7 @@ generated by LDoc diff --git a/docs/commands/Cheat-Mode.html b/docs/commands/Cheat-Mode.html index 1e4cc198..7bafc60e 100644 --- a/docs/commands/Cheat-Mode.html +++ b/docs/commands/Cheat-Mode.html @@ -80,6 +80,7 @@ + @@ -362,7 +363,7 @@ generated by LDoc diff --git a/docs/commands/Clear-Inventory.html b/docs/commands/Clear-Inventory.html index 03e6c886..bf601ad5 100644 --- a/docs/commands/Clear-Inventory.html +++ b/docs/commands/Clear-Inventory.html @@ -80,6 +80,7 @@ + @@ -389,7 +390,7 @@ generated by LDoc diff --git a/docs/commands/Debug.html b/docs/commands/Debug.html index edfcdbb1..532efa99 100644 --- a/docs/commands/Debug.html +++ b/docs/commands/Debug.html @@ -80,6 +80,7 @@ + @@ -366,7 +367,7 @@ generated by LDoc diff --git a/docs/commands/Find.html b/docs/commands/Find.html index 586d8d34..17fec9b6 100644 --- a/docs/commands/Find.html +++ b/docs/commands/Find.html @@ -80,6 +80,7 @@ + @@ -361,7 +362,7 @@ generated by LDoc diff --git a/docs/commands/Help.html b/docs/commands/Help.html index 25a8f115..0122b470 100644 --- a/docs/commands/Help.html +++ b/docs/commands/Help.html @@ -80,6 +80,7 @@ + @@ -405,7 +406,7 @@ generated by LDoc diff --git a/docs/commands/Home.html b/docs/commands/Home.html index e88d2da7..793b64f4 100644 --- a/docs/commands/Home.html +++ b/docs/commands/Home.html @@ -80,6 +80,7 @@ + @@ -459,7 +460,7 @@ generated by LDoc diff --git a/docs/commands/Interface.html b/docs/commands/Interface.html index 2cf6091a..1e467b7b 100644 --- a/docs/commands/Interface.html +++ b/docs/commands/Interface.html @@ -80,6 +80,7 @@ + @@ -417,7 +418,7 @@ generated by LDoc diff --git a/docs/commands/Jail.html b/docs/commands/Jail.html index 1d41e418..238e0248 100644 --- a/docs/commands/Jail.html +++ b/docs/commands/Jail.html @@ -80,6 +80,7 @@ + @@ -612,7 +613,7 @@ generated by LDoc diff --git a/docs/commands/Kill.html b/docs/commands/Kill.html index 6b7e21d8..2f3a42d3 100644 --- a/docs/commands/Kill.html +++ b/docs/commands/Kill.html @@ -80,6 +80,7 @@ + @@ -390,7 +391,7 @@ generated by LDoc diff --git a/docs/commands/Me.html b/docs/commands/Me.html index a071c0c1..24b64a87 100644 --- a/docs/commands/Me.html +++ b/docs/commands/Me.html @@ -80,6 +80,7 @@ + @@ -361,7 +362,7 @@ generated by LDoc diff --git a/docs/commands/Rainbow.html b/docs/commands/Rainbow.html index dc82cc79..d921f1ef 100644 --- a/docs/commands/Rainbow.html +++ b/docs/commands/Rainbow.html @@ -80,6 +80,7 @@ + @@ -389,7 +390,7 @@ generated by LDoc diff --git a/docs/commands/Repair.html b/docs/commands/Repair.html index 29437a17..b6f8113b 100644 --- a/docs/commands/Repair.html +++ b/docs/commands/Repair.html @@ -79,6 +79,7 @@ + @@ -322,7 +323,7 @@ generated by LDoc diff --git a/docs/commands/Reports.html b/docs/commands/Reports.html index 65f2d825..d51b8af1 100644 --- a/docs/commands/Reports.html +++ b/docs/commands/Reports.html @@ -80,6 +80,7 @@ + @@ -586,7 +587,7 @@ generated by LDoc diff --git a/docs/commands/Roles.html b/docs/commands/Roles.html index e0d338c1..acf6971f 100644 --- a/docs/commands/Roles.html +++ b/docs/commands/Roles.html @@ -80,6 +80,7 @@ + @@ -558,7 +559,7 @@ generated by LDoc diff --git a/docs/commands/Spawn.html b/docs/commands/Spawn.html index f8ef4787..a940c112 100644 --- a/docs/commands/Spawn.html +++ b/docs/commands/Spawn.html @@ -80,6 +80,7 @@ + @@ -390,7 +391,7 @@ generated by LDoc diff --git a/docs/commands/Tag.html b/docs/commands/Tag.html index ac1dd9e2..bafc6f14 100644 --- a/docs/commands/Tag.html +++ b/docs/commands/Tag.html @@ -80,6 +80,7 @@ + @@ -444,7 +445,7 @@ generated by LDoc diff --git a/docs/commands/Teleport.html b/docs/commands/Teleport.html index efe6fe04..2afdbc08 100644 --- a/docs/commands/Teleport.html +++ b/docs/commands/Teleport.html @@ -80,6 +80,7 @@ + @@ -485,7 +486,7 @@ generated by LDoc diff --git a/docs/commands/Warnings.html b/docs/commands/Warnings.html index 4d8a95a6..adabade7 100644 --- a/docs/commands/Warnings.html +++ b/docs/commands/Warnings.html @@ -80,6 +80,7 @@ + @@ -570,7 +571,7 @@ generated by LDoc diff --git a/docs/configs/Advanced-Start.html b/docs/configs/Advanced-Start.html index 981debc7..3f5c06a8 100644 --- a/docs/configs/Advanced-Start.html +++ b/docs/configs/Advanced-Start.html @@ -85,6 +85,7 @@ + @@ -507,7 +508,7 @@ generated by LDoc diff --git a/docs/configs/Bonuses.html b/docs/configs/Bonuses.html index f42ddc42..e04bc9e6 100644 --- a/docs/configs/Bonuses.html +++ b/docs/configs/Bonuses.html @@ -77,6 +77,7 @@ + @@ -238,7 +239,7 @@ generated by LDoc diff --git a/docs/configs/Chat-Reply.html b/docs/configs/Chat-Reply.html index 37c2a42d..17898132 100644 --- a/docs/configs/Chat-Reply.html +++ b/docs/configs/Chat-Reply.html @@ -86,6 +86,7 @@ + @@ -486,7 +487,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Admin.html b/docs/configs/Commands-Auth-Admin.html index 48724dfc..e9d41e16 100644 --- a/docs/configs/Commands-Auth-Admin.html +++ b/docs/configs/Commands-Auth-Admin.html @@ -85,6 +85,7 @@ + @@ -295,7 +296,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Roles.html b/docs/configs/Commands-Auth-Roles.html index dc9614f2..ed8de360 100644 --- a/docs/configs/Commands-Auth-Roles.html +++ b/docs/configs/Commands-Auth-Roles.html @@ -85,6 +85,7 @@ + @@ -321,7 +322,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Runtime-Disable.html b/docs/configs/Commands-Auth-Runtime-Disable.html index c68b216a..b74be123 100644 --- a/docs/configs/Commands-Auth-Runtime-Disable.html +++ b/docs/configs/Commands-Auth-Runtime-Disable.html @@ -86,6 +86,7 @@ + @@ -443,7 +444,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Parse-Roles.html b/docs/configs/Commands-Parse-Roles.html index f432ec70..3cd75126 100644 --- a/docs/configs/Commands-Parse-Roles.html +++ b/docs/configs/Commands-Parse-Roles.html @@ -85,6 +85,7 @@ + @@ -355,7 +356,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Parse.html b/docs/configs/Commands-Parse.html index d3c7c295..454432dc 100644 --- a/docs/configs/Commands-Parse.html +++ b/docs/configs/Commands-Parse.html @@ -85,6 +85,7 @@ + @@ -339,7 +340,7 @@ see ./expcore/commands.lua for more details

    generated by LDoc diff --git a/docs/configs/Compilatron.html b/docs/configs/Compilatron.html index daeb3b5e..7f9f5bae 100644 --- a/docs/configs/Compilatron.html +++ b/docs/configs/Compilatron.html @@ -85,6 +85,7 @@ + @@ -355,7 +356,7 @@ generated by LDoc diff --git a/docs/configs/Death-Logger.html b/docs/configs/Death-Logger.html index 60c66414..3df18979 100644 --- a/docs/configs/Death-Logger.html +++ b/docs/configs/Death-Logger.html @@ -85,6 +85,7 @@ + @@ -417,7 +418,7 @@ generated by LDoc diff --git a/docs/configs/Discord-Alerts.html b/docs/configs/Discord-Alerts.html index 6cbff49c..307fba0d 100644 --- a/docs/configs/Discord-Alerts.html +++ b/docs/configs/Discord-Alerts.html @@ -77,6 +77,7 @@ + @@ -238,7 +239,7 @@ generated by LDoc diff --git a/docs/configs/File-Loader.html b/docs/configs/File-Loader.html index f83ad879..8dd2e4d2 100644 --- a/docs/configs/File-Loader.html +++ b/docs/configs/File-Loader.html @@ -77,6 +77,7 @@ + @@ -241,7 +242,7 @@ generated by LDoc diff --git a/docs/configs/Permission-Groups.html b/docs/configs/Permission-Groups.html index 8a41a0bb..c748144f 100644 --- a/docs/configs/Permission-Groups.html +++ b/docs/configs/Permission-Groups.html @@ -85,6 +85,7 @@ + @@ -296,7 +297,7 @@ generated by LDoc diff --git a/docs/configs/Player-List.html b/docs/configs/Player-List.html index abbd67bc..f416997b 100644 --- a/docs/configs/Player-List.html +++ b/docs/configs/Player-List.html @@ -86,6 +86,7 @@ + @@ -813,7 +814,7 @@ generated by LDoc diff --git a/docs/configs/Pollution-Grading.html b/docs/configs/Pollution-Grading.html index 55ce2814..bd47979f 100644 --- a/docs/configs/Pollution-Grading.html +++ b/docs/configs/Pollution-Grading.html @@ -85,6 +85,7 @@ + @@ -385,7 +386,7 @@ generated by LDoc diff --git a/docs/configs/Popup-Messages.html b/docs/configs/Popup-Messages.html index 2a98b0b2..8f84f684 100644 --- a/docs/configs/Popup-Messages.html +++ b/docs/configs/Popup-Messages.html @@ -85,6 +85,7 @@ + @@ -415,7 +416,7 @@ generated by LDoc diff --git a/docs/configs/Preset-Player-Colours.html b/docs/configs/Preset-Player-Colours.html index 5933597f..e49269ee 100644 --- a/docs/configs/Preset-Player-Colours.html +++ b/docs/configs/Preset-Player-Colours.html @@ -85,6 +85,7 @@ + @@ -325,7 +326,7 @@ generated by LDoc diff --git a/docs/configs/Repair.html b/docs/configs/Repair.html index 1c90a44e..ff7b2189 100644 --- a/docs/configs/Repair.html +++ b/docs/configs/Repair.html @@ -85,6 +85,7 @@ + @@ -415,7 +416,7 @@ generated by LDoc diff --git a/docs/configs/Rockets.html b/docs/configs/Rockets.html index 4478572f..15088476 100644 --- a/docs/configs/Rockets.html +++ b/docs/configs/Rockets.html @@ -85,6 +85,7 @@ + @@ -835,7 +836,7 @@ generated by LDoc diff --git a/docs/configs/Roles.html b/docs/configs/Roles.html index f503d293..6cc0063b 100644 --- a/docs/configs/Roles.html +++ b/docs/configs/Roles.html @@ -85,6 +85,7 @@ + @@ -293,7 +294,7 @@ generated by LDoc diff --git a/docs/configs/Science.html b/docs/configs/Science.html index fc973191..a85612a6 100644 --- a/docs/configs/Science.html +++ b/docs/configs/Science.html @@ -85,6 +85,7 @@ + @@ -355,7 +356,7 @@ generated by LDoc diff --git a/docs/configs/Scorched-Earth.html b/docs/configs/Scorched-Earth.html index b8e6ad74..f9888961 100644 --- a/docs/configs/Scorched-Earth.html +++ b/docs/configs/Scorched-Earth.html @@ -85,6 +85,7 @@ + @@ -389,7 +390,7 @@ generated by LDoc diff --git a/docs/configs/Spawn-Area.html b/docs/configs/Spawn-Area.html index 8ac57876..fec2403b 100644 --- a/docs/configs/Spawn-Area.html +++ b/docs/configs/Spawn-Area.html @@ -85,6 +85,7 @@ + @@ -745,7 +746,7 @@ generated by LDoc diff --git a/docs/configs/Tasks.html b/docs/configs/Tasks.html index 44ef1e74..43bdb919 100644 --- a/docs/configs/Tasks.html +++ b/docs/configs/Tasks.html @@ -85,6 +85,7 @@ + @@ -385,7 +386,7 @@ generated by LDoc diff --git a/docs/configs/Warnings.html b/docs/configs/Warnings.html index 1a874b76..d5b14073 100644 --- a/docs/configs/Warnings.html +++ b/docs/configs/Warnings.html @@ -85,6 +85,7 @@ + @@ -356,7 +357,7 @@ generated by LDoc diff --git a/docs/configs/Warps.html b/docs/configs/Warps.html index a8b05959..3fb7f77f 100644 --- a/docs/configs/Warps.html +++ b/docs/configs/Warps.html @@ -85,6 +85,7 @@ + @@ -685,7 +686,7 @@ generated by LDoc diff --git a/docs/control/Jail.html b/docs/control/Jail.html index 4e10b7c8..a6acc5ce 100644 --- a/docs/control/Jail.html +++ b/docs/control/Jail.html @@ -69,6 +69,7 @@ + @@ -1209,7 +1210,7 @@ generated by LDoc diff --git a/docs/control/Production.html b/docs/control/Production.html index 115f41c1..53874e4d 100644 --- a/docs/control/Production.html +++ b/docs/control/Production.html @@ -69,6 +69,7 @@ + @@ -1330,7 +1331,7 @@ generated by LDoc diff --git a/docs/control/Reports.html b/docs/control/Reports.html index f8c8e04b..67fb2864 100644 --- a/docs/control/Reports.html +++ b/docs/control/Reports.html @@ -69,6 +69,7 @@ + @@ -1111,7 +1112,7 @@ generated by LDoc diff --git a/docs/control/Rockets.html b/docs/control/Rockets.html index 9c23440e..4d560f6f 100644 --- a/docs/control/Rockets.html +++ b/docs/control/Rockets.html @@ -68,6 +68,7 @@ + @@ -985,7 +986,7 @@ generated by LDoc diff --git a/docs/control/Tasks.html b/docs/control/Tasks.html index b09d725e..f37fc0d6 100644 --- a/docs/control/Tasks.html +++ b/docs/control/Tasks.html @@ -68,6 +68,7 @@ + @@ -1040,7 +1041,7 @@ generated by LDoc diff --git a/docs/control/Warnings.html b/docs/control/Warnings.html index e2f72325..38998a09 100644 --- a/docs/control/Warnings.html +++ b/docs/control/Warnings.html @@ -68,6 +68,7 @@ + @@ -1466,7 +1467,7 @@ generated by LDoc diff --git a/docs/control/Warps.html b/docs/control/Warps.html index 1a650f00..fca4cb74 100644 --- a/docs/control/Warps.html +++ b/docs/control/Warps.html @@ -69,6 +69,7 @@ + @@ -1414,7 +1415,7 @@ generated by LDoc diff --git a/docs/core/Commands.html b/docs/core/Commands.html index 37d28eb4..590f6080 100644 --- a/docs/core/Commands.html +++ b/docs/core/Commands.html @@ -57,6 +57,7 @@ + @@ -1973,7 +1974,7 @@ generated by LDoc diff --git a/docs/core/Common-Library.html b/docs/core/Common-Library.html index e4c5c30d..6f6e5c02 100644 --- a/docs/core/Common-Library.html +++ b/docs/core/Common-Library.html @@ -53,6 +53,7 @@ + @@ -2747,7 +2748,7 @@ Common.table_insert(tbl,50,tbl2) generated by LDoc diff --git a/docs/core/ExpStyle.html b/docs/core/ExpStyle.html new file mode 100644 index 00000000..f0baf989 --- /dev/null +++ b/docs/core/ExpStyle.html @@ -0,0 +1,1366 @@ + + + + + + + + ExpStyle core + + + + + + + +
    +
    + + + + + + + +
    + + + + + + + + +

    ExpStyle core

    +

    Core Module - ExpStyle

    +

    + + + + + + + + + + + +
    get_keys(location) Gets all non nil keys at a location, keys can be added and removed during runtime - this is similar to Store.get but will always return a table even if it is empty
    is_registered(location)
    + +

    Dependencies

    + + + + + + + + + + + + + + + + + + + + + + +
    expcore.gui
    gui.concept.frame
    gui.concept.flow
    gui.concept.table
    gui.concept.scroll
    expcore.common
    + + +

    Elements

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    alignmentA flow which can be used to align text and other elements
    containerA container frame that can be used to add a boader around your content
    data_labelA label pair which has a static label and a data label which can be changed
    footerA frame that acts as a footer to a section of content
    headerA frame that acts as a header to a section of content
    scroll_tableA table that is inside a vertical scroll area
    time_labelA label that show time in a nice, user friendly way
    toggle_buttonA button that will toggle its caption each time it is pressed
    unit_labelA label triplet which has a static label, a data label which can be changed, and a unit label
    + + +

    Functions

    + + + + + + + + + + + + + + + + + + + + + + + + +
    data_label:update_data_element(element, data)Updates the caption and tooltip of the data label using the data format function
    data_label:update_from_parent(parent, data)Updates the caption and tooltip of the data label using the data format function, given the parent of the data label
    time_label:update_time(element, time)Updates the time that is on a label
    unit_label:update_data_element(element, data)Updates the caption and tooltip and unit of the data label using the data format function
    unit_label:update_from_parent(parent, data)Updates the caption and tooltip and unit of the unit label using the data format function, given the parent of the unit label
    + + +
    + + +

    Dependencies

    +
    +
    +
    +
    + # + expcore.gui +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + gui.concept.frame +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + gui.concept.flow +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + gui.concept.table +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + gui.concept.scroll +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.common +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +

    Elements

    +
    +
    +
    +
    + # + alignment +
    +
    +
    +
    + +

    A flow which can be used to align text and other elements

    +

    + + + + + + + + + + See also: + + + + + Usage: +
    -- Concept Structure
    +-- Root
    +--> [alignment] - the alignment area
    +Gui.new_concept('alignment')
    +:set_horizontal_align('center')
    + + +
    +
    +
    +
    + # + container +
    +
    +
    +
    + +

    A container frame that can be used to add a boader around your content

    +

    + + + + + + + + + + See also: + + + + + Usage: +
    -- Concept Structure
    +-- Root
    +--> [container] - the outer frame
    +-->> container - the content area
    +Gui.new_concept('container')
    + + +
    +
    +
    +
    + # + data_label +
    +
    +
    +
    + +

    A label pair which has a static label and a data label which can be changed

    +

    + + + + + + + + + + See also: + + + + + Usage: +
    -- Concept Structure
    +-- Root
    +--> [data_label] - the static label
    +--> [properties.data_name] - the data label which can be updated
    +Gui.new_concept('data_label')
    +:set_data_label_name('game_ticks')
    +:set_data_caption('0')
    +:set_data_format(function(concept,element,data,...)
    +    -- This is used with update_data_element and update_from_parent
    +    local caption = tostirng('data')
    +    local tooltip = 'This game has beeing running for: '..caption..' ticks'
    +    return caption, tooltip
    +end)
    + + +
    +
    +
    +
    + # + footer +
    +
    +
    +
    + +

    A frame that acts as a footer to a section of content

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + tooltip + + : + + (string) + + the tooltip to show on the title + +
    • + + +
    + + + + + + + + + See also: + + + + + Usage: +
    -- Concept Structure
    +-- Root
    +--> [footer] - the footer frame
    +-->> footer_caption - the lable with the title in it
    +-->> footer_content - the area to contain butons
    +Gui.new_concept('footer')
    +:set_title('Example Footer')
    + + +
    +
    +
    +
    + # + header +
    +
    +
    +
    + +

    A frame that acts as a header to a section of content

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + tooltip + + : + + (string) + + the tooltip to show on the title + +
    • + + +
    + + + + + + + + + See also: + + + + + Usage: +
    -- Concept Structure
    +-- Root
    +--> [header] - the header frame
    +-->> header_caption - the lable with the title in it
    +-->> header_content - the area to contain butons
    +Gui.new_concept('header')
    +:set_title('Example Header')
    + + +
    +
    +
    +
    + # + scroll_table +
    +
    +
    +
    + +

    A table that is inside a vertical scroll area

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + hight + + : + + (number) + + the max hight of the scroll area + +
    • + + +
    + + + + + + + + + See also: + + + + + Usage: +
    -- Concept Structure
    +-- Root
    +--> [scroll_table] - the scroll area
    +-->> table - the table area
    +Gui.new_concept('scroll_table')
    +:set_height(200)
    +:set_column_count(2)
    + + +
    +
    +
    +
    + # + time_label +
    +
    +
    +
    + +

    A label that show time in a nice, user friendly way

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + time + + : + + (number) + + the time to display in tick + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Concept Structure
    +-- Root
    +--> [time_label] - the label with the time
    +local time_label =
    +Gui.new_concept('time_label')
    +:set_use_hours(true)
    +:set_time(game.tick)
    +
    +time_label:update_time(element,game.tick)
    + + +
    +
    +
    +
    + # + toggle_button +
    +
    +
    +
    + +

    A button that will toggle its caption each time it is pressed

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + alt_caption + + : + + (string) + + the caption to show on the button in its true state + +
    • + + + + + +
    • + + alt_tooltip + + : + + (string) + + the tooltip to show on the button in its true state + +
    • + + +
    + + + + + + + + + See also: + + + + + Usage: +
    -- Concept Structure
    +-- Root
    +--> [toggle_button] - the header button
    +Gui.new_concept('toggle_button')
    +:set_caption('<')
    +:set_tooltip('Press to close.')
    +:set_alt_caption('>')
    +:set_alt_tooltip('Press to open.')
    +:on_click(function(event)
    +    local state = event.state and 'close' or 'open'
    +    event.player.print('Toggle button is now: '..state)
    +end)
    + + +
    +
    +
    +
    + # + unit_label +
    +
    +
    +
    + +

    A label triplet which has a static label, a data label which can be changed, and a unit label

    +

    + + + + + + + + + + See also: + + + + + Usage: +
    -- Concept Structure
    +-- Root
    +--> [unit_label] - the static label
    +--> [properties.data_name] - the data label which can be updated
    +--> [properties.data_name..'_unit'] - the data label unit which can be updated
    +Gui.new_concept('unit_label')
    +:set_data_label_name('game_ticks')
    +:set_data_caption('0')
    +:set_data_unit('ticks')
    +:set_data_format(function(concept,element,data,...)
    +    -- This is used with update_data_element and update_from_parent
    +    local caption = tostirng(data)
    +    local unit = data > 1 and 'ticks' or 'tick'
    +    local tooltip = 'This game has beeing running for: '..caption..' ticks'
    +    return caption, unit, tooltip
    +end)
    + + +
    +
    +

    Functions

    +
    +
    +
    +
    + # + data_label:update_data_element(element, data) +
    +
    +
    +
    + +

    Updates the caption and tooltip of the data label using the data format function

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the data label element that you want to update + +
    • + + + + + +
    • + + data + + : + + (any) + + the data that you want to pass to the format function + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Updating the data to the current game tick
    +data_label:update_data_element(element,game.tick)
    + + +
    +
    +
    +
    + # + data_label:update_from_parent(parent, data) +
    +
    +
    +
    + +

    Updates the caption and tooltip of the data label using the data format function, given the parent of the data label

    +

    + + + Parameters: + +
      + + + + + +
    • + + parent + + : + + (LuaGuiElement) + + the parent element to the data label element that you want to update + +
    • + + + + + +
    • + + data + + : + + (any) + + the data that you want to pass to the format function + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Updating the data to the current game tick
    +data_label:update_from_parent(parent,game.tick)
    + + +
    +
    +
    +
    + # + time_label:update_time(element, time) +
    +
    +
    +
    + +

    Updates the time that is on a label

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the label that you want to update + +
    • + + + + + +
    • + + time + + : + + (number) + + the number of tick you want it to show + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Update the time to show game time
    +time_label:update_time(element,game.time)
    + + +
    +
    +
    +
    + # + unit_label:update_data_element(element, data) +
    +
    +
    +
    + +

    Updates the caption and tooltip and unit of the data label using the data format function

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the unit label element that you want to update + +
    • + + + + + +
    • + + data + + : + + (any) + + the data that you want to pass to the format function + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Updating the data to the current game tick
    +unit_label:update_data_element(element,game.tick)
    + + +
    +
    +
    +
    + # + unit_label:update_from_parent(parent, data) +
    +
    +
    +
    + +

    Updates the caption and tooltip and unit of the unit label using the data format function, given the parent of the unit label

    +

    + + + Parameters: + +
      + + + + + +
    • + + parent + + : + + (LuaGuiElement) + + the parent element to the unit label element that you want to update + +
    • + + + + + +
    • + + data + + : + + (any) + + the data that you want to pass to the format function + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Updating the data to the current game tick
    +unit_label:update_from_parent(parent,game.tick)
    + + +
    +
    + + + + + + + + + + diff --git a/docs/core/Gui.html b/docs/core/Gui.html index 67827252..9524e47e 100644 --- a/docs/core/Gui.html +++ b/docs/core/Gui.html @@ -62,6 +62,7 @@ + @@ -353,7 +354,7 @@ Gui.new_concept('button') -- W Grey semi-transparent boxes that contain other elements. - frame + label A piece of text. @@ -485,6 +486,14 @@ Gui.new_concept('button') -- W Destroies and element if it is valid + find(element, ...) + Finds and returns a gui element if it is valid from a long chain of element names or concepts + + + exists + Checks if a gui element exists or not, returns it if found else the path where it failed + + toggle_enabled(element) Toggles the enabled state of an element @@ -565,7 +574,7 @@ Gui.new_concept('button') -- W Used to define how the concept is turned into an ingame element or "instance" as we may refer to them - Prototype:draw(parent_element) + Prototype:draw(parent_element[, override_name]) Calls all the draw functions in order to create this concept in game; will also store and sync the instance if stores are used @@ -1342,8 +1351,8 @@ Gui.new_concept('frame')
    - # - frame + # + label
    @@ -3488,6 +3497,169 @@ Gui.get_concept('button') Gui.destroy(element) +
    +
    +
    +
    + # + find(element, ...) +
    +
    +
    +
    + +

    Finds and returns a gui element if it is valid from a long chain of element names or concepts

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the root element to start checking from + +
    • + + + + + +
    • + + ... + + : + + (string or table) + + element names or element concepts that point to your element + +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + if the element was found, failed +
    • +
    • + (string) + the path of the element that the search stoped at +
    • +
    +
    Or
    +
      +
    • + (boolean) + if the element was found, found +
    • +
    • + (LuaGuiElement) + the element that was found +
    • +
    + + + + + + + + Usage: +
    -- Getting the center gui
    +local exists, center = Gui.find(player,'gui','center')
    + + +
    +
    +
    +
    + # + exists +
    +
    +
    +
    + +

    Checks if a gui element exists or not, returns it if found else the path where it failed

    +

    + + + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the root element to start checking from + +
    • + + + + + +
    • + + ... + + : + + (string or table) + + element names or element concepts that point to your element + +
    • + + +
    + + + + + + + + + See also: + + + + + Usage: +
    -- Getting the center gui
    +local exists, center = Gui.exists(player,'gui','center')
    + +
    @@ -4686,7 +4858,7 @@ Gui.get_concept('Button')
    # - Prototype:draw(parent_element) + Prototype:draw(parent_element[, override_name])
    @@ -4717,6 +4889,23 @@ Gui.get_concept('Button')
  • + + + +
  • + + override_name + + : + + (string) + + when given this will be the name of the element rather than the concept id + + (optional) +
  • + + @@ -5611,7 +5800,7 @@ Gui.get_concept('CustomButton') generated by LDoc diff --git a/docs/core/Permissions-Groups.html b/docs/core/Permissions-Groups.html index 6095d508..14d8fd23 100644 --- a/docs/core/Permissions-Groups.html +++ b/docs/core/Permissions-Groups.html @@ -56,6 +56,7 @@ + @@ -1433,7 +1434,7 @@ generated by LDoc diff --git a/docs/core/Roles.html b/docs/core/Roles.html index 3e6a7fa4..dbd23fa6 100644 --- a/docs/core/Roles.html +++ b/docs/core/Roles.html @@ -60,6 +60,7 @@ + @@ -3153,7 +3154,7 @@ generated by LDoc diff --git a/docs/core/Store.html b/docs/core/Store.html index 6fd3ab97..3b0822b1 100644 --- a/docs/core/Store.html +++ b/docs/core/Store.html @@ -53,6 +53,7 @@ + @@ -1204,7 +1205,7 @@ this is similar to Store.get but will always return a table even if it is empty< generated by LDoc diff --git a/docs/core/Sudo.html b/docs/core/Sudo.html index 9f4c83f9..1e719894 100644 --- a/docs/core/Sudo.html +++ b/docs/core/Sudo.html @@ -53,6 +53,7 @@ + @@ -545,7 +546,7 @@ generated by LDoc diff --git a/docs/core/Toolbar.html b/docs/core/Toolbar.html index 2db838da..848922b5 100644 --- a/docs/core/Toolbar.html +++ b/docs/core/Toolbar.html @@ -56,6 +56,7 @@ + @@ -1660,7 +1661,7 @@ Gui.new_concept('toolbar-frame') generated by LDoc diff --git a/docs/guis/Player-List.html b/docs/guis/Player-List.html index e80e3022..5afefbbf 100644 --- a/docs/guis/Player-List.html +++ b/docs/guis/Player-List.html @@ -65,6 +65,7 @@ + @@ -627,7 +628,7 @@ generated by LDoc diff --git a/docs/guis/Rocket-Info.html b/docs/guis/Rocket-Info.html index 65b15a82..8804e5c6 100644 --- a/docs/guis/Rocket-Info.html +++ b/docs/guis/Rocket-Info.html @@ -65,6 +65,7 @@ + @@ -630,7 +631,7 @@ generated by LDoc diff --git a/docs/guis/Science-Info.html b/docs/guis/Science-Info.html index 567731c0..3a06ef3e 100644 --- a/docs/guis/Science-Info.html +++ b/docs/guis/Science-Info.html @@ -65,6 +65,7 @@ + @@ -450,7 +451,7 @@ generated by LDoc diff --git a/docs/guis/Task-List.html b/docs/guis/Task-List.html index 28d1ef22..8178d793 100644 --- a/docs/guis/Task-List.html +++ b/docs/guis/Task-List.html @@ -65,6 +65,7 @@ + @@ -633,7 +634,7 @@ generated by LDoc diff --git a/docs/guis/Warps-List.html b/docs/guis/Warps-List.html index 91e2640e..c267b5c2 100644 --- a/docs/guis/Warps-List.html +++ b/docs/guis/Warps-List.html @@ -65,6 +65,7 @@ + @@ -838,7 +839,7 @@ generated by LDoc diff --git a/docs/index.html b/docs/index.html index a2c82dd5..e1859d62 100644 --- a/docs/index.html +++ b/docs/index.html @@ -59,6 +59,10 @@ Core Module - Gui + ExpStyle + Core Module - ExpStyle + + Permissions-Groups Core Module - Permission Groups - Permission group making for factorio so you never have to make one by hand again @@ -514,7 +518,7 @@ see ./expcore/commands.lua for more details generated by LDoc diff --git a/docs/modules/ExpStyle.html b/docs/modules/ExpStyle.html new file mode 100644 index 00000000..fede875a --- /dev/null +++ b/docs/modules/ExpStyle.html @@ -0,0 +1,1343 @@ + + + + + + + + ExpStyle module + + + + + + + +
    +
    + + + + + + + +
    + + + + + + + + +

    ExpStyle module

    +

    Core Module - ExpStyle

    +

    + + + + + + + + + + + + + +

    Dependencies

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    expcore.gui
    gui.concept.frame
    expcore.gui
    gui.concept.frame
    expcore.gui
    gui.concept.table
    expcore.gui
    gui.concept.table
    expcore.gui
    gui.concept.table
    gui.concept.scroll
    expcore.gui
    expcore.common
    expcore.gui
    gui.concept.table
    expcore.gui
    gui.concept.frame
    + + +

    Elements

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    containerA container frame that can be used to add a boader around your content
    data_labelA label pair which has a static label and a data label which can be changed
    footerA frame that acts as a footer to a section of content
    headerA frame that acts as a header to a section of content
    scroll_tableA table that is inside a vertical scroll area
    time_labelA label that show time in a nice, user friendly way
    toggle_buttonA button that will toggle its caption each time it is pressed
    unit_labelA label triplet which has a static label, a data label which can be changed, and a unit label
    + + +

    Functions

    + + + + + + + + +
    time_label:update_time(element, time)Updates the time that is on a label
    + + +
    + + +

    Dependencies

    +
    +
    +
    +
    + # + expcore.gui +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + gui.concept.frame +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.gui +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + gui.concept.frame +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.gui +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + gui.concept.table +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.gui +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + gui.concept.table +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.gui +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + gui.concept.table +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + gui.concept.scroll +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.gui +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.common +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.gui +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + gui.concept.table +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.gui +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + gui.concept.frame +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +

    Elements

    +
    +
    +
    +
    + # + container +
    +
    +
    +
    + +

    A container frame that can be used to add a boader around your content

    +

    + + + + + + + + + + See also: + + + + + Usage: +
    -- Concept Structure
    +-- Root
    +--> [container] - the outer frame
    +-->> container - the content area
    +Gui.new_concept('container')
    + + +
    +
    +
    +
    + # + data_label +
    +
    +
    +
    + +

    A label pair which has a static label and a data label which can be changed

    +

    + + + + + + + + + + See also: + + + + + Usage: +
    -- Concept Structure
    +-- Root
    +--> [data_label] - the static label
    +--> [properties.data_name] - the data label which can be updated
    +Gui.new_concept('data_label')
    +:set_data_label_name('game_ticks')
    +:set_data_caption('0')
    +:set_data_format(function(concept,element,data,...)
    +    -- This is used with update_data_element and update_from_parent
    +    local caption = tostirng('data')
    +    local tooltip = 'This game has beeing running for: '..caption..' ticks'
    +    return caption, tooltip
    +end)
    + + +
    +
    +
    +
    + # + footer +
    +
    +
    +
    + +

    A frame that acts as a footer to a section of content

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + tooltip + + : + + (string) + + the tooltip to show on the title + +
    • + + +
    + + + + + + + + + See also: + + + + + Usage: +
    -- Concept Structure
    +-- Root
    +--> [footer] - the footer frame
    +-->> footer_caption - the lable with the title in it
    +-->> footer_content - the area to contain butons
    +Gui.new_concept('footer')
    +:set_title('Example Footer')
    + + +
    +
    +
    +
    + # + header +
    +
    +
    +
    + +

    A frame that acts as a header to a section of content

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + tooltip + + : + + (string) + + the tooltip to show on the title + +
    • + + +
    + + + + + + + + + See also: + + + + + Usage: +
    -- Concept Structure
    +-- Root
    +--> [header] - the header frame
    +-->> header_caption - the lable with the title in it
    +-->> header_content - the area to contain butons
    +Gui.new_concept('header')
    +:set_title('Example Header')
    + + +
    +
    +
    +
    + # + scroll_table +
    +
    +
    +
    + +

    A table that is inside a vertical scroll area

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + hight + + : + + (number) + + the max hight of the scroll area + +
    • + + +
    + + + + + + + + + See also: + + + + + Usage: +
    -- Concept Structure
    +-- Root
    +--> [scroll_table] - the scroll area
    +-->> table - the table area
    +Gui.new_concept('scroll_table')
    +:set_height(200)
    +:set_column_count(2)
    + + +
    +
    +
    +
    + # + time_label +
    +
    +
    +
    + +

    A label that show time in a nice, user friendly way

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + time + + : + + (number) + + the time to display in tick + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Concept Structure
    +-- Root
    +--> [time_label] - the label with the time
    +local time_label =
    +Gui.new_concept('time_label')
    +:set_use_hours(true)
    +:set_time(game.tick)
    +
    +time_label:update_time(element,game.tick)
    + + +
    +
    +
    +
    + # + toggle_button +
    +
    +
    +
    + +

    A button that will toggle its caption each time it is pressed

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + alt_caption + + : + + (string) + + the caption to show on the button in its true state + +
    • + + + + + +
    • + + alt_tooltip + + : + + (string) + + the tooltip to show on the button in its true state + +
    • + + +
    + + + + + + + + + See also: + + + + + Usage: +
    -- Concept Structure
    +-- Root
    +--> [toggle_button] - the header button
    +Gui.new_concept('toggle_button')
    +:set_caption('<')
    +:set_tooltip('Press to close.')
    +:set_alt_caption('>')
    +:set_alt_tooltip('Press to open.')
    +:on_click(function(event)
    +    local state = event.state and 'close' or 'open'
    +    event.player.print('Toggle button is now: '..state)
    +end)
    + + +
    +
    +
    +
    + # + unit_label +
    +
    +
    +
    + +

    A label triplet which has a static label, a data label which can be changed, and a unit label

    +

    + + + + + + + + + + See also: + + + + + Usage: +
    -- Concept Structure
    +-- Root
    +--> [unit_label] - the static label
    +--> [properties.data_name] - the data label which can be updated
    +--> [properties.data_name..'_unit'] - the data label unit which can be updated
    +Gui.new_concept('unit_label')
    +:set_data_label_name('game_ticks')
    +:set_data_caption('0')
    +:set_data_unit('ticks')
    +:set_data_format(function(concept,element,data,...)
    +    -- This is used with update_data_element and update_from_parent
    +    local caption = tostirng(data)
    +    local unit = data > 1 and 'ticks' or 'tick'
    +    local tooltip = 'This game has beeing running for: '..caption..' ticks'
    +    return caption, unit, tooltip
    +end)
    + + +
    +
    +

    Functions

    +
    +
    +
    +
    + # + time_label:update_time(element, time) +
    +
    +
    +
    + +

    Updates the time that is on a label

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the label that you want to update + +
    • + + + + + +
    • + + time + + : + + (number) + + the number of tick you want it to show + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Update the time to show game time
    +time_label:update_time(element,game.time)
    + + +
    +
    + + + +
    +
    +
    + + + + diff --git a/docs/modules/control.html b/docs/modules/control.html index 4fb5d84e..96f093f1 100644 --- a/docs/modules/control.html +++ b/docs/modules/control.html @@ -72,6 +72,7 @@ + @@ -352,7 +353,7 @@ generated by LDoc diff --git a/docs/modules/tesrt.html b/docs/modules/tesrt.html new file mode 100644 index 00000000..52c8b244 --- /dev/null +++ b/docs/modules/tesrt.html @@ -0,0 +1,386 @@ + + + + + + + + tesrt module + + + + + + + +
    +
    + + + + + + + +
    + + + + + + + + +

    tesrt module

    +

    Core Module - ExpStyle

    +

    + + + + + + + + + + + + + +

    Dependencies

    + + + + + + + + + + +
    expcore.gui
    gui.concept.flow
    + + +

    Elements

    + + + + + + + + +
    alignmentA flow which can be used to align text and other elements
    + + +
    + + +

    Dependencies

    +
    +
    +
    +
    + # + expcore.gui +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + gui.concept.flow +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +

    Elements

    +
    +
    +
    +
    + # + alignment +
    +
    +
    +
    + +

    A flow which can be used to align text and other elements

    +

    + + + + + + + + + + See also: + + + + + Usage: +
    -- Concept Structure
    +-- Root
    +--> [alignment] - the alignment area
    +Gui.new_concept('alignment')
    +:set_horizontal_align('center')
    + + +
    +
    + + + +
    +
    +
    + + + + diff --git a/docs/modules/utils.alien_evolution_progress.html b/docs/modules/utils.alien_evolution_progress.html index de092da3..d8b98af4 100644 --- a/docs/modules/utils.alien_evolution_progress.html +++ b/docs/modules/utils.alien_evolution_progress.html @@ -73,6 +73,7 @@ + @@ -420,7 +421,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 7087a571..8d316e12 100644 --- a/docs/modules/utils.core.html +++ b/docs/modules/utils.core.html @@ -74,6 +74,7 @@ + @@ -1165,7 +1166,7 @@ generated by LDoc diff --git a/docs/modules/utils.debug.html b/docs/modules/utils.debug.html index 1d9e7fdc..40c5610d 100644 --- a/docs/modules/utils.debug.html +++ b/docs/modules/utils.debug.html @@ -72,6 +72,7 @@ + @@ -655,7 +656,7 @@ generated by LDoc diff --git a/docs/modules/utils.dump_env.html b/docs/modules/utils.dump_env.html index c4da3636..02727b03 100644 --- a/docs/modules/utils.dump_env.html +++ b/docs/modules/utils.dump_env.html @@ -72,6 +72,7 @@ + @@ -324,7 +325,7 @@ generated by LDoc diff --git a/docs/modules/utils.event.html b/docs/modules/utils.event.html index bc1f5698..dfa11db4 100644 --- a/docs/modules/utils.event.html +++ b/docs/modules/utils.event.html @@ -73,6 +73,7 @@ + @@ -1293,7 +1294,7 @@ generated by LDoc diff --git a/docs/modules/utils.event_core.html b/docs/modules/utils.event_core.html index b53537ea..38eff51c 100644 --- a/docs/modules/utils.event_core.html +++ b/docs/modules/utils.event_core.html @@ -72,6 +72,7 @@ + @@ -435,7 +436,7 @@ generated by LDoc diff --git a/docs/modules/utils.math.html b/docs/modules/utils.math.html index b74b9490..da148586 100644 --- a/docs/modules/utils.math.html +++ b/docs/modules/utils.math.html @@ -72,6 +72,7 @@ + @@ -354,7 +355,7 @@ generated by LDoc diff --git a/docs/modules/utils.recipe_locker.html b/docs/modules/utils.recipe_locker.html index 59449178..e422551c 100644 --- a/docs/modules/utils.recipe_locker.html +++ b/docs/modules/utils.recipe_locker.html @@ -73,6 +73,7 @@ + @@ -442,7 +443,7 @@ generated by LDoc diff --git a/docs/modules/utils.state_machine.html b/docs/modules/utils.state_machine.html index 9a60f448..daa620a5 100644 --- a/docs/modules/utils.state_machine.html +++ b/docs/modules/utils.state_machine.html @@ -73,6 +73,7 @@ + @@ -753,7 +754,7 @@ generated by LDoc diff --git a/docs/modules/utils.table.html b/docs/modules/utils.table.html index eaec6291..b90becff 100644 --- a/docs/modules/utils.table.html +++ b/docs/modules/utils.table.html @@ -74,6 +74,7 @@ + @@ -1419,7 +1420,7 @@ generated by LDoc diff --git a/docs/modules/utils.task.html b/docs/modules/utils.task.html index e853536f..db13570d 100644 --- a/docs/modules/utils.task.html +++ b/docs/modules/utils.task.html @@ -73,6 +73,7 @@ + @@ -652,7 +653,7 @@ generated by LDoc diff --git a/docs/modules/utils.timestamp.html b/docs/modules/utils.timestamp.html index 97e2409e..ef9b3b28 100644 --- a/docs/modules/utils.timestamp.html +++ b/docs/modules/utils.timestamp.html @@ -72,6 +72,7 @@ + @@ -443,7 +444,7 @@ generated by LDoc diff --git a/docs/topics/license.html b/docs/topics/license.html index 219ecba4..2268d7de 100644 --- a/docs/topics/license.html +++ b/docs/topics/license.html @@ -53,6 +53,7 @@ + @@ -790,7 +791,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 24b2d167..b5eed503 100644 --- a/docs/topics/readme.md.html +++ b/docs/topics/readme.md.html @@ -53,6 +53,7 @@ + @@ -334,7 +335,7 @@ generated by LDoc diff --git a/expcore/gui/core.lua b/expcore/gui/core.lua index 5365d54a..23b13a5b 100644 --- a/expcore/gui/core.lua +++ b/expcore/gui/core.lua @@ -139,6 +139,45 @@ function Gui.destroy(element) return false end +--[[-- Finds and returns a gui element if it is valid from a long chain of element names or concepts +@tparam LuaGuiElement element the root element to start checking from +@tparam ?string|table ... element names or element concepts that point to your element +@treturn[1] boolean if the element was found, failed +@treturn[1] string the path of the element that the search stoped at +@treturn[2] boolean if the element was found, found +@treturn[2] LuaGuiElement the element that was found +@usage-- Getting the center gui +local exists, center = Gui.find(player,'gui','center') +]] +function Gui.find(element,...) + local path = tostring(element.name) + for _,next_element_name in pairs{...} do + if type(next_element_name) == 'table' then + next_element_name = next_element_name.name + end + + element = element[next_element_name] + path = path..'.'..tostring(next_element_name) + if not Gui.valid(element) then + return false, path + end + end + return true, element +end + +--[[-- Checks if a gui element exists or not, returns it if found else the path where it failed +@see Gui.find +@tparam LuaGuiElement element the root element to start checking from +@tparam ?string|table ... element names or element concepts that point to your element +@treturn[1] boolean if the element was found, failed +@treturn[1] string the path of the element that the search stoped at +@treturn[2] boolean if the element was found, found +@treturn[2] LuaGuiElement the element that was found +@usage-- Getting the center gui +local exists, center = Gui.exists(player,'gui','center') +]] +Gui.exists = Gui.find + --[[-- Toggles the enabled state of an element @tparam LuaGuiElement element the element that you want to toggle the enabled state of @treturn boolean the new enabled state of the element diff --git a/expcore/gui/styles/expstyle/alignment.lua b/expcore/gui/styles/expstyle/alignment.lua index 23477684..80c44f8a 100644 --- a/expcore/gui/styles/expstyle/alignment.lua +++ b/expcore/gui/styles/expstyle/alignment.lua @@ -1,13 +1,14 @@ --[[-- Core Module - ExpStyle - @module ExpStyle + @core ExpStyle + @alias expstyle ]] -local Gui = require 'expcore.gui' --- @dep expcore.gui +local Gui = require 'expcore.gui' -- @dep expcore.gui -Gui.require_concept 'flow' --- @dep gui.concept.flow +Gui.require_concept 'flow' -- @dep gui.concept.flow --[[-- A flow which can be used to align text and other elements -@see flow +@see Gui.flow @element alignment @usage-- Concept Structure -- Root diff --git a/expcore/gui/styles/expstyle/container.lua b/expcore/gui/styles/expstyle/container.lua index ca1a62bb..00ac52ac 100644 --- a/expcore/gui/styles/expstyle/container.lua +++ b/expcore/gui/styles/expstyle/container.lua @@ -2,12 +2,12 @@ @module ExpStyle ]] -local Gui = require 'expcore.gui' --- @dep expcore.gui +local Gui = require 'expcore.gui' -- @dep expcore.gui -Gui.require_concept 'frame' --- @dep gui.concept.frame +Gui.require_concept 'frame' -- @dep gui.concept.frame --[[-- A container frame that can be used to add a boader around your content -@see frame +@see Gui.frame @element container @usage-- Concept Structure -- Root diff --git a/expcore/gui/styles/expstyle/data_label.lua b/expcore/gui/styles/expstyle/data_label.lua index c6ca002c..62c39e73 100644 --- a/expcore/gui/styles/expstyle/data_label.lua +++ b/expcore/gui/styles/expstyle/data_label.lua @@ -2,15 +2,15 @@ @module ExpStyle ]] -local Gui = require 'expcore.gui' --- @dep expcore.gui +local Gui = require 'expcore.gui' -- @dep expcore.gui -Gui.require_concept 'label' --- @dep gui.concept.frame +Gui.require_concept 'label' -- @dep gui.concept.frame local right_align = Gui.new_concept('alignment') --[[-- A label pair which has a static label and a data label which can be changed -@see label +@see Gui.label @element data_label @usage-- Concept Structure -- Root @@ -64,6 +64,12 @@ end) return data_label_element end) +--[[-- Updates the caption and tooltip of the data label using the data format function +@tparam LuaGuiElement element the data label element that you want to update +@tparam any data the data that you want to pass to the format function +@usage-- Updating the data to the current game tick +data_label:update_data_element(element,game.tick) +]] function data_label:update_data_element(element,data,...) local caption, tooltip = self.properties.data_format(self,element,data,...) if caption then @@ -74,6 +80,12 @@ function data_label:update_data_element(element,data,...) end end +--[[-- Updates the caption and tooltip of the data label using the data format function, given the parent of the data label +@tparam LuaGuiElement parent the parent element to the data label element that you want to update +@tparam any data the data that you want to pass to the format function +@usage-- Updating the data to the current game tick +data_label:update_from_parent(parent,game.tick) +]] function data_label:update_from_parent(parent,data,...) local properties = self.properties local data_name = properties.data_label_name or properties.name..'_data' diff --git a/expcore/gui/styles/expstyle/footer.lua b/expcore/gui/styles/expstyle/footer.lua index 3497832b..2ca0a762 100644 --- a/expcore/gui/styles/expstyle/footer.lua +++ b/expcore/gui/styles/expstyle/footer.lua @@ -2,15 +2,15 @@ @module ExpStyle ]] -local Gui = require 'expcore.gui' --- @dep expcore.gui +local Gui = require 'expcore.gui' -- @dep expcore.gui -Gui.require_concept 'frame' --- @dep gui.concept.table +Gui.require_concept 'frame' -- @dep gui.concept.table local right_align = Gui.new_concept('alignment') --[[-- A frame that acts as a footer to a section of content -@see frame +@see Gui.frame @element footer @tparam string tooltip the tooltip to show on the title @usage-- Concept Structure diff --git a/expcore/gui/styles/expstyle/header.lua b/expcore/gui/styles/expstyle/header.lua index 94991865..f570442e 100644 --- a/expcore/gui/styles/expstyle/header.lua +++ b/expcore/gui/styles/expstyle/header.lua @@ -2,15 +2,15 @@ @module ExpStyle ]] -local Gui = require 'expcore.gui' --- @dep expcore.gui +local Gui = require 'expcore.gui' -- @dep expcore.gui -Gui.require_concept 'frame' --- @dep gui.concept.table +Gui.require_concept 'frame' -- @dep gui.concept.table local right_align = Gui.new_concept('alignment') --[[-- A frame that acts as a header to a section of content -@see frame +@see Gui.frame @element header @tparam string tooltip the tooltip to show on the title @usage-- Concept Structure diff --git a/expcore/gui/styles/expstyle/index.lua b/expcore/gui/styles/expstyle/index.lua index aa8afa39..6d773cfb 100644 --- a/expcore/gui/styles/expstyle/index.lua +++ b/expcore/gui/styles/expstyle/index.lua @@ -1,7 +1,18 @@ --[[-- Core Module - ExpStyle - @core ExpStyle + @module ExpStyle + @alias expstyle ]] +--- @dep expcore.gui + +--- @dep gui.concept.frame + +--- @dep gui.concept.flow + +--- @dep gui.concept.table + +--- @dep gui.concept.scroll + local function r(name) require('expcore.gui.styles.expstyle.'..name) end @@ -9,5 +20,9 @@ end r 'container' r 'alignment' r 'header' +r 'footer' r 'scroll_table' -r 'time_label' \ No newline at end of file +r 'time_label' +r 'data_label' +r 'unit_label' +r 'toggle_button' \ No newline at end of file diff --git a/expcore/gui/styles/expstyle/scroll_table.lua b/expcore/gui/styles/expstyle/scroll_table.lua index 411851b7..cd48ff0a 100644 --- a/expcore/gui/styles/expstyle/scroll_table.lua +++ b/expcore/gui/styles/expstyle/scroll_table.lua @@ -2,10 +2,10 @@ @module ExpStyle ]] -local Gui = require 'expcore.gui' --- @dep expcore.gui +local Gui = require 'expcore.gui' -- @dep expcore.gui -Gui.require_concept 'table' --- @dep gui.concept.table -Gui.require_concept 'scroll' --- @dep gui.concept.scroll +Gui.require_concept 'table' -- @dep gui.concept.table +Gui.require_concept 'scroll' -- @dep gui.concept.scroll local scroll_area = Gui.new_concept('scroll') @@ -13,7 +13,7 @@ Gui.new_concept('scroll') :set_horizontal_scroll('never') --[[-- A table that is inside a vertical scroll area -@see table +@see Gui.table @element scroll_table @tparam number hight the max hight of the scroll area @usage-- Concept Structure diff --git a/expcore/gui/styles/expstyle/time_label.lua b/expcore/gui/styles/expstyle/time_label.lua index 64f5f6b7..3fc4b004 100644 --- a/expcore/gui/styles/expstyle/time_label.lua +++ b/expcore/gui/styles/expstyle/time_label.lua @@ -2,7 +2,7 @@ @module ExpStyle ]] -local Gui = require 'expcore.gui' --- @dep expcore.gui +local Gui = require 'expcore.gui' -- @dep expcore.gui local format_time = ext_require('expcore.common','format_time') --- @dep expcore.common --- Converts a tick into string format with workds and symbols diff --git a/expcore/gui/styles/expstyle/toggle_button.lua b/expcore/gui/styles/expstyle/toggle_button.lua index 06adc602..00a894c5 100644 --- a/expcore/gui/styles/expstyle/toggle_button.lua +++ b/expcore/gui/styles/expstyle/toggle_button.lua @@ -2,12 +2,12 @@ @module ExpStyle ]] -local Gui = require 'expcore.gui' --- @dep expcore.gui +local Gui = require 'expcore.gui' -- @dep expcore.gui -Gui.require_concept 'button' --- @dep gui.concept.table +Gui.require_concept 'button' -- @dep gui.concept.table --[[-- A button that will toggle its caption each time it is pressed -@see button +@see Gui.button @element toggle_button @tparam string alt_caption the caption to show on the button in its true state @tparam string alt_tooltip the tooltip to show on the button in its true state diff --git a/expcore/gui/styles/expstyle/unit_label.lua b/expcore/gui/styles/expstyle/unit_label.lua index 3295997a..50bdd4b5 100644 --- a/expcore/gui/styles/expstyle/unit_label.lua +++ b/expcore/gui/styles/expstyle/unit_label.lua @@ -2,15 +2,15 @@ @module ExpStyle ]] -local Gui = require 'expcore.gui' --- @dep expcore.gui +local Gui = require 'expcore.gui' -- @dep expcore.gui -Gui.require_concept 'label' --- @dep gui.concept.frame +Gui.require_concept 'label' -- @dep gui.concept.frame local right_align = Gui.new_concept('alignment') --[[-- A label triplet which has a static label, a data label which can be changed, and a unit label -@see label +@see Gui.label @see data_label @element unit_label @usage-- Concept Structure @@ -60,6 +60,12 @@ end) return element end) +--[[-- Updates the caption and tooltip and unit of the data label using the data format function +@tparam LuaGuiElement element the unit label element that you want to update +@tparam any data the data that you want to pass to the format function +@usage-- Updating the data to the current game tick +unit_label:update_data_element(element,game.tick) +]] function unit_label:update_data_element(element,data,...) local caption, unit, tooltip = self.properties.data_format(self,element,data,...) local unit_element = element.parent.parent[element.name..'_unit'] @@ -75,6 +81,12 @@ function unit_label:update_data_element(element,data,...) end end +--[[-- Updates the caption and tooltip and unit of the unit label using the data format function, given the parent of the unit label +@tparam LuaGuiElement parent the parent element to the unit label element that you want to update +@tparam any data the data that you want to pass to the format function +@usage-- Updating the data to the current game tick +unit_label:update_from_parent(parent,game.tick) +]] function unit_label:update_from_parent(parent,data,...) local properties = self.properties local data_name = properties.data_label_name or properties.name..'_data' From d39fd5ab18e1fd6c19552e30161feacd3e29f789 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sat, 28 Sep 2019 16:17:17 +0100 Subject: [PATCH 24/26] Added player List --- config/_file_loader.lua | 2 +- config/action_buttons.lua | 89 +++-- expcore/gui/core.lua | 24 +- expcore/gui/styles/expstyle/data_label.lua | 2 +- expcore/gui/styles/expstyle/footer.lua | 16 +- expcore/gui/styles/expstyle/scroll_table.lua | 4 +- expcore/gui/styles/expstyle/unit_label.lua | 11 +- expcore/toolbar.lua | 8 +- modules/gui/player-list.lua | 393 ++++++++++--------- 9 files changed, 293 insertions(+), 256 deletions(-) diff --git a/config/_file_loader.lua b/config/_file_loader.lua index e9be5b99..3821a304 100644 --- a/config/_file_loader.lua +++ b/config/_file_loader.lua @@ -43,7 +43,7 @@ return { --'modules.gui.science-info', --'modules.gui.warp-list', --'modules.gui.task-list', - --'modules.gui.player-list', + 'modules.gui.player-list', --'modules.commands.debug', -- Config Files 'config.expcore-commands.auth_admin', -- commands tagged with admin_only are blocked for non admins diff --git a/config/action_buttons.lua b/config/action_buttons.lua index 2e2fb9ae..13a15c7a 100644 --- a/config/action_buttons.lua +++ b/config/action_buttons.lua @@ -15,12 +15,16 @@ local Jail = require 'modules.control.jail' --- @dep modules.control.jail local Colors = require 'resources.color_presets' --- @dep resources.color_presets local format_chat_player_name = ext_require('expcore.common','format_chat_player_name') --- @dep expcore.common +Gui.require_concept('button') + local action_player_store = 'gui.left.player-list.action-player' local action_name_store = 'gui.left.player-list.action-name' -- common style used by all action buttons -local function tool_button_style(style) - Gui.set_padding_style(style,-1,-1,-1,-1) +local function tool_button_style(properties,parent,element) + element.style = 'tool_button' + local style = element.style + style.padding = -1 style.height = 28 style.width = 28 end @@ -55,11 +59,12 @@ end --- Teleports the user to the action player -- @element goto_player local goto_player = -Gui.new_button() -:set_sprites('utility/export') +Gui.new_concept('button') +:set_sprite('utility/export') :set_tooltip{'player-list.goto-player'} -:set_style('tool_button',tool_button_style) -:on_click(function(player,element) +:define_draw(tool_button_style) +:on_click(function(event) + local player = event.player local action_player_name = get_action_player_name(player) local action_player = Game.get_player_from_any(action_player_name) if not player.character or not action_player.character then @@ -72,11 +77,12 @@ end) --- Teleports the action player to the user -- @element bring_player local bring_player = -Gui.new_button() -:set_sprites('utility/import') +Gui.new_concept('button') +:set_sprite('utility/import') :set_tooltip{'player-list.bring-player'} -:set_style('tool_button',tool_button_style) -:on_click(function(player,element) +:define_draw(tool_button_style) +:on_click(function(event) + local player = event.player local action_player_name = get_action_player_name(player) local action_player = Game.get_player_from_any(action_player_name) if not player.character or not action_player.character then @@ -89,11 +95,12 @@ end) --- Kills the action player, if there are alive -- @element kill_player local kill_player = -Gui.new_button() -:set_sprites('utility/too_far') +Gui.new_concept('button') +:set_sprite('utility/too_far') :set_tooltip{'player-list.kill-player'} -:set_style('tool_button',tool_button_style) -:on_click(function(player,element) +:define_draw(tool_button_style) +:on_click(function(event) + local player = event.player local action_player_name = get_action_player_name(player) local action_player = Game.get_player_from_any(action_player_name) if action_player.character then @@ -106,11 +113,12 @@ end) --- Reports the action player, requires a reason to be given -- @element report_player local report_player = -Gui.new_button() -:set_sprites('utility/spawn_flag') +Gui.new_concept('button') +:set_sprite('utility/spawn_flag') :set_tooltip{'player-list.report-player'} -:set_style('tool_button',tool_button_style) -:on_click(function(player,element) +:define_draw(tool_button_style) +:on_click(function(event) + local player = event.player local action_player_name = get_action_player_name(player) if Reports.is_reported(action_player_name,player.name) then player.print({'expcom-report.already-reported'},Colors.orange_red) @@ -130,11 +138,12 @@ end --- Gives the action player a warning, requires a reason -- @element warn_player local warn_player = -Gui.new_button() -:set_sprites('utility/spawn_flag') +Gui.new_concept('button') +:set_sprite('utility/spawn_flag') :set_tooltip{'player-list.warn-player'} -:set_style('tool_button',tool_button_style) -:on_click(function(player,element) +:define_draw(tool_button_style) +:on_click(function(event) + local player = event.player Store.set(action_name_store,player.name,'command/give-warning') end) @@ -148,11 +157,12 @@ end --- Jails the action player, requires a reason -- @element jail_player local jail_player = -Gui.new_button() -:set_sprites('utility/item_editor_icon') +Gui.new_concept('button') +:set_sprite('utility/item_editor_icon') :set_tooltip{'player-list.jail-player'} -:set_style('tool_button',tool_button_style) -:on_click(function(player,element) +:define_draw(tool_button_style) +:on_click(function(event) + local player = event.player local action_player_name,action_player_name_color = get_action_player_name(player) if Jail.is_jailed(action_player_name) then player.print({'expcom-jail.already-jailed',action_player_name_color},Colors.orange_red) @@ -171,11 +181,12 @@ end --- Temp bans the action player, requires a reason -- @element temp_ban_player local temp_ban_player = -Gui.new_button() -:set_sprites('utility/clock') +Gui.new_concept('button') +:set_sprite('utility/clock') :set_tooltip{'player-list.temp-ban-player'} -:set_style('tool_button',tool_button_style) -:on_click(function(player,element) +:define_draw(tool_button_style) +:on_click(function(event) + local player = event.player local action_player_name,action_player_name_color = get_action_player_name(player) if Jail.is_jailed(action_player_name) then player.print({'expcom-jail.already-banned',action_player_name_color},Colors.orange_red) @@ -194,11 +205,12 @@ end --- Kicks the action player, requires a reason -- @element kick_player local kick_player = -Gui.new_button() -:set_sprites('utility/warning_icon') +Gui.new_concept('button') +:set_sprite('utility/warning_icon') :set_tooltip{'player-list.kick-player'} -:set_style('tool_button',tool_button_style) -:on_click(function(player,element) +:define_draw(tool_button_style) +:on_click(function(event) + local player = event.player Store.set(action_name_store,player.name,'command/kick') end) @@ -210,11 +222,12 @@ end --- Bans the action player, requires a reason -- @element ban_player local ban_player = -Gui.new_button() -:set_sprites('utility/danger_icon') +Gui.new_concept('button') +:set_sprite('utility/danger_icon') :set_tooltip{'player-list.ban-player'} -:set_style('tool_button',tool_button_style) -:on_click(function(player,element) +:define_draw(tool_button_style) +:on_click(function(event) + local player = event.player Store.set(action_name_store,player.name,'command/ban') end) diff --git a/expcore/gui/core.lua b/expcore/gui/core.lua index 23b13a5b..118bfc87 100644 --- a/expcore/gui/core.lua +++ b/expcore/gui/core.lua @@ -147,9 +147,9 @@ end @treturn[2] boolean if the element was found, found @treturn[2] LuaGuiElement the element that was found @usage-- Getting the center gui -local exists, center = Gui.find(player,'gui','center') +local exists, center = Gui.exists(player,'gui','center') ]] -function Gui.find(element,...) +function Gui.exists(element,...) local path = tostring(element.name) for _,next_element_name in pairs{...} do if type(next_element_name) == 'table' then @@ -165,18 +165,22 @@ function Gui.find(element,...) return true, element end ---[[-- Checks if a gui element exists or not, returns it if found else the path where it failed -@see Gui.find +--[[-- Checks if a gui element exists or not, if not found will throw an error +@see Gui.exists @tparam LuaGuiElement element the root element to start checking from @tparam ?string|table ... element names or element concepts that point to your element -@treturn[1] boolean if the element was found, failed -@treturn[1] string the path of the element that the search stoped at -@treturn[2] boolean if the element was found, found -@treturn[2] LuaGuiElement the element that was found +@treturn LuaGuiElement the element that was found @usage-- Getting the center gui -local exists, center = Gui.exists(player,'gui','center') +local exists, center = Gui.find(player,'gui','center') ]] -Gui.exists = Gui.find +function Gui.find(element,...) + local exists, element = Gui.exists(element,...) + if not exists then + return error('Could not find element: '..element,2) + else + return element + end +end --[[-- Toggles the enabled state of an element @tparam LuaGuiElement element the element that you want to toggle the enabled state of diff --git a/expcore/gui/styles/expstyle/data_label.lua b/expcore/gui/styles/expstyle/data_label.lua index 62c39e73..a393ba8b 100644 --- a/expcore/gui/styles/expstyle/data_label.lua +++ b/expcore/gui/styles/expstyle/data_label.lua @@ -40,7 +40,7 @@ end) -- Draw :define_draw(function(properties,parent,element) -- Make the label right aligned - local data_name = properties.data_label_name or properties.name..'_data' + local data_name = properties.data_label_name or properties.name..'_data' local right_align_element = right_align:draw(parent,data_name) -- Add a new label diff --git a/expcore/gui/styles/expstyle/footer.lua b/expcore/gui/styles/expstyle/footer.lua index 2ca0a762..01035f19 100644 --- a/expcore/gui/styles/expstyle/footer.lua +++ b/expcore/gui/styles/expstyle/footer.lua @@ -31,19 +31,21 @@ Gui.new_concept('frame') -- Update the table style Gui.set_padding(element,2,2,4,4) element.style = 'subfooter_frame' - element.caption = nil + element.caption = '' local style = element.style style.horizontally_stretchable = true style.use_header_filler = false -- Add the caption to the frame - element.add{ - type = 'label', - name = 'footer_caption', - caption = properties.title, - tooltip = properties.tooltip - } + if properties.title then + element.add{ + type = 'label', + name = 'footer_caption', + caption = properties.title, + tooltip = properties.tooltip + } + end -- Add the right align area local align = right_align:draw(element,'footer_content') diff --git a/expcore/gui/styles/expstyle/scroll_table.lua b/expcore/gui/styles/expstyle/scroll_table.lua index cd48ff0a..8da23384 100644 --- a/expcore/gui/styles/expstyle/scroll_table.lua +++ b/expcore/gui/styles/expstyle/scroll_table.lua @@ -27,7 +27,7 @@ Gui.new_concept('scroll_table') Gui.new_concept('table') :save_as('scroll_table') -:new_property('hight',nil,100) +:new_property('height',nil,100) -- Add a scroll before the table is drawn :define_pre_draw(function(properties,parent,element) @@ -36,7 +36,7 @@ Gui.new_concept('table') -- Set the scroll style Gui.set_padding(scroll,1,1,2,2) scroll.style.horizontally_stretchable = true - scroll.style.maximal_height = properties.hight + scroll.style.maximal_height = properties.height -- Change the name of the element to table before it is drawn properties.name = 'table' diff --git a/expcore/gui/styles/expstyle/unit_label.lua b/expcore/gui/styles/expstyle/unit_label.lua index 50bdd4b5..ca47ffd3 100644 --- a/expcore/gui/styles/expstyle/unit_label.lua +++ b/expcore/gui/styles/expstyle/unit_label.lua @@ -4,11 +4,6 @@ local Gui = require 'expcore.gui' -- @dep expcore.gui -Gui.require_concept 'label' -- @dep gui.concept.frame - -local right_align = -Gui.new_concept('alignment') - --[[-- A label triplet which has a static label, a data label which can be changed, and a unit label @see Gui.label @see data_label @@ -34,11 +29,8 @@ end) local unit_label = Gui.new_concept('data_label') :save_as('unit_label') -:new_property('data_label_name') -:new_property('data_caption') -:new_property('data_tooltip') :new_property('data_unit') -:new_property('data_format',nil,function(concept,element,data,...) +:set_data_format(function(concept,element,data,...) local base_unit = concept.properties.data_unit local caption = tostring(data) local unit = data == 1 and base_unit or base_unit..'s' @@ -53,6 +45,7 @@ end) -- Add the unit label parent.add{ name = element.name..'_unit', + type='label', caption = unit or '', tooltip = element.tooltip } diff --git a/expcore/toolbar.lua b/expcore/toolbar.lua index da1b5d16..03dd4a1b 100644 --- a/expcore/toolbar.lua +++ b/expcore/toolbar.lua @@ -232,9 +232,9 @@ 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_property('open_by_default',nil,false) +:new_property('use_container',nil,true) +:new_property('direction',nil,'horizontal') :new_event('on_update') -- Clone @@ -258,7 +258,6 @@ end) frame.style.padding = 2 - -- Add and return the container if a container is used if properties.use_container then local container = frame.add{ @@ -270,7 +269,6 @@ end) Gui.set_padding(container) return container - end return frame diff --git a/modules/gui/player-list.lua b/modules/gui/player-list.lua index e58a55bd..a97db8c9 100644 --- a/modules/gui/player-list.lua +++ b/modules/gui/player-list.lua @@ -9,16 +9,25 @@ local Roles = require 'expcore.roles' --- @dep expcore.roles local Store = require 'expcore.store' --- @dep expcore.store local Game = require 'utils.game' --- @dep utils.game local Event = require 'utils.event' --- @dep utils.event -local format_time = ext_require('expcore.common','format_time') --- @dep expcore.common local config = require 'config.action_buttons' --- @dep config.action_buttons local Colors = require 'resources.color_presets' --- @dep resources.color_presets +require 'expcore.toolbar' --- @dep expcore.toolbar + +Gui.require_concept('label') +Gui.require_concept('button') +Gui.require_concept('text_field') +Gui.require_concept('frame') +Gui.require_style('expstyle') local action_player_store = 'gui.left.player-list.action-player' local action_name_store = 'gui.left.player-list.action-name' ---- used on player name label to allow zoom to map -local zoom_to_map_name = Gui.uid_name() -Gui.on_click(zoom_to_map_name,function(event) +--- Name label that alows zoom to map +-- @element zoom_to_map +local zoom_to_map = +Gui.new_concept('label') +:new_event('on_click',defines.events.on_gui_click) +:on_click(function(event) local action_player_name = event.element.caption local action_player = Game.get_player_from_any(action_player_name) if event.button == defines.mouse_button_type.left then @@ -36,136 +45,130 @@ Gui.on_click(zoom_to_map_name,function(event) end end end) +:define_pre_draw(function(properties,parent,element) + -- Place the button into a flow + local flow = + parent.add{ + type = 'flow', + } + + return element, flow +end) +:define_draw(function(properties,parent,element,player,role_name) + local player_name = player.name + element.caption = player_name + element.tooltip = {'player-list.open-map',player_name,player.tag,role_name} + + Gui.set_padding(element,0,0,0,2) + element.style.font_color = player.chat_color +end) + +--- Right align for the time label +-- @element right_align +local right_align = +Gui.new_concept('alignment') + +--- Shows the players online time +-- @element time_label +local time = +Gui.new_concept('time_label') +:set_time_format{minutes = true} +:set_time(0) +:define_draw(function(properties,parent,element) + Gui.set_padding(element) +end) --- Button used to open the action bar -- @element open_action_bar local open_action_bar = -Gui.new_button() -:set_sprites('utility/expand_dots_white') +Gui.new_concept('button') +:set_sprite('utility/expand_dots_white') :set_tooltip{'player-list.open-action-bar'} -:set_embedded_flow(function(element,action_player_name) - return action_player_name +:define_pre_draw(function(properties,parent,element,action_player_name) + -- Place the button into a flow + local flow = + parent.add{ + type = 'flow', + name = action_player_name + } + + return element, flow end) -:set_style('frame_button',function(style) - Gui.set_padding_style(style,-2,-2,-2,-2) +:define_draw(function(properties,parent,element) + -- Update the style of the element + element.style = 'frame_button' + local style = element.style + style.padding = -2 style.width = 8 style.height = 14 end) -:on_click(function(player,element) +:on_click(function(event) + -- Open the action bar when pressed + local element = event.element + local player_name = event.player.name local new_action_player_name = element.parent.name - local action_player_name = Store.get(action_player_store,player.name) + local action_player_name = Store.get(action_player_store,player_name) if action_player_name == new_action_player_name then - Store.clear(action_player_store,player.name) -- will close if already open + Store.clear(action_player_store,player_name) -- will close if already open else - Store.set(action_player_store,player.name,new_action_player_name) + Store.set(action_player_store,player_name,new_action_player_name) end end) --- Button used to close the action bar -- @element close_action_bar local close_action_bar = -Gui.new_button() -:set_sprites('utility/close_black','utility/close_white') +Gui.new_concept('button') +:set_sprite('utility/close_black','utility/close_white') :set_tooltip{'player-list.close-action-bar'} -:set_style('tool_button',function(style) - Gui.set_padding_style(style,-1,-1,-1,-1) +:define_draw(function(properties,parent,element) + -- Update the style of the element + element.style = 'tool_button' + local style = element.style + style.padding = -1 style.height = 28 style.width = 28 end) -:on_click(function(player,element) - Store.clear(action_player_store,player.name) - Store.clear(action_name_store,player.name) +:on_click(function(event) + -- Close the action bar + local player_name = event.player.name + Store.clear(action_player_store,player_name) + Store.clear(action_name_store,player_name) end) ---- Button used to confirm a reason --- @element reason_confirm -local reason_confirm = -Gui.new_button() -:set_sprites('utility/confirm_slot') -:set_tooltip{'player-list.reason-confirm'} -:set_style('tool_button',function(style) - Gui.set_padding_style(style,-1,-1,-1,-1) - style.height = 28 - style.width = 28 -end) -:on_click(function(player,element) - local reason = element.parent.entry.text or 'Non Given' - local action_name = Store.get(action_name_store,player.name) - local reason_callback = config[action_name].reason_callback - reason_callback(player,reason) - Store.clear(action_player_store,player.name) - Store.clear(action_name_store,player.name) - element.parent.entry.text = '' +--- Adds all the player info into the content table +-- @element player_info +local player_info = +Gui.new_concept() +:define_draw(function(properties,parent,element,player,role_name) + local player_name = player.name + open_action_bar:draw(parent,nil,player_name) + zoom_to_map:draw(parent,nil,player,role_name) + time:update_time(time:draw(right_align:draw(parent,time.name..player_name)),player.online_time) end) ---[[ Creates the main gui areas for the player list - element - > container - >> scroll - >>> table - >> action_bar -]] -local function generate_container(player,element) - Gui.set_padding(element,2,2,2,2) - element.style.minimal_width = 200 +--- Stores all the online players +-- @element content_table +local content_table = +Gui.new_concept('scroll_table') +:set_height(188) +:set_column_count(3) - -- main container which contains the other elements - local container = - element.add{ - name='container', - type='frame', - direction='vertical', - style='window_content_frame_packed' - } - Gui.set_padding(container) +--- Stores all the action buttons +-- @element action_bar +local action_bar = +Gui.new_concept('frame') +:define_draw(function(properties,parent,element) + element.style = 'subfooter_frame' + Gui.set_padding(element,1,1,3,3) - -- 3 wide table to contain: action button, player name, and play time - local list_table = Gui.create_scroll_table(container,3,188) + local style = element.style + style.horizontally_stretchable = true + style.height = 35 - -- action bar which contains the different action buttons - local action_bar = - container.add{ - name='action_bar', - type='frame', - style='subfooter_frame' - } - Gui.set_padding(action_bar,1,1,3,3) - action_bar.style.horizontally_stretchable = true - action_bar.style.height = 35 + close_action_bar:draw(element) - -- reason bar which contains the reason text field and confirm button - local reason_bar = - container.add{ - name='reason_bar', - type='frame', - style='subfooter_frame' - } - Gui.set_padding(reason_bar,-1,-1,3,3) - reason_bar.style.horizontally_stretchable = true - reason_bar.style.height = 35 - local action_name = Store.get(action_name_store,player.name) - reason_bar.visible = action_name ~= nil - - -- text entry for the reason bar - local reason_field = - reason_bar.add{ - name='entry', - type='textfield', - style='stretchable_textfield', - tooltip={'player-list.reason-entry'} - } - Gui.set_padding(reason_field) - reason_field.style.height = 28 - reason_field.style.minimal_width = 160 - - reason_confirm(reason_bar) - - return list_table, action_bar -end - ---- Adds buttons and permission flows to the action bar -local function generate_action_bar(player,element) - close_action_bar(element) + local player = Gui.get_player_from_element(element) local action_player = Store.get(action_player_store,player.name) for action_name,buttons in pairs(config) do @@ -176,7 +179,7 @@ local function generate_action_bar(player,element) } for _,button in ipairs(buttons) do - button(permission_flow) + button:draw(permission_flow) end if not Roles.player_allowed(player,action_name) then @@ -186,18 +189,79 @@ local function generate_action_bar(player,element) if buttons.auth and action_player and not buttons.auth(player,action_player) then permission_flow.visible = false end + end if not action_player then element.visible = false end -end +end) + +--- Text entry for reason +-- @element reason_field +local reason_field = +Gui.new_concept('text_field') +:set_tooltip{'player-list.reason-entry'} +:define_draw(function(properties,parent,element) + element.style = 'stretchable_textfield' + local style = element.style + style.padding = 0 + style.minimal_width = 160 + style.height = 28 +end) + +--- Button used to confirm a reason +-- @element reason_confirm +local reason_confirm = +Gui.new_concept('button') +:set_sprite('utility/confirm_slot') +:set_tooltip{'player-list.reason-confirm'} +:define_draw(function(properties,parent,element) + -- Update the style of the element + element.style = 'tool_button' + local style = element.style + style.padding = -1 + style.height = 28 + style.width = 28 +end) +:on_click(function(event) + -- Confirm the reason given + local element = event.element + local player_name = event.player.name + local reason = element.parent.entry.text or 'Non Given' + local action_name = Store.get(action_name_store,player_name) + local reason_callback = config[action_name].reason_callback + reason_callback(event.player,reason) + Store.clear(action_player_store,player_name) + Store.clear(action_name_store,player_name) + element.parent.entry.text = '' +end) + +--- Stores the reason entry and confirmation button +-- @element reason_bar +local reason_bar = +Gui.new_concept('frame') +:define_draw(function(properties,parent,element) + element.style = 'subfooter_frame' + Gui.set_padding(element,-1,-1,3,3) + + local style = element.style + style.horizontally_stretchable = true + style.height = 35 + + local player = Gui.get_player_from_element(element) + local action_name = Store.get(action_name_store,player.name) + element.visible = action_name ~= nil + + reason_field:draw(element) + reason_confirm:draw(element) +end) --- Updates the action bar -local player_list_name +local player_list local function update_action_bar(player) - local frame = Gui.classes.left_frames.get_frame(player_list_name,player) - local element = frame.container.action_bar + local content = player_list:get_content(player) + local element = Gui.find(content,action_bar) local action_player_name = Store.get(action_player_store,player.name) if not action_player_name then @@ -212,6 +276,7 @@ local function update_action_bar(player) element.visible = true for action_name,buttons in pairs(config) do if buttons.auth and not buttons.auth(player,action_player) then + print(action_name) element[action_name].visible = false elseif Roles.player_allowed(player,action_name) then element[action_name].visible = true @@ -221,70 +286,37 @@ local function update_action_bar(player) end end ---- Adds a player to the player list -local function add_player(list_table,player,role_name) - open_action_bar(list_table,player.name) - - -- flow to contain player_name to allow all to have trigger for zoom to map - local player_name_flow = - list_table.add{ - type='flow' - } - Gui.set_padding(player_name_flow) - - -- player name with the tooltip of their highest role and in they colour - local player_name = - player_name_flow.add{ - name=zoom_to_map_name, - type='label', - caption=player.name, - tooltip={'player-list.open-map',player.name,player.tag,role_name} - } - Gui.set_padding(player_name,0,0,0,2) - player_name.style.font_color = player.chat_color - - -- flow which allows right align for the play time - local time_flow = Gui.create_alignment(list_table,'player-time-'..player.index) - - -- time given in Xh Ym and is right aligned - local tick = game.tick > 0 and game.tick or 1 - local percent = math.round(player.online_time/tick,3)*100 - local time = - time_flow.add{ - name='label', - type='label', - caption=format_time(player.online_time), - tooltip={'player-list.afk-time',percent,format_time(player.afk_time,{minutes=true,long=true})} - } - Gui.set_padding(time) -end - --- Adds fake players to the player list -local function add_fake_players(list_table,count) +local function add_fake_players(content_area,count) local role_name = 'Fake Player' for i = 1,count do - add_player(list_table,{ + local player = { name='Player '..i, index=0-i, tag='', online_time=math.random(0,game.tick), afk_time=math.random(0,game.tick), chat_color=table.get_random_dictionary_entry(Colors) - },role_name) + } + + player_info:draw(content_area,nil,player,role_name) end end --- Registers the player list -- @element player_list -local player_list = -Gui.new_left_frame('gui/player-list') -:set_sprites('entity/character') +player_list = +Gui.new_concept('toolbar-frame') +:set_permission_alias('gui/player-list') +:set_sprite('entity/character') :set_tooltip{'player-list.main-tooltip'} -:set_open_by_default() +:set_open_by_default(true) :set_direction('vertical') -:on_creation(function(player,element) - local list_table,action_bar = generate_container(player,element) - generate_action_bar(player,action_bar) +:define_draw(function(properties,parent,element) + local content_area = + content_table:draw(element) + action_bar:draw(element) + reason_bar:draw(element) local players = {} for _,next_player in pairs(game.connected_players) do @@ -298,55 +330,49 @@ Gui.new_left_frame('gui/player-list') for _,role_name in pairs(Roles.config.order) do if players[role_name] then for _,next_player in pairs(players[role_name]) do - add_player(list_table,next_player,role_name) + player_info:draw(content_area,nil,next_player,role_name) end end end - --add_fake_players(list_table,6) - --add_fake_players(list_table,20) + add_fake_players(content_area,4) end) -:on_update(function(player,element) - local list = element.container.scroll.table +:on_update(function(event) + local list = Gui.find(event.element,content_table,'table') for _,next_player in pairs(game.connected_players) do - local time_element_name = 'player-time-'..next_player.index - local time_element = list[time_element_name] + local time_element = Gui.find(list,time.name..next_player.name,time) if time_element and time_element.valid then - time_element.label.caption = format_time(next_player.online_time) - local tick = game.tick > 0 and game.tick or 1 - local percent = math.round(next_player.online_time/tick,3)*100 - time_element.label.tooltip = {'player-list.afk-time',percent,format_time(next_player.afk_time,{minutes=true,long=true})} + time:update_time(time_element,next_player.online_time) end end end) -player_list_name = player_list:uid() - --- When the action player is changed the action bar will update Store.register(action_player_store,function(value,category) local player = Game.get_player_from_any(category) update_action_bar(player) - local frame = player_list:get_frame(player) - local data_table = frame.container.scroll.table + local frame = player_list:get_content(player) + local data_table = Gui.find(frame,content_table,'table') for _,next_player in pairs(game.connected_players) do - local element = data_table[next_player.name][open_action_bar.name] + local element = Gui.find(data_table,next_player.name,open_action_bar) local style = 'frame_button' if next_player.name == value then style = 'tool_button' end element.style = style - Gui.set_padding(element,-2,-2,-2,-2) - element.style.width = 8 - element.style.height = 14 + style = element.style + style.padding = -2 + style.width = 8 + style.height = 14 end end) --- When the action name is changed the reason input will update Store.register(action_name_store,function(value,category) local player = Game.get_player_from_any(category) - local frame = Gui.classes.left_frames.get_frame(player_list_name,player) - local element = frame.container.reason_bar + local frame = player_list:get_content(player) + local element = Gui.find(frame,reason_bar) if value then local action_player_name = Store.get(action_player_store,category) local action_player = Game.get_player_from_any(action_player_name) @@ -362,10 +388,11 @@ Store.register(action_name_store,function(value,category) end) --- Many events which trigger the gui to be re drawn, it will also update the times every 30 seconds -Event.on_nth_tick(1800,player_list 'update_all') -Event.add(defines.events.on_player_joined_game,player_list 'redraw_all') -Event.add(defines.events.on_player_left_game,player_list 'redraw_all') -Event.add(Roles.events.on_role_assigned,player_list 'redraw_all') -Event.add(Roles.events.on_role_unassigned,player_list 'redraw_all') +local update = function(event) player_list:update_all(event) end +Event.on_nth_tick(1800,update) +Event.add(defines.events.on_player_joined_game,update) +Event.add(defines.events.on_player_left_game,update) +Event.add(Roles.events.on_role_assigned,update) +Event.add(Roles.events.on_role_unassigned,update) return player_list \ No newline at end of file From 654550bcb13fd922ce922423eaecb526ebf5440c Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sat, 28 Sep 2019 16:34:52 +0100 Subject: [PATCH 25/26] Revert --- config/_file_loader.lua | 10 +- config/action_buttons.lua | 89 +- expcore/gui.lua | 345 ++++- expcore/gui/concepts/button.lua | 90 -- expcore/gui/concepts/center.lua | 198 +++ expcore/gui/concepts/checkbox.lua | 62 - expcore/gui/concepts/dropdown.lua | 169 --- expcore/gui/concepts/elem_button.lua | 51 - expcore/gui/concepts/empty.lua | 36 - expcore/gui/concepts/flow.lua | 42 - expcore/gui/concepts/frame.lua | 45 - expcore/gui/concepts/label.lua | 46 - expcore/gui/concepts/left.lua | 322 +++++ expcore/gui/concepts/line.lua | 35 - expcore/gui/concepts/popups.lua | 230 ++++ expcore/gui/concepts/progress_bar.lua | 168 --- expcore/gui/concepts/scroll.lua | 47 - expcore/gui/concepts/slider.lua | 91 -- expcore/gui/concepts/table.lua | 58 - expcore/gui/concepts/text_box.lua | 84 -- expcore/gui/concepts/text_field.lua | 100 -- expcore/gui/concepts/toolbar.lua | 114 ++ expcore/gui/core.lua | 591 +++++---- expcore/gui/elements/buttons.lua | 128 ++ expcore/gui/elements/checkbox.lua | 252 ++++ expcore/gui/elements/dropdown.lua | 187 +++ expcore/gui/elements/elem-button.lua | 99 ++ expcore/gui/elements/progress-bar.lua | 390 ++++++ expcore/gui/elements/slider.lua | 177 +++ expcore/gui/elements/text.lua | 149 +++ expcore/gui/instances.lua | 235 ++++ expcore/gui/prototype.lua | 948 ++++---------- expcore/gui/styles/expstyle/alignment.lua | 49 - expcore/gui/styles/expstyle/container.lua | 37 - expcore/gui/styles/expstyle/data_label.lua | 101 -- expcore/gui/styles/expstyle/footer.lua | 54 - expcore/gui/styles/expstyle/header.lua | 52 - expcore/gui/styles/expstyle/index.lua | 28 - expcore/gui/styles/expstyle/scroll_table.lua | 60 - expcore/gui/styles/expstyle/time_label.lua | 92 -- expcore/gui/styles/expstyle/toggle_button.lua | 49 - expcore/gui/styles/expstyle/unit_label.lua | 100 -- expcore/gui/test.lua | 1158 ++++++++--------- expcore/toolbar.lua | 493 ------- modules/gui/player-list.lua | 393 +++--- 45 files changed, 4139 insertions(+), 4115 deletions(-) delete mode 100644 expcore/gui/concepts/button.lua create mode 100644 expcore/gui/concepts/center.lua delete mode 100644 expcore/gui/concepts/checkbox.lua delete mode 100644 expcore/gui/concepts/dropdown.lua delete mode 100644 expcore/gui/concepts/elem_button.lua delete mode 100644 expcore/gui/concepts/empty.lua delete mode 100644 expcore/gui/concepts/flow.lua delete mode 100644 expcore/gui/concepts/frame.lua delete mode 100644 expcore/gui/concepts/label.lua create mode 100644 expcore/gui/concepts/left.lua delete mode 100644 expcore/gui/concepts/line.lua create mode 100644 expcore/gui/concepts/popups.lua delete mode 100644 expcore/gui/concepts/progress_bar.lua delete mode 100644 expcore/gui/concepts/scroll.lua delete mode 100644 expcore/gui/concepts/slider.lua delete mode 100644 expcore/gui/concepts/table.lua delete mode 100644 expcore/gui/concepts/text_box.lua delete mode 100644 expcore/gui/concepts/text_field.lua create mode 100644 expcore/gui/concepts/toolbar.lua create mode 100644 expcore/gui/elements/buttons.lua create mode 100644 expcore/gui/elements/checkbox.lua create mode 100644 expcore/gui/elements/dropdown.lua create mode 100644 expcore/gui/elements/elem-button.lua create mode 100644 expcore/gui/elements/progress-bar.lua create mode 100644 expcore/gui/elements/slider.lua create mode 100644 expcore/gui/elements/text.lua create mode 100644 expcore/gui/instances.lua delete mode 100644 expcore/gui/styles/expstyle/alignment.lua delete mode 100644 expcore/gui/styles/expstyle/container.lua delete mode 100644 expcore/gui/styles/expstyle/data_label.lua delete mode 100644 expcore/gui/styles/expstyle/footer.lua delete mode 100644 expcore/gui/styles/expstyle/header.lua delete mode 100644 expcore/gui/styles/expstyle/index.lua delete mode 100644 expcore/gui/styles/expstyle/scroll_table.lua delete mode 100644 expcore/gui/styles/expstyle/time_label.lua delete mode 100644 expcore/gui/styles/expstyle/toggle_button.lua delete mode 100644 expcore/gui/styles/expstyle/unit_label.lua delete mode 100644 expcore/toolbar.lua diff --git a/config/_file_loader.lua b/config/_file_loader.lua index 3821a304..c4a5bba6 100644 --- a/config/_file_loader.lua +++ b/config/_file_loader.lua @@ -39,12 +39,12 @@ return { 'modules.addons.discord-alerts', 'modules.addons.chat-reply', -- GUI - --'modules.gui.rocket-info', - --'modules.gui.science-info', - --'modules.gui.warp-list', - --'modules.gui.task-list', + 'modules.gui.rocket-info', + 'modules.gui.science-info', + 'modules.gui.warp-list', + 'modules.gui.task-list', 'modules.gui.player-list', - --'modules.commands.debug', + 'modules.commands.debug', -- Config Files 'config.expcore-commands.auth_admin', -- commands tagged with admin_only are blocked for non admins 'config.expcore-commands.auth_roles', -- commands must be allowed via the role config diff --git a/config/action_buttons.lua b/config/action_buttons.lua index 13a15c7a..2e2fb9ae 100644 --- a/config/action_buttons.lua +++ b/config/action_buttons.lua @@ -15,16 +15,12 @@ local Jail = require 'modules.control.jail' --- @dep modules.control.jail local Colors = require 'resources.color_presets' --- @dep resources.color_presets local format_chat_player_name = ext_require('expcore.common','format_chat_player_name') --- @dep expcore.common -Gui.require_concept('button') - local action_player_store = 'gui.left.player-list.action-player' local action_name_store = 'gui.left.player-list.action-name' -- common style used by all action buttons -local function tool_button_style(properties,parent,element) - element.style = 'tool_button' - local style = element.style - style.padding = -1 +local function tool_button_style(style) + Gui.set_padding_style(style,-1,-1,-1,-1) style.height = 28 style.width = 28 end @@ -59,12 +55,11 @@ end --- Teleports the user to the action player -- @element goto_player local goto_player = -Gui.new_concept('button') -:set_sprite('utility/export') +Gui.new_button() +:set_sprites('utility/export') :set_tooltip{'player-list.goto-player'} -:define_draw(tool_button_style) -:on_click(function(event) - local player = event.player +:set_style('tool_button',tool_button_style) +:on_click(function(player,element) local action_player_name = get_action_player_name(player) local action_player = Game.get_player_from_any(action_player_name) if not player.character or not action_player.character then @@ -77,12 +72,11 @@ end) --- Teleports the action player to the user -- @element bring_player local bring_player = -Gui.new_concept('button') -:set_sprite('utility/import') +Gui.new_button() +:set_sprites('utility/import') :set_tooltip{'player-list.bring-player'} -:define_draw(tool_button_style) -:on_click(function(event) - local player = event.player +:set_style('tool_button',tool_button_style) +:on_click(function(player,element) local action_player_name = get_action_player_name(player) local action_player = Game.get_player_from_any(action_player_name) if not player.character or not action_player.character then @@ -95,12 +89,11 @@ end) --- Kills the action player, if there are alive -- @element kill_player local kill_player = -Gui.new_concept('button') -:set_sprite('utility/too_far') +Gui.new_button() +:set_sprites('utility/too_far') :set_tooltip{'player-list.kill-player'} -:define_draw(tool_button_style) -:on_click(function(event) - local player = event.player +:set_style('tool_button',tool_button_style) +:on_click(function(player,element) local action_player_name = get_action_player_name(player) local action_player = Game.get_player_from_any(action_player_name) if action_player.character then @@ -113,12 +106,11 @@ end) --- Reports the action player, requires a reason to be given -- @element report_player local report_player = -Gui.new_concept('button') -:set_sprite('utility/spawn_flag') +Gui.new_button() +:set_sprites('utility/spawn_flag') :set_tooltip{'player-list.report-player'} -:define_draw(tool_button_style) -:on_click(function(event) - local player = event.player +:set_style('tool_button',tool_button_style) +:on_click(function(player,element) local action_player_name = get_action_player_name(player) if Reports.is_reported(action_player_name,player.name) then player.print({'expcom-report.already-reported'},Colors.orange_red) @@ -138,12 +130,11 @@ end --- Gives the action player a warning, requires a reason -- @element warn_player local warn_player = -Gui.new_concept('button') -:set_sprite('utility/spawn_flag') +Gui.new_button() +:set_sprites('utility/spawn_flag') :set_tooltip{'player-list.warn-player'} -:define_draw(tool_button_style) -:on_click(function(event) - local player = event.player +:set_style('tool_button',tool_button_style) +:on_click(function(player,element) Store.set(action_name_store,player.name,'command/give-warning') end) @@ -157,12 +148,11 @@ end --- Jails the action player, requires a reason -- @element jail_player local jail_player = -Gui.new_concept('button') -:set_sprite('utility/item_editor_icon') +Gui.new_button() +:set_sprites('utility/item_editor_icon') :set_tooltip{'player-list.jail-player'} -:define_draw(tool_button_style) -:on_click(function(event) - local player = event.player +:set_style('tool_button',tool_button_style) +:on_click(function(player,element) local action_player_name,action_player_name_color = get_action_player_name(player) if Jail.is_jailed(action_player_name) then player.print({'expcom-jail.already-jailed',action_player_name_color},Colors.orange_red) @@ -181,12 +171,11 @@ end --- Temp bans the action player, requires a reason -- @element temp_ban_player local temp_ban_player = -Gui.new_concept('button') -:set_sprite('utility/clock') +Gui.new_button() +:set_sprites('utility/clock') :set_tooltip{'player-list.temp-ban-player'} -:define_draw(tool_button_style) -:on_click(function(event) - local player = event.player +:set_style('tool_button',tool_button_style) +:on_click(function(player,element) local action_player_name,action_player_name_color = get_action_player_name(player) if Jail.is_jailed(action_player_name) then player.print({'expcom-jail.already-banned',action_player_name_color},Colors.orange_red) @@ -205,12 +194,11 @@ end --- Kicks the action player, requires a reason -- @element kick_player local kick_player = -Gui.new_concept('button') -:set_sprite('utility/warning_icon') +Gui.new_button() +:set_sprites('utility/warning_icon') :set_tooltip{'player-list.kick-player'} -:define_draw(tool_button_style) -:on_click(function(event) - local player = event.player +:set_style('tool_button',tool_button_style) +:on_click(function(player,element) Store.set(action_name_store,player.name,'command/kick') end) @@ -222,12 +210,11 @@ end --- Bans the action player, requires a reason -- @element ban_player local ban_player = -Gui.new_concept('button') -:set_sprite('utility/danger_icon') +Gui.new_button() +:set_sprites('utility/danger_icon') :set_tooltip{'player-list.ban-player'} -:define_draw(tool_button_style) -:on_click(function(event) - local player = event.player +:set_style('tool_button',tool_button_style) +:on_click(function(player,element) Store.set(action_name_store,player.name,'command/ban') end) diff --git a/expcore/gui.lua b/expcore/gui.lua index 18584b47..6cf395f1 100644 --- a/expcore/gui.lua +++ b/expcore/gui.lua @@ -1,71 +1,284 @@ --[[-- Core Module - Gui + - This file is used to require all the different elements of the gui module + - each module has an outline here but for more details see their separate files in ./gui + - please read the files for more documentation that cant be shown here + - please note there is a rework planned but not started @core Gui @alias Gui - -@usage-- Making the base button concept -local button = -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',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) -- 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, - name = properties.name, - caption = properties.caption, - tooltip = properties.tooltip - } - - else - element = parent.add{ - type = properties.type, - name = properties.name, - sprite = properties.sprite, - tooltip = properties.tooltip - } - - end - - -- 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-- Making a new button which has a custom style -local custom_button = -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) -: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) - -@usage-- Drawing a concept -custom_button:draw(game.player.gui.left) ]] -return require 'expcore.gui.core' \ No newline at end of file +local Gui = require 'expcore.gui.core' --- @dep expcore.gui.core + +--[[ + Core + + Gui.new_define(prototype) --- Used internally to create new element defines from a class prototype + Gui.draw(name,element) --- Draws a copy of the element define to the parent element, see draw_to + + Gui.categorize_by_player(element) --- A categorize function to be used with add_store, each player has their own value + Gui.categorize_by_force(element) --- A categorize function to be used with add_store, each force has its own value + Gui.categorize_by_surface(element) --- A categorize function to be used with add_store, each surface has its own value + + Gui.toggle_enabled(element) --- Will toggle the enabled state of an element + Gui.toggle_visible(element) --- Will toggle the visibility of an element + Gui.set_padding(element,up,down,left,right) --- Sets the padding for a gui element + Gui.set_padding_style(style,up,down,left,right) --- Sets the padding for a gui style + Gui.create_alignment(element,flow_name) --- Allows the creation of a right align flow to place elements into + Gui.destroy_if_valid(element) --- Destroys an element but tests for it being present and valid first + Gui.create_scroll_table(element,table_size,maximal_height,name) --- Creates a scroll area with a table inside, table can be any size + Gui.create_header(element,caption,tooltip,right_align,name) --- Creates a header section with a label and button area + + Prototype Constructor + + Constructor.event(event_name) --- Creates a new function to add functions to an event handler + Constructor.extend(new_prototype) --- Extents a prototype with the base functions of all gui prototypes, no metatables + Constructor.store(sync,callback) --- Creates a new function which adds a store to a gui define + Constructor.setter(value_type,key,second_key) --- Creates a setter function that checks the type when a value is set + + Base Prototype + + Prototype:uid() --- Gets the uid for the element define + Prototype:debug_name(value) --- Sets a debug alias for the define + Prototype:set_caption(value) --- Sets the caption for the element define + Prototype:set_tooltip(value) --- Sets the tooltip for the element define + Prototype:set_style(style,callback) --- Sets the style for the element define + Prototype:set_embedded_flow(state) --- Sets the element to be drawn inside a nameless flow, can be given a name using a function + + Prototype:set_pre_authenticator --- Sets an authenticator that blocks the draw function if check fails + Prototype:set_post_authenticator --- Sets an authenticator that disables the element if check fails + + Prototype:raise_event(event_name,...) --- Raises a custom event for this define, any number of params can be given + Prototype:draw_to(element,...) --- The main function for defines, when called will draw an instance of this define to the given element + + Prototype:get_store(category) --- Gets the value in this elements store, category needed if categorize function used + Prototype:set_store(category,value) --- Sets the value in this elements store, category needed if categorize function used + Prototype:clear_store(category) --- Sets the value in this elements store to nil, category needed if categorize function used +]] + +local Instances = require 'expcore.gui.instances' --- @dep expcore.gui.instances +Gui.new_instance_group = Instances.registers +Gui.get_instances = Instances.get_elements +Gui.add_instance = Instances.get_elements +Gui.update_instances = Instances.apply_to_elements +Gui.classes.instances = Instances +--[[ + Instances.has_categories(name) --- Returns if a instance group has a categorise function; must be registered + Instances.is_registered(name) --- Returns if the given name is a registered instance group + Instances.register(name,categorise) --- Registers the name of an instance group to allow for storing element instances + + Instances.add_element(name,element) --- Adds an element to the instance group under the correct category; must be registered + Instances.get_elements_raw(name,category) --- Gets all element instances without first removing any invalid ones; used internally and must be registered + Instances.get_valid_elements(name,category,callback) --- Gets all valid element instances and has the option of running a callback on those that are valid + + Instances.unregistered_add_element(name,category,element) --- A version of add_element that does not require the group to be registered + Instances.unregistered_get_elements(name,category,callback) --- A version of get_elements that does not require the group to be registered +]] + +local Button = require 'expcore.gui.elements.buttons' --- @dep expcore.gui.elements.buttons +Gui.new_button = Button.new_button +Gui.classes.button = Button +--[[ + Button.new_button(name) --- Creates a new button element define + + Button._prototype:on_click(player,element) --- Registers a handler for when the button is clicked + Button._prototype:on_left_click(player,element) --- Registers a handler for when the button is clicked with the left mouse button + Button._prototype:on_right_click(player,element) --- Registers a handler for when the button is clicked with the right mouse button + + Button._prototype:set_sprites(sprite,hovered_sprite,clicked_sprite) --- Adds sprites to a button making it a sprite button + Button._prototype:set_click_filter(filter,...) --- Adds a click / mouse button filter to the button + Button._prototype:set_key_filter(filter,...) --- Adds a control key filter to the button +]] + +local Checkbox = require 'expcore.gui.elements.checkbox' --- @dep expcore.gui.elements.checkbox +Gui.new_checkbox = Checkbox.new_checkbox +Gui.new_radiobutton = Checkbox.new_radiobutton +Gui.new_radiobutton_option_set = Checkbox.new_option_set +Gui.draw_option_set = Checkbox.draw_option_set +Gui.classes.checkbox = Checkbox +--[[ + Checkbox.new_checkbox(name) --- Creates a new checkbox element define + Checkbox._prototype_checkbox:on_element_update(callback) --- Registers a handler for when an element instance updates + Checkbox._prototype_checkbox:on_store_update(callback) --- Registers a handler for when the stored value updates + + Checkbox.new_radiobutton(name) --- Creates a new radiobutton element define + Checkbox._prototype_radiobutton:on_element_update(callback) --- Registers a handler for when an element instance updates + Checkbox._prototype_radiobutton:on_store_update(callback) --- Registers a handler for when the stored value updates + Checkbox._prototype_radiobutton:add_as_option(option_set,option_name) --- Adds this radiobutton to be an option in the given option set (only one can be true at a time) + + Checkbox.new_option_set(name,callback,categorize) --- Registers a new option set that can be linked to radiobuttons (only one can be true at a time) + Checkbox.draw_option_set(name,element) --- Draws all radiobuttons that are part of an option set at once (Gui.draw will not work) + + Checkbox.reset_radiobutton(element,exclude,recursive) --- Sets all radiobuttons in a element to false (unless excluded) and can act recursively +]] + +local Dropdown = require 'expcore.gui.elements.dropdown' --- @dep expcore.gui.elements.dropdown +Gui.new_dropdown = Dropdown.new_dropdown +Gui.new_list_box = Dropdown.new_list_box +Gui.classes.dropdown = Dropdown +--[[ + Dropdown.new_dropdown(name) --- Creates a new dropdown element define + Dropdown.new_list_box(name) --- Creates a new list box element define + + Dropdown._prototype:on_element_update(callback) --- Registers a handler for when an element instance updates + Dropdown._prototype:on_store_update(callback) --- Registers a handler for when the stored value updates + + Dropdown._prototype:new_static_options(options,...) --- Adds new static options to the dropdown which will trigger the general callback + Dropdown._prototype:new_dynamic_options(callback) --- Adds a callback which should return a table of values to be added as options for the dropdown (appended after static options) + Dropdown._prototype:add_option_callback(option,callback) --- Adds a case specific callback which will only run when that option is selected (general case still triggered) + + Dropdown.select_value(element,value) --- Selects the option from a dropdown or list box given the value rather than key + Dropdown.get_selected_value(element) --- Returns the currently selected value rather than index +]] + +local Slider = require 'expcore.gui.elements.slider' --- @dep expcore.gui.elements.slider +Gui.new_slider = Slider.new_slider +Gui.classes.slider = Slider +--[[ + Slider.new_slider(name) --- Creates a new slider element define + + Slider._prototype:on_element_update(callback) --- Registers a handler for when an element instance updates + Slider._prototype:on_store_update(callback) --- Registers a handler for when the stored value updates + + Slider._prototype:set_range(min,max) --- Sets the range of a slider, if not used will use default values for a slider + Slider._prototype:draw_label(element) --- Draws a new label and links its value to the value of this slider, if no store then it will only show one value per player + Slider._prototype:enable_auto_draw_label(state) --- Enables auto draw of the label, the label will share the same parent element as the slider +]] + +local Text = require 'expcore.gui.elements.text' --- @dep expcore.gui.elements.text +Gui.new_text_filed = Text.new_text_field +Gui.new_text_box = Text.new_text_box +Gui.classes.text = Text +--[[ + Text.new_text_field(name) --- Creates a new text field element define + Text._prototype_field:on_element_update(callback) --- Registers a handler for when an element instance updates + Text._prototype_field:on_store_update(callback) --- Registers a handler for when the stored value updates + + Text.new_text_box(name) --- Creates a new text box element define + Text._prototype_field:on_element_update(callback) --- Registers a handler for when an element instance updates + Text._prototype_field:on_store_update(callback) --- Registers a handler for when the stored value updates + Text._prototype_box:set_selectable(state) --- Sets the text box to be selectable + Text._prototype_box:set_word_wrap(state) --- Sets the text box to have word wrap + Text._prototype_box:set_read_only(state) --- Sets the text box to be read only +]] + +local ElemButton = require 'expcore.gui.elements.elem-button' --- @dep expcore.gui.elements.elem-button +Gui.new_elem_button = ElemButton.new_elem_button +Gui.classes.elem_button = ElemButton +--[[ + ElemButton.new_elem_button(name) --- Creates a new elem button element define + + ElemButton._prototype:on_element_update(callback) --- Registers a handler for when an element instance updates + ElemButton._prototype:on_store_update(callback) --- Registers a handler for when the stored value updates + + ElemButton._prototype:set_type(type) --- Sets the type of the elem button, the type is required so this must be called at least once + ElemButton._prototype:set_default(value) --- Sets the default value for the elem button, this may be a function or a string +]] + +local ProgressBar = require 'expcore.gui.elements.progress-bar' --- @dep expcore.gui.elements.progress-bar +Gui.new_progressbar = ProgressBar.new_progressbar +Gui.set_progressbar_maximum = ProgressBar.set_maximum +Gui.increment_progressbar = ProgressBar.increment +Gui.decrement_progressbar = ProgressBar.decrement +Gui.classes.progressbar = ProgressBar +--[[ + ProgressBar.set_maximum(element,amount,count_down) --- Sets the maximum value that represents the end value of the progress bar + ProgressBar.increment(element,amount) --- Increases the value of the progressbar, if a define is given all of its instances are incremented + ProgressBar.decrement(element,amount) --- Decreases the value of the progressbar, if a define is given all of its instances are decreased + + ProgressBar.new_progressbar(name) --- Creates a new progressbar element define + ProgressBar._prototype:set_maximum(amount,count_down) --- Sets the maximum value that represents the end value of the progress bar + ProgressBar._prototype:use_count_down(state) --- Will set the progress bar to start at 1 and trigger when it hits 0 + ProgressBar._prototype:increment(amount,category) --- Increases the value of the progressbar + ProgressBar._prototype:increment_filtered(amount,filter) --- Increases the value of the progressbar, if the filter condition is met, does not work with store + ProgressBar._prototype:decrement(amount,category) --- Decreases the value of the progressbar + ProgressBar._prototype:decrement_filtered(amount,filter) --- Decreases the value of the progressbar, if the filter condition is met, does not work with store + ProgressBar._prototype:add_element(element,maximum) --- Adds an element into the list of instances that will are waiting to complete, does not work with store + ProgressBar._prototype:reset_element(element) --- Resets an element, or its store, to be back at the start, either 1 or 0 + + ProgressBar._prototype:on_complete(callback) --- Triggers when a progress bar element completes (hits 0 or 1) + ProgressBar._prototype:on_complete(callback) --- Triggers when a store value completes (hits 0 or 1) + ProgressBar._prototype:event_counter(filter) --- Event handler factory that counts up by 1 every time the event triggers, can filter which elements are incremented + ProgressBar._prototype:event_countdown(filter) --- Event handler factory that counts down by 1 every time the event triggers, can filter which elements are decremented +]] + +local Toolbar = require 'expcore.gui.concepts.toolbar' --- @dep expcore.gui.concepts.toolbar +Gui.new_toolbar_button = Toolbar.new_button +Gui.add_button_to_toolbar = Toolbar.add_button +Gui.update_toolbar = Toolbar.update +Gui.classes.toolbar = Toolbar +--[[ + Toolbar.new_button(name) --- Adds a new button to the toolbar + Toolbar.add_button(button) --- Adds an existing buttton to the toolbar + Toolbar.update(player) --- Updates the player's toolbar with an new buttons or expected change in auth return +]] + +local LeftFrames = require 'expcore.gui.concepts.left' --- @dep expcore.gui.concepts.left +Gui.get_left_frame_flow = LeftFrames.get_flow +Gui.toggle_left_frame = LeftFrames.toggle_frame +Gui.new_left_frame = LeftFrames.new_frame +Gui.classes.left_frames = LeftFrames +--[[ + LeftFrames.get_flow(player) --- Gets the left frame flow for a player + LeftFrames.get_frame(name,player) --- Gets one frame from the left flow by its name + LeftFrames.get_open(player) --- Gets all open frames for a player, if non are open it will remove the close all button + LeftFrames.toggle_frame(name,player,state) --- Toggles the visibility of a left frame, or sets its visibility state + + LeftFrames.new_frame(permission_name) --- Creates a new left frame define + LeftFrames._prototype:set_open_by_default(state) --- Sets if the frame is visible when a player joins, can also be a function to return a boolean + LeftFrames._prototype:set_direction(direction) --- Sets the direction of the frame, either vertical or horizontal + LeftFrames._prototype:get_frame(player) --- Gets the frame for this define from the left frame flow + LeftFrames._prototype:is_open(player) --- Returns if the player currently has this define visible + LeftFrames._prototype:toggle(player) --- Toggles the visibility of the left frame + + LeftFrames._prototype:update(player) --- Updates the contents of the left frame, first tries update callback, other wise will clear and redraw + LeftFrames._prototype:update_all(update_offline) --- Updates the frame for all players, see update + LeftFrames._prototype:redraw(player) --- Redraws the frame by calling on_draw, will always clear the frame + LeftFrames._prototype:redraw_all(update_offline) --- Redraws the frame for all players, see redraw + + LeftFrames._prototype:on_draw(player,frame) --- Use to draw your elements to the new frame + LeftFrames._prototype:on_update(player,frame) --- Use to edit your frame when there is no need to redraw it + LeftFrames._prototype:on_player_toggle(player,frame) --- Triggered when the player toggle the left frame + LeftFrames._prototype:event_handler(action) --- Creates an event handler that will trigger one of its functions, use with Event.add +]] + +local CenterFrames = require 'expcore.gui.concepts.center' --- @dep expcore.gui.concepts.center +Gui.get_center_flow = CenterFrames.get_flow +Gui.toggle_center_frame = CenterFrames.toggle_frame +Gui.draw_center_frame = CenterFrames.draw_frame +Gui.redraw_center_frame = CenterFrames.redraw_frames +Gui.new_center_frame = CenterFrames.new_frame +Gui.classes.center_frames = CenterFrames +--[[ + CenterFrames.get_flow(player) --- Gets the center flow for a player + CenterFrames.clear_flow(player) --- Clears the center flow for a player + CenterFrames.draw_frame(player,name) --- Draws the center frame for a player, if already open then will do nothing + CenterFrames.redraw_frame(player,name) --- Draws the center frame for a player, if already open then will destroy it and redraw + CenterFrames.toggle_frame(player,name,state) --- Toggles if the frame is currently open or not, will open if closed and close if open + + CenterFrames.new_frame(permission_name) --- Sets the frame to be the current active gui when opened and closes all other frames + CenterFrames._prototype:on_draw(player,frame) --- Use to draw your elements onto the new frame + CenterFrames._prototype:set_auto_focus(state) --- Sets the frame to be the current active gui when opened and closes all other frames + CenterFrames._prototype:draw_frame(player) --- Draws this frame to the player, if already open does nothing (will call on_draw to draw to the frame) + CenterFrames._prototype:redraw_frame(player) --- Draws this frame to the player, if already open it will remove it and redraw it (will call on_draw to draw to the frame) + CenterFrames._prototype:toggle_frame(player) --- Toggles if the frame is open, if open it will close it and if closed it will open it + CenterFrames._prototype:event_handler(action) --- Creates an event handler that will trigger one of its functions, use with Event.add +]] + +local PopupFrames = require 'expcore.gui.concepts.popups' --- @dep expcore.gui.concepts.popups +Gui.get_popup_flow = PopupFrames.get_flow +Gui.open_popup = PopupFrames.open +Gui.new_popup = PopupFrames.new_popup +Gui.classes.popup_frames = PopupFrames +--[[ + PopupFrames.get_flow(player) --- Gets the left flow that contains the popup frames + PopupFrames.open(define_name,player,open_time,...) --- Opens a popup for the player, can give the amount of time it is open as well as params for the draw function + + PopupFrames.close_progress --- Progress bar which when depleted will close the popup frame + PopupFrames.close_button --- A button which can be used to close the gui before the timer runs out + + PopupFrames.new_popup(name) --- Creates a new popup frame define + PopupFrames._prototype:set_default_open_time(amount) --- Sets the default open time for the popup, will be used if non is provided with open + PopupFrames._prototype:open(player,open_time,...) --- Opens this define for a player, can be given open time and any other params for the draw function +]] + +return Gui \ No newline at end of file diff --git a/expcore/gui/concepts/button.lua b/expcore/gui/concepts/button.lua deleted file mode 100644 index 4cbcc6cd..00000000 --- a/expcore/gui/concepts/button.lua +++ /dev/null @@ -1,90 +0,0 @@ ---[[-- Core Module - Gui - @module Gui - @alias Gui -]] - -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 Concepts.SpritePath sprite upto three sprites in the order: default, hovered, clicked - -@usage-- Making a basic button -local 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.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() -: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 -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',function(properties,value) - properties.caption = value - properties.type = 'button' -end) -: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', - sprite = properties.sprite, - hovered_sprite = properties.hovered_sprite, - clicked_sprite = properties.clicked_sprite, - tooltip = properties.tooltip - } - - else - -- Draw a button - element = parent.add{ - name = properties.name, - type = 'button', - caption = properties.caption, - tooltip = properties.tooltip - } - - end - - return element -end) \ No newline at end of file diff --git a/expcore/gui/concepts/center.lua b/expcore/gui/concepts/center.lua new file mode 100644 index 00000000..ffbc3f9f --- /dev/null +++ b/expcore/gui/concepts/center.lua @@ -0,0 +1,198 @@ +--[[-- Core Module - Gui + @module Gui + @alias Prototype +]] + +--- Center Guis. +-- Gui structure define for center gui frames +-- @section center + +--[[ +>>>> Functions + CenterFrames.get_flow(player) --- Gets the center flow for a player + CenterFrames.clear_flow(player) --- Clears the center flow for a player + CenterFrames.draw_frame(player,name) --- Draws the center frame for a player, if already open then will do nothing + CenterFrames.redraw_frame(player,name) --- Draws the center frame for a player, if already open then will destroy it and redraw + CenterFrames.toggle_frame(player,name,state) --- Toggles if the frame is currently open or not, will open if closed and close if open + + CenterFrames.new_frame(permission_name) --- Sets the frame to be the current active gui when opened and closes all other frames + CenterFrames._prototype:on_draw(player,frame) --- Use to draw your elements onto the new frame + CenterFrames._prototype:set_auto_focus(state) --- Sets the frame to be the current active gui when opened and closes all other frames + CenterFrames._prototype:draw_frame(player) --- Draws this frame to the player, if already open does nothing (will call on_draw to draw to the frame) + CenterFrames._prototype:redraw_frame(player) --- Draws this frame to the player, if already open it will remove it and redraw it (will call on_draw to draw to the frame) + CenterFrames._prototype:toggle_frame(player) --- Toggles if the frame is open, if open it will close it and if closed it will open it + CenterFrames._prototype:event_handler(action) --- Creates an event handler that will trigger one of its functions, use with Event.add +]] +local Gui = require 'expcore.gui.core' --- @dep expcore.gui.core +local Prototype = require 'expcore.gui.prototype' --- @dep expcore.gui.prototype +local Toolbar = require 'expcore.gui.concepts.toolbar' --- @dep expcore.gui.concepts.toolbar +local Game = require 'utils.game' --- @dep utils.game + +local CenterFrames = { + _prototype = Prototype.extend{ + on_creation = Prototype.event + } +} + +--- Gets the center flow for a player +-- @tparam LuaPlayer player the player to get the flow for +-- @treturn LuaGuiElement the center flow +function CenterFrames.get_flow(player) + player = Game.get_player_from_any(player) + return player.gui.center +end + +--- Clears the center flow for a player +-- @tparam LuaPlayer player the player to clear the flow for +function CenterFrames.clear_flow(player) + local flow = CenterFrames.get_flow(player) + flow.clear() +end + +--- Draws the center frame for a player, if already open then will do nothing +-- @tparam LuaPlayer player the player that will have the frame drawn +-- @tparam string name the name of the hui that will drawn +-- @treturn LuaGuiElement the new frame that was made +function CenterFrames.draw_frame(player,name) + local define = Gui.get_define(name,true) + if define then + return define:draw_frame(player) + end +end + +--- Draws the center frame for a player, if already open then will destroy it and redraw +-- @tparam LuaPlayer player the player that will have the frame drawn +-- @tparam string name the name of the hui that will drawn +-- @treturn LuaGuiElement the new frame that was made +function CenterFrames.redraw_frame(player,name) + local define = Gui.get_define(name,true) + if define then + return define:draw_frame(player) + end +end + +--- Toggles if the frame is currently open or not, will open if closed and close if open +-- @tparam LuaPlayer player the player that will have the frame toggled +-- @tparam string name the name of the hui that will be toggled +-- @tparam[opt] boolean state when set will force a state for the frame +-- @treturn boolean if the frame if no open or closed +function CenterFrames.toggle_frame(player,name,state) + local define = Gui.get_define(name,true) + if define then + if state == true then + define:draw_frame(player) + return true + elseif state == false then + local flow = CenterFrames.get_flow(player) + if flow[define.name..'-frame'] then + flow[define.name..'-frame'].destroy() + end + return false + else + return define:toggle_frame(player) + end + end +end + +--- Creates a new center frame define +-- @tparam string permission_name the name that can be used with the permission system +-- @treturn table the new center frame define +function CenterFrames.new_frame(permission_name) + local self = Toolbar.new_button(permission_name) + + self:on_click(function(player,element) + self:toggle_frame(player) + end) + + local mt = getmetatable(self) + mt.__index = CenterFrames._prototype + mt.__call = self.event_handler + + Gui.on_custom_close(self.name..'-frame',function(event) + local element = event.element + if element and element.valid then element.destroy() end + end) + + return self +end + +--- Sets the frame to be the current active gui when opened and closes all other frames +-- @tparam[opt=true] boolean state when true will auto close other frames and set this frame as player.opened +function CenterFrames._prototype:set_auto_focus(state) + if state == false then + self.auto_focus = false + else + self.auto_focus = true + end +end + +--- Draws this frame to the player, if already open does nothing (will call on_draw to draw to the frame) +-- @tparam LuaPlayer player the player to draw the frame for +-- @treturn LuaGuiElement the new frame that was drawn +function CenterFrames._prototype:draw_frame(player) + player = Game.get_player_from_any(player) + local flow = CenterFrames.get_flow(player) + + if flow[self.name..'-frame'] then + return flow[self.name..'-frame'] + end + + if self.auto_focus then + flow.clear() + end + + local frame = flow.add{ + type='frame', + name=self.name..'-frame' + } + + if self.auto_focus then + player.opened = frame + end + + self:raise_event('on_creation',player,frame) + + return frame +end + +--- Draws this frame to the player, if already open it will remove it and redraw it (will call on_draw to draw to the frame) +-- @tparam LuaPlayer player the player to draw the frame for +-- @treturn LuaGuiElement the new frame that was drawn +function CenterFrames._prototype:redraw_frame(player) + player = Game.get_player_from_any(player) + local flow = CenterFrames.get_flow(player) + + if flow[self.name..'-frame'] then + flow[self.name..'-frame'].destroy() + end + + return self:draw_frame(player) +end + +--- Toggles if the frame is open, if open it will close it and if closed it will open it +-- @tparam LuaPlayer player the player to draw the frame for +-- @treturn boolean with the gui frame is now open +function CenterFrames._prototype:toggle_frame(player) + player = Game.get_player_from_any(player) + local flow = CenterFrames.get_flow(player) + + if flow[self.name..'-frame'] then + flow[self.name..'-frame'].destroy() + return false + else + self:draw_frame(player) + return true + end +end + +--- Creates an event handler that will trigger one of its functions, use with Event.add +-- @tparam[opt=update] string action the action to take on this event +function CenterFrames._prototype:event_handler(action) + action = action or 'update' + return function(event) + local player = Game.get_player_by_index(event.player_index) + self[action](self,player) + end +end + +return CenterFrames \ No newline at end of file diff --git a/expcore/gui/concepts/checkbox.lua b/expcore/gui/concepts/checkbox.lua deleted file mode 100644 index 364d9624..00000000 --- a/expcore/gui/concepts/checkbox.lua +++ /dev/null @@ -1,62 +0,0 @@ ---[[-- Core Module - Gui - @module Gui - @alias Gui -]] - -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.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() -: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',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', - caption = properties.caption, - tooltip = properties.tooltip, - state = state - } - - -- Set the default state - default = Gui.resolve_property(default,element) - if default and default ~= state then - element.state = default - end - - return element -end) \ No newline at end of file diff --git a/expcore/gui/concepts/dropdown.lua b/expcore/gui/concepts/dropdown.lua deleted file mode 100644 index 40e10afc..00000000 --- a/expcore/gui/concepts/dropdown.lua +++ /dev/null @@ -1,169 +0,0 @@ ---[[-- Core Module - Gui - @module Gui - @alias Gui -]] - -local Gui = require 'expcore.gui.core' -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 -local 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.new_concept('dropdown') -:set_dynamic_items(function(element) - local items = {} - for _,player in pairs(game.connected_players) do - items[#items+1] = player.name - end - return items -end) -:on_selection_changed(function(event) - local value = Gui.get_dropdown_value(event.element) - event.player.print('Dynamic dropdown is now: '..value) -end) - -]] - -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',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',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) - --- 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 = 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) - Gui.add_dropdown_items(element,start_index,dynamic_items) - 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) - end - - return element -end) - ---- Dropdowns. --- functions used with dropdowns --- @section dropdowns - ---[[-- Selects the index of a dropdown with this value -@tparam LuaGuiElement element the dropdown that you want to set the selection for -@tparam ?string|Concepts.LocalisedString value the value that you want selected -@treturn boolean if an item with this value was found -@usage-- Selecting the item with the value 'foo' -Gui.set_dropdown_value(element,'foo') -]] -function Gui.set_dropdown_value(element,value) - for index, item in pairs(element.items) do - if item == value then - element.selected_index = index - return true - end - end - return false -end - ---[[-- Gets the selected item value of a dropdown -@tparam LuaGuiElement element the dropdown that you want the selected value of -@treturn ?string|Concepts.LocalisedString the value that is currently selected -@usage-- Getting the selected value -local selected_value = Gui.get_dropdown_value(element) -]] -function Gui.get_dropdown_value(element) - return element.items[element.selected_index] -end - ---[[-- Adds the given items into the list of items for this dropdown -@tparam LuaGuiElement element the dropdown that you want to add the items to -@tparam[opt] number start_index the index at which the items will be added, if not given appened to the end -@tparam table new_items the list of new items that you want to add -@treturn table the list of items that the element now has -@usage-- Add the items 'foo' and 'bar' to the end -Gui.add_dropdown_items(element,{'foo','bar'}) -@usage-- Add the items 'foo' and 'bar' to the start -Gui.add_dropdown_items(element,1,{'foo','bar'}) -]] -function Gui.add_dropdown_items(element,start_index,new_items) - if not new_items then - new_items = start_index - start_index = nil - end - - local items = element.items - element.items = array_insert(items,start_index,new_items) - - return items -end \ No newline at end of file diff --git a/expcore/gui/concepts/elem_button.lua b/expcore/gui/concepts/elem_button.lua deleted file mode 100644 index 4318b181..00000000 --- a/expcore/gui/concepts/elem_button.lua +++ /dev/null @@ -1,51 +0,0 @@ ---[[-- Core Module - Gui - @module Gui - @alias Gui -]] - -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.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() -:save_as('elem_button') - --- Events -:new_event('on_selection_changed',defines.events.on_gui_elem_changed) - --- Properties -:new_property('default') -: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 - end - - return element -end) \ No newline at end of file diff --git a/expcore/gui/concepts/empty.lua b/expcore/gui/concepts/empty.lua deleted file mode 100644 index 46c0233a..00000000 --- a/expcore/gui/concepts/empty.lua +++ /dev/null @@ -1,36 +0,0 @@ ---[[-- Core Module - Gui - @module Gui - @alias Gui -]] - -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.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', - style = properties.style - } - - return element -end) \ No newline at end of file diff --git a/expcore/gui/concepts/flow.lua b/expcore/gui/concepts/flow.lua deleted file mode 100644 index b4af20d4..00000000 --- a/expcore/gui/concepts/flow.lua +++ /dev/null @@ -1,42 +0,0 @@ ---[[-- Core Module - Gui - @module Gui - @alias Gui -]] - -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.new_concept('flow') -:define_draw(function(properties,parent,element) - element.add{ - type = 'label', - caption = 'Hello, World!' - } -end) - -]] - -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', - caption = properties.title, - direction = properties.direction - } - - return element -end) \ No newline at end of file diff --git a/expcore/gui/concepts/frame.lua b/expcore/gui/concepts/frame.lua deleted file mode 100644 index 6a216353..00000000 --- a/expcore/gui/concepts/frame.lua +++ /dev/null @@ -1,45 +0,0 @@ ---[[-- Core Module - Gui - @module Gui - @alias Gui -]] - -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.new_concept('frame') -:set_title('Basic Frame') -:define_draw(function(properties,parent,element) - element.add{ - type = 'label', - caption = 'Hello, World!' - } -end) - -]] - -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', - caption = properties.title, - direction = properties.direction - } - - return element -end) \ No newline at end of file diff --git a/expcore/gui/concepts/label.lua b/expcore/gui/concepts/label.lua deleted file mode 100644 index 9c2df448..00000000 --- a/expcore/gui/concepts/label.lua +++ /dev/null @@ -1,46 +0,0 @@ ---[[-- Core Module - Gui - @module Gui - @alias Gui -]] - -local Gui = require 'expcore.gui.core' - ---[[-- A piece of text. -@element label - -@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.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', - caption = properties.caption, - 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/left.lua b/expcore/gui/concepts/left.lua new file mode 100644 index 00000000..e827f36a --- /dev/null +++ b/expcore/gui/concepts/left.lua @@ -0,0 +1,322 @@ +--[[-- Core Module - Gui + @module Gui + @alias Prototype +]] + +--- Left Guis. +-- Gui structure define for left frames +-- @section left + +--[[ +>>>> Example formating + + -- first we add config that relates to the button on the toolbar, all normal button functions are present + local left_frame = + Gui.new_left_frame('test-left-frame') + :set_caption('Test Left Gui') + :set_post_authenticator(function(player,button_name) + return global.show_test_gui + end) + + -- then we add the config for the left frame, on_draw should draw the gui from an empty frame, on_update should take a frame from on_draw on edit it + :set_open_by_default() + :on_draw(function(_player,frame) + for _,player in pairs(game.connected_players) do + frame.add{ + type='label', + caption=player.name + } + end + end) + + -- now we can use the action factory to call events on the gui, actions are: 'update', 'update_all', 'redraw', 'redraw_all' + Event.add(defines.events.on_player_joined_game,left_frame 'update_all') + Event.add(defines.events.on_player_left_game,left_frame 'update_all') + +>>>> Functions + LeftFrames.get_flow(player) --- Gets the left frame flow for a player + LeftFrames.get_frame(name,player) --- Gets one frame from the left flow by its name + LeftFrames.get_open(player) --- Gets all open frames for a player, if non are open it will remove the close all button + LeftFrames.toggle_frame(name,player,state) --- Toggles the visibility of a left frame, or sets its visibility state + + LeftFrames.new_frame(permission_name) --- Creates a new left frame define + LeftFrames._prototype:set_open_by_default(state) --- Sets if the frame is visible when a player joins, can also be a function to return a boolean + LeftFrames._prototype:set_direction(direction) --- Sets the direction of the frame, either vertical or horizontal + LeftFrames._prototype:get_frame(player) --- Gets the frame for this define from the left frame flow + LeftFrames._prototype:is_open(player) --- Returns if the player currently has this define visible + LeftFrames._prototype:toggle(player) --- Toggles the visibility of the left frame + + LeftFrames._prototype:update(player) --- Updates the contents of the left frame, first tries update callback, other wise will clear and redraw + LeftFrames._prototype:update_all(update_offline) --- Updates the frame for all players, see update + LeftFrames._prototype:redraw(player) --- Redraws the frame by calling on_draw, will always clear the frame + LeftFrames._prototype:redraw_all(update_offline) --- Redraws the frame for all players, see redraw + + LeftFrames._prototype:on_draw(player,frame) --- Use to draw your elements to the new frame + LeftFrames._prototype:on_update(player,frame) --- Use to edit your frame when there is no need to redraw it + LeftFrames._prototype:on_player_toggle(player,frame) --- Is triggered when the player presses the toggle button + LeftFrames._prototype:event_handler(action) --- Creates an event handler that will trigger one of its functions, use with Event.add +]] +local Gui = require 'expcore.gui.core' --- @dep expcore.gui.core +local Prototype = require 'expcore.gui.prototype' --- @dep expcore.gui.prototype +local Toolbar = require 'expcore.gui.concepts.toolbar' --- @dep expcore.gui.concepts.toolbar +local Buttons = require 'expcore.gui.elements.buttons' --- @dep expcore.gui.elements.buttons +local mod_gui = require 'mod-gui' --- @dep mod-gui +local Game = require 'utils.game' --- @dep utils.game +local Event = require 'utils.event' --- @dep utils.event + +local LeftFrames = { + frames={}, + _prototype=Prototype.extend{ + on_creation = Prototype.event, + on_update = Prototype.event, + on_player_toggle = Prototype.event + } +} +setmetatable(LeftFrames._prototype, { + __index = Buttons._prototype +}) + +--- Gets the left frame flow for a player +-- @tparam LuaPlayer player the player to get the flow of +-- @treturn LuaGuiElement the left frame flow for the player +function LeftFrames.get_flow(player) + player = Game.get_player_from_any(player) + return mod_gui.get_frame_flow(player) +end + +--- Gets one frame from the left flow by its name +-- @tparam string name the name of the gui frame to get +-- @tparam LuaPlayer player the player to get the frame of +-- @treturn LuaGuiElement the frame in the left frame flow with that name +function LeftFrames.get_frame(name,player) + local define = LeftFrames.frames[name] + if not define then + return error('Left Frame '..name..' is not defined.',2) + end + return define:get_frame(player) +end + +--- Gets all open frames for a player, if non are open it will remove the close all button +-- @tparam LuaPlayer player the player to get the flow of +-- @treturn table contains all the open (and registered) frames for the player +function LeftFrames.get_open(player) + local open = {} + local flow = LeftFrames.get_flow(player) + + for _,define in pairs(LeftFrames.frames) do + if define:is_open(player) then + table.insert(open,define) + end + end + + flow[LeftFrames.toggle_button.name].visible = #open ~= 0 + + return open +end + +--- Toggles the visibility of a left frame, or sets its visibility state +-- @tparam string name the name of the gui frame to toggle +-- @tparam LuaPlayer player the player to get the frame of +-- @tparam[opt] boolean state when given will be the state that the visibility is set to +-- @treturn boolean the new state of the visibility +function LeftFrames.toggle_frame(name,player,state) + local define = LeftFrames.frames[name] + if not define then + return error('Left Frame '..name..' is not defined.',2) + end + + local frame = LeftFrames.get_frame(name,player) + if state ~= nil then + frame.visible = state + else + Gui.toggle_visible(frame) + end + + LeftFrames.get_open(player) + + return frame.visible +end + +--- Creates a new left frame define +-- @tparam string permission_name the name that can be used with the permission system +-- @treturn table the new left frame define +function LeftFrames.new_frame(permission_name) + local self = Toolbar.new_button(permission_name) + + local mt = getmetatable(self) + mt.__index = LeftFrames._prototype + mt.__call = self.event_handler + + self:on_click(function(player,_element) + local visible = self:toggle(player) + local frame = self:get_frame(player) + self:raise_event('on_player_toggle',player,frame,visible) + end) + + LeftFrames.frames[self.name] = self + + return self +end + +--- Sets if the frame is visible when a player joins, can also be a function to return a boolean +-- @tparam[opt=true] ?boolean|function state the default state of the visibility, can be a function +-- state param - player LuaPlayer - the player that has joined the game +-- state param - define_name string - the define name for the frame +-- state return - boolean - false will hide the frame +function LeftFrames._prototype:set_open_by_default(state) + if state == false then + self.open_by_default = false + elseif state == nil then + self.open_by_default = true + else + self.open_by_default = state + end + return self +end + +--- Sets the direction of the frame, either vertical or horizontal +-- @tparam string direction the direction to have the elements be added to the frame +function LeftFrames._prototype:set_direction(direction) + self.direction = direction + return self +end + +--- Creates the gui for the first time, used internally +-- @tparam LuaPlayer player the player to draw the frame to +-- @treturn LuaGuiElement the frame that was made +function LeftFrames._prototype:_internal_draw(player) + local flow = LeftFrames.get_flow(player) + local frame = flow.add{ + type='frame', + name=self.name..'-frame', + direction=self.direction + } + + self:raise_event('on_creation',player,frame) + + if not self.open_by_default then + frame.visible = false + elseif type(self.open_by_default) == 'function' then + if not self.open_by_default(player,self.name) then + frame.visible = false + end + end + + if not Toolbar.allowed(player,self.name) then + frame.visible = false + end + + return frame +end + +--- Gets the frame for this define from the left frame flow +-- @tparam LuaPlayer player the player to get the frame of +-- @treturn LuaGuiElement the frame in the left frame flow for this define +function LeftFrames._prototype:get_frame(player) + local flow = LeftFrames.get_flow(player) + if flow[self.name..'-frame'] and flow[self.name..'-frame'].valid then + return flow[self.name..'-frame'] + else + return self:_internal_draw(player) + end +end + +--- Returns if the player currently has this define visible +-- @tparam LuaPlayer player the player to get the frame of +-- @treturn boolean true if it is open/visible +function LeftFrames._prototype:is_open(player) + local frame = self:get_frame(player) + return frame and frame.visible or false +end + +--- Toggles the visibility of the left frame +-- @tparam LuaPlayer player the player to toggle the frame of +-- @treturn boolean the new state of the visibility +function LeftFrames._prototype:toggle(player) + local frame = self:get_frame(player) + Gui.toggle_visible(frame) + LeftFrames.get_open(player) + return frame.visible +end + +--- Updates the contents of the left frame, first tries update callback, other wise will clear and redraw +-- @tparam LuaPlayer player the player to update the frame of +function LeftFrames._prototype:update(player) + local frame = self:get_frame(player) + if self:raise_event('on_update',player,frame) == 0 then + frame.clear() + self:raise_event('on_creation',player,frame) + end +end + +--- Updates the frame for all players, see update +-- @tparam[opt=false] boolean update_offline when true will update the frame for offline players +function LeftFrames._prototype:update_all(update_offline) + local players = update_offline == true and game.players or game.connected_players + for _,player in pairs(players) do + self:update(player) + end +end + +--- Redraws the frame by calling on_draw, will always clear the frame +-- @tparam LuaPlayer player the player to update the frame of +function LeftFrames._prototype:redraw(player) + local frame = self:get_frame(player) + frame.clear() + self:raise_event('on_creation',player,frame) +end + +--- Redraws the frame for all players, see redraw +-- @tparam[opt=false] boolean update_offline when true will update the frame for offline players +function LeftFrames._prototype:redraw_all(update_offline) + local players = update_offline == true and game.players or game.connected_players + for _,player in pairs(players) do + self:redraw(player) + end +end + +--- Creates an event handler that will trigger one of its functions, use with Event.add +-- @tparam[opt=update] string action the action to take on this event +function LeftFrames._prototype:event_handler(action) + action = action or 'update' + return function(event) + local player + if event and event.player_index then + player = Game.get_player_by_index(event.player_index) + end + self[action](self,player) + end +end + +LeftFrames.toggle_button = +Buttons.new_button() +:set_tooltip{'expcore-gui.left-button-tooltip'} +:set_caption('<') +:on_click(function(player,element) + for _,define in pairs(LeftFrames.frames) do + local frame = LeftFrames.get_frame(define.name,player) + frame.visible = false + define:raise_event('on_player_toggle',player,frame,false) + end + element.visible = false +end) + +Event.add(defines.events.on_player_created,function(event) + local player = Game.get_player_by_index(event.player_index) + local flow = LeftFrames.get_flow(player) + + local close_button = LeftFrames.toggle_button(flow) + Gui.set_padding(close_button) + local style = close_button.style + style.width = 18 + style.height = 36 + style.font = 'default-small-bold' + + for _,define in pairs(LeftFrames.frames) do + define:_internal_draw(player) + end + + LeftFrames.get_open(player) +end) + +return LeftFrames \ No newline at end of file diff --git a/expcore/gui/concepts/line.lua b/expcore/gui/concepts/line.lua deleted file mode 100644 index 28f41cc7..00000000 --- a/expcore/gui/concepts/line.lua +++ /dev/null @@ -1,35 +0,0 @@ ---[[-- Core Module - Gui - @module Gui - @alias Gui -]] - -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.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', - direction = properties.direction - } - - return element -end) \ No newline at end of file diff --git a/expcore/gui/concepts/popups.lua b/expcore/gui/concepts/popups.lua new file mode 100644 index 00000000..bda932b3 --- /dev/null +++ b/expcore/gui/concepts/popups.lua @@ -0,0 +1,230 @@ +--[[-- Core Module - Gui + @module Gui + @alias Prototype +]] + +--- Popups. +-- Gui structure define for popup gui +-- @section popups + +--[[ +>>>> Functions + PopupFrames.get_flow(player) --- Gets the left flow that contains the popup frames + PopupFrames.open(define_name,player,open_time,...) --- Opens a popup for the player, can give the amount of time it is open as well as params for the draw function + + PopupFrames.close_progress --- Progress bar which when depleted will close the popup frame + PopupFrames.close_button --- A button which can be used to close the gui before the timer runs out + + PopupFrames.new_popup(name) --- Creates a new popup frame define + PopupFrames._prototype:set_default_open_time(amount) --- Sets the default open time for the popup, will be used if non is provided with open + PopupFrames._prototype:open(player,open_time,...) --- Opens this define for a player, can be given open time and any other params for the draw function +]] +local Gui = require 'expcore.gui.core' --- @dep expcore.gui.core +local Prototype = require 'expcore.gui.prototype' --- @dep expcore.gui.prototype +local Game = require 'utils.game' --- @dep utils.game +local Event = require 'utils.event' --- @dep utils.event +local ProgressBar = require 'expcore.gui.elements.progress-bar' --- @dep expcore.gui.elements.progress-bar +local Button = require 'expcore.gui.elements.buttons' --- @dep expcore.gui.elements.buttons +local mod_gui = require 'mod-gui' --- @dep mod-gui +local Color = require 'resources.color_presets' --- @dep resources.color_presets +local Global = require 'utils.global' --- @dep utils.global + +local PopupFrames = { + paused_popups={}, + popup_flow_name = Gui.uid_name(), + main_frame_name = Gui.uid_name(), + close_frame_name = Gui.uid_name(), + _prototype = Prototype.extend{ + on_creation = Prototype.event + } +} +Global.register(PopupFrames.paused_popups,function(tbl) + PopupFrames.paused_popups = tbl +end) + +--- Sets the state of the element in the paused list, nil or true +-- @tparam LuaGuiElement element the element to set the state of +-- @tparam[opt] boolean state the state to set it to, true will pause the the progress bar +local function set_paused_state(element,state) + local name = element.player_index..':'..element.index + PopupFrames.paused_popups[name] = state +end + +--- Gets the state of the element in the paused list, nil or true +-- @tparam LuaGuiElement element the element to get the state of +local function get_paused_state(element) + local name = element.player_index..':'..element.index + return PopupFrames.paused_popups[name] +end + +--- Gets the left flow that contains the popup frames +-- @tparam LuaPlayer player the player to get the flow for +-- @treturn LuaGuiElement the left flow that contains the popup frames +function PopupFrames.get_flow(player) + player = Game.get_player_from_any(player) + local flow = mod_gui.get_frame_flow(player) + return flow[PopupFrames.popup_flow_name] +end + +--- Opens a popup for the player, can give the amount of time it is open as well as params for the draw function +-- @tparam string define_name the name of the define that you want to open for the player +-- @tparam LuaPlayer player the player to open the popup for +-- @tparam[opt] number open_time the minimum number of ticks you want the popup open for, 0 means no limit, nil will take default +-- @tparam any ... the other params that you want to pass to your on_draw event +-- @treturn LuaGuiElement the frame that was drawn, the inner gui flow which contains the content +function PopupFrames.open(define_name,player,open_time,...) + local define = Gui.get_define(define_name,true) + player = Game.get_player_from_any(player) + return define:open(player,open_time,...) +end + +--- Closes the popup, is called by progress bar and close button +-- @tparam LuaGuiElement element either the progress bar or the close button +local function close_popup(element) + local frame = element.parent.parent.parent + if not frame or not frame.valid then return end + set_paused_state(element.parent[PopupFrames.close_progress:uid()]) + frame.destroy() +end + +--- Progress bar which when depleted will close the popup frame +PopupFrames.close_progress = +ProgressBar.new_progressbar() +:use_count_down() +:set_tooltip('Pause/Resume Auto-close') +:on_complete(function(player,element) + close_popup(element) +end) + +--- A button which can be used to close the gui before the timer runs out +PopupFrames.close_button = +Button.new_button() +:set_sprites('utility/close_white') +:set_tooltip('Close Popup') +:on_click(function(player,element) + close_popup(element) +end) + +--- When the progress bar is clicked it will pause its progress, or resume if previously paused +Gui.on_click(PopupFrames.close_progress:uid(),function(event) + local element = event.element + if get_paused_state(element) then + set_paused_state(element) + else + set_paused_state(element,true) + end +end) + +--- When the parent flow of the progress bar is clicked it will pause its progress, or resume if previously paused +Gui.on_click(PopupFrames.close_frame_name,function(event) + local element = event.element[PopupFrames.close_progress:uid()] + if get_paused_state(element) then + set_paused_state(element) + else + set_paused_state(element,true) + end +end) + +--- Creates a new popup frame define +-- @tparam[opt] string name the optional debug name that can be added +-- @treturn table the new popup frame define +function PopupFrames.new_popup(name) + local self = Gui.new_define(PopupFrames._prototype,name) + self.draw_data.type = 'flow' + self.draw_data.direction = 'vertical' + + local mt = getmetatable(self) + mt.__call = function(tbl,player,open_time,...) + return tbl:open(player,open_time,...) + end + + self:on_draw(function(player,element,maximum,...) + -- main content frame + local frame = element.add{ + type='flow', + name=PopupFrames.main_frame_name + } + frame.style.horizontally_stretchable = true + + -- flow for progress bar and close button + local close_flow = element.add{ + type='flow', + name=PopupFrames.close_frame_name + } + close_flow.style.horizontally_stretchable = true + + -- progress bar, when 0 then a static full one is drawn + local progress_style + if maximum == 0 then + progress_style = close_flow.add{ + type='progressbar', + tooltip='No Auto-close', + value=1 + }.style + else + progress_style = PopupFrames.close_progress(close_flow,maximum).style + end + progress_style.top_padding = 6 + progress_style.bottom_padding = 3 + progress_style.height = 11 + progress_style.color = Color.grey + + -- close button, will close the popup when clicked + local close_button = PopupFrames.close_button(close_flow) + Gui.set_padding(close_button) + local close_button_style = close_button.style + close_button_style.width = 20 + close_button_style.height = 20 + + -- event trigger to draw the gui content + self:raise_event('on_creation',player,frame,...) + end) + + return self +end + +--- Sets the default open time for the popup, will be used if non is provided with open +-- @tparam number amount the number of ticks, by default, the popup will be open for +-- @treturn table the define to allow for chaining +function PopupFrames._prototype:set_default_open_time(amount) + self.default_open_time = amount + return self +end + +--- Opens this define for a player, can be given open time and any other params for the draw function +-- @tparam LuaPlayer player the player to open the popup for +-- @tparam[opt] number open_time the minimum number of ticks you want the popup open for, 0 means no limit, nil will take default +-- @tparam any ... the other params that you want to pass to your on_draw event +-- @treturn LuaGuiElement the frame that was drawn, the inner gui flow which contains the content +function PopupFrames._prototype:open(player,open_time,...) + open_time = open_time or self.default_open_time or 0 + player = Game.get_player_from_any(player) + + local flow = PopupFrames.get_flow(player) + local frame = flow.add{ + type='frame', + style='blurry_frame' + } + + Gui.set_padding(frame,3,3,4,4) + return self:draw_to(frame,open_time,...)[PopupFrames.main_frame_name] +end + +--- When player is first created the popup flow is added to they left flow +Event.add(defines.events.on_player_created,function(event) + local player = Game.get_player_by_index(event.player_index) + local flow = mod_gui.get_frame_flow(player) + + flow.add{ + type='flow', + direction='vertical', + name=PopupFrames.popup_flow_name + } +end) + +--- Every tick any, not paused, progress bars will go down by one tick +Event.add(defines.events.on_tick,PopupFrames.close_progress:event_countdown(function(element) + return not get_paused_state(element) +end)) + +return PopupFrames \ No newline at end of file diff --git a/expcore/gui/concepts/progress_bar.lua b/expcore/gui/concepts/progress_bar.lua deleted file mode 100644 index 4bcb0b8a..00000000 --- a/expcore/gui/concepts/progress_bar.lua +++ /dev/null @@ -1,168 +0,0 @@ ---[[-- Core Module - Gui - @module Gui - @alias Gui -]] - -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.new_concept('progress_bar') -:set_tooltip('Basic progress bar') -:set_maximum(5) -:new_event('on_click',defines.events.on_gui_click) -:on_click(function(event) - event.concept:increment(event.element) -end) -:set_delay_completion(true) -:on_completion(function(event) - event.concept:reset(event.element) -end) - -]] - -local progress_bar = -Gui.new_concept() -:save_as('progress_bar') - --- Events -:new_event('on_completion') - --- Properties -:new_property('tooltip') -: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, - type = 'progressbar', - value = properties.inverted and 1 or 0 - } - - return element -end) - ---- Progress Bars. --- functions used with progress bars --- @section progress_bars - --- logic for changing the value of a progress bar -local function raw_update(concept,element,amount) - local old_value = element.value - local new_value = old_value + amount - element.value = new_value - - local check_value = concept.properties.delay_completion and old_value or new_value - if amount < 0 and check_value <= 0 or amount > 0 and check_value >= 1 then - concept:raise_event('on_completion',{ - element = element - }) - else - return new_value - - end - -end - ---[[-- Will increase the progress of a progress bar based on this concept, if the concept has an instance store then element acts as the category, if you have a combined store it will NOT update all instances -@tparam ?LuaGuiElement|string element either the element that is changed or the category that is being changed (only if an instance store is defined) -@tparam[opt=1] number amount the amount that will bar will increase, note that this amount must be less than the max -@treturn ?number|nil the new value of the element, use this to sync a data store, if the return is nil then either a instance store was used or the new value may have changed -@usage-- Incrementing progress bar with no instance store -local new_value = progress_bar:increment(element) -@usage-- Incrementing progress bar with an instance store -progress_bar:increment(category) -]] -function progress_bar:increment(element,amount) - local properties = self.properties - local inverted = properties.inverted - local maximum = properties.maximum - amount = amount and amount/maximum or 1/maximum - amount = inverted and -amount or amount - - if self.instance_store and not self.sync_instance then - self.update_instances(element,function(next_element) - raw_update(self,next_element,amount) - end) - - else - return raw_update(self,element,amount) - - end -end - ---[[-- Will decrease the progress of a progress bar based on this concept, if the concept has an instance store then element acts as the category, if you have a combined store it will NOT update all instances -@tparam ?LuaGuiElement|string element either the element that is changed or the category that is being changed (only if an instance store is defined) -@tparam[opt=1] number amount the amount that will bar will decrease, note that this amount must be less than the max -@treturn number the new value of the element, use this to sync a data store, if the return is nil then either a instance store was used or the new value may have changed -@usage-- Decrementing progress bar with no instance store -local new_value = progress_bar:decrement(element) -@usage-- Decrementing progress bar with an instance store -progress_bar:decrement(category) -]] -function progress_bar:decrement(element,amount) - self:increment(element,-amount) -end - ---[[-- Resets the progress back to 0% for this element, if the concept has an instance store then element acts as the category, if you have a combined store it will NOT update all instances -@tparam ?LuaGuiElement|string element either the element that is changed or the category that is being changed (only if an instance store is defined) -@treturn ?number|nil the new value of the element, use this to sync a data store, if the return is nil then either a instance store was used or the new value may have changed -@usage-- Reseting a progress bar with no instance store -local new_value = progress_bar:reset(element) -@usage-- Reseting a progress bar with an instance store -progress_bar:reset(category) -]] -function progress_bar:reset(element) - local new_value = self.properties.inverted and 1 or 0 - if self.instacne_store and not self.sync_instance then - self.update_instances(element,function(next_element) - next_element.value = new_value - end) - - else - element.value = new_value - return new_value - - end -end - ---[[-- Increment any progress bar by the given percentage -@tparam LuaGuiElement element the progress bar that you want to update -@tparam[opt=0.01] number amount the percentage that you want to increment the progress bar by -@treturn boolean true if the bar is now full -@usage-- Increment any progress bar by 10% -Gui.increment_progress_bar(element,0.1) -]] -function Gui.increment_progress_bar(element,amount) - amount = amount or 0.01 - element.value = element.value + amount - return element.value >= 1 -end - ---[[-- Decrement any progress bar by the given percentage -@tparam LuaGuiElement element the progress bar that you want to update -@tparam[opt=0.01] number amount the percentage that you want to decrement the progress bar by -@treturn boolean true if the bar is now empty -@usage-- Decrement any progress bar by 10% -Gui.decrement_progress_bar(element,0.1) -]] -function Gui.decrement_progress_bar(element,amount) - amount = amount or 0.01 - element.value = element.value - amount - return element.value <= 0 -end \ No newline at end of file diff --git a/expcore/gui/concepts/scroll.lua b/expcore/gui/concepts/scroll.lua deleted file mode 100644 index 034766f7..00000000 --- a/expcore/gui/concepts/scroll.lua +++ /dev/null @@ -1,47 +0,0 @@ ---[[-- Core Module - Gui - @module Gui - @alias Gui -]] - -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.new_concept('scroll') -:define_draw(function(properties,parent,element) - element.style.hieght = 50 - for i = 1,10 do - element.add{ - type = 'label', - caption = i - } - end -end) - -]] - -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', - horizontal_scroll_policy = properties.horizontal_scroll, - vertical_scroll_policy = properties.vertical_scroll - } - - return element -end) \ No newline at end of file diff --git a/expcore/gui/concepts/slider.lua b/expcore/gui/concepts/slider.lua deleted file mode 100644 index 703fe102..00000000 --- a/expcore/gui/concepts/slider.lua +++ /dev/null @@ -1,91 +0,0 @@ ---[[-- Core Module - Gui - @module Gui - @alias Gui -]] - -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.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.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() -: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',nil,false) -:new_property('range',function(properties,minimum,maximum) - if type(minimum) == 'function' then - properties.range = minimum - else - properties.minimum = minimum - 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', - caption = properties.caption, - minimum_value = properties.minimum, - maximum_value = properties.maximum, - discrete_slider = properties.discrete_slider, - discrete_values = value_step ~= nil, - value_step = value_step, - 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() - max = max or element.get_slider_maximum() - 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 - end - - return element -end) \ No newline at end of file diff --git a/expcore/gui/concepts/table.lua b/expcore/gui/concepts/table.lua deleted file mode 100644 index 3a7ae3bf..00000000 --- a/expcore/gui/concepts/table.lua +++ /dev/null @@ -1,58 +0,0 @@ ---[[-- Core Module - Gui - @module Gui - @alias Gui -]] - -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.new_concept('table') -:set_column_count(5) -:define_draw(function(properties,parent,element) - for i = 1,25 do - element.add{ - type = 'lable', - caption = i - } - end -end) - -]] - -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', - column_count = column_count, - draw_vertical_lines = properties.vertical_lines, - draw_horizontal_lines = properties.horizontal_lines, - draw_horizontal_line_after_headers = properties.header_lines, - vertical_centering = properties.vertical_centering - } - - return element -end) \ No newline at end of file diff --git a/expcore/gui/concepts/text_box.lua b/expcore/gui/concepts/text_box.lua deleted file mode 100644 index 122ba17f..00000000 --- a/expcore/gui/concepts/text_box.lua +++ /dev/null @@ -1,84 +0,0 @@ ---[[-- Core Module - Gui - @module Gui - @alias Gui -]] - -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.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.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() -: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('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', - tooltip = properties.tooltip, - clear_and_focus_on_right_click = properties.clear_on_rmb, - 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/text_field.lua b/expcore/gui/concepts/text_field.lua deleted file mode 100644 index dd8f862d..00000000 --- a/expcore/gui/concepts/text_field.lua +++ /dev/null @@ -1,100 +0,0 @@ ---[[-- Core Module - Gui - @module Gui - @alias Gui -]] - -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.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.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.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() -: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('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', - tooltip = properties.tooltip, - clear_and_focus_on_right_click = properties.clear_on_rmb, - lose_focus_on_confirm = properties.lose_forcus, - numeric = properties.is_number or properties.is_decimal or properties.is_negative, - allow_decimal = properties.is_decimal, - allow_negative = properties.is_negative, - is_password = properties.is_password, - text = text - } - - -- 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/toolbar.lua b/expcore/gui/concepts/toolbar.lua new file mode 100644 index 00000000..10a8d971 --- /dev/null +++ b/expcore/gui/concepts/toolbar.lua @@ -0,0 +1,114 @@ +--[[-- Core Module - Gui + @module Gui + @alias Prototype +]] + +--- Toolbar. +-- Gui structure for the toolbar (top left) +-- @section toolbar + +--[[ +>>>> Example format + -- this is the same as any other button define, this just automatically draws it + -- you can use add_button if you already defined the button + local toolbar_button = + Toolbar.new_button('print-click') + :on_click(function(player,_element) + player.print('You clicked a button!') + end) + +>>>> Functions + Toolbar.new_button(name) --- Adds a new button to the toolbar + Toolbar.add_button(button) --- Adds an existing buttton to the toolbar + Toolbar.update(player) --- Updates the player's toolbar with an new buttons or expected change in auth return +]] +local Gui = require 'expcore.gui.core' --- @dep expcore.gui.core +local Buttons = require 'expcore.gui.elements.buttons' --- @dep expcore.gui.elements.buttons +local Roles = require 'expcore.roles' --- @dep expcore.roles +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 + +local Toolbar = { + permission_names = {}, + buttons = {} +} + +function Toolbar.allowed(player,define_name) + local permission_name = Toolbar.permission_names[define_name] or define_name + return Roles.player_allowed(player,permission_name) +end + +function Toolbar.permission_alias(define_name,permission_name) + Toolbar.permission_names[define_name] = permission_name +end + +--- Adds a new button to the toolbar +-- @tparam[opt] string name when given allows an alias to the button for the permission system +-- @treturn table the button define +function Toolbar.new_button(name) + local button = + Buttons.new_button() + :set_post_authenticator(Toolbar.allowed) + :set_style(mod_gui.button_style,function(style) + Gui.set_padding_style(style,-2,-2,-2,-2) + end) + Toolbar.add_button(button) + Toolbar.permission_alias(button.name,name) + return button +end + +--- Adds an existing buttton to the toolbar +-- @tparam table button the button define for the button to be added +function Toolbar.add_button(button) + table.insert(Toolbar.buttons,button) + Gui.allow_player_to_toggle_top_element_visibility(button.name) + Gui.on_player_show_top(button.name,function(event) + if not button.post_authenticator(event.player,button.name) then + event.element.visible = false + end + end) + if not button.post_authenticator then + button:set_post_authenticator(function() return true end) + end +end + +--- Updates the player's toolbar with an new buttons or expected change in auth return +-- @tparam LuaPlayer player the player to update the toolbar for +function Toolbar.update(player) + local top = Gui.get_top_element_flow(player) + if not top then return end + local visible = top[Gui.top_toggle_button_name].caption == '<' + for _,button in pairs(Toolbar.buttons) do + local element + if top[button.name] then element = top[button.name] + else element = button:draw_to(top) end + if button.post_authenticator(player,button.name) then + element.visible = visible + element.enabled = true + else + element.visible = false + element.enabled = false + end + end +end + +--- When there is a new player they will have the toolbar update +Event.add(defines.events.on_player_created,function(event) + local player = Game.get_player_by_index(event.player_index) + Toolbar.update(player) +end) + +--- When a player gets a new role they will have the toolbar updated +Event.add(Roles.events.on_role_assigned,function(event) + local player = Game.get_player_by_index(event.player_index) + Toolbar.update(player) +end) + +--- When a player loses a role they will have the toolbar updated +Event.add(Roles.events.on_role_unassigned,function(event) + local player = Game.get_player_by_index(event.player_index) + Toolbar.update(player) +end) + +return Toolbar \ No newline at end of file diff --git a/expcore/gui/core.lua b/expcore/gui/core.lua index 118bfc87..1fd93480 100644 --- a/expcore/gui/core.lua +++ b/expcore/gui/core.lua @@ -1,293 +1,368 @@ --[[-- Core Module - Gui @module Gui - @alias Gui + @alias Prototype ]] -local Game = require 'utils.game' -- @dep utils.game -local resolve_value = ext_require('expcore.common','resolve_value') -- @dep expcore.common -local Prototype = require 'expcore.gui.prototype' +--- Core. +-- Core gui file for making element defines and element classes (use require 'expcore.gui') +-- see utils.gui for event handlering +-- see expcore.gui.test for examples for element defines +-- @section core -local Gui = { - concepts = {} -} +--[[ +>>>> Basic useage with no defines + This module can be igroned if you are only wanting only event handlers as utils.gui adds the following: ---- Concept Control. --- Functions that act as a landing point for the other funtions --- @section concept-control + Gui.uid_name() --- Generates a unqiue name to register events to + Gui.on_checked_state_changed(callback) --- Register a handler for the on_gui_checked_state_changed event + Gui.on_click(callback) --- Register a handler for the on_gui_click event + Gui.on_elem_changed(callback) --- Register a handler for the on_gui_elem_changed + Gui.on_selection_state_changed(callback) --- Register a handler for the on_gui_selection_state_changed event + Gui.on_text_changed(callback) --- Register a handler for the on_gui_text_changed event + Gui.on_value_changed(callback) --- Register a handler for the on_gui_value_changed event ---[[-- 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') --- @dep Gui.concept.frame + Note that all event handlers will include event.player as a valid player and that if the player or the + element is not valid then the callback will not be run. + +>>>> Basic prototype functions (see expcore.gui.prototype) + Using a class defination you can create a new element dinfation in our examples we will be using the checkbox. + + local checkbox_example = Gui.new_checkbox() + + Although all class definations are stored in Gui.classes the main function used to make new element defination are + made aviable in the top level gui module. All functions which return a new element defination will accept a name argument + which is a name which is used while debuging and is not required to be used (has not been used in examples) + + Every element define will accept a caption and tooltip (although some may not show) and to do this you would use the two + set function provided for the element defines: + + checkbox_example:set_caption('Example Checkbox') + checkbox_example:set_tooltip('Example checkbox') + + Each element define can have event handlers set, for our example checkbox we only have access to on_change which will trigger + when the state of the checkbox changes; if we want to assign handlers using the utils.gui methods then we can get the uid by calling + the uid function on the element define; however, each element can only have one handler (of each event) so it is not possible to use + Gui.on_checked_state_changed and on_change at the same time in our example. + + checkbox_example:on_change(function(player,element,value) + player.print('Example checkbox is now: '..tostring(value)) + end) + + local checkbox_example_uid = checkbox_example:uid() + Gui.on_click(checkbox_example_uid,function(event) + event.player.print('You clicked the example checkbox!') + end) + + Finally you will want to draw your element defines for which you can call deirectly on the deinfe or use Gui.draw to do; when Gui.draw is + used it can be given either the element define, the define's uid or the debug name of the define (if set): + + checkbox_example:draw_to(parent_element) + Gui.draw(checkbox_example_uid,parent_element) + +>>>> Using authenticators with draw + When an element is drawn to its parent it can always be used but if you want to limit who can use it then you can use an authenticator. There + are two types which can be used: post and pre; using a pre authenticator will mean that the draw function is stoped before the element is added + to the parent element while using a post authenticator will draw the element to the parent but will disable the element from interaction. Both may + be used if you have use for such. + + -- unless global.checkbox_example_allow_pre_auth is true then the checkbox will not be drawn + checkbox_example:set_pre_authenticator(function(player,define_name) + player.print('Example checkbox pre auth callback ran') + return global.checkbox_example_allow_pre_auth + end) + + -- unless global.checkbox_example_allow_post_auth is true then the checkbox will be drawn but deactiveated (provided pre auth returns true) + checkbox_example:set_post_authenticator(function(player,define_name) + player.print('Example checkbox pre auth callback ran') + return global.checkbox_example_allow_post_auth + end) + +>>>> Using store (see expcore.gui.prototype and expcore.gui.instances) + A powerful assept of this gui system is allowing an automatic store for the state of a gui element, this means that when a gui is closed and re-opened + the elements which have a store will retain they value even if the element was previously destroied. The store is not limited to only per player and can + be catergorised by any method you want such as one that is shared between all players or by all players on a force. Using a method that is not limited to + one player means that when one player changes the state of the element it will be automaticlly updated for all other player (even if the element is already drawn) + and so this is a powerful and easy way to sync gui elements. + + -- note the example below is the same as checkbox_example:add_store(Gui.categorize_by_player) + checkbox_example:add_store(function(element) + local player = Game.get_player_by_index(element.player_index) + return player.force.name + end) + + Of course this tool is not limited to only player interactions; the current satate of a define can be gotten using a number of methods and the value can + even be updated by the script and have all instances of the element define be updated. When you use a category then we must give a category to the get + and set functions; in our case we used Gui.categorize_by_player which uses the player's name as the category which is why 'Cooldude2606' is given as a argument, + if we did not set a function for add_store then all instances for all players have the same value and so a category is not required. + + checkbox_example:get_store('Cooldude2606') + Gui.get_store(name,'Cooldude2606') + + checkbox_example:set_store('Cooldude2606',true) + Gui.set_store(name,'Cooldude2606',true) + + These methods use the Store module which means that if you have the need to access these sotre location (for example if you want to add a watch function) then + you can get the store location of any define using checkbox_example.store + + Important note about event handlers: when the store is updated it will also trigger the event handlers (such as on_element_update) for that define but only + for the valid instances of the define which means if a player does not have the element drawn on a gui then it will not trigger the events; if you want a + trigger for all updates then you can use on_store_update however you will be required to parse the category which may or may not be a + player name (depends what store categorize function you use) + +>>>> Example formating + + local checkbox_example = + Gui.new_checkbox() + :set_caption('Example Checkbox') + :set_tooltip('Example checkbox') + :add_store(Gui.categorize_by_player) + :on_element_update(function(player,element,value) + player.print('Example checkbox is now: '..tostring(value)) + end) + +>>>> Functions + Gui.new_define(prototype) --- Used internally to create new element defines from a class prototype + Gui.draw(name,element) --- Draws a copy of the element define to the parent element, see draw_to + + Gui.categorize_by_player(element) --- A categorize function to be used with add_store, each player has their own value + Gui.categorize_by_force(element) --- A categorize function to be used with add_store, each force has its own value + Gui.categorize_by_surface(element) --- A categorize function to be used with add_store, each surface has its own value + + Gui.toggle_enabled(element) --- Will toggle the enabled state of an element + Gui.toggle_visible(element) --- Will toggle the visiblity of an element + Gui.set_padding(element,up,down,left,right) --- Sets the padding for a gui element + Gui.set_padding_style(style,up,down,left,right) --- Sets the padding for a gui style + Gui.create_alignment(element,flow_name) --- Allows the creation of a right align flow to place elements into + Gui.destroy_if_valid(element) --- Destroies an element but tests for it being present and valid first + Gui.create_scroll_table(element,table_size,maximal_height,name) --- Creates a scroll area with a table inside, table can be any size + Gui.create_header(element,caption,tooltip,right_align,name) --- Creates a header section with a label and button area ]] -function Gui.require_concept(concept_name) - require('expcore.gui.concepts.'..concept_name) -end +local Gui = require 'utils.gui' --- @dep utils.gui +local Game = require 'utils.game' --- @dep utils.game ---[[-- 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..'.index') -end +Gui.classes = {} -- Stores the class definations used to create element defines +Gui.defines = {} -- Stores the indivdual element definations +Gui.names = {} -- Stores debug names to link to gui uids ---[[-- 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) - 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 +--- Used to create new element defines from a class prototype, please use the own given by the class +-- @tparam table prototype the class prototype that will be used for the element define +-- @tparam[opt] string debug_name the name that you want to see while debuging +-- @treturn table the new element define with all functions accessed via __index metamethod +function Gui.new_define(prototype,debug_name) + local name = Gui.uid_name() + local define = setmetatable({ + debug_name = debug_name, + name = name, + events = {}, + draw_data = { + name = name + } + },{ + __index = prototype, + __call = function(self,...) + return self:draw_to(...) end - - elseif vtype == 'number' then - for _,concept in pairs(Gui.concepts) do - if concept.name == name then - return concept - end - end - - end - + }) + Gui.defines[define.name] = define + return define 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, 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(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 -end - ---[[-- Used to draw a concept to a parent element -@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(concept,parent,...) - concept = Gui.get_concept(concept) or error('Invalid gui concept "'..tostring(concept)..'"',2) - return concept:draw(parent,...) -end - ---- Element Control. --- Functions that aim to making working with gui elements easier --- @section element-control - ---[[-- Gets the player who owns this element -@tparam LuaGuiElement element the element that you want to get the player of -@treturn LuaPlayer the player who owns this element -@usage-- Getting the player of an element -local player = Gui.get_player_from_element(element) -]] -function Gui.get_player_from_element(element) - return Game.get_player_by_index(element.player_index) -end - ---[[-- Simple check for if an element is valid -@tparam LuaGuiElement element the element that you want to check is valid -@treturn boolean true if the element is valid -@usage-- Return if not valid -if not Gui.valid(element) then return end -]] -function Gui.valid(element) - return element and element.valid or false -end - ---[[-- Destroies and element if it is valid -@tparam LuaGuiElement element the element that you want to destroy -@treturn boolean true if the element was valid and was destoried -@usage-- Destoring an element -Gui.destroy(element) -]] -function Gui.destroy(element) - if element and element.valid then - element.destroy() - return true - end - return false -end - ---[[-- Finds and returns a gui element if it is valid from a long chain of element names or concepts -@tparam LuaGuiElement element the root element to start checking from -@tparam ?string|table ... element names or element concepts that point to your element -@treturn[1] boolean if the element was found, failed -@treturn[1] string the path of the element that the search stoped at -@treturn[2] boolean if the element was found, found -@treturn[2] LuaGuiElement the element that was found -@usage-- Getting the center gui -local exists, center = Gui.exists(player,'gui','center') -]] -function Gui.exists(element,...) - local path = tostring(element.name) - for _,next_element_name in pairs{...} do - if type(next_element_name) == 'table' then - next_element_name = next_element_name.name - end - - element = element[next_element_name] - path = path..'.'..tostring(next_element_name) - if not Gui.valid(element) then - return false, path +--- Gets an element define give the uid, debug name or a copy of the element define +-- @tparam ?string|table name the uid, debug name or define for the element define to get +-- @tparam[opt] boolean internal when true the error trace is one level higher (used internally) +-- @treturn table the element define that was found or an error +function Gui.get_define(name,internal) + if type(name) == 'table' then + if name.name and Gui.defines[name.name] then + return Gui.defines[name.name] end end - return true, element -end ---[[-- Checks if a gui element exists or not, if not found will throw an error -@see Gui.exists -@tparam LuaGuiElement element the root element to start checking from -@tparam ?string|table ... element names or element concepts that point to your element -@treturn LuaGuiElement the element that was found -@usage-- Getting the center gui -local exists, center = Gui.find(player,'gui','center') -]] -function Gui.find(element,...) - local exists, element = Gui.exists(element,...) - if not exists then - return error('Could not find element: '..element,2) - else - return element + local define = Gui.defines[name] + + if not define and Gui.names[name] then + return Gui.defines[Gui.names[name]] + + elseif not define then + return error('Invalid name for element define, name not found.',internal and 3 or 2) or nil + end + + return define end ---[[-- Toggles the enabled state of an element -@tparam LuaGuiElement element the element that you want to toggle the enabled state of -@treturn boolean the new enabled state of the element -@usage-- Toggle the enabled state of an element -Gui.toggle_enabled(element) -]] -function Gui.toggle_enabled(element) - if not element or not element.valid then return end - if not element.enabled then - element.enabled = true - return true - else - element.enabled = false - return false - end -end - ---[[-- Toggles the visible state of an element -@tparam LuaGuiElement element the element that you want to toggle the visible state of -@treturn boolean the new visible state of the element -@usage-- Toggle the visible state of an element -Gui.toggle_visible(element) -]] -function Gui.toggle_visible(element) - if not element or not element.valid then return end - if not element.visible then - element.visible = true - return true - else - element.visible = false - return false - end -end - ---[[-- Sets the padding for a gui element -@tparam LuaGuiElement element the element to set the padding for -@tparam[opt=0] ?number|boolean up the amount of padding on the top, true leaves unchanged -@tparam[opt=0] ?number|boolean down the amount of padding on the bottom, true leaves unchanged -@tparam[opt=0] ?number|boolean left the amount of padding on the left, true leaves unchanged -@tparam[opt=0] ?number|boolean right the amount of padding on the right, true leaves unchanged -@usage-- Remove all padding of an element -Gui.set_padding(element) -@usage-- Remove side padding but keep vertical padding -Gui.set_padding(element,true,true) -@usage-- Remove all padding but set right to 2 -Gui.set_padding(element,false,false,false,2) -]] -function Gui.set_padding(element,up,down,left,right) - local style = element.style - style.top_padding = up == true and style.top_padding or up or 0 - style.bottom_padding = down == true and style.top_padding or down or 0 - style.left_padding = left == true and style.top_padding or left or 0 - style.right_padding = right == true and style.top_padding or right or 0 -end - ---[[ Used to check a property exists and if it is a function then call the function -@function Gui.resolve_property -@tparam any value the value that you are testing exists and call if its a function -@tparam LuaGuiElement element the element that is passed to the function if it is a function -@treturn any the value or what it returns if it is a function -@usage-- Getting the default value -local default = Gui.resolve_property(properties.default,element) -if default then - element.value = default -end -]] -Gui.resolve_property = resolve_value - ---- Store Categories. --- Functions that are common types of categories --- @section store-categories - ---[[-- A categorize function to be used with add_store, each player has their own category -@tparam LuaGuiElement element the element that will be converted to a string -@treturn string the player's name who owns this element -@usage-- Storing data on a per player basis, can be used with instances -Gui.get_concept('CustomButton') -:define_data_store(Gui.categorize_by_player) -]] +--- A categorize function to be used with add_store, each player has their own value +-- @tparam LuaGuiElement element the element that will be converted to a string +-- @treturn string the player's name who owns this element function Gui.categorize_by_player(element) local player = Game.get_player_by_index(element.player_index) return player.name end ---[[-- A categorize function to be used with add_store, each force has its own category -@tparam LuaGuiElement element the element that will be converted to a string -@treturn string the player's force name who owns this element -@usage-- Storing data on a per force basis, can be used with instances -Gui.get_concept('CustomButton') -:define_data_store(Gui.categorize_by_force) -]] +--- A categorize function to be used with add_store, each force has its own value +-- @tparam LuaGuiElement element the element that will be converted to a string +-- @treturn string the player's force name who owns this element function Gui.categorize_by_force(element) local player = Game.get_player_by_index(element.player_index) return player.force.name end ---[[-- A categorize function to be used with add_store, each surface has its own category -@tparam LuaGuiElement element the element that will be converted to a string -@treturn string the player's surface name who owns this element -@usage-- Storing data on a per surface basis, can be used with instances -Gui.get_concept('CustomButton') -:define_data_store(Gui.categorize_by_surface) -]] +--- A categorize function to be used with add_store, each surface has its own value +-- @tparam LuaGuiElement element the element that will be converted to a string +-- @treturn string the player's surface name who owns this element function Gui.categorize_by_surface(element) local player = Game.get_player_by_index(element.player_index) return player.surface.name end +--- Draws a copy of the element define to the parent element, see draw_to +-- @tparam ?string|table name the uid, debug name or define for the element define to draw +-- @tparam LuaGuiEelement element the parent element that it the define will be drawn to +-- @treturn LuaGuiElement the new element that was created +function Gui.draw(name,element,...) + local define = Gui.get_define(name,true) + return define:draw_to(element,...) +end + +--- Will toggle the enabled state of an element +-- @tparam LuaGuiElement element the gui element to toggle +-- @treturn boolean the new state that the element has +function Gui.toggle_enabled(element) + if not element or not element.valid then return end + if not element.enabled then + element.enabled = true + else + element.enabled = false + end + return element.enabled +end + +--- Will toggle the visiblity of an element +-- @tparam LuaGuiElement element the gui element to toggle +-- @treturn boolean the new state that the element has +function Gui.toggle_visible(element) + if not element or not element.valid then return end + if not element.visible then + element.visible = true + else + element.visible = false + end + return element.visible +end + +--- Sets the padding for a gui element +-- @tparam LuaGuiElement element the element to set the padding for +-- @tparam[opt=0] number up the amount of padding on the top +-- @tparam[opt=0] number down the amount of padding on the bottom +-- @tparam[opt=0] number left the amount of padding on the left +-- @tparam[opt=0] number right the amount of padding on the right +function Gui.set_padding(element,up,down,left,right) + local style = element.style + style.top_padding = up or 0 + style.bottom_padding = down or 0 + style.left_padding = left or 0 + style.right_padding = right or 0 +end + +--- Sets the padding for a gui style +-- @tparam LuaStyle style the element to set the padding for +-- @tparam[opt=0] number up the amount of padding on the top +-- @tparam[opt=0] number down the amount of padding on the bottom +-- @tparam[opt=0] number left the amount of padding on the left +-- @tparam[opt=0] number right the amount of padding on the right +function Gui.set_padding_style(style,up,down,left,right) + style.top_padding = up or 0 + style.bottom_padding = down or 0 + style.left_padding = left or 0 + style.right_padding = right or 0 +end + +--- Allows the creation of an alignment flow to place elements into +-- @tparam LuaGuiElement element the element to add this alignment into +-- @tparam[opt] string name the name to use for the alignment +-- @tparam[opt='right'] string horizontal_align the horizontal alignment of the elements in this flow +-- @tparam[opt='center'] string vertical_align the vertical alignment of the elements in this flow +-- @treturn LuaGuiElement the new flow that was created +function Gui.create_alignment(element,name,horizontal_align,vertical_align) + local flow = element.add{name=name,type='flow'} + local style = flow.style + Gui.set_padding(flow,1,1,2,2) + style.horizontal_align = horizontal_align or 'right' + style.vertical_align = vertical_align or 'center' + style.horizontally_stretchable =style.horizontal_align ~= 'center' + style.vertically_stretchable = style.vertical_align ~= 'center' + return flow +end + +--- Destroies an element but tests for it being present and valid first +-- @tparam LuaGuiElement element the element to be destroied +-- @treturn boolean true if it was destoried +function Gui.destroy_if_valid(element) + if element and element.valid then + element.destroy() + return true + end +end + +--- Creates a scroll area with a table inside, table can be any size +-- @tparam LuaGuiElement element the element to add this scroll into +-- @tparam number table_size the number of columns in the table +-- @tparam number maximal_height the max hieght of the scroll +-- @tparam[opt='scroll'] string name the name of the scoll element +-- @treturn LuaGuiElement the table that was made +function Gui.create_scroll_table(element,table_size,maximal_height,name) + local list_scroll = + element.add{ + name=name or 'scroll', + type='scroll-pane', + direction='vertical', + horizontal_scroll_policy='never', + vertical_scroll_policy='auto-and-reserve-space' + } + Gui.set_padding(list_scroll,1,1,2,2) + list_scroll.style.horizontally_stretchable = true + list_scroll.style.maximal_height = maximal_height + + local list_table = + list_scroll.add{ + name='table', + type='table', + column_count=table_size + } + Gui.set_padding(list_table) + list_table.style.horizontally_stretchable = true + list_table.style.vertical_align = 'center' + list_table.style.cell_padding = 0 + + return list_table +end + +--- Creates a header section with a label and button area +-- @tparam LuaGuiElement element the element to add this header into +-- @tparam localeString caption the caption that is used as the title +-- @tparam[opt] localeString tooltip the tooltip that is shown on the caption +-- @tparam[opt] boolean right_align when true will include the right align area +-- @tparam[opt='header'] string name the name of the header area +-- @treturn LuaGuiElement the header that was made, or the align area if that was created +function Gui.create_header(element,caption,tooltip,right_align,name) + local header = + element.add{ + name=name or 'header', + type='frame', + style='subheader_frame' + } + Gui.set_padding(header,2,2,4,4) + header.style.horizontally_stretchable = true + header.style.use_header_filler = false + + header.add{ + type='label', + style='heading_1_label', + caption=caption, + tooltip=tooltip + } + + return right_align and Gui.create_alignment(header,'header-align') or header +end + return Gui \ No newline at end of file diff --git a/expcore/gui/elements/buttons.lua b/expcore/gui/elements/buttons.lua new file mode 100644 index 00000000..aa06f58b --- /dev/null +++ b/expcore/gui/elements/buttons.lua @@ -0,0 +1,128 @@ +--[[-- Core Module - Gui + @module Gui + @alias Prototype +]] + +--- Buttons. +-- Gui class define for buttons and sprite buttons +-- @section Buttons + +--[[ +>>>> Functions + Button.new_button(name) --- Creates a new button element define + + Button._prototype:on_click(player,element) --- Registers a handler for when the button is clicked + Button._prototype:on_left_click(player,element) --- Registers a handler for when the button is clicked with the left mouse button + Button._prototype:on_right_click(player,element) --- Registers a handler for when the button is clicked with the right mouse button + + Button._prototype:set_sprites(sprite,hovered_sprite,clicked_sprite) --- Adds sprites to a button making it a sprite button + Button._prototype:set_click_filter(filter,...) --- Adds a click / mouse button filter to the button + Button._prototype:set_key_filter(filter,...) --- Adds a control key filter to the button + + Other functions present from expcore.gui.core +]] +local mod_gui = require 'mod-gui' --- @dep mod-gui +local Gui = require 'expcore.gui.core' --- @dep expcore.gui.core +local Prototype = require 'expcore.gui.prototype' --- @dep expcore.gui.prototype + +local Button = { + _prototype=Prototype.extend{ + on_raw_click = Prototype.event, + on_click = Prototype.event, + on_left_click = Prototype.event, + on_right_click = Prototype.event, + } +} + +--- Creates a new button element define +-- @tparam[opt] string name the optional debug name that can be added +-- @treturn table the new button element define +function Button.new_button(name) + + local self = Gui.new_define(Button._prototype,name) + self.draw_data.type = 'button' + self.draw_data.style = mod_gui.button_style + + Gui.on_click(self.name,function(event) + local mouse_button = event.button + local keys = {alt=event.alt,control=event.control,shift=event.shift} + local player,element = event.player,event.element + event.keys = keys + + self:raise_event('on_raw_click',event) + + if self.post_authenticator then + if not self.post_authenticator(event.player,self.name) then return end + end + + if mouse_button == defines.mouse_button_type.left then + self:raise_event('on_left_click',player,element) + elseif mouse_button == defines.mouse_button_type.right and self.events.on_right_click then + self:raise_event('on_right_click',player,element) + end + + if self.mouse_button_filter and not self.mouse_button_filter[mouse_button] then return end + if self.key_button_filter then + for key,state in pairs(self.key_button_filter) do + if state and not keys[key] then return end + end + end + + self:raise_event('on_click',player,element) + end) + + return self +end + +--- Adds sprites to a button making it a sprite button +-- @tparam SpritePath sprite the sprite path for the default sprite for the button +-- @tparam[opt] SpritePath hovered_sprite the sprite path for the sprite when the player hovers over the button +-- @tparam[opt] SpritePath clicked_sprite the sprite path for the sprite when the player clicks the button +-- @treturn self returns the button define to allow chaining +function Button._prototype:set_sprites(sprite,hovered_sprite,clicked_sprite) + self.draw_data.type = 'sprite-button' + self.draw_data.sprite = sprite + self.draw_data.hovered_sprite = hovered_sprite + self.draw_data.clicked_sprite = clicked_sprite + return self +end + +--- Adds a click / mouse button filter to the button +-- @tparam table filter ?string|table either a of mouse buttons or the first mouse button to filter, with a table true means allowed +-- @tparam[opt] table ... when filter is not a you can add the mouse buttons one after each other +-- @treturn self returns the button define to allow chaining +function Button._prototype:set_click_filter(filter,...) + if type(filter) == 'string' then + filter = {[filter]=true} + for _,v in pairs({...}) do + filter[v] = true + end + end + + for k,v in pairs(filter) do + if type(v) == 'string' then + filter[k] = defines.mouse_button_type[v] + end + end + + self.mouse_button_filter = filter + return self +end + +--- Adds a control key filter to the button +-- @tparam table filter ?string|table either a of control keys or the first control keys to filter, with a table true means allowed +-- @tparam[opt] table ... when filter is not a you can add the control keys one after each other +-- @treturn self returns the button define to allow chaining +function Button._prototype:set_key_filter(filter,...) + if type(filter) == 'string' then + filter = {[filter]=true} + for _,v in pairs({...}) do + filter[v] = true + end + end + + self.key_button_filter = filter + return self +end + +return Button \ No newline at end of file diff --git a/expcore/gui/elements/checkbox.lua b/expcore/gui/elements/checkbox.lua new file mode 100644 index 00000000..98f50811 --- /dev/null +++ b/expcore/gui/elements/checkbox.lua @@ -0,0 +1,252 @@ +--[[-- Core Module - Gui + @module Gui + @alias Prototype +]] + +--- Checkboxs. +-- Gui class define for checkbox and radiobuttons +-- @section checkboxs + +--[[ +>>>> Using an option set + An option set is a set of radio buttons where only one of them can be active at a time, this means that when one + is clicked all the other ones are set to false, an option set must be defined before hand and will always store + its state but is not limited by how it can categorize the store. + + First you must register the store with a name and a update callback, and an optional function for categorize: + + local example_option_set = + Gui.new_option_set('example-option-set',function(value,category) + game.print('Example options set '..category..' is now: '..tostring(value)) + end,Gui.categorize_by_player) + + Then you must register some radiobutton defines and include them in the option set: + + local example_option_one = + Gui.new_radiobutton() + :set_caption('Option One') + :add_as_option(example_option_set,'One') + + local example_option_two = + Gui.new_radiobutton() + :set_caption('Option Two') + :add_as_option(example_option_set,'Two') + + Note that these radiobuttons can still have on_element_update events but this may result in a double trigger of events as + the option set update is always triggered; also add_store cant be used as the option set acts as the store however get + and set store will still work but will effect the option set rather than the individual radiobuttons. + +>>>> Functions + Checkbox.new_checkbox(name) --- Creates a new checkbox element define + Checkbox._prototype_checkbox:on_element_update(callback) --- Registers a handler for when an element instance updates + Checkbox._prototype_checkbox:on_store_update(callback) --- Registers a handler for when the stored value updates + + Checkbox.new_radiobutton(name) --- Creates a new radiobutton element define + Checkbox._prototype_radiobutton:on_element_update(callback) --- Registers a handler for when an element instance updates + Checkbox._prototype_radiobutton:on_store_update(callback) --- Registers a handler for when the stored value updates + Checkbox._prototype_radiobutton:add_as_option(option_set,option_name) --- Adds this radiobutton to be an option in the given option set (only one can be true at a time) + + Checkbox.new_option_set(name,callback,categorize) --- Registers a new option set that can be linked to radiobutton (only one can be true at a time) + Checkbox.draw_option_set(name,element) --- Draws all radiobuttons that are part of an option set at once (Gui.draw will not work) + + Checkbox.reset_radiobutton(element,exclude,recursive) --- Sets all radiobutton in a element to false (unless excluded) and can act recursively + + Other functions present from expcore.gui.core +]] +local Gui = require 'expcore.gui.core' --- @dep expcore.gui.core +local Prototype = require 'expcore.gui.prototype' --- @dep expcore.gui.prototype +local Store = require 'expcore.store' --- @dep expcore.store +local Game = require 'utils.game' --- @dep utils.game + +--- Store call for store update +-- @tparam table define the define that this is acting on +-- @tparam LuaGuiElement element the element that triggered the event +-- @tparam boolean value the new state of the checkbox +local function store_update(define,element,value) + element.state = value + local player = Game.get_player_by_index(element.player_index) + define:raise_event('on_element_update',player,element,value) +end + +local Checkbox = { + option_sets={}, + option_categorize={}, + _prototype_checkbox=Prototype.extend{ + on_element_update = Prototype.event, + on_store_update = Prototype.event, + add_store = Prototype.store(false,store_update), + add_sync_store = Prototype.store(true,store_update) + }, + _prototype_radiobutton=Prototype.extend{ + on_element_update = Prototype.event, + on_store_update = Prototype.event, + add_store = Prototype.store(false,store_update), + add_sync_store = Prototype.store(true,store_update) + } +} + +--- Creates a new checkbox element define +-- @tparam[opt] string name the optional debug name that can be added +-- @treturn table the new checkbox element define +function Checkbox.new_checkbox(name) + + local self = Gui.new_define(Checkbox._prototype_checkbox,name) + self.draw_data.type = 'checkbox' + self.draw_data.state = false + + self:on_draw(function(player,element) + if self.store then + local category = self.categorize and self.categorize(element) or nil + local state = self:get_store(category,true) + if state then element.state = true end + end + end) + + Gui.on_checked_state_changed(self.name,function(event) + local element = event.element + + if self.option_set then + local value = Checkbox.option_sets[self.option_set][element.name] + local category = self.categorize and self.categorize(element) + self:set_store(category,value) + + elseif self.store then + local value = element.state + local category = self.categorize and self.categorize(element) + self:set_store(category,value) + + else + self:raise_event('on_element_update',event.player,element,element.state) + + end + end) + + return self +end + +--- Creates a new radiobutton element define, has all functions checkbox has +-- @tparam[opt] string name the optional debug name that can be added +-- @treturn table the new button element define +function Checkbox.new_radiobutton(name) + local self = Checkbox.new_checkbox(name) + self.draw_data.type = 'radiobutton' + + local mt = getmetatable(self) + mt.__index = Checkbox._prototype_radiobutton + + return self +end + +--- Adds this radiobutton to be an option in the given option set (only one can be true at a time) +-- @tparam string option_set the name of the option set to add this element to +-- @tparam string option_name the name of this option that will be used to identify it +-- @treturn self the define to allow chaining +function Checkbox._prototype_radiobutton:add_as_option(option_set,option_name) + self.option_set = option_set + self.option_name = option_name or self.name + + Checkbox.option_sets[option_set][self.option_name] = self.name + Checkbox.option_sets[option_set][self.name] = self.option_name + + self:add_store(Checkbox.option_categorize[option_set]) + + return self +end + +--- Gets the stored value of the radiobutton or the option set if present +-- @tparam string category[opt] the category to get such as player name or force name +-- @tparam boolean internal used to prevent stackover flow +-- @treturn any the value that is stored for this define +function Checkbox._prototype_radiobutton:get_store(category,internal) + if not self.store then return end + local location = not internal and self.option_set or self.store + return Store.get(location,category) +end + +--- Sets the stored value of the radiobutton or the option set if present +-- @tparam string category[opt] the category to get such as player name or force name +-- @tparam boolean value the value to set for this define, must be valid for its type ie for checkbox etc +-- @tparam boolean internal used to prevent stackover flow +-- @treturn boolean true if the value was set +function Checkbox._prototype_radiobutton:set_store(category,value,internal) + if not self.store then return end + local location = not internal and self.option_set or self.store + return Store.set(location,category,value) +end + +--- Registers a new option set that can be linked to radiobuttons (only one can be true at a time) +-- @tparam string name the name of the option set, must be unique +-- @tparam function callback the update callback when the value of the option set changes +-- callback param - value string - the new selected option for this option set +-- callback param - category string - the category that updated if categorize was used +-- @tparam function categorize the function used to convert an element into a string +-- @treturn string the name of this option set to be passed to add_as_option +function Checkbox.new_option_set(name,callback,categorize) + + Store.register(name,function(value,category) + local options = Checkbox.option_sets[name] + for opt_name,define_name in pairs(options) do + if Gui.defines[define_name] then + local define = Gui.get_define(define_name) + local state = opt_name == value + define:set_store(category,state,true) + end + end + callback(value,category) + end) + + Checkbox.option_categorize[name] = categorize + Checkbox.option_sets[name] = {} + + return name +end + +--- Draws all radiobuttons that are part of an option set at once (Gui.draw will not work) +-- @tparam string name the name of the option set to draw the radiobuttons of +-- @tparam LuaGuiElement element the parent element that the radiobuttons will be drawn to +function Checkbox.draw_option_set(name,element) + if not Checkbox.option_sets[name] then return end + local options = Checkbox.option_sets[name] + + for _,option in pairs(options) do + if Gui.defines[option] then + Gui.defines[option]:draw_to(element) + end + end + +end + +--- Sets all radiobutton in a element to false (unless excluded) and can act recursively +-- @tparam LuaGuiElement element the root gui element to start setting radio buttons from +-- @tparam[opt] table exclude ?string|table the name of the radiobutton to exclude or a of radiobuttons where true will set the state true +-- @tparam[opt=false] ?number|boolean recursive if true will recur as much as possible, if a will recur that number of times +-- @treturn boolean true if successful +function Checkbox.reset_radiobuttons(element,exclude,recursive) + if not element or not element.valid then return end + exclude = type(exclude) == 'table' and exclude or exclude ~= nil and {[exclude]=true} or {} + recursive = type(recursive) == 'number' and recursive-1 or recursive + + for _,child in pairs(element.children) do + if child and child.valid and child.type == 'radiobutton' then + local state = exclude[child.name] or false + local define = Gui.defines[child.name] + + if define then + local category = define.categorize and define.categorize(child) or state + define:set_store(category,state) + + else + child.state = state + + end + + elseif child.children and (type(recursive) == 'number' and recursive >= 0 or recursive == true) then + Checkbox.reset_radiobutton(child,exclude,recursive) + + end + end + + return true +end + +return Checkbox \ No newline at end of file diff --git a/expcore/gui/elements/dropdown.lua b/expcore/gui/elements/dropdown.lua new file mode 100644 index 00000000..c56eb960 --- /dev/null +++ b/expcore/gui/elements/dropdown.lua @@ -0,0 +1,187 @@ +--[[-- Core Module - Gui + @module Gui + @alias Prototype +]] + +--- Dropdowns. +-- Gui class define for dropdowns and list box +-- @section dropdowns + +--[[ +>>>> Functions + Dropdown.new_dropdown(name) --- Creates a new dropdown element define + Dropdown.new_list_box(name) --- Creates a new list box element define + + Dropdown._prototype:on_element_update(callback) --- Registers a handler for when an element instance updates + Dropdown._prototype:on_store_update(callback) --- Registers a handler for when the stored value updates + + Dropdown._prototype:new_static_options(options,...) --- Adds new static options to the dropdown which will trigger the general callback + Dropdown._prototype:new_dynamic_options(callback) --- Adds a callback which should return a table of values to be added as options for the dropdown (appended after static options) + Dropdown._prototype:add_option_callback(option,callback) --- Adds a case specific callback which will only run when that option is selected (general case still triggered) + + Dropdown.select_value(element,value) --- Selects the option from a dropdown or list box given the value rather than key + Dropdown.get_selected_value(element) --- Returns the currently selected value rather than index + + Other functions present from expcore.gui.core +]] +local Gui = require 'expcore.gui.core' --- @dep expcore.gui.core +local Prototype = require 'expcore.gui.prototype' --- @dep expcore.gui.prototype +local Game = require 'utils.game' --- @dep utils.game + +local select_value +--- Store call for store update +-- @tparam table define the define that this is acting on +-- @tparam LuaGuiElement element the element that triggered the event +-- @tparam string value the new option for the dropdown +local function store_update(define,element,value) + select_value(element,value) + local player = Game.get_player_by_index(element.player_index) + define:raise_event('on_element_update',player,element,value) + + if define.option_callbacks and define.option_callbacks[value] then + define.option_callbacks[value](player,element,value) + end +end + +local Dropdown = { + _prototype=Prototype.extend{ + on_element_update = Prototype.event, + on_store_update = Prototype.event, + add_store = Prototype.store(false,store_update), + add_sync_store = Prototype.store(true,store_update) + } +} + +--- Creates a new dropdown element define +-- @tparam[opt] string name the optional debug name that can be added +-- @treturn table the new dropdown element define +function Dropdown.new_dropdown(name) + + local self = Gui.new_define(Dropdown._prototype,name) + self.draw_data.type = 'drop-down' + + self:on_draw(function(player,element) + if self.dynamic_options then + local dynamic_options = self.dynamic_options(player,element) + local items = element.items + for _,v in pairs(dynamic_options) do + table.insert(items,v) + end + element.items = items + end + + if self.store then + local category = self.categorize and self.categorize(element) or nil + local value = self:get_store(category) + if value then Dropdown.select_value(element,value) end + end + end) + + Gui.on_selection_state_changed(self.name,function(event) + local element = event.element + local value = Dropdown.get_selected_value(element) + + if self.store then + local category = self.categorize and self.categorize(element) or value + self:set_store(category,value) + + else + local player = event.player + local option_callbacks = self.option_callbacks + self:raise_event('on_element_update',player,element,value) + if option_callbacks and option_callbacks[value] then + option_callbacks[value](player,element,value) + end + + end + + end) + + return self +end + +--- Creates a new list box element define +-- @tparam[opt] string name the optional debug name that can be added +-- @treturn table the new list box element define +function Dropdown.new_list_box(name) + local self = Dropdown.new_dropdown(name) + self.draw_data.type = 'list-box' + + return self +end + +--- Adds new static options to the dropdown which will trigger the general callback +-- @tparam table options ?string|table either a of option strings or the first option string, with a table values are the options +-- @tparam[opt] table ... when options is not a you can add the options one after each other +-- @tparam self the define to allow chaining +function Dropdown._prototype:new_static_options(options,...) + if type(options) == 'string' then + options = {options} + for _,v in pairs({...}) do + table.insert(options,v) + end + end + + self.options = options + self.draw_data.items = options + return self +end +Dropdown._prototype.add_options = Dropdown._prototype.new_static_options + +--- Adds a callback which should return a table of values to be added as options for the dropdown (appended after static options) +-- @tparam function callback the function that will run to get the options for the dropdown +-- callback param - player LuaPlayer - the player that the element is being drawn to +-- callback param - element LuaGuiElement - the element that is being drawn +-- callback return - table - the values of this table will be appended to the static options of the dropdown +-- @treturn self the define to allow chaining +function Dropdown._prototype:new_dynamic_options(callback) + if type(callback) ~= 'function' then + return error('Dynamic options callback must be a function',2) + end + self.dynamic_options = callback + return self +end +Dropdown._prototype.add_dynamic = Dropdown._prototype.new_dynamic_options + +--- Adds a case specific callback which will only run when that option is selected (general case still triggered) +-- @tparam string option the name of the option to trigger the callback on; if not already added then will be added as an option +-- @tparam function callback the function that will be called when that option is selected +-- callback param - player LuaPlayer - the player who owns the gui element +-- callback param - element LuaGuiElement - the element which is being effected +-- callback param - value string - the new option that has been selected +-- @treturn self the define to allow chaining +function Dropdown._prototype:add_option_callback(option,callback) + if not self.option_callbacks then self.option_callbacks = {} end + if not self.options then self.options = {} end + + self.option_callbacks[option] = callback + if not table.contains(self.options,option) then + table.insert(self.options,option) + end + + return self +end + +--- Selects the option from a dropdown or list box given the value rather than key +-- @tparam LuaGuiElement element the element that contains the option +-- @tparam string value the option to select from the dropdown +-- @treturn number the key where the value was +function Dropdown.select_value(element,value) + for k,item in pairs(element.items) do + if item == value then + element.selected_index = k + return k + end + end +end +select_value = Dropdown.select_value + +--- Returns the currently selected value rather than index +-- @tparam LuaGuiElement element the gui element that you want to get the value of +-- @treturn string the value that is currently selected +function Dropdown.get_selected_value(element) + local index = element.selected_index + return element.items[index] +end + +return Dropdown \ No newline at end of file diff --git a/expcore/gui/elements/elem-button.lua b/expcore/gui/elements/elem-button.lua new file mode 100644 index 00000000..e61859bf --- /dev/null +++ b/expcore/gui/elements/elem-button.lua @@ -0,0 +1,99 @@ +--[[-- Core Module - Gui + @module Gui + @alias Prototype +]] + +--- Elem Buttons. +-- Gui class defines for elem buttons +-- @section elem-buttons + +--[[ +>>>> Functions + ElemButton.new_elem_button(name) --- Creates a new elem button element define + + ElemButton._prototype:on_element_update(callback) --- Registers a handler for when an element instance updates + ElemButton._prototype:on_store_update(callback) --- Registers a handler for when the stored value updates + + ElemButton._prototype:set_type(type) --- Sets the type of the elem button, the type is required so this must be called at least once + ElemButton._prototype:set_default(value) --- Sets the default value for the elem button, this may be a function or a string + + Other functions present from expcore.gui.core +]] +local Gui = require 'expcore.gui.core' --- @dep expcore.gui.core +local Prototype = require 'expcore.gui.prototype' --- @dep expcore.gui.prototype +local Game = require 'utils.game' --- @dep utils.game + +--- Store call for store update +-- @tparam table define the define that this is acting on +-- @tparam LuaGuiElement element the element that triggered the event +-- @tparam string value the new value for the elem button +local function store_update(define,element,value) + element.elem_value = value + local player = Game.get_player_by_index(element.player_index) + define:raise_event('on_element_update',player,element,value) +end + +local ElemButton = { + _prototype=Prototype.extend{ + on_element_update = Prototype.event, + on_store_update = Prototype.event, + add_store = Prototype.store(false,store_update), + add_sync_store = Prototype.store(true,store_update) + } +} + +--- Creates a new elem button element define +-- @tparam[opt] string name the optional debug name that can be added +-- @treturn table the new elem button element define +function ElemButton.new_elem_button(name) + + local self = Gui.new_define(ElemButton._prototype,name) + self.draw_data.type = 'choose-elem-button' + + self:on_draw(function(player,element) + if type(self.default) == 'function' then + element.elem_value = self.default(player,element) + end + + if self.store then + local category = self.categorize and self.categorize(element) or nil + local value = self:get_store(category) + if value then element.elem_value = value end + end + end) + + Gui.on_elem_changed(self.name,function(event) + local element = event.element + local value = element.elem_value + + if self.store then + local category = self.categorize and self.categorize(element) or value + self:set_store(category,value) + + else + self:raise_event('on_element_update',event.player,element,value) + + end + + end) + + return self +end + +--- Sets the type of the elem button, the type is required so this must be called at least once +-- @tparam string type the type that this elem button is see factorio api +-- @treturn the element define to allow for chaining +ElemButton._prototype.set_type = Prototype.setter('string','draw_data','elem_type') + +--- Sets the default value for the elem button, this may be a function or a string +-- @tparam ?string|function value string a will be a static default and a function will be called when drawn to get the default +-- @treturn the element define to allow for chaining +function ElemButton._prototype:set_default(value) + self.default = value + if type(value) ~= 'function' then + self.draw_data[self.draw_data.elem_type] = value + end + return self +end + +return ElemButton \ No newline at end of file diff --git a/expcore/gui/elements/progress-bar.lua b/expcore/gui/elements/progress-bar.lua new file mode 100644 index 00000000..671f11cb --- /dev/null +++ b/expcore/gui/elements/progress-bar.lua @@ -0,0 +1,390 @@ +--[[-- Core Module - Gui + @module Gui + @alias Prototype +]] + +--- Progress Bars. +-- Gui element define for progress bars +-- @section progress-bars + +--[[ +>>>> Functions + ProgressBar.set_maximum(element,amount,count_down) --- Sets the maximum value that represents the end value of the progress bar + ProgressBar.increment(element,amount) --- Increases the value of the progressbar, if a define is given all of its instances have incremented + ProgressBar.decrement(element,amount) --- Decreases the value of the progressbar, if a define is given all of its instances have decremented + + ProgressBar.new_progressbar(name) --- Creates a new progressbar element define + ProgressBar._prototype:set_maximum(amount,count_down) --- Sets the maximum value that represents the end value of the progress bar + ProgressBar._prototype:use_count_down(state) --- Will set the progress bar to start at 1 and trigger when it hits 0 + ProgressBar._prototype:increment(amount,category) --- Increases the value of the progressbar + ProgressBar._prototype:increment_filtered(amount,filter) --- Increases the value of the progressbar, if the filter condition is met, does not work with store + ProgressBar._prototype:decrement(amount,category) --- Decreases the value of the progressbar + ProgressBar._prototype:decrement_filtered(amount,filter) --- Decreases the value of the progressbar, if the filter condition is met, does not work with store + ProgressBar._prototype:add_element(element,maximum) --- Adds an element into the list of instances that will are waiting to complete, does not work with store + ProgressBar._prototype:reset_element(element) --- Resets an element, or its store, to be back at the start, either 1 or 0 + + ProgressBar._prototype:on_complete(callback) --- Triggers when a progress bar element completes (hits 0 or 1) + ProgressBar._prototype:on_complete(callback) --- Triggers when a store value completes (hits 0 or 1) + ProgressBar._prototype:event_counter(filter) --- Event handler factory that counts up by 1 every time the event triggers, can filter which elements have incremented + ProgressBar._prototype:event_countdown(filter) --- Event handler factory that counts down by 1 every time the event triggers, can filter which elements have decremented +]] +local Gui = require 'expcore.gui.core' --- @dep expcore.gui.core +local Prototype = require 'expcore.gui.prototype' --- @dep expcore.gui.prototype +local Global = require 'utils.global' --- @dep utils.global +local Game = require 'utils.game' --- @dep utils.game + +--- Event call for when the value is outside the range 0-1 +-- @tparam table define the define that this is acting on +-- @tparam LuaGuiElement element the element that triggered the event +local function event_call(define,element) + local player = Game.get_player_by_index(element.player_index) + define:raise_event('on_complete',player,element,function() + define:add_element(element) + define:reset_element(element) + end) +end + +--- Store call for store update +-- @tparam table define the define that this is acting on +-- @tparam LuaGuiElement element the element that triggered the event +-- @tparam number value the new value for the progress bar +local function store_update(define,element,value) + if value then + element.value = value + if define.count_down and value <= 0 + or not define.count_down and value >= 1 then + event_call(define,element) + end + end +end + +local ProgressBar = { + unregistered={}, -- elements with no callbacks + independent={}, -- elements with a link to a define + _prototype=Prototype.extend{ + on_complete = Prototype.event, + on_store_complete = Prototype.event, + add_store = Prototype.store(false,store_update), + add_sync_store = Prototype.store(true,store_update) + } +} + +Global.register({ + unregistered = ProgressBar.unregistered, + independent = ProgressBar.independent +},function(tbl) + ProgressBar.unregistered = tbl.unregistered + ProgressBar.independent = tbl.independent +end) + +--- Gets the define data, cant use Gui.get_define as it would error +-- @tparam ?table|string define the define to get +-- @treturn table the define or nil +local function get_define(define) + if type(define) == 'table' then + if define.name and Gui.defines[define.name] then + return Gui.defines[define.name] + end + end + + return Gui.defines[define] +end + +--- Gets the element data, used when there is no define +-- @tparam LuaGuiElement element the element to get the data of +-- @treturn table the element data similar to define +local function get_element(element) + if not element.valid then return end + local name = element.player_index..':'..element.index + + if ProgressBar.unregistered[name] then + return ProgressBar.unregistered[name] + end +end + +--- Sets the maximum value that represents the end value of the progress bar +-- @tparam ?LuaGuiElement|string element either a gui element or a registered define +-- @tparam number amount the amount to have set as the maximum +function ProgressBar.set_maximum(element,amount) + amount = amount > 0 and amount or error('amount must be greater than 0') + + local define = get_define(element) + if define then + define:set_default_maximum(amount) + + else + local element_data = get_element(element) + + if element_data then + element_data.maximum = amount + + else + local name = element.player_index..':'..element.index + ProgressBar.unregistered[name] = { + element=element, + maximum=amount or 1 + } + + end + + end +end + +--- Increases the value of the progressbar, if a define is given all of its instances have incremented +-- @tparam ?LuaGuiElement|string element either a gui element or a registered define +-- @tparam[opt=1] number amount the amount to increase the progressbar by +function ProgressBar.increment(element,amount) + amount = type(amount) == 'number' and amount or 1 + + local define = get_define(element) + if define then + define:increment(amount) + + else + local element_data = get_element(element) + + if element_data then + local real_amount = amount/element_data.maximum + element.value = element.value + real_amount + + if element.value >= 1 then + local name = element.player_index..':'..element.index + ProgressBar.unregistered[name] = nil + return true + end + end + + end +end + +--- Decreases the value of the progressbar, if a define is given all of its instances have decremented +-- @tparam ?LuaGuiElement|string element either a gui element or a registered define +-- @tparam[opt=1] number amount the amount to decrease the progressbar by +function ProgressBar.decrement(element,amount) + amount = type(amount) == 'number' and amount or 1 + + local define = get_define(element) + if define then + define:decrement(amount) + + else + local element_data = get_element(element) + + if element_data then + local real_amount = amount/element_data.maximum + element.value = element.value - real_amount + + if element.value <= 0 then + local name = element.player_index..':'..element.index + ProgressBar.unregistered[name] = nil + return true + end + end + + end +end + +--- Creates a new progressbar element define +-- @tparam[opt] string name the optional debug name that can be added +-- @treturn table the new progressbar element define +function ProgressBar.new_progressbar(name) + + local self = Gui.new_define(ProgressBar._prototype,name) + self.draw_data.type = 'progressbar' + + self:on_draw(function(player,element,maximum) + if self.store then + local category = self.categorize and self.categorize(element) or nil + local value = self:get_store(category) + if not value then + value = self.count_down and 1 or 0 + self:set_store(category,value) + end + element.value = value + + else + if self.count_down then + element.value = 1 + end + + if not ProgressBar.independent[self.name] then + ProgressBar.independent[self.name] = {} + end + + table.insert(ProgressBar.independent[self.name],{ + element = element, + maximum = maximum + }) + + end + + end) + + return self +end + +--- Sets the maximum value that represents the end value of the progress bar +-- @tparam number amount the amount to have set as the maximum +-- @treturn table the define to allow chaining +function ProgressBar._prototype:set_default_maximum(amount) + amount = amount > 0 and amount or error('amount must be greater than 0') + self.default_maximum = amount + return self +end + +--- Will set the progress bar to start at 1 and trigger when it hits 0 +-- @tparam[opt=true] boolean state when true the bar will start filled, to be used with decrease +-- @treturn table the define to allow chaining +function ProgressBar._prototype:use_count_down(state) + if state == false then + self.count_down = false + else + self.count_down = true + end + return self +end + +--- Main logic for changing the value of a progress bar, this only applies when its a registered define +-- @tparam table self the define that is being changed +-- @tparam number amount the amount which it is being changed by, may be negative +-- @tparam[opt] string category the category to use with store +-- @tparam[opt] function filter when given the filter must return true for the value of the element to be changed +local function change_value_prototype(self,amount,category,filter) + + local function reset_store() + local value = self.count_down and 1 or 0 + self:set_store(category,value) + end + + if self.store then + local value = self:get_store(category) or self.count_down and 1 or 0 + local maximum = self.default_maximum or 1 + local new_value = value + (amount/maximum) + + self:set_store(category,new_value) + + if self.count_down and new_value <= 0 + or not self.count_down and new_value >= 1 then + self:clear_store(category) + self:raise_event('on_store_complete',category,reset_store) + return + end + + return + end + + if ProgressBar.independent[self.name] then + for key,element_data in pairs(ProgressBar.independent[self.name]) do + local element = element_data.element + if not element or not element.valid then + ProgressBar.independent[self.name][key] = nil + + else + if not filter or filter(element) then + local maximum = element_data.maximum or self.default_maximum or 1 + element.value = element.value + (amount/maximum) + + if self.count_down and element.value <= 0 + or not self.count_down and element.value >= 1 then + ProgressBar.independent[self.name][key] = nil + event_call(self,element) + end + end + + end + end + end + +end + +--- Increases the value of the progressbar +-- @tparam[opt=1] number amount the amount to increase the progressbar by +-- @tparam[opt] string category the category that is used with a store +function ProgressBar._prototype:increment(amount,category) + amount = type(amount) == 'number' and amount or 1 + change_value_prototype(self,amount,category) +end + +--- Increases the value of the progressbar, if the filter condition is met, does not work with store +-- @tparam[opt=1] number amount the amount to increase the progressbar by +-- @tparam function filter the filter to be used +function ProgressBar._prototype:increment_filtered(amount,filter) + amount = type(amount) == 'number' and amount or 1 + change_value_prototype(self,amount,nil,filter) +end + +--- Decreases the value of the progressbar +-- @tparam[opt=1] number amount the amount to decrease the progressbar by +-- @tparam[opt] string category the category that is used with a store +function ProgressBar._prototype:decrement(amount,category) + amount = type(amount) == 'number' and amount or 1 + change_value_prototype(self,-amount,category) +end + +--- Decreases the value of the progressbar, if the filter condition is met, does not work with store +-- @tparam[opt=1] number amount the amount to decrease the progressbar by +-- @tparam function filter the filter to be used +function ProgressBar._prototype:decrement_filtered(amount,filter) + amount = type(amount) == 'number' and amount or 1 + change_value_prototype(self,-amount,nil,filter) +end + +--- Adds an element into the list of instances that will are waiting to complete, does not work with store +-- note use store if you want persistent data, this only stores the elements not the values which they have +-- @tparam LuaGuiElement element the element that you want to add into the waiting to complete list +-- @tparam[opt] number maximum the maximum for this element if not given the default for this define is used +function ProgressBar._prototype:add_element(element,maximum) + if self.store then return end + if not ProgressBar.independent[self.name] then + ProgressBar.independent[self.name] = {} + end + table.insert(ProgressBar.independent[self.name],{ + element = element, + maximum = maximum + }) +end + +--- Resets an element, or its store, to be back at the start, either 1 or 0 +-- @tparam LuaGuiElement element the element that you want to reset the progress of +function ProgressBar._prototype:reset_element(element) + if not element or not element.valid then return end + local value = self.count_down and 1 or 0 + if self.store then + local category = self.categorize and self.categorize(element) or value + self:set_store(category,value) + else + element.value = value + end +end + +--- Event handler factory that counts up by 1 every time the event triggers, can filter which elements have incremented +-- @tparam[opt] function filter when given will use filtered increment +-- @treturn function the event handler +function ProgressBar._prototype:event_counter(filter) + if type(filter) == 'function' then + return function() + self:increment_filtered(1,filter) + end + else + return function() + self:increment() + end + end +end + +--- Event handler factory that counts down by 1 every time the event triggers, can filter which elements have decremented +-- @tparam[opt] function filter when given will use filtered decrement +-- @treturn function the event handler +function ProgressBar._prototype:event_countdown(filter) + if type(filter) == 'function' then + return function() + self:decrement_filtered(1,filter) + end + else + return function() + self:decrement() + end + end +end + +return ProgressBar \ No newline at end of file diff --git a/expcore/gui/elements/slider.lua b/expcore/gui/elements/slider.lua new file mode 100644 index 00000000..110dd1bd --- /dev/null +++ b/expcore/gui/elements/slider.lua @@ -0,0 +1,177 @@ +--[[-- Core Module - Gui + @module Gui + @alias Prototype +]] + +--- Sliders. +-- Gui class define for sliders +-- @section sliders + +--[[ +>>>> Functions + Slider.new_slider(name) --- Creates a new slider element define + + Slider._prototype:on_element_update(callback) --- Registers a handler for when an element instance updates + Slider._prototype:on_store_update(callback) --- Registers a handler for when the stored value updates + + Slider._prototype:set_range(min,max) --- Sets the range of a slider, if not used will use default values for a slider + Slider._prototype:draw_label(element) --- Draws a new label and links its value to the value of this slider, if no store then it will only show one value per player + Slider._prototype:enable_auto_draw_label(state) --- Enables auto draw of the label, the label will share the same parent element as the slider + + Other functions present from expcore.gui.core +]] +local Gui = require 'expcore.gui.core' --- @dep expcore.gui.core +local Prototype = require 'expcore.gui.prototype' --- @dep expcore.gui.prototype +local Instances = require 'expcore.gui.instances' --- @dep expcore.gui.instances +local Game = require 'utils.game' --- @dep utils.game + +--- Event call for on_value_changed and store update +-- @tparam table define the define that this is acting on +-- @tparam LuaGuiElement element the element that triggered the event +-- @tparam number value the new value for the slider +local function event_call(define,element,value) + local player = Game.get_player_by_index(element.player_index) + + local min,max = element.get_slider_minimum(),element.get_slider_maximum() + local delta = max-min + local percent = delta == 0 and 0 or (value-min)/delta + + define:raise_event('on_element_update',player,element,value,percent) + + local category = player.name + if define.categorize then + category = define.categorize(element) + end + + Instances.unregistered_get_elements(define.name..'-label',category,function(label) + label.caption = tostring(math.round(value,2)) + end) +end + +--- Store call for store update +-- @tparam table define the define that this is acting on +-- @tparam LuaGuiElement element the element that triggered the event +-- @tparam number value the new value for the slider +local function store_update(define,element,value) + element.slider_value = value + event_call(define,element,value) +end + +local Slider = { + _prototype=Prototype.extend{ + on_element_update = Prototype.event, + on_store_update = Prototype.event, + add_store = Prototype.store(false,store_update), + add_sync_store = Prototype.store(true,store_update) + } +} + +--- Creates a new slider element define +-- @tparam[opt] string name the optional debug name that can be added +-- @treturn table the new slider element define +function Slider.new_slider(name) + + local self = Gui.new_define(Slider._prototype,name) + self.draw_data.type = 'slider' + + self:on_draw(function(player,element) + local min,max = element.get_slider_minimum(),element.get_slider_maximum() + + if type(self.min) == 'function' then + min = self.min(player,element) + end + + if type(self.max) == 'function' then + max = self.max(player,element) + end + + element.set_slider_minimum_maximum(min,max) + + if self.store then + local category = self.categorize and self.categorize(element) or nil + local value = self:get_store(category) + if value then element.slider_value = value end + end + + if self.auto_label then + self:draw_label(element.parent) + end + end) + + Gui.on_value_changed(self.name,function(event) + local element = event.element + local value = element.slider_value + + if self.store then + local category = self.categorize and self.categorize(element) or value + self:set_store(category,value) + + else + event_call(self,element,value) + + end + + end) + + return self +end + +--- Sets the range of a slider, if not used will use default values for a slider +-- @tparam[opt] number min the minimum value that the slider can take +-- @tparam[opt] number max the maximum value that the slider can take +-- @treturn self the define to allow chaining +function Slider._prototype:set_range(min,max) + self.min = min + self.max = max + + if type(min) == 'number' then + self.draw_data.minimum_value = min + end + + if type(max) == 'number' then + self.draw_data.maximum_value = max + end + + return self +end + +--- Draws a new label and links its value to the value of this slider, if no store then it will only show one value per player +-- @tparam LuaGuiElement element the parent element that the label will be drawn to +-- @treturn LuaGuiElement the new label element so that styles can be applied +function Slider._prototype:draw_label(element) + local name = self.name..'-label' + if element[name] then return end + + local value = 0 + if self.store then + local category = self.categorize and self.categorize(element) or value + value = self:get_store(category) or 0 + end + + local new_element = element.add{ + name=name, + type='label', + caption=tostring(math.round(value,2)) + } + + local categorise = self.categorise or Gui.categorize_by_player + local category = categorise(new_element) + + Instances.unregistered_add_element(name,category,new_element) + + return new_element +end + +--- Enables auto draw of the label, the label will share the same parent element as the slider +-- @tparam[opt=true] boolean state when false will disable the auto draw of the label +-- @treturn self the define to allow chaining +function Slider._prototype:enable_auto_draw_label(state) + if state == false then + self.auto_label = false + else + self.auto_label = true + end + return self +end + +return Slider \ No newline at end of file diff --git a/expcore/gui/elements/text.lua b/expcore/gui/elements/text.lua new file mode 100644 index 00000000..406c4ea0 --- /dev/null +++ b/expcore/gui/elements/text.lua @@ -0,0 +1,149 @@ +--[[-- Core Module - Gui + @module Gui + @alias Prototype +]] + +--- Text. +-- Gui class define for text fields and text boxes +-- @section text + +--[[ +>>>> Functions + Text.new_text_field(name) --- Creates a new text field element define + Text._prototype_field:on_element_update(callback) --- Registers a handler for when an element instance updates + Text._prototype_field:on_store_update(callback) --- Registers a handler for when the stored value updates + + Text.new_text_box(name) --- Creates a new text box element define + Text._prototype_field:on_element_update(callback) --- Registers a handler for when an element instance updates + Text._prototype_field:on_store_update(callback) --- Registers a handler for when the stored value updates + Text._prototype_box:set_selectable(state) --- Sets the text box to be selectable + Text._prototype_box:set_word_wrap(state) --- Sets the text box to have word wrap + Text._prototype_box:set_read_only(state) --- Sets the text box to be read only + + Other functions present from expcore.gui.core +]] +local Gui = require 'expcore.gui.core' --- @dep expcore.gui.core +local Prototype = require 'expcore.gui.prototype' --- @dep expcore.gui.prototype +local Game = require 'utils.game' --- @dep utils.game + +--- Store call for store update +-- @tparam table define the define that this is acting on +-- @tparam LuaGuiElement element the element that triggered the event +-- @tparam string value the new text for the text field +local function store_update(define,element,value) + element.text = value + local player = Game.get_player_by_index(element.player_index) + define:raise_event('on_element_update',player,element,value) +end + +local Text = { + _prototype_field=Prototype.extend{ + on_element_update = Prototype.event, + on_store_update = Prototype.event, + add_store = Prototype.store(false,store_update), + add_sync_store = Prototype.store(true,store_update) + }, + _prototype_box=Prototype.extend{ + on_element_update = Prototype.event, + on_store_update = Prototype.event, + add_store = Prototype.store(false,store_update), + add_sync_store = Prototype.store(true,store_update) + } +} + +--- Creates a new text field element define +-- @tparam[opt] string name the optional debug name that can be added +-- @treturn table the new text field element define +function Text.new_text_field(name) + + local self = Gui.new_define(Text._prototype_field,name) + self.draw_data.type = 'textfield' + + self:on_draw(function(player,element) + if self.selectable then + element.selectable = true + end + + if self.word_wrap then + element.word_wrap = true + end + + if self.read_only then + element.read_only = true + end + + if self.store then + local category = self.categorize and self.categorize(element) or nil + local value = self:get_store(category) + if value then element.text = value end + end + end) + + Gui.on_text_changed(self.name,function(event) + local element = event.element + local value = element.text + + if self.store then + local category = self.categorize and self.categorize(element) or value + self:set_store(category,value) + + else + self:raise_event('on_element_update',event.player,element,value) + + end + + end) + + return self +end + +--- Creates a new text box element define +-- @tparam[opt] string name the optional debug name that can be added +-- @treturn table the new text box element define +function Text.new_text_box(name) + local self = Text.new_text_field(name) + self.draw_data.type = 'text-box' + + local mt = getmetatable(self) + mt.__index = Text._prototype_box + + return self +end + +--- Sets the text box to be selectable +-- @tparam[opt=true] boolean state when false will set the state to false +-- @treturn self table the define to allow for chaining +function Text._prototype_box:set_selectable(state) + if state == false then + self.selectable = false + else + self.selectable = true + end + return self +end + +--- Sets the text box to have word wrap +-- @tparam[opt=true] boolean state when false will set the state to false +-- @treturn self table the define to allow for chaining +function Text._prototype_box:set_word_wrap(state) + if state == false then + self.word_wrap = false + else + self.word_wrap = true + end + return self +end + +--- Sets the text box to be read only +-- @tparam[opt=true] boolean state when false will set the state to false +-- @treturn self table the define to allow for chaining +function Text._prototype_box:set_read_only(state) + if state == false then + self.read_only = false + else + self.read_only = true + end + return self +end + +return Text \ No newline at end of file diff --git a/expcore/gui/instances.lua b/expcore/gui/instances.lua new file mode 100644 index 00000000..86fcd11f --- /dev/null +++ b/expcore/gui/instances.lua @@ -0,0 +1,235 @@ +--[[-- Core Module - Gui + @module Gui + @alias Prototype +]] + +--- Instances. +-- This file is a breakout from core which forcues on instance management of defines +-- @section instances + +--[[ +>>>> Using registered instance groups + The main use of this module is to register a group of elements referred here as "instances of an element define" in which + is meant that you define the name of a group of drawn elements that are really just multiple versions of a single element. + For example this might be that you have one label in multiple places (either for one player or many) and you want to update + the caption of all of them at once; this is where this module comes it. + + First you must register the way that the instances are stored and under what name, using Instances.register you will give the + name of the collective group of instances followed by an optional categorise function which allows variants to be stored under one + name (like one for each force or player) + + -- categorise works in the same way as store categorise + -- so the function will world here but no value is stored only gui elements + Instances.register('score',Gui.categorize_by_force) + + Then when you draw the new element to a gui you will want to add the element to the group: + + Instances.add_element('score',new_element) + + Then when you want to get the instances you have two options; Instances.get_elements or Instances.apply_to_elements when you want loop + over the elements it is more efficient to use apply_to_elements: + + Instances.get_elements('score','player') -- returns all elements that were added with the 'player' category + Instances.apply_to_elements('score','player',function(element) -- runs the function on every valid element + element.caption = 0 + end) + + Note that if you don't give a categorise function then you don't need to give a category when getting the elements. + +>>>> Using unregistered instance groups + When using a registered group and the functions that go with them it is much simpler to use and more importantly includes error checking + for valid instance group names; the down side is that the group must be registered which can only be done during start-up and not during runtime. + To counter this there are two functions similar to those above in order to add and get instances but may lead to errors not being noticed due to + the error internal error checking being skipped to allow it to work. + + The main difference between the two groups of functions is that the category must always be present even if is nil; example below shows how a + instance group would work when registered vs unregistered: + + -- Registered with category + Instances.register('score',Gui.categorize_by_force) -- force_store will return the force name of an element + Instances.add_element('score',new_element) -- the new element is added to the category based on in force + Instances.apply_to_elements('score','player',function(element) + element.caption = '0' + end) -- gets all instances from the player force and sets the caption to 0 + + -- Unregistered with category + Instances.unregistered_add_element('score','player',new_element) -- adds the new element to the player category + Instances.unregistered_apply_to_elements('score','player',function(element) + element.caption = '0' + end) -- gets all instances from the player force and sets the caption to 0 + + -- Registered without category; note that category can just be ignored + Instances.register('score') -- all instances will be under one group with no categories + Instances.add_element('score',new_element) -- adds the new element to the instance list + Instances.apply_to_elements('score',function(element) + element.caption = '0' + end) -- gets all instances and sets the element caption to 0 + + -- Unregistered without category; note that category must be given as nil + Instances.unregistered_add_element('score',nil,new_element) -- adds the new element to a single group with no categories + Instances.unregistered_apply_to_elements('score',nil,function(element) + element.caption = '0' + end) -- gets all instances and sets the element caption to 0 + +>>>> Functions + Instances.has_categories(name) --- Returns if a instance group has a categorise function; must be registered + Instances.is_registered(name) --- Returns if the given name is a registered instance group + Instances.register(name,categorise) --- Registers the name of an instance group to allow for storing element instances + + Instances.add_element(name,element) --- Adds an element to the instance group under the correct category; must be registered + Instances.get_elements_raw(name,category) --- Gets all element instances without first removing any invalid ones; used internally and must be registered + Instances.get_valid_elements(name,category,callback) --- Gets all valid element instances and has the option of running a callback on those that are valid + + Instances.unregistered_add_element(name,category,element) --- A version of add_element that does not require the group to be registered + Instances.unregistered_get_elements(name,category,callback) --- A version of get_elements that does not require the group to be registered +]] +local Global = require 'utils.global' --- @dep utils.global + +local Instances = { + categorise={}, + data={} +} +Global.register(Instances.data,function(tbl) + Instances.data = tbl +end) + +--- Returns if a instance group has a categorise function; must be registered +-- @tparam string name the name of the instance group +-- @treturn boolean true if there is a categorise function +function Instances.has_categories(name) + return type(Instances.categorise[name]) == 'function' +end + +--- Returns if the given name is a registered instance group +-- @tparam string name the name of the instance group you are testing +-- @treturn boolean true if the name is registered +function Instances.is_registered(name) + return Instances.categorise[name] ~= nil +end + +--- Registers the name of an instance group to allow for storing element instances +-- @tparam string name the name of the instance group; must to unique +-- @tparam[opt] function categorise function used to turn the element into a string +-- categorise param - element LuaGuiElement - the gui element to be turned into a string +-- categorise return - string - the category that the element will be added to like the player's name or force's name +-- @treturn string the name that was added so it can be used as a variable +function Instances.register(name,categorise) + if _LIFECYCLE ~= _STAGE.control then + return error('Can only be called during the control stage', 2) + end + + if Instances.categorise[name] then + return error('Instances for '..name..' already exist.',2) + end + + categorise = type(categorise) == 'function' and categorise or true + + Instances.data[name] = {} + Instances.categorise[name] = categorise + + return name +end + +--- Adds an element to the instance group under the correct category; must be registered +-- @tparam string name the name of the instance group to add the element to +-- @tparam LuaGuiElement element the element to add the the instance group +function Instances.add_element(name,element) + if not Instances.categorise[name] then + return error('Invalid name for instance group: '..name,2) + end + + if Instances.has_categories(name) then + local category = Instances.categorise[name](element) + if not Instances.data[name][category] then Instances.data[name][category] = {} end + table.insert(Instances.data[name][category],element) + else + table.insert(Instances.data[name],element) + end +end + +--- Gets all element instances without first removing any invalid ones; used internally and must be registered +-- @tparam string name the name of the instance group to get the instances of +-- @tparam[opt] string category the category to get the instance from, not needed when no categorise function +-- @treturn table the table of element instances of which some may be invalid +function Instances.get_elements_raw(name,category) + if not Instances.categorise[name] then + return error('Invalid name for instance group: '..name,2) + end + + if Instances.has_categories(name) then + return Instances.data[name][category] or {} + else + return Instances.data[name] + end +end + +--- Gets all valid element instances and has the option of running a callback on those that are valid +-- @tparam string name the name of the instance group to get the instances of +-- @tparam[opt] string category the category to get the instances of, not needed when no categorise function +-- @tparam[opt] function callback when given the callback will be ran on all valid elements +-- callback param - element LuaGuiElement - the current valid element +-- @treturn table the table of element instances with all invalid ones removed +function Instances.get_valid_elements(name,category,callback) + if not Instances.categorise[name] then + return error('Invalid name for instance group: '..name,2) + end + + category = category or callback + local elements = Instances.get_elements_raw(name,category) + local categorise = Instances.has_categories(name) + + for key,element in pairs(elements) do + if not element or not element.valid then + elements[key] = nil + else + if categorise and callback then callback(element) + elseif category then category(element) end + end + end + + return elements +end +Instances.get_elements = Instances.get_valid_elements +Instances.apply_to_elements = Instances.get_valid_elements + +--- A version of add_element that does not require the group to be registered +-- @tparam string name the name of the instance group to add the element to +-- @tparam ?string|nil category the category to add the element to, can be nil but must still be given +-- @tparam LuaGuiElement element the element to add to the instance group +function Instances.unregistered_add_element(name,category,element) + if not Instances.data[name] then Instances.data[name] = {} end + if category then + if not Instances.data[name][category] then Instances.data[name][category] = {} end + table.insert(Instances.data[name][category],element) + else + table.insert(Instances.data[name],element) + end +end + +--- A version of get_elements that does not require the group to be registered +-- @tparam string name the name of the instance group to get the instances of +-- @tparam ?string|nil category the category to get the instances of, can be nil but must still be given +-- @tparam[opt] function callback when given will be called on all valid instances +-- callback param - element LuaGuiElement - the current valid element +-- @treturn table the table of element instances with all invalid ones removed +function Instances.unregistered_get_elements(name,category,callback) + local elements = Instances.data[name] + if elements and category then + elements = elements[category] + end + + if not elements then return {} end + + for key,element in pairs(elements) do + if not element or not element.valid then + elements[key] = nil + else + if callback then callback(element) end + end + end + + return elements +end +Instances.unregistered_apply_to_elements = Instances.runtime_get_elements + +return Instances \ No newline at end of file diff --git a/expcore/gui/prototype.lua b/expcore/gui/prototype.lua index 269b4023..20624583 100644 --- a/expcore/gui/prototype.lua +++ b/expcore/gui/prototype.lua @@ -3,721 +3,309 @@ @alias Prototype ]] ---- Concept Base. --- Functions that are used to make concepts --- @section concept-base +--- Prototype. +-- Used to create new gui prototypes see elements and concepts +-- @section prototype -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 +--[[ + >>>> Functions + Constructor.event(event_name) --- Creates a new function to add functions to an event handler + Constructor.extend(new_prototype) --- Extents a prototype with the base functions of all gui prototypes, no metatables + Constructor.store(sync,callback) --- Creates a new function which adds a store to a gui define + Constructor.setter(value_type,key,second_key) --- Creates a setter function that checks the type when a value is set -local Factorio_Events = {} -local Prototype = { - draw_callbacks = {}, - clone_callbacks = {}, - properties = {}, - factorio_events = {}, - events = {} -} + Prototype:uid() --- Gets the uid for the element define + Prototype:debug_name(value) --- Sets a debug alias for the define + Prototype:set_caption(value) --- Sets the caption for the element define + Prototype:set_tooltip(value) --- Sets the tooltip for the element define + Prototype:set_style(style,callback) --- Sets the style for the element define + Prototype:set_embedded_flow(state) --- Sets the element to be drawn inside a nameless flow, can be given a name using a function ---- Acts as a gernal handler for any factorio event -local function factorio_event_handler(event) - local element = event.element - local rasied_event = event.name - local factorio_event_concepts = Factorio_Events[rasied_event] - if element then - if not element.valid then return end - local concept = factorio_event_concepts[element.name] - if concept then - for event_name, factorio_event in pairs(concept.factorio_events) do - if rasied_event == factorio_event then - concept:raise_event(event_name,event,true) - end - end + Prototype:set_pre_authenticator --- Sets an authenticator that blocks the draw function if check fails + Prototype:set_post_authenticator --- Sets an authenticator that disables the element if check fails + + Prototype:raise_event(event_name,...) --- Raises a custom event for this define, any number of params can be given + Prototype:draw_to(element,...) --- The main function for defines, when called will draw an instance of this define to the given element + + Prototype:get_store(category) --- Gets the value in this elements store, category needed if categorize function used + Prototype:set_store(category,value) --- Sets the value in this elements store, category needed if categorize function used + Prototype:clear_store(category) --- Sets the value in this elements store to nil, category needed if categorize function used +]] +local Game = require 'utils.game' --- @dep utils.game +local Store = require 'expcore.store' --- @dep expcore.store +local Instances = require 'expcore.gui.instances' --- @dep expcore.gui.instances + +local Constructor = {} +local Prototype = {} + +--- Creates a new function to add functions to an event handler +-- @tparam string event_name the name of the event that callbacks will be added to +-- @treturn function the function used to register handlers +function Constructor.event(event_name) + --- Adds a callback as a handler for an event + -- @tparam table self the gui define being acted on + -- @tparam function callback the function that will be added as a handler for the event + -- @treturn table self returned to allowing chaining of functions + return function(self,callback) + if type(callback) ~= 'function' then + return error('Event callback for '..event_name..' must be a function',2) end - else - for _,concept in pairs(factorio_event_concepts) do - for event_name, factorio_event in pairs(concept.factorio_events) do - if rasied_event == factorio_event then - concept:raise_event(event_name,event,true) - end - end + local handlers = self.events[event_name] + if not handlers then + handlers = {} + self.events[event_name] = handlers end + handlers[#handlers+1] = callback + return self end end ---[[-- Used to copy all the settings from one concept to another and removing links to the orginal -@tparam string concept_name the name of the new concept; must be unique -@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(Gui.concepts.button):clone() -]] -function Prototype:clone() - local concept = table.deep_copy(self) - - -- Replace name of the concept - 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 = {} - for event_name,_ in pairs(self.events) do - concept.events[event_name] = {} - end - - -- Remakes even handlers for factorio - for _,factorio_event in pairs(concept.factorio_events) do - Factorio_Events[factorio_event][concept.name] = concept - end - - -- Remove all refrences to an instance store - if concept.instance_store then - concept.instance_store = nil - concept.get_instances = nil - concept.add_instance = nil - concept.update_instances = nil - end - - -- Remove all refrences to a data store - if concept.data_store then - concept.data_store = nil - concept.get_data = nil - concept.set_data = nil - concept.clear_data = nil - concept.update_data = nil - concept.on_data_store_update = nil - concept.events.on_data_store_update = nil - end - - -- Remove all refrences to a combined store - if concept.sync_instance then - concept.sync_instance = nil - concept.set_store_from_instance = nil - end - - -- Loop over all the clone defines, element is updated when a value is returned - 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.debug_name..':\n\t'..rtn) - end - end - - return concept -end - ---[[-- Use to add your own callbacks to the clone function, for example adding to a local table -@tparam function clone_callback the function which is called with the concept to have something done to it -@treturn table self to allow chaining -@usage-- Adding concept to a local table -local buttons = {} -local button = -Gui.get_concept('Button') -:define_clone(function(concept) - buttons[concept.name] = concept -end) -]] -function Prototype:define_clone(clone_callback) - -- Check that it is a function that is being added - if type(clone_callback) ~= 'function' then - error('Draw define must be a function',2) - end - - -- Add the draw function - self.clone_callbacks[#self.clone_callbacks+1] = clone_callback - - return 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) - -- over writen in core file - 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 - ---[[-- Adds a new event trigger to the concept which can be linked to a factorio event -@tparam string event_name the name of the event to add, must be unique, recomented to start with "on_" -@tparam[opt] defines.events factorio_event when given will fire the custom event when the factorio event is raised -@tparam[opt] function event_condition used to filter when a factorio event triggers the custom event; if the event contains a reference to an element then names are automatically filtered -@treturn GuiConcept to allow chaining of functions -@usage-- Adds an on_admin_clicked event to fire when ever an admin clicks the button -local custom_button = -Gui.get_concept('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) -]] -function Prototype:new_event(event_name,factorio_event,event_condition) - -- Check the event does not already exist - if self.events[event_name] then - error('Event is already defined',2) - end - ---[[-- Adds a custom event handler, replace with the name of the event -@function Prototype:on_custom_event -@tparam function handler the function which will recive the event -@treturn GuiConcept to allow chaining of functions -@usage-- When an admin clicks the button a message is printed -local custom_button = -Gui.get_concept('CustomButton') -:on_admin_clicked(function(event) - game.print(event.player.name..' pressed my admin button') -end) -]] - - -- Adds a handler table and the event handler adder, comment above not indented to look better in docs - self.events[event_name] = {} - self[event_name] = function(concept,handler) - if type(handler) ~= 'function' then - error('Event handler must be a function',2) - end - - local handlers = concept.events[event_name] - handlers[#handlers+1] = handler - - return concept - end - - -- Adds the factorio event handler if this event is linked to one - if factorio_event then - self.factorio_events[event_name] = factorio_event - self.events[event_name].factorio_event_condition = event_condition - - local factorio_event_concepts = Factorio_Events[factorio_event] - if not factorio_event_concepts then - factorio_event_concepts = {} - Factorio_Events[factorio_event] = factorio_event_concepts - Event.add(factorio_event,factorio_event_handler) - end - - if not factorio_event_concepts[self.name] then - factorio_event_concepts[self.name] = self - end - end - - return self -end - ---[[-- Raises a custom event, folowing keys included automaticlly: concept, event name, game tick, player from player_index, element if valid -@tparam string event_name the name of the event that you want to raise -@tparam[opt={}] table event table containg data you want to send with the event, some keys already included -@tparam[opt=false] boolean from_factorio internal use, if the raise came from the factorio event handler -@usage-- Raising the custom event on_admin_clicked -local custom_button = -Gui.get_concept('CustomButton') - --- Note that this is an example and would not work due it expecting a valid element for event.element --- this will however work fine if you can provide all expected keys, or its not linked to any factorio event -custom_button:raise_event('on_admin_clicked',{ - player_index = game.player.index -}) -]] -function Prototype:raise_event(event_name,event,from_factorio) - -- Check that the event exists - if not self.events[event_name] then - error('Event is not defined',2) - end - - -- Setup the event table with automatic keys - event = event or {} - event.concept = self - event.name = event.name or event_name - event.tick = event.tick or game.tick - event.player = event.player_index and Game.get_player_by_index(event.player_index) or nil - if event.element and not event.element.valid then return end - - -- Get the event handlers - local handlers = self.events[event_name] - - -- If it is from factorio and the filter fails - if from_factorio and handlers.factorio_event_condition and not handlers.factorio_event_condition(event) then - return - end - - -- Trigger every handler - for _,handler in ipairs(handlers) do - local success, err = pcall(handler,event) - if not success then - 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[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 = -Gui.get_concept('Button') -: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) -]] -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 - - -- 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 -@tparam any value the value that you want to set for this property -@treturn GuiConcept to allow chaining of functions -@usage-- Setting the caption on the base button concept after a cloning -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 = -Gui.get_concept('CustomButton') -:set_caption('Custom Button') -]] - - self['set_'..property_name] = function(concept,value,...) - if setter_callback then - -- 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.debug_name..'/'..property_name..':\n\t'..err) - end +--- Extents a prototype with the base functions of all gui prototypes, no metatables +-- @tparam table new_prototype the prototype that you want to add the functions to +-- @treturn table the same prototype but with the new functions added +function Constructor.extend(new_prototype) + for key,value in pairs(Prototype) do + if type(value) == 'table' then + new_prototype[key] = table.deepcopy(value) else - -- Otherwise just update the key - concept.properties[property_name] = value - end - - 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 - ---[[-- Used to define how the concept is turned into an ingame element or "instance" as we may refer to them -@tparam function draw_callback the function that will be called to draw/update the instance; this function must return the instance or the new acting instance -@treturn GuiConcept to allow chaining of functions -@usage-- Adding the draw define for the base button concept, we then return the element -local button = -Gui.get_concept('Button') -:define_draw(function(properties,parent,element) - -- 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.add{ - type = properties.type, - name = properties.name, - caption = properties.caption, - tooltip = properties.tooltip - } - - else - element = parent.add{ - type = properties.type, - name = properties.name, - sprite = properties.sprite, - tooltip = properties.tooltip - } - - end - - -- 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) - -- Check that it is a function that is being added - if type(draw_callback) ~= 'function' then - error('Draw define must be a function',2) - end - - -- Add the draw function - self.draw_callbacks[#self.draw_callbacks+1] = draw_callback - - return self -end - ---[[ Used to define a draw callback that is ran before any other draw callbacks, see define_draw -@tparam function draw_callback the function that will be called to draw/update the instance; this function must return the instance or the new acting instance -@treturn GuiConcept to allow chaining of functions -@usage-- Placing a button into a flow -local button = -Gui.get_concept('Button') -:define_pre_draw(function(properties,parent,element) - -- 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' - } - - -- 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_pre_draw(draw_callback) - -- Check that it is a function that is being added - if type(draw_callback) ~= 'function' then - error('Draw define must be a function',2) - end - - -- Add the draw function - table.insert(self.draw_callbacks,1,draw_callback) - - return self -end - ---[[-- Calls all the draw functions in order to create this concept in game; will also store and sync the instance if stores are used -@tparam LuaGuiElement parent_element the element that the concept will use as a base -@tparam[opt] string override_name when given this will be the name of the element rather than the concept id -@treturn LuaGuiElement the element that was created and then passed though and returned by the draw functions -@usage-- Drawing the custom button concept -local custom_button = -Gui.get_concept('CustomButton') - --- Note that the draw function from button was cloned, so unless we want to alter the base button we dont need a new draw define -custom_button:draw(game.player.gui.left) -]] -function Prototype:draw(parent_element,override_name,...) - local old_name = self.properties.name - local parent = parent_element - local element - - if override_name then self.properties.name = override_name end - -- Loop over all the draw defines, element is updated when a value is returned - for _,draw_callback in pairs(self.draw_callbacks) do - local success, _element, _parent = pcall(draw_callback,self.properties,parent,element,...) - if success then - if _element then element = _element end - if _parent then parent = _parent end - elseif not success then - self.properties.name = old_name - error('Gui draw handler error with '..self.debug_name..':\n\t'.._element) + new_prototype[key] = value end end - - -- Return the name back to its previous value - self.properties.name = old_name - - -- Adds the instance if instance store is used - if self.add_instance then - self.add_instance(element) - end - - -- Syncs the instance if there is a combined store - if self.sync_instance then - self.sync_instance(element) - end - - return element -end - ---- Concept Instances. --- Functions that are used to make store concept instances --- @section concept-instances - ---[[-- Adds an instance store to the concept; when a new instance is made it is stored so you can access it later -@tparam[opt] function category_callback when given will act as a way to turn an element into a string to act as a key; keys returned can over lap -@treturn GuiConcept to allow chaining of functions -@usage-- Allowing storing instances of the custom button; stored by the players index --- Note even thou this is a copy of Button; if Button had an instance store it would not be cloned over -local custom_button = -Gui.get_concept('CustomButton') -:define_instance_store(function(element) - return element.player_index -- The instances are stored based on player id -end) -]] -function Prototype:define_instance_store(category_callback) - self.instance_store = Store.register('gui_instances_'..self.name) - - local valid_category = category_callback and type(category_callback) == 'function' - local function get_category(category) - if type(category) == 'table' and type(category.__self) == 'userdata' then - return valid_category and category_callback(category) or nil - else - return category + for key,value in pairs(new_prototype) do + if value == Constructor.event then + new_prototype[key] = Constructor.event(key) end end + return new_prototype +end ---[[-- Gets all insatnces in a category, category may be nil to return all -@function Prototype.get_instances -@tparam[opt] ?string|LuaGuiElement category the category to get, can only be nil if categories are not used -@treturn table a table which contains all the instances -@usage-- Getting all the instances of the player with index 1 -local custom_button = -Gui.get_concept('CustomButton') +--- Creates a new function which adds a store to a gui define +-- @tparam boolean sync if the function should create a synced store +-- @tparam function callback the function called when needing to update the value of an element +-- @treturn function the function that will add a store for this define +function Constructor.store(sync,callback) + --- Adds a store for the define that is shared between all instances of the define in the same category, categorize is a function that returns a string + -- @tparam self table the gui define being acted on + -- @tparam[opt] string location a unique location identifier, when omitted a uid location will be used, use when sync is set to true + -- @tparam[opt] function categorize function used to determine the category of a LuaGuiElement, when omitted all share one single category + -- categorize param - LuaGuiElement element - the element that needs to be converted + -- categorize return - string - a deterministic string that references to a category such as player name or force name + -- @treturn self the element define to allow chaining + return function(self,location,categorize) + if self.store then return end -custom_button.get_instances(1) -- player index 1 -]] - function self.get_instances(category) - return Store.get(self.instance_store,get_category(category)) - end + if not sync then + categorize = location + location = Store.uid_location() + end ---[[-- Adds an instance to this concept, used automatically during concept:draw -@function Prototype.add_instance -@tparam LuaGuiElement element the element that will be added as an instance -@tparam[opt] string category the category to add this element under, if nil the category callback is used to assign one -@usage-- Adding an element as a instance for this concept, mostly for internal use -local custom_button = -Gui.get_concept('CustomButton') + if Store.is_registered(location) then + return error('Location for store is already registered: '..location,2) + end -custom_button.add_instance(element) -- normally not needed due to use in concept:draw -]] - function self.add_instance(element,category) - category = category or get_category(element) - if not valid_category then category = nil end - return Store.update(self.instance_store,category,function(tbl) - if type(tbl) ~= 'table' then - return {element} - else - table.insert(tbl,element) + self.store = location + self.categorize = categorize + + Instances.register(self.name,self.categorize) + + Store.register(self.store,sync,function(value,category) + self:raise_event('on_store_update',value,category) + + if Instances.is_registered(self.name) then + Instances.apply_to_elements(self.name,category,function(element) + callback(self,element,value) + end) end end) + + return self end - ---[[-- Applies an update function to all instances, simialr use to what table.forEach would be -@function Prototype.update_instances -@tparam[opt] ?string|LuaGuiElement category the category to get, can only be nil if categories are not used -@tparam function update_callback the function which is called on each instance, recives other args passed to update_instances -@usage-- Changing the font color of all instances for player 1 -local custom_button = -Gui.get_concept('CustomButton') - -custom_button.update_instances(1,function(element) - element.style.font_color = {r=1,g=0,b=0} -end) -]] - function self.update_instances(category,update_callback,...) - local args - if type(category) == 'function' then - args = {update_callback,...} - update_callback = category - category = nil - end - - local instances = Store.get(self.instance_store,get_category(category)) or {} - for key,instance in pairs(instances) do - if not instance or not instance.valid then - instances[key] = nil - - else - if args then - update_callback(instance,unpack(args)) - else - update_callback(instance,...) - end - end - end - end - - return self end ---- Concept Data. --- Functions that are used to store concept data --- @section concept-data +--- Creates a setter function that checks the type when a value is set +-- @tparam string value_type the type that the value should be when it is set +-- @tparam string key the key of the define that will be set +-- @tparam[opt] string second_key allows for setting of a key in a sub table +-- @treturn function the function that will check the type and set the value +function Constructor.setter(value_type,key,second_key) + local display_message = 'Gui define '..key..' must be of type '..value_type + if second_key then + display_message = 'Gui define '..second_key..' must be of type '..value_type + end ---[[-- Adds a data store to this concept which allows you to store synced/percistent data between instances -@tparam[opt] function category_callback when given will act as a way to turn an element into a string to act as a key; keys returned can over lap -@treturn GuiConcept to allow chaining of functions -@usage-- Adding a way to store data for this concept; each player has their own store --- Note even thou this is a copy of Button; if Button had an data store it would not be cloned over -local custom_button = -Gui.get_concept('CustomButton') -:define_data_store(function(element) - return element.player_index -- The data is stored based on player id -end) -]] -function Prototype:define_data_store(category_callback) - self:new_event('on_data_store_update') - self.data_store = Store.register('gui_data_'..self.name,function(value,key) - self:raise_event('on_data_store_update',{ - category = key, - value = value - }) - end) + local locale = false + if value_type == 'locale-string' then + locale = true + value_type = 'table' + end - local valid_category = category_callback and type(category_callback) == 'function' - local function get_category(category) - if type(category) == 'table' and type(category.__self) == 'userdata' then - return valid_category and category_callback(category) or nil + return function(self,value) + local v_type = type(value) + if v_type ~= value_type and (not locale or v_type ~= 'string') then + error(display_message,2) + end + + if second_key then + self[key][second_key] = value else - return category + self[key] = value + end + + return self + end +end + +--- Gets the uid for the element define +-- @treturn string the uid of this element define +function Prototype:uid() + return self.name +end + +--- Sets a debug alias for the define +-- @tparam string name the debug name for the element define that can be used to get this element define +-- @treturn self the element define to allow chaining +Prototype.debug_name = Constructor.setter('string','debug_name') + +--- Sets the caption for the element define +-- @tparam string caption the caption that will be drawn with the element +-- @treturn self the element define to allow chaining +Prototype.set_caption = Constructor.setter('locale-string','draw_data','caption') + +--- Sets the tooltip for the element define +-- @tparam string tooltip the tooltip that will be displayed for this element when drawn +-- @treturn self the element define to allow chaining +Prototype.set_tooltip = Constructor.setter('locale-string','draw_data','tooltip') + +--- Sets an authenticator that blocks the draw function if check fails +-- @tparam function callback the function that will be ran to test if the element should be drawn or not +-- callback param - LuaPlayer player - the player that the element is being drawn to +-- callback param - string define_name - the name of the define that is being drawn +-- callback return - boolean - false will stop the element from being drawn +-- @treturn self the element define to allow chaining +Prototype.set_pre_authenticator = Constructor.setter('function','pre_authenticator') + +--- Sets an authenticator that disables the element if check fails +-- @tparam function callback the function that will be ran to test if the element should be enabled or not +-- callback param - LuaPlayer player - the player that the element is being drawn to +-- callback param - string define_name - the name of the define that is being drawn +-- callback return - boolean - false will disable the element +-- @treturn self the element define to allow chaining +Prototype.set_post_authenticator = Constructor.setter('function','post_authenticator') + +--- Registers a callback to the on_draw event +-- @tparam function callback +-- callback param - LuaPlayer player - the player that the element was drawn to +-- callback param - LuaGuiElement element - the element that was drawn +-- callback param - any ... - any other params passed by the draw_to function +Prototype.on_draw = Constructor.event('on_draw') + +--- Registers a callback to the on_style_update event +-- @tparam function callback +-- callback param - LuaStyle style - the style that was changed and/or needs changing +Prototype.on_style_update = Constructor.event('on_style_update') + +--- Sets the style for the element define +-- @tparam string style the style that will be used for this element when drawn +-- @tparam[opt] function callback function is called when element is drawn to alter its style +-- @treturn self the element define to allow chaining +function Prototype:set_style(style,callback) + self.draw_data.style = style + if callback then + self:on_style_update(callback) + end + return self +end + +--- Sets the element to be drawn inside a nameless flow, can be given a name using a function +-- @tparam ?boolean|function state when true a padless flow is created to contain the element +-- @treturn self the element define to allow chaining +function Prototype:set_embedded_flow(state) + if state == false or type(state) == 'function' then + self.embedded_flow = state + else + self.embedded_flow = true + end + return self +end + +--- Raises a custom event for this define, any number of params can be given +-- @tparam string event_name the name of the event that you want to raise +-- @tparam any ... any params that you want to pass to the event +-- @treturn number the number of handlers that were registered +function Prototype:raise_event(event_name,...) + local handlers = self.events[event_name] + if handlers then + for _,handler in pairs(handlers) do + handler(...) end end - ---[[-- Gets the data that is stored for this category -@function Prototype.get_data -@tparam[opt] ?string|LuaGuiElement category the category to get, can only be nil if categories are not used -@treturn any the data that you had stored in this location -@usage-- Getting the stored data for player 1 -local custom_button = -Gui.get_concept('CustomButton') - -custom_button.get_data(1) -- player index 1 -]] - function self.get_data(category) - return Store.get(self.data_store,get_category(category)) - end - ---[[-- Sets the data that is stored for this category -@function Prototype.set_data -@tparam[opt] ?string|LuaGuiElement category the category to set, can only be nil if categories are not used -@tparam any value the data that you want to stored in this location -@usage-- Setting the data for player 1 to a table with two keys -local custom_button = -Gui.get_concept('CustomButton') - --- A table is used to show correct way to use a table with self.update_data --- but a table is not required and can be any data, however upvalues may cause desyncs -custom_button.set_data(1,{ - clicks = 0, - required_clicks = 100 -}) -- player index 1 -]] - function self.set_data(category,value) - return Store.set(self.data_store,get_category(category),value) - end - ---[[-- Clears the data that is stored for this category -@function Prototype.clear_data -@tparam[opt] ?string|LuaGuiElement category the category to clear, can only be nil if categories are not used -@usage-- Clearing the data for player 1 -local custom_button = -Gui.get_concept('CustomButton') - -custom_button.clear_data(1) -- player index 1 -]] - function self.clear_data(category) - return Store.clear(self.data_store,get_category(category)) - end - ---[[-- Updates the data that is stored for this category -@function Prototype.update_data -@tparam[opt] ?string|LuaGuiElement category the category to clear, can only be nil if categories are not used -@tparam function update_callback the function which is called to update the data -@usage-- Updating the clicks key in the concept data for player 1 -local custom_button = -Gui.get_concept('CustomButton') - -custom_button.update_data(1,function(tbl) - tbl.clicks = tbl.clicks + 1 -- here we are incrementing the clicks by 1 -end) -- player index 1 - -@usage-- Updating a value when a table is not used, alterative to get set --- so for this example assume that we did custom_button.set_data(1,0) -custom_button.update_data(1,function(value) - return value + 1 -- here we are incrementing the value by 1, we may only be tracking clicks -end) -- player index 1 -]] - function self.update_data(category,update_callback,...) - return Store.update(self.data_store,get_category(category),update_callback,...) - end - - return self + return handlers and #handlers or 0 end ---- Concept Combined Instances. --- Functions that are used to make store concept instances and data --- @section concept-instances +--- The main function for defines, when called will draw an instance of this define to the given element +-- what is drawn is based on the data in draw_data which is set using other functions +-- @tparam LuaGuiElement element the element that the define will draw a instance of its self onto +-- @treturn LuaGuiElement the new element that was drawn +function Prototype:draw_to(element,...) + local name = self.name + if element[name] then return end + local player = Game.get_player_by_index(element.player_index) ---[[-- Used to add a both instance and data store which are linked together, new instances are synced to the current value, changing the stored value will change all instances -@tparam[opt] function category_callback when given will act as a way to turn an element into a string to act as a key; keys returned can over lap -@tparam function sync_callback the function which is called to update an instance to match the store, this is called on all instances when concept.set_data or update_data is used -@treturn GuiConcept to allow chaining of functions -@usage-- Adding a check box which is a "global setting" synced between all players -local custom_button = -Gui.get_concept('checkbox'):clone('my_checkbox') -:set_caption('My Checkbox') -:set_tooltip('Clicking this check box will change it for everyone') -:on_state_changed(function(event) - local element = event.element - event.concept.set_data(element,element.state) -- Update the stored data to trigger an update of all other instances -end) -:define_combined_store(function(element,state) -- We could add a category function here if we wanted to - element.state = state or false -- Note that the value passed may be nil if there is no stored value and no default set -end) -]] -function Prototype:define_combined_store(category_callback,sync_callback) - if sync_callback == nil then - sync_callback = category_callback - category_callback = nil + if self.pre_authenticator then + if not self.pre_authenticator(player,self.name) then return end end - self:define_data_store(category_callback) - self:define_instance_store(category_callback) - - -- Will update all instances when the data store updates - self:on_data_store_update(function(event) - self.update_instances(event.category,sync_callback,event.value) - end) - ---[[-- Will sync an instance to match the stored value based on the given sync callback -@function Prototype.sync_instance -@tparam LuaGuiElement element the element that you want to have update -@usage-- Setting the caption of this element to be the same as the stored value -local custom_button = -Gui.get_concept('CustomButton') - --- Used internally when first draw and automatically when the store updates -custom_button.sync_instance(element) -]] - local properties = self.properties - function self.sync_instance(element) - local default = properties.default - local value = self.get_data(element) or type(default) == 'function' and default(element) or default - sync_callback(element,value) + if self.embedded_flow then + local embedded_name + if type(self.embedded_flow) == 'function' then + embedded_name = self.embedded_flow(element,...) + end + element = element.add{type='flow',name=embedded_name} + element.style.padding = 0 end - return self + local new_element = element.add(self.draw_data) + + self:raise_event('on_style_update',new_element.style) + + if self.post_authenticator then + new_element.enabled = self.post_authenticator(player,self.name) + end + + if Instances.is_registered(self.name) then + Instances.add_element(self.name,new_element) + end + + self:raise_event('on_draw',player,new_element) + + return new_element end -return Prototype \ No newline at end of file +--- Gets the value in this elements store, category needed if categorize function used +-- @tparam string category[opt] the category to get such as player name or force name +-- @treturn any the value that is stored for this define +function Prototype:get_store(category) + if not self.store then return end + return Store.get(self.store,category) +end + +--- Sets the value in this elements store, category needed if categorize function used +-- @tparam string category[opt] the category to get such as player name or force name +-- @tparam any value the value to set for this define, must be valid for its type ie for checkbox etc +-- @treturn boolean true if the value was set +function Prototype:set_store(category,value) + if not self.store then return end + return Store.set(self.store,category,value) +end + +--- Sets the value in this elements store to nil, category needed if categorize function used +-- @tparam[opt] string category the category to get such as player name or force name +-- @treturn boolean true if the value was set +function Prototype:clear_store(category) + if not self.store then return end + return Store.clear(self.store,category) +end + +return Constructor \ No newline at end of file diff --git a/expcore/gui/styles/expstyle/alignment.lua b/expcore/gui/styles/expstyle/alignment.lua deleted file mode 100644 index 80c44f8a..00000000 --- a/expcore/gui/styles/expstyle/alignment.lua +++ /dev/null @@ -1,49 +0,0 @@ ---[[-- Core Module - ExpStyle - @core ExpStyle - @alias expstyle -]] - -local Gui = require 'expcore.gui' -- @dep expcore.gui - -Gui.require_concept 'flow' -- @dep gui.concept.flow - ---[[-- A flow which can be used to align text and other elements -@see Gui.flow -@element alignment -@usage-- Concept Structure --- Root ---> [alignment] - the alignment area -Gui.new_concept('alignment') -:set_horizontal_align('center') -]] - -Gui.new_concept('flow') -:save_as('alignment') - -:new_property('horizontal_align',nil,'right') -:new_property('vertical_align',nil,'center') -:new_property('width') -:new_property('height') - -:define_draw(function(properties,parent,element) - local style = element.style - Gui.set_padding(element,1,1,2,2) - - -- Set the alignment of the flow - style.horizontal_align = properties.horizontal_align - style.vertical_align = properties.vertical_align - - -- Set the stretchablity based on the alignment - style.horizontally_stretchable = style.horizontal_align ~= 'center' - style.vertically_stretchable = style.vertical_align ~= 'center' - - -- Set the width if given - local width = properties.width - if width then style.width = width end - - -- Set the hieght if given - local height = properties.height - if height then style.height = height end - - return element -end) \ No newline at end of file diff --git a/expcore/gui/styles/expstyle/container.lua b/expcore/gui/styles/expstyle/container.lua deleted file mode 100644 index 00ac52ac..00000000 --- a/expcore/gui/styles/expstyle/container.lua +++ /dev/null @@ -1,37 +0,0 @@ ---[[-- Core Module - ExpStyle - @module ExpStyle -]] - -local Gui = require 'expcore.gui' -- @dep expcore.gui - -Gui.require_concept 'frame' -- @dep gui.concept.frame - ---[[-- A container frame that can be used to add a boader around your content -@see Gui.frame -@element container -@usage-- Concept Structure --- Root ---> [container] - the outer frame --->> container - the content area -Gui.new_concept('container') -]] - -Gui.new_concept('frame') -:save_as('container') -:define_draw(function(properties,parent,element) - -- Update the outter frame padding - element.style.padding = 2 - - -- Add the inner frame - element = element.add{ - name = 'container', - type = 'frame', - direction = properties.direction, - style = 'window_content_frame_packed' - } - - -- Update the inner frame padding - element.style.padding = 0 - - return element -end) \ No newline at end of file diff --git a/expcore/gui/styles/expstyle/data_label.lua b/expcore/gui/styles/expstyle/data_label.lua deleted file mode 100644 index a393ba8b..00000000 --- a/expcore/gui/styles/expstyle/data_label.lua +++ /dev/null @@ -1,101 +0,0 @@ ---[[-- Core Module - ExpStyle - @module ExpStyle -]] - -local Gui = require 'expcore.gui' -- @dep expcore.gui - -Gui.require_concept 'label' -- @dep gui.concept.frame - -local right_align = -Gui.new_concept('alignment') - ---[[-- A label pair which has a static label and a data label which can be changed -@see Gui.label -@element data_label -@usage-- Concept Structure --- Root ---> [data_label] - the static label ---> [properties.data_name] - the data label which can be updated -Gui.new_concept('data_label') -:set_data_label_name('game_ticks') -:set_data_caption('0') -:set_data_format(function(concept,element,data,...) - -- This is used with update_data_element and update_from_parent - local caption = tostirng('data') - local tooltip = 'This game has beeing running for: '..caption..' ticks' - return caption, tooltip -end) -]] - -local data_label = -Gui.new_concept('label') -:save_as('data_label') -:new_property('data_label_name') -:new_property('data_caption') -:new_property('data_tooltip') -:new_property('data_format',nil,function(concept,element,data,...) - return tostring(data) -end) - --- Draw -:define_draw(function(properties,parent,element) - -- Make the label right aligned - local data_name = properties.data_label_name or properties.name..'_data' - local right_align_element = right_align:draw(parent,data_name) - - -- Add a new label - local data_label_element = - right_align_element.add{ - name = 'data_label' - } - - -- Get the data caption - local caption = Gui.resolve_property(properties.data_caption,element) - if caption then - data_label_element.caption = caption - end - - -- Get the data tooltip - local tooltip = Gui.resolve_property(properties.data_tooltip,element) - if tooltip then - data_label_element.tooltip = tooltip - end - - return data_label_element -end) - ---[[-- Updates the caption and tooltip of the data label using the data format function -@tparam LuaGuiElement element the data label element that you want to update -@tparam any data the data that you want to pass to the format function -@usage-- Updating the data to the current game tick -data_label:update_data_element(element,game.tick) -]] -function data_label:update_data_element(element,data,...) - local caption, tooltip = self.properties.data_format(self,element,data,...) - if caption then - element.caption = caption - end - if tooltip then - element.tooltip = tooltip - end -end - ---[[-- Updates the caption and tooltip of the data label using the data format function, given the parent of the data label -@tparam LuaGuiElement parent the parent element to the data label element that you want to update -@tparam any data the data that you want to pass to the format function -@usage-- Updating the data to the current game tick -data_label:update_from_parent(parent,game.tick) -]] -function data_label:update_from_parent(parent,data,...) - local properties = self.properties - local data_name = properties.data_label_name or properties.name..'_data' - local element = parent[data_name] and parent[data_name].data_label or error('Data label is not a child of this element element',2) - - local caption, tooltip = properties.data_format(self,element,data,...) - if caption then - element.caption = caption - end - if tooltip then - element.tooltip = tooltip - end -end \ No newline at end of file diff --git a/expcore/gui/styles/expstyle/footer.lua b/expcore/gui/styles/expstyle/footer.lua deleted file mode 100644 index 01035f19..00000000 --- a/expcore/gui/styles/expstyle/footer.lua +++ /dev/null @@ -1,54 +0,0 @@ ---[[-- Core Module - ExpStyle - @module ExpStyle -]] - -local Gui = require 'expcore.gui' -- @dep expcore.gui - -Gui.require_concept 'frame' -- @dep gui.concept.table - -local right_align = -Gui.new_concept('alignment') - ---[[-- A frame that acts as a footer to a section of content -@see Gui.frame -@element footer -@tparam string tooltip the tooltip to show on the title -@usage-- Concept Structure --- Root ---> [footer] - the footer frame --->> footer_caption - the lable with the title in it --->> footer_content - the area to contain butons -Gui.new_concept('footer') -:set_title('Example Footer') -]] - -Gui.new_concept('frame') -:save_as('footer') -:new_property('tooltip') - --- Draw -:define_draw(function(properties,parent,element) - -- Update the table style - Gui.set_padding(element,2,2,4,4) - element.style = 'subfooter_frame' - element.caption = '' - - local style = element.style - style.horizontally_stretchable = true - style.use_header_filler = false - - -- Add the caption to the frame - if properties.title then - element.add{ - type = 'label', - name = 'footer_caption', - caption = properties.title, - tooltip = properties.tooltip - } - end - - -- Add the right align area - local align = right_align:draw(element,'footer_content') - - return align -end) \ No newline at end of file diff --git a/expcore/gui/styles/expstyle/header.lua b/expcore/gui/styles/expstyle/header.lua deleted file mode 100644 index f570442e..00000000 --- a/expcore/gui/styles/expstyle/header.lua +++ /dev/null @@ -1,52 +0,0 @@ ---[[-- Core Module - ExpStyle - @module ExpStyle -]] - -local Gui = require 'expcore.gui' -- @dep expcore.gui - -Gui.require_concept 'frame' -- @dep gui.concept.table - -local right_align = -Gui.new_concept('alignment') - ---[[-- A frame that acts as a header to a section of content -@see Gui.frame -@element header -@tparam string tooltip the tooltip to show on the title -@usage-- Concept Structure --- Root ---> [header] - the header frame --->> header_caption - the lable with the title in it --->> header_content - the area to contain butons -Gui.new_concept('header') -:set_title('Example Header') -]] - -Gui.new_concept('frame') -:save_as('header') -:new_property('tooltip') - --- Draw -:define_draw(function(properties,parent,element) - -- Update the table style - Gui.set_padding(element,2,2,4,4) - element.style = 'subheader_frame' - element.caption = nil - - local style = element.style - style.horizontally_stretchable = true - style.use_header_filler = false - - -- Add the caption to the frame - element.add{ - type = 'label', - name = 'header_caption', - caption = properties.title, - tooltip = properties.tooltip - } - - -- Add the right align area - local align = right_align:draw(element,'header_content') - - return align -end) \ No newline at end of file diff --git a/expcore/gui/styles/expstyle/index.lua b/expcore/gui/styles/expstyle/index.lua deleted file mode 100644 index 6d773cfb..00000000 --- a/expcore/gui/styles/expstyle/index.lua +++ /dev/null @@ -1,28 +0,0 @@ ---[[-- Core Module - ExpStyle - @module ExpStyle - @alias expstyle -]] - ---- @dep expcore.gui - ---- @dep gui.concept.frame - ---- @dep gui.concept.flow - ---- @dep gui.concept.table - ---- @dep gui.concept.scroll - -local function r(name) - require('expcore.gui.styles.expstyle.'..name) -end - -r 'container' -r 'alignment' -r 'header' -r 'footer' -r 'scroll_table' -r 'time_label' -r 'data_label' -r 'unit_label' -r 'toggle_button' \ No newline at end of file diff --git a/expcore/gui/styles/expstyle/scroll_table.lua b/expcore/gui/styles/expstyle/scroll_table.lua deleted file mode 100644 index 8da23384..00000000 --- a/expcore/gui/styles/expstyle/scroll_table.lua +++ /dev/null @@ -1,60 +0,0 @@ ---[[-- Core Module - ExpStyle - @module ExpStyle -]] - -local Gui = require 'expcore.gui' -- @dep expcore.gui - -Gui.require_concept 'table' -- @dep gui.concept.table -Gui.require_concept 'scroll' -- @dep gui.concept.scroll - -local scroll_area = -Gui.new_concept('scroll') -:set_vertical_scroll('auto-and-reserve-space') -:set_horizontal_scroll('never') - ---[[-- A table that is inside a vertical scroll area -@see Gui.table -@element scroll_table -@tparam number hight the max hight of the scroll area -@usage-- Concept Structure --- Root ---> [scroll_table] - the scroll area --->> table - the table area -Gui.new_concept('scroll_table') -:set_height(200) -:set_column_count(2) -]] - -Gui.new_concept('table') -:save_as('scroll_table') -:new_property('height',nil,100) - --- Add a scroll before the table is drawn -:define_pre_draw(function(properties,parent,element) - local scroll = scroll_area:draw(parent,properties.name) - - -- Set the scroll style - Gui.set_padding(scroll,1,1,2,2) - scroll.style.horizontally_stretchable = true - scroll.style.maximal_height = properties.height - - -- Change the name of the element to table before it is drawn - properties.name = 'table' - - return element, scroll -end) - --- Draw -:define_draw(function(properties,parent,element) - -- Update the table style - local style = element.style - style.padding = 0 - style.horizontally_stretchable = true - style.vertical_align = 'center' - style.cell_padding = 0 - - -- Change the stored name back to the actual name - properties.name = element.parent.name - - return element -end) \ No newline at end of file diff --git a/expcore/gui/styles/expstyle/time_label.lua b/expcore/gui/styles/expstyle/time_label.lua deleted file mode 100644 index 3fc4b004..00000000 --- a/expcore/gui/styles/expstyle/time_label.lua +++ /dev/null @@ -1,92 +0,0 @@ ---[[-- Core Module - ExpStyle - @module ExpStyle -]] - -local Gui = require 'expcore.gui' -- @dep expcore.gui -local format_time = ext_require('expcore.common','format_time') --- @dep expcore.common - ---- Converts a tick into string format with workds and symbols -local function get_format(properties,time) - local caption, tooltip - - -- Check if a custom format is wanted - if properties.time_format then - -- Get the caption - local format = table.deep_copy(properties.time_format) - caption = format_time(time,format) - - -- Get the tooltip, always long format - format.long = true - tooltip = format_time(time,format) - - else - -- Get the caption - caption = format_time(time,{ - hours = properties.use_hours, - minutes = true, - seconds = true - }) - - -- Get the tooltip, same as the caption but long format - tooltip = format_time(time,{ - hours = properties.use_hours, - minutes = true, - seconds = true, - long = true - }) - - end - - return caption, tooltip -end - ---[[-- A label that show time in a nice, user friendly way -@element time_label -@tparam number time the time to display in tick -@usage-- Concept Structure --- Root ---> [time_label] - the label with the time -local time_label = -Gui.new_concept('time_label') -:set_use_hours(true) -:set_time(game.tick) - -time_label:update_time(element,game.tick) -]] - -local time_label = -Gui.new_concept() -:save_as('time_label') - --- Properties -:new_property('time') -:new_property('use_hours',nil,false) -:new_property('time_format') - --- Draw -:define_draw(function(properties,parent,element,time) - -- Get the caption and tooltip - local caption, tooltip = get_format(properties,time or properties.time) - - -- Draw a label - element = parent.add{ - name = properties.name, - type = 'label', - caption = caption, - tooltip = tooltip - } - - return element -end) - ---[[-- Updates the time that is on a label -@tparam LuaGuiElement element the label that you want to update -@tparam number time the number of tick you want it to show -@usage-- Update the time to show game time -time_label:update_time(element,game.time) -]] -function time_label:update_time(element,time) - local caption, tooltip = get_format(self.properties,time) - element.caption = caption - element.tooltip = tooltip -end \ No newline at end of file diff --git a/expcore/gui/styles/expstyle/toggle_button.lua b/expcore/gui/styles/expstyle/toggle_button.lua deleted file mode 100644 index 00a894c5..00000000 --- a/expcore/gui/styles/expstyle/toggle_button.lua +++ /dev/null @@ -1,49 +0,0 @@ ---[[-- Core Module - ExpStyle - @module ExpStyle -]] - -local Gui = require 'expcore.gui' -- @dep expcore.gui - -Gui.require_concept 'button' -- @dep gui.concept.table - ---[[-- A button that will toggle its caption each time it is pressed -@see Gui.button -@element toggle_button -@tparam string alt_caption the caption to show on the button in its true state -@tparam string alt_tooltip the tooltip to show on the button in its true state -@usage-- Concept Structure --- Root ---> [toggle_button] - the header button -Gui.new_concept('toggle_button') -:set_caption('<') -:set_tooltip('Press to close.') -:set_alt_caption('>') -:set_alt_tooltip('Press to open.') -:on_click(function(event) - local state = event.state and 'close' or 'open' - event.player.print('Toggle button is now: '..state) -end) -]] - -Gui.new_concept('button') -:save_as('toggle_button') -:new_property('alt_caption') -:new_property('alt_tooltip') - --- Events -:on_click(function(event) - local concept = event.concept - local properties = concept.properties - local element = event.element - if element.caption == properties.caption then - element.caption = properties.alt_caption - element.tooltip = properties.alt_tooltip or properties.tooltip - event.state = true - - else - element.caption = properties.caption - element.tooltip = properties.tooltip or properties.alt_tooltip - event.state = false - - end -end) \ No newline at end of file diff --git a/expcore/gui/styles/expstyle/unit_label.lua b/expcore/gui/styles/expstyle/unit_label.lua deleted file mode 100644 index ca47ffd3..00000000 --- a/expcore/gui/styles/expstyle/unit_label.lua +++ /dev/null @@ -1,100 +0,0 @@ ---[[-- Core Module - ExpStyle - @module ExpStyle -]] - -local Gui = require 'expcore.gui' -- @dep expcore.gui - ---[[-- A label triplet which has a static label, a data label which can be changed, and a unit label -@see Gui.label -@see data_label -@element unit_label -@usage-- Concept Structure --- Root ---> [unit_label] - the static label ---> [properties.data_name] - the data label which can be updated ---> [properties.data_name..'_unit'] - the data label unit which can be updated -Gui.new_concept('unit_label') -:set_data_label_name('game_ticks') -:set_data_caption('0') -:set_data_unit('ticks') -:set_data_format(function(concept,element,data,...) - -- This is used with update_data_element and update_from_parent - local caption = tostirng(data) - local unit = data > 1 and 'ticks' or 'tick' - local tooltip = 'This game has beeing running for: '..caption..' ticks' - return caption, unit, tooltip -end) -]] - -local unit_label = -Gui.new_concept('data_label') -:save_as('unit_label') -:new_property('data_unit') -:set_data_format(function(concept,element,data,...) - local base_unit = concept.properties.data_unit - local caption = tostring(data) - local unit = data == 1 and base_unit or base_unit..'s' - return caption, unit -end) - --- Draw -:define_draw(function(properties,parent,element) - -- Get the unit data - local unit = Gui.resolve_property(properties.data_unit,element) - - -- Add the unit label - parent.add{ - name = element.name..'_unit', - type='label', - caption = unit or '', - tooltip = element.tooltip - } - - return element -end) - ---[[-- Updates the caption and tooltip and unit of the data label using the data format function -@tparam LuaGuiElement element the unit label element that you want to update -@tparam any data the data that you want to pass to the format function -@usage-- Updating the data to the current game tick -unit_label:update_data_element(element,game.tick) -]] -function unit_label:update_data_element(element,data,...) - local caption, unit, tooltip = self.properties.data_format(self,element,data,...) - local unit_element = element.parent.parent[element.name..'_unit'] - if caption then - element.caption = caption - end - if tooltip then - element.tooltip = tooltip - unit_element.tooltip = tooltip - end - if unit then - unit_element.caption = unit - end -end - ---[[-- Updates the caption and tooltip and unit of the unit label using the data format function, given the parent of the unit label -@tparam LuaGuiElement parent the parent element to the unit label element that you want to update -@tparam any data the data that you want to pass to the format function -@usage-- Updating the data to the current game tick -unit_label:update_from_parent(parent,game.tick) -]] -function unit_label:update_from_parent(parent,data,...) - local properties = self.properties - local data_name = properties.data_label_name or properties.name..'_data' - local element = parent[data_name] and parent[data_name].data_label or error('Data label is not a child of this element element',2) - local unit_element = parent[data_name..'_unit'] - - local caption, unit, tooltip = properties.data_format(self,element,data,...) - if caption then - element.caption = caption - end - if tooltip then - element.tooltip = tooltip - unit_element.tooltip = tooltip - end - if unit then - unit_element.caption = unit - end -end \ No newline at end of file diff --git a/expcore/gui/test.lua b/expcore/gui/test.lua index e57b7ece..2e25c61b 100644 --- a/expcore/gui/test.lua +++ b/expcore/gui/test.lua @@ -1,717 +1,663 @@ --[[-- Core Module - Gui @module Gui - @alias Gui + @alias tests ]] ---- Tests. --- functions used to test --- @section tests +--- Test. +-- This file creates a test gui that is used to test every input method +-- note that this does not cover every permutation only features in independence +-- for example store in most cases is just by player name, but other store methods are tested with checkbox +-- @section test -local Gui = require 'expcore.gui' -local Game = require 'utils.game' -local Event = require 'utils.event' -require 'expcore.toolbar' +local Gui = require 'expcore.gui' --- @dep expcore.gui +local format_chat_colour,table_keys = ext_require('expcore.common','format_chat_colour','table_keys') --- @dep expcore.common +local Colors = require 'resources.color_presets' --- @dep resources.color_presets +local Event = require 'utils.event' --- @dep utils.event +local Store = require 'expcore.store' --- @dep expcore.store local tests = {} --[[ -The main test frame + Toolbar Tests + > No display - Toolbar button with no display + > With caption - Toolbar button with a caption display + > With icons - Toolbar button with an icon ]] -Gui.require_concept('frame') - -local test_frame = -Gui.new_concept('frame') -:set_title('Gui Tests') -:define_draw(function(properties,parent,element) - for category, _ in pairs(tests) do - element.add{ - type = 'flow', - name = category, - direction = 'vertical' - } - end +Gui.new_toolbar_button('click-1') +:set_post_authenticator(function(player,button_name) + return global.click_one +end) +:on_click(function(player,element) + player.print('CLICK 1') end) -Gui.new_concept('toolbar-button') -:set_permission_alias('gui-test') -:set_caption('Element Tests') -:on_click(function(event) - local player = event.player - if not Gui.destroy(player.gui.center[test_frame.name]) then - Gui.run_tests(event.player) - end +Gui.new_toolbar_button('click-2') +:set_caption('Click Two') +:set_post_authenticator(function(player,button_name) + return global.click_two +end) +:on_click(function(player,element) + player.print('CLICK 2') end) -local test_left_frame = -Gui.new_concept('toolbar-frame') -:set_permission_alias('gui-test') -:set_caption('Frame Test Left') -:define_draw(function(properties,parent,element) - local list_area = - element.add{ - name = 'scroll', - type = 'scroll-pane', - direction = 'vertical', - horizontal_scroll_policy = 'never', - vertical_scroll_policy = 'auto-and-reserve-space' - } - Gui.set_padding(list_area,1,1,2,2) - 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', - caption=player.name - } - end +Gui.new_toolbar_button('click-3') +:set_sprites('utility/questionmark') +:set_post_authenticator(function(player,button_name) + return global.click_three end) -:on_update(function(event) - 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', - caption=player.name - } - end +:on_click(function(player,element) + player.print('CLICK 3') end) -Event.add(defines.events.on_player_joined_game,function(event) - test_left_frame:update_all(event) -end) -Event.add(defines.events.on_player_left_game,function(event) - test_left_frame:update_all(event) -end) - ---[[-- Runs a set of gui tests to ensure that the system is working -@tparam LuaPlayer player the player that the guis are made for and who recives the results -@tparam[opt] string category when given only tests in this category are ran -@usage-- Run all gui tests -Gui.run_tests(game.player) -]] -function Gui.run_tests(player,category) - local results = { - passed = 0, - failed = 0, - total = 0, - errors = {} - } - - if not category then - results.breakdown = {} - - for cat,_ in pairs(tests) do - local rtn = Gui.run_tests(player,cat) - results.passed = results.passed + rtn.passed - results.failed = results.failed + rtn.failed - results.total = results.total + rtn.total - - for test_name, err in pairs(rtn.errors) do - results.errors[cat..'/'..test_name] = err - end - - results.breakdown[cat] = rtn - end - - player.print(string.format('All Tests Complete. %d failed.',results.failed)) - - return results - end - - local frame = player.gui.center[test_frame.name] or test_frame:draw(player.gui.center) - local cat_tests = tests[category] - - results.total = #cat_tests - - local output = player.print - for test_name, concept in pairs(cat_tests) do - local success, err = pcall(concept.draw,concept,frame[category]) - - if success then - results.passed = results.passed + 1 - else - results.errors[test_name] = err - results.failed = results.failed + 1 - output(string.format('Test "%s / %s" failed:\n%s',category,test_name,err)) - end - - end - - output(string.format('Test Complete "%s". %d failed.',category,results.failed)) - - return results -end - --[[ -Buttons -> Basic Button -- Button with a caption and a tooltip -> Sprite Button -- Button with a single sprite and a tooltip -> Multi Sprite Button -- Button with three sprites and a tooltip -> Admin Button -- Button which is disabled if the player is not an admin + Center Frame Tests + > Main test gui - Main test gui triggers all other tests ]] -Gui.require_concept('button') - -local basic_button = -Gui.new_concept('button') -:debug('basic_button') -:set_caption('Basic Button') -:set_tooltip('Basic button') -:on_click(function(event) - event.player.print('You pressed basic button!') +local test_gui = +Gui.new_center_frame('gui-test-open') +:set_caption('Open Test Gui') +:set_tooltip('Main test gui triggers all other tests') +:set_post_authenticator(function(player,button_name) + return global.show_test_gui end) -local sprite_button = -Gui.new_concept('button') -:debug('sprite_button') -:set_sprite('utility/warning_icon') -:set_tooltip('Sprite button') -:on_click(function(event) - event.player.print('You pressed sprite button!') -end) +:on_creation(function(player,frame) + for test_group_name,test_group in pairs(tests) do -local 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) - event.player.print('You pressed multi sprite button!') -end) + player.print('Starting tests for: '..format_chat_colour(test_group_name,Colors.cyan)) + + local pass_count = 0 + local test_count = 0 + + local flow = frame.add{ + type='flow', + name=test_group_name, + direction='vertical' + } + + for test_name,test in pairs(test_group) do + local test_function = type(test) == 'function' and test or test.draw_to + test_count = test_count+1 + + local success,err = pcall(test_function,test,flow) + if success then + pass_count = pass_count+1 + else + player.print('Failed Test: '..format_chat_colour(test_name,Colors.red)) + log('Gui Test Failed: '..test_name..' stacktrace:\n'..err) + end + + end + + if pass_count == test_count then + player.print('All tests '..format_chat_colour('passed',Colors.green)..' ('..test_group_name..')') + else + player.print('Passed '..format_chat_colour(pass_count..'/'..test_count,Colors.cyan)..' ('..test_group_name..')') + end -local admin_button = -Gui.new_concept('button') -:debug('admin_button') -:set_caption('Admin Button') -:set_tooltip('Admin button') -:define_draw(function(properties,parent,element) - local player = Game.get_player_by_index(element.player_index) - if not player.admin then - element.enabled = false - element.tooltip = 'You must be admin to press this button' end end) -:on_click(function(event) - event.player.print('You pressed admin button!') + +--[[ + Left Frame Test + > Left frame which holds all online player names, updates when player leaves or joins +]] + +local left_frame = +Gui.new_left_frame('test-left-frame') +:set_caption('Test Left Gui') +:set_tooltip('Left frame which holds all online player names, updates when player leaves or joins') +:set_post_authenticator(function(player,button_name) + return global.show_test_gui +end) + +:set_open_by_default() +:on_creation(function(_player,frame) + for _,player in pairs(game.connected_players) do + frame.add{ + type='label', + caption=player.name + } + end +end) + +Event.add(defines.events.on_player_joined_game,left_frame 'update_all') +Event.add(defines.events.on_player_left_game,left_frame 'update_all') + +--[[ + Popup Test + > Allows opening a popup which contains the players name and tick it was opened +]] + +local test_popup = +Gui.new_popup('test-popup') +:on_creation(function(player,frame) + frame.add{ + type='label', + caption=player.name + } + frame.add{ + type='label', + caption=game.tick + } +end) + +Gui.new_toolbar_button('test-popup-open') +:set_caption('Test Popup') +:set_tooltip('Allows opening a popup which contains the players name and tick it was opened') +:set_post_authenticator(function(player,button_name) + return global.show_test_gui +end) +:on_click(function(player,element) + test_popup(player,300) +end) + +--[[ + Button Tests + > No display - Simple button which has no display + > Caption - Simple button but has a caption on it + > Icons - Button with an icon display plus two icons for hover and select + > Auth - Button which can only be passed when auth is true (press no display to toggle; needs reopen) +]] + +local button_no_display = +Gui.new_button('test-button-no-display') +:set_tooltip('Button no display') +:on_click(function(player,element) + player.print('Button no display') + global.test_auth_button = not global.test_auth_button + player.print('Auth Button auth state: '..tostring(global.test_auth_button)) +end) + +local button_with_caption = +Gui.new_button('test-button-with-caption') +:set_tooltip('Button with caption') +:set_caption('Button Caption') +:on_click(function(player,element) + player.print('Button with caption') +end) + +local button_with_icon = +Gui.new_button('test-button-with-icon') +:set_tooltip('Button with icons') +:set_sprites('utility/warning_icon','utility/warning','utility/warning_white') +:on_click(function(player,element) + player.print('Button with icons') +end) + +local button_with_auth = +Gui.new_button('test-button-with-auth') +:set_tooltip('Button with auth') +:set_post_authenticator(function(player,button_name) + return global.test_auth_button +end) +:on_click(function(player,element) + player.print('Button with auth') end) tests.Buttons = { - ['Basic Button'] = basic_button, - ['Sprite Button'] = sprite_button, - ['Multi Sprite Button'] = multi_sprite_button, - ['Admin Button'] = admin_button, + ['No display']=button_no_display, + ['Caption']=button_with_caption, + ['Icons']=button_with_icon, + ['Auth']=button_with_auth } --[[ -Checkboxs -> Basic Checkbox -- Simple checkbox that can be toggled -> Game Stored Checkbox -- Checkbox which syncs its state between all players -> Force Stored Checkbox -- Checkbox which syncs its state with all players on the same force -> Player Stored Checkbox -- Checkbox that stores its state between re-draws + Checkbox Test + > Local -- Simple checkbox that can toggle + > Game store -- Checkbox which syncs its state between all players + > Force store -- Checkbox which syncs its state with all players on the same force + > Player store -- Checkbox that stores its state between re-draws ]] -Gui.require_concept('checkbox') - -local basic_checkbox = -Gui.new_concept('checkbox') -:debug('basic_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)) +local checkbox_local = +Gui.new_checkbox('test-checkbox-local') +:set_tooltip('Checkbox local') +:set_caption('Checkbox Local') +:on_element_update(function(player,element,state) + player.print('Checkbox local: '..tostring(state)) end) -local game_checkbox = -Gui.new_concept('checkbox') -:debug('game_checkbox') -:set_caption('Game Stored Checkbox') -:set_tooltip('Game stored checkbox') -:on_state_changed(function(event) - local element = event.element - event.concept.set_data(element,element.state) -- Update other instances - event.player.print('Game stored checkbox is now: '..tostring(element.state)) -end) -:define_combined_store(function(element,state) - element.state = state or false +local checkbox_game = +Gui.new_checkbox('test-checkbox-store-game') +:set_tooltip('Checkbox store game') +:set_caption('Checkbox Store Game') +:add_store() +:on_element_update(function(player,element,state) + player.print('Checkbox store game: '..tostring(state)) end) -local force_checkbox = -Gui.new_concept('checkbox') -:debug('force_checkbox') -:set_caption('Force Stored Checkbox') -:set_tooltip('Force stored checkbox') -:on_state_changed(function(event) - local element = event.element - event.concept.set_data(element,element.state) -- Update other instances - event.player.print('Force stored checkbox is now: '..tostring(element.state)) -end) -:define_combined_store(Gui.categorize_by_force,function(element,state) - element.state = state or false +local checkbox_force = +Gui.new_checkbox('test-checkbox-store-force') +:set_tooltip('Checkbox store force') +:set_caption('Checkbox Store Force') +:add_store(Gui.categorize_by_force) +:on_element_update(function(player,element,state) + player.print('Checkbox store force: '..tostring(state)) end) -local player_checkbox = -Gui.new_concept('checkbox') -:debug('player_checkbox') -:set_caption('Player Stored Checkbox') -:set_tooltip('Player stored checkbox') -:on_state_changed(function(event) - local element = event.element - event.concept.set_data(element,element.state) -- Update other instances - event.player.print('Player stored checkbox is now: '..tostring(element.state)) -end) -:define_combined_store(Gui.categorize_by_player,function(element,state) - element.state = state or false +local checkbox_player = +Gui.new_checkbox('test-checkbox-store-player') +:set_tooltip('Checkbox store player') +:set_caption('Checkbox Store Player') +:add_store(Gui.categorize_by_player) +:on_element_update(function(player,element,state) + player.print('Checkbox store player: '..tostring(state)) end) -tests.Checkboxs = { - ['Basic Checkbox'] = basic_checkbox, - ['Game Stored Checkbox'] = game_checkbox, - ['Force Stored Checkbox'] = force_checkbox, - ['Player Stored Checkbox'] = player_checkbox +tests.Checkboxes = { + ['Local']=checkbox_local, + ['Game store']=checkbox_game, + ['Force store']=checkbox_force, + ['Player store']=checkbox_player } --[[ -Dropdowns -> Static Dropdown -- Simple dropdown with all options being static -> Dynamic Dropdown -- Dropdown which has items based on when it is drawn -> Static Player Stored Dropdown -- Dropdown where the values is synced for each player -> Dynamic Player Stored Dropdown -- Same as above but now with dynamic options + Radiobutton Tests + > Local -- Simple radiobutton that can only be toggled true + > Player store -- Radio button that saves its state between re-draws + > Option set -- A set of radio buttons where only one can be true at a time ]] -Gui.require_concept('dropdown') - -local 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) - event.player.print('Static dropdown is now: '..value) +local radiobutton_local = +Gui.new_radiobutton('test-radiobutton-local') +:set_tooltip('Radiobutton local') +:set_caption('Radiobutton Local') +:on_element_update(function(player,element,state) + player.print('Radiobutton local: '..tostring(state)) end) -local dynamic_dropdown = -Gui.new_concept('dropdown') -:debug('dynamic_dropdown') -:set_dynamic_items(function(element) - local items = {} - for concept_name,_ in pairs(Gui.concepts) do - if concept_name:len() < 16 then - items[#items+1] = concept_name - end +local radiobutton_player = +Gui.new_radiobutton('test-radiobutton-store') +:set_tooltip('Radiobutton store') +:set_caption('Radiobutton Store') +:add_store(Gui.categorize_by_player) +:on_element_update(function(player,element,state) + player.print('Radiobutton store: '..tostring(state)) +end) + +local radiobutton_option_set = +Gui.new_radiobutton_option_set('gui.test.share',function(value,category) + game.print('Radiobutton option set for: '..category..' is now: '..tostring(value)) +end,Gui.categorize_by_player) + +local radiobutton_option_one = +Gui.new_radiobutton('test-radiobutton-option-one') +:set_tooltip('Radiobutton option set') +:set_caption('Radiobutton Option One') +:add_as_option(radiobutton_option_set,'One') +:on_element_update(function(player,element,state) + player.print('Radiobutton option one: '..tostring(state)) +end) + +local radiobutton_option_two = +Gui.new_radiobutton('test-radiobutton-option-two') +:set_tooltip('Radiobutton option set') +:set_caption('Radiobutton Option Two') +:add_as_option(radiobutton_option_set,'Two') +:on_element_update(function(player,element,state) + player.print('Radiobutton option two: '..tostring(state)) +end) + +local radiobutton_option_three = +Gui.new_radiobutton('test-radiobutton-option-three') +:set_tooltip('Radiobutton option set') +:set_caption('Radiobutton Option Three') +:add_as_option(radiobutton_option_set,'Three') +:on_element_update(function(player,element,state) + player.print('Radiobutton option three: '..tostring(state)) +end) + +tests.Radiobuttons = { + ['Local']=radiobutton_local, + ['Player store']=radiobutton_player, + ['Option set']=function(self,frame) + Gui.draw_option_set(radiobutton_option_set,frame) end - return items -end) -:on_selection_changed(function(event) - local value = Gui.get_dropdown_value(event.element) - event.player.print('Dynamic dropdown is now: '..value) +} + +--[[ + Dropdown Test + > Local static general -- Simple dropdown with all static options and general handler + > Player startic general -- Dropdown with all static options and general handler and stores option between re-draws + > Local static case -- Dropdown with all static options but case handlers and a general handler + > Player static case -- Dropdown with all static options but case handlers and a general handler and stores option between re-draws + > Local dynamic -- Dropdown with one static option with the reset generated by a function + > Player dynamic -- Dropdown with one static option with the reset generated by a function and stores option between re-draws +]] + +local dropdown_local_static_general = +Gui.new_dropdown('test-dropdown-local-static-general') +:set_tooltip('Dropdown local static general') +:add_options('One','Two','Three','Four') +:on_element_update(function(player,element,value) + player.print('Dropdown local static general: '..tostring(value)) end) -local 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 - local value = Gui.get_dropdown_value(element) - event.concept.set_data(element,value) - event.player.print('Static player stored dropdown is now: '..value) -end) -:define_combined_store(Gui.categorize_by_player,function(element,value) - Gui.set_dropdown_value(element,value) +local dropdown_player_static_general = +Gui.new_dropdown('test-dropdown-store-static-general') +:set_tooltip('Dropdown store static general') +:add_options('One','Two','Three','Four') +:add_store(Gui.categorize_by_player) +:on_element_update(function(player,element,value) + player.print('Dropdown store static general: '..tostring(value)) end) -local 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 - if concept_name:len() < 16 then - items[#items+1] = concept_name - end - end - return items +local function print_option_selected_1(player,element,value) + player.print('Dropdown local static case (case): '..tostring(value)) +end + +local dropdown_local_static_case = +Gui.new_dropdown('test-dropdown-local-static-case') +:set_tooltip('Dropdown local static case') +:add_options('One','Two') +:add_option_callback('One',print_option_selected_1) +:add_option_callback('Two',print_option_selected_1) +:add_option_callback('Three',print_option_selected_1) +:add_option_callback('Four',print_option_selected_1) +:on_element_update(function(player,element,value) + player.print('Dropdown local static case (general): '..tostring(value)) end) -:on_selection_changed(function(event) - local element = event.element - local value = Gui.get_dropdown_value(element) - event.concept.set_data(element,value) - event.player.print('Dynamic player dropdown is now: '..value) + +local function print_option_selected_2(player,element,value) + player.print('Dropdown store static case (case): '..tostring(value)) +end + +local dropdown_player_static_case = +Gui.new_dropdown('test-dropdown-store-static-case') +:set_tooltip('Dropdown store static case') +:add_store(Gui.categorize_by_player) +:add_options('One','Two') +:add_option_callback('One',print_option_selected_2) +:add_option_callback('Two',print_option_selected_2) +:add_option_callback('Three',print_option_selected_2) +:add_option_callback('Four',print_option_selected_2) +:on_element_update(function(player,element,value) + player.print('Dropdown store static case (general): '..tostring(value)) end) -:define_combined_store(Gui.categorize_by_player,function(element,value) - Gui.set_dropdown_value(element,value) + +local dropdown_local_dynamic = +Gui.new_dropdown('test-dropdown-local-dynamic') +:set_tooltip('Dropdown local dynamic') +:add_options('Static') +:add_dynamic(function(player,element) + return table_keys(Colors) +end) +:on_element_update(function(player,element,value) + player.print('Dropdown local dynamic: '..tostring(value)) +end) + +local dropdown_player_dynamic = +Gui.new_dropdown('test-dropdown-store-dynamic') +:set_tooltip('Dropdown store dynamic') +:add_options('Static') +:add_dynamic(function(player,element) + return table_keys(Colors) +end) +:add_store(Gui.categorize_by_player) +:on_element_update(function(player,element,value) + player.print('Dropdown store dynamic: '..tostring(value)) end) tests.Dropdowns = { - ['Static Dropdown'] = static_dropdown, - ['Dynamic Dropdown'] = dynamic_dropdown, - ['Static Player Stored Dropdown'] = static_player_dropdown, - ['Dynamic Player Stored Dropdown'] = dynamic_player_dropdown + ['Local static general']=dropdown_local_static_general, + ['Player startic general']=dropdown_player_static_general, + ['Local static case']=dropdown_local_static_case, + ['Player static case']=dropdown_player_static_case, + ['Local dynamic general']=dropdown_local_dynamic, + ['Player dynamic general']=dropdown_player_dynamic } --[[ -Listboxs -> Static Listbox -- Simple Listbox with all options being static -> Static Player Stored Listbox -- Listbox where the values is synced for each player + List Box Tests + > Local -- A list box with all static options and general handler + > Store -- A list box with all static options and general handler and stores options between re-draws ]] -local 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) - local value = Gui.get_dropdown_value(event.element) - event.player.print('Static listbox is now: '..value) +local list_box_local = +Gui.new_list_box('test-list-box-local') +:set_tooltip('List box local') +:add_options('One','Two','Three','Four') +:on_element_update(function(player,element,value) + player.print('Dropdown local: '..tostring(value)) end) -local 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) - local element = event.element - local value = Gui.get_dropdown_value(element) - event.concept.set_data(element,value) - event.player.print('Static player stored listbox is now: '..value) -end) -:define_combined_store(Gui.categorize_by_player,function(element,value) - Gui.set_dropdown_value(element,value) +local list_box_player = +Gui.new_list_box('test-list-box-store') +:set_tooltip('List box store') +:add_options('One','Two','Three','Four') +:add_store(Gui.categorize_by_player) +:on_element_update(function(player,element,value) + player.print('Dropdown store: '..tostring(value)) end) -tests.Listboxs = { - ['Static Listbox'] = static_listbox, - ['Static Player Stored Listbox'] = static_player_listbox +tests["List Boxes"] = { + ['Local']=list_box_local, + ['Player']=list_box_player } --[[ -Elem Buttons -> Basic Elem Button -- Basic elem button -> Defaut Selection Elem Button -- Same as above but has a default selection -> Player Stored Elem Button -- Same as above but is stored per player + Slider Tests + > Local default -- Simple slider with default range + > Store default -- Slider with default range that stores value between re-draws + > Static range -- Simple slider with a static range + > Dynamic range -- Slider with a dynamic range + > Local label -- Simple slider with default range which has a label + > Store label -- Slider with default range which has a label and stores value between re-draws ]] -Gui.require_concept('elem_button') - -local basic_elem_button = -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) +local slider_local_default = +Gui.new_slider('test-slider-local-default') +:set_tooltip('Slider local default') +:on_element_update(function(player,element,value,percent) + player.print('Slider local default: '..tostring(math.round(value))..' '..tostring(math.round(percent,1))) end) -local 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) - local value = event.element.elem_value - event.player.print('Default selection elem button is now: '..value.type..'/'..value.name) + +local slider_player_default = +Gui.new_slider('test-slider-store-default') +:set_tooltip('Slider store default') +:add_store(Gui.categorize_by_player) +:on_element_update(function(player,element,value,percent) + player.print('Slider store default: '..tostring(math.round(value))..' '..tostring(math.round(percent,1))) end) -local 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 - local value = element.elem_value - event.concept.set_data(element,value) - event.player.print('Player stored elem button is now: '..value) -end) -:define_combined_store(Gui.categorize_by_player,function(element,value) - element.elem_value = value +local slider_static = +Gui.new_slider('test-slider-static-range') +:set_tooltip('Slider static range') +:set_range(5,50) +:on_element_update(function(player,element,value,percent) + player.print('Slider static range: '..tostring(math.round(value))..' '..tostring(math.round(percent,1))) end) -tests['Elem Buttons'] = { - ['Basic Elem Button'] = basic_elem_button, - ['Defaut Selection Elem Button'] = default_selection_elem_button, - ['Player Stored Elem Button'] = player_elem_button -} - ---[[ -Progress Bars -> Basic Progress Bar -- will increse when pressed, when full then it will reset -> Inverted Progress Bar -- will increse when pressed, when empty then it will reset -> Game Instance Progress Bar -- will take 5 seconds to fill, when full it will reset, note instances are required due to on_tick -> Force Instance Progress Bar -- will increse when pressed, instance only means all instances will increse at same time but may not have the same value -> 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.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) -:on_click(function(event) - event.concept:increment(event.element) +local slider_dynamic = +Gui.new_slider('test-slider-dynamic-range') +:set_tooltip('Slider dynamic range') +:set_range(function(player,element) + return player.index - 5 +end,function(player,element) + return player.index + 4 end) -:set_delay_completion(true) -:on_completion(function(event) - event.concept:reset(event.element) +:on_element_update(function(player,element,value,percent) + player.print('Slider dynamic range: '..tostring(math.round(value))..' '..tostring(math.round(percent,1))) end) -local inverted_progress_bar = -Gui.new_concept('progress_bar') -:debug('inverted_progress_bar') -:set_tooltip('Inverted progress bar') -:set_inverted(true) -:set_maximum(5) -:new_event('on_click',defines.events.on_gui_click) -:on_click(function(event) - event.concept:increment(event.element) -end) -:on_completion(function(event) - event.concept:reset(event.element) +local label_slider_local = +Gui.new_slider('test-slider-local-label') +:set_tooltip('Slider local label') +:enable_auto_draw_label() +:on_element_update(function(player,element,value,percent) + player.print('Slider local label: '..tostring(math.round(value))..' '..tostring(math.round(percent,1))) end) -local 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) -:on_tick(function(event) - event.concept:increment(event.element) -end) -:set_delay_completion(true) -:on_completion(function(event) - event.concept:reset(event.element) -end) -:define_instance_store() - -local 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) -:on_click(function(event) - event.concept:increment(event.element) -end) -:set_delay_completion(true) -:on_completion(function(event) - event.concept:reset(event.element) -end) -:define_instance_store(Gui.categorize_by_force) - -local 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) -:on_click(function(event) - local element = event.element - local concept = event.concept - local new_value = concept:increment(element) - if new_value then concept.set_data(element,new_value) end -end) -:set_delay_completion(true) -:on_completion(function(event) - local element = event.element - local concept = event.concept - local new_value = concept:reset(element) - concept.set_data(element,new_value) -end) -:define_combined_store(Gui.categorize_by_force,function(element,value) - element.value = value or 0 -end) - -tests['Progress Bars'] = { - ['Basic Progress Bar'] = basic_progress_bar, - ['Inverted Progress Bar'] = inverted_progress_bar, - ['Game Instance Progress Bar'] = game_progress_bar, - ['Force Instance Progress Bar'] = force_instance_progress_bar, - ['Force Stored Progress Bar'] = force_stored_progress_bar -} - ---[[ -Sliders -> Basic Slider -- Just a basic slider with range 1 to 10 -> Interval Slider -- Same as above but can only be intergers -> Discrete Slider -- A discrete slider -> Dynamic Slider -- A slider which has a dynamic range -> Player Stored Slider -- Slider which stores the value per player, also goes 1 to 10 -]] - -Gui.require_concept('slider') - -local 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.new_concept('slider') -:debug('interval_slider') -:set_range(1,10) -:set_value_step(1) -:on_value_changed(function(event) - event.player.print('Interval slider is now: '..event.element.slider_value) -end) - -local discrete_slider = -Gui.new_concept('slider') -:debug('discrete_slider') -:set_range(1,10) -:set_value_step(1) -:set_discrete_slider(true) -:on_value_changed(function(event) - event.player.print('Discrete slider is now: '..event.element.slider_value) -end) - -local 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() -end) -:set_value_step(1) -:set_discrete_slider(true) -:on_value_changed(function(event) - event.player.print('Dynamic slider is now: '..event.element.slider_value) -end) - -local player_slider = -Gui.new_concept('slider') -:debug('player_slider') -:set_range(1,10) -:set_value_step(1) -:set_discrete_slider(true) -:on_value_changed(function(event) - local element = event.element - local value = element.slider_value - event.concept.set_data(element,value) - event.player.print('Player stored slider is now: '..value) -end) -:define_combined_store(Gui.categorize_by_player,function(element,value) - element.slider_value = value or 0 +local label_slider_player = +Gui.new_slider('test-slider-store-label') +:set_tooltip('Slider store label') +:enable_auto_draw_label() +:add_store(Gui.categorize_by_player) +:on_element_update(function(player,element,value,percent) + player.print('Slider store label: '..tostring(math.round(value))..' '..tostring(math.round(percent,1))) end) tests.Sliders = { - ['Basic Slider'] = basic_slider, - ['Interval Slider'] = interval_slider, - ['Discrete Slider'] = discrete_slider, - ['Dynamic Slider'] = dynamic_slider, - ['Player Stored Slider'] = player_slider + ['Local default']=slider_local_default, + ['Player default']=slider_player_default, + ['Static range']=slider_static, + ['Dynamic range']=slider_dynamic, + ['Local label']=function(self,frame) + local flow = frame.add{type='flow'} + label_slider_local:draw_to(flow) + end, + ['Player label']=function(self,frame) + local flow = frame.add{type='flow'} + label_slider_player:draw_to(flow) + end } --[[ -Text Fields -> Basic Text Field -- Just a text field which text can be entered into -> Better Text Field -- Same as above but will clear on rmb and un forcus on confirmation -> Decimal Text Field -- Text field which accepts decimal values -> Password Text Field -- Text field which stars out the typed characters -> Player Stored Text Field - Same as basic but will store value per player + Text Tests + > Local field -- Simple text field + > Store field -- Test field that stores text between re-draws + > Local box -- Simple text box + > Wrap box -- Text box which has word wrap and selection disabled ]] -Gui.require_concept('text_field') - --- Making a text field -local 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) +local text_filed_local = +Gui.new_text_filed('test-text-field-local') +:set_tooltip('Text field local') +:on_element_update(function(player,element,value) + player.print('Text field local: '..value) end) -local 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) -:on_confirmation(function(event) - event.player.print('Better text field is now: '..event.element.text) +local text_filed_store = +Gui.new_text_filed('test-text-field-store') +:set_tooltip('Text field store') +:add_store(Gui.categorize_by_player) +:on_element_update(function(player,element,value) + player.print('Text field store: '..value) end) -local 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) - event.player.print('Decimal text field is now: '..event.element.text) +local text_box_local = +Gui.new_text_box('test-text-box-local') +:set_tooltip('Text box local') +:on_element_update(function(player,element,value) + player.print('Text box local: '..value) end) -local 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) - event.player.print('Password text field is now: '..event.element.text) +local text_box_wrap = +Gui.new_text_box('test-text-box-wrap') +:set_tooltip('Text box wrap') +:set_selectable(false) +:set_word_wrap() +:on_element_update(function(player,element,value) + player.print('Text box wrap: '..value) end) -local 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 - local text = element.text - event.concept.set_data(element,text) - event.player.print('Player stored text field is now: '..text) -end) -:define_combined_store(Gui.categorize_by_player, function(element,value) - element.text = value or '' -end) - -tests['Text Fields'] = { - ['Basic Text Field'] = basic_text_field, - ['Better Text Field'] = better_text_field, - ['Decimal Text Field'] = decimal_text_field, - ['Password Text Field'] = password_text_field, - ['Player Stored Text Field'] = player_text_field +tests.Texts = { + ['Local field']=text_filed_local, + ['Store field']=text_filed_store, + ['Local box']=text_box_local, + ['Wrap box']=text_box_wrap } --[[ -Text Boxs -> Basic Text Box -- A text box that can not be edited -> Editible Text Box -- A text box that can be edited + Elem Button Tests + > Local -- Simple elem button + > Default -- Simple elem button which has a default value + > Function -- Elem button which has a dynamic default + > Store -- Elem button which stores its value between re-draws ]] -Gui.require_concept('text_box') - -local 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) - element.style.height = 75 +local elem_local = +Gui.new_elem_button('test-elem-local') +:set_tooltip('Elem') +:set_type('item') +:on_element_update(function(player,element,value) + player.print('Elem: '..value) end) -local 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') -:on_text_changed(function(event) - event.player.print('Editible text box is now: '..event.element.text) -end) -:define_draw(function(properties,parent,element) - element.style.height = 75 +local elem_default = +Gui.new_elem_button('test-elem-default') +:set_tooltip('Elem default') +:set_type('item') +:set_default('iron-plate') +:on_element_update(function(player,element,value) + player.print('Elem default: '..value) end) -tests['Text Boxs'] = { - ['Basic Text Box'] = basic_text_box, - ['Editible Text Box'] = editible_text_box +local elem_function = +Gui.new_elem_button('test-elem-function') +:set_tooltip('Elem function') +:set_type('item') +:set_default(function(player,element) + return 'iron-plate' +end) +:on_element_update(function(player,element,value) + player.print('Elem function: '..value) +end) + +local elem_store = +Gui.new_elem_button('test-elem-store') +:set_tooltip('Elem store') +:set_type('item') +:add_store(Gui.categorize_by_player) +:on_element_update(function(player,element,value) + player.print('Elem store: '..value) +end) + +tests["Elem Buttons"] = { + ['Local']=elem_local, + ['Default']=elem_default, + ['Function']=elem_function, + ['Store']=elem_store +} + +--[[ + Progress bar tests + > Simple -- Progress bar that fills every 2 seconds + > Store -- Progress bar that fills every 5 seconds with synced value + > Reverse -- Progress bar that decreases every 2 seconds +]] + +local progressbar_one = +Gui.new_progressbar('test-prog-one') +:set_default_maximum(120) +:on_complete(function(player,element,reset_element) + reset_element() +end) + +local progressbar_two = +Gui.new_progressbar('test-prog-one') +:set_default_maximum(300) +:add_store(Gui.categorize_by_force) +:on_complete(function(player,element,reset_element) + reset_element() +end) +:on_store_complete(function(category,reset_store) + reset_store() +end) + +local progressbar_three = +Gui.new_progressbar('test-prog-one') +:set_default_maximum(120) +:use_count_down() +:on_complete(function(player,element,reset_element) + reset_element() +end) + +Event.add(defines.events.on_tick,function() + progressbar_one:increment() + progressbar_three:decrement() + local categories = Store.get_children(progressbar_two.store) + for _,category in pairs(categories) do + progressbar_two:increment(1,category) + end +end) + +tests["Progress Bars"] = { + ['Simple']=progressbar_one, + ['Store']=progressbar_two, + ['Reverse']=progressbar_three } \ No newline at end of file diff --git a/expcore/toolbar.lua b/expcore/toolbar.lua deleted file mode 100644 index 03dd4a1b..00000000 --- a/expcore/toolbar.lua +++ /dev/null @@ -1,493 +0,0 @@ ---[[-- Core Module - Toolbar - @core Toolbar - @alias Toolbar -]] - -local Gui = require 'expcore.gui' --- @dep expcore.gui -local Roles = require 'expcore.roles' --- @dep expcore.roles -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 -local Toolbar = { - button_concepts = {}, - frame_concepts = {}, - permissions = {} -} - -Gui.Toolbar = Toolbar - ---- Permissions. --- Functions to do with deciding which player can do what --- @section permissions - ---[[-- Used to test if a player is allowed to use a button on the toolbar, if you are not using expcore.roles then change this function -@tparam LuaPlayer player the player you want ot test is allowed to use this button -@tparam string concept_name the name of the button concept that you want to see if the player is allowed to use -@treturn boolean true if the player is allowed to use it -@usage-- Test if a player can use 'test-player-list' -local allowed = Toolbar.allowed(game.player,'test-player-list') -]] -function Toolbar.allowed(player,concept_name) - local permission = Toolbar.permissions[concept_name] or concept_name - return Roles.player_allowed(player,permission) -end - ---[[-- Use to add an alias for the allowed test, alias is what is tested for rather than the concept name -@tparam string concept_name the name of the concept that will point to this alias -@tparam string alias the permission string that will be tested when this concept is used with Toolbar.allowed -@usage-- Adding an alias for the 'test-player-list' concept -Toolbar.set_permission_alias('test-player-list','gui/player-list') -]] -function Toolbar.set_permission_alias(concept_name,alias) - Toolbar.permissions[concept_name] = alias -end - ---- Buttons. --- All function to do with the toolbar buttons --- @section buttons - ---[[-- Adds a concept to be drawn to the button area and allows it to be toggled with the toggle toolbar button -@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.new_concept('button') -:set_caption('Click Me') -:on_click(function(event) - event.player.print('You Clicked Me!!') -end) - -Toolbar.add_button_concept(new_button) -]] -function Toolbar.add_button_concept(concept) - local concepts = Toolbar.button_concepts - concepts[#concepts+1] = concept -end - ---[[-- Updates all the buttons for a player, this means hide and show buttons based on permissions -@tparam LuaPlayer player the player to update the toolbar buttons for -@usage-- Updating your toolbar -Toolbar.update_buttons(player) -]] -function Toolbar.update_buttons(player) - toolbar_concept:raise_event('on_button_update',{ - player_index = player.index - }) -end - ---[[-- Returns an array of buttons names that the given player is able to see, returns none if toolbar hidden -@tparam LuaPlayer player the player you want to get the visible buttons of -@treturn table an array of names of the visible buttons -@usage-- Get a list of all your visible buttons -Toolbar.get_visible_buttons(game.player) -]] -function Toolbar.get_visible_buttons(player) - local rtn = {} - local top_flow = mod_gui.get_button_flow(player) - - for _,concept in pairs(Toolbar.button_concepts) do - local element = top_flow[concept.name] - if element.visible then - rtn[#rtn+1] = element.name - end - end - - return rtn -end - ---[[-- The base element to be used with the toolbar, others can be used but this is recomented -@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.new_concept('toolbar-button') -:set_caption('Click Me') -:on_click(function(event) - event.player.print('You Clicked Me!!') -end) - -]] -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 -end) - ---- Frames. --- Functions to do with the toolbar frames --- @section frames - ---[[-- Adds a frame concept to the toolbar frame area, this will not add a button to the toolbar -@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.new_concept('frame') -:set_title('Test') - -Toolbar.add_frame_concept(new_frame) -]] -function Toolbar.add_frame_concept(concept) - local concepts = Toolbar.frame_concepts - concepts[#concepts+1] = concept -end - ---[[-- Hides all the frames for a player -@tparam LuaPlayer player the player to hide the frames for -@usage-- Hiding all your frames -Toolbar.hide_frames(game.player) -]] -function Toolbar.hide_frames(player) - toolbar_concept:raise_event('on_hide_frames',{ - player_index = player.index - }) -end - ---[[-- Gets an array of the names of all the visible frames for a player -@tparam LuaPlayer player the player that you want to get the visible frames of -@treturn table an array of names of the visible frames for the given player -@usage-- Get all your visible frames -Toolbar.get_visible_frames(game.player) -]] -function Toolbar.get_visible_frames(player) - local rtn = {} - local left_flow = mod_gui.get_frame_flow(player) - - for _,concept in pairs(Toolbar.frame_concepts) do - local element = left_flow[concept.name..'-frame'] - if element.visible then - rtn[#rtn+1] = element.name - end - end - - left_flow[toolbar_hide_concept.name].visible = #rtn > 0 - - return rtn -end - ---[[-- The base toolbar frame, others can be used but this is recomented -@element toolbar-frame - -@param on_update fired when the frame is to have its content updated - -@tparam boolean open_by_default weather the frame should be open when a player first joins -@tparam boolean use_container true by default and will place a container inside the frame for content -@tparam string direction the direction that the items in the frame are added - -@usage-- Adding a basic player list -local player_list = -Gui.new_concept('toolbar-frame') -:set_permission_alias('player_list') -:set_caption('Player List') -:toggle_with_click() - -:define_draw(function(properties,parent,element) - local list_area = - element.add{ - name = 'scroll', - type = 'scroll-pane', - direction = 'vertical', - horizontal_scroll_policy = 'never', - vertical_scroll_policy = 'auto-and-reserve-space' - } - Gui.set_padding(list_area,1,1,2,2) - list_area.style.horizontally_stretchable = true - list_area.style.maximal_height = 200 - - for _,player in pairs(game.connected_players) do - list_area.add{ - type='label', - caption=player.name - } - end -end) - -:on_update(function(event) - local list_area = event.element.scroll - list_area.clear() - - for _,player in pairs(game.connected_players) do - list_area.add{ - type='label', - caption=player.name - } - end -end) - -]] -Toolbar.frame = -Gui.new_concept('toolbar-button') -:save_as('toolbar-frame') - --- Properties -:new_property('open_by_default',nil,false) -:new_property('use_container',nil,true) -:new_property('direction',nil,'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) - local left_flow = mod_gui.get_frame_flow(player) - local frame = left_flow.add{ - name = properties.name..'-frame', - type = 'frame', - direction = properties.direction - } - - frame.style.padding = 2 - - if properties.use_container then - local container = - frame.add{ - name = 'container', - type = 'frame', - direction = properties.direction, - style = 'window_content_frame_packed' - } - Gui.set_padding(container) - - return container - end - - return frame -end) - ---[[-- Gets the content area of the frame concept for this player, each player only has one area -@tparam LuaPlayer player the player that you want to get the frame content for -@treturn LuaGuiElement the content area of this concept for this player -@usage-- Get the content area of a concept -local frame = player_list:get_content(game.player) -]] -function Toolbar.frame:get_content(player) - local left_flow = mod_gui.get_frame_flow(player) - local frame = left_flow[self.name..'-frame'] - return frame.container or frame -end - ---[[-- Toggles the visibilty of this concept for the given player -@tparam LuaPlayer player the player that you want to toggle the frame for -@treturn boolean the new state of the visibilty of this concept for the player -@usage-- Toggle the frame for your self -player_list:toggle_visible_state(game.player) -]] -function Toolbar.frame:toggle_visible_state(player) - local left_flow = mod_gui.get_frame_flow(player) - local frame = left_flow[self.name..'-frame'] - if frame.visible then - frame.visible = false - Toolbar.get_visible_frames(player) - return false - else - frame.visible = true - Toolbar.get_visible_frames(player) - return true - end -end - ---[[-- Gets the current visibilty state of this conept for this player -@tparam LuaPlayer player the player that you want the visibilty state for -@treturn boolean the current visiblity state of this concept to the player -@usage-- Getting the current visiblity state -player_list:get_visible_state(player)]] -function Toolbar.frame:get_visible_state(player) - local left_flow = mod_gui.get_frame_flow(player) - return left_flow[self.name..'-frame'].visible -end - ---[[-- Triggers an update of the content within the concept for this player, uses on_update handlers -@tparam LuaPlayer player the player to update the concept content for -@tparam[opt] table event the event data that you want to pass to the update handlers -@usage-- Updating the frame for your player -player_list:update(game.player) -]] -function Toolbar.frame:update(player,event) - event = event or {} - event.player_index = player.index - event.element = self:get_content(player) - self:raise_event('on_update',event) -end - ---[[-- Triggers an update of the content with in this frame for all players -@tparam[opt] table event the event data that you want to pass to the update handlers -@usage-- Update the grame for all players -player_list:update_all() -]] -function Toolbar.frame:update_all(event) - local players = event.update_offline == true and game.players or game.connected_players - for _,player in pairs(players) do - self:update(player) - end -end - ---- Other Elements. --- All the other elements that are used to make this work --- @section elements - ---[[-- The main toolbar element, draws, updates, and controls the other concepts -@element toolbar -@param on_button_update fired when the buttons are updated for a player -@param on_hide_frames fired when the frames are hidden for a player -]] -toolbar_concept = -Gui.new_concept() -:debug('toolbar') -:define_draw(function(properties,player) - -- Get the main flows - local top_flow = mod_gui.get_button_flow(player) - if not top_flow then return end - local left_flow = mod_gui.get_frame_flow(player) - if not left_flow then return end - - -- Draw toggle buttons first - toolbar_toggle_concept:draw(top_flow) - toolbar_hide_concept:draw(left_flow) - - -- Draw all the buttons and frames - local done = {} - for _,concept in pairs(Toolbar.button_concepts) do - done[concept.name] = true - concept:draw(top_flow) - top_flow[concept.name].visible = Toolbar.allowed(player,concept.name) - - local frame = left_flow[concept.name..'-frame'] - if frame then - frame.visible = Gui.resolve_property(concept.properties.open_by_default,frame) - end - end - - -- Draws frames that did not have buttons - for _,concept in pairs(Toolbar.frame_concepts) do - if not done[concept.name] then - concept:draw(left_flow) - local frame = left_flow[concept.name..'-frame'] - if frame then - frame.visible = Gui.resolve_property(concept.properties.open_by_default,frame) - end - end - end - - -- Toggle the clear toobar if needed - 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 - local player = event.player - local top_flow = mod_gui.get_button_flow(player) - if not top_flow then return end - - -- Set the visiblity of the elements - local visible = top_flow[toolbar_toggle_concept.name].caption == '<' - for _,concept in pairs(Toolbar.button_concepts) do - local element = top_flow[concept.name] - if Gui.valid(element) then - element.visible = visible and Toolbar.allowed(player,concept.name) - end - end - -end) - --- When frames are hidden -:new_event('on_hide_frames') -:on_hide_frames(function(event) - -- Get the left flow - local player = event.player - local left_flow = mod_gui.get_frame_flow(player) - if not left_flow then return end - - -- Set the visiblity of the elements - left_flow[toolbar_hide_concept.name].visible = false - for _,concept in pairs(Toolbar.frame_concepts) do - local element = left_flow[concept.name..'-frame'] - if Gui.valid(element) then element.visible = false end - end -end) - ---- Used so toggle and hide can have the same look as each other -local function toolbar_button_draw(properties,parent,element) - element.style = mod_gui.button_style - local style = element.style - style.width = 18 - style.height = 36 - style.padding = 0 - style.left_padding = 1 - style.font = 'default-small-bold' -end - ---[[-- Button which toggles the the visible state of all toolbar buttons, triggers on_button_update -@element toolbar-toggle -]] -toolbar_toggle_concept = -Gui.new_concept('button') -:set_caption('<') -:set_tooltip{'gui_util.button_tooltip'} -:define_draw(toolbar_button_draw) -:on_click(function(event) - local element = event.element - element.caption = element.caption == '<' and '>' or '<' - toolbar_concept:raise_event('on_button_update',{ - player_index = event.player_index - }) -end) - ---[[-- Button which hides all visible toolbar frames, triggers on_hide_frames -@element toolbar-clear -]] -toolbar_hide_concept = -Gui.new_concept('button') -:set_caption('<') -:set_tooltip{'expcore-gui.left-button-tooltip'} -:define_draw(toolbar_button_draw) -:on_click(function(event) - event.element.visible = false - toolbar_concept:raise_event('on_hide_frames',{ - player_index = event.player_index - }) -end) - ---- When there is a new player they will have the toolbar update -Event.add(defines.events.on_player_created,function(event) - local player = Game.get_player_by_index(event.player_index) - toolbar_concept:draw(player) -end) - ---- When a player gets a new role they will have the toolbar updated -Event.add(Roles.events.on_role_assigned,function(event) - toolbar_concept:raise_event('on_button_update',{ - player_index = event.player_index - }) -end) - ---- When a player loses a role they will have the toolbar updated -Event.add(Roles.events.on_role_unassigned,function(event) - toolbar_concept:raise_event('on_button_update',{ - player_index = event.player_index - }) -end) - -return Toolbar \ No newline at end of file diff --git a/modules/gui/player-list.lua b/modules/gui/player-list.lua index a97db8c9..e58a55bd 100644 --- a/modules/gui/player-list.lua +++ b/modules/gui/player-list.lua @@ -9,25 +9,16 @@ local Roles = require 'expcore.roles' --- @dep expcore.roles local Store = require 'expcore.store' --- @dep expcore.store local Game = require 'utils.game' --- @dep utils.game local Event = require 'utils.event' --- @dep utils.event +local format_time = ext_require('expcore.common','format_time') --- @dep expcore.common local config = require 'config.action_buttons' --- @dep config.action_buttons local Colors = require 'resources.color_presets' --- @dep resources.color_presets -require 'expcore.toolbar' --- @dep expcore.toolbar - -Gui.require_concept('label') -Gui.require_concept('button') -Gui.require_concept('text_field') -Gui.require_concept('frame') -Gui.require_style('expstyle') local action_player_store = 'gui.left.player-list.action-player' local action_name_store = 'gui.left.player-list.action-name' ---- Name label that alows zoom to map --- @element zoom_to_map -local zoom_to_map = -Gui.new_concept('label') -:new_event('on_click',defines.events.on_gui_click) -:on_click(function(event) +--- used on player name label to allow zoom to map +local zoom_to_map_name = Gui.uid_name() +Gui.on_click(zoom_to_map_name,function(event) local action_player_name = event.element.caption local action_player = Game.get_player_from_any(action_player_name) if event.button == defines.mouse_button_type.left then @@ -45,130 +36,136 @@ Gui.new_concept('label') end end end) -:define_pre_draw(function(properties,parent,element) - -- Place the button into a flow - local flow = - parent.add{ - type = 'flow', - } - - return element, flow -end) -:define_draw(function(properties,parent,element,player,role_name) - local player_name = player.name - element.caption = player_name - element.tooltip = {'player-list.open-map',player_name,player.tag,role_name} - - Gui.set_padding(element,0,0,0,2) - element.style.font_color = player.chat_color -end) - ---- Right align for the time label --- @element right_align -local right_align = -Gui.new_concept('alignment') - ---- Shows the players online time --- @element time_label -local time = -Gui.new_concept('time_label') -:set_time_format{minutes = true} -:set_time(0) -:define_draw(function(properties,parent,element) - Gui.set_padding(element) -end) --- Button used to open the action bar -- @element open_action_bar local open_action_bar = -Gui.new_concept('button') -:set_sprite('utility/expand_dots_white') +Gui.new_button() +:set_sprites('utility/expand_dots_white') :set_tooltip{'player-list.open-action-bar'} -:define_pre_draw(function(properties,parent,element,action_player_name) - -- Place the button into a flow - local flow = - parent.add{ - type = 'flow', - name = action_player_name - } - - return element, flow +:set_embedded_flow(function(element,action_player_name) + return action_player_name end) -:define_draw(function(properties,parent,element) - -- Update the style of the element - element.style = 'frame_button' - local style = element.style - style.padding = -2 +:set_style('frame_button',function(style) + Gui.set_padding_style(style,-2,-2,-2,-2) style.width = 8 style.height = 14 end) -:on_click(function(event) - -- Open the action bar when pressed - local element = event.element - local player_name = event.player.name +:on_click(function(player,element) local new_action_player_name = element.parent.name - local action_player_name = Store.get(action_player_store,player_name) + local action_player_name = Store.get(action_player_store,player.name) if action_player_name == new_action_player_name then - Store.clear(action_player_store,player_name) -- will close if already open + Store.clear(action_player_store,player.name) -- will close if already open else - Store.set(action_player_store,player_name,new_action_player_name) + Store.set(action_player_store,player.name,new_action_player_name) end end) --- Button used to close the action bar -- @element close_action_bar local close_action_bar = -Gui.new_concept('button') -:set_sprite('utility/close_black','utility/close_white') +Gui.new_button() +:set_sprites('utility/close_black','utility/close_white') :set_tooltip{'player-list.close-action-bar'} -:define_draw(function(properties,parent,element) - -- Update the style of the element - element.style = 'tool_button' - local style = element.style - style.padding = -1 +:set_style('tool_button',function(style) + Gui.set_padding_style(style,-1,-1,-1,-1) style.height = 28 style.width = 28 end) -:on_click(function(event) - -- Close the action bar - local player_name = event.player.name - Store.clear(action_player_store,player_name) - Store.clear(action_name_store,player_name) +:on_click(function(player,element) + Store.clear(action_player_store,player.name) + Store.clear(action_name_store,player.name) end) ---- Adds all the player info into the content table --- @element player_info -local player_info = -Gui.new_concept() -:define_draw(function(properties,parent,element,player,role_name) - local player_name = player.name - open_action_bar:draw(parent,nil,player_name) - zoom_to_map:draw(parent,nil,player,role_name) - time:update_time(time:draw(right_align:draw(parent,time.name..player_name)),player.online_time) +--- Button used to confirm a reason +-- @element reason_confirm +local reason_confirm = +Gui.new_button() +:set_sprites('utility/confirm_slot') +:set_tooltip{'player-list.reason-confirm'} +:set_style('tool_button',function(style) + Gui.set_padding_style(style,-1,-1,-1,-1) + style.height = 28 + style.width = 28 +end) +:on_click(function(player,element) + local reason = element.parent.entry.text or 'Non Given' + local action_name = Store.get(action_name_store,player.name) + local reason_callback = config[action_name].reason_callback + reason_callback(player,reason) + Store.clear(action_player_store,player.name) + Store.clear(action_name_store,player.name) + element.parent.entry.text = '' end) ---- Stores all the online players --- @element content_table -local content_table = -Gui.new_concept('scroll_table') -:set_height(188) -:set_column_count(3) +--[[ Creates the main gui areas for the player list + element + > container + >> scroll + >>> table + >> action_bar +]] +local function generate_container(player,element) + Gui.set_padding(element,2,2,2,2) + element.style.minimal_width = 200 ---- Stores all the action buttons --- @element action_bar -local action_bar = -Gui.new_concept('frame') -:define_draw(function(properties,parent,element) - element.style = 'subfooter_frame' - Gui.set_padding(element,1,1,3,3) + -- main container which contains the other elements + local container = + element.add{ + name='container', + type='frame', + direction='vertical', + style='window_content_frame_packed' + } + Gui.set_padding(container) - local style = element.style - style.horizontally_stretchable = true - style.height = 35 + -- 3 wide table to contain: action button, player name, and play time + local list_table = Gui.create_scroll_table(container,3,188) - close_action_bar:draw(element) + -- action bar which contains the different action buttons + local action_bar = + container.add{ + name='action_bar', + type='frame', + style='subfooter_frame' + } + Gui.set_padding(action_bar,1,1,3,3) + action_bar.style.horizontally_stretchable = true + action_bar.style.height = 35 - local player = Gui.get_player_from_element(element) + -- reason bar which contains the reason text field and confirm button + local reason_bar = + container.add{ + name='reason_bar', + type='frame', + style='subfooter_frame' + } + Gui.set_padding(reason_bar,-1,-1,3,3) + reason_bar.style.horizontally_stretchable = true + reason_bar.style.height = 35 + local action_name = Store.get(action_name_store,player.name) + reason_bar.visible = action_name ~= nil + + -- text entry for the reason bar + local reason_field = + reason_bar.add{ + name='entry', + type='textfield', + style='stretchable_textfield', + tooltip={'player-list.reason-entry'} + } + Gui.set_padding(reason_field) + reason_field.style.height = 28 + reason_field.style.minimal_width = 160 + + reason_confirm(reason_bar) + + return list_table, action_bar +end + +--- Adds buttons and permission flows to the action bar +local function generate_action_bar(player,element) + close_action_bar(element) local action_player = Store.get(action_player_store,player.name) for action_name,buttons in pairs(config) do @@ -179,7 +176,7 @@ Gui.new_concept('frame') } for _,button in ipairs(buttons) do - button:draw(permission_flow) + button(permission_flow) end if not Roles.player_allowed(player,action_name) then @@ -189,79 +186,18 @@ Gui.new_concept('frame') if buttons.auth and action_player and not buttons.auth(player,action_player) then permission_flow.visible = false end - end if not action_player then element.visible = false end -end) - ---- Text entry for reason --- @element reason_field -local reason_field = -Gui.new_concept('text_field') -:set_tooltip{'player-list.reason-entry'} -:define_draw(function(properties,parent,element) - element.style = 'stretchable_textfield' - local style = element.style - style.padding = 0 - style.minimal_width = 160 - style.height = 28 -end) - ---- Button used to confirm a reason --- @element reason_confirm -local reason_confirm = -Gui.new_concept('button') -:set_sprite('utility/confirm_slot') -:set_tooltip{'player-list.reason-confirm'} -:define_draw(function(properties,parent,element) - -- Update the style of the element - element.style = 'tool_button' - local style = element.style - style.padding = -1 - style.height = 28 - style.width = 28 -end) -:on_click(function(event) - -- Confirm the reason given - local element = event.element - local player_name = event.player.name - local reason = element.parent.entry.text or 'Non Given' - local action_name = Store.get(action_name_store,player_name) - local reason_callback = config[action_name].reason_callback - reason_callback(event.player,reason) - Store.clear(action_player_store,player_name) - Store.clear(action_name_store,player_name) - element.parent.entry.text = '' -end) - ---- Stores the reason entry and confirmation button --- @element reason_bar -local reason_bar = -Gui.new_concept('frame') -:define_draw(function(properties,parent,element) - element.style = 'subfooter_frame' - Gui.set_padding(element,-1,-1,3,3) - - local style = element.style - style.horizontally_stretchable = true - style.height = 35 - - local player = Gui.get_player_from_element(element) - local action_name = Store.get(action_name_store,player.name) - element.visible = action_name ~= nil - - reason_field:draw(element) - reason_confirm:draw(element) -end) +end --- Updates the action bar -local player_list +local player_list_name local function update_action_bar(player) - local content = player_list:get_content(player) - local element = Gui.find(content,action_bar) + local frame = Gui.classes.left_frames.get_frame(player_list_name,player) + local element = frame.container.action_bar local action_player_name = Store.get(action_player_store,player.name) if not action_player_name then @@ -276,7 +212,6 @@ local function update_action_bar(player) element.visible = true for action_name,buttons in pairs(config) do if buttons.auth and not buttons.auth(player,action_player) then - print(action_name) element[action_name].visible = false elseif Roles.player_allowed(player,action_name) then element[action_name].visible = true @@ -286,37 +221,70 @@ local function update_action_bar(player) end end +--- Adds a player to the player list +local function add_player(list_table,player,role_name) + open_action_bar(list_table,player.name) + + -- flow to contain player_name to allow all to have trigger for zoom to map + local player_name_flow = + list_table.add{ + type='flow' + } + Gui.set_padding(player_name_flow) + + -- player name with the tooltip of their highest role and in they colour + local player_name = + player_name_flow.add{ + name=zoom_to_map_name, + type='label', + caption=player.name, + tooltip={'player-list.open-map',player.name,player.tag,role_name} + } + Gui.set_padding(player_name,0,0,0,2) + player_name.style.font_color = player.chat_color + + -- flow which allows right align for the play time + local time_flow = Gui.create_alignment(list_table,'player-time-'..player.index) + + -- time given in Xh Ym and is right aligned + local tick = game.tick > 0 and game.tick or 1 + local percent = math.round(player.online_time/tick,3)*100 + local time = + time_flow.add{ + name='label', + type='label', + caption=format_time(player.online_time), + tooltip={'player-list.afk-time',percent,format_time(player.afk_time,{minutes=true,long=true})} + } + Gui.set_padding(time) +end + --- Adds fake players to the player list -local function add_fake_players(content_area,count) +local function add_fake_players(list_table,count) local role_name = 'Fake Player' for i = 1,count do - local player = { + add_player(list_table,{ name='Player '..i, index=0-i, tag='', online_time=math.random(0,game.tick), afk_time=math.random(0,game.tick), chat_color=table.get_random_dictionary_entry(Colors) - } - - player_info:draw(content_area,nil,player,role_name) + },role_name) end end --- Registers the player list -- @element player_list -player_list = -Gui.new_concept('toolbar-frame') -:set_permission_alias('gui/player-list') -:set_sprite('entity/character') +local player_list = +Gui.new_left_frame('gui/player-list') +:set_sprites('entity/character') :set_tooltip{'player-list.main-tooltip'} -:set_open_by_default(true) +:set_open_by_default() :set_direction('vertical') -:define_draw(function(properties,parent,element) - local content_area = - content_table:draw(element) - action_bar:draw(element) - reason_bar:draw(element) +:on_creation(function(player,element) + local list_table,action_bar = generate_container(player,element) + generate_action_bar(player,action_bar) local players = {} for _,next_player in pairs(game.connected_players) do @@ -330,49 +298,55 @@ Gui.new_concept('toolbar-frame') for _,role_name in pairs(Roles.config.order) do if players[role_name] then for _,next_player in pairs(players[role_name]) do - player_info:draw(content_area,nil,next_player,role_name) + add_player(list_table,next_player,role_name) end end end - add_fake_players(content_area,4) + --add_fake_players(list_table,6) + --add_fake_players(list_table,20) end) -:on_update(function(event) - local list = Gui.find(event.element,content_table,'table') +:on_update(function(player,element) + local list = element.container.scroll.table for _,next_player in pairs(game.connected_players) do - local time_element = Gui.find(list,time.name..next_player.name,time) + local time_element_name = 'player-time-'..next_player.index + local time_element = list[time_element_name] if time_element and time_element.valid then - time:update_time(time_element,next_player.online_time) + time_element.label.caption = format_time(next_player.online_time) + local tick = game.tick > 0 and game.tick or 1 + local percent = math.round(next_player.online_time/tick,3)*100 + time_element.label.tooltip = {'player-list.afk-time',percent,format_time(next_player.afk_time,{minutes=true,long=true})} end end end) +player_list_name = player_list:uid() + --- When the action player is changed the action bar will update Store.register(action_player_store,function(value,category) local player = Game.get_player_from_any(category) update_action_bar(player) - local frame = player_list:get_content(player) - local data_table = Gui.find(frame,content_table,'table') + local frame = player_list:get_frame(player) + local data_table = frame.container.scroll.table for _,next_player in pairs(game.connected_players) do - local element = Gui.find(data_table,next_player.name,open_action_bar) + local element = data_table[next_player.name][open_action_bar.name] local style = 'frame_button' if next_player.name == value then style = 'tool_button' end element.style = style - style = element.style - style.padding = -2 - style.width = 8 - style.height = 14 + Gui.set_padding(element,-2,-2,-2,-2) + element.style.width = 8 + element.style.height = 14 end end) --- When the action name is changed the reason input will update Store.register(action_name_store,function(value,category) local player = Game.get_player_from_any(category) - local frame = player_list:get_content(player) - local element = Gui.find(frame,reason_bar) + local frame = Gui.classes.left_frames.get_frame(player_list_name,player) + local element = frame.container.reason_bar if value then local action_player_name = Store.get(action_player_store,category) local action_player = Game.get_player_from_any(action_player_name) @@ -388,11 +362,10 @@ Store.register(action_name_store,function(value,category) end) --- Many events which trigger the gui to be re drawn, it will also update the times every 30 seconds -local update = function(event) player_list:update_all(event) end -Event.on_nth_tick(1800,update) -Event.add(defines.events.on_player_joined_game,update) -Event.add(defines.events.on_player_left_game,update) -Event.add(Roles.events.on_role_assigned,update) -Event.add(Roles.events.on_role_unassigned,update) +Event.on_nth_tick(1800,player_list 'update_all') +Event.add(defines.events.on_player_joined_game,player_list 'redraw_all') +Event.add(defines.events.on_player_left_game,player_list 'redraw_all') +Event.add(Roles.events.on_role_assigned,player_list 'redraw_all') +Event.add(Roles.events.on_role_unassigned,player_list 'redraw_all') return player_list \ No newline at end of file From a595b79dd7f03da97a518547ab9a68301f8707f9 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sat, 28 Sep 2019 16:34:58 +0100 Subject: [PATCH 26/26] Revert --- docs/addons/Advanced-Start.html | 4 +- docs/addons/Chat-Popups.html | 4 +- docs/addons/Chat-Reply.html | 4 +- docs/addons/Compilatron.html | 4 +- docs/addons/Damage-Popups.html | 4 +- docs/addons/Death-Logger.html | 4 +- docs/addons/Discord-Alerts.html | 4 +- docs/addons/Player-Colours.html | 4 +- docs/addons/Pollution-Grading.html | 4 +- docs/addons/Scorched-Earth.html | 4 +- docs/addons/Spawn-Area.html | 4 +- docs/commands/Admin-Chat.html | 4 +- docs/commands/Bonus.html | 4 +- docs/commands/Cheat-Mode.html | 4 +- docs/commands/Clear-Inventory.html | 4 +- docs/commands/Debug.html | 4 +- docs/commands/Find.html | 4 +- docs/commands/Help.html | 4 +- docs/commands/Home.html | 4 +- docs/commands/Interface.html | 4 +- docs/commands/Jail.html | 4 +- docs/commands/Kill.html | 4 +- docs/commands/Me.html | 4 +- docs/commands/Rainbow.html | 4 +- docs/commands/Repair.html | 4 +- docs/commands/Reports.html | 4 +- docs/commands/Roles.html | 4 +- docs/commands/Spawn.html | 4 +- docs/commands/Tag.html | 4 +- docs/commands/Teleport.html | 4 +- docs/commands/Warnings.html | 4 +- docs/configs/Advanced-Start.html | 4 +- docs/configs/Bonuses.html | 4 +- docs/configs/Chat-Reply.html | 4 +- docs/configs/Commands-Auth-Admin.html | 4 +- docs/configs/Commands-Auth-Roles.html | 4 +- .../Commands-Auth-Runtime-Disable.html | 4 +- docs/configs/Commands-Parse-Roles.html | 4 +- docs/configs/Commands-Parse.html | 4 +- docs/configs/Compilatron.html | 4 +- docs/configs/Death-Logger.html | 4 +- docs/configs/Discord-Alerts.html | 4 +- docs/configs/File-Loader.html | 4 +- docs/configs/Permission-Groups.html | 4 +- docs/configs/Player-List.html | 4 +- docs/configs/Pollution-Grading.html | 4 +- docs/configs/Popup-Messages.html | 4 +- docs/configs/Preset-Player-Colours.html | 4 +- docs/configs/Repair.html | 4 +- docs/configs/Rockets.html | 4 +- docs/configs/Roles.html | 4 +- docs/configs/Science.html | 4 +- docs/configs/Scorched-Earth.html | 4 +- docs/configs/Spawn-Area.html | 4 +- docs/configs/Tasks.html | 4 +- docs/configs/Warnings.html | 4 +- docs/configs/Warps.html | 4 +- docs/control/Jail.html | 4 +- docs/control/Production.html | 4 +- docs/control/Reports.html | 4 +- docs/control/Rockets.html | 4 +- docs/control/Tasks.html | 4 +- docs/control/Warnings.html | 4 +- docs/control/Warps.html | 4 +- docs/core/Commands.html | 4 +- docs/core/Common-Library.html | 4 +- docs/core/Gui.html | 12963 +++++++++++----- docs/core/Permissions-Groups.html | 4 +- docs/core/Roles.html | 4 +- docs/core/Store.html | 4 +- docs/core/Sudo.html | 4 +- docs/guis/Player-List.html | 4 +- docs/guis/Rocket-Info.html | 4 +- docs/guis/Science-Info.html | 4 +- docs/guis/Task-List.html | 4 +- docs/guis/Warps-List.html | 4 +- docs/index.html | 16 +- docs/modules/control.html | 4 +- .../utils.alien_evolution_progress.html | 4 +- docs/modules/utils.core.html | 4 +- docs/modules/utils.debug.html | 4 +- docs/modules/utils.dump_env.html | 4 +- docs/modules/utils.event.html | 4 +- docs/modules/utils.event_core.html | 4 +- docs/modules/utils.math.html | 4 +- docs/modules/utils.recipe_locker.html | 4 +- docs/modules/utils.state_machine.html | 4 +- docs/modules/utils.table.html | 4 +- docs/modules/utils.task.html | 4 +- docs/modules/utils.timestamp.html | 4 +- docs/topics/license.html | 4 +- docs/topics/readme.md.html | 4 +- 92 files changed, 9171 insertions(+), 4168 deletions(-) diff --git a/docs/addons/Advanced-Start.html b/docs/addons/Advanced-Start.html index 7eff9ff1..17a11fd8 100644 --- a/docs/addons/Advanced-Start.html +++ b/docs/addons/Advanced-Start.html @@ -70,12 +70,10 @@ - - @@ -350,7 +348,7 @@ generated by LDoc diff --git a/docs/addons/Chat-Popups.html b/docs/addons/Chat-Popups.html index b7f62e7a..ec447b0d 100644 --- a/docs/addons/Chat-Popups.html +++ b/docs/addons/Chat-Popups.html @@ -70,12 +70,10 @@ - - @@ -351,7 +349,7 @@ generated by LDoc diff --git a/docs/addons/Chat-Reply.html b/docs/addons/Chat-Reply.html index 461b1085..227a2701 100644 --- a/docs/addons/Chat-Reply.html +++ b/docs/addons/Chat-Reply.html @@ -70,12 +70,10 @@ - - @@ -378,7 +376,7 @@ generated by LDoc diff --git a/docs/addons/Compilatron.html b/docs/addons/Compilatron.html index 69e05991..dc49b78b 100644 --- a/docs/addons/Compilatron.html +++ b/docs/addons/Compilatron.html @@ -71,12 +71,10 @@ - - @@ -587,7 +585,7 @@ generated by LDoc diff --git a/docs/addons/Damage-Popups.html b/docs/addons/Damage-Popups.html index b23f36ff..c5d5f078 100644 --- a/docs/addons/Damage-Popups.html +++ b/docs/addons/Damage-Popups.html @@ -70,12 +70,10 @@ - - @@ -351,7 +349,7 @@ generated by LDoc diff --git a/docs/addons/Death-Logger.html b/docs/addons/Death-Logger.html index 970986a7..71cc9bde 100644 --- a/docs/addons/Death-Logger.html +++ b/docs/addons/Death-Logger.html @@ -70,12 +70,10 @@ - - @@ -406,7 +404,7 @@ generated by LDoc diff --git a/docs/addons/Discord-Alerts.html b/docs/addons/Discord-Alerts.html index ce786d86..27d0af48 100644 --- a/docs/addons/Discord-Alerts.html +++ b/docs/addons/Discord-Alerts.html @@ -70,12 +70,10 @@ - - @@ -462,7 +460,7 @@ generated by LDoc diff --git a/docs/addons/Player-Colours.html b/docs/addons/Player-Colours.html index be4036df..7d67adeb 100644 --- a/docs/addons/Player-Colours.html +++ b/docs/addons/Player-Colours.html @@ -70,12 +70,10 @@ - - @@ -406,7 +404,7 @@ generated by LDoc diff --git a/docs/addons/Pollution-Grading.html b/docs/addons/Pollution-Grading.html index 9c0a334d..d488a111 100644 --- a/docs/addons/Pollution-Grading.html +++ b/docs/addons/Pollution-Grading.html @@ -70,12 +70,10 @@ - - @@ -322,7 +320,7 @@ generated by LDoc diff --git a/docs/addons/Scorched-Earth.html b/docs/addons/Scorched-Earth.html index 69be957b..55bea826 100644 --- a/docs/addons/Scorched-Earth.html +++ b/docs/addons/Scorched-Earth.html @@ -70,12 +70,10 @@ - - @@ -406,7 +404,7 @@ generated by LDoc diff --git a/docs/addons/Spawn-Area.html b/docs/addons/Spawn-Area.html index 7be892ff..13dfba39 100644 --- a/docs/addons/Spawn-Area.html +++ b/docs/addons/Spawn-Area.html @@ -70,12 +70,10 @@ - - @@ -378,7 +376,7 @@ generated by LDoc diff --git a/docs/commands/Admin-Chat.html b/docs/commands/Admin-Chat.html index 59344610..731be00d 100644 --- a/docs/commands/Admin-Chat.html +++ b/docs/commands/Admin-Chat.html @@ -80,12 +80,10 @@ - - @@ -390,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Bonus.html b/docs/commands/Bonus.html index fc584a2e..d49279c2 100644 --- a/docs/commands/Bonus.html +++ b/docs/commands/Bonus.html @@ -80,12 +80,10 @@ - - @@ -502,7 +500,7 @@ generated by LDoc diff --git a/docs/commands/Cheat-Mode.html b/docs/commands/Cheat-Mode.html index 7bafc60e..accc40eb 100644 --- a/docs/commands/Cheat-Mode.html +++ b/docs/commands/Cheat-Mode.html @@ -80,12 +80,10 @@ - - @@ -363,7 +361,7 @@ generated by LDoc diff --git a/docs/commands/Clear-Inventory.html b/docs/commands/Clear-Inventory.html index bf601ad5..e20883e3 100644 --- a/docs/commands/Clear-Inventory.html +++ b/docs/commands/Clear-Inventory.html @@ -80,12 +80,10 @@ - - @@ -390,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Debug.html b/docs/commands/Debug.html index 532efa99..af847b74 100644 --- a/docs/commands/Debug.html +++ b/docs/commands/Debug.html @@ -80,12 +80,10 @@ - - @@ -367,7 +365,7 @@ generated by LDoc diff --git a/docs/commands/Find.html b/docs/commands/Find.html index 17fec9b6..fc61f8cf 100644 --- a/docs/commands/Find.html +++ b/docs/commands/Find.html @@ -80,12 +80,10 @@ - - @@ -362,7 +360,7 @@ generated by LDoc diff --git a/docs/commands/Help.html b/docs/commands/Help.html index 0122b470..c5d73042 100644 --- a/docs/commands/Help.html +++ b/docs/commands/Help.html @@ -80,12 +80,10 @@ - - @@ -406,7 +404,7 @@ generated by LDoc diff --git a/docs/commands/Home.html b/docs/commands/Home.html index 793b64f4..05da9559 100644 --- a/docs/commands/Home.html +++ b/docs/commands/Home.html @@ -80,12 +80,10 @@ - - @@ -460,7 +458,7 @@ generated by LDoc diff --git a/docs/commands/Interface.html b/docs/commands/Interface.html index 1e467b7b..bc2e0590 100644 --- a/docs/commands/Interface.html +++ b/docs/commands/Interface.html @@ -80,12 +80,10 @@ - - @@ -418,7 +416,7 @@ generated by LDoc diff --git a/docs/commands/Jail.html b/docs/commands/Jail.html index 238e0248..6ff4802e 100644 --- a/docs/commands/Jail.html +++ b/docs/commands/Jail.html @@ -80,12 +80,10 @@ - - @@ -613,7 +611,7 @@ generated by LDoc diff --git a/docs/commands/Kill.html b/docs/commands/Kill.html index 2f3a42d3..a16c18b0 100644 --- a/docs/commands/Kill.html +++ b/docs/commands/Kill.html @@ -80,12 +80,10 @@ - - @@ -391,7 +389,7 @@ generated by LDoc diff --git a/docs/commands/Me.html b/docs/commands/Me.html index 24b64a87..2f8cb3f4 100644 --- a/docs/commands/Me.html +++ b/docs/commands/Me.html @@ -80,12 +80,10 @@ - - @@ -362,7 +360,7 @@ generated by LDoc diff --git a/docs/commands/Rainbow.html b/docs/commands/Rainbow.html index d921f1ef..83127954 100644 --- a/docs/commands/Rainbow.html +++ b/docs/commands/Rainbow.html @@ -80,12 +80,10 @@ - - @@ -390,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Repair.html b/docs/commands/Repair.html index b6f8113b..dfc8fde0 100644 --- a/docs/commands/Repair.html +++ b/docs/commands/Repair.html @@ -79,12 +79,10 @@ - - @@ -323,7 +321,7 @@ generated by LDoc diff --git a/docs/commands/Reports.html b/docs/commands/Reports.html index d51b8af1..bb852d95 100644 --- a/docs/commands/Reports.html +++ b/docs/commands/Reports.html @@ -80,12 +80,10 @@ - - @@ -587,7 +585,7 @@ generated by LDoc diff --git a/docs/commands/Roles.html b/docs/commands/Roles.html index acf6971f..338a0c5e 100644 --- a/docs/commands/Roles.html +++ b/docs/commands/Roles.html @@ -80,12 +80,10 @@ - - @@ -559,7 +557,7 @@ generated by LDoc diff --git a/docs/commands/Spawn.html b/docs/commands/Spawn.html index a940c112..9eba8a8f 100644 --- a/docs/commands/Spawn.html +++ b/docs/commands/Spawn.html @@ -80,12 +80,10 @@ - - @@ -391,7 +389,7 @@ generated by LDoc diff --git a/docs/commands/Tag.html b/docs/commands/Tag.html index bafc6f14..b8609e4a 100644 --- a/docs/commands/Tag.html +++ b/docs/commands/Tag.html @@ -80,12 +80,10 @@ - - @@ -445,7 +443,7 @@ generated by LDoc diff --git a/docs/commands/Teleport.html b/docs/commands/Teleport.html index 2afdbc08..eeed3aa0 100644 --- a/docs/commands/Teleport.html +++ b/docs/commands/Teleport.html @@ -80,12 +80,10 @@ - - @@ -486,7 +484,7 @@ generated by LDoc diff --git a/docs/commands/Warnings.html b/docs/commands/Warnings.html index adabade7..337f8b93 100644 --- a/docs/commands/Warnings.html +++ b/docs/commands/Warnings.html @@ -80,12 +80,10 @@ - - @@ -571,7 +569,7 @@ generated by LDoc diff --git a/docs/configs/Advanced-Start.html b/docs/configs/Advanced-Start.html index 3f5c06a8..72c02f54 100644 --- a/docs/configs/Advanced-Start.html +++ b/docs/configs/Advanced-Start.html @@ -85,12 +85,10 @@ - - @@ -508,7 +506,7 @@ generated by LDoc diff --git a/docs/configs/Bonuses.html b/docs/configs/Bonuses.html index e04bc9e6..31d8e33c 100644 --- a/docs/configs/Bonuses.html +++ b/docs/configs/Bonuses.html @@ -77,12 +77,10 @@ - - @@ -239,7 +237,7 @@ generated by LDoc diff --git a/docs/configs/Chat-Reply.html b/docs/configs/Chat-Reply.html index 17898132..da119978 100644 --- a/docs/configs/Chat-Reply.html +++ b/docs/configs/Chat-Reply.html @@ -86,12 +86,10 @@ - - @@ -487,7 +485,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Admin.html b/docs/configs/Commands-Auth-Admin.html index e9d41e16..fa578e05 100644 --- a/docs/configs/Commands-Auth-Admin.html +++ b/docs/configs/Commands-Auth-Admin.html @@ -85,12 +85,10 @@ - - @@ -296,7 +294,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Roles.html b/docs/configs/Commands-Auth-Roles.html index ed8de360..2e83f8aa 100644 --- a/docs/configs/Commands-Auth-Roles.html +++ b/docs/configs/Commands-Auth-Roles.html @@ -85,12 +85,10 @@ - - @@ -322,7 +320,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Runtime-Disable.html b/docs/configs/Commands-Auth-Runtime-Disable.html index b74be123..e908fa8c 100644 --- a/docs/configs/Commands-Auth-Runtime-Disable.html +++ b/docs/configs/Commands-Auth-Runtime-Disable.html @@ -86,12 +86,10 @@ - - @@ -444,7 +442,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Parse-Roles.html b/docs/configs/Commands-Parse-Roles.html index 3cd75126..3206b122 100644 --- a/docs/configs/Commands-Parse-Roles.html +++ b/docs/configs/Commands-Parse-Roles.html @@ -85,12 +85,10 @@ - - @@ -356,7 +354,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Parse.html b/docs/configs/Commands-Parse.html index 454432dc..14f65272 100644 --- a/docs/configs/Commands-Parse.html +++ b/docs/configs/Commands-Parse.html @@ -85,12 +85,10 @@ - - @@ -340,7 +338,7 @@ see ./expcore/commands.lua for more details

    generated by LDoc diff --git a/docs/configs/Compilatron.html b/docs/configs/Compilatron.html index 7f9f5bae..2d0f47b4 100644 --- a/docs/configs/Compilatron.html +++ b/docs/configs/Compilatron.html @@ -85,12 +85,10 @@ - - @@ -356,7 +354,7 @@ generated by LDoc diff --git a/docs/configs/Death-Logger.html b/docs/configs/Death-Logger.html index 3df18979..f03d13cd 100644 --- a/docs/configs/Death-Logger.html +++ b/docs/configs/Death-Logger.html @@ -85,12 +85,10 @@ - - @@ -418,7 +416,7 @@ generated by LDoc diff --git a/docs/configs/Discord-Alerts.html b/docs/configs/Discord-Alerts.html index 307fba0d..e7cc6d8b 100644 --- a/docs/configs/Discord-Alerts.html +++ b/docs/configs/Discord-Alerts.html @@ -77,12 +77,10 @@ - - @@ -239,7 +237,7 @@ generated by LDoc diff --git a/docs/configs/File-Loader.html b/docs/configs/File-Loader.html index 8dd2e4d2..25d76c3b 100644 --- a/docs/configs/File-Loader.html +++ b/docs/configs/File-Loader.html @@ -77,12 +77,10 @@ - - @@ -242,7 +240,7 @@ generated by LDoc diff --git a/docs/configs/Permission-Groups.html b/docs/configs/Permission-Groups.html index c748144f..5798d322 100644 --- a/docs/configs/Permission-Groups.html +++ b/docs/configs/Permission-Groups.html @@ -85,12 +85,10 @@ - - @@ -297,7 +295,7 @@ generated by LDoc diff --git a/docs/configs/Player-List.html b/docs/configs/Player-List.html index f416997b..28764dd5 100644 --- a/docs/configs/Player-List.html +++ b/docs/configs/Player-List.html @@ -86,12 +86,10 @@ - - @@ -814,7 +812,7 @@ generated by LDoc diff --git a/docs/configs/Pollution-Grading.html b/docs/configs/Pollution-Grading.html index bd47979f..3f407af5 100644 --- a/docs/configs/Pollution-Grading.html +++ b/docs/configs/Pollution-Grading.html @@ -85,12 +85,10 @@ - - @@ -386,7 +384,7 @@ generated by LDoc diff --git a/docs/configs/Popup-Messages.html b/docs/configs/Popup-Messages.html index 8f84f684..e217cb89 100644 --- a/docs/configs/Popup-Messages.html +++ b/docs/configs/Popup-Messages.html @@ -85,12 +85,10 @@ - - @@ -416,7 +414,7 @@ generated by LDoc diff --git a/docs/configs/Preset-Player-Colours.html b/docs/configs/Preset-Player-Colours.html index e49269ee..6ded0dd1 100644 --- a/docs/configs/Preset-Player-Colours.html +++ b/docs/configs/Preset-Player-Colours.html @@ -85,12 +85,10 @@ - - @@ -326,7 +324,7 @@ generated by LDoc diff --git a/docs/configs/Repair.html b/docs/configs/Repair.html index ff7b2189..04430dd7 100644 --- a/docs/configs/Repair.html +++ b/docs/configs/Repair.html @@ -85,12 +85,10 @@ - - @@ -416,7 +414,7 @@ generated by LDoc diff --git a/docs/configs/Rockets.html b/docs/configs/Rockets.html index 15088476..2a142796 100644 --- a/docs/configs/Rockets.html +++ b/docs/configs/Rockets.html @@ -85,12 +85,10 @@ - - @@ -836,7 +834,7 @@ generated by LDoc diff --git a/docs/configs/Roles.html b/docs/configs/Roles.html index 6cc0063b..3fbacb0e 100644 --- a/docs/configs/Roles.html +++ b/docs/configs/Roles.html @@ -85,12 +85,10 @@ - - @@ -294,7 +292,7 @@ generated by LDoc diff --git a/docs/configs/Science.html b/docs/configs/Science.html index a85612a6..873dbf53 100644 --- a/docs/configs/Science.html +++ b/docs/configs/Science.html @@ -85,12 +85,10 @@ - - @@ -356,7 +354,7 @@ generated by LDoc diff --git a/docs/configs/Scorched-Earth.html b/docs/configs/Scorched-Earth.html index f9888961..5f2f2131 100644 --- a/docs/configs/Scorched-Earth.html +++ b/docs/configs/Scorched-Earth.html @@ -85,12 +85,10 @@ - - @@ -390,7 +388,7 @@ generated by LDoc diff --git a/docs/configs/Spawn-Area.html b/docs/configs/Spawn-Area.html index fec2403b..ebefadb6 100644 --- a/docs/configs/Spawn-Area.html +++ b/docs/configs/Spawn-Area.html @@ -85,12 +85,10 @@ - - @@ -746,7 +744,7 @@ generated by LDoc diff --git a/docs/configs/Tasks.html b/docs/configs/Tasks.html index 43bdb919..2ea51a33 100644 --- a/docs/configs/Tasks.html +++ b/docs/configs/Tasks.html @@ -85,12 +85,10 @@ - - @@ -386,7 +384,7 @@ generated by LDoc diff --git a/docs/configs/Warnings.html b/docs/configs/Warnings.html index d5b14073..1971da7d 100644 --- a/docs/configs/Warnings.html +++ b/docs/configs/Warnings.html @@ -85,12 +85,10 @@ - - @@ -357,7 +355,7 @@ generated by LDoc diff --git a/docs/configs/Warps.html b/docs/configs/Warps.html index 3fb7f77f..c90c3b4f 100644 --- a/docs/configs/Warps.html +++ b/docs/configs/Warps.html @@ -85,12 +85,10 @@ - - @@ -686,7 +684,7 @@ generated by LDoc diff --git a/docs/control/Jail.html b/docs/control/Jail.html index a6acc5ce..8b2073fa 100644 --- a/docs/control/Jail.html +++ b/docs/control/Jail.html @@ -69,12 +69,10 @@ - - @@ -1210,7 +1208,7 @@ generated by LDoc diff --git a/docs/control/Production.html b/docs/control/Production.html index 53874e4d..cfc5135f 100644 --- a/docs/control/Production.html +++ b/docs/control/Production.html @@ -69,12 +69,10 @@ - - @@ -1331,7 +1329,7 @@ generated by LDoc diff --git a/docs/control/Reports.html b/docs/control/Reports.html index 67fb2864..02a29320 100644 --- a/docs/control/Reports.html +++ b/docs/control/Reports.html @@ -69,12 +69,10 @@ - - @@ -1112,7 +1110,7 @@ generated by LDoc diff --git a/docs/control/Rockets.html b/docs/control/Rockets.html index 4d560f6f..4cd079d7 100644 --- a/docs/control/Rockets.html +++ b/docs/control/Rockets.html @@ -68,12 +68,10 @@ - - @@ -986,7 +984,7 @@ generated by LDoc diff --git a/docs/control/Tasks.html b/docs/control/Tasks.html index f37fc0d6..0a82275c 100644 --- a/docs/control/Tasks.html +++ b/docs/control/Tasks.html @@ -68,12 +68,10 @@ - - @@ -1041,7 +1039,7 @@ generated by LDoc diff --git a/docs/control/Warnings.html b/docs/control/Warnings.html index 38998a09..cca92779 100644 --- a/docs/control/Warnings.html +++ b/docs/control/Warnings.html @@ -68,12 +68,10 @@ - - @@ -1467,7 +1465,7 @@ generated by LDoc diff --git a/docs/control/Warps.html b/docs/control/Warps.html index fca4cb74..4af6171d 100644 --- a/docs/control/Warps.html +++ b/docs/control/Warps.html @@ -69,12 +69,10 @@ - - @@ -1415,7 +1413,7 @@ generated by LDoc diff --git a/docs/core/Commands.html b/docs/core/Commands.html index 590f6080..b6e82a2c 100644 --- a/docs/core/Commands.html +++ b/docs/core/Commands.html @@ -57,12 +57,10 @@ - - @@ -1974,7 +1972,7 @@ generated by LDoc diff --git a/docs/core/Common-Library.html b/docs/core/Common-Library.html index 6f6e5c02..ee9e8780 100644 --- a/docs/core/Common-Library.html +++ b/docs/core/Common-Library.html @@ -53,12 +53,10 @@ - - @@ -2748,7 +2746,7 @@ Common.table_insert(tbl,50,tbl2) generated by LDoc diff --git a/docs/core/Gui.html b/docs/core/Gui.html index 9524e47e..6533ff0e 100644 --- a/docs/core/Gui.html +++ b/docs/core/Gui.html @@ -41,17 +41,22 @@ @@ -62,12 +67,10 @@ - - @@ -213,17 +216,22 @@ @@ -243,7 +251,11 @@

    Gui core

    -

    Core Module - Gui

    +

    Core Module - Gui + - This file is used to require all the different elements of the gui module + - each module has an outline here but for more details see their separate files in ./gui + - please read the files for more documentation that cant be shown here + - please note there is a rework planned but not started

    @@ -251,69 +263,6 @@ -

    Usage

    -
    -- Making the base button concept
    -local button =
    -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',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) -- 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,
    -            name = properties.name,
    -            caption = properties.caption,
    -            tooltip = properties.tooltip
    -        }
    -
    -    else
    -        element = parent.add{
    -            type = properties.type,
    -            name = properties.name,
    -            sprite = properties.sprite,
    -            tooltip = properties.tooltip
    -        }
    -
    -    end
    -
    -    -- 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)
    -
    -- Making a new button which has a custom style
    -local custom_button =
    -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)
    -: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
    -custom_button:draw(game.player.gui.left)
    @@ -321,69 +270,461 @@ Gui.new_concept('button') -- W -

    Elements

    +

    Dependencies

    - - + - - + - - + - - + - - + - - + - - + - - + - - + - - + - - + - - + - - + + + +
    buttonClickable elements that fire on_gui_click when clicked.expcore.gui.core
    checkboxClickable elements with a cross in the middle that can be turned off or on.expcore.gui.instances
    dropdownA drop down list of other elements.expcore.gui.elements.buttons
    elem_buttonA button that lets the player pick one of an: item, entity, tile, or signal similar to the filter-select window.expcore.gui.elements.checkbox
    emptyA empty widget that just exists.expcore.gui.elements.dropdown
    flowInvisible containers that lay out children either horizontally or vertically.expcore.gui.elements.slider
    frameGrey semi-transparent boxes that contain other elements.expcore.gui.elements.text
    labelA piece of text.expcore.gui.elements.elem-button
    lineA vertical or horizontal line.expcore.gui.elements.progress-bar
    progress_barIndicate progress by displaying a partially filled bar.expcore.gui.concepts.toolbar
    scrollSimilar to a flow but includes the ability to show and use scroll bars.expcore.gui.concepts.left
    sliderA number picker.expcore.gui.concepts.center
    tableAn invisible container that lays out children in a specific number of columns.expcore.gui.concepts.popups
    + + +

    Center Guis

    + + + + + - - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    expcore.gui.core
    text_boxA multi-line text box that supports selection and copy-paste.expcore.gui.prototype
    text_fieldBoxes of text the user can type in.expcore.gui.concepts.toolbar
    utils.game
    CenterFrames.get_flow(player)Gets the center flow for a player
    CenterFrames.clear_flow(player)Clears the center flow for a player
    CenterFrames.draw_frame(player, name)Draws the center frame for a player, if already open then will do nothing
    CenterFrames.redraw_frame(player, name)Draws the center frame for a player, if already open then will destroy it and redraw
    CenterFrames.toggle_frame(player, name[, state])Toggles if the frame is currently open or not, will open if closed and close if open
    CenterFrames.new_frame(permission_name)Creates a new center frame define
    CenterFrames._prototype:set_auto_focus([state=true])Sets the frame to be the current active gui when opened and closes all other frames
    CenterFrames._prototype:draw_frame(player)Draws this frame to the player, if already open does nothing (will call on_draw to draw to the frame)
    CenterFrames._prototype:redraw_frame(player)Draws this frame to the player, if already open it will remove it and redraw it (will call on_draw to draw to the frame)
    CenterFrames._prototype:toggle_frame(player)Toggles if the frame is open, if open it will close it and if closed it will open it
    CenterFrames._prototype:event_handler([action=update])Creates an event handler that will trigger one of its functions, use with Event.add
    + + +

    Left Guis

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    expcore.gui.core
    expcore.gui.prototype
    expcore.gui.concepts.toolbar
    expcore.gui.elements.buttons
    mod-gui
    utils.game
    utils.event
    LeftFrames.get_flow(player)Gets the left frame flow for a player
    LeftFrames.get_frame(name, player)Gets one frame from the left flow by its name
    LeftFrames.get_open(player)Gets all open frames for a player, if non are open it will remove the close all button
    LeftFrames.toggle_frame(name, player[, state])Toggles the visibility of a left frame, or sets its visibility state
    LeftFrames.new_frame(permission_name)Creates a new left frame define
    LeftFrames._prototype:set_open_by_default([state=true])Sets if the frame is visible when a player joins, can also be a function to return a boolean
    LeftFrames._prototype:set_direction(direction)Sets the direction of the frame, either vertical or horizontal
    LeftFrames._prototype:_internal_draw(player)Creates the gui for the first time, used internally
    LeftFrames._prototype:get_frame(player)Gets the frame for this define from the left frame flow
    LeftFrames._prototype:is_open(player)Returns if the player currently has this define visible
    LeftFrames._prototype:toggle(player)Toggles the visibility of the left frame
    LeftFrames._prototype:update(player)Updates the contents of the left frame, first tries update callback, other wise will clear and redraw
    LeftFrames._prototype:update_all([update_offline=false])Updates the frame for all players, see update
    LeftFrames._prototype:redraw(player)Redraws the frame by calling on_draw, will always clear the frame
    LeftFrames._prototype:redraw_all([update_offline=false])Redraws the frame for all players, see redraw
    LeftFrames._prototype:event_handler([action=update])Creates an event handler that will trigger one of its functions, use with Event.add
    + + +

    Popups

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    expcore.gui.core
    expcore.gui.prototype
    utils.game
    utils.event
    expcore.gui.elements.progress-bar
    expcore.gui.elements.buttons
    mod-gui
    resources.color_presets
    utils.global
    PopupFrames.get_flow(player)Gets the left flow that contains the popup frames
    PopupFrames.open(define_name, player[, open_time], ...)Opens a popup for the player, can give the amount of time it is open as well as params for the draw function
    PopupFrames.close_progressProgress bar which when depleted will close the popup frame
    PopupFrames.close_buttonA button which can be used to close the gui before the timer runs out
    PopupFrames.new_popup([name])Creates a new popup frame define
    PopupFrames._prototype:set_default_open_time(amount)Sets the default open time for the popup, will be used if non is provided with open
    PopupFrames._prototype:open(player[, open_time], ...)Opens this define for a player, can be given open time and any other params for the draw function
    + + +

    Toolbar

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    expcore.gui.core
    expcore.gui.elements.buttons
    expcore.roles
    utils.event
    utils.game
    mod-gui
    Toolbar.new_button([name])Adds a new button to the toolbar
    Toolbar.add_button(button)Adds an existing buttton to the toolbar
    Toolbar.update(player)Updates the player's toolbar with an new buttons or expected change in auth return
    + + +

    Core

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    utils.gui
    utils.game
    new_define(prototype[, debug_name])Used to create new element defines from a class prototype, please use the own given by the class
    get_define(name[, internal])Gets an element define give the uid, debug name or a copy of the element define
    categorize_by_player(element)A categorize function to be used with add_store, each player has their own value
    categorize_by_force(element)A categorize function to be used with add_store, each force has its own value
    categorize_by_surface(element)A categorize function to be used with add_store, each surface has its own value
    draw(name, element)Draws a copy of the element define to the parent element, see draw_to
    toggle_enabled(element)Will toggle the enabled state of an element
    toggle_visible(element)Will toggle the visiblity of an element
    set_padding(element[, up=0][, down=0][, left=0][, right=0])Sets the padding for a gui element
    set_padding_style(style[, up=0][, down=0][, left=0][, right=0])Sets the padding for a gui style
    create_alignment(element[, name][, horizontal_align='right'][, vertical_align='center'])Allows the creation of an alignment flow to place elements into
    destroy_if_valid(element)Destroies an element but tests for it being present and valid first
    create_scroll_table(element, table_size, maximal_height[, name='scroll'])Creates a scroll area with a table inside, table can be any size
    create_header(element, caption[, tooltip][, right_align][, name='header'])Creates a header section with a label and button area
    + + +

    Buttons

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    mod-gui
    expcore.gui.core
    expcore.gui.prototype
    Button.new_button([name])Creates a new button element define
    Button._prototype:set_sprites(sprite[, hovered_sprite][, clicked_sprite])Adds sprites to a button making it a sprite button
    Button._prototype:set_click_filter(filter[, ...])Adds a click / mouse button filter to the button
    Button._prototype:set_key_filter(filter[, ...])Adds a control key filter to the button
    + + +

    Checkboxs

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    expcore.gui.core
    expcore.gui.prototype
    expcore.store
    utils.game
    Checkbox.new_checkbox([name])Creates a new checkbox element define
    Checkbox.new_radiobutton([name])Creates a new radiobutton element define, has all functions checkbox has
    Checkbox._prototype_radiobutton:add_as_option(option_set, option_name)Adds this radiobutton to be an option in the given option set (only one can be true at a time)
    Checkbox._prototype_radiobutton:get_store(category, internal)Gets the stored value of the radiobutton or the option set if present
    Checkbox._prototype_radiobutton:set_store(category, value, internal)Sets the stored value of the radiobutton or the option set if present
    Checkbox.new_option_set(name, callback, categorize)Registers a new option set that can be linked to radiobuttons (only one can be true at a time)
    Checkbox.draw_option_set(name, element)Draws all radiobuttons that are part of an option set at once (Gui.draw will not work)
    Checkbox.reset_radiobuttons(element[, exclude][, recursive=false])Sets all radiobutton in a element to false (unless excluded) and can act recursively
    @@ -394,16 +735,70 @@ Gui.new_concept('button') -- W - set_dropdown_value(element, value) - Selects the index of a dropdown with this value + expcore.gui.core - get_dropdown_value(element) - Gets the selected item value of a dropdown + expcore.gui.prototype - add_dropdown_items(element[, start_index], new_items) - Adds the given items into the list of items for this dropdown + utils.game + + + Dropdown.new_dropdown([name]) + Creates a new dropdown element define + + + Dropdown.new_list_box([name]) + Creates a new list box element define + + + Dropdown._prototype:new_static_options(options[, ...], the) + Adds new static options to the dropdown which will trigger the general callback + + + Dropdown._prototype:new_dynamic_options(callback) + Adds a callback which should return a table of values to be added as options for the dropdown (appended after static options) + + + Dropdown._prototype:add_option_callback(option, callback) + Adds a case specific callback which will only run when that option is selected (general case still triggered) + + + Dropdown.select_value(element, value) + Selects the option from a dropdown or list box given the value rather than key + + + Dropdown.get_selected_value(element) + Returns the currently selected value rather than index + + + + + +

    Elem Buttons

    + + + + + + + + + + + + + + + + + + + + + + +
    expcore.gui.core
    expcore.gui.prototype
    utils.game
    ElemButton.new_elem_button([name])Creates a new elem button element define
    ElemButton._prototype.set_typeSets the type of the elem button, the type is required so this must be called at least once
    ElemButton._prototype:set_default(value)Sets the default value for the elem button, this may be a function or a string
    @@ -414,248 +809,306 @@ Gui.new_concept('button') -- W - progress_bar:increment(element[, amount=1]) - Will increase the progress of a progress bar based on this concept, if the concept has an instance store then element acts as the category, if you have a combined store it will NOT update all instances + expcore.gui.core - progress_bar:decrement(element[, amount=1]) - Will decrease the progress of a progress bar based on this concept, if the concept has an instance store then element acts as the category, if you have a combined store it will NOT update all instances + expcore.gui.prototype - progress_bar:reset(element) - Resets the progress back to 0% for this element, if the concept has an instance store then element acts as the category, if you have a combined store it will NOT update all instances + utils.global - increment_progress_bar(element[, amount=0.01]) - Increment any progress bar by the given percentage + utils.game - decrement_progress_bar(element[, amount=0.01]) - Decrement any progress bar by the given percentage + ProgressBar.set_maximum(element, amount) + Sets the maximum value that represents the end value of the progress bar + + + ProgressBar.increment(element[, amount=1]) + Increases the value of the progressbar, if a define is given all of its instances have incremented + + + ProgressBar.decrement(element[, amount=1]) + Decreases the value of the progressbar, if a define is given all of its instances have decremented + + + ProgressBar.new_progressbar([name]) + Creates a new progressbar element define + + + ProgressBar._prototype:set_default_maximum(amount) + Sets the maximum value that represents the end value of the progress bar + + + ProgressBar._prototype:use_count_down([state=true]) + Will set the progress bar to start at 1 and trigger when it hits 0 + + + ProgressBar._prototype:increment([amount=1][, category]) + Increases the value of the progressbar + + + ProgressBar._prototype:increment_filtered([amount=1], filter) + Increases the value of the progressbar, if the filter condition is met, does not work with store + + + ProgressBar._prototype:decrement([amount=1][, category]) + Decreases the value of the progressbar + + + ProgressBar._prototype:decrement_filtered([amount=1], filter) + Decreases the value of the progressbar, if the filter condition is met, does not work with store + + + ProgressBar._prototype:add_element(element[, maximum]) + Adds an element into the list of instances that will are waiting to complete, does not work with store + note use store if you want persistent data, this only stores the elements not the values which they have + + + ProgressBar._prototype:reset_element(element) + Resets an element, or its store, to be back at the start, either 1 or 0 + + + ProgressBar._prototype:event_counter([filter]) + Event handler factory that counts up by 1 every time the event triggers, can filter which elements have incremented + + + ProgressBar._prototype:event_countdown([filter]) + Event handler factory that counts down by 1 every time the event triggers, can filter which elements have decremented -

    Concept Control

    +

    Sliders

    - - + - - + - - + - - + - - + + - - + + + + + + + + + +
    require_concept(concept_name)Loads a concept from the concepts fileexpcore.gui.core
    require_style(style_name)Loads a set of concepts from the styles fileexpcore.gui.prototype
    get_concept(name)Gets a gui concept from name, id, or its selfexpcore.gui.instances
    Prototype:save_as(save_name)Used to save the concept to the main gui module to allow access from other filesutils.game
    new_concept([base_concept])Returns a new gui concept, option to provide a base concept to copy properties and draw functions fromSlider.new_slider([name])Creates a new slider element define
    draw_concept(concept, parent)Used to draw a concept to a parent elementSlider._prototype:set_range([min][, max])Sets the range of a slider, if not used will use default values for a slider
    Slider._prototype:draw_label(element)Draws a new label and links its value to the value of this slider, if no store then it will only show one value per player
    Slider._prototype:enable_auto_draw_label([state=true])Enables auto draw of the label, the label will share the same parent element as the slider
    -

    Element Control

    +

    Text

    - - + - - + - - + - - + + - - + + - - + + - - + + - - + +
    get_player_from_element(element)Gets the player who owns this elementexpcore.gui.core
    valid(element)Simple check for if an element is validexpcore.gui.prototype
    destroy(element)Destroies and element if it is validutils.game
    find(element, ...)Finds and returns a gui element if it is valid from a long chain of element names or conceptsText.new_text_field([name])Creates a new text field element define
    existsChecks if a gui element exists or not, returns it if found else the path where it failedText.new_text_box([name])Creates a new text box element define
    toggle_enabled(element)Toggles the enabled state of an elementText._prototype_box:set_selectable([state=true])Sets the text box to be selectable
    toggle_visible(element)Toggles the visible state of an elementText._prototype_box:set_word_wrap([state=true])Sets the text box to have word wrap
    set_padding(element[, up=0][, down=0][, left=0][, right=0])Sets the padding for a gui elementText._prototype_box:set_read_only([state=true])Sets the text box to be read only
    -

    Store Categories

    +

    Instances

    - - + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + +
    categorize_by_player(element)A categorize function to be used with add_store, each player has their own categoryutils.global
    categorize_by_force(element)A categorize function to be used with add_store, each force has its own categoryInstances.has_categories(name)Returns if a instance group has a categorise function; must be registered
    categorize_by_surface(element)A categorize function to be used with add_store, each surface has its own categoryInstances.is_registered(name)Returns if the given name is a registered instance group
    Instances.register(name[, categorise])Registers the name of an instance group to allow for storing element instances
    Instances.add_element(name, element)Adds an element to the instance group under the correct category; must be registered
    Instances.get_elements_raw(name[, category])Gets all element instances without first removing any invalid ones; used internally and must be registered
    Instances.get_valid_elements(name[, category][, callback])Gets all valid element instances and has the option of running a callback on those that are valid
    Instances.unregistered_add_element(name, category, element)A version of add_element that does not require the group to be registered
    Instances.unregistered_get_elements(name, category[, callback])A version of get_elements that does not require the group to be registered
    -

    Concept Base

    +

    Prototype

    - - + - - + - - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Prototype:clone(concept_name)Used to copy all the settings from one concept to another and removing links to the orginalutils.game
    Prototype:define_clone(clone_callback)Use to add your own callbacks to the clone function, for example adding to a local tableexpcore.store
    Prototype:save_as(save_name)Used to save the concept to the main gui module to allow access from other filesexpcore.gui.instances
    Prototype:debug(name)Sets a debug name that can be used with error handlersConstructor.event(event_name)Creates a new function to add functions to an event handler
    Prototype:new_event(event_name[, factorio_event][, event_condition])Adds a new event trigger to the concept which can be linked to a factorio eventConstructor.extend(new_prototype)Extents a prototype with the base functions of all gui prototypes, no metatables
    Prototype:on_custom_event(handler)Adds a custom event handler, replace with the name of the eventConstructor.store(sync, callback)Creates a new function which adds a store to a gui define
    Prototype:raise_event(event_name[, event={}][, from_factorio=false])Raises a custom event, folowing keys included automaticlly: concept, event name, game tick, player from player_index, element if validConstructor.setter(value_type, key[, second_key])Creates a setter function that checks the type when a value is set
    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 controlPrototype:uid()Gets the uid for the element define
    Prototype:set_custom_property(value)Sets a new value for a property, triggers setter method if provided, replace with property namePrototype.debug_nameSets a debug alias for the define
    Prototype:define_draw(draw_callback)Used to define how the concept is turned into an ingame element or "instance" as we may refer to themPrototype.set_captionSets the caption for the element define
    Prototype:draw(parent_element[, override_name])Calls all the draw functions in order to create this concept in game; will also store and sync the instance if stores are usedPrototype.set_tooltipSets the tooltip for the element define
    Prototype.set_pre_authenticatorSets an authenticator that blocks the draw function if check fails
    Prototype.set_post_authenticatorSets an authenticator that disables the element if check fails
    Prototype.on_drawRegisters a callback to the on_draw event
    Prototype.on_style_updateRegisters a callback to the on_style_update event
    Prototype:set_style(style[, callback])Sets the style for the element define
    Prototype:set_embedded_flow(state)Sets the element to be drawn inside a nameless flow, can be given a name using a function
    Prototype:raise_event(event_name, ...)Raises a custom event for this define, any number of params can be given
    Prototype:draw_to(element)The main function for defines, when called will draw an instance of this define to the given element + what is drawn is based on the data in draw_data which is set using other functions
    Prototype:get_store(category)Gets the value in this elements store, category needed if categorize function used
    Prototype:set_store(category, value)Sets the value in this elements store, category needed if categorize function used
    Prototype:clear_store([category])Sets the value in this elements store to nil, category needed if categorize function used
    -

    Concept Instances

    +

    Test

    - - + - - + - - + - - - - -
    Prototype:define_instance_store([category_callback])Adds an instance store to the concept; when a new instance is made it is stored so you can access it laterexpcore.gui
    Prototype.get_instances([category])Gets all insatnces in a category, category may be nil to return allexpcore.common
    Prototype.add_instance(element[, category])Adds an instance to this concept, used automatically during concept:drawresources.color_presets
    Prototype.update_instances([category], update_callback)Applies an update function to all instances, simialr use to what table.forEach would be
    - - -

    Concept Data

    - - - - - - + - - - - - - - - - - - - - - - - -
    Prototype:define_data_store([category_callback])Adds a data store to this concept which allows you to store synced/percistent data between instancesutils.event
    Prototype.get_data([category])Gets the data that is stored for this category
    Prototype.set_data([category], value)Sets the data that is stored for this category
    Prototype.clear_data([category])Clears the data that is stored for this category
    Prototype.update_data([category], update_callback)Updates the data that is stored for this category
    - - -

    Concept Combined Instances

    - - - - - - - - - - - - -
    Prototype:define_combined_store([category_callback], sync_callback)Used to add a both instance and data store which are linked together, new instances are synced to the current value, changing the stored value will change all instances
    Prototype.sync_instance(element)Will sync an instance to match the stored value based on the given sync callback
    - - -

    Tests

    - - - - - - +
    run_tests(player[, category])Runs a set of gui tests to ensure that the system is workingexpcore.store
    @@ -664,122 +1117,20 @@ Gui.new_concept('button') -- W
    -

    Elements

    +

    Dependencies

    - # - button + # + expcore.gui.core
    -

    Clickable elements that fire on_gui_click when clicked.

    -

    - Properties / Events: - -
      - - - - - -
    • - - on_click - - : - - - fired when the player clicks the button - -
    • - - - - - -
    • - - on_left_click - - : - - - fired when the player clicks with the right mouse button - -
    • - - - - - -
    • - - on_left_click - - : - - - fired when the player clicks with the right mouse button - -
    • - - - - - -
    • - - caption - - : - - (string or LocalisedString) - - the message that is shown on the button - -
    • - - - - - -
    • - - tooltip - - : - - (string or LocalisedString) - - the tooltip that shows when a player hovers over the button - -
    • - - - - - -
    • - - sprite - - : - - (SpritePath) - - upto three sprites in the order: default, hovered, clicked - -
    • - - -
    - @@ -790,126 +1141,21 @@ Gui.new_concept('button') -- W - Usage: -
    -- Making a basic button
    -local 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)
    -
    -- Making a sprite button
    -local 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)
    - # - checkbox + # + expcore.gui.instances
    -

    Clickable elements with a cross in the middle that can be turned off or on.

    -

    - Properties / Events: - -
      - - - - - -
    • - - on_state_changed - - : - - - fired when the state of the element is changed - -
    • - - - - - -
    • - - caption - - : - - (string or LocalisedString) - - the message that is shown next to the checkbox - -
    • - - - - - -
    • - - tooltip - - : - - (string or LocalisedString) - - the tooltip that shows when a player hovers over the checkbox - -
    • - - - - - -
    • - - default - - : - - (boolean or function) - - the default state of this checkbox, or a function which returns the default state - -
    • - - - - - -
    • - - use_radio - - : - - (boolean) - - setting to true will use radio buttons rather than checkboxs - -
    • - - -
    - @@ -920,118 +1166,21 @@ Gui.new_concept('button') - Usage: -
    -- Making a basic checkbox
    -local 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)
    - # - dropdown + # + expcore.gui.elements.buttons
    -

    A drop down list of other elements.

    -

    - Properties / Events: - -
      - - - - - -
    • - - on_selection_changed - - : - - - fired when the selected value is changed - -
    • - - - - - -
    • - - default - - : - - (string, LocalisedString or function) - - the option which is selected by default, or a function which returns the default - -
    • - - - - - -
    • - - use_list_box - - : - - (boolean) - - when true a list box will be used rather than a dropdown menu - -
    • - - - - - -
    • - - static_items - - : - - (nil or table) - - when called with a table the values will be added as items for the dropdown, if called with nil then all items are cleared - -
    • - - - - - -
    • - - dynamic_items - - : - - (function) - - 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 - -
    • - - -
    - @@ -1042,100 +1191,21 @@ Gui.new_concept('checkbox') - Usage: -
    -- Making a basic dropdown
    -local 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)
    -
    -- Making a dropdown with dynamic items, example is name of online players
    -local dynamic_dropdown =
    -Gui.new_concept('dropdown')
    -:set_dynamic_items(function(element)
    -    local items = {}
    -    for _,player in pairs(game.connected_players) do
    -        items[#items+1] = player.name
    -    end
    -    return items
    -end)
    -:on_selection_changed(function(event)
    -    local value = Gui.get_dropdown_value(event.element)
    -    event.player.print('Dynamic dropdown is now: '..value)
    -end)
    - # - elem_button + # + expcore.gui.elements.checkbox
    -

    A button that lets the player pick one of an: item, entity, tile, or signal similar to the filter-select window.

    -

    - Properties / Events: - -
      - - - - - -
    • - - on_selection_changed - - : - - - fired when the selected value is changed - -
    • - - - - - -
    • - - default - - : - - (string, SignalID or function) - - the option which is selected by default, or a function which returns the default - -
    • - - - - - -
    • - - elem_type - - : - - (string) - - the type of elem selection that this is, default is item selection - -
    • - - -
    - @@ -1146,53 +1216,21 @@ Gui.new_concept('dropdown') - Usage: -
    -- Making a basic elem button
    -local basic_elem_button =
    -Gui.new_concept('elem_button')
    -:on_selection_changed(function(event)
    -    event.player.print('Basic elem button is now: '..event.element.elem_value)
    -end)
    - # - empty + # + expcore.gui.elements.dropdown
    -

    A empty widget that just exists.

    -

    The root GUI element screen is an empty-widget.

    - Properties / Events: - -
      - - - - - -
    • - - style - - : - - (string) - - the style that the element will have - -
    • - - -
    - @@ -1203,51 +1241,21 @@ Gui.new_concept('elem_button') - Usage: -
    -- Making a draggable space styled widget
    -local draggable_space =
    -Gui.new_concept('empty')
    -:set_style('draggable_space')
    - # - flow + # + expcore.gui.elements.slider
    -

    Invisible containers that lay out children either horizontally or vertically.

    -

    The root GUI elements (top, left and center; see LuaGui) are flows.

    - Properties / Events: - -
      - - - - - -
    • - - direction - - : - - (string) - - the direction that children will be added - -
    • - - -
    - @@ -1258,72 +1266,21 @@ Gui.new_concept('empty') - Usage: -
    -- Making a basic flow, contains a label with hello world
    -local basic_flow =
    -Gui.new_concept('flow')
    -:define_draw(function(properties,parent,element)
    -    element.add{
    -        type = 'label',
    -        caption = 'Hello, World!'
    -    }
    -end)
    - # - frame + # + expcore.gui.elements.text
    -

    Grey semi-transparent boxes that contain other elements.

    -

    They have a caption, and, just like flows, they lay out children either horizontally or vertically.

    - Properties / Events: - -
      - - - - - -
    • - - title - - : - - (string or LocalisedString) - - the title that will show in the frame - -
    • - - - - - -
    • - - direction - - : - - (string) - - the direction that children will be added - -
    • - - -
    - @@ -1334,89 +1291,21 @@ Gui.new_concept('flow') - Usage: -
    -- Making a basic frame, contains a label with hello world
    -local basic_frame =
    -Gui.new_concept('frame')
    -:set_title('Basic Frame')
    -:define_draw(function(properties,parent,element)
    -    element.add{
    -        type = 'label',
    -        caption = 'Hello, World!'
    -    }
    -end)
    - # - label + # + expcore.gui.elements.elem-button
    -

    A piece of text.

    -

    - Properties / Events: - -
      - - - - - -
    • - - caption - - : - - (string or LocalisedString) - - the caption that will show in the label - -
    • - - - - - -
    • - - description - - : - - (string or LocalisedString) - - the description that will show on the label - -
    • - - - - - -
    • - - rich_text - - : - - (defines.rich_text_setting) - - how this element handles rich text - -
    • - - -
    - @@ -1427,51 +1316,21 @@ Gui.new_concept('frame') - Usage: -
    -- Making a basic label
    -local basic_label =
    -Gui.new_concept('label')
    -:set_caption('Hello, World!')
    - # - line + # + expcore.gui.elements.progress-bar
    -

    A vertical or horizontal line.

    -

    - Properties / Events: - -
      - - - - - -
    • - - direction - - : - - (string) - - the direction that children will be added - -
    • - - -
    - @@ -1482,113 +1341,21 @@ Gui.new_concept('label') - Usage: -
    -- Making a basic frame, contains a label with hello world
    -local basic_line =
    -Gui.new_concept('line')
    - # - progress_bar + # + expcore.gui.concepts.toolbar
    -

    Indicate progress by displaying a partially filled bar.

    -

    - Properties / Events: - -
      - - - - - -
    • - - on_completion - - : - - - fired when increment reaches the maxium value set by set_maximum - -
    • - - - - - -
    • - - tooltip - - : - - (string or LocalisedString) - - the tooltip that will show for this element - -
    • - - - - - -
    • - - maximum - - : - - (number) - - the maxium amount an instance can be increased, default 100 - -
    • - - - - - -
    • - - delay_completion - - : - - (boolean) - - when true the progress will be completed untill after the maximum rather than at the maximum - -
    • - - - - - -
    • - - inverted - - : - - (boolean) - - 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 - -
    • - - -
    - @@ -1599,76 +1366,21 @@ Gui.new_concept('line') - Usage: -
    -- Making a basic progress bar, will increase when pressed then will reset when full
    -local 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)
    -:on_click(function(event)
    -    event.concept:increment(event.element)
    -end)
    -:set_delay_completion(true)
    -:on_completion(function(event)
    -    event.concept:reset(event.element)
    -end)
    - # - scroll + # + expcore.gui.concepts.left
    -

    Similar to a flow but includes the ability to show and use scroll bars.

    -

    - Properties / Events: - -
      - - - - - -
    • - - horizontal_scroll - - : - - (string) - - the horizontal scroll policy for this scroll pane - -
    • - - - - - -
    • - - vertical_scroll - - : - - (string) - - the vertical scroll policy for this scroll pane - -
    • - - -
    - @@ -1679,122 +1391,21 @@ Gui.new_concept('progress_bar') - Usage: -
    -- Making a basic flow, contains a label with hello world
    -local basic_scroll =
    -Gui.new_concept('scroll')
    -:define_draw(function(properties,parent,element)
    -    element.style.hieght = 50
    -    for i = 1,10 do
    -        element.add{
    -            type = 'label',
    -            caption = i
    -        }
    -    end
    -end)
    - # - slider + # + expcore.gui.concepts.center
    -

    A number picker.

    -

    - Properties / Events: - -
      - - - - - -
    • - - on_value_changed - - : - - - fired when the value of the slider is changed - -
    • - - - - - -
    • - - value_step - - : - - (number) - - the minimum amount by which the value of the slider can be changed - -
    • - - - - - -
    • - - default - - : - - (number or function) - - the default value of the slider or a function which returns the default value - -
    • - - - - - -
    • - - discrete_slider - - : - - (boolean) - - makes this slider a discrete slider, this means that the slider button will stop at the same interval as the values do - -
    • - - - - - -
    • - - range - - : - - (number or function) - - accepts two params the minimum and the maximum for this slider, or a single function to return both - -
    • - - -
    - @@ -1805,127 +1416,21 @@ Gui.new_concept('scroll') - Usage: -
    -- Making a basic slider
    -local 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.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)
    - # - table + # + expcore.gui.concepts.popups
    -

    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.

    - Properties / Events: - -
      - - - - - -
    • - - column_count - - : - - (number or function) - - the column count of the table or a function that returns the count being given then parent element - -
    • - - - - - -
    • - - vertical_lines - - : - - (boolean) - - when true vertical lines will be drawn on the table - -
    • - - - - - -
    • - - horizontal_lines - - : - - (boolean) - - when true horizontal lines will be drawn on the table - -
    • - - - - - -
    • - - header_lines - - : - - (boolean) - - when true horizontal lines will be drawn under the first row - -
    • - - - - - -
    • - - vertical_centering - - : - - (boolean) - - when true element will be vertically centered with in the table - -
    • - - -
    - @@ -1936,440 +1441,123 @@ Gui.new_concept('slider') - Usage: -
    -- Making a basic table, contains 25 labels
    -local basic_table =
    -Gui.new_concept('table')
    -:set_column_count(5)
    -:define_draw(function(properties,parent,element)
    -    for i = 1,25 do
    -        element.add{
    -            type = 'lable',
    -            caption = i
    -        }
    -    end
    -end)
    - - -
    -
    -
    -
    - # - text_box -
    -
    -
    -
    - -

    A multi-line text box that supports selection and copy-paste.

    -

    - - - Properties / Events: - -
      - - - - - -
    • - - on_text_changed - - : - - - fired when the text within the text box is changed - -
    • - - - - - -
    • - - tooltip - - : - - (string or LocalisedString) - - the tooltip that shows when a player hovers over the text box - -
    • - - - - - -
    • - - default - - : - - (string or function) - - the default text that will appear in the text box, or a function that returns it - -
    • - - - - - -
    • - - rich_text - - : - - (defines.rich_text_setting) - - how this element handles rich text - -
    • - - - - - -
    • - - clear_on_rmb - - : - - (boolean) - - if the text box will be cleared and forcused on a right click - -
    • - - - - - -
    • - - is_selectable - - : - - (boolean) - - when true the text inside the box can be selected - -
    • - - - - - -
    • - - has_word_wrap - - : - - (boolean) - - when true the text will wrap onto the next line if it reachs the end - -
    • - - - - - -
    • - - is_read_only - - : - - (boolean) - - when true the text inside the box can not be edited by the player - -
    • - - -
    - - - - - - - - - - - - Usage: -
    -- Making a text box
    -local 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.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)
    - - -
    -
    -
    -
    - # - text_field -
    -
    -
    -
    - -

    Boxes of text the user can type in.

    -

    - - - Properties / Events: - -
      - - - - - -
    • - - on_text_changed - - : - - - fired when the text within the text field is changed - -
    • - - - - - -
    • - - on_confirmation - - : - - - fired when the player presses enter with the text field forcused - -
    • - - - - - -
    • - - tooltip - - : - - (string or LocalisedString) - - the tooltip that shows when a player hovers over the text field - -
    • - - - - - -
    • - - default - - : - - (string or function) - - the default text that will appear in the text field, or a function that returns it - -
    • - - - - - -
    • - - rich_text - - : - - (defines.rich_text_setting) - - how this element handles rich text - -
    • - - - - - -
    • - - clear_on_rmb - - : - - (boolean) - - if the text field will be cleared and forcused on a right click - -
    • - - - - - -
    • - - lose_forcus - - : - - (boolean) - - if the text field will lose forcus after the confirmation event - -
    • - - - - - -
    • - - is_number - - : - - (boolean) - - if this text field contains a number value, can be ignored if is_decimal or is_negitive is used - -
    • - - - - - -
    • - - is_decimal - - : - - (boolean) - - if this text field contains a decimal value - -
    • - - - - - -
    • - - is_negative - - : - - (boolean) - - if this text field contains a negative value - -
    • - - - - - -
    • - - is_password - - : - - (boolean) - - if this text field contains a password value - -
    • - - -
    - - - - - - - - - - - - Usage: -
    -- Making a text field
    -local 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.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)
    -
    -- Making a decimal input
    -local 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)
    -

    Dropdowns

    +

    Center Guis

    - # - set_dropdown_value(element, value) + # + expcore.gui.core
    -

    Selects the index of a dropdown with this value

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.gui.prototype +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.gui.concepts.toolbar +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + utils.game +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + CenterFrames.get_flow(player) +
    +
    +
    +
    + +

    Gets the center flow for a player

    @@ -2383,29 +1571,13 @@ Gui.new_concept('text_field')
  • - element + player : - (LuaGuiElement) + (LuaPlayer) - the dropdown that you want to set the selection for - -
  • - - - - - -
  • - - value - - : - - (string or LocalisedString) - - the value that you want selected + the player to get the flow for
  • @@ -2418,147 +1590,337 @@ Gui.new_concept('text_field') Returns: + + + + + + + + + +
    +
    +
    +
    + # + CenterFrames.clear_flow(player) +
    +
    +
    +
    + +

    Clears the center flow for a player

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player to clear the flow for + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + CenterFrames.draw_frame(player, name) +
    +
    +
    +
    + +

    Draws the center frame for a player, if already open then will do nothing

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player that will have the frame drawn + +
    • + + + + + +
    • + + name + + : + + (string) + + the name of the hui that will drawn + +
    • + + +
    + + + + + Returns: + + + + + + + + + + +
    +
    +
    +
    + # + CenterFrames.redraw_frame(player, name) +
    +
    +
    +
    + +

    Draws the center frame for a player, if already open then will destroy it and redraw

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player that will have the frame drawn + +
    • + + + + + +
    • + + name + + : + + (string) + + the name of the hui that will drawn + +
    • + + +
    + + + + + Returns: + + + + + + + + + + +
    +
    +
    +
    + # + CenterFrames.toggle_frame(player, name[, state]) +
    +
    +
    +
    + +

    Toggles if the frame is currently open or not, will open if closed and close if open

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player that will have the frame toggled + +
    • + + + + + +
    • + + name + + : + + (string) + + the name of the hui that will be toggled + +
    • + + + + + +
    • + + state + + : + (boolean) - if an item with this value was found -
    • -
    - - - - - - - Usage: -
    -- Selecting the item with the value 'foo'
    -Gui.set_dropdown_value(element,'foo')
    - - -
    -
    -
    -
    - # - get_dropdown_value(element) -
    -
    -
    -
    - -

    Gets the selected item value of a dropdown

    -

    - - - Parameters: - -
      - - - - - -
    • - - element - - : - - (LuaGuiElement) - - the dropdown that you want the selected value of - -
    • - - -
    - - - - - Returns: - - - - - - - - - Usage: -
    -- Getting the selected value
    -local selected_value = Gui.get_dropdown_value(element)
    - - -
    -
    -
    -
    - # - add_dropdown_items(element[, start_index], new_items) -
    -
    -
    -
    - -

    Adds the given items into the list of items for this dropdown

    -

    - - - Parameters: - -
      - - - - - -
    • - - element - - : - - (LuaGuiElement) - - the dropdown that you want to add the items to - -
    • - - - - - -
    • - - start_index - - : - - (number) - - the index at which the items will be added, if not given appened to the end + when set will force a state for the frame (optional)
    • +
    + + + + + Returns: +
      +
    • + (boolean) + if the frame if no open or closed +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + CenterFrames.new_frame(permission_name) +
    +
    +
    +
    + +

    Creates a new center frame define

    +

    + + + Parameters: + +
      + +
    • - new_items + permission_name : - (table) + (string) - the list of new items that you want to add + the name that can be used with the permission system
    • @@ -2572,7 +1934,7 @@ Gui.new_concept('text_field')
      • (table) - the list of items that the element now has + the new center frame define
      @@ -2582,28 +1944,20 @@ Gui.new_concept('text_field') - Usage: -
      -- Add the items 'foo' and 'bar' to the end
      -Gui.add_dropdown_items(element,{'foo','bar'})
      -
      -- Add the items 'foo' and 'bar' to the start
      -Gui.add_dropdown_items(element,1,{'foo','bar'})
    -
    -

    Progress Bars

    -
    - # - progress_bar:increment(element[, amount=1]) + # + CenterFrames._prototype:set_auto_focus([state=true])
    -

    Will increase the progress of a progress bar based on this concept, if the concept has an instance store then element acts as the category, if you have a combined store it will NOT update all instances

    +

    Sets the frame to be the current active gui when opened and closes all other frames

    @@ -2617,31 +1971,15 @@ Gui.new_concept('text_field')
  • - element + state : - (LuaGuiElement or string) + (boolean) - either the element that is changed or the category that is being changed (only if an instance store is defined) + when true will auto close other frames and set this frame as player.opened -
  • - - - - - -
  • - - amount - - : - - (number) - - the amount that will bar will increase, note that this amount must be less than the max - - (default: 1) + (default: true)
  • @@ -2650,13 +1988,6 @@ Gui.new_concept('text_field') - Returns: -
      -
    • - (number or nil) - the new value of the element, use this to sync a data store, if the return is nil then either a instance store was used or the new value may have changed -
    • -
    @@ -2664,25 +1995,20 @@ Gui.new_concept('text_field') - Usage: -
    -- Incrementing progress bar with no instance store
    -local new_value = progress_bar:increment(element)
    -
    -- Incrementing progress bar with an instance store
    -progress_bar:increment(category)
    - # - progress_bar:decrement(element[, amount=1]) + # + CenterFrames._prototype:draw_frame(player)
    -

    Will decrease the progress of a progress bar based on this concept, if the concept has an instance store then element acts as the category, if you have a combined store it will NOT update all instances

    +

    Draws this frame to the player, if already open does nothing (will call on_draw to draw to the frame)

    @@ -2696,92 +2022,13 @@ Gui.new_concept('text_field')
  • - element + player : - (LuaGuiElement or string) + (LuaPlayer) - either the element that is changed or the category that is being changed (only if an instance store is defined) - -
  • - - - - - -
  • - - amount - - : - - (number) - - the amount that will bar will decrease, note that this amount must be less than the max - - (default: 1) -
  • - - - - - - - - Returns: -
      -
    • - (number) - the new value of the element, use this to sync a data store, if the return is nil then either a instance store was used or the new value may have changed -
    • -
    - - - - - - - - Usage: -
    -- Decrementing progress bar with no instance store
    -local new_value = progress_bar:decrement(element)
    -
    -- Decrementing progress bar with an instance store
    -progress_bar:decrement(category)
    - - -
    -
    -
    -
    - # - progress_bar:reset(element) -
    -
    -
    -
    - -

    Resets the progress back to 0% for this element, if the concept has an instance store then element acts as the category, if you have a combined store it will NOT update all instances

    -

    - - - Parameters: - -
      - - - - - -
    • - - element - - : - - (LuaGuiElement or string) - - either the element that is changed or the category that is being changed (only if an instance store is defined) + the player to draw the frame for
    • @@ -2794,58 +2041,37 @@ Gui.new_concept('text_field') Returns:
      • - (number or nil) - the new value of the element, use this to sync a data store, if the return is nil then either a instance store was used or the new value may have changed -
      • -
      - - - - - - - - Usage: -
      -- Reseting a progress bar with no instance store
      -local new_value = progress_bar:reset(element)
      -
      -- Reseting a progress bar with an instance store
      -progress_bar:reset(category)
      - - -
    -
    -
    -
    - # - increment_progress_bar(element[, amount=0.01]) -
    -
    -
    -
    - -

    Increment any progress bar by the given percentage

    -

    - - - Parameters: - -
      - - - - - -
    • - - element - - : - (LuaGuiElement) - - the progress bar that you want to update - + the new frame that was drawn
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + CenterFrames._prototype:redraw_frame(player) +
    +
    +
    +
    + +

    Draws this frame to the player, if already open it will remove it and redraw it (will call on_draw to draw to the frame)

    +

    + + + Parameters: + +
      @@ -2853,15 +2079,71 @@ Gui.new_concept('text_field')
    • - amount + player : - (number) + (LuaPlayer) - the percentage that you want to increment the progress bar by + the player to draw the frame for + +
    • + + +
    + + + + + Returns: + + + + + + + + + + +
    +
    +
    +
    + # + CenterFrames._prototype:toggle_frame(player) +
    +
    +
    +
    + +

    Toggles if the frame is open, if open it will close it and if closed it will open it

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player to draw the frame for - (default: 0.01)
    • @@ -2874,7 +2156,7 @@ Gui.new_concept('text_field')
      • (boolean) - true if the bar is now full + with the gui frame is now open
      @@ -2884,23 +2166,20 @@ Gui.new_concept('text_field') - Usage: -
      -- Increment any progress bar by 10%
      -Gui.increment_progress_bar(element,0.1)
    - # - decrement_progress_bar(element[, amount=0.01]) + # + CenterFrames._prototype:event_handler([action=update])
    -

    Decrement any progress bar by the given percentage

    +

    Creates an event handler that will trigger one of its functions, use with Event.add

    @@ -2914,31 +2193,243 @@ Gui.new_concept('text_field')
  • - element + action : - (LuaGuiElement) + (string) - the progress bar that you want to update + the action to take on this event + (default: update)
  • + + + + + + + + + + + + + + +
    +
    +

    Left Guis

    +
    +
    +
    +
    + # + expcore.gui.core +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.gui.prototype +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.gui.concepts.toolbar +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.gui.elements.buttons +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + mod-gui +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + utils.game +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + utils.event +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + LeftFrames.get_flow(player) +
    +
    +
    +
    + +

    Gets the left frame flow for a player

    +

    + + + Parameters: + +
      + +
    • - amount + player : - (number) + (LuaPlayer) - the percentage that you want to decrement the progress bar by + the player to get the flow of - (default: 0.01)
    • @@ -2950,8 +2441,8 @@ Gui.new_concept('text_field') Returns: @@ -2961,132 +2452,20 @@ Gui.new_concept('text_field') - Usage: -
      -- Decrement any progress bar by 10%
      -Gui.decrement_progress_bar(element,0.1)
      - - -
    -
    -

    Concept Control

    -
    -
    -
    -
    - # - require_concept(concept_name) -
    -
    -
    -
    - -

    Loads a concept from the concepts file

    -

    - - - Parameters: - -
      - - - - - -
    • - - concept_name - - : - - (string) - - the name of the concept to require - -
    • - - -
    - - - - - - - - - - - - Usage: -
    -- Load a base concept
    -Gui.require_concept('frame') --- @dep Gui.concept.frame
    - # - require_style(style_name) + # + LeftFrames.get_frame(name, player)
    -

    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
    - - -
    -
    -
    -
    - # - get_concept(name) -
    -
    -
    -
    - -

    Gets a gui concept from name, id, or its self

    +

    Gets one frame from the left flow by its name

    @@ -3104,9 +2483,25 @@ Gui.new_concept('text_field') : - (string, number or table) + (string) - the name, id, or the concept you want to get + the name of the gui frame to get + + + + + + + +
  • + + player + + : + + (LuaPlayer) + + the player to get the frame of
  • @@ -3116,6 +2511,13 @@ Gui.new_concept('text_field') + Returns: +
      +
    • + (LuaGuiElement) + the frame in the left frame flow with that name +
    • +
    @@ -3123,23 +2525,20 @@ Gui.new_concept('text_field') - Usage: -
    -- Getting a gui concept
    -local button = Gui.get_concept('Button')
    - # - Prototype:save_as(save_name) + # + LeftFrames.get_open(player)
    -

    Used to save the concept to the main gui module to allow access from other files

    +

    Gets all open frames for a player, if non are open it will remove the close all button

    @@ -3153,69 +2552,102 @@ Gui.new_concept('text_field')
  • - save_name + player + + : + + (LuaPlayer) + + the player to get the flow of + +
  • + + + + + + + + Returns: +
      +
    • + (table) + contains all the open (and registered) frames for the player +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + LeftFrames.toggle_frame(name, player[, state]) +
    +
    +
    +
    + +

    Toggles the visibility of a left frame, or sets its visibility state

    +

    + + + Parameters: + +
      + + + + + +
    • + + name : (string) - the new name of the concept + the name of the gui frame to toggle
    • -
    - - - - - - - - - - - - Usage: -
    -- 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')
    - - -
    -
    -
    -
    - # - new_concept([base_concept]) -
    -
    -
    -
    - -

    Returns a new gui concept, option to provide a base concept to copy properties and draw functions from

    -

    - - - Parameters: - -
      - -
    • - base_concept + player : - (string, number or table) + (LuaPlayer) - the concept that you want to copy the details of + the player to get the frame of + +
    • + + + + + +
    • + + state + + : + + (boolean) + + when given will be the state that the visibility is set to (optional)
    • @@ -3226,6 +2658,13 @@ Gui.get_concept('button') + Returns: +
        +
      • + (boolean) + the new state of the visibility +
      • +
      @@ -3233,23 +2672,20 @@ Gui.get_concept('button') - Usage: -
      -- Making a new button, see module usage
      -local button = Gui.new_concept('Button')
    - # - draw_concept(concept, parent) + # + LeftFrames.new_frame(permission_name)
    -

    Used to draw a concept to a parent element

    +

    Creates a new left frame define

    @@ -3263,29 +2699,174 @@ Gui.get_concept('button')
  • - concept + permission_name : - (string, number or table) + (string) - the name of the concept that you want to draw + the name that can be used with the permission system
  • + + + + + + Returns: +
      +
    • + (table) + the new left frame define +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + LeftFrames._prototype:set_open_by_default([state=true]) +
    +
    +
    +
    + +

    Sets if the frame is visible when a player joins, can also be a function to return a boolean

    +

    + + + Parameters: + +
      + +
    • - parent + state : - (LuaGuiElement) + (boolean or function) - the element that will act as a parent for the new element + the default state of the visibility, can be a function + state param - player LuaPlayer - the player that has joined the game + state param - define_name string - the define name for the frame + state return - boolean - false will hide the frame + + (default: true) +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + LeftFrames._prototype:set_direction(direction) +
    +
    +
    +
    + +

    Sets the direction of the frame, either vertical or horizontal

    +

    + + + Parameters: + +
      + + + + + +
    • + + direction + + : + + (string) + + the direction to have the elements be added to the frame + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + LeftFrames._prototype:_internal_draw(player) +
    +
    +
    +
    + +

    Creates the gui for the first time, used internally

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player to draw the frame to
    • @@ -3299,7 +2880,7 @@ Gui.get_concept('button')
      • (LuaGuiElement) - the element that was created + the frame that was made
      @@ -3309,26 +2890,672 @@ Gui.get_concept('button') - Usage: -
      -- Drawing a new element
      -Gui.draw_concept('Button',element)
      + + +
    +
    +
    +
    + # + LeftFrames._prototype:get_frame(player) +
    +
    +
    +
    + +

    Gets the frame for this define from the left frame flow

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player to get the frame of + +
    • + + +
    + + + + + Returns: +
      +
    • + (LuaGuiElement) + the frame in the left frame flow for this define +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + LeftFrames._prototype:is_open(player) +
    +
    +
    +
    + +

    Returns if the player currently has this define visible

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player to get the frame of + +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + true if it is open/visible +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + LeftFrames._prototype:toggle(player) +
    +
    +
    +
    + +

    Toggles the visibility of the left frame

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player to toggle the frame of + +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + the new state of the visibility +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + LeftFrames._prototype:update(player) +
    +
    +
    +
    + +

    Updates the contents of the left frame, first tries update callback, other wise will clear and redraw

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player to update the frame of + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + LeftFrames._prototype:update_all([update_offline=false]) +
    +
    +
    +
    + +

    Updates the frame for all players, see update

    +

    + + + Parameters: + +
      + + + + + +
    • + + update_offline + + : + + (boolean) + + when true will update the frame for offline players + + (default: false) +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + LeftFrames._prototype:redraw(player) +
    +
    +
    +
    + +

    Redraws the frame by calling on_draw, will always clear the frame

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player to update the frame of + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + LeftFrames._prototype:redraw_all([update_offline=false]) +
    +
    +
    +
    + +

    Redraws the frame for all players, see redraw

    +

    + + + Parameters: + +
      + + + + + +
    • + + update_offline + + : + + (boolean) + + when true will update the frame for offline players + + (default: false) +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + LeftFrames._prototype:event_handler([action=update]) +
    +
    +
    +
    + +

    Creates an event handler that will trigger one of its functions, use with Event.add

    +

    + + + Parameters: + +
      + + + + + +
    • + + action + + : + + (string) + + the action to take on this event + + (default: update) +
    • + + +
    + + + + + + + + + + +
    -

    Element Control

    +

    Popups

    - # - get_player_from_element(element) + # + expcore.gui.core
    -

    Gets the player who owns this element

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.gui.prototype +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + utils.game +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + utils.event +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.gui.elements.progress-bar +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.gui.elements.buttons +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + mod-gui +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + resources.color_presets +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + utils.global +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + PopupFrames.get_flow(player) +
    +
    +
    +
    + +

    Gets the left flow that contains the popup frames

    @@ -3342,73 +3569,13 @@ Gui.get_concept('button')
  • - element + player : - (LuaGuiElement) - - the element that you want to get the player of - -
  • - - - - - - - - Returns: -
      -
    • (LuaPlayer) - the player who owns this element -
    • -
    - - - - - - - Usage: -
    -- Getting the player of an element
    -local player = Gui.get_player_from_element(element)
    - - -
    -
    -
    -
    - # - valid(element) -
    -
    -
    -
    - -

    Simple check for if an element is valid

    -

    - - - Parameters: - -
      - - - - - -
    • - - element - - : - - (LuaGuiElement) - - the element that you want to check is valid + the player to get the flow for
    • @@ -3421,8 +3588,8 @@ Gui.get_concept('button') Returns:
      • - (boolean) - true if the element is valid + (LuaGuiElement) + the left flow that contains the popup frames
      @@ -3432,23 +3599,20 @@ Gui.get_concept('button') - Usage: -
      -- Return if not valid
      -if not Gui.valid(element) then return end
    - # - destroy(element) + # + PopupFrames.open(define_name, player[, open_time], ...)
    -

    Destroies and element if it is valid

    +

    Opens a popup for the player, can give the amount of time it is open as well as params for the draw function

    @@ -3462,73 +3626,29 @@ Gui.get_concept('button')
  • - element + define_name : - (LuaGuiElement) + (string) - the element that you want to destroy + the name of the define that you want to open for the player
  • - - - - - - Returns: -
      -
    • - (boolean) - true if the element was valid and was destoried -
    • -
    - - - - - - - - Usage: -
    -- Destoring an element
    -Gui.destroy(element)
    - - -
    -
    -
    -
    - # - find(element, ...) -
    -
    -
    -
    - -

    Finds and returns a gui element if it is valid from a long chain of element names or concepts

    -

    - - - Parameters: - -
      - -
    • - element + player : - (LuaGuiElement) + (LuaPlayer) - the root element to start checking from + the player to open the popup for
    • @@ -3536,15 +3656,32 @@ Gui.get_concept('button') +
    • + + open_time + + : + + (number) + + the minimum number of ticks you want the popup open for, 0 means no limit, nil will take default + + (optional) +
    • + + + + +
    • ... : - (string or table) + (any) - element names or element concepts that point to your element + the other params that you want to pass to your on_draw event
    • @@ -3557,23 +3694,836 @@ Gui.get_concept('button') Returns:
      • - (boolean) - if the element was found, failed + (LuaGuiElement) + the frame that was drawn, the inner gui flow which contains the content
      • +
      + + + + + + + + + +
    +
    +
    +
    + # + PopupFrames.close_progress +
    +
    +
    +
    + +

    Progress bar which when depleted will close the popup frame

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + PopupFrames.close_button +
    +
    +
    +
    + +

    A button which can be used to close the gui before the timer runs out

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + PopupFrames.new_popup([name]) +
    +
    +
    +
    + +

    Creates a new popup frame define

    +

    + + + Parameters: + +
      + + + + + +
    • + + name + + : + + (string) + + the optional debug name that can be added + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the new popup frame define +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + PopupFrames._prototype:set_default_open_time(amount) +
    +
    +
    +
    + +

    Sets the default open time for the popup, will be used if non is provided with open

    +

    + + + Parameters: + +
      + + + + + +
    • + + amount + + : + + (number) + + the number of ticks, by default, the popup will be open for + +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the define to allow for chaining +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + PopupFrames._prototype:open(player[, open_time], ...) +
    +
    +
    +
    + +

    Opens this define for a player, can be given open time and any other params for the draw function

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player to open the popup for + +
    • + + + + + +
    • + + open_time + + : + + (number) + + the minimum number of ticks you want the popup open for, 0 means no limit, nil will take default + + (optional) +
    • + + + + + +
    • + + ... + + : + + (any) + + the other params that you want to pass to your on_draw event + +
    • + + +
    + + + + + Returns: +
      +
    • + (LuaGuiElement) + the frame that was drawn, the inner gui flow which contains the content +
    • +
    + + + + + + + + + +
    +
    +

    Toolbar

    +
    +
    +
    +
    + # + expcore.gui.core +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.gui.elements.buttons +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.roles +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + utils.event +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + utils.game +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + mod-gui +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + Toolbar.new_button([name]) +
    +
    +
    +
    + +

    Adds a new button to the toolbar

    +

    + + + Parameters: + +
      + + + + + +
    • + + name + + : + + (string) + + when given allows an alias to the button for the permission system + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the button define +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + Toolbar.add_button(button) +
    +
    +
    +
    + +

    Adds an existing buttton to the toolbar

    +

    + + + Parameters: + +
      + + + + + +
    • + + button + + : + + (table) + + the button define for the button to be added + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + Toolbar.update(player) +
    +
    +
    +
    + +

    Updates the player's toolbar with an new buttons or expected change in auth return

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player to update the toolbar for + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +

    Core

    +
    +
    +
    +
    + # + utils.gui +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + utils.game +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + new_define(prototype[, debug_name]) +
    +
    +
    +
    + +

    Used to create new element defines from a class prototype, please use the own given by the class

    +

    + + + Parameters: + +
      + + + + + +
    • + + prototype + + : + + (table) + + the class prototype that will be used for the element define + +
    • + + + + + +
    • + + debug_name + + : + + (string) + + the name that you want to see while debuging + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the new element define with all functions accessed via __index metamethod +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + get_define(name[, internal]) +
    +
    +
    +
    + +

    Gets an element define give the uid, debug name or a copy of the element define

    +

    + + + Parameters: + +
      + + + + + +
    • + + name + + : + + (string or table) + + the uid, debug name or define for the element define to get + +
    • + + + + + +
    • + + internal + + : + + (boolean) + + when true the error trace is one level higher (used internally) + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the element define that was found or an error +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + categorize_by_player(element) +
    +
    +
    +
    + +

    A categorize function to be used with add_store, each player has their own value

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the element that will be converted to a string + +
    • + + +
    + + + + + Returns: +
    • (string) - the path of the element that the search stoped at -
    • -
    -
    Or
    -
      -
    • - (boolean) - if the element was found, found -
    • -
    • - (LuaGuiElement) - the element that was found + the player's name who owns this element
    @@ -3583,26 +4533,24 @@ Gui.get_concept('button') - Usage: -
    -- Getting the center gui
    -local exists, center = Gui.find(player,'gui','center')
    - # - exists + # + categorize_by_force(element)
    -

    Checks if a gui element exists or not, returns it if found else the path where it failed

    +

    A categorize function to be used with add_store, each force has its own value

    + Parameters:
      @@ -3610,7 +4558,7 @@ Gui.get_concept('button') -
    • +
    • element @@ -3618,23 +4566,7 @@ Gui.get_concept('button') (LuaGuiElement) - the root element to start checking from - -
    • - - - - - -
    • - - ... - - : - - (string or table) - - element names or element concepts that point to your element + the element that will be converted to a string
    • @@ -3644,20 +4576,150 @@ Gui.get_concept('button') + Returns: +
        +
      • + (string) + the player's force name who owns this element +
      • +
      + + + + + + + + + +
    +
    +
    +
    + # + categorize_by_surface(element) +
    +
    +
    +
    + +

    A categorize function to be used with add_store, each surface has its own value

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the element that will be converted to a string + +
    • + + +
    + + + + + Returns: +
      +
    • + (string) + the player's surface name who owns this element +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + draw(name, element) +
    +
    +
    +
    + +

    Draws a copy of the element define to the parent element, see draw_to

    +

    + + + Parameters: + +
      + + + + + +
    • + + name + + : + + (string or table) + + the uid, debug name or define for the element define to draw + +
    • + + + + + +
    • + + element + + : + + (LuaGuiEelement) + + the parent element that it the define will be drawn to + +
    • + + +
    + + + + + Returns: + - See also: - - Usage: -
    -- Getting the center gui
    -local exists, center = Gui.exists(player,'gui','center')
    @@ -3671,7 +4733,7 @@ Gui.get_concept('button')
    -

    Toggles the enabled state of an element

    +

    Will toggle the enabled state of an element

    @@ -3691,7 +4753,7 @@ Gui.get_concept('button') (LuaGuiElement) - the element that you want to toggle the enabled state of + the gui element to toggle @@ -3705,7 +4767,7 @@ Gui.get_concept('button')
    • (boolean) - the new enabled state of the element + the new state that the element has
    @@ -3715,9 +4777,6 @@ Gui.get_concept('button') - Usage: -
    -- Toggle the enabled state of an element
    -Gui.toggle_enabled(element)
    @@ -3731,7 +4790,7 @@ Gui.get_concept('button')
    -

    Toggles the visible state of an element

    +

    Will toggle the visiblity of an element

    @@ -3751,7 +4810,7 @@ Gui.get_concept('button') (LuaGuiElement) - the element that you want to toggle the visible state of + the gui element to toggle @@ -3765,7 +4824,7 @@ Gui.get_concept('button')
    • (boolean) - the new visible state of the element + the new state that the element has
    @@ -3775,9 +4834,6 @@ Gui.get_concept('button') - Usage: -
    -- Toggle the visible state of an element
    -Gui.toggle_visible(element)
    @@ -3825,9 +4881,9 @@ Gui.get_concept('button') : - (number or boolean) + (number) - the amount of padding on the top, true leaves unchanged + the amount of padding on the top (default: 0) @@ -3842,9 +4898,9 @@ Gui.get_concept('button') : - (number or boolean) + (number) - the amount of padding on the bottom, true leaves unchanged + the amount of padding on the bottom (default: 0) @@ -3859,9 +4915,9 @@ Gui.get_concept('button') : - (number or boolean) + (number) - the amount of padding on the left, true leaves unchanged + the amount of padding on the left (default: 0) @@ -3876,9 +4932,9 @@ Gui.get_concept('button') : - (number or boolean) + (number) - the amount of padding on the right, true leaves unchanged + the amount of padding on the right (default: 0) @@ -3896,368 +4952,537 @@ Gui.get_concept('button') - Usage: -
    -- Remove all padding of an element
    -Gui.set_padding(element)
    -
    -- Remove side padding but keep vertical padding
    -Gui.set_padding(element,true,true)
    -
    -- Remove all padding but set right to 2
    -Gui.set_padding(element,false,false,false,2)
    + + +
    +
    +
    +
    + # + set_padding_style(style[, up=0][, down=0][, left=0][, right=0]) +
    +
    +
    +
    + +

    Sets the padding for a gui style

    +

    + + + Parameters: + +
      + + + + + +
    • + + style + + : + + (LuaStyle) + + the element to set the padding for + +
    • + + + + + +
    • + + up + + : + + (number) + + the amount of padding on the top + + (default: 0) +
    • + + + + + +
    • + + down + + : + + (number) + + the amount of padding on the bottom + + (default: 0) +
    • + + + + + +
    • + + left + + : + + (number) + + the amount of padding on the left + + (default: 0) +
    • + + + + + +
    • + + right + + : + + (number) + + the amount of padding on the right + + (default: 0) +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + create_alignment(element[, name][, horizontal_align='right'][, vertical_align='center']) +
    +
    +
    +
    + +

    Allows the creation of an alignment flow to place elements into

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the element to add this alignment into + +
    • + + + + + +
    • + + name + + : + + (string) + + the name to use for the alignment + + (optional) +
    • + + + + + +
    • + + horizontal_align + + : + + (string) + + the horizontal alignment of the elements in this flow + + (default: 'right') +
    • + + + + + +
    • + + vertical_align + + : + + (string) + + the vertical alignment of the elements in this flow + + (default: 'center') +
    • + + +
    + + + + + Returns: + + + + + + + + + + +
    +
    +
    +
    + # + destroy_if_valid(element) +
    +
    +
    +
    + +

    Destroies an element but tests for it being present and valid first

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the element to be destroied + +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + true if it was destoried +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + create_scroll_table(element, table_size, maximal_height[, name='scroll']) +
    +
    +
    +
    + +

    Creates a scroll area with a table inside, table can be any size

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the element to add this scroll into + +
    • + + + + + +
    • + + table_size + + : + + (number) + + the number of columns in the table + +
    • + + + + + +
    • + + maximal_height + + : + + (number) + + the max hieght of the scroll + +
    • + + + + + +
    • + + name + + : + + (string) + + the name of the scoll element + + (default: 'scroll') +
    • + + +
    + + + + + Returns: + + + + + + + + + + +
    +
    +
    +
    + # + create_header(element, caption[, tooltip][, right_align][, name='header']) +
    +
    +
    +
    + +

    Creates a header section with a label and button area

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the element to add this header into + +
    • + + + + + +
    • + + caption + + : + + (localeString) + + the caption that is used as the title + +
    • + + + + + +
    • + + tooltip + + : + + (localeString) + + the tooltip that is shown on the caption + + (optional) +
    • + + + + + +
    • + + right_align + + : + + (boolean) + + when true will include the right align area + + (optional) +
    • + + + + + +
    • + + name + + : + + (string) + + the name of the header area + + (default: 'header') +
    • + + +
    + + + + + Returns: +
      +
    • + (LuaGuiElement) + the header that was made, or the align area if that was created +
    • +
    + + + + + + +
    -

    Store Categories

    +

    Buttons

    - # - categorize_by_player(element) + # + mod-gui
    -

    A categorize function to be used with add_store, each player has their own category

    -

    - Parameters: - -
      - - - - - -
    • - - element - - : - - (LuaGuiElement) - - the element that will be converted to a string - -
    • - - -
    - - - - - Returns: -
      -
    • - (string) - the player's name who owns this element -
    • -
    - - - - - - - - Usage: -
    -- Storing data on a per player basis, can be used with instances
    -Gui.get_concept('CustomButton')
    -:define_data_store(Gui.categorize_by_player)
    - - -
    -
    -
    -
    - # - categorize_by_force(element) -
    -
    -
    -
    - -

    A categorize function to be used with add_store, each force has its own category

    -

    - - - Parameters: - -
      - - - - - -
    • - - element - - : - - (LuaGuiElement) - - the element that will be converted to a string - -
    • - - -
    - - - - - Returns: -
      -
    • - (string) - the player's force name who owns this element -
    • -
    - - - - - - - - Usage: -
    -- Storing data on a per force basis, can be used with instances
    -Gui.get_concept('CustomButton')
    -:define_data_store(Gui.categorize_by_force)
    - - -
    -
    -
    -
    - # - categorize_by_surface(element) -
    -
    -
    -
    - -

    A categorize function to be used with add_store, each surface has its own category

    -

    - - - Parameters: - -
      - - - - - -
    • - - element - - : - - (LuaGuiElement) - - the element that will be converted to a string - -
    • - - -
    - - - - - Returns: -
      -
    • - (string) - the player's surface name who owns this element -
    • -
    - - - - - - - - Usage: -
    -- Storing data on a per surface basis, can be used with instances
    -Gui.get_concept('CustomButton')
    -:define_data_store(Gui.categorize_by_surface)
    - - -
    -
    -

    Concept Base

    -
    -
    -
    -
    - # - Prototype:clone(concept_name) -
    -
    -
    -
    - -

    Used to copy all the settings from one concept to another and removing links to the orginal

    -

    - - - Parameters: - -
      - - - - - -
    • - - concept_name - - : - - (string) - - the name of the new concept; must be unique - -
    • - - -
    - - - - - Returns: -
      -
    • - (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(Gui.concepts.button):clone()
    - - -
    -
    -
    -
    - # - Prototype:define_clone(clone_callback) -
    -
    -
    -
    - -

    Use to add your own callbacks to the clone function, for example adding to a local table

    -

    - - - Parameters: - -
      - - - - - -
    • - - clone_callback - - : - - (function) - - the function which is called with the concept to have something done to it - -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - self to allow chaining -
    • -
    - - - - - - - - Usage: -
    -- Adding concept to a local table
    -local buttons = {}
    -local button =
    -Gui.get_concept('Button')
    -:define_clone(function(concept)
    -    buttons[concept.name] = concept
    -end)
    - - -
    -
    -
    -
    - # - Prototype:save_as(save_name) -
    -
    -
    -
    - -

    Used to save the concept to the main gui module to allow access from other files

    -

    - - - Parameters: - -
      - - - - - -
    • - - save_name - - : - - (string) - - the new name of the concept - -
    • - - -
    - @@ -4268,26 +5493,70 @@ Gui.get_concept('Button') - Usage: -
    -- 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) + # + expcore.gui.core
    -

    Sets a debug name that can be used with error handlers

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.gui.prototype +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + Button.new_button([name]) +
    +
    +
    +
    + +

    Creates a new button element define

    @@ -4307,7 +5576,539 @@ Gui.get_concept('button') (string) - the name that will be used in error messages + the optional debug name that can be added + + (optional) + + + + + + + + + Returns: +
      +
    • + (table) + the new button element define +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + Button._prototype:set_sprites(sprite[, hovered_sprite][, clicked_sprite]) +
    +
    +
    +
    + +

    Adds sprites to a button making it a sprite button

    +

    + + + Parameters: + +
      + + + + + +
    • + + sprite + + : + + (SpritePath) + + the sprite path for the default sprite for the button + +
    • + + + + + +
    • + + hovered_sprite + + : + + (SpritePath) + + the sprite path for the sprite when the player hovers over the button + + (optional) +
    • + + + + + +
    • + + clicked_sprite + + : + + (SpritePath) + + the sprite path for the sprite when the player clicks the button + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (self) + returns the button define to allow chaining +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + Button._prototype:set_click_filter(filter[, ...]) +
    +
    +
    +
    + +

    Adds a click / mouse button filter to the button

    +

    + + + Parameters: + +
      + + + + + +
    • + + filter + + : + + (table) + + ?string|table either a of mouse buttons or the first mouse button to filter, with a table true means allowed + +
    • + + + + + +
    • + + ... + + : + + (table) + + when filter is not a you can add the mouse buttons one after each other + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (self) + returns the button define to allow chaining +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + Button._prototype:set_key_filter(filter[, ...]) +
    +
    +
    +
    + +

    Adds a control key filter to the button

    +

    + + + Parameters: + +
      + + + + + +
    • + + filter + + : + + (table) + + ?string|table either a of control keys or the first control keys to filter, with a table true means allowed + +
    • + + + + + +
    • + + ... + + : + + (table) + + when filter is not a you can add the control keys one after each other + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (self) + returns the button define to allow chaining +
    • +
    + + + + + + + + + +
    +
    +

    Checkboxs

    +
    +
    +
    +
    + # + expcore.gui.core +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.gui.prototype +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.store +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + utils.game +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + Checkbox.new_checkbox([name]) +
    +
    +
    +
    + +

    Creates a new checkbox element define

    +

    + + + Parameters: + +
      + + + + + +
    • + + name + + : + + (string) + + the optional debug name that can be added + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the new checkbox element define +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + Checkbox.new_radiobutton([name]) +
    +
    +
    +
    + +

    Creates a new radiobutton element define, has all functions checkbox has

    +

    + + + Parameters: + +
      + + + + + +
    • + + name + + : + + (string) + + the optional debug name that can be added + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the new button element define +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + Checkbox._prototype_radiobutton:add_as_option(option_set, option_name) +
    +
    +
    +
    + +

    Adds this radiobutton to be an option in the given option set (only one can be true at a time)

    +

    + + + Parameters: + +
      + + + + + +
    • + + option_set + + : + + (string) + + the name of the option set to add this element to + +
    • + + + + + +
    • + + option_name + + : + + (string) + + the name of this option that will be used to identify it
    • @@ -4321,7 +6122,7 @@ Gui.get_concept('button')
      • (self) - to allow chaining + the define to allow chaining
      @@ -4331,23 +6132,3615 @@ Gui.get_concept('button') - Usage: -
      -- Set the debug name
      -unsaved_concept:debug('Example button')
    - # - Prototype:new_event(event_name[, factorio_event][, event_condition]) + # + Checkbox._prototype_radiobutton:get_store(category, internal)
    -

    Adds a new event trigger to the concept which can be linked to a factorio event

    +

    Gets the stored value of the radiobutton or the option set if present

    +

    + + + Parameters: + +
      + + + + + +
    • + + category + + : + + (string) + + [opt] the category to get such as player name or force name + +
    • + + + + + +
    • + + internal + + : + + (boolean) + + used to prevent stackover flow + +
    • + + +
    + + + + + Returns: +
      +
    • + (any) + the value that is stored for this define +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + Checkbox._prototype_radiobutton:set_store(category, value, internal) +
    +
    +
    +
    + +

    Sets the stored value of the radiobutton or the option set if present

    +

    + + + Parameters: + +
      + + + + + +
    • + + category + + : + + (string) + + [opt] the category to get such as player name or force name + +
    • + + + + + +
    • + + value + + : + + (boolean) + + the value to set for this define, must be valid for its type ie for checkbox etc + +
    • + + + + + +
    • + + internal + + : + + (boolean) + + used to prevent stackover flow + +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + true if the value was set +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + Checkbox.new_option_set(name, callback, categorize) +
    +
    +
    +
    + +

    Registers a new option set that can be linked to radiobuttons (only one can be true at a time)

    +

    + + + Parameters: + +
      + + + + + +
    • + + name + + : + + (string) + + the name of the option set, must be unique + +
    • + + + + + +
    • + + callback + + : + + (function) + + the update callback when the value of the option set changes + callback param - value string - the new selected option for this option set + callback param - category string - the category that updated if categorize was used + +
    • + + + + + +
    • + + categorize + + : + + (function) + + the function used to convert an element into a string + +
    • + + +
    + + + + + Returns: +
      +
    • + (string) + the name of this option set to be passed to add_as_option +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + Checkbox.draw_option_set(name, element) +
    +
    +
    +
    + +

    Draws all radiobuttons that are part of an option set at once (Gui.draw will not work)

    +

    + + + Parameters: + +
      + + + + + +
    • + + name + + : + + (string) + + the name of the option set to draw the radiobuttons of + +
    • + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the parent element that the radiobuttons will be drawn to + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + Checkbox.reset_radiobuttons(element[, exclude][, recursive=false]) +
    +
    +
    +
    + +

    Sets all radiobutton in a element to false (unless excluded) and can act recursively

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the root gui element to start setting radio buttons from + +
    • + + + + + +
    • + + exclude + + : + + (table) + + ?string|table the name of the radiobutton to exclude or a of radiobuttons where true will set the state true + + (optional) +
    • + + + + + +
    • + + recursive + + : + + (number or boolean) + + if true will recur as much as possible, if a will recur that number of times + + (default: false) +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + true if successful +
    • +
    + + + + + + + + + +
    +
    +

    Dropdowns

    +
    +
    +
    +
    + # + expcore.gui.core +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.gui.prototype +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + utils.game +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + Dropdown.new_dropdown([name]) +
    +
    +
    +
    + +

    Creates a new dropdown element define

    +

    + + + Parameters: + +
      + + + + + +
    • + + name + + : + + (string) + + the optional debug name that can be added + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the new dropdown element define +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + Dropdown.new_list_box([name]) +
    +
    +
    +
    + +

    Creates a new list box element define

    +

    + + + Parameters: + +
      + + + + + +
    • + + name + + : + + (string) + + the optional debug name that can be added + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the new list box element define +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + Dropdown._prototype:new_static_options(options[, ...], the) +
    +
    +
    +
    + +

    Adds new static options to the dropdown which will trigger the general callback

    +

    + + + Parameters: + +
      + + + + + +
    • + + options + + : + + (table) + + ?string|table either a of option strings or the first option string, with a table values are the options + +
    • + + + + + +
    • + + ... + + : + + (table) + + when options is not a you can add the options one after each other + + (optional) +
    • + + + + + +
    • + + the + + : + + (self) + + define to allow chaining + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + Dropdown._prototype:new_dynamic_options(callback) +
    +
    +
    +
    + +

    Adds a callback which should return a table of values to be added as options for the dropdown (appended after static options)

    +

    + + + Parameters: + +
      + + + + + +
    • + + callback + + : + + (function) + + the function that will run to get the options for the dropdown + callback param - player LuaPlayer - the player that the element is being drawn to + callback param - element LuaGuiElement - the element that is being drawn + callback return - table - the values of this table will be appended to the static options of the dropdown + +
    • + + +
    + + + + + Returns: +
      +
    • + (self) + the define to allow chaining +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + Dropdown._prototype:add_option_callback(option, callback) +
    +
    +
    +
    + +

    Adds a case specific callback which will only run when that option is selected (general case still triggered)

    +

    + + + Parameters: + +
      + + + + + +
    • + + option + + : + + (string) + + the name of the option to trigger the callback on; if not already added then will be added as an option + +
    • + + + + + +
    • + + callback + + : + + (function) + + the function that will be called when that option is selected + callback param - player LuaPlayer - the player who owns the gui element + callback param - element LuaGuiElement - the element which is being effected + callback param - value string - the new option that has been selected + +
    • + + +
    + + + + + Returns: +
      +
    • + (self) + the define to allow chaining +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + Dropdown.select_value(element, value) +
    +
    +
    +
    + +

    Selects the option from a dropdown or list box given the value rather than key

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the element that contains the option + +
    • + + + + + +
    • + + value + + : + + (string) + + the option to select from the dropdown + +
    • + + +
    + + + + + Returns: +
      +
    • + (number) + the key where the value was +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + Dropdown.get_selected_value(element) +
    +
    +
    +
    + +

    Returns the currently selected value rather than index

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the gui element that you want to get the value of + +
    • + + +
    + + + + + Returns: +
      +
    • + (string) + the value that is currently selected +
    • +
    + + + + + + + + + +
    +
    +

    Elem Buttons

    +
    +
    +
    +
    + # + expcore.gui.core +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.gui.prototype +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + utils.game +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + ElemButton.new_elem_button([name]) +
    +
    +
    +
    + +

    Creates a new elem button element define

    +

    + + + Parameters: + +
      + + + + + +
    • + + name + + : + + (string) + + the optional debug name that can be added + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the new elem button element define +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + ElemButton._prototype.set_type +
    +
    +
    +
    + +

    Sets the type of the elem button, the type is required so this must be called at least once

    +

    + + + +
      + + + + + +
    • + + type + + : + + (string) + + the type that this elem button is see factorio api + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + ElemButton._prototype:set_default(value) +
    +
    +
    +
    + +

    Sets the default value for the elem button, this may be a function or a string

    +

    + + + Parameters: + +
      + + + + + +
    • + + value + + : + + (string or function) + + string a will be a static default and a function will be called when drawn to get the default + +
    • + + +
    + + + + + Returns: +
      +
    • + (the) + element define to allow for chaining +
    • +
    + + + + + + + + + +
    +
    +

    Progress Bars

    +
    +
    +
    +
    + # + expcore.gui.core +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.gui.prototype +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + utils.global +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + utils.game +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + ProgressBar.set_maximum(element, amount) +
    +
    +
    +
    + +

    Sets the maximum value that represents the end value of the progress bar

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement or string) + + either a gui element or a registered define + +
    • + + + + + +
    • + + amount + + : + + (number) + + the amount to have set as the maximum + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + ProgressBar.increment(element[, amount=1]) +
    +
    +
    +
    + +

    Increases the value of the progressbar, if a define is given all of its instances have incremented

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement or string) + + either a gui element or a registered define + +
    • + + + + + +
    • + + amount + + : + + (number) + + the amount to increase the progressbar by + + (default: 1) +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + ProgressBar.decrement(element[, amount=1]) +
    +
    +
    +
    + +

    Decreases the value of the progressbar, if a define is given all of its instances have decremented

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement or string) + + either a gui element or a registered define + +
    • + + + + + +
    • + + amount + + : + + (number) + + the amount to decrease the progressbar by + + (default: 1) +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + ProgressBar.new_progressbar([name]) +
    +
    +
    +
    + +

    Creates a new progressbar element define

    +

    + + + Parameters: + +
      + + + + + +
    • + + name + + : + + (string) + + the optional debug name that can be added + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the new progressbar element define +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + ProgressBar._prototype:set_default_maximum(amount) +
    +
    +
    +
    + +

    Sets the maximum value that represents the end value of the progress bar

    +

    + + + Parameters: + +
      + + + + + +
    • + + amount + + : + + (number) + + the amount to have set as the maximum + +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the define to allow chaining +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + ProgressBar._prototype:use_count_down([state=true]) +
    +
    +
    +
    + +

    Will set the progress bar to start at 1 and trigger when it hits 0

    +

    + + + Parameters: + +
      + + + + + +
    • + + state + + : + + (boolean) + + when true the bar will start filled, to be used with decrease + + (default: true) +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the define to allow chaining +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + ProgressBar._prototype:increment([amount=1][, category]) +
    +
    +
    +
    + +

    Increases the value of the progressbar

    +

    + + + Parameters: + +
      + + + + + +
    • + + amount + + : + + (number) + + the amount to increase the progressbar by + + (default: 1) +
    • + + + + + +
    • + + category + + : + + (string) + + the category that is used with a store + + (optional) +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + ProgressBar._prototype:increment_filtered([amount=1], filter) +
    +
    +
    +
    + +

    Increases the value of the progressbar, if the filter condition is met, does not work with store

    +

    + + + Parameters: + +
      + + + + + +
    • + + amount + + : + + (number) + + the amount to increase the progressbar by + + (default: 1) +
    • + + + + + +
    • + + filter + + : + + (function) + + the filter to be used + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + ProgressBar._prototype:decrement([amount=1][, category]) +
    +
    +
    +
    + +

    Decreases the value of the progressbar

    +

    + + + Parameters: + +
      + + + + + +
    • + + amount + + : + + (number) + + the amount to decrease the progressbar by + + (default: 1) +
    • + + + + + +
    • + + category + + : + + (string) + + the category that is used with a store + + (optional) +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + ProgressBar._prototype:decrement_filtered([amount=1], filter) +
    +
    +
    +
    + +

    Decreases the value of the progressbar, if the filter condition is met, does not work with store

    +

    + + + Parameters: + +
      + + + + + +
    • + + amount + + : + + (number) + + the amount to decrease the progressbar by + + (default: 1) +
    • + + + + + +
    • + + filter + + : + + (function) + + the filter to be used + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + ProgressBar._prototype:add_element(element[, maximum]) +
    +
    +
    +
    + +

    Adds an element into the list of instances that will are waiting to complete, does not work with store + note use store if you want persistent data, this only stores the elements not the values which they have

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the element that you want to add into the waiting to complete list + +
    • + + + + + +
    • + + maximum + + : + + (number) + + the maximum for this element if not given the default for this define is used + + (optional) +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + ProgressBar._prototype:reset_element(element) +
    +
    +
    +
    + +

    Resets an element, or its store, to be back at the start, either 1 or 0

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the element that you want to reset the progress of + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + ProgressBar._prototype:event_counter([filter]) +
    +
    +
    +
    + +

    Event handler factory that counts up by 1 every time the event triggers, can filter which elements have incremented

    +

    + + + Parameters: + +
      + + + + + +
    • + + filter + + : + + (function) + + when given will use filtered increment + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (function) + the event handler +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + ProgressBar._prototype:event_countdown([filter]) +
    +
    +
    +
    + +

    Event handler factory that counts down by 1 every time the event triggers, can filter which elements have decremented

    +

    + + + Parameters: + +
      + + + + + +
    • + + filter + + : + + (function) + + when given will use filtered decrement + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (function) + the event handler +
    • +
    + + + + + + + + + +
    +
    +

    Sliders

    +
    +
    +
    +
    + # + expcore.gui.core +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.gui.prototype +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.gui.instances +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + utils.game +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + Slider.new_slider([name]) +
    +
    +
    +
    + +

    Creates a new slider element define

    +

    + + + Parameters: + +
      + + + + + +
    • + + name + + : + + (string) + + the optional debug name that can be added + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the new slider element define +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + Slider._prototype:set_range([min][, max]) +
    +
    +
    +
    + +

    Sets the range of a slider, if not used will use default values for a slider

    +

    + + + Parameters: + +
      + + + + + +
    • + + min + + : + + (number) + + the minimum value that the slider can take + + (optional) +
    • + + + + + +
    • + + max + + : + + (number) + + the maximum value that the slider can take + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (self) + the define to allow chaining +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + Slider._prototype:draw_label(element) +
    +
    +
    +
    + +

    Draws a new label and links its value to the value of this slider, if no store then it will only show one value per player

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the parent element that the label will be drawn to + +
    • + + +
    + + + + + Returns: +
      +
    • + (LuaGuiElement) + the new label element so that styles can be applied +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + Slider._prototype:enable_auto_draw_label([state=true]) +
    +
    +
    +
    + +

    Enables auto draw of the label, the label will share the same parent element as the slider

    +

    + + + Parameters: + +
      + + + + + +
    • + + state + + : + + (boolean) + + when false will disable the auto draw of the label + + (default: true) +
    • + + +
    + + + + + Returns: +
      +
    • + (self) + the define to allow chaining +
    • +
    + + + + + + + + + +
    +
    +

    Text

    +
    +
    +
    +
    + # + expcore.gui.core +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.gui.prototype +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + utils.game +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + Text.new_text_field([name]) +
    +
    +
    +
    + +

    Creates a new text field element define

    +

    + + + Parameters: + +
      + + + + + +
    • + + name + + : + + (string) + + the optional debug name that can be added + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the new text field element define +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + Text.new_text_box([name]) +
    +
    +
    +
    + +

    Creates a new text box element define

    +

    + + + Parameters: + +
      + + + + + +
    • + + name + + : + + (string) + + the optional debug name that can be added + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the new text box element define +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + Text._prototype_box:set_selectable([state=true]) +
    +
    +
    +
    + +

    Sets the text box to be selectable

    +

    + + + Parameters: + +
      + + + + + +
    • + + state + + : + + (boolean) + + when false will set the state to false + + (default: true) +
    • + + +
    + + + + + Returns: +
      +
    • + (self) + table the define to allow for chaining +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + Text._prototype_box:set_word_wrap([state=true]) +
    +
    +
    +
    + +

    Sets the text box to have word wrap

    +

    + + + Parameters: + +
      + + + + + +
    • + + state + + : + + (boolean) + + when false will set the state to false + + (default: true) +
    • + + +
    + + + + + Returns: +
      +
    • + (self) + table the define to allow for chaining +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + Text._prototype_box:set_read_only([state=true]) +
    +
    +
    +
    + +

    Sets the text box to be read only

    +

    + + + Parameters: + +
      + + + + + +
    • + + state + + : + + (boolean) + + when false will set the state to false + + (default: true) +
    • + + +
    + + + + + Returns: +
      +
    • + (self) + table the define to allow for chaining +
    • +
    + + + + + + + + + +
    +
    +

    Instances

    +
    +
    +
    +
    + # + utils.global +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + Instances.has_categories(name) +
    +
    +
    +
    + +

    Returns if a instance group has a categorise function; must be registered

    +

    + + + Parameters: + +
      + + + + + +
    • + + name + + : + + (string) + + the name of the instance group + +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + true if there is a categorise function +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + Instances.is_registered(name) +
    +
    +
    +
    + +

    Returns if the given name is a registered instance group

    +

    + + + Parameters: + +
      + + + + + +
    • + + name + + : + + (string) + + the name of the instance group you are testing + +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + true if the name is registered +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + Instances.register(name[, categorise]) +
    +
    +
    +
    + +

    Registers the name of an instance group to allow for storing element instances

    +

    + + + Parameters: + +
      + + + + + +
    • + + name + + : + + (string) + + the name of the instance group; must to unique + +
    • + + + + + +
    • + + categorise + + : + + (function) + + function used to turn the element into a string + categorise param - element LuaGuiElement - the gui element to be turned into a string + categorise return - string - the category that the element will be added to like the player's name or force's name + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (string) + the name that was added so it can be used as a variable +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + Instances.add_element(name, element) +
    +
    +
    +
    + +

    Adds an element to the instance group under the correct category; must be registered

    +

    + + + Parameters: + +
      + + + + + +
    • + + name + + : + + (string) + + the name of the instance group to add the element to + +
    • + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the element to add the the instance group + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + Instances.get_elements_raw(name[, category]) +
    +
    +
    +
    + +

    Gets all element instances without first removing any invalid ones; used internally and must be registered

    +

    + + + Parameters: + +
      + + + + + +
    • + + name + + : + + (string) + + the name of the instance group to get the instances of + +
    • + + + + + +
    • + + category + + : + + (string) + + the category to get the instance from, not needed when no categorise function + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the table of element instances of which some may be invalid +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + Instances.get_valid_elements(name[, category][, callback]) +
    +
    +
    +
    + +

    Gets all valid element instances and has the option of running a callback on those that are valid

    +

    + + + Parameters: + +
      + + + + + +
    • + + name + + : + + (string) + + the name of the instance group to get the instances of + +
    • + + + + + +
    • + + category + + : + + (string) + + the category to get the instances of, not needed when no categorise function + + (optional) +
    • + + + + + +
    • + + callback + + : + + (function) + + when given the callback will be ran on all valid elements + callback param - element LuaGuiElement - the current valid element + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the table of element instances with all invalid ones removed +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + Instances.unregistered_add_element(name, category, element) +
    +
    +
    +
    + +

    A version of add_element that does not require the group to be registered

    +

    + + + Parameters: + +
      + + + + + +
    • + + name + + : + + (string) + + the name of the instance group to add the element to + +
    • + + + + + +
    • + + category + + : + + (string or nil) + + the category to add the element to, can be nil but must still be given + +
    • + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the element to add to the instance group + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + Instances.unregistered_get_elements(name, category[, callback]) +
    +
    +
    +
    + +

    A version of get_elements that does not require the group to be registered

    +

    + + + Parameters: + +
      + + + + + +
    • + + name + + : + + (string) + + the name of the instance group to get the instances of + +
    • + + + + + +
    • + + category + + : + + (string or nil) + + the category to get the instances of, can be nil but must still be given + +
    • + + + + + +
    • + + callback + + : + + (function) + + when given will be called on all valid instances + callback param - element LuaGuiElement - the current valid element + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the table of element instances with all invalid ones removed +
    • +
    + + + + + + + + + +
    +
    +

    Prototype

    +
    +
    +
    +
    + # + utils.game +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.store +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.gui.instances +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + Constructor.event(event_name) +
    +
    +
    +
    + +

    Creates a new function to add functions to an event handler

    @@ -4367,45 +9760,11 @@ Gui.get_concept('button') (string) - the name of the event to add, must be unique, recomented to start with "on_" + the name of the event that callbacks will be added to - - - -
  • - - factorio_event - - : - - (defines.events) - - when given will fire the custom event when the factorio event is raised - - (optional) -
  • - - - - - -
  • - - event_condition - - : - - (function) - - used to filter when a factorio event triggers the custom event; if the event contains a reference to an element then names are automatically filtered - - (optional) -
  • - - @@ -4414,8 +9773,8 @@ Gui.get_concept('button') Returns:
    • - (GuiConcept) - to allow chaining of functions + (function) + the function used to register handlers
    @@ -4425,27 +9784,20 @@ Gui.get_concept('button') - Usage: -
    -- Adds an on_admin_clicked event to fire when ever an admin clicks the button
    -local custom_button =
    -Gui.get_concept('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)
    - # - Prototype:on_custom_event(handler) + # + Constructor.extend(new_prototype)
    -

    Adds a custom event handler, replace with the name of the event

    +

    Extents a prototype with the base functions of all gui prototypes, no metatables

    @@ -4459,13 +9811,13 @@ Gui.get_concept('Button'):clone( - handler + new_prototype : - (function) + (table) - the function which will recive the event + the prototype that you want to add the functions to @@ -4478,8 +9830,689 @@ Gui.get_concept('Button'):clone(Returns:
    • - (GuiConcept) - to allow chaining of functions + (table) + the same prototype but with the new functions added +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + Constructor.store(sync, callback) +
    +
    +
    +
    + +

    Creates a new function which adds a store to a gui define

    +

    + + + Parameters: + +
      + + + + + +
    • + + sync + + : + + (boolean) + + if the function should create a synced store + +
    • + + + + + +
    • + + callback + + : + + (function) + + the function called when needing to update the value of an element + +
    • + + +
    + + + + + Returns: +
      +
    • + (function) + the function that will add a store for this define +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + Constructor.setter(value_type, key[, second_key]) +
    +
    +
    +
    + +

    Creates a setter function that checks the type when a value is set

    +

    + + + Parameters: + +
      + + + + + +
    • + + value_type + + : + + (string) + + the type that the value should be when it is set + +
    • + + + + + +
    • + + key + + : + + (string) + + the key of the define that will be set + +
    • + + + + + +
    • + + second_key + + : + + (string) + + allows for setting of a key in a sub table + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (function) + the function that will check the type and set the value +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + Prototype:uid() +
    +
    +
    +
    + +

    Gets the uid for the element define

    +

    + + + + + + Returns: +
      +
    • + (string) + the uid of this element define +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + Prototype.debug_name +
    +
    +
    +
    + +

    Sets a debug alias for the define

    +

    + + + +
      + + + + + +
    • + + name + + : + + (string) + + the debug name for the element define that can be used to get this element define + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + Prototype.set_caption +
    +
    +
    +
    + +

    Sets the caption for the element define

    +

    + + + +
      + + + + + +
    • + + caption + + : + + (string) + + the caption that will be drawn with the element + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + Prototype.set_tooltip +
    +
    +
    +
    + +

    Sets the tooltip for the element define

    +

    + + + +
      + + + + + +
    • + + tooltip + + : + + (string) + + the tooltip that will be displayed for this element when drawn + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + Prototype.set_pre_authenticator +
    +
    +
    +
    + +

    Sets an authenticator that blocks the draw function if check fails

    +

    + + + +
      + + + + + +
    • + + callback + + : + + (function) + + the function that will be ran to test if the element should be drawn or not + callback param - LuaPlayer player - the player that the element is being drawn to + callback param - string define_name - the name of the define that is being drawn + callback return - boolean - false will stop the element from being drawn + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + Prototype.set_post_authenticator +
    +
    +
    +
    + +

    Sets an authenticator that disables the element if check fails

    +

    + + + +
      + + + + + +
    • + + callback + + : + + (function) + + the function that will be ran to test if the element should be enabled or not + callback param - LuaPlayer player - the player that the element is being drawn to + callback param - string define_name - the name of the define that is being drawn + callback return - boolean - false will disable the element + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + Prototype.on_draw +
    +
    +
    +
    + +

    Registers a callback to the on_draw event

    +

    + + + +
      + + + + + +
    • + + callback + + : + + (function) + + + callback param - LuaPlayer player - the player that the element was drawn to + callback param - LuaGuiElement element - the element that was drawn + callback param - any ... - any other params passed by the draw_to function + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + Prototype.on_style_update +
    +
    +
    +
    + +

    Registers a callback to the on_style_update event

    +

    + + + +
      + + + + + +
    • + + callback + + : + + (function) + + + callback param - LuaStyle style - the style that was changed and/or needs changing + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + Prototype:set_style(style[, callback]) +
    +
    +
    +
    + +

    Sets the style for the element define

    +

    + + + Parameters: + +
      + + + + + +
    • + + style + + : + + (string) + + the style that will be used for this element when drawn + +
    • + + + + + +
    • + + callback + + : + + (function) + + function is called when element is drawn to alter its style + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (self) + the element define to allow chaining +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + Prototype:set_embedded_flow(state) +
    +
    +
    +
    + +

    Sets the element to be drawn inside a nameless flow, can be given a name using a function

    +

    + + + Parameters: + +
      + + + + + +
    • + + state + + : + + (boolean or function) + + when true a padless flow is created to contain the element + +
    • + + +
    + + + + + Returns: +
      +
    • + (self) + the element define to allow chaining
    @@ -4489,13 +10522,6 @@ Gui.get_concept('Button'):clone( - Usage: -
    -- When an admin clicks the button a message is printed
    -local custom_button =
    -Gui.get_concept('CustomButton')
    -:on_admin_clicked(function(event)
    -    game.print(event.player.name..' pressed my admin button')
    -end)
    @@ -4503,13 +10529,13 @@ Gui.get_concept('CustomButton')
    # - Prototype:raise_event(event_name[, event={}][, from_factorio=false]) + Prototype:raise_event(event_name, ...)
    -

    Raises a custom event, folowing keys included automaticlly: concept, event name, game tick, player from player_index, element if valid

    +

    Raises a custom event for this define, any number of params can be given

    @@ -4539,15 +10565,186 @@ Gui.get_concept('CustomButton')
  • - event + ... : - (table) + (any) - table containg data you want to send with the event, some keys already included + any params that you want to pass to the event + +
  • + + + + + + + + Returns: +
      +
    • + (number) + the number of handlers that were registered +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + Prototype:draw_to(element) +
    +
    +
    +
    + +

    The main function for defines, when called will draw an instance of this define to the given element + what is drawn is based on the data in draw_data which is set using other functions

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the element that the define will draw a instance of its self onto + +
    • + + +
    + + + + + Returns: + + + + + + + + + + +
    +
    +
    +
    + # + Prototype:get_store(category) +
    +
    +
    +
    + +

    Gets the value in this elements store, category needed if categorize function used

    +

    + + + Parameters: + +
      + + + + + +
    • + + category + + : + + (string) + + [opt] the category to get such as player name or force name + +
    • + + +
    + + + + + Returns: +
      +
    • + (any) + the value that is stored for this define +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + Prototype:set_store(category, value) +
    +
    +
    +
    + +

    Sets the value in this elements store, category needed if categorize function used

    +

    + + + Parameters: + +
      + + + + + +
    • + + category + + : + + (string) + + [opt] the category to get such as player name or force name - (default: {})
    • @@ -4556,122 +10753,27 @@ Gui.get_concept('CustomButton')
    • - from_factorio + value : + (any) + + the value to set for this define, must be valid for its type ie for checkbox etc + +
    • + + +
    + + + + + Returns: +
      +
    • (boolean) - - internal use, if the raise came from the factorio event handler - - (default: false) -
    • - - -
    - - - - - - - - - - - - Usage: -
    -- Raising the custom event on_admin_clicked
    -local custom_button =
    -Gui.get_concept('CustomButton')
    -
    --- Note that this is an example and would not work due it expecting a valid element for event.element
    --- this will however work fine if you can provide all expected keys, or its not linked to any factorio event
    -custom_button:raise_event('on_admin_clicked',{
    -    player_index = game.player.index
    -})
    - - -
    -
    -
    -
    - # - 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

    -

    - - - Parameters: - -
      - - - - - -
    • - - property_name - - : - - (string) - - the name of the new property, must be unique - -
    • - - - - - -
    • - - setter_callback - - : - - (function) - - this function is called when set is called, if not provided then key in concept.properties is updated to new value - - (optional) -
    • - - - - - -
    • - - default - - : - - (any) - - use this as the default value, will call the setter callback if defined - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (GuiConcept) - to allow chaining of functions + true if the value was set
    @@ -4681,35 +10783,20 @@ Gui.get_concept('CustomButton') - Usage: -
    -- Adding caption, sprite, and tooltip to the base button concept
    -local button =
    -Gui.get_concept('Button')
    -: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)
    - # - Prototype:set_custom_property(value) + # + Prototype:clear_store([category])
    -

    Sets a new value for a property, triggers setter method if provided, replace with property name

    +

    Sets the value in this elements store to nil, category needed if categorize function used

    @@ -4721,391 +10808,6 @@ Gui.get_concept('Button') -
  • - - value - - : - - (any) - - the value that you want to set for this property - -
  • - - - - - - - - Returns: -
      -
    • - (GuiConcept) - to allow chaining of functions -
    • -
    - - - - - - - - Usage: -
    -- Setting the caption on the base button concept after a cloning
    -local custom_button =
    -Gui.get_concept('Button')
    -:set_caption('Default Button')
    -
    -- 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 =
    -Gui.get_concept('CustomButton')
    -:set_caption('Custom Button')
    - - -
    -
    -
    -
    - # - Prototype:define_draw(draw_callback) -
    -
    -
    -
    - -

    Used to define how the concept is turned into an ingame element or "instance" as we may refer to them

    -

    - - - Parameters: - -
      - - - - - -
    • - - draw_callback - - : - - (function) - - the function that will be called to draw/update the instance; this function must return the instance or the new acting instance - -
    • - - -
    - - - - - Returns: -
      -
    • - (GuiConcept) - to allow chaining of functions -
    • -
    - - - - - - - - Usage: -
    -- Adding the draw define for the base button concept, we then return the element
    -local button =
    -Gui.get_concept('Button')
    -:define_draw(function(properties,parent,element)
    -    -- 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.add{
    -            type = properties.type,
    -            name = properties.name,
    -            caption = properties.caption,
    -            tooltip = properties.tooltip
    -        }
    -
    -    else
    -        element = parent.add{
    -            type = properties.type,
    -            name = properties.name,
    -            sprite = properties.sprite,
    -            tooltip = properties.tooltip
    -        }
    -
    -    end
    -
    -    -- 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)
    - - -
    -
    -
    -
    - # - Prototype:draw(parent_element[, override_name]) -
    -
    -
    -
    - -

    Calls all the draw functions in order to create this concept in game; will also store and sync the instance if stores are used

    -

    - - - Parameters: - -
      - - - - - -
    • - - parent_element - - : - - (LuaGuiElement) - - the element that the concept will use as a base - -
    • - - - - - -
    • - - override_name - - : - - (string) - - when given this will be the name of the element rather than the concept id - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (LuaGuiElement) - the element that was created and then passed though and returned by the draw functions -
    • -
    - - - - - - - - Usage: -
    -- Drawing the custom button concept
    -local custom_button =
    -Gui.get_concept('CustomButton')
    -
    --- Note that the draw function from button was cloned, so unless we want to alter the base button we dont need a new draw define
    -custom_button:draw(game.player.gui.left)
    - - -
    -
    -

    Concept Instances

    -
    -
    -
    -
    - # - Prototype:define_instance_store([category_callback]) -
    -
    -
    -
    - -

    Adds an instance store to the concept; when a new instance is made it is stored so you can access it later

    -

    - - - Parameters: - -
      - - - - - -
    • - - category_callback - - : - - (function) - - when given will act as a way to turn an element into a string to act as a key; keys returned can over lap - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (GuiConcept) - to allow chaining of functions -
    • -
    - - - - - - - - Usage: -
    -- Allowing storing instances of the custom button; stored by the players index
    --- Note even thou this is a copy of Button; if Button had an instance store it would not be cloned over
    -local custom_button =
    -Gui.get_concept('CustomButton')
    -:define_instance_store(function(element)
    -    return element.player_index -- The instances are stored based on player id
    -end)
    - - -
    -
    -
    -
    - # - Prototype.get_instances([category]) -
    -
    -
    -
    - -

    Gets all insatnces in a category, category may be nil to return all

    -

    - - - Parameters: - -
      - - - - - -
    • - - category - - : - - (string or LuaGuiElement) - - the category to get, can only be nil if categories are not used - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - a table which contains all the instances -
    • -
    - - - - - - - - Usage: -
    -- Getting all the instances of the player with index 1
    -local custom_button =
    -Gui.get_concept('CustomButton')
    -
    -custom_button.get_instances(1) -- player index 1
    - - -
    -
    -
    -
    - # - Prototype.add_instance(element[, category]) -
    -
    -
    -
    - -

    Adds an instance to this concept, used automatically during concept:draw

    -

    - - - Parameters: - -
      - - - - - -
    • - - element - - : - - (LuaGuiElement) - - the element that will be added as an instance - -
    • - - - - -
    • category @@ -5114,142 +10816,7 @@ custom_button.get_instances(1) -- player index string) - the category to add this element under, if nil the category callback is used to assign one - - (optional) -
    • - - -
    - - - - - - - - - - - - Usage: -
    -- Adding an element as a instance for this concept, mostly for internal use
    -local custom_button =
    -Gui.get_concept('CustomButton')
    -
    -custom_button.add_instance(element) -- normally not needed due to use in concept:draw
    - - -
    -
    -
    -
    - # - Prototype.update_instances([category], update_callback) -
    -
    -
    -
    - -

    Applies an update function to all instances, simialr use to what table.forEach would be

    -

    - - - Parameters: - -
      - - - - - -
    • - - category - - : - - (string or LuaGuiElement) - - the category to get, can only be nil if categories are not used - - (optional) -
    • - - - - - -
    • - - update_callback - - : - - (function) - - the function which is called on each instance, recives other args passed to update_instances - -
    • - - -
    - - - - - - - - - - - - Usage: -
    -- Changing the font color of all instances for player 1
    -local custom_button =
    -Gui.get_concept('CustomButton')
    -
    -custom_button.update_instances(1,function(element)
    -    element.style.font_color = {r=1,g=0,b=0}
    -end)
    - - -
    -
    -

    Concept Data

    -
    -
    -
    -
    - # - Prototype:define_data_store([category_callback]) -
    -
    -
    -
    - -

    Adds a data store to this concept which allows you to store synced/percistent data between instances

    -

    - - - Parameters: - -
      - - - - - -
    • - - category_callback - - : - - (function) - - when given will act as a way to turn an element into a string to act as a key; keys returned can over lap + the category to get such as player name or force name (optional)
    • @@ -5263,8 +10830,8 @@ custom_button.update_instances(1,GuiConcept) - to allow chaining of functions + (boolean) + true if the value was set
    @@ -5274,364 +10841,27 @@ custom_button.update_instances(1,-- Adding a way to store data for this concept; each player has their own store --- Note even thou this is a copy of Button; if Button had an data store it would not be cloned over -local custom_button = -Gui.get_concept('CustomButton') -:define_data_store(function(element) - return element.player_index -- The data is stored based on player id -end) - - -
    -
    -
    -
    - # - Prototype.get_data([category]) -
    -
    -
    -
    - -

    Gets the data that is stored for this category

    -

    - - - Parameters: - -
      - - - - - -
    • - - category - - : - - (string or LuaGuiElement) - - the category to get, can only be nil if categories are not used - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (any) - the data that you had stored in this location -
    • -
    - - - - - - - - Usage: -
    -- Getting the stored data for player 1
    -local custom_button =
    -Gui.get_concept('CustomButton')
    -
    -custom_button.get_data(1) -- player index 1
    - - -
    -
    -
    -
    - # - Prototype.set_data([category], value) -
    -
    -
    -
    - -

    Sets the data that is stored for this category

    -

    - - - Parameters: - -
      - - - - - -
    • - - category - - : - - (string or LuaGuiElement) - - the category to set, can only be nil if categories are not used - - (optional) -
    • - - - - - -
    • - - value - - : - - (any) - - the data that you want to stored in this location - -
    • - - -
    - - - - - - - - - - - - Usage: -
    -- Setting the data for player 1 to a table with two keys
    -local custom_button =
    -Gui.get_concept('CustomButton')
    -
    --- A table is used to show correct way to use a table with self.update_data
    --- but a table is not required and can be any data, however upvalues may cause desyncs
    -custom_button.set_data(1,{
    -    clicks = 0,
    -    required_clicks = 100
    -}) -- player index 1
    - - -
    -
    -
    -
    - # - Prototype.clear_data([category]) -
    -
    -
    -
    - -

    Clears the data that is stored for this category

    -

    - - - Parameters: - -
      - - - - - -
    • - - category - - : - - (string or LuaGuiElement) - - the category to clear, can only be nil if categories are not used - - (optional) -
    • - - -
    - - - - - - - - - - - - Usage: -
    -- Clearing the data for player 1
    -local custom_button =
    -Gui.get_concept('CustomButton')
    -
    -custom_button.clear_data(1) -- player index 1
    - - -
    -
    -
    -
    - # - Prototype.update_data([category], update_callback) -
    -
    -
    -
    - -

    Updates the data that is stored for this category

    -

    - - - Parameters: - -
      - - - - - -
    • - - category - - : - - (string or LuaGuiElement) - - the category to clear, can only be nil if categories are not used - - (optional) -
    • - - - - - -
    • - - update_callback - - : - - (function) - - the function which is called to update the data - -
    • - - -
    - - - - - - - - - - - - Usage: -
    -- Updating the clicks key in the concept data for player 1
    -local custom_button =
    -Gui.get_concept('CustomButton')
    -
    -custom_button.update_data(1,function(tbl)
    -    tbl.clicks = tbl.clicks + 1 -- here we are incrementing the clicks by 1
    -end) -- player index 1
    -
    -
    -- Updating a value when a table is not used, alterative to get set
    --- so for this example assume that we did custom_button.set_data(1,0)
    -custom_button.update_data(1,function(value)
    -    return value + 1 -- here we are incrementing the value by 1, we may only be tracking clicks
    -end) -- player index 1
    -

    Concept Combined Instances

    +

    Test

    - # - Prototype:define_combined_store([category_callback], sync_callback) + # + expcore.gui
    -

    Used to add a both instance and data store which are linked together, new instances are synced to the current value, changing the stored value will change all instances

    -

    - Parameters: - -
      - - - - - -
    • - - category_callback - - : - - (function) - - when given will act as a way to turn an element into a string to act as a key; keys returned can over lap - - (optional) -
    • - - - - - -
    • - - sync_callback - - : - - (function) - - the function which is called to update an instance to match the store, this is called on all instances when concept.set_data or update_data is used - -
    • - - -
    - - Returns: -
      -
    • - (GuiConcept) - to allow chaining of functions -
    • -
    @@ -5639,59 +10869,21 @@ custom_button.update_data(1,fu - Usage: -
    -- Adding a check box which is a "global setting" synced between all players
    -local custom_button =
    -Gui.get_concept('checkbox'):clone('my_checkbox')
    -:set_caption('My Checkbox')
    -:set_tooltip('Clicking this check box will change it for everyone')
    -:on_state_changed(function(event)
    -    local element = event.element
    -    event.concept.set_data(element,element.state) -- Update the stored data to trigger an update of all other instances
    -end)
    -:define_combined_store(function(element,state) -- We could add a category function here if we wanted to
    -    element.state = state or false -- Note that the value passed may be nil if there is no stored value and no default set
    -end)
    - # - Prototype.sync_instance(element) + # + expcore.common
    -

    Will sync an instance to match the stored value based on the given sync callback

    -

    - Parameters: - -
      - - - - - -
    • - - element - - : - - (LuaGuiElement) - - the element that you want to have update - -
    • - - -
    - @@ -5702,73 +10894,71 @@ Gui.get_concept('checkbox'):clone(-- Setting the caption of this element to be the same as the stored value -local custom_button = -Gui.get_concept('CustomButton') - --- Used internally when first draw and automatically when the store updates -custom_button.sync_instance(element)
    -
    -

    Tests

    -
    - # - run_tests(player[, category]) + # + resources.color_presets +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + utils.event +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.store
    -

    Runs a set of gui tests to ensure that the system is working

    -

    - Parameters: - -
      - - - - - -
    • - - player - - : - - (LuaPlayer) - - the player that the guis are made for and who recives the results - -
    • - - - - - -
    • - - category - - : - - (string) - - when given only tests in this category are ran - - (optional) -
    • - - -
    - @@ -5779,9 +10969,6 @@ Gui.get_concept('CustomButton') - Usage: -
    -- Run all gui tests
    -Gui.run_tests(game.player)
    @@ -5800,7 +10987,7 @@ Gui.get_concept('CustomButton') generated by LDoc diff --git a/docs/core/Permissions-Groups.html b/docs/core/Permissions-Groups.html index 14d8fd23..cffa89f8 100644 --- a/docs/core/Permissions-Groups.html +++ b/docs/core/Permissions-Groups.html @@ -56,12 +56,10 @@ - - @@ -1434,7 +1432,7 @@ generated by LDoc diff --git a/docs/core/Roles.html b/docs/core/Roles.html index dbd23fa6..3187a4f7 100644 --- a/docs/core/Roles.html +++ b/docs/core/Roles.html @@ -60,12 +60,10 @@ - - @@ -3154,7 +3152,7 @@ generated by LDoc diff --git a/docs/core/Store.html b/docs/core/Store.html index 3b0822b1..97eda35f 100644 --- a/docs/core/Store.html +++ b/docs/core/Store.html @@ -53,12 +53,10 @@ - - @@ -1205,7 +1203,7 @@ this is similar to Store.get but will always return a table even if it is empty< generated by LDoc diff --git a/docs/core/Sudo.html b/docs/core/Sudo.html index 1e719894..53d24d08 100644 --- a/docs/core/Sudo.html +++ b/docs/core/Sudo.html @@ -53,12 +53,10 @@ - - @@ -546,7 +544,7 @@ generated by LDoc diff --git a/docs/guis/Player-List.html b/docs/guis/Player-List.html index 5afefbbf..5d601cbe 100644 --- a/docs/guis/Player-List.html +++ b/docs/guis/Player-List.html @@ -65,12 +65,10 @@ - - @@ -628,7 +626,7 @@ generated by LDoc diff --git a/docs/guis/Rocket-Info.html b/docs/guis/Rocket-Info.html index 8804e5c6..e3d10a38 100644 --- a/docs/guis/Rocket-Info.html +++ b/docs/guis/Rocket-Info.html @@ -65,12 +65,10 @@ - - @@ -631,7 +629,7 @@ generated by LDoc diff --git a/docs/guis/Science-Info.html b/docs/guis/Science-Info.html index 3a06ef3e..59dc47ca 100644 --- a/docs/guis/Science-Info.html +++ b/docs/guis/Science-Info.html @@ -65,12 +65,10 @@ - - @@ -451,7 +449,7 @@ generated by LDoc diff --git a/docs/guis/Task-List.html b/docs/guis/Task-List.html index 8178d793..a97b0a3e 100644 --- a/docs/guis/Task-List.html +++ b/docs/guis/Task-List.html @@ -65,12 +65,10 @@ - - @@ -634,7 +632,7 @@ generated by LDoc diff --git a/docs/guis/Warps-List.html b/docs/guis/Warps-List.html index c267b5c2..75ae9c1d 100644 --- a/docs/guis/Warps-List.html +++ b/docs/guis/Warps-List.html @@ -65,12 +65,10 @@ - - @@ -839,7 +837,7 @@ generated by LDoc diff --git a/docs/index.html b/docs/index.html index e1859d62..6466ea5d 100644 --- a/docs/index.html +++ b/docs/index.html @@ -56,11 +56,11 @@ Gui - Core Module - Gui - - - ExpStyle - Core Module - ExpStyle + Core Module - Gui + - This file is used to require all the different elements of the gui module + - each module has an outline here but for more details see their separate files in ./gui + - please read the files for more documentation that cant be shown here + - please note there is a rework planned but not started Permissions-Groups @@ -82,10 +82,6 @@ Core Module - Sudo - An extention of task and token to allow a single require to register and run functions bypassing all permissions. - - Toolbar - Core Module - Toolbar -

    Addons

    @@ -518,7 +514,7 @@ see ./expcore/commands.lua for more detailsgenerated by LDoc diff --git a/docs/modules/control.html b/docs/modules/control.html index 96f093f1..88f0ccce 100644 --- a/docs/modules/control.html +++ b/docs/modules/control.html @@ -72,12 +72,10 @@ - - @@ -353,7 +351,7 @@ generated by LDoc diff --git a/docs/modules/utils.alien_evolution_progress.html b/docs/modules/utils.alien_evolution_progress.html index d8b98af4..c377d74b 100644 --- a/docs/modules/utils.alien_evolution_progress.html +++ b/docs/modules/utils.alien_evolution_progress.html @@ -73,12 +73,10 @@ - - @@ -421,7 +419,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 8d316e12..3378c6d3 100644 --- a/docs/modules/utils.core.html +++ b/docs/modules/utils.core.html @@ -74,12 +74,10 @@ - - @@ -1166,7 +1164,7 @@ generated by LDoc diff --git a/docs/modules/utils.debug.html b/docs/modules/utils.debug.html index 40c5610d..b00a200b 100644 --- a/docs/modules/utils.debug.html +++ b/docs/modules/utils.debug.html @@ -72,12 +72,10 @@ - - @@ -656,7 +654,7 @@ generated by LDoc diff --git a/docs/modules/utils.dump_env.html b/docs/modules/utils.dump_env.html index 02727b03..e4dc2c92 100644 --- a/docs/modules/utils.dump_env.html +++ b/docs/modules/utils.dump_env.html @@ -72,12 +72,10 @@ - - @@ -325,7 +323,7 @@ generated by LDoc diff --git a/docs/modules/utils.event.html b/docs/modules/utils.event.html index dfa11db4..62b58139 100644 --- a/docs/modules/utils.event.html +++ b/docs/modules/utils.event.html @@ -73,12 +73,10 @@ - - @@ -1294,7 +1292,7 @@ generated by LDoc diff --git a/docs/modules/utils.event_core.html b/docs/modules/utils.event_core.html index 38eff51c..64b7e446 100644 --- a/docs/modules/utils.event_core.html +++ b/docs/modules/utils.event_core.html @@ -72,12 +72,10 @@ - - @@ -436,7 +434,7 @@ generated by LDoc diff --git a/docs/modules/utils.math.html b/docs/modules/utils.math.html index da148586..56d4d37f 100644 --- a/docs/modules/utils.math.html +++ b/docs/modules/utils.math.html @@ -72,12 +72,10 @@ - - @@ -355,7 +353,7 @@ generated by LDoc diff --git a/docs/modules/utils.recipe_locker.html b/docs/modules/utils.recipe_locker.html index e422551c..3f85b13d 100644 --- a/docs/modules/utils.recipe_locker.html +++ b/docs/modules/utils.recipe_locker.html @@ -73,12 +73,10 @@ - - @@ -443,7 +441,7 @@ generated by LDoc diff --git a/docs/modules/utils.state_machine.html b/docs/modules/utils.state_machine.html index daa620a5..98f7bcd5 100644 --- a/docs/modules/utils.state_machine.html +++ b/docs/modules/utils.state_machine.html @@ -73,12 +73,10 @@ - - @@ -754,7 +752,7 @@ generated by LDoc diff --git a/docs/modules/utils.table.html b/docs/modules/utils.table.html index b90becff..3cbf7778 100644 --- a/docs/modules/utils.table.html +++ b/docs/modules/utils.table.html @@ -74,12 +74,10 @@ - - @@ -1420,7 +1418,7 @@ generated by LDoc diff --git a/docs/modules/utils.task.html b/docs/modules/utils.task.html index db13570d..00472a97 100644 --- a/docs/modules/utils.task.html +++ b/docs/modules/utils.task.html @@ -73,12 +73,10 @@ - - @@ -653,7 +651,7 @@ generated by LDoc diff --git a/docs/modules/utils.timestamp.html b/docs/modules/utils.timestamp.html index ef9b3b28..99473b65 100644 --- a/docs/modules/utils.timestamp.html +++ b/docs/modules/utils.timestamp.html @@ -72,12 +72,10 @@ - - @@ -444,7 +442,7 @@ generated by LDoc diff --git a/docs/topics/license.html b/docs/topics/license.html index 2268d7de..e28db313 100644 --- a/docs/topics/license.html +++ b/docs/topics/license.html @@ -53,12 +53,10 @@ - - @@ -791,7 +789,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 b5eed503..cc1c1178 100644 --- a/docs/topics/readme.md.html +++ b/docs/topics/readme.md.html @@ -53,12 +53,10 @@ - - @@ -335,7 +333,7 @@ generated by LDoc