Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //GUIManager.h
- #pragma once
- #include "stdafx.h"
- #include "GUIBase.h"
- class DrawManager;
- class GUIManager {
- public:
- GUIManager();
- ~GUIManager();
- void Draw(const std::string &p_identifier, DrawManager *p_drawManager);
- void DrawAll(DrawManager *p_drawManager);
- void UpdatePlayerHealth(int p_currentHP, int p_maxHP);
- void Add(const std::string &p_identifier, GUIBase *p_GUIElement);
- GUIBase* GetGUI(const std::string &p_identifier);
- void Remove(const std::string &p_identifier);
- private:
- std::map<std::string, GUIBase*> m_guiElements;
- };
- //GUIManager.cpp
- #include "stdafx.h"
- #include "GUIManager.h"
- #include "DrawManager.h"
- #include "PlayerHealthBar.h"
- GUIManager::GUIManager()
- {
- }
- GUIManager::~GUIManager()
- {
- auto it = m_guiElements.begin();
- while (it != m_guiElements.end()) {
- delete it->second;
- it = m_guiElements.erase(it);
- }
- m_guiElements.clear(); //Redundant?
- }
- void GUIManager::Draw(const std::string &p_identifier, DrawManager *p_drawManager) //This function might also be redundant >.>
- {
- auto it = m_guiElements.find(p_identifier);
- if (it == m_guiElements.end()) {
- printf("Can't find GUI Element %s!", p_identifier.c_str());
- return;
- }
- else {
- it->second->draw(p_drawManager->GetWindow());
- }
- }
- void GUIManager::DrawAll(DrawManager *p_drawManager)
- {
- std::map<std::string, GUIBase*> tempStorage = m_guiElements;
- auto it = tempStorage.begin();
- for (int i = 0; i < GUIBase::Strata::StrataAmount; ++i) {
- while (it != tempStorage.end())
- {
- if (it->second->GetStrata() == i) {
- it->second->draw(p_drawManager->GetWindow());
- //it = tempStorage.erase(it);
- }
- //else {
- // it++;
- //}
- ++it;
- }
- it = tempStorage.begin();
- }
- }
- void GUIManager::UpdatePlayerHealth(int p_currentHP, int p_maxHP)
- {
- auto it = m_guiElements.begin();
- while (it != m_guiElements.end()) {
- PlayerHealthBar* HPBar = dynamic_cast<PlayerHealthBar*>(it->second); //Need the checks from dynamic to make sure it actually is the health bar
- if (HPBar == nullptr) {
- continue;
- }
- else {
- HPBar->Update(p_currentHP, p_maxHP);
- break;
- }
- ++it;
- }
- }
- void GUIManager::Add(const std::string &p_identifier, GUIBase *p_GUIElement)
- {
- auto it = m_guiElements.find(p_identifier);
- if (m_guiElements.size() > 0) {
- if (it == m_guiElements.end()) {
- printf("%s already in the GUIManager! Choose another identifier!", p_identifier);
- return;
- }
- else {
- m_guiElements.insert(std::make_pair(p_identifier, p_GUIElement));
- }
- }
- else {
- m_guiElements.insert(std::make_pair(p_identifier, p_GUIElement));
- }
- }
- GUIBase* GUIManager::GetGUI(const std::string &p_identifier)
- {
- auto it = m_guiElements.find(p_identifier);
- if (it != m_guiElements.end()) {
- return it->second;
- }
- else {
- printf("Can't find GUI Element %s!", p_identifier.c_str());
- return nullptr;
- }
- }
- void GUIManager::Remove(const std::string &p_identifier)
- {
- auto it = m_guiElements.find(p_identifier);
- if (it == m_guiElements.end()) {
- printf("Can't find %s in the GUI Map!", p_identifier);
- return;
- }
- else {
- delete it->second;
- m_guiElements.erase(it);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment