Fixed UIText class for non-uniform scale
This commit is contained in:
parent
31e16585d1
commit
363f28cb9c
Binary file not shown.
@ -83,6 +83,9 @@ public:
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// ===============================================
|
||||||
|
// ON KEY UP
|
||||||
|
// ===============================================
|
||||||
else if (Game::event.type == SDL_KEYUP)
|
else if (Game::event.type == SDL_KEYUP)
|
||||||
{
|
{
|
||||||
switch (Game::event.key.keysym.sym)
|
switch (Game::event.key.keysym.sym)
|
||||||
@ -128,6 +131,13 @@ public:
|
|||||||
case SDLK_u:
|
case SDLK_u:
|
||||||
break;
|
break;
|
||||||
case SDLK_i:
|
case SDLK_i:
|
||||||
|
break;
|
||||||
|
case SDLK_d:
|
||||||
|
if (Game::debugMenu == false){
|
||||||
|
Game::debugMenu = true;}
|
||||||
|
else {
|
||||||
|
Game::debugMenu = false;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case SDLK_ESCAPE: // exit the game when Escape pressed
|
case SDLK_ESCAPE: // exit the game when Escape pressed
|
||||||
Game::isRunning = false;
|
Game::isRunning = false;
|
||||||
|
@ -28,6 +28,10 @@ UIText* text;
|
|||||||
UINineSlice* my9Slice;
|
UINineSlice* my9Slice;
|
||||||
UIText* scoreboardText;
|
UIText* scoreboardText;
|
||||||
UINineSlice* scoreboard9Slice;
|
UINineSlice* scoreboard9Slice;
|
||||||
|
UINineSlice* debugBox;
|
||||||
|
UIText* debugStaticText;
|
||||||
|
UIText* debugdynamicText;
|
||||||
|
|
||||||
GameStateManager* Game::gsm = new GameStateManager();
|
GameStateManager* Game::gsm = new GameStateManager();
|
||||||
|
|
||||||
SDL_Renderer* Game::renderer = nullptr;
|
SDL_Renderer* Game::renderer = nullptr;
|
||||||
@ -38,6 +42,7 @@ SDL_Rect Game::camera;
|
|||||||
AssetManager* Game::assets = new AssetManager(&manager);
|
AssetManager* Game::assets = new AssetManager(&manager);
|
||||||
|
|
||||||
bool Game::isRunning = false;
|
bool Game::isRunning = false;
|
||||||
|
bool Game::debugMenu = false;
|
||||||
|
|
||||||
auto& player(manager.addEntity());
|
auto& player(manager.addEntity());
|
||||||
|
|
||||||
@ -48,9 +53,7 @@ auto& puppy(manager.addEntity());
|
|||||||
auto& uiInfo(manager.addEntity());
|
auto& uiInfo(manager.addEntity());
|
||||||
|
|
||||||
bool Game::debugCollisionBoxes = false;
|
bool Game::debugCollisionBoxes = false;
|
||||||
|
|
||||||
bool Game::gravityOnPlayer = true;
|
bool Game::gravityOnPlayer = true;
|
||||||
|
|
||||||
bool Game::playerIsGrounded = false;
|
bool Game::playerIsGrounded = false;
|
||||||
|
|
||||||
int gScale = 0;
|
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 = new UINineSlice("textBox");
|
||||||
my9Slice->MakeSlices("textBox",32,32,14,16,14,16,myDestRect,globalScale);
|
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
|
//ecs implementation
|
||||||
|
|
||||||
map->LoadMap("assets/maps/br-map-color.txt",70,45, globalScale);
|
map->LoadMap("assets/maps/br-map-color.txt",70,45, globalScale);
|
||||||
|
@ -36,6 +36,7 @@ public:
|
|||||||
static SDL_Renderer *renderer;
|
static SDL_Renderer *renderer;
|
||||||
static SDL_Event event;
|
static SDL_Event event;
|
||||||
// static std::vector<ColliderComponent*> colliders;
|
// static std::vector<ColliderComponent*> colliders;
|
||||||
|
static bool debugMenu;
|
||||||
static bool isRunning;
|
static bool isRunning;
|
||||||
static bool debugCollisionBoxes;
|
static bool debugCollisionBoxes;
|
||||||
static bool gravityOnPlayer;
|
static bool gravityOnPlayer;
|
||||||
|
@ -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
|
//Parse input text into an array of char
|
||||||
int posX = x;
|
int posX = x;
|
||||||
@ -64,18 +64,18 @@ void UIText::ParseString(std::string inputText, int x, int y, int scale, std::st
|
|||||||
posX = x;
|
posX = x;
|
||||||
posY += letterHeight;
|
posY += letterHeight;
|
||||||
}
|
}
|
||||||
UIText::AddLetter(posX, posY, current, tag);
|
UIText::AddLetter(posX, posY, current, tag, letterScale);
|
||||||
current = inputText[i];
|
current = inputText[i];
|
||||||
} while ((strcmp(¤t,"\0"))!=0);
|
} while ((strcmp(¤t,"\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());
|
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);
|
// 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.setTag(tag);
|
||||||
letter.addGroup(Game::groupUI_Layer1);
|
letter.addGroup(Game::groupUI_Layer1);
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,8 @@ public:
|
|||||||
~UIText();
|
~UIText();
|
||||||
|
|
||||||
// void SetCharClips(SDL_Texture* fontTex, int x, int y, int letterW, int letterH);
|
// 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 AddLetter(int xpos, int ypos, char crnt, std::string tag, int lttrScale);
|
||||||
void ParseString(std::string inputText, int x, int y, int scale, std::string tag);
|
void ParseString(std::string inputText, int x, int y, int letterScale, std::string tag);
|
||||||
int scale;
|
int scale;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user