FrameworkZ 4.4.2
Provides a framework for Project Zomboid with various systems.
Loading...
Searching...
No Matches
LoadCharacterMenu.lua
Go to the documentation of this file.
1PFW_LoadCharacterMenu = ISPanel:derive("PFW_LoadCharacterMenu")
3function PFW_LoadCharacterMenu:initialise()
4 ISPanel.initialise(self)
5
7 self.gender = "Male"
9
11 local transitionButtonHeight = self.height / 2
12 local transitionButtonY = self.height / 2 - transitionButtonHeight / 2
13 local isFemale = (self.gender == "Female" and true) or (self.gender == "Male" and false)
15 local widthLeft = 150
16 local heightLeft = 300
17 local xLeft = self.width / 8 - widthLeft / 8
18 local yLeft = self.height / 2 - heightLeft / 2
20 local widthSelected = 200
21 local heightSelected = 400
22 local xSelected = self.width / 2 - widthSelected / 2
23 local ySelected = self.height / 2 - heightSelected / 2
24
25 local widthRight = 150
26 local heightRight = 300
27 local xRight = self.width - (self.width / 8 + widthLeft)
28 local yRight = self.height / 2 - heightLeft / 2
29
30 self.survivor = SurvivorFactory:CreateSurvivor(SurvivorType.Neutral, isFemale)
31 self.survivor:setFemale(isFemale)
32
33 self.nextButton = ISButton:new(self.width - 30, transitionButtonY, 30, transitionButtonHeight, ">", self, PFW_LoadCharacterMenu.onNext)
34 self.nextButton.font = UIFont.Large
35 self.nextButton.internal = "NEXT"
36 self.nextButton:initialise()
37 self.nextButton:instantiate()
38 self:addChild(self.nextButton)
39
40 self.previousButton = ISButton:new(0, transitionButtonY, 30, transitionButtonHeight, "<", self, PFW_LoadCharacterMenu.onPrevious)
41 self.previousButton.font = UIFont.Large
42 self.previousButton.internal = "PREVIOUS"
43 self.previousButton:initialise()
44 self.previousButton:instantiate()
45 self:addChild(self.previousButton)
46
47 self.leftCharacter = PFW_CharacterView:new(xLeft, yLeft, widthLeft, heightLeft, isoPlayer, self.characters[1], "", "", IsoDirections.SW)
48 self.leftCharacter:setVisible(false)
49 self.leftCharacter:initialise()
50 self:addChild(self.leftCharacter)
51
52 self.selectedCharacter = PFW_CharacterView:new(xSelected, ySelected, widthSelected, heightSelected, isoPlayer, self.characters[1], "", "", IsoDirections.S)
53 self.selectedCharacter:setVisible(false)
54 self.selectedCharacter:initialise()
55 self:addChild(self.selectedCharacter)
56
57 self.rightCharacter = PFW_CharacterView:new(xRight, yRight, widthRight, heightRight, isoPlayer, self.characters[1], "", "", IsoDirections.SE)
58 self.rightCharacter:setVisible(false)
59 self.rightCharacter:initialise()
60 self:addChild(self.rightCharacter)
61
62 if not self.player.previousCharacter then
63 if #self.characters == 1 then
64 self.selectedCharacter:setCharacter(self.characters[1])
65 self.selectedCharacter:reinitialize(self.characters[1])
66 self.selectedCharacter:setVisible(true)
67 elseif #self.characters >= 2 then
68 self.selectedCharacter:setCharacter(self.characters[1])
69 self.selectedCharacter:reinitialize(self.characters[1])
70
71 self.rightCharacter:setCharacter(self.characters[2])
72 self.rightCharacter:reinitialize(self.characters[2])
73
74 self.selectedCharacter:setVisible(true)
75 self.rightCharacter:setVisible(true)
76 end
77 else
78 for i = 1, #self.characters do
79 if i == self.player.previousCharacter then
80 self.currentIndex = i
81 break
82 end
83 end
84
85 if #self.characters == 1 then
86 self.selectedCharacter:setCharacter(self.characters[self.currentIndex])
87 self.selectedCharacter:reinitialize(self.characters[self.currentIndex])
88 self.selectedCharacter:setVisible(true)
89 self.leftCharacter:setVisible(false)
90 self.rightCharacter:setVisible(false)
91 elseif #self.characters >= 2 then
92 if self.currentIndex == 1 then
93 self.leftCharacter:setVisible(false)
94 self.rightCharacter:setVisible(true)
95 elseif self.currentIndex == #self.characters then
96 self.leftCharacter:setVisible(true)
97 self.rightCharacter:setVisible(false)
98 else
99 self.leftCharacter:setVisible(true)
100 self.rightCharacter:setVisible(true)
101 end
102
103 self.selectedCharacter:setCharacter(self.characters[self.currentIndex])
104 self.selectedCharacter:reinitialize(self.characters[self.currentIndex])
105 self.selectedCharacter:setVisible(true)
106
107 if self.leftCharacter:isVisible() then
108 self.leftCharacter:setCharacter(self.characters[self.currentIndex - 1])
109 self.leftCharacter:reinitialize(self.characters[self.currentIndex - 1])
110 end
111 if self.rightCharacter:isVisible() then
112 self.rightCharacter:setCharacter(self.characters[self.currentIndex + 1])
113 self.rightCharacter:reinitialize(self.characters[self.currentIndex + 1])
114 end
115 end
116 end
117
118 --[[
119 self.characterPreview = PFW_CharacterPreview:new(self.width / 2 - characterPreviewWidth / 2, self.height / 2 - characterPreviewHeight / 2, characterPreviewWidth, characterPreviewHeight, "EventIdle")
120 self.characterPreview:initialise()
121 self.characterPreview:removeChild(self.characterPreview.animCombo)
122 self.characterPreview:setCharacter(getPlayer())
123 self.characterPreview:setSurvivorDesc(self.survivor)
124 self:addChild(self.characterPreview)
125 --]]
126end
127
128function PFW_LoadCharacterMenu:onNext()
129 self.currentIndex = math.min(self.currentIndex + 1, #self.characters)
130 self:updateCharacterPreview()
131end
132
133function PFW_LoadCharacterMenu:onPrevious()
134 self.currentIndex = math.max(self.currentIndex - 1, 1)
135 self:updateCharacterPreview()
136end
137
138function PFW_LoadCharacterMenu:updateCharacterPreview()
139 self.selectedCharacter:setCharacter(self.characters[self.currentIndex])
140 self.selectedCharacter:reinitialize(self.characters[self.currentIndex])
141 self.selectedCharacter:setVisible(true)
142
143 if self.currentIndex > 1 then
144 self.leftCharacter:setCharacter(self.characters[self.currentIndex - 1])
145 self.leftCharacter:reinitialize(self.characters[self.currentIndex - 1])
146 self.leftCharacter:setVisible(true)
147 else
148 self.leftCharacter:setVisible(false)
149 end
150
151 if self.currentIndex < #self.characters then
152 self.rightCharacter:setCharacter(self.characters[self.currentIndex + 1])
153 self.rightCharacter:reinitialize(self.characters[self.currentIndex + 1])
154 self.rightCharacter:setVisible(true)
155 else
156 self.rightCharacter:setVisible(false)
157 end
158end
159
160function PFW_LoadCharacterMenu:render()
161 ISPanel.prerender(self)
162
163 -- Render the character preview and any other UI elements here
164end
165
166function PFW_LoadCharacterMenu:new(x, y, width, height, player)
167 local o = {}
168
169 o = ISPanel:new(x, y, width, height)
170 setmetatable(o, self)
171 self.__index = self
172 o.backgroundColor = {r=0, g=0, b=0, a=0}
173 o.borderColor = {r=0, g=0, b=0, a=0}
174 o.moveWithMouse = false
175 o.player = player
176 PFW_LoadCharacterMenu.instance = o
177
178 return o
179end
180
void local y()
void local isFemale()
void self survivor()
void local x()
void player
void self isoPlayer
void local height()
void local width
void self characterPreview()
void PFW_LoadCharacterMenu()
void self currentIndex()
void for i()
void self createCharacterButton font()
void self self
Definition MainMenu.lua:85
void processingNotification backgroundColor a()
void local getPlayer()
void local character()
void characterModData characters()
void characterModData previousCharacter()
void if item internal()