Skip to content

Commit

Permalink
Removed event on_research_finished
Browse files Browse the repository at this point in the history
  Bugfixes:
    - Fixed refresh when container change
    - Removed event on_research_finished (not need)
    - Fixed recipe selector (collision name)
  • Loading branch information
Helfima committed Sep 18, 2019
1 parent 1100119 commit ef9d2d0
Show file tree
Hide file tree
Showing 11 changed files with 233 additions and 7 deletions.
7 changes: 7 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
---------------------------------------------------------------------------------------------------
Version: 0.9.4
Date: 18. 09. 2019
Bugfixes:
- Fixed refresh when container change
- Removed event on_research_finished (not need)
- Fixed recipe selector (collision name)
---------------------------------------------------------------------------------------------------
Version: 0.9.3
Date: 18. 09. 2019
Features:
Expand Down
2 changes: 2 additions & 0 deletions controller/Controller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ require "dialog.StatusPanel"
require "dialog.Settings"
require "dialog.Download"
require "dialog.Calculator"
require "dialog.RecipeExplorer"
require "edition.RecipeEdition"
require "edition.ProductEdition"
require "edition.ResourceEdition"
Expand Down Expand Up @@ -71,6 +72,7 @@ function Controller:prepare()
table.insert(forms, HelpPanel("HMHelpPanel"))
table.insert(forms, Download("HMDownload"))
table.insert(forms, Calculator("HMCalculator"))
table.insert(forms, RecipeExplorer("HMRecipeExplorer"))

table.insert(forms, ProductionLineTab("HMProductionLineTab"))
table.insert(forms, ProductionBlockTab("HMProductionBlockTab"))
Expand Down
4 changes: 2 additions & 2 deletions controller/EventController.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function EventController.start()
EventController.pcallEvent(defines.events.on_player_joined_game, EventController.onPlayerJoinedGame)
EventController.pcallEvent(defines.events.on_runtime_mod_setting_changed, EventController.onRuntimeModSettingChanged)
EventController.pcallEvent(defines.events.on_console_command, EventController.onConsoleCommand)
EventController.pcallEvent(defines.events.on_research_finished, EventController.onResearchFinished)
--EventController.pcallEvent(defines.events.on_research_finished, EventController.onResearchFinished)
--EventController.pcallEvent(defines.events.on_gui_closed, EventController.onGuiClosed)

EventController.pcallNthTick(10, EventController.onNthTick)
Expand Down Expand Up @@ -128,7 +128,7 @@ end
--
function EventController.onResearchFinished(event)
Logging:trace(EventController.classname, "onResearchFinished(event)", event)
Controller:resetCaches()
Cache.reset()
--Player.print("Caches are reseted!")
end

Expand Down
210 changes: 210 additions & 0 deletions dialog/RecipeExplorer.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
-------------------------------------------------------------------------------
-- Class to build RecipeExplorer panel
--
-- @module RecipeExplorer
-- @extends #Form
--

RecipeExplorer = newclass(Form)

local display_panel = nil

-------------------------------------------------------------------------------
-- Initialization
--
-- @function [parent=#RecipeExplorer] init
--
function RecipeExplorer:onInit()
self.panelCaption = ({"helmod_recipe-explorer-panel.title"})
end

-------------------------------------------------------------------------------
-- On before event
--
-- @function [parent=#RecipeExplorer] onBeforeEvent
--
-- @param #LuaEvent event
--
-- @return #boolean if true the next call close dialog
--
function RecipeExplorer:onBeforeEvent(event)
-- close si nouvel appel
return true
end


-------------------------------------------------------------------------------
-- Get or create column panel
--
-- @function [parent=#RecipeExplorer] getColumnPanel
--
function RecipeExplorer:getColumnPanel()
local flow_panel, content_panel, menu_panel = self:getPanel()
if content_panel["main_panel"] ~= nil and content_panel["main_panel"].valid then
return content_panel["main_panel"]["display_panel1"], content_panel["main_panel"]["display_panel2"]
end
local panel = ElementGui.addGuiFlowH(content_panel, "main_panel", helmod_flow_style.horizontal)
local display_panel1 = ElementGui.addGuiFlowV(panel, "display_panel1", helmod_flow_style.vertical)
local display_panel2 = ElementGui.addGuiFlowV(panel, "display_panel2", helmod_flow_style.vertical)
display_panel2.style.width=200

return display_panel1, display_panel2
end

-------------------------------------------------------------------------------
-- Get or create display panel
--
-- @function [parent=#RecipeExplorer] getDisplayPanel
--
function RecipeExplorer:getDisplayPanel()
local display_panel1, display_panel2 = self:getColumnPanel()
if display_panel1["display"] ~= nil and display_panel1["display"].valid then
return display_panel1["display"]
end
return ElementGui.addGuiFrameV(display_panel1, "display", helmod_frame_style.panel)
end

-------------------------------------------------------------------------------
-- Get or create keyboard panel
--
-- @function [parent=#RecipeExplorer] getKeyboardPanel
--
function RecipeExplorer:getKeyboardPanel()
local display_panel1, display_panel2 = self:getColumnPanel()
if display_panel1["keyboard"] ~= nil and display_panel1["keyboard"].valid then
return display_panel1["keyboard"]
end
local panel = ElementGui.addGuiFrameV(display_panel1, "keyboard", helmod_frame_style.panel)
panel.style.horizontally_stretchable = true
return panel
end

-------------------------------------------------------------------------------
-- Get or create history panel
--
-- @function [parent=#RecipeExplorer] getHistoryPanel
--
function RecipeExplorer:getHistoryPanel()
local display_panel1, display_panel2 = self:getColumnPanel()
if display_panel2["history"] ~= nil and display_panel2["history"].valid then
return display_panel2["history"]
end
local panel = ElementGui.addGuiFrameV(display_panel2, "history", helmod_frame_style.panel)
panel.style.horizontally_stretchable = true
panel.style.vertically_stretchable = true
return panel
end

-------------------------------------------------------------------------------
-- On event
--
-- @function [parent=#RecipeExplorer] onEvent
--
-- @param #LuaEvent event
--
function RecipeExplorer:onEvent(event)
Logging:debug(self.classname, "onEvent()", event)
-- import
if event.action == "compute" then
local text = event.element.text
local ok , err = pcall(function()
local result = formula(text)
self:addHistory(text, result)
User.setParameter("RecipeExplorer_value", result or 0)
self:updateDisplay()
self:updateHistory()
end)
if not(ok) then
Player.print("Formula is not valid!")
end
end
if event.action == "selected-key" then
if event.item1 == "enter" then
local ok , err = pcall(function()
local RecipeExplorer_value = User.getParameter("RecipeExplorer_value") or 0
local result = formula(RecipeExplorer_value)
self:addHistory(RecipeExplorer_value, result)
User.setParameter("RecipeExplorer_value", result or 0)
self:updateDisplay()
self:updateHistory()
end)
if not(ok) then
Player.print("Formula is not valid!")
end
elseif event.item1 == "clear" then
User.setParameter("RecipeExplorer_value", 0)
self:updateDisplay()
else
local RecipeExplorer_value = User.getParameter("RecipeExplorer_value") or 0
if RecipeExplorer_value == 0 then RecipeExplorer_value = "" end
User.setParameter("RecipeExplorer_value", RecipeExplorer_value..event.item1)
self:updateDisplay()
end
end
end

-------------------------------------------------------------------------------
-- Add history
--
-- @function [parent=#RecipeExplorer] addHistory
--
-- @param #string RecipeExplorer_value
-- @param #number result
--
function RecipeExplorer:addHistory(RecipeExplorer_value, result)
if RecipeExplorer_value ~= result then
local RecipeExplorer_history = User.getParameter("RecipeExplorer_history") or {}
table.insert(RecipeExplorer_history,1,string.format("%s=%s",RecipeExplorer_value,result))
if #RecipeExplorer_history > 9 then table.remove(RecipeExplorer_history,#RecipeExplorer_history) end
User.setParameter("RecipeExplorer_history", RecipeExplorer_history)
end
end

-------------------------------------------------------------------------------
-- On update
--
-- @function [parent=#RecipeExplorer] RecipeExplorer
--
-- @param #LuaEvent event
--
function RecipeExplorer:onUpdate(event)
self:updateDisplay(item, item2, item3)
self:updateKeyboard(item, item2, item3)
self:updateHistory(item, item2, item3)
end

-------------------------------------------------------------------------------
-- Update display
--
-- @function [parent=#RecipeExplorer] updateDisplay
--
function RecipeExplorer:updateDisplay()
Logging:debug(self.classname, "updateDisplay()")
local keyboard_panel = self:getDisplayPanel()
keyboard_panel.clear()

--local table_panel = ElementGui.addGuiTable(keyboard_panel,"keys",2)
local RecipeExplorer_value = User.getParameter("RecipeExplorer_value") or 0
display_panel = ElementGui.addGuiText(keyboard_panel,self.classname.."=compute=ID=",RecipeExplorer_value,"helmod_textfield_RecipeExplorer")
--display_panel.style.horizontally_stretchable = true
display_panel.style.width=155
display_panel.style.horizontal_align = "right"
display_panel.focus()
end

-------------------------------------------------------------------------------
-- Update history
--
-- @function [parent=#RecipeExplorer] updateHistory
--
function RecipeExplorer:updateHistory()
Logging:debug(self.classname, "updateHistory()")
local history_panel = self:getHistoryPanel()
history_panel.clear()

local RecipeExplorer_history = User.getParameter("RecipeExplorer_history") or {}
for index, line in pairs(RecipeExplorer_history) do
ElementGui.addGuiLabel(history_panel,string.format("history_%s",index),line)
end

end
Binary file modified graphics/icons/menu_icons.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.3",
"version": "0.9.4",
"title": "Helmod: assistant for planning your base.",
"author": "Helfima",
"contact": "Helfima",
Expand Down
3 changes: 3 additions & 0 deletions locale/en/helmod.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ mod-info=Now the options are in the Options/Mods menu of the game
[helmod_preferences-edition-panel]
title=Preferences

[helmod_recipe-explorer-panel]
title=Recipe Explorer

data-section=Data table
model-section=Model
other-section=Other
Expand Down
3 changes: 2 additions & 1 deletion prototypes/style.lua
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ local list = {
{name="robot"},
{name="ok"},
{name="checkmark"},
{name="services"}
{name="services"},
{name="search"}
}
for icon_row,icon in pairs(list) do
menuIcons(icon.name, icon_row, icon.font)
Expand Down
3 changes: 2 additions & 1 deletion selector/AbstractSelector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ function AbstractSelector:onEvent(event)
if type == "fluid-wagon" then
User.setParameter("vehicle_fluid",event.item2)
end
Controller:send("on_gui_refresh", event)
end
end
end
Expand Down Expand Up @@ -506,7 +507,7 @@ function AbstractSelector:onCreateElementLists()
local filter_show_disable = User.getSetting("filter_show_disable")
local filter_show_hidden = User.getSetting("filter_show_hidden")

-- list_products[element.name][group_name][lua_recipe.name]
-- list_products[element.name][type - lua_recipe.name]
for key, element in pairs(list) do
-- filter sur le nom element (product ou ingredient)
if self:checkFilter(key) then
Expand Down
5 changes: 3 additions & 2 deletions selector/RecipeSelector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,16 @@ function RecipeSelector:appendGroups(element, type, list_products, list_ingredie
local prototype = self:getPrototype(element, type)

local lua_prototype = prototype:native()
local prototype_name = string.format("%s-%s",type , lua_prototype.name)
Logging:trace(self.classname, "lua_recipe", lua_prototype)
for key, element in pairs(prototype:getRawProducts()) do
if list_products[element.name] == nil then list_products[element.name] = {} end
list_products[element.name][lua_prototype.name] = {name=lua_prototype.name, group=lua_prototype.group.name, subgroup=lua_prototype.subgroup.name, type=type, order=lua_prototype.order}
list_products[element.name][prototype_name] = {name=lua_prototype.name, group=lua_prototype.group.name, subgroup=lua_prototype.subgroup.name, type=type, order=lua_prototype.order}
loop.product = loop.product + 1
end
for key, element in pairs(prototype:getRawIngredients()) do
if list_ingredients[element.name] == nil then list_ingredients[element.name] = {} end
list_ingredients[element.name][lua_prototype.name] = {name=lua_prototype.name, group=lua_prototype.group.name, subgroup=lua_prototype.subgroup.name, type=type, order=lua_prototype.order}
list_ingredients[element.name][prototype_name] = {name=lua_prototype.name, group=lua_prototype.group.name, subgroup=lua_prototype.subgroup.name, type=type, order=lua_prototype.order}
loop.ingredient = loop.ingredient + 1
end

Expand Down
1 change: 1 addition & 0 deletions tab/AbstractTab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ function AbstractTab:updateMenuPanel(event)
ElementGui.addGuiButton(group1, "HMTechnologySelector=OPEN=ID=", block_id, "helmod_button_icon_graduation",nil, ({"helmod_result-panel.add-button-technology"}))
ElementGui.addGuiButton(group1, "HMContainerSelector=OPEN=ID=", block_id, "helmod_button_icon_container",nil, ({"helmod_result-panel.select-button-container"}))
--ElementGui.addGuiButton(group1, "HMPreferenceEdition=OPEN=ID=", block_id, "helmod_button_icon_services",nil, {"helmod_button.preferences"})
--ElementGui.addGuiButton(group1, "HMRecipeExplorer=OPEN=ID=", block_id, "helmod_button_icon_search",nil, {"helmod_button.search"})

local group2 = ElementGui.addGuiFlowH(action_panel,"group2",helmod_flow_style.horizontal)
-- copy past
Expand Down

0 comments on commit ef9d2d0

Please sign in to comment.