FrameworkZ 4.4.2
Provides a framework for Project Zomboid with various systems.
Loading...
Searching...
No Matches
CharacterPreview.lua
Go to the documentation of this file.
3require "ISUI/ISPanel"
5PFW_CharacterPreview = ISPanel:derive("PFW_CharacterPreview")
7local FONT_HGT_SMALL = getTextManager():getFontHeight(UIFont.Small)
8local FONT_HGT_MEDIUM = getTextManager():getFontHeight(UIFont.Medium)
9
10function PFW_CharacterPreview:initialise()
11 ISPanel.initialise(self)
13 self.avatarBackgroundTexture = getTexture("media/ui/avatarBackground.png")
15 local comboHgt = FONT_HGT_SMALL + 3 * 2
17 self.avatarPanel = ISUI3DModel:new(0, 0, self.width, self.height - comboHgt)
18 self.avatarPanel.backgroundColor = {r=0, g=0, b=0, a=0.8}
19 self.avatarPanel.borderColor = {r=1, g=1, b=1, a=0.2}
20 self:addChild(self.avatarPanel)
21 self.avatarPanel:setState("idle")
22 self.avatarPanel:setDirection(self.direction)
23 self.avatarPanel:setIsometric(false)
24 self.avatarPanel:setDoRandomExtAnimations(true)
25 self.avatarPanel:reportEvent(self.defaultAnimation and self.defaultAnimation or "EventWalk")
26
27 self.turnLeftButton = ISButton:new(self.avatarPanel.x, self.avatarPanel:getBottom()-15, 15, 15, "", self, self.onTurnChar)
28 self.turnLeftButton.internal = "TURNCHARACTERLEFT"
29 self.turnLeftButton:initialise()
30 self.turnLeftButton:instantiate()
31 self.turnLeftButton:setImage(getTexture("media/ui/ArrowLeft.png"))
32 self:addChild(self.turnLeftButton)
33
34 self.turnRightButton = ISButton:new(self.avatarPanel:getRight()-15, self.avatarPanel:getBottom()-15, 15, 15, "", self, self.onTurnChar)
35 self.turnRightButton.internal = "TURNCHARACTERRIGHT"
36 self.turnRightButton:initialise()
37 self.turnRightButton:instantiate()
38 self.turnRightButton:setImage(getTexture("media/ui/ArrowRight.png"))
39 self:addChild(self.turnRightButton)
40
41 self.animCombo = ISComboBox:new(0, self.avatarPanel:getBottom() + 2, self.width, comboHgt, self, self.onAnimSelected)
42 self.animCombo:initialise()
43 self:addChild(self.animCombo)
44 self.animCombo:addOptionWithData(getText("IGUI_anim_Walk"), "EventWalk")
45 self.animCombo:addOptionWithData(getText("IGUI_anim_Idle"), "EventIdle")
46 self.animCombo:addOptionWithData(getText("IGUI_anim_Run"), "EventRun")
47 self.animCombo.selected = 1
48end
49
50function PFW_CharacterPreview:prerender()
51 ISPanel.prerender(self)
52
53 self:drawRectBorder(self.avatarPanel.x - 2, self.avatarPanel.y - 2, self.avatarPanel.width + 4, self.avatarPanel.height + 4, 1, 0.3, 0.3, 0.3);
54 self:drawTextureScaled(self.avatarBackgroundTexture, self.avatarPanel.x, self.avatarPanel.y, self.avatarPanel.width, self.avatarPanel.height, 1, 1, 1, 1);
55end
56
57function PFW_CharacterPreview:onTurnChar(button, x, y)
58 local direction = self.avatarPanel:getDirection()
59 if button.internal == "TURNCHARACTERLEFT" then
60 direction = IsoDirections.RotLeft(direction)
61 self.avatarPanel:setDirection(direction)
62 elseif button.internal == "TURNCHARACTERRIGHT" then
63 direction = IsoDirections.RotRight(direction)
64 self.avatarPanel:setDirection(direction)
65 end
66end
67
68function PFW_CharacterPreview:onAnimSelected(combo)
69-- self.avatarPanel:setState(combo:getOptionData(combo.selected))
70 self.avatarPanel:reportEvent(combo:getOptionData(combo.selected))
71end
72
73function PFW_CharacterPreview:setCharacter(character)
74 self.avatarPanel:setCharacter(character)
75end
76
77function PFW_CharacterPreview:setSurvivorDesc(survivorDesc)
78 self.avatarPanel:setSurvivorDesc(survivorDesc)
79end
80
81function PFW_CharacterPreview:new(x, y, width, height, defaultAnimation, defaultDirection)
82 local o = ISPanel:new(x, y, width, height)
83
84 setmetatable(o, self)
86
87 -- The panel is bigger than it appears when the animation selection dropdown is removed. Maybe there's a better way to handle that?
88 o.backgroundColor = {r=0, g=0, b=0, a=0}
89 o.borderColor = {r=0, g=0, b=0, a=0}
90 o.direction = defaultDirection and defaultDirection or IsoDirections.SW
91 o.defaultAnimation = defaultAnimation
92
93 return o
94end
95
void local ui()
void local FONT_HGT_SMALL()
void PFW_CharacterPreview()
void local FONT_HGT_MEDIUM()
void FrameworkZ()
void local y()
void local x()
void local height()
void local width
void self self
Definition MainMenu.lua:85
void processingNotification backgroundColor a()
void local character()
void if item internal()
void FrameworkZ DollarFormats __index()
FrameworkZ global table.
void onAnimSelected(combo)
void onTurnChar(button, x, y)
void setSurvivorDesc(survivorDesc)
void setCharacter(character)