FrameworkZ 10.8.3
Provides a framework for Project Zomboid with various systems.
Loading...
Searching...
No Matches
User_Interfaces.lua
Go to the documentation of this file.
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},
20 buttonBorder = false,
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")
31local UI = {}
32UI.__index = UI
33
34function UI:Initialize()
35 return FrameworkZ.UserInterfaces:Initialize(self.uniqueID, self)
36end
37
38function UI:RegisterNextStep(fromMenuName, toMenuName, fromMenu, toMenu, enterToMenuCallback, exitToMenuCallback, toMenuParameters)
39 local step = {
40 fromMenuName = fromMenuName,
41 toMenuName = toMenuName,
42 fromMenu = fromMenu,
43 toMenu = toMenu,
44 enterToMenuCallback = enterToMenuCallback,
45 exitToMenuCallback = exitToMenuCallback,
46 toMenuParameters = toMenuParameters
47 }
49 table.insert(self.steps, step)
51 return step
52end
53
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
59
60 if fromMenu.instance then
61 enterToMenuCallback(self.parent, fromMenu.instance)
62 fromMenu.instance:setVisible(false)
63 end
65 self.onEnterInitialMenu(self.parent)
66 self.currentStep = 1
67
68 return
69 end
70
71 -- Moving to current step's to menu
72 if self.currentStep == 1 then
73 local canGoForward = true
74
75 if self.onExitInitialMenu then
76 canGoForward = self.onExitInitialMenu(self.parent)
77 end
78
79 if canGoForward then
80 local currentStepInfo = self.steps[self.currentStep]
81 local toMenu = currentStepInfo.toMenu
82 local enterToMenuCallback = currentStepInfo.enterToMenuCallback
83 local toMenuParameters = currentStepInfo.toMenuParameters
84
85 if toMenu.instance then
86 if enterToMenuCallback then
87 enterToMenuCallback(self.parent, toMenu.instance)
88 end
90 toMenu.instance:setVisible(true)
91 else
92 local toMenuName = currentStepInfo.toMenuName
93 self.parent[toMenuName] = toMenu:new(toMenuParameters)
94
95 if enterToMenuCallback then
96 enterToMenuCallback(self.parent, self.parent[toMenuName])
97 end
98
99 self.parent[toMenuName]:initialise()
100 self.parent:addChild(self.parent[toMenuName])
101 end
102
103 self.currentStep = self.currentStep + 1
104 end
105
106 -- Move to next step's to menu
107 else
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
116
117 if fromMenu.instance then
118 if exitToMenuCallback then
119 canGoForward = exitToMenuCallback(self.parent, fromMenu.instance, true)
120 end
121
122 if canGoForward then
123 fromMenu.instance:setVisible(false)
124 end
125 end
126
127 if canGoForward then
128 if toMenu.instance then
129 if enterToMenuCallback then
130 enterToMenuCallback(self.parent, toMenu)
131 end
132
133 toMenu.instance:setVisible(true)
134 else
135 local toMenuName = currentStepInfo.toMenuName
136 self.parent[toMenuName] = toMenu:new(toMenuParameters)
137
138 if enterToMenuCallback then
139 enterToMenuCallback(self.parent, self.parent[toMenuName])
140 end
142 self.parent[toMenuName]:initialise()
143 self.parent:addChild(self.parent[toMenuName])
144 end
146 self.currentStep = self.currentStep + 1
147 end
148 end
150 return true
151end
152
153function UI:ShowPreviousStep()
154 if self.currentStep <= 1 then
155 return false
156 end
157
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
163
164 if toMenu.instance then
165 if exitToMenuCallback then
166 exitToMenuCallback(self.parent, toMenu, false)
167 end
168
169 toMenu.instance:setVisible(false)
170 end
171
172 if self.onEnterInitialMenu then
173 self.onEnterInitialMenu(self.parent)
174 end
175
176 -- Move to previous step's menu
177 else
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
184
185 if fromMenu and fromMenu.instance then
186 if exitFromMenuCallback then
187 exitFromMenuCallback(self.parent, fromMenu)
188 end
189
190 fromMenu.instance:setVisible(false)
191 end
192
193 if toMenu and toMenu.instance then
194 if enterToMenuCallback then
195 enterToMenuCallback(self.parent, toMenu)
196 end
197
198 toMenu.instance:setVisible(true)
199 end
200 end
201
202 self.currentStep = self.currentStep - 1
203
204 return true
205end
206
207function FrameworkZ.UserInterfaces:New(uniqueID, parent)
208 local object = {
209 uniqueID = uniqueID,
210 parent = parent,
211 currentStep = 1,
212 steps = {}
213 }
214
215 setmetatable(object, UI)
216
217 return object
218end
219
220function FrameworkZ.UserInterfaces:Initialize(uniqueID, userInterface)
221 self.List[uniqueID] = userInterface
222
223 return uniqueID
224end
225
226function FrameworkZ.UserInterfaces:AddButtonEffects(button)
227 local theme = self.ButtonTheme
228
229 if not theme.buttonBackground then
230 button:setDisplayBackground(false)
231 else
232 button.backgroundColor = theme.buttonBackgroundColor
233 end
234
235 button.oldOnMouseMove = button.onMouseMove
236 button.onMouseMove = function(x, y)
237 button.oldOnMouseMove(x, y)
238
239 if button.mouseOver then
240 button.textColor = theme.buttonHoverTextColor
241
242 if theme.buttonHoverBackground then
243 button.backgroundColor = theme.buttonHoverBackgroundColor
244 end
245
246 if theme.buttonHoverBorder then
247 button.borderColor = theme.buttonHoverBorderColor
248 end
249 end
250 end
251
252 button.oldOnMouseMoveOutside = button.onMouseMoveOutside
253 button.onMouseMoveOutside = function(x, y)
254 button.oldOnMouseMoveOutside(x, y)
255
256 if not button.mouseOver then
257 button.textColor = theme.buttonTextColor
258 end
259
260 if theme.buttonBackground then
261 button.backgroundColor = theme.buttonBackgroundColor
262 end
263
264 if theme.buttonBorder then
265 button.borderColor = theme.buttonBorderColor
266 end
267 end
268end
269
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)
274
275 local button = ISButton:new(x, y, width, height, text, target, onClick)
276 button.font = theme.hugeButtonFontSize
277 self:AddButtonEffects(button)
278 button:initialise()
279 parent:addChild(button)
280
281 return button
282end
void local y()
void local x()
void uniqueID()
void self self
Definition MainMenu.lua:89
void local enterToMenuCallback()
void local toMenuName()
void local canGoForward()
void self parent()
void local currentStepInfo()
void local previousStepInfo()
void local exitFromMenuCallback()
void local exitToMenuCallback()
void local toMenuParameters()
void local fromMenu()
void local toMenu()
void FrameworkZ()
void FrameworkZ UI()
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 ShowNextStep()
void ShowPreviousStep()
void Initialize()
void RegisterNextStep(fromMenuName, toMenuName, fromMenu, toMenu, enterToMenuCallback, exitToMenuCallback, toMenuParameters)