mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 04:21:41 +09:00
Refactor some of the Guis from the legacy plugin (#399)
* Fix bugs in core and add default args to Gui defs * Refactor production Gui * Refactor landfill blueprint button * Fix more bugs in core * Consistent naming of new guis * Refactor module inserter gui * Refactor surveillance gui * Add shorthand for data from arguments * Make element names consistent * Add types * Change how table rows work * Refactor player stats gui * Refactor quick actions gui * Refactor research milestones gui * Refactor player bonus gui * Refactor science production gui * Refactor autofill gui * Cleanup use of aligned flow * Rename "Gui.element" to "Gui.define" * Rename Gui types * Rename property_from_arg * Add guide for making guis * Add full reference document * Add condensed reference * Apply style guide to refactored guis * Bug fixes
This commit is contained in:
@@ -78,13 +78,13 @@ end
|
||||
|
||||
--- Will add a new warp to the list, checks if the player is too close to an existing one
|
||||
-- @element add_new_warp
|
||||
local add_new_warp = Gui.element("add_new_warp")
|
||||
local add_new_warp = Gui.define("add_new_warp")
|
||||
:draw{
|
||||
type = "sprite-button",
|
||||
sprite = "utility/add",
|
||||
tooltip = { "warp-list.add-tooltip" },
|
||||
style = "shortcut_bar_button",
|
||||
name = Gui.property_from_name,
|
||||
name = Gui.from_name,
|
||||
}
|
||||
:style(Styles.sprite22)
|
||||
:on_click(function(def, player, element)
|
||||
@@ -158,7 +158,7 @@ local add_new_warp = Gui.element("add_new_warp")
|
||||
|
||||
--- Warp icon button, this will trigger a warp when the player is able to
|
||||
-- @element warp_icon_button
|
||||
local warp_icon_button = Gui.element("warp_icon_button")
|
||||
local warp_icon_button = Gui.define("warp_icon_button")
|
||||
:draw(function(def, parent, warp)
|
||||
local warp_position = warp.position
|
||||
|
||||
@@ -193,7 +193,7 @@ local warp_icon_button = Gui.element("warp_icon_button")
|
||||
|
||||
--- The button that is visible when the warp is in edit state
|
||||
-- @element warp_icon_editing
|
||||
local warp_icon_editing = Gui.element("warp_icon_editing")
|
||||
local warp_icon_editing = Gui.define("warp_icon_editing")
|
||||
:draw(function(def, parent, warp)
|
||||
return parent.add{
|
||||
name = def.name,
|
||||
@@ -207,7 +207,7 @@ local warp_icon_editing = Gui.element("warp_icon_editing")
|
||||
|
||||
--- Warp label, visible if the player is not in edit state
|
||||
-- @element warp_label
|
||||
local warp_label = Gui.element("warp_label")
|
||||
local warp_label = Gui.define("warp_label")
|
||||
:draw(function(def, parent, warp)
|
||||
local last_edit_name = warp.last_edit_name
|
||||
local last_edit_time = warp.last_edit_time
|
||||
@@ -234,11 +234,11 @@ local warp_label = Gui.element("warp_label")
|
||||
--- 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("warp_status")
|
||||
local warp_status = Gui.define("warp_status")
|
||||
:draw{
|
||||
type = "label",
|
||||
caption = "[img=utility/electricity_icon_unplugged]", -- Temporary icon
|
||||
name = Gui.property_from_name,
|
||||
name = Gui.from_name,
|
||||
}
|
||||
:style{
|
||||
-- When editing mode because textbox is larger the icon would move up.
|
||||
@@ -248,7 +248,7 @@ local warp_status = Gui.element("warp_status")
|
||||
|
||||
--- Warp textfield, visible if the player is in edit state
|
||||
-- @element warp_textfield
|
||||
local warp_textfield = Gui.element("warp_textfield")
|
||||
local warp_textfield = Gui.define("warp_textfield")
|
||||
:draw(function(def, parent, warp)
|
||||
-- Draw the element
|
||||
return parent.add{
|
||||
@@ -281,13 +281,13 @@ local warp_textfield = Gui.element("warp_textfield")
|
||||
|
||||
--- Confirms the edit to name or icon of the warp
|
||||
-- @element confirm_edit_button
|
||||
local confirm_edit_button = Gui.element("confirm_edit_button")
|
||||
local confirm_edit_button = Gui.define("confirm_edit_button")
|
||||
:draw{
|
||||
type = "sprite-button",
|
||||
sprite = "utility/confirm_slot",
|
||||
tooltip = { "warp-list.confirm-tooltip" },
|
||||
style = "shortcut_bar_button_green",
|
||||
name = Gui.property_from_name,
|
||||
name = Gui.from_name,
|
||||
}
|
||||
:style(Styles.sprite22)
|
||||
:on_click(function(def, player, element)
|
||||
@@ -301,13 +301,13 @@ local confirm_edit_button = Gui.element("confirm_edit_button")
|
||||
|
||||
--- Cancels the editing changes of the selected warp name or icon
|
||||
-- @element cancel_edit_button
|
||||
local cancel_edit_button = Gui.element("cancel_edit_button")
|
||||
local cancel_edit_button = Gui.define("cancel_edit_button")
|
||||
:draw{
|
||||
type = "sprite-button",
|
||||
sprite = "utility/close_black",
|
||||
tooltip = { "warp-list.cancel-tooltip" },
|
||||
style = "shortcut_bar_button_red",
|
||||
name = Gui.property_from_name,
|
||||
name = Gui.from_name,
|
||||
}
|
||||
:style(Styles.sprite22)
|
||||
:on_click(function(def, player, element)
|
||||
@@ -323,13 +323,13 @@ local cancel_edit_button = Gui.element("cancel_edit_button")
|
||||
|
||||
--- Removes a warp from the list, including the physical area and map tag
|
||||
-- @element remove_warp_button
|
||||
local remove_warp_button = Gui.element("remove_warp_button")
|
||||
local remove_warp_button = Gui.define("remove_warp_button")
|
||||
:draw{
|
||||
type = "sprite-button",
|
||||
sprite = "utility/trash",
|
||||
tooltip = { "warp-list.remove-tooltip" },
|
||||
style = "shortcut_bar_button_red",
|
||||
name = Gui.property_from_name,
|
||||
name = Gui.from_name,
|
||||
}
|
||||
:style(Styles.sprite22)
|
||||
:on_click(function(def, player, element)
|
||||
@@ -339,13 +339,13 @@ local remove_warp_button = Gui.element("remove_warp_button")
|
||||
|
||||
--- Opens edit mode for the warp
|
||||
-- @element edit_warp_button
|
||||
local edit_warp_button = Gui.element("edit_warp_button")
|
||||
local edit_warp_button = Gui.define("edit_warp_button")
|
||||
:draw{
|
||||
type = "sprite-button",
|
||||
sprite = "utility/rename_icon",
|
||||
tooltip = { "warp-list.edit-tooltip-none" },
|
||||
style = "shortcut_bar_button",
|
||||
name = Gui.property_from_name,
|
||||
name = Gui.from_name,
|
||||
}
|
||||
:style(Styles.sprite22)
|
||||
:on_click(function(def, player, element)
|
||||
@@ -356,7 +356,7 @@ local edit_warp_button = Gui.element("edit_warp_button")
|
||||
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 = Gui.element("add_warp_elements")
|
||||
local add_warp_elements = Gui.define("add_warp_elements")
|
||||
:draw(function(_, parent, warp)
|
||||
-- Add icon flow, this will contain the warp button and warp icon edit button
|
||||
local icon_flow = parent.add{
|
||||
@@ -396,6 +396,8 @@ local add_warp_elements = Gui.element("add_warp_elements")
|
||||
cancel_edit_button(button_flow)
|
||||
edit_warp_button(button_flow)
|
||||
remove_warp_button(button_flow)
|
||||
|
||||
return Gui.no_return()
|
||||
end)
|
||||
|
||||
-- Removes the three elements that are added as part of the warp base
|
||||
@@ -407,10 +409,10 @@ end
|
||||
|
||||
--- This timer controls when a player is able to warp, eg every 60 seconds
|
||||
-- @element warp_timer
|
||||
local warp_timer = Gui.element("warp_timer")
|
||||
local warp_timer = Gui.define("warp_timer")
|
||||
:draw{
|
||||
type = "progressbar",
|
||||
name = Gui.property_from_name,
|
||||
name = Gui.from_name,
|
||||
tooltip = { "warp-list.timer-tooltip-zero", config.cooldown_duration },
|
||||
minimum_value = 0,
|
||||
maximum_value = config.cooldown_duration * config.update_smoothing,
|
||||
@@ -634,7 +636,7 @@ end
|
||||
|
||||
--- Main warp list container for the left flow
|
||||
-- @element warp_list_container
|
||||
warp_list_container = Gui.element("warp_list_container")
|
||||
warp_list_container = Gui.define("warp_list_container")
|
||||
:draw(function(def, parent)
|
||||
local player = Gui.get_player(parent)
|
||||
-- Check if user has permission to add warps
|
||||
@@ -816,7 +818,7 @@ Event.on_nth_tick(math.floor(60 / config.update_smoothing), function()
|
||||
|
||||
-- Change the enabled state of the add warp button
|
||||
local container = Gui.get_left_element(warp_list_container, player)
|
||||
local add_warp_element = container.frame.header.flow[add_new_warp.name]
|
||||
local add_warp_element = container.frame.header[add_new_warp.name]
|
||||
local old_closest_warp_name = add_warp_element.tooltip[2] or closest_warp and closest_warp.name
|
||||
local was_able_to_make_warp = add_warp_element.enabled
|
||||
local can_make_warp = closest_distance == nil or closest_distance > mr2
|
||||
@@ -875,7 +877,7 @@ local function role_update_event(event)
|
||||
update_all_warps(player, scroll_table)
|
||||
|
||||
-- Update the new warp button in case the user can now add them
|
||||
local add_new_warp_element = frame.header.flow[add_new_warp.name]
|
||||
local add_new_warp_element = frame.header[add_new_warp.name]
|
||||
add_new_warp_element.visible = allow_add_warp
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user