Skip to content

Commit

Permalink
Fixed desync (tooltip cache)
Browse files Browse the repository at this point in the history
Fixed desync (tooltip cache)
Added belt container
Added tool for product edition
Added partial french help
  • Loading branch information
Helfima committed Jan 16, 2018
1 parent 272a9cf commit 738d84b
Show file tree
Hide file tree
Showing 15 changed files with 339 additions and 54 deletions.
29 changes: 25 additions & 4 deletions core/ElementGui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ function ElementGui.getInputNumber(element)
return count
end

-------------------------------------------------------------------------------
-- Set the number of textfield input
--
-- @function [parent=#ElementGui] setInputNumber
--
-- @param #LuaGuiElement element textfield input
-- @param #number value
--
-- @return #number number of textfield input
--
function ElementGui.setInputNumber(element, value)
Logging:trace(ElementGui.classname, "setInputNumber", element, value)
if element ~= nil and element.text ~= nil then
element.text = value
end
end

-------------------------------------------------------------------------------
-- Add a sprite element
--
Expand Down Expand Up @@ -997,12 +1014,13 @@ end
local cache_tooltip_recipe = {}

function ElementGui.getTooltipRecipe(prototype)
Logging:debug(ElementGui.classname, "getTooltipRecipe", prototype)
Logging:trace(ElementGui.classname, "getTooltipRecipe", prototype)
RecipePrototype.load(prototype)
if RecipePrototype.native() == nil then return nil end
local prototype_type = prototype.type or "other"
if cache_tooltip_recipe[prototype_type] ~= nil and cache_tooltip_recipe[prototype_type][prototype.name] ~= nil then
return cache_tooltip_recipe[prototype_type][prototype.name]
if cache_tooltip_recipe[prototype_type] ~= nil and cache_tooltip_recipe[prototype_type][prototype.name] ~= nil and cache_tooltip_recipe[prototype_type][prototype.name].enabled == RecipePrototype.getEnabled() then
Logging:debug(ElementGui.classname, "use cache", prototype.name)
return cache_tooltip_recipe[prototype_type][prototype.name].value
end
-- initalize tooltip
local tooltip = {"tooltip.recipe-info"}
Expand Down Expand Up @@ -1046,7 +1064,10 @@ function ElementGui.getTooltipRecipe(prototype)
-- finalise la derniere valeur
table.insert(lastTooltip, "")
if cache_tooltip_recipe[prototype_type] == nil then cache_tooltip_recipe[prototype_type] = {} end
cache_tooltip_recipe[prototype_type][prototype.name] = tooltip
Logging:debug(ElementGui.classname, "build cache", prototype.name)
cache_tooltip_recipe[prototype_type][prototype.name] = {}
cache_tooltip_recipe[prototype_type][prototype.name].value = tooltip
cache_tooltip_recipe[prototype_type][prototype.name].enabled = RecipePrototype.getEnabled()
return tooltip
end

Expand Down
20 changes: 10 additions & 10 deletions core/defines.lua
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,23 @@ helmod_settings_mod = {
default_value = true,
order = "d2"
},
--model-filter-generator
model_filter_generator = {
type = "bool-setting",
setting_type = "runtime-global",
localised_name = {"helmod_settings.model-filter-generator"},
localised_description = {"helmod_settings.model-filter-generator-desc"},
default_value = true,
order = "d3"
},
--model-filter-factory-module
model_filter_factory_module = {
type = "bool-setting",
setting_type = "runtime-global",
localised_name = {"helmod_settings.model-filter-factory-module"},
localised_description = {"helmod_settings.model-filter-factory-module-desc"},
default_value = true,
order = "d3"
order = "d4"
},
--model-filter-beacon-module
model_filter_beacon_module = {
Expand All @@ -304,15 +313,6 @@ helmod_settings_mod = {
localised_name = {"helmod_settings.model-filter-beacon-module"},
localised_description = {"helmod_settings.model-filter-beacon-module-desc"},
default_value = true,
order = "d4"
},
--model-filter-generator
model_filter_generator = {
type = "bool-setting",
setting_type = "runtime-global",
localised_name = {"helmod_settings.model-filter-generator"},
localised_description = {"helmod_settings.model-filter-generator-desc"},
default_value = true,
order = "d5"
},
--properties-tab
Expand Down
2 changes: 1 addition & 1 deletion dialog/HelpPanel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ local help_data = {
localised_text = "mod-settings-map",
desc = false,
list = "none",
count = 8
count = 10
},
{
sprite = "mod-settings-player",
Expand Down
127 changes: 102 additions & 25 deletions edition/ProductEdition.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,32 @@ function ProductEdition.methods:getInfoPanel()
return ElementGui.addGuiFrameV(panel, "info", helmod_frame_style.panel)
end

-------------------------------------------------------------------------------
-- Get or create tool panel
--
-- @function [parent=#ProductEdition] getToolPanel
--
function ProductEdition.methods:getToolPanel()
local panel = self:getPanel()
if panel["tool_panel"] ~= nil and panel["tool_panel"].valid then
return panel["tool_panel"]
end
return ElementGui.addGuiFrameV(panel, "tool_panel", helmod_frame_style.panel, {"helmod_product-edition-panel.tool"})
end

-------------------------------------------------------------------------------
-- Get or create action panel
--
-- @function [parent=#ProductEdition] getActionPanel
--
function ProductEdition.methods:getActionPanel()
local panel = self:getPanel()
if panel["action_panel"] ~= nil and panel["action_panel"].valid then
return panel["action_panel"]
end
return ElementGui.addGuiFrameV(panel, "action_panel", helmod_frame_style.panel)
end

-------------------------------------------------------------------------------
-- After open
--
Expand All @@ -96,6 +122,8 @@ function ProductEdition.methods:after_open(event, action, item, item2, item3)
self:getInfoPanel()
end

local product = nil

-------------------------------------------------------------------------------
-- On update
--
Expand All @@ -108,7 +136,19 @@ end
-- @param #string item3 third item name
--
function ProductEdition.methods:onUpdate(event, action, item, item2, item3)
local model = Model.getModel()
product = nil
if model.blocks[item] ~= nil then
for _, element in pairs(model.blocks[item].products) do
if element.name == item2 then
product = element
end
end
end

self:updateInfo(item, item2, item3)
self:updateTool(item, item2, item3)
self:updateAction(item, item2, item3)
end

-------------------------------------------------------------------------------
Expand All @@ -120,37 +160,67 @@ end
-- @param #string item2 second item name
-- @param #string item3 third item name
--

function ProductEdition.methods:updateInfo(item, item2, item3)
Logging:debug(self:classname(), "updateInfo():", item, item2, item3)
local info_panel = self:getInfoPanel()
local model = Model.getModel()

if model.blocks[item] ~= nil then
local product = nil
for _, element in pairs(model.blocks[item].products) do
if element.name == item2 then
product = element
end
end

if product ~= nil then
info_panel.clear()
if product ~= nil then
info_panel.clear()

local tablePanel = ElementGui.addGuiTable(info_panel,"table-header",2)
ElementGui.addGuiButtonSprite(tablePanel, "product", Player.getIconType(product), product.name)
ElementGui.addGuiLabel(tablePanel, "product-label", Player.getLocalisedName(product))
local tablePanel = ElementGui.addGuiTable(info_panel,"table-header",2)
ElementGui.addGuiButtonSprite(tablePanel, "product", Player.getIconType(product), product.name)
ElementGui.addGuiLabel(tablePanel, "product-label", Player.getLocalisedName(product))

ElementGui.addGuiLabel(tablePanel, "quantity-label", ({"helmod_common.quantity"}))
ElementGui.addGuiText(tablePanel, "quantity", product.count)
ElementGui.addGuiLabel(tablePanel, "quantity-label", ({"helmod_common.quantity"}))
ElementGui.addGuiText(tablePanel, "quantity", product.count)
end
end

local action_panel = ElementGui.addGuiTable(info_panel,"table_action",3)
ElementGui.addGuiButton(action_panel, self:classname().."=product-update=ID="..item.."=", product.name, "helmod_button_default", ({"helmod_button.save"}))
ElementGui.addGuiButton(action_panel, self:classname().."=product-reset=ID="..item.."=", product.name, "helmod_button_default", ({"helmod_button.reset"}))
ElementGui.addGuiButton(action_panel, self:classname().."=CLOSE=ID="..item.."=", product.name, "helmod_button_default", ({"helmod_button.close"}))
end
-------------------------------------------------------------------------------
-- Update action
--
-- @function [parent=#ProductEdition] updateAction
--
-- @param #string item first item name
-- @param #string item2 second item name
-- @param #string item3 third item name
--
function ProductEdition.methods:updateAction(item, item2, item3)
Logging:debug(self:classname(), "updateAction():", item, item2, item3)
local action_panel = self:getActionPanel()
if product ~= nil then
action_panel.clear()
local action_panel = ElementGui.addGuiTable(action_panel,"table_action",3)
ElementGui.addGuiButton(action_panel, self:classname().."=product-update=ID="..item.."=", product.name, "helmod_button_default", ({"helmod_button.save"}))
ElementGui.addGuiButton(action_panel, self:classname().."=product-reset=ID="..item.."=", product.name, "helmod_button_default", ({"helmod_button.reset"}))
ElementGui.addGuiButton(action_panel, self:classname().."=CLOSE=ID="..item.."=", product.name, "helmod_button_default", ({"helmod_button.close"}))
end
end

-------------------------------------------------------------------------------
-- Update tool
--
-- @function [parent=#ProductEdition] updateTool
--
-- @param #string item first item name
-- @param #string item2 second item name
-- @param #string item3 third item name
--
local belt_count = 1
function ProductEdition.methods:updateTool(item, item2, item3)
Logging:debug(self:classname(), "updateTool():", item, item2, item3)
local tool_panel = self:getToolPanel()
tool_panel.clear()
local table_panel = ElementGui.addGuiTable(tool_panel,"table-header",1)
ItemPrototype.load("transport-belt").getLocalisedName()
ElementGui.addGuiLabel(table_panel, "quantity-label", {"helmod_product-edition-panel.transport-belt"})
ElementGui.addGuiText(table_panel, "quantity", belt_count)

local table_panel = ElementGui.addGuiTable(tool_panel,"table-belt",5)
for key, prototype in pairs(Player.getEntityPrototypes({"transport-belt"})) do
ElementGui.addGuiButtonSelectSprite(table_panel, self:classname().."=element-select=ID=", Player.getEntityIconType(prototype), prototype.name, prototype.name, EntityPrototype.load(prototype).getLocalisedName())
end
end
-------------------------------------------------------------------------------
-- On event
--
Expand All @@ -168,9 +238,8 @@ function ProductEdition.methods:onEvent(event, action, item, item2, item3)
if Player.isAdmin() or model.owner == Player.native().name or (model.share ~= nil and bit32.band(model.share, 2) > 0) then
if action == "product-update" then
local products = {}
local inputPanel = self:getInfoPanel()["table-header"]

local quantity = ElementGui.getInputNumber(inputPanel["quantity"])
local input_panel = self:getInfoPanel()["table-header"]
local quantity = ElementGui.getInputNumber(input_panel["quantity"])

ModelBuilder.updateProduct(item, item2, quantity)
ModelCompute.update()
Expand All @@ -186,5 +255,13 @@ function ProductEdition.methods:onEvent(event, action, item, item2, item3)
self.parent:refreshDisplayData(nil, item, item2)
self:close()
end
if action == "element-select" then
local input_panel = self:getToolPanel()["table-header"]
belt_count = ElementGui.getInputNumber(input_panel["quantity"])
local belt_speed = EntityPrototype.load(item).getBeltSpeed()

local output_panel = self:getInfoPanel()["table-header"]
ElementGui.setInputNumber(output_panel["quantity"], belt_count * belt_speed * Product.belt_ratio)
end
end
end
2 changes: 1 addition & 1 deletion info.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

{
"name": "helmod",
"version": "0.7.3",
"version": "0.7.4",
"title": "Helmod: assistant for planning your base.",
"author": "Helfima",
"contact": "Helfima",
Expand Down
4 changes: 3 additions & 1 deletion locale/en/helmod.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ technology-title=Technology selector
container-title=Container selector

[helmod_product-edition-panel]
title=Edit Product
title=Edit Product
tool=Tool
transport-belt=Transport belt number for 1 sec

[helmod_resource-edition-panel]
title=Edit Resource
Expand Down
12 changes: 7 additions & 5 deletions locale/en/help.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ mod-settings-map-desc=
mod-settings-map-1=Debug mode: never use this when you play a game, the mod write lot of log.
mod-settings-map-2=Element number format: Choose the number of decimal that you want see.
mod-settings-map-3=Factory number format: Choose the number of decimal that you want see.
mod-settings-map-4=Display ****: Add some column in the result table, you don't need that
mod-settings-map-5=Filter on text changed: If it's enabled, the filter on selector is auto apply. perhaps in MP game you must disable.
mod-settings-map-6=Filter on factory, beacon or generator: If you don't see the factory or beacon in edition panel, you can remove this filter to see all.
mod-settings-map-7=Module restriction: Some time you need allow all module, disable if you want use module anywhere.
mod-settings-map-8=Display properties tab: It's a extra-tab to see all properties of entities or others.
mod-settings-map-4=Display all sheet: Allow to see all sheet for the admin
mod-settings-map-5=Real name: Display system name of all element
mod-settings-map-6=Display ****: Add some column in the result table, you don't need that
mod-settings-map-7=Filter on text changed: If it's enabled, the filter on selector is auto apply. perhaps in MP game you must disable.
mod-settings-map-8=Filter on factory, beacon or generator: If you don't see the factory or beacon in edition panel, you can remove this filter to see all.
mod-settings-map-9=Module restriction: Some time you need allow all module, disable if you want use module anywhere.
mod-settings-map-10=Display properties tab: It's a extra-tab to see all properties of entities or others.

mod-settings-player=Mod Settings Per Player
mod-settings-player-desc=
Expand Down
2 changes: 2 additions & 0 deletions locale/fr/helmod.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ container-title=Sélecteur de conteneur

[helmod_product-edition-panel]
title=Edition de produit
tool=Utilitaire
transport-belt=Nombre de convoyer pour 1 sec

[helmod_resource-edition-panel]
title=Edition de resource
Expand Down
Loading

0 comments on commit 738d84b

Please sign in to comment.