mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 04:21:41 +09:00
Added setings left container
- Changed toolbar button to left flow toggle; - Added Ammo section; - Added Fuel section; - Added default config settings; - Added autofill item toggle button and textboxes;
This commit is contained in:
@@ -4,4 +4,42 @@
|
|||||||
return {
|
return {
|
||||||
-- General config
|
-- General config
|
||||||
icon = 'item/piercing-rounds-magazine', --- @setting icon that will be used for the toolbar
|
icon = 'item/piercing-rounds-magazine', --- @setting icon that will be used for the toolbar
|
||||||
|
default_settings = {
|
||||||
|
{
|
||||||
|
type = 'ammo',
|
||||||
|
item = 'uranium-rounds-magazine',
|
||||||
|
amount = 100,
|
||||||
|
enabled = false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type = 'ammo',
|
||||||
|
item = 'piercing-rounds-magazine',
|
||||||
|
amount = 100,
|
||||||
|
enabled = false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type = 'ammo',
|
||||||
|
item = 'firearm-magazine',
|
||||||
|
amount = 100,
|
||||||
|
enabled = false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type = 'fuel',
|
||||||
|
item = 'nuclear-fuel',
|
||||||
|
amount = 100,
|
||||||
|
enabled = false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type = 'fuel',
|
||||||
|
item = 'solid-fuel',
|
||||||
|
amount = 100,
|
||||||
|
enabled = false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type = 'fuel',
|
||||||
|
item = 'coal',
|
||||||
|
amount = 100,
|
||||||
|
enabled = false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -82,7 +82,13 @@ edit-tooltip-none=Currently being edited by: Nobody
|
|||||||
discard-tooltip=Remove task
|
discard-tooltip=Remove task
|
||||||
|
|
||||||
[autofill]
|
[autofill]
|
||||||
main-tooltip=Autofill toggle
|
main-tooltip=Autofill settings
|
||||||
|
ammo-caption=Ammo Autofill
|
||||||
|
ammo-tooltip=Autofill settings when placing turrets
|
||||||
|
fuel-caption=Fuel Autofill
|
||||||
|
fuel-tooltip=Autofill settings when placing vehicles
|
||||||
|
toggle-tooltip=Enable or disable the autofill for the item
|
||||||
|
amount-tooltip=Amount of items it will try to take from your inventory and put in the turret
|
||||||
|
|
||||||
[warp-list]
|
[warp-list]
|
||||||
main-caption=Warp List
|
main-caption=Warp List
|
||||||
|
|||||||
@@ -7,25 +7,114 @@
|
|||||||
local Gui = require 'expcore.gui' --- @dep expcore.gui
|
local Gui = require 'expcore.gui' --- @dep expcore.gui
|
||||||
local Global = require 'utils.global' --- @dep utils.global
|
local Global = require 'utils.global' --- @dep utils.global
|
||||||
local config = require 'config.gui.autofill' --- @dep config.gui.autofill
|
local config = require 'config.gui.autofill' --- @dep config.gui.autofill
|
||||||
|
local Event = require 'utils.event' --- @dep utils.event
|
||||||
|
|
||||||
--- Table that stores if autofill is enabled or not
|
--- Table that stores if autofill is enabled or not
|
||||||
local autofill_enabled = {}
|
local autofill_player_settings = {}
|
||||||
Global.register(autofill_enabled, function(tbl)
|
Global.register(autofill_player_settings, function(tbl)
|
||||||
autofill_enabled = tbl
|
autofill_player_settings = tbl
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--- Button on the top flow used to toggle autofill
|
local autofill_container
|
||||||
local toolbar_autofill_toggle
|
|
||||||
toolbar_autofill_toggle = Gui.toolbar_button(config.icon, {'autofill.main-tooltip'})
|
--- Draw a section header and main scroll
|
||||||
:on_click(function(player)
|
-- @element autofill_section_container
|
||||||
local top_flow = Gui.get_top_flow(player)
|
local section =
|
||||||
local element = top_flow[toolbar_autofill_toggle.name]
|
Gui.element(function(_, parent, section_name, table_size)
|
||||||
if not autofill_enabled[player.name] then
|
-- Draw the header for the section
|
||||||
autofill_enabled[player.name] = true
|
Gui.header(
|
||||||
player.print("true")
|
parent,
|
||||||
else
|
{'autofill.'..section_name..'-caption'},
|
||||||
autofill_enabled[player.name] = false
|
{'autofill.'..section_name..'-tooltip'},
|
||||||
player.print("false")
|
true,
|
||||||
|
section_name..'-header'
|
||||||
|
)
|
||||||
|
-- Table used to display the settings
|
||||||
|
local scroll_table = Gui.scroll_table(parent, 215, table_size, section_name..'-scroll-table')
|
||||||
|
return scroll_table
|
||||||
|
end)
|
||||||
|
|
||||||
|
local toggle_item_button =
|
||||||
|
Gui.element(function(event_trigger, parent, item_name)
|
||||||
|
return parent.add{
|
||||||
|
name = event_trigger,
|
||||||
|
type = 'sprite-button',
|
||||||
|
sprite = 'item/'..item_name,
|
||||||
|
tooltip = {'autofill.toggle-tooltip'},
|
||||||
|
style = 'shortcut_bar_button_red'
|
||||||
|
}
|
||||||
|
end)
|
||||||
|
:style(Gui.sprite_style(32, nil, { right_margin = -3 }))
|
||||||
|
:on_click(function(player, element)
|
||||||
|
for _, setting in pairs(autofill_player_settings[player.name]) do
|
||||||
|
if 'item/'..setting.item == element.sprite then
|
||||||
|
if setting.enabled then
|
||||||
|
setting.enabled = false
|
||||||
|
element.style = 'shortcut_bar_button_red'
|
||||||
|
else
|
||||||
|
setting.enabled = true
|
||||||
|
element.style = 'shortcut_bar_button_green'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
local amount_textfield =
|
||||||
|
Gui.element(function(event_trigger, parent, amount)
|
||||||
|
return parent.add{
|
||||||
|
name = event_trigger,
|
||||||
|
type = 'textfield',
|
||||||
|
text = amount,
|
||||||
|
tooltip = {'autofill.amount-tooltip'},
|
||||||
|
clear_and_focus_on_right_click = true
|
||||||
|
}
|
||||||
|
end)
|
||||||
|
:style{
|
||||||
|
maximal_width = 90,
|
||||||
|
height = 28
|
||||||
|
}
|
||||||
|
|
||||||
|
local add_autofill_setting =
|
||||||
|
Gui.element(function(_, parent, item_name, amount)
|
||||||
|
local toggle_flow = parent.add{ type = 'flow', name = 'toggle-setting-'..item_name }
|
||||||
|
local amount_flow = parent.add{ type = 'flow', name = 'amount-setting-'..item_name }
|
||||||
|
toggle_flow.style.padding = 0
|
||||||
|
amount_flow.style.padding = 0
|
||||||
|
toggle_item_button(toggle_flow, item_name)
|
||||||
|
amount_textfield(amount_flow, amount)
|
||||||
|
end)
|
||||||
|
|
||||||
|
--- Main gui container for the left flow
|
||||||
|
-- @element autofill_container
|
||||||
|
autofill_container =
|
||||||
|
Gui.element(function(event_trigger, parent)
|
||||||
|
-- Draw the internal container
|
||||||
|
local container = Gui.container(parent, event_trigger, 100)
|
||||||
|
-- Draw the header
|
||||||
|
local ammo_table = section(container, 'ammo', 2)
|
||||||
|
local fuel_table = section(container, 'fuel', 2)
|
||||||
|
|
||||||
|
for _, setting in pairs(config.default_settings) do
|
||||||
|
if setting.type == 'ammo' then
|
||||||
|
add_autofill_setting(ammo_table, setting.item, setting.amount)
|
||||||
|
elseif setting.type == 'fuel' then
|
||||||
|
add_autofill_setting(fuel_table, setting.item, setting.amount)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Return the external container
|
||||||
|
return container.parent
|
||||||
|
end)
|
||||||
|
:add_to_left_flow()
|
||||||
|
|
||||||
|
--- Button on the top flow used to toggle autofill container
|
||||||
|
-- @element autofill_toggle
|
||||||
|
Gui.left_toolbar_button(config.icon, {'autofill.main-tooltip'}, autofill_container)
|
||||||
|
|
||||||
|
--- 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] = config.default_settings
|
||||||
end
|
end
|
||||||
Gui.toolbar_button_style(element, autofill_enabled[player.name])
|
|
||||||
end)
|
end)
|
||||||
Reference in New Issue
Block a user