FrameworkZ 4.4.2
Provides a framework for Project Zomboid with various systems.
Loading...
Searching...
No Matches
Introduction.lua
Go to the documentation of this file.
1require "ISUI/ISPanel"
3PFW_Introduction = ISPanel:derive("PFW_Introduction")
5function PFW_Introduction:initialise()
6 local emitter = self.playerObject:getEmitter()
7 self.vignetteTexture = getTexture("media/textures/vignette.png")
8 self.cfwTexture = getTexture(FrameworkZ.Config.IntroFrameworkImage)
9 self.hl2rpTexture = getTexture(FrameworkZ.Config.IntroGamemodeImage)
10
11 ISPanel.initialise(self)
12
13 self.initializing = ISLabel:new((self.width - getTextManager():MeasureStringX(UIFont.Large, "Initializing...")) / 2, (self.height - getTextManager():MeasureStringY(UIFont.Large, "Initializing...")) / 2, 25, "Initializing...", 1, 1, 1, 1, UIFont.Large, true)
14 self:addChild(self.initializing)
16 FrameworkZ.Timers:Simple(FrameworkZ.Config.InitializationDuration, function()
18 if not FrameworkZ.Config.SkipIntro then
19 self:removeChild(self.initializing)
20 emitter:playSoundImpl(FrameworkZ.Config.IntroMusic, nil)
22 emitter:playSoundImpl("button1", nil)
23 self.backgroundColor = {r=0.1, g=0.1, b=0.1, a=1}
24
25 FrameworkZ.Timers:Simple(0.1, function()
26 self.backgroundColor = {r=0, g=0, b=0, a=1}
28 self.cfw = ISImage:new(self.width / 2 - self.cfwTexture:getWidth() / 2, self.height / 2 - self.cfwTexture:getHeight() / 2, self.cfwTexture:getWidth(), self.cfwTexture:getHeight(), self.cfwTexture)
29 self.cfw.backgroundColor = {r=1, g=1, b=1, a=1}
30 self.cfw.scaledWidth = self.cfwTexture:getWidth()
31 self.cfw.scaledHeight = self.cfwTexture:getHeight()
32 self.cfw.shrinking = true
33 self.cfw:initialise()
34 self:addChild(self.cfw)
35
36 FrameworkZ.Timers:Simple(7, function()
37 self:removeChild(self.cfw)
38 self.cfw = nil
39
40 emitter:playSoundImpl("lightswitch2", nil)
41 self.backgroundColor = {r=0.1, g=0.1, b=0.1, a=1}
42
43 FrameworkZ.Timers:Simple(0.1, function()
44 self.backgroundColor = {r=0, g=0, b=0, a=1}
45
46 self.hl2rp = ISImage:new(self.width / 2 - self.hl2rpTexture:getWidth() / 2, self.height / 2 - self.hl2rpTexture:getHeight() / 2, self.hl2rpTexture:getWidth(), self.hl2rpTexture:getHeight(), self.hl2rpTexture)
47 self.hl2rp.backgroundColor = {r=1, g=1, b=1, a=1}
48 self.hl2rp.scaledWidth = self.hl2rpTexture:getWidth()
49 self.hl2rp.scaledHeight = self.hl2rpTexture:getHeight()
50 self.hl2rp.shrinking = true
51 self.hl2rp:initialise()
52 self:addChild(self.hl2rp)
53
54 FrameworkZ.Timers:Simple(7, function()
55 self:removeChild(self.hl2rp)
56 self.hl2rp = nil
57
58 emitter:playSoundImpl("lightswitch2", nil)
59 self.backgroundColor = {r=0.1, g=0.1, b=0.1, a=1}
60
61 FrameworkZ.Timers:Remove("IntroTick")
62
63 FrameworkZ.Timers:Simple(0.1, function()
64 self.backgroundColor = {r=0, g=0, b=0, a=1}
65
66 local characterSelect = PFW_MainMenu:new(0, 0, getCore():getScreenWidth(), getCore():getScreenHeight(), self.playerObject)
67 characterSelect:initialise()
68 characterSelect:addToUIManager()
69
70 FrameworkZ.Timers:Simple(1, function()
71 self:setVisible(false)
72 self:removeFromUIManager()
73 end)
74 end)
75 end)
76 end)
77 end)
78 end)
79 else
80 FrameworkZ.Timers:Remove("IntroTick")
81 local characterSelect = PFW_MainMenu:new(0, 0, getCore():getScreenWidth(), getCore():getScreenHeight(), self.playerObject)
82 characterSelect:initialise()
83 characterSelect:addToUIManager()
84
85 FrameworkZ.Timers:Simple(1, function()
86 self:setVisible(false)
87 self:removeFromUIManager()
88 end)
89 end
90 end)
91end
92
93local function calculateWidthHeight(originalAspectRatio, width, height, changeValue)
94 -- Scenario 1: Increase width by 1 and adjust height
95 local newWidth1 = width + changeValue
96 local newHeight1 = math.floor((newWidth1 / originalAspectRatio) + 0.5)
97
98 -- Scenario 2: Increase height by 1 and adjust width
99 local newHeight2 = height + changeValue
100 local newWidth2 = math.floor((newHeight2 * originalAspectRatio) + 0.5)
101
102 -- Calculate the aspect ratio difference for both scenarios
103 local difference1 = math.abs((newWidth1 / newHeight1) - originalAspectRatio)
104 local difference2 = math.abs((newWidth2 / newHeight2) - originalAspectRatio)
105
106 -- Choose the scenario with the smallest difference
107 if difference1 < difference2 then
108 return newWidth1, newHeight1
109 else
110 return newWidth2, newHeight2
111 end
112end
113
114FrameworkZ.Timers:Create("IntroTick", 0.1, 0, function()
117
118 if instance.cfw then
119 if instance.cfw.shrinking == true and instance.cfw.scaledWidth / instance.cfw:getWidth() >= 0.95 then
120 local width, height = calculateWidthHeight(instance.cfw.width / instance.cfw.height, instance.cfw.scaledWidth, instance.cfw.scaledHeight, -1)
121
124 elseif instance.cfw.shrinking == true then
125 instance.cfw.shrinking = false
126 end
127
128 if instance.cfw.shrinking == false and instance.cfw.scaledWidth / instance.cfw:getWidth() <= 1 then
129 local width, height = calculateWidthHeight(instance.cfw.width / instance.cfw.height, instance.cfw.scaledWidth, instance.cfw.scaledHeight, 1)
130
133 elseif instance.cfw.shrinking == false then
134 instance.cfw.shrinking = true
135 end
136
137 instance.cfw:setX(instance.width / 2 - instance.cfw.scaledWidth / 2)
138 instance.cfw:setY(instance.height / 2 - instance.cfw.scaledHeight / 2)
139 end
140
141 if instance.hl2rp then
142 if instance.hl2rp.shrinking == true and instance.hl2rp.scaledWidth / instance.hl2rp:getWidth() >= 0.95 then
143 local width, height = calculateWidthHeight(instance.hl2rp.width / instance.hl2rp.height, instance.hl2rp.scaledWidth, instance.hl2rp.scaledHeight, -1)
144
147 elseif instance.hl2rp.shrinking == true then
148 instance.hl2rp.shrinking = false
149 end
150
151 if instance.hl2rp.shrinking == false and instance.hl2rp.scaledWidth / instance.hl2rp:getWidth() <= 1 then
152 local width, height = calculateWidthHeight(instance.hl2rp.width / instance.hl2rp.height, instance.hl2rp.scaledWidth, instance.hl2rp.scaledHeight, 1)
153
156 elseif instance.hl2rp.shrinking == false then
157 instance.hl2rp.shrinking = true
158 end
159
160 instance.hl2rp:setX(instance.width / 2 - instance.hl2rp.scaledWidth / 2)
161 instance.hl2rp:setY(instance.height / 2 - instance.hl2rp.scaledHeight / 2)
162 end
163 end
164end)
165
166function PFW_Introduction:update()
167 ISPanel.update(self)
168end
169
170function PFW_Introduction:new(x, y, width, height, playerObject)
171 local o = {}
172
173 o = ISPanel:new(x, y, width, height)
174 setmetatable(o, self)
175 self.__index = self
176 o.backgroundColor = {r=0, g=0, b=0, a=1}
177 o.borderColor = {r=0, g=0, b=0, a=1}
178 o.moveWithMouse = false
179 o.playerObject = playerObject
180 PFW_Introduction.instance = o
181
182 return o
183end
184
185return PFW_Introduction
void SkipIntro()
void IntroGamemodeImage()
void FrameworkZ Config()
void IntroMusic()
void InitializationDuration()
void IntroFrameworkImage()
void local y()
void local x()
void local newHeight1()
void local newWidth1()
void if instance cfw shrinking()
void local height()
void local newHeight2()
void PFW_Introduction()
void local width
void instance cfw scaledWidth()
void local newWidth2()
void local difference1()
void local difference2()
void instance cfw scaledHeight()
void local instance()
void self emitter()
void self self
Definition MainMenu.lua:85
void self self nil
Definition MainMenu.lua:91
void PFW_MainMenu()
void processingNotification backgroundColor a()
Timers module for FrameworkZ. Allows for the creation of timers for delaying code executions.
Definition Timers.lua:5
FrameworkZ global table.