| 1 |
// |
| 2 |
// Copyright(C) 2022 by Ryan Krafnick |
| 3 |
// |
| 4 |
// This program is free software; you can redistribute it and/or |
| 5 |
// modify it under the terms of the GNU General Public License |
| 6 |
// as published by the Free Software Foundation; either version 2 |
| 7 |
// of the License, or (at your option) any later version. |
| 8 |
// |
| 9 |
// This program is distributed in the hope that it will be useful, |
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
// GNU General Public License for more details. |
| 13 |
// |
| 14 |
// DESCRIPTION: |
| 15 |
// DSDA HUD Component Base |
| 16 |
// |
| 17 |
|
| 18 |
#include <math.h> |
| 19 |
|
| 20 |
#include "base.h" |
| 21 |
|
| 22 |
static char digit_lump[9]; |
| 23 |
static const char* digit_lump_format; |
| 24 |
|
| 25 |
int dsda_HudComponentY(int y_offset, int vpt, double ratio) { |
| 26 |
int dsda_ExHudVerticalOffset(void); |
| 27 |
|
| 28 |
int y = 0; |
| 29 |
int vpt_align; |
| 30 |
|
| 31 |
if (ratio) |
| 32 |
y_offset *= ratio; |
| 33 |
|
| 34 |
vpt_align = vpt & VPT_ALIGN_MASK; |
| 35 |
if (BOTTOM_ALIGNMENT(vpt_align)) { |
| 36 |
y = 200; |
| 37 |
y_offset = -y_offset; |
| 38 |
|
| 39 |
y -= dsda_ExHudVerticalOffset(); |
| 40 |
} |
| 41 |
|
| 42 |
return y + y_offset; |
| 43 |
} |
| 44 |
|
| 45 |
void dsda_InitTextHC(dsda_text_t* component, int x_offset, int y_offset, int vpt) { |
| 46 |
static double ratio; |
| 47 |
int x, y; |
| 48 |
|
| 49 |
DO_ONCE |
| 50 |
if (exhud_font.line_height != 8) |
| 51 |
ratio = (double) exhud_font.line_height / 8.0; |
| 52 |
END_ONCE |
| 53 |
|
| 54 |
x = x_offset; |
| 55 |
y = dsda_HudComponentY(y_offset, vpt, ratio); |
| 56 |
|
| 57 |
HUlib_initTextLine(&component->text, x, y, &exhud_font, CR_GRAY, vpt); |
| 58 |
} |
| 59 |
|
| 60 |
void dsda_InitBlockyHC(dsda_text_t* component, int x_offset, int y_offset, int vpt) { |
| 61 |
static double ratio; |
| 62 |
int x, y; |
| 63 |
|
| 64 |
DO_ONCE |
| 65 |
if (hud_font.line_height != 8) |
| 66 |
ratio = (double) hud_font.line_height / 8.0; |
| 67 |
END_ONCE |
| 68 |
|
| 69 |
x = x_offset; |
| 70 |
y = dsda_HudComponentY(y_offset, vpt, ratio); |
| 71 |
|
| 72 |
HUlib_initTextLine(&component->text, x, y, &hud_font, CR_GRAY, vpt); |
| 73 |
} |
| 74 |
|
| 75 |
void dsda_InitPatchHC(dsda_patch_component_t* component, int x_offset, int y_offset, int vpt) { |
| 76 |
int x, y; |
| 77 |
|
| 78 |
x = x_offset; |
| 79 |
y = dsda_HudComponentY(y_offset, vpt, 0); |
| 80 |
|
| 81 |
component->x = x; |
| 82 |
component->y = y; |
| 83 |
component->vpt = vpt; |
| 84 |
|
| 85 |
if (raven) |
| 86 |
digit_lump_format = "IN%.1d"; |
| 87 |
else |
| 88 |
digit_lump_format = "STTNUM%.1d"; |
| 89 |
} |
| 90 |
|
| 91 |
int dsda_HexenArmor(player_t* player) { |
| 92 |
int temp = pclass[player->pclass].auto_armor_save |
| 93 |
+ player->armorpoints[ARMOR_ARMOR] |
| 94 |
+ player->armorpoints[ARMOR_SHIELD] |
| 95 |
+ player->armorpoints[ARMOR_HELMET] |
| 96 |
+ player->armorpoints[ARMOR_AMULET]; |
| 97 |
return FixedDiv(temp, 5 * FRACUNIT) >> FRACBITS; |
| 98 |
} |
| 99 |
|
| 100 |
static void dsda_DrawBigDigit(int x, int y, int cm, int vpt, int digit) { |
| 101 |
extern int sts_colored_numbers; |
| 102 |
if (digit > 9 || digit < 0) |
| 103 |
return; |
| 104 |
|
| 105 |
snprintf(digit_lump, sizeof(digit_lump), digit_lump_format, digit); |
| 106 |
V_DrawNamePatch(x, y, FG, digit_lump, cm, vpt | ((sts_colored_numbers ? VPT_TRANS : VPT_NONE))); |
| 107 |
} |
| 108 |
|
| 109 |
static int digit_mod[6] = { 1, 10, 100, 1000, 10000, 100000 }; |
| 110 |
static int digit_div[6] = { 1, 1, 10, 100, 1000, 10000 }; |
| 111 |
|
| 112 |
void dsda_DrawBigNumber(int x, int y, int delta_x, int delta_y, int cm, int vpt, int count, int n) { |
| 113 |
int i; |
| 114 |
int digit, any_digit; |
| 115 |
|
| 116 |
if (count > 5) |
| 117 |
return; |
| 118 |
|
| 119 |
any_digit = 0; |
| 120 |
|
| 121 |
for (i = count; i > 0; --i) { |
| 122 |
digit = (n % digit_mod[i]) / digit_div[i]; |
| 123 |
any_digit |= digit; |
| 124 |
|
| 125 |
if (any_digit || i == 1) |
| 126 |
dsda_DrawBigDigit(x, y, cm, vpt, digit); |
| 127 |
|
| 128 |
x += delta_x; |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
void dsda_DrawBasicText(dsda_text_t* component) { |
| 133 |
HUlib_drawTextLine(&component->text, false); |
| 134 |
} |
| 135 |
|
| 136 |
void dsda_RefreshHudText(dsda_text_t* component) { |
| 137 |
const char* s; |
| 138 |
|
| 139 |
HUlib_clearTextLine(&component->text); |
| 140 |
|
| 141 |
s = component->msg; |
| 142 |
while (*s) HUlib_addCharToTextLine(&component->text, *(s++)); |
| 143 |
} |