-
Notifications
You must be signed in to change notification settings - Fork 6
/
ZStatusBars.txt
403 lines (346 loc) · 11.4 KB
/
ZStatusBars.txt
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
//==============================================================================
//==============================================================================
// Status Bars
// Quake4 original HUD
// Made by AlphaEnt.
// Modified by DBT for this mod.
// Vastly modified by Michaelis, following vision of DBT.
// Remade completely by Michaelis for Doom-4-Doom.
// There is no trace of AlphaEnt's work at this point.
// Recreated completely again for ZScript by Major Cooke
//==============================================================================
//==============================================================================
#include "ZStatusHud.txt"
Class Doom4StatusBar : BaseStatusBar
{
enum ED4HUDFlags
{
// VCenter = Vertical (Y/Up/Down) centering
// HCenter = Horizontal (X/Left/Right) centering (going left/right)
HUDCenterX = DI_SCREEN_HCENTER,
HudCenterY = DI_SCREEN_VCENTER,
HUDLeftTop = DI_SCREEN_LEFT_TOP,
HUDLeftMid = DI_SCREEN_LEFT|HUDCenterY,
HUDLeftBot = DI_SCREEN_LEFT_BOTTOM,
HUDTop = DI_SCREEN_TOP|HUDCenterX,
HUDMid = DI_SCREEN_CENTER,
HUDBot = DI_SCREEN_CENTER_BOTTOM,
HUDRightTop = DI_SCREEN_RIGHT_TOP,
HUDRightMid = DI_SCREEN_RIGHT|HUDCenterY,
HUDRightBot = DI_SCREEN_RIGHT_BOTTOM,
ItemCenterX = DI_ITEM_HCENTER,
ItemCenterY = DI_ITEM_VCENTER,
ItemOffsets = DI_ITEM_OFFSETS,
ItemLeftTop = DI_ITEM_LEFT_TOP,
ItemLeftMid = DI_ITEM_LEFT|ItemCenterY,
ItemLeftBot = DI_ITEM_LEFT_BOTTOM,
ItemTop = DI_ITEM_TOP|ItemCenterX,
ItemMid = DI_ITEM_CENTER,
ItemBot = DI_ITEM_CENTER_BOTTOM,
ItemRightTop = DI_ITEM_RIGHT_TOP,
ItemRightMid = DI_ITEM_RIGHT|ItemCenterY,
ItemRightBot = DI_ITEM_RIGHT_BOTTOM,
HUDItemLeftTop = (HUDLeftTop|ItemLeftTop),
HUDItemLeftMid = (HUDLeftMid|ItemLeftMid),
HUDItemLeftBot = (HUDLeftBot|ItemLeftBot),
HUDItemTop = (HUDTop|ItemTop),
HUDItemMid = (HUDMid|ItemMid),
HUDItemBot = (HUDBot|ItemBot),
HUDItemRightTop = (HUDRightTop|ItemRightTop),
HUDItemRightMid = (HUDRightMid|ItemRightMid),
HUDItemRightBot = (HUDRightBot|ItemRightBot),
}
// Keys
static const Class<Inventory> keynames[] =
{
"BlueCard",
"YellowCard",
"RedCard",
"BlueSkull",
"YellowSkull",
"RedSkull"
};
static const String keyimg[] =
{
"KEYCB",
"KEYCY",
"KEYCR",
"SKKYB",
"SKKYY",
"SKKYR"
};
Vector2 KeyPos[6];
Vector2 SlotPos[6];
Vector2 KeySlotSize;
// Y positions for keys and slots
const TopKeyY = 665.0;
const BotKeyY = 699.0;
const TopSlotY = 661.0;
const BotSlotY = 697.0;
// X positions for the keys
const LKeyX = 209.0;
const MKeyX = 249.0;
const RKeyX = 289.0;
const CardOffX = -5.0; // Needed for the key cards as they're smaller.
// X positions for the slots
const LSlotX = 200.0;
const MSlotX = 240.0;
const RSlotX = 280.0;
const DemonKeyOffsetX = -60.0;
const DemonKeyOffsetY = 0.0;
// Cash positions
const FakeCashStart = 35 * 4;
const FakeCashFade = 35.0;
// Image alignments
const imageAlignmentLeft = DI_ITEM_LEFT_TOP|DI_ITEM_OFFSETS|DI_SCREEN_CENTER_BOTTOM;
// Interpolators
DynamicValueInterpolator mHealthInterpolator;
DynamicValueInterpolator mHealthInterpolator2;
DynamicValueInterpolator mHealthInterpolator3;
DynamicValueInterpolator mHealthInterpolator4;
DynamicValueInterpolator mTimeInterpolator;
// Fonts for HUDS
transient HUDFont mHUDFont, mIndexFont, mBigFont, mConsoleFont, mQ4HudFont, mSmallFont;
// Life counter
double LifeCounterFade;
int LifeCount[2];
// Misc variables
InventoryBarState diparms;
InventoryBarState diparms_sbar;
Actor plr;
Vector2 BaseSize, DemonKeyOffsets, HPOffset, AmmoOffset;
double fadeamt;
int DemonTimer;
uint FakeCashTimer, FakeCash, Cash, PrevCash, HP, MaxHP, UpgradeMode;
uint8 DoomDollMax, DoomDollCount, MegasphereCount, MegasphereMax, AmmoClamp;
bool ignoreFakeUpdate, noReticle, addonOverride, automap, AmDemon, WasDemon, Resonator;
D4DHandler Event;
override void Draw (int state, double TicFrac)
{
if (!plr) plr = CPlayer.mo;
Super.Draw (state, TicFrac);
if (state == HUD_StatusBar || state == HUD_Fullscreen)
{
/*
if (state == HUD_Fullscreen)
{
HPOffset = (70, 0); //(LOfx, LOfy);
AmmoOffset = (-70, 0); //(ROfx, ROfy);
}
else
{
HPOffset = (0,0);
AmmoOffset = (0,0);
}
if (bars)
{
SetSize(-1, 1024, 768);
CompleteBorder = true;
BeginStatusBar(true);
DrawMainBar (TicFrac);
}
*/
BeginHud();
DrawFullScreenStuff();
}
}
override void Init()
{
Super.Init();
BaseSize = (320, 200);
SetSize(0, BaseSize.X, BaseSize.Y);
// CompleteBorder = true;
FirstTic = true;
String KS = "KEYSLOT0";
let id = TexMan.CheckForTexture(KS, TexMan.Type_Any);
if (id) [KeySlotSize.X, KeySlotSize.Y] = TexMan.GetSize(id);
// Create the font used for the fullscreen HUD
Font fnt = "HUDFONT_DOOM";
mHUDFont = HUDFont.Create(fnt, fnt.GetCharWidth("0") + 1, true, 1, 1);
fnt = "INDEXFONT_DOOM";
mIndexFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), true);
fnt = "BIGFONT";
mBigFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), true, 2, 2);
fnt = "CONFONT";
mConsoleFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), true);
fnt = "Q4HUDFONT";
mQ4HudFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), true);
fnt = "SMALLFNT";
mSmallFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), true);
mHealthInterpolator = DynamicValueInterpolator.Create(0, 0.25, 1, 20);
mHealthInterpolator2 = DynamicValueInterpolator.Create(0, 0.25, 1, 20);
mHealthInterpolator3 = DynamicValueInterpolator.Create(0, 0.25, 1, 20);
mHealthInterpolator4 = DynamicValueInterpolator.Create(0, 0.25, 1, 20);
DemonKeyOffsets = (DemonKeyOffsetX, DemonKeyOffsetY);
}
override void NewGame ()
{
Super.NewGame();
plr = CPlayer.mo;
ResetInterpolators(100, 0);
DemonKeyOffsets = (DemonKeyOffsetX, DemonKeyOffsetY);
Event = D4DHandler(EventHandler.Find("D4DHandler"));
UpgradeMode = D4D_UpgradeMode;
}
void ResetInterpolators(int health, int time = 0)
{
mHealthInterpolator.Reset(health);
mHealthInterpolator2.Reset(health);
mHealthInterpolator3.Reset(health);
mHealthInterpolator4.Reset(health);
}
// For everything that doesn't need to be processed every frame, only update
// these on game ticks. 35 calls a second versus 60, easy to figure out which
// is better, yes?
bool FirstTic;
override void Tick()
{
Super.Tick();
noReticle = GetAmountOnly("NoReticle");
DemonTimer = GetAmountOnly("DemonTimerToken");
DemonKeyOffsets = (DemonKeyOffsetX, DemonKeyOffsetY);
if (addonOverride)
{
automap = false;
return;
}
PrevCash = Cash;
WasDemon = AmDemon;
AmDemon = (CPlayer.mo && CPlayer.mo is "DemonPlayerBase");
if (AmDemon)
{
// mTimeInterpolator.Update(DemonTimer);
mHealthInterpolator2.Update(CPlayer.health);
mHealthInterpolator3.Update(CPlayer.health);
mHealthInterpolator4.Update(CPlayer.health);
FakeCash = FakeCashTimer = 0;
MaxHP = CPlayer.mo.GetMaxHealth();
}
// Handle everything else here. I'm doing this purposely away from the
// draw functions because these really don't need updating every single TicFrac.
else
{
mHealthInterpolator.Update(CPlayer.health);
// Cash
Cash = GetAmountOnly("D4DCash");
if (FirstTic)
{
FirstTic = false;
PrevCash = Cash;
}
// Megaspheres
[MegasphereCount, MegasphereMax] = GetAmount("D4MegasphereDamageReducer");
Resonator = (GetAmountOnly("D4MegachargeUpgrade1") > 0);
// Extra Lives
LifeCount[0] = GetAmountOnly("D4ExtraLife");
// Doom Doll Count
DoomDollCount = GetAmountOnly("DollUses");
// Handle cash increases.
if (PrevCash < Cash)
{
FakeCash += Max(0, Cash - PrevCash);
FakeCashTimer = FakeCashStart;
PrevCash = Cash;
}
else
{
//ignoreFakeUpdate = false;
if (FakeCashTimer > 0)
{
FakeCashTimer--;
fadeamt = (FakeCashTimer > FakeCashFade - 1) ? 1.0 : Clamp((FakeCashTimer * (1.0 / FakeCashFade)), 0.0, 1.0);
}
else
FakeCash = 0;
}
}
if (WasDemon != AmDemon)
{
ResetInterpolators(CPlayer.health, DemonTimer);
}
automap = false;
}
override void DrawAutomapHUD(double ticFrac)
{
automap = true;
Super.DrawAutomapHud(ticFrac);
}
//==========================================================================
// Custom helper functions
//==========================================================================
double GetPowerFadeAlpha(Class<Powerup> item, int expirewarn = 105)
{
if (!CPlayer || !CPlayer.mo) return 0.0;
if (expirewarn < 1) return 1.0;
let power = Powerup(CPlayer.mo.FindInventory(item, true));
if (!power)
return 0.0;
if (power && power.EffectTics >= expirewarn)
return 1.0;
return (power.EffectTics / double(expirewarn));
}
// For only getting the current amount instead of both amount and max amounts.
int GetAmountOnly(class<Inventory> item, bool subtype = false)
{
let it = CPlayer.mo.FindInventory(item, subtype);
return (it ? it.Amount : 0);
}
// Uniform scaling.
void DrawStringScaled(HUDFont font, String string, Vector2 pos, int flags = 0, int translation = Font.CR_UNTRANSLATED, double Alpha = 1., int wrapwidth = -1, int linespacing = 4, double scaling = 1.0)
{
DrawString(font, string, pos, flags, translation, ALpha, wrapwidth, linespacing, (scaling, scaling));
}
void DrawInventoryBarScaled(InventoryBarState parms, Vector2 position, int numfields, int flags = 0, double bgalpha = 1., double scale = 1.0)
{
Vector2 vscale = (1, 1) * scale;
double width = parms.boxsize.X * numfields * scale;
[position, flags] = AdjustPosition(position, flags, width, parms.boxsize.Y * scale);
CPlayer.mo.InvFirst = ValidateInvFirst(numfields);
if (CPlayer.mo.InvFirst == null) return; // Player has no listed inventory items.
Vector2 boxsize = parms.boxsize * scale;
// First draw all the boxes
for(int i = 0; i < numfields; i++)
{
DrawTexture(parms.box, position + (boxsize.X * i, 0), flags | DI_ITEM_LEFT_TOP, bgalpha, scale: vscale);
}
// now the items and the rest
Vector2 itempos = position + boxsize / 2;
Vector2 textpos = position + boxsize - (1, 1 + parms.amountfont.mFont.GetHeight());
int i = 0;
Inventory item;
for(item = CPlayer.mo.InvFirst; item != NULL && i < numfields; item = item.NextInv())
{
for(int j = 0; j < 2; j++)
{
if (j ^ !!(flags & DI_DRAWCURSORFIRST))
{
if (item == CPlayer.mo.InvSel)
{
double flashAlpha = bgalpha;
if (flags & DI_ARTIFLASH) flashAlpha *= itemflashFade;
DrawTexture(parms.selector, position + parms.selectofs + (boxsize.X * i, 0), flags | DI_ITEM_LEFT_TOP, flashAlpha, scale: vscale);
}
}
else
{
DrawInventoryIcon(item, itempos + (boxsize.X * i, 0), flags | DI_ITEM_CENTER, scale: vscale);
}
}
if (parms.amountfont != null && (item.Amount > 1 || (flags & DI_ALWAYSSHOWCOUNTERS)))
{
DrawString(parms.amountfont, FormatNumber(item.Amount, 0, 5), textpos + (boxsize.X * i, 0), flags | DI_TEXT_ALIGN_RIGHT, parms.cr, parms.itemalpha, scale: vscale);
}
i++;
}
// Is there something to the left?
if (CPlayer.mo.FirstInv() != CPlayer.mo.InvFirst)
{
DrawTexture(parms.left, position + (-parms.arrowoffset.X, parms.arrowoffset.Y), flags | DI_ITEM_RIGHT|DI_ITEM_VCENTER, scale: vscale);
}
// Is there something to the right?
if (item != NULL)
{
DrawTexture(parms.right, position + parms.arrowoffset + (width, 0), flags | DI_ITEM_LEFT|DI_ITEM_VCENTER, scale: vscale);
}
}
}