FrameworkZ 10.8.3
Provides a framework for Project Zomboid with various systems.
Loading...
Searching...
No Matches
CharacterView.lua
Go to the documentation of this file.
3
4function FrameworkZ.UI.CharacterView:initialise()
5 ISPanel.initialise(self)
7 local FONT_HEIGHT_SMALL = getTextManager():getFontHeight(UIFont.Small)
8 local FONT_HEIGHT_MEDIUM = getTextManager():getFontHeight(UIFont.Medium)
9 local FONT_HEIGHT_LARGE = getTextManager():getFontHeight(UIFont.Large)
13 end
17 end
20 for k, v in pairs(self.descriptionLabels) do
21 self:removeChild(v)
22 end
23 end
24
26 self.uiHelper = FrameworkZ.UI
27 local descriptionLines = self:getDescriptionLines(self.description)
28 local descriptionHeight = FONT_HEIGHT_SMALL * 4
29 local isFemale = (self.character.INFO_GENDER == "Female" and true) or (self.character.INFO_GENDER == "Male" and false)
30 local x = self.uiHelper.GetMiddle(self.width, UIFont.Medium, self.name)
31 local y = 0
32
33 self.survivor = SurvivorFactory:CreateSurvivor(SurvivorType.Neutral, isFemale)
34 self.survivor:setFemale(isFemale)
36 self.characterNameLabel = ISLabel:new(x, 0, FONT_HEIGHT_MEDIUM, self.name, 1, 1, 1, 1, UIFont.Medium, true)
42
43 self.characterPreview = FrameworkZ.UI.CharacterPreview:new(0, y, self.width, previewHeight, "EventIdle", self.defaultDirection)
44 self.characterPreview:initialise()
45 self.characterPreview:removeChild(self.characterPreview.animCombo)
48 self:updateAppearance()
49 self:addChild(self.characterPreview)
50
51 y = y + previewHeight
52
53 for k, v in pairs(descriptionLines) do
54 x = self.uiHelper.GetMiddle(self.width, UIFont.Small, v)
56 local totalLines = #descriptionLines
57 local adjustedK = k - 1
58 local alphaStart = 1.0
59 local alphaMin = 0.2
60 local decayRate = 5
61 local alpha
62
63 if totalLines == 1 then
64 alpha = alphaStart -- Directly set to alphaStart if there's only one line
65 else
66 alpha = alphaMin + (alphaStart - alphaMin) * ((1 - adjustedK / (totalLines - 1)) ^ decayRate)
67 alpha = math.max(alpha, alphaMin)
68 end
69
70 local descriptionLabel = ISLabel:new(x, y, FONT_HEIGHT_SMALL, v, 1, 1, 1, alpha, UIFont.Small, true)
71 descriptionLabel:initialise()
72 self:addChild(descriptionLabel)
73
74 table.insert(self.descriptionLabels, descriptionLabel)
75
76 if k <= 3 then
77 y = y + descriptionLabel.height
78 else
79 -- For more than 3 lines, the loop breaks after adding "..." to the last displayed line
80 break
81 end
82 end
83end
84
85function FrameworkZ.UI.CharacterView:render()
86 ISPanel.prerender(self)
87
88 -- Render the character preview and any other UI elements here
89end
90
91function FrameworkZ.UI.CharacterView:updateAppearance()
92 local survivor = self.survivor
93 local character = self.character
94
95 for k, v in ipairs (FrameworkZ.Characters.EquipmentSlots) do
96 survivor:setWornItem(v, nil)
97 end
98
99 local headItem = character.EQUIPMENT_SLOT_HEAD and InventoryItemFactory.CreateItem(character.EQUIPMENT_SLOT_HEAD.id) or nil
100 local faceItem = character.EQUIPMENT_SLOT_FACE and InventoryItemFactory.CreateItem(character.EQUIPMENT_SLOT_FACE.id) or nil
101 local earsItem = character.EQUIPMENT_SLOT_EARS and InventoryItemFactory.CreateItem(character.EQUIPMENT_SLOT_EARS.id) or nil
102 local backpackItem = character.EQUIPMENT_SLOT_BACKPACK and InventoryItemFactory.CreateItem(character.EQUIPMENT_SLOT_BACKPACK.id) or nil
103 local glovesItem = character.EQUIPMENT_SLOT_GLOVES and InventoryItemFactory.CreateItem(character.EQUIPMENT_SLOT_GLOVES.id) or nil
104 local undershirtItem = character.EQUIPMENT_SLOT_UNDERSHIRT and InventoryItemFactory.CreateItem(character.EQUIPMENT_SLOT_UNDERSHIRT.id) or nil
105 local overshirtItem = character.EQUIPMENT_SLOT_OVERSHIRT and InventoryItemFactory.CreateItem(character.EQUIPMENT_SLOT_OVERSHIRT.id) or nil
106 local vestItem = character.EQUIPMENT_SLOT_VEST and InventoryItemFactory.CreateItem(character.EQUIPMENT_SLOT_VEST.id) or nil
107 local beltItem = character.EQUIPMENT_SLOT_BELT and InventoryItemFactory.CreateItem(character.EQUIPMENT_SLOT_BELT.id) or nil
108 local pantsItem = character.EQUIPMENT_SLOT_PANTS and InventoryItemFactory.CreateItem(character.EQUIPMENT_SLOT_PANTS.id) or nil
109 local socksItem = character.EQUIPMENT_SLOT_SOCKS and InventoryItemFactory.CreateItem(character.EQUIPMENT_SLOT_SOCKS.id) or nil
110 local shoesItem = character.EQUIPMENT_SLOT_SHOES and InventoryItemFactory.CreateItem(character.EQUIPMENT_SLOT_SHOES.id) or nil
111
112 survivor:getHumanVisual():setSkinTextureIndex(character.INFO_SKIN_COLOR)
113 survivor:getHumanVisual():setHairModel(character.INFO_HAIR_STYLE)
114 survivor:getHumanVisual():setBeardModel(character.INFO_BEARD_STYLE)
115
116 local immutableColor = ImmutableColor.new(character.INFO_HAIR_COLOR.r, character.INFO_HAIR_COLOR.g, character.INFO_HAIR_COLOR.b, 1)
117
118 survivor:getHumanVisual():setHairColor(immutableColor)
119 survivor:getHumanVisual():setBeardColor(immutableColor)
120 survivor:getHumanVisual():setNaturalHairColor(immutableColor)
121 survivor:getHumanVisual():setNaturalBeardColor(immutableColor)
122
123 if headItem then survivor:setWornItem(EQUIPMENT_SLOT_HEAD, headItem) end
124 if faceItem then survivor:setWornItem(EQUIPMENT_SLOT_FACE, faceItem) end
125 if earsItem then survivor:setWornItem(EQUIPMENT_SLOT_EARS, earsItem) end
126 if backpackItem then survivor:setWornItem(EQUIPMENT_SLOT_BACKPACK, backpackItem) end
127 if glovesItem then survivor:setWornItem(EQUIPMENT_SLOT_GLOVES, glovesItem) end
128 if undershirtItem then survivor:setWornItem(EQUIPMENT_SLOT_UNDERSHIRT, undershirtItem) end
129 if overshirtItem then survivor:setWornItem(EQUIPMENT_SLOT_OVERSHIRT, overshirtItem) end
130 if vestItem then survivor:setWornItem(EQUIPMENT_SLOT_VEST, vestItem) end
131 if beltItem then survivor:setWornItem(EQUIPMENT_SLOT_BELT, beltItem) end
132 if pantsItem then survivor:setWornItem(EQUIPMENT_SLOT_PANTS, pantsItem) end
133 if socksItem then survivor:setWornItem(EQUIPMENT_SLOT_SOCKS, socksItem) end
134 if shoesItem then survivor:setWornItem(EQUIPMENT_SLOT_SHOES, shoesItem) end
135
136 self.characterPreview:setSurvivorDesc(survivor)
137end
138
139function FrameworkZ.UI.CharacterView:setCharacter(character)
140 self.character = character
141end
142
143function FrameworkZ.UI.CharacterView:setName(name)
144 self.name = name
145end
146
147function FrameworkZ.UI.CharacterView:setDescription(description)
148 self.description = description
149end
150
151function FrameworkZ.UI.CharacterView:reinitialize(character)
152 self:setCharacter(character)
153 self:setName(character.INFO_NAME)
154 self:setDescription(character.INFO_DESCRIPTION)
155 self:initialise()
156end
157
158function FrameworkZ.UI.CharacterView:getDescriptionLines(description)
159 local lines = {}
160 local line = ""
161 local lineLength = 0
162 local words = {}
163
164 for word in string.gmatch(description, "%S+") do
165 table.insert(words, word)
166 end
167
168 if #words == 0 then
169 return {description}
170 end
171
172 for i = 1, #words do
173 local word = words[i]
174 local wordLength = string.len(word) + 1
175
176 if lineLength + wordLength <= 30 or lineLength == 0 then
177 line = lineLength == 0 and word or line .. " " .. word
178 lineLength = lineLength + wordLength
179 else
180 table.insert(lines, line)
181 line = word
182 lineLength = wordLength
183 end
184 end
185
186 if line ~= "" then
187 table.insert(lines, line)
188 end
189
190 return lines
191end
192
193function FrameworkZ.UI.CharacterView:new(x, y, width, height, isoPlayer, character, name, description, defaultDirection)
194 local o = {}
195
196 o = ISPanel:new(x, y, width, height)
197 setmetatable(o, self)
198 self.__index = self
199 o.backgroundColor = {r=0, g=0, b=0, a=0}
200 o.borderColor = {r=0, g=0, b=0, a=0}
201 o.moveWithMouse = false
202 o.isoPlayer = isoPlayer
203 o.character = character
204 o.name = name
205 o.description = description
206 o.defaultDirection = defaultDirection
207 FrameworkZ.UI.CharacterView.instance = o
208
209 return o
210end
211
212return FrameworkZ.UI.CharacterView
void FrameworkZ UI CharacterPreview()
void local y()
void alpha()
void local decayRate()
void local alphaStart()
void self characterPreview()
void local totalLines()
void local alphaMin()
void local descriptionHeight()
void self characterNameLabel()
void self survivor()
void self uiHelper()
void self descriptionLabels()
void local descriptionLabel()
void local adjustedK()
void local isFemale()
void local previewHeight()
void local x()
void local descriptionLines()
void local height()
void local width
void description()
void self self
Definition MainMenu.lua:89
void local getTextManager()
void local name()
void if type v()
void isoPlayer()
void getDescriptionLines(description)
void setDescription(description)
Contains all of the User Interfaces for FrameworkZ.
void local word()
void for i()
void local wordLength()