From 8197b172ad279d8b8741faf9067f4d593e6dd12f Mon Sep 17 00:00:00 2001 From: badgamernl Date: Sat, 7 Nov 2020 02:30:37 +0100 Subject: [PATCH 01/26] Working implementation --- locale/en/gui.cfg | 1 + modules/control/warps.lua | 5 +++++ modules/gui/warp-list.lua | 35 ++++++++++++++++++++++------------- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/locale/en/gui.cfg b/locale/en/gui.cfg index e4fa8611..5b027785 100644 --- a/locale/en/gui.cfg +++ b/locale/en/gui.cfg @@ -107,6 +107,7 @@ discard-tooltip=Remove warp 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-different-network=The warp is not connected to the same energy network goto-edit=Edit warp icon [readme] diff --git a/modules/control/warps.lua b/modules/control/warps.lua index 27dae30a..ddbc6f95 100644 --- a/modules/control/warps.lua +++ b/modules/control/warps.lua @@ -187,6 +187,11 @@ function Warps.make_warp_area(warp_id) entity.health = 0 entity.minable = false entity.rotatable = false + + -- Save reference of the last power pole + if entity.type == 'electric-pole' then + warp.electic_pole = entity + end end end diff --git a/modules/gui/warp-list.lua b/modules/gui/warp-list.lua index 699b46f0..e46ae014 100644 --- a/modules/gui/warp-list.lua +++ b/modules/gui/warp-list.lua @@ -308,27 +308,36 @@ Gui.element{ local warp_list_container --- Update the warp buttons for a player -function update_wrap_buttons(player, timer, in_range) +function update_wrap_buttons(player, timer, warp_id) -- Get the warp table local frame = Gui.get_left_element(player, warp_list_container) local scroll_table = frame.container.scroll.table -- Check if the buttons should be active timer = timer or PlayerCooldown:get(player) - in_range = in_range or PlayerInRange:get(player) - local button_disabled = timer > 0 or not in_range + warp_id = warp_id or PlayerInRange:get(player) + local button_disabled = timer > 0 or not warp_id + + local warp = warp_id and Warps.get_warp(warp_id) -- Change the enabled state of the warp buttons local warp_ids = Warps.get_force_warp_ids(player.force.name) - for _, warp_id in pairs(warp_ids) do - local element = scroll_table['icon-'..warp_id][warp_icon_button.name] + for _, next_warp_id in pairs(warp_ids) do + local element = scroll_table['icon-'..next_warp_id][warp_icon_button.name] if element and element.valid then - element.enabled = not button_disabled if button_disabled then element.tooltip = {'warp-list.goto-disabled'} + element.enabled = false else - local position = Warps.get_warp(warp_id).position - element.tooltip = {'warp-list.goto-tooltip', position.x, position.y} + local next_warp = Warps.get_warp(next_warp_id) + if warp.electic_pole and next_warp.electic_pole and warp.electic_pole.electric_network_id == next_warp.electic_pole.electric_network_id then + local position = next_warp.position + element.tooltip = {'warp-list.goto-tooltip', position.x, position.y} + element.enabled = true + else + element.tooltip = {'warp-list.goto-different-network'} + element.enabled = false + end end end end @@ -506,17 +515,17 @@ Warps.on_update(function(_, warp, old_warp) end) --- When the player leaves or enters range of a warp this is triggered -PlayerInRange:on_update(function(player_name, player_in_range) +PlayerInRange:on_update(function(player_name, warp_id) local player = game.players[player_name] -- 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_element(player, warp_list_container, player_in_range) + Gui.toggle_left_element(player, warp_list_container, warp_id ~= nil) end -- Check if the player requires proximity if not check_player_permissions(player, 'bypass_warp_proximity') then - update_wrap_buttons(player, nil, player_in_range) + update_wrap_buttons(player, nil, warp_id) end end) @@ -595,9 +604,9 @@ Event.on_nth_tick(math.floor(60/config.update_smoothing), function() -- 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 - PlayerInRange:set(player, false) + PlayerInRange:set(player, nil) elseif not was_in_range and in_range then - PlayerInRange:set(player, true) + PlayerInRange:set(player, closest_warp.warp_id) end -- Change the enabled state of the add warp button From 94cfceb5a34e445c612999976c3189c987c90e7b Mon Sep 17 00:00:00 2001 From: badgamernl Date: Sun, 8 Nov 2020 05:00:35 +0100 Subject: [PATCH 02/26] Fix electric pole name --- modules/control/warps.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/control/warps.lua b/modules/control/warps.lua index ddbc6f95..36c78358 100644 --- a/modules/control/warps.lua +++ b/modules/control/warps.lua @@ -190,7 +190,7 @@ function Warps.make_warp_area(warp_id) -- Save reference of the last power pole if entity.type == 'electric-pole' then - warp.electic_pole = entity + warp.electric_pole = entity end end end From 90e025aa1a005ac9632576d0398e2819977fd4fa Mon Sep 17 00:00:00 2001 From: badgamernl Date: Sun, 8 Nov 2020 05:04:53 +0100 Subject: [PATCH 03/26] Warp-list changes: - Refactor gui layout - Changed update flow --- locale/en/gui.cfg | 4 +- modules/gui/warp-list.lua | 538 +++++++++++++++++++++----------------- 2 files changed, 300 insertions(+), 242 deletions(-) diff --git a/locale/en/gui.cfg b/locale/en/gui.cfg index 5b027785..ca7750c4 100644 --- a/locale/en/gui.cfg +++ b/locale/en/gui.cfg @@ -106,8 +106,10 @@ edit-tooltip-none=Currently being edited by: Nobody discard-tooltip=Remove warp 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-cooldown=You are on cooldown, wait for the cooldown to recharge +goto-disabled=You must be on a warp point goto-different-network=The warp is not connected to the same energy network +goto-same-warp=You are already on this warp goto-edit=Edit warp icon [readme] diff --git a/modules/gui/warp-list.lua b/modules/gui/warp-list.lua index e46ae014..99e2b93c 100644 --- a/modules/gui/warp-list.lua +++ b/modules/gui/warp-list.lua @@ -30,8 +30,7 @@ end) --- Styles used for sprite buttons local Styles = { - sprite20 = Gui.sprite_style(20), - sprite22 = Gui.sprite_style(20, nil, { right_margin = -3 }), + sprite22 = { height = 22, width = 22, padding = -2 }, sprite32 = { height = 32, width = 32, left_margin = 1 } } @@ -73,9 +72,9 @@ Gui.element{ type = 'sprite-button', sprite = 'utility/add', tooltip = {'warp-list.add-tooltip'}, - style = 'tool_button' + style = 'shortcut_bar_button' } -:style(Styles.sprite20) +:style(Styles.sprite22) :on_click(function(player, _) -- Add the new warp local force_name = player.force.name @@ -86,167 +85,10 @@ Gui.element{ 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(Styles.sprite20) -: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(Styles.sprite20) -: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 - } - icon_flow.style.padding = 0 - - -- Add a flow which will contain the warp name and edit buttons - local warp_flow = parent.add{ type = 'flow', name = warp_id } - warp_flow.style.padding = 0 - - -- Add the two edit buttons outside the warp flow - local edit_flow = Gui.alignment(parent, '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.element{ - type = 'sprite-button', - sprite = 'utility/confirm_slot', - tooltip = {'warp-list.confirm-tooltip'}, - style = 'shortcut_bar_button_green' -} -:style(Styles.sprite22) -:on_click(function(player, element) - local warp_id = element.parent.name - 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) - ---- Cancels the editing changes of the selected warp name or icon --- @element cancel_edit -local cancel_edit = -Gui.element{ - type = 'sprite-button', - sprite = 'utility/close_black', - tooltip = {'warp-list.cancel-tooltip'}, - style = 'shortcut_bar_button_red' -} -:style(Styles.sprite22) -:on_click(function(player, element) - local warp_id = element.parent.name - Warps.set_editing(warp_id, player.name) -end) - ---- Editing state for a warp, contains 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 - } - - -- Add the edit buttons - cancel_edit(parent) - confirm_edit(parent) - - -- Return the element - return element -end) -:style{ - maximal_width = 110, - height = 20 -} -:on_confirmed(function(player, element, _) - local warp_id = element.parent.name - 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) - ---- 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 last_edit_name = warp.last_edit_name - local last_edit_time = warp.last_edit_time - -- Draw the element - return parent.add{ - name = event_trigger, - type = 'label', - caption = warp.name, - tooltip = {'warp-list.last-edit', last_edit_name, format_time(last_edit_time)} - } -end) -:style{ - single_line = false, - maximal_width = 150 -} -: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) - -local update_wrap_buttons ---- Default state for the warp icon, when pressed teleports the player +--- Warp icon button, this will trigger a warp when the player is able to -- @element warp_icon_button -warp_icon_button = +local warp_icon_button = Gui.element(function(event_trigger, parent, warp) local warp_position = warp.position @@ -274,16 +116,17 @@ end) -- Reset the warp cooldown if the player does not have unlimited warps if not check_player_permissions(player, 'bypass_warp_cooldown') then PlayerCooldown:set(player, config.cooldown_duration) - update_wrap_buttons(player) end + + PlayerInRange:set(player, warp_id) end) ---- Editing state for the warp icon, chose elem used to chosse icon +--- The button that is visible when the warp is in edit state -- @element warp_icon_editing local warp_icon_editing = -Gui.element(function(_, parent, warp) +Gui.element(function(event_trigger, parent, warp) return parent.add{ - name = warp_icon_button.name, + name = event_trigger, type = 'choose-elem-button', elem_type = 'signal', signal = {type = warp.icon.type, name = warp.icon.name}, @@ -292,6 +135,179 @@ Gui.element(function(_, parent, warp) end) :style(Styles.sprite32) +--- Warp label, visible if the player is not in edit state +-- @element warp_label +local warp_label = +Gui.element(function(event_trigger, parent, warp) + local last_edit_name = warp.last_edit_name + local last_edit_time = warp.last_edit_time + -- Draw the element + return parent.add{ + name = event_trigger, + type = 'label', + caption = warp.name, + tooltip = {'warp-list.last-edit', last_edit_name, format_time(last_edit_time)} + } +end) +:style{ + single_line = false, + horizontally_stretchable = true +} +:on_click(function(player, element, _) + local warp_id = element.parent.caption + local warp = Warps.get_warp(warp_id) + local position = warp.position + player.zoom_to_world(position, 1.5) +end) + +--- Warp textfield, visible if the player is in edit state +-- @element warp_textfield +local warp_textfield = +Gui.element(function(event_trigger, parent, warp) + -- Draw the element + local element = + parent.add{ + name = event_trigger, + type = 'textfield', + text = warp.name, + clear_and_focus_on_right_click = true + } + + -- Return the element + return element +end) +:style{ + maximal_width = 81, + height = 22, + padding = -2 +} +:on_confirmed(function(player, element, _) + local warp_id = element.parent.caption + local warp_name = element.text + local warp_icon = element.parent.parent['icon-'..warp_id][warp_icon_editing.name].elem_value + Warps.set_editing(warp_id, player.name) + Warps.update_warp(warp_id, warp_name, warp_icon, player.name) +end) + + +--- Confirms the edit to name or icon of the warp +-- @element confirm_edit_button +local confirm_edit_button = +Gui.element{ + type = 'sprite-button', + sprite = 'utility/confirm_slot', + tooltip = {'warp-list.confirm-tooltip'}, + style = 'shortcut_bar_button_green' +} +:style(Styles.sprite22) +:on_click(function(player, element) + local warp_id = element.parent.caption + local warp_name = element.parent.parent['name-'..warp_id][warp_textfield.name].text + local warp_icon = element.parent.parent['icon-'..warp_id][warp_icon_editing.name].elem_value + Warps.set_editing(warp_id, player.name) + Warps.update_warp(warp_id, warp_name, warp_icon, player.name) +end) + +--- Cancels the editing changes of the selected warp name or icon +-- @element cancel_edit_button +local cancel_edit_button = +Gui.element{ + type = 'sprite-button', + sprite = 'utility/close_black', + tooltip = {'warp-list.cancel-tooltip'}, + style = 'shortcut_bar_button_red' +} +:style(Styles.sprite22) +:on_click(function(player, element) + local warp_id = element.parent.caption + Warps.set_editing(warp_id, player.name) +end) + +--- Removes a warp from the list, including the physical area and map tag +-- @element remove_warp_button +local remove_warp_button = +Gui.element{ + type = 'sprite-button', + sprite = 'utility/trash', + tooltip = {'warp-list.discard-tooltip'}, + style = 'shortcut_bar_button_red' +} +:style(Styles.sprite22) +:on_click(function(_, element) + local warp_id = element.parent.caption + Warps.remove_warp(warp_id) +end) + +--- Opens edit mode for the warp +-- @element edit_warp_button +local edit_warp_button = +Gui.element{ + type = 'sprite-button', + sprite = 'utility/rename_icon_normal', + tooltip = {'warp-list.edit-tooltip-none'}, + style = 'shortcut_bar_button' +} +:style(Styles.sprite22) +:on_click(function(player, element) + local warp_id = element.parent.caption + Warps.set_editing(warp_id, player.name, true) +end) + +local update_wrap_buttons +--- Set of three elements which make up each row of the warp table +-- @element add_warp_elements +local add_warp_elements = +Gui.element(function(_, parent, warp) + -- Add icon flow this will contain the warp button and warp icon edit button + local icon_flow = parent.add{ + name = 'icon-'..warp.warp_id, + type = 'flow', + caption = warp.warp_id + } + icon_flow.style.padding = 0 + + -- Add the button and the icon edit button + warp_icon_button(icon_flow, warp) + warp_icon_editing(icon_flow, warp) + + -- Add name flow this will contain the warp label and textbox + local name_flow = parent.add{ + type = 'flow', + name = 'name-'..warp.warp_id, + caption = warp.warp_id + } + name_flow.style.padding = 0 + + -- Add the label and textfield of the warp + warp_label(name_flow, warp) + warp_textfield(name_flow, warp) + + + -- Add button flow this will contain buttons to manage this specific warp + local button_flow = parent.add{ + type = 'flow', + name = 'button-'..warp.warp_id, + caption = warp.warp_id + } + button_flow.style.padding = 0 + + -- Add both edit state buttons + confirm_edit_button(button_flow) + cancel_edit_button(button_flow) + edit_warp_button(button_flow) + remove_warp_button(button_flow) + + -- Return the warp flow elements + return { icon_flow, name_flow, button_flow } +end) + +-- Removes the three elements that are added as part of the warp base +local function remove_warp_elements(parent, warp_id) + Gui.destroy_if_valid(parent['icon-'..warp_id]) + Gui.destroy_if_valid(parent['name-'..warp_id]) + Gui.destroy_if_valid(parent['button-'..warp_id]) +end + --- This timer controls when a player is able to warp, eg every 60 seconds -- @element warp_timer local warp_timer = @@ -307,6 +323,46 @@ Gui.element{ } local warp_list_container + +-- Helper function to style and enable or disable a button element +local function update_icon_button(element, on_cooldown, warp, warp_player_is_on) + -- Check if button element is valid + if not element or not element.valid then return end + + local label_style = element.parent.parent['name-'..warp.warp_id][warp_label.name].style + + if not warp_player_is_on then + element.tooltip = {'warp-list.goto-disabled'} + element.enabled = false + label_style.font_color = { 1, 1, 1, 0.7 } + return + end + + if warp_player_is_on.warp_id == warp.warp_id then + element.tooltip = {'warp-list.goto-same-warp'} + element.enabled = false + label_style.font_color = { 1, 1, 1, 0.7 } + elseif on_cooldown then + element.tooltip = {'warp-list.goto-cooldown'} + element.enabled = false + label_style.font_color = { 1, 1, 1, 0.7 } + else + -- Check if the warps are in the same electricity network + local warp_electric_network_id = warp and warp.electric_pole.electric_network_id or -1 + local player_warp_electric_network_id = warp_player_is_on and warp_player_is_on.electric_pole.electric_network_id or -1 + if warp_electric_network_id == player_warp_electric_network_id then + local position = warp_player_is_on.position + element.tooltip = {'warp-list.goto-tooltip', position.x, position.y} + element.enabled = true + label_style.font_color = { 1, 1, 1, 1 } + else + element.tooltip = {'warp-list.goto-different-network'} + element.enabled = false + label_style.font_color = { 1, 0, 0, 0.7 } + end + end +end + --- Update the warp buttons for a player function update_wrap_buttons(player, timer, warp_id) -- Get the warp table @@ -316,30 +372,16 @@ function update_wrap_buttons(player, timer, warp_id) -- Check if the buttons should be active timer = timer or PlayerCooldown:get(player) warp_id = warp_id or PlayerInRange:get(player) - local button_disabled = timer > 0 or not warp_id + local on_cooldown = timer > 0 - local warp = warp_id and Warps.get_warp(warp_id) + local warp_player_is_on = warp_id and Warps.get_warp(warp_id) or nil -- Change the enabled state of the warp buttons local warp_ids = Warps.get_force_warp_ids(player.force.name) for _, next_warp_id in pairs(warp_ids) do local element = scroll_table['icon-'..next_warp_id][warp_icon_button.name] - if element and element.valid then - if button_disabled then - element.tooltip = {'warp-list.goto-disabled'} - element.enabled = false - else - local next_warp = Warps.get_warp(next_warp_id) - if warp.electic_pole and next_warp.electic_pole and warp.electic_pole.electric_network_id == next_warp.electic_pole.electric_network_id then - local position = next_warp.position - element.tooltip = {'warp-list.goto-tooltip', position.x, position.y} - element.enabled = true - else - element.tooltip = {'warp-list.goto-different-network'} - element.enabled = false - end - end - end + local next_warp = Warps.get_warp(next_warp_id) + update_icon_button(element, on_cooldown, next_warp, warp_player_is_on) end end @@ -347,25 +389,41 @@ end 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 the warp does no longer exist then remove the warp elements from the warp table if not warp then - remove_warp_base(warp_table, warp_id) + remove_warp_elements(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) + -- Check if the warp elements are created, if they are not then create a new set of them + if not warp_table['icon-'..warp_id] then + add_warp_elements(warp_table, warp) + end local icon_flow = warp_table['icon-'..warp_id] + local name_flow = warp_table['name-'..warp_id] + local button_flow = warp_table['button-'..warp_id] - -- Update the edit flow - local edit_flow = warp_table['edit-'..warp_id] + -- Create local references to the elements for this warp + local warp_icon_element = icon_flow[warp_icon_button.name] + local warp_icon_edit_element = icon_flow[warp_icon_editing.name] + + local label_element = name_flow[warp_label.name] + local textfield_element = name_flow[warp_textfield.name] + + local cancel_edit_element = button_flow[cancel_edit_button.name] + local confirm_edit_element = button_flow[confirm_edit_button.name] + + local edit_warp_element = button_flow[edit_warp_button.name] + local remove_warp_element = button_flow[remove_warp_button.name] + + -- Hide the edit button if the player is not allowed to edit the warp local player_allowed_edit = check_player_permissions(player, 'allow_edit_warp', warp) local players_editing = table.get_keys(warp.currently_editing) - local edit_warp_element = edit_flow[edit_warp.name] - local discard_warp_element = edit_flow[discard_warp.name] - + -- button_flow.visible = player_allowed_edit edit_warp_element.visible = player_allowed_edit - discard_warp_element.visible = player_allowed_edit + remove_warp_element.visible = player_allowed_edit + + -- Set the tooltip of the edit button 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, ', ')} @@ -374,54 +432,43 @@ local function update_warp(player, warp_table, warp_id) 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' + -- Set the warp elements visibility based on if the user is editing or not 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)} - -- The SpritePath type is not the same as the SignalID type - local sprite = warp_icon.type .. '/' ..warp_icon.name - if warp_icon.type == 'virtual' then - sprite = 'virtual-signal/' ..warp_icon.name - end - icon_entry.sprite = sprite - - 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 = PlayerCooldown:get(player) - local in_range = PlayerInRange:get(player) - local apply_proximity = not check_player_permissions(player, 'bypass_warp_proximity') - if 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() - warp_table.parent.scroll_to_element(warp_flow, 'top-third') - icon_flow.clear() - warp_icon_editing(icon_flow, warp) - + if player_is_editing then + -- Set the icon elements visibility + warp_icon_element.visible = false + warp_icon_edit_element.visible = true + -- Set the name elements visibility + label_element.visible = false + textfield_element.visible = true + textfield_element.focus() + warp_table.parent.scroll_to_element(textfield_element, 'top-third') + -- Set the edit buttons + cancel_edit_element.visible = true + confirm_edit_element.visible = true + -- Set the warp buttons + edit_warp_element.visible = false + remove_warp_element.visible = false + else + -- Set the icon elements visibility + warp_icon_element.visible = true + warp_icon_edit_element.visible = false + -- Set the name elements visibility + label_element.visible = true + textfield_element.visible = false + -- Set the edit buttons + cancel_edit_element.visible = false + confirm_edit_element.visible = false + -- Set the warp buttons + edit_warp_element.visible = true and player_allowed_edit + remove_warp_element.visible = true and player_allowed_edit end + + local timer = PlayerCooldown:get(player) + local current_warp_id = PlayerInRange:get(player) + local to_warp = current_warp_id and Warps.get_warp(current_warp_id) or nil + local apply_proximity = not check_player_permissions(player, 'bypass_warp_proximity') + update_icon_button(warp_icon_element, timer > 0 or (apply_proximity and not current_warp_id), warp, to_warp) end -- Update all the warps for a player @@ -469,6 +516,8 @@ Gui.element(function(event_trigger, parent) -- Draw the scroll table for the warps local scroll_table = Gui.scroll_table(container, 250, 3) + -- Set the scroll panel to always show the scrollbar (not doing this will result in a changing gui size) + scroll_table.parent.vertical_scroll_policy = 'always' -- Change the style of the scroll table local scroll_table_style = scroll_table.style @@ -640,6 +689,13 @@ Event.add(defines.events.on_player_created, function(event) spawn_id = Warps.add_warp(force.name, player.surface, spawn_position, nil, 'Spawn') Warps.set_spawn_warp(spawn_id, force) Warps.make_warp_tag(spawn_id) + + local entities = player.surface.find_entities_filtered{ type = 'electric-pole', position = spawn_position, radius = 20, limit = 1 } + if entities and entities[1] then + local warp = Warps.get_warp(spawn_id) + warp.electric_pole = entities[1] + player.print('found') + end end end) From bb5790a33d7c38490051b8ce1aa3666ad8a39d7b Mon Sep 17 00:00:00 2001 From: badgamernl Date: Sun, 8 Nov 2020 15:30:10 +0100 Subject: [PATCH 04/26] Fix function name --- modules/gui/warp-list.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/gui/warp-list.lua b/modules/gui/warp-list.lua index 99e2b93c..70cc04dd 100644 --- a/modules/gui/warp-list.lua +++ b/modules/gui/warp-list.lua @@ -481,7 +481,7 @@ local function update_all_warps(player, warp_table) end -- Update all warps for all players on a force -local function update_all_wrap_force(force) +local function update_all_warp_force(force) local warp_ids = Warps.get_force_warp_ids(force.name) for _, player in pairs(force.connected_players) do local frame = Gui.get_left_element(player, warp_list_container) @@ -557,9 +557,9 @@ end) Warps.on_update(function(_, warp, old_warp) -- Get the force to update, warp is nil when removed if warp then - update_all_wrap_force(game.forces[warp.force_name]) + update_all_warp_force(game.forces[warp.force_name]) else - update_all_wrap_force(game.forces[old_warp.force_name]) + update_all_warp_force(game.forces[old_warp.force_name]) end end) From c95616d1f807aea2d8b429f6e75f83e0e5673fa2 Mon Sep 17 00:00:00 2001 From: badgamernl Date: Sun, 8 Nov 2020 15:38:00 +0100 Subject: [PATCH 05/26] Fix network id checks --- modules/gui/warp-list.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/gui/warp-list.lua b/modules/gui/warp-list.lua index 70cc04dd..5fffb2bf 100644 --- a/modules/gui/warp-list.lua +++ b/modules/gui/warp-list.lua @@ -348,8 +348,8 @@ local function update_icon_button(element, on_cooldown, warp, warp_player_is_on) label_style.font_color = { 1, 1, 1, 0.7 } else -- Check if the warps are in the same electricity network - local warp_electric_network_id = warp and warp.electric_pole.electric_network_id or -1 - local player_warp_electric_network_id = warp_player_is_on and warp_player_is_on.electric_pole.electric_network_id or -1 + local warp_electric_network_id = warp.electric_pole and warp.electric_pole.electric_network_id or -1 + local player_warp_electric_network_id = warp_player_is_on.electric_pole and warp_player_is_on.electric_pole.electric_network_id or -2 if warp_electric_network_id == player_warp_electric_network_id then local position = warp_player_is_on.position element.tooltip = {'warp-list.goto-tooltip', position.x, position.y} From e851b48a0eced5357e2f32f43aec655d5cf36c98 Mon Sep 17 00:00:00 2001 From: badgamernl Date: Sun, 8 Nov 2020 16:04:07 +0100 Subject: [PATCH 06/26] Remove spawn debug message --- modules/gui/warp-list.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/gui/warp-list.lua b/modules/gui/warp-list.lua index 5fffb2bf..f28308a0 100644 --- a/modules/gui/warp-list.lua +++ b/modules/gui/warp-list.lua @@ -694,7 +694,6 @@ Event.add(defines.events.on_player_created, function(event) if entities and entities[1] then local warp = Warps.get_warp(spawn_id) warp.electric_pole = entities[1] - player.print('found') end end end) From 84fda87848d223aa31b4bb485436bda6d3e6cba5 Mon Sep 17 00:00:00 2001 From: bbassie Date: Sun, 8 Nov 2020 18:44:04 +0100 Subject: [PATCH 07/26] Changed warp area to fit the radius --- config/gui/warps.lua | 25 ++++++++++++++++++------- modules/control/warps.lua | 37 +++++++++---------------------------- 2 files changed, 27 insertions(+), 35 deletions(-) diff --git a/config/gui/warps.lua b/config/gui/warps.lua index 98e8f627..29e8075d 100644 --- a/config/gui/warps.lua +++ b/config/gui/warps.lua @@ -29,13 +29,24 @@ return { -- 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} + {'small-lamp', -4, -2}, {'small-lamp', -2, -4}, {'small-electric-pole',-3,-3}, -- Top left corner + {'small-lamp', 3, -2}, {'small-lamp', 1, -4}, {'small-electric-pole',2,-3}, -- Top right corner + {'small-lamp', 3, 1}, {'small-lamp', 1, 3}, {'small-electric-pole',2,2}, -- Bottom right corner + {'small-lamp', -4, 1}, {'small-lamp', -2, 3}, {'small-electric-pole',-3,2}, -- Bottom left corner }, - 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} + {"black-refined-concrete",-4,-2},{"black-refined-concrete",-4,-1},{"black-refined-concrete",-4,0},{"black-refined-concrete",-4,1}, + {"black-refined-concrete",-3,-3},{"purple-refined-concrete",-3,-2},{"purple-refined-concrete",-3,-1},{"purple-refined-concrete",-3,0}, + {"purple-refined-concrete",-3,1},{"black-refined-concrete",-3,2},{"black-refined-concrete",-2,-4},{"purple-refined-concrete",-2,-3}, + {"purple-refined-concrete",-2,-2},{"purple-refined-concrete",-2,-1},{"purple-refined-concrete",-2,0},{"purple-refined-concrete",-2,1}, + {"purple-refined-concrete",-2,2},{"black-refined-concrete",-2,3},{"black-refined-concrete",-1,-4},{"purple-refined-concrete",-1,-3}, + {"purple-refined-concrete",-1,-2},{"purple-refined-concrete",-1,-1},{"purple-refined-concrete",-1,0},{"purple-refined-concrete",-1,1}, + {"purple-refined-concrete",-1,2},{"black-refined-concrete",-1,3},{"black-refined-concrete",0,-4},{"purple-refined-concrete",0,-3}, + {"purple-refined-concrete",0,-2},{"purple-refined-concrete",0,-1},{"purple-refined-concrete",0,0},{"purple-refined-concrete",0,1}, + {"purple-refined-concrete",0,2},{"black-refined-concrete",0,3},{"black-refined-concrete",1,-4},{"purple-refined-concrete",1,-3}, + {"purple-refined-concrete",1,-2},{"purple-refined-concrete",1,-1},{"purple-refined-concrete",1,0},{"purple-refined-concrete",1,1}, + {"purple-refined-concrete",1,2},{"black-refined-concrete",1,3},{"black-refined-concrete",2,-3},{"purple-refined-concrete",2,-2}, + {"purple-refined-concrete",2,-1},{"purple-refined-concrete",2,0},{"purple-refined-concrete",2,1},{"black-refined-concrete",2,2}, + {"black-refined-concrete",3,-2},{"black-refined-concrete",3,-1},{"black-refined-concrete",3,0},{"black-refined-concrete",3,1} } -} \ No newline at end of file +} diff --git a/modules/control/warps.lua b/modules/control/warps.lua index 36c78358..c855d499 100644 --- a/modules/control/warps.lua +++ b/modules/control/warps.lua @@ -148,31 +148,15 @@ function Warps.make_warp_area(warp_id) local position = warp.position local posx = position.x local posy = position.y - 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 local old_tile = surface.get_tile(position).name warp.old_tile = old_tile - -- Make a circle that acts as a base for the warp structure - local base_tile = config.base_tile - local base_tiles = {} - for x = -radius, radius do - local x2 = x^2 - for y = -radius, radius do - local y2 = y^2 - if x2+y2 < radius2 then - table.insert(base_tiles, {name=base_tile, position={x+posx, y+posy}}) - end - end - end - surface.set_tiles(base_tiles) - -- Add a tile pattern on top of the base local tiles = {} - for _, pos in pairs(config.tiles) do - table.insert(tiles, {name=base_tile, position={pos[1]+posx, pos[2]+posy}}) + for _, tile in pairs(config.tiles) do + table.insert(tiles, {name=tile[1], position={tile[2]+posx, tile[3]+posy}}) end surface.set_tiles(tiles) @@ -193,6 +177,10 @@ function Warps.make_warp_area(warp_id) warp.electric_pole = entity end end + + local radius = config.standard_proximity_radius + rendering.draw_circle{ color = {0,1,0,.5}, radius = 0.1, filled = true, target = position, surface = surface, draw_on_ground = true } + rendering.draw_circle{ color = {0,1,0,.5}, radius = radius, filled = false, target = position, surface = surface, draw_on_ground = true } end --[[-- Remove the warp area for a warp @@ -207,22 +195,15 @@ function Warps.remove_warp_area(warp_id) local position = warp.position local surface = warp.surface local radius = config.standard_proximity_radius - local radius2 = radius^2 -- Check that a warp area was created previously local base_tile = warp.old_tile if not base_tile then return end - -- Reset all the tiles that were replaced + -- Loop over warp tiles and set them to the old tile that was below local tiles = {} - for x = -radius, radius do - local x2 = x^2 - for y = -radius, radius do - local y2 = y^2 - if x2+y2 < radius2 then - table.insert(tiles, {name=base_tile, position={x+position.x, y+position.y}}) - end - end + for _, tile in pairs(config.tiles) do + table.insert(tiles, {name=base_tile, position={tile[2]+position.x, tile[3]+position.y}}) end surface.set_tiles(tiles) From 1d980c6d64b004d08bb1bcbb97b7c22314fc97ba Mon Sep 17 00:00:00 2001 From: bbassie Date: Sun, 8 Nov 2020 19:02:55 +0100 Subject: [PATCH 08/26] Warp water check --- locale/en/gui.cfg | 1 + modules/gui/warp-list.lua | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/locale/en/gui.cfg b/locale/en/gui.cfg index ca7750c4..18ffc672 100644 --- a/locale/en/gui.cfg +++ b/locale/en/gui.cfg @@ -97,6 +97,7 @@ main-caption=Warp List main-tooltip=Warp List; Must be within __1__ tiles to use sub-tooltip=Warps can only be used every __1__ seconds and when within __2__ tiles too-close=Can't make warp; too close to warp: __1__ +too-close-to-water=Cannot create warp this close to water, please move __1__ tiles away from the water body last-edit=Last edited by __1__ at __2__\nClick to view on map add-tooltip=Add new warp confirm-tooltip=Save changes diff --git a/modules/gui/warp-list.lua b/modules/gui/warp-list.lua index f28308a0..a0ff2187 100644 --- a/modules/gui/warp-list.lua +++ b/modules/gui/warp-list.lua @@ -12,7 +12,7 @@ local Roles = require 'expcore.roles' --- @dep expcore.roles local Colors = require 'utils.color_presets' --- @dep utils.color_presets local config = require 'config.gui.warps' --- @dep config.gui.warps local Warps = require 'modules.control.warps' --- @dep modules.control.warps -local format_time = _C.format_time --- @dep expcore.common +local format_time, player_return = _C.format_time, _C.player_return --- @dep expcore.common --- Stores all data for the warp gui local WrapGuiData = Datastore.connect('WrapGuiData') @@ -80,6 +80,17 @@ Gui.element{ local force_name = player.force.name local surface = player.surface local position = player.position + + -- Check if the warp is too close to water + local water_tiles = surface.find_tiles_filtered{collision_mask = "water-tile", radius = config.standard_proximity_radius + 1, position = position, limit = 1} + if #water_tiles > 0 then + player_return({'expcore-commands.command-fail', {'warp-list.too-close-to-water', config.standard_proximity_radius + 1}}, 'orange_red', player) + local play_sound = 'utility/wire_pickup' + if game.player then game.player.play_sound{path=play_sound} end + return + end + + -- Create the 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) From ebfe24c21c3107bfe0a5554fbc893b38e960252d Mon Sep 17 00:00:00 2001 From: bbassie Date: Sun, 8 Nov 2020 19:04:44 +0100 Subject: [PATCH 09/26] Removed temp debug rendering --- modules/control/warps.lua | 4 ---- 1 file changed, 4 deletions(-) diff --git a/modules/control/warps.lua b/modules/control/warps.lua index c855d499..bc1e7207 100644 --- a/modules/control/warps.lua +++ b/modules/control/warps.lua @@ -177,10 +177,6 @@ function Warps.make_warp_area(warp_id) warp.electric_pole = entity end end - - local radius = config.standard_proximity_radius - rendering.draw_circle{ color = {0,1,0,.5}, radius = 0.1, filled = true, target = position, surface = surface, draw_on_ground = true } - rendering.draw_circle{ color = {0,1,0,.5}, radius = radius, filled = false, target = position, surface = surface, draw_on_ground = true } end --[[-- Remove the warp area for a warp From 94fa2bc8eafc130e2572c58bc2e4d740b981284e Mon Sep 17 00:00:00 2001 From: bbassie Date: Sun, 15 Nov 2020 01:46:59 +0100 Subject: [PATCH 10/26] Warp additions * Add bypass styling and functionality * Fix using wrong warp position for goto label * Add warp placement checks * Edit remove warp to keep the corpses of the entities * Fix warp label and textbox * Make Warp container wider by 20 --- locale/en/gui.cfg | 4 ++ modules/control/warps.lua | 16 +++++-- modules/gui/warp-list.lua | 97 +++++++++++++++++++++++++++++++-------- 3 files changed, 94 insertions(+), 23 deletions(-) diff --git a/locale/en/gui.cfg b/locale/en/gui.cfg index 18ffc672..5fd0e35e 100644 --- a/locale/en/gui.cfg +++ b/locale/en/gui.cfg @@ -98,6 +98,8 @@ main-tooltip=Warp List; Must be within __1__ tiles to use sub-tooltip=Warps can only be used every __1__ seconds and when within __2__ tiles too-close=Can't make warp; too close to warp: __1__ too-close-to-water=Cannot create warp this close to water, please move __1__ tiles away from the water body +too-close-to-entities=Cannot create warp this close to entities, please move __1__ tiles away from the entities or destroy them +too-close-to-neutral-entities=Cannot create warp this close to neutral entities, please move __1__ tiles away from the neutral entities or destroy them last-edit=Last edited by __1__ at __2__\nClick to view on map add-tooltip=Add new warp confirm-tooltip=Save changes @@ -107,6 +109,8 @@ edit-tooltip-none=Currently being edited by: Nobody discard-tooltip=Remove warp timer-tooltip=Warp cooldown takes __1__ seconds goto-tooltip=Go to x __1__ y __2__ +goto-bypass=Go to x __1__ y __2__, bypass mode +goto-bypass-different-network=Go to x __1__ y __2__, bypass mode different network goto-cooldown=You are on cooldown, wait for the cooldown to recharge goto-disabled=You must be on a warp point goto-different-network=The warp is not connected to the same energy network diff --git a/modules/control/warps.lua b/modules/control/warps.lua index bc1e7207..5c797805 100644 --- a/modules/control/warps.lua +++ b/modules/control/warps.lua @@ -208,9 +208,19 @@ function Warps.remove_warp_area(warp_id) {position.x+radius, position.y+radius} } - -- Remove all the entities that are in the area - local entities = surface.find_entities_filtered{ force='neutral', area=area } - for _, entity in pairs(entities) do if entity and entity.valid and entity.name ~= 'player' then entity.destroy() end end + -- Remove warp structure entities + local entity_names = {} + for _, entity in pairs(config.entities) do + table.insert(entity_names, entity[1]) + end + local entities = surface.find_entities_filtered{ force='neutral', area=area, name = entity_names } + for _, entity in pairs(entities) do + -- Destroy them, this will leave corpses of the entities that it distroyed. + if entity and entity.valid and entity.destructible == false then + entity.destructible = true + entity.die(entity.force) + end + end -- Rechart map area, usefull if warp is not covered by a radar game.forces[warp.force_name].chart(surface, area) diff --git a/modules/gui/warp-list.lua b/modules/gui/warp-list.lua index a0ff2187..45541720 100644 --- a/modules/gui/warp-list.lua +++ b/modules/gui/warp-list.lua @@ -82,11 +82,52 @@ Gui.element{ local position = player.position -- Check if the warp is too close to water - local water_tiles = surface.find_tiles_filtered{collision_mask = "water-tile", radius = config.standard_proximity_radius + 1, position = position, limit = 1} + local water_tiles = surface.find_tiles_filtered{ collision_mask = "water-tile", radius = config.standard_proximity_radius + 1, position = position } if #water_tiles > 0 then player_return({'expcore-commands.command-fail', {'warp-list.too-close-to-water', config.standard_proximity_radius + 1}}, 'orange_red', player) local play_sound = 'utility/wire_pickup' if game.player then game.player.play_sound{path=play_sound} end + for _, tile in pairs(water_tiles) do + rendering.draw_sprite{ + sprite = 'utility/rail_path_not_possible', + x_scale = 0.5, + y_scale = 0.5, + target = tile.position, + surface = surface, + players = {player}, + time_to_live = 60 + } + end + return + end + + -- Check if there are player entities in the way (has a bigger radius because the enities that can be placed by a player are larger) + local entities = surface.find_entities_filtered{ + radius = config.standard_proximity_radius + 4.5, + position = position, + collision_mask = { + 'item-layer', 'object-layer', 'player-layer', 'water-tile' + } + } + -- Remove 1 because that is the current player + if #entities-1 > 0 then + player_return({'expcore-commands.command-fail', {'warp-list.too-close-to-entities', config.standard_proximity_radius + 4.5}}, 'orange_red', player) + local play_sound = 'utility/wire_pickup' + if game.player then game.player.play_sound{path=play_sound} end + local character = player.character + for _, entity in pairs(entities) do + if entity ~= character then + rendering.draw_sprite{ + sprite = 'utility/rail_path_not_possible', + x_scale = 0.5, + y_scale = 0.5, + target = entity, + surface = surface, + players = {player}, + time_to_live = 60 + } + end + end return end @@ -162,6 +203,8 @@ Gui.element(function(event_trigger, parent, warp) end) :style{ single_line = false, + left_padding = 2, + right_padding = 2, horizontally_stretchable = true } :on_click(function(player, element, _) @@ -188,9 +231,11 @@ Gui.element(function(event_trigger, parent, warp) return element end) :style{ - maximal_width = 81, + maximal_width = 97, height = 22, - padding = -2 + padding = -2, + left_margin = 2, + right_margin = 2, } :on_confirmed(function(player, element, _) local warp_id = element.parent.caption @@ -336,40 +381,54 @@ Gui.element{ local warp_list_container -- Helper function to style and enable or disable a button element -local function update_icon_button(element, on_cooldown, warp, warp_player_is_on) +local function update_icon_button(element, on_cooldown, warp, warp_player_is_on, bypass_warp_proximity) -- Check if button element is valid if not element or not element.valid then return end local label_style = element.parent.parent['name-'..warp.warp_id][warp_label.name].style - if not warp_player_is_on then + if not warp_player_is_on and not bypass_warp_proximity then element.tooltip = {'warp-list.goto-disabled'} element.enabled = false - label_style.font_color = { 1, 1, 1, 0.7 } + label_style.font_color = Colors.light_grey return end - if warp_player_is_on.warp_id == warp.warp_id then + if warp_player_is_on and warp_player_is_on.warp_id == warp.warp_id then element.tooltip = {'warp-list.goto-same-warp'} element.enabled = false - label_style.font_color = { 1, 1, 1, 0.7 } + label_style.font_color = Colors.light_grey elseif on_cooldown then element.tooltip = {'warp-list.goto-cooldown'} element.enabled = false - label_style.font_color = { 1, 1, 1, 0.7 } + label_style.font_color = Colors.light_grey else + if not warp_player_is_on and bypass_warp_proximity then + local position = warp.position + element.tooltip = {'warp-list.goto-bypass', position.x, position.y} + element.enabled = true + label_style.font_color = Colors.dark_turquoise + return + end -- Check if the warps are in the same electricity network local warp_electric_network_id = warp.electric_pole and warp.electric_pole.electric_network_id or -1 local player_warp_electric_network_id = warp_player_is_on.electric_pole and warp_player_is_on.electric_pole.electric_network_id or -2 if warp_electric_network_id == player_warp_electric_network_id then - local position = warp_player_is_on.position + local position = warp.position element.tooltip = {'warp-list.goto-tooltip', position.x, position.y} element.enabled = true - label_style.font_color = { 1, 1, 1, 1 } + label_style.font_color = Colors.white else + if bypass_warp_proximity then + local position = warp.position + element.tooltip = {'warp-list.goto-bypass-different-network', position.x, position.y} + element.enabled = true + label_style.font_color = Colors.orange + return + end element.tooltip = {'warp-list.goto-different-network'} element.enabled = false - label_style.font_color = { 1, 0, 0, 0.7 } + label_style.font_color = Colors.crimson end end end @@ -389,10 +448,11 @@ function update_wrap_buttons(player, timer, warp_id) -- Change the enabled state of the warp buttons local warp_ids = Warps.get_force_warp_ids(player.force.name) + local bypass_warp_proximity = check_player_permissions(player, 'bypass_warp_proximity') for _, next_warp_id in pairs(warp_ids) do local element = scroll_table['icon-'..next_warp_id][warp_icon_button.name] local next_warp = Warps.get_warp(next_warp_id) - update_icon_button(element, on_cooldown, next_warp, warp_player_is_on) + update_icon_button(element, on_cooldown, next_warp, warp_player_is_on, bypass_warp_proximity) end end @@ -478,8 +538,8 @@ local function update_warp(player, warp_table, warp_id) local timer = PlayerCooldown:get(player) local current_warp_id = PlayerInRange:get(player) local to_warp = current_warp_id and Warps.get_warp(current_warp_id) or nil - local apply_proximity = not check_player_permissions(player, 'bypass_warp_proximity') - update_icon_button(warp_icon_element, timer > 0 or (apply_proximity and not current_warp_id), warp, to_warp) + local bypass_warp_proximity = check_player_permissions(player, 'bypass_warp_proximity') + update_icon_button(warp_icon_element, timer > 0, warp, to_warp, bypass_warp_proximity) end -- Update all the warps for a player @@ -510,7 +570,7 @@ end warp_list_container = Gui.element(function(event_trigger, parent) -- Draw the internal container - local container = Gui.container(parent, event_trigger, 200) + local container = Gui.container(parent, event_trigger, 220) -- Draw the header local header = Gui.header( @@ -583,10 +643,7 @@ PlayerInRange:on_update(function(player_name, warp_id) Gui.toggle_left_element(player, warp_list_container, warp_id ~= nil) end - -- Check if the player requires proximity - if not check_player_permissions(player, 'bypass_warp_proximity') then - update_wrap_buttons(player, nil, warp_id) - end + update_wrap_buttons(player, nil, warp_id) end) --- Update the warp cooldown progress bars to match the current cooldown From c308aa8c21e4f4cdb841cc20cc0a80df7031cb68 Mon Sep 17 00:00:00 2001 From: bbassie Date: Tue, 17 Nov 2020 23:35:14 +0100 Subject: [PATCH 11/26] * If statement restructured like suggested, seems to work fine; * Changed cooldown color to be same as the disabled one; --- modules/gui/warp-list.lua | 40 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/modules/gui/warp-list.lua b/modules/gui/warp-list.lua index 45541720..5b659324 100644 --- a/modules/gui/warp-list.lua +++ b/modules/gui/warp-list.lua @@ -387,14 +387,18 @@ local function update_icon_button(element, on_cooldown, warp, warp_player_is_on, local label_style = element.parent.parent['name-'..warp.warp_id][warp_label.name].style - if not warp_player_is_on and not bypass_warp_proximity then - element.tooltip = {'warp-list.goto-disabled'} - element.enabled = false - label_style.font_color = Colors.light_grey - return - end - - if warp_player_is_on and warp_player_is_on.warp_id == warp.warp_id then + if not warp_player_is_on then + if bypass_warp_proximity then + local position = warp.position + element.tooltip = {'warp-list.goto-bypass', position.x, position.y} + element.enabled = true + label_style.font_color = Colors.dark_turquoise + else + element.tooltip = {'warp-list.goto-disabled'} + element.enabled = false + label_style.font_color = Colors.light_grey + end + elseif warp_player_is_on and warp_player_is_on.warp_id == warp.warp_id then element.tooltip = {'warp-list.goto-same-warp'} element.enabled = false label_style.font_color = Colors.light_grey @@ -403,14 +407,6 @@ local function update_icon_button(element, on_cooldown, warp, warp_player_is_on, element.enabled = false label_style.font_color = Colors.light_grey else - if not warp_player_is_on and bypass_warp_proximity then - local position = warp.position - element.tooltip = {'warp-list.goto-bypass', position.x, position.y} - element.enabled = true - label_style.font_color = Colors.dark_turquoise - return - end - -- Check if the warps are in the same electricity network local warp_electric_network_id = warp.electric_pole and warp.electric_pole.electric_network_id or -1 local player_warp_electric_network_id = warp_player_is_on.electric_pole and warp_player_is_on.electric_pole.electric_network_id or -2 if warp_electric_network_id == player_warp_electric_network_id then @@ -418,14 +414,12 @@ local function update_icon_button(element, on_cooldown, warp, warp_player_is_on, element.tooltip = {'warp-list.goto-tooltip', position.x, position.y} element.enabled = true label_style.font_color = Colors.white + elseif bypass_warp_proximity then + local position = warp.position + element.tooltip = {'warp-list.goto-bypass-different-network', position.x, position.y} + element.enabled = true + label_style.font_color = Colors.orange else - if bypass_warp_proximity then - local position = warp.position - element.tooltip = {'warp-list.goto-bypass-different-network', position.x, position.y} - element.enabled = true - label_style.font_color = Colors.orange - return - end element.tooltip = {'warp-list.goto-different-network'} element.enabled = false label_style.font_color = Colors.crimson From d0afee78a45930fb63a024006afb25af0a95069f Mon Sep 17 00:00:00 2001 From: bbassie Date: Sat, 23 Jan 2021 23:01:05 +0100 Subject: [PATCH 12/26] Color status to icon status Because debate about the color usage I made the change to using icons. --- locale/en/gui.cfg | 10 ++++-- modules/gui/warp-list.lua | 65 ++++++++++++++++++++++++++++++++------- 2 files changed, 62 insertions(+), 13 deletions(-) diff --git a/locale/en/gui.cfg b/locale/en/gui.cfg index 5fd0e35e..3af12c0c 100644 --- a/locale/en/gui.cfg +++ b/locale/en/gui.cfg @@ -93,9 +93,15 @@ invalid=Autofill set to maximum amount: __1__ __2__ for __3__ inserted=Inserted __1__ __2__ into __3__ [warp-list] -main-caption=Warp List +main-caption=Warp List [img=info] main-tooltip=Warp List; Must be within __1__ tiles to use -sub-tooltip=Warps can only be used every __1__ seconds and when within __2__ tiles +sub-tooltip=Warps can only be used every __1__ seconds and when within __2__ tiles\n__3__\n__4__\n__5__\n__6__\n__7__\n__8__ +sub-tooltip-current= - __1__ This is the warp you are currently standing on; +sub-tooltip-connected= - __1__ This warp is connected to the same network as the warp you're standing on; +sub-tooltip-different= - __1__ This warp is not connected to the one u are standing on; +sub-tooltip-bypass= - __1__ This warp is out of range or in another network (but because of the permission you have you're able to warp to this warp); +sub-tooltip-not_available= - __1__ This warp is out of range; +sub-tooltip-cooldown= - __1__ You are currently on cooldown; too-close=Can't make warp; too close to warp: __1__ too-close-to-water=Cannot create warp this close to water, please move __1__ tiles away from the water body too-close-to-entities=Cannot create warp this close to entities, please move __1__ tiles away from the entities or destroy them diff --git a/modules/gui/warp-list.lua b/modules/gui/warp-list.lua index 5b659324..09651779 100644 --- a/modules/gui/warp-list.lua +++ b/modules/gui/warp-list.lua @@ -33,6 +33,15 @@ local Styles = { sprite22 = { height = 22, width = 22, padding = -2 }, sprite32 = { height = 32, width = 32, left_margin = 1 } } +--- Status icon of a warp +local warp_status_icons = { + cooldown = '[img=utility/multiplayer_waiting_icon]', + not_available = '[img=utility/not_available]', + bypass = '[img=utility/side_menu_bonus_icon]', + current = '[img=utility/side_menu_map_icon]', + connected = '[img=utility/logistic_network_panel_white]', + different = '[img=utility/warning_white]', +} --- Returns if a player is allowed to edit the given warp --- If a player is allowed to use the edit buttons @@ -214,6 +223,22 @@ end) player.zoom_to_world(position, 1.5) end) +--- Warp status, visible if the player is not in edit state +--- This will show if the warp is connected or not +-- @element warp_status +local warp_status = +Gui.element(function(event_trigger, parent) + -- Draw the element + return parent.add{ + name = event_trigger, + type = 'label', + caption = '[img=utility/electricity_icon_unplugged]', -- Temporary icon + } +end) +:style{ + single_line = false, +} + --- Warp textfield, visible if the player is in edit state -- @element warp_textfield local warp_textfield = @@ -231,7 +256,7 @@ Gui.element(function(event_trigger, parent, warp) return element end) :style{ - maximal_width = 97, + maximal_width = 73, height = 22, padding = -2, left_margin = 2, @@ -335,6 +360,7 @@ Gui.element(function(_, parent, warp) name_flow.style.padding = 0 -- Add the label and textfield of the warp + warp_status(name_flow) warp_label(name_flow, warp) warp_textfield(name_flow, warp) @@ -386,26 +412,31 @@ local function update_icon_button(element, on_cooldown, warp, warp_player_is_on, if not element or not element.valid then return end local label_style = element.parent.parent['name-'..warp.warp_id][warp_label.name].style + local warp_status_element = element.parent.parent['name-'..warp.warp_id][warp_status.name] if not warp_player_is_on then if bypass_warp_proximity then local position = warp.position element.tooltip = {'warp-list.goto-bypass', position.x, position.y} element.enabled = true - label_style.font_color = Colors.dark_turquoise + warp_status_element.caption = warp_status_icons.bypass + label_style.font = 'default-semibold' else element.tooltip = {'warp-list.goto-disabled'} element.enabled = false - label_style.font_color = Colors.light_grey + warp_status_element.caption = warp_status_icons.not_available + label_style.font = 'default' end - elseif warp_player_is_on and warp_player_is_on.warp_id == warp.warp_id then + elseif warp_player_is_on.warp_id == warp.warp_id then element.tooltip = {'warp-list.goto-same-warp'} element.enabled = false - label_style.font_color = Colors.light_grey + warp_status_element.caption = warp_status_icons.current + label_style.font = 'default' elseif on_cooldown then element.tooltip = {'warp-list.goto-cooldown'} element.enabled = false - label_style.font_color = Colors.light_grey + warp_status_element.caption = warp_status_icons.cooldown + label_style.font = 'default' else local warp_electric_network_id = warp.electric_pole and warp.electric_pole.electric_network_id or -1 local player_warp_electric_network_id = warp_player_is_on.electric_pole and warp_player_is_on.electric_pole.electric_network_id or -2 @@ -413,16 +444,19 @@ local function update_icon_button(element, on_cooldown, warp, warp_player_is_on, local position = warp.position element.tooltip = {'warp-list.goto-tooltip', position.x, position.y} element.enabled = true - label_style.font_color = Colors.white + warp_status_element.caption = warp_status_icons.connected + label_style.font = 'default-semibold' elseif bypass_warp_proximity then local position = warp.position element.tooltip = {'warp-list.goto-bypass-different-network', position.x, position.y} element.enabled = true - label_style.font_color = Colors.orange + warp_status_element.caption = warp_status_icons.bypass + label_style.font = 'default-semibold' else element.tooltip = {'warp-list.goto-different-network'} element.enabled = false - label_style.font_color = Colors.crimson + warp_status_element.caption = warp_status_icons.different + label_style.font = 'default' end end end @@ -486,7 +520,6 @@ local function update_warp(player, warp_table, warp_id) local players_editing = table.get_keys(warp.currently_editing) -- button_flow.visible = player_allowed_edit edit_warp_element.visible = player_allowed_edit - remove_warp_element.visible = player_allowed_edit -- Set the tooltip of the edit button if #players_editing > 0 then @@ -570,7 +603,17 @@ Gui.element(function(event_trigger, parent) local header = Gui.header( container, {'warp-list.main-caption'}, - {'warp-list.sub-tooltip', config.cooldown_duration, config.standard_proximity_radius}, + { + 'warp-list.sub-tooltip', + config.cooldown_duration, + config.standard_proximity_radius, + {'warp-list.sub-tooltip-current',warp_status_icons.current}, + {'warp-list.sub-tooltip-connected',warp_status_icons.connected}, + {'warp-list.sub-tooltip-different',warp_status_icons.different}, + {'warp-list.sub-tooltip-bypass',warp_status_icons.bypass}, + {'warp-list.sub-tooltip-not_available',warp_status_icons.not_available}, + {'warp-list.sub-tooltip-cooldown',warp_status_icons.cooldown}, + }, true ) From 8b717ee1a5817a1b5319c2cb0055914fd519b582 Mon Sep 17 00:00:00 2001 From: bbassie Date: Sun, 24 Jan 2021 01:58:30 +0100 Subject: [PATCH 13/26] Warp improvements * Fixed that it clears table every warp update. * Dirty fix unknown signal icon, it gets replaced by the old icon --- modules/control/warps.lua | 5 +++++ modules/gui/warp-list.lua | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/modules/control/warps.lua b/modules/control/warps.lua index 5c797805..e66d3998 100644 --- a/modules/control/warps.lua +++ b/modules/control/warps.lua @@ -359,6 +359,11 @@ Warps.update_warp(warp_id, 'My Warp', 'iron-plate', game.player.name) ]] function Warps.update_warp(warp_id, new_name, new_icon, player_name) WrapData:update(warp_id, function(_, warp) + -- If the icon is not valid then replace with the old icon + if new_icon and not new_icon.name or not new_icon.type then + new_icon = warp.icon + end + warp.last_edit_name = player_name or '' warp.last_edit_time = game.tick warp.name = new_name or warp.name diff --git a/modules/gui/warp-list.lua b/modules/gui/warp-list.lua index 09651779..95059507 100644 --- a/modules/gui/warp-list.lua +++ b/modules/gui/warp-list.lua @@ -550,9 +550,18 @@ local function update_warp(player, warp_table, warp_id) else -- Set the icon elements visibility warp_icon_element.visible = true + -- The SpritePath type is not the same as the SignalID type + local sprite = warp.icon.type .. '/' ..warp.icon.name + if warp.icon.type == 'virtual' then + sprite = 'virtual-signal/' ..warp.icon.name + end + warp_icon_element.sprite = sprite + -- Set icon edit to the warps icon + warp_icon_edit_element.elem_value = warp.icon warp_icon_edit_element.visible = false -- Set the name elements visibility label_element.visible = true + label_element.caption = warp.name textfield_element.visible = false -- Set the edit buttons cancel_edit_element.visible = false @@ -585,7 +594,6 @@ local function update_all_warp_force(force) local frame = Gui.get_left_element(player, warp_list_container) local warp_table = frame.container.scroll.table - warp_table.clear() for _, warp_id in ipairs(warp_ids) do update_warp(player, warp_table, warp_id) end From 7e7660f1e19be1e8502c3833c412917ac0a1f093 Mon Sep 17 00:00:00 2001 From: bbassie Date: Sun, 24 Jan 2021 02:26:26 +0100 Subject: [PATCH 14/26] Add tooltip to icon for better accessibility --- modules/gui/warp-list.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/gui/warp-list.lua b/modules/gui/warp-list.lua index 95059507..f3f08e7b 100644 --- a/modules/gui/warp-list.lua +++ b/modules/gui/warp-list.lua @@ -419,22 +419,26 @@ local function update_icon_button(element, on_cooldown, warp, warp_player_is_on, local position = warp.position element.tooltip = {'warp-list.goto-bypass', position.x, position.y} element.enabled = true + warp_status_element.tooltip = {'warp-list.goto-bypass', position.x, position.y} warp_status_element.caption = warp_status_icons.bypass label_style.font = 'default-semibold' else element.tooltip = {'warp-list.goto-disabled'} element.enabled = false + warp_status_element.tooltip = {'warp-list.goto-disabled'} warp_status_element.caption = warp_status_icons.not_available label_style.font = 'default' end elseif warp_player_is_on.warp_id == warp.warp_id then element.tooltip = {'warp-list.goto-same-warp'} element.enabled = false + warp_status_element.tooltip = {'warp-list.goto-same-warp'} warp_status_element.caption = warp_status_icons.current label_style.font = 'default' elseif on_cooldown then element.tooltip = {'warp-list.goto-cooldown'} element.enabled = false + warp_status_element.tooltip = {'warp-list.goto-cooldown'} warp_status_element.caption = warp_status_icons.cooldown label_style.font = 'default' else @@ -444,17 +448,20 @@ local function update_icon_button(element, on_cooldown, warp, warp_player_is_on, local position = warp.position element.tooltip = {'warp-list.goto-tooltip', position.x, position.y} element.enabled = true + warp_status_element.tooltip = {'warp-list.goto-tooltip', position.x, position.y} warp_status_element.caption = warp_status_icons.connected label_style.font = 'default-semibold' elseif bypass_warp_proximity then local position = warp.position element.tooltip = {'warp-list.goto-bypass-different-network', position.x, position.y} element.enabled = true + warp_status_element.tooltip = {'warp-list.goto-bypass-different-network', position.x, position.y} warp_status_element.caption = warp_status_icons.bypass label_style.font = 'default-semibold' else element.tooltip = {'warp-list.goto-different-network'} element.enabled = false + warp_status_element.tooltip = {'warp-list.goto-different-network'} warp_status_element.caption = warp_status_icons.different label_style.font = 'default' end From 290ec4f26b362a7d58175dbcf321f3bb9b891660 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sun, 24 Jan 2021 02:39:20 +0000 Subject: [PATCH 15/26] Bumped lua action to v8 --- .github/workflows/dev-deploy.yml | 2 +- .github/workflows/pr-checker.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dev-deploy.yml b/.github/workflows/dev-deploy.yml index 418d1360..f1d49189 100644 --- a/.github/workflows/dev-deploy.yml +++ b/.github/workflows/dev-deploy.yml @@ -18,7 +18,7 @@ jobs: fetch-depth: 0 - name: Install Lua - uses: leafo/gh-actions-lua@v5 + uses: leafo/gh-actions-lua@v8.0.0 - name: Install LuaRocks uses: leafo/gh-actions-luarocks@v2 diff --git a/.github/workflows/pr-checker.yml b/.github/workflows/pr-checker.yml index 77e50408..f2277cd5 100644 --- a/.github/workflows/pr-checker.yml +++ b/.github/workflows/pr-checker.yml @@ -28,7 +28,7 @@ jobs: fetch-depth: 0 - name: Install Lua - uses: leafo/gh-actions-lua@v5 + uses: leafo/gh-actions-lua@v8.0.0 - name: Install LuaRocks uses: leafo/gh-actions-luarocks@v2 From a7b1d33777b4e603bb512f4e908b7fd7438541a5 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sun, 24 Jan 2021 02:56:49 +0000 Subject: [PATCH 16/26] Bumped luarocks action to v4 --- .github/workflows/dev-deploy.yml | 2 +- .github/workflows/pr-checker.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dev-deploy.yml b/.github/workflows/dev-deploy.yml index f1d49189..d1773da3 100644 --- a/.github/workflows/dev-deploy.yml +++ b/.github/workflows/dev-deploy.yml @@ -21,7 +21,7 @@ jobs: uses: leafo/gh-actions-lua@v8.0.0 - name: Install LuaRocks - uses: leafo/gh-actions-luarocks@v2 + uses: leafo/gh-actions-luarocks@v4 - name: Install LDoc run: luarocks install ldoc 1.4.4-1 diff --git a/.github/workflows/pr-checker.yml b/.github/workflows/pr-checker.yml index f2277cd5..aaf4242a 100644 --- a/.github/workflows/pr-checker.yml +++ b/.github/workflows/pr-checker.yml @@ -31,7 +31,7 @@ jobs: uses: leafo/gh-actions-lua@v8.0.0 - name: Install LuaRocks - uses: leafo/gh-actions-luarocks@v2 + uses: leafo/gh-actions-luarocks@v4 - name: Install LDoc run: luarocks install ldoc 1.4.4-1 From ca8d03304c968d40457190db3d1fe96da960af29 Mon Sep 17 00:00:00 2001 From: Bastiaan Date: Sun, 24 Jan 2021 19:41:23 +0100 Subject: [PATCH 17/26] Removed one use variable Co-authored-by: Cooldude2606 --- modules/gui/warp-list.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/gui/warp-list.lua b/modules/gui/warp-list.lua index f3f08e7b..e4f08fc5 100644 --- a/modules/gui/warp-list.lua +++ b/modules/gui/warp-list.lua @@ -94,8 +94,7 @@ Gui.element{ local water_tiles = surface.find_tiles_filtered{ collision_mask = "water-tile", radius = config.standard_proximity_radius + 1, position = position } if #water_tiles > 0 then player_return({'expcore-commands.command-fail', {'warp-list.too-close-to-water', config.standard_proximity_radius + 1}}, 'orange_red', player) - local play_sound = 'utility/wire_pickup' - if game.player then game.player.play_sound{path=play_sound} end + if game.player then game.player.play_sound{ path = 'utility/wire_pickup' } end for _, tile in pairs(water_tiles) do rendering.draw_sprite{ sprite = 'utility/rail_path_not_possible', @@ -862,4 +861,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) \ No newline at end of file +Event.add(defines.events.on_chart_tag_removed, maintain_tag) From e72f927d64a4dc9844e252e9d9ef6a654a641f08 Mon Sep 17 00:00:00 2001 From: bbassie Date: Sun, 24 Jan 2021 20:11:11 +0100 Subject: [PATCH 18/26] Fixes to warp module * Variable name. * Moved variable initialisation to outside a function. --- modules/control/warps.lua | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/modules/control/warps.lua b/modules/control/warps.lua index e66d3998..14b308c9 100644 --- a/modules/control/warps.lua +++ b/modules/control/warps.lua @@ -37,6 +37,12 @@ Global.register(force_warps, function(tbl) force_warps = tbl end) +-- Create a array of entity names that will be added to the remove filter +local remove_warp_area_entity_names = {} +for _, entity in pairs(config.entities) do + table.insert(remove_warp_area_entity_names, entity[1]) +end + -- When a warp is updated change its chat tag and resort the warp order WrapData:on_update(function(warp_id, warp, old_warp) if warp then @@ -193,13 +199,13 @@ function Warps.remove_warp_area(warp_id) local radius = config.standard_proximity_radius -- Check that a warp area was created previously - local base_tile = warp.old_tile - if not base_tile then return end + local old_tile = warp.old_tile + if not old_tile then return end -- Loop over warp tiles and set them to the old tile that was below local tiles = {} for _, tile in pairs(config.tiles) do - table.insert(tiles, {name=base_tile, position={tile[2]+position.x, tile[3]+position.y}}) + table.insert(tiles, {name=old_tile, position={tile[2]+position.x, tile[3]+position.y}}) end surface.set_tiles(tiles) @@ -209,11 +215,7 @@ function Warps.remove_warp_area(warp_id) } -- Remove warp structure entities - local entity_names = {} - for _, entity in pairs(config.entities) do - table.insert(entity_names, entity[1]) - end - local entities = surface.find_entities_filtered{ force='neutral', area=area, name = entity_names } + local entities = surface.find_entities_filtered{ force='neutral', area=area, name = remove_warp_area_entity_names } for _, entity in pairs(entities) do -- Destroy them, this will leave corpses of the entities that it distroyed. if entity and entity.valid and entity.destructible == false then From b84dad66d597626aa05cac1803cac9f492bd2cee Mon Sep 17 00:00:00 2001 From: bbassie Date: Sun, 24 Jan 2021 20:13:43 +0100 Subject: [PATCH 19/26] Fixes to warp-list gui * Fixed indentation. * Updated function names to be more representative of what they do. * Added more comments * Moved some variables around for easier readability and such --- modules/gui/warp-list.lua | 51 +++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/modules/gui/warp-list.lua b/modules/gui/warp-list.lua index f3f08e7b..03a18308 100644 --- a/modules/gui/warp-list.lua +++ b/modules/gui/warp-list.lua @@ -35,12 +35,12 @@ local Styles = { } --- Status icon of a warp local warp_status_icons = { - cooldown = '[img=utility/multiplayer_waiting_icon]', + cooldown = '[img=utility/multiplayer_waiting_icon]', not_available = '[img=utility/not_available]', - bypass = '[img=utility/side_menu_bonus_icon]', - current = '[img=utility/side_menu_map_icon]', - connected = '[img=utility/logistic_network_panel_white]', - different = '[img=utility/warning_white]', + bypass = '[img=utility/side_menu_bonus_icon]', + current = '[img=utility/side_menu_map_icon]', + connected = '[img=utility/logistic_network_panel_white]', + different = '[img=utility/warning_white]', } --- Returns if a player is allowed to edit the given warp @@ -119,7 +119,7 @@ Gui.element{ } } -- Remove 1 because that is the current player - if #entities-1 > 0 then + if #entities > 1 then player_return({'expcore-commands.command-fail', {'warp-list.too-close-to-entities', config.standard_proximity_radius + 4.5}}, 'orange_red', player) local play_sound = 'utility/wire_pickup' if game.player then game.player.play_sound{path=play_sound} end @@ -244,16 +244,12 @@ end) local warp_textfield = Gui.element(function(event_trigger, parent, warp) -- Draw the element - local element = - parent.add{ + return parent.add{ name = event_trigger, type = 'textfield', text = warp.name, clear_and_focus_on_right_click = true } - - -- Return the element - return element end) :style{ maximal_width = 73, @@ -334,7 +330,7 @@ Gui.element{ Warps.set_editing(warp_id, player.name, true) end) -local update_wrap_buttons +local update_all_warp_elements --- Set of three elements which make up each row of the warp table -- @element add_warp_elements local add_warp_elements = @@ -407,14 +403,16 @@ Gui.element{ local warp_list_container -- Helper function to style and enable or disable a button element -local function update_icon_button(element, on_cooldown, warp, warp_player_is_on, bypass_warp_proximity) +local function update_warp_elements(element, warp, warp_player_is_on, on_cooldown, bypass_warp_proximity) -- Check if button element is valid if not element or not element.valid then return end local label_style = element.parent.parent['name-'..warp.warp_id][warp_label.name].style local warp_status_element = element.parent.parent['name-'..warp.warp_id][warp_status.name] + -- If player is not on a warp if not warp_player_is_on then + -- If player is allowed to warp without being on a warp. If not then disable the warp location if bypass_warp_proximity then local position = warp.position element.tooltip = {'warp-list.goto-bypass', position.x, position.y} @@ -429,12 +427,14 @@ local function update_icon_button(element, on_cooldown, warp, warp_player_is_on, warp_status_element.caption = warp_status_icons.not_available label_style.font = 'default' end + -- If player is on the warp that is being updated elseif warp_player_is_on.warp_id == warp.warp_id then element.tooltip = {'warp-list.goto-same-warp'} element.enabled = false warp_status_element.tooltip = {'warp-list.goto-same-warp'} warp_status_element.caption = warp_status_icons.current label_style.font = 'default' + -- If player is on cooldown elseif on_cooldown then element.tooltip = {'warp-list.goto-cooldown'} element.enabled = false @@ -442,6 +442,7 @@ local function update_icon_button(element, on_cooldown, warp, warp_player_is_on, warp_status_element.caption = warp_status_icons.cooldown label_style.font = 'default' else + -- If the warp the player is standing on is the same as the warp that is being updated local warp_electric_network_id = warp.electric_pole and warp.electric_pole.electric_network_id or -1 local player_warp_electric_network_id = warp_player_is_on.electric_pole and warp_player_is_on.electric_pole.electric_network_id or -2 if warp_electric_network_id == player_warp_electric_network_id then @@ -451,6 +452,7 @@ local function update_icon_button(element, on_cooldown, warp, warp_player_is_on, warp_status_element.tooltip = {'warp-list.goto-tooltip', position.x, position.y} warp_status_element.caption = warp_status_icons.connected label_style.font = 'default-semibold' + -- If the warp is not in the same network but the player is allowed to warp without being on a warp elseif bypass_warp_proximity then local position = warp.position element.tooltip = {'warp-list.goto-bypass-different-network', position.x, position.y} @@ -458,6 +460,7 @@ local function update_icon_button(element, on_cooldown, warp, warp_player_is_on, warp_status_element.tooltip = {'warp-list.goto-bypass-different-network', position.x, position.y} warp_status_element.caption = warp_status_icons.bypass label_style.font = 'default-semibold' + -- If the warp is in a different network than the one the player is standing on else element.tooltip = {'warp-list.goto-different-network'} element.enabled = false @@ -469,25 +472,26 @@ local function update_icon_button(element, on_cooldown, warp, warp_player_is_on, end --- Update the warp buttons for a player -function update_wrap_buttons(player, timer, warp_id) +function update_all_warp_elements(player, timer, warp_id) -- Get the warp table local frame = Gui.get_left_element(player, warp_list_container) local scroll_table = frame.container.scroll.table - -- Check if the buttons should be active + -- Check if the player is currenty on cooldown timer = timer or PlayerCooldown:get(player) - warp_id = warp_id or PlayerInRange:get(player) local on_cooldown = timer > 0 - + -- Get the warp the player is on + warp_id = warp_id or PlayerInRange:get(player) local warp_player_is_on = warp_id and Warps.get_warp(warp_id) or nil + -- Check player permission + local bypass_warp_proximity = check_player_permissions(player, 'bypass_warp_proximity') -- Change the enabled state of the warp buttons local warp_ids = Warps.get_force_warp_ids(player.force.name) - local bypass_warp_proximity = check_player_permissions(player, 'bypass_warp_proximity') for _, next_warp_id in pairs(warp_ids) do local element = scroll_table['icon-'..next_warp_id][warp_icon_button.name] local next_warp = Warps.get_warp(next_warp_id) - update_icon_button(element, on_cooldown, next_warp, warp_player_is_on, bypass_warp_proximity) + update_warp_elements(element, next_warp, warp_player_is_on, on_cooldown, bypass_warp_proximity) end end @@ -560,7 +564,7 @@ local function update_warp(player, warp_table, warp_id) -- The SpritePath type is not the same as the SignalID type local sprite = warp.icon.type .. '/' ..warp.icon.name if warp.icon.type == 'virtual' then - sprite = 'virtual-signal/' ..warp.icon.name + sprite = 'virtual-signal/' ..warp.icon.name end warp_icon_element.sprite = sprite -- Set icon edit to the warps icon @@ -570,6 +574,7 @@ local function update_warp(player, warp_table, warp_id) label_element.visible = true label_element.caption = warp.name textfield_element.visible = false + textfield_element.text = warp.name -- Set the edit buttons cancel_edit_element.visible = false confirm_edit_element.visible = false @@ -582,7 +587,7 @@ local function update_warp(player, warp_table, warp_id) local current_warp_id = PlayerInRange:get(player) local to_warp = current_warp_id and Warps.get_warp(current_warp_id) or nil local bypass_warp_proximity = check_player_permissions(player, 'bypass_warp_proximity') - update_icon_button(warp_icon_element, timer > 0, warp, to_warp, bypass_warp_proximity) + update_warp_elements(warp_icon_element, warp, to_warp, timer > 0, bypass_warp_proximity) end -- Update all the warps for a player @@ -695,7 +700,7 @@ PlayerInRange:on_update(function(player_name, warp_id) Gui.toggle_left_element(player, warp_list_container, warp_id ~= nil) end - update_wrap_buttons(player, nil, warp_id) + update_all_warp_elements(player, nil, warp_id) end) --- Update the warp cooldown progress bars to match the current cooldown @@ -714,7 +719,7 @@ PlayerCooldown:on_update(function(player_name, player_cooldown) -- Trigger update of buttons if cooldown is now 0 if player_cooldown == 0 then - update_wrap_buttons(player, player_cooldown, nil) + update_all_warp_elements(player, player_cooldown, nil) end end) From cd566c8246d7c7b588dc01a04a2e7b41a2e19a60 Mon Sep 17 00:00:00 2001 From: bbassie Date: Tue, 26 Jan 2021 23:01:07 +0100 Subject: [PATCH 20/26] Implemented requested changes * Pressing `Discard changes` removes warp if it has been pressed after `New warp`. * Changed `not_available` (not in range) status icon to a cross, fits the sizing of the other icons better. * Renamed locals key `'warp-list.discard-tooltip'` to `'warp-list.remove-tooltip'` * Added textfield squashable and strechable to make it dynamic to the container size. * Container size changes depending on permissiong `'allow_add_warp'` --- locale/en/gui.cfg | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/locale/en/gui.cfg b/locale/en/gui.cfg index 3af12c0c..7c625577 100644 --- a/locale/en/gui.cfg +++ b/locale/en/gui.cfg @@ -97,9 +97,9 @@ main-caption=Warp List [img=info] main-tooltip=Warp List; Must be within __1__ tiles to use sub-tooltip=Warps can only be used every __1__ seconds and when within __2__ tiles\n__3__\n__4__\n__5__\n__6__\n__7__\n__8__ sub-tooltip-current= - __1__ This is the warp you are currently standing on; -sub-tooltip-connected= - __1__ This warp is connected to the same network as the warp you're standing on; +sub-tooltip-connected= - __1__ This warp is in the same electricity network; sub-tooltip-different= - __1__ This warp is not connected to the one u are standing on; -sub-tooltip-bypass= - __1__ This warp is out of range or in another network (but because of the permission you have you're able to warp to this warp); +sub-tooltip-bypass= - __1__ Because your role you are allowed to go to this warp; sub-tooltip-not_available= - __1__ This warp is out of range; sub-tooltip-cooldown= - __1__ You are currently on cooldown; too-close=Can't make warp; too close to warp: __1__ @@ -112,7 +112,7 @@ confirm-tooltip=Save changes cancel-tooltip=Discard changes edit-tooltip=Currently being edited by: __1__ edit-tooltip-none=Currently being edited by: Nobody -discard-tooltip=Remove warp +remove-tooltip=Remove warp timer-tooltip=Warp cooldown takes __1__ seconds goto-tooltip=Go to x __1__ y __2__ goto-bypass=Go to x __1__ y __2__, bypass mode From 90f650ce7ac9f80893a897b4b195bd9ad66ca27f Mon Sep 17 00:00:00 2001 From: bbassie Date: Tue, 26 Jan 2021 23:01:07 +0100 Subject: [PATCH 21/26] Implemented requested changes * Pressing `Discard changes` removes warp if it has been pressed after `New warp`. * Changed `not_available` (not in range) status icon to a cross, fits the sizing of the other icons better. * Renamed locals key `'warp-list.discard-tooltip'` to `'warp-list.remove-tooltip'` * Added textfield squashable and strechable to make it dynamic to the container size. * Container size changes depending on permissiong `'allow_add_warp'` --- locale/en/gui.cfg | 6 +++--- modules/control/warps.lua | 4 +++- modules/gui/warp-list.lua | 35 ++++++++++++++++++++++++++++------- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/locale/en/gui.cfg b/locale/en/gui.cfg index 3af12c0c..7c625577 100644 --- a/locale/en/gui.cfg +++ b/locale/en/gui.cfg @@ -97,9 +97,9 @@ main-caption=Warp List [img=info] main-tooltip=Warp List; Must be within __1__ tiles to use sub-tooltip=Warps can only be used every __1__ seconds and when within __2__ tiles\n__3__\n__4__\n__5__\n__6__\n__7__\n__8__ sub-tooltip-current= - __1__ This is the warp you are currently standing on; -sub-tooltip-connected= - __1__ This warp is connected to the same network as the warp you're standing on; +sub-tooltip-connected= - __1__ This warp is in the same electricity network; sub-tooltip-different= - __1__ This warp is not connected to the one u are standing on; -sub-tooltip-bypass= - __1__ This warp is out of range or in another network (but because of the permission you have you're able to warp to this warp); +sub-tooltip-bypass= - __1__ Because your role you are allowed to go to this warp; sub-tooltip-not_available= - __1__ This warp is out of range; sub-tooltip-cooldown= - __1__ You are currently on cooldown; too-close=Can't make warp; too close to warp: __1__ @@ -112,7 +112,7 @@ confirm-tooltip=Save changes cancel-tooltip=Discard changes edit-tooltip=Currently being edited by: __1__ edit-tooltip-none=Currently being edited by: Nobody -discard-tooltip=Remove warp +remove-tooltip=Remove warp timer-tooltip=Warp cooldown takes __1__ seconds goto-tooltip=Go to x __1__ y __2__ goto-bypass=Go to x __1__ y __2__, bypass mode diff --git a/modules/control/warps.lua b/modules/control/warps.lua index 14b308c9..7ca057b3 100644 --- a/modules/control/warps.lua +++ b/modules/control/warps.lua @@ -46,6 +46,7 @@ end -- When a warp is updated change its chat tag and resort the warp order WrapData:on_update(function(warp_id, warp, old_warp) if warp then + warp.updates = warp.updates + 1 -- Update the map chart tag if there is one if warp.tag then Warps.make_warp_tag(warp_id) @@ -327,7 +328,8 @@ function Warps.add_warp(force_name, surface, position, player_name, warp_name) }, last_edit_name = player_name or '', last_edit_time = game.tick, - currently_editing = editing + currently_editing = editing, + updates = 0, }) return warp_id diff --git a/modules/gui/warp-list.lua b/modules/gui/warp-list.lua index 833b29f1..80884a26 100644 --- a/modules/gui/warp-list.lua +++ b/modules/gui/warp-list.lua @@ -36,7 +36,7 @@ local Styles = { --- Status icon of a warp local warp_status_icons = { cooldown = '[img=utility/multiplayer_waiting_icon]', - not_available = '[img=utility/not_available]', + not_available = '[img=utility/set_bar_slot]', bypass = '[img=utility/side_menu_bonus_icon]', current = '[img=utility/side_menu_map_icon]', connected = '[img=utility/logistic_network_panel_white]', @@ -210,7 +210,7 @@ Gui.element(function(event_trigger, parent, warp) } end) :style{ - single_line = false, + single_line = true, left_padding = 2, right_padding = 2, horizontally_stretchable = true @@ -235,6 +235,8 @@ Gui.element(function(event_trigger, parent) } end) :style{ + -- when editing mode because textbox is larger the icon would move up. + top_padding = 1, single_line = false, } @@ -251,7 +253,12 @@ Gui.element(function(event_trigger, parent, warp) } end) :style{ - maximal_width = 73, + -- Needed fields to make it squashable and strechable. + minimal_width = 10, + maximal_width = 300, + horizontally_squashable = "on", + horizontally_stretchable = "on", + -- Other styling height = 22, padding = -2, left_margin = 2, @@ -296,6 +303,12 @@ Gui.element{ :style(Styles.sprite22) :on_click(function(player, element) local warp_id = element.parent.caption + -- Check if this is this is the first edit, if so remove the warp. + local warp = Warps.get_warp(warp_id) + if warp.updates == 1 then + Warps.remove_warp(warp_id) + return + end Warps.set_editing(warp_id, player.name) end) @@ -305,7 +318,7 @@ local remove_warp_button = Gui.element{ type = 'sprite-button', sprite = 'utility/trash', - tooltip = {'warp-list.discard-tooltip'}, + tooltip = {'warp-list.remove-tooltip'}, style = 'shortcut_bar_button_red' } :style(Styles.sprite22) @@ -615,8 +628,12 @@ end -- @element warp_list_container warp_list_container = Gui.element(function(event_trigger, parent) + local player = Gui.get_player_from_element(parent) + -- Check if user has permission to add warps + local allow_add_warp = check_player_permissions(player, 'allow_add_warp') + -- Draw the internal container - local container = Gui.container(parent, event_trigger, 220) + local container = Gui.container(parent, event_trigger, allow_add_warp and 268 or 220) -- Draw the header local header = Gui.header( @@ -637,9 +654,8 @@ Gui.element(function(event_trigger, parent) ) -- 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') + add_new_warp_element.visible = allow_add_warp -- Draw the scroll table for the warps local scroll_table = Gui.scroll_table(container, 250, 3) @@ -835,6 +851,11 @@ local function role_update_event(event) local player = game.players[event.player_index] local container = Gui.get_left_element(player, warp_list_container).container + -- Check if user has permission to add warps + local allow_add_warp = check_player_permissions(player, 'allow_add_warp') + -- Update container size depending on if the player is allowed to add warps + container.parent.style.width = allow_add_warp and 268 or 220 + -- Update the warps, incase the user can now edit them local scroll_table = container.scroll.table update_all_warps(player, scroll_table) From 2fe9d5650e5e7d81e73e989a1fa3e0e6550ec0e8 Mon Sep 17 00:00:00 2001 From: bbassie Date: Fri, 29 Jan 2021 01:08:58 +0100 Subject: [PATCH 22/26] Finishing touches: * Removed 1 time use local * Fixed double permission check * Locale fixes --- locale/en/gui.cfg | 3 +-- modules/gui/warp-list.lua | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/locale/en/gui.cfg b/locale/en/gui.cfg index 7c625577..567e7220 100644 --- a/locale/en/gui.cfg +++ b/locale/en/gui.cfg @@ -99,13 +99,12 @@ sub-tooltip=Warps can only be used every __1__ seconds and when within __2__ til sub-tooltip-current= - __1__ This is the warp you are currently standing on; sub-tooltip-connected= - __1__ This warp is in the same electricity network; sub-tooltip-different= - __1__ This warp is not connected to the one u are standing on; -sub-tooltip-bypass= - __1__ Because your role you are allowed to go to this warp; +sub-tooltip-bypass= - __1__ This warp is possible to go to because of your role; sub-tooltip-not_available= - __1__ This warp is out of range; sub-tooltip-cooldown= - __1__ You are currently on cooldown; too-close=Can't make warp; too close to warp: __1__ too-close-to-water=Cannot create warp this close to water, please move __1__ tiles away from the water body too-close-to-entities=Cannot create warp this close to entities, please move __1__ tiles away from the entities or destroy them -too-close-to-neutral-entities=Cannot create warp this close to neutral entities, please move __1__ tiles away from the neutral entities or destroy them last-edit=Last edited by __1__ at __2__\nClick to view on map add-tooltip=Add new warp confirm-tooltip=Save changes diff --git a/modules/gui/warp-list.lua b/modules/gui/warp-list.lua index 80884a26..de0ab193 100644 --- a/modules/gui/warp-list.lua +++ b/modules/gui/warp-list.lua @@ -120,8 +120,7 @@ Gui.element{ -- Remove 1 because that is the current player if #entities > 1 then player_return({'expcore-commands.command-fail', {'warp-list.too-close-to-entities', config.standard_proximity_radius + 4.5}}, 'orange_red', player) - local play_sound = 'utility/wire_pickup' - if game.player then game.player.play_sound{path=play_sound} end + if game.player then game.player.play_sound{path='utility/wire_pickup'} end local character = player.character for _, entity in pairs(entities) do if entity ~= character then @@ -862,7 +861,7 @@ local function role_update_event(event) -- 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') + add_new_warp_element.visible = allow_add_warp end Event.add(Roles.events.on_role_assigned, role_update_event) From d987a6ca2cc50dca0f58ff8fc67f4b84feaa32a5 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Tue, 30 Mar 2021 03:35:43 +0100 Subject: [PATCH 23/26] Made requested locale changes --- locale/en/gui.cfg | 19 ++++++++++--------- modules/gui/warp-list.lua | 27 +++++++++++++++------------ 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/locale/en/gui.cfg b/locale/en/gui.cfg index 567e7220..9727629f 100644 --- a/locale/en/gui.cfg +++ b/locale/en/gui.cfg @@ -96,15 +96,15 @@ inserted=Inserted __1__ __2__ into __3__ main-caption=Warp List [img=info] main-tooltip=Warp List; Must be within __1__ tiles to use sub-tooltip=Warps can only be used every __1__ seconds and when within __2__ tiles\n__3__\n__4__\n__5__\n__6__\n__7__\n__8__ -sub-tooltip-current= - __1__ This is the warp you are currently standing on; -sub-tooltip-connected= - __1__ This warp is in the same electricity network; -sub-tooltip-different= - __1__ This warp is not connected to the one u are standing on; -sub-tooltip-bypass= - __1__ This warp is possible to go to because of your role; -sub-tooltip-not_available= - __1__ This warp is out of range; +sub-tooltip-current= - __1__ This is your current warp point; +sub-tooltip-connected= - __1__ You can travel to this warp point; +sub-tooltip-different= - __1__ This warp is on a different network; sub-tooltip-cooldown= - __1__ You are currently on cooldown; -too-close=Can't make warp; too close to warp: __1__ -too-close-to-water=Cannot create warp this close to water, please move __1__ tiles away from the water body -too-close-to-entities=Cannot create warp this close to entities, please move __1__ tiles away from the entities or destroy them +sub-tooltip-not_available= - __1__ You are not in range of a warp point; +sub-tooltip-bypass= - __1__ Your role allows you to travel here; +too-close=Cannot create warp; too close to existing warp point: __1__ +too-close-to-water=Cannot create warp; too close to water, please move __1__ tiles away from the water body or landfill it +too-close-to-entities=Cannot create warp; too close to other entities, please move __1__ tiles away from the entities or remove them last-edit=Last edited by __1__ at __2__\nClick to view on map add-tooltip=Add new warp confirm-tooltip=Save changes @@ -112,7 +112,8 @@ cancel-tooltip=Discard changes edit-tooltip=Currently being edited by: __1__ edit-tooltip-none=Currently being edited by: Nobody remove-tooltip=Remove warp -timer-tooltip=Warp cooldown takes __1__ seconds +timer-tooltip=Please wait __1__ seconds before you warp again +timer-tooltip-zero=After each warp you will need to wait __1__ seconds before you can warp again goto-tooltip=Go to x __1__ y __2__ goto-bypass=Go to x __1__ y __2__, bypass mode goto-bypass-different-network=Go to x __1__ y __2__, bypass mode different network diff --git a/modules/gui/warp-list.lua b/modules/gui/warp-list.lua index de0ab193..dbb8c401 100644 --- a/modules/gui/warp-list.lua +++ b/modules/gui/warp-list.lua @@ -402,7 +402,7 @@ end local warp_timer = Gui.element{ type = 'progressbar', - tooltip = {'warp-list.timer-tooltip', config.cooldown_duration}, + tooltip = {'warp-list.timer-tooltip-zero', config.cooldown_duration}, minimum_value = 0, maximum_value = config.cooldown_duration*config.update_smoothing } @@ -463,7 +463,7 @@ local function update_warp_elements(element, warp, warp_player_is_on, on_cooldow warp_status_element.tooltip = {'warp-list.goto-tooltip', position.x, position.y} warp_status_element.caption = warp_status_icons.connected label_style.font = 'default-semibold' - -- If the warp is not in the same network but the player is allowed to warp without being on a warp + -- If the warp is not on the same network but the player is allowed to warp without being on a warp elseif bypass_warp_proximity then local position = warp.position element.tooltip = {'warp-list.goto-bypass-different-network', position.x, position.y} @@ -471,7 +471,7 @@ local function update_warp_elements(element, warp, warp_player_is_on, on_cooldow warp_status_element.tooltip = {'warp-list.goto-bypass-different-network', position.x, position.y} warp_status_element.caption = warp_status_icons.bypass label_style.font = 'default-semibold' - -- If the warp is in a different network than the one the player is standing on + -- If the warp is on a different network than the one the player is standing on else element.tooltip = {'warp-list.goto-different-network'} element.enabled = false @@ -540,7 +540,6 @@ local function update_warp(player, warp_table, warp_id) -- Hide the edit button if the player is not allowed to edit the warp local player_allowed_edit = check_player_permissions(player, 'allow_edit_warp', warp) local players_editing = table.get_keys(warp.currently_editing) - -- button_flow.visible = player_allowed_edit edit_warp_element.visible = player_allowed_edit -- Set the tooltip of the edit button @@ -645,9 +644,9 @@ Gui.element(function(event_trigger, parent) {'warp-list.sub-tooltip-current',warp_status_icons.current}, {'warp-list.sub-tooltip-connected',warp_status_icons.connected}, {'warp-list.sub-tooltip-different',warp_status_icons.different}, - {'warp-list.sub-tooltip-bypass',warp_status_icons.bypass}, - {'warp-list.sub-tooltip-not_available',warp_status_icons.not_available}, {'warp-list.sub-tooltip-cooldown',warp_status_icons.cooldown}, + {'warp-list.sub-tooltip-not_available',warp_status_icons.not_available}, + {'warp-list.sub-tooltip-bypass',warp_status_icons.bypass}, }, true ) @@ -670,12 +669,14 @@ Gui.element(function(event_trigger, parent) local warp_timer_element = warp_timer(container) -- Change the progress of the warp timer - local progress = 1 local timer = PlayerCooldown:get(player) if timer > 0 then - progress = 1 - (timer/config.cooldown_duration) + warp_timer_element.tooltip = {'warp-list.timer-tooltip', timer} + warp_timer_element.value = 1 - (timer/config.cooldown_duration) + else + warp_timer_element.tooltip = {'warp-list.timer-tooltip-zero', config.cooldown_duration} + warp_timer_element.value = 1 end - warp_timer_element.value = progress -- Add any existing warps update_all_warps(player, scroll_table) @@ -725,11 +726,13 @@ PlayerCooldown:on_update(function(player_name, player_cooldown) local warp_timer_element = frame.container[warp_timer.name] -- Set the progress - local progress = 1 if player_cooldown and player_cooldown > 0 then - progress = 1 - (player_cooldown/config.cooldown_duration) + warp_timer_element.tooltip = {'warp-list.timer-tooltip', player_cooldown} + warp_timer_element.value = 1 - (player_cooldown/config.cooldown_duration) + else + warp_timer_element.tooltip = {'warp-list.timer-tooltip-zero', config.cooldown_duration} + warp_timer_element.value = 1 end - warp_timer_element.value = progress -- Trigger update of buttons if cooldown is now 0 if player_cooldown == 0 then From 023e142d241678fec0af9231bac5d0d7cbe7ba12 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Tue, 30 Mar 2021 03:39:11 +0100 Subject: [PATCH 24/26] Apply suggestions from code review All changes where corrections to spelling and grammar in comments. Co-authored-by: mark9064 <30447455+mark9064@users.noreply.github.com> --- modules/control/warps.lua | 14 +++++++------- modules/gui/warp-list.lua | 20 ++++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/modules/control/warps.lua b/modules/control/warps.lua index 7ca057b3..d7551032 100644 --- a/modules/control/warps.lua +++ b/modules/control/warps.lua @@ -37,13 +37,13 @@ Global.register(force_warps, function(tbl) force_warps = tbl end) --- Create a array of entity names that will be added to the remove filter +-- Create an array of entity names that will be added to the remove filter local remove_warp_area_entity_names = {} for _, entity in pairs(config.entities) do table.insert(remove_warp_area_entity_names, entity[1]) end --- When a warp is updated change its chat tag and resort the warp order +-- When a warp is updated change its chat tag and restore the warp order WrapData:on_update(function(warp_id, warp, old_warp) if warp then warp.updates = warp.updates + 1 @@ -156,7 +156,7 @@ function Warps.make_warp_area(warp_id) local posx = position.x local posy = position.y - -- Get the tile that is being replaced, store.update not needed as we dont want it to trigger + -- Get the tile that is being replaced, store.update not needed as we don't want it to trigger local old_tile = surface.get_tile(position).name warp.old_tile = old_tile @@ -203,7 +203,7 @@ function Warps.remove_warp_area(warp_id) local old_tile = warp.old_tile if not old_tile then return end - -- Loop over warp tiles and set them to the old tile that was below + -- Restore the original tiles before the creation of the warp local tiles = {} for _, tile in pairs(config.tiles) do table.insert(tiles, {name=old_tile, position={tile[2]+position.x, tile[3]+position.y}}) @@ -218,14 +218,14 @@ function Warps.remove_warp_area(warp_id) -- Remove warp structure entities local entities = surface.find_entities_filtered{ force='neutral', area=area, name = remove_warp_area_entity_names } for _, entity in pairs(entities) do - -- Destroy them, this will leave corpses of the entities that it distroyed. + -- Destroy them, this will leave corpses of the entities that it destroyed. if entity and entity.valid and entity.destructible == false then entity.destructible = true entity.die(entity.force) end end - -- Rechart map area, usefull if warp is not covered by a radar + -- Rechart map area, useful if warp is not covered by a radar game.forces[warp.force_name].chart(surface, area) end @@ -459,4 +459,4 @@ function Warps.get_editing(warp_id, player_name) end -- Module return -return Warps \ No newline at end of file +return Warps diff --git a/modules/gui/warp-list.lua b/modules/gui/warp-list.lua index dbb8c401..2dcc3382 100644 --- a/modules/gui/warp-list.lua +++ b/modules/gui/warp-list.lua @@ -234,7 +234,7 @@ Gui.element(function(event_trigger, parent) } end) :style{ - -- when editing mode because textbox is larger the icon would move up. + -- When editing mode because textbox is larger the icon would move up. top_padding = 1, single_line = false, } @@ -252,7 +252,7 @@ Gui.element(function(event_trigger, parent, warp) } end) :style{ - -- Needed fields to make it squashable and strechable. + -- Required fields to make it squashable and strechable. minimal_width = 10, maximal_width = 300, horizontally_squashable = "on", @@ -302,7 +302,7 @@ Gui.element{ :style(Styles.sprite22) :on_click(function(player, element) local warp_id = element.parent.caption - -- Check if this is this is the first edit, if so remove the warp. + -- Check if this is the first edit, if so remove the warp. local warp = Warps.get_warp(warp_id) if warp.updates == 1 then Warps.remove_warp(warp_id) @@ -346,7 +346,7 @@ local update_all_warp_elements -- @element add_warp_elements local add_warp_elements = Gui.element(function(_, parent, warp) - -- Add icon flow this will contain the warp button and warp icon edit button + -- Add icon flow, this will contain the warp button and warp icon edit button local icon_flow = parent.add{ name = 'icon-'..warp.warp_id, type = 'flow', @@ -358,7 +358,7 @@ Gui.element(function(_, parent, warp) warp_icon_button(icon_flow, warp) warp_icon_editing(icon_flow, warp) - -- Add name flow this will contain the warp label and textbox + -- Add name flow, this will contain the warp label and textbox local name_flow = parent.add{ type = 'flow', name = 'name-'..warp.warp_id, @@ -372,7 +372,7 @@ Gui.element(function(_, parent, warp) warp_textfield(name_flow, warp) - -- Add button flow this will contain buttons to manage this specific warp + -- Add button flow, this will contain buttons to manage this specific warp local button_flow = parent.add{ type = 'flow', name = 'button-'..warp.warp_id, @@ -510,13 +510,13 @@ end local function update_warp(player, warp_table, warp_id) local warp = Warps.get_warp(warp_id) - -- If the warp does no longer exist then remove the warp elements from the warp table + -- If the warp no longer exists then remove the warp elements from the warp table if not warp then remove_warp_elements(warp_table, warp_id) return end - -- Check if the warp elements are created, if they are not then create a new set of them + -- Create the warp elements if they do not already exist if not warp_table['icon-'..warp_id] then add_warp_elements(warp_table, warp) end @@ -551,7 +551,7 @@ local function update_warp(player, warp_table, warp_id) edit_warp_element.tooltip = {'warp-list.edit-tooltip-none'} end - -- Set the warp elements visibility based on if the user is editing or not + -- Set the visibility of the warp elements based on whether the user is editing or not local player_is_editing = warp.currently_editing[player.name] if player_is_editing then -- Set the icon elements visibility @@ -855,7 +855,7 @@ local function role_update_event(event) -- Check if user has permission to add warps local allow_add_warp = check_player_permissions(player, 'allow_add_warp') - -- Update container size depending on if the player is allowed to add warps + -- Update container size depending on whether the player is allowed to add warps container.parent.style.width = allow_add_warp and 268 or 220 -- Update the warps, incase the user can now edit them From cf612e6984e2b917a96cd4ccf7edb107d4a90405 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Tue, 30 Mar 2021 03:50:45 +0100 Subject: [PATCH 25/26] Fixed warp cooldown not using seconds --- locale/en/gui.cfg | 2 +- modules/gui/warp-list.lua | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/locale/en/gui.cfg b/locale/en/gui.cfg index 9727629f..0bb66d15 100644 --- a/locale/en/gui.cfg +++ b/locale/en/gui.cfg @@ -112,7 +112,7 @@ cancel-tooltip=Discard changes edit-tooltip=Currently being edited by: __1__ edit-tooltip-none=Currently being edited by: Nobody remove-tooltip=Remove warp -timer-tooltip=Please wait __1__ seconds before you warp again +timer-tooltip=Please wait __1__ seconds before you can warp timer-tooltip-zero=After each warp you will need to wait __1__ seconds before you can warp again goto-tooltip=Go to x __1__ y __2__ goto-bypass=Go to x __1__ y __2__, bypass mode diff --git a/modules/gui/warp-list.lua b/modules/gui/warp-list.lua index dbb8c401..5dab7aaa 100644 --- a/modules/gui/warp-list.lua +++ b/modules/gui/warp-list.lua @@ -174,7 +174,7 @@ end) -- Reset the warp cooldown if the player does not have unlimited warps if not check_player_permissions(player, 'bypass_warp_cooldown') then - PlayerCooldown:set(player, config.cooldown_duration) + PlayerCooldown:set(player, config.update_smoothing*config.cooldown_duration) end PlayerInRange:set(player, warp_id) @@ -671,8 +671,8 @@ Gui.element(function(event_trigger, parent) -- Change the progress of the warp timer local timer = PlayerCooldown:get(player) if timer > 0 then - warp_timer_element.tooltip = {'warp-list.timer-tooltip', timer} - warp_timer_element.value = 1 - (timer/config.cooldown_duration) + warp_timer_element.tooltip = {'warp-list.timer-tooltip', math.floor(timer/config.update_smoothing)} + warp_timer_element.value = 1 - (timer/config.update_smoothing/config.cooldown_duration) else warp_timer_element.tooltip = {'warp-list.timer-tooltip-zero', config.cooldown_duration} warp_timer_element.value = 1 @@ -727,8 +727,8 @@ PlayerCooldown:on_update(function(player_name, player_cooldown) -- Set the progress if player_cooldown and player_cooldown > 0 then - warp_timer_element.tooltip = {'warp-list.timer-tooltip', player_cooldown} - warp_timer_element.value = 1 - (player_cooldown/config.cooldown_duration) + warp_timer_element.tooltip = {'warp-list.timer-tooltip', math.floor(player_cooldown/config.update_smoothing)} + warp_timer_element.value = 1 - (player_cooldown/config.update_smoothing/config.cooldown_duration) else warp_timer_element.tooltip = {'warp-list.timer-tooltip-zero', config.cooldown_duration} warp_timer_element.value = 1 From 60bb28daea46ef67e12205f21cd573c0bd099a4e Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Tue, 30 Mar 2021 03:56:39 +0100 Subject: [PATCH 26/26] Chagned tooltips on buttons to match info tooltip --- locale/en/gui.cfg | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/locale/en/gui.cfg b/locale/en/gui.cfg index 0bb66d15..7c17b22b 100644 --- a/locale/en/gui.cfg +++ b/locale/en/gui.cfg @@ -117,10 +117,10 @@ timer-tooltip-zero=After each warp you will need to wait __1__ seconds before yo goto-tooltip=Go to x __1__ y __2__ goto-bypass=Go to x __1__ y __2__, bypass mode goto-bypass-different-network=Go to x __1__ y __2__, bypass mode different network -goto-cooldown=You are on cooldown, wait for the cooldown to recharge -goto-disabled=You must be on a warp point -goto-different-network=The warp is not connected to the same energy network goto-same-warp=You are already on this warp +goto-different-network=This warp is on a different network, use power poles to connect it +goto-cooldown=You are on cooldown, wait for your cooldown to recharge +goto-disabled=You are not on a warp point, walk to a warp point goto-edit=Edit warp icon [readme]