-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstoryview.cpp
More file actions
41 lines (36 loc) · 1.44 KB
/
storyview.cpp
File metadata and controls
41 lines (36 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "storyview.hpp"
#include "gamemodel.hpp"
#include "menuview.hpp"
#include "time.hpp"
StoryView::StoryView(GameModel* model)
: IView(model),
m_logo(stf::SpriteFromBMP("sprs/logo.bmp"))
{}
void StoryView::show(Renderer& renderer)
{
const std::string s = Time(nullptr).asString() + std::string(" %s Points: '%s' | GameTime: %d:%d:%d:%d");
Vec2d zerop = renderer.Size / 2 - Vec2d(s.length()/2, 0);
m_logo.show(renderer, true, {0,0}, {0, -m_logo.Size().y - 2});
try {
stf::sdb::Model::QueryResult *qres = static_cast<GameModel*>(m_model)->results.all();
int k = 0;
for(auto it = qres->begin(); it != qres->end(); ++it) {
GameResultModel* info = qres->get<GameResultModel>(*it);
renderer.draw(zerop + stf::Vec2d(0, k++ * 2), "%s Points: '%d' | GameTime: %d:%d:%d:%d",
info->mTime().asString().c_str(),
info->mPoints(),
daysFromSeconds(info->mGameTime()),
hoursFromSeconds(info->mGameTime()),
minutesFromSeconds(info->mGameTime()),
secondsFromSeconds(info->mGameTime()));
}
} catch(const std::string& ex) {
std::string s("There are no results here yet");
Vec2d p = renderer.Size / 2 - Vec2d(s.length() / 2, 0);
renderer.drawText(p, s.c_str());
}
}
IView* StoryView::keyEventsHandler(const int)
{
return new MenuView(static_cast<GameModel*>(m_model));
}