Fixed UIText class for non-uniform scale

This commit is contained in:
Alan Youngblood 2021-07-29 08:21:45 -04:00
parent 31e16585d1
commit 363f28cb9c
6 changed files with 35 additions and 9 deletions

Binary file not shown.

View File

@ -83,6 +83,9 @@ public:
break;
}
}
// ===============================================
// ON KEY UP
// ===============================================
else if (Game::event.type == SDL_KEYUP)
{
switch (Game::event.key.keysym.sym)
@ -128,6 +131,13 @@ public:
case SDLK_u:
break;
case SDLK_i:
break;
case SDLK_d:
if (Game::debugMenu == false){
Game::debugMenu = true;}
else {
Game::debugMenu = false;
}
break;
case SDLK_ESCAPE: // exit the game when Escape pressed
Game::isRunning = false;

View File

@ -28,6 +28,10 @@ UIText* text;
UINineSlice* my9Slice;
UIText* scoreboardText;
UINineSlice* scoreboard9Slice;
UINineSlice* debugBox;
UIText* debugStaticText;
UIText* debugdynamicText;
GameStateManager* Game::gsm = new GameStateManager();
SDL_Renderer* Game::renderer = nullptr;
@ -38,6 +42,7 @@ SDL_Rect Game::camera;
AssetManager* Game::assets = new AssetManager(&manager);
bool Game::isRunning = false;
bool Game::debugMenu = false;
auto& player(manager.addEntity());
@ -48,9 +53,7 @@ auto& puppy(manager.addEntity());
auto& uiInfo(manager.addEntity());
bool Game::debugCollisionBoxes = false;
bool Game::gravityOnPlayer = true;
bool Game::playerIsGrounded = false;
int gScale = 0;
@ -134,6 +137,18 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
my9Slice = new UINineSlice("textBox");
my9Slice->MakeSlices("textBox",32,32,14,16,14,16,myDestRect,globalScale);
// debug UI box
std::string debugStaticString = "Debug info";
debugStaticText = new UIText(debugStaticString, "font", 0,0,8,12,1);
text->ParseString(debugStaticString,240*globalScale,44,1,"debug");
SDL_Rect debugBoxRect = SDL_Rect();
debugBoxRect.x = 240*globalScale;
debugBoxRect.y = 8*globalScale;
debugBoxRect.w = 80*globalScale;
debugBoxRect.h = 80*globalScale;
debugBox = new UINineSlice("textBox");
debugBox->MakeSlices("textBox",32,32,14,16,14,16,debugBoxRect,1);
//ecs implementation
map->LoadMap("assets/maps/br-map-color.txt",70,45, globalScale);

View File

@ -36,6 +36,7 @@ public:
static SDL_Renderer *renderer;
static SDL_Event event;
// static std::vector<ColliderComponent*> colliders;
static bool debugMenu;
static bool isRunning;
static bool debugCollisionBoxes;
static bool gravityOnPlayer;

View File

@ -31,7 +31,7 @@ UIText::~UIText()
{
}
void UIText::ParseString(std::string inputText, int x, int y, int scale, std::string tag)
void UIText::ParseString(std::string inputText, int x, int y, int letterScale, std::string tag)
{
//Parse input text into an array of char
int posX = x;
@ -64,18 +64,18 @@ void UIText::ParseString(std::string inputText, int x, int y, int scale, std::st
posX = x;
posY += letterHeight;
}
UIText::AddLetter(posX, posY, current, tag);
UIText::AddLetter(posX, posY, current, tag, letterScale);
current = inputText[i];
} while ((strcmp(&current,"\0"))!=0);
}
void UIText::AddLetter(int xpos, int ypos, char crnt, std::string tag)
void UIText::AddLetter(int xpos, int ypos, char crnt, std::string tag, int lttrScale)
{
auto& letter(manager.addEntity());
letter.addComponent<TransformComponent>(xpos*scale, ypos*scale, letterWidth, letterHeight, 1);
letter.addComponent<TransformComponent>(xpos*lttrScale, ypos*lttrScale, letterWidth, letterHeight, 1);
// printf("Scale: %d\n",scale);
letter.addComponent<SpriteComponent>("font", SpriteComponent::spriteText, crnt, letterWidth, letterHeight, scale);
letter.addComponent<SpriteComponent>("font", SpriteComponent::spriteText, crnt, letterWidth, letterHeight, lttrScale);
letter.setTag(tag);
letter.addGroup(Game::groupUI_Layer1);
}

View File

@ -24,8 +24,8 @@ public:
~UIText();
// void SetCharClips(SDL_Texture* fontTex, int x, int y, int letterW, int letterH);
void AddLetter(int xpos, int ypos, char crnt, std::string tag);
void ParseString(std::string inputText, int x, int y, int scale, std::string tag);
void AddLetter(int xpos, int ypos, char crnt, std::string tag, int lttrScale);
void ParseString(std::string inputText, int x, int y, int letterScale, std::string tag);
int scale;
};