diff --git a/build/BeagleRescue b/build/BeagleRescue index 66f7a2b..27fe35d 100755 Binary files a/build/BeagleRescue and b/build/BeagleRescue differ diff --git a/src/ecs/UITextComponent.h b/src/ecs/UITextComponent.h index 1d88865..26aa163 100644 --- a/src/ecs/UITextComponent.h +++ b/src/ecs/UITextComponent.h @@ -20,8 +20,7 @@ #include #include #include - -// Should include and to make an array of tuples with two SDL_Rect type vars to feed to the draw function. +#include class UITextComponent : public Component { @@ -29,7 +28,6 @@ private: TransformComponent *transform; SDL_Texture *texture; SDL_Rect srcRect, destRect; -// char letter; std::string text; int letterWidth, letterHeight; int scale = 1; @@ -46,8 +44,6 @@ public: letterWidth = letterW; letterHeight = letterH; scale = letterScale; -// destRect.w = letterW*letterScale; -// destRect.h = letterH*letterScale; } ~UITextComponent() @@ -63,7 +59,6 @@ public: void init() override { transform = &entity->getComponent(); - } void update() override @@ -74,7 +69,6 @@ public: void draw() override { -// This should be updated to iterate through an array of each letter's srcRect and destRect for (int l = 0; l < text.length(); l++) { std::tuple lttr = getLetterTexture(text[l],l); @@ -85,13 +79,13 @@ public: std::tuple getLetterTexture(char currentLetter, int i) { std::tuple letterTuple; - + int charsPerLine = std::floor(transform->width/letterWidth); srcRect.x = ((currentLetter-ASCII_START_IDX) % ASCII_ROW_COUNT)*letterWidth; srcRect.y = ((currentLetter-ASCII_START_IDX)/ASCII_ROW_COUNT)*letterHeight; srcRect.w = letterWidth; srcRect.h = letterHeight; - destRect.x = static_cast(transform->position.x)*scale+i*letterWidth*scale; - destRect.y = static_cast(transform->position.y)*scale; + destRect.x = static_cast(transform->position.x)*scale+(i%charsPerLine)*letterWidth*scale; + destRect.y = static_cast(transform->position.y)*scale+std::floor(i/charsPerLine)*letterHeight*scale*1.5; destRect.w = letterWidth*scale; destRect.h = letterHeight*scale; letterTuple = std::make_tuple(srcRect,destRect); diff --git a/src/game/Game.cpp b/src/game/Game.cpp index 3322d76..ca0a1bc 100644 --- a/src/game/Game.cpp +++ b/src/game/Game.cpp @@ -151,7 +151,7 @@ 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,Game::groupUI_Layer0); - uiInfo.addComponent(160,120,64,32,1); + uiInfo.addComponent(10,10,180,56,1); uiInfo.addComponent("font", "UI Text works again!", 8, 12, 1); uiInfo.addGroup(groupUI_Layer3); // debug UI text @@ -258,7 +258,7 @@ void Game::update() SDL_Rect playerCol = player.getComponent().collider; Vector2D playerPos = player.getComponent().position; - uiInfo.getComponent().updateString("New Text Works!"); + uiInfo.getComponent().updateString("Updating UIText works well, even with basic word wrap for new lines."); // if (gsm->currentState == GameStateManager::ST_INIT) // {