FrameworkZ 4.4.2
Provides a framework for Project Zomboid with various systems.
Loading...
Searching...
No Matches
User_Interfaces.lua
Go to the documentation of this file.
1if not isClient() then return end
5--! \brief User Interfaces module. This module is used to create user interfaces for the game.
6--! \class FrameworkZ.UserInterfaces
7FrameworkZ.UserInterfaces = {}
8FrameworkZ.UserInterfaces.__index = FrameworkZ.UserInterfaces
9FrameworkZ.UserInterfaces.List = {}
10FrameworkZ.UserInterfaces = FrameworkZ.Foundation:NewModule(FrameworkZ.UserInterfaces, "UserInterfaces")
11
12local UI = {}
13UI.__index = UI
14
15function UI:Initialize()
16 return FrameworkZ.UserInterfaces:Initialize(self.uniqueID, self)
17end
19function UI:RegisterNextStep(fromMenuName, toMenuName, fromMenu, toMenu, enterToMenuCallback, exitToMenuCallback, toMenuParameters)
20 local step = {
21 fromMenuName = fromMenuName,
22 toMenuName = toMenuName,
23 fromMenu = fromMenu,
24 toMenu = toMenu,
25 enterToMenuCallback = enterToMenuCallback,
26 exitToMenuCallback = exitToMenuCallback,
27 toMenuParameters = toMenuParameters
28 }
29
30 table.insert(self.steps, step)
31
32 return step
33end
34
35function UI:ShowNextStep()
36 if self.currentStep >= #self.steps then
37 local currentStepInfo = self.steps[self.currentStep]
38 local fromMenu = currentStepInfo.fromMenu
39 local enterToMenuCallback = currentStepInfo.enterToMenuCallback
40
41 if fromMenu.instance then
42 enterToMenuCallback(self.parent, fromMenu.instance)
43 fromMenu.instance:setVisible(false)
44 end
46 self.onEnterInitialMenu(self.parent)
47 self.currentStep = 1
48
49 return
50 end
52 -- Moving to current step's to menu
53 if self.currentStep == 1 then
54 local canGoForward = true
55
56 if self.onExitInitialMenu then
57 canGoForward = self.onExitInitialMenu(self.parent)
58 end
59
60 if canGoForward then
61 local currentStepInfo = self.steps[self.currentStep]
62 local toMenu = currentStepInfo.toMenu
63 local enterToMenuCallback = currentStepInfo.enterToMenuCallback
64 local toMenuParameters = currentStepInfo.toMenuParameters
65
66 if toMenu.instance then
67 if enterToMenuCallback then
68 enterToMenuCallback(self.parent, toMenu.instance)
69 end
70
71 toMenu.instance:setVisible(true)
72 else
73 local toMenuName = currentStepInfo.toMenuName
74 self.parent[toMenuName] = toMenu:new(toMenuParameters)
75
76 if enterToMenuCallback then
77 enterToMenuCallback(self.parent, self.parent[toMenuName])
78 end
79
80 self.parent[toMenuName]:initialise()
81 self.parent:addChild(self.parent[toMenuName])
82 end
83
84 self.currentStep = self.currentStep + 1
85 end
86
87 -- Move to next step's to menu
88 else
89 local previousStepInfo = self.steps[self.currentStep - 1]
90 local currentStepInfo = self.steps[self.currentStep]
91 local fromMenu = currentStepInfo.fromMenu
92 local toMenu = currentStepInfo.toMenu
93 local enterToMenuCallback = currentStepInfo.enterToMenuCallback
94 local exitToMenuCallback = previousStepInfo.exitToMenuCallback
95 local toMenuParameters = currentStepInfo.toMenuParameters
96 local canGoForward = true
97
98 if fromMenu.instance then
99 if exitToMenuCallback then
100 canGoForward = exitToMenuCallback(self.parent, fromMenu.instance, true)
101 end
102
103 if canGoForward then
104 fromMenu.instance:setVisible(false)
105 end
106 end
107
108 if canGoForward then
109 if toMenu.instance then
110 if enterToMenuCallback then
111 enterToMenuCallback(self.parent, toMenu)
112 end
113
114 toMenu.instance:setVisible(true)
115 else
116 local toMenuName = currentStepInfo.toMenuName
117 self.parent[toMenuName] = toMenu:new(toMenuParameters)
118
119 if enterToMenuCallback then
120 enterToMenuCallback(self.parent, self.parent[toMenuName])
121 end
122
123 self.parent[toMenuName]:initialise()
124 self.parent:addChild(self.parent[toMenuName])
125 end
126
127 self.currentStep = self.currentStep + 1
128 end
129 end
130
131 return true
132end
133
134function UI:ShowPreviousStep()
135 if self.currentStep <= 1 then
136 return false
137 end
138
139 -- Moving from initial menu
140 if self.currentStep == 2 then
141 local previousStepInfo = self.steps[self.currentStep - 1]
142 local toMenu = previousStepInfo.toMenu
143 local exitToMenuCallback = previousStepInfo.exitToMenuCallback
144
145 if toMenu.instance then
146 if exitToMenuCallback then
147 exitToMenuCallback(self.parent, toMenu, false)
148 end
149
150 toMenu.instance:setVisible(false)
151 end
152
153 if self.onEnterInitialMenu then
154 self.onEnterInitialMenu(self.parent)
155 end
156
157 -- Move to previous step's menu
158 else
159 local currentStepInfo = self.steps[self.currentStep]
160 local previousStepInfo = self.steps[self.currentStep - 1]
161 local fromMenu = currentStepInfo.fromMenu
162 local toMenu = previousStepInfo.fromMenu
163 local enterToMenuCallback = self.steps[self.currentStep - 2].enterToMenuCallback
164 local exitFromMenuCallback = previousStepInfo.exitToMenuCallback
165
166 if fromMenu and fromMenu.instance then
167 if exitFromMenuCallback then
168 exitFromMenuCallback(self.parent, fromMenu)
169 end
170
171 fromMenu.instance:setVisible(false)
172 end
173
174 if toMenu and toMenu.instance then
175 if enterToMenuCallback then
176 enterToMenuCallback(self.parent, toMenu)
177 end
178
179 toMenu.instance:setVisible(true)
180 end
181 end
182
183 self.currentStep = self.currentStep - 1
184
185 return true
186end
187
188function FrameworkZ.UserInterfaces:New(uniqueID, parent)
189 local object = {
190 uniqueID = uniqueID,
191 parent = parent,
192 currentStep = 1,
193 steps = {}
194 }
195
196 setmetatable(object, UI)
197
198 return object
199end
200
201function FrameworkZ.UserInterfaces:Initialize(uniqueID, userInterface)
202 self.List[uniqueID] = userInterface
203
204 return uniqueID
205end
void local isClient()
void uniqueID()
void self self
Definition MainMenu.lua:85
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()
User Interfaces module. This module is used to create user interfaces for the game.
void New(uniqueID, parent)
void Initialize(uniqueID, userInterface)
FrameworkZ UserInterfaces List
FrameworkZ UserInterfaces __index
FrameworkZ global table.
void ShowNextStep()
void ShowPreviousStep()
void Initialize()
void RegisterNextStep(fromMenuName, toMenuName, fromMenu, toMenu, enterToMenuCallback, exitToMenuCallback, toMenuParameters)