Skip to content

Commit

Permalink
Finalize new UI
Browse files Browse the repository at this point in the history
Finalize new UI
Fixed module limitation
  • Loading branch information
Helfima committed Aug 23, 2019
1 parent f8e8778 commit 4a47c72
Show file tree
Hide file tree
Showing 26 changed files with 340 additions and 236 deletions.
6 changes: 3 additions & 3 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---------------------------------------------------------------------------------------------------
Version: 0.8.19
Date: 19. 08. 2019
Features:
Version: 0.9.0
Date: 23. 08. 2019
Changes:
- Changed UI, now draggable
- Changed cache operation
Bugfixes:
- Fixed module limitation
Expand Down
60 changes: 42 additions & 18 deletions controller/Controller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ function Controller.init()
Logging:debug(Controller.classname, "init()")

local controllers = {}
table.insert(controllers, Settings:new())
table.insert(controllers, HelpPanel:new())
table.insert(controllers, Download:new())

Expand Down Expand Up @@ -158,7 +157,7 @@ function Controller.cleanController(player)
if string.find(children_name,"helmod") then
lua_gui_element[children_name].destroy()
end
if Controller.getView(children_name) then
if Controller.getView(children_name) and children_name ~= "HMPinPanel" then
Controller.getView(children_name):close()
end
if children_name == "HMTab" then
Expand All @@ -172,6 +171,23 @@ function Controller.cleanController(player)
end
end

-------------------------------------------------------------------------------
-- closeEditionOrSelector
--
-- @function [parent=#Controller] closeEditionOrSelector
--
-- @param #LuaPlayer player
--
function Controller.closeEditionOrSelector()
Logging:trace(Controller.classname, "closeEditionOrSelector()")
local lua_gui_element = Player.getGui("screen")
for _,children_name in pairs(lua_gui_element.children_names) do
if Controller.getView(children_name) and (string.find(children_name,"Edition") ~= nil) then
Controller.getView(children_name):close()
end
end
end

-------------------------------------------------------------------------------
-- Bind all controllers
--
Expand All @@ -187,7 +203,7 @@ function Controller.bindController(player)
if lua_gui_element["helmod_planner-command"] ~= nil then lua_gui_element["helmod_planner-command"].destroy() end

lua_gui_element = ModGui.get_button_flow(Player.native())
if not(User.getModSetting("display_main_icon")) or User.getVersion() < "0.8.18" then
if not(User.getModSetting("display_main_icon")) or User.getVersion() < User.version then
if lua_gui_element["helmod_planner-command"] ~= nil then lua_gui_element["helmod_planner-command"].destroy() end
end
if lua_gui_element ~= nil and lua_gui_element["helmod_planner-command"] == nil and User.getModSetting("display_main_icon") then
Expand All @@ -196,6 +212,11 @@ function Controller.bindController(player)
gui_button.style.width = 37
gui_button.style.height = 37
end
if User.getVersion() < User.version then
local message = string.format("%s %s: %s","Helmod",game.active_mods["helmod"], "Now every panel is draggable.")
Player.print(message)
end
User.update()
end
end

Expand Down Expand Up @@ -334,32 +355,32 @@ function Controller.sendEvent(event, classname, action, item, item2, item3)
end

if Event.prepare == false then
Logging:debug(Controller.classname, "-> prepare", game.tick)
Logging:trace(Controller.classname, "-> prepare", game.tick)
if action == "OPEN" then
User.setActiveForm(classname)
end

Logging:debug(Controller.classname, "-> before event: navigate", navigate)
Logging:trace(Controller.classname, "-> before event: navigate", navigate)

for _,form in pairs(views) do
local form_name = form:classname()
Logging:debug(Controller.classname, "--> beforeEvent", form_name, classname)
Logging:trace(Controller.classname, "--> beforeEvent", form_name, classname)
if form_name == classname and User.isActiveForm(form_name) then
form:beforeEvent(event, action, item, item2, item3)
end
end

for _,form in pairs(views) do
local form_name = form:classname()
Logging:debug(Controller.classname, "--> onEvent", form_name, classname)
Logging:trace(Controller.classname, "--> onEvent", form_name, classname)
if form_name == classname and User.isActiveForm(form_name) then
form:onEvent(event, action, item, item2, item3)
end
end

for _,form in pairs(views) do
local form_name = form:classname()
Logging:debug(Controller.classname, "--> prepare", form_name)
Logging:trace(Controller.classname, "--> prepare", form_name)
if User.isActiveForm(form_name) then
local prepared = form:prepare(event, action, item, item2, item3)
if(prepared == true) then
Expand All @@ -374,17 +395,17 @@ function Controller.sendEvent(event, classname, action, item, item2, item3)
end
end

Logging:debug(Controller.classname, "-> open and update", game.tick)
Logging:trace(Controller.classname, "-> open and update", game.tick)
for _,form in pairs(views) do
local form_name = form:classname()
Logging:debug(Controller.classname, "--> open and update", form_name, User.isActiveForm(form_name))
Logging:trace(Controller.classname, "--> open and update", form_name, User.isActiveForm(form_name))
if User.isActiveForm(form_name) then
if action == "OPEN" or Event.force_open == true then
Logging:debug(Controller.classname, "---> open form", form_name)
Logging:trace(Controller.classname, "---> open form", form_name)
form:open(event, action, item, item2, item3)
end
if not(action ~= "OPEN" and form_name == classname) or Event.force_refresh == true then
Logging:debug(Controller.classname, "---> update form", form_name)
Logging:trace(Controller.classname, "---> update form", form_name)
form:update(event, action, item, item2, item3)
end
else
Expand Down Expand Up @@ -478,6 +499,11 @@ function Controller.onEvent(event, action, item, item2, item3)
Logging:debug(Controller.classname, "onEvent()", action, item, item2, item3)
local model = Model.getModel()

-- ***************************
-- access for all
-- ***************************
Controller.onEventAccessAll(event, action, item, item2, item3)

-- *******************************
-- access admin only
-- *******************************
Expand Down Expand Up @@ -510,11 +536,6 @@ function Controller.onEvent(event, action, item, item2, item3)
Controller.onEventAccessDelete(event, action, item, item2, item3)
end

-- ***************************
-- access for all
-- ***************************
Controller.onEventAccessAll(event, action, item, item2, item3)

end

-------------------------------------------------------------------------------
Expand Down Expand Up @@ -553,6 +574,7 @@ function Controller.onEventAccessAll(event, action, item, item2, item3)
end
Event.force_refresh = true
Event.force_open = true
Controller.closeEditionOrSelector()
Controller.createEvent(event, item, "OPEN", item, item2, item3)
end

Expand Down Expand Up @@ -665,7 +687,9 @@ function Controller.onEventAccessWrite(event, action, item, item2, item3)
end

if action == "change-time" then
model.time = tonumber(item) or 1
local index = event.element.selected_index
model.time = helmod_base_times[index].value or 1
Logging:debug(Controller.classname, "change-time", index, helmod_base_times[index], model.time)
ModelCompute.update()
Event.force_refresh = true
end
Expand Down
17 changes: 9 additions & 8 deletions core/ElementGui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,12 @@ end
-- @param #string style style of button
-- @param #string caption container for element
-- @param #string tooltip displayed text
-- @param #number size
--
-- @return #LuaGuiElement the LuaGuiElement added
--
function ElementGui.addGuiButton(parent, action, key, style, caption, tooltip)
Logging:trace(ElementGui.classname, "addGuiButton", parent, action, key, style, caption, tooltip)
function ElementGui.addGuiButton(parent, action, key, style, caption, tooltip, size)
Logging:trace(ElementGui.classname, "addGuiButton", parent, action, key, style, caption, tooltip, size)
local options = {}
options.type = "button"
if key ~= nil then
Expand Down Expand Up @@ -205,6 +206,10 @@ function ElementGui.addGuiButton(parent, action, key, style, caption, tooltip)
end
button = parent.add(options)
end
if size ~= nil then
button.style.width = size
button.style.height = size
end
return button
end

Expand Down Expand Up @@ -711,9 +716,7 @@ function ElementGui.addGuiFlowH(parent, key, style)
options.type = "flow"
options.direction = "horizontal"
options.name = key
if style ~= nil then
options.style = style
end
options.style = style or helmod_flow_style.horizontal
return parent.add(options)
end

Expand All @@ -734,9 +737,7 @@ function ElementGui.addGuiFlowV(parent, key, style)
options.type = "flow"
options.direction = "vertical"
options.name = key
if style ~= nil then
options.style = style
end
options.style = style or helmod_flow_style.vertical
return parent.add(options)
end

Expand Down
79 changes: 42 additions & 37 deletions core/Form.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,28 @@ end
function Form.methods:getPanel()
local parent_panel = self:getParentPanel()
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:getPanelName(), helmod_frame_style.default, self.panelCaption or self:classname())
panel.style.horizontally_stretchable = true
panel.style.vertically_stretchable = true
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)
return panel
else
local panel = ElementGui.addGuiFlowH(parent_panel, self:classname(), helmod_flow_style.horizontal)
panel.style.horizontally_stretchable = true
panel.style.vertically_stretchable = true
return panel
return parent_panel[self:getPanelName()], parent_panel[self:getPanelName()]["content_panel"], parent_panel[self:getPanelName()]["header_panel"]["menu_panel"]
end

local flow_panel = ElementGui.addGuiFrameV(parent_panel, self:getPanelName(), helmod_frame_style.hidden)
flow_panel.style.horizontally_stretchable = true
flow_panel.style.vertically_stretchable = true
flow_panel.location = User.getLocationForm(self:getPanelName())
Logging:debug(self:classname(), "location", self:getPanelName(), User.getLocationForm(self:getPanelName()))
ElementGui.setStyle(flow_panel, self:classname(), "width")
ElementGui.setStyle(flow_panel, self:classname(), "height")

local header_panel = ElementGui.addGuiFlowH(flow_panel, "header_panel")
local title_panel = ElementGui.addGuiFrameH(header_panel, "title_panel", helmod_frame_style.default, self.panelCaption or self:classname())
title_panel.style.height = 40
local menu_panel = ElementGui.addGuiFrameH(header_panel, "menu_panel", helmod_frame_style.panel)
--menu_panel.style.horizontal_spacing = 10
menu_panel.style.horizontal_align = "right"

local content_panel = ElementGui.addGuiFlowV(flow_panel, "content_panel")
title_panel.drag_target = flow_panel
--Logging:debug(self:classname(), "children",panel.children_names)
return flow_panel, content_panel, menu_panel
end

-------------------------------------------------------------------------------
Expand All @@ -116,15 +121,15 @@ end
-- @return #LuaGuiElement
--
function Form.methods:getMenuPanel()
local parent_panel = self:getPanel()
local flow_panel, content_panel, menu_panel = self:getPanel()
local panel_name = "menu"
if parent_panel[panel_name] ~= nil and parent_panel[panel_name].valid then
return parent_panel[panel_name]
if content_panel[panel_name] ~= nil and content_panel[panel_name].valid then
return content_panel[panel_name]
end
local panel = ElementGui.addGuiFlowH(parent_panel, panel_name, helmod_flow_style.horizontal)
local panel = ElementGui.addGuiFrameH(content_panel, panel_name, helmod_frame_style.default)
panel.style.horizontally_stretchable = true
--panel.style.vertically_stretchable = true
panel.style.height = 32
panel.style.height = 40
return panel
end

Expand Down Expand Up @@ -285,26 +290,25 @@ function Form.methods:prepare(event, action, item, item2, item3)
end

-------------------------------------------------------------------------------
-- Update header
-- Update top menu
--
-- @function [parent=#Form] updateTitle
-- @function [parent=#Form] updateTopMenu
--
-- @param #LuaEvent event
-- @param #string action action name
-- @param #string item first item name
-- @param #string item2 second item name
-- @param #string item3 third item name
--
function Form.methods:updateTitle(event, action, item, item2, item3)
Logging:debug(self:classname(), "updateTitle():", action, item, item2, item3)
function Form.methods:updateTopMenu(event, action, item, item2, item3)
Logging:debug(self:classname(), "updateTopMenu()", action, item, item2, item3)
-- ajoute un menu
if self.panelCaption ~= nil then

local left_menu_panel = self:getLeftMenuPanel()
local right_menu_panel = self:getRightMenuPanel()
right_menu_panel.clear()
local flow_panel, content_panel, menu_panel = self:getPanel()
menu_panel.clear()
if self.panelClose then
local group1 = ElementGui.addGuiFlowH(right_menu_panel,"group1",helmod_flow_style.horizontal)
local group1 = ElementGui.addGuiFlowH(menu_panel,"group1",helmod_flow_style.horizontal)
for _, form in pairs(Controller.getViews()) do
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()
Expand All @@ -313,7 +317,7 @@ function Form.methods:updateTitle(event, action, item, item2, item3)
end
end

local group2 = ElementGui.addGuiFlowH(right_menu_panel,"group2",helmod_flow_style.horizontal)
local group2 = ElementGui.addGuiFlowH(menu_panel,"group2",helmod_flow_style.horizontal)
if self.help_button then
ElementGui.addGuiButton(group2, "HMHelpPanel=OPEN", nil, "helmod_button_icon_help", nil, ({"helmod_button.help"}))
end
Expand All @@ -335,10 +339,11 @@ end
--
function Form.methods:update(event, action, item, item2, item3)
Logging:debug(self:classname(), "update():", action, item, item2, item3)
local panel = self:getPanel()
if self.auto_clear then panel.clear() end

self:updateTitle(event, action, item, item2, item3)
local flow_panel, content_panel, menu_panel = self:getPanel()
if self.auto_clear then content_panel.clear() end
if action == "OPEN" then
self:updateTopMenu(event, action, item, item2, item3)
end
self:onUpdate(event, action, item, item2, item3)
end

Expand Down Expand Up @@ -366,10 +371,10 @@ end
--
function Form.methods:close(force)
Logging:debug(self:classname(), "close()")
local panel = self:getPanel()
User.setCloseForm(self:classname(), panel.location)
local flow_panel, content_panel, menu_panel = self:getPanel()
User.setCloseForm(self:classname(), flow_panel.location)
self:onClose()
panel.destroy()
flow_panel.destroy()
end

-------------------------------------------------------------------------------
Expand Down
14 changes: 13 additions & 1 deletion core/defines.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
helmod_base_times = {
{ value = 1, caption = "1s", tooltip="1s"},
{ value = 60, caption = "1", tooltip="1mn"},
{ value = 300, caption = "5", tooltip="5mn"},
{ value = 600, caption = "10", tooltip="10mn"},
{ value = 1800, caption = "30", tooltip="30mn"},
{ value = 3600, caption = "1h", tooltip="1h"},
{ value = 3600*6, caption = "6h", tooltip="6h"},
{ value = 3600*12, caption = "12h", tooltip="12h"},
{ value = 3600*24, caption = "24h", tooltip="24h"}
}

helmod_flow_style = {
flow = "flow",
horizontal = "helmod_flow_horizontal",
Expand All @@ -7,7 +19,7 @@ helmod_flow_style = {
helmod_frame_style = {
default = "helmod_frame_default",
hidden = "helmod_frame_hidden",
panel = "helmod_frame_default",
panel = "helmod_frame_panel",
cell = "helmod_frame_hidden",
tab = "helmod_frame_tab",
section = "helmod_frame_section",
Expand Down
Loading

0 comments on commit 4a47c72

Please sign in to comment.