-
Notifications
You must be signed in to change notification settings - Fork 0
/
menuview.cpp
69 lines (59 loc) · 1.78 KB
/
menuview.cpp
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "menuview.hpp"
#include "gameview.hpp"
#include "endview.hpp"
#include "storyview.hpp"
MenuView::MenuView(GameModel* model)
: stf::smv::IView(model),
m_logo(stf::SpriteFromBMP("sprs/logo.bmp")),
m_smenu(stf::Sprite("sprs/pause_menu.spr"))
{
m_menuItemsCount = m_smenu.markers().size() / 2;
}
void MenuView::show(stf::Renderer& renderer)
{
IView::show(renderer);
stf::Vec2d pzero = renderer.Size / 2 - m_smenu.Size() / 2;
m_logo.show(renderer, true, {0,0}, {0, -m_logo.Size().y - 2});
m_smenu.show(renderer, true);
renderer.drawPixel(pzero + m_smenu.markers().at(m_cursor * 2), '>');
renderer.drawPixel(pzero + m_smenu.markers().at(m_cursor * 2 + 1), '<');
}
stf::smv::IView* MenuView::keyEventsHandler(const int key)
{
switch(key)
{
case 'w':
if(m_cursor > 0)
--m_cursor;
else if(m_cursor == 0)
m_cursor = m_menuItemsCount - 1;
break;;
case 's':
if(m_cursor < m_menuItemsCount - 1)
++m_cursor;
else if(m_cursor == m_menuItemsCount - 1)
m_cursor = 0;
break;
case ' ': return menuSelectConfirm();
}
return this;
}
stf::smv::IView* MenuView::menuSelectConfirm()
{
switch(m_cursor)
{
case 0:
return new GameView(static_cast<GameModel*>(m_model), true);
case 1:
try { static_cast<GameModel*>(m_model)->saves.load();
return new GameView(static_cast<GameModel*>(m_model));
} catch(...) { }
break;
case 2:
return new StoryView(static_cast<GameModel*>(m_model));
case 3:
try { static_cast<GameModel*>(m_model)->saves.save(); } catch(...) { }
return new CloseView(static_cast<GameModel*>(m_model));
}
return this;
}