Mario Kart 64
Loading...
Searching...
No Matches
Text.h
Go to the documentation of this file.
1#pragma once
2
3#include <libultraship.h>
4#include "engine/Actor.h"
5#include "src/textures.h"
6#include "engine/CoreMath.h"
7#include "port/Game.h"
8
9class AText : public AActor {
10public:
11 enum TextMode : int16_t {
14 };
15
16 enum FadeMode : int16_t {
20 };
21
27
31
33 const char* Texture;
34 f32 column;
35 f32 row;
36 u32 width;
37 u32 height;
38 s32 mode;
39 Vtx vtx[4];
40 };
41
42 std::vector<CharacterList> TextureList;
43
44 std::string Text; // The text to be displayed
46 uint32_t PlayerIndex;
47 float WidthOffset = 0.0f;
48 float HeightOffset = 8.0f; // Place text above player
49 f32 ScaleX = 1.0f;
50 f32 LetterSpacing = 1.0f;
51 f32 Far = 14000.0f;
52 f32 Close = 350.0f;
53
54 bool FaceCamera = true;
55 bool Animate = false;
56 bool SingleColour = true; // Only used for imGUI to show more colour options
57 // 1 colour for each of the 4 vtx
58 // This allows setting each vtx colour individually
60
61 // Constructor
62 AText(const SpawnParams& params);
63 virtual ~AText() override = default;
64
100 static inline AText* Spawn(std::string text, FVector pos, FVector scale, AText::TextMode textMode, int16_t playerIndex) {
101 SpawnParams params = {
102 .Name = "hm:text",
103 .Type = static_cast<int16_t>(textMode),
104 .Behaviour = static_cast<int16_t>(playerIndex),
105 .Skin = text,
106 .Location = pos,
107 .Scale = scale,
108 };
109 return static_cast<AText*>(gWorldInstance.AddActor(new AText(params)));
110 }
111
112 // Virtual functions to be overridden by derived classes
113 virtual void Tick() override;
114 virtual void Draw(Camera* camera) override;
115 virtual void SetSpawnParams(SpawnParams& params) override;
116 virtual bool IsMod() override;
117 virtual void DrawEditorProperties() override;
118 void DrawColourEditor(bool* updated);
119 void FollowPlayer();
120
121 void SetText(std::string text);
122
123 std::string ValidateString(const std::string_view& text);
124 void Refresh();
125 void Print3D(char* text, s32 tracking, s32 mode);
126 void PrintLetter3D(MenuTexture* glyphTexture, f32 column, f32 row, s32 mode);
127 void SetupVtx();
128 void DrawText3D(Camera* camera); // Based on func_80095BD0
129 void AnimateColour(Vtx* vtx); // Animate the vtx colours
130 void FadeIn(Vtx* vtx);
131 void FadeOut(Vtx* vtx);
132
133 inline uint8_t FloatToU8(float v) {
134 return (uint8_t)(v * 255.0f);
135 }
136
137 Vtx myVtx[12] = { // D_02007BB8
138 {{{ 0, 16, 0}, 0, { 0, 0}, {0xff, 0xff, 0xff, 0xff}}},
139 {{{26, 16, 0}, 0, {1600, 0}, {0xff, 0xff, 0xff, 0xff}}},
140 {{{26, 0, 0}, 0, {1600, 960}, {0xff, 0xff, 0xff, 0xff}}},
141 {{{ 0, 0, 0}, 0, { 0, 960}, {0xff, 0xff, 0xff, 0xff}}},
142 {{{ 0, 16, 0}, 0, { 0, 0}, {0xff, 0xff, 0xff, 0xff}}},
143 {{{16, 16, 0}, 0, {960, 0}, {0xff, 0xff, 0xff, 0xff}}},
144 {{{16, 0, 0}, 0, {960, 960}, {0xff, 0xff, 0xff, 0xff}}},
145 {{{ 0, 0, 0}, 0, { 0, 960}, {0xff, 0xff, 0xff, 0xff}}},
146 {{{ 0, 32, 0}, 0, { 0, 0}, {0xff, 0xff, 0xff, 0xff}}},
147 {{{30, 32, 0}, 0, {1856, 0}, {0xff, 0xff, 0xff, 0xff}}},
148 {{{30, 0, 0}, 0, {1856, 1984}, {0xff, 0xff, 0xff, 0xff}}},
149 {{{ 0, 0, 0}, 0, { 0, 1984}, {0xff, 0xff, 0xff, 0xff}}},
150 };
151};
World gWorldInstance
Definition Game.cpp:77
AActor()
Definition Actor.cpp:13
Vtx myVtx[12]
Definition Text.h:137
f32 LetterSpacing
Definition Text.h:50
virtual void Tick() override
Definition Text.cpp:145
float HeightOffset
Definition Text.h:48
bool SingleColour
Definition Text.h:56
static AText * Spawn(std::string text, FVector pos, FVector scale, AText::TextMode textMode, int16_t playerIndex)
Definition Text.h:100
void SetupVtx()
Definition Text.cpp:315
virtual void Draw(Camera *camera) override
Definition Text.cpp:168
f32 Close
Definition Text.h:52
virtual ~AText() override=default
void SetText(std::string text)
Definition Text.cpp:107
std::string ValidateString(const std::string_view &text)
Definition Text.cpp:79
FadeMode FadeState
Definition Text.h:30
f32 Far
Definition Text.h:51
uint32_t PlayerIndex
Definition Text.h:46
std::string Text
Definition Text.h:44
DistanceProps
Definition Text.h:22
@ TOO_CLOSE
Definition Text.h:23
@ TOO_FAR
Definition Text.h:25
@ ACTIVE
Definition Text.h:24
void DrawColourEditor(bool *updated)
Definition Text.cpp:552
f32 ScaleX
Definition Text.h:49
FadeMode
Definition Text.h:16
@ NO_FADE
Definition Text.h:17
@ FADE_OUT
Definition Text.h:19
@ FADE_IN
Definition Text.h:18
void PrintLetter3D(MenuTexture *glyphTexture, f32 column, f32 row, s32 mode)
Definition Text.cpp:290
virtual bool IsMod() override
Definition Text.cpp:121
float WidthOffset
Definition Text.h:47
void Refresh()
Definition Text.cpp:116
void Print3D(char *text, s32 tracking, s32 mode)
Definition Text.cpp:218
TextMode Mode
Definition Text.h:45
DistanceProps Dist
Definition Text.h:28
void DrawText3D(Camera *camera)
Definition Text.cpp:352
DistanceProps PrevState
Definition Text.h:29
void FadeIn(Vtx *vtx)
Definition Text.cpp:418
void AnimateColour(Vtx *vtx)
Definition Text.cpp:405
void FollowPlayer()
Definition Text.cpp:155
virtual void DrawEditorProperties() override
Definition Text.cpp:449
bool Animate
Definition Text.h:55
AText(const SpawnParams &params)
Definition Text.cpp:24
TextMode
Definition Text.h:11
@ STATIONARY
Definition Text.h:12
@ FOLLOW_PLAYER
Definition Text.h:13
virtual void SetSpawnParams(SpawnParams &params) override
Definition Text.cpp:123
std::vector< CharacterList > TextureList
Definition Text.h:42
uint8_t FloatToU8(float v)
Definition Text.h:133
RGBA8 TextColour[4]
Definition Text.h:59
void FadeOut(Vtx *vtx)
Definition Text.cpp:433
bool FaceCamera
Definition Text.h:54
Definition Text.h:32
const char * Texture
Definition Text.h:33
u32 width
Definition Text.h:36
s32 mode
Definition Text.h:38
f32 row
Definition Text.h:35
f32 column
Definition Text.h:34
u32 height
Definition Text.h:37
Vtx vtx[4]
Definition Text.h:39
Definition camera.h:27
Definition CoreMath.h:30
struct for a texture use in menu mainly
Definition textures.h:15
Definition CoreMath.h:17
Definition SpawnParams.h:30