Skip to content

Commit

Permalink
add beacons menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Helfima committed Jul 7, 2023
1 parent 4208fec commit f5fd927
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 7 deletions.
44 changes: 44 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#vscode
.vscode/*

# Compiled Lua sources
luac.out

# luarocks build files
*.src.rock
*.zip
*.tar.gz

# Object files
*.o
*.os
*.ko
*.obj
*.elf

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo
*.def
*.exp

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

5 changes: 1 addition & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,19 @@
{
"type": "factoriomod",
"request": "launch",
"name": "Factorio Mod Debug",
"factorioPath": "E:/Perso/Factorio_Test/Factorio_1.1.x/bin/x64/factorio.exe"
"name": "Factorio Mod Debug"
},
{
"type": "factoriomod",
"request": "launch",
"name": "Factorio Mod Debug (Settings & Data)",
"factorioPath": "",
"hookSettings": true,
"hookData": true
},
{
"type": "factoriomod",
"request": "launch",
"name": "Factorio Mod Debug (Profile)",
"factorioPath": "",
"hookMode": "profile"
}
]
Expand Down
76 changes: 73 additions & 3 deletions edition/RecipeEdition.lua
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,26 @@ function RecipeEdition:getBeaconTablePanel()
table_panel.vertical_centering = false
local info_panel = GuiElement.add(table_panel, GuiFlowV(info_name))
info_panel.style.minimal_width = 250
GuiElement.add(info_panel, GuiLabel("beacon_label"):caption({"helmod_common.beacon"}):style("helmod_label_title_frame"))

local module_panel = GuiElement.add(table_panel, GuiFlowV(module_name))

module_panel.style.minimal_width = 300
return info_panel, module_panel
end

-------------------------------------------------------------------------------
---Get or create beacon selection panel
---@return LuaGuiElement
function RecipeEdition:getBeaconSelectionPanel()
local info_panel, module_panel = self:getBeaconTablePanel()
local selection_name = "beacon_selection"
if info_panel[selection_name] ~= nil and info_panel[selection_name].valid then
return info_panel[selection_name]
end
local selection_panel = GuiElement.add(info_panel, GuiFlowV(selection_name))
return selection_panel
end

-------------------------------------------------------------------------------
---Get or create beacon info panel
---@return LuaGuiElement, LuaGuiElement
Expand Down Expand Up @@ -374,6 +386,28 @@ function RecipeEdition:onEvent(event)
Controller:send("on_gui_refresh", event)
end

if event.action == "beacon-select" then
User.setParameter("current_beacon_selection", tonumber(event.item4))
self:update(event)
end

if event.action == "beacon-add" then
if recipe.beacons == nil then recipe.beacons = {} end
local new_beacon = Model.newBeacon()
table.insert(recipe.beacons, new_beacon)
User.setParameter("current_beacon_selection", #recipe.beacons)
self:update(event)
end

if event.action == "beacon-remove" then
local current_key = User.getParameter("current_beacon_selection") or 1
if #recipe.beacons > 1 then
table.remove(recipe.beacons, current_key)
end
User.setParameter("current_beacon_selection", #recipe.beacons)
self:update(event)
end

if event.action == "beacon-tool" then
if event.item4 == "default" then
User.setDefaultBeacon(recipe)
Expand Down Expand Up @@ -518,6 +552,7 @@ function RecipeEdition:onUpdate(event)
self:updateFactoryInfo(event)
self:updateFactoryModulesActive(event)
self:updateFactoryModules(event)
self:updateBeaconSelection(event)
self:updateBeaconInfoTool(event)
self:updateBeaconInfo(event)
self:updateBeaconModulesActive(event)
Expand Down Expand Up @@ -978,14 +1013,47 @@ function RecipeEdition:updateBeaconInfo(event)
end
end

---Update beacon tool
---@param event LuaEvent
function RecipeEdition:updateBeaconSelection(event)
local selection_panel = self:getBeaconSelectionPanel()
local model, block, recipe = self:getParameterObjects()

local tool_panel = GuiElement.add(selection_panel, GuiFlowH("tool1"))
tool_panel.style.horizontal_spacing = 5

GuiElement.add(tool_panel, GuiLabel("beacon_label"):caption({"helmod_common.beacon"}):style("helmod_label_title_frame"))
if recipe ~= nil then
local selection_panel = GuiElement.add(tool_panel, GuiFlowH("selections"))
selection_panel.style.horizontal_spacing = 2
selection_panel.style.horizontally_stretchable = true
selection_panel.style.horizontal_align = "right"
selection_panel.style.right_margin = 10

local beacons = recipe.beacons or {recipe.beacon}
local current_beacon_selection = User.getParameter("current_beacon_selection") or 1
for key, beacon in pairs(beacons) do
local style = "helmod_button_menu_sm_bold"
if current_beacon_selection == key then
style = "helmod_button_menu_sm_bold_selected"
end
GuiElement.add(selection_panel, GuiButton(self.classname, "beacon-select", model.id, block.id, recipe.id, key):caption(key):style(style))
end

GuiElement.add(selection_panel, GuiButton(self.classname, "beacon-add", model.id, block.id, recipe.id):sprite("menu", defines.sprites.add.black, defines.sprites.add.black):style("helmod_button_menu_sm"))
GuiElement.add(selection_panel, GuiButton(self.classname, "beacon-remove", model.id, block.id, recipe.id):sprite("menu", defines.sprites.remove.black, defines.sprites.remove.black):style("helmod_button_menu_sm"))
end
end
-------------------------------------------------------------------------------
---Update beacon tool
---@param event LuaEvent
function RecipeEdition:updateBeaconInfoTool(event)
local tool_panel, detail_panel = self:getBeaconInfoPanel()
local model, block, recipe = self:getParameterObjects()
if recipe ~= nil then
local beacon = recipe.beacon
local beacons = recipe.beacons or {recipe.beacon}
local current_beacon_selection = User.getParameter("current_beacon_selection") or 1
local beacon = beacons[current_beacon_selection]

tool_panel.clear()

Expand Down Expand Up @@ -1032,7 +1100,9 @@ function RecipeEdition:updateBeaconModulesActive(event)
local tool_panel, module_panel = self:getBeaconModulePanel()
local model, block, recipe = self:getParameterObjects()
if recipe ~= nil then
local beacon = recipe.beacon
local beacons = recipe.beacons or {recipe.beacon}
local current_beacon_selection = User.getParameter("current_beacon_selection") or 1
local beacon = beacons[current_beacon_selection]

tool_panel.clear()
GuiElement.add(tool_panel, GuiLabel("module_label"):caption({"helmod_recipe-edition-panel.current-modules"}):style("helmod_label_title_frame"))
Expand Down

0 comments on commit f5fd927

Please sign in to comment.