Skip to content

Commit

Permalink
updated ui: the game instance now has a global game ui that contains …
Browse files Browse the repository at this point in the history
…ui element in a nested hierarchy
  • Loading branch information
Ipagaxi committed Aug 29, 2024
1 parent 77dce66 commit 96d86e9
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 3 deletions.
Empty file.
8 changes: 8 additions & 0 deletions src/Activities/CharacterActivity/CharacterActivityUI.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef CHARACTERACTIVITYUI_H
#define CHARACTERACTIVITYUI_H

class CharacterActivityUI {

};

#endif
6 changes: 3 additions & 3 deletions src/Activities/FightActivity/FightActivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ FightActivity::FightActivity() : Activity(), fightActivityUIObjects(), currentFi
this->fightActivityUIObjects.enemyOverview = std::make_unique<UIEnemyOverview>(this->enemy);
this->fightActivityUIObjects.playerOverview = std::make_unique<UIPlayerOverview>(Game::getInstance().player);

this->fightActivityUIObjects.backgroundTX.loadFromFile(RESOURCE_PATH + "backgrounds/background_fight.png");
this->fightActivityUIObjects.backgroundSP.setTexture(this->fightActivityUIObjects.backgroundTX);
game.gameUI.changeBackgroundTexture("background_fight.png");

this->fightActivityUIObjects.backgroundMusic.openFromFile(RESOURCE_PATH + "music/fight_background_music.wav");
this->fightActivityUIObjects.backgroundMusic.setLoop(true);
Expand Down Expand Up @@ -67,7 +66,8 @@ ActivityEnum FightActivity::executeActivity() {
ActivityEnum currentActivity = ActivityEnum::Fight;

game.gameWindow.draw(this->fightActivityUIObjects.turnSP);
game.gameWindow.draw(this->fightActivityUIObjects.backgroundSP);
//game.gameWindow.draw(this->fightActivityUIObjects.backgroundSP);
game.gameWindow.draw(game.gameUI.backgroundSP);
this->fightActivityUIObjects.playerOverview->draw();
this->fightActivityUIObjects.enemyOverview->draw();
this->exitButton.draw();
Expand Down
2 changes: 2 additions & 0 deletions src/System/Game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "Activities/ActivityEnum.hpp"
//#include "Activities/Activity.hpp"
#include "System/GameUI.hpp"
#include "Global/Utility.hpp"
#include "Actors/Player.hpp"
#include "System/GameEvents.hpp"
Expand All @@ -19,6 +20,7 @@ class Game {
sf::Font mainFont;
GameEvents gameEvents;
GameStatus gameStatus;
GameUI gameUI;
sf::RenderWindow& gameWindow;

std::shared_ptr<Player> player = std::make_shared<Player>(Player("Ipagaxi", 100, 12, {100, 100, 100}, "default_actor_quer.png"));
Expand Down
14 changes: 14 additions & 0 deletions src/System/GameUI.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "GameUI.hpp"

#include "Game.hpp"

GameUI::GameUI() {
this->backgroundTX.loadFromFile(RESOURCE_PATH + "backgrounds/backgroundMenu.png");
this->backgroundSP.setTexture(this->backgroundTX);
}

void GameUI::changeBackgroundTexture(std::string filename) {
this->backgroundTX.loadFromFile(RESOURCE_PATH + "backgrounds/" + filename);
this->backgroundSP.setTexture(this->backgroundTX);
}

23 changes: 23 additions & 0 deletions src/System/GameUI.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef GAMEUI_HPP
#define GAMEUI_HPP

#include <SFML/Graphics.hpp>
#include <string>

#include "Activities/CharacterActivity/CharacterActivityUI.hpp"
#include "Global/Utility.hpp"

class GameUI {
public:
GameUI();

sf::Texture backgroundTX;
sf::Sprite backgroundSP;

CharacterActivityUI characterActivityUI;

void changeBackgroundTexture(std::string filename);

};

#endif

0 comments on commit 96d86e9

Please sign in to comment.