mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-29 20:16:38 +09:00
Change in look and feel:
- Change the way the header text is displayed; - Change entity toggle to be checkmark and cross; - Added burner mining drill to autofill; - Added comments; - Changed use of some scroll tables to just normal tables; - Fixed entity toggle not working when placing down entities;
This commit is contained in:
@@ -12,6 +12,7 @@ local tank = 'tank'
|
|||||||
local spidertron = 'spidertron'
|
local spidertron = 'spidertron'
|
||||||
local locomotive = 'locomotive'
|
local locomotive = 'locomotive'
|
||||||
local gun_turret = 'gun-turret'
|
local gun_turret = 'gun-turret'
|
||||||
|
local burner_mining_drill = 'burner-mining-drill'
|
||||||
local stone_furnace = 'stone-furnace'
|
local stone_furnace = 'stone-furnace'
|
||||||
local steel_furnace = 'steel-furnace'
|
local steel_furnace = 'steel-furnace'
|
||||||
|
|
||||||
@@ -29,6 +30,7 @@ local config = {
|
|||||||
spidertron = spidertron,
|
spidertron = spidertron,
|
||||||
locomotive = locomotive,
|
locomotive = locomotive,
|
||||||
gun_turret = gun_turret,
|
gun_turret = gun_turret,
|
||||||
|
burner_mining_drill = burner_mining_drill,
|
||||||
stone_furnace = stone_furnace,
|
stone_furnace = stone_furnace,
|
||||||
steel_furnace = steel_furnace
|
steel_furnace = steel_furnace
|
||||||
},
|
},
|
||||||
@@ -126,7 +128,7 @@ local default_autofill_item_settings = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
category = config.categories.fuel,
|
category = config.categories.fuel,
|
||||||
entity = {config.entities.car, config.entities.tank, config.entities.locomotive, config.entities.stone_furnace, config.entities.steel_furnace},
|
entity = {config.entities.car, config.entities.tank, config.entities.locomotive, config.entities.burner_mining_drill, config.entities.stone_furnace, config.entities.steel_furnace},
|
||||||
type = {defines.inventory.fuel},
|
type = {defines.inventory.fuel},
|
||||||
name = 'nuclear-fuel',
|
name = 'nuclear-fuel',
|
||||||
amount = 1,
|
amount = 1,
|
||||||
@@ -134,7 +136,7 @@ local default_autofill_item_settings = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
category = config.categories.fuel,
|
category = config.categories.fuel,
|
||||||
entity = {config.entities.car, config.entities.tank, config.entities.locomotive, config.entities.stone_furnace, config.entities.steel_furnace},
|
entity = {config.entities.car, config.entities.tank, config.entities.locomotive, config.entities.burner_mining_drill, config.entities.stone_furnace, config.entities.steel_furnace},
|
||||||
type = {defines.inventory.fuel},
|
type = {defines.inventory.fuel},
|
||||||
name = 'rocket-fuel',
|
name = 'rocket-fuel',
|
||||||
amount = 10,
|
amount = 10,
|
||||||
@@ -142,7 +144,7 @@ local default_autofill_item_settings = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
category = config.categories.fuel,
|
category = config.categories.fuel,
|
||||||
entity = {config.entities.car, config.entities.tank, config.entities.locomotive, config.entities.stone_furnace, config.entities.steel_furnace},
|
entity = {config.entities.car, config.entities.tank, config.entities.locomotive, config.entities.burner_mining_drill, config.entities.stone_furnace, config.entities.steel_furnace},
|
||||||
type = {defines.inventory.fuel},
|
type = {defines.inventory.fuel},
|
||||||
name = 'solid-fuel',
|
name = 'solid-fuel',
|
||||||
amount = 10,
|
amount = 10,
|
||||||
@@ -150,7 +152,7 @@ local default_autofill_item_settings = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
category = config.categories.fuel,
|
category = config.categories.fuel,
|
||||||
entity = {config.entities.car, config.entities.tank, config.entities.locomotive, config.entities.stone_furnace, config.entities.steel_furnace},
|
entity = {config.entities.car, config.entities.tank, config.entities.locomotive, config.entities.burner_mining_drill, config.entities.stone_furnace, config.entities.steel_furnace},
|
||||||
type = {defines.inventory.fuel},
|
type = {defines.inventory.fuel},
|
||||||
name = 'coal',
|
name = 'coal',
|
||||||
amount = 10,
|
amount = 10,
|
||||||
@@ -202,6 +204,8 @@ generate_default_setting(config.entities.spidertron, defines.inventory.car_ammo,
|
|||||||
|
|
||||||
generate_default_setting(config.entities.gun_turret, defines.inventory.turret_ammo, true)
|
generate_default_setting(config.entities.gun_turret, defines.inventory.turret_ammo, true)
|
||||||
|
|
||||||
|
generate_default_setting(config.entities.burner_mining_drill, defines.inventory.fuel, true)
|
||||||
|
|
||||||
generate_default_setting(config.entities.stone_furnace, defines.inventory.fuel, true)
|
generate_default_setting(config.entities.stone_furnace, defines.inventory.fuel, true)
|
||||||
|
|
||||||
generate_default_setting(config.entities.steel_furnace, defines.inventory.fuel, true)
|
generate_default_setting(config.entities.steel_furnace, defines.inventory.fuel, true)
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ discard-tooltip=Remove task
|
|||||||
|
|
||||||
[autofill]
|
[autofill]
|
||||||
main-tooltip=Autofill settings
|
main-tooltip=Autofill settings
|
||||||
|
toggle-section-caption=__1__ __2__
|
||||||
toggle-section-tooltip=Expand Section
|
toggle-section-tooltip=Expand Section
|
||||||
toggle-section-collapse-tooltip=Collapse Section
|
toggle-section-collapse-tooltip=Collapse Section
|
||||||
toggle-entity-tooltip=Toggle the autofill of __1__ entity (overwrites autofill settings of the entity)
|
toggle-entity-tooltip=Toggle the autofill of __1__ entity (overwrites autofill settings of the entity)
|
||||||
|
|||||||
@@ -25,8 +25,9 @@ local function rich_img(type, value)
|
|||||||
return '[img='..type..'/'..value..']'
|
return '[img='..type..'/'..value..']'
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Button to toggle a section dropdown
|
--- Toggle enitity button, used for toggling autofill for the specific entity
|
||||||
-- @element toggle_section
|
-- All entity autofill settings will be ignored if its disabled
|
||||||
|
-- @element toggle_item_button
|
||||||
local toggle_section =
|
local toggle_section =
|
||||||
Gui.element{
|
Gui.element{
|
||||||
type = 'sprite-button',
|
type = 'sprite-button',
|
||||||
@@ -49,31 +50,23 @@ toggle_section
|
|||||||
element.hovered_sprite = 'utility/expand'
|
element.hovered_sprite = 'utility/expand'
|
||||||
element.tooltip = {'autofill.toggle-section-tooltip'}
|
element.tooltip = {'autofill.toggle-section-tooltip'}
|
||||||
end
|
end
|
||||||
local event = {}
|
|
||||||
for _, child in pairs(element.parent.parent.children) do
|
|
||||||
if child.alignment and child.alignment[toggle_section.name] then
|
|
||||||
if element.parent.name ~= child.name then
|
|
||||||
event.element = child.alignment[toggle_section.name]
|
|
||||||
toggle_section:raise_custom_event(event)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Used to assign an event to the header label to trigger a toggle
|
--- Used to assign an event to the header label to trigger a toggle
|
||||||
-- @element header_toggle
|
-- @element header_toggle
|
||||||
local header_toggle = Gui.element()
|
local header_toggle = Gui.element()
|
||||||
:on_click(function(_, element, event)
|
:on_click(function(_, element, event)
|
||||||
event.element = element.parent.alignment[toggle_section.name]
|
event.element = element.parent.alignment[toggle_section.name]
|
||||||
toggle_section:raise_custom_event(event)
|
toggle_section:raise_custom_event(event)
|
||||||
end)
|
end)
|
||||||
-- Used to assign an event to the header label to trigger a toggle
|
|
||||||
|
--- Used to assign an event to the header label to trigger a toggle
|
||||||
-- @element header_toggle
|
-- @element header_toggle
|
||||||
local entity_toggle = Gui.element(function(event_trigger, parent, entity_name)
|
local entity_toggle = Gui.element(function(event_trigger, parent, entity_name)
|
||||||
return parent.add{
|
return parent.add{
|
||||||
name = event_trigger,
|
name = event_trigger,
|
||||||
type = 'sprite-button',
|
type = 'sprite-button',
|
||||||
sprite = 'item/'..entity_name,
|
sprite = 'utility/confirm_slot',
|
||||||
tooltip = {'autofill.toggle-entity-tooltip', rich_img('item', entity_name)},
|
tooltip = {'autofill.toggle-entity-tooltip', rich_img('item', entity_name)},
|
||||||
style = 'shortcut_bar_button_green'
|
style = 'shortcut_bar_button_green'
|
||||||
}
|
}
|
||||||
@@ -86,9 +79,11 @@ end)
|
|||||||
if not setting then return end
|
if not setting then return end
|
||||||
if setting.enabled then
|
if setting.enabled then
|
||||||
setting.enabled = false
|
setting.enabled = false
|
||||||
|
element.sprite = 'utility/close_black'
|
||||||
element.style = 'shortcut_bar_button_red'
|
element.style = 'shortcut_bar_button_red'
|
||||||
else
|
else
|
||||||
setting.enabled = true
|
setting.enabled = true
|
||||||
|
element.sprite = 'utility/confirm_slot'
|
||||||
element.style = 'shortcut_bar_button_green'
|
element.style = 'shortcut_bar_button_green'
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
@@ -100,7 +95,7 @@ Gui.element(function(_, parent, section_name, table_size)
|
|||||||
-- Draw the header for the section
|
-- Draw the header for the section
|
||||||
local header = Gui.header(
|
local header = Gui.header(
|
||||||
parent,
|
parent,
|
||||||
{'entity-name.'..section_name},
|
{'autofill.toggle-section-caption', rich_img('item', section_name), {'entity-name.'..section_name}},
|
||||||
{'autofill.toggle-section-tooltip'},
|
{'autofill.toggle-section-tooltip'},
|
||||||
true,
|
true,
|
||||||
section_name..'-header',
|
section_name..'-header',
|
||||||
@@ -111,15 +106,19 @@ Gui.element(function(_, parent, section_name, table_size)
|
|||||||
entity_toggle(header, section_name)
|
entity_toggle(header, section_name)
|
||||||
toggle_section(header)
|
toggle_section(header)
|
||||||
|
|
||||||
-- Table used to display the settings
|
local section_table = parent.add{
|
||||||
local scroll_table = Gui.scroll_table(parent, 999, table_size, section_name)
|
type = 'table',
|
||||||
scroll_table.parent.visible = false
|
name = section_name,
|
||||||
|
column_count = table_size
|
||||||
|
}
|
||||||
|
|
||||||
return scroll_table
|
section_table.visible = false
|
||||||
|
|
||||||
|
return section_table
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
--- Toggle item button, used for toggling autofill for the specific item
|
||||||
|
-- @element toggle_item_button
|
||||||
local toggle_item_button =
|
local toggle_item_button =
|
||||||
Gui.element(function(event_trigger, parent, item)
|
Gui.element(function(event_trigger, parent, item)
|
||||||
return parent.add{
|
return parent.add{
|
||||||
@@ -133,7 +132,7 @@ end)
|
|||||||
:style(Gui.sprite_style(32, nil, { right_margin = -3 }))
|
:style(Gui.sprite_style(32, nil, { right_margin = -3 }))
|
||||||
:on_click(function(player, element)
|
:on_click(function(player, element)
|
||||||
local item_name = string.sub(element.parent.name, 1 + string.len('toggle-setting-'), -1)
|
local item_name = string.sub(element.parent.name, 1 + string.len('toggle-setting-'), -1)
|
||||||
local entity_name = element.parent.parent.parent.parent.parent.parent.name
|
local entity_name = element.parent.parent.parent.parent.name
|
||||||
if not autofill_player_settings[player.name] then return end
|
if not autofill_player_settings[player.name] then return end
|
||||||
local setting = autofill_player_settings[player.name][entity_name]
|
local setting = autofill_player_settings[player.name][entity_name]
|
||||||
if not setting then return end
|
if not setting then return end
|
||||||
@@ -148,6 +147,9 @@ end)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
--- Amount text field for a autofill item
|
||||||
|
-- @element amount_textfield
|
||||||
local amount_textfield =
|
local amount_textfield =
|
||||||
Gui.element(function(event_trigger, parent, item)
|
Gui.element(function(event_trigger, parent, item)
|
||||||
return parent.add{
|
return parent.add{
|
||||||
@@ -165,7 +167,7 @@ end)
|
|||||||
}
|
}
|
||||||
:on_confirmed(function(player, element, _)
|
:on_confirmed(function(player, element, _)
|
||||||
local item_name = string.sub(element.parent.name, 1 + string.len('toggle-setting-'), -1)
|
local item_name = string.sub(element.parent.name, 1 + string.len('toggle-setting-'), -1)
|
||||||
local entity_name = element.parent.parent.parent.parent.parent.parent.name
|
local entity_name = element.parent.parent.parent.parent.name
|
||||||
if not autofill_player_settings[player.name] then return end
|
if not autofill_player_settings[player.name] then return end
|
||||||
local setting = autofill_player_settings[player.name][entity_name]
|
local setting = autofill_player_settings[player.name][entity_name]
|
||||||
if not setting then return end
|
if not setting then return end
|
||||||
@@ -175,6 +177,8 @@ end)
|
|||||||
player.print({'autofill.confirmed', item.amount, rich_img('item', item.name), rich_img('entity', entity_name) })
|
player.print({'autofill.confirmed', item.amount, rich_img('item', item.name), rich_img('entity', entity_name) })
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
--- Autofill setting, contains a button and a textbox
|
||||||
|
-- @element add_autofill_setting
|
||||||
local add_autofill_setting =
|
local add_autofill_setting =
|
||||||
Gui.element(function(_, parent, item)
|
Gui.element(function(_, parent, item)
|
||||||
local toggle_flow = parent.add{ type = 'flow', name = 'toggle-setting-'..item.name }
|
local toggle_flow = parent.add{ type = 'flow', name = 'toggle-setting-'..item.name }
|
||||||
@@ -185,6 +189,8 @@ Gui.element(function(_, parent, item)
|
|||||||
amount_textfield(amount_flow, item)
|
amount_textfield(amount_flow, item)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
--- Toggle item button empty, just a filler gui element
|
||||||
|
-- @element toggle_item_button_empty
|
||||||
local toggle_item_button_empty =
|
local toggle_item_button_empty =
|
||||||
Gui.element(function(_, parent, i)
|
Gui.element(function(_, parent, i)
|
||||||
return parent.add{
|
return parent.add{
|
||||||
@@ -195,6 +201,8 @@ end)
|
|||||||
:style(Gui.sprite_style(32, nil, { right_margin = -3 }))
|
:style(Gui.sprite_style(32, nil, { right_margin = -3 }))
|
||||||
|
|
||||||
|
|
||||||
|
--- Amount text field empty, just a filler gui element
|
||||||
|
-- @element amount_textfield_empty
|
||||||
local amount_textfield_empty =
|
local amount_textfield_empty =
|
||||||
Gui.element(function(_, parent, i)
|
Gui.element(function(_, parent, i)
|
||||||
return parent.add{
|
return parent.add{
|
||||||
@@ -204,6 +212,8 @@ Gui.element(function(_, parent, i)
|
|||||||
end)
|
end)
|
||||||
:style{ maximal_width = 40, height = 31, padding = -2 }
|
:style{ maximal_width = 40, height = 31, padding = -2 }
|
||||||
|
|
||||||
|
--- Autofill setting empty, contains filler button and textfield gui elements
|
||||||
|
-- @element add_empty_autofill_setting
|
||||||
local add_empty_autofill_setting =
|
local add_empty_autofill_setting =
|
||||||
Gui.element(function(_, parent, i)
|
Gui.element(function(_, parent, i)
|
||||||
local toggle_flow = parent.add{ type = 'flow', name = 'toggle-setting-empty-'..i }
|
local toggle_flow = parent.add{ type = 'flow', name = 'toggle-setting-empty-'..i }
|
||||||
@@ -223,19 +233,33 @@ autofill_container =
|
|||||||
Gui.element(function(event_trigger, parent)
|
Gui.element(function(event_trigger, parent)
|
||||||
-- Draw the internal container
|
-- Draw the internal container
|
||||||
local container = Gui.container(parent, event_trigger)
|
local container = Gui.container(parent, event_trigger)
|
||||||
container.parent.style.minimal_width = 245
|
container.parent.style.minimal_width = 257
|
||||||
-- Draw the header
|
-- Draw the scroll container
|
||||||
|
local scroll_table = Gui.scroll_table(container, 400, 1, 'autofill-scroll-table')
|
||||||
|
scroll_table.style.vertical_spacing = 0
|
||||||
|
scroll_table.parent.vertical_scroll_policy = 'always'
|
||||||
|
-- Loop over each default entity config
|
||||||
for _, setting in pairs(config.default_entities) do
|
for _, setting in pairs(config.default_entities) do
|
||||||
local table_sizes = {}
|
local table_sizes = {}
|
||||||
local tables = {}
|
local tables = {}
|
||||||
local entity_table = section(container, setting.entity, 3)
|
-- Draw a section for the element
|
||||||
|
local entity_table = section(scroll_table, setting.entity, 3)
|
||||||
|
-- Loop over each item category
|
||||||
for _, category in pairs(config.categories) do
|
for _, category in pairs(config.categories) do
|
||||||
if not table_sizes[category] then table_sizes[category] = 0 end
|
if not table_sizes[category] then table_sizes[category] = 0 end
|
||||||
|
-- Draw a alignment gui to make sure the gui is floating to the top of the parent
|
||||||
local alignment = Gui.alignment(entity_table, category..'-'..setting.entity, 'center', 'top')
|
local alignment = Gui.alignment(entity_table, category..'-'..setting.entity, 'center', 'top')
|
||||||
alignment.style.padding = 0
|
alignment.style.padding = 0
|
||||||
local category_table = Gui.scroll_table(alignment, 999, 2, category)
|
-- Draw table
|
||||||
|
local category_table = alignment.add{
|
||||||
|
type = 'table',
|
||||||
|
name = 'category-table',
|
||||||
|
column_count = 2
|
||||||
|
}
|
||||||
|
category_table.style.vertical_spacing = 1
|
||||||
category_table.parent.style.padding = 0
|
category_table.parent.style.padding = 0
|
||||||
tables[category] = category_table
|
tables[category] = category_table
|
||||||
|
-- Add item autofill setting gui elements to the table
|
||||||
for _, item in pairs(setting.items) do
|
for _, item in pairs(setting.items) do
|
||||||
if item.category == category then
|
if item.category == category then
|
||||||
add_autofill_setting(category_table, item)
|
add_autofill_setting(category_table, item)
|
||||||
@@ -244,6 +268,7 @@ Gui.element(function(event_trigger, parent)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Add empty gui elements for the categories with less items than the other categories
|
||||||
local t = table.get_values(table_sizes)
|
local t = table.get_values(table_sizes)
|
||||||
table.sort(t)
|
table.sort(t)
|
||||||
local biggest = t[#t]
|
local biggest = t[#t]
|
||||||
@@ -269,8 +294,6 @@ Event.add(defines.events.on_player_created, function(event)
|
|||||||
if not autofill_player_settings[player.name] then
|
if not autofill_player_settings[player.name] then
|
||||||
autofill_player_settings[player.name] = table.deep_copy(config.default_entities)
|
autofill_player_settings[player.name] = table.deep_copy(config.default_entities)
|
||||||
end
|
end
|
||||||
|
|
||||||
print(game.table_to_json(autofill_player_settings[player.name]))
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local function entity_build(event)
|
local function entity_build(event)
|
||||||
@@ -285,15 +308,17 @@ local function entity_build(event)
|
|||||||
-- Check if player has settings
|
-- Check if player has settings
|
||||||
if not autofill_player_settings[player.name] then return end
|
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
|
-- Check if autofill for the entity is enabled
|
||||||
if not autofill_player_settings[player.name][entity.name] then return end
|
if not entity_settings then return end
|
||||||
|
if not entity_settings.enabled then return end
|
||||||
|
|
||||||
-- Get the inventory of the player
|
-- Get the inventory of the player
|
||||||
local player_inventory = player.get_main_inventory()
|
local player_inventory = player.get_main_inventory()
|
||||||
|
|
||||||
local text_position = { x = entity.position.x, y = entity.position.y }
|
local text_position = { x = entity.position.x, y = entity.position.y }
|
||||||
-- Loop over all possible items to insert into the entity
|
-- Loop over all possible items to insert into the entity
|
||||||
for _, item in pairs(autofill_player_settings[player.name][entity.name].items) do
|
for _, item in pairs(entity_settings.items) do
|
||||||
-- Check if the item is enabled or goto next item
|
-- Check if the item is enabled or goto next item
|
||||||
if not item.enabled then goto end_item end
|
if not item.enabled then goto end_item end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user