FrameworkZ 10.8.3
Provides a framework for Project Zomboid with various systems.
Loading...
Searching...
No Matches
CreateCharacterAppearance.lua
Go to the documentation of this file.
2FrameworkZ.Interfaces:Register(FrameworkZ.UI.CreateCharacterAppearance, "CreateCharacterAppearance")
3
4local yOffset = 0
5
7 ISPanel.initialise(self)
9 local isFemale = (self.gender == "Female" and true) or (self.gender == "Male" and false)
10 self.survivor = SurvivorFactory:CreateSurvivor(SurvivorType.Neutral, isFemale)
11 self.survivor:setFemale(isFemale)
12 self.survivor:getHumanVisual():setSkinTextureIndex(self.skinColor)
13
14 local immutableColor = ImmutableColor.new(self.hairColor.r, self.hairColor.g, self.hairColor.b, 1)
15
16 self.survivor:getHumanVisual():setHairColor(immutableColor)
17 self.survivor:getHumanVisual():setBeardColor(immutableColor)
18 self.survivor:getHumanVisual():setNaturalHairColor(immutableColor)
19 self.survivor:getHumanVisual():setNaturalBeardColor(immutableColor)
23 local title = "Appearance"
24 local subtitle = "Customize your character's appearance."
25 local factionWidth = 500
26 local factionHeight = 300
27 local dropdownWidth = self.width * 0.5
28 local middleX = self.width / 2
29 local quarterX = self.width / 4
30 self.factionsClothing = FrameworkZ.Factions:GetFactionByID(self.faction).clothing
31 self.initialFaction = nil
32 local entryWidth = 200
33 local xPadding = self.width * 0.1
34 local entryX = xPadding
35 local labelX = xPadding - 5
36
37 ISPanel.initialise(self)
38
39 yOffset = self.uiHelper.GetHeight(UIFont.Title, title)
40
41 self.title = ISLabel:new(self.uiHelper.GetMiddle(self.width, UIFont.Title, title), yOffset, 25, title, 1, 1, 1, 1, UIFont.Title, true)
42 self.title:initialise()
43 self:addChild(self.title)
44
45 yOffset = yOffset + self.uiHelper.GetHeight(UIFont.Large, subtitle)
46
47 self.subtitle = ISLabel:new(self.uiHelper.GetMiddle(self.width, UIFont.Large, subtitle), yOffset, 25, subtitle, 1, 1, 1, 1, UIFont.Large, true)
48 self.subtitle:initialise()
49 self:addChild(self.subtitle)
50
51 yOffset = yOffset + 45
52
54 self.characterPreview:initialise()
56 self.characterPreview:setSurvivorDesc(self.survivor)
58
59 self.hairLabel = ISLabel:new(entryX - 5, yOffset, 25, "Hair:", 1, 1, 1, 1, UIFont.Large, false)
60 self.hairLabel:initialise()
61 self:addChild(self.hairLabel)
62
63 local hairStyles = getAllHairStyles(isFemale)
64
65 self.hairDropdown = ISComboBox:new(entryX, yOffset, entryWidth, 25, self, self.onHairChanged)
66
67 for i = 1, hairStyles:size() do
68 local styleId = hairStyles:get(i - 1)
69 local hairStyle = isFemale and getHairStylesInstance():FindFemaleStyle(styleId) or getHairStylesInstance():FindMaleStyle(styleId)
70 local label = styleId
72 if label == "" then
73 label = getText("IGUI_Hair_Bald")
74 else
75 label = getText("IGUI_Hair_" .. label)
76 end
78 if not hairStyle:isNoChoose() then
79 self.hairDropdown:addOptionWithData(label, hairStyles:get(i - 1))
80 end
81 end
82
83 self.hairDropdown:initialise()
84 self:onHairChanged(self.hairDropdown)
85 self:addChild(self.hairDropdown)
86
87 yOffset = yOffset + 30
88
89 self.beardLabel = ISLabel:new(entryX - 5, yOffset, 25, "Beard:", 1, 1, 1, 1, UIFont.Large, false)
90 self.beardLabel:initialise()
91 self:addChild(self.beardLabel)
92
93 self.beardDropdown = ISComboBox:new(entryX, yOffset, entryWidth, 25, self, self.onBeardChanged)
94
95 if not isFemale then
96 local beardStyles = getAllBeardStyles()
97
98 for i = 1, beardStyles:size() do
99 local label = beardStyles:get(i - 1)
100
101 if label == "" then
102 label = getText("IGUI_Beard_None")
103 else
104 label = getText("IGUI_Beard_" .. label);
105 end
106
107 self.beardDropdown:addOptionWithData(label, beardStyles:get(i - 1))
108 end
109 end
110
111 if isFemale then
112 self.beardDropdown:addOptionWithData("N/A", nil)
113 end
114
115 self.beardDropdown:initialise()
116 self:onBeardChanged(self.beardDropdown)
117 self:addChild(self.beardDropdown)
118
119 yOffset = yOffset + 30
120
121 if self.factionsClothing then
122 self.headLabel, self.headDropdown = self:addClothingOption(entryX, yOffset, 25, entryWidth, "Head:", "Hat", self.factionsClothing.head)
123 self.faceLabel, self.faceDropdown = self:addClothingOption(entryX, yOffset, 25, entryWidth, "Face:", "Mask", self.factionsClothing.face)
124 self.earsLabel, self.earsDropdown = self:addClothingOption(entryX, yOffset, 25, entryWidth, "Ears:", "Ears", self.factionsClothing.ears)
125 self.backpackLabel, self.backpackDropdown = self:addClothingOption(entryX, yOffset, 25, entryWidth, "Backpack:", "Back", self.factionsClothing.backpack)
126 self.glovesLabel, self.glovesDropdown = self:addClothingOption(entryX, yOffset, 25, entryWidth, "Gloves:", "Hands", self.factionsClothing.gloves)
127 self.undershirtLabel, self.undershirtDropdown = self:addClothingOption(entryX, yOffset, 25, entryWidth, "Undershirt:", "Tshirt", self.factionsClothing.undershirt)
128 self.overshirtLabel, self.overshirtDropdown = self:addClothingOption(entryX, yOffset, 25, entryWidth, "Overshirt:", "Shirt", self.factionsClothing.overshirt)
129 self.vestLabel, self.vestDropdown = self:addClothingOption(entryX, yOffset, 25, entryWidth, "Vest:", "TorsoExtraVest", self.factionsClothing.vest)
130 self.beltLabel, self.beltDropdown = self:addClothingOption(entryX, yOffset, 25, entryWidth, "Belt:", "Belt", self.factionsClothing.belt)
131 self.pantsLabel, self.pantsDropdown = self:addClothingOption(entryX, yOffset, 25, entryWidth, "Pants:", "Pants", self.factionsClothing.pants)
132 self.socksLabel, self.socksDropdown = self:addClothingOption(entryX, yOffset, 25, entryWidth, "Socks:", "Socks", self.factionsClothing.socks)
133 self.shoesLabel, self.shoesDropdown = self:addClothingOption(entryX, yOffset, 25, entryWidth, "Shoes:", "Shoes", self.factionsClothing.shoes)
134 end
135end
136
137function FrameworkZ.UI.CreateCharacterAppearance:addClothingOption(x, y, height, entryWidth, labelText, clothingLocation, clothingTable)
138 if not clothingTable then return nil, nil end
139
140 local label = ISLabel:new(x - 5, y, height, labelText, 1, 1, 1, 1, UIFont.Large, false)
141 label:initialise()
142 self:addChild(label)
143
144 local dropdown = ISComboBox:new(x, y, entryWidth, height,self, self.onClothingChanged)
145
146 if clothingTable then
147 for k, v in pairs(clothingTable) do
148 dropdown:addOptionWithData(v, {location = clothingLocation, itemID = k})
149 end
150 end
151
152 dropdown:addOptionWithData("None", {location = clothingLocation, itemID = nil})
153 dropdown:initialise()
154 self:onClothingChanged(dropdown)
155 self:addChild(dropdown)
156
157 if not clothingTable then
158 label:setVisible(false)
159 dropdown:setVisible(false)
160
161 return label, dropdown
162 end
163 yOffset = yOffset + 30
164
165 return label, dropdown
166end
167
168function FrameworkZ.UI.CreateCharacterAppearance:onHairChanged(dropdown)
169 local hair = dropdown:getOptionData(dropdown.selected)
170
171 self.hairType = dropdown.selected - 1
172 self.survivor:getHumanVisual():setHairModel(hair)
173 self.characterPreview:setSurvivorDesc(self.survivor)
174end
175
176function FrameworkZ.UI.CreateCharacterAppearance:onBeardChanged(dropdown)
177 local beard = dropdown:getOptionData(dropdown.selected)
178
179 self.beardType = dropdown.selected - 1
180 self.survivor:getHumanVisual():setBeardModel(beard)
181 self.characterPreview:setSurvivorDesc(self.survivor)
182end
183
184function FrameworkZ.UI.CreateCharacterAppearance:onClothingChanged(dropdown)
185 if not dropdown then return end
186
187 local dropdownData = dropdown:getOptionData(dropdown.selected)
188 local itemID = dropdownData.itemID
189 local location = dropdownData.location
190 local item = InventoryItemFactory.CreateItem(itemID)
191
192 self.survivor:setWornItem(location, nil)
193
194 if item then
195 self.survivor:setWornItem(location, item)
196 end
197
198 self.characterPreview:setSurvivorDesc(self.survivor)
199end
200
201function FrameworkZ.UI.CreateCharacterAppearance:resetGender(newGender)
202 if self.survivor and self.gender ~= newGender then
203 self.gender = newGender
204
205 local isFemale = (self.gender == "Female" and true) or (self.gender == "Male" and false)
206 self.survivor = SurvivorFactory:CreateSurvivor(SurvivorType.Neutral, isFemale)
207 self.survivor:setFemale(isFemale)
208 self:onClothingChanged(self.headDropdown)
209 self:onClothingChanged(self.undershirtDropdown)
210 self:onClothingChanged(self.overshirtDropdown)
211 self:onClothingChanged(self.pantsDropdown)
212 self:onClothingChanged(self.socksDropdown)
213 self:onClothingChanged(self.shoesDropdown)
214 self.characterPreview:setSurvivorDesc(self.survivor)
215
216 self:onHairChanged(self.hairDropdown)
217
218 self.wasGenderUpdated = true
219 end
220end
221
222function FrameworkZ.UI.CreateCharacterAppearance:resetHairColor()
223 if self.survivor then
224 local immutableColor = ImmutableColor.new(self.hairColor.r, self.hairColor.g, self.hairColor.b, 1)
225
226 self.survivor:getHumanVisual():setHairColor(immutableColor)
227 self.survivor:getHumanVisual():setBeardColor(immutableColor)
228 self.survivor:getHumanVisual():setNaturalHairColor(immutableColor)
229 self.survivor:getHumanVisual():setNaturalBeardColor(immutableColor)
230
231 self.characterPreview:setSurvivorDesc(self.survivor)
232 end
233end
234
235function FrameworkZ.UI.CreateCharacterAppearance:resetHairStyles()
236 if self.survivor then
237 local hairStyles = getAllHairStyles(self.survivor:isFemale())
238
239 self.hairDropdown:clear()
240
241 for i = 1, hairStyles:size() do
242 local styleId = hairStyles:get(i - 1)
243 local hairStyle = self.survivor:isFemale() and getHairStylesInstance():FindFemaleStyle(styleId) or getHairStylesInstance():FindMaleStyle(styleId)
244 local label = styleId
245
246 if label == "" then
247 label = getText("IGUI_Hair_Bald")
248 else
249 label = getText("IGUI_Hair_" .. label)
250 end
251
252 if not hairStyle:isNoChoose() then
253 self.hairDropdown:addOptionWithData(label, hairStyles:get(i - 1))
254 end
255 end
256
257 if self.wasGenderUpdated then
258 self.hairDropdown:select("Bald")
259 end
260
261 self:onHairChanged(self.hairDropdown)
262 end
263end
264
265function FrameworkZ.UI.CreateCharacterAppearance:resetBeardStyles()
266 if self.survivor then
267 local isFemale = (self.gender == "Female" and true) or (self.gender == "Male" and false)
268
269 if not isFemale then
270 local beardStyles = getAllBeardStyles()
271
272 self.beardDropdown:clear()
273
274 for i = 1, beardStyles:size() do
275 local label = beardStyles:get(i - 1)
276
277 if label == "" then
278 label = getText("IGUI_Beard_None")
279 else
280 label = getText("IGUI_Beard_" .. label)
281 end
282
283 self.beardDropdown:addOptionWithData(label, beardStyles:get(i - 1))
284 end
285
286 self:onBeardChanged(self.beardDropdown)
287 else
288 self.beardDropdown:clear()
289 self.beardDropdown:addOptionWithData("N/A", nil)
291
292 self:onBeardChanged(self.beardDropdown)
293 end
294 end
295end
296
297function FrameworkZ.UI.CreateCharacterAppearance:resetSkinColor()
298 if self.survivor then
299 self.survivor:getHumanVisual():setSkinTextureIndex(self.skinColor)
300 self.characterPreview:setSurvivorDesc(self.survivor)
301 end
302end
303
305 ISPanel.render(self)
306end
307
309 ISPanel.update(self)
310end
311
312function FrameworkZ.UI.CreateCharacterAppearance:new(parameters)
313 local o = {}
314
315 o = ISPanel:new(parameters.x, parameters.y, parameters.width, parameters.height)
316 setmetatable(o, self)
317 self.__index = self
318 o.backgroundColor = {r=0, g=0, b=0, a=0}
319 o.borderColor = {r=0, g=0, b=0, a=0}
320 o.moveWithMouse = false
321 o.playerObject = parameters.playerObject
322 o.faction = parameters.faction
323 o.gender = parameters.gender
324 o.skinColor = parameters.skinColor
325 o.hairColor = parameters.hairColor
327
328 return o
329end
330
void FrameworkZ UI CharacterPreview()
void local y()
void self characterPreview()
void self survivor()
void self uiHelper()
void local x()
void self self faceDropdown()
void self self vestDropdown()
void self self socksDropdown()
void FrameworkZ UI CreateCharacterAppearance()
Definition MainMenu.lua:93
void self self pantsDropdown()
void self self overshirtDropdown()
void self beltLabel
void self shoesLabel
void local beardStyles()
void self self backpackDropdown()
void self socksLabel
void self beardDropdown()
void self vestLabel
void self self earsDropdown()
void self earsLabel
void self backpackLabel
void self self shoesDropdown()
void self beardLabel()
void self overshirtLabel
void self pantsLabel
void self self beltDropdown()
void self headLabel
void self self undershirtDropdown()
void self self headDropdown()
void self faceLabel
void self glovesLabel
void self undershirtLabel
void local yOffset()
void self self glovesDropdown()
void for i()
void local label()
void self subtitle()
void self faction()
void self title()
void local height()
void local width
void item()
void itemID()
void self FrameworkZ UI self nil
Definition MainMenu.lua:95
void self self
Definition MainMenu.lua:89
void local middleX()
void processingNotification backgroundColor a()
void local isFemale()
void self playerListPanel render()
void local select()
void if type v()
void local getPlayer()
Factions module for FrameworkZ. Defines and interacts with FACTION object.
Definition Factions.lua:13
void addClothingOption(x, y, height, entryWidth, labelText, clothingLocation, clothingTable)
Contains all of the User Interfaces for FrameworkZ.