1-- TODO rename
module to something specific for UI steps and whatnot
3if not isClient() then return end
5FrameworkZ = FrameworkZ or {}
7--! \brief User Interfaces module. This module is used to create user interfaces for the game.
8--! \class FrameworkZ.UserInterfaces
9FrameworkZ.UserInterfaces = {}
10FrameworkZ.UserInterfaces.__index = FrameworkZ.UserInterfaces
11FrameworkZ.UserInterfaces.List = {}
12FrameworkZ.UserInterfaces.ButtonTheme = {
13 massiveButtonFontSize = UIFont.Massive,
14 hugeButtonFontSize = UIFont.Title,
15 largeButtonFontSize = UIFont.Large,
16 mediumButtonFontSize = UIFont.Medium,
17 smallButtonFontSize = UIFont.Small,
18 buttonBackground = false,
19 buttonBackgroundColor = {r=0.1, g=0.1, b=0.1, a=1},
21 buttonBorderColor = {r=1, g=1, b=1, a=1},
22 buttonTextColor = {r=1, g=1, b=1, a=1},
23 buttonHoverBackground = false,
24 buttonHoverBackgroundColor = {r=0.1, g=0.1, b=0.1, a=1},
25 buttonHoverBorder = false,
26 buttonHoverBorderColor = {r=1, g=1, b=1, a=1},
27 buttonHoverTextColor = {r=1, g=0.84, b=0, a=1},
29FrameworkZ.UserInterfaces = FrameworkZ.Foundation:NewModule(FrameworkZ.UserInterfaces, "UserInterfaces")
34function UI:Initialize()
35 return FrameworkZ.UserInterfaces:Initialize(self.uniqueID, self)
38function UI:RegisterNextStep(fromMenuName, toMenuName, fromMenu, toMenu, enterToMenuCallback, exitToMenuCallback, toMenuParameters)
40 fromMenuName = fromMenuName,
41 toMenuName = toMenuName,
44 enterToMenuCallback = enterToMenuCallback,
45 exitToMenuCallback = exitToMenuCallback,
46 toMenuParameters = toMenuParameters
49 table.insert(self.steps, step)
54function UI:ShowNextStep()
55 if self.currentStep >= #self.steps then
56 local currentStepInfo = self.steps[self.currentStep]
57 local fromMenu = currentStepInfo.fromMenu
58 local enterToMenuCallback = currentStepInfo.enterToMenuCallback
60 if fromMenu.instance then
61 enterToMenuCallback(self.parent, fromMenu.instance)
62 fromMenu.instance:setVisible(false)
65 self.onEnterInitialMenu(self.parent)
71 -- Moving to current step's to menu
72 if self.currentStep == 1 then
73 local canGoForward = true
75 if self.onExitInitialMenu then
76 canGoForward = self.onExitInitialMenu(self.parent)
80 local currentStepInfo = self.steps[self.currentStep]
81 local toMenu = currentStepInfo.toMenu
82 local enterToMenuCallback = currentStepInfo.enterToMenuCallback
83 local toMenuParameters = currentStepInfo.toMenuParameters
85 if toMenu.instance then
86 if enterToMenuCallback then
87 enterToMenuCallback(self.parent, toMenu.instance)
90 toMenu.instance:setVisible(true)
92 local toMenuName = currentStepInfo.toMenuName
93 self.parent[toMenuName] = toMenu:new(toMenuParameters)
95 if enterToMenuCallback then
96 enterToMenuCallback(self.parent, self.parent[toMenuName])
99 self.parent[toMenuName]:initialise()
100 self.parent:addChild(self.parent[toMenuName])
103 self.currentStep = self.currentStep + 1
106 -- Move to next step's to menu
108 local previousStepInfo = self.steps[self.currentStep - 1]
109 local currentStepInfo = self.steps[self.currentStep]
110 local fromMenu = currentStepInfo.fromMenu
111 local toMenu = currentStepInfo.toMenu
112 local enterToMenuCallback = currentStepInfo.enterToMenuCallback
113 local exitToMenuCallback = previousStepInfo.exitToMenuCallback
114 local toMenuParameters = currentStepInfo.toMenuParameters
115 local canGoForward = true
117 if fromMenu.instance then
118 if exitToMenuCallback then
119 canGoForward = exitToMenuCallback(self.parent, fromMenu.instance, true)
123 fromMenu.instance:setVisible(false)
128 if toMenu.instance then
129 if enterToMenuCallback then
130 enterToMenuCallback(self.parent, toMenu)
133 toMenu.instance:setVisible(true)
135 local toMenuName = currentStepInfo.toMenuName
136 self.parent[toMenuName] = toMenu:new(toMenuParameters)
138 if enterToMenuCallback then
139 enterToMenuCallback(self.parent, self.parent[toMenuName])
142 self.parent[toMenuName]:initialise()
143 self.parent:addChild(self.parent[toMenuName])
146 self.currentStep = self.currentStep + 1
153function UI:ShowPreviousStep()
154 if self.currentStep <= 1 then
158 -- Moving from initial menu
159 if self.currentStep == 2 then
160 local previousStepInfo = self.steps[self.currentStep - 1]
161 local toMenu = previousStepInfo.toMenu
162 local exitToMenuCallback = previousStepInfo.exitToMenuCallback
164 if toMenu.instance then
165 if exitToMenuCallback then
166 exitToMenuCallback(self.parent, toMenu, false)
169 toMenu.instance:setVisible(false)
172 if self.onEnterInitialMenu then
173 self.onEnterInitialMenu(self.parent)
176 -- Move to previous step's menu
178 local currentStepInfo = self.steps[self.currentStep]
179 local previousStepInfo = self.steps[self.currentStep - 1]
180 local fromMenu = currentStepInfo.fromMenu
181 local toMenu = previousStepInfo.fromMenu
182 local enterToMenuCallback = self.steps[self.currentStep - 2].enterToMenuCallback
183 local exitFromMenuCallback = previousStepInfo.exitToMenuCallback
185 if fromMenu and fromMenu.instance then
186 if exitFromMenuCallback then
187 exitFromMenuCallback(self.parent, fromMenu)
190 fromMenu.instance:setVisible(false)
193 if toMenu and toMenu.instance then
194 if enterToMenuCallback then
195 enterToMenuCallback(self.parent, toMenu)
198 toMenu.instance:setVisible(true)
202 self.currentStep = self.currentStep - 1
207function FrameworkZ.UserInterfaces:New(uniqueID, parent)
215 setmetatable(object, UI)
220function FrameworkZ.UserInterfaces:Initialize(uniqueID, userInterface)
221 self.List[uniqueID] = userInterface
226function FrameworkZ.UserInterfaces:AddButtonEffects(button)
227 local theme = self.ButtonTheme
229 if not theme.buttonBackground then
230 button:setDisplayBackground(false)
232 button.backgroundColor = theme.buttonBackgroundColor
235 button.oldOnMouseMove = button.onMouseMove
236 button.onMouseMove = function(x, y)
237 button.oldOnMouseMove(x, y)
239 if button.mouseOver then
240 button.textColor = theme.buttonHoverTextColor
242 if theme.buttonHoverBackground then
243 button.backgroundColor = theme.buttonHoverBackgroundColor
246 if theme.buttonHoverBorder then
247 button.borderColor = theme.buttonHoverBorderColor
252 button.oldOnMouseMoveOutside = button.onMouseMoveOutside
253 button.onMouseMoveOutside = function(x, y)
254 button.oldOnMouseMoveOutside(x, y)
256 if not button.mouseOver then
257 button.textColor = theme.buttonTextColor
260 if theme.buttonBackground then
261 button.backgroundColor = theme.buttonBackgroundColor
264 if theme.buttonBorder then
265 button.borderColor = theme.buttonBorderColor
270function FrameworkZ.UserInterfaces:CreateHugeButton(parent, x, y, text, target, onClick)
271 local theme = self.ButtonTheme
272 local width = getTextManager():MeasureStringX(theme.hugeButtonFontSize, text)
273 local height = getTextManager():MeasureStringY(theme.hugeButtonFontSize, text)
275 local button = ISButton:new(x, y, width, height, text, target, onClick)
276 button.font = theme.hugeButtonFontSize
277 self:AddButtonEffects(button)
279 parent:addChild(button)
void local enterToMenuCallback()
void local canGoForward()
void local currentStepInfo()
void local previousStepInfo()
void local exitFromMenuCallback()
void local exitToMenuCallback()
void local toMenuParameters()
Contains all of the User Interfaces for FrameworkZ.
User Interfaces module. This module is used to create user interfaces for the game.
FrameworkZ UserInterfaces ButtonTheme
FrameworkZ UserInterfaces List
FrameworkZ UserInterfaces __index
void RegisterNextStep(fromMenuName, toMenuName, fromMenu, toMenu, enterToMenuCallback, exitToMenuCallback, toMenuParameters)