From f7cff8b2361825ecb8f6e6d88adf2cf64c53b6d5 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Thu, 24 Oct 2019 01:44:41 +0100 Subject: [PATCH] Task List Updated --- config/_file_loader.lua | 4 +- config/tasks.lua | 11 +- 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 | 35 +- 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 | 875 +++++++++++++++++- docs/core/Permissions-Groups.html | 2 +- docs/core/Roles.html | 2 +- docs/core/Store.html | 29 +- 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 | 156 +++- 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 | 391 ++++++-- expcore/store.lua | 34 +- modules/control/tasks.lua | 2 +- modules/gui/task-list.lua | 624 ++++++++----- 98 files changed, 1849 insertions(+), 488 deletions(-) diff --git a/config/_file_loader.lua b/config/_file_loader.lua index 44f73644..b7ccbd92 100644 --- a/config/_file_loader.lua +++ b/config/_file_loader.lua @@ -42,15 +42,13 @@ return { --'modules.gui.rocket-info', --'modules.gui.science-info', --'modules.gui.warp-list', - --'modules.gui.task-list', + 'modules.gui.task-list', --'modules.gui.player-list', --'modules.commands.debug', - 'expcore.gui', -- 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 } \ No newline at end of file diff --git a/config/tasks.lua b/config/tasks.lua index 95165ee0..994acff8 100644 --- a/config/tasks.lua +++ b/config/tasks.lua @@ -2,8 +2,11 @@ -- @config Tasks return { - any_user_can_add_new_task = true, --- @setting any_user_can_add_new_task when false only people with edit permission can make new reports - user_can_edit_own_tasks = true, --- @setting user_can_edit_own_tasks when false only people with edit permission can edit reports - only_admins_can_edit = false, --- @setting only_admins_can_edit true will hide the edit and delete buttons from non (game) admins - edit_tasks_role_permission = 'gui/task-list/edit' --- @setting edit_tasks_role_permission value used with custom permission system + -- values can be all, admin, expcore.roles, none + allow_add_task = 'all', --- @setting allow_add_task dictates who is allowed to add new tasks; values: all, admin, expcore.roles, none + expcore_roles_add_permission = 'gui/task-list/add', --- @setting expcore_roles_add_permission if expcore.roles is used then this is the required permission + -- values can be all, admin, expcore.roles, none + allow_edit_task = 'expcore.roles', --- @setting allow_edit_task dictates who is allowed to edit existing tasks; values: all, admin, expcore.roles, none + expcore_roles_edit_permission = 'gui/task-list/edit', --- @setting expcore_roles_edit_permission if expcore.roles is used then this is the required permission + user_can_edit_own_tasks = true --- @settings if true then the user who made the task can edit it regardless of the allow_edit_task setting } \ No newline at end of file diff --git a/docs/addons/Advanced-Start.html b/docs/addons/Advanced-Start.html index 4871b8c9..4fc1a161 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 3efd7ce5..31bafcd7 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 c5d3cfc4..740ed70e 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 57a4a065..6fb21b76 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 f42f7dee..4f5b7ae2 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 6f540b7d..8983690a 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 e9f689ac..e0085ca5 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 06a8e29a..5de171a9 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 806b86fd..08b4fc10 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 bcfab620..dcc7f831 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 7f9b0c0a..54a470ef 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 0a936c4e..894d9fd7 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 e7e42cdd..bb480f1c 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 53b422c3..11a3faa5 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 17ef4f9d..fb090d39 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 880bb18e..1960d836 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 f8d25958..ac910592 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 b7d54d80..5488f96a 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 d279fe65..371db9aa 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 8458181f..ef15886c 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 214140d6..5f07e558 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 421f28a9..a892d1aa 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 a31f9a45..c6e4fa94 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 439294a8..d7dd8363 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 98e6942b..6225e155 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 1957df69..2c739395 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 0f9bc8b1..d94c73f6 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 f72dbee2..24f01cf0 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 60783e88..2dd125fd 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 353738fe..8a4262f3 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 d33d1547..884b4a42 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 94b0896f..7d0e5d3d 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 e7bb072a..9612f09e 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 ee1e2dd2..021275cd 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 157b0311..dd7c7ddb 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 59a9ed26..689ef12e 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 b299522c..9f3db256 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 42155a89..de12ef31 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 8128d402..76a3b440 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 0932f52e..d3162a9e 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 1e635943..38e0eee2 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 7214429c..f9d7156b 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 21a5ee90..9331d05b 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 1ab7621e..3deb9a8e 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 bd67fe6b..2d91ee39 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 d775b006..64fa59aa 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 02436326..f648a0f5 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 2d2a05a7..267b19c9 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 5141d747..0449a9f1 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 f011e724..8d50f302 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 e435071a..33b1ba00 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 bea29f94..6aa0aa00 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 f271bf65..df64e68c 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 a1a68698..0cd0d9f7 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 e4f9760a..8a8ae44b 100644 --- a/docs/configs/Tasks.html +++ b/docs/configs/Tasks.html @@ -241,16 +241,16 @@ - any_user_can_add_new_task + allow_add_task - user_can_edit_own_tasks + expcore_roles_add_permission - only_admins_can_edit + allow_edit_task - edit_tasks_role_permission + expcore_roles_edit_permission @@ -264,15 +264,15 @@
- # - any_user_can_add_new_task + # + allow_add_task

-

when false only people with edit permission can make new reports

+

dictates who is allowed to add new tasks; values: all, admin, expcore.roles, none

@@ -291,15 +291,16 @@
- # - user_can_edit_own_tasks + # + expcore_roles_add_permission

-

when false only people with edit permission can edit reports

+

if expcore.roles is used then this is the required permission + values can be all, admin, expcore.roles, none

@@ -318,15 +319,15 @@
- # - only_admins_can_edit + # + allow_edit_task

-

true will hide the edit and delete buttons from non (game) admins

+

dictates who is allowed to edit existing tasks; values: all, admin, expcore.roles, none

@@ -345,15 +346,15 @@
- # - edit_tasks_role_permission + # + expcore_roles_edit_permission

-

value used with custom permission system

+

if expcore.roles is used then this is the required permission

@@ -384,7 +385,7 @@ generated by LDoc
diff --git a/docs/configs/Warnings.html b/docs/configs/Warnings.html index 751529ef..2a237eb2 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 3840e9b9..5ef899b2 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 8ed47a2e..a809745f 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 2cac6422..12a57823 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 16391654..a239a42c 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 831e5343..a11e1edc 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 c68201ec..cbe14682 100644 --- a/docs/control/Tasks.html +++ b/docs/control/Tasks.html @@ -998,7 +998,7 @@ Tasks.update_task(task_id,'We need more iron!',game. generated by LDoc diff --git a/docs/control/Warnings.html b/docs/control/Warnings.html index ff7f7802..84f5e53c 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 7791b32f..16a7f9de 100644 --- a/docs/control/Warps.html +++ b/docs/control/Warps.html @@ -1563,7 +1563,7 @@ Warps.make_warp_tag(warp_id) generated by LDoc diff --git a/docs/core/Commands.html b/docs/core/Commands.html index 075e5bb8..545ac82f 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 caba804c..fedadfc1 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 74601e95..c438edc4 100644 --- a/docs/core/Gui.html +++ b/docs/core/Gui.html @@ -48,6 +48,7 @@ + @@ -214,6 +215,7 @@ + @@ -245,34 +247,58 @@

Usage

-- Defining a button that prints the player's name
 local example_button =
-Gui.new_element{
+Gui.element{
     type = 'button',
     caption = 'Example Button'
 }
-:on_click(function(event)
-    local player = event.player
+:on_click(function(player,element,event)
     player.print(player.name)
 end)
-
-- Defining using a custom function
+    
-- Defining a button with a custom style
+local example_button =
+Gui.element{
+    type = 'button',
+    caption = 'Example Button'
+}
+:style{
+    height = 25,
+    width = 100
+}
+:on_click(function(player,element,event)
+    player.print(player.name)
+end)
+
-- Defining a button using a custom function
 local example_flow_with_button =
-Gui.new_element(function(event_trigger,parent)
-    local flow =
+Gui.element(function(event_trigger,parent)
+    -- Add the flow the button is in
+    local flow =
     parent.add{
         name = 'example_flow',
         type = 'flow'
     }
 
-    local element =
+    -- Get the players name
+    local player = game.players[parent.player_index]
+    local player_name = player.name
+
+    -- Add the button
+    local element =
     flow.add{
         name = event_trigger,
         type = 'button',
-        caption = 'Example Button'
+        caption = 'Example Button: '..player_name
     }
 
-    return element
+    -- Set the style of the button
+    local style = element.style
+    style.height = 25
+    style.width = 100]
+    style.font_color = player.color
+
+    -- Return the element
+    return element
 end)
-:on_click(function(event)
-    local player = event.player
+:on_click(function(player,element,event)
     player.print(player.name)
 end)
-- Drawing an element
@@ -321,7 +347,7 @@ Gui.new_element(function(event_trigger,parent)
     
     
     _prototype_element
-    The element prototype which is returned from Gui.new_element
+    The element prototype which is returned from Gui.element
     
     
     _mt_element
@@ -348,10 +374,14 @@ Gui.new_element(function(event_trigger,parent)
     
     
     
-    new_element(element_define)
+    element(element_define)
     Base function used to define new elements, can be used with a table or with a function
     
     
+    Gui._prototype_element:style(style_define)
+    Extension of Gui.element when using the table method, values applied after the element is drawn
+    
+    
     Gui._prototype_element:add_to_top_flow([authenticator])
     Adds an element to be drawn to the top flow when a player joins
     
@@ -428,6 +458,10 @@ Gui.new_element(function(event_trigger,parent)
     Button which toggles the top flow elements
     
     
+    top_flow_button_style
+    The style that should be used for buttons on the top flow
+    
+    
     get_top_flow(player)
     Gets the flow which contains the elements for the top flow
     
@@ -465,6 +499,42 @@ Gui.new_element(function(event_trigger,parent)
     
     
     
+    
+    
+    

Helper Functions

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
get_player_from_element(element)Get the player that owns a gui element
toggle_enabled_state(element[, state])Will toggle the enabled state of an element or set it to the one given
toggle_visible_state(element[, state])Will toggle the visible state of an element or set it to the one given
destroy_if_valid(element)Destory a gui element without causing any errors, likly if the element may have already been removed
alignment(parent[, horizontal_align='right'][, vertical_align='center'][, name='alignment'])Draw a flow that has custom element alignments, default is right align
scroll_table(parent, height, column_count[, name='scroll'])Draw a scroll pane that has a table inside of it
header(parent, caption[, tooltip][, add_alignment=false][, name='header'])Used to add a header to a frame, this has the option for a custom right alignment flow for buttons

@@ -643,7 +713,7 @@ Gui.new_element(function(event_trigger,parent)
-

The element prototype which is returned from Gui.new_element

+

The element prototype which is returned from Gui.element

@@ -764,8 +834,8 @@ Gui.new_element(function(event_trigger,parent)
- # - new_element(element_define) + # + element(element_define)
@@ -818,27 +888,115 @@ Gui.new_element(function(event_trigger,parent) Usage:
-- Defining an element with a table
 local example_button =
-Gui.new_element{
+Gui.element{
     type = 'button',
     caption = 'Example Button'
 }
-- Defining an element with a function
 local example_flow_with_button =
-Gui.new_element(function(event_trigger,parent)
-    local flow =
+Gui.element(function(event_trigger,parent,...)
+    -- Add the flow the button is in
+    local flow =
     parent.add{
         name = 'example_flow',
         type = 'flow'
     }
 
-    local element =
+    -- Add the button
+    local element =
     flow.add{
         name = event_trigger,
         type = 'button',
         caption = 'Example Button'
     }
 
-    return element
+    -- Set the style of the button
+    local style = element.style
+    style.height = 25
+    style.width = 100
+
+    -- Return the element
+    return element
+end)
+ + +
+
+
+
+ # + Gui._prototype_element:style(style_define) +
+
+
+
+ +

Extension of Gui.element when using the table method, values applied after the element is drawn

+

+ + + Parameters: + +
    + + + + + +
  • + + style_define + + : + + (table or function) + + used to define how the style is applied, using a table is the simplist way of doing this + +
  • + + +
+ + + + + Returns: +
    +
  • + (table) + the new element define that is used to register events to this element +
  • +
+ + + + + + + + Usage: +
-- Setting the height and width of the example button
+local example_button =
+Gui.element{
+    type = 'button',
+    caption = 'Example Button'
+}
+:style{
+    height = 25,
+    width = 100
+}
+
-- Using a function to set the style
+local example_button =
+Gui.element{
+    type = 'button',
+    caption = 'Example Button'
+}
+:style(function(style,element,...)
+    local player = game.players[element.player_index]
+    style.height = 25
+    style.width = 100
+    style.font_color = player.color
 end)
@@ -884,6 +1042,13 @@ Gui.new_element(function(event_trigger,parent) + Returns: +
    +
  • + (table) + the new element define that is used to register events to this element +
  • +
@@ -941,6 +1106,13 @@ Gui.new_element(function(event_trigger,parent) + Returns: +
    +
  • + (table) + the new element define that is used to register events to this element +
  • +
@@ -1568,6 +1740,33 @@ Gui.new_element(function(event_trigger,parent) + + + + + + +
+
+
+
+ # + top_flow_button_style +
+
+
+
+ +

The style that should be used for buttons on the top flow

+

+ + + + + + + + @@ -2004,6 +2203,638 @@ Gui.new_element(function(event_trigger,parent) Gui.toggle_top_flow(game.player,example_flow_with_button,true)
+
+ +

Helper Functions

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

Get the player that owns a gui element

+

+ + + Parameters: + +
    + + + + + +
  • + + element + + : + + (LuaGuiElement) + + the element that you want to get the owner of + +
  • + + +
+ + + + + Returns: +
    +
  • + (LuaPlayer) + the player that owns this element +
  • +
+ + + + + + + + Usage: +
-- Geting the owner of an element
+local player = Gui.get_player_from_element(element)
+ + +
+
+
+
+ # + toggle_enabled_state(element[, state]) +
+
+
+
+ +

Will toggle the enabled state of an element or set it to the one given

+

+ + + Parameters: + +
    + + + + + +
  • + + element + + : + + (LuaGuiElement) + + the element that you want to toggle the state of + +
  • + + + + + +
  • + + state + + : + + (boolean) + + the state that you want to set + + (optional) +
  • + + +
+ + + + + Returns: +
    +
  • + (boolean) + the new enabled state that the element has +
  • +
+ + + + + + + + Usage: +
-- Toggling the the enabled state
+local new_enabled_state = Gui.toggle_enabled_state(element)
+ + +
+
+
+
+ # + toggle_visible_state(element[, state]) +
+
+
+
+ +

Will toggle the visible state of an element or set it to the one given

+

+ + + Parameters: + +
    + + + + + +
  • + + element + + : + + (LuaGuiElement) + + the element that you want to toggle the state of + +
  • + + + + + +
  • + + state + + : + + (boolean) + + the state that you want to set + + (optional) +
  • + + +
+ + + + + Returns: +
    +
  • + (boolean) + the new visible state that the element has +
  • +
+ + + + + + + + Usage: +
-- Toggling the the visible state
+local new_visible_state = Gui.toggle_visible_state(element)
+ + +
+
+
+
+ # + destroy_if_valid(element) +
+
+
+
+ +

Destory a gui element without causing any errors, likly if the element may have already been removed

+

+ + + Parameters: + +
    + + + + + +
  • + + element + + : + + (LuaGuiElement) + + the element that you want to remove + +
  • + + +
+ + + + + Returns: +
    +
  • + (boolean) + true if the element was valid and has been removed +
  • +
+ + + + + + + + Usage: +
-- Likely use case for element not existing
+Gui.destroy_if_valid(element[child_name])
+ + +
+
+
+
+ # + alignment(parent[, horizontal_align='right'][, vertical_align='center'][, name='alignment']) +
+
+
+
+ +

Draw a flow that has custom element alignments, default is right align

+

+ + + Parameters: + +
    + + + + + +
  • + + parent + + : + + (LuaGuiElement) + + the parent element that the alignment flow will be added to + +
  • + + + + + +
  • + + horizontal_align + + : + + (string) + + the horizontal alignment of the elements in the flow + + (default: 'right') +
  • + + + + + +
  • + + vertical_align + + : + + (string) + + the vertical alignment of the elements in the flow + + (default: 'center') +
  • + + + + + +
  • + + name + + : + + (string) + + the name of the alignment flow + + (default: 'alignment') +
  • + + +
+ + + + + Returns: + + + + + + + + + Usage: +
-- Adding a right align flow
+local alignment = Gui.alignment(element,'example_right_alignment')
+
-- Adding a horizontal center and top align flow
+local alignment = Gui.alignment(element,'example_center_top_alignment','center','top')
+ + +
+
+
+
+ # + scroll_table(parent, height, column_count[, name='scroll']) +
+
+
+
+ +

Draw a scroll pane that has a table inside of it

+

+ + + Parameters: + +
    + + + + + +
  • + + parent + + : + + (LuaGuiElement) + + the parent element that the scroll table will be added to + +
  • + + + + + +
  • + + height + + : + + (number) + + the maximum height for the scroll pane + +
  • + + + + + +
  • + + column_count + + : + + (number) + + the number of columns that the table will have + +
  • + + + + + +
  • + + name + + : + + (string) + + the name of the scroll pane that is added, the table is always called 'table' + + (default: 'scroll') +
  • + + +
+ + + + + Returns: + + + + + + + + + Usage: +
-- Adding a scroll table with max height of 200 and column count of 3
+local scroll_table = Gui.scroll_table(element,'example_scroll_table',200,3)
+ + +
+
+
+
+ # + header(parent, caption[, tooltip][, add_alignment=false][, name='header']) +
+
+
+
+ +

Used to add a header to a frame, this has the option for a custom right alignment flow for buttons

+

+ + + Parameters: + +
    + + + + + +
  • + + parent + + : + + (LuaGuiElement) + + the parent element that the header will be added to + +
  • + + + + + +
  • + + caption + + : + + (string or LocalizedString) + + the caption that will be shown on the header + +
  • + + + + + +
  • + + tooltip + + : + + (string or LocalizedString) + + the tooltip that will be shown on the header + + (optional) +
  • + + + + + +
  • + + add_alignment + + : + + (boolean) + + when true an alignment flow will be added for buttons + + (default: false) +
  • + + + + + +
  • + + name + + : + + (string) + + the name of the header that is being added, the alignment is always called 'alignment' + + (default: 'header') +
  • + + +
+ + + + + Returns: +
    +
  • + (LuaGuiElement) + either the header or the header alignment if add_alignment is true +
  • +
+ + + + + + + + Usage: +
-- Adding a custom header
+local header_alignment = Gui.header(
+    element,
+    'example_header',
+    'Example Caption',
+    'Example Tooltip',
+    true
+)
+ +
@@ -2020,7 +2851,7 @@ Gui.new_element(function(event_trigger,parent) generated by LDoc diff --git a/docs/core/Permissions-Groups.html b/docs/core/Permissions-Groups.html index d684f92e..13bacb25 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 2e261b19..cfb25893 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 c977f109..f5eb98bb 100644 --- a/docs/core/Store.html +++ b/docs/core/Store.html @@ -262,7 +262,7 @@ Store.set(scenario_diffculty,'hard') end) -- When any key in the store is changed this function will trigger -Store.watch(player_scores,function(value,key) +Store.watch(player_scores,function(value,key,old_value) game.print(key..' now has a score of '..value) end) @@ -370,7 +370,7 @@ Store.set(player_scores,game.player,10) Used to trigger watcher functions, this may be used to trigger them if you did not use Store.update or Store.set - raw_trigger(store[, key][, value]) + raw_trigger(store[, key][, value][, old_value]) Used to trigger watcher functions, the value and key are passed directly to the watchers regardless if the value is correct @@ -791,7 +791,7 @@ Store.set(player_scores,game.player,10) end) -- Register the watcher so that when we change the value the message is printed -Store.watch(player_scores,function(value,key) +Store.watch(player_scores,function(value,key,old_value) game.print(key..' now has a score of '..value) end) @@ -1361,7 +1361,7 @@ Store.set(player_scores,game.player,10)
# - raw_trigger(store[, key][, value]) + raw_trigger(store[, key][, value][, old_value])
@@ -1426,6 +1426,23 @@ Store.set(player_scores,game.player,10) + + + +
  • + + old_value + + : + + (any) + + the old value that was at this key or store often the same if value is a table, passed directly to the watcher + + (optional) +
  • + + @@ -1445,7 +1462,7 @@ Store.set(player_scores,game.player,10) -- Trigger the watchers with a fake change of diffculty -- This is mostly used internally but it can be useful in other cases -Store.raw_trigger(scenario_diffculty,nil,'normal')
    +Store.raw_trigger(scenario_diffculty,nil,'normal','normal')
    @@ -1464,7 +1481,7 @@ Store.set(player_scores,game.player,10) generated by LDoc diff --git a/docs/core/Sudo.html b/docs/core/Sudo.html index ea78d5a3..9a0a180b 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 d1ca6a0e..e0e633ba 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 21253ddc..5714de34 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 3dc31aa5..12c80988 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 454a6901..a16009c7 100644 --- a/docs/guis/Task-List.html +++ b/docs/guis/Task-List.html @@ -271,27 +271,43 @@ add_new_task - Button in the header to add a new task + Button displayed in the ehader bar, used to add a new task confirm_edit - Used to save changes to a task + Button displayed next to tasks which the user is currently editing, used to save changes cancel_edit - Used to cancel any changes you made to a task + Button displayed next to tasks which the user is currently editing, used to discard changes discard_task - Removes the task from the list + Button displayed next to tasks which the user is can edit, used to delete a task from the list edit_task - Opens edit mode for the task + Button displayed next to tasks which the user is can edit, used to start editing a task - task_list - Registers the task list + add_task_base + Set of three elements which make up each row of the task table + + + task_label + Default state for a task, contains only a label with the task message + + + task_editing + Editing state for a task, contrins a text field and the two edit buttons + + + task_list_container + Main task list container for the left flow + + + task_list_toggle + Button on the top flow used to toggle the task list container @@ -465,7 +481,7 @@
    -

    Button in the header to add a new task

    +

    Button displayed in the ehader bar, used to add a new task

    @@ -492,7 +508,7 @@
    -

    Used to save changes to a task

    +

    Button displayed next to tasks which the user is currently editing, used to save changes

    @@ -519,7 +535,7 @@
    -

    Used to cancel any changes you made to a task

    +

    Button displayed next to tasks which the user is currently editing, used to discard changes

    @@ -546,7 +562,7 @@
    -

    Removes the task from the list

    +

    Button displayed next to tasks which the user is can edit, used to delete a task from the list

    @@ -573,7 +589,7 @@
    -

    Opens edit mode for the task

    +

    Button displayed next to tasks which the user is can edit, used to start editing a task

    @@ -593,14 +609,122 @@
    - # - task_list + # + add_task_base
    -

    Registers the task list

    +

    Set of three elements which make up each row of the task table

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + task_label +
    +
    +
    +
    + +

    Default state for a task, contains only a label with the task message

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + task_editing +
    +
    +
    +
    + +

    Editing state for a task, contrins a text field and the two edit buttons

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + task_list_container +
    +
    +
    +
    + +

    Main task list container for the left flow

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + task_list_toggle +
    +
    +
    +
    + +

    Button on the top flow used to toggle the task list container

    @@ -632,7 +756,7 @@ generated by LDoc
    diff --git a/docs/guis/Warps-List.html b/docs/guis/Warps-List.html index a4647a51..18297a4b 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 cd8ed91c..a5e3d006 100644 --- a/docs/index.html +++ b/docs/index.html @@ -511,7 +511,7 @@ see ./expcore/commands.lua for more details generated by LDoc diff --git a/docs/modules/control.html b/docs/modules/control.html index 2b73d7da..6cca966d 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 fc152587..6291b757 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 d3a78a5d..b6393f5d 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 661eb841..c5882630 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 fff59dbb..2927bed7 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 663e8dcb..49848f9e 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 26e97c55..ec13ecfc 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 c192045d..e4815bc6 100644 --- a/docs/modules/utils.math.html +++ b/docs/modules/utils.math.html @@ -353,7 +353,7 @@ generated by LDoc diff --git a/docs/modules/utils.recipe_locker.html b/docs/modules/utils.recipe_locker.html index 51c8fb76..717e7598 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 5708101d..aeb9fd7f 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 2c9404e6..13f18afb 100644 --- a/docs/modules/utils.table.html +++ b/docs/modules/utils.table.html @@ -1418,7 +1418,7 @@ generated by LDoc diff --git a/docs/modules/utils.task.html b/docs/modules/utils.task.html index f1a4a0be..47a1f7d6 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 c22b2df7..df8680e8 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 6901e6e6..ffb5dd8e 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 e472eb59..7dba1a3c 100644 --- a/docs/topics/readme.md.html +++ b/docs/topics/readme.md.html @@ -338,7 +338,7 @@ Please report these errors to [the issues page](issues). generated by LDoc diff --git a/expcore/gui.lua b/expcore/gui.lua index 8e25a7c3..b6237b87 100644 --- a/expcore/gui.lua +++ b/expcore/gui.lua @@ -5,35 +5,60 @@ @usage-- Defining a button that prints the player's name local example_button = -Gui.new_element{ +Gui.element{ type = 'button', caption = 'Example Button' } -:on_click(function(event) - local player = event.player +:on_click(function(player,element,event) player.print(player.name) end) -@usage-- Defining using a custom function +@usage-- Defining a button with a custom style +local example_button = +Gui.element{ + type = 'button', + caption = 'Example Button' +} +:style{ + height = 25, + width = 100 +} +:on_click(function(player,element,event) + player.print(player.name) +end) + +@usage-- Defining a button using a custom function local example_flow_with_button = -Gui.new_element(function(event_trigger,parent) +Gui.element(function(event_trigger,parent) + -- Add the flow the button is in local flow = parent.add{ name = 'example_flow', type = 'flow' } + -- Get the players name + local player = game.players[parent.player_index] + local player_name = player.name + + -- Add the button local element = flow.add{ name = event_trigger, type = 'button', - caption = 'Example Button' + caption = 'Example Button: '..player_name } + -- Set the style of the button + local style = element.style + style.height = 25 + style.width = 100] + style.font_color = player.color + + -- Return the element return element end) -:on_click(function(event) - local player = event.player +:on_click(function(player,element,event) player.print(player.name) end) @@ -62,14 +87,16 @@ local Gui = { --- An index used for debuging to find the file where different elements where registered -- @table file_paths file_paths = {}, - --- The element prototype which is returned from Gui.new_element + --- The element prototype which is returned from Gui.element -- @table _prototype_element _prototype_element = {}, --- The prototype metatable applied to new element defines -- @table _mt_element _mt_element = { __call = function(self,parent,...) - return self._draw(self.name,parent,...) + local element = self._draw(self.name,parent,...) + if self._style then self._style(element.style,element,...) end + return element end } } @@ -85,20 +112,22 @@ Gui._mt_element.__index = Gui._prototype_element @usage-- Defining an element with a table local example_button = -Gui.new_element{ +Gui.element{ type = 'button', caption = 'Example Button' } @usage-- Defining an element with a function local example_flow_with_button = -Gui.new_element(function(event_trigger,parent) +Gui.element(function(event_trigger,parent,...) + -- Add the flow the button is in local flow = parent.add{ name = 'example_flow', type = 'flow' } + -- Add the button local element = flow.add{ name = event_trigger, @@ -106,11 +135,17 @@ Gui.new_element(function(event_trigger,parent) caption = 'Example Button' } + -- Set the style of the button + local style = element.style + style.height = 25 + style.width = 100 + + -- Return the element return element end) ]] -function Gui.new_element(element_define) +function Gui.element(element_define) -- Set the metatable to allow access to register events local element = setmetatable({}, Gui._mt_element) @@ -139,8 +174,54 @@ function Gui.new_element(element_define) return element end +--[[-- Extension of Gui.element when using the table method, values applied after the element is drawn +@tparam ?table|function style_define used to define how the style is applied, using a table is the simplist way of doing this +@treturn table the new element define that is used to register events to this element + +@usage-- Setting the height and width of the example button +local example_button = +Gui.element{ + type = 'button', + caption = 'Example Button' +} +:style{ + height = 25, + width = 100 +} + +@usage-- Using a function to set the style +local example_button = +Gui.element{ + type = 'button', + caption = 'Example Button' +} +:style(function(style,element,...) + local player = game.players[element.player_index] + style.height = 25 + style.width = 100 + style.font_color = player.color +end) + +]] +function Gui._prototype_element:style(style_define) + -- Add the defination function + if type(style_define) == 'table' then + self._style = function(style) + for key,value in pairs(style_define) do + style[key] = value + end + end + else + self._style = style_define + end + + -- Return the element so event handers can be accessed + return self +end + --[[-- Adds an element to be drawn to the top flow when a player joins @tparam[opt] function authenticator called during toggle or update to decide if the element should be visible +@treturn table the new element define that is used to register events to this element @usage-- Adding the example button example_button:add_to_top_flow(function(player) @@ -151,10 +232,12 @@ end) ]] function Gui._prototype_element:add_to_top_flow(authenticator) Gui.top_elements[self.name] = authenticator or true + return self end --[[-- Adds an element to be drawn to the left flow when a player joins @tparam[opt] ?boolean|function open_on_join called during first darw to decide if the element is visible +@treturn table the new element define that is used to register events to this element @usage-- Adding the example button example_flow_with_button:add_to_left_flow(true) @@ -162,6 +245,7 @@ example_flow_with_button:add_to_left_flow(true) ]] function Gui._prototype_element:add_to_left_flow(open_on_join) Gui.left_elements[self.name] = open_on_join or false + return self end -- This function is called for event event @@ -186,7 +270,7 @@ local function general_event_handler(event) end event.player = player - local success, err = pcall(handler,event) + local success, err = pcall(handler,player,element,event) if not success then error('There as been an error with an event handler for a gui element:\n\t'..err) end @@ -259,31 +343,23 @@ Gui._prototype_element.on_value_changed = event_handler_factory(defines.events.o --- Button which toggles the top flow elements -- @element toggle_top_flow local toggle_top_flow = -Gui.new_element(function(event_trigger,parent) - -- Draw the element - local element = - parent.add{ - name = event_trigger, - type = 'button', - style = mod_gui.button_style, - caption = '<', - tooltip = {'gui_util.button_tooltip'} - } - - -- Change its style - local style = element.style - style.width = 18 - style.height = 36 - style.padding = 0 - style.font = 'default-small-bold' - - -- Return the element - return element -end) -:on_click(function(event) - Gui.toggle_top_flow(event.player) +Gui.element{ + type = 'button', + style = 'back_button', + tooltip = {'gui_util.button_tooltip'} +} +:style{ + width = 18, + height = 36 +} +:on_click(function(player,_,_) + Gui.toggle_top_flow(player) end) +--- The style that should be used for buttons on the top flow +-- @field Gui.top_flow_button_style +Gui.top_flow_button_style = mod_gui.button_style + --[[-- Gets the flow which contains the elements for the top flow @function Gui.get_top_flow(player) @tparam LuaPlayer player the player that you want to get the flow for @@ -305,7 +381,7 @@ Gui.update_top_flow(game.player) function Gui.update_top_flow(player) local top_flow = Gui.get_top_flow(player) local toggle_button = top_flow[toggle_top_flow.name] - local is_visible = toggle_button.caption == '<' + local is_visible = toggle_button.style.name == 'back_button' -- Set the visible state of all elements in the flow for name,authenticator in pairs(Gui.top_elements) do @@ -335,7 +411,7 @@ Gui.toggle_top_flow(game.player,true) function Gui.toggle_top_flow(player,state) local top_flow = Gui.get_top_flow(player) local toggle_button = top_flow[toggle_top_flow.name] - local new_state = state or toggle_button.caption == '>' + local new_state = state or toggle_button.style.name == 'forward_button' -- Set the visible state of all elements in the flow for name,authenticator in pairs(Gui.top_elements) do @@ -344,11 +420,15 @@ function Gui.toggle_top_flow(player,state) -- Change the style of the toggle button if new_state then - toggle_button.caption = '<' - toggle_button.style.height = 34 + toggle_button.style = 'back_button' + local style = toggle_button.style + style.height = 36 + style.width = 18 else - toggle_button.caption = '>' - toggle_button.style.height = 24 + toggle_button.style = 'forward_button' + local style = toggle_button.style + style.height = 20 + style.width = 18 end return new_state @@ -360,29 +440,17 @@ end --- Button which hides the elements in the left flow -- @element hide_left_flow local hide_left_flow = -Gui.new_element(function(event_trigger,parent) - -- Draw the element - local element = - parent.add{ - name = event_trigger, - type = 'button', - style = mod_gui.button_style, - caption = '<', - tooltip = {'expcore-gui.left-button-tooltip'} - } - - -- Change its style - local style = element.style - style.width = 18 - style.height = 36 - style.padding = 0 - style.font = 'default-small-bold' - - -- Return the element - return element -end) -:on_click(function(event) - Gui.hide_left_flow(event.player) +Gui.element{ + type = 'button', + style = 'back_button', + tooltip = {'expcore-gui.left-button-tooltip'} +} +:style{ + width = 18, + height = 36 +} +:on_click(function(player,_,_) + Gui.hide_left_flow(player) end) --[[-- Gets the flow which contains the elements for the left flow @@ -486,4 +554,195 @@ Event.add(defines.events.on_player_joined_game,function(event) hide_left.visible = show_hide_left end) +--- Helper Functions. +-- @section helperFunctions + +--[[-- Get the player that owns a gui element +@tparam LuaGuiElement element the element that you want to get the owner of +@treturn LuaPlayer the player that owns this element + +@usage-- Geting the owner of an element +local player = Gui.get_player_from_element(element) + +]] +function Gui.get_player_from_element(element) + if not element or not element.valid then return end + return game.players[element.player_index] +end + +--[[-- Will toggle the enabled state of an element or set it to the one given +@tparam LuaGuiElement element the element that you want to toggle the state of +@tparam[opt] boolean state the state that you want to set +@treturn boolean the new enabled state that the element has + +@usage-- Toggling the the enabled state +local new_enabled_state = Gui.toggle_enabled_state(element) + +]] +function Gui.toggle_enabled_state(element,state) + if not element or not element.valid then return end + local new_state = state or not element.enabled + element.enabled = new_state + return new_state +end + +--[[-- Will toggle the visible state of an element or set it to the one given +@tparam LuaGuiElement element the element that you want to toggle the state of +@tparam[opt] boolean state the state that you want to set +@treturn boolean the new visible state that the element has + +@usage-- Toggling the the visible state +local new_visible_state = Gui.toggle_visible_state(element) + +]] +function Gui.toggle_visible_state(element,state) + if not element or not element.valid then return end + local new_state = state or not element.visible + element.visible = new_state + return new_state +end + +--[[-- Destory a gui element without causing any errors, likly if the element may have already been removed +@tparam LuaGuiElement element the element that you want to remove +@treturn boolean true if the element was valid and has been removed + +@usage-- Likely use case for element not existing +Gui.destroy_if_valid(element[child_name]) + +]] +function Gui.destroy_if_valid(element) + if not element or not element.valid then return false end + element.destroy() + return true +end + +--[[-- Draw a flow that has custom element alignments, default is right align +@tparam LuaGuiElement parent the parent element that the alignment flow will be added to +@tparam[opt='right'] string horizontal_align the horizontal alignment of the elements in the flow +@tparam[opt='center'] string vertical_align the vertical alignment of the elements in the flow +@tparam[opt='alignment'] string name the name of the alignment flow +@treturn LuaGuiElement the alignment flow that was created + +@usage-- Adding a right align flow +local alignment = Gui.alignment(element,'example_right_alignment') + +@usage-- Adding a horizontal center and top align flow +local alignment = Gui.alignment(element,'example_center_top_alignment','center','top') + +]] +function Gui.alignment(parent,horizontal_align,vertical_align,name) + -- Draw the alignment flow + local alignment = + parent.add{ + name = name or 'alignment', + type = 'flow', + } + + -- Change its style + local style = alignment.style + style.padding = {1,2} + style.vertical_align = vertical_align or 'center' + style.horizontal_align = horizontal_align or 'right' + style.vertically_stretchable = style.vertical_align ~= 'center' + style.horizontally_stretchable = style.horizontal_align ~= 'center' + + -- Return the flow + return alignment +end + +--[[-- Draw a scroll pane that has a table inside of it +@tparam LuaGuiElement parent the parent element that the scroll table will be added to +@tparam number height the maximum height for the scroll pane +@tparam number column_count the number of columns that the table will have +@tparam[opt='scroll'] string name the name of the scroll pane that is added, the table is always called 'table' +@treturn LuaGuiElement the table that was created + +@usage-- Adding a scroll table with max height of 200 and column count of 3 +local scroll_table = Gui.scroll_table(element,'example_scroll_table',200,3) + +]] +function Gui.scroll_table(parent,height,column_count,name) + -- Draw the scroll + local scroll = + parent.add{ + name = name or 'scroll', + type = 'scroll-pane', + direction = 'vertical', + horizontal_scroll_policy = 'never', + vertical_scroll_policy = 'auto-and-reserve-space', + style = 'scroll_pane_under_subheader' + } + + -- Change the style of the scroll + local scroll_style = scroll.style + scroll_style.padding = {1,2} + scroll_style.maximal_height = height + scroll_style.horizontally_stretchable = true + + -- Draw the table + local scroll_table = + scroll.add{ + type = 'table', + name = 'table', + column_count = column_count + } + + -- Change the style of the table + local table_style = scroll_table.style + table_style.padding = 0 + table_style.cell_padding = 0 + table_style.vertical_align = 'center' + table_style.horizontally_stretchable = true + + -- Return the scroll table + return scroll_table +end + +--[[-- Used to add a header to a frame, this has the option for a custom right alignment flow for buttons +@tparam LuaGuiElement parent the parent element that the header will be added to +@tparam ?string|Concepts.LocalizedString caption the caption that will be shown on the header +@tparam[opt] ?string|Concepts.LocalizedString tooltip the tooltip that will be shown on the header +@tparam[opt=false] boolean add_alignment when true an alignment flow will be added for buttons +@tparam[opt='header'] string name the name of the header that is being added, the alignment is always called 'alignment' +@treturn LuaGuiElement either the header or the header alignment if add_alignment is true + +@usage-- Adding a custom header +local header_alignment = Gui.header( + element, + 'example_header', + 'Example Caption', + 'Example Tooltip', + true +) + +]] +function Gui.header(parent,caption,tooltip,add_alignment,name) + -- Draw the header + local header = + parent.add{ + name = name or 'header', + type = 'frame', + style = 'subheader_frame' + } + + -- Change the style of the header + local style = header.style + style.padding = {2,4} + style.use_header_filler = false + style.horizontally_stretchable = true + + -- Draw the caption label + header.add{ + name = 'header_label', + type = 'label', + style = 'heading_1_label', + caption = caption, + tooltip = tooltip + } + + -- Return either the header or the added alignment + return add_alignment and Gui.alignment(header) or header +end + +-- Module return return Gui \ No newline at end of file diff --git a/expcore/store.lua b/expcore/store.lua index f58e41b9..735ccef4 100644 --- a/expcore/store.lua +++ b/expcore/store.lua @@ -27,7 +27,7 @@ local player_scores = Store.register(function(player) -- Use player name as the end) -- When any key in the store is changed this function will trigger -Store.watch(player_scores,function(value,key) +Store.watch(player_scores,function(value,key,old_value) game.print(key..' now has a score of '..value) end) @@ -175,7 +175,7 @@ local player_scores = Store.register(function(player) end) -- Register the watcher so that when we change the value the message is printed -Store.watch(player_scores,function(value,key) +Store.watch(player_scores,function(value,key,old_value) game.print(key..' now has a score of '..value) end) @@ -274,18 +274,21 @@ Store.clear(player_scores) ]] function Store.clear(store,key) key = Store.validate(store,key,2) + local old_value -- Check if there is a key being used if key then if type(data_store[store]) == 'table' then + old_value = data_store[store][key] data_store[store][key] = nil end else + old_value = data_store[store] data_store[store] = nil end -- Trigger any watch functions - Store.raw_trigger(store,key,nil) + Store.raw_trigger(store,key,nil,old_value) end --[[-- Used to set the data in a store, will trigger any watchers, key is optional depending on if you are using them @@ -325,19 +328,22 @@ function Store.set(store,key,value) -- Check the store is valid key = Store.validate(store,key,2) + local old_value -- If there is a key being used then the store must be a able if key then if type(data_store[store]) ~= 'table' then data_store[store] = {_value = data_store[store]} end + old_value = data_store[store][key] data_store[store][key] = value else + old_value = data_store[store] data_store[store] = value end -- Trigger any watchers - Store.raw_trigger(store,key,value) + Store.raw_trigger(store,key,value,old_value) end --[[-- Used to update the data in a store, use this with tables, will trigger any watchers, key is optional depending on if you are using them @@ -386,7 +392,7 @@ function Store.update(store,key,updater) -- Check the store is valid key = Store.validate(store,key,2) - local value + local value, old_value -- If a key is used then the store must be a table if key then @@ -397,6 +403,7 @@ function Store.update(store,key,updater) -- Call the updater and if it returns a value then set this value local rtn = updater(data_store[store][key]) if rtn then + old_value = data_store[store][key] data_store[store][key] = rtn end value = data_store[store][key] @@ -405,6 +412,7 @@ function Store.update(store,key,updater) -- Call the updater and if it returns a value then set this value local rtn = updater(data_store[store]) if rtn then + old_value = data_store[store][key] data_store[store] = rtn end value = data_store[store] @@ -412,7 +420,7 @@ function Store.update(store,key,updater) end -- Trigger any watchers - Store.raw_trigger(store,key,value) + Store.raw_trigger(store,key,value,old_value) end --[[-- Used to update all values that are in a store, similar to Store.update but acts on all keys at once, will trigger watchers for every key present @@ -455,7 +463,7 @@ function Store.map(store,updater) if rtn then data[key] = rtn end - Store.raw_trigger(store,key,data[key]) + Store.raw_trigger(store,key,data[key],value) end end @@ -476,9 +484,10 @@ function Store.trigger(store,key) -- Get the data from the data store local data = data_store[store] if key then - Store.raw_trigger(store,key,data[key]) + data = data[key] + Store.raw_trigger(store,key,data,data) else - Store.raw_trigger(store,key,data) + Store.raw_trigger(store,key,data,data) end end @@ -486,6 +495,7 @@ end @tparam number store the uid of the store that you want to trigger @tparam[opt] ?string|any key the key that you want to trigger, must be a string unless you have a serializer @tparam[opt] any value the new value that is at this key or store, passed directly to the watcher +@tparam[opt] any old_value the old value that was at this key or store often the same if value is a table, passed directly to the watcher @usage-- Triggering a manule call of the watchers -- The type of store we use does not really matter for this as long as you pass it what you watchers are expecting @@ -493,16 +503,16 @@ local scenario_diffculty = Store.register() -- Trigger the watchers with a fake change of diffculty -- This is mostly used internally but it can be useful in other cases -Store.raw_trigger(scenario_diffculty,nil,'normal') +Store.raw_trigger(scenario_diffculty,nil,'normal','normal') ]] -function Store.raw_trigger(store,key,value) +function Store.raw_trigger(store,key,value,old_value) key = Store.validate(store,key,2) -- Get the watchers and then loop over them local watchers = Store.watchers[store] or {} for _,watcher in pairs(watchers) do - local success, err = pcall(watcher,value,key) + local success, err = pcall(watcher,value,key,old_value) if not success then error('Store watcher casued an error:\n\t'..err) end diff --git a/modules/control/tasks.lua b/modules/control/tasks.lua index 6b2d9630..0806efde 100644 --- a/modules/control/tasks.lua +++ b/modules/control/tasks.lua @@ -89,8 +89,8 @@ Tasks.remove_task(task_id) function Tasks.remove_task(task_id) local task = Store.get(task_store,task_id) local force_name = task.force_name - Store.clear(task_store,task_id) table.remove_element(force_tasks[force_name],task_id) + Store.clear(task_store,task_id) end --[[-- Update the message and last edited information for a task diff --git a/modules/gui/task-list.lua b/modules/gui/task-list.lua index d82a3a77..9f393205 100644 --- a/modules/gui/task-list.lua +++ b/modules/gui/task-list.lua @@ -12,337 +12,455 @@ local format_time,table_keys = ext_require('expcore.common','format_time','table local Tasks = require 'modules.control.tasks' --- @dep modules.control.tasks --- If a player is allowed to use the edit buttons -local function player_allowed_edit(player,task) +local function check_player_permissions(player,task) if task then + -- When a task is given check if the player can edit it + local allow_edit_task = config.allow_edit_task + + -- Check if the player being the last to edit will override existing permisisons if config.user_can_edit_own_tasks and task.last_edit_name == player.name then return true end - else - if config.any_user_can_add_new_task then + + -- Check player has permisison based on value in the config + if allow_edit_task == 'all' then return true + elseif allow_edit_task == 'admin' then + return player.admin + elseif allow_edit_task == 'expcore.roles' then + return Roles.player_allowed(player,config.edit_tasks_role_permission) end - end - if config.only_admins_can_edit and not player.admin then + -- Return false as all other condidtions have not been met + return false + else + -- When a task is not given check if the player can add a new task + local allow_add_task = config.allow_add_task + + -- Check player has permisison based on value in the config + if allow_add_task == 'all' then + return true + elseif allow_add_task == 'admin' then + return player.admin + elseif allow_add_task == 'expcore.roles' then + return Roles.player_allowed(player,config.expcore_roles_add_permission) + end + + -- Return false as all other condidtions have not been met return false end - - if config.edit_tasks_role_permission and not Roles.player_allowed(player,config.edit_tasks_role_permission) then - return false - end - - return true end ---- Button in the header to add a new task +--- Button displayed in the ehader bar, used to add a new task -- @element add_new_task local add_new_task = -Gui.new_button() -:set_sprites('utility/add') -:set_tooltip{'task-list.add-tooltip'} -:set_style('tool_button',function(style) - Gui.set_padding_style(style,-2,-2,-2,-2) - style.height = 20 - style.width = 20 -end) -:on_click(function(player,element) +Gui.element{ + type = 'sprite-button', + sprite = 'utility/add', + tooltip = {'task-list.add-tooltip'}, + style = 'tool_button' +} +:style{ + padding = -2, + height = 20, + width = 20 +} +:on_click(function(player,_,_) Tasks.add_task(player.force.name,nil,player.name) end) ---- Used to save changes to a task +--- Button displayed next to tasks which the user is currently editing, used to save changes -- @element confirm_edit local confirm_edit = -Gui.new_button() -:set_sprites('utility/downloaded') -:set_tooltip{'task-list.confirm-tooltip'} -:set_style('tool_button',function(style) - Gui.set_padding_style(style,-2,-2,-2,-2) - style.height = 20 - style.width = 20 -end) -:on_click(function(player,element) +Gui.element{ + type = 'sprite-button', + sprite = 'utility/downloaded', + tooltip = {'task-list.confirm-tooltip'}, + style = 'tool_button' +} +:style{ + padding = -2, + height = 20, + width = 20 +} +:on_click(function(player,element,_) local task_id = element.parent.name - local new_message = element.parent.task.text + local new_message = element.parent.task_entry.text Tasks.set_editing(task_id,player.name) Tasks.update_task(task_id,new_message,player.name) end) ---- Used to cancel any changes you made to a task +--- Button displayed next to tasks which the user is currently editing, used to discard changes -- @element cancel_edit local cancel_edit = -Gui.new_button() -:set_sprites('utility/close_black') -:set_tooltip{'task-list.cancel-tooltip'} -:set_style('tool_button',function(style) - Gui.set_padding_style(style,-2,-2,-2,-2) - style.height = 20 - style.width = 20 -end) -:on_click(function(player,element) +Gui.element{ + type = 'sprite-button', + sprite = 'utility/close_black', + tooltip = {'task-list.cancel-tooltip'}, + style = 'tool_button' +} +:style{ + padding = -2, + height = 20, + width = 20 +} +:on_click(function(player,element,_) local task_id = element.parent.name Tasks.set_editing(task_id,player.name) end) ---- Removes the task from the list +--- Button displayed next to tasks which the user is can edit, used to delete a task from the list -- @element discard_task local discard_task = -Gui.new_button() -:set_sprites('utility/trash') -:set_tooltip{'task-list.discard-tooltip'} -:set_style('tool_button',function(style) - Gui.set_padding_style(style,-2,-2,-2,-2) - style.height = 20 - style.width = 20 -end) -:on_click(function(player,element) - local task_id = element.parent.name +Gui.element{ + type = 'sprite-button', + sprite = 'utility/trash', + tooltip = {'task-list.discard-tooltip'}, + style = 'tool_button' +} +:style{ + padding = -2, + height = 20, + width = 20 +} +:on_click(function(_,element,_) + local task_id = element.parent.name:sub(6) Tasks.remove_task(task_id) end) ---- Opens edit mode for the task +--- Button displayed next to tasks which the user is can edit, used to start editing a task -- @element edit_task local edit_task = -Gui.new_button() -:set_sprites('utility/rename_icon_normal') -:set_tooltip{'task-list.edit-tooltip-none'} -:set_style('tool_button',function(style) - Gui.set_padding_style(style,-2,-2,-2,-2) - style.height = 20 - style.width = 20 -end) -:on_click(function(player,element) - local task_id = element.parent.name +Gui.element{ + type = 'sprite-button', + sprite = 'utility/rename_icon_normal', + tooltip = {'task-list.edit-tooltip-none'}, + style = 'tool_button' +} +:style{ + padding = -2, + height = 20, + width = 20 +} +:on_click(function(player,element,_) + local task_id = element.parent.name:sub(6) Tasks.set_editing(task_id,player.name,true) end) ---[[ Generates each task, handles both view and edit mode - element - > count-"task_id" - >> label - > "task_id" - >> task - >> cancel_edit (edit mode) - >> confirm_edit (edit mode) - > edit-"task_id" - >> edit_task - >> discard_task -]] -local function generate_task(player,element,task_id) +--- Set of three elements which make up each row of the task table +-- @element add_task_base +local add_task_base = +Gui.element(function(_,parent,task_id) + -- Add the task number label + parent.add{ + name = 'count-'..task_id, + type = 'label', + caption = '0)' + } + + -- Add a flow which will contain the task message and edit buttons + local task_flow = + parent.add{ + name = task_id, + type = 'flow', + } + + -- Set the padding on the task flow + local task_flow_style = task_flow.style + task_flow_style.padding = 0 + + -- Add the two edit buttons outside the task flow + local edit_flow = Gui.alignment(parent,nil,nil,'edit-'..task_id) + edit_task(edit_flow) + discard_task(edit_flow) + + -- Return the task flow as the main element + return task_flow +end) + +-- Removes the three elements that are added as part of the task base +local function remove_task_base(parent,task_id) + Gui.destroy_if_valid(parent['count-'..task_id]) + Gui.destroy_if_valid(parent['edit-'..task_id]) + Gui.destroy_if_valid(parent[task_id]) +end + +--- Default state for a task, contains only a label with the task message +-- @element task_label +local task_label = +Gui.element(function(_,parent,task) + local message = task.message + local last_edit_name = task.last_edit_name + local last_edit_time = task.last_edit_time + + -- Draw the element + local element = + parent.add{ + name = 'task_entry', + type = 'label', + caption = message, + tooltip = {'task-list.last-edit', last_edit_name, format_time(last_edit_time)} + } + + -- Change the style + local style = element.style + style.single_line = false + style.maximal_width = 150 + + -- Return the element + return element +end) + +--- Editing state for a task, contrins a text field and the two edit buttons +-- @element task_editing +local task_editing = +Gui.element(function(_,parent,task) + local message = task.message + + -- Draw the element + local element = + parent.add{ + name = 'task_entry', + type = 'textfield', + text = message + } + + -- Change the style + local style = element.style + style.maximal_width = 150 + style.height = 20 + + -- Add the edit buttons + cancel_edit(parent) + confirm_edit(parent) + + -- Return the element + return element +end) + +--- Updates a task for a player +local function update_task(player,task_table,task_id) local task = Tasks.get_task(task_id) local task_ids = Tasks.get_force_task_ids(player.force.name) local task_number = table.index_of(task_ids, task_id) + -- Task no longer exists so should be removed from the list if not task then - -- task is nil so remove it from the list - element.parent.no_tasks.visible = #task_ids == 1 - Gui.destroy_if_valid(element['count-'..task_id]) - Gui.destroy_if_valid(element['edit-'..task_id]) - Gui.destroy_if_valid(element[task_id]) - - else - local message = task.message - local editing = task.curently_editing[player.name] - local last_edit_name = task.last_edit_name - local last_edit_time = task.last_edit_time - - element.parent.no_tasks.visible = false - -- if it is not already present then add it now - local task_area = element[task_id] - if not task_area then - -- label to show the task number - element.add{ - name='count-'..task_id, - type='label', - caption=task_number..')' - } - - -- area which stores the task and buttons - task_area = - element.add{ - name=task_id, - type='flow', - } - Gui.set_padding(task_area) - - -- if the player can edit then it adds the edit and delete button - local flow = Gui.create_alignment(element,'edit-'..task_id) - local sub_flow = flow.add{type='flow',name=task_id} - - edit_task(sub_flow) - discard_task(sub_flow) - - end - - -- update the number indexes and the current editing players - element['count-'..task_id].caption = task_number..')' - - local edit_area = element['edit-'..task_id][task_id] - local players = table_keys(task.editing) - local allowed = player_allowed_edit(player,task) - - edit_area.visible = allowed - - if #players > 0 then - edit_area[edit_task.name].tooltip = {'task-list.edit-tooltip',table.concat(players,', ')} - else - edit_area[edit_task.name].tooltip = {'task-list.edit-tooltip-none'} - end - - -- draws/updates the task area - local element_type = task_area.task and task_area.task.type or nil - if not editing and element_type == 'label' then - -- update the label already present - task_area.task.caption = message - task_area.task.tooltip = {'task-list.last-edit',last_edit_name,format_time(last_edit_time)} - - elseif not editing then - -- create the label, view mode - if edit_area then - edit_area[edit_task.name].enabled = true - end - - task_area.clear() - - local label = - task_area.add{ - name='task', - type='label', - caption=message, - tooltip={'task-list.last-edit',last_edit_name,format_time(last_edit_time)} - } - label.style.single_line = false - label.style.maximal_width = 150 - - elseif editing and element_type ~= 'textfield' then - -- create the text field, edit mode, update it omitted as value is being edited - if edit_area then - edit_area[edit_task.name].enabled = false - end - - task_area.clear() - - local entry = - task_area.add{ - name='task', - type='textfield', - text=message - } - entry.style.maximal_width = 150 - entry.style.height = 20 - - cancel_edit(task_area) - confirm_edit(task_area) - - end - + task_table.parent.no_tasks.visible = #task_ids == 0 + remove_task_base(task_table,task_id) + return end + -- Get the task flow for this task + local task_flow = task_table[task_id] or add_task_base(task_table,task_id) + task_table.parent.no_tasks.visible = false + task_table['count-'..task_id].caption = task_number..')' + + -- Update the edit flow + local edit_flow = task_table['edit-'..task_id] + local player_allowed_edit = check_player_permissions(player,task) + local players_editing = table_keys(task.curently_editing) + local edit_task_element = edit_flow[edit_task.name] + local discard_task_element = edit_flow[discard_task.name] + + edit_task_element.visible = player_allowed_edit + discard_task_element.visible = player_allowed_edit + if #players_editing > 0 then + edit_task_element.tooltip = {'task-list.edit-tooltip',table.concat(players_editing,', ')} + else + edit_task_element.tooltip = {'task-list.edit-tooltip-none'} + end + + -- Check if the player is was editing and/or currently editing + local task_entry = task_flow.task_entry or task_label(task_flow,task) + local player_was_editing = task_entry.type == 'textfield' + local player_is_editing = task.curently_editing[player.name] + + -- Update the task flow + if not player_was_editing and not player_is_editing then + -- Update the task message label + local message = task.message + local last_edit_name = task.last_edit_name + local last_edit_time = task.last_edit_time + task_entry.caption = message + task_entry.tooltip = {'task-list.last-edit', last_edit_name, format_time(last_edit_time)} + + elseif player_was_editing and not player_is_editing then + -- Player was editing but is no longer, remove text field and add label + edit_task_element.enabled = true + task_flow.clear() + task_label(task_flow,task) + + elseif not player_was_editing and player_is_editing then + -- Player was not editing but now is, remove label and add text field + edit_task_element.enabled = false + task_flow.clear() + task_editing(task_flow,task) + + end end ---[[ generates the main gui structure - element - > container - >> header - >>> right aligned add_new_task - >> scroll - >>> no_tasks - >>> table -]] -local function generate_container(player,element) - Gui.set_padding(element,2,2,2,2) - element.style.minimal_width = 200 +local function update_all_tasks(player,scroll_table) + local task_ids = Tasks.get_force_task_ids(player.force.name) + if #task_ids > 0 then + for _,task_id in ipairs(task_ids) do + update_task(player,scroll_table,task_id) + end + end +end - -- main container which contains the other elements - local container = - element.add{ - name='container', - type='frame', - direction='vertical', - style='window_content_frame_packed' +--- Main task list container for the left flow +-- @element task_list_container +local task_list_container = +Gui.element(function(event_trigger,parent) + -- Draw the external container + local frame = + parent.add{ + name = event_trigger, + type = 'frame' } - Gui.set_padding(container) - container.style.vertically_stretchable = false - -- main header for the gui - local header_area = Gui.create_header( + -- Set the frame style + frame.style.padding = 2 + + -- Draw the internal container + local container = + frame.add{ + name = 'container', + type = 'frame', + direction = 'vertical', + style = 'window_content_frame_packed' + } + + -- Set the container style + local style = container.style + style.vertically_stretchable = false + + -- Draw the header + local header = Gui.header( container, {'task-list.main-caption'}, {'task-list.sub-tooltip'}, true ) - --- Right aligned button to toggle the section - if player_allowed_edit(player) then - add_new_task(header_area) - end + -- Draw the new task button + local player = Gui.get_player_from_element(parent) + local add_new_task_element = add_new_task(header) + add_new_task_element.visible = check_player_permissions(player) - -- table that stores all the data - local flow_table = Gui.create_scroll_table(container,3,185) - flow_table.draw_horizontal_lines = true - flow_table.vertical_centering = false - flow_table.style.top_cell_padding = 3 - flow_table.style.bottom_cell_padding = 3 + -- Draw the scroll table for the tasks + local scroll_table = Gui.scroll_table(container,185,3) + scroll_table.draw_horizontal_lines = true + scroll_table.vertical_centering = false - -- message to say that you have no tasks - local non_made = - flow_table.parent.add{ - name='no_tasks', - type='label', - caption={'task-list.no-tasks'} + -- Change the style of the scroll table + local scroll_table_style = scroll_table.style + scroll_table_style.top_cell_padding = 3 + scroll_table_style.bottom_cell_padding = 3 + + -- Draw the no tasks label + local no_tasks_label = + scroll_table.parent.add{ + name = 'no_tasks', + type = 'label', + caption = {'task-list.no-tasks'} } - non_made.style.width = 200 - non_made.style.single_line = false - return flow_table -end + -- Change the style of the no tasks label + local no_tasks_style = no_tasks_label.style + no_tasks_style.padding = {2,4} + no_tasks_style.single_line = false + no_tasks_style.width = 200 ---- Registers the task list --- @element task_list -local task_list = -Gui.new_left_frame('gui/task-list') -:set_sprites('utility/not_enough_repair_packs_icon') -:set_direction('vertical') -:set_tooltip{'task-list.main-tooltip'} -:set_open_by_default() -:on_creation(function(player,element) - local data_table = generate_container(player,element) + -- Add any existing tasks local task_ids = Tasks.get_force_task_ids(player.force.name) - - for _,task_id in pairs(task_ids) do - generate_task(player,data_table,task_id) + if #task_ids > 0 then + no_tasks_style.visible = false + for _,task_id in ipairs(task_ids) do + update_task(player,scroll_table,task_id) + end end + + -- Return the exteral container + return frame end) -:on_update(function(player,element) - local data_table = element.container.scroll.table +:add_to_left_flow(function(player) local task_ids = Tasks.get_force_task_ids(player.force.name) + return #task_ids > 0 +end) - for _,task_id in pairs(task_ids) do - generate_task(player,data_table,task_id) - end +--- Button on the top flow used to toggle the task list container +-- @element task_list_toggle +Gui.element{ + type = 'sprite-button', + sprite = 'utility/not_enough_repair_packs_icon', + tooltip = {'task-list.main-tooltip'}, + style = Gui.top_flow_button_style +} +:style{ + padding = -2 +} +:add_to_top_flow(function(player) + return Roles.player_allowed(player,'gui/task-list') +end) +:on_click(function(player,_,_) + Gui.toggle_left_element(player, task_list_container) end) --- When a new task is added it will udpate the task list for everyone on that force -Tasks.on_update(function(task,task_id) - local players +Tasks.on_update(function(task,task_id,removed_task) + -- Get the force to update, task is nil when removed + local force if task then - local force = game.forces[task.force_name] - players = force.connected_players + force = game.forces[task.force_name] else - players = game.connected_players + force = game.forces[removed_task.force_name] end - for _,player in pairs(players) do - local frame = task_list:get_frame(player) - local element = frame.container.scroll.table - generate_task(player,element,task_id) + -- Update the task for all the players on the force + local task_ids = Tasks.get_force_task_ids(force.name) + for _,player in pairs(force.connected_players) do + local left_flow = Gui.get_left_flow(player) + local frame = left_flow[task_list_container.name] + local scroll_table = frame.container.scroll.table + + -- Update the task that was changed + update_task(player,scroll_table,task_id) + + -- Update the numbering of the other tasks if the task was removed + if not task then + for task_number, next_task_id in pairs(task_ids) do + scroll_table['count-'..next_task_id].caption = task_number..')' + end + end end + end) --- Update the tasks when the player joins -Event.add(defines.events.on_player_joined_game,task_list 'redraw') +Event.add(defines.events.on_player_joined_game,function(event) + local player = game.players[event.player_index] + local left_flow = Gui.get_left_flow(player) + local frame = left_flow[task_list_container.name] + local scroll_table = frame.container.scroll.table + update_all_tasks(player,scroll_table) +end) --- Makes sure the right buttons are present when roles change -Event.add(Roles.events.on_role_assigned,task_list 'redraw') -Event.add(Roles.events.on_role_unassigned,task_list 'redraw') +local function role_update_event(event) + local player = game.players[event.player_index] + local left_flow = Gui.get_left_flow(player) + local container = left_flow[task_list_container.name].container -return task_list \ No newline at end of file + -- Update the tasks, incase the user can now edit them + local scroll_table = container.scroll.table + update_all_tasks(player,scroll_table) + + -- Update the new task button incase the user can now add them + local add_new_task_element = container.header.alignment[add_new_task.name] + add_new_task_element.visible = check_player_permissions(player) +end + +Event.add(Roles.events.on_role_assigned,role_update_event) +Event.add(Roles.events.on_role_unassigned,role_update_event) \ No newline at end of file