SpaghettiKart
Loading...
Searching...
No Matches
Text.h
Go to the documentation of this file.
1#pragma once
2
3#include <libultraship.h>
5#include "engine/Actor.h"
6#include "src/textures.h"
7#include "engine/CoreMath.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() {
64 _count--;
65 };
66
67 static size_t GetCount() {
68 return _count;
69 }
70
106 static AText* Spawn(std::string text, FVector pos, FVector scale, AText::TextMode textMode, int16_t playerIndex) {
107 SpawnParams params = {
108 .Name = "hm:text",
109 .Type = static_cast<int16_t>(textMode),
110 .Behaviour = playerIndex,
111 .Skin = text,
112 .Location = pos,
113 .Scale = scale,
114 };
115 return dynamic_cast<AText*>(AddActorToWorld<AText>(params));
116 }
117
118 // Virtual functions to be overridden by derived classes
119 virtual void Tick() override;
120 virtual void Draw(Camera* camera) override;
121 virtual void SetSpawnParams(SpawnParams& params) override;
122 virtual bool IsMod() override;
123 virtual void DrawEditorProperties() override;
124 void DrawColourEditor(bool* updated);
125 void FollowPlayer();
126
127 void SetText(std::string text);
128 std::string ValidateString(const std::string_view& text);
129 void Refresh();
130 void Print3D(char* text, s32 tracking, s32 mode);
131 void PrintLetter3D(MenuTexture* glyphTexture, f32 column, f32 row, s32 mode);
132 void SetupVtx();
133 void DrawText3D(Camera* camera); // Based on func_80095BD0
134 void AnimateColour(Vtx* vtx); // Animate the vtx colours
135 void FadeIn(Vtx* vtx);
136 void FadeOut(Vtx* vtx);
137
138 inline uint8_t FloatToU8(float v) {
139 return (uint8_t)(v * 255.0f);
140 }
141
142 Vtx myVtx[12] = { // D_02007BB8
143 {{{ 0, 16, 0}, 0, { 0, 0}, {0xff, 0xff, 0xff, 0xff}}},
144 {{{26, 16, 0}, 0, {1600, 0}, {0xff, 0xff, 0xff, 0xff}}},
145 {{{26, 0, 0}, 0, {1600, 960}, {0xff, 0xff, 0xff, 0xff}}},
146 {{{ 0, 0, 0}, 0, { 0, 960}, {0xff, 0xff, 0xff, 0xff}}},
147 {{{ 0, 16, 0}, 0, { 0, 0}, {0xff, 0xff, 0xff, 0xff}}},
148 {{{16, 16, 0}, 0, {960, 0}, {0xff, 0xff, 0xff, 0xff}}},
149 {{{16, 0, 0}, 0, {960, 960}, {0xff, 0xff, 0xff, 0xff}}},
150 {{{ 0, 0, 0}, 0, { 0, 960}, {0xff, 0xff, 0xff, 0xff}}},
151 {{{ 0, 32, 0}, 0, { 0, 0}, {0xff, 0xff, 0xff, 0xff}}},
152 {{{30, 32, 0}, 0, {1856, 0}, {0xff, 0xff, 0xff, 0xff}}},
153 {{{30, 0, 0}, 0, {1856, 1984}, {0xff, 0xff, 0xff, 0xff}}},
154 {{{ 0, 0, 0}, 0, { 0, 1984}, {0xff, 0xff, 0xff, 0xff}}},
155 };
156private:
157 static size_t _count;
158 size_t _idx;
159};
static AActor * AddActorToWorld(const SpawnParams &params)
Definition RegisterContent.h:14
AActor()
Definition Actor.cpp:13
FVector Scale
Definition Actor.h:35
Vtx myVtx[12]
Definition Text.h:142
f32 LetterSpacing
Definition Text.h:50
virtual void Tick() override
Definition Text.cpp:150
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:106
void SetupVtx()
Definition Text.cpp:320
virtual void Draw(Camera *camera) override
Definition Text.cpp:173
virtual ~AText()
Definition Text.h:63
f32 Close
Definition Text.h:52
void SetText(std::string text)
Definition Text.cpp:112
std::string ValidateString(const std::string_view &text)
Definition Text.cpp:84
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:558
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:295
size_t _idx
Definition Text.h:158
static size_t _count
Definition Text.h:157
virtual bool IsMod() override
Definition Text.cpp:126
float WidthOffset
Definition Text.h:47
void Refresh()
Definition Text.cpp:121
void Print3D(char *text, s32 tracking, s32 mode)
Definition Text.cpp:223
TextMode Mode
Definition Text.h:45
DistanceProps Dist
Definition Text.h:28
void DrawText3D(Camera *camera)
Definition Text.cpp:357
DistanceProps PrevState
Definition Text.h:29
void FadeIn(Vtx *vtx)
Definition Text.cpp:424
void AnimateColour(Vtx *vtx)
Definition Text.cpp:411
void FollowPlayer()
Definition Text.cpp:160
virtual void DrawEditorProperties() override
Definition Text.cpp:455
bool Animate
Definition Text.h:55
AText(const SpawnParams &params)
Definition Text.cpp:26
static size_t GetCount()
Definition Text.h:67
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:128
std::vector< CharacterList > TextureList
Definition Text.h:42
uint8_t FloatToU8(float v)
Definition Text.h:138
RGBA8 TextColour[4]
Definition Text.h:59
void FadeOut(Vtx *vtx)
Definition Text.cpp:439
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:35
Definition CoreMath.h:30
struct for a texture use in menu mainly
Definition textures.h:15
Definition CoreMath.h:17
Definition SpawnParams.h:30