FrameworkZ 4.4.2
Provides a framework for Project Zomboid with various systems.
Loading...
Searching...
No Matches
MainMenu.lua
Go to the documentation of this file.
1require "ISUI/ISPanel"
3PFW_MainMenu = ISPanel:derive("PFW_MainMenu")
6local nextLightning = 5
7
8function PFW_MainMenu:initialise()
9
10 -- HL2RP LIGHTNING STUFF
11 --[[
12 FrameworkZ.Timers:Create("MainMenuTick", 1, 0, function()
14 if not FrameworkZ.Timers:Exists("NextLightning") then
15 FrameworkZ.Timers:Create("NextLightning", nextLightning, 1, function()
16 local mainMenu = PFW_MainMenu.instance
17 mainMenu.shouldFlashLightning = true
18 mainMenu.hasFlashed1 = false
19 mainMenu.hasFlashed2 = false
20 mainMenu.hasFlashed3 = false
21 nextLightning = ZombRandBetween(10, 60)
23 FrameworkZ.Timers:Simple(2, function()
24 mainMenu.emitter:playSoundImpl("thunder" .. ZombRandBetween(3, 4), nil)
25 end)
26 end)
27 end
28 end
29 end)
30 --]]
31
33 self.emitter = self.playerObject:getEmitter()
36 local createCharacterLabel = "Create Character"
37 local loadCharacterLabel = "Load Character"
38 local disconnectLabel = "Disconnect"
39 local middleX = self.width / 2 - 200 / 2
40 local middleY = self.height / 2 + FrameworkZ.UI.GetHeight(UIFont.Title, title) + FrameworkZ.UI.GetHeight(UIFont.Large, subtitle)
41
42 ISPanel.initialise(self)
45 local stepWidth, stepHeight = 500, 600
46 local stepX, stepY = self.width / 2 - stepWidth / 2, self.height / 2 - stepHeight / 2
48 self.createCharacterSteps = FrameworkZ.UserInterfaces:New("VanillaCreateCharacter", self)
52
53 if PFW_MainMenu.customSteps then
54 PFW_MainMenu.customSteps()
55 else
57 self.createCharacterSteps:RegisterNextStep("SelectFaction", "EnterInfo", PFW_CreateCharacterFaction, PFW_CreateCharacterInfo, self.onEnterInfoMenu, self.onExitInfoMenu, {x = stepX, y = stepY, width = stepWidth, height = stepHeight, playerObject = self.playerObject})
58 self.createCharacterSteps:RegisterNextStep("EnterInfo", "CustomizeAppearance", PFW_CreateCharacterInfo, PFW_CreateCharacterAppearance, self.onEnterAppearanceMenu, self.onExitAppearanceMenu, {x = stepX, y = stepY, width = stepWidth, height = stepHeight, playerObject = self.playerObject})
59 self.createCharacterSteps:RegisterNextStep("CustomizeAppearance", "MainMenu", PFW_CreateCharacterAppearance, self, self.onFinalizeCharacter, nil, {x = stepX, y = stepY, width = stepWidth, height = stepHeight, playerObject = self.playerObject})
60 end
62 self.titleY = self.uiHelper.GetHeight(UIFont.Title, title)
64 self.title = ISLabel:new(self.uiHelper.GetMiddle(self.width, UIFont.Title, title), self.titleY, 25, title, 1, 1, 1, 1, UIFont.Title, true)
65 self:addChild(self.title)
66
67 self.subtitle = ISLabel:new(self.uiHelper.GetMiddle(self.width, UIFont.Large, subtitle), self.titleY + self.uiHelper.GetHeight(UIFont.Large, subtitle), 25, subtitle, 1, 1, 1, 1, UIFont.Large, true)
68 self:addChild(self.subtitle)
71 self.createCharacterButton.font = UIFont.Large
74 self.loadCharacterButton = ISButton:new(middleX, middleY, 200, 50, loadCharacterLabel, self, PFW_MainMenu.onEnterLoadCharacterMenu)
77
78 self.disconnectButton = ISButton:new(middleX, middleY + 75, 200, 50, disconnectLabel, self, PFW_MainMenu.onDisconnect)
79 self.disconnectButton.font = UIFont.Large
80 self:addChild(self.disconnectButton)
82 --[[
83 self.closeButton = ISButton:new(middleX, middleY + 150, 200, 50, "Close", self, PFW_MainMenu.onClose)
84 self.closeButton.font = UIFont.Large
86 --]]
87end
88
90function PFW_MainMenu:fadeOutMainMenuMusic()
91 if self.emitter:isPlaying(currentMainMenuSong) then
94
95 if mainMenuMusicVolume <= 0 then
96 FrameworkZ.Timers:Remove("FadeOutMainMenuMusic")
98 end
99 end
100end
102function PFW_MainMenu:onClose()
103 FrameworkZ.Timers:Create("FadeOutMainMenuMusic", 0.01, 0, function()
104 self:fadeOutMainMenuMusic()
105 end)
106
107 self:setVisible(false)
108 self:removeFromUIManager()
109end
110
111function PFW_MainMenu:onEnterMainMenu()
116 self.createCharacterButton:setVisible(true)
117 self.loadCharacterButton:setVisible(true)
118 self.disconnectButton:setVisible(true)
119end
120
121function PFW_MainMenu:onExitMainMenu()
122 local maxCharacters = 1
123 local currentCharacters = 0
124
125 if currentCharacters < maxCharacters then
126 self.createCharacterButton:setVisible(false)
127 self.loadCharacterButton:setVisible(false)
128 self.disconnectButton:setVisible(false)
130 return true
131 else
132 return false
133 end
134end
135
136function PFW_MainMenu:showStepControls(menu, backButtonIndex, backButton, backButtonText, forwardButtonIndex, forwardButton, forwardButtonText)
137 if not backButton then
138 local width = 200
139 local height = 50
140 local x = menu:getX()
141 local y = menu:getY() + menu.height + 25
142
143 self[backButtonIndex] = ISButton:new(x, y, width, height, backButtonText, self.createCharacterSteps, self.createCharacterSteps.ShowPreviousStep)
144 self[backButtonIndex].font = UIFont.Large
145 self:addChild(self[backButtonIndex])
146 else
147 backButton:setVisible(true)
148 end
150 if not forwardButton then
151 local width = 200
152 local height = 50
153 local x = menu:getX() + menu.width - width
154 local y = menu:getY() + menu.height + 25
156 self[forwardButtonIndex] = ISButton:new(x, y, width, height, forwardButtonText, self.createCharacterSteps, self.createCharacterSteps.ShowNextStep)
157 self[forwardButtonIndex].font = UIFont.Large
158 self:addChild(self[forwardButtonIndex])
159 else
160 forwardButton:setVisible(true)
161 end
162end
164function PFW_MainMenu:hideStepControls(backButton, forwardButton)
165 if backButton then
166 backButton:setVisible(false)
167 end
168
169 if forwardButton then
170 forwardButton:setVisible(false)
171 end
172end
174function PFW_MainMenu:onEnterFactionMenu(menu)
175 self:showStepControls(menu, "returnToMainMenu", self.returnToMainMenu, "< Main Menu (Cancel)", "enterInfoForward", self.enterInfoForward, "Info >")
176end
178function PFW_MainMenu:onExitFactionMenu(menu)
179 self:hideStepControls(self.returnToMainMenu, self.enterInfoForward)
180
181 return true
182end
183
184function PFW_MainMenu:onEnterInfoMenu(menu)
185 self:showStepControls(menu, "selectFaction", self.selectFaction, "< Faction", "customizeAppearance", self.customizeAppearance, "Appearance >")
186end
187
188function PFW_MainMenu:onExitInfoMenu(menu, isForward)
189 local infoInstance = PFW_CreateCharacterInfo.instance
190 local name = infoInstance.nameEntry:getText()
191 local description = infoInstance.descriptionEntry:getText()
192 local warningMessage = ""
193
194 if not name or name == "" then
195 warningMessage = warningMessage .. "Name must be filled in"
196 elseif #name < 8 then
197 warningMessage = warningMessage .. (warningMessage == "" and "" or " and ") .. "Name must be at least 8 characters"
198 end
199
200 if not description or description == "" then
201 warningMessage = warningMessage .. (warningMessage == "" and "" or " and ") .. "Description must be filled in"
202 elseif #description < 24 then
203 warningMessage = warningMessage .. (warningMessage == "" and "" or " and ") .. "Description must be at least 24 characters"
204 end
205
206 if warningMessage ~= "" and isForward then
207 FrameworkZ.Notifications:AddToQueue("Cannot proceed: " .. warningMessage, FrameworkZ.Notifications.Types.Warning, nil, self)
208 return false
209 end
210
211 self:hideStepControls(self.selectFaction, self.customizeAppearance)
212
213 return true
214end
215
218 menu.gender = PFW_CreateCharacterInfo.instance.gender
219 menu.skinColor = PFW_CreateCharacterInfo.instance.skinColorDropdown:getOptionData(PFW_CreateCharacterInfo.instance.skinColorDropdown.selected)
220 menu.hairColor = PFW_CreateCharacterInfo.instance.hairColorDropdown:getOptionData(PFW_CreateCharacterInfo.instance.hairColorDropdown.selected)
221
224
225 PFW_CreateCharacterAppearance.instance:resetGender(menu.gender)
228 PFW_CreateCharacterAppearance.instance:resetBeardStyles()
230 PFW_CreateCharacterAppearance.instance.wasGenderUpdated = false
231
232 self:showStepControls(menu, "enterInfoBack", self.enterInfoBack, "< Info", "finalizeCharacter", self.finalizeCharacter, "Finalize >")
233end
234
236 self:hideStepControls(self.enterInfoBack, self.finalizeCharacter)
237
238 return true
239end
240
242 self:hideStepControls(self.enterInfoBack, self.finalizeCharacter)
243
244 local infoInstance = PFW_CreateCharacterInfo.instance
245 local factionInstance = PFW_CreateCharacterFaction.instance
246 local appearanceInstance = PFW_CreateCharacterAppearance.instance
247
248 local faction = factionInstance.faction
249 local gender = infoInstance.genderDropdown:getSelectedText()
250 local name = infoInstance.nameEntry:getText()
251 local description = infoInstance.descriptionEntry:getText()
252 local age = infoInstance.ageSlider:getCurrentValue()
253 local height = infoInstance.heightSlider:getCurrentValue()
254 local weight = infoInstance.weightSlider:getCurrentValue()
255 local physique = infoInstance.physiqueDropdown:getSelectedText()
256 local eyeColor = infoInstance.eyeColorDropdown:getSelectedText()
257 local hairColor = infoInstance.hairColorDropdown and infoInstance.hairColorDropdown:getOptionData(infoInstance.hairColorDropdown.selected) or nil
258 local skinColor = infoInstance.skinColorDropdown and infoInstance.skinColorDropdown:getOptionData(infoInstance.skinColorDropdown.selected) or nil
259
260 local hair = appearanceInstance.hairDropdown and appearanceInstance.hairDropdown:getOptionData(appearanceInstance.hairDropdown.selected) or nil
261 local beard = appearanceInstance.beardDropdown and appearanceInstance.beardDropdown:getOptionData(appearanceInstance.beardDropdown.selected) or nil
262 local head = appearanceInstance.headDropdown and appearanceInstance.headDropdown:getOptionData(appearanceInstance.headDropdown.selected).itemID or nil
263 local face = appearanceInstance.faceDropdown and appearanceInstance.faceDropdown:getOptionData(appearanceInstance.faceDropdown.selected).itemID or nil
264 local ears = appearanceInstance.earsDropdown and appearanceInstance.earsDropdown:getOptionData(appearanceInstance.earsDropdown.selected).itemID or nil
265 local backpack = appearanceInstance.backpackDropdown and appearanceInstance.backpackDropdown:getOptionData(appearanceInstance.backpackDropdown.selected).itemID or nil
266 local rightHand = nil
267 local rightHandAccessory = nil
268 local leftHand = nil
269 local leftHandAccessory = nil
270 local gloves = appearanceInstance.glovesDropdown and appearanceInstance.glovesDropdown:getOptionData(appearanceInstance.glovesDropdown.selected).itemID or nil
271 local undershirt = appearanceInstance.undershirtDropdown and appearanceInstance.undershirtDropdown:getOptionData(appearanceInstance.undershirtDropdown.selected).itemID or nil
272 local overshirt = appearanceInstance.overshirtDropdown and appearanceInstance.overshirtDropdown:getOptionData(appearanceInstance.overshirtDropdown.selected).itemID or nil
273 local vest = appearanceInstance.vestDropdown and appearanceInstance.vestDropdown:getOptionData(appearanceInstance.vestDropdown.selected).itemID or nil
274 local belt = appearanceInstance.beltDropdown and appearanceInstance.beltDropdown:getOptionData(appearanceInstance.beltDropdown.selected).itemID or nil
275 local pants = appearanceInstance.pantsDropdown and appearanceInstance.pantsDropdown:getOptionData(appearanceInstance.pantsDropdown.selected).itemID or nil
276 local socks = appearanceInstance.socksDropdown and appearanceInstance.socksDropdown:getOptionData(appearanceInstance.socksDropdown.selected).itemID or nil
277 local shoes = appearanceInstance.shoesDropdown and appearanceInstance.shoesDropdown:getOptionData(appearanceInstance.shoesDropdown.selected).itemID or nil
278
279 local characterData = {
280 INFO_FACTION = faction,
281 INFO_GENDER = gender,
282 INFO_NAME = name,
283 INFO_DESCRIPTION = description,
284 INFO_AGE = age,
285 INFO_HEIGHT = height,
286 INFO_WEIGHT = weight,
287 INFO_PHYSIQUE = physique,
288 INFO_EYE_COLOR = eyeColor,
289 INFO_BEARD_COLOR = hairColor,
290 INFO_HAIR_COLOR = hairColor,
291 INFO_SKIN_COLOR = skinColor,
292 INFO_HAIR_STYLE = hair,
293 INFO_BEARD_STYLE = beard,
294 EQUIPMENT_SLOT_HEAD = {id = head},
295 EQUIPMENT_SLOT_FACE = {id = face},
296 EQUIPMENT_SLOT_EARS = {id = ears},
297 EQUIPMENT_SLOT_BACKPACK = {id = backpack},
298 EQUIPMENT_SLOT_GLOVES = {id = gloves},
299 EQUIPMENT_SLOT_UNDERSHIRT = {id = undershirt},
300 EQUIPMENT_SLOT_OVERSHIRT = {id = overshirt},
301 EQUIPMENT_SLOT_VEST = {id = vest},
302 EQUIPMENT_SLOT_BELT = {id = belt},
303 EQUIPMENT_SLOT_PANTS = {id = pants},
304 EQUIPMENT_SLOT_SOCKS = {id = socks},
305 EQUIPMENT_SLOT_SHOES = {id = shoes}
306 }
307
308 local success, characterID = FrameworkZ.Players:CreateCharacter(self.playerObject:getUsername(), characterData)
309
310 if success then
311 FrameworkZ.Notifications:AddToQueue("Successfully created character " .. name .. " #" .. characterID .. ".", nil, nil, self)
312 else
313 FrameworkZ.Notifications:AddToQueue("Failed to create character.", nil, nil, self)
314 end
315
316 return true
317end
318
319function PFW_MainMenu:onEnterLoadCharacterMenu()
320 local player = FrameworkZ.Players:GetPlayerByID(self.playerObject:getUsername())
321
322 if not player then
323 FrameworkZ.Notifications:AddToQueue("Failed to load characters.", FrameworkZ.Notifications.Types.Danger, nil, self)
324
325 return false
326 elseif #player.characters <= 0 then
327 FrameworkZ.Notifications:AddToQueue("No characters found.", FrameworkZ.Notifications.Types.Warning, nil, self)
328
329 return false
330 end
331
332 self:onExitMainMenu()
333
334 if not self.loadCharacterMenu then
335 local width = 800
336 local height = 600
337 local x = self.width / 2 - width / 2
338 local y = self.height / 2 - height / 2
339
341 self.loadCharacterMenu:initialise()
342 self:addChild(self.loadCharacterMenu)
343 else
344 self.loadCharacterMenu:setVisible(true)
345 self.loadCharacterMenu:updateCharacterPreview()
346 end
347
348 if not self.loadCharacterBackButton then
349 local widthReturn = 200
350 local heightReturn = 50
351 local xReturn = self.loadCharacterMenu:getX()
353
354 self.loadCharacterBackButton = ISButton:new(xReturn, yReturn, widthReturn, heightReturn, "< Main Menu", self, self.onEnterMainMenuFromLoadCharacterMenu)
355 self.loadCharacterBackButton.font = UIFont.Large
357 else
358 self.loadCharacterBackButton:setVisible(true)
359 end
360
362 local widthLoad = 200
363 local heightLoad = 50
366
367 self.loadCharacterForwardButton = ISButton:new(xLoad, yLoad, widthLoad, heightLoad, "Load Character >", self, self.onLoadCharacter)
370 else
371 self.loadCharacterForwardButton:setVisible(true)
372 end
373 --self.loadCharacterMenu:addToUIManager()
374end
375
376function PFW_MainMenu:onEnterMainMenuFromLoadCharacterMenu()
377 self.loadCharacterBackButton:setVisible(false)
378 self.loadCharacterForwardButton:setVisible(false)
379 self.loadCharacterMenu:setVisible(false)
380
381 self:onEnterMainMenu()
382end
383
384function PFW_MainMenu:onLoadCharacter()
385 local character = FrameworkZ.Players:GetCharacterByID(self.playerObject:getUsername(), self.loadCharacterMenu.currentIndex)
386
387 if not character then
388 FrameworkZ.Notifications:AddToQueue("No character selected.", FrameworkZ.Notifications.Types.Warning, nil, self)
389 return
390 end
391
392 local success = FrameworkZ.Players:LoadCharacter(self.playerObject:getUsername(), character, self.loadCharacterMenu.selectedCharacter.survivor)
393
394 if success then
395 FrameworkZ.Notifications:AddToQueue("Successfully loaded character " .. character.INFO_NAME .. " #" .. character.META_ID .. ".")
396 self:onClose()
397 else
398 FrameworkZ.Notifications:AddToQueue("Failed to load character.", FrameworkZ.Notifications.Types.Danger, nil, self)
399 end
400end
401
402function PFW_MainMenu:onDisconnect()
403 self:setVisible(false)
404 self:removeFromUIManager()
405 getCore():exitToMenu()
406end
407
408function PFW_MainMenu:prerender()
409 ISPanel.prerender(self)
410
411 local opacity = 1
412
413 -- HL2RP LIGHTNING STUFF
414 --[[
415 local opacity = 0.25
416
418 opacity = 0.5
419
420 if not self.hasFlashed1 then
421 self:drawTextureScaled(getTexture("media/textures/lightning_1.png"), 0, 0, self.width, self.height, opacity, 1, 1, 1)
422 elseif not self.hasFlashed2 then
423 self:drawTextureScaled(getTexture("media/textures/lightning_2.png"), 0, 0, self.width, self.height, opacity, 1, 1, 1)
424 elseif not self.hasFlashed3 then
425 self:drawTextureScaled(getTexture("media/textures/lightning_1.png"), 0, 0, self.width, self.height, opacity, 1, 1, 1)
426 end
427
428 FrameworkZ.Timers:Simple(0.05, function()
429 self.hasFlashed1 = true
430
431 FrameworkZ.Timers:Simple(0.05, function()
432 self.hasFlashed2 = true
433
434 FrameworkZ.Timers:Simple(0.05, function()
435 self.hasFlashed3 = true
437 end)
438 end)
439 end)
440 end
441 --]]
442
443 self:drawTextureScaled(getTexture(FrameworkZ.Config.MainMenuImage), 0, 0, self.width, self.height, opacity, 1, 1, 1)
444end
445
446function PFW_MainMenu:update()
447 ISPanel.update(self)
448
449 if not self.emitter:isPlaying(currentMainMenuSong) then
451 end
452end
453
454function PFW_MainMenu:new(x, y, width, height, playerObject)
455 local o = {}
456
457 o = ISPanel:new(x, y, width, height)
458 setmetatable(o, self)
459 self.__index = self
460 o.backgroundColor = {r=0, g=0, b=0, a=1}
461 o.borderColor = {r=0, g=0, b=0, a=1}
462 o.moveWithMouse = false
463 o.playerObject = playerObject
464 PFW_MainMenu.instance = o
465
466 return o
467end
468
469return PFW_MainMenu
void GamemodeDescription()
void MainMenuImage()
void Version()
void MainMenuMusic()
void GamemodeTitle()
void FrameworkZ Config()
void VersionType()
void self survivor()
void characterData EQUIPMENT_SLOT_FACE()
void characterData EQUIPMENT_SLOT_GLOVES()
void physique()
void characterData EQUIPMENT_SLOT_VEST()
void characterData EQUIPMENT_SLOT_SHOES()
void hairColor()
void skinColor()
void characterData EQUIPMENT_SLOT_OVERSHIRT()
void characterData EQUIPMENT_SLOT_HEAD()
void characterData EQUIPMENT_SLOT_BACKPACK()
void eyeColor()
void weight()
void characterData EQUIPMENT_SLOT_UNDERSHIRT()
void characterData EQUIPMENT_SLOT_SOCKS()
void characterData EQUIPMENT_SLOT_BELT()
void player
void age()
void characterData EQUIPMENT_SLOT_EARS()
void characterData EQUIPMENT_SLOT_PANTS()
void name()
void self self faceDropdown()
void self self vestDropdown()
void self self socksDropdown()
void self self pantsDropdown()
void self self overshirtDropdown()
void self self backpackDropdown()
void self beardDropdown()
void self self earsDropdown()
void self self shoesDropdown()
void self self beltDropdown()
void self self undershirtDropdown()
void self self headDropdown()
void self self glovesDropdown()
void self faction()
void local instance()
void itemID()
void self currentIndex()
void self createCharacterButton font()
void local widthReturn()
void local y()
void local createCharacterLabel()
void self self onFinalizeCharacter
Definition MainMenu.lua:91
void if not description or description()
void local stepWidth
Definition MainMenu.lua:73
void self self onEnterInfoMenu
Definition MainMenu.lua:87
void local yReturn()
void local mainMenuMusicVolume()
void self loadCharacterBackButton()
void local height()
void self hasFlashed2()
void local subtitle()
void self MainMenu
Definition MainMenu.lua:91
void self emitter()
void self self self onExitAppearanceMenu
Definition MainMenu.lua:89
void self closeButton()
void local heightLoad()
void self self self onExitInfoMenu
Definition MainMenu.lua:87
void self shouldFlashLightning()
void local yLoad()
void local xReturn()
void self self
Definition MainMenu.lua:85
void self disconnectButton()
void local stepY()
void self createCharacterSteps onExitInitialMenu()
void self loadCharacterForwardButton()
void self self nil
Definition MainMenu.lua:91
void self titleY()
void local width()
void self createCharacterButton()
void local stepHeight()
void self hasFlashed1()
void local heightReturn()
void self self onEnterAppearanceMenu
Definition MainMenu.lua:89
void local disconnectLabel()
void self self self onExitFactionMenu
Definition MainMenu.lua:85
void local loadCharacterLabel()
void PFW_MainMenu()
void local xLoad()
void local widthLoad()
void local currentMainMenuSong()
void local middleY()
void self loadCharacterMenu()
void self SelectFaction
Definition MainMenu.lua:85
void local success()
void self createCharacterSteps
Definition MainMenu.lua:85
void self hasFlashed3()
void local middleX()
void self loadCharacterButton()
void local nextLightning()
void self uiHelper()
void local stepX
Definition MainMenu.lua:75
void local x()
void self self onEnterFactionMenu
Definition MainMenu.lua:85
void warningMessage()
void local title()
void self createCharacterSteps onEnterInitialMenu()
void processingNotification backgroundColor a()
void local character()
void characterModData characters()
void characterModData maxCharacters()
Players module for FrameworkZ. Defines and interacts with PLAYER object.
Definition Players.lua:13
FrameworkZ global table.
void initialise()
void prerender()
void onEnterMainMenuFromLoadCharacterMenu()
void onExitFactionMenu(menu)
void onEnterFactionMenu(menu)
void onLoadCharacter()
void onClose()
void onEnterInfoMenu(menu)
void hideStepControls(backButton, forwardButton)
void onFinalizeCharacter(menu)
void onDisconnect()
void onEnterMainMenu()
void showStepControls(menu, backButtonIndex, backButton, backButtonText, forwardButtonIndex, forwardButton, forwardButtonText)
void onExitAppearanceMenu(menu)
void fadeOutMainMenuMusic()
void onEnterAppearanceMenu(menu)
void onExitMainMenu()
void onEnterLoadCharacterMenu()
void onExitInfoMenu(menu, isForward)