-
Notifications
You must be signed in to change notification settings - Fork 1
/
ifs_pc_spawnselect.lua
304 lines (252 loc) · 9.3 KB
/
ifs_pc_spawnselect.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
--
-- Copyright (c) 2005 Pandemic Studios, LLC. All rights reserved.
--
--This is the PC version of the charselect, which includes elements of the spawndisplay
-- all the if mode stuff has been removed, as there is no splitscreen for PC
-- Helper function. Builds the chunks for this screen programatically
-- (i.e. based on screensize). It makes and shoves things into the
-- 'this.Info' block, which is a container aligned to the right-middle
-- of the screen. Thus, within its space, x=0 is the right edge,
-- x=-100 is to its left. y=0 is the middle of the screen, y=-100 is
-- above that, y=100 is below.
function ifs_pc_SpawnSelect_fnBuildScreen(this, mode)
-- Make a container that's aligned to the left-top of the screen
-- to shove our stuff into
this.Info = NewIFContainer {
ScreenRelativeX = 0.0,
ScreenRelativeY = 0.0,
inert = 1, -- delete from Lua memory once pushed to C
}
this.BotInfo = NewIFContainer {
ScreenRelativeX = 1.0,
ScreenRelativeY = 1.0,
inert = 1, -- delete from Lua memory once pushed to C
}
local w,h = ScriptCB_GetSafeScreenInfo() -- of the usable screen
local MAX_CLASS_SLOTS = 10 -- must match MAX_CLASS_SLOTS in pcSpawnDisplay.h
--make sure there's at least 7 slots, but not more than MAX_CLASS_SLOTS, depending on how many classes are available in the map
local numSlots = math.min( math.max(7, GetTeamClassCount(1), GetTeamClassCount(2)), MAX_CLASS_SLOTS )
local numClassesTeam1 = GetTeamClassCount(1)
local numClassesTeam2 = Get
local boxw, boxh, texth
-- Scale a box based on screensize
boxw = w * 0.35
boxh = h * 0.03--could be too small
local sideh = h * 0.15
local sidew = w * 0.1
local okcancelw = w * 0.2
local okcancelh = h * 0.03
local unitcountw = w * 0.3
local unitcounth = h * 0.2
local fontsize = gPopupTinyTextFont
local smallfontsize = gPopupTinyTextFont
local screenWidth, screenHeight = ScriptCB_GetScreenInfo()
if screenHeight > 600 and screenHeight < 960 then
fontsize = gListboxItemFont
smallfontsize = gPopupTinyTextFont
elseif screenHeight >= 960 then
fontsize = gListboxItemFont
smallfontsize = gListboxItemFont
end
local SideXOffset = w * .1
local SideYOffest = h * .17
local buttonlabelheight = ScriptCB_GetFontHeight(fontsize) + 3 --magic number for a little padding
local SlotYOffset = 15 + buttonlabelheight --compensate for label height
local SlotUnitNameOffsetX = w * .05 --will need the icon offset eventually
local SlotTextOffsetX = SlotUnitNameOffsetX + 20
local textheight = h/numSlots - boxh - buttonlabelheight
local popupWidth = w * .3
local popupHeight = h * .15
local leftsideRot = 35
--Make two buttons for the two sides, (a frame and an bitmap for each)
--These are the frames
Icon0PosX = w/2 -- - sidew/2
Icon1PosX = w/2 -- + sidew/2
this.Info.SideIcon0 = NewBorderRect
{
ZPos = 190, -- behind most
x = w/2,
y = SideYOffest,
width = sidew*2,
height = sideh,
alpha = 0, -- invisible hotspot, here we come.
}
this.Info.SideIcon1 = NewBorderRect
{
ZPos = 190, -- behind most
x = w/2,
y = SideYOffest,
width = sidew * 2,
height = sideh,
alpha = 0,
}
--The two models
this.Info.SideModel0 = NewIFModel {
x = 0.0, y = 0.0,
-- x = Icon0PosX, y = SideYOffest,
scale = 1.0,
OmegaY = -0.3,
lighting = 1,
ColorR = 76, ColorG = 180, ColorB = 255,
}
this.Info.SideModel1 = NewIFModel {
x = 0.0, y = 0.0,
-- x = Icon1PosX, y = SideYOffest,
scale = 1.0,
OmegaY = -0.3,
lighting = 1,
ColorR = 76, ColorG = 180, ColorB = 255,
}
--Make two buttons for the Accept & Cancel button
--And the text that goes in them
local okYPos = h - 0.1*h
this.Info.Ok = NewPCIFButton
{
x = w/2,
y = okYPos,
btnw = okcancelw,
btnh = okcancelh,
font = gListboxItemFont,
bg_width = okcancelw,
string = "ifs.SpawnDisplay.Spawn",
}
--displays the unit count, and optionally some extra info as to why
--a character cannot select a character class
this.Info.UnitCount = NewIFText
{
x = w/2 - unitcountw/2,
y = okYPos - unitcounth,
font = fontsize,
halign = "hcenter",
valign = "bottom",
textw = unitcountw, -- usable area for text
texth = unitcounth,
font = fontsize,
style = "shadow",
ColorR = 255, ColorG = 255, ColorB = 255, -- white
flashy = 0,
}
local i
for i = 0,MAX_CLASS_SLOTS do
local tag = string.format("SlotWindow%d",i)
this.Info[tag] = NewButtonWindow
{
ZPos = 200,
x = SlotUnitNameOffsetX + SlotUnitNameOffsetX * 2.5,
y = SlotYOffset + i * ( boxh + textheight + buttonlabelheight + 2 ),
--ScreenRelativeX = 0.0, -- center
--ScreenRelativeY = 0.0,
width = boxw,
height = textheight + boxh,
titleText = "ifs.profile.list",
font = fontsize,
buttonHeightPad = 1,
buttonGutter = 1,
titleOffsetX = 5,
}
this.Info[tag].bHotspot = 1
this.Info[tag].fHotspotX = -0.5 * (boxw)
this.Info[tag].fHotspotY = -0.5 * (textheight + boxh) - buttonlabelheight
this.Info[tag].fHotspotW = boxw
this.Info[tag].fHotspotH = textheight + boxh + buttonlabelheight
this.Info[tag].InfoText = NewIFText --the equipment/weapon text
{
width = boxw,
halign = "hcenter",
valign = "vcenter",
textw = boxw - boxh, -- usable area for text
texth = textheight,
font = smallfontsize,
string = "InfoText",
ColorR = 255, ColorG = 255, ColorB = 255, -- white
flashy = 0,
}
--how many lines of text to squeeze into the info box
local numLines = 4
if numSlots > 7 and screenHeight < 960 then
numLines = 3
end
local textscale = textheight / (numLines * ScriptCB_GetFontHeight(smallfontsize))
--if textscale < 1 then
this.Info[tag].InfoText.HScale = textscale
this.Info[tag].InfoText.VScale = textscale
--end
end
end
function ifs_pc_spawnselect_animateicons(activeSide)
local this = ifs_pc_SpawnSelect
this.activeSide = activeSide
local w,h = ScriptCB_GetSafeScreenInfo()
local SideYOffest = h * .17
local Icon0PosX = w/2 -- - w*0.05
local Icon1PosX = w/2 -- + w*0.05
local resScale = w / 800
if(activeSide < 0.5) then
AnimationMgr_AddAnimation(this.Info.SideModel0,{ fTotalTime = 0.75,fStartAlpha = 0.0, fEndAlpha = 1,
fStartX = Icon0PosX,fEndX = Icon0PosX,
fStartY = SideYOffest,fEndY = SideYOffest,
fStartW = 0.25*resScale,fStartH = 0.25*resScale,fEndW = 0.5*resScale,fEndH = 0.5*resScale,})
AnimationMgr_AddAnimation(this.Info.SideModel1,{ fTotalTime = 0.75,fStartAlpha = 1, fEndAlpha = 0.0,
fStartX = Icon1PosX,fEndX = Icon1PosX,
fStartY = SideYOffest,fEndY = SideYOffest,
fStartW = 0.5*resScale,fStartH = 0.5*resScale,fEndW = 0.25*resScale,fEndH = 0.25*resScale,})
else
AnimationMgr_AddAnimation(this.Info.SideModel0,{ fTotalTime = 0.75,fStartAlpha = 1, fEndAlpha = 0.0,
fStartX = Icon0PosX,fEndX = Icon0PosX,
fStartY = SideYOffest,fEndY = SideYOffest,
fStartW = 0.5*resScale,fStartH = 0.5*resScale,fEndW = 0.25*resScale,fEndH = 0.25*resScale,})
AnimationMgr_AddAnimation(this.Info.SideModel1,{ fTotalTime = 0.75,fStartAlpha = 0.0, fEndAlpha = 1,
fStartX = Icon1PosX,fEndX = Icon1PosX,
fStartY = SideYOffest,fEndY = SideYOffest,
fStartW = 0.25*resScale,fStartH = 0.25*resScale,fEndW = 0.5*resScale,fEndH = 0.5*resScale,})
end
-- make them spin fast for a bit
IFModel_fnSetOmegaY(this.Info.SideModel0,-10)
IFModel_fnSetOmegaY(this.Info.SideModel1,-10)
this.IconModelFastMode = 1
end
ifs_pc_SpawnSelect = NewIFShellScreen
{
nologo = 1,
bNohelptext_accept = 1, -- we have our own
bNohelptext_backPC = nil,
bDimBackdrop = nil,
-- Actual contents are created in ifs_charselect_fnBuildScreen
-- Note: for now, the exe is handling all the inputs/events, so this
-- screen has no Enter/Exit/Update/Input handlers. It does have an
-- Input_Back handler to override the base class's default functionality
-- (go to previous screen)
Enter = function(this, bFwd)
gIFShellScreenTemplate_fnEnter(this, bFwd) -- call default enter function
AnimationMgr_ClearAnimations(this.Info.SideModel0)
AnimationMgr_ClearAnimations(this.Info.SideModel1)
ifs_pc_spawnselect_animateicons(this.activeSide or 0)
end,
Input_Back = function(this)
end,
Input_GeneralLeft = function(this,bFromAI)
end,
Input_GeneralRight = function(this,bFromAI)
end,
Input_GeneralUp = function(this,bFromAI)
end,
Input_GeneralDown = function(this,bFromAI)
end,
Update = function(this,fDt)
-- Call default base class's update function (make button bounce)
gIFShellScreenTemplate_fnUpdate(this,fDt)
-- if the models are done animating, slow down the rotations
if(this.IconModelFastMode and not this.Info.SideModel0.bAnimActive) then
IFModel_fnSetOmegaY(this.Info.SideModel0,-0.3)
IFModel_fnSetOmegaY(this.Info.SideModel1,-0.3)
this.IconModelFastMode = nil
end
end,
}
--Call me from C++ to create the screen and cleanup afterwards
function ifs_pc_SpawnSelect_fnInit()
ifs_pc_SpawnSelect_fnBuildScreen(ifs_pc_SpawnSelect, 0)
AddIFScreen(ifs_pc_SpawnSelect,"ifs_pc_SpawnSelect")
ifs_pc_SpawnSelect_fnBuildScreen = nil
ifs_pc_SpawnSelect_fnInit = nil
end