Skip to content

Commit

Permalink
Added class User
Browse files Browse the repository at this point in the history
Added class User
Fixed UI (stable)
  • Loading branch information
Helfima committed Aug 23, 2019
1 parent 7d4f15b commit f8e8778
Show file tree
Hide file tree
Showing 46 changed files with 890 additions and 1,147 deletions.
330 changes: 131 additions & 199 deletions controller/Controller.lua

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion core/Command.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ function Command.parse(event)
elseif string.lower(event.parameters) == "unittest" then
UnitTest.run(event)
elseif string.lower(event.parameters) == "resetuserui" then
Player.resetGlobal()
User.reset()
Player.print("User UI are reseted!")
elseif string.lower(event.parameters) == "resetuserallui" then
User.resetAll()
Player.print("User UI are reseted!")
elseif string.lower(event.parameters) == "resetcaches" then
Controller.resetCaches()
Expand Down
44 changes: 22 additions & 22 deletions core/ElementGui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ end
--
function ElementGui.addCellLabel(parent, name, label, minimal_width)
Logging:trace(ElementGui.classname, "addCellLabel()", name, label, minimal_width)
local display_cell_mod = Player.getSettings("display_cell_mod")
local display_cell_mod = User.getModGlobalSetting("display_cell_mod")
local cell = ElementGui.addCell(parent, "cell_"..name)

if display_cell_mod == "small-text"then
Expand Down Expand Up @@ -901,7 +901,7 @@ end
--
function ElementGui.addCellLabel2(parent, name, label1, label2, minimal_width)
Logging:trace(ElementGui.classname, "addCellLabel()", name, label1, label2, minimal_width)
local display_cell_mod = Player.getSettings("display_cell_mod")
local display_cell_mod = User.getModGlobalSetting("display_cell_mod")
local cell = ElementGui.addCell(parent, "cell_"..name, 1)

if display_cell_mod == "small-text"then
Expand Down Expand Up @@ -938,7 +938,7 @@ end
--
function ElementGui.addCellIcon(parent, element, action, select, tooltip_name, color)
Logging:trace(ElementGui.classname, "addCellIcon()", element, action, select, tooltip_name, color)
local display_cell_mod = Player.getSettings("display_cell_mod")
local display_cell_mod = User.getModGlobalSetting("display_cell_mod")
-- ingredient = {type="item", name="steel-plate", amount=8}
if display_cell_mod == "small-icon" then
if parent ~= nil and select == true then
Expand Down Expand Up @@ -969,7 +969,7 @@ end
--
function ElementGui.addCellElement(parent, element, action, select, tooltip_name, color, index)
Logging:trace(ElementGui.classname, "addCellElement()", element, action, select, tooltip_name, color)
local display_cell_mod = Player.getSettings("display_cell_mod")
local display_cell_mod = User.getModGlobalSetting("display_cell_mod")
-- ingredient = {type="item", name="steel-plate", amount=8}
local button = nil
color = color or "blue"
Expand Down Expand Up @@ -1013,7 +1013,7 @@ end
--
function ElementGui.addCellElementSm(parent, element, action, select, tooltip_name, color, index)
Logging:trace(ElementGui.classname, "addCellElementSm()", element, action, select, tooltip_name, color)
local display_cell_mod = Player.getSettings("display_cell_mod")
local display_cell_mod = User.getModGlobalSetting("display_cell_mod")
-- ingredient = {type="item", name="steel-plate", amount=8}
local button = nil
color = color or "blue"
Expand Down Expand Up @@ -1055,7 +1055,7 @@ end
--
function ElementGui.addCellElementM(parent, element, action, select, tooltip_name, color, index)
Logging:trace(ElementGui.classname, "addCellElementM()", element, action, select, tooltip_name, color)
local display_cell_mod = Player.getSettings("display_cell_mod")
local display_cell_mod = User.getModGlobalSetting("display_cell_mod")
-- ingredient = {type="item", name="steel-plate", amount=8}
local button = nil
color = color or "blue"
Expand Down Expand Up @@ -1097,7 +1097,7 @@ end
--
function ElementGui.addCellProduct(parent, element, action, select, tooltip_name, color, index)
Logging:trace(ElementGui.classname, "addCellProduct():", element, action, select, tooltip_name, color)
local display_cell_mod = Player.getSettings("display_cell_mod")
local display_cell_mod = User.getModGlobalSetting("display_cell_mod")
-- ingredient = {type="item", name="steel-plate", amount=8}
local button = nil
color = color or "blue"
Expand Down Expand Up @@ -1127,7 +1127,7 @@ end
--
function ElementGui.addCellProductSm(parent, element, action, select, tooltip_name, color, index)
Logging:trace(ElementGui.classname, "addCellProductSm():", element, action, select, tooltip_name, color)
local display_cell_mod = Player.getSettings("display_cell_mod")
local display_cell_mod = User.getModGlobalSetting("display_cell_mod")
-- ingredient = {type="item", name="steel-plate", amount=8}
local button = nil
color = color or "blue"
Expand Down Expand Up @@ -1157,7 +1157,7 @@ end
--
function ElementGui.addCellFactory(parent, factory, action, select, tooltip_name, color)
Logging:trace(ElementGui.classname, "addCellFactory():", factory, action, select, tooltip_name, color)
local display_cell_mod = Player.getSettings("display_cell_mod")
local display_cell_mod = User.getModGlobalSetting("display_cell_mod")
-- ingredient = {type="item", name="steel-plate", amount=8}
local button = nil
color = color or "green"
Expand Down Expand Up @@ -1200,7 +1200,7 @@ end
--
function ElementGui.addCellRecipe(parent, recipe, action, select, tooltip_name, color)
Logging:trace(ElementGui.classname, "addCellRecipe():", recipe, action, select, tooltip_name, color)
local display_cell_mod = Player.getSettings("display_cell_mod")
local display_cell_mod = User.getModGlobalSetting("display_cell_mod")
-- ingredient = {type="item", name="steel-plate", amount=8}
local button = nil
color = color or "green"
Expand Down Expand Up @@ -1228,7 +1228,7 @@ end
--
function ElementGui.addCellBlock(parent, block, action, select, tooltip_name, color)
Logging:trace(ElementGui.classname, "addCellRecipe():", block, action, select, tooltip_name, color)
local display_cell_mod = Player.getSettings("display_cell_mod")
local display_cell_mod = User.getModGlobalSetting("display_cell_mod")
-- ingredient = {type="item", name="steel-plate", amount=8}
local button = nil
color = color or "green"
Expand Down Expand Up @@ -1256,7 +1256,7 @@ end
--
function ElementGui.addCellEnergy(parent, recipe, action, select, tooltip_name, color)
Logging:trace(ElementGui.classname, "addCellEnergy():", recipe, action, select, tooltip_name, color)
local display_cell_mod = Player.getSettings("display_cell_mod")
local display_cell_mod = User.getModGlobalSetting("display_cell_mod")
-- ingredient = {type="item", name="steel-plate", amount=8}
local button = nil
color = color or "green"
Expand All @@ -1281,20 +1281,20 @@ end
--
function ElementGui.addCellCargoInfo(parent, element)
Logging:trace(ElementGui.classname, "addCellCargoInfo():", element)
local globalGui = Player.getGlobalGui()
local parameters = User.getParameter()
Product.load(element)
if Product.native() ~= nil then
local table_cargo = ElementGui.addGuiTable(parent,"element_cargo", 1, "helmod_beacon_modules")
if element.type == 0 or element.type == "item" then
local container_solid = globalGui.container_solid or "steel-chest"
local vehicle_solid = globalGui.vehicle_solid or "cargo-wagon"
local container_solid = parameters.container_solid or "steel-chest"
local vehicle_solid = parameters.vehicle_solid or "cargo-wagon"
ElementGui.addGuiButtonSpriteSm(table_cargo, container_solid, "item", container_solid, nil, ElementGui.getTooltipProduct(element, container_solid))
ElementGui.addGuiButtonSpriteSm(table_cargo, vehicle_solid, "item", vehicle_solid, nil, ElementGui.getTooltipProduct(element, vehicle_solid))
end

if element.type == 1 or element.type == "fluid" then
local container_fluid = globalGui.container_fluid or "storage-tank"
local vehicle_fluid = globalGui.wagon_fluid or "fluid-wagon"
local container_fluid = parameters.container_fluid or "storage-tank"
local vehicle_fluid = parameters.wagon_fluid or "fluid-wagon"
ElementGui.addGuiButtonSpriteSm(table_cargo, container_fluid, "item", container_fluid, nil, ElementGui.getTooltipProduct(element, container_fluid))
ElementGui.addGuiButtonSpriteSm(table_cargo, vehicle_fluid, "item", vehicle_fluid, nil, ElementGui.getTooltipProduct(element, vehicle_fluid))
end
Expand Down Expand Up @@ -1479,8 +1479,8 @@ end
--
function ElementGui.getStyleSizes()
Logging:trace(ElementGui.classname, "getStyleSizes()")
local display_ratio_horizontal = Player.getSettings("display_ratio_horizontal")
local display_ratio_vertictal = Player.getSettings("display_ratio_vertical")
local display_ratio_horizontal = User.getModGlobalSetting("display_ratio_horizontal")
local display_ratio_vertictal = User.getModGlobalSetting("display_ratio_vertical")

local width , height = ElementGui.getDisplaySizes()
local style_sizes = {}
Expand Down Expand Up @@ -1579,7 +1579,7 @@ function ElementGui.getStyleSizes()
style_sizes.scroll_block_list.minimal_width = width_main - width_dialog - width_scroll
style_sizes.scroll_block_list.maximal_width = width_main - width_dialog - width_scroll

if Player.getSettings("debug", true) ~= "none" then
if User.getModGlobalSetting("debug") ~= "none" then
style_sizes.scroll_block_list.minimal_height = height_main - height_block_header - 200
style_sizes.scroll_block_list.maximal_height = height_main - height_block_header - 200
else
Expand All @@ -1602,7 +1602,7 @@ end
--
function ElementGui.getIndexColumnNumber()

local display_ratio_horizontal = Player.getSettings("display_ratio_horizontal")
local display_ratio_horizontal = User.getModGlobalSetting("display_ratio_horizontal")
local width , height = ElementGui.getDisplaySizes()
local width_main = math.ceil(width*display_ratio_horizontal)

Expand All @@ -1620,7 +1620,7 @@ end
--
function ElementGui.getElementColumnNumber(size)

local display_ratio_horizontal = Player.getSettings("display_ratio_horizontal")
local display_ratio_horizontal = User.getModGlobalSetting("display_ratio_horizontal")
local width , height = ElementGui.getDisplaySizes()
local width_main = math.ceil(width*display_ratio_horizontal)
Logging:debug(ElementGui.classname, "getElementColumnNumber(width)", width_main, math.ceil((width_main-600)/(2*size)))
Expand Down
40 changes: 22 additions & 18 deletions core/Form.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function Form.methods:init(parent)
self.locate = "screen"
self.panelClose = true
self.help_button = true
self.auto_clear = true

self:onInit(parent)
end
Expand Down Expand Up @@ -55,6 +56,17 @@ function Form.methods:isSpecial()
return false
end

-------------------------------------------------------------------------------
-- Get panel name
--
-- @function [parent=#Form] getPanelName
--
-- @return #LuaGuiElement
--
function Form.methods:getPanelName()
return self:classname()
end

-------------------------------------------------------------------------------
-- Get the parent panel
--
Expand All @@ -75,21 +87,15 @@ end
-- @return #LuaGuiElement
--
function Form.methods:getPanel()
local ui = Player.getGlobalUI()
local parent_panel = self:getParentPanel()
if parent_panel[self:classname()] ~= nil and parent_panel[self:classname()].valid then
return parent_panel[self:classname()]
if parent_panel[self:getPanelName()] ~= nil and parent_panel[self:getPanelName()].valid then
return parent_panel[self:getPanelName()]
end
if parent_panel.name == self.locate then
local panel = ElementGui.addGuiFrameV(parent_panel, self:classname(), helmod_frame_style.default, self.panelCaption or self:classname())
local panel = ElementGui.addGuiFrameV(parent_panel, self:getPanelName(), helmod_frame_style.default, self.panelCaption or self:classname())
panel.style.horizontally_stretchable = true
panel.style.vertically_stretchable = true
local location = Controller.getLocationForm(self:classname())
if location ~= nil then
panel.location = location
else
panel.force_auto_center()
end
panel.location = User.getLocationForm(self:getPanelName())
ElementGui.setStyle(panel, self:classname(), "width")
ElementGui.setStyle(panel, self:classname(), "height")
--Logging:debug(self:classname(), "children",panel.children_names)
Expand Down Expand Up @@ -191,7 +197,7 @@ end
function Form.methods:open(event, action, item, item2, item3)
Logging:debug(self:classname(), "open()", action, item, item2, item3)
local parent_panel = self:getParentPanel()
if parent_panel[self:classname()] == nil then
if parent_panel[self:getPanelName()] == nil then
self:onOpen(event, action, item, item2, item3)
end
end
Expand All @@ -211,7 +217,7 @@ function Form.methods:beforeEvent(event, action, item, item2, item3)
Logging:debug(self:classname(), "beforeEvent()", action, item, item2, item3)
local parent_panel = self:getParentPanel()
local close = self:onBeforeEvent(event, action, item, item2, item3)
if parent_panel ~= nil and parent_panel[self:classname()] ~= nil and parent_panel[self:classname()].valid then
if parent_panel ~= nil and parent_panel[self:getPanelName()] ~= nil and parent_panel[self:getPanelName()].valid then
Logging:debug(self:classname() , "must close?",close)
if close and action == "OPEN" then
self:close(true)
Expand Down Expand Up @@ -300,9 +306,9 @@ function Form.methods:updateTitle(event, action, item, item2, item3)
if self.panelClose then
local group1 = ElementGui.addGuiFlowH(right_menu_panel,"group1",helmod_flow_style.horizontal)
for _, form in pairs(Controller.getViews()) do
if string.find(form:classname(), "Tab") and form:isVisible() and form:isSpecial() then
if string.find(self:classname(), "Tab") and string.find(form:classname(), "Tab") and form:isVisible() and form:isSpecial() then
local style, selected_style = form:getButtonStyles()
if Controller.isActiveForm(form:classname()) then style = selected_style end
if User.isActiveForm(form:classname()) then style = selected_style end
ElementGui.addGuiButton(group1, self:classname().."=change-tab=ID=", form:classname(), style, nil, form:getButtonCaption())
end
end
Expand Down Expand Up @@ -330,8 +336,7 @@ end
function Form.methods:update(event, action, item, item2, item3)
Logging:debug(self:classname(), "update():", action, item, item2, item3)
local panel = self:getPanel()
panel.clear()
panel.focus()
if self.auto_clear then panel.clear() end

self:updateTitle(event, action, item, item2, item3)
self:onUpdate(event, action, item, item2, item3)
Expand Down Expand Up @@ -361,9 +366,8 @@ end
--
function Form.methods:close(force)
Logging:debug(self:classname(), "close()")
local ui = Player.getGlobalUI()
local panel = self:getPanel()
Controller.setCloseForm(self:classname(), panel.location)
User.setCloseForm(self:classname(), panel.location)
self:onClose()
panel.destroy()
end
Expand Down
4 changes: 2 additions & 2 deletions core/Format.lua
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ end
--
function Format.formatNumberFactory(number)
local decimal = 2
local format_number = Player.getSettings("format_number_factory", true)
local format_number = User.getModGlobalSetting("format_number_factory")
if format_number == "0" then decimal = 0 end
if format_number == "0.0" then decimal = 1 end
if format_number == "0.00" then decimal = 2 end
Expand All @@ -136,7 +136,7 @@ end
--
function Format.formatNumberElement(number)
local decimal = 2
local format_number = Player.getSettings("format_number_element", true)
local format_number = User.getModGlobalSetting("format_number_element")
if format_number == "0" then decimal = 0 end
if format_number == "0.0" then decimal = 1 end
if format_number == "0.00" then decimal = 2 end
Expand Down
Loading

0 comments on commit f8e8778

Please sign in to comment.