Skip to content

Commit

Permalink
Added default and propagation beacon settings
Browse files Browse the repository at this point in the history
  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)
  • Loading branch information
Helfima committed Oct 20, 2019
1 parent 408b15f commit 0b95fe9
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 45 deletions.
8 changes: 8 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
8 changes: 6 additions & 2 deletions controller/Controller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions core/ElementGui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions core/logging.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
21 changes: 15 additions & 6 deletions data/Model.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

}

-------------------------------------------------------------------------------
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions data/ModelBuilder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion data/ModelCompute.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion data/User.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion info.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 3 additions & 3 deletions prototypes/style.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down Expand Up @@ -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"
}
Expand Down Expand Up @@ -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"
}
Expand Down
17 changes: 12 additions & 5 deletions selector/AbstractSelector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions selector/RecipeSelector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 9 additions & 12 deletions tab/ProductionBlockTab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand Down
Loading

0 comments on commit 0b95fe9

Please sign in to comment.