[Add] Event history box.
This commit is contained in:
parent
112c1c5725
commit
ae81b99958
@ -211,6 +211,8 @@ void Game::Render(void) {
|
||||
_npcHealth.RenderLiteral();
|
||||
}
|
||||
|
||||
_eventHistory.Render();
|
||||
|
||||
} else {
|
||||
_ingameMenu.Render();
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "../libUnuk/System/Debug.h"
|
||||
#include "../libUnuk/UI/Text.h"
|
||||
#include "../libUnuk/UI/Bar.h"
|
||||
#include "../libUnuk/UI/EventHistory.h"
|
||||
#include "../libUnuk/Engine/MemClass.h"
|
||||
using namespace std;
|
||||
|
||||
@ -59,4 +60,6 @@ private:
|
||||
|
||||
Text _playerHealth;
|
||||
Bar _playerHealthBar;
|
||||
|
||||
EventHistory _eventHistory;
|
||||
};
|
||||
|
51
src/libUnuk/UI/EventHistory.cpp
Normal file
51
src/libUnuk/UI/EventHistory.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
#include "EventHistory.h"
|
||||
#include "../../Unuk/Constants.h"
|
||||
|
||||
const int EventHistory::BOX_WIDTH = 350;
|
||||
const int EventHistory::BOX_HEIGHT = 130;
|
||||
|
||||
EventHistory::EventHistory(void) {
|
||||
_background.SetXY(SCREEN_WIDTH/2 - BOX_WIDTH/2, 10);
|
||||
_background.SetWidthHeight(BOX_WIDTH, BOX_HEIGHT);
|
||||
_background.SetRGB(0, 0, 0);
|
||||
|
||||
_text.SetXY(_background.GetX() + 5, _background.GetY() + 5);
|
||||
|
||||
_visible = false;
|
||||
}
|
||||
|
||||
EventHistory::~EventHistory(void) {
|
||||
}
|
||||
|
||||
void EventHistory::LogEvent(const std::string& evtText) {
|
||||
_events.push_back(evtText);
|
||||
|
||||
if(_events.size() > 5) {
|
||||
_events.erase(_events.begin());
|
||||
}
|
||||
|
||||
std::string textStr;
|
||||
for(std::list<std::string>::iterator evIt = _events.begin(); evIt != _events.end(); ++evIt) {
|
||||
textStr.append(*evIt);
|
||||
textStr.append("\n");
|
||||
}
|
||||
|
||||
_text.SetTextBlended(textStr, small, 255, 255, 255);
|
||||
|
||||
_timeToVanish.Start();
|
||||
_visible = true;
|
||||
}
|
||||
|
||||
void EventHistory::Render(void) {
|
||||
if(_visible && (_timeToVanish.GetTicks() >= 2500)) {
|
||||
_timeToVanish.Stop();
|
||||
_visible = false;
|
||||
}
|
||||
|
||||
if(!_visible) {
|
||||
return;
|
||||
}
|
||||
|
||||
_background.DrawLiteral();
|
||||
_text.RenderLiteral();
|
||||
}
|
28
src/libUnuk/UI/EventHistory.h
Normal file
28
src/libUnuk/UI/EventHistory.h
Normal file
@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <list>
|
||||
|
||||
#include "Text.h"
|
||||
#include "../System/Rect.h"
|
||||
#include "../System/Timer.h"
|
||||
|
||||
class EventHistory {
|
||||
public:
|
||||
EventHistory(void);
|
||||
~EventHistory(void);
|
||||
|
||||
void LogEvent(const std::string& evtText);
|
||||
|
||||
void Render(void);
|
||||
|
||||
private:
|
||||
std::list<std::string> _events;
|
||||
Text _text;
|
||||
Rect _background;
|
||||
|
||||
Timer _timeToVanish;
|
||||
bool _visible;
|
||||
|
||||
static const int BOX_WIDTH;
|
||||
static const int BOX_HEIGHT;
|
||||
};
|
Loading…
Reference in New Issue
Block a user