FrameworkZ 4.4.2
Provides a framework for Project Zomboid with various systems.
Loading...
Searching...
No Matches
CreateCharacterInfo.lua
Go to the documentation of this file.
1require "ISUI/ISPanel"
3PFW_CreateCharacterInfo = ISPanel:derive("PFW_CreateCharacterInfo")
5function PFW_CreateCharacterInfo:initialise()
7 self.warningStep = 0.02
8 self.warningRed = 1
11 self.isAbnormal = false
13 local emitter = self.playerObject:getEmitter()
14 local title = "Information"
15 local subtitle = "Enter your character's general info."
16 local xPadding = self.width * 0.2
17 local entryWidth = self.width * 0.7
18 local middleX = self.width / 2 - (xPadding + entryWidth) / 2
19 local entryX = middleX + xPadding
20 local labelX = middleX + xPadding - 5
21 local yOffset = 0
22
23 self.nameLimit = 32
24 self.recommendedNameLength = 8
25 self.descriptionLimit = 256
26 self.recommendedDescriptionLength = 24
28 -- 9 fields (1 double height) = 9 * 30 + 75 = 345
30 ISPanel.initialise(self)
32 yOffset = self.uiHelper.GetHeight(UIFont.Title, title)
33
34 self.title = ISLabel:new(self.uiHelper.GetMiddle(self.width, UIFont.Title, title), yOffset, 25, title, 1, 1, 1, 1, UIFont.Title, true)
35 self.title:initialise()
36 self:addChild(self.title)
38 yOffset = yOffset + self.uiHelper.GetHeight(UIFont.Large, subtitle)
40 self.subtitle = ISLabel:new(self.uiHelper.GetMiddle(self.width, UIFont.Large, subtitle), yOffset, 25, subtitle, 1, 1, 1, 1, UIFont.Large, true)
41 self.subtitle:initialise()
42 self:addChild(self.subtitle)
43
44 yOffset = yOffset + 45
45
46 self.genderLabel = ISLabel:new(labelX, yOffset, 25, "Gender:", 1, 1, 1, 1, UIFont.Large, false)
47 self.genderLabel:initialise()
48 self:addChild(self.genderLabel)
49
50 self.gender = "Male"
51 self.genderDropdown = ISComboBox:new(entryX, yOffset, entryWidth, 25, self, self.onGenderChanged)
52 self.genderDropdown:addOption("Male")
53 self.genderDropdown:addOption("Female")
54 self:addChild(self.genderDropdown)
55
56 yOffset = yOffset + 30
57
58 self.nameLabel = ISLabel:new(labelX, yOffset, 25, "Name (32):", 1, 1, 1, 1, UIFont.Large, false)
59 self.nameLabel:initialise()
60 self:addChild(self.nameLabel)
61
62 self.nameEntry = ISTextEntryBox:new("", entryX, yOffset, entryWidth, 25)
63 self.nameEntry.backgroundColor = {r=0, g=0, b=0, a=1.0}
64 self.nameEntry.borderColor = {r=1, g=0, b=0, a=1.0}
65 self.nameEntry:initialise()
66 self.nameEntry:instantiate()
67 self:addChild(self.nameEntry)
68
69 yOffset = yOffset + 30
70
71 self.descriptionLabel = ISLabel:new(labelX, yOffset, 25, "Description (256):", 1, 1, 1, 1, UIFont.Large, false)
72 self.descriptionLabel:initialise()
73 self:addChild(self.descriptionLabel)
74
75 self.descriptionEntry = ISTextEntryBox:new("", entryX, yOffset, entryWidth, 100)
76 self.descriptionEntry.backgroundColor = {r=0, g=0, b=0, a=1.0}
77 self.descriptionEntry.borderColor = {r=1, g=0, b=0, a=1}
78 self.descriptionEntry:initialise()
79 self.descriptionEntry:instantiate()
80 self.descriptionEntry:setMultipleLine(true)
81 self.descriptionEntry:setMaxLines(0)
82 self:addChild(self.descriptionEntry)
83
84 yOffset = yOffset + 110
85
86 self.ageLabel = ISLabel:new(labelX, yOffset, 25, "Age (25):", 1, 1, 1, 1, UIFont.Large, false)
87 self.ageLabel:initialise()
88 self:addChild(self.ageLabel)
89
90 self.ageSlider = ISSliderPanel:new(entryX, yOffset, entryWidth, 25, self, self.onAgeChanged)
91 self.ageSlider.currentValue = 25
92 self.ageSlider.minValue = FrameworkZ.Config.CharacterMinAge
93 self.ageSlider.maxValue = FrameworkZ.Config.CharacterMaxAge
94 self.ageSlider.stepValue = 1
95 self:addChild(self.ageSlider)
96
97 --[[self.ageDropdown = ISComboBox:new(entryX, yOffset, entryWidth, 25)
98 self.ageDropdown:addOption("18")
99 self.ageDropdown:addOption("19")
100 self.ageDropdown:addOption("20")
101 -- Add more age options as needed
102 self:addChild(self.ageDropdown)--]]
103
104 yOffset = yOffset + 30
105
106 self.heightLabel = ISLabel:new(labelX, yOffset, 25, "Height (5'10\"):", 1, 1, 1, 1, UIFont.Large, false)
107 self.heightLabel:initialise()
108 self:addChild(self.heightLabel)
109
110 self.heightSlider = ISSliderPanel:new(entryX, yOffset, entryWidth, 25, self, self.onHeightChanged)
111 self.heightSlider.currentValue = 70
112 self.heightSlider.minValue = FrameworkZ.Config.CharacterMinHeight
113 self.heightSlider.maxValue = FrameworkZ.Config.CharacterMaxHeight
114 self.heightSlider.stepValue = 1
115 self:addChild(self.heightSlider)
116
117 --[[self.heightFeetDropdown = ISComboBox:new(entryX, yOffset, entryWidth, 25)
118 self.heightFeetDropdown:addOption("5")
119 self.heightFeetDropdown:addOption("6")
120 -- Add more height options as needed
121 self:addChild(self.heightFeetDropdown)--]]
122
123 --[[
124 yOffset = yOffset + 30
125
126 self.heightInchesLabel = ISLabel:new(labelX, yOffset, 25, "Height (10\"):", 1, 1, 1, 1, UIFont.Large, false)
127 self.heightInchesLabel:initialise()
128 self:addChild(self.heightInchesLabel)
129
130 self.heightInchesSlider = ISSliderPanel:new(entryX, yOffset, entryWidth, 25, self, self.onHeightInchesChanged)
131 self.heightInchesSlider.currentValue = 10
132 self.heightInchesSlider.minValue = 0
133 self.heightInchesSlider.maxValue = 11
134 self.heightInchesSlider.stepValue = 1
135 self:addChild(self.heightInchesSlider)
136 --]]
137
138 --[[self.heightInchesDropdown = ISComboBox:new(entryX, yOffset, entryWidth, 25)
139 self.heightInchesDropdown:addOption("0")
140 self.heightInchesDropdown:addOption("1")
141 -- Add more height options as needed
142 self:addChild(self.heightInchesDropdown)--]]
143
144 yOffset = yOffset + 30
145
146 self.weightLabel = ISLabel:new(labelX, yOffset, 25, "Weight (150 lb):", 1, 1, 1, 1, UIFont.Large, false)
147 self.weightLabel:initialise()
148 self:addChild(self.weightLabel)
149
150 self.weightSlider = ISSliderPanel:new(entryX, yOffset, entryWidth, 25, self, self.onWeightChanged)
151 self.weightSlider.currentValue = 150
152 self.weightSlider.minValue = FrameworkZ.Config.CharacterMinWeight
153 self.weightSlider.maxValue = FrameworkZ.Config.CharacterMaxWeight
154 self.weightSlider.stepValue = 5
155 self:addChild(self.weightSlider)
156
157 yOffset = yOffset + 30
158
159 self.physiqueLabel = ISLabel:new(labelX, yOffset, 25, "Physique:", 1, 1, 1, 1, UIFont.Large, false)
160 self.physiqueLabel:initialise()
161 self:addChild(self.physiqueLabel)
162
163 self.physiqueDropdown = ISComboBox:new(entryX, yOffset, entryWidth, 25)
164 self.physiqueDropdown:addOption("Skinny")
165 self.physiqueDropdown:addOption("Slim")
166 self.physiqueDropdown:addOption("Average")
167 self.physiqueDropdown:addOption("Muscular")
168 self.physiqueDropdown:addOption("Overweight")
169 self.physiqueDropdown:addOption("Obese")
170 self.physiqueDropdown:initialise()
171 self.physiqueDropdown:select("Average")
172 self:addChild(self.physiqueDropdown)
173
174 yOffset = yOffset + 30
175
176 self.eyeColorLabel = ISLabel:new(labelX, yOffset, 25, "Eye Color:", 1, 1, 1, 1, UIFont.Large, false)
177 self.eyeColorLabel:initialise()
178 self:addChild(self.eyeColorLabel)
179
180 self.eyeColorDropdown = ISComboBox:new(entryX, yOffset, entryWidth, 25)
181 self.eyeColorDropdown:addOption("Blue")
182 self.eyeColorDropdown:addOption("Brown")
183 self.eyeColorDropdown:addOption("Gray")
184 self.eyeColorDropdown:addOption("Green")
185 self.eyeColorDropdown:addOption("Heterochromatic")
186 -- Add more eye color options as needed
187 self:addChild(self.eyeColorDropdown)
188
189 yOffset = yOffset + 30
190
191 self.hairColorLabel = ISLabel:new(labelX, yOffset, 25, "Hair Color:", 1, 1, 1, 1, UIFont.Large, false)
192 self.hairColorLabel:initialise()
193 self:addChild(self.hairColorLabel)
194
195 self.hairColorDropdown = ISComboBox:new(entryX, yOffset, entryWidth, 25)
196 self.hairColorDropdown:addOptionWithData("Black", {r = HAIR_COLOR_BLACK_R, g = HAIR_COLOR_BLACK_G, b = HAIR_COLOR_BLACK_B})
197 self.hairColorDropdown:addOptionWithData("Blonde", {r = HAIR_COLOR_BLONDE_R, g = HAIR_COLOR_BLONDE_G, b = HAIR_COLOR_BLONDE_B})
198 self.hairColorDropdown:addOptionWithData("Brown", {r = HAIR_COLOR_BROWN_R, g = HAIR_COLOR_BROWN_G, b = HAIR_COLOR_BROWN_B})
199 self.hairColorDropdown:addOptionWithData("Gray", {r = HAIR_COLOR_GRAY_R, g = HAIR_COLOR_GRAY_G, b = HAIR_COLOR_GRAY_B})
200 self.hairColorDropdown:addOptionWithData("Red", {r = HAIR_COLOR_RED_R, g = HAIR_COLOR_RED_G, b = HAIR_COLOR_RED_B})
201 self.hairColorDropdown:addOptionWithData("White", {r = HAIR_COLOR_WHITE_R, g = HAIR_COLOR_WHITE_G, b = HAIR_COLOR_WHITE_B})
202 self:addChild(self.hairColorDropdown)
203
204 yOffset = yOffset + 30
205
206 self.skinColorLabel = ISLabel:new(labelX, yOffset, 25, "Skin Color:", 1, 1, 1, 1, UIFont.Large, false)
207 self.skinColorLabel:initialise()
208 self:addChild(self.skinColorLabel)
209
210 self.skinColorDropdown = ISComboBox:new(entryX, yOffset, entryWidth, 25)
211 self.skinColorDropdown:addOptionWithData("Pale", SKIN_COLOR_PALE)
212 self.skinColorDropdown:addOptionWithData("White", SKIN_COLOR_WHITE)
213 self.skinColorDropdown:addOptionWithData("Tanned", SKIN_COLOR_TANNED)
214 self.skinColorDropdown:addOptionWithData("Brown", SKIN_COLOR_BROWN)
215 self.skinColorDropdown:addOptionWithData("Dark Brown", SKIN_COLOR_DARK_BROWN)
216 self:addChild(self.skinColorDropdown)
217
218 yOffset = yOffset + 30
219
220 -- HL2RP abnormal stuff
221 --[[
222 local warningText1 = "Your character would be considered abnormal."
223 local warningText2 = "The Combine will target you."
224
225 self.abnormalLabel1 = ISLabel:new(self.uiHelper.GetMiddle(self.width, UIFont.Large, warningText1), yOffset, 50, warningText1, 1, 1, 1, 1, UIFont.Large, true)
226 self.abnormalLabel1:initialise()
227 self.abnormalLabel1:setVisible(false)
228 self:addChild(self.abnormalLabel1)
229
230 yOffset = yOffset + 30
231
232 self.abnormalLabel2 = ISLabel:new(self.uiHelper.GetMiddle(self.width, UIFont.Large, warningText2), yOffset, 50, warningText2, 1, 1, 1, 1, UIFont.Large, true)
233 self.abnormalLabel2:initialise()
234 self.abnormalLabel2:setVisible(false)
235 self:addChild(self.abnormalLabel2)
236 --]]
237
238 --[[self.weightDropdown = ISComboBox:new(entryX, yOffset, entryWidth, 25)
239 self.weightDropdown:addOption("0")
240 self.weightDropdown:addOption("25")
241 -- Add more weight options as needed
242 self:addChild(self.weightDropdown)--]]
243end
244
245function PFW_CreateCharacterInfo:onGenderChanged(dropdown)
246 self.gender = dropdown:getOptionText(dropdown.selected)
247end
248
249function PFW_CreateCharacterInfo:onAgeChanged(newValue, slider)
250 self.ageLabel:setName("Age (" .. newValue .. "):")
251
252 -- HL2RP abnormal stuff
253 --[[
254 if newValue < 20 or newValue >= 60 then
255 self.isAbnormal = true
256 self.abnormalLabel1:setVisible(true)
257 self.abnormalLabel2:setVisible(true)
258 else
259 self.isAbnormal = false
260 self.abnormalLabel1:setVisible(false)
261 self.abnormalLabel2:setVisible(false)
262 end
263 --]]
264end
265
266function PFW_CreateCharacterInfo:onHeightChanged(newValue, slider)
267 local feet = math.floor(newValue / 12)
268 local inches = newValue % 12
269
270 self.heightLabel:setName("Height (" .. feet .. "' " .. inches .. "\"):")
271
272 -- HL2RP abnormal stuff
273 --[[
274 if newValue < 60 or newValue > 74 then
275 self.isAbnormal = true
276 self.abnormalLabel1:setVisible(true)
277 self.abnormalLabel2:setVisible(true)
278 else
279 self.isAbnormal = false
280 self.abnormalLabel1:setVisible(false)
281 self.abnormalLabel2:setVisible(false)
282 end
283 --]]
284end
285
286function PFW_CreateCharacterInfo:onWeightChanged(newValue, slider)
287 self.weightLabel:setName("Weight (" .. newValue .. " lb):")
288
289 -- HL2RP abnormal stuff
290 --[[
291 if newValue < 125 or newValue > 175 then
292 self.isAbnormal = true
293 self.abnormalLabel1:setVisible(true)
294 self.abnormalLabel2:setVisible(true)
295 else
296 self.isAbnormal = false
297 self.abnormalLabel1:setVisible(false)
298 self.abnormalLabel2:setVisible(false)
299 end
300 --]]
301end
302
303function PFW_CreateCharacterInfo:prerender()
304 ISPanel.prerender(self)
305end
306
307function PFW_CreateCharacterInfo:update()
308 ISPanel.update(self)
309
310 -- HL2RP abnormal stuff
311 --[[
312 if self.abnormalLabel1 and self.abnormalLabel2 and self.abnormalLabel1:getIsVisible() == true and self.abnormalLabel2:getIsVisible() == true then
313 if self.warningTurningRed == true then
314 if self.warningGreen > 0 or self.warningBlue > 0 then
315 self.warningGreen = self.warningGreen - self.warningStep
316 self.warningBlue = self.warningBlue - self.warningStep
317 else
318 self.warningTurningRed = false
319 end
320 else
321 if self.warningGreen < 1 or self.warningBlue < 1 then
322 self.warningGreen = self.warningGreen + self.warningStep
323 self.warningBlue = self.warningBlue + self.warningStep
324 else
326 end
327 end
328
329 self.abnormalLabel1:setColor(self.warningRed, self.warningGreen, self.warningBlue)
330 self.abnormalLabel2:setColor(self.warningRed, self.warningGreen, self.warningBlue)
331 end
332 --]]
333
334 if self.nameLabel and self.nameEntry then
335 local usedCharacters = string.len(self.nameEntry:getText())
336 local remainingCharacters = self.nameLimit - usedCharacters
337
338 if remainingCharacters < 0 then
339 self.nameEntry:setText(string.sub(self.nameEntry:getText(), 1, self.nameLimit))
341 end
342
343 local red, green
344 if usedCharacters >= self.nameLimit then
345 red = 1
346 green = 1
347 else
348 if usedCharacters <= self.recommendedNameLength then
349 local ratio = usedCharacters / self.recommendedNameLength
350 red = 1 - ratio
351 green = ratio
352 else
353 local ratio = (usedCharacters - self.recommendedNameLength) / (self.nameLimit - self.recommendedNameLength)
354 red = math.max(0, math.min(1, ratio * 0.5))
355 green = math.max(0, math.min(1, 1 - ratio * 0.5))
356 end
357 end
358
359 self.nameLabel:setName("Name (" .. remainingCharacters .. "):")
360 self.nameEntry.borderColor = {r=red, g=green, b=0, a=0.7}
361 end
362
363 if self.descriptionLabel and self.descriptionEntry then
364 local usedCharacters = string.len(self.descriptionEntry:getText())
365 local remainingCharacters = self.descriptionLimit - usedCharacters
366
367 if remainingCharacters < 0 then
368 self.descriptionEntry:setText(string.sub(self.descriptionEntry:getText(), 1, self.descriptionLimit))
370 end
371
372 local red, green
373 if usedCharacters >= self.descriptionLimit then
374 red = 1
375 green = 1
376 else
377 if usedCharacters <= self.recommendedDescriptionLength then
378 local ratio = usedCharacters / self.recommendedDescriptionLength
379 red = 1 - ratio
380 green = ratio
381 else
382 local ratio = (usedCharacters - self.recommendedDescriptionLength) / (self.descriptionLimit - self.recommendedDescriptionLength)
383 red = math.max(0, math.min(1, ratio * 0.5))
384 green = math.max(0, math.min(1, 1 - ratio * 0.5))
385 end
386 end
387
388 self.descriptionLabel:setName("Description (" .. remainingCharacters .. "):")
389 self.descriptionEntry.borderColor = {r=red, g=green, b=0, a=0.7}
390 end
391end
392
393function PFW_CreateCharacterInfo:new(parameters)
394 local o = {}
395
396 o = ISPanel:new(parameters.x, parameters.y, parameters.width, parameters.height)
397 setmetatable(o, self)
398 self.__index = self
399 o.backgroundColor = {r=0, g=0, b=0, a=0}
400 o.borderColor = {r=0, g=0, b=0, a=0}
401 o.moveWithMouse = false
402 o.playerObject = parameters.playerObject
403 PFW_CreateCharacterInfo.instance = o
404
405 return o
406end
407
void CharacterMaxHeight()
void CharacterMinAge()
void CharacterMaxAge()
void CharacterMinHeight()
void FrameworkZ Config()
void CharacterMinWeight()
void CharacterMaxWeight()
void if select("#",...)()
void local color()
void self uiHelper()
void local descriptionLabel()
void weight()
void age()
void local yOffset()
void self subtitle()
void self title()
void green()
void red()
void self warningTurningRed()
void self warningBlue()
void self warningGreen()
void local usedCharacters()
void local remainingCharacters()
void PFW_CreateCharacterInfo()
Definition MainMenu.lua:87
void local height()
void local width
void self emitter()
void self self
Definition MainMenu.lua:85
void local middleX()
void processingNotification backgroundColor a()
void local character()
FrameworkZ global table.
void onGenderChanged(dropdown)
void onWeightChanged(newValue, slider)
void onAgeChanged(newValue, slider)
void onHeightChanged(newValue, slider)