Locale and code quality improvements

- Added tank ammo autofill to config
- Fixed locale to be fancier
- Fixed some repatative code
This commit is contained in:
badgamernl
2020-08-20 21:45:35 +02:00
parent 05153c7a6c
commit 8efa1c0954
3 changed files with 30 additions and 20 deletions

View File

@@ -29,6 +29,11 @@ return {
type = 'fuel', type = 'fuel',
inventory = defines.inventory.fuel, inventory = defines.inventory.fuel,
enabled = true enabled = true
},
{
type = 'ammo',
inventory = defines.inventory.car_ammo,
enabled = true
} }
}, },
['gun-turret'] = { ['gun-turret'] = {

View File

@@ -84,11 +84,11 @@ discard-tooltip=Remove task
[autofill] [autofill]
main-tooltip=Autofill settings main-tooltip=Autofill settings
ammo-caption=Ammo Autofill ammo-caption=Ammo Autofill
ammo-tooltip=Autofill settings when placing turrets ammo-tooltip=Autofill settings when playing entities with a ammo slot
fuel-caption=Fuel Autofill fuel-caption=Fuel Autofill
fuel-tooltip=Autofill settings when placing vehicles fuel-tooltip=Autofill settings when placing entities with a fuel slot
toggle-tooltip=Enable or disable the autofill for the item toggle-tooltip=Toggle the autofill of __1__ into the __2__ slot of entities
amount-tooltip=Amount of items it will try to take from your inventory and put in the turret amount-tooltip=Amount of items it will try and put into the __1__ slot of entities
confirmed=Set autofill amount to __1__ for __2__ confirmed=Set autofill amount to __1__ for __2__
filled=Autofilled the __1__ with __2__ __3__ filled=Autofilled the __1__ with __2__ __3__
[warp-list] [warp-list]

View File

@@ -21,11 +21,15 @@ end)
local autofill_container local autofill_container
local function rich_img(type, value)
return '[img='..type..'/'..value..']'
end
--- Draw a section header and main scroll --- Draw a section header and main scroll
-- @element autofill_section_container -- @element autofill_section_container
local section = local section =
Gui.element(function(_, parent, section_name, table_size) Gui.element(function(_, parent, section_name, table_size)
-- Draw the header for the section -- Draw the header for the section
Gui.header( Gui.header(
parent, parent,
{'autofill.'..section_name..'-caption'}, {'autofill.'..section_name..'-caption'},
@@ -39,12 +43,12 @@ Gui.element(function(_, parent, section_name, table_size)
end) end)
local toggle_item_button = local toggle_item_button =
Gui.element(function(event_trigger, parent, item_name) Gui.element(function(event_trigger, parent, setting)
return parent.add{ return parent.add{
name = event_trigger, name = event_trigger,
type = 'sprite-button', type = 'sprite-button',
sprite = 'item/'..item_name, sprite = 'item/'..setting.item,
tooltip = {'autofill.toggle-tooltip'}, tooltip = {'autofill.toggle-tooltip', rich_img('item', setting.item), setting.type},
style = 'shortcut_bar_button_red' style = 'shortcut_bar_button_red'
} }
end) end)
@@ -64,12 +68,12 @@ end)
end) end)
local amount_textfield = local amount_textfield =
Gui.element(function(event_trigger, parent, amount) Gui.element(function(event_trigger, parent, setting)
return parent.add{ return parent.add{
name = event_trigger, name = event_trigger,
type = 'textfield', type = 'textfield',
text = amount, text = setting.amount,
tooltip = {'autofill.amount-tooltip'}, tooltip = {'autofill.amount-tooltip', setting.type},
clear_and_focus_on_right_click = true clear_and_focus_on_right_click = true
} }
end) end)
@@ -89,13 +93,13 @@ end)
end) end)
local add_autofill_setting = local add_autofill_setting =
Gui.element(function(_, parent, item_name, amount) Gui.element(function(_, parent, setting)
local toggle_flow = parent.add{ type = 'flow', name = 'toggle-setting-'..item_name } local toggle_flow = parent.add{ type = 'flow', name = 'toggle-setting-'..setting.item }
local amount_flow = parent.add{ type = 'flow', name = 'amount-setting-'..item_name } local amount_flow = parent.add{ type = 'flow', name = 'amount-setting-'..setting.item }
toggle_flow.style.padding = 0 toggle_flow.style.padding = 0
amount_flow.style.padding = 0 amount_flow.style.padding = 0
toggle_item_button(toggle_flow, item_name) toggle_item_button(toggle_flow, setting)
amount_textfield(amount_flow, amount) amount_textfield(amount_flow, setting)
end) end)
--- Main gui container for the left flow --- Main gui container for the left flow
@@ -104,15 +108,16 @@ 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, 100) local container = Gui.container(parent, event_trigger, 100)
-- Draw the header -- Draw the header
local ammo_table = section(container, 'ammo', 2) local ammo_table = section(container, 'ammo', 2)
local fuel_table = section(container, 'fuel', 2) local fuel_table = section(container, 'fuel', 2)
for _, setting in pairs(config.default_settings) do for _, setting in pairs(config.default_settings) do
if setting.type == 'ammo' then if setting.type == 'ammo' then
add_autofill_setting(ammo_table, setting.item, setting.amount) add_autofill_setting(ammo_table, setting)
elseif setting.type == 'fuel' then elseif setting.type == 'fuel' then
add_autofill_setting(fuel_table, setting.item, setting.amount) add_autofill_setting(fuel_table, setting)
end end
end end
@@ -177,11 +182,11 @@ local function entity_build(event)
end end
inserted = entity_inventory.insert({name=item, count=preferd_amount}) inserted = entity_inventory.insert({name=item, count=preferd_amount})
player_inventory.remove({name=item, count=inserted}) player_inventory.remove({name=item, count=inserted})
print_text(entity.surface, entity.position, {'autofill.filled', '[img=entity/'..entity.name..']', inserted, '[img=item/'..item..']' }, { r = 0, g = 255, b = 0, a = 1}) print_text(entity.surface, entity.position, {'autofill.filled', rich_img('entity', entity.name), inserted, rich_img('item', item) }, { r = 0, g = 255, b = 0, a = 1})
else else
inserted = entity_inventory.insert({name=item, count=item_amount}) inserted = entity_inventory.insert({name=item, count=item_amount})
player_inventory.remove({name=item, count=inserted}) player_inventory.remove({name=item, count=inserted})
print_text(entity.surface, entity.position, {'autofill.filled', '[img=entity/'..entity.name..']', inserted, '[img=item/'..item..']' }, { r = 255, g = 165, b = 0, a = 1}) print_text(entity.surface, entity.position, {'autofill.filled', rich_img('entity', entity.name), inserted, rich_img('item', item) }, { r = 255, g = 165, b = 0, a = 1})
end end
goto continue goto continue
end end