diff --git a/dialog/PinPanel.lua b/dialog/PinPanel.lua index a864b60a..5213e229 100644 --- a/dialog/PinPanel.lua +++ b/dialog/PinPanel.lua @@ -250,11 +250,11 @@ function PinPanel.methods:addProductionBlockRow(player, guiTable, blockId, recip local model = self.model:getModel(player) -- col recipe - local guiRecipe = self:addGuiFlowH(guiTable,"recipe"..recipe.name, "helmod_flow_default") + local guiRecipe = self:addGuiFlowH(guiTable,"recipe"..recipe.id, "helmod_flow_default") self:addGuiButtonSprite(guiRecipe, "PinPanel_recipe_"..blockId.."=", self.player:getRecipeIconType(player, recipe), recipe.name, recipe.name, self.player:getRecipeLocalisedName(player, recipe)) -- products - local tProducts = self:addGuiTable(guiTable,"products_"..recipe.name, 3) + local tProducts = self:addGuiTable(guiTable,"products_"..recipe.id, 3) if recipe.products ~= nil then for r, product in pairs(recipe.products) do local cell = self:addGuiFlowH(tProducts,"cell_"..product.name, "helmod_flow_default") @@ -266,9 +266,9 @@ function PinPanel.methods:addProductionBlockRow(player, guiTable, blockId, recip end -- col factory - local guiFactory = self:addGuiFlowH(guiTable,"factory"..recipe.name, "helmod_flow_default") + local guiFactory = self:addGuiFlowH(guiTable,"factory"..recipe.id, "helmod_flow_default") local factory = recipe.factory - self:addGuiLabel(guiFactory, factory.name, self:formatNumber(factory.limit_count), "helmod_label_right_30") + self:addGuiLabel(guiFactory, factory.name, self:formatNumberFactory(factory.limit_count), "helmod_label_right_30") self:addGuiButtonSprite(guiFactory, "PinPanel_recipe_"..blockId.."="..recipe.name.."=", self.player:getIconType(factory), factory.name, factory.name, self.player:getLocalisedName(player, factory)) local guiFactoryModule = self:addGuiTable(guiFactory,"factory-modules"..recipe.name, 2, "helmod_factory_modules") -- modules @@ -290,7 +290,7 @@ function PinPanel.methods:addProductionBlockRow(player, guiTable, blockId, recip end -- ingredients - local tIngredient = self:addGuiTable(guiTable,"ingredients_"..recipe.name, 3) + local tIngredient = self:addGuiTable(guiTable,"ingredients_"..recipe.id, 3) if recipe.ingredients ~= nil then for r, ingredient in pairs(recipe.ingredients) do local cell = self:addGuiFlowH(tIngredient,"cell_"..ingredient.name, "helmod_flow_default") @@ -304,9 +304,9 @@ function PinPanel.methods:addProductionBlockRow(player, guiTable, blockId, recip local display_pin_beacon = self.player:getGlobalSettings(player,"display_pin_beacon") if display_pin_beacon == true then -- col beacon - local guiBeacon = self:addGuiFlowH(guiTable,"beacon"..recipe.name, "helmod_flow_default") + local guiBeacon = self:addGuiFlowH(guiTable,"beacon"..recipe.id, "helmod_flow_default") local beacon = recipe.beacon - self:addGuiLabel(guiBeacon, beacon.name, self:formatNumber(beacon.limit_count), "helmod_label_right_30") + self:addGuiLabel(guiBeacon, beacon.name, self:formatNumberFactory(beacon.limit_count), "helmod_label_right_30") self:addGuiButtonSprite(guiBeacon, "PinPanel_recipe_"..blockId.."="..recipe.name.."=", self.player:getIconType(beacon), beacon.name, beacon.name, self.player:getLocalisedName(player, beacon)) local guiBeaconModule = self:addGuiTable(guiBeacon,"beacon-modules"..recipe.name, 1, "helmod_beacon_modules") -- modules @@ -355,3 +355,19 @@ function PinPanel.methods:on_event(player, event, action, item, item2, item3) self:updateInfo(player, event, action, globalGui.pinBlock, item2, item3) end end + +------------------------------------------------------------------------------- +-- Format number for factory +-- +-- @function [parent=#PinPanel] formatNumberFactory +-- +-- @param #number number +-- +function PinPanel.methods:formatNumberFactory(number) + local decimal = 2 + local format_number = self.player:getSettings(nil, "format_number_factory", true) + if format_number == "0" then decimal = 0 end + if format_number == "0.0" then decimal = 1 end + if format_number == "0.00" then decimal = 2 end + return self:formatNumber(number, decimal) +end \ No newline at end of file diff --git a/info.json b/info.json index 1faf4a38..f39875e6 100644 --- a/info.json +++ b/info.json @@ -1,7 +1,7 @@ { "name": "helmod", - "version": "0.5.4", + "version": "0.5.5", "title": "Helmod: Assistant to plan its base.", "author": "Helfima", "contact": "Helfima", diff --git a/model/Model.lua b/model/Model.lua index c473eb21..a1847c00 100644 --- a/model/Model.lua +++ b/model/Model.lua @@ -696,12 +696,12 @@ function Model.methods:addRecipeIntoProductionBlock(player, key) local model = self:getModel(player) local globalGui = self.player:getGlobalGui(player) local blockId = globalGui.currentBlock - local recipe = self.player:getRecipe(player, key); + local lua_recipe = self.player:getRecipe(player, key); - if recipe ~= nil then + if lua_recipe ~= nil then -- ajoute le bloc si il n'existe pas if model.blocks[blockId] == nil then - local modelBlock = self:createProductionBlockModel(player, recipe) + local modelBlock = self:createProductionBlockModel(player, lua_recipe) local index = self:countBlocks(player) modelBlock.index = index modelBlock.unlinked = unlinked @@ -713,14 +713,14 @@ function Model.methods:addRecipeIntoProductionBlock(player, key) end -- ajoute le recipe si il n'existe pas - local ModelRecipe = self:createRecipeModel(player, recipe.name, 0) + local ModelRecipe = self:createRecipeModel(player, lua_recipe.name, 0) local index = self:countBlockRecipes(player, blockId) - ModelRecipe.is_resource = not(recipe.force) - ModelRecipe.energy = recipe.energy - ModelRecipe.category = recipe.category - ModelRecipe.group = recipe.group.name - ModelRecipe.ingredients = recipe.ingredients - ModelRecipe.products = recipe.products + ModelRecipe.is_resource = not(lua_recipe.force) + ModelRecipe.energy = lua_recipe.energy + ModelRecipe.category = lua_recipe.category + ModelRecipe.group = lua_recipe.group.name + ModelRecipe.ingredients = lua_recipe.ingredients + ModelRecipe.products = lua_recipe.products ModelRecipe.index = index self:recipeReset(ModelRecipe) -- ajoute les produits du block @@ -734,13 +734,13 @@ function Model.methods:addRecipeIntoProductionBlock(player, key) end model.blocks[blockId].recipes[ModelRecipe.id] = ModelRecipe - local defaultFactory = self:getDefaultRecipeFactory(player, recipe.name) + local defaultFactory = self:getDefaultRecipeFactory(player, lua_recipe.name) if defaultFactory ~= nil then - self:setFactory(player, blockId, recipe.name, defaultFactory) + self:setFactory(player, blockId, ModelRecipe.id, defaultFactory) end - local defaultBeacon = self:getDefaultRecipeBeacon(player, recipe.name) + local defaultBeacon = self:getDefaultRecipeBeacon(player, lua_recipe.name) if defaultBeacon ~= nil then - self:setBeacon(player, blockId, recipe.name, defaultBeacon) + self:setBeacon(player, blockId, ModelRecipe.id, defaultBeacon) end return model.blocks[blockId] end @@ -906,7 +906,7 @@ function Model.methods:setBeacon(player, item, key, name) local beacon = self.player:getEntityPrototype(name) if beacon ~= nil then -- set global default - self:setDefaultRecipeBeacon(player, key, beacon.name) + self:setDefaultRecipeBeacon(player, item, key, beacon.name) object.beacon.name = beacon.name -- copy the default parameters @@ -999,7 +999,7 @@ function Model.methods:setFactory(player, item, key, name) local factory = self.player:getEntityPrototype(name) if factory ~= nil then -- set global default - self:setDefaultRecipeFactory(player, key, factory.name) + self:setDefaultRecipeFactory(player, item, key, factory.name) object.factory.name = factory.name --object.factory.type = factory.type @@ -2176,11 +2176,13 @@ end -- @function [parent=#Model] setDefaultRecipeFactory -- -- @param #LuaPlayer player +-- @param #string item block_id or resource -- @param #string key recipe name -- @param #string name factory name -- -function Model.methods:setDefaultRecipeFactory(player, key, name) - local recipe = self:getDefaultRecipe(player, key) +function Model.methods:setDefaultRecipeFactory(player, item, key, name) + local object = self:getObject(player, item, key) + local recipe = self:getDefaultRecipe(player, object.name) recipe.factory = name end @@ -2208,11 +2210,13 @@ end -- @function [parent=#Model] setDefaultRecipeBeacon -- -- @param #LuaPlayer player +-- @param #string item block_id or resource -- @param #string key recipe name -- @param #string name factory name -- -function Model.methods:setDefaultRecipeBeacon(player, key, name) - local recipe = self:getDefaultRecipe(player, key) +function Model.methods:setDefaultRecipeBeacon(player, item, key, name) + local object = self:getObject(player, item, key) + local recipe = self:getDefaultRecipe(player, object.name) recipe.beacon = name end