-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
214 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#pragma once | ||
#include "View.h" | ||
#include <content/Texture.h> | ||
|
||
namespace UI | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// | ||
// Created by desktop on 17.12.16. | ||
// | ||
|
||
#include "Hud.h" | ||
#include "BarView.h" | ||
#include <engine/BaseEngine.h> | ||
|
||
UI::Hud::Hud(Engine::BaseEngine& engine) : m_Engine(engine) | ||
{ | ||
Textures::TextureAllocator& alloc = engine.getEngineTextureAlloc(); | ||
|
||
m_pHealthBar = new BarView(); | ||
m_pManaBar = new BarView(); | ||
m_pEnemyHealthBar = new BarView(); | ||
|
||
addChild(m_pHealthBar); | ||
addChild(m_pManaBar); | ||
addChild(m_pEnemyHealthBar); | ||
|
||
// Initialize status bars | ||
{ | ||
Handle::TextureHandle hBarBackground = alloc.loadTextureVDF("BAR_BACK.TGA"); | ||
Handle::TextureHandle hBarHealth = alloc.loadTextureVDF("BAR_HEALTH.TGA"); | ||
Handle::TextureHandle hBarMana = alloc.loadTextureVDF("BAR_MANA.TGA"); | ||
|
||
// Images | ||
m_pHealthBar->setBackgroundImage(alloc.getTexture(hBarBackground)); | ||
m_pManaBar->setBackgroundImage(alloc.getTexture(hBarBackground)); | ||
m_pEnemyHealthBar->setBackgroundImage(alloc.getTexture(hBarBackground)); | ||
|
||
m_pHealthBar->setBarImage(alloc.getTexture(hBarHealth)); | ||
m_pManaBar->setBarImage(alloc.getTexture(hBarMana)); | ||
m_pEnemyHealthBar->setBarImage(alloc.getTexture(hBarHealth)); | ||
|
||
// Alignment | ||
m_pHealthBar->setAlignment(A_BottomLeft); | ||
m_pManaBar->setAlignment(A_BottomRight); | ||
m_pEnemyHealthBar->setAlignment(A_TopCenter); | ||
|
||
// Size | ||
Math::float2 barSize = Math::float2(0.6f, 0.6f); | ||
m_pHealthBar->setSize(barSize); | ||
m_pManaBar->setSize(barSize); | ||
m_pEnemyHealthBar->setSize(barSize); | ||
|
||
// Position | ||
m_pHealthBar->setTranslation(Math::float2(0.01f, 0.99f)); | ||
m_pManaBar->setTranslation(Math::float2(0.99f, 0.99f)); | ||
m_pEnemyHealthBar->setTranslation(Math::float2(0.5f, 0.01f)); | ||
} | ||
} | ||
|
||
UI::Hud::~Hud() | ||
{ | ||
removeChild(m_pHealthBar); | ||
removeChild(m_pManaBar); | ||
removeChild(m_pEnemyHealthBar); | ||
|
||
delete m_pManaBar; | ||
delete m_pHealthBar; | ||
delete m_pEnemyHealthBar; | ||
} | ||
|
||
void UI::Hud::update(double dt, Engine::Input::MouseState& mstate, Render::RenderConfig& config) | ||
{ | ||
View::update(dt, mstate, config); | ||
} | ||
|
||
void UI::Hud::setHealth(float value) | ||
{ | ||
m_pHealthBar->setValue(value); | ||
} | ||
|
||
void UI::Hud::setMana(float value) | ||
{ | ||
m_pManaBar->setValue(value); | ||
} | ||
|
||
void UI::Hud::setEnemyHealth(float value) | ||
{ | ||
m_pEnemyHealthBar->setValue(value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#pragma once | ||
#include "View.h" | ||
|
||
namespace Engine | ||
{ | ||
class BaseEngine; | ||
} | ||
|
||
namespace UI | ||
{ | ||
class BarView; | ||
class Hud : public View | ||
{ | ||
public: | ||
Hud(Engine::BaseEngine& engine); | ||
~Hud(); | ||
|
||
/** | ||
* Updates/draws the UI-Views | ||
* @param dt time since last frame | ||
* @param mstate mouse-state | ||
*/ | ||
void update(double dt, Engine::Input::MouseState &mstate, Render::RenderConfig &config) override; | ||
|
||
/** | ||
* @param value Value for health-bar in 0..1 range | ||
*/ | ||
void setHealth(float value); | ||
|
||
/** | ||
* @param value Value for mana-bar in 0..1 range | ||
*/ | ||
void setMana(float value); | ||
|
||
/** | ||
* @param value Value for enemy health-bar in 0..1 range | ||
*/ | ||
void setEnemyHealth(float value); | ||
protected: | ||
|
||
BarView* m_pHealthBar; | ||
BarView* m_pManaBar; | ||
BarView* m_pEnemyHealthBar; | ||
|
||
/** | ||
* Engine access, ie. for main texture allocator and VDFS-index | ||
*/ | ||
Engine::BaseEngine& m_Engine; | ||
}; | ||
} |