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