From 8efa1c09544a910c189a73341ff832bcba1be664 Mon Sep 17 00:00:00 2001 From: badgamernl Date: Thu, 20 Aug 2020 21:45:35 +0200 Subject: [PATCH] Locale and code quality improvements - Added tank ammo autofill to config - Fixed locale to be fancier - Fixed some repatative code --- config/gui/autofill.lua | 5 +++++ locale/en/gui.cfg | 8 ++++---- modules/gui/autofill.lua | 37 +++++++++++++++++++++---------------- 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/config/gui/autofill.lua b/config/gui/autofill.lua index 7e1605cd..d7069993 100644 --- a/config/gui/autofill.lua +++ b/config/gui/autofill.lua @@ -29,6 +29,11 @@ return { type = 'fuel', inventory = defines.inventory.fuel, enabled = true + }, + { + type = 'ammo', + inventory = defines.inventory.car_ammo, + enabled = true } }, ['gun-turret'] = { diff --git a/locale/en/gui.cfg b/locale/en/gui.cfg index 2ae942f0..4d6ab0be 100644 --- a/locale/en/gui.cfg +++ b/locale/en/gui.cfg @@ -84,11 +84,11 @@ discard-tooltip=Remove task [autofill] main-tooltip=Autofill settings 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-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 +fuel-tooltip=Autofill settings when placing entities with a fuel slot +toggle-tooltip=Toggle the autofill of __1__ into the __2__ slot of entities +amount-tooltip=Amount of items it will try and put into the __1__ slot of entities confirmed=Set autofill amount to __1__ for __2__ filled=Autofilled the __1__ with __2__ __3__ [warp-list] diff --git a/modules/gui/autofill.lua b/modules/gui/autofill.lua index 78bf5192..a4e7a635 100644 --- a/modules/gui/autofill.lua +++ b/modules/gui/autofill.lua @@ -21,11 +21,15 @@ end) local autofill_container +local function rich_img(type, value) + return '[img='..type..'/'..value..']' +end + --- Draw a section header and main scroll -- @element autofill_section_container local section = Gui.element(function(_, parent, section_name, table_size) - -- Draw the header for the section + -- Draw the header for the section Gui.header( parent, {'autofill.'..section_name..'-caption'}, @@ -39,12 +43,12 @@ Gui.element(function(_, parent, section_name, table_size) end) local toggle_item_button = -Gui.element(function(event_trigger, parent, item_name) +Gui.element(function(event_trigger, parent, setting) return parent.add{ name = event_trigger, type = 'sprite-button', - sprite = 'item/'..item_name, - tooltip = {'autofill.toggle-tooltip'}, + sprite = 'item/'..setting.item, + tooltip = {'autofill.toggle-tooltip', rich_img('item', setting.item), setting.type}, style = 'shortcut_bar_button_red' } end) @@ -64,12 +68,12 @@ end) end) local amount_textfield = -Gui.element(function(event_trigger, parent, amount) +Gui.element(function(event_trigger, parent, setting) return parent.add{ name = event_trigger, type = 'textfield', - text = amount, - tooltip = {'autofill.amount-tooltip'}, + text = setting.amount, + tooltip = {'autofill.amount-tooltip', setting.type}, clear_and_focus_on_right_click = true } end) @@ -89,13 +93,13 @@ end) end) 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 } +Gui.element(function(_, parent, setting) + local toggle_flow = parent.add{ type = 'flow', name = 'toggle-setting-'..setting.item } + local amount_flow = parent.add{ type = 'flow', name = 'amount-setting-'..setting.item } toggle_flow.style.padding = 0 amount_flow.style.padding = 0 - toggle_item_button(toggle_flow, item_name) - amount_textfield(amount_flow, amount) + toggle_item_button(toggle_flow, setting) + amount_textfield(amount_flow, setting) end) --- Main gui container for the left flow @@ -104,15 +108,16 @@ 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) + add_autofill_setting(ammo_table, setting) elseif setting.type == 'fuel' then - add_autofill_setting(fuel_table, setting.item, setting.amount) + add_autofill_setting(fuel_table, setting) end end @@ -177,11 +182,11 @@ local function entity_build(event) end inserted = entity_inventory.insert({name=item, count=preferd_amount}) 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 inserted = entity_inventory.insert({name=item, count=item_amount}) 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 goto continue end