diff --git a/changelog.txt b/changelog.txt index bb16ea99..b068c753 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,12 @@ --------------------------------------------------------------------------------------------------- +Version: 0.9.10 +Date: 20. 10. 2019 + Changes: + - Added default and propagation beacon settings + - Added auto scroll when line move up/down + - Changed module table of cell when module count > 4 (on 2 row) + - Updated Russian locale (by Astorin) +--------------------------------------------------------------------------------------------------- Version: 0.9.9 Date: 19. 10. 2019 Features: diff --git a/controller/Controller.lua b/controller/Controller.lua index 2f3093bb..1ef60c38 100644 --- a/controller/Controller.lua +++ b/controller/Controller.lua @@ -658,9 +658,9 @@ function Controller:onEventAccessWrite(event) local recipes = Player.searchRecipe(event.item3) if #recipes == 1 then local recipe = recipes[1] - ModelBuilder.addRecipeIntoProductionBlock(recipe.name, recipe.type) + local new_recipe = ModelBuilder.addRecipeIntoProductionBlock(recipe.name, recipe.type) ModelCompute.update() - User.setParameter("scroll_down",true) + User.setParameter("scroll_element", new_recipe.id) self:send("on_gui_update", event) else self:send("on_gui_open", event,"HMRecipeSelector") @@ -707,6 +707,7 @@ function Controller:onEventAccessWrite(event) if event.control then step = 1000 end ModelBuilder.upProductionBlock(event.item1, step) ModelCompute.update() + User.setParameter("scroll_element", event.item1) self:send("on_gui_update", event) end @@ -716,6 +717,7 @@ function Controller:onEventAccessWrite(event) if event.control then step = 1000 end ModelBuilder.downProductionBlock(event.item1, step) ModelCompute.update() + User.setParameter("scroll_element", event.item1) self:send("on_gui_update", event) end end @@ -733,6 +735,7 @@ function Controller:onEventAccessWrite(event) if event.control then step = 1000 end ModelBuilder.upProductionRecipe(event.item1, event.item2, step) ModelCompute.update() + User.setParameter("scroll_element", event.item2) self:send("on_gui_update", event) end @@ -742,6 +745,7 @@ function Controller:onEventAccessWrite(event) if event.control then step = 1000 end ModelBuilder.downProductionRecipe(event.item1, event.item2, step) ModelCompute.update() + User.setParameter("scroll_element", event.item2) self:send("on_gui_update", event) end end diff --git a/core/ElementGui.lua b/core/ElementGui.lua index 7d0b4e94..68de282b 100644 --- a/core/ElementGui.lua +++ b/core/ElementGui.lua @@ -1284,8 +1284,9 @@ function ElementGui.addCellFactory(parent, factory, action, select, tooltip_name ElementGui.addGuiButtonSprite(row1, action, "entity", factory.name, nil, ({tooltip_name, Player.getLocalisedName(factory)})) end - local col_size = 2 - if display_cell_mod == "small-icon" then col_size = 5 end + local col_size = math.ceil(Model.countModulesModel(factory)/2) + if col_size < 2 then col_size = 2 end + if display_cell_mod == "small-icon" then col_size = col_size * 2 end local cell_factory_module = ElementGui.addGuiTable(row1,"factory-modules", col_size, "helmod_factory_modules") -- modules if factory.modules ~= nil then diff --git a/core/logging.lua b/core/logging.lua index c415debe..0e830068 100644 --- a/core/logging.lua +++ b/core/logging.lua @@ -3,6 +3,7 @@ Logging = {} local append_log=false local debug_level = 0 local debug_filter = "all" +local profiler = nil function Logging:new() self.limit = 5 @@ -12,6 +13,25 @@ function Logging:new() self:updateLevel() end +function Logging:profilerStart() + if profiler == nil then profiler = game.create_profiler() end + profiler.reset() +end + +function Logging:profilerReset() + if profiler ~= nil then + log(profiler) + profiler.reset() + end +end + +function Logging:profilerStop() + if profiler ~= nil then + log(profiler) + profiler.stop() + end +end + function Logging:checkClass(logClass) if debug_filter == "all" or debug_filter == logClass then return true end return false diff --git a/data/Model.lua b/data/Model.lua index 8be1e8f9..f3c3b98f 100644 --- a/data/Model.lua +++ b/data/Model.lua @@ -13,7 +13,10 @@ local Model = { -- 15°c initial_temp = 15, -- 200J/unit/°c - fluid_energy_per_unit = 200 + fluid_energy_per_unit = 200, + beacon_combo = 4, + beacon_factory = 1.2 + } ------------------------------------------------------------------------------- @@ -268,8 +271,8 @@ function Model.newBeacon(name, count) beaconModel.type = "item" beaconModel.count = count or 0 beaconModel.energy = 0 - beaconModel.combo = 4 - beaconModel.factory = 1.2 + beaconModel.combo = Model.beacon_combo + beaconModel.factory = Model.beacon_factory -- limit infini = 0 beaconModel.limit = 0 -- modules @@ -408,8 +411,10 @@ end -- function Model.countModulesModel(element) local count = 0 - for name, value in pairs(element.modules) do - count = count + value + if element ~= nil and element.modules ~= nil then + for name, value in pairs(element.modules) do + count = count + value + end end return count end @@ -569,13 +574,17 @@ end -- @param #string item block_id or resource -- @param #string key object name -- @param #string name beacon name +-- @param #number combo beacon combo +-- @param #number factory beacon factory -- -function Model.setBeacon(item, key, name) +function Model.setBeacon(item, key, name, combo, factory) local object = Model.getObject(item, key) if object ~= nil then local beacon_prototype = EntityPrototype(name) if beacon_prototype:native() ~= nil then object.beacon.name = name + object.beacon.combo = combo or Model.beacon_combo + object.beacon.factory = factory or Model.beacon_factory if Model.countModulesModel(object.beacon) >= beacon_prototype:getModuleInventorySize() then object.beacon.modules = {} end diff --git a/data/ModelBuilder.lua b/data/ModelBuilder.lua index 1ce847cd..885a1f67 100644 --- a/data/ModelBuilder.lua +++ b/data/ModelBuilder.lua @@ -15,6 +15,8 @@ local ModelBuilder = { -- @param #string key recipe name -- @param #string type recipe type -- +-- @return recipe +-- function ModelBuilder.addRecipeIntoProductionBlock(key, type) Logging:debug(ModelBuilder.classname, "addRecipeIntoProductionBlock()", key, type) local model = Model.getModel() @@ -82,7 +84,7 @@ function ModelBuilder.addRecipeIntoProductionBlock(key, type) local default_beacon = User.getDefaultBeacon(ModelRecipe) if default_beacon ~= nil then - Model.setBeacon(current_block, ModelRecipe.id, default_beacon.name) + Model.setBeacon(current_block, ModelRecipe.id, default_beacon.name, default_beacon.combo, default_beacon.factory) else local default_beacon_name = Model.getDefaultRecipeBeacon(lua_recipe.name) if default_beacon_name ~= nil then @@ -95,7 +97,7 @@ function ModelBuilder.addRecipeIntoProductionBlock(key, type) end Logging:debug(ModelBuilder.classname, "addRecipeIntoProductionBlock()", model.blocks[current_block]) - return model.blocks[current_block] + return ModelRecipe end end @@ -490,7 +492,7 @@ function ModelBuilder.setBeaconBlock(block_id, current_recipe) for key, recipe in pairs(block.recipes) do local prototype_recipe = RecipePrototype(recipe) if default_beacon_mode ~= "category" or prototype_recipe:getCategory() == RecipePrototype(current_recipe):getCategory() then - Model.setBeacon(block_id, key, current_recipe.beacon.name) + Model.setBeacon(block_id, key, current_recipe.beacon.name, current_recipe.beacon.combo, current_recipe.beacon.factory) if User.getParameter("default_beacon_with_module") == true then ModelBuilder.setBeaconModulePriority(block_id, key, current_recipe.beacon.module_priority) end diff --git a/data/ModelCompute.lua b/data/ModelCompute.lua index 63ee2a6d..370320dc 100644 --- a/data/ModelCompute.lua +++ b/data/ModelCompute.lua @@ -91,7 +91,7 @@ function ModelCompute.update() local beacon = recipe.beacon local _recipe = Player.getRecipe(recipe.name) Model.setFactory(productBlock.id, recipe.name, factory.name) - Model.setBeacon(productBlock.id, recipe.name, beacon.name) + Model.setBeacon(productBlock.id, recipe.name, beacon.name, beacon.combo, beacon.factory) if _recipe ~= nil then recipe.is_resource = not(_recipe.force) if recipe.is_resource then recipe.category = "extraction-machine" end diff --git a/data/User.lua b/data/User.lua index 2c54fe6b..09dba2b8 100644 --- a/data/User.lua +++ b/data/User.lua @@ -246,7 +246,7 @@ function User.setDefaultBeacon(recipe) local category = recipe_prototype:getCategory() local beacon = recipe.beacon if category ~= nil then - default_beacon[category] = {name = beacon.name} + default_beacon[category] = {name = beacon.name, combo = beacon.combo, factory = beacon.factory} User.setParameter("default_beacon", default_beacon) end end diff --git a/info.json b/info.json index 07b1bc8f..03616086 100644 --- a/info.json +++ b/info.json @@ -1,6 +1,6 @@ { "name": "helmod", - "version": "0.9.9", + "version": "0.9.10", "title": "Helmod: assistant for planning your base.", "author": "Helfima", "contact": "Helfima", diff --git a/prototypes/style.lua b/prototypes/style.lua index f009bc42..620a2197 100644 --- a/prototypes/style.lua +++ b/prototypes/style.lua @@ -1518,7 +1518,7 @@ for _,style in pairs(style_element_list) do bottom_padding = 2, left_padding = 0, - width = 80, + minimal_width = 80, horizontally_stretchable = "on", vertically_stretchable = "off" } @@ -1549,7 +1549,7 @@ for _,style in pairs(style_element_list) do bottom_padding = 2, left_padding = 0, - width = 50, + minimal_width = 50, horizontally_stretchable = "on", vertically_stretchable = "off" } @@ -1580,7 +1580,7 @@ for _,style in pairs(style_element_list) do bottom_padding = 2, left_padding = 0, - width = 30, + minimal_width = 30, horizontally_stretchable = "on", vertically_stretchable = "off" } diff --git a/selector/AbstractSelector.lua b/selector/AbstractSelector.lua index 84204fbb..a5ffbbb5 100644 --- a/selector/AbstractSelector.lua +++ b/selector/AbstractSelector.lua @@ -239,9 +239,9 @@ function AbstractSelector:onEvent(event) else -- classic selector if event.action == "element-select" and event.item1 ~= "container" then - local productionBlock = ModelBuilder.addRecipeIntoProductionBlock(event.item2, event.item1) + local new_recipe = ModelBuilder.addRecipeIntoProductionBlock(event.item2, event.item1) ModelCompute.update() - User.setParameter("scroll_down",true) + User.setParameter("scroll_element", new_recipe.id) User.setActiveForm("HMProductionBlockTab") Controller:send("on_gui_refresh", event) end @@ -408,10 +408,15 @@ function AbstractSelector:onUpdate(event) self:createElementLists() + --Logging:profilerStart() self:updateFilter(event) + --Logging:profilerReset() self:updateGroupSelector(event) + --Logging:profilerReset() self:updateItemList(event) -end + --Logging:profilerStop() + + end ------------------------------------------------------------------------------- -- Check filter @@ -635,10 +640,12 @@ function AbstractSelector:updateItemList(event) local list_subgroup = Cache.getData(self.classname, "list_subgroup") or {} local list_item = Cache.getData(self.classname, "list_item") or {} -- recuperation recipes et subgroupes - local recipe_selector_list = ElementGui.addGuiTable(item_list_panel, "recipe_list", 1, helmod_table_style.list) + --local recipe_selector_list = ElementGui.addGuiTable(item_list_panel, "recipe_list", 1, helmod_table_style.list) + local recipe_selector_list = GuiElement.add(item_list_panel, GuiFlowV("recipe_list")) for subgroup, list in spairs(list_item,function(t,a,b) return list_subgroup[b]["order"] > list_subgroup[a]["order"] end) do -- boucle subgroup - local guiRecipeSubgroup = ElementGui.addGuiTable(recipe_selector_list, "recipe-table-"..subgroup, 10, "helmod_table_recipe_selector") + --local guiRecipeSubgroup = ElementGui.addGuiTable(recipe_selector_list, "recipe-table-"..subgroup, 10, "helmod_table_recipe_selector") + local guiRecipeSubgroup = GuiElement.add(recipe_selector_list, GuiTable("recipe-table-", subgroup):column(10):style("helmod_table_recipe_selector")) for key, prototype in spairs(list,function(t,a,b) return t[b]["order"] > t[a]["order"] end) do local tooltip = self:buildPrototypeTooltip(prototype) self:buildPrototypeIcon(guiRecipeSubgroup, prototype, tooltip) diff --git a/selector/RecipeSelector.lua b/selector/RecipeSelector.lua index b872fb88..b7affa52 100644 --- a/selector/RecipeSelector.lua +++ b/selector/RecipeSelector.lua @@ -138,6 +138,6 @@ function RecipeSelector:buildPrototypeIcon(guiElement, prototype, tooltip) elseif recipe_prototype:getEnabled() == false then color = "red" end - --GuiElement.add(guiElement, GuiButtonSelectSprite(self.classname, "element-select", type):sprite(prototype.type), prototype_name.."1"):caption(prototype_localised_name):tooltip(tooltip):color(color)) - ElementGui.addGuiButtonSelectSprite(guiElement, self.classname.."=element-select=ID="..type.."=", prototype.type, prototype_name, prototype_localised_name, tooltip, color) + GuiElement.add(guiElement, GuiButtonSelectSprite(self.classname, "element-select=ID", type):sprite(prototype.type, prototype_name):caption(prototype_localised_name):tooltip(tooltip):color(color)) + --ElementGui.addGuiButtonSelectSprite(guiElement, self.classname.."=element-select=ID="..type.."=", prototype.type, prototype_name, prototype_localised_name, tooltip, color) end diff --git a/tab/ProductionBlockTab.lua b/tab/ProductionBlockTab.lua index 4db58879..41f4d2fd 100644 --- a/tab/ProductionBlockTab.lua +++ b/tab/ProductionBlockTab.lua @@ -6,7 +6,9 @@ require "tab.AbstractTab" -- @extends #AbstractTab -- -ProductionBlockTab = newclass(AbstractTab) +ProductionBlockTab = newclass(AbstractTab,function(base,classname) + AbstractTab.init(base,classname) +end) ------------------------------------------------------------------------------- -- Return button caption @@ -269,9 +271,7 @@ end -- @param #LuaEvent event -- function ProductionBlockTab:updateInput(event) - Logging:debug(self.classname, "updateInput", event) local model = Model.getModel() - Logging:debug(self.classname, "model:", model) -- data local current_block = User.getParameter("current_block") or "new" @@ -310,9 +310,7 @@ end -- @param #LuaEvent event -- function ProductionBlockTab:updateOutput(event) - Logging:debug(self.classname, "updateOutput", event) local model = Model.getModel() - Logging:debug(self.classname, "model:", model) -- data local current_block = User.getParameter("current_block") or "new" @@ -361,9 +359,8 @@ end -- @param #LuaEvent event -- function ProductionBlockTab:updateData(event) - Logging:debug("ProductionBlockTab", "updateData()", event) + Logging:debug(self.classname, "updateData()", event) local model = Model.getModel() - Logging:debug("ProductionBlockTab", "model:", model) local current_block = User.getParameter("current_block") or "new" self:updateInfo(event) @@ -423,12 +420,14 @@ function ProductionBlockTab:updateData(event) local last_element = nil for _, recipe in spairs(elements.recipes, function(t,a,b) return t[b]["index"] > t[a]["index"] end) do - last_element = self:addTableRow(result_table, elements, recipe) + local recipe_cell = self:addTableRow(result_table, elements, recipe) + if User.getParameter("scroll_element") == recipe.id then last_element = recipe_cell end end - if User.getParameter("scroll_down") then + Logging:debug(self.classname, "scroll_element", User.getParameter("scroll_element")) + if last_element ~= nil then scroll_panel2.scroll_to_element(last_element) - User.setParameter("scroll_down", false) + User.setParameter("scroll_element", nil) end end @@ -442,8 +441,6 @@ end -- @param #LuaGuiElement itable container for element -- function ProductionBlockTab:addTableHeader(itable) - Logging:debug("ProductionBlockTab", "addTableHeader()", itable) - self:addCellHeader(itable, "action", {"helmod_result-panel.col-header-action"}) -- optionnal columns self:addCellHeader(itable, "index", {"helmod_result-panel.col-header-index"},"index") diff --git a/tab/ProductionLineTab.lua b/tab/ProductionLineTab.lua index 28c82c35..b95141ce 100644 --- a/tab/ProductionLineTab.lua +++ b/tab/ProductionLineTab.lua @@ -40,7 +40,6 @@ end function ProductionLineTab:updateInfo(event) Logging:debug(self.classname, "updateInfo", event) local model = Model.getModel() - Logging:debug(self.classname, "model:", model) -- data local info_scroll, output_scroll, input_scroll = self:getInfoPanel() info_scroll.clear() @@ -90,7 +89,6 @@ end function ProductionLineTab:updateInput(event) Logging:debug(self.classname, "updateInput", event) local model = Model.getModel() - Logging:debug("ProductionBlockTab", "model:", model) -- data local info_scroll, output_scroll, input_scroll = self:getInfoPanel() input_scroll.clear() @@ -156,8 +154,7 @@ function ProductionLineTab:updateData(event) self:updateInput(event) -- data panel - local scrollPanel = self:getResultScrollPanel() - --test scrollPanel.add({type="choose-elem-button", elem_type="recipe"}) + local scroll_panel = self:getResultScrollPanel() local countBlock = Model.countBlocks() if countBlock > 0 then @@ -169,14 +166,20 @@ function ProductionLineTab:updateData(event) end end - local result_table = ElementGui.addGuiTable(scrollPanel,"list-data",5 + extra_cols, "helmod_table-odd") + local result_table = ElementGui.addGuiTable(scroll_panel,"list-data",5 + extra_cols, "helmod_table-odd") result_table.vertical_centering = false self:addTableHeader(result_table) - local i = 0 + local last_element = nil for _, element in spairs(model.blocks, function(t,a,b) return t[b]["index"] > t[a]["index"] end) do - self:addTableRow(result_table, element) + local element_cell = self:addTableRow(result_table, element) + if User.getParameter("scroll_element") == element.id then last_element = element_cell end + end + + if last_element ~= nil then + scroll_panel.scroll_to_element(last_element) + User.setParameter("scroll_element", nil) end end end @@ -278,4 +281,5 @@ function ProductionLineTab:addTableRow(gui_table, block) ElementGui.addCellElement(cell_ingredients, ingredient, self.classname.."=production-block-add=ID="..block.id.."="..ingredient.name.."=", true, "tooltip.add-recipe", ElementGui.color_button_add, index) end end + return cell_recipe end \ No newline at end of file