-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfixes: - Fixed refresh when container change - Removed event on_research_finished (not need) - Fixed recipe selector (collision name)
- Loading branch information
Showing
11 changed files
with
233 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters