diff --git a/config/_file_loader.lua b/config/_file_loader.lua index b7ccbd92..7629b905 100644 --- a/config/_file_loader.lua +++ b/config/_file_loader.lua @@ -41,7 +41,7 @@ return { -- GUI --'modules.gui.rocket-info', --'modules.gui.science-info', - --'modules.gui.warp-list', + 'modules.gui.warp-list', 'modules.gui.task-list', --'modules.gui.player-list', --'modules.commands.debug', diff --git a/config/roles.lua b/config/roles.lua index d46d08fe..8bc10b92 100644 --- a/config/roles.lua +++ b/config/roles.lua @@ -61,7 +61,8 @@ Roles.new_role('Administrator','Admin') :set_flag('instance-respawn') :set_parent('Moderator') :allow{ - 'gui/warp-list/no-limit', + 'gui/warp-list/bypass-cooldown', + 'gui/warp-list/bypass-proximity', } Roles.new_role('Moderator','Mod') @@ -179,7 +180,9 @@ Roles.new_role('Member','Mem') :set_custom_color{r=24,g=172,b=188} :set_parent('Regular') :allow{ + 'gui/task-list/add', 'gui/task-list/edit', + 'gui/warp-list/add', 'gui/warp-list/edit' } @@ -215,6 +218,8 @@ local default = Roles.new_role('Guest','') 'gui/science-info', 'gui/task-list', 'gui/warp-list', + 'gui/warp-list/apply-cooldown', + 'gui/warp-list/apply-proximity', } --- Jail role diff --git a/config/tasks.lua b/config/tasks.lua index 994acff8..f7968e8e 100644 --- a/config/tasks.lua +++ b/config/tasks.lua @@ -2,11 +2,12 @@ -- @config Tasks return { - -- values can be all, admin, expcore.roles, none + -- Adding tasks 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 + expcore_roles_allow_add_task = 'gui/task-list/add', --- @setting expcore_roles_allow_add_task if expcore.roles is used then this is the required permission + + -- Editing tasks 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 + expcore_roles_allow_edit_task = 'gui/task-list/edit', --- @setting expcore_roles_allow_edit_task 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/config/warps.lua b/config/warps.lua index fb620108..d1710ba8 100644 --- a/config/warps.lua +++ b/config/warps.lua @@ -2,24 +2,39 @@ -- @config Warps return { - recharge_time = 60, --- @setting recharge_time The amount of time in seconds that the player must wait between warps, acts as a balance - update_smoothing = 10, --- @setting update_smoothing Higher is better, the amount of smoothing applied to recharge timer and other gui updates, max is 60 - minimum_distance = 100, --- @setting minimum_distance The minimum distance that must be between warp points, creating new ones is blocked when too close - activation_range = 4, --- @setting activation_range The distance the player must be to a warp in order to use the warp gui, gui can still be viewed but not used - spawn_activation_range = 20, --- @setting spawn_activation_range A second activation range which is used for the forces spawn point - default_icon = 'discharge-defense-equipment', --- @setting default_icon The default icon which is used by warps; must be an item name - user_can_edit_own_warps = false, --- @setting user_can_edit_own_warps When true the user can always edit warps which they created regardless of other settings - any_user_can_add_new_warp = false, --- @setting any_user_can_add_new_warp When true any user is able to create new warps, however editing may still be restricted - only_admins_can_edit = false, --- @setting only_admins_can_edit When true only admins can edit warps - edit_warps_role_permission = 'gui/warp-list/edit', --- @setting edit_warps_role_permission Role permission used by the role system to allow editing warps - bypass_warp_limits_permission = 'gui/warp-list/no-limit', --- @setting bypass_warp_limits_permission Role permission used by the role system to allow bypassing the time and distance restrictions - entities = { --- @setting entities The entities which are created for warps + -- General config + update_smoothing = 10, --- @setting update_smoothing the amount of smoothing applied to updates to the cooldown timer, higher is better, max is 60 + minimum_distance = 100, --- @setting minimum_distance the minimum distance that is allowed between warps on the same force + default_icon = 'discharge-defense-equipment', --- @setting default_icon the default icon that will be used for warps + + -- Warp cooldowns + bypass_warp_cooldown = 'expcore.roles', --- @setting bypass_warp_cooldown dictates who the warp cooldown is applied to; values: all, admin, expcore.roles, none + expcore_roles_bypass_warp_cooldown = 'gui/warp-list/bypass-cooldown', --- @setting expcore_roles_bypass_warp_cooldown if expcore.roles is used then this is the required permission + cooldown_duraction = 60, --- @setting cooldown_duraction the duration of the warp cooldown in seconds + + -- Warp proximity + bypass_warp_proximity = 'expcore.roles', --- @setting bypass_warp_proximity dictates who the warp proximity is applied to; values: all, admin, expcore.roles, none + expcore_roles_bypass_warp_proximity = 'gui/warp-list/bypass-proximity', --- @setting expcore_roles_bypass_warp_proximity if expcore.roles is used then this is the required permission + standard_proximity_radius = 4, --- @setting standard_proximity_radius the minimum distance a player is allowed to be to a warp in order to use it + spawn_proximity_radius = 20, --- @setting spawn_proximity_radius the minimum distance a player is allowed to be from they spawn point to use warps + + -- Adding warps + allow_add_warp = 'expcore.roles', --- @setting allow_add_warp dictates who is allowed to add warps; values: all, admin, expcore.roles, none + expcore_roles_allow_add_warp = 'gui/warp-list/add', --- @setting expcore_roles_allow_add_warp if expcore.roles is used then this is the required permission + + -- Editing warps + allow_edit_warp = 'expcore.roles', --- @setting allow_edit_warp dictates who is allowed to edit warps; values: all, admin, expcore.roles, none + expcore_roles_allow_edit_warp = 'gui/warp-list/edit', --- @setting expcore_roles_allow_edit_warp if expcore.roles is used then this is the required permission + user_can_edit_own_warps = false, --- @settings user_can_edit_own_warps if true then the user who made the warp can edit it regardless of the allow_edit_warp setting + + -- Warp area generation + entities = { --- @setting entities The entities which are created for warp areas {'small-lamp',-3,-2},{'small-lamp',-3,2},{'small-lamp',3,-2},{'small-lamp',3,2}, {'small-lamp',-2,-3},{'small-lamp',2,-3},{'small-lamp',-2,3},{'small-lamp',2,3}, {'small-electric-pole',-3,-3},{'small-electric-pole',3,3},{'small-electric-pole',-3,3},{'small-electric-pole',3,-3} }, - base_tile = 'tutorial-grid', --- @setting base_tile The tile which is used for the warps - tiles = { --- @setting tiles The tiles which are created for warps + base_tile = 'tutorial-grid', --- @setting base_tile The tile which is used for the warp areas + tiles = { --- @setting tiles The tiles which are created for warp areas {-3,-2},{-3,-1},{-3,0},{-3,1},{-3,2},{3,-2},{3,-1},{3,0},{3,1},{3,2}, {-2,-3},{-1,-3},{0,-3},{1,-3},{2,-3},{-2,3},{-1,3},{0,3},{1,3},{2,3} } diff --git a/docs/addons/Advanced-Start.html b/docs/addons/Advanced-Start.html index 4fc1a161..a94550d3 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 31bafcd7..5104f56d 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 740ed70e..12b2d4b7 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 6fb21b76..eda52288 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 4f5b7ae2..a9885689 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 8983690a..20304e86 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 e0085ca5..b5db145a 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 5de171a9..b6c03a49 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 08b4fc10..8a822e46 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 dcc7f831..1beb5873 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 54a470ef..0545406e 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 894d9fd7..2cd5e62f 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 bb480f1c..7ed81faf 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 11a3faa5..9fe4825c 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 fb090d39..d14c747d 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 1960d836..c774d4d6 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 ac910592..5eae53a7 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 5488f96a..b69015ea 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 371db9aa..4f5e97b4 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 ef15886c..5f0aa397 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 5f07e558..15d03b28 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 a892d1aa..d857f4de 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 c6e4fa94..a1e124e2 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 d7dd8363..d81a5601 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 6225e155..89d221c1 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 2c739395..68d1dbac 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 d94c73f6..e76ebc00 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 24f01cf0..ae86a1c8 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 2dd125fd..1308a173 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 8a4262f3..3766b23a 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 884b4a42..f6b81295 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 7d0e5d3d..edadff82 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 9612f09e..93bd8e14 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 021275cd..0dda65b9 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 dd7c7ddb..82cc7f4b 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 689ef12e..f4b77ef8 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 9f3db256..d72f5edf 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 de12ef31..00353bdc 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 76a3b440..5cd6e37d 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 d3162a9e..c1e53996 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 38e0eee2..e345fe69 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 f9d7156b..27950dfa 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 9331d05b..9f00aa0c 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 3deb9a8e..c794811b 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 2d91ee39..ae73091b 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 64fa59aa..6251d78c 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 f648a0f5..c39118c6 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 267b19c9..af464cc2 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 0449a9f1..858ae123 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 8d50f302..d8c76b79 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 33b1ba00..f08ad41d 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 6aa0aa00..0abe99c3 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 df64e68c..5c8300dc 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 0cd0d9f7..46f1ca96 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 8a8ae44b..4b21194e 100644 --- a/docs/configs/Tasks.html +++ b/docs/configs/Tasks.html @@ -244,13 +244,13 @@ allow_add_task - expcore_roles_add_permission + expcore_roles_allow_add_task allow_edit_task - expcore_roles_edit_permission + expcore_roles_allow_edit_task @@ -291,16 +291,15 @@
- # - expcore_roles_add_permission + # + expcore_roles_allow_add_task

-

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

+

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

@@ -346,8 +345,8 @@
- # - expcore_roles_edit_permission + # + expcore_roles_allow_edit_task
@@ -385,7 +384,7 @@ generated by LDoc diff --git a/docs/configs/Warnings.html b/docs/configs/Warnings.html index 2a237eb2..e1fb3569 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 5ef899b2..723c7258 100644 --- a/docs/configs/Warps.html +++ b/docs/configs/Warps.html @@ -241,37 +241,46 @@ - recharge_time - - update_smoothing minimum_distance - activation_range - - - spawn_activation_range - - default_icon - user_can_edit_own_warps + bypass_warp_cooldown - any_user_can_add_new_warp + expcore_roles_bypass_warp_cooldown - only_admins_can_edit + cooldown_duraction - edit_warps_role_permission + bypass_warp_proximity - bypass_warp_limits_permission + expcore_roles_bypass_warp_proximity + + + standard_proximity_radius + + + spawn_proximity_radius + + + allow_add_warp + + + expcore_roles_allow_add_warp + + + allow_edit_warp + + + expcore_roles_allow_edit_warp entities @@ -294,33 +303,6 @@
- # - recharge_time -
-
-
-
- -

-

The amount of time in seconds that the player must wait between warps, acts as a balance

- - - - - - - - - - - - - - -
-
-
-
# update_smoothing
@@ -329,7 +311,7 @@

-

Higher is better, the amount of smoothing applied to recharge timer and other gui updates, max is 60

+

the amount of smoothing applied to updates to the cooldown timer, higher is better

@@ -356,61 +338,7 @@

-

The minimum distance that must be between warp points, creating new ones is blocked when too close

- - - - - - - - - - - - - - - -
-
-
- # - activation_range -
-
-
-
- -

-

The distance the player must be to a warp in order to use the warp gui, gui can still be viewed but not used

- - - - - - - - - - - - - - -
-
-
-
- # - spawn_activation_range -
-
-
-
- -

-

A second activation range which is used for the forces spawn point

+

the minimum distance that is allowed between warps on the same force

@@ -437,7 +365,7 @@

-

The default icon which is used by warps; must be an item name

+

the default icon that will be used for warps

@@ -456,15 +384,15 @@
- # - user_can_edit_own_warps + # + bypass_warp_cooldown

-

When true the user can always edit warps which they created regardless of other settings

+

dictates who the warp cooldown is applied to; values: all, admin, expcore.roles, none

@@ -483,15 +411,15 @@
- # - any_user_can_add_new_warp + # + expcore_roles_bypass_warp_cooldown

-

When true any user is able to create new warps, however editing may still be restricted

+

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

@@ -510,15 +438,15 @@
- # - only_admins_can_edit + # + cooldown_duraction

-

When true only admins can edit warps

+

the duration of the warp cooldown in seconds

@@ -537,15 +465,15 @@
- # - edit_warps_role_permission + # + bypass_warp_proximity

-

Role permission used by the role system to allow editing warps

+

dictates who the warp proximity is applied to; values: all, admin, expcore.roles, none

@@ -564,15 +492,177 @@
- # - bypass_warp_limits_permission + # + expcore_roles_bypass_warp_proximity

-

Role permission used by the role system to allow bypassing the time and distance restrictions

+

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

+ + + + + + + + + + + + + + +
+
+
+
+ # + standard_proximity_radius +
+
+
+
+ +

+

the minimum distance a player is allowed to be to a warp in order to use it

+ + + + + + + + + + + + + + +
+
+
+
+ # + spawn_proximity_radius +
+
+
+
+ +

+

the minimum distance a player is allowed to be from they spawn point to use warps

+ + + + + + + + + + + + + + +
+
+
+
+ # + allow_add_warp +
+
+
+
+ +

+

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

+ + + + + + + + + + + + + + +
+
+
+
+ # + expcore_roles_allow_add_warp +
+
+
+
+ +

+

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

+ + + + + + + + + + + + + + +
+
+
+
+ # + allow_edit_warp +
+
+
+
+ +

+

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

+ + + + + + + + + + + + + + +
+
+
+
+ # + expcore_roles_allow_edit_warp +
+
+
+
+ +

+

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

@@ -599,7 +689,7 @@

-

The entities which are created for warps

+

The entities which are created for warp areas

@@ -626,7 +716,7 @@

-

The tile which is used for the warps

+

The tile which is used for the warp areas

@@ -653,7 +743,7 @@

-

The tiles which are created for warps

+

The tiles which are created for warp areas

@@ -684,7 +774,7 @@ generated by LDoc
diff --git a/docs/control/Jail.html b/docs/control/Jail.html index a809745f..65aeb8d0 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 12a57823..252850bf 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 a239a42c..c722290a 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 a11e1edc..b53870c6 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 cbe14682..64a3b413 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 84f5e53c..31e9150f 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 16a7f9de..6580b84a 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 545ac82f..3a2e7a33 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 fedadfc1..dab10ae9 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 c438edc4..21d1c537 100644 --- a/docs/core/Gui.html +++ b/docs/core/Gui.html @@ -2851,7 +2851,7 @@ Gui.element{ generated by LDoc diff --git a/docs/core/Permissions-Groups.html b/docs/core/Permissions-Groups.html index 13bacb25..bf67317a 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 cfb25893..3beabbe4 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 f5eb98bb..5cf287d0 100644 --- a/docs/core/Store.html +++ b/docs/core/Store.html @@ -1481,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 9a0a180b..479ac70d 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 e0e633ba..be347756 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 5714de34..2c0e4c87 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 12c80988..3ba61f51 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 a16009c7..6136165e 100644 --- a/docs/guis/Task-List.html +++ b/docs/guis/Task-List.html @@ -274,6 +274,18 @@ Button displayed in the ehader bar, used to add a new task + edit_task + Button displayed next to tasks which the user is can edit, used to start editing a task + + + discard_task + Button displayed next to tasks which the user is can edit, used to delete a task from the list + + + add_task_base + Set of three elements which make up each row of the task table + + confirm_edit Button displayed next to tasks which the user is currently editing, used to save changes @@ -282,26 +294,14 @@ Button displayed next to tasks which the user is currently editing, used to discard changes - discard_task - Button displayed next to tasks which the user is can edit, used to delete a task from the list - - - edit_task - Button displayed next to tasks which the user is can edit, used to start editing a task - - - add_task_base - Set of three elements which make up each row of the task table + task_editing + Editing state for a task, contrins a text field and the two edit buttons 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 @@ -491,6 +491,87 @@ + + + + + + +
+
+
+
+ # + edit_task +
+
+
+
+ +

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

+

+ + + + + + + + + + + + + + +
+
+
+
+ # + discard_task +
+
+
+
+ +

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

+

+ + + + + + + + + + + + + + +
+
+
+
+ # + add_task_base +
+
+
+
+ +

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

+

+ + + + + + + + @@ -555,68 +636,14 @@
- # - discard_task + # + task_editing
-

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

-

- - - - - - - - - - - - - - -
-
-
-
- # - edit_task -
-
-
-
- -

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

-

- - - - - - - - - - - - - - -
-
-
-
- # - add_task_base -
-
-
-
- -

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

+

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

@@ -653,33 +680,6 @@ - - - - - - -
-
-
-
- # - task_editing -
-
-
-
- -

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

-

- - - - - - - - @@ -756,7 +756,7 @@ generated by LDoc
diff --git a/docs/guis/Warps-List.html b/docs/guis/Warps-List.html index 18297a4b..db64af56 100644 --- a/docs/guis/Warps-List.html +++ b/docs/guis/Warps-List.html @@ -282,30 +282,10 @@ - zoom_to_map - Used on the name label to allow zoom to map - - - warp_timer - This timer controls when a player is able to warp, eg every 60 seconds - - - goto_warp - When the button is clicked it will teleport the player - - add_new_warp Will add a new warp to the list, checks if the player is too close to an existing one - confirm_edit - Confirms the edit to name or icon of the warp - - - cancel_edit - Cancels the editing changes of the selected warp name or icon - - discard_warp Removes a warp from the list, including the physical area and map tag @@ -314,8 +294,44 @@ Opens edit mode for the warp - warp_list - Registers the warp list + add_warp_base + Set of three elements which make up each row of the warp table + + + confirm_edit + Confirms the edit to name or icon of the warp + + + cancel_edit + Cancels the editing changes of the selected warp name or icon + + + warp_editing + Editing state for a warp, contrins a text field and the two edit buttons + + + warp_label + Default state for a warp, contains only a label with the warp name + + + warp_icon_button + Default state for the warp icon, when pressed teleports the player + + + warp_icon_editing + Editing state for the warp icon, chose elem used to chosse icon + + + warp_timer + This timer controls when a player is able to warp, eg every 60 seconds + + + warp_list_container + Main warp list container for the left flow + + + warp_list_toggle + Button on the top flow used to toggle the warp list container @@ -582,87 +598,6 @@
- # - zoom_to_map -
-
-
-
- -

Used on the name label to allow zoom to map

-

- - - - - - - - - - - - - - -
-
-
-
- # - warp_timer -
-
-
-
- -

This timer controls when a player is able to warp, eg every 60 seconds

-

- - - - - - - - - - - - - - -
-
-
-
- # - goto_warp -
-
-
-
- -

When the button is clicked it will teleport the player

-

- - - - - - - - - - - - - - -
-
-
-
# add_new_warp
@@ -680,60 +615,6 @@ - - - - - - - -
-
-
- # - confirm_edit -
-
-
-
- -

Confirms the edit to name or icon of the warp

-

- - - - - - - - - - - - - - -
-
-
-
- # - cancel_edit -
-
-
-
- -

Cancels the editing changes of the selected warp name or icon

-

- - - - - - - - @@ -798,14 +679,257 @@
- # - warp_list + # + add_warp_base
-

Registers the warp list

+

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

+

+ + + + + + + + + + + + + + +
+
+
+
+ # + confirm_edit +
+
+
+
+ +

Confirms the edit to name or icon of the warp

+

+ + + + + + + + + + + + + + +
+
+
+
+ # + cancel_edit +
+
+
+
+ +

Cancels the editing changes of the selected warp name or icon

+

+ + + + + + + + + + + + + + +
+
+
+
+ # + warp_editing +
+
+
+
+ +

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

+

+ + + + + + + + + + + + + + +
+
+
+
+ # + warp_label +
+
+
+
+ +

Default state for a warp, contains only a label with the warp name

+

+ + + + + + + + + + + + + + +
+
+
+
+ # + warp_icon_button +
+
+
+
+ +

Default state for the warp icon, when pressed teleports the player

+

+ + + + + + + + + + + + + + +
+
+
+
+ # + warp_icon_editing +
+
+
+
+ +

Editing state for the warp icon, chose elem used to chosse icon

+

+ + + + + + + + + + + + + + +
+
+
+
+ # + warp_timer +
+
+
+
+ +

This timer controls when a player is able to warp, eg every 60 seconds

+

+ + + + + + + + + + + + + + +
+
+
+
+ # + warp_list_container +
+
+
+
+ +

Main warp list container for the left flow

+

+ + + + + + + + + + + + + + +
+
+
+
+ # + warp_list_toggle +
+
+
+
+ +

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

@@ -837,7 +961,7 @@ generated by LDoc
diff --git a/docs/index.html b/docs/index.html index a5e3d006..6154fead 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 6cca966d..a712091a 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 6291b757..3ffd68e8 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 b6393f5d..48b74c3f 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 c5882630..b34baf22 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 2927bed7..42ee92fc 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 49848f9e..f851a4f8 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 ec13ecfc..aed7f3cf 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 e4815bc6..f72252fd 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 717e7598..20e6ef12 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 aeb9fd7f..9fe3a7ae 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 13f18afb..d7c02aa1 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 47a1f7d6..dda2c43f 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 df8680e8..98b6d7f3 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 ffb5dd8e..2d42a575 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 7dba1a3c..4284e0e5 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 96193316..70af10f9 100644 --- a/expcore/gui.lua +++ b/expcore/gui.lua @@ -411,15 +411,15 @@ 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.style.name == 'forward_button' + if state == nil then state = toggle_button.style.name == 'forward_button' end -- Set the visible state of all elements in the flow for name,authenticator in pairs(Gui.top_elements) do - top_flow[name].visible = new_state and authenticator(player) or false + top_flow[name].visible = state and authenticator(player) or false end -- Change the style of the toggle button - if new_state then + if state then toggle_button.style = 'back_button' local style = toggle_button.style style.height = 36 @@ -431,7 +431,7 @@ function Gui.toggle_top_flow(player,state) style.width = 18 end - return new_state + return state end --- Left Flow. @@ -501,8 +501,8 @@ function Gui.toggle_left_element(player,element_define,state) -- Set the visible state local element = left_flow[element_define.name] - local new_state = state or not element.visible - element.visible = new_state + if state == nil then state = not element.visible end + element.visible = state -- Check if the hide button should be visible local show_hide_button = false @@ -514,11 +514,11 @@ function Gui.toggle_left_element(player,element_define,state) end hide_button.visible = show_hide_button - return new_state + return state end -- Draw the two flows when a player joins -Event.add(defines.events.on_player_joined_game,function(event) +Event.add(defines.events.on_player_created,function(event) local player = game.players[event.player_index] -- Draw the top flow @@ -581,9 +581,9 @@ 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 + if state == nil then state = not element.enabled end + element.enabled = state + return state end --[[-- Will toggle the visible state of an element or set it to the one given @@ -597,9 +597,9 @@ 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 + if state == nil then state = not element.visible end + element.visible = state + return state end --[[-- Destory a gui element without causing any errors, likly if the element may have already been removed diff --git a/locale/en/gui.cfg b/locale/en/gui.cfg index 91d1faf2..332d2f42 100644 --- a/locale/en/gui.cfg +++ b/locale/en/gui.cfg @@ -91,7 +91,7 @@ cancel-tooltip=Discard changes edit-tooltip=Currently being edited by: __1__ edit-tooltip-none=Currently being edited by: Nobody discard-tooltip=Remove warp -timer-tooltip=Warp charge, charge time __1__ seconds +timer-tooltip=Warp cooldown takes __1__ seconds goto-tooltip=Go to x __1__ y __2__ goto-disabled=You must be on a warp point and have a full charge to warp goto-edit=Edit warp icon diff --git a/modules/control/warps.lua b/modules/control/warps.lua index ad503c3a..8958c833 100644 --- a/modules/control/warps.lua +++ b/modules/control/warps.lua @@ -150,7 +150,7 @@ function Warps.make_warp_area(warp_id) local position = warp.position local posx = position.x local posy = position.y - local radius = config.activation_range + local radius = config.standard_proximity_radius local radius2 = radius^2 -- Get the tile that is being replaced, store.update not needed as we dont want it to trigger @@ -203,7 +203,7 @@ function Warps.remove_warp_area(warp_id) local warp = Store.get(warp_store,warp_id) local position = warp.position local surface = warp.surface - local radius = config.activation_range + local radius = config.standard_proximity_radius local radius2 = radius^2 -- Check that a warp area was created previously diff --git a/modules/gui/task-list.lua b/modules/gui/task-list.lua index c36c3422..68baedae 100644 --- a/modules/gui/task-list.lua +++ b/modules/gui/task-list.lua @@ -333,7 +333,9 @@ Gui.element(function(event_trigger,parent) } -- Set the frame style - frame.style.padding = 2 + local frame_style = frame.style + frame_style.padding = 2 + frame_style.minimal_width = 200 -- Draw the internal container local container = diff --git a/modules/gui/warp-list.lua b/modules/gui/warp-list.lua index d5d12a4f..f39c562d 100644 --- a/modules/gui/warp-list.lua +++ b/modules/gui/warp-list.lua @@ -20,6 +20,11 @@ local player_in_range_store = Store.register(function(player) return player.name end) +-- Stores the time remaing for a players warp cooldown +local player_warp_cooldown_store = Store.register(function(player) + return player.name +end) + -- Table that stores a boolean value of weather to keep the warp gui open local keep_gui_open = {} Global.register(keep_gui_open,function(tbl) @@ -27,130 +32,160 @@ Global.register(keep_gui_open,function(tbl) end) --- Returns if a player is allowed to edit the given warp -local function player_allowed_edit(player,warp) - if warp then +--- If a player is allowed to use the edit buttons +local function check_player_permissions(player,action,warp) + -- Check if the action is allow edit and then check bypass settings + if action == 'allow_edit_warp' then + -- Check if the warp is the spawn then it cant be edited local spawn_id = Warps.get_spawn_warp_id(player.force.name) if spawn_id == warp.warp_id then return false end + + -- Check if the player being the last to edit will override existing permisisons if config.user_can_edit_own_warps and warp.last_edit_name == player.name then return true end - else - if config.any_user_can_add_new_warp then - return true - end end - if config.only_admins_can_edit and not player.admin then - return false + -- Check player has permisison based on value in the config + local action_config = config[action] + if action_config == 'all' then + return true + elseif action_config == 'admin' then + return player.admin + elseif action_config == 'expcore.roles' then + return Roles.player_allowed(player,config['expcore_roles_'..action]) end - if config.edit_warps_role_permission and not Roles.player_allowed(player,config.edit_warps_role_permission) then - return false - end - - return true + -- Return false as all other condidtions have not been met + return false end ---- Used on the name label to allow zoom to map --- @element zoom_to_map -local zoom_to_map_name = Gui.uid_name() -Gui.on_click(zoom_to_map_name,function(event) - local warp_id = event.element.parent.name - local warp = Warps.get_warp(warp_id) - local position = warp.position - event.player.zoom_to_world(position,1.5) -end) - - ---- This timer controls when a player is able to warp, eg every 60 seconds --- @element warp_timer -local warp_timer = -Gui.new_progressbar() -:set_tooltip{'warp-list.timer-tooltip',config.recharge_time} -:set_default_maximum(math.floor(config.recharge_time*config.update_smoothing)) -:add_store(Gui.categorize_by_player) -:set_style(nil,function(style) - style.horizontally_stretchable = true - style.color = Colors.light_blue -end) -:on_store_complete(function(player_name,reset) - Store.trigger(player_in_range_store,player_name) -end) - ---- When the button is clicked it will teleport the player --- @element goto_warp -local goto_warp = -Gui.new_button() -:set_sprites('item/'..config.default_icon) -:set_tooltip{'warp-list.goto-tooltip',0,0} -:set_style('quick_bar_slot_button',function(style) - style.height = 32 - style.width = 32 -end) -:on_click(function(player,element) - local warp_id = element.parent.caption - Warps.teleport_player(warp_id,player) - - -- Reset the warp cooldown if the player does not have unlimited warps - if config.bypass_warp_limits_permission and not Roles.player_allowed(player,config.bypass_warp_limits_permission) then - warp_timer:set_store(player.name,0) - Store.trigger(player_in_range_store,player) - end -end) - --- Will add a new warp to the list, checks if the player is too close to an existing one -- @element add_new_warp local add_new_warp = -Gui.new_button() -:set_sprites('utility/add') -:set_tooltip{'warp-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) +Gui.element{ + type = 'sprite-button', + sprite = 'utility/add', + tooltip = {'warp-list.add-tooltip'}, + style = 'tool_button' +} +:style{ + padding = -2, + height = 20, + width = 20 +} :on_click(function(player,element) + -- Add the new warp local force_name = player.force.name local surface = player.surface local position = player.position - local px = position.x - local py = position.y - local dist2 = config.minimum_distance^2 - - -- Check the distance to all existing warps - local warp_ids = Warps.get_force_warp_ids(force_name) - for _,warp_id in pairs(warp_ids) do - local warp = Warps.get_warp(warp_id) - local pos = warp.position - if surface == warp.surface and (px-pos.x)^2+(py-pos.y)^2 < dist2 then - player.print{'warp-list.too-close',warp.name} - return - end - end - - -- Add the new warp local warp_id = Warps.add_warp(force_name,surface,position,player.name) Warps.make_warp_tag(warp_id) Warps.make_warp_area(warp_id) end) +--- Removes a warp from the list, including the physical area and map tag +-- @element discard_warp +local discard_warp = +Gui.element{ + type = 'sprite-button', + sprite = 'utility/trash', + tooltip = {'warp-list.discard-tooltip'}, + style = 'tool_button' +} +:style{ + padding = -2, + height = 20, + width = 20 +} +:on_click(function(_,element) + local warp_id = element.parent.name:sub(6) + Warps.remove_warp(warp_id) +end) + +--- Opens edit mode for the warp +-- @element edit_warp +local edit_warp = +Gui.element{ + type = 'sprite-button', + sprite = 'utility/rename_icon_normal', + tooltip = {'warp-list.edit-tooltip-none'}, + style = 'tool_button' +} +:style{ + padding = -2, + height = 20, + width = 20 +} +:on_click(function(player,element) + local warp_id = element.parent.name:sub(6) + Warps.set_editing(warp_id,player.name,true) +end) + +--- Set of three elements which make up each row of the warp table +-- @element add_warp_base +local add_warp_base = +Gui.element(function(_,parent,warp_id) + -- Add the icon flow + local icon_flow = + parent.add{ + name = 'icon-'..warp_id, + type = 'flow', + caption = warp_id + } + + -- Change the style of the flow + icon_flow.style.padding = 0 + + -- Add a flow which will contain the warp name and edit buttons + local warp_flow = + parent.add{ + name = warp_id, + type = 'flow', + } + + -- Set the padding on the warp flow + warp_flow.style.padding = 0 + + -- Add the two edit buttons outside the warp flow + local edit_flow = Gui.alignment(parent,nil,nil,'edit-'..warp_id) + edit_warp(edit_flow) + discard_warp(edit_flow) + + -- Return the warp flow as the main element + return warp_flow +end) + +-- Removes the three elements that are added as part of the warp base +local function remove_warp_base(parent,warp_id) + Gui.destroy_if_valid(parent['icon-'..warp_id]) + Gui.destroy_if_valid(parent['edit-'..warp_id]) + Gui.destroy_if_valid(parent[warp_id]) +end + --- Confirms the edit to name or icon of the warp -- @element confirm_edit +local warp_editing +local warp_icon_button local confirm_edit = -Gui.new_button() -:set_sprites('utility/downloaded') -:set_tooltip{'warp-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) +Gui.element{ + type = 'sprite-button', + sprite = 'utility/downloaded', + tooltip = {'warp-list.confirm-tooltip'}, + style = 'shortcut_bar_button_green' +} +:style{ + padding = -2, + right_margin = -3, + height = 22, + width = 22 +} :on_click(function(player,element) local warp_id = element.parent.name - local warp_name = element.parent.warp.text - local warp_icon = element.parent.parent['icon-'..warp_id].icon.elem_value + local warp_name = element.parent[warp_editing.name].text + local warp_icon = element.parent.parent['icon-'..warp_id][warp_icon_button.name].elem_value Warps.set_editing(warp_id,player.name) Warps.update_warp(warp_id,warp_name,warp_icon,player.name) end) @@ -158,360 +193,462 @@ end) --- Cancels the editing changes of the selected warp name or icon -- @element cancel_edit local cancel_edit = -Gui.new_button() -:set_sprites('utility/close_black') -:set_tooltip{'warp-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) +Gui.element{ + type = 'sprite-button', + sprite = 'utility/close_black', + tooltip = {'warp-list.cancel-tooltip'}, + style = 'shortcut_bar_button_red' +} +:style{ + padding = -2, + right_margin = -3, + height = 22, + width = 22 +} :on_click(function(player,element) local warp_id = element.parent.name Warps.set_editing(warp_id,player.name) end) ---- Removes a warp from the list, including the physical area and map tag --- @element discard_warp -local discard_warp = -Gui.new_button() -:set_sprites('utility/trash') -:set_tooltip{'warp-list.discard-tooltip'} -:set_style('tool_button',function(style) - Gui.set_padding_style(style,-2,-2,-2,-2) +--- Editing state for a warp, contrins a text field and the two edit buttons +-- @element warp_editing +warp_editing = +Gui.element(function(event_trigger,parent,warp) + local name = warp.name + + -- Draw the element + local element = + parent.add{ + name = event_trigger, + type = 'textfield', + text = name, + clear_and_focus_on_right_click = true + } + + -- Change the style + local style = element.style + style.maximal_width = 110 style.height = 20 - style.width = 20 + + -- Add the edit buttons + cancel_edit(parent) + confirm_edit(parent) + + -- Return the element + return element end) -:on_click(function(player,element) +:on_confirmed(function(player,element,_) local warp_id = element.parent.name - Warps.remove_warp(warp_id) + local warp_name = element.text + local warp_icon = element.parent.parent['icon-'..warp_id][warp_icon_button.name].elem_value + Warps.set_editing(warp_id,player.name) + Warps.update_warp(warp_id,warp_name,warp_icon,player.name) end) ---- Opens edit mode for the warp --- @element edit_warp -local edit_warp = -Gui.new_button() -:set_sprites('utility/rename_icon_normal') -:set_tooltip{'warp-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 warp_id = element.parent.name - Warps.set_editing(warp_id,player.name,true) -end) +--- Default state for a warp, contains only a label with the warp name +-- @element warp_label +local warp_label = +Gui.element(function(event_trigger,parent,warp) + local name = warp.name + local last_edit_name = warp.last_edit_name + local last_edit_time = warp.last_edit_time ---[[ Generates each warp, handles both view and edit mode - element - > icon-"warp_id" - >> goto_warp or icon - > "warp_id" - >> warp - >> cancel_edit (edit mode) - >> confirm_edit (edit mode) - > edit-"warp_id" - >> "warp_id" - >>> edit_warp - >>> discard_warp -]] -local function generate_warp(player,element,warp_id) + -- Draw the element + local element = + parent.add{ + name = event_trigger, + type = 'label', + caption = name, + tooltip = {'warp-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) +:on_click(function(player,element,_) + local warp_id = element.parent.name local warp = Warps.get_warp(warp_id) + local position = warp.position + player.zoom_to_world(position,1.5) +end) + + +--- Default state for the warp icon, when pressed teleports the player +-- @element warp_icon_button +warp_icon_button = +Gui.element(function(event_trigger,parent,warp) + local warp_position = warp.position + + -- Draw the element + local element = + parent.add{ + name = event_trigger, + type = 'sprite-button', + sprite = 'item/'..warp.icon, + tooltip = {'warp-list.goto-tooltip',warp_position.x,warp_position.y}, + style = 'quick_bar_slot_button' + } + + -- Change the style + local style = element.style + style.height = 32 + style.width = 32 + + -- Return the element + return element +end) +:on_click(function(player,element,_) + local warp_id = element.parent.caption + Warps.teleport_player(warp_id,player) + + -- Reset the warp cooldown if the player does not have unlimited warps + if not check_player_permissions(player,'bypass_warp_cooldown') then + Store.set(player_warp_cooldown_store,player,config.cooldown_duraction) + Store.trigger(player_in_range_store,player) + end +end) + +--- Editing state for the warp icon, chose elem used to chosse icon +-- @element warp_icon_editing +local warp_icon_editing = +Gui.element(function(event_trigger,parent,warp) + local warp_icon = warp.icon + + -- Draw the element + local element = + parent.add{ + name = warp_icon_button.name, + type = 'choose-elem-button', + elem_type = 'item', + item = warp_icon, + tooltip = {'warp-list.goto-edit'}, + } + + -- Change the style + local style = element.style + style.height = 32 + style.width = 32 + + -- Return the element + return element +end) + +--- This timer controls when a player is able to warp, eg every 60 seconds +-- @element warp_timer +local warp_timer = +Gui.element{ + type = 'progressbar', + tooltip = {'warp-list.timer-tooltip',config.cooldown_duraction}, + minimum_value = 0, + maximum_value = config.cooldown_duraction*config.update_smoothing +} +:style{ + horizontally_stretchable = true, + color = Colors.light_blue +} + +--- Updates a warp for a player +local function update_warp(player,warp_table,warp_id) + local warp = Warps.get_warp(warp_id) + + -- Warp no longer exists so should be removed from the list if not warp then - -- warp is nil so remove it from the list - Gui.destroy_if_valid(element['icon-'..warp_id]) - Gui.destroy_if_valid(element['edit-'..warp_id]) - Gui.destroy_if_valid(element[warp_id]) - - else - local warp_name = warp.name - local warp_icon = warp.icon - local editing = warp.currently_editing[player.name] - local last_edit_name = warp.last_edit_name - local last_edit_time = warp.last_edit_time - local position = warp.position - - -- if it is not already present then add it now - local warp_area = element[warp_id] - local icon_area = element['icon-'..warp_id] - if not warp_area then - -- area to store the warp icon - icon_area = - element.add{ - name='icon-'..warp_id, - type='flow', - caption=warp_id - } - Gui.set_padding(icon_area) - - -- area which stores the warp and buttons - warp_area = - element.add{ - name=warp_id, - type='flow', - } - Gui.set_padding(warp_area) - - -- if the player can edit then it adds the edit and delete button - local flow = Gui.create_alignment(element,'edit-'..warp_id) - local sub_flow = flow.add{type='flow',name=warp_id} - - edit_warp(sub_flow) - discard_warp(sub_flow) - - end - - local edit_area = element['edit-'..warp_id][warp_id] - local players = warp.currently_editing and table_keys(warp.currently_editing) or {} - local allowed = player_allowed_edit(player,warp) - - edit_area.visible = allowed - - if #players > 0 then - edit_area[edit_warp.name].tooltip = {'warp-list.edit-tooltip',table.concat(players,', ')} - else - edit_area[edit_warp.name].tooltip = {'warp-list.edit-tooltip-none'} - end - - -- draws/updates the warp area - local label_element = warp_area.warp or warp_area[zoom_to_map_name] or nil - local element_type = label_element and label_element.type or nil - if not editing and element_type == 'label' then - -- update the label already present - label_element.caption = warp_name - label_element.tooltip = {'warp-list.last-edit',last_edit_name,format_time(last_edit_time)} - icon_area[goto_warp.name].sprite = 'item/'..warp_icon - - elseif not editing then - -- create the label, view mode - if edit_area then - edit_area[edit_warp.name].enabled = true - end - - -- redraws the icon for the warp - icon_area.clear() - - local btn = goto_warp(icon_area) - btn.sprite = 'item/'..warp_icon - btn.tooltip = {'warp-list.goto-tooltip',position.x,position.y} - - local timer = warp_timer:get_store(player.name) - local enabled = not timer and Store.get(player_in_range_store,player) - or Roles.player_allowed(player,config.bypass_warp_limits_permission) - if not enabled then - btn.enabled = false - btn.tooltip = {'warp-list.goto-disabled'} - end - - -- redraws the label for the warp name - warp_area.clear() - - local label = - warp_area.add{ - name=zoom_to_map_name, - type='label', - caption=warp_name, - tooltip={'warp-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_warp.name].enabled = false - end - - -- redraws the icon for the warp and allows selection - icon_area.clear() - - local btn = - icon_area.add{ - name='icon', - type='choose-elem-button', - elem_type='item', - item=warp_icon, - tooltip={'warp-list.goto-edit'}, - } - btn.style.height = 32 - btn.style.width = 32 - - -- redraws the label for the warp name and allows editing - warp_area.clear() - - local entry = - warp_area.add{ - name='warp', - type='textfield', - text=warp_name - } - entry.style.maximal_width = 150 - entry.style.height = 20 - - cancel_edit(warp_area) - confirm_edit(warp_area) - - end - + remove_warp_base(warp_table,warp_id) + return end + -- Get the warp flow for this warp + local warp_flow = warp_table[warp_id] or add_warp_base(warp_table,warp_id) + local icon_flow = warp_table['icon-'..warp_id] + + -- Update the edit flow + local edit_flow = warp_table['edit-'..warp_id] + local player_allowed_edit = check_player_permissions(player,'allow_edit_warp',warp) + local players_editing = table_keys(warp.currently_editing) + local edit_warp_element = edit_flow[edit_warp.name] + local discard_warp_element = edit_flow[discard_warp.name] + + edit_warp_element.visible = player_allowed_edit + discard_warp_element.visible = player_allowed_edit + if #players_editing > 0 then + edit_warp_element.hovered_sprite = 'utility/warning_icon' + edit_warp_element.tooltip = {'warp-list.edit-tooltip',table.concat(players_editing,', ')} + else + edit_warp_element.hovered_sprite = edit_warp_element.sprite + edit_warp_element.tooltip = {'warp-list.edit-tooltip-none'} + end + + -- Check if the player is was editing and/or currently editing + local warp_label_element = warp_flow[warp_label.name] or warp_label(warp_flow,warp) + local icon_entry = icon_flow[warp_icon_button.name] or warp_icon_button(icon_flow,warp) + local player_was_editing = icon_entry.type == 'choose-elem-button' + local player_is_editing = warp.currently_editing[player.name] + + -- Update the warp and icon flow + if not player_was_editing and not player_is_editing then + -- Update the warp name label and icon + local warp_name = warp.name + local warp_icon = warp.icon + local last_edit_name = warp.last_edit_name + local last_edit_time = warp.last_edit_time + warp_label_element.caption = warp_name + warp_label_element.tooltip = {'warp-list.last-edit',last_edit_name,format_time(last_edit_time)} + icon_entry.sprite = 'item/'..warp_icon + + elseif player_was_editing and not player_is_editing then + -- Player was editing but is no longer, remove text field and add label + edit_warp_element.enabled = true + warp_flow.clear() + warp_label(warp_flow,warp) + + icon_flow.clear() + local warp_icon_element = warp_icon_button(icon_flow,warp) + local timer = Store.get(player_warp_cooldown_store,player) + local in_range = Store.get(player_in_range_store,player) + local apply_proximity = not check_player_permissions(player,'bypass_warp_proximity') + if (timer and timer > 0) or (apply_proximity and not in_range) then + warp_icon_element.enabled = false + warp_icon_element.tooltip = {'warp-list.goto-disabled'} + end + + elseif not player_was_editing and player_is_editing then + -- Player was not editing but now is, remove label and add text field + edit_warp_element.enabled = false + warp_flow.clear() + warp_editing(warp_flow,warp).focus() + icon_flow.clear() + warp_icon_editing(icon_flow,warp) + + end end ---[[ generates the main gui structure - element - > container - >> header - >>> right aligned add_new_warp - >> scroll - >>> table - >> warp_timer -]] -local function generate_container(player,element) - Gui.set_padding(element,2,2,2,2) - element.style.minimal_width = 200 +local function update_all_warps(player,warp_table) + local warp_ids = Warps.get_force_warp_ids(player.force.name) + if #warp_ids > 0 then + for _,warp_id in ipairs(warp_ids) do + update_warp(player,warp_table,warp_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 warp list container for the left flow +-- @element warp_list_container +local warp_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 + local frame_style = frame.style + frame_style.padding = 2 + frame_style.minimal_width = 200 + + -- 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, {'warp-list.main-caption'}, - {'warp-list.sub-tooltip',config.recharge_time,config.activation_range}, + {'warp-list.sub-tooltip', config.cooldown_duraction, config.standard_proximity_radius}, true ) - --- Right aligned button to toggle the section - if player_allowed_edit(player) then - add_new_warp(header_area) + -- Draw the new warp button + local player = Gui.get_player_from_element(parent) + local add_new_warp_element = add_new_warp(header) + add_new_warp_element.visible = check_player_permissions(player,'allow_add_warp') + + -- Draw the scroll table for the warps + local scroll_table = Gui.scroll_table(container,258,3) + + -- 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 warp cooldown progress bar + local warp_timer_element = warp_timer(container) + + -- Change the progress of the warp timer + local progress = 1 + local timer = Store.get(player_warp_cooldown_store,player) + if timer and timer > 0 then + progress = 1 - (timer/config.cooldown_duraction) end + warp_timer_element.value = progress - -- table that stores all the data - local flow_table = Gui.create_scroll_table(container,3,258) - flow_table.style.top_cell_padding = 3 - flow_table.style.bottom_cell_padding = 3 + -- Add any existing warps + update_all_warps(player,scroll_table) - warp_timer(container) - - return flow_table -end - ---- Registers the warp list --- @element warp_list -local warp_list = -Gui.new_left_frame('gui/warp-list') -:set_sprites('item/'..config.default_icon) -:set_tooltip{'warp-list.main-tooltip',config.activation_range} -:set_direction('vertical') -:on_creation(function(player,element) - local data_table = generate_container(player,element) - local warp_ids = Warps.get_force_warp_ids(player.force.name) - - for _,warp_id in ipairs(warp_ids) do - generate_warp(player,data_table,warp_id) - end + -- Return the exteral container + return frame end) -:on_update(function(player,element) - local data_table = element.container.scroll.table - local warp_ids = Warps.get_force_warp_ids(player.force.name) +:add_to_left_flow() - data_table.clear() - for _,warp_id in ipairs(warp_ids) do - generate_warp(player,data_table,warp_id) - end +--- Button on the top flow used to toggle the warp list container +-- @element warp_list_toggle +Gui.element{ + type = 'sprite-button', + sprite = 'item/'..config.default_icon, + tooltip = {'warp-list.main-tooltip',config.standard_proximity_radius}, + style = Gui.top_flow_button_style +} +:style{ + padding = -2 +} +:add_to_top_flow(function(player) + return Roles.player_allowed(player,'gui/warp-list') end) -:on_player_toggle(function(player,element,visible) - keep_gui_open[player.name] = visible +:on_click(function(player,_,_) + local visible_state = Gui.toggle_left_element(player, warp_list_container) + keep_gui_open[player.name] = visible_state end) --- When the name of a warp is updated this is triggered -Warps.on_update(function(warp) - local players - local force_name +Warps.on_update(function(warp,_,removed_warp) + -- Get the force to update, warp is nil when removed + local force if warp then - local force = game.forces[warp.force_name] - players = force.connected_players - force_name = warp.force_name + force = game.forces[warp.force_name] else - players = game.connected_players + force = game.forces[removed_warp.force_name] end -- Update the gui for selected players - local force_warps = {} - for _,player in pairs(players) do - local frame = warp_list:get_frame(player) - local element = frame.container.scroll.table - - -- Get the warp ids for the players force - force_name = force_name or player.force.name - local warp_ids = force_warps[force_name] - if not warp_ids then - warp_ids = Warps.get_force_warp_ids(force_name) - force_warps[force_name] = warp_ids - end + local warp_ids = Warps.get_force_warp_ids(force.name) + for _,player in pairs(force.connected_players) do + local left_flow = Gui.get_left_flow(player) + local frame = left_flow[warp_list_container.name] + local scroll_table = frame.container.scroll.table -- Update the gui - element.clear() - for _,warp_id in ipairs(warp_ids) do - generate_warp(player,element,warp_id) + scroll_table.clear() + for _,next_warp_id in ipairs(warp_ids) do + update_warp(player,scroll_table,next_warp_id) end end end) --- Update the warps when the player joins -Event.add(defines.events.on_player_joined_game,warp_list 'redraw') -Event.add(Roles.events.on_role_assigned,warp_list 'redraw') -Event.add(Roles.events.on_role_unassigned,warp_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[warp_list_container.name] + local scroll_table = frame.container.scroll.table + update_all_warps(player,scroll_table) +end) + +--- Makes sure the right buttons are present when roles change +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[warp_list_container.name].container + + -- Update the warps, incase the user can now edit them + local scroll_table = container.scroll.table + update_all_warps(player,scroll_table) + + -- Update the new warp button incase the user can now add them + local add_new_warp_element = container.header.alignment[add_new_warp.name] + add_new_warp_element.visible = check_player_permissions(player,'allow_add_warp') +end + +Event.add(Roles.events.on_role_assigned,role_update_event) +Event.add(Roles.events.on_role_unassigned,role_update_event) --- When the player leaves or enters range of a warp this is triggered Store.watch(player_in_range_store,function(value,player_name) local player = game.players[player_name] local force = player.force - local frame = warp_list:get_frame(player_name) - local table_area = frame.container.scroll.table - local timer = warp_timer:get_store(player_name) - local state = not timer and value + -- Change if the frame is visible based on if the player is in range if not keep_gui_open[player.name] then - Gui.toggle_left_frame(warp_list.name,player,value) + Gui.toggle_left_element(player,warp_list_container,value) end - if Roles.player_allowed(player,config.bypass_warp_limits_permission) then + -- Check if the player requires proximity + if check_player_permissions(player,'bypass_warp_proximity') then return end + -- Get the warp table + local left_flow = Gui.get_left_flow(player) + local frame = left_flow[warp_list_container.name] + local scroll_table = frame.container.scroll.table + + -- Check if the buttons should be active + local timer = Store.get(player_warp_cooldown_store,player) + local button_disabled = timer and timer > 0 or not value + + -- Change the enabled state of the warp buttons local warp_ids = Warps.get_force_warp_ids(force.name) for _,warp_id in pairs(warp_ids) do - local element = table_area['icon-'..warp_id][goto_warp.name] + local element = scroll_table['icon-'..warp_id][warp_icon_button.name] if element and element.valid then - element.enabled = state - if state then + element.enabled = not button_disabled + if button_disabled then + element.tooltip = {'warp-list.goto-disabled'} + else local position = Warps.get_warp(warp_id).position element.tooltip = {'warp-list.goto-tooltip',position.x,position.y} - else - element.tooltip = {'warp-list.goto-disabled'} end end end end) ---- Handles updating the timer and checking distance from a warp -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(warp_timer.store) or {} - for category,_ in pairs(categories) do - warp_timer:increment(1,category) +--- Update the warp cooldown progress bars to match the store +Store.watch(player_warp_cooldown_store,function(value,player_name,old_value) + if value == old_value then return end + -- Get the progress bar element + local player = game.players[player_name] + local left_flow = Gui.get_left_flow(player) + local frame = left_flow[warp_list_container.name] + local warp_timer_element = frame.container[warp_timer.name] + + -- Set the progress + local progress = 1 + local timer = Store.get(player_warp_cooldown_store,player) + if timer and timer > 0 then + progress = 1 - (timer/config.cooldown_duraction) end + warp_timer_element.value = progress + + -- Trigger update of buttons if cooldown is now 0 + if value == 0 then + Store.trigger(player_in_range_store,player_name) + end +end) + +--- Handles updating the timer and checking distance from a warp +local r2 = config.standard_proximity_radius^2 +local rs2 = config.spawn_proximity_radius^2 +local mr2 = config.minimum_distance^2 +Event.on_nth_tick(math.floor(60/config.update_smoothing),function() + Store.map(player_warp_cooldown_store,function(value) + if value > 0 then + return value - 1 + end + end) local force_warps = {} local warps = {} @@ -527,6 +664,8 @@ Event.on_nth_tick(math.floor(60/config.update_smoothing),function() end -- Check if the force has any warps + local closest_warp + local closest_distance if #warp_ids > 0 then local surface = player.surface local pos = player.position @@ -545,20 +684,35 @@ Event.on_nth_tick(math.floor(60/config.update_smoothing),function() local warp_pos = warp.position if warp.surface == surface then local dx, dy = px-warp_pos.x, py-warp_pos.y - if (warp_id == warp_ids.spawn and (dx*dx)+(dy*dy) < rs2) or (dx*dx)+(dy*dy) < r2 then - -- Set in range to true if the player was preiovusly out of range - if not was_in_range then - Store.set(player_in_range_store,player,true) - end - was_in_range = false -- stops setting back to false below - break + local dist = (dx*dx)+(dy*dy) + if closest_distance == nil or dist < closest_distance then + closest_warp = warp + closest_distance = dist + if dist < r2 then break end end end end - -- Set in range to false if the player was preiovusly in range - if was_in_range then + -- Check the dist to the closest warp + local in_range = closest_warp.warp_id == warp_ids.spawn and closest_distance < rs2 or closest_distance < r2 + if was_in_range and not in_range then Store.set(player_in_range_store,player,false) + elseif not was_in_range and in_range then + Store.set(player_in_range_store,player,true) + end + + -- Change the enabled state of the add warp button + local left_flow = Gui.get_left_flow(player) + local frame = left_flow[warp_list_container.name] + local add_warp_element = frame.container.header.alignment[add_new_warp.name] + local was_able_to_make_warp = add_warp_element.enabled + local can_make_warp = closest_distance > mr2 + if can_make_warp and not was_able_to_make_warp then + add_warp_element.enabled = true + add_warp_element.tooltip = {'warp-list.add-tooltip'} + elseif not can_make_warp and was_able_to_make_warp then + add_warp_element.enabled = false + add_warp_element.tooltip = {'warp-list.too-close',closest_warp.name} end end @@ -567,18 +721,10 @@ Event.on_nth_tick(math.floor(60/config.update_smoothing),function() end) ---- When a player is created it will set them being in range to false to stop warping on join +--- When a player is created make sure that there is a spawn warp created Event.add(defines.events.on_player_created,function(event) - local player = Game.get_player_by_index(event.player_index) - - -- Check if a player is allowed unlimited warps - local allowed = config.bypass_warp_limits_permission and Roles.player_allowed(player,config.bypass_warp_limits_permission) or false - Store.set(player_in_range_store,player,allowed) - if allowed then - warp_timer:set_store(player.name,1) - end - -- If the force has no spawn then make a spawn warp + local player = Game.get_player_by_index(event.player_index) local force = player.force local spawn_id = Warps.get_spawn_warp_id(force.name) if not spawn_id then @@ -590,6 +736,7 @@ Event.add(defines.events.on_player_created,function(event) end end) +--- When a chart tag is removed or edited make sure it is not one that belongs to a warp local function maintain_tag(event) if not event.player_index then return end local tag = event.tag @@ -608,6 +755,4 @@ local function maintain_tag(event) end Event.add(defines.events.on_chart_tag_modified,maintain_tag) -Event.add(defines.events.on_chart_tag_removed,maintain_tag) - -return warp_list \ No newline at end of file +Event.add(defines.events.on_chart_tag_removed,maintain_tag) \ No newline at end of file