-
Notifications
You must be signed in to change notification settings - Fork 0
/
HomeScreen.cpp
76 lines (65 loc) · 1.49 KB
/
HomeScreen.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
70
71
72
73
74
75
76
#include <SFML/System/Time.hpp>
#include "Application.h"
#include "HomeScreen.h"
#include "FontManager.h"
#include "SoundManager.h"
#include "Callback.h"
HomeScreen::HomeScreen(Application * app)
: Screen(app),
Widget()
{
this->_buttonStart = new Button("Play", this);
this->_buttonExit = new Button("Exit", this);
this->_buttonExit->move(0, 200);
this->_group = new FocusableGroup(this);
this->_group->addItem(this->_buttonStart);
this->_group->addItem(this->_buttonExit);
this->_group->activate(0);
this->_group->setFocus(true);
this->_buttonExit->bind(Widget::Event::Submit, new Callback<HomeScreen>(this, &HomeScreen::exit));
}
void HomeScreen::show()
{
SoundManager::get()->music("night").setLoop(true);
SoundManager::get()->music("night").play();
}
void HomeScreen::hide()
{
SoundManager::get()->music("night").stop();
}
/*void HomeScreen::handleEvent(const sf::Event & event)
{
if (event.type == sf::Event::Closed)
{
this->exit();
}
else if (event.type == sf::Event::KeyPressed)
{
switch (event.key.code)
{
case sf::Keyboard::Down:
this->_group->next();
break;
case sf::Keyboard::Up:
this->_group->prev();
break;
case sf::Keyboard::Right:
this->_buttonExit->emit("activate");
break;
}
}
}*/
void HomeScreen::render(sf::RenderTarget & target)
{
target.clear(sf::Color::White);
target.draw(*this->_buttonStart);
target.draw(*this->_buttonExit);
}
const string HomeScreen::name()
{
return "HomeScreen";
}
void HomeScreen::exit()
{
this->_app->close();
}