mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
Convert tasks, production, tools, and landfill
This commit is contained in:
@@ -145,7 +145,9 @@ elements.subframe_base = ExpGui.element("container_subframe")
|
|||||||
style = ExpGui.property_from_arg(1),
|
style = ExpGui.property_from_arg(1),
|
||||||
}
|
}
|
||||||
:style{
|
:style{
|
||||||
padding = { 2, 4 },
|
height = 0,
|
||||||
|
minimal_height = 36,
|
||||||
|
padding = { 3, 4 },
|
||||||
use_header_filler = false,
|
use_header_filler = false,
|
||||||
horizontally_stretchable = true,
|
horizontally_stretchable = true,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ return {
|
|||||||
"modules.gui.rocket-info",
|
"modules.gui.rocket-info",
|
||||||
"modules.gui.science-info",
|
"modules.gui.science-info",
|
||||||
"modules.gui.autofill",
|
"modules.gui.autofill",
|
||||||
--"modules.gui.task-list",
|
"modules.gui.task-list",
|
||||||
--"modules.gui.warp-list",
|
--"modules.gui.warp-list",
|
||||||
--"modules.gui.player-list",
|
--"modules.gui.player-list",
|
||||||
--"modules.gui.server-ups",
|
--"modules.gui.server-ups",
|
||||||
@@ -55,14 +55,14 @@ return {
|
|||||||
--"modules.gui.vlayer",
|
--"modules.gui.vlayer",
|
||||||
--"modules.gui.research",
|
--"modules.gui.research",
|
||||||
--"modules.gui.module",
|
--"modules.gui.module",
|
||||||
--"modules.gui.landfill",
|
"modules.gui.landfill",
|
||||||
--"modules.gui.tool",
|
"modules.gui.tool",
|
||||||
--"modules.gui.production",
|
"modules.gui.production",
|
||||||
--"modules.gui.playerdata",
|
--"modules.gui.playerdata",
|
||||||
--"modules.gui.surveillance",
|
--"modules.gui.surveillance",
|
||||||
--"modules.graftorio.require", -- graftorio
|
|
||||||
--"modules.gui.toolbar", -- must be loaded last to register toolbar handlers
|
--"modules.gui.toolbar", -- must be loaded last to register toolbar handlers
|
||||||
|
|
||||||
|
"modules.graftorio.require", -- graftorio
|
||||||
--- Config Files
|
--- Config Files
|
||||||
"config.expcore.permission_groups", -- loads some predefined permission groups
|
"config.expcore.permission_groups", -- loads some predefined permission groups
|
||||||
"config.expcore.roles", -- loads some predefined roles
|
"config.expcore.roles", -- loads some predefined roles
|
||||||
|
|||||||
@@ -164,6 +164,10 @@ Storage.register(Data, function(tbl)
|
|||||||
for name, datastore in pairs(Datastores) do
|
for name, datastore in pairs(Datastores) do
|
||||||
datastore.data = Data[name]
|
datastore.data = Data[name]
|
||||||
end
|
end
|
||||||
|
end, function(tbl)
|
||||||
|
for name in pairs(Datastores) do
|
||||||
|
tbl[name] = tbl[name] or {}
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
----- Datastore Manager
|
----- Datastore Manager
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
@alias landfill_container
|
@alias landfill_container
|
||||||
]]
|
]]
|
||||||
|
|
||||||
local Gui = require("modules.exp_legacy.expcore.gui") --- @dep expcore.gui
|
local Gui = require("modules/exp_gui")
|
||||||
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
||||||
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
|
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
|
||||||
|
|
||||||
@@ -93,8 +93,10 @@ for i, map in ipairs(curves) do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- @param blueprint LuaItemStack
|
||||||
|
--- @return table
|
||||||
local function landfill_gui_add_landfill(blueprint)
|
local function landfill_gui_add_landfill(blueprint)
|
||||||
local entities = blueprint.get_blueprint_entities()
|
local entities = assert(blueprint.get_blueprint_entities())
|
||||||
local tile_index = 0
|
local tile_index = 0
|
||||||
local new_tiles = {}
|
local new_tiles = {}
|
||||||
|
|
||||||
@@ -164,11 +166,16 @@ local function landfill_gui_add_landfill(blueprint)
|
|||||||
return { tiles = new_tiles }
|
return { tiles = new_tiles }
|
||||||
end
|
end
|
||||||
|
|
||||||
-- @element toolbar_button
|
--- Add the toolbar button
|
||||||
Gui.toolbar_button("item/landfill", { "landfill.main-tooltip" }, function(player)
|
Gui.create_toolbar_button{
|
||||||
|
name = "landfill",
|
||||||
|
sprite = "item/landfill",
|
||||||
|
tooltip = { "landfill.main-tooltip" },
|
||||||
|
visible = function(player, element)
|
||||||
return Roles.player_allowed(player, "gui/landfill")
|
return Roles.player_allowed(player, "gui/landfill")
|
||||||
end)
|
end
|
||||||
:on_click(function(player, _, _)
|
}:on_click(function(def, event, element)
|
||||||
|
local player = Gui.get_player(event)
|
||||||
if player.cursor_stack and player.cursor_stack.valid_for_read then
|
if player.cursor_stack and player.cursor_stack.valid_for_read then
|
||||||
if player.cursor_stack.type == "blueprint" and player.cursor_stack.is_blueprint_setup() then
|
if player.cursor_stack.type == "blueprint" and player.cursor_stack.is_blueprint_setup() then
|
||||||
local modified = landfill_gui_add_landfill(player.cursor_stack)
|
local modified = landfill_gui_add_landfill(player.cursor_stack)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
---- Production Data
|
---- Production Data
|
||||||
-- @gui Production
|
-- @gui Production
|
||||||
|
|
||||||
local Gui = require("modules.exp_legacy.expcore.gui") --- @dep expcore.gui
|
local Gui = require("modules/exp_gui")
|
||||||
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
||||||
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
|
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
|
||||||
|
|
||||||
@@ -35,8 +35,8 @@ end
|
|||||||
|
|
||||||
--- Display group
|
--- Display group
|
||||||
-- @element production_data_group
|
-- @element production_data_group
|
||||||
local production_data_group =
|
local production_data_group = Gui.element("production_data_group")
|
||||||
Gui.element(function(_definition, parent, i)
|
:draw(function(_def, parent, i)
|
||||||
local item
|
local item
|
||||||
|
|
||||||
if i == 0 then
|
if i == 0 then
|
||||||
@@ -93,10 +93,10 @@ local production_data_group =
|
|||||||
|
|
||||||
--- A vertical flow containing all the production data
|
--- A vertical flow containing all the production data
|
||||||
-- @element production_data_set
|
-- @element production_data_set
|
||||||
local production_data_set =
|
local production_data_set = Gui.element("production_data_set")
|
||||||
Gui.element(function(_, parent, name)
|
:draw(function(_, parent, name)
|
||||||
local production_set = parent.add{ type = "flow", direction = "vertical", name = name }
|
local production_set = parent.add{ type = "flow", direction = "vertical", name = name }
|
||||||
local disp = Gui.scroll_table(production_set, 350, 4, "disp")
|
local disp = Gui.elements.scroll_table(production_set, 350, 4, "disp")
|
||||||
|
|
||||||
production_data_group(disp, 0)
|
production_data_group(disp, 0)
|
||||||
|
|
||||||
@@ -111,31 +111,37 @@ local production_data_set =
|
|||||||
return production_set
|
return production_set
|
||||||
end)
|
end)
|
||||||
|
|
||||||
production_container =
|
production_container = Gui.element("production_container")
|
||||||
Gui.element(function(definition, parent)
|
:draw(function(def, parent)
|
||||||
local container = Gui.container(parent, definition.name, 350)
|
local container = Gui.elements.container(parent, 350)
|
||||||
|
|
||||||
production_data_set(container, "production_st")
|
production_data_set(container, "production_st")
|
||||||
|
|
||||||
return container.parent
|
return container.parent
|
||||||
end)
|
end)
|
||||||
:static_name(Gui.unique_static_name)
|
|
||||||
:add_to_left_flow()
|
|
||||||
|
|
||||||
Gui.left_toolbar_button("entity/assembling-machine-3", { "production.main-tooltip" }, production_container, function(player)
|
--- Add the element to the left flow with a toolbar button
|
||||||
|
Gui.add_left_element(production_container, false)
|
||||||
|
Gui.create_toolbar_button{
|
||||||
|
name = "production_toggle",
|
||||||
|
left_element = production_container,
|
||||||
|
sprite = "entity/assembling-machine-3",
|
||||||
|
tooltip = { "production.main-tooltip" },
|
||||||
|
visible = function(player, element)
|
||||||
return Roles.player_allowed(player, "gui/production")
|
return Roles.player_allowed(player, "gui/production")
|
||||||
end)
|
end
|
||||||
|
}
|
||||||
|
|
||||||
Event.on_nth_tick(60, function()
|
Event.on_nth_tick(60, function()
|
||||||
for _, player in pairs(game.connected_players) do
|
for _, player in pairs(game.connected_players) do
|
||||||
local frame = Gui.get_left_element(player, production_container)
|
local container = Gui.get_left_element(production_container, player)
|
||||||
local stat = player.force.get_item_production_statistics(player.surface) -- Allow remote view
|
local stat = player.force.get_item_production_statistics(player.surface) -- Allow remote view
|
||||||
local precision_value = precision[frame.container["production_st"].disp.table["production_0_e"].selected_index]
|
local precision_value = precision[container.frame["production_st"].disp.table["production_0_e"].selected_index]
|
||||||
local table = frame.container["production_st"].disp.table
|
local table = container.frame["production_st"].disp.table
|
||||||
|
|
||||||
for i = 1, 8 do
|
for i = 1, 8 do
|
||||||
local production_prefix = "production_" .. i
|
local production_prefix = "production_" .. i
|
||||||
local item = table[production_prefix .. "_e"].elem_value
|
local item = table[production_prefix .. "_e"].elem_value --[[ @as string ]]
|
||||||
|
|
||||||
if item then
|
if item then
|
||||||
local add = math.floor(stat.get_flow_count{ name = item, category = "input", precision_index = precision_value, count = false } / 6) / 10
|
local add = math.floor(stat.get_flow_count{ name = item, category = "input", precision_index = precision_value, count = false } / 6) / 10
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
]]
|
]]
|
||||||
|
|
||||||
local ExpUtil = require("modules/exp_util")
|
local ExpUtil = require("modules/exp_util")
|
||||||
local Gui = require("modules.exp_legacy.expcore.gui") --- @dep expcore.gui
|
local Gui = require("modules/exp_gui")
|
||||||
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
||||||
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
|
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
|
||||||
local Datastore = require("modules.exp_legacy.expcore.datastore") --- @dep expcore.datastore
|
local Datastore = require("modules.exp_legacy.expcore.datastore") --- @dep expcore.datastore
|
||||||
@@ -83,15 +83,18 @@ end
|
|||||||
|
|
||||||
--- Button displayed in the header bar, used to add a new task
|
--- Button displayed in the header bar, used to add a new task
|
||||||
-- @element add_new_task
|
-- @element add_new_task
|
||||||
local add_new_task =
|
local add_new_task = Gui.element("add_new_task")
|
||||||
Gui.element{
|
:draw{
|
||||||
type = "sprite-button",
|
type = "sprite-button",
|
||||||
sprite = "utility/add",
|
sprite = "utility/add",
|
||||||
tooltip = { "task-list.add-tooltip" },
|
tooltip = { "task-list.add-tooltip" },
|
||||||
style = "tool_button",
|
style = "tool_button",
|
||||||
name = Gui.unique_static_name,
|
name = Gui.property_from_name,
|
||||||
}:style(Styles.sprite22):on_click(
|
}
|
||||||
function(player, _, _)
|
:style(Styles.sprite22)
|
||||||
|
:on_click(
|
||||||
|
function(def, event, element)
|
||||||
|
local player = Gui.get_player(event)
|
||||||
-- Disable editing
|
-- Disable editing
|
||||||
PlayerIsEditing:set(player, false)
|
PlayerIsEditing:set(player, false)
|
||||||
-- Clear selected
|
-- Clear selected
|
||||||
@@ -103,8 +106,8 @@ local add_new_task =
|
|||||||
|
|
||||||
--- Header displayed when no tasks are in the task list
|
--- Header displayed when no tasks are in the task list
|
||||||
-- @element no_tasks_found
|
-- @element no_tasks_found
|
||||||
local no_tasks_found =
|
local no_tasks_found = Gui.element("no_tasks_found")
|
||||||
Gui.element(
|
:draw(
|
||||||
function(_, parent)
|
function(_, parent)
|
||||||
local header =
|
local header =
|
||||||
parent.add{
|
parent.add{
|
||||||
@@ -113,6 +116,7 @@ local no_tasks_found =
|
|||||||
style = "negative_subheader_frame",
|
style = "negative_subheader_frame",
|
||||||
}
|
}
|
||||||
header.style.horizontally_stretchable = true
|
header.style.horizontally_stretchable = true
|
||||||
|
header.style.bottom_margin = 0
|
||||||
-- Flow used for centering the content in the subheader
|
-- Flow used for centering the content in the subheader
|
||||||
local center =
|
local center =
|
||||||
header.add{
|
header.add{
|
||||||
@@ -134,50 +138,43 @@ local no_tasks_found =
|
|||||||
|
|
||||||
--- Frame element with the right styling
|
--- Frame element with the right styling
|
||||||
-- @element subfooter_frame
|
-- @element subfooter_frame
|
||||||
local subfooter_frame =
|
local subfooter_frame = Gui.element("task_list_subfooter_frame")
|
||||||
Gui.element(
|
:draw{
|
||||||
function(_, parent, name)
|
|
||||||
return parent.add{
|
|
||||||
type = "frame",
|
type = "frame",
|
||||||
name = name,
|
name = Gui.property_from_arg(1),
|
||||||
direction = "vertical",
|
direction = "vertical",
|
||||||
style = "subfooter_frame",
|
style = "subfooter_frame",
|
||||||
}
|
}
|
||||||
end
|
:style{
|
||||||
):style{
|
height = 0,
|
||||||
padding = 5,
|
padding = 5,
|
||||||
use_header_filler = false,
|
use_header_filler = false,
|
||||||
horizontally_stretchable = true,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
--- Label element preset
|
--- Label element preset
|
||||||
-- @element subfooter_label
|
-- @element subfooter_label
|
||||||
local subfooter_label =
|
local subfooter_label = Gui.element("task_list_subfooter_label")
|
||||||
Gui.element(
|
:draw{
|
||||||
function(_, parent, caption)
|
|
||||||
return parent.add{
|
|
||||||
name = "footer_label",
|
name = "footer_label",
|
||||||
type = "label",
|
type = "label",
|
||||||
style = "frame_title",
|
style = "frame_title",
|
||||||
caption = caption,
|
caption = Gui.property_from_arg(1),
|
||||||
}
|
}
|
||||||
end
|
|
||||||
)
|
|
||||||
|
|
||||||
--- Action flow that contains action buttons
|
--- Action flow that contains action buttons
|
||||||
-- @element subfooter_actions
|
-- @element subfooter_actions
|
||||||
local subfooter_actions =
|
local subfooter_actions = Gui.element("task_list_subfooter_actions")
|
||||||
Gui.element{
|
:draw{
|
||||||
type = "flow",
|
type = "flow",
|
||||||
name = "actions",
|
name = "actions",
|
||||||
}
|
}
|
||||||
|
|
||||||
--- Button element with a flow around it to fix duplicate name inside of the scroll flow
|
--- Button element with a flow around it to fix duplicate name inside of the scroll flow
|
||||||
-- @element task_list_item
|
-- @element task_list_item
|
||||||
local task_list_item =
|
local task_list_item = Gui.element("task_list_item")
|
||||||
Gui.element(
|
:draw(
|
||||||
function(definition, parent, task)
|
function(def, parent, task)
|
||||||
local flow = parent.add{
|
local flow = parent.add{
|
||||||
type = "flow",
|
type = "flow",
|
||||||
name = "task-" .. task.task_id,
|
name = "task-" .. task.task_id,
|
||||||
@@ -187,7 +184,7 @@ local task_list_item =
|
|||||||
flow.style.horizontally_stretchable = true
|
flow.style.horizontally_stretchable = true
|
||||||
|
|
||||||
local button = flow.add{
|
local button = flow.add{
|
||||||
name = definition.name,
|
name = def.name,
|
||||||
type = "button",
|
type = "button",
|
||||||
style = "list_box_item",
|
style = "list_box_item",
|
||||||
caption = task.title,
|
caption = task.title,
|
||||||
@@ -199,17 +196,19 @@ local task_list_item =
|
|||||||
|
|
||||||
return button
|
return button
|
||||||
end
|
end
|
||||||
):on_click(
|
)
|
||||||
function(player, element, _)
|
:on_click(
|
||||||
|
function(def, event, element)
|
||||||
|
local player = Gui.get_player(event)
|
||||||
local task_id = element.parent.caption
|
local task_id = element.parent.caption
|
||||||
PlayerSelected:set(player, task_id)
|
PlayerSelected:set(player, task_id)
|
||||||
end
|
end
|
||||||
):static_name(Gui.unique_static_name)
|
)
|
||||||
|
|
||||||
--- Scrollable list of all tasks
|
--- Scrollable list of all tasks
|
||||||
-- @element task_list
|
-- @element task_list
|
||||||
local task_list =
|
local task_list = Gui.element("task_list")
|
||||||
Gui.element(
|
:draw(
|
||||||
function(_, parent)
|
function(_, parent)
|
||||||
local scroll_pane =
|
local scroll_pane =
|
||||||
parent.add{
|
parent.add{
|
||||||
@@ -239,15 +238,16 @@ local task_list =
|
|||||||
|
|
||||||
--- Button element inside the task view footer to start editing a task
|
--- Button element inside the task view footer to start editing a task
|
||||||
-- @element task_view_edit_button
|
-- @element task_view_edit_button
|
||||||
local task_view_edit_button =
|
local task_view_edit_button = Gui.element("task_view_edit_button")
|
||||||
Gui.element{
|
:draw{
|
||||||
type = "button",
|
type = "button",
|
||||||
name = Gui.unique_static_name,
|
name = Gui.property_from_name,
|
||||||
caption = { "", "[img=utility/rename_icon] ", { "task-list.edit" } },
|
caption = { "", "[img=utility/rename_icon] ", { "task-list.edit" } },
|
||||||
tooltip = { "task-list.edit-tooltip" },
|
tooltip = { "task-list.edit-tooltip" },
|
||||||
style = "shortcut_bar_button",
|
style = "shortcut_bar_button",
|
||||||
}:style(Styles.footer_button):on_click(
|
}:style(Styles.footer_button):on_click(
|
||||||
function(player, _, _)
|
function(def, event, element)
|
||||||
|
local player = Gui.get_player(event)
|
||||||
local selected = PlayerSelected:get(player)
|
local selected = PlayerSelected:get(player)
|
||||||
PlayerIsEditing:set(player, true)
|
PlayerIsEditing:set(player, true)
|
||||||
|
|
||||||
@@ -257,30 +257,35 @@ local task_view_edit_button =
|
|||||||
|
|
||||||
--- Button to close the task view footer
|
--- Button to close the task view footer
|
||||||
-- @element task_view_close_button
|
-- @element task_view_close_button
|
||||||
local task_view_close_button =
|
local task_view_close_button = Gui.element("task_view_close_button")
|
||||||
Gui.element{
|
:draw{
|
||||||
type = "sprite-button",
|
type = "sprite-button",
|
||||||
sprite = "utility/collapse",
|
sprite = "utility/collapse",
|
||||||
style = "frame_action_button",
|
style = "frame_action_button",
|
||||||
tooltip = { "task-list.close-tooltip" },
|
tooltip = { "task-list.close-tooltip" },
|
||||||
}
|
}
|
||||||
:style(Styles.sprite22):on_click(
|
:style(Styles.sprite22)
|
||||||
function(player, _, _)
|
:on_click(
|
||||||
|
function(def, event, element)
|
||||||
|
local player = Gui.get_player(event)
|
||||||
PlayerSelected:set(player, nil)
|
PlayerSelected:set(player, nil)
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
--- Button to delete the task inside the task view footer
|
--- Button to delete the task inside the task view footer
|
||||||
-- @element task_view_delete_button
|
-- @element task_view_delete_button
|
||||||
local task_view_delete_button =
|
local task_view_delete_button = Gui.element("task_view_delete_button")
|
||||||
Gui.element{
|
:draw{
|
||||||
type = "button",
|
type = "button",
|
||||||
name = Gui.unique_static_name,
|
name = Gui.property_from_name,
|
||||||
caption = { "", "[img=utility/trash] ", { "task-list.delete" } },
|
caption = { "", "[img=utility/trash] ", { "task-list.delete" } },
|
||||||
tooltip = { "task-list.delete-tooltip" },
|
tooltip = { "task-list.delete-tooltip" },
|
||||||
style = "shortcut_bar_button_red",
|
style = "shortcut_bar_button_red",
|
||||||
}:style(Styles.footer_button):on_click(
|
}
|
||||||
function(player, _, _)
|
:style(Styles.footer_button)
|
||||||
|
:on_click(
|
||||||
|
function(def, event, element)
|
||||||
|
local player = Gui.get_player(event)
|
||||||
local selected = PlayerSelected:get(player)
|
local selected = PlayerSelected:get(player)
|
||||||
PlayerSelected:set(player, nil)
|
PlayerSelected:set(player, nil)
|
||||||
Tasks.remove_task(selected)
|
Tasks.remove_task(selected)
|
||||||
@@ -289,13 +294,13 @@ local task_view_delete_button =
|
|||||||
|
|
||||||
--- Subfooter inside the tasklist container that holds all the elements for viewing a task
|
--- Subfooter inside the tasklist container that holds all the elements for viewing a task
|
||||||
-- @element task_view_footer
|
-- @element task_view_footer
|
||||||
local task_view_footer =
|
local task_view_footer = Gui.element("task_view_footer")
|
||||||
Gui.element(
|
:draw(
|
||||||
function(_, parent)
|
function(_, parent)
|
||||||
local footer = subfooter_frame(parent, "view")
|
local footer = subfooter_frame(parent, "view")
|
||||||
local flow = footer.add{ type = "flow" }
|
local flow = footer.add{ type = "flow" }
|
||||||
subfooter_label(flow, { "task-list.view-footer-header" })
|
subfooter_label(flow, { "task-list.view-footer-header" })
|
||||||
local alignment = Gui.alignment(flow)
|
local alignment = Gui.elements.aligned_flow(flow)
|
||||||
task_view_close_button(alignment)
|
task_view_close_button(alignment)
|
||||||
local title_label =
|
local title_label =
|
||||||
footer.add{
|
footer.add{
|
||||||
@@ -345,9 +350,9 @@ local task_create_confirm_button
|
|||||||
|
|
||||||
--- Textfield element used in both the task create and edit footers
|
--- Textfield element used in both the task create and edit footers
|
||||||
-- @element task_message_textfield
|
-- @element task_message_textfield
|
||||||
local task_message_textfield =
|
local task_message_textfield = Gui.element("task_message_textfield")
|
||||||
Gui.element{
|
:draw{
|
||||||
name = Gui.unique_static_name,
|
name = Gui.property_from_name,
|
||||||
type = "text-box",
|
type = "text-box",
|
||||||
text = "",
|
text = "",
|
||||||
}:style{
|
}:style{
|
||||||
@@ -356,7 +361,8 @@ local task_message_textfield =
|
|||||||
horizontally_stretchable = true,
|
horizontally_stretchable = true,
|
||||||
}
|
}
|
||||||
:on_text_changed(
|
:on_text_changed(
|
||||||
function(player, element, _)
|
function(def, event, element)
|
||||||
|
local player = Gui.get_player(event)
|
||||||
local is_editing = PlayerIsEditing:get(player)
|
local is_editing = PlayerIsEditing:get(player)
|
||||||
local is_creating = PlayerIsCreating:get(player)
|
local is_creating = PlayerIsCreating:get(player)
|
||||||
|
|
||||||
@@ -372,15 +378,18 @@ local task_message_textfield =
|
|||||||
|
|
||||||
--- Button to confirm the changes inside the task edit footer
|
--- Button to confirm the changes inside the task edit footer
|
||||||
-- @element task_edit_confirm_button
|
-- @element task_edit_confirm_button
|
||||||
task_edit_confirm_button =
|
task_edit_confirm_button = Gui.element("task_edit_confirm_button")
|
||||||
Gui.element{
|
:draw{
|
||||||
type = "button",
|
type = "button",
|
||||||
name = Gui.unique_static_name,
|
name = Gui.property_from_name,
|
||||||
caption = { "", "[img=utility/check_mark] ", { "task-list.confirm" } },
|
caption = { "", "[img=utility/check_mark] ", { "task-list.confirm" } },
|
||||||
tooltip = { "task-list.confirm-tooltip" },
|
tooltip = { "task-list.confirm-tooltip" },
|
||||||
style = "shortcut_bar_button_green",
|
style = "shortcut_bar_button_green",
|
||||||
}:style(Styles.footer_button):on_click(
|
}
|
||||||
function(player, element, _)
|
:style(Styles.footer_button)
|
||||||
|
:on_click(
|
||||||
|
function(def, event, element)
|
||||||
|
local player = Gui.get_player(event)
|
||||||
local selected = PlayerSelected:get(player)
|
local selected = PlayerSelected:get(player)
|
||||||
PlayerIsEditing:set(player, false)
|
PlayerIsEditing:set(player, false)
|
||||||
local new_message = element.parent.parent[task_message_textfield.name].text
|
local new_message = element.parent.parent[task_message_textfield.name].text
|
||||||
@@ -392,14 +401,17 @@ task_edit_confirm_button =
|
|||||||
|
|
||||||
--- Button to discard the changes inside the task edit footer
|
--- Button to discard the changes inside the task edit footer
|
||||||
-- @element edit_task_discard_button
|
-- @element edit_task_discard_button
|
||||||
local edit_task_discard_button =
|
local edit_task_discard_button = Gui.element("edit_task_discard_button")
|
||||||
Gui.element{
|
:draw{
|
||||||
type = "button",
|
type = "button",
|
||||||
caption = { "", "[img=utility/close_black] ", { "task-list.discard" } },
|
caption = { "", "[img=utility/close_black] ", { "task-list.discard" } },
|
||||||
tooltip = { "task-list.discard-tooltip" },
|
tooltip = { "task-list.discard-tooltip" },
|
||||||
style = "shortcut_bar_button_red",
|
style = "shortcut_bar_button_red",
|
||||||
}:style(Styles.footer_button):on_click(
|
}
|
||||||
function(player, _, _)
|
:style(Styles.footer_button)
|
||||||
|
:on_click(
|
||||||
|
function(def, event, element)
|
||||||
|
local player = Gui.get_player(event)
|
||||||
local selected = PlayerSelected:get(player)
|
local selected = PlayerSelected:get(player)
|
||||||
Tasks.set_editing(selected, player.name, nil)
|
Tasks.set_editing(selected, player.name, nil)
|
||||||
PlayerIsEditing:set(player, false)
|
PlayerIsEditing:set(player, false)
|
||||||
@@ -408,8 +420,8 @@ local edit_task_discard_button =
|
|||||||
|
|
||||||
--- Subfooter inside the tasklist container that holds all the elements for editing a task
|
--- Subfooter inside the tasklist container that holds all the elements for editing a task
|
||||||
-- @element task_edit_footer
|
-- @element task_edit_footer
|
||||||
local task_edit_footer =
|
local task_edit_footer = Gui.element("task_edit_footer")
|
||||||
Gui.element(
|
:draw(
|
||||||
function(_, parent)
|
function(_, parent)
|
||||||
local footer = subfooter_frame(parent, "edit")
|
local footer = subfooter_frame(parent, "edit")
|
||||||
subfooter_label(footer, { "task-list.edit-footer-header" })
|
subfooter_label(footer, { "task-list.edit-footer-header" })
|
||||||
@@ -427,16 +439,19 @@ local task_edit_footer =
|
|||||||
|
|
||||||
--- Button to confirm the changes inside the task create footer
|
--- Button to confirm the changes inside the task create footer
|
||||||
-- @element task_create_confirm_button
|
-- @element task_create_confirm_button
|
||||||
task_create_confirm_button =
|
task_create_confirm_button = Gui.element("task_create_confirm_button")
|
||||||
Gui.element{
|
:draw{
|
||||||
type = "button",
|
type = "button",
|
||||||
name = Gui.unique_static_name,
|
name = Gui.property_from_name,
|
||||||
caption = { "", "[img=utility/check_mark] ", { "task-list.confirm" } },
|
caption = { "", "[img=utility/check_mark] ", { "task-list.confirm" } },
|
||||||
tooltip = { "task-list.confirm-tooltip" },
|
tooltip = { "task-list.confirm-tooltip" },
|
||||||
style = "shortcut_bar_button_green",
|
style = "shortcut_bar_button_green",
|
||||||
enabled = false,
|
enabled = false,
|
||||||
}:style(Styles.footer_button):on_click(
|
}
|
||||||
function(player, element, _)
|
:style(Styles.footer_button)
|
||||||
|
:on_click(
|
||||||
|
function(def, event, element)
|
||||||
|
local player = Gui.get_player(event)
|
||||||
local message = element.parent.parent[task_message_textfield.name].text
|
local message = element.parent.parent[task_message_textfield.name].text
|
||||||
PlayerIsCreating:set(player, false)
|
PlayerIsCreating:set(player, false)
|
||||||
local parsed = parse_message(message)
|
local parsed = parse_message(message)
|
||||||
@@ -447,22 +462,25 @@ task_create_confirm_button =
|
|||||||
|
|
||||||
--- Button to discard the changes inside the task create footer
|
--- Button to discard the changes inside the task create footer
|
||||||
-- @element task_create_discard_button
|
-- @element task_create_discard_button
|
||||||
local task_create_discard_button =
|
local task_create_discard_button = Gui.element("task_create_discard_button")
|
||||||
Gui.element{
|
:draw{
|
||||||
type = "button",
|
type = "button",
|
||||||
caption = { "", "[img=utility/close_black] ", { "task-list.discard" } },
|
caption = { "", "[img=utility/close_black] ", { "task-list.discard" } },
|
||||||
tooltip = { "task-list.discard-tooltip" },
|
tooltip = { "task-list.discard-tooltip" },
|
||||||
style = "shortcut_bar_button_red",
|
style = "shortcut_bar_button_red",
|
||||||
}:style(Styles.footer_button):on_click(
|
}
|
||||||
function(player, _, _)
|
:style(Styles.footer_button)
|
||||||
|
:on_click(
|
||||||
|
function(def, event, element)
|
||||||
|
local player = Gui.get_player(event)
|
||||||
PlayerIsCreating:set(player, false)
|
PlayerIsCreating:set(player, false)
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
--- Subfooter inside the tasklist container that holds all the elements to create a new task
|
--- Subfooter inside the tasklist container that holds all the elements to create a new task
|
||||||
-- @element task_create_footer
|
-- @element task_create_footer
|
||||||
local task_create_footer =
|
local task_create_footer = Gui.element("task_create_footer")
|
||||||
Gui.element(
|
:draw(
|
||||||
function(_, parent)
|
function(_, parent)
|
||||||
local footer = subfooter_frame(parent, "create")
|
local footer = subfooter_frame(parent, "create")
|
||||||
subfooter_label(footer, { "task-list.create-footer-header" })
|
subfooter_label(footer, { "task-list.create-footer-header" })
|
||||||
@@ -480,7 +498,7 @@ local task_create_footer =
|
|||||||
|
|
||||||
--- Clear and repopulate the task list with all current tasks
|
--- Clear and repopulate the task list with all current tasks
|
||||||
local repopulate_task_list = function(task_list_element)
|
local repopulate_task_list = function(task_list_element)
|
||||||
local force = Gui.get_player_from_element(task_list_element).force
|
local force = Gui.get_player(task_list_element).force
|
||||||
local task_ids = Tasks.get_force_task_ids(force.name)
|
local task_ids = Tasks.get_force_task_ids(force.name)
|
||||||
task_list_element.clear()
|
task_list_element.clear()
|
||||||
|
|
||||||
@@ -497,19 +515,21 @@ end
|
|||||||
|
|
||||||
--- Main task list container for the left flow
|
--- Main task list container for the left flow
|
||||||
-- @element task_list_container
|
-- @element task_list_container
|
||||||
local task_list_container =
|
local task_list_container = Gui.element("task_list_container")
|
||||||
Gui.element(
|
:draw(
|
||||||
function(definition, parent)
|
function(def, parent)
|
||||||
-- Draw the internal container
|
-- Draw the internal container
|
||||||
local container = Gui.container(parent, definition.name, 268)
|
local container = Gui.elements.container(parent, 268)
|
||||||
container.style.maximal_width = 268
|
container.style.maximal_width = 268
|
||||||
container.style.minimal_width = 268
|
|
||||||
|
|
||||||
-- Draw the header
|
-- Draw the header
|
||||||
local header = Gui.header(container, { "task-list.main-caption" }, { "task-list.sub-tooltip" }, true)
|
local header = Gui.elements.header(container, {
|
||||||
|
caption = { "task-list.main-caption" },
|
||||||
|
tooltip = { "task-list.sub-tooltip" },
|
||||||
|
})
|
||||||
|
|
||||||
-- Draw the new task button
|
-- Draw the new task button
|
||||||
local player = Gui.get_player_from_element(parent)
|
local player = Gui.get_player(parent)
|
||||||
local add_new_task_element = add_new_task(header)
|
local add_new_task_element = add_new_task(header)
|
||||||
add_new_task_element.visible = check_player_permissions(player)
|
add_new_task_element.visible = check_player_permissions(player)
|
||||||
|
|
||||||
@@ -529,23 +549,22 @@ local task_list_container =
|
|||||||
-- Return the external container
|
-- Return the external container
|
||||||
return container.parent
|
return container.parent
|
||||||
end
|
end
|
||||||
):static_name(Gui.unique_static_name):add_to_left_flow(
|
|
||||||
function(player)
|
|
||||||
local task_ids = Tasks.get_force_task_ids(player.force.name)
|
|
||||||
return #task_ids > 0
|
|
||||||
end
|
|
||||||
)
|
)
|
||||||
|
|
||||||
--- Button on the top flow used to toggle the task list container
|
--- Add the element to the left flow with a toolbar button
|
||||||
-- @element toggle_left_element
|
Gui.add_left_element(task_list_container, function(player)
|
||||||
Gui.left_toolbar_button(
|
local task_ids = Tasks.get_force_task_ids(player.force.name)
|
||||||
"utility/not_enough_repair_packs_icon",
|
return #task_ids > 0
|
||||||
{ "task-list.main-tooltip" },
|
end)
|
||||||
task_list_container,
|
Gui.create_toolbar_button{
|
||||||
function(player)
|
name = "task_list_toggle",
|
||||||
|
left_element = task_list_container,
|
||||||
|
sprite = "utility/not_enough_repair_packs_icon",
|
||||||
|
tooltip = { "task-list.main-tooltip" },
|
||||||
|
visible = function(player, element)
|
||||||
return Roles.player_allowed(player, "gui/task-list")
|
return Roles.player_allowed(player, "gui/task-list")
|
||||||
end
|
end
|
||||||
)
|
}
|
||||||
|
|
||||||
-- Function to update a single task and some of the elements inside the container
|
-- Function to update a single task and some of the elements inside the container
|
||||||
local update_task = function(player, task_list_element, task_id)
|
local update_task = function(player, task_list_element, task_id)
|
||||||
@@ -575,8 +594,8 @@ end
|
|||||||
-- Update the footer task edit view
|
-- Update the footer task edit view
|
||||||
local update_task_edit_footer = function(player, task_id)
|
local update_task_edit_footer = function(player, task_id)
|
||||||
local task = Tasks.get_task(task_id)
|
local task = Tasks.get_task(task_id)
|
||||||
local frame = Gui.get_left_element(player, task_list_container)
|
local container = Gui.get_left_element(task_list_container, player)
|
||||||
local edit_flow = frame.container.edit
|
local edit_flow = container.frame.edit
|
||||||
|
|
||||||
local message_element = edit_flow[task_message_textfield.name]
|
local message_element = edit_flow[task_message_textfield.name]
|
||||||
|
|
||||||
@@ -587,8 +606,8 @@ end
|
|||||||
-- Update the footer task view
|
-- Update the footer task view
|
||||||
local update_task_view_footer = function(player, task_id)
|
local update_task_view_footer = function(player, task_id)
|
||||||
local task = Tasks.get_task(task_id)
|
local task = Tasks.get_task(task_id)
|
||||||
local frame = Gui.get_left_element(player, task_list_container)
|
local container = Gui.get_left_element(task_list_container, player)
|
||||||
local view_flow = frame.container.view
|
local view_flow = container.frame.view
|
||||||
local has_permission = check_player_permissions(player, task)
|
local has_permission = check_player_permissions(player, task)
|
||||||
|
|
||||||
local title_element = view_flow.title
|
local title_element = view_flow.title
|
||||||
@@ -633,8 +652,8 @@ Tasks.on_update(
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local frame = Gui.get_left_element(player, task_list_container)
|
local container = Gui.get_left_element(task_list_container, player)
|
||||||
local task_list_element = frame.container.scroll.task_list
|
local task_list_element = container.frame.scroll.task_list
|
||||||
|
|
||||||
-- Update the task that was changed
|
-- Update the task that was changed
|
||||||
update_task(player, task_list_element, task_id)
|
update_task(player, task_list_element, task_id)
|
||||||
@@ -647,12 +666,12 @@ PlayerIsCreating:on_update(
|
|||||||
function(player_name, curr_state, _)
|
function(player_name, curr_state, _)
|
||||||
local player = game.players[player_name]
|
local player = game.players[player_name]
|
||||||
|
|
||||||
local frame = Gui.get_left_element(player, task_list_container)
|
local container = Gui.get_left_element(task_list_container, player)
|
||||||
local create = frame.container.create
|
local create = container.frame.create
|
||||||
|
|
||||||
-- Clear the textfield
|
-- Clear the textfield
|
||||||
local message_element = frame.container.create[task_message_textfield.name]
|
local message_element = container.frame.create[task_message_textfield.name]
|
||||||
local confirm_button_element = frame.container.create.actions[task_create_confirm_button.name]
|
local confirm_button_element = container.frame.create.actions[task_create_confirm_button.name]
|
||||||
message_element.focus()
|
message_element.focus()
|
||||||
message_element.text = ""
|
message_element.text = ""
|
||||||
confirm_button_element.enabled = false
|
confirm_button_element.enabled = false
|
||||||
@@ -670,10 +689,10 @@ PlayerSelected:on_update(
|
|||||||
function(player_name, curr_state, prev_state)
|
function(player_name, curr_state, prev_state)
|
||||||
local player = game.players[player_name]
|
local player = game.players[player_name]
|
||||||
|
|
||||||
local frame = Gui.get_left_element(player, task_list_container)
|
local container = Gui.get_left_element(task_list_container, player)
|
||||||
local task_list_element = frame.container.scroll.task_list
|
local task_list_element = container.frame.scroll.task_list
|
||||||
local view_flow = frame.container.view
|
local view_flow = container.frame.view
|
||||||
local edit_flow = frame.container.edit
|
local edit_flow = container.frame.edit
|
||||||
local is_editing = PlayerIsEditing:get(player)
|
local is_editing = PlayerIsEditing:get(player)
|
||||||
local is_creating = PlayerIsCreating:get(player)
|
local is_creating = PlayerIsCreating:get(player)
|
||||||
|
|
||||||
@@ -721,9 +740,9 @@ PlayerIsEditing:on_update(
|
|||||||
function(player_name, curr_state, _)
|
function(player_name, curr_state, _)
|
||||||
local player = game.players[player_name]
|
local player = game.players[player_name]
|
||||||
|
|
||||||
local frame = Gui.get_left_element(player, task_list_container)
|
local container = Gui.get_left_element(task_list_container, player)
|
||||||
local view_flow = frame.container.view
|
local view_flow = container.frame.view
|
||||||
local edit_flow = frame.container.edit
|
local edit_flow = container.frame.edit
|
||||||
|
|
||||||
local selected = PlayerSelected:get(player)
|
local selected = PlayerSelected:get(player)
|
||||||
if curr_state then
|
if curr_state then
|
||||||
@@ -740,7 +759,7 @@ PlayerIsEditing:on_update(
|
|||||||
--- Makes sure the right buttons are present when roles change
|
--- Makes sure the right buttons are present when roles change
|
||||||
local function role_update_event(event)
|
local function role_update_event(event)
|
||||||
local player = game.players[event.player_index]
|
local player = game.players[event.player_index]
|
||||||
local container = Gui.get_left_element(player, task_list_container).container
|
local frame = Gui.get_left_element(task_list_container, player).frame
|
||||||
-- Update the view task
|
-- Update the view task
|
||||||
local selected = PlayerSelected:get(player)
|
local selected = PlayerSelected:get(player)
|
||||||
if selected then
|
if selected then
|
||||||
@@ -752,7 +771,7 @@ local function role_update_event(event)
|
|||||||
|
|
||||||
-- Update the new task button and create footer in case the user can now add them
|
-- Update the new task button and create footer in case the user can now add them
|
||||||
local has_permission = check_player_permissions(player)
|
local has_permission = check_player_permissions(player)
|
||||||
local add_new_task_element = container.header.alignment[add_new_task.name]
|
local add_new_task_element = frame.header.alignment[add_new_task.name]
|
||||||
add_new_task_element.visible = has_permission
|
add_new_task_element.visible = has_permission
|
||||||
local is_creating = PlayerIsCreating:get(player)
|
local is_creating = PlayerIsCreating:get(player)
|
||||||
if is_creating and not has_permission then
|
if is_creating and not has_permission then
|
||||||
@@ -767,8 +786,8 @@ Event.add(Roles.events.on_role_unassigned, role_update_event)
|
|||||||
local function reset_task_list(event)
|
local function reset_task_list(event)
|
||||||
-- Repopulate the task list
|
-- Repopulate the task list
|
||||||
local player = game.players[event.player_index]
|
local player = game.players[event.player_index]
|
||||||
local frame = Gui.get_left_element(player, task_list_container)
|
local container = Gui.get_left_element(task_list_container, player)
|
||||||
local task_list_element = frame.container.scroll.task_list
|
local task_list_element = container.frame.scroll.task_list
|
||||||
repopulate_task_list(task_list_element)
|
repopulate_task_list(task_list_element)
|
||||||
|
|
||||||
-- Check if the selected task is still valid
|
-- Check if the selected task is still valid
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
]]
|
]]
|
||||||
|
|
||||||
local ExpUtil = require("modules/exp_util")
|
local ExpUtil = require("modules/exp_util")
|
||||||
local Gui = require("modules/exp_legacy/expcore/gui") --- @dep expcore.gui
|
local Gui = require("modules/exp_gui")
|
||||||
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
|
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
|
||||||
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
||||||
local Selection = require("modules/exp_legacy/modules/control/selection") --- @dep modules.control.selection
|
local Selection = require("modules/exp_legacy/modules/control/selection") --- @dep modules.control.selection
|
||||||
@@ -27,10 +27,10 @@ local style = {
|
|||||||
|
|
||||||
--- Arty label
|
--- Arty label
|
||||||
-- @element tool_gui_arty_l
|
-- @element tool_gui_arty_l
|
||||||
local tool_gui_arty_l =
|
local tool_gui_arty_l = Gui.element("tool_gui_arty_l")
|
||||||
Gui.element{
|
:draw{
|
||||||
type = "label",
|
type = "label",
|
||||||
name = "tool_arty_l",
|
name = Gui.property_from_name,
|
||||||
caption = { "tool.artillery" },
|
caption = { "tool.artillery" },
|
||||||
tooltip = { "tool.artillery-tooltip" },
|
tooltip = { "tool.artillery-tooltip" },
|
||||||
style = "heading_2_label"
|
style = "heading_2_label"
|
||||||
@@ -40,14 +40,15 @@ local tool_gui_arty_l =
|
|||||||
|
|
||||||
--- Arty button
|
--- Arty button
|
||||||
-- @element tool_gui_arty_b
|
-- @element tool_gui_arty_b
|
||||||
local tool_gui_arty_b =
|
local tool_gui_arty_b = Gui.element("tool_gui_arty_b")
|
||||||
Gui.element{
|
:draw{
|
||||||
type = "button",
|
type = "button",
|
||||||
name = "tool_arty_b",
|
name = Gui.property_from_name,
|
||||||
caption = { "tool.apply" }
|
caption = { "tool.apply" }
|
||||||
}:style(
|
}:style(
|
||||||
style.button
|
style.button
|
||||||
):on_click(function(player, _, _)
|
):on_click(function(def, event, element)
|
||||||
|
local player = Gui.get_player(event)
|
||||||
if Selection.is_selecting(player, SelectionArtyArea) then
|
if Selection.is_selecting(player, SelectionArtyArea) then
|
||||||
Selection.stop(player)
|
Selection.stop(player)
|
||||||
|
|
||||||
@@ -59,10 +60,10 @@ local tool_gui_arty_b =
|
|||||||
|
|
||||||
--- Waterfill label
|
--- Waterfill label
|
||||||
-- @element tool_gui_waterfill_l
|
-- @element tool_gui_waterfill_l
|
||||||
local tool_gui_waterfill_l =
|
local tool_gui_waterfill_l = Gui.element("tool_gui_waterfill_l")
|
||||||
Gui.element{
|
:draw{
|
||||||
type = "label",
|
type = "label",
|
||||||
name = "tool_waterfill_l",
|
name = Gui.property_from_name,
|
||||||
caption = { "tool.waterfill" },
|
caption = { "tool.waterfill" },
|
||||||
tooltip = { "tool.waterfill-tooltip" },
|
tooltip = { "tool.waterfill-tooltip" },
|
||||||
style = "heading_2_label"
|
style = "heading_2_label"
|
||||||
@@ -72,14 +73,15 @@ local tool_gui_waterfill_l =
|
|||||||
|
|
||||||
--- Waterfill button
|
--- Waterfill button
|
||||||
-- @element tool_gui_waterfill_b
|
-- @element tool_gui_waterfill_b
|
||||||
local tool_gui_waterfill_b =
|
local tool_gui_waterfill_b = Gui.element("tool_gui_waterfill_b")
|
||||||
Gui.element{
|
:draw{
|
||||||
type = "button",
|
type = "button",
|
||||||
name = "tool_waterfill_b",
|
name = Gui.property_from_name,
|
||||||
caption = { "tool.apply" }
|
caption = { "tool.apply" }
|
||||||
}:style(
|
}:style(
|
||||||
style.button
|
style.button
|
||||||
):on_click(function(player, _, _)
|
):on_click(function(def, event, element)
|
||||||
|
local player = Gui.get_player(event)
|
||||||
if Selection.is_selecting(player, SelectionWaterfillArea) then
|
if Selection.is_selecting(player, SelectionWaterfillArea) then
|
||||||
Selection.stop(player)
|
Selection.stop(player)
|
||||||
return player.print{ "exp-commands_waterfill.exit" }
|
return player.print{ "exp-commands_waterfill.exit" }
|
||||||
@@ -93,10 +95,10 @@ local tool_gui_waterfill_b =
|
|||||||
|
|
||||||
--- Train label
|
--- Train label
|
||||||
-- @element tool_gui_train_l
|
-- @element tool_gui_train_l
|
||||||
local tool_gui_train_l =
|
local tool_gui_train_l = Gui.element("tool_gui_train_l")
|
||||||
Gui.element{
|
:draw{
|
||||||
type = "label",
|
type = "label",
|
||||||
name = "tool_train_l",
|
name = Gui.property_from_name,
|
||||||
caption = { "tool.train" },
|
caption = { "tool.train" },
|
||||||
tooltip = { "tool.train-tooltip" },
|
tooltip = { "tool.train-tooltip" },
|
||||||
style = "heading_2_label"
|
style = "heading_2_label"
|
||||||
@@ -106,23 +108,24 @@ local tool_gui_train_l =
|
|||||||
|
|
||||||
--- Train button
|
--- Train button
|
||||||
-- @element tool_gui_train_b
|
-- @element tool_gui_train_b
|
||||||
local tool_gui_train_b =
|
local tool_gui_train_b = Gui.element("tool_gui_train_b")
|
||||||
Gui.element{
|
:draw{
|
||||||
type = "button",
|
type = "button",
|
||||||
name = "tool_train_b",
|
name = Gui.property_from_name,
|
||||||
caption = { "tool.apply" }
|
caption = { "tool.apply" }
|
||||||
}:style(
|
}:style(
|
||||||
style.button
|
style.button
|
||||||
):on_click(function(player, _, _)
|
):on_click(function(def, event, element)
|
||||||
|
local player = Gui.get_player(event)
|
||||||
addon_train.manual(player)
|
addon_train.manual(player)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--- Research label
|
--- Research label
|
||||||
-- @element tool_gui_research_l
|
-- @element tool_gui_research_l
|
||||||
local tool_gui_research_l =
|
local tool_gui_research_l = Gui.element("tool_gui_research_l")
|
||||||
Gui.element{
|
:draw{
|
||||||
type = "label",
|
type = "label",
|
||||||
name = "tool_research_l",
|
name = Gui.property_from_name,
|
||||||
caption = { "tool.research" },
|
caption = { "tool.research" },
|
||||||
tooltip = { "tool.research-tooltip" },
|
tooltip = { "tool.research-tooltip" },
|
||||||
style = "heading_2_label"
|
style = "heading_2_label"
|
||||||
@@ -132,18 +135,19 @@ local tool_gui_research_l =
|
|||||||
|
|
||||||
--- Research button
|
--- Research button
|
||||||
-- @element tool_gui_research_b
|
-- @element tool_gui_research_b
|
||||||
local tool_gui_research_b =
|
local tool_gui_research_b = Gui.element("tool_gui_research_b")
|
||||||
Gui.element{
|
:draw{
|
||||||
type = "button",
|
type = "button",
|
||||||
name = "tool_research_b",
|
name = Gui.property_from_name,
|
||||||
caption = { "tool.apply" }
|
caption = { "tool.apply" }
|
||||||
}:style(
|
}:style(
|
||||||
style.button
|
style.button
|
||||||
):on_click(function(player, _, _)
|
):on_click(function(def, event, element)
|
||||||
|
local player = Gui.get_player(event)
|
||||||
local enabled = addon_research.set_auto_research()
|
local enabled = addon_research.set_auto_research()
|
||||||
|
|
||||||
if enabled then
|
if enabled then
|
||||||
addon_research.res_queue(player.force, true)
|
addon_research.res_queue(player.force --[[ @as LuaForce ]], true)
|
||||||
end
|
end
|
||||||
|
|
||||||
local player_name = ExpUtil.format_player_name_locale(player)
|
local player_name = ExpUtil.format_player_name_locale(player)
|
||||||
@@ -152,10 +156,10 @@ local tool_gui_research_b =
|
|||||||
|
|
||||||
--- Spawn label
|
--- Spawn label
|
||||||
-- @element tool_gui_spawn_l
|
-- @element tool_gui_spawn_l
|
||||||
local tool_gui_spawn_l =
|
local tool_gui_spawn_l = Gui.element("tool_gui_spawn_l")
|
||||||
Gui.element{
|
:draw{
|
||||||
type = "label",
|
type = "label",
|
||||||
name = "tool_spawn_l",
|
name = Gui.property_from_name,
|
||||||
caption = { "tool.spawn" },
|
caption = { "tool.spawn" },
|
||||||
tooltip = { "tool.spawn-tooltip" },
|
tooltip = { "tool.spawn-tooltip" },
|
||||||
style = "heading_2_label"
|
style = "heading_2_label"
|
||||||
@@ -165,14 +169,15 @@ local tool_gui_spawn_l =
|
|||||||
|
|
||||||
--- Spawn button
|
--- Spawn button
|
||||||
-- @element tool_gui_spawn_b
|
-- @element tool_gui_spawn_b
|
||||||
local tool_gui_spawn_b =
|
local tool_gui_spawn_b = Gui.element("tool_gui_spawn_b")
|
||||||
Gui.element{
|
:draw{
|
||||||
type = "button",
|
type = "button",
|
||||||
name = "tool_spawn_b",
|
name = Gui.property_from_name,
|
||||||
caption = { "tool.apply" }
|
caption = { "tool.apply" }
|
||||||
}:style(
|
}:style(
|
||||||
style.button
|
style.button
|
||||||
):on_click(function(player, _, _)
|
):on_click(function(def, event, element)
|
||||||
|
local player = Gui.get_player(event)
|
||||||
if not player.character
|
if not player.character
|
||||||
or player.character.health <= 0
|
or player.character.health <= 0
|
||||||
or not ExpUtil.teleport_player(player, game.surfaces.nauvis, { 0, 0 }, "dismount") then
|
or not ExpUtil.teleport_player(player, game.surfaces.nauvis, { 0, 0 }, "dismount") then
|
||||||
@@ -180,9 +185,9 @@ local tool_gui_spawn_b =
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local function tool_perm(player)
|
local function tool_perm(player, container)
|
||||||
local frame = Gui.get_left_element(player, tool_container)
|
container = container or Gui.get_left_element(tool_container, player)
|
||||||
local disp = frame.container["tool_st"].disp.table
|
local disp = container.frame.tool_st.disp.table
|
||||||
local allowed
|
local allowed
|
||||||
|
|
||||||
allowed = Roles.player_allowed(player, "command/artillery")
|
allowed = Roles.player_allowed(player, "command/artillery")
|
||||||
@@ -208,10 +213,10 @@ end
|
|||||||
|
|
||||||
--- A vertical flow containing all the tool
|
--- A vertical flow containing all the tool
|
||||||
-- @element tool_set
|
-- @element tool_set
|
||||||
local tool_set =
|
local tool_set = Gui.element("tool_set")
|
||||||
Gui.element(function(_, parent, name)
|
:draw(function(_, parent, name)
|
||||||
local tool_set = parent.add{ type = "flow", direction = "vertical", name = name }
|
local tool_set = parent.add{ type = "flow", direction = "vertical", name = name }
|
||||||
local disp = Gui.scroll_table(tool_set, 240, 2, "disp")
|
local disp = Gui.elements.scroll_table(tool_set, 240, 2, "disp")
|
||||||
|
|
||||||
tool_gui_arty_l(disp)
|
tool_gui_arty_l(disp)
|
||||||
tool_gui_arty_b(disp)
|
tool_gui_arty_b(disp)
|
||||||
@@ -233,25 +238,29 @@ local tool_set =
|
|||||||
|
|
||||||
--- The main container for the tool gui
|
--- The main container for the tool gui
|
||||||
-- @element tool_container
|
-- @element tool_container
|
||||||
tool_container =
|
tool_container = Gui.element("tool_container")
|
||||||
Gui.element(function(definition, parent)
|
:draw(function(def, parent)
|
||||||
local player = Gui.get_player_from_element(parent)
|
local player = Gui.get_player(parent)
|
||||||
local container = Gui.container(parent, definition.name, 240)
|
local container = Gui.elements.container(parent, 240)
|
||||||
|
|
||||||
tool_set(container, "tool_st")
|
tool_set(container, "tool_st")
|
||||||
|
|
||||||
tool_perm(player)
|
tool_perm(player, container.parent)
|
||||||
|
|
||||||
return container.parent
|
return container.parent
|
||||||
end)
|
end)
|
||||||
:static_name(Gui.unique_static_name)
|
|
||||||
:add_to_left_flow()
|
|
||||||
|
|
||||||
--- Button on the top flow used to toggle the tool container
|
--- Add the element to the left flow with a toolbar button
|
||||||
-- @element toggle_left_element
|
Gui.add_left_element(tool_container, false)
|
||||||
Gui.left_toolbar_button("item/repair-pack", { "tool.main-tooltip" }, tool_container, function(player)
|
Gui.create_toolbar_button{
|
||||||
|
name = "tool_toggle",
|
||||||
|
left_element = tool_container,
|
||||||
|
sprite = "item/repair-pack",
|
||||||
|
tooltip = { "tool.main-tooltip" },
|
||||||
|
visible = function(player, element)
|
||||||
return Roles.player_allowed(player, "gui/tool")
|
return Roles.player_allowed(player, "gui/tool")
|
||||||
end)
|
end
|
||||||
|
}
|
||||||
|
|
||||||
Event.add(Roles.events.on_role_assigned, function(event)
|
Event.add(Roles.events.on_role_assigned, function(event)
|
||||||
tool_perm(game.players[event.player_index])
|
tool_perm(game.players[event.player_index])
|
||||||
|
|||||||
@@ -49,15 +49,16 @@ local ExpUtil = require("modules/exp_util")
|
|||||||
|
|
||||||
--- @class ExpUtil_Storage
|
--- @class ExpUtil_Storage
|
||||||
local Storage = {
|
local Storage = {
|
||||||
_registered = {}, --- @type table<string, { init: table, callback: fun(tbl: table) }> Map of all registered values and their initial values
|
_registered = {}, --- @type table<string, { init: table, callback: fun(tbl: table), on_init: fun(tbl: table)? }>
|
||||||
}
|
}
|
||||||
|
|
||||||
--- Register a new table to be stored in storage, can only be called once per file, can not be called during runtime
|
--- Register a new table to be stored in storage, can only be called once per file, can not be called during runtime
|
||||||
--- @generic T:table
|
--- @generic T:table
|
||||||
--- @param tbl T The initial value for the table you are registering, this should be a local variable
|
--- @param tbl T The initial value for the table you are registering, this should be a local variable
|
||||||
--- @param callback fun(tbl: T) The callback used to replace local references and metatables
|
--- @param callback fun(tbl: T) The callback used to replace local references and metatables
|
||||||
|
--- @param on_init fun(tbl: T)? The callback used to setup/validate storage if a static value is not enough
|
||||||
-- This function does not return the table because the callback can't access the local it would be assigned to
|
-- This function does not return the table because the callback can't access the local it would be assigned to
|
||||||
function Storage.register(tbl, callback)
|
function Storage.register(tbl, callback, on_init)
|
||||||
ExpUtil.assert_not_runtime()
|
ExpUtil.assert_not_runtime()
|
||||||
ExpUtil.assert_argument_type(tbl, "table", 1, "tbl")
|
ExpUtil.assert_argument_type(tbl, "table", 1, "tbl")
|
||||||
ExpUtil.assert_argument_type(callback, "function", 2, "callback")
|
ExpUtil.assert_argument_type(callback, "function", 2, "callback")
|
||||||
@@ -70,6 +71,7 @@ function Storage.register(tbl, callback)
|
|||||||
Storage._registered[name] = {
|
Storage._registered[name] = {
|
||||||
init = tbl,
|
init = tbl,
|
||||||
callback = callback,
|
callback = callback,
|
||||||
|
on_init = on_init,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -110,6 +112,9 @@ function Storage.on_init()
|
|||||||
if exp_storage[name] == nil then
|
if exp_storage[name] == nil then
|
||||||
exp_storage[name] = info.init
|
exp_storage[name] = info.init
|
||||||
end
|
end
|
||||||
|
if info.on_init then
|
||||||
|
info.on_init(exp_storage[name])
|
||||||
|
end
|
||||||
info.callback(exp_storage[name])
|
info.callback(exp_storage[name])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user