mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
Merge branch 'main' of https://github.com/PHIDIAS0303/ExpCluster
This commit is contained in:
@@ -1,373 +0,0 @@
|
||||
--[[-- Gui Module - Autofill
|
||||
- Adds a button to enable Autofill
|
||||
@gui Autofill
|
||||
@alias autofill
|
||||
]]
|
||||
|
||||
local Storage = require("modules/exp_util/storage")
|
||||
local FlyingText = require("modules/exp_util/flying_text")
|
||||
local Gui = require("modules/exp_gui")
|
||||
local Roles = require("modules.exp_legacy.expcore.roles")
|
||||
local config = require("modules.exp_legacy.config.gui.autofill") -- @dep config.gui.autofill
|
||||
local Event = require("modules/exp_legacy/utils/event") -- @dep utils.event
|
||||
|
||||
--- Table that stores if autofill is enabled or not
|
||||
local autofill_player_settings = {}
|
||||
Storage.register(autofill_player_settings, function(tbl)
|
||||
autofill_player_settings = tbl
|
||||
end)
|
||||
|
||||
local autofill_container
|
||||
|
||||
local function rich_img(type, value)
|
||||
return "[img=" .. type .. "/" .. value .. "]"
|
||||
end
|
||||
|
||||
--- Toggle entity section visibility
|
||||
-- @element toggle_item_button
|
||||
local toggle_section = Gui.element("autofill_toggle_section")
|
||||
:draw{
|
||||
type = "sprite-button",
|
||||
sprite = "utility/expand",
|
||||
tooltip = { "autofill.toggle-section-tooltip" },
|
||||
style = "frame_action_button",
|
||||
name = Gui.property_from_name,
|
||||
}
|
||||
:style(Gui.styles.sprite{
|
||||
size = 20
|
||||
})
|
||||
:on_click(function(def, player, element)
|
||||
local header_flow = assert(element.parent)
|
||||
local flow_name = header_flow.caption
|
||||
local flow = header_flow.parent.parent[flow_name]
|
||||
if Gui.toggle_visible_state(flow) then
|
||||
element.sprite = "utility/collapse"
|
||||
element.tooltip = { "autofill.toggle-section-collapse-tooltip" }
|
||||
else
|
||||
element.sprite = "utility/expand"
|
||||
element.tooltip = { "autofill.toggle-section-tooltip" }
|
||||
end
|
||||
end)
|
||||
|
||||
--- Toggle enitity button, used for toggling autofill for the specific entity
|
||||
-- All entity autofill settings will be ignored if its disabled
|
||||
-- @element entity_toggle
|
||||
local entity_toggle = Gui.element("entity_toggle")
|
||||
:draw(function(_, parent, entity_name)
|
||||
return parent.add{
|
||||
type = "sprite-button",
|
||||
sprite = "utility/confirm_slot",
|
||||
tooltip = { "autofill.toggle-entity-tooltip", rich_img("item", entity_name) },
|
||||
style = "shortcut_bar_button_green",
|
||||
}
|
||||
end)
|
||||
:style(Gui.styles.sprite{
|
||||
size = 22
|
||||
})
|
||||
:on_click(function(def, player, element)
|
||||
local entity_name = string.match(element.parent.parent.name, "(.*)%-header")
|
||||
if not autofill_player_settings[player.name] then return end
|
||||
local setting = autofill_player_settings[player.name][entity_name]
|
||||
if not setting then return end
|
||||
if setting.enabled then
|
||||
setting.enabled = false
|
||||
element.sprite = "utility/close_black"
|
||||
element.style = "shortcut_bar_button_red"
|
||||
else
|
||||
setting.enabled = true
|
||||
element.sprite = "utility/confirm_slot"
|
||||
element.style = "shortcut_bar_button_green"
|
||||
end
|
||||
-- Correct the button size
|
||||
local style = element.style
|
||||
style.padding = -2
|
||||
style.height = 22
|
||||
style.width = 22
|
||||
end)
|
||||
|
||||
--- Draw a section header and main scroll
|
||||
-- @element autofill_section_container
|
||||
local section = Gui.element("autofill_section")
|
||||
:draw(function(def, parent, section_name, table_size)
|
||||
-- Draw the header for the section
|
||||
local header = Gui.elements.header(parent, {
|
||||
name = section_name .. "-header",
|
||||
caption = { "autofill.toggle-section-caption", rich_img("item", section_name), { "entity-name." .. section_name } },
|
||||
tooltip = { "autofill.toggle-section-tooltip" },
|
||||
label_name = "label",
|
||||
})
|
||||
|
||||
def:link_element(header.parent.label)
|
||||
|
||||
-- Right aligned button to toggle the section
|
||||
header.caption = section_name
|
||||
entity_toggle(header, section_name)
|
||||
toggle_section(header)
|
||||
|
||||
local section_table = parent.add{
|
||||
type = "table",
|
||||
name = section_name,
|
||||
column_count = table_size,
|
||||
}
|
||||
|
||||
section_table.visible = false
|
||||
|
||||
return def:unlink_element(section_table)
|
||||
end)
|
||||
:on_click(function(def, player, element, event)
|
||||
event.element = element.parent.flow[toggle_section.name]
|
||||
toggle_section:raise_event(event)
|
||||
end)
|
||||
|
||||
--- Toggle item button, used for toggling autofill for the specific item
|
||||
-- @element toggle_item_button
|
||||
local toggle_item_button = Gui.element("toggle_item_button")
|
||||
:draw(function(_, parent, item)
|
||||
return parent.add{
|
||||
type = "sprite-button",
|
||||
sprite = "item/" .. item.name,
|
||||
tooltip = { "autofill.toggle-tooltip", rich_img("item", item.name), item.category },
|
||||
style = "shortcut_bar_button_red",
|
||||
}
|
||||
end)
|
||||
:style(Gui.styles.sprite{
|
||||
size = 32,
|
||||
right_margin = -3,
|
||||
})
|
||||
:on_click(function(def, player, element)
|
||||
local item_name = element.parent.tooltip
|
||||
local entity_name = element.parent.parent.parent.name
|
||||
if not autofill_player_settings[player.name] then return end
|
||||
local setting = autofill_player_settings[player.name][entity_name]
|
||||
if not setting then return end
|
||||
local item = setting.items[item_name]
|
||||
if not item then return end
|
||||
if item.enabled then
|
||||
item.enabled = false
|
||||
element.style = "shortcut_bar_button_red"
|
||||
else
|
||||
item.enabled = true
|
||||
element.style = "shortcut_bar_button_green"
|
||||
end
|
||||
-- Correct the button size
|
||||
local style = element.style
|
||||
style.right_margin = -3
|
||||
style.padding = -2
|
||||
style.height = 32
|
||||
style.width = 32
|
||||
end)
|
||||
|
||||
--- Amount text field for a autofill item
|
||||
-- @element amount_textfield
|
||||
local amount_textfield = Gui.element("amount_textfield")
|
||||
:draw(function(_, parent, item)
|
||||
return parent.add{
|
||||
type = "textfield",
|
||||
text = item.amount,
|
||||
tooltip = { "autofill.amount-tooltip", item.category },
|
||||
clear_and_focus_on_right_click = true,
|
||||
numeric = true,
|
||||
allow_decimal = false,
|
||||
allow_negative = false,
|
||||
}
|
||||
end)
|
||||
:style{
|
||||
maximal_width = 40,
|
||||
height = 31,
|
||||
padding = -2,
|
||||
}
|
||||
:on_text_changed(function(def, player, element)
|
||||
local value = tonumber(element.text)
|
||||
if not value then value = 0 end
|
||||
local clamped = math.clamp(value, 0, 1000)
|
||||
local item_name = element.parent.tooltip
|
||||
local entity_name = element.parent.parent.parent.name
|
||||
if not autofill_player_settings[player.name] then return end
|
||||
local setting = autofill_player_settings[player.name][entity_name]
|
||||
if not setting then return end
|
||||
local item = setting.items[item_name]
|
||||
if not item then return end
|
||||
item.amount = clamped
|
||||
if clamped ~= value then
|
||||
element.text = tostring(clamped)
|
||||
player.print{ "autofill.invalid", item.amount, rich_img("item", item.name), rich_img("entity", entity_name) }
|
||||
return
|
||||
end
|
||||
end)
|
||||
|
||||
--- Autofill setting, contains a button and a textbox
|
||||
-- @element add_autofill_setting
|
||||
local add_autofill_setting = Gui.element("add_autofill_setting")
|
||||
:draw(function(_, parent, item)
|
||||
local toggle_flow = parent.add{ type = "flow", name = "toggle-setting-" .. item.name, tooltip = item.name }
|
||||
local amount_flow = parent.add{ type = "flow", name = "amount-setting-" .. item.name, tooltip = item.name }
|
||||
toggle_flow.style.padding = 0
|
||||
amount_flow.style.padding = 0
|
||||
toggle_item_button(toggle_flow, item)
|
||||
amount_textfield(amount_flow, item)
|
||||
end)
|
||||
|
||||
--- Autofill setting empty, contains filler button and textfield gui elements
|
||||
-- @element add_empty_autofill_setting
|
||||
local add_empty_autofill_setting = Gui.element("add_empty_autofill_setting")
|
||||
:draw(function(_, parent)
|
||||
local toggle_element = parent.add{
|
||||
type = "sprite-button",
|
||||
}
|
||||
toggle_element.style.right_margin = -3
|
||||
toggle_element.style.width = 32
|
||||
toggle_element.style.height = 32
|
||||
toggle_element.enabled = false
|
||||
local amount_element = parent.add{
|
||||
type = "textfield",
|
||||
}
|
||||
amount_element.style.maximal_width = 40
|
||||
amount_element.style.height = 31
|
||||
amount_element.style.padding = -2
|
||||
amount_element.enabled = false
|
||||
end)
|
||||
|
||||
--- Main gui container for the left flow
|
||||
-- @element autofill_container
|
||||
autofill_container = Gui.element("autofill_container")
|
||||
:draw(function(def, parent)
|
||||
-- Draw the internal container
|
||||
local container = Gui.elements.container(parent)
|
||||
-- Draw the scroll container
|
||||
local scroll_table = Gui.elements.scroll_table(container, 400, 1, "autofill-scroll-table")
|
||||
-- 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"
|
||||
-- Scroll panel has by default padding
|
||||
scroll_table.parent.style.padding = 0
|
||||
-- Remove the default gap that is added in a table between elements
|
||||
scroll_table.style.vertical_spacing = 0
|
||||
-- Center the first column in the table
|
||||
scroll_table.style.column_alignments[1] = "center"
|
||||
-- Loop over each default entity config
|
||||
for _, setting in pairs(config.default_entities) do
|
||||
local table_sizes = {}
|
||||
local tables = {}
|
||||
-- Draw a section for the element
|
||||
local entity_table = section(scroll_table, setting.entity, 3)
|
||||
-- Add some padding around the table
|
||||
entity_table.style.padding = 3
|
||||
-- Make sure each column is alignment top center
|
||||
entity_table.style.column_alignments[1] = "top-center"
|
||||
entity_table.style.column_alignments[2] = "top-center"
|
||||
entity_table.style.column_alignments[3] = "top-center"
|
||||
-- Loop over each item category
|
||||
for _, category in pairs(config.categories) do
|
||||
if not table_sizes[category] then table_sizes[category] = 0 end
|
||||
-- Draw table
|
||||
local category_table = entity_table.add{
|
||||
type = "table",
|
||||
name = category .. "-category",
|
||||
column_count = 2,
|
||||
}
|
||||
-- Add padding between each item
|
||||
category_table.style.vertical_spacing = 1
|
||||
tables[category] = category_table
|
||||
-- Add item autofill setting gui elements to the table
|
||||
for _, item in pairs(setting.items) do
|
||||
if item.category == category then
|
||||
add_autofill_setting(category_table, item)
|
||||
table_sizes[category] = table_sizes[category] + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Add empty gui elements for the categories with less items than the other categories
|
||||
local t = table.get_values(table_sizes)
|
||||
table.sort(t)
|
||||
local biggest = t[#t]
|
||||
for category, size in pairs(table_sizes) do
|
||||
for i = biggest - size, 1, -1 do
|
||||
add_empty_autofill_setting(tables[category])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Return the external container
|
||||
return container.parent
|
||||
end)
|
||||
|
||||
--- Add the element to the left flow with a toolbar button
|
||||
Gui.add_left_element(autofill_container, false)
|
||||
Gui.toolbar.create_button{
|
||||
name = "autofill_toggle",
|
||||
left_element = autofill_container,
|
||||
sprite = config.icon,
|
||||
tooltip = { "autofill.main-tooltip" },
|
||||
visible = function(player, element)
|
||||
return Roles.player_allowed(player, "gui/autofill")
|
||||
end
|
||||
}
|
||||
|
||||
--- When a player is created make sure they have the default autofill settings
|
||||
Event.add(defines.events.on_player_created, function(event)
|
||||
local player = game.players[event.player_index]
|
||||
if not autofill_player_settings[player.name] then
|
||||
autofill_player_settings[player.name] = table.deep_copy(config.default_entities)
|
||||
end
|
||||
end)
|
||||
|
||||
local function entity_build(event)
|
||||
-- Check if player exists
|
||||
local player = game.players[event.player_index]
|
||||
if not player then
|
||||
return
|
||||
end
|
||||
-- Check if the entity is in the config and enabled
|
||||
local entity = event.entity
|
||||
|
||||
-- Check if player has settings
|
||||
if not autofill_player_settings[player.name] then return end
|
||||
|
||||
local entity_settings = autofill_player_settings[player.name][entity.name]
|
||||
-- Check if autofill for the entity is enabled
|
||||
if not entity_settings then return end
|
||||
if not entity_settings.enabled then return end
|
||||
|
||||
-- Get the inventory of the player
|
||||
local player_inventory = player.get_main_inventory() --- @cast player_inventory -nil
|
||||
|
||||
local offset = { x = 0, y = 0 }
|
||||
-- Loop over all possible items to insert into the entity
|
||||
for _, item in pairs(entity_settings.items) do
|
||||
-- Check if the item is enabled or goto next item
|
||||
if not item.enabled then goto end_item end
|
||||
|
||||
-- Get the inventory of the entity or goto next item
|
||||
local entity_inventory = entity.get_inventory(item.inv)
|
||||
if not entity_inventory then goto end_item end
|
||||
|
||||
local preferred_amount = item.amount
|
||||
local item_amount = player_inventory.get_item_count(item.name)
|
||||
if item_amount ~= 0 then
|
||||
local inserted
|
||||
local color = { r = 0, g = 255, b = 0, a = 255 }
|
||||
if item_amount >= preferred_amount then
|
||||
-- Can item be inserted? no, goto next item!
|
||||
if not entity_inventory.can_insert{ name = item.name, count = preferred_amount } then
|
||||
goto end_item
|
||||
end
|
||||
inserted = entity_inventory.insert{ name = item.name, count = preferred_amount }
|
||||
else
|
||||
inserted = entity_inventory.insert{ name = item.name, count = item_amount }
|
||||
color = { r = 255, g = 165, b = 0, a = 255 }
|
||||
end
|
||||
player_inventory.remove{ name = item.name, count = inserted }
|
||||
FlyingText.create_above_entity{
|
||||
target_entity = entity,
|
||||
text = { "autofill.inserted", inserted, rich_img("item", item.name), rich_img("entity", entity.name) },
|
||||
offset = offset,
|
||||
player = player,
|
||||
color = color,
|
||||
}
|
||||
offset.y = offset.y - 0.33
|
||||
end
|
||||
::end_item::
|
||||
end
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_built_entity, entity_build)
|
||||
@@ -1,347 +0,0 @@
|
||||
--[[-- Gui Module - Bonus
|
||||
@gui Bonus
|
||||
@alias bonus_container
|
||||
]]
|
||||
|
||||
local Gui = require("modules/exp_gui")
|
||||
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
||||
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
|
||||
local config = require("modules.exp_legacy.config.bonus") --- @dep config.bonus
|
||||
local vlayer = require("modules.exp_legacy.modules.control.vlayer")
|
||||
local format_number = require("util").format_number --- @dep util
|
||||
|
||||
local bonus_container
|
||||
|
||||
--- @param player LuaPlayer
|
||||
--- @param container LuaGuiElement?
|
||||
--- @return number
|
||||
local function bonus_gui_pts_needed(player, container)
|
||||
container = container or Gui.get_left_element(bonus_container, player)
|
||||
local disp = container.frame["bonus_st_2"].disp.table
|
||||
local total = 0
|
||||
|
||||
for k, v in pairs(config.conversion) do
|
||||
total = total + (disp["bonus_display_" .. k .. "_slider"].slider_value / config.player_bonus[v].cost_scale * config.player_bonus[v].cost)
|
||||
end
|
||||
|
||||
total = total + (
|
||||
disp["bonus_display_personal_battery_recharge_slider"].slider_value
|
||||
/ config.player_special_bonus["personal_battery_recharge"].cost_scale
|
||||
* config.player_special_bonus["personal_battery_recharge"].cost
|
||||
)
|
||||
|
||||
return total
|
||||
end
|
||||
|
||||
--- @param player LuaPlayer
|
||||
--- @param reset boolean?
|
||||
local function apply_bonus(player, reset)
|
||||
if reset or not Roles.player_allowed(player, "gui/bonus") then
|
||||
for k, v in pairs(config.player_bonus) do
|
||||
player[k] = 0
|
||||
|
||||
if v.combined_bonus then
|
||||
for i = 1, #v.combined_bonus do
|
||||
player[v.combined_bonus[i]] = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
if not player.character then
|
||||
return
|
||||
end
|
||||
|
||||
local container = Gui.get_left_element(bonus_container, player)
|
||||
local disp = container.frame["bonus_st_2"].disp.table
|
||||
|
||||
for k, v in pairs(config.conversion) do
|
||||
player[v] = disp["bonus_display_" .. k .. "_slider"].slider_value
|
||||
|
||||
if config.player_bonus[v].combined_bonus then
|
||||
for i = 1, #config.player_bonus[v].combined_bonus do
|
||||
player[config.player_bonus[v].combined_bonus[i]] = disp["bonus_display_" .. k .. "_slider"].slider_value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function apply_periodic_bonus(player)
|
||||
if not Roles.player_allowed(player, "gui/bonus") then
|
||||
return
|
||||
end
|
||||
|
||||
if not player.character then
|
||||
return
|
||||
end
|
||||
|
||||
local container = Gui.get_left_element(bonus_container, player)
|
||||
local disp = container.frame["bonus_st_2"].disp.table
|
||||
|
||||
if vlayer.get_statistics()["energy_sustained"] > 0 then
|
||||
local armor = player.get_inventory(defines.inventory.character_armor)
|
||||
|
||||
if armor and armor[1] and armor[1].valid_for_read and armor[1].grid then
|
||||
local armor_grid = armor[1].grid
|
||||
|
||||
if armor_grid and armor_grid.available_in_batteries and armor_grid.battery_capacity and armor_grid.available_in_batteries < armor_grid.battery_capacity then
|
||||
local slider = disp["bonus_display_personal_battery_recharge_slider"].slider_value * 100000 * config.player_special_bonus_rate / 6
|
||||
|
||||
for i = 1, #armor_grid.equipment do
|
||||
if armor_grid.equipment[i].energy < armor_grid.equipment[i].max_energy then
|
||||
local energy_required = math.min(math.floor(armor_grid.equipment[i].max_energy - armor_grid.equipment[i].energy), vlayer.get_statistics()["energy_storage"], slider)
|
||||
armor_grid.equipment[i].energy = armor_grid.equipment[i].energy + energy_required
|
||||
vlayer.energy_changed(-energy_required)
|
||||
|
||||
slider = slider - energy_required
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local bonus_data_score_limit = {}
|
||||
local function get_bonus_score_limit(player)
|
||||
if not bonus_data_score_limit[player] then
|
||||
bonus_data_score_limit[player] = math.floor(config.pts.base * (1 + config.pts.increase_percentage_per_role_level * (Roles.get_role_by_name(config.pts.role_name).index - Roles.get_player_highest_role(player).index)))
|
||||
end
|
||||
return bonus_data_score_limit[player]
|
||||
end
|
||||
|
||||
--- Control label for the bonus points available
|
||||
-- @element bonus_gui_control_pts
|
||||
local bonus_gui_control_pts = Gui.element("bonus_gui_control_pts")
|
||||
:draw{
|
||||
type = "label",
|
||||
name = Gui.property_from_name,
|
||||
caption = { "bonus.control-pts-a" },
|
||||
style = "heading_2_label",
|
||||
}:style{
|
||||
width = config.gui_display_width["half"],
|
||||
}
|
||||
|
||||
local bonus_gui_control_pts_count = Gui.element("bonus_gui_control_pts_count")
|
||||
:draw{
|
||||
type = "progressbar",
|
||||
name = Gui.property_from_name,
|
||||
caption = "0 / 0",
|
||||
value = 0,
|
||||
style = "electric_satisfaction_statistics_progressbar",
|
||||
}:style{
|
||||
width = config.gui_display_width["half"],
|
||||
font = "heading-2",
|
||||
color = { 1, 0, 0 },
|
||||
}
|
||||
|
||||
--- A button used for pts calculations
|
||||
-- @element bonus_gui_control_refresh
|
||||
local bonus_gui_control_reset = Gui.element("bonus_gui_control_reset")
|
||||
:draw{
|
||||
type = "button",
|
||||
name = Gui.property_from_name,
|
||||
caption = { "bonus.control-reset" },
|
||||
}:style{
|
||||
width = config.gui_display_width["half"],
|
||||
}:on_click(function(def, player, element)
|
||||
local container = Gui.get_left_element(bonus_container, player)
|
||||
local disp = container.frame["bonus_st_2"].disp.table
|
||||
|
||||
for k, v in pairs(config.conversion) do
|
||||
local s = "bonus_display_" .. k .. "_slider"
|
||||
disp[s].slider_value = config.player_bonus[v].value
|
||||
disp[disp[s].tags.counter].caption = (config.player_bonus[v].is_percentage and (format_number(disp[s].slider_value * 100, false) .. " %")) or format_number(disp[s].slider_value, false)
|
||||
end
|
||||
|
||||
local slider = disp["bonus_display_personal_battery_recharge_slider"]
|
||||
slider.slider_value = config.player_special_bonus["personal_battery_recharge"].value
|
||||
disp[slider.tags.counter].caption = format_number(slider.slider_value, false)
|
||||
|
||||
local n = bonus_gui_pts_needed(player)
|
||||
local limit = get_bonus_score_limit(player)
|
||||
element.parent[bonus_gui_control_pts_count.name].caption = n .. " / " .. limit
|
||||
element.parent[bonus_gui_control_pts_count.name].value = n / limit
|
||||
end)
|
||||
|
||||
--- A button used for pts apply
|
||||
-- @element bonus_gui_control_apply
|
||||
local bonus_gui_control_apply = Gui.element("bonus_gui_control_apply")
|
||||
:draw{
|
||||
type = "button",
|
||||
name = Gui.property_from_name,
|
||||
caption = { "bonus.control-apply" },
|
||||
}:style{
|
||||
width = config.gui_display_width["half"],
|
||||
}:on_click(function(def, player, element)
|
||||
local n = bonus_gui_pts_needed(player)
|
||||
local limit = get_bonus_score_limit(player)
|
||||
element.parent[bonus_gui_control_pts_count.name].caption = n .. " / " .. limit
|
||||
element.parent[bonus_gui_control_pts_count.name].value = n / limit
|
||||
|
||||
if n <= limit then
|
||||
apply_bonus(player)
|
||||
end
|
||||
end)
|
||||
|
||||
--- A vertical flow containing all the bonus control
|
||||
-- @element bonus_control_set
|
||||
local bonus_control_set = Gui.element("bonus_control_set")
|
||||
:draw(function(_, parent, name)
|
||||
local bonus_set = parent.add{ type = "flow", direction = "vertical", name = name }
|
||||
local disp = Gui.elements.scroll_table(bonus_set, config.gui_display_width["half"] * 2, 2, "disp")
|
||||
|
||||
bonus_gui_control_pts(disp)
|
||||
bonus_gui_control_pts_count(disp)
|
||||
bonus_gui_control_reset(disp)
|
||||
bonus_gui_control_apply(disp)
|
||||
|
||||
return bonus_set
|
||||
end)
|
||||
|
||||
--- Display group
|
||||
-- @element bonus_gui_slider
|
||||
local bonus_gui_slider = Gui.element("bonus_gui_slider")
|
||||
:draw(function(def, parent, name, caption, tooltip, bonus)
|
||||
local label = parent.add{
|
||||
type = "label",
|
||||
caption = caption,
|
||||
tooltip = tooltip,
|
||||
style = "heading_2_label",
|
||||
}
|
||||
label.style.width = config.gui_display_width["label"]
|
||||
|
||||
local slider = parent.add{
|
||||
type = "slider",
|
||||
name = name .. "_slider",
|
||||
value = bonus.value,
|
||||
maximum_value = bonus.max,
|
||||
value_step = bonus.scale,
|
||||
discrete_values = true,
|
||||
style = "notched_slider",
|
||||
tags = {
|
||||
counter = name .. "_count",
|
||||
is_percentage = bonus.is_percentage,
|
||||
},
|
||||
}
|
||||
slider.style.width = config.gui_display_width["slider"]
|
||||
slider.style.horizontally_stretchable = true
|
||||
|
||||
local count = parent.add{
|
||||
type = "label",
|
||||
name = name .. "_count",
|
||||
caption = (bonus.is_percentage and format_number(bonus.value * 100, false) .. " %") or format_number(bonus.value, false),
|
||||
style = "heading_2_label",
|
||||
}
|
||||
count.style.width = config.gui_display_width["count"]
|
||||
|
||||
return slider
|
||||
end)
|
||||
:on_value_changed(function(def, player, element)
|
||||
element.parent[element.tags.counter].caption = (element.tags.is_percentage and format_number(element.slider_value * 100, false) .. " %") or format_number(element.slider_value, false)
|
||||
local container = Gui.get_left_element(bonus_container, player)
|
||||
local disp = container.frame["bonus_st_1"].disp.table
|
||||
local n = bonus_gui_pts_needed(player)
|
||||
local limit = get_bonus_score_limit(player)
|
||||
disp[bonus_gui_control_pts_count.name].caption = n .. " / " .. limit
|
||||
disp[bonus_gui_control_pts_count.name].value = n / limit
|
||||
end)
|
||||
|
||||
--- A vertical flow containing all the bonus data
|
||||
-- @element bonus_data_set
|
||||
local bonus_data_set = Gui.element("bonus_data_set")
|
||||
:draw(function(_, parent, name)
|
||||
local bonus_set = parent.add{ type = "flow", direction = "vertical", name = name }
|
||||
local disp = Gui.elements.scroll_table(bonus_set, config.gui_display_width["half"] * 2, 3, "disp")
|
||||
|
||||
for k, v in pairs(config.conversion) do
|
||||
bonus_gui_slider(disp, "bonus_display_" .. k, { "bonus.display-" .. k }, { "bonus.display-" .. k .. "-tooltip" }, config.player_bonus[v])
|
||||
end
|
||||
|
||||
bonus_gui_slider(disp, "bonus_display_personal_battery_recharge", { "bonus.display-personal-battery-recharge" }, { "bonus.display-personal-battery-recharge-tooltip" }, config.player_special_bonus["personal_battery_recharge"])
|
||||
|
||||
return bonus_set
|
||||
end)
|
||||
|
||||
--- The main container for the bonus gui
|
||||
-- @element bonus_container
|
||||
bonus_container = Gui.element("bonus_container")
|
||||
:draw(function(def, parent)
|
||||
local player = Gui.get_player(parent)
|
||||
local container = Gui.elements.container(parent, config.gui_display_width["half"] * 2)
|
||||
|
||||
bonus_control_set(container, "bonus_st_1")
|
||||
bonus_data_set(container, "bonus_st_2")
|
||||
|
||||
local disp = container["bonus_st_1"].disp.table
|
||||
local n = bonus_gui_pts_needed(player, container.parent)
|
||||
local limit = get_bonus_score_limit(player)
|
||||
disp[bonus_gui_control_pts_count.name].caption = n .. " / " .. limit
|
||||
disp[bonus_gui_control_pts_count.name].value = n / limit
|
||||
|
||||
return container.parent
|
||||
end)
|
||||
|
||||
--- Add the element to the left flow with a toolbar button
|
||||
Gui.add_left_element(bonus_container, false)
|
||||
Gui.toolbar.create_button{
|
||||
name = "bonus_toggle",
|
||||
left_element = bonus_container,
|
||||
sprite = "item/exoskeleton-equipment",
|
||||
tooltip = { "bonus.main-tooltip" },
|
||||
visible = function(player, element)
|
||||
return Roles.player_allowed(player, "gui/bonus")
|
||||
end
|
||||
}
|
||||
|
||||
Event.add(defines.events.on_player_created, function(event)
|
||||
if event.player_index ~= 1 then
|
||||
return
|
||||
end
|
||||
|
||||
for k, v in pairs(config.force_bonus) do
|
||||
game.players[event.player_index].force[k] = v.value
|
||||
end
|
||||
|
||||
for k, v in pairs(config.surface_bonus) do
|
||||
game.players[event.player_index].surface[k] = v.value
|
||||
end
|
||||
end)
|
||||
|
||||
local function recalculate_bonus(event)
|
||||
local player = game.players[event.player_index]
|
||||
if event.name == Roles.events.on_role_assigned or event.name == Roles.events.on_role_unassigned then
|
||||
-- If the player's roles changed then we need to recalculate their limit
|
||||
bonus_data_score_limit[player] = nil
|
||||
end
|
||||
|
||||
local container = Gui.get_left_element(bonus_container, player)
|
||||
local disp = container.frame["bonus_st_1"].disp.table
|
||||
local n = bonus_gui_pts_needed(player)
|
||||
local limit = get_bonus_score_limit(player)
|
||||
disp[bonus_gui_control_pts_count.name].caption = n .. " / " .. limit
|
||||
disp[bonus_gui_control_pts_count.name].value = n / limit
|
||||
|
||||
apply_bonus(player, n > limit)
|
||||
end
|
||||
|
||||
Event.add(Roles.events.on_role_assigned, recalculate_bonus)
|
||||
Event.add(Roles.events.on_role_unassigned, recalculate_bonus)
|
||||
Event.add(defines.events.on_player_respawned, recalculate_bonus)
|
||||
|
||||
--- When a player dies allow them to have instant respawn
|
||||
Event.add(defines.events.on_player_died, function(event)
|
||||
local player = game.players[event.player_index]
|
||||
if Roles.player_has_flag(player, "instant-respawn") then
|
||||
player.ticks_to_respawn = 120
|
||||
end
|
||||
end)
|
||||
|
||||
Event.on_nth_tick(config.player_special_bonus_rate, function(_)
|
||||
for _, player in pairs(game.connected_players) do
|
||||
if player.character then
|
||||
apply_periodic_bonus(player)
|
||||
end
|
||||
end
|
||||
end)
|
||||
@@ -61,12 +61,8 @@ function Public.dump_text(text, player)
|
||||
return false
|
||||
end
|
||||
|
||||
rawset(game, "player", player)
|
||||
|
||||
local suc, var = pcall(func)
|
||||
|
||||
rawset(game, "player", nil)
|
||||
|
||||
if not suc then
|
||||
return false
|
||||
end
|
||||
|
||||
@@ -1,394 +0,0 @@
|
||||
---- module inserter
|
||||
-- @gui Module
|
||||
|
||||
local Gui = require("modules/exp_gui")
|
||||
local AABB = require("modules/exp_util/aabb")
|
||||
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
||||
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
|
||||
local config = require("modules.exp_legacy.config.module") --- @dep config.module
|
||||
local Selection = require("modules.exp_legacy.modules.control.selection") --- @dep modules.control.selection
|
||||
local SelectionModuleArea = "ModuleArea"
|
||||
|
||||
local module_container -- Container for this GUI
|
||||
|
||||
local machine_names = {}
|
||||
for mod_name, machine_set in pairs(config.machine_set) do
|
||||
if script.active_mods[mod_name] then
|
||||
for machine_name, v in pairs(machine_set) do
|
||||
config.machine[machine_name] = v
|
||||
table.insert(machine_names, machine_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local prod_module_names = {}
|
||||
for name, item in pairs(prototypes.item) do
|
||||
if item.module_effects and item.module_effects.productivity and item.module_effects.productivity > 0 then
|
||||
prod_module_names[#prod_module_names + 1] = name
|
||||
end
|
||||
end
|
||||
|
||||
local elem_filter = {
|
||||
machine_name = { {
|
||||
filter = "name",
|
||||
name = machine_names,
|
||||
} },
|
||||
no_prod = { {
|
||||
filter = "type",
|
||||
type = "module",
|
||||
}, {
|
||||
filter = "name",
|
||||
name = prod_module_names,
|
||||
mode = "and",
|
||||
invert = true,
|
||||
} },
|
||||
with_prod = { {
|
||||
filter = "type",
|
||||
type = "module",
|
||||
} },
|
||||
}
|
||||
|
||||
--- Apply module changes to a crafting machine
|
||||
--- @param player LuaPlayer
|
||||
--- @param area BoundingBox
|
||||
--- @param machine_name string
|
||||
--- @param planner_with_prod LuaItemStack
|
||||
--- @param planner_no_prod LuaItemStack
|
||||
local function apply_module_to_crafter(player, area, machine_name, planner_with_prod, planner_no_prod)
|
||||
local force = player.force
|
||||
local surface = player.surface
|
||||
local upgrade_area = surface.upgrade_area
|
||||
|
||||
--- @type BoundingBox
|
||||
local param_area = { left_top = {}, right_bottom = {} }
|
||||
|
||||
--- @type LuaSurface.upgrade_area_param
|
||||
local params = {
|
||||
area = param_area,
|
||||
item = planner_with_prod,
|
||||
player = player,
|
||||
force = force,
|
||||
}
|
||||
|
||||
for _, entity in pairs(surface.find_entities_filtered{ area = area, name = machine_name, force = force }) do
|
||||
local pos = entity.position
|
||||
param_area.left_top = pos
|
||||
param_area.right_bottom = pos
|
||||
|
||||
local m_current_recipe = entity.get_recipe()
|
||||
local r_proto = m_current_recipe and m_current_recipe.prototype
|
||||
|
||||
if r_proto and (r_proto.maximum_productivity or (r_proto.allowed_effects and r_proto.allowed_effects["productivity"])) then
|
||||
params.item = planner_with_prod
|
||||
upgrade_area(params)
|
||||
else
|
||||
params.item = planner_no_prod
|
||||
upgrade_area(params)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- when an area is selected to add protection to the area
|
||||
--- @param event EventData.on_player_selected_area
|
||||
Selection.on_selection(SelectionModuleArea, function(event)
|
||||
local area = AABB.expand(event.area)
|
||||
local player = game.players[event.player_index]
|
||||
local container = Gui.get_left_element(module_container, player)
|
||||
local scroll_table = container.frame.scroll.table
|
||||
|
||||
-- Create an inventory with three upgrade planners
|
||||
local inventory = game.create_inventory(3)
|
||||
inventory.insert{ name = "upgrade-planner", count = 3 }
|
||||
local planner_all = inventory[1]
|
||||
local planner_with_prod = inventory[2]
|
||||
local planner_no_prod = inventory[3]
|
||||
local mapper_index = 1
|
||||
|
||||
for row = 1, config.default_module_row_count do
|
||||
local machine_name = scroll_table["module_mm_" .. row .. "_0"].elem_value --[[@as string]]
|
||||
local entity_proto = prototypes.entity[machine_name]
|
||||
|
||||
if machine_name then
|
||||
local is_prod_crafter = false
|
||||
local module_index = 1
|
||||
local modules = {}
|
||||
local no_prod = {}
|
||||
|
||||
-- Add all the modules selected
|
||||
for column = 1, entity_proto.module_inventory_size do
|
||||
local module_name = scroll_table["module_mm_" .. row .. "_" .. column].elem_value --[[ @as {name:string, quality:string} ]]
|
||||
|
||||
if module_name then
|
||||
local not_prod = module_name.name:gsub("productivity", "efficiency")
|
||||
modules[module_index] = module_name
|
||||
no_prod[module_index] = { name = not_prod, quality = module_name.quality }
|
||||
module_index = module_index + 1
|
||||
if not is_prod_crafter and module_name ~= not_prod and entity_proto.get_crafting_speed() then
|
||||
is_prod_crafter = true
|
||||
end
|
||||
else
|
||||
modules[module_index] = {}
|
||||
no_prod[module_index] = {}
|
||||
module_index = module_index + 1
|
||||
end
|
||||
end
|
||||
|
||||
if is_prod_crafter then
|
||||
-- Crafting machines with prod need to be handled on a case by case biases
|
||||
local i = 0
|
||||
for quality_name in pairs(prototypes.quality) do
|
||||
i = i + 1
|
||||
planner_with_prod.set_mapper(i, "from", {
|
||||
type = "entity",
|
||||
name = machine_name,
|
||||
quality = quality_name,
|
||||
comparator = "=",
|
||||
})
|
||||
planner_no_prod.set_mapper(i, "from", {
|
||||
type = "entity",
|
||||
name = machine_name,
|
||||
quality = quality_name,
|
||||
comparator = "=",
|
||||
})
|
||||
planner_with_prod.set_mapper(i, "to", {
|
||||
type = "entity",
|
||||
name = machine_name,
|
||||
module_slots = modules,
|
||||
quality = quality_name,
|
||||
comparator = "=",
|
||||
})
|
||||
planner_no_prod.set_mapper(i, "to", {
|
||||
type = "entity",
|
||||
name = machine_name,
|
||||
module_slots = no_prod,
|
||||
quality = quality_name,
|
||||
comparator = "=",
|
||||
})
|
||||
end
|
||||
apply_module_to_crafter(player, area, machine_name, planner_with_prod, planner_no_prod)
|
||||
else
|
||||
-- All other machines can be applied in a single upgrade planner
|
||||
for quality_name in pairs(prototypes.quality) do
|
||||
planner_all.set_mapper(mapper_index, "from", {
|
||||
type = "entity",
|
||||
name = machine_name,
|
||||
quality = quality_name,
|
||||
comparator = "=",
|
||||
})
|
||||
planner_all.set_mapper(mapper_index, "to", {
|
||||
type = "entity",
|
||||
name = machine_name,
|
||||
module_slots = modules,
|
||||
quality = quality_name,
|
||||
comparator = "=",
|
||||
})
|
||||
mapper_index = mapper_index + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Apply module changes for non crafting (or without prod selected)
|
||||
if mapper_index > 1 then
|
||||
player.surface.upgrade_area{
|
||||
area = area,
|
||||
item = planner_all,
|
||||
force = player.force,
|
||||
player = player,
|
||||
}
|
||||
end
|
||||
|
||||
inventory.destroy()
|
||||
end)
|
||||
|
||||
--- Set the state of all elem selectors on a row
|
||||
--- @param player LuaPlayer
|
||||
--- @param element_name string
|
||||
local function row_set(player, element_name)
|
||||
local container = Gui.get_left_element(module_container, player)
|
||||
local scroll_table = container.frame.scroll.table
|
||||
local machine_name = scroll_table[element_name .. "0"].elem_value --[[ @as string ]]
|
||||
|
||||
if machine_name then
|
||||
local active_to = prototypes.entity[machine_name].module_inventory_size
|
||||
local row_count = math.ceil(active_to / config.module_slots_per_row)
|
||||
local visible_to = row_count * config.module_slots_per_row
|
||||
for i = 1, config.module_slot_max do
|
||||
local element = scroll_table[element_name .. i]
|
||||
if i <= active_to then
|
||||
if config.machine[machine_name].prod then
|
||||
element.elem_filters = elem_filter.with_prod
|
||||
else
|
||||
element.elem_filters = elem_filter.no_prod
|
||||
end
|
||||
|
||||
element.visible = true
|
||||
element.enabled = true
|
||||
element.elem_value = { name = config.machine[machine_name].module }
|
||||
else
|
||||
element.visible = i <= visible_to
|
||||
element.enabled = false
|
||||
element.elem_value = nil
|
||||
end
|
||||
if i % (config.module_slots_per_row + 1) == 0 then
|
||||
scroll_table[element_name .. "pad" .. i].visible = element.visible
|
||||
end
|
||||
end
|
||||
else
|
||||
for i = 1, config.module_slot_max do
|
||||
local element = scroll_table[element_name .. i]
|
||||
element.visible = i <= config.module_slots_per_row
|
||||
element.enabled = false
|
||||
element.elem_value = nil
|
||||
if i % (config.module_slots_per_row + 1) == 0 then
|
||||
scroll_table[element_name .. "pad" .. i].visible = false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local button_apply = Gui.element("button_apply")
|
||||
:draw{
|
||||
type = "button",
|
||||
caption = { "module.apply" },
|
||||
style = "button",
|
||||
}:on_click(function(def, player, element)
|
||||
if Selection.is_selecting(player, SelectionModuleArea) then
|
||||
Selection.stop(player)
|
||||
else
|
||||
Selection.start(player, SelectionModuleArea)
|
||||
end
|
||||
end)
|
||||
|
||||
module_container = Gui.element("module_container")
|
||||
:draw(function(definition, parent)
|
||||
local container = Gui.elements.container(parent, (config.module_slots_per_row + 2) * 36)
|
||||
Gui.elements.header(container, {
|
||||
caption = "Module Inserter",
|
||||
})
|
||||
|
||||
local slots_per_row = config.module_slots_per_row + 1
|
||||
local scroll_table = Gui.elements.scroll_table(container, (config.module_slots_per_row + 2) * 36, slots_per_row, "scroll")
|
||||
|
||||
for i = 1, config.default_module_row_count do
|
||||
scroll_table.add{
|
||||
name = "module_mm_" .. i .. "_0",
|
||||
type = "choose-elem-button",
|
||||
elem_type = "entity",
|
||||
elem_filters = elem_filter.machine_name,
|
||||
style = "slot_button",
|
||||
}
|
||||
|
||||
for j = 1, config.module_slot_max do
|
||||
if j % slots_per_row == 0 then
|
||||
scroll_table.add{
|
||||
type = "flow",
|
||||
name = "module_mm_" .. i .. "_pad" .. j,
|
||||
visible = false,
|
||||
}
|
||||
end
|
||||
scroll_table.add{
|
||||
name = "module_mm_" .. i .. "_" .. j,
|
||||
type = "choose-elem-button",
|
||||
elem_type = "item-with-quality",
|
||||
elem_filters = elem_filter.no_prod,
|
||||
style = "slot_button",
|
||||
enabled = false,
|
||||
visible = j <= config.module_slots_per_row,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
button_apply(container)
|
||||
|
||||
return container.parent
|
||||
end)
|
||||
|
||||
--- Add the element to the left flow with a toolbar button
|
||||
Gui.add_left_element(module_container, false)
|
||||
Gui.toolbar.create_button{
|
||||
name = "module_toggle",
|
||||
left_element = module_container,
|
||||
sprite = "item/productivity-module-3",
|
||||
tooltip = { "module.main-tooltip" },
|
||||
visible = function(player, element)
|
||||
return Roles.player_allowed(player, "gui/module")
|
||||
end
|
||||
}
|
||||
|
||||
--- @param event EventData.on_gui_elem_changed
|
||||
Event.add(defines.events.on_gui_elem_changed, function(event)
|
||||
if event.element.name:sub(1, 10) == "module_mm_" then
|
||||
if event.element.name:sub(-1) == "0" then
|
||||
row_set(game.players[event.player_index], "module_mm_" .. event.element.name:sub(-3):sub(1, 1) .. "_")
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
--- @param event EventData.on_entity_settings_pasted
|
||||
Event.add(defines.events.on_entity_settings_pasted, function(event)
|
||||
local source = event.source
|
||||
local destination = event.destination
|
||||
local player = game.players[event.player_index]
|
||||
|
||||
if not player then
|
||||
return
|
||||
end
|
||||
|
||||
if not source or not source.valid then
|
||||
return
|
||||
end
|
||||
|
||||
if not destination or not destination.valid then
|
||||
return
|
||||
end
|
||||
|
||||
-- rotate machine also
|
||||
if config.copy_paste_rotation then
|
||||
if (source.name == destination.name or source.prototype.fast_replaceable_group == destination.prototype.fast_replaceable_group) then
|
||||
if source.supports_direction and destination.supports_direction and source.type ~= "transport-belt" then
|
||||
local destination_box = destination.bounding_box
|
||||
|
||||
local ltx = destination_box.left_top.x
|
||||
local lty = destination_box.left_top.y
|
||||
local rbx = destination_box.right_bottom.x
|
||||
local rby = destination_box.right_bottom.y
|
||||
|
||||
local old_direction = destination.direction
|
||||
destination.direction = source.direction
|
||||
|
||||
if ltx ~= destination_box.left_top.x or lty ~= destination_box.left_top.y or rbx ~= destination_box.right_bottom.x or rby ~= destination_box.right_bottom.y then
|
||||
destination.direction = old_direction
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
TODO handle later as may need using global to reduce creation of upgrade plans
|
||||
|
||||
if config.copy_paste_module then
|
||||
if source.name ~= destination.name then
|
||||
return
|
||||
end
|
||||
|
||||
local source_inventory = source.get_module_inventory()
|
||||
|
||||
if not source_inventory then
|
||||
return
|
||||
end
|
||||
|
||||
local source_inventory_content = source_inventory.get_contents()
|
||||
|
||||
if not source_inventory_content then
|
||||
return
|
||||
end
|
||||
|
||||
clear_module(player, destination.bounding_box, destination.name)
|
||||
|
||||
if next(source_inventory_content) ~= nil then
|
||||
apply_module(player, destination.bounding_box, destination.name, { ["n"] = source_inventory_content, ["p"] = source_inventory_content })
|
||||
end
|
||||
end
|
||||
]]
|
||||
end)
|
||||
@@ -23,13 +23,13 @@ config.set_datastores(SelectedPlayer, SelectedAction)
|
||||
|
||||
--- Button used to open the action bar
|
||||
-- @element open_action_bar
|
||||
local open_action_bar = Gui.element("open_action_bar")
|
||||
local open_action_bar = Gui.define("open_action_bar")
|
||||
:draw{
|
||||
type = "sprite-button",
|
||||
sprite = "utility/expand_dots",
|
||||
tooltip = { "player-list.open-action-bar" },
|
||||
style = "frame_button",
|
||||
name = Gui.property_from_name,
|
||||
name = Gui.from_name,
|
||||
}
|
||||
:style{
|
||||
padding = -2,
|
||||
@@ -48,7 +48,7 @@ local open_action_bar = Gui.element("open_action_bar")
|
||||
|
||||
--- Button used to close the action bar
|
||||
-- @element close_action_bar
|
||||
local close_action_bar = Gui.element("close_action_bar")
|
||||
local close_action_bar = Gui.define("close_action_bar")
|
||||
:draw{
|
||||
type = "sprite-button",
|
||||
sprite = "utility/close_black",
|
||||
@@ -68,7 +68,7 @@ local close_action_bar = Gui.element("close_action_bar")
|
||||
|
||||
--- Button used to confirm a reason
|
||||
-- @element reason_confirm
|
||||
local reason_confirm = Gui.element("reason_confirm")
|
||||
local reason_confirm = Gui.define("reason_confirm")
|
||||
:draw{
|
||||
type = "sprite-button",
|
||||
sprite = "utility/confirm_slot",
|
||||
@@ -94,7 +94,7 @@ local reason_confirm = Gui.element("reason_confirm")
|
||||
|
||||
--- Set of elements that are used to make up a row of the player table
|
||||
-- @element add_player_base
|
||||
local add_player_base = Gui.element("add_player_base")
|
||||
local add_player_base = Gui.define("add_player_base")
|
||||
:draw(function(_, parent, player_data)
|
||||
-- Add the button to open the action bar
|
||||
local toggle_action_bar_flow = parent.add{ type = "flow", name = player_data.name }
|
||||
@@ -162,7 +162,7 @@ end
|
||||
|
||||
--- Adds all the buttons and flows that make up the action bar
|
||||
-- @element add_action_bar
|
||||
local add_action_bar_buttons = Gui.element("add_action_bar_buttons")
|
||||
local add_action_bar_buttons = Gui.define("add_action_bar_buttons")
|
||||
:draw(function(_, parent)
|
||||
close_action_bar(parent)
|
||||
-- Loop over all the buttons in the config
|
||||
@@ -210,10 +210,10 @@ end
|
||||
|
||||
--- Main player list container for the left flow
|
||||
-- @element player_list_container
|
||||
local player_list_container = Gui.element("player_list_container")
|
||||
local player_list_container = Gui.define("player_list_container")
|
||||
:draw(function(definition, parent)
|
||||
-- Draw the internal container
|
||||
local container = Gui.elements.container(parent, 200)
|
||||
local container = Gui.elements.container(parent)
|
||||
|
||||
-- Draw the scroll table for the players
|
||||
local scroll_table = Gui.elements.scroll_table(container, 184, 3, "scroll")
|
||||
|
||||
@@ -1,224 +0,0 @@
|
||||
---- module pd
|
||||
-- @gui PlayerData
|
||||
|
||||
local ExpUtil = require("modules/exp_util")
|
||||
local Gui = require("modules/exp_gui")
|
||||
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
|
||||
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
||||
local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data
|
||||
require("modules.exp_legacy.modules.data.statistics")
|
||||
local format_number = require("util").format_number --- @dep util
|
||||
|
||||
local pd_container
|
||||
local label_width = {
|
||||
["name"] = 135,
|
||||
["count"] = 105,
|
||||
["total"] = 480,
|
||||
}
|
||||
|
||||
local short_time_format = ExpUtil.format_time_factory_locale{ format = "short", coefficient = 3600, hours = true, minutes = true }
|
||||
|
||||
local function format_number_n(n)
|
||||
return format_number(math.floor(n), false) .. string.format("%.2f", n % 1):sub(2)
|
||||
end
|
||||
|
||||
local PlayerStats = PlayerData.Statistics
|
||||
local computed_stats = {
|
||||
DamageDeathRatio = {
|
||||
default = format_number_n(0),
|
||||
calculate = function(player_name)
|
||||
return format_number_n(PlayerStats["DamageDealt"]:get(player_name, 0) / PlayerStats["Deaths"]:get(player_name, 1))
|
||||
end,
|
||||
},
|
||||
KillDeathRatio = {
|
||||
default = format_number_n(0),
|
||||
calculate = function(player_name)
|
||||
return format_number_n(PlayerStats["Kills"]:get(player_name, 0) / PlayerStats["Deaths"]:get(player_name, 1))
|
||||
end,
|
||||
},
|
||||
SessionTime = {
|
||||
default = short_time_format(0),
|
||||
calculate = function(player_name)
|
||||
return short_time_format((PlayerStats["Playtime"]:get(player_name, 0) - PlayerStats["AfkTime"]:get(player_name, 0)) / PlayerStats["JoinCount"]:get(player_name, 1))
|
||||
end,
|
||||
},
|
||||
BuildRatio = {
|
||||
default = format_number_n(0),
|
||||
calculate = function(player_name)
|
||||
return format_number_n(PlayerStats["MachinesBuilt"]:get(player_name, 0) / PlayerStats["MachinesRemoved"]:get(player_name, 1))
|
||||
end,
|
||||
},
|
||||
RocketPerHour = {
|
||||
default = format_number_n(0),
|
||||
calculate = function(player_name)
|
||||
return format_number_n(PlayerStats["RocketsLaunched"]:get(player_name, 0) * 60 / PlayerStats["Playtime"]:get(player_name, 1))
|
||||
end,
|
||||
},
|
||||
TreeKillPerMinute = {
|
||||
default = format_number_n(0),
|
||||
calculate = function(player_name)
|
||||
return format_number_n(PlayerStats["TreesDestroyed"]:get(player_name, 0) / PlayerStats["Playtime"]:get(player_name, 1))
|
||||
end,
|
||||
},
|
||||
NetPlayTime = {
|
||||
default = short_time_format(0),
|
||||
calculate = function(player_name)
|
||||
return short_time_format((PlayerStats["Playtime"]:get(player_name, 0) - PlayerStats["AfkTime"]:get(player_name, 0)))
|
||||
end,
|
||||
},
|
||||
AFKTimeRatio = {
|
||||
default = format_number_n(0),
|
||||
calculate = function(player_name)
|
||||
return format_number_n(PlayerStats["AfkTime"]:get(player_name, 0) * 100 / PlayerStats["Playtime"]:get(player_name, 1))
|
||||
end,
|
||||
},
|
||||
Locale = {
|
||||
default = "en",
|
||||
calculate = function(player)
|
||||
return player.locale
|
||||
end,
|
||||
},
|
||||
}
|
||||
|
||||
local label = Gui.element("label")
|
||||
:draw(function(_, parent, width, caption, tooltip, name)
|
||||
local new_label = parent.add{
|
||||
type = "label",
|
||||
caption = caption,
|
||||
tooltip = tooltip,
|
||||
name = name,
|
||||
style = "heading_2_label",
|
||||
}
|
||||
|
||||
new_label.style.width = width
|
||||
return new_label
|
||||
end)
|
||||
|
||||
local pd_data_set = Gui.element("pd_data_set")
|
||||
:draw(function(_, parent, name)
|
||||
local pd_data_set = parent.add{ type = "flow", direction = "vertical", name = name }
|
||||
local disp = Gui.elements.scroll_table(pd_data_set, label_width["total"], 4, "disp")
|
||||
|
||||
for _, stat_name in pairs(PlayerData.Statistics.metadata.display_order) do
|
||||
local child = PlayerData.Statistics[stat_name]
|
||||
local metadata = child.metadata
|
||||
local value = metadata.stringify_short and metadata.stringify_short(0) or metadata.stringify and metadata.stringify(0) or format_number(0, false)
|
||||
label(disp, label_width["name"], metadata.name or { "exp-statistics." .. stat_name }, metadata.tooltip or { "exp-statistics." .. stat_name .. "-tooltip" })
|
||||
label(disp, label_width["count"], { "readme.data-format", value, metadata.unit or "" }, metadata.value_tooltip or { "exp-statistics." .. stat_name .. "-tooltip" }, stat_name)
|
||||
end
|
||||
|
||||
for stat_name, data in pairs(computed_stats) do
|
||||
label(disp, label_width["name"], { "exp-statistics." .. stat_name }, { "exp-statistics." .. stat_name .. "-tooltip" })
|
||||
label(disp, label_width["count"], { "readme.data-format", data.default, "" }, { "exp-statistics." .. stat_name .. "-tooltip" }, stat_name)
|
||||
end
|
||||
|
||||
return pd_data_set
|
||||
end)
|
||||
|
||||
local function pd_update(table, player_name)
|
||||
for _, stat_name in pairs(PlayerData.Statistics.metadata.display_order) do
|
||||
local child = PlayerData.Statistics[stat_name]
|
||||
local metadata = child.metadata
|
||||
local value = child:get(player_name)
|
||||
if metadata.stringify_short then
|
||||
value = metadata.stringify_short(value or 0)
|
||||
elseif metadata.stringify then
|
||||
value = metadata.stringify(value or 0)
|
||||
else
|
||||
value = format_number(value or 0, false)
|
||||
end
|
||||
table[stat_name].caption = { "readme.data-format", value, metadata.unit or "" }
|
||||
end
|
||||
|
||||
for stat_name, data in pairs(computed_stats) do
|
||||
table[stat_name].caption = { "readme.data-format", data.calculate(player_name), "" }
|
||||
end
|
||||
end
|
||||
|
||||
local pd_username_player = Gui.element("pd_username_player")
|
||||
:draw(function(def, parent, player_list)
|
||||
return parent.add{
|
||||
name = def.name,
|
||||
type = "drop-down",
|
||||
items = player_list,
|
||||
selected_index = #player_list > 0 and 1 or nil,
|
||||
}
|
||||
end)
|
||||
:style{
|
||||
horizontally_stretchable = true,
|
||||
}:on_selection_state_changed(function(def, player, element)
|
||||
local player_name = game.connected_players[element.selected_index]
|
||||
local table = element.parent.parent.parent.parent["pd_st_2"].disp.table
|
||||
pd_update(table, player_name)
|
||||
end)
|
||||
|
||||
local pd_username_update = Gui.element("pd_username_update")
|
||||
:draw{
|
||||
type = "button",
|
||||
name = Gui.property_from_name,
|
||||
caption = "update",
|
||||
}:style{
|
||||
width = 128,
|
||||
}:on_click(function(def, player, element)
|
||||
local player_index = element.parent[pd_username_player.name].selected_index
|
||||
|
||||
if player_index > 0 then
|
||||
local player_name = game.connected_players[player_index]
|
||||
local table = element.parent.parent.parent.parent["pd_st_2"].disp.table
|
||||
pd_update(table, player_name)
|
||||
end
|
||||
end)
|
||||
|
||||
local pd_username_set = Gui.element("pd_username_set")
|
||||
:draw(function(_, parent, name, player_list)
|
||||
local pd_username_set = parent.add{ type = "flow", direction = "vertical", name = name }
|
||||
local disp = Gui.elements.scroll_table(pd_username_set, label_width["total"], 2, "disp")
|
||||
|
||||
pd_username_player(disp, player_list)
|
||||
pd_username_update(disp)
|
||||
|
||||
return pd_username_set
|
||||
end)
|
||||
|
||||
pd_container = Gui.element("pd_container")
|
||||
:draw(function(def, parent)
|
||||
local container = Gui.elements.container(parent, label_width["total"])
|
||||
local player_list = {}
|
||||
|
||||
for _, player in pairs(game.connected_players) do
|
||||
table.insert(player_list, player.name)
|
||||
end
|
||||
|
||||
pd_username_set(container, "pd_st_1", player_list)
|
||||
pd_data_set(container, "pd_st_2")
|
||||
|
||||
return container.parent
|
||||
end)
|
||||
|
||||
--- Add the element to the left flow with a toolbar button
|
||||
Gui.add_left_element(pd_container, false)
|
||||
Gui.toolbar.create_button{
|
||||
name = "player_data_toggle",
|
||||
left_element = pd_container,
|
||||
sprite = "item/power-armor-mk2",
|
||||
tooltip = "Player Data GUI",
|
||||
visible = function(player, element)
|
||||
return Roles.player_allowed(player, "gui/playerdata")
|
||||
end
|
||||
}
|
||||
|
||||
local function gui_player_list_update()
|
||||
local player_list = {}
|
||||
|
||||
for _, player in pairs(game.connected_players) do
|
||||
table.insert(player_list, player.name)
|
||||
end
|
||||
|
||||
for _, player in pairs(game.connected_players) do
|
||||
local container = Gui.get_left_element(pd_container, player)
|
||||
container.frame["pd_st_1"].disp.table[pd_username_player.name].items = player_list
|
||||
end
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_player_joined_game, gui_player_list_update)
|
||||
Event.add(defines.events.on_player_left_game, gui_player_list_update)
|
||||
@@ -1,152 +0,0 @@
|
||||
---- Production Data
|
||||
-- @gui Production
|
||||
|
||||
local Gui = require("modules/exp_gui")
|
||||
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
||||
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
|
||||
|
||||
local production_container
|
||||
|
||||
local precision = {
|
||||
[1] = defines.flow_precision_index.five_seconds,
|
||||
[2] = defines.flow_precision_index.one_minute,
|
||||
[3] = defines.flow_precision_index.ten_minutes,
|
||||
[4] = defines.flow_precision_index.one_hour,
|
||||
[5] = defines.flow_precision_index.ten_hours,
|
||||
}
|
||||
|
||||
local font_color = {
|
||||
["positive"] = { r = 0.3, g = 1, b = 0.3 },
|
||||
["negative"] = { r = 1, g = 0.3, b = 0.3 },
|
||||
}
|
||||
|
||||
local function format_n(amount)
|
||||
if math.abs(amount) < 0.009 then
|
||||
return "0.00"
|
||||
end
|
||||
local suffix = ""
|
||||
local suffix_list = {
|
||||
[" G"] = 1e9,
|
||||
[" M"] = 1e6,
|
||||
[" k"] = 1e3
|
||||
}
|
||||
local scale = 1
|
||||
for letter, limit in pairs(suffix_list) do
|
||||
if math.abs(amount) >= limit then
|
||||
scale = limit
|
||||
suffix = letter
|
||||
break
|
||||
end
|
||||
end
|
||||
local formatted = string.format("%.2f%s", amount / scale, suffix)
|
||||
-- Split into integer and fractional parts
|
||||
local integer_part, fractional_part = formatted:match("^(%-?%d+)%.(%d+)(.*)$")
|
||||
-- Add commas to integer part
|
||||
return string.format("%s.%s%s", (integer_part or formatted):reverse():gsub("(%d%d%d)", "%1,"):reverse():gsub("^,", ""):gsub("-,", "-"), fractional_part or "00", suffix)
|
||||
end
|
||||
|
||||
--- Display group
|
||||
-- @element production_data_group
|
||||
local production_data_group = Gui.element("production_data_group")
|
||||
:draw(function(_def, parent, i)
|
||||
local item
|
||||
|
||||
if i == 0 then
|
||||
item = parent.add{
|
||||
type = "drop-down",
|
||||
name = "production_0_e",
|
||||
items = { "5s", "1m", "10m", "1h", "10h" },
|
||||
selected_index = 3,
|
||||
}
|
||||
item.style.width = 80
|
||||
else
|
||||
item = parent.add{
|
||||
type = "choose-elem-button",
|
||||
name = "production_" .. i .. "_e",
|
||||
elem_type = "item",
|
||||
style = "slot_button",
|
||||
}
|
||||
item.style.height = 32
|
||||
item.style.width = 32
|
||||
end
|
||||
|
||||
for j = 1, 3 do
|
||||
local data = parent.add{
|
||||
type = "label",
|
||||
name = "production_" .. i .. "_" .. j,
|
||||
caption = "0.00",
|
||||
style = "heading_2_label",
|
||||
}
|
||||
data.style.font_color = font_color["positive"]
|
||||
end
|
||||
|
||||
return item
|
||||
end)
|
||||
|
||||
--- A vertical flow containing all the production data
|
||||
-- @element production_data_set
|
||||
local production_data_set = Gui.element("production_data_set")
|
||||
:draw(function(_, parent, name)
|
||||
local production_set = parent.add{ type = "flow", direction = "vertical", name = name }
|
||||
local disp = Gui.elements.scroll_table(production_set, 320, 4, "disp")
|
||||
for i = 2, 4 do
|
||||
disp.style.column_alignments[i] = "right"
|
||||
end
|
||||
production_data_group(disp, 0)
|
||||
disp["production_0_1"].caption = { "production.label-prod" }
|
||||
disp["production_0_1"].tooltip = { "production.tooltip-per-second" }
|
||||
disp["production_0_2"].caption = { "production.label-con" }
|
||||
disp["production_0_2"].tooltip = { "production.tooltip-per-second" }
|
||||
disp["production_0_3"].caption = { "production.label-bal" }
|
||||
disp["production_0_3"].tooltip = { "production.tooltip-per-second" }
|
||||
for i = 1, 8 do
|
||||
production_data_group(disp, i)
|
||||
end
|
||||
return production_set
|
||||
end)
|
||||
|
||||
production_container = Gui.element("production_container")
|
||||
:draw(function(def, parent)
|
||||
local container = Gui.elements.container(parent, 320)
|
||||
production_data_set(container, "production_st")
|
||||
return container.parent
|
||||
end)
|
||||
|
||||
--- Add the element to the left flow with a toolbar button
|
||||
Gui.add_left_element(production_container, false)
|
||||
Gui.toolbar.create_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")
|
||||
end
|
||||
}
|
||||
|
||||
Event.on_nth_tick(60, function()
|
||||
for _, player in pairs(game.connected_players) do
|
||||
local container = Gui.get_left_element(production_container, player)
|
||||
local stat = player.force.get_item_production_statistics(player.surface) -- Allow remote view
|
||||
local precision_value = precision[container.frame["production_st"].disp.table["production_0_e"].selected_index]
|
||||
local table = container.frame["production_st"].disp.table
|
||||
for i = 1, 8 do
|
||||
local production_prefix = "production_" .. i
|
||||
local item = table[production_prefix .. "_e"].elem_value --[[ @as string ]]
|
||||
if item then
|
||||
local add = math.floor(stat.get_flow_count{ name = item, category = "input", precision_index = precision_value, count = false } / 6) / 10
|
||||
local minus = math.floor(stat.get_flow_count{ name = item, category = "output", precision_index = precision_value, count = false } / 6) / 10
|
||||
local sum = add - minus
|
||||
table[production_prefix .. "_1"].caption = format_n(add)
|
||||
table[production_prefix .. "_2"].caption = format_n(minus)
|
||||
table[production_prefix .. "_3"].caption = format_n(sum)
|
||||
table[production_prefix .. "_3"].style.font_color = (sum < 0 and font_color["negative"]) or font_color["positive"]
|
||||
else
|
||||
table[production_prefix .. "_1"].caption = "0.00"
|
||||
table[production_prefix .. "_2"].caption = "0.00"
|
||||
table[production_prefix .. "_3"].caption = "0.00"
|
||||
table[production_prefix .. "_3"].style.font_color = font_color["positive"]
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
@@ -23,7 +23,7 @@ local title_width = 270 -- controls the centering of the titles
|
||||
local scroll_height = 275 -- controls the height of the scrolls
|
||||
|
||||
--- Sub content area used within the content areas
|
||||
local sub_content = Gui.element("readme_sub_content")
|
||||
local sub_content = Gui.define("readme_sub_content")
|
||||
:draw{
|
||||
type = "frame",
|
||||
direction = "vertical",
|
||||
@@ -37,7 +37,7 @@ local sub_content = Gui.element("readme_sub_content")
|
||||
}
|
||||
|
||||
--- Table which has a title above it above it
|
||||
local title_table = Gui.element("readme_title_table")
|
||||
local title_table = Gui.define("readme_title_table")
|
||||
:draw(function(_, parent, bar_size, caption, column_count)
|
||||
Gui.elements.title_label(parent, bar_size, caption)
|
||||
|
||||
@@ -55,7 +55,7 @@ local title_table = Gui.element("readme_title_table")
|
||||
}
|
||||
|
||||
--- Scroll to be used with Gui.elements.title_label tables
|
||||
local title_table_scroll = Gui.element("readme_title_table_scroll")
|
||||
local title_table_scroll = Gui.define("readme_title_table_scroll")
|
||||
:draw{
|
||||
type = "scroll-pane",
|
||||
direction = "vertical",
|
||||
@@ -70,7 +70,7 @@ local title_table_scroll = Gui.element("readme_title_table_scroll")
|
||||
}
|
||||
|
||||
--- Used to connect to servers in server list
|
||||
local join_server = Gui.element("readme_join_server")
|
||||
local join_server = Gui.define("readme_join_server")
|
||||
:draw(function(_, parent, server_id, wrong_version)
|
||||
local status = External.get_server_status(server_id) or "Offline"
|
||||
if wrong_version then status = "Version" end
|
||||
@@ -111,7 +111,7 @@ local join_server = Gui.element("readme_join_server")
|
||||
local welcome_time_format = ExpUtil.format_time_factory_locale{ format = "long", days = true, hours = true, minutes = true }
|
||||
|
||||
--- Content area for the welcome tab
|
||||
define_tab({ "readme.welcome-tab" }, { "readme.welcome-tooltip" }, Gui.element("readme_welcome")
|
||||
define_tab({ "readme.welcome-tab" }, { "readme.welcome-tooltip" }, Gui.define("readme_welcome")
|
||||
:draw(function(_, parent)
|
||||
local server_details = { name = "APERX S0 - Local", welcome = "Failed to load description: disconnected from external api.", reset_time = "Non Set", branch = "Unknown" }
|
||||
if External.valid() then server_details = External.get_current_server() end
|
||||
@@ -148,7 +148,7 @@ define_tab({ "readme.welcome-tab" }, { "readme.welcome-tooltip" }, Gui.element("
|
||||
end))
|
||||
|
||||
--- Content area for the rules tab
|
||||
define_tab({ "readme.rules-tab" }, { "readme.rules-tooltip" }, Gui.element("readme_rules")
|
||||
define_tab({ "readme.rules-tab" }, { "readme.rules-tooltip" }, Gui.define("readme_rules")
|
||||
:draw(function(_, parent)
|
||||
local container = parent.add{ type = "flow", direction = "vertical" }
|
||||
|
||||
@@ -172,7 +172,7 @@ define_tab({ "readme.rules-tab" }, { "readme.rules-tooltip" }, Gui.element("read
|
||||
end))
|
||||
|
||||
--- Content area for the commands tab
|
||||
define_tab({ "readme.commands-tab" }, { "readme.commands-tooltip" }, Gui.element("readme_commands")
|
||||
define_tab({ "readme.commands-tab" }, { "readme.commands-tooltip" }, Gui.define("readme_commands")
|
||||
:draw(function(_, parent)
|
||||
local container = parent.add{ type = "flow", direction = "vertical" }
|
||||
local player = Gui.get_player(parent)
|
||||
@@ -198,7 +198,7 @@ define_tab({ "readme.commands-tab" }, { "readme.commands-tooltip" }, Gui.element
|
||||
end))
|
||||
|
||||
--- Content area for the servers tab
|
||||
define_tab({ "readme.servers-tab" }, { "readme.servers-tooltip" }, Gui.element("readme_servers")
|
||||
define_tab({ "readme.servers-tab" }, { "readme.servers-tooltip" }, Gui.define("readme_servers")
|
||||
:draw(function(_, parent)
|
||||
local container = parent.add{ type = "flow", direction = "vertical" }
|
||||
|
||||
@@ -241,7 +241,7 @@ define_tab({ "readme.servers-tab" }, { "readme.servers-tooltip" }, Gui.element("
|
||||
end))
|
||||
|
||||
--- Content area for the servers tab
|
||||
define_tab({ "readme.backers-tab" }, { "readme.backers-tooltip" }, Gui.element("readme_backers")
|
||||
define_tab({ "readme.backers-tab" }, { "readme.backers-tooltip" }, Gui.define("readme_backers")
|
||||
:draw(function(_, parent)
|
||||
local container = parent.add{ type = "flow", direction = "vertical" }
|
||||
|
||||
@@ -304,7 +304,7 @@ define_tab({ "readme.backers-tab" }, { "readme.backers-tooltip" }, Gui.element("
|
||||
end))
|
||||
|
||||
--- Content area for the player data tab
|
||||
define_tab({ "readme.data-tab" }, { "readme.data-tooltip" }, Gui.element("readme_data")
|
||||
define_tab({ "readme.data-tab" }, { "readme.data-tooltip" }, Gui.define("readme_data")
|
||||
:draw(function(_, parent)
|
||||
local container = parent.add{ type = "flow", direction = "vertical" }
|
||||
local player = Gui.get_player(parent)
|
||||
@@ -399,7 +399,7 @@ define_tab({ "readme.data-tab" }, { "readme.data-tooltip" }, Gui.element("readme
|
||||
|
||||
--- Main readme container for the center flow
|
||||
local readme_toggle
|
||||
local readme = Gui.element("readme")
|
||||
local readme = Gui.define("readme")
|
||||
:draw(function(def, parent)
|
||||
local container = parent.add{
|
||||
name = def.name,
|
||||
|
||||
@@ -1,292 +0,0 @@
|
||||
--- research gui
|
||||
-- @gui Research
|
||||
|
||||
local ExpUtil = require("modules/exp_util")
|
||||
local Gui = require("modules/exp_gui")
|
||||
local Storage = require("modules/exp_util/storage")
|
||||
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
||||
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
|
||||
local config = require("modules.exp_legacy.config.research") --- @dep config.research
|
||||
|
||||
local table_to_json = helpers.table_to_json
|
||||
local write_file = helpers.write_file
|
||||
|
||||
local research = {
|
||||
time = {},
|
||||
res_queue_enable = false
|
||||
}
|
||||
|
||||
Storage.register(research, function(tbl)
|
||||
research = tbl
|
||||
end)
|
||||
|
||||
for _, mod_name in ipairs(config.mod_set_lookup) do
|
||||
if script.active_mods[mod_name] then
|
||||
config.mod_set = mod_name
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
local research_time_format = ExpUtil.format_time_factory{ format = "clock", hours = true, minutes = true, seconds = true }
|
||||
local empty_time = research_time_format(nil)
|
||||
|
||||
local font_color = {
|
||||
["neutral"] = { r = 1, g = 1, b = 1 },
|
||||
["positive"] = { r = 0.3, g = 1, b = 0.3 },
|
||||
["negative"] = { r = 1, g = 0.3, b = 0.3 },
|
||||
}
|
||||
|
||||
local res = {
|
||||
["lookup_name"] = {},
|
||||
["disp"] = {},
|
||||
}
|
||||
|
||||
do
|
||||
local res_total = 0
|
||||
local i = 1
|
||||
|
||||
for k, v in pairs(config.milestone[config.mod_set]) do
|
||||
research.time[i] = 0
|
||||
res["lookup_name"][k] = i
|
||||
res_total = res_total + v * 60
|
||||
|
||||
res["disp"][i] = {
|
||||
raw_name = k,
|
||||
target = res_total,
|
||||
target_disp = research_time_format(res_total),
|
||||
}
|
||||
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
|
||||
local function research_add_log()
|
||||
local result_data = {}
|
||||
|
||||
for i = 1, #research.time do
|
||||
result_data[res["disp"][i]["raw_name"]] = research.time[i]
|
||||
end
|
||||
|
||||
write_file(config.file_name, table_to_json(result_data) .. "\n", true, 0)
|
||||
end
|
||||
|
||||
local function research_res_n()
|
||||
local current = #res.disp + 1
|
||||
|
||||
for i = 1, #res.disp do
|
||||
if research.time[i] == 0 then
|
||||
current = i
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
return math.clamp(current - 3, 1, math.max(1, #res.disp - 7))
|
||||
end
|
||||
|
||||
local function research_notification(event)
|
||||
if config.inf_res[config.mod_set][event.research.name] then
|
||||
if event.research.name == config.bonus_inventory.log[config.mod_set].name and event.research.level == config.bonus_inventory.log[config.mod_set].level + 1 then
|
||||
-- Add run result to log
|
||||
research_add_log()
|
||||
end
|
||||
|
||||
if not (event.by_script) then
|
||||
game.print{ "research.inf", research_time_format(game.tick), event.research.name, event.research.level - 1 }
|
||||
end
|
||||
elseif not (event.by_script) then
|
||||
game.print{ "research.msg", research_time_format(game.tick), event.research.name }
|
||||
end
|
||||
|
||||
if config.bonus_inventory.enabled and config.bonus_inventory.res[event.research.name] then
|
||||
event.research.force[config.bonus_inventory.name] = math.min((event.research.level - 1) * config.bonus_inventory.rate, config.bonus_inventory.limit)
|
||||
end
|
||||
|
||||
if config.pollution_ageing_by_research and config.bonus_inventory.res[event.research.name] then
|
||||
game.map_settings.pollution.ageing = math.min(10, event.research.level / 5)
|
||||
end
|
||||
end
|
||||
|
||||
local function research_gui_update()
|
||||
local res_disp = {}
|
||||
local res_n = research_res_n()
|
||||
|
||||
for i = 1, 8 do
|
||||
local res_i = res_n + i - 1
|
||||
local entry = res.disp[res_i] or {}
|
||||
local data = {
|
||||
name = "",
|
||||
target = "",
|
||||
attempt = "",
|
||||
difference = "",
|
||||
color = font_color["positive"]
|
||||
}
|
||||
|
||||
if entry.raw_name then
|
||||
assert(prototypes.technology[entry.raw_name], "Invalid Research: " .. tostring(entry.raw_name))
|
||||
data.name = { "research.res-name", entry.raw_name, prototypes.technology[entry.raw_name].localised_name }
|
||||
data.target = entry.target_disp
|
||||
|
||||
if research.time[res_i] == 0 then
|
||||
data.attempt = empty_time
|
||||
data.difference = empty_time
|
||||
|
||||
else
|
||||
data.attempt = research_time_format(research.time[res_i])
|
||||
local diff = research.time[res_i] - entry.target
|
||||
data.difference = (diff < 0 and "-" or "") .. research_time_format(math.abs(diff))
|
||||
data.color = (diff < 0 and font_color["positive"]) or font_color["negative"]
|
||||
end
|
||||
end
|
||||
|
||||
res_disp[i] = data
|
||||
end
|
||||
|
||||
return res_disp
|
||||
end
|
||||
|
||||
--- Display label for the clock display
|
||||
-- @element research_gui_clock_display
|
||||
local research_gui_clock = Gui.element("research_gui_clock")
|
||||
:draw{
|
||||
type = "label",
|
||||
name = Gui.property_from_name,
|
||||
caption = empty_time,
|
||||
style = "heading_2_label",
|
||||
}
|
||||
|
||||
--- A vertical flow containing the clock
|
||||
-- @element research_clock_set
|
||||
local research_clock_set = Gui.element("research_clock_set")
|
||||
:draw(function(_, parent, name)
|
||||
local research_set = parent.add{ type = "flow", direction = "vertical", name = name }
|
||||
local disp = Gui.elements.scroll_table(research_set, 390, 1, "disp")
|
||||
|
||||
research_gui_clock(disp)
|
||||
|
||||
return research_set
|
||||
end)
|
||||
|
||||
--- Display group
|
||||
-- @element research_data_group
|
||||
local research_data_group = Gui.element("research_data_group")
|
||||
:draw(function(_def, parent, i)
|
||||
local labels = { "name", "target", "attempt", "difference" }
|
||||
|
||||
for _, label in ipairs(labels) do
|
||||
local elem = parent.add{
|
||||
type = "label",
|
||||
name = "research_" .. i .. "_" .. label,
|
||||
caption = "",
|
||||
style = "heading_2_label"
|
||||
}
|
||||
elem.style.minimal_width = (label == "name" and 180) or 70
|
||||
elem.style.horizontal_align = (label == "name" and "left") or "right"
|
||||
elem.style.font_color = (label == "difference" and font_color["positive"]) or font_color["neutral"]
|
||||
end
|
||||
end)
|
||||
|
||||
--- A vertical flow containing the data
|
||||
-- @element research_data_set
|
||||
local research_data_set = Gui.element("research_data_set")
|
||||
:draw(function(_, parent, name)
|
||||
local research_set = parent.add{ type = "flow", direction = "vertical", name = name }
|
||||
local disp = Gui.elements.scroll_table(research_set, 390, 4, "disp")
|
||||
local res_disp = research_gui_update()
|
||||
|
||||
research_data_group(disp, 0)
|
||||
disp["research_0_name"].caption = { "research.name" }
|
||||
disp["research_0_target"].caption = { "research.target" }
|
||||
disp["research_0_attempt"].caption = { "research.attempt" }
|
||||
disp["research_0_difference"].caption = { "research.difference" }
|
||||
disp["research_0_difference"].style.font_color = font_color["neutral"]
|
||||
|
||||
for i = 1, 8 do
|
||||
research_data_group(disp, i)
|
||||
local research_name_i = "research_" .. i
|
||||
disp[research_name_i .. "_name"].caption = res_disp[i]["name"]
|
||||
disp[research_name_i .. "_target"].caption = res_disp[i]["target"]
|
||||
disp[research_name_i .. "_attempt"].caption = res_disp[i]["attempt"]
|
||||
disp[research_name_i .. "_difference"].caption = res_disp[i]["difference"]
|
||||
disp[research_name_i .. "_difference"].style.font_color = res_disp[i]["color"]
|
||||
end
|
||||
|
||||
return research_set
|
||||
end)
|
||||
|
||||
local research_container = Gui.element("research_container")
|
||||
:draw(function(def, parent)
|
||||
local container = Gui.elements.container(parent, 390)
|
||||
|
||||
research_clock_set(container, "research_st_1")
|
||||
research_data_set(container, "research_st_2")
|
||||
|
||||
return container.parent
|
||||
end)
|
||||
|
||||
--- Add the element to the left flow with a toolbar button
|
||||
Gui.add_left_element(research_container, false)
|
||||
Gui.toolbar.create_button{
|
||||
name = "research_toggle",
|
||||
left_element = research_container,
|
||||
sprite = "item/space-science-pack",
|
||||
tooltip = { "research.main-tooltip" },
|
||||
visible = function(player, element)
|
||||
return Roles.player_allowed(player, "gui/research")
|
||||
end
|
||||
}
|
||||
|
||||
Event.add(defines.events.on_research_finished, function(event)
|
||||
research_notification(event)
|
||||
local research_name = event.research.name
|
||||
|
||||
if not res["lookup_name"][research_name] then
|
||||
return
|
||||
end
|
||||
|
||||
research.time[res.lookup_name[research_name]] = game.tick
|
||||
|
||||
local res_disp = research_gui_update()
|
||||
|
||||
for _, player in pairs(game.connected_players) do
|
||||
if Roles.player_allowed(player, "gui/research") then
|
||||
local container = Gui.get_left_element(research_container, player)
|
||||
local disp = container.frame["research_st_2"].disp.table
|
||||
|
||||
for i = 1, 8 do
|
||||
local research_name_i = "research_" .. i
|
||||
disp[research_name_i .. "_name"].caption = res_disp[i]["name"]
|
||||
disp[research_name_i .. "_target"].caption = res_disp[i]["target"]
|
||||
disp[research_name_i .. "_attempt"].caption = res_disp[i]["attempt"]
|
||||
disp[research_name_i .. "_difference"].caption = res_disp[i]["difference"]
|
||||
disp[research_name_i .. "_difference"].style.font_color = res_disp[i]["color"]
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
Event.add(defines.events.on_research_started, function(event)
|
||||
if config.limit_res[event.research.name] and event.research.level > config.limit_res[event.research.name] then
|
||||
event.research.enabled = false
|
||||
event.research.visible_when_disabled = true
|
||||
local rq = event.research.force.research_queue
|
||||
|
||||
for i = #rq, 1, -1 do
|
||||
if rq[i] == event.research.name then
|
||||
table.remove(rq, i)
|
||||
end
|
||||
end
|
||||
|
||||
event.research.force.cancel_current_research()
|
||||
event.research.force.research_queue = rq
|
||||
end
|
||||
end)
|
||||
|
||||
Event.on_nth_tick(60, function()
|
||||
local current_time = research_time_format(game.tick)
|
||||
|
||||
for _, player in pairs(game.connected_players) do
|
||||
local container = Gui.get_left_element(research_container, player)
|
||||
local disp = container.frame["research_st_1"].disp.table
|
||||
disp[research_gui_clock.name].caption = current_time
|
||||
end
|
||||
end)
|
||||
@@ -39,12 +39,12 @@ end
|
||||
|
||||
--- Button to toggle the auto launch on a rocket silo
|
||||
-- @element toggle_launch
|
||||
local toggle_launch = Gui.element("toggle_launch")
|
||||
local toggle_launch = Gui.define("toggle_launch")
|
||||
:draw{
|
||||
type = "sprite-button",
|
||||
sprite = "utility/play",
|
||||
tooltip = { "rocket-info.toggle-rocket-tooltip" },
|
||||
name = Gui.property_from_name,
|
||||
name = Gui.from_name,
|
||||
}
|
||||
:style(Gui.styles.sprite{
|
||||
size = 16,
|
||||
@@ -65,7 +65,7 @@ local toggle_launch = Gui.element("toggle_launch")
|
||||
|
||||
--- XY cords that allow zoom to map when pressed
|
||||
-- @element silo_cords
|
||||
local silo_cords = Gui.element("silo_cords")
|
||||
local silo_cords = Gui.define("silo_cords")
|
||||
:draw(function(definition, parent, silo_data)
|
||||
local silo_name = silo_data.silo_name
|
||||
local pos = silo_data.position
|
||||
@@ -105,6 +105,8 @@ local silo_cords = Gui.element("silo_cords")
|
||||
definition:link_element(label_x)
|
||||
definition:link_element(label_y)
|
||||
end
|
||||
|
||||
return Gui.no_return()
|
||||
end)
|
||||
:on_click(function(def, player, element)
|
||||
local rocket_silo_name = element.parent.caption
|
||||
@@ -114,7 +116,7 @@ local silo_cords = Gui.element("silo_cords")
|
||||
|
||||
--- Base element for each rocket in the progress list
|
||||
-- @element rocket_entry
|
||||
local rocket_entry = Gui.element("rocket_entry")
|
||||
local rocket_entry = Gui.define("rocket_entry")
|
||||
:draw(function(_, parent, silo_data)
|
||||
local silo_name = silo_data.silo_name
|
||||
local player = Gui.get_player(parent)
|
||||
@@ -149,7 +151,7 @@ local rocket_entry = Gui.element("rocket_entry")
|
||||
|
||||
--- Data label which contains a name and a value label pair
|
||||
-- @element data_label
|
||||
local data_label = Gui.element("data_label")
|
||||
local data_label = Gui.define("data_label")
|
||||
:draw(function(_, parent, label_data)
|
||||
local data_name = label_data.name
|
||||
local data_subname = label_data.subname
|
||||
@@ -392,14 +394,14 @@ end
|
||||
|
||||
-- Button to toggle a section dropdown
|
||||
-- @element toggle_section
|
||||
local toggle_section = Gui.element("rocket_info_toggle_section")
|
||||
local toggle_section = Gui.define("rocket_info_toggle_section")
|
||||
:draw{
|
||||
type = "sprite-button",
|
||||
sprite = "utility/expand",
|
||||
hovered_sprite = "utility/expand",
|
||||
tooltip = { "rocket-info.toggle-section-tooltip" },
|
||||
style = "frame_action_button",
|
||||
name = Gui.property_from_name,
|
||||
name = Gui.from_name,
|
||||
}
|
||||
:style(Gui.styles.sprite{
|
||||
size = 20,
|
||||
@@ -419,17 +421,16 @@ local toggle_section = Gui.element("rocket_info_toggle_section")
|
||||
|
||||
-- Draw a section header and main scroll
|
||||
-- @element rocket_list_container
|
||||
local section = Gui.element("rocket_info_section")
|
||||
local section = Gui.define("rocket_info_section")
|
||||
:draw(function(definition, parent, section_name, table_size)
|
||||
-- Draw the header for the section
|
||||
local header = Gui.elements.header(parent, {
|
||||
name = section_name .. "-header",
|
||||
caption = { "rocket-info.section-caption-" .. section_name },
|
||||
tooltip = { "rocket-info.section-tooltip-" .. section_name },
|
||||
label_name = "label",
|
||||
})
|
||||
|
||||
definition:link_element(header.parent.label)
|
||||
definition:link_element(header.label)
|
||||
|
||||
-- Right aligned button to toggle the section
|
||||
header.caption = section_name
|
||||
@@ -449,7 +450,7 @@ local section = Gui.element("rocket_info_section")
|
||||
|
||||
--- Main gui container for the left flow
|
||||
-- @element rocket_list_container
|
||||
local rocket_list_container = Gui.element("rocket_list_container")
|
||||
local rocket_list_container = Gui.define("rocket_list_container")
|
||||
:draw(function(definition, parent)
|
||||
-- Draw the internal container
|
||||
local container = Gui.elements.container(parent, 200)
|
||||
|
||||
@@ -1,388 +0,0 @@
|
||||
--[[-- Gui Module - Science Info
|
||||
- Adds a science info gui that shows production usage and net for the different science packs as well as an eta
|
||||
@gui Science-Info
|
||||
@alias science_info
|
||||
]]
|
||||
|
||||
local ExpUtil = require("modules/exp_util")
|
||||
local Gui = require("modules/exp_gui")
|
||||
local Roles = require("modules.exp_legacy.expcore.roles")
|
||||
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
||||
local config = require("modules.exp_legacy.config.gui.science") --- @dep config.gui.science
|
||||
local Production = require("modules.exp_legacy.modules.control.production") --- @dep modules.control.production
|
||||
|
||||
local clock_time_format = ExpUtil.format_time_factory_locale{ format = "clock", hours = true, minutes = true, seconds = true }
|
||||
local long_time_format = ExpUtil.format_time_factory_locale{ format = "long", hours = true, minutes = true, seconds = true }
|
||||
|
||||
local null_time_clock = { "science-info.eta-time", clock_time_format(nil) }
|
||||
local null_time_long = long_time_format(nil)
|
||||
|
||||
--- Remove invalid science packs, this can result from a certain mod not being loaded
|
||||
for i = #config, 1, -1 do
|
||||
if not prototypes.item[config[i]] then
|
||||
table.remove(config, i)
|
||||
end
|
||||
end
|
||||
|
||||
--- Data label that contains the value and the suffix
|
||||
-- @element production_label
|
||||
local production_label = Gui.element("science_info_production_label")
|
||||
:draw(function(_, parent, production_label_data)
|
||||
local name = production_label_data.name
|
||||
local tooltip = production_label_data.tooltip
|
||||
local color = production_label_data.color
|
||||
|
||||
-- Add an alignment for the number
|
||||
local alignment = Gui.elements.aligned_flow(parent, { name = name })
|
||||
|
||||
-- Add the main value label
|
||||
local element =
|
||||
alignment.add{
|
||||
name = "label",
|
||||
type = "label",
|
||||
caption = production_label_data.caption,
|
||||
tooltip = tooltip,
|
||||
}
|
||||
|
||||
-- Change the style
|
||||
element.style.font_color = color
|
||||
|
||||
-- Add the suffix label
|
||||
local suffix_element =
|
||||
parent.add{
|
||||
name = "suffix-" .. name,
|
||||
type = "label",
|
||||
caption = { "science-info.unit", production_label_data.suffix },
|
||||
tooltip = tooltip,
|
||||
}
|
||||
|
||||
-- Change the style
|
||||
local suffix_element_style = suffix_element.style
|
||||
suffix_element_style.font_color = color
|
||||
suffix_element_style.right_margin = 1
|
||||
|
||||
-- Return the value label
|
||||
return element
|
||||
end)
|
||||
|
||||
-- Get the data that is used with the production label
|
||||
local function get_production_label_data(name, tooltip, value, cutout, secondary)
|
||||
local data_colour = Production.get_color(config.color_cutoff * cutout, value, secondary)
|
||||
local suffix, caption = Production.format_number(value)
|
||||
|
||||
return {
|
||||
name = name,
|
||||
caption = caption,
|
||||
suffix = suffix,
|
||||
tooltip = tooltip,
|
||||
color = data_colour,
|
||||
}
|
||||
end
|
||||
|
||||
-- Updates a prodution label to match the current data
|
||||
local function update_production_label(parent, production_label_data)
|
||||
local name = production_label_data.name
|
||||
local tooltip = production_label_data.tooltip
|
||||
local color = production_label_data.color
|
||||
|
||||
-- Update the production label
|
||||
local production_label_element = parent[name] and parent[name].label or production_label(parent, production_label_data)
|
||||
production_label_element.caption = production_label_data.caption
|
||||
production_label_element.tooltip = production_label_data.tooltip
|
||||
production_label_element.style.font_color = color
|
||||
|
||||
-- Update the suffix label
|
||||
local suffix_element = parent["suffix-" .. name]
|
||||
suffix_element.caption = { "science-info.unit", production_label_data.suffix }
|
||||
suffix_element.tooltip = tooltip
|
||||
suffix_element.style.font_color = color
|
||||
end
|
||||
|
||||
--- Adds 4 elements that show the data for a science pack
|
||||
-- @element science_pack_base
|
||||
local science_pack_base = Gui.element("science_info_science_pack_base")
|
||||
:draw(function(_, parent, science_pack_data)
|
||||
local science_pack = science_pack_data.science_pack
|
||||
|
||||
-- Draw the icon for the science pack
|
||||
local icon_style = science_pack_data.icon_style
|
||||
local pack_icon =
|
||||
parent.add{
|
||||
name = "icon-" .. science_pack,
|
||||
type = "sprite-button",
|
||||
sprite = "item/" .. science_pack,
|
||||
tooltip = { "item-name." .. science_pack },
|
||||
style = icon_style,
|
||||
}
|
||||
|
||||
-- Change the style of the icon
|
||||
local pack_icon_style = pack_icon.style
|
||||
pack_icon.ignored_by_interaction = true
|
||||
pack_icon_style.height = 55
|
||||
if icon_style == "slot_button" then
|
||||
pack_icon_style.padding = { 0, -2 }
|
||||
pack_icon_style.width = 36
|
||||
end
|
||||
|
||||
-- Draw the delta flow
|
||||
local delta_flow =
|
||||
parent.add{
|
||||
name = "delta-" .. science_pack,
|
||||
type = "frame",
|
||||
style = "bordered_frame",
|
||||
}
|
||||
delta_flow.style.padding = { 0, 3 }
|
||||
|
||||
-- Draw the delta flow table
|
||||
local delta_table =
|
||||
delta_flow.add{
|
||||
name = "table",
|
||||
type = "table",
|
||||
column_count = 2,
|
||||
}
|
||||
delta_table.style.padding = 0
|
||||
|
||||
-- Draw the production labels
|
||||
update_production_label(delta_table, science_pack_data.positive)
|
||||
update_production_label(delta_table, science_pack_data.negative)
|
||||
update_production_label(parent, science_pack_data.net)
|
||||
|
||||
-- Return the pack icon
|
||||
return pack_icon
|
||||
end)
|
||||
|
||||
local function get_science_pack_data(player, science_pack)
|
||||
local force = player.force
|
||||
|
||||
-- Check that some packs have been made
|
||||
local total = Production.get_production_total(force, science_pack)
|
||||
if total.made == 0 then return end
|
||||
local minute = Production.get_production(force, science_pack, defines.flow_precision_index.one_minute)
|
||||
local hour = Production.get_production(force, science_pack, defines.flow_precision_index.one_hour)
|
||||
|
||||
-- Get the icon style
|
||||
local icon_style = "slot_button"
|
||||
local flux = Production.get_fluctuations(force, science_pack, defines.flow_precision_index.one_minute)
|
||||
if minute.net > 0 and flux.net > -config.color_flux / 2 then
|
||||
icon_style = "slot_sized_button_green"
|
||||
elseif flux.net < -config.color_flux then
|
||||
icon_style = "slot_sized_button_red"
|
||||
elseif minute.made > 0 then
|
||||
icon_style = "yellow_slot_button"
|
||||
end
|
||||
|
||||
-- Return the pack data
|
||||
return {
|
||||
science_pack = science_pack,
|
||||
icon_style = icon_style,
|
||||
positive = get_production_label_data(
|
||||
"pos-" .. science_pack,
|
||||
{ "science-info.pos-tooltip", total.made },
|
||||
minute.made, hour.made
|
||||
),
|
||||
negative = get_production_label_data(
|
||||
"neg-" .. science_pack,
|
||||
{ "science-info.neg-tooltip", total.used },
|
||||
-minute.used, hour.used
|
||||
),
|
||||
net = get_production_label_data(
|
||||
"net-" .. science_pack,
|
||||
{ "science-info.net-tooltip", total.net },
|
||||
minute.net, minute.net > 0 and hour.net or 0,
|
||||
minute.made + minute.used
|
||||
),
|
||||
}
|
||||
end
|
||||
|
||||
local function update_science_pack(pack_table, science_pack_data)
|
||||
if not science_pack_data then return end
|
||||
local science_pack = science_pack_data.science_pack
|
||||
pack_table.parent.non_made.visible = false
|
||||
|
||||
-- Update the icon
|
||||
--- @type LuaGuiElement
|
||||
local pack_icon = pack_table["icon-" .. science_pack] or science_pack_base(pack_table, science_pack_data)
|
||||
local icon_style = science_pack_data.icon_style
|
||||
pack_icon.style = icon_style
|
||||
|
||||
local pack_icon_style = pack_icon.style
|
||||
pack_icon_style.height = 55
|
||||
if icon_style == "slot_button" then
|
||||
pack_icon_style.padding = { 0, -2 }
|
||||
pack_icon_style.width = 36
|
||||
end
|
||||
|
||||
-- Update the production labels
|
||||
local delta_table = pack_table["delta-" .. science_pack].table
|
||||
update_production_label(delta_table, science_pack_data.positive)
|
||||
update_production_label(delta_table, science_pack_data.negative)
|
||||
update_production_label(pack_table, science_pack_data.net)
|
||||
end
|
||||
|
||||
--- Gets the data that is used with the eta label
|
||||
local function get_eta_label_data(player)
|
||||
local force = player.force
|
||||
|
||||
-- If there is no current research then return no research
|
||||
local research = force.current_research
|
||||
if not research then
|
||||
return { research = false }
|
||||
end
|
||||
|
||||
local limit
|
||||
local progress = force.research_progress
|
||||
local remaining = research.research_unit_count * (1 - progress)
|
||||
|
||||
-- Check for the limiting science pack
|
||||
for _, ingredient in pairs(research.research_unit_ingredients) do
|
||||
local pack_name = ingredient.name
|
||||
local required = ingredient.amount * remaining
|
||||
local time = Production.get_consumsion_eta(force, pack_name, defines.flow_precision_index.one_minute, required)
|
||||
if not limit or limit < time then
|
||||
limit = time
|
||||
end
|
||||
end
|
||||
|
||||
-- Return the caption and tooltip
|
||||
return limit and limit > 0 and {
|
||||
research = true,
|
||||
caption = clock_time_format(limit),
|
||||
tooltip = long_time_format(limit),
|
||||
} or {
|
||||
research = false
|
||||
}
|
||||
end
|
||||
|
||||
-- Updates the eta label
|
||||
local function update_eta_label(element, eta_label_data)
|
||||
-- If no research selected show null
|
||||
if not eta_label_data.research then
|
||||
element.caption = null_time_clock
|
||||
element.tooltip = null_time_long
|
||||
return
|
||||
end
|
||||
|
||||
-- Update the element
|
||||
element.caption = { "science-info.eta-time", eta_label_data.caption }
|
||||
element.tooltip = eta_label_data.tooltip
|
||||
end
|
||||
|
||||
--- Main task list container for the left flow
|
||||
-- @element task_list_container
|
||||
local science_info = Gui.element("science_info")
|
||||
:draw(function(def, parent)
|
||||
local player = Gui.get_player(parent)
|
||||
|
||||
-- Draw the internal container
|
||||
local container = Gui.elements.container(parent, 200)
|
||||
|
||||
-- Draw the header
|
||||
Gui.elements.header(container, {
|
||||
caption = { "science-info.main-caption" },
|
||||
tooltip = { "science-info.main-tooltip" },
|
||||
})
|
||||
|
||||
-- Draw the scroll table for the tasks
|
||||
local scroll_table = Gui.elements.scroll_table(container, 178, 4, "scroll")
|
||||
|
||||
-- Draw the no packs label
|
||||
local no_packs_label =
|
||||
scroll_table.parent.add{
|
||||
name = "non_made",
|
||||
type = "label",
|
||||
caption = { "science-info.no-packs" },
|
||||
}
|
||||
|
||||
-- Change the style of the no packs label
|
||||
local no_packs_style = no_packs_label.style
|
||||
no_packs_style.padding = { 2, 4 }
|
||||
no_packs_style.single_line = false
|
||||
no_packs_style.width = 200
|
||||
|
||||
-- Add the footer and eta
|
||||
if config.show_eta then
|
||||
-- Draw the footer
|
||||
local footer = Gui.elements.footer(container, {
|
||||
name = "footer",
|
||||
caption = { "science-info.eta-caption" },
|
||||
tooltip = { "science-info.eta-tooltip" },
|
||||
})
|
||||
|
||||
-- Draw the eta label
|
||||
local eta_label =
|
||||
footer.add{
|
||||
name = "label",
|
||||
type = "label",
|
||||
caption = null_time_clock,
|
||||
tooltip = null_time_long,
|
||||
style = "frame_title",
|
||||
}
|
||||
|
||||
-- Update the eta
|
||||
update_eta_label(eta_label, get_eta_label_data(player))
|
||||
end
|
||||
|
||||
-- Add packs which have been made
|
||||
for _, science_pack in ipairs(config) do
|
||||
update_science_pack(scroll_table, get_science_pack_data(player, science_pack))
|
||||
end
|
||||
|
||||
-- Return the external container
|
||||
return container.parent
|
||||
end)
|
||||
|
||||
--- Add the element to the left flow with a toolbar button
|
||||
Gui.add_left_element(science_info, false)
|
||||
Gui.toolbar.create_button{
|
||||
name = "science_info_toggle",
|
||||
left_element = science_info,
|
||||
sprite = "entity/lab",
|
||||
tooltip = { "science-info.main-tooltip" },
|
||||
visible = function(player, element)
|
||||
return Roles.player_allowed(player, "gui/science-info")
|
||||
end
|
||||
}
|
||||
|
||||
--- Updates the gui every 1 second
|
||||
Event.on_nth_tick(60, function()
|
||||
local force_pack_data = {}
|
||||
local force_eta_data = {}
|
||||
for _, player in pairs(game.connected_players) do
|
||||
local force_name = player.force.name
|
||||
local container = Gui.get_left_element(science_info, player)
|
||||
local frame = container.frame
|
||||
|
||||
-- Update the science packs
|
||||
local scroll_table = frame.scroll.table
|
||||
local pack_data = force_pack_data[force_name]
|
||||
if not pack_data then
|
||||
-- No data in cache so it needs to be generated
|
||||
pack_data = {}
|
||||
force_pack_data[force_name] = pack_data
|
||||
for _, science_pack in ipairs(config) do
|
||||
local next_data = get_science_pack_data(player, science_pack)
|
||||
pack_data[science_pack] = next_data
|
||||
update_science_pack(scroll_table, next_data)
|
||||
end
|
||||
else
|
||||
-- Data found in cache is no need to generate it
|
||||
for _, next_data in pairs(pack_data) do
|
||||
update_science_pack(scroll_table, next_data)
|
||||
end
|
||||
end
|
||||
|
||||
-- Update the eta times
|
||||
if not config.show_eta then return end
|
||||
local eta_label = frame.footer.flow.label
|
||||
local eta_data = force_eta_data[force_name]
|
||||
if not eta_data then
|
||||
-- No data in chache so it needs to be generated
|
||||
eta_data = get_eta_label_data(player)
|
||||
force_eta_data[force_name] = eta_data
|
||||
update_eta_label(eta_label, eta_data)
|
||||
else
|
||||
-- Data found in chache is no need to generate it
|
||||
update_eta_label(eta_label, eta_data)
|
||||
end
|
||||
end
|
||||
end)
|
||||
@@ -1,202 +0,0 @@
|
||||
---- module surveillance
|
||||
-- @gui surveillance
|
||||
|
||||
local Gui = require("modules/exp_gui")
|
||||
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
|
||||
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
||||
|
||||
local cctv_player = Gui.element("cctv_player")
|
||||
:draw(function(def, parent, player_list)
|
||||
return parent.add{
|
||||
name = def.name,
|
||||
type = "drop-down",
|
||||
items = player_list,
|
||||
selected_index = #player_list > 0 and 1 or nil,
|
||||
}
|
||||
end)
|
||||
:style{
|
||||
horizontally_stretchable = true,
|
||||
}
|
||||
|
||||
local cctv_status = Gui.element("cctv_status")
|
||||
:draw{
|
||||
type = "drop-down",
|
||||
items = { { "surveillance.status-enable" }, { "surveillance.status-disable" } },
|
||||
selected_index = 2,
|
||||
}:style{
|
||||
width = 96,
|
||||
}:on_selection_state_changed(function(def, player, element)
|
||||
if element.selected_index == 1 then
|
||||
element.parent.parent.parent.cctv_display.visible = true
|
||||
else
|
||||
element.parent.parent.parent.cctv_display.visible = false
|
||||
end
|
||||
end)
|
||||
|
||||
local cctv_type = Gui.element("cctv_type")
|
||||
:draw{
|
||||
type = "drop-down",
|
||||
name = Gui.property_from_name,
|
||||
items = { { "surveillance.type-player" }, { "surveillance.type-static" }, { "surveillance.type-player-loop" } },
|
||||
selected_index = 1,
|
||||
}:style{
|
||||
width = 96,
|
||||
}
|
||||
|
||||
local cctv_location = Gui.element("cctv_location")
|
||||
:draw{
|
||||
type = "button",
|
||||
name = Gui.property_from_name,
|
||||
caption = { "surveillance.func-set" },
|
||||
}:style{
|
||||
width = 48,
|
||||
}:on_click(function(def, player, element)
|
||||
element.parent.parent.parent.cctv_display.position = player.physical_position
|
||||
end)
|
||||
|
||||
local zoom_in = Gui.element("zoom_in")
|
||||
:draw{
|
||||
type = "button",
|
||||
name = Gui.property_from_name,
|
||||
caption = "+",
|
||||
}:style{
|
||||
width = 32,
|
||||
}:on_click(function(def, player, element)
|
||||
local display = element.parent.parent.parent.cctv_display
|
||||
if display.zoom < 2.0 then
|
||||
display.zoom = display.zoom + 0.05
|
||||
end
|
||||
end)
|
||||
|
||||
local zoom_out = Gui.element("zoom_out")
|
||||
:draw{
|
||||
type = "button",
|
||||
name = Gui.property_from_name,
|
||||
caption = "-",
|
||||
}:style{
|
||||
width = 32,
|
||||
}:on_click(function(def, player, element)
|
||||
local display = element.parent.parent.parent.cctv_display
|
||||
if display.zoom > 0.2 then
|
||||
display.zoom = display.zoom - 0.05
|
||||
end
|
||||
end)
|
||||
|
||||
local camera_set = Gui.element("camera_set")
|
||||
:draw(function(_, parent, name, player_list)
|
||||
local camera_set = parent.add{ type = "flow", direction = "vertical", name = name }
|
||||
local buttons = Gui.elements.scroll_table(camera_set, 480, 6, "buttons")
|
||||
|
||||
cctv_player(buttons, player_list)
|
||||
cctv_status(buttons)
|
||||
cctv_type(buttons)
|
||||
cctv_location(buttons)
|
||||
zoom_out(buttons)
|
||||
zoom_in(buttons)
|
||||
|
||||
local camera = camera_set.add{
|
||||
type = "camera",
|
||||
name = "cctv_display",
|
||||
position = { x = 0, y = 0 },
|
||||
surface_index = game.surfaces["nauvis"].index,
|
||||
zoom = 0.75,
|
||||
}
|
||||
|
||||
camera.visible = false
|
||||
camera.style.minimal_width = 480
|
||||
camera.style.minimal_height = 290
|
||||
return camera_set
|
||||
end)
|
||||
|
||||
local cctv_container = Gui.element("cctv_container")
|
||||
:draw(function(def, parent)
|
||||
local container = Gui.elements.container(parent, 480)
|
||||
local scroll = container.add{ name = "scroll", type = "scroll-pane", direction = "vertical" }
|
||||
scroll.style.maximal_height = 704
|
||||
local player_list = {}
|
||||
|
||||
for _, player in pairs(game.connected_players) do
|
||||
table.insert(player_list, player.name)
|
||||
end
|
||||
|
||||
camera_set(scroll, "cctv_st_1", player_list)
|
||||
camera_set(scroll, "cctv_st_2", player_list)
|
||||
|
||||
return container.parent
|
||||
end)
|
||||
|
||||
--- Add the element to the left flow with a toolbar button
|
||||
Gui.add_left_element(cctv_container, false)
|
||||
Gui.toolbar.create_button{
|
||||
name = "cctv_toggle",
|
||||
left_element = cctv_container,
|
||||
sprite = "entity/radar",
|
||||
tooltip = { "surveillance.main-tooltip" },
|
||||
visible = function(player, element)
|
||||
return Roles.player_allowed(player, "gui/surveillance")
|
||||
end
|
||||
}
|
||||
|
||||
local function gui_update()
|
||||
local player_list = {}
|
||||
|
||||
for _, player in pairs(game.connected_players) do
|
||||
table.insert(player_list, player.name)
|
||||
end
|
||||
|
||||
for _, player in pairs(game.connected_players) do
|
||||
local container = Gui.get_left_element(cctv_container, player)
|
||||
container.frame.scroll["cctv_st_1"].buttons.table[cctv_player.name].items = player_list
|
||||
container.frame.scroll["cctv_st_2"].buttons.table[cctv_player.name].items = player_list
|
||||
end
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_player_joined_game, gui_update)
|
||||
Event.add(defines.events.on_player_left_game, gui_update)
|
||||
|
||||
Event.add(defines.events.on_tick, function(_)
|
||||
for _, player in pairs(game.connected_players) do
|
||||
local container = Gui.get_left_element(cctv_container, player)
|
||||
|
||||
for i = 1, 2 do
|
||||
local scroll_table_name = "cctv_st_" .. i
|
||||
local current_camera_set = container.frame.scroll[scroll_table_name]
|
||||
local switch_index = current_camera_set.buttons.table[cctv_type.name].selected_index
|
||||
|
||||
if (switch_index == 1) or (switch_index == 3) then
|
||||
local selected_index = current_camera_set.buttons.table[cctv_player.name].selected_index
|
||||
|
||||
if selected_index ~= 0 then
|
||||
selected_index = current_camera_set.buttons.table[cctv_player.name].items[selected_index] --[[ @as number ]]
|
||||
current_camera_set["cctv_display"].position = game.players[selected_index].physical_position
|
||||
current_camera_set["cctv_display"].surface_index = game.players[selected_index].surface_index
|
||||
else
|
||||
current_camera_set["cctv_display"].position = { x = 0, y = 0 }
|
||||
current_camera_set["cctv_display"].surface_index = game.surfaces["nauvis"].index
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
Event.on_nth_tick(600, function(_)
|
||||
for _, player in pairs(game.connected_players) do
|
||||
local container = Gui.get_left_element(cctv_container, player)
|
||||
|
||||
for i = 1, 2 do
|
||||
local current_camera_set = container.frame.scroll["cctv_st_" .. i]
|
||||
|
||||
if current_camera_set.buttons.table[cctv_type.name].selected_index == 3 then
|
||||
local item_n = #current_camera_set.buttons.table[cctv_player.name].items
|
||||
|
||||
if item_n ~= 0 then
|
||||
if current_camera_set.buttons.table[cctv_player.name].selected_index < item_n then
|
||||
current_camera_set.buttons.table[cctv_player.name].selected_index = current_camera_set.buttons.table[cctv_player.name].selected_index + 1
|
||||
else
|
||||
current_camera_set.buttons.table[cctv_player.name].selected_index = 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
@@ -83,13 +83,13 @@ end
|
||||
|
||||
--- Button displayed in the header bar, used to add a new task
|
||||
-- @element add_new_task
|
||||
local add_new_task = Gui.element("add_new_task")
|
||||
local add_new_task = Gui.define("add_new_task")
|
||||
:draw{
|
||||
type = "sprite-button",
|
||||
sprite = "utility/add",
|
||||
tooltip = { "task-list.add-tooltip" },
|
||||
style = "tool_button",
|
||||
name = Gui.property_from_name,
|
||||
name = Gui.from_name,
|
||||
}
|
||||
:style(Styles.sprite22)
|
||||
:on_click(
|
||||
@@ -105,7 +105,7 @@ local add_new_task = Gui.element("add_new_task")
|
||||
|
||||
--- Header displayed when no tasks are in the task list
|
||||
-- @element no_tasks_found
|
||||
local no_tasks_found = Gui.element("no_tasks_found")
|
||||
local no_tasks_found = Gui.define("no_tasks_found")
|
||||
:draw(
|
||||
function(_, parent)
|
||||
local header =
|
||||
@@ -137,10 +137,10 @@ local no_tasks_found = Gui.element("no_tasks_found")
|
||||
|
||||
--- Frame element with the right styling
|
||||
-- @element subfooter_frame
|
||||
local subfooter_frame = Gui.element("task_list_subfooter_frame")
|
||||
local subfooter_frame = Gui.define("task_list_subfooter_frame")
|
||||
:draw{
|
||||
type = "frame",
|
||||
name = Gui.property_from_arg(1),
|
||||
name = Gui.from_argument(1),
|
||||
direction = "vertical",
|
||||
style = "subfooter_frame",
|
||||
}
|
||||
@@ -153,17 +153,17 @@ local subfooter_frame = Gui.element("task_list_subfooter_frame")
|
||||
|
||||
--- Label element preset
|
||||
-- @element subfooter_label
|
||||
local subfooter_label = Gui.element("task_list_subfooter_label")
|
||||
local subfooter_label = Gui.define("task_list_subfooter_label")
|
||||
:draw{
|
||||
name = "footer_label",
|
||||
type = "label",
|
||||
style = "frame_title",
|
||||
caption = Gui.property_from_arg(1),
|
||||
caption = Gui.from_argument(1),
|
||||
}
|
||||
|
||||
--- Action flow that contains action buttons
|
||||
-- @element subfooter_actions
|
||||
local subfooter_actions = Gui.element("task_list_subfooter_actions")
|
||||
local subfooter_actions = Gui.define("task_list_subfooter_actions")
|
||||
:draw{
|
||||
type = "flow",
|
||||
name = "actions",
|
||||
@@ -171,7 +171,7 @@ local subfooter_actions = Gui.element("task_list_subfooter_actions")
|
||||
|
||||
--- Button element with a flow around it to fix duplicate name inside of the scroll flow
|
||||
-- @element task_list_item
|
||||
local task_list_item = Gui.element("task_list_item")
|
||||
local task_list_item = Gui.define("task_list_item")
|
||||
:draw(
|
||||
function(def, parent, task)
|
||||
local flow = parent.add{
|
||||
@@ -205,7 +205,7 @@ local task_list_item = Gui.element("task_list_item")
|
||||
|
||||
--- Scrollable list of all tasks
|
||||
-- @element task_list
|
||||
local task_list = Gui.element("task_list")
|
||||
local task_list = Gui.define("task_list")
|
||||
:draw(
|
||||
function(_, parent)
|
||||
local scroll_pane =
|
||||
@@ -236,10 +236,10 @@ local task_list = Gui.element("task_list")
|
||||
|
||||
--- Button element inside the task view footer to start editing a task
|
||||
-- @element task_view_edit_button
|
||||
local task_view_edit_button = Gui.element("task_view_edit_button")
|
||||
local task_view_edit_button = Gui.define("task_view_edit_button")
|
||||
:draw{
|
||||
type = "button",
|
||||
name = Gui.property_from_name,
|
||||
name = Gui.from_name,
|
||||
caption = { "", "[img=utility/rename_icon] ", { "task-list.edit" } },
|
||||
tooltip = { "task-list.edit-tooltip" },
|
||||
style = "shortcut_bar_button",
|
||||
@@ -254,7 +254,7 @@ local task_view_edit_button = Gui.element("task_view_edit_button")
|
||||
|
||||
--- Button to close the task view footer
|
||||
-- @element task_view_close_button
|
||||
local task_view_close_button = Gui.element("task_view_close_button")
|
||||
local task_view_close_button = Gui.define("task_view_close_button")
|
||||
:draw{
|
||||
type = "sprite-button",
|
||||
sprite = "utility/collapse",
|
||||
@@ -270,10 +270,10 @@ local task_view_close_button = Gui.element("task_view_close_button")
|
||||
|
||||
--- Button to delete the task inside the task view footer
|
||||
-- @element task_view_delete_button
|
||||
local task_view_delete_button = Gui.element("task_view_delete_button")
|
||||
local task_view_delete_button = Gui.define("task_view_delete_button")
|
||||
:draw{
|
||||
type = "button",
|
||||
name = Gui.property_from_name,
|
||||
name = Gui.from_name,
|
||||
caption = { "", "[img=utility/trash] ", { "task-list.delete" } },
|
||||
tooltip = { "task-list.delete-tooltip" },
|
||||
style = "shortcut_bar_button_red",
|
||||
@@ -289,7 +289,7 @@ local task_view_delete_button = Gui.element("task_view_delete_button")
|
||||
|
||||
--- Subfooter inside the tasklist container that holds all the elements for viewing a task
|
||||
-- @element task_view_footer
|
||||
local task_view_footer = Gui.element("task_view_footer")
|
||||
local task_view_footer = Gui.define("task_view_footer")
|
||||
:draw(
|
||||
function(_, parent)
|
||||
local footer = subfooter_frame(parent, "view")
|
||||
@@ -345,9 +345,9 @@ local task_create_confirm_button
|
||||
|
||||
--- Textfield element used in both the task create and edit footers
|
||||
-- @element task_message_textfield
|
||||
local task_message_textfield = Gui.element("task_message_textfield")
|
||||
local task_message_textfield = Gui.define("task_message_textfield")
|
||||
:draw{
|
||||
name = Gui.property_from_name,
|
||||
name = Gui.from_name,
|
||||
type = "text-box",
|
||||
text = "",
|
||||
}:style{
|
||||
@@ -372,10 +372,10 @@ local task_message_textfield = Gui.element("task_message_textfield")
|
||||
|
||||
--- Button to confirm the changes inside the task edit footer
|
||||
-- @element task_edit_confirm_button
|
||||
task_edit_confirm_button = Gui.element("task_edit_confirm_button")
|
||||
task_edit_confirm_button = Gui.define("task_edit_confirm_button")
|
||||
:draw{
|
||||
type = "button",
|
||||
name = Gui.property_from_name,
|
||||
name = Gui.from_name,
|
||||
caption = { "", "[img=utility/check_mark] ", { "task-list.confirm" } },
|
||||
tooltip = { "task-list.confirm-tooltip" },
|
||||
style = "shortcut_bar_button_green",
|
||||
@@ -394,7 +394,7 @@ task_edit_confirm_button = Gui.element("task_edit_confirm_button")
|
||||
|
||||
--- Button to discard the changes inside the task edit footer
|
||||
-- @element edit_task_discard_button
|
||||
local edit_task_discard_button = Gui.element("edit_task_discard_button")
|
||||
local edit_task_discard_button = Gui.define("edit_task_discard_button")
|
||||
:draw{
|
||||
type = "button",
|
||||
caption = { "", "[img=utility/close_black] ", { "task-list.discard" } },
|
||||
@@ -412,7 +412,7 @@ local edit_task_discard_button = Gui.element("edit_task_discard_button")
|
||||
|
||||
--- Subfooter inside the tasklist container that holds all the elements for editing a task
|
||||
-- @element task_edit_footer
|
||||
local task_edit_footer = Gui.element("task_edit_footer")
|
||||
local task_edit_footer = Gui.define("task_edit_footer")
|
||||
:draw(
|
||||
function(_, parent)
|
||||
local footer = subfooter_frame(parent, "edit")
|
||||
@@ -431,10 +431,10 @@ local task_edit_footer = Gui.element("task_edit_footer")
|
||||
|
||||
--- Button to confirm the changes inside the task create footer
|
||||
-- @element task_create_confirm_button
|
||||
task_create_confirm_button = Gui.element("task_create_confirm_button")
|
||||
task_create_confirm_button = Gui.define("task_create_confirm_button")
|
||||
:draw{
|
||||
type = "button",
|
||||
name = Gui.property_from_name,
|
||||
name = Gui.from_name,
|
||||
caption = { "", "[img=utility/check_mark] ", { "task-list.confirm" } },
|
||||
tooltip = { "task-list.confirm-tooltip" },
|
||||
style = "shortcut_bar_button_green",
|
||||
@@ -453,7 +453,7 @@ task_create_confirm_button = Gui.element("task_create_confirm_button")
|
||||
|
||||
--- Button to discard the changes inside the task create footer
|
||||
-- @element task_create_discard_button
|
||||
local task_create_discard_button = Gui.element("task_create_discard_button")
|
||||
local task_create_discard_button = Gui.define("task_create_discard_button")
|
||||
:draw{
|
||||
type = "button",
|
||||
caption = { "", "[img=utility/close_black] ", { "task-list.discard" } },
|
||||
@@ -469,7 +469,7 @@ local task_create_discard_button = Gui.element("task_create_discard_button")
|
||||
|
||||
--- Subfooter inside the tasklist container that holds all the elements to create a new task
|
||||
-- @element task_create_footer
|
||||
local task_create_footer = Gui.element("task_create_footer")
|
||||
local task_create_footer = Gui.define("task_create_footer")
|
||||
:draw(
|
||||
function(_, parent)
|
||||
local footer = subfooter_frame(parent, "create")
|
||||
@@ -505,7 +505,7 @@ end
|
||||
|
||||
--- Main task list container for the left flow
|
||||
-- @element task_list_container
|
||||
local task_list_container = Gui.element("task_list_container")
|
||||
local task_list_container = Gui.define("task_list_container")
|
||||
:draw(
|
||||
function(def, parent)
|
||||
-- Draw the internal container
|
||||
@@ -762,7 +762,7 @@ local function role_update_event(event)
|
||||
|
||||
-- Update the new task button and create footer in case the user can now add them
|
||||
local has_permission = check_player_permissions(player)
|
||||
local add_new_task_element = frame.header.flow[add_new_task.name]
|
||||
local add_new_task_element = frame.header[add_new_task.name]
|
||||
add_new_task_element.visible = has_permission
|
||||
local is_creating = PlayerIsCreating:get(player)
|
||||
if is_creating and not has_permission then
|
||||
|
||||
@@ -1,272 +0,0 @@
|
||||
--[[-- Gui Module - Tool
|
||||
@gui Tool
|
||||
@alias tool_container
|
||||
]]
|
||||
|
||||
local ExpUtil = require("modules/exp_util")
|
||||
local Gui = require("modules/exp_gui")
|
||||
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
|
||||
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 addon_train = require("modules/exp_scenario/commands/trains")
|
||||
local addon_research = require("modules/exp_scenario/commands/research")
|
||||
|
||||
local tool_container
|
||||
|
||||
local SelectionArtyArea = "ExpCommand_Artillery"
|
||||
local SelectionWaterfillArea = "ExpCommand_Waterfill"
|
||||
|
||||
local style = {
|
||||
label = {
|
||||
width = 160
|
||||
},
|
||||
button = {
|
||||
width = 80
|
||||
}
|
||||
}
|
||||
|
||||
--- Arty label
|
||||
-- @element tool_gui_arty_l
|
||||
local tool_gui_arty_l = Gui.element("tool_gui_arty_l")
|
||||
:draw{
|
||||
type = "label",
|
||||
name = Gui.property_from_name,
|
||||
caption = { "tool.artillery" },
|
||||
tooltip = { "tool.artillery-tooltip" },
|
||||
style = "heading_2_label"
|
||||
}:style(
|
||||
style.label
|
||||
)
|
||||
|
||||
--- Arty button
|
||||
-- @element tool_gui_arty_b
|
||||
local tool_gui_arty_b = Gui.element("tool_gui_arty_b")
|
||||
:draw{
|
||||
type = "button",
|
||||
name = Gui.property_from_name,
|
||||
caption = { "tool.apply" }
|
||||
}:style(
|
||||
style.button
|
||||
):on_click(function(def, player, element)
|
||||
if Selection.is_selecting(player, SelectionArtyArea) then
|
||||
Selection.stop(player)
|
||||
player.print{ "exp-commands_artillery.exit" }
|
||||
|
||||
else
|
||||
Selection.start(player, SelectionArtyArea)
|
||||
player.print{ "exp-commands_artillery.enter" }
|
||||
end
|
||||
end)
|
||||
|
||||
--- Waterfill label
|
||||
-- @element tool_gui_waterfill_l
|
||||
local tool_gui_waterfill_l = Gui.element("tool_gui_waterfill_l")
|
||||
:draw{
|
||||
type = "label",
|
||||
name = Gui.property_from_name,
|
||||
caption = { "tool.waterfill" },
|
||||
tooltip = { "tool.waterfill-tooltip" },
|
||||
style = "heading_2_label"
|
||||
}:style(
|
||||
style.label
|
||||
)
|
||||
|
||||
--- Waterfill button
|
||||
-- @element tool_gui_waterfill_b
|
||||
local tool_gui_waterfill_b = Gui.element("tool_gui_waterfill_b")
|
||||
:draw{
|
||||
type = "button",
|
||||
name = Gui.property_from_name,
|
||||
caption = { "tool.apply" }
|
||||
}:style(
|
||||
style.button
|
||||
):on_click(function(def, player, element)
|
||||
if Selection.is_selecting(player, SelectionWaterfillArea) then
|
||||
Selection.stop(player)
|
||||
return player.print{ "exp-commands_waterfill.exit" }
|
||||
else
|
||||
local item_count_cliff = player.get_item_count("cliff-explosives")
|
||||
local item_count_craft = math.min(math.floor(player.get_item_count("explosives") / 10), player.get_item_count("barrel"), player.get_item_count("grenade"))
|
||||
local item_count_total = item_count_cliff + item_count_craft
|
||||
if item_count_total == 0 then
|
||||
return player.print{ "exp-commands_waterfill.requires-explosives" }
|
||||
else
|
||||
Selection.start(player, SelectionWaterfillArea)
|
||||
return player.print{ "exp-commands_waterfill.enter" }
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
--- Train label
|
||||
-- @element tool_gui_train_l
|
||||
local tool_gui_train_l = Gui.element("tool_gui_train_l")
|
||||
:draw{
|
||||
type = "label",
|
||||
name = Gui.property_from_name,
|
||||
caption = { "tool.train" },
|
||||
tooltip = { "tool.train-tooltip" },
|
||||
style = "heading_2_label"
|
||||
}:style(
|
||||
style.label
|
||||
)
|
||||
|
||||
--- Train button
|
||||
-- @element tool_gui_train_b
|
||||
local tool_gui_train_b = Gui.element("tool_gui_train_b")
|
||||
:draw{
|
||||
type = "button",
|
||||
name = Gui.property_from_name,
|
||||
caption = { "tool.apply" }
|
||||
}:style(
|
||||
style.button
|
||||
):on_click(function(def, player, element)
|
||||
addon_train.manual(player)
|
||||
end)
|
||||
|
||||
--- Research label
|
||||
-- @element tool_gui_research_l
|
||||
local tool_gui_research_l = Gui.element("tool_gui_research_l")
|
||||
:draw{
|
||||
type = "label",
|
||||
name = Gui.property_from_name,
|
||||
caption = { "tool.research" },
|
||||
tooltip = { "tool.research-tooltip" },
|
||||
style = "heading_2_label"
|
||||
}:style(
|
||||
style.label
|
||||
)
|
||||
|
||||
--- Research button
|
||||
-- @element tool_gui_research_b
|
||||
local tool_gui_research_b = Gui.element("tool_gui_research_b")
|
||||
:draw{
|
||||
type = "button",
|
||||
name = Gui.property_from_name,
|
||||
caption = { "tool.apply" }
|
||||
}:style(
|
||||
style.button
|
||||
):on_click(function(def, player, element)
|
||||
local enabled = addon_research.set_auto_research()
|
||||
|
||||
if enabled then
|
||||
addon_research.res_queue(player.force --[[ @as LuaForce ]], true)
|
||||
end
|
||||
|
||||
local player_name = ExpUtil.format_player_name_locale(player)
|
||||
game.print{ "exp-commands_research.auto-research", player_name, enabled }
|
||||
end)
|
||||
|
||||
--- Spawn label
|
||||
-- @element tool_gui_spawn_l
|
||||
local tool_gui_spawn_l = Gui.element("tool_gui_spawn_l")
|
||||
:draw{
|
||||
type = "label",
|
||||
name = Gui.property_from_name,
|
||||
caption = { "tool.spawn" },
|
||||
tooltip = { "tool.spawn-tooltip" },
|
||||
style = "heading_2_label"
|
||||
}:style(
|
||||
style.label
|
||||
)
|
||||
|
||||
--- Spawn button
|
||||
-- @element tool_gui_spawn_b
|
||||
local tool_gui_spawn_b = Gui.element("tool_gui_spawn_b")
|
||||
:draw{
|
||||
type = "button",
|
||||
name = Gui.property_from_name,
|
||||
caption = { "tool.apply" }
|
||||
}:style(
|
||||
style.button
|
||||
):on_click(function(def, player, element)
|
||||
if not player.character
|
||||
or player.character.health <= 0
|
||||
or not ExpUtil.teleport_player(player, game.surfaces.nauvis, { 0, 0 }, "dismount") then
|
||||
return player.print{ "exp-commands_teleport.unavailable" }
|
||||
end
|
||||
end)
|
||||
|
||||
local function tool_perm(player, container)
|
||||
container = container or Gui.get_left_element(tool_container, player)
|
||||
local disp = container.frame.tool_st.disp.table
|
||||
local allowed
|
||||
|
||||
allowed = Roles.player_allowed(player, "command/artillery")
|
||||
disp[tool_gui_arty_l.name].visible = allowed
|
||||
disp[tool_gui_arty_b.name].visible = allowed
|
||||
|
||||
allowed = Roles.player_allowed(player, "command/waterfill")
|
||||
disp[tool_gui_waterfill_l.name].visible = allowed
|
||||
disp[tool_gui_waterfill_b.name].visible = allowed
|
||||
|
||||
allowed = Roles.player_allowed(player, "command/set-trains-to-automatic")
|
||||
disp[tool_gui_train_l.name].visible = allowed
|
||||
disp[tool_gui_train_b.name].visible = allowed
|
||||
|
||||
allowed = Roles.player_allowed(player, "command/set-auto-research")
|
||||
disp[tool_gui_research_l.name].visible = allowed
|
||||
disp[tool_gui_research_b.name].visible = allowed
|
||||
|
||||
allowed = Roles.player_allowed(player, "command/spawn")
|
||||
disp[tool_gui_spawn_l.name].visible = allowed
|
||||
disp[tool_gui_spawn_b.name].visible = allowed
|
||||
end
|
||||
|
||||
--- A vertical flow containing all the tool
|
||||
-- @element tool_set
|
||||
local tool_set = Gui.element("tool_set")
|
||||
:draw(function(_, parent, name)
|
||||
local tool_set = parent.add{ type = "flow", direction = "vertical", name = name }
|
||||
local disp = Gui.elements.scroll_table(tool_set, 240, 2, "disp")
|
||||
|
||||
tool_gui_arty_l(disp)
|
||||
tool_gui_arty_b(disp)
|
||||
|
||||
tool_gui_waterfill_l(disp)
|
||||
tool_gui_waterfill_b(disp)
|
||||
|
||||
tool_gui_train_l(disp)
|
||||
tool_gui_train_b(disp)
|
||||
|
||||
tool_gui_research_l(disp)
|
||||
tool_gui_research_b(disp)
|
||||
|
||||
tool_gui_spawn_l(disp)
|
||||
tool_gui_spawn_b(disp)
|
||||
|
||||
return tool_set
|
||||
end)
|
||||
|
||||
--- The main container for the tool gui
|
||||
-- @element tool_container
|
||||
tool_container = Gui.element("tool_container")
|
||||
:draw(function(def, parent)
|
||||
local player = Gui.get_player(parent)
|
||||
local container = Gui.elements.container(parent, 240)
|
||||
|
||||
tool_set(container, "tool_st")
|
||||
|
||||
tool_perm(player, container.parent)
|
||||
|
||||
return container.parent
|
||||
end)
|
||||
|
||||
--- Add the element to the left flow with a toolbar button
|
||||
Gui.add_left_element(tool_container, false)
|
||||
Gui.toolbar.create_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")
|
||||
end
|
||||
}
|
||||
|
||||
Event.add(Roles.events.on_role_assigned, function(event)
|
||||
tool_perm(game.players[event.player_index])
|
||||
end)
|
||||
|
||||
Event.add(Roles.events.on_role_unassigned, function(event)
|
||||
tool_perm(game.players[event.player_index])
|
||||
end)
|
||||
@@ -143,20 +143,20 @@ end)
|
||||
|
||||
--- Display label for the number of solar panels
|
||||
-- @element vlayer_gui_display_item_solar_name
|
||||
local vlayer_gui_display_item_solar_name = Gui.element("vlayer_gui_display_item_solar_name")
|
||||
local vlayer_gui_display_item_solar_name = Gui.define("vlayer_gui_display_item_solar_name")
|
||||
:draw{
|
||||
type = "label",
|
||||
name = Gui.property_from_name,
|
||||
name = Gui.from_name,
|
||||
caption = { "vlayer.display-item-solar" },
|
||||
style = "heading_2_label",
|
||||
}:style{
|
||||
width = 200,
|
||||
}
|
||||
|
||||
local vlayer_gui_display_item_solar_count = Gui.element("vlayer_gui_display_item_solar_count")
|
||||
local vlayer_gui_display_item_solar_count = Gui.define("vlayer_gui_display_item_solar_count")
|
||||
:draw{
|
||||
type = "progressbar",
|
||||
name = Gui.property_from_name,
|
||||
name = Gui.from_name,
|
||||
caption = "",
|
||||
value = 0,
|
||||
style = "electric_satisfaction_statistics_progressbar",
|
||||
@@ -167,20 +167,20 @@ local vlayer_gui_display_item_solar_count = Gui.element("vlayer_gui_display_item
|
||||
|
||||
--- Display label for the number of accumulators
|
||||
-- @element vlayer_gui_display_item_accumulator_name
|
||||
local vlayer_gui_display_item_accumulator_name = Gui.element("vlayer_gui_display_item_accumulator_name")
|
||||
local vlayer_gui_display_item_accumulator_name = Gui.define("vlayer_gui_display_item_accumulator_name")
|
||||
:draw{
|
||||
type = "label",
|
||||
name = Gui.property_from_name,
|
||||
name = Gui.from_name,
|
||||
caption = { "vlayer.display-item-accumulator" },
|
||||
style = "heading_2_label",
|
||||
}:style{
|
||||
width = 200,
|
||||
}
|
||||
|
||||
local vlayer_gui_display_item_accumulator_count = Gui.element("vlayer_gui_display_item_accumulator_count")
|
||||
local vlayer_gui_display_item_accumulator_count = Gui.define("vlayer_gui_display_item_accumulator_count")
|
||||
:draw{
|
||||
type = "progressbar",
|
||||
name = Gui.property_from_name,
|
||||
name = Gui.from_name,
|
||||
caption = "",
|
||||
value = 0,
|
||||
style = "electric_satisfaction_statistics_progressbar",
|
||||
@@ -191,10 +191,10 @@ local vlayer_gui_display_item_accumulator_count = Gui.element("vlayer_gui_displa
|
||||
|
||||
--- Display label for the surface area
|
||||
-- @element vlayer_gui_display_signal_surface_area_name
|
||||
local vlayer_gui_display_signal_surface_area_name = Gui.element("vlayer_gui_display_signal_surface_area_name")
|
||||
local vlayer_gui_display_signal_surface_area_name = Gui.define("vlayer_gui_display_signal_surface_area_name")
|
||||
:draw{
|
||||
type = "label",
|
||||
name = Gui.property_from_name,
|
||||
name = Gui.from_name,
|
||||
caption = { "vlayer.display-remaining-surface-area" },
|
||||
tooltip = { "vlayer.display-remaining-surface-area-tooltip" },
|
||||
style = "heading_2_label",
|
||||
@@ -202,10 +202,10 @@ local vlayer_gui_display_signal_surface_area_name = Gui.element("vlayer_gui_disp
|
||||
width = 200,
|
||||
}
|
||||
|
||||
local vlayer_gui_display_signal_surface_area_count = Gui.element("vlayer_gui_display_signal_surface_area_count")
|
||||
local vlayer_gui_display_signal_surface_area_count = Gui.define("vlayer_gui_display_signal_surface_area_count")
|
||||
:draw{
|
||||
type = "progressbar",
|
||||
name = Gui.property_from_name,
|
||||
name = Gui.from_name,
|
||||
caption = "",
|
||||
value = 0,
|
||||
style = "electric_satisfaction_statistics_progressbar",
|
||||
@@ -216,10 +216,10 @@ local vlayer_gui_display_signal_surface_area_count = Gui.element("vlayer_gui_dis
|
||||
|
||||
--- Display label for the sustained energy production
|
||||
-- @element vlayer_gui_display_signal_sustained_name
|
||||
local vlayer_gui_display_signal_sustained_name = Gui.element("vlayer_gui_display_signal_sustained_name")
|
||||
local vlayer_gui_display_signal_sustained_name = Gui.define("vlayer_gui_display_signal_sustained_name")
|
||||
:draw{
|
||||
type = "label",
|
||||
name = Gui.property_from_name,
|
||||
name = Gui.from_name,
|
||||
caption = { "vlayer.display-sustained-production" },
|
||||
tooltip = { "vlayer.display-sustained-production-tooltip" },
|
||||
style = "heading_2_label",
|
||||
@@ -227,10 +227,10 @@ local vlayer_gui_display_signal_sustained_name = Gui.element("vlayer_gui_display
|
||||
width = 200,
|
||||
}
|
||||
|
||||
local vlayer_gui_display_signal_sustained_count = Gui.element("vlayer_gui_display_signal_sustained_count")
|
||||
local vlayer_gui_display_signal_sustained_count = Gui.define("vlayer_gui_display_signal_sustained_count")
|
||||
:draw{
|
||||
type = "progressbar",
|
||||
name = Gui.property_from_name,
|
||||
name = Gui.from_name,
|
||||
caption = "",
|
||||
value = 0,
|
||||
style = "electric_satisfaction_statistics_progressbar",
|
||||
@@ -241,10 +241,10 @@ local vlayer_gui_display_signal_sustained_count = Gui.element("vlayer_gui_displa
|
||||
|
||||
--- Display label for the current energy production
|
||||
-- @element vlayer_gui_display_signal_production_name
|
||||
local vlayer_gui_display_signal_production_name = Gui.element("vlayer_gui_display_signal_production_name")
|
||||
local vlayer_gui_display_signal_production_name = Gui.define("vlayer_gui_display_signal_production_name")
|
||||
:draw{
|
||||
type = "label",
|
||||
name = Gui.property_from_name,
|
||||
name = Gui.from_name,
|
||||
caption = { "vlayer.display-current-production" },
|
||||
tooltip = { "vlayer.display-current-production-tooltip" },
|
||||
style = "heading_2_label",
|
||||
@@ -252,10 +252,10 @@ local vlayer_gui_display_signal_production_name = Gui.element("vlayer_gui_displa
|
||||
width = 200,
|
||||
}
|
||||
|
||||
local vlayer_gui_display_signal_production_count = Gui.element("vlayer_gui_display_signal_production_count")
|
||||
local vlayer_gui_display_signal_production_count = Gui.define("vlayer_gui_display_signal_production_count")
|
||||
:draw{
|
||||
type = "progressbar",
|
||||
name = Gui.property_from_name,
|
||||
name = Gui.from_name,
|
||||
caption = "",
|
||||
value = 0,
|
||||
style = "electric_satisfaction_statistics_progressbar",
|
||||
@@ -266,10 +266,10 @@ local vlayer_gui_display_signal_production_count = Gui.element("vlayer_gui_displ
|
||||
|
||||
--- Display label for the sustained energy capacity
|
||||
-- @element vlayer_gui_display_signal_capacity_name
|
||||
local vlayer_gui_display_signal_capacity_name = Gui.element("vlayer_gui_display_signal_capacity_name")
|
||||
local vlayer_gui_display_signal_capacity_name = Gui.define("vlayer_gui_display_signal_capacity_name")
|
||||
:draw{
|
||||
type = "label",
|
||||
name = Gui.property_from_name,
|
||||
name = Gui.from_name,
|
||||
caption = { "vlayer.display-current-capacity" },
|
||||
tooltip = { "vlayer.display-current-capacity-tooltip" },
|
||||
style = "heading_2_label",
|
||||
@@ -277,10 +277,10 @@ local vlayer_gui_display_signal_capacity_name = Gui.element("vlayer_gui_display_
|
||||
width = 200,
|
||||
}
|
||||
|
||||
local vlayer_gui_display_signal_capacity_count = Gui.element("vlayer_gui_display_signal_capacity_count")
|
||||
local vlayer_gui_display_signal_capacity_count = Gui.define("vlayer_gui_display_signal_capacity_count")
|
||||
:draw{
|
||||
type = "progressbar",
|
||||
name = Gui.property_from_name,
|
||||
name = Gui.from_name,
|
||||
caption = "",
|
||||
value = 0,
|
||||
style = "electric_satisfaction_statistics_progressbar",
|
||||
@@ -291,7 +291,7 @@ local vlayer_gui_display_signal_capacity_count = Gui.element("vlayer_gui_display
|
||||
|
||||
--- A vertical flow containing all the displays labels and their counts
|
||||
-- @element vlayer_display_set
|
||||
local vlayer_display_set = Gui.element("vlayer_display_set")
|
||||
local vlayer_display_set = Gui.define("vlayer_display_set")
|
||||
:draw(function(_, parent, name)
|
||||
local vlayer_set = parent.add{ type = "flow", direction = "vertical", name = name }
|
||||
local disp = Gui.elements.scroll_table(vlayer_set, 400, 2, "disp")
|
||||
@@ -331,10 +331,10 @@ end
|
||||
|
||||
--- A drop down list filter by this type
|
||||
-- @element vlayer_gui_control_type
|
||||
vlayer_gui_control_type = Gui.element("vlayer_gui_control_type")
|
||||
vlayer_gui_control_type = Gui.define("vlayer_gui_control_type")
|
||||
:draw{
|
||||
type = "drop-down",
|
||||
name = Gui.property_from_name,
|
||||
name = Gui.from_name,
|
||||
items = { { "vlayer.control-type-energy" }, { "vlayer.control-type-circuit" }, { "vlayer.control-type-storage-input" }, { "vlayer.control-type-storage-output" } },
|
||||
selected_index = 1,
|
||||
}:style{
|
||||
@@ -345,20 +345,20 @@ vlayer_gui_control_type = Gui.element("vlayer_gui_control_type")
|
||||
|
||||
--- A drop down list to see the exact item to remove
|
||||
-- @element vlayer_gui_control_list
|
||||
vlayer_gui_control_list = Gui.element("vlayer_gui_control_list")
|
||||
vlayer_gui_control_list = Gui.define("vlayer_gui_control_list")
|
||||
:draw{
|
||||
type = "drop-down",
|
||||
name = Gui.property_from_name,
|
||||
name = Gui.from_name,
|
||||
}:style{
|
||||
width = 200,
|
||||
}
|
||||
|
||||
--- A button to refresh the remove list
|
||||
-- @element vlayer_gui_control_refresh
|
||||
local vlayer_gui_control_refresh = Gui.element("vlayer_gui_control_refresh")
|
||||
local vlayer_gui_control_refresh = Gui.define("vlayer_gui_control_refresh")
|
||||
:draw{
|
||||
type = "button",
|
||||
name = Gui.property_from_name,
|
||||
name = Gui.from_name,
|
||||
caption = { "vlayer.control-refresh" },
|
||||
}:style{
|
||||
width = 200,
|
||||
@@ -368,10 +368,10 @@ local vlayer_gui_control_refresh = Gui.element("vlayer_gui_control_refresh")
|
||||
|
||||
--- A button to check if the item is the one wanted to remove
|
||||
-- @element vlayer_gui_control_see
|
||||
local vlayer_gui_control_see = Gui.element("vlayer_gui_control_see")
|
||||
local vlayer_gui_control_see = Gui.define("vlayer_gui_control_see")
|
||||
:draw{
|
||||
type = "button",
|
||||
name = Gui.property_from_name,
|
||||
name = Gui.from_name,
|
||||
caption = { "vlayer.control-see" },
|
||||
}:style{
|
||||
width = 200,
|
||||
@@ -392,10 +392,10 @@ local vlayer_gui_control_see = Gui.element("vlayer_gui_control_see")
|
||||
|
||||
--- A button used to build the vlayer interface
|
||||
-- @element vlayer_gui_control_build
|
||||
local vlayer_gui_control_build = Gui.element("vlayer_gui_control_build")
|
||||
local vlayer_gui_control_build = Gui.define("vlayer_gui_control_build")
|
||||
:draw{
|
||||
type = "button",
|
||||
name = Gui.property_from_name,
|
||||
name = Gui.from_name,
|
||||
caption = { "vlayer.control-build" },
|
||||
}:style{
|
||||
width = 200,
|
||||
@@ -413,10 +413,10 @@ local vlayer_gui_control_build = Gui.element("vlayer_gui_control_build")
|
||||
|
||||
--- A button used to remove the vlayer interface
|
||||
-- @element vlayer_gui_control_remove
|
||||
local vlayer_gui_control_remove = Gui.element("vlayer_gui_control_remove")
|
||||
local vlayer_gui_control_remove = Gui.define("vlayer_gui_control_remove")
|
||||
:draw{
|
||||
type = "button",
|
||||
name = Gui.property_from_name,
|
||||
name = Gui.from_name,
|
||||
caption = { "vlayer.control-remove" },
|
||||
}:style{
|
||||
width = 200,
|
||||
@@ -441,7 +441,7 @@ local vlayer_gui_control_remove = Gui.element("vlayer_gui_control_remove")
|
||||
|
||||
--- A vertical flow containing all the control buttons
|
||||
-- @element vlayer_control_set
|
||||
local vlayer_control_set = Gui.element("vlayer_control_set")
|
||||
local vlayer_control_set = Gui.define("vlayer_control_set")
|
||||
:draw(function(_, parent, name)
|
||||
local player = Gui.get_player(parent)
|
||||
local vlayer_set = parent.add{ type = "flow", direction = "vertical", name = name }
|
||||
@@ -462,7 +462,7 @@ local vlayer_control_set = Gui.element("vlayer_control_set")
|
||||
|
||||
--- The main container for the vlayer gui
|
||||
-- @element vlayer_container
|
||||
vlayer_container = Gui.element("vlayer_container")
|
||||
vlayer_container = Gui.define("vlayer_container")
|
||||
:draw(function(definition, parent)
|
||||
local container = Gui.elements.container(parent, 400)
|
||||
|
||||
|
||||
@@ -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