Skip to content

Commit 17e3761

Browse files
authored
xHudFontMeter Progress (#648)
* xHudFontMeter overhead * Method for converting color32u to iColor_tag * Generally okay matches for xHudFontMeter * Seeing if it builds with new commented out * Other build fix (thanks Sway) * Revert, this was fine * My redefinition of the load method was breaking things. Reverted and method commented to be a stub. * Square tweaks
1 parent 4f84754 commit 17e3761

File tree

3 files changed

+213
-13
lines changed

3 files changed

+213
-13
lines changed

src/SB/Core/gc/iColor.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define ICOLOR_H
33

44
#include <types.h>
5+
#include <xHud.h>
56

67
struct iColor_tag
78
{
@@ -18,6 +19,16 @@ struct iColor_tag
1819
this->a = rhs.a;
1920
return *this;
2021
};
22+
23+
// Conversion constructor instead?
24+
iColor_tag& operator=(const xhud::color32u& rhs)
25+
{
26+
this->r = rhs.r;
27+
this->g = rhs.g;
28+
this->b = rhs.b;
29+
this->a = rhs.a;
30+
return *this;
31+
};
2132
};
2233

2334
#endif

src/SB/Core/x/xHudFontMeter.cpp

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,183 @@
11
#include "xHudFontMeter.h"
22

33
#include <types.h>
4+
#include <xMath2.h>
5+
#include <PowerPC_EABI_Support\MSL_C\MSL_Common\printf.h>
6+
#include <PowerPC_EABI_Support\MSL_C++\MSL_Common\Include\new.h>
7+
8+
void xhud::font_meter_widget::load(xBase& data, xDynAsset& asset, u32 size_t)
9+
{
10+
// Stubbed out for now for causing build failure. 100% match locally though if method redefined to be nonstatic.
11+
// widget::init_base((xBase&)*this, *(xBaseAsset*)&data, sizeof(xhud::font_meter_widget) + 0x10);
12+
// new (&this->rc.size)
13+
// xhud::font_meter_widget(*(xhud::font_meter_asset*)&data); // TODO: proper size value
14+
}
15+
16+
xhud::font_meter_widget::font_meter_widget(xhud::font_meter_asset& init) : meter_widget(init)
17+
{
18+
basic_rect<F32> screen_bounds;
19+
20+
this->font.id = init.font.id;
21+
this->font.justify = init.font.justify;
22+
this->start_font.id = init.font.id;
23+
this->start_font.justify = init.font.justify;
24+
25+
// No assembly for this operator but bytewise is too many instructions
26+
this->font.c = init.font.c;
27+
this->start_font.c = init.font.c;
28+
this->font.drop_c = init.font.drop_c;
29+
this->start_font.drop_c = init.font.drop_c;
30+
31+
this->last_value = ((S32)(this->value)) - 20;
32+
this->xf.id = 0;
33+
this->xf.width = this->font.w;
34+
this->xf.height = this->font.h;
35+
this->xf.space = this->font.space;
36+
37+
this->xf.color = this->font.c;
38+
this->xf.clip = screen_bounds;
39+
}
40+
41+
void xhud::font_meter_widget::destruct()
42+
{
43+
xhud::meter_widget::destruct();
44+
}
45+
46+
void xhud::font_meter_widget::destroy()
47+
{
48+
this->destruct();
49+
}
50+
51+
U32 xhud::font_meter_widget::type()
52+
{
53+
static S8 init;
54+
static U32 myid;
55+
56+
if (init == 0)
57+
{
58+
myid = xStrHash(((xhud::font_meter_asset*)this)->type_name());
59+
init = 1;
60+
}
61+
return myid;
62+
}
63+
64+
U8 xhud::font_meter_widget::is(U32 id)
65+
{
66+
U8 val = 0;
67+
68+
if ((id == this->type()) || (((xhud::meter_widget*)this->is(id)) != 0))
69+
{
70+
val = 1;
71+
}
72+
return val;
73+
}
74+
75+
void xhud::font_meter_widget::update(F32 dt)
76+
77+
{
78+
char* format_text[3];
79+
format_text[0] = 0;
80+
81+
F32 a;
82+
S32 new_value;
83+
basic_rect<F32> bounds;
84+
85+
U8 flag_1;
86+
U8 flag_2;
87+
88+
this->updater(dt);
89+
this->xf.id = this->font.id;
90+
this->xf.space = this->font.space;
91+
a = this->rc.size.x;
92+
this->font.w = a;
93+
this->xf.width = a;
94+
a = this->rc.size.y;
95+
this->font.h = a;
96+
this->xf.height = a;
97+
98+
a = this->rc.a * (F32)this->start_font.c.a + 0.5;
99+
if (a <= 0.0)
100+
{
101+
flag_1 = 0;
102+
}
103+
else if (a >= 255.0)
104+
{
105+
flag_1 = 255;
106+
}
107+
else if (a < 2.1474836e+09)
108+
{
109+
flag_1 = (U8)(S32)a;
110+
}
111+
else
112+
{
113+
flag_1 = (U8)(S32)(a - 2.1474836e+09);
114+
}
115+
this->font.c.a = flag_1;
116+
117+
a = this->rc.a * (F32)this->start_font.drop_c.a + 0.5;
118+
if (a <= 0.0)
119+
{
120+
flag_1 = 0;
121+
}
122+
else if (a >= 255.0)
123+
{
124+
flag_1 = 255;
125+
}
126+
else if (a < 2.1474836e+09)
127+
{
128+
flag_1 = (U8)(S32)a;
129+
}
130+
else
131+
{
132+
flag_1 = (U8)(S32)(a - 2.1474836e+09);
133+
}
134+
this->font.drop_c.a = flag_1;
135+
136+
new_value = (S32)(this->value + 0.5);
137+
if (this->last_value != new_value)
138+
{
139+
this->last_value = new_value;
140+
a = this->max_value;
141+
if (a < this->min_value)
142+
{
143+
flag_2 = 0;
144+
}
145+
else
146+
{
147+
flag_2 = ((font_meter_asset*)(this->a))->counter_mode;
148+
}
149+
sprintf(this->buffer, format_text[flag_2], new_value, (S32)(a + 0.5));
150+
bounds = this->xf.bounds(this->buffer);
151+
this->offset.x = -bounds.x;
152+
this->offset.y = -bounds.y;
153+
}
154+
return;
155+
}
156+
157+
void xhud::font_meter_widget::render()
158+
159+
{
160+
F32 x;
161+
F32 temp_x;
162+
F32 y;
163+
164+
temp_x = this->offset.x + this->rc.loc.x;
165+
y = this->offset.y + this->rc.loc.y;
166+
if (this->font.drop_c.a != 0)
167+
{
168+
this->xf.color = this->font.drop_c;
169+
x = temp_x + this->font.drop_x;
170+
this->xf.render(this->buffer, x, y + this->font.drop_y);
171+
}
172+
if (this->font.c.a != 0)
173+
{
174+
this->xf.color = this->font.c;
175+
this->xf.render(this->buffer, temp_x, y);
176+
}
177+
return;
178+
}
179+
180+
char* xhud::font_meter_asset::type_name()
181+
{
182+
return "hud:meter:font";
183+
}

src/SB/Core/x/xHudFontMeter.h

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,36 @@ namespace xhud
1818
color32u c;
1919
color32u drop_c;
2020
};
21-
21+
2222
struct font_meter_asset : meter_asset
2323
{
24-
font_context font; // offset 0x4C, size 0x24
25-
U8 counter_mode; // offset 0x70, size 0x1
26-
U8 pad1; // offset 0x71, size 0x1
27-
U8 pad2; // offset 0x72, size 0x1
28-
U8 pad3; // offset 0x73, size 0x1
24+
font_context font; // offset 0x4C, size 0x24
25+
U8 counter_mode; // offset 0x70, size 0x1
26+
U8 pad1; // offset 0x71, size 0x1
27+
U8 pad2; // offset 0x72, size 0x1
28+
U8 pad3; // offset 0x73, size 0x1
29+
30+
char* type_name();
2931
};
3032

3133
struct font_meter_widget : meter_widget
3234
{
33-
font_context font;
34-
font_context start_font;
35-
S32 precision;
36-
xVec2 offset;
37-
char buffer[12];
38-
S32 last_value;
39-
xfont xf;
35+
font_context font; // 0xC4
36+
font_context start_font; // 0xE8
37+
S32 precision; // 0x10C
38+
xVec2 offset; // 0x110
39+
char buffer[12]; // 0x118
40+
S32 last_value; // 0x124
41+
xfont xf; // 0x128
4042

4143
static void load(xBase& data, xDynAsset& asset, size_t);
44+
font_meter_widget(xhud::font_meter_asset& init);
45+
void destruct();
46+
void destroy();
47+
U32 type();
48+
U8 is(U32 id);
49+
void update(F32 dt);
50+
void render();
4251

4352
font_meter_asset* get_asset()
4453
{

0 commit comments

Comments
 (0)