New UITextComponent implemented
This commit is contained in:
@ -16,7 +16,7 @@
|
||||
|
||||
extern Manager manager;
|
||||
|
||||
UIText::UIText(std::string text, std::string texId, int x, int y, int letterW, int letterH, int lScale)
|
||||
UIText::UIText(std::string text, std::string texId, int x, int y, int letterW, int letterH, int lScale, std::string tag, Game::groupLabels group)
|
||||
{
|
||||
inputText = text;
|
||||
textureID = texId;
|
||||
@ -25,6 +25,10 @@ UIText::UIText(std::string text, std::string texId, int x, int y, int letterW, i
|
||||
letterWidth = letterW;
|
||||
letterHeight = letterH;
|
||||
scale = lScale;
|
||||
// gameGroup = Game::groupLabels::groupUI_Layer3;
|
||||
auto& uiLetters(manager.addEntity());
|
||||
uiLetters.setTag(tag);
|
||||
uiLetters.addGroup(group);
|
||||
}
|
||||
|
||||
UIText::~UIText()
|
||||
@ -33,12 +37,16 @@ UIText::~UIText()
|
||||
|
||||
void UIText::ParseString(std::string inputText, int x, int y, int letterScale, std::string tag, Game::groupLabels group)
|
||||
{
|
||||
// gameGroup = group;
|
||||
//Parse input text into an array of char
|
||||
int posX = x;
|
||||
int posY = y;
|
||||
int i = 0;
|
||||
char current = inputText[i];
|
||||
|
||||
int charsNumber = inputText.length();
|
||||
// printf("Counting string \'%s\': \n",inputText.c_str());
|
||||
// printf("%d\n",charsNumber);
|
||||
|
||||
do
|
||||
{
|
||||
++i;
|
||||
@ -60,15 +68,24 @@ void UIText::ParseString(std::string inputText, int x, int y, int letterScale, s
|
||||
void UIText::AddLetter(int xpos, int ypos, char crnt, std::string tag, int lttrScale, Game::groupLabels groupLabel)
|
||||
{
|
||||
// =======THIS NEEDS TO BE REFACTORED TO NOT USE INDIVIDUAL ENTITIES FOR EACH LETTER============
|
||||
auto& letter(manager.addEntity());
|
||||
letter.addComponent<TransformComponent>(xpos*lttrScale, ypos*lttrScale, letterWidth, letterHeight, 1);
|
||||
letter.addComponent<SpriteComponent>("font", SpriteComponent::spriteText, crnt, letterWidth, letterHeight, lttrScale);
|
||||
letter.setTag(tag);
|
||||
letter.addGroup(groupLabel);
|
||||
// auto& letter(manager.addEntity());
|
||||
// letter.addComponent<TransformComponent>(xpos*lttrScale, ypos*lttrScale, letterWidth, letterHeight, 1);
|
||||
// letter.addComponent<SpriteComponent>("font", SpriteComponent::spriteText, crnt, letterWidth, letterHeight, lttrScale);
|
||||
// letter.setTag(tag);
|
||||
// letter.addGroup(groupLabel);
|
||||
SDL_Texture* letterTexture;
|
||||
letterTexture = Game::assets->GetTexture(textureID);
|
||||
SDL_Rect srcRect,destRect;
|
||||
srcRect.x = ((crnt-ASCII_START_IDX) % ASCII_ROW_COUNT)*letterWidth;
|
||||
srcRect.y = ((crnt-ASCII_START_IDX)/ASCII_ROW_COUNT)*letterHeight;
|
||||
srcRect.w = letterWidth;
|
||||
srcRect.h = letterHeight;
|
||||
destRect.x = xpos;
|
||||
destRect.y = ypos;
|
||||
destRect.w = letterWidth*scale;
|
||||
destRect.h = letterHeight*scale;
|
||||
|
||||
TextureManager::Draw(letterTexture,srcRect,destRect,SDL_FLIP_NONE);
|
||||
}
|
||||
|
||||
void UIText::RemoveAllLetters()
|
||||
{
|
||||
manager.getEntitiesByTag("");
|
||||
}
|
||||
|
||||
|
@ -8,27 +8,47 @@
|
||||
#ifndef SRC_UITEXT_H_
|
||||
#define SRC_UITEXT_H_
|
||||
|
||||
#define ASCII_START_IDX 32
|
||||
#define ASCII_COUNT 96
|
||||
#define ASCII_ROW_COUNT 16
|
||||
|
||||
#include "SDL2/SDL.h"
|
||||
#include <iostream>
|
||||
#include "../game/Game.hpp"
|
||||
#include "../assetmgr/TextureManager.h"
|
||||
#include "../assetmgr/AssetManager.h"
|
||||
|
||||
class UIText
|
||||
{
|
||||
private:
|
||||
// SDL_Texture *texture;
|
||||
// SDL_Rect srcRect, destRect;
|
||||
char letter;
|
||||
// int frames = 0;
|
||||
// int speed = 100;
|
||||
int letterWidth, letterHeight;
|
||||
int scale = 1;
|
||||
public:
|
||||
std::string inputText;
|
||||
int letterHeight;
|
||||
int letterWidth;
|
||||
// int letterHeight;
|
||||
// int letterWidth;
|
||||
// virtual void init() {}
|
||||
// virtual void update() {}
|
||||
// virtual void draw() {}
|
||||
|
||||
Game::groupLabels gameGroup;
|
||||
int posX;
|
||||
int posY;
|
||||
std::string textureID;
|
||||
UIText(std::string inputText, std::string texID, int x, int y, int letterW, int letterH, int lScale);
|
||||
UIText(std::string inputText, std::string texID, int x, int y, int letterW, int letterH, int lScale, std::string tag, Game::groupLabels group);
|
||||
~UIText();
|
||||
|
||||
void init() {}
|
||||
void update() {}
|
||||
void draw() {}
|
||||
void AddLetter(int xpos, int ypos, char crnt, std::string tag, int lttrScale, Game::groupLabels groupLabel);
|
||||
void ParseString(std::string inputText, int x, int y, int letterScale, std::string tag, Game::groupLabels group);
|
||||
void RemoveAllLetters();
|
||||
void UpdateString(std::string newInputText);
|
||||
int scale;
|
||||
// void setTex(std::string id);
|
||||
// int scale;
|
||||
};
|
||||
|
||||
#endif /* SRC_UITEXT_H_ */
|
||||
|
Reference in New Issue
Block a user