-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenuScene.cpp
More file actions
219 lines (184 loc) · 6.75 KB
/
Copy pathmenuScene.cpp
File metadata and controls
219 lines (184 loc) · 6.75 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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#include "menuScene.h"
namespace gamecore {
MenuScene::MenuScene(sf::RenderWindow* window)
: Scene(window)
{
}
void MenuScene::MainLoop()
{
sf::Vector2f pos;
while (window_->isOpen() && exitCode_ == ExitSceneCode::None)
{
sf::Event event;
while (window_->pollEvent(event))
{
switch (event.type)
{
case sf::Event::Closed:
window_->close();
exitCode_ = ExitSceneCode::CloseWindow;
break;
case sf::Event::MouseMoved:
pos = window_->mapPixelToCoords({ event.mouseMove.x, event.mouseMove.y });
eventsMouseMoved_(sf::Event::MouseMoveEvent{ (int)pos.x, (int)pos.y });
break;
case sf::Event::MouseButtonPressed:
pos = window_->mapPixelToCoords({ event.mouseButton.x, event.mouseButton.y });
eventsMouseDown_({ event.mouseButton.button, (int)pos.x, (int)pos.y }, this);
break;
}
}
window_->clear();
Draw();
window_->display();
}
}
void MenuScene::Initialization()
{
sf::Vector2f size = window_->getDefaultView().getSize();
ruleView_.reset(sf::FloatRect(centerRule_, size));
settingsView_.reset(sf::FloatRect(centerSettings_, size));
AddTexture("img/back_ground.jpg"s, (int)Texture::BackGround);
Scene::CreateGUInterface<GUiSprite>(0, false, GetTexture((int)Texture::BackGround));
sf::Vector2f center = size / 2.f;
AddFont("img/Wander Over Yonder Regular.ttf"s, (int)Font::Message);
{
auto* msg = CreateGUInterface<GUiLabel>
(1, false, Events::MouseDown | Events::MouseMoved, GetFont((int)Font::Message), (int)MenuItem::NewGame);
msg->SetString(L"Íîâàÿ èãðà");
msg->SetCharacterSize(70);
msg->SetFillColor(ColorStyle.base);
sf::FloatRect msgRect = msg->GetText().getGlobalBounds();
msg->SetPosition({ center.x - msgRect.width / 2.f, center.y - 200 });
}
{
auto* msg = CreateGUInterface<GUiLabel>
(1, false, Events::MouseDown | Events::MouseMoved, GetFont((int)Font::Message), (int)MenuItem::Settings);
msg->SetString(L"Íàñòðîéêè");
msg->SetCharacterSize(70);
msg->SetFillColor(ColorStyle.base);
sf::FloatRect msgRect = msg->GetText().getGlobalBounds();
msg->SetPosition({ center.x - msgRect.width / 2u, center.y - 100});
}
{
auto* msg = CreateGUInterface<GUiLabel>
(1, false, Events::MouseDown | Events::MouseMoved, GetFont((int)Font::Message), (int)MenuItem::Rule);
msg->SetString(L"Ïðàâèëà èãðû");
msg->SetCharacterSize(70);
msg->SetFillColor(ColorStyle.base);
sf::FloatRect msgRect = msg->GetText().getGlobalBounds();
msg->SetPosition({ center.x - msgRect.width / 2u, center.y });
}
// Äîáàâëÿåì îïèñàíèå ïðàâèë
{
auto* rule = CreateGUInterface<GUiLabel>
(1, false, Events::MouseDown, GetFont((int)Font::Message), (int)MenuItem::GoMenu);
rule->SetString(ruleText);
rule->SetCharacterSize(37);
rule->SetFillColor(ColorStyle.base);
sf::FloatRect msgRect = rule->GetText().getGlobalBounds();
rule->SetPosition(centerRule_ +sf::Vector2f({ 50, 20 }));
}
// Äîáàâëÿåì îïèñàíèå íàñòðîåê
center = settingsView_.getCenter();
{
auto* settingText = Scene::CreateGUInterface<GUiText>(1, false, GetFont((int)Font::Message), -1);
settingText->SetString(L"Âûáåðèòå óðîâåíü ñëîæíîñòè");
settingText->SetCharacterSize(70);
settingText->SetFillColor(ColorStyle.highlighting);
sf::FloatRect msgRect = settingText->GetText().getGlobalBounds();
settingText->SetPosition(sf::Vector2f({ center.x - msgRect.width / 2, center.y - 350 }));
}
{
auto* msg = CreateGUInterface<GUiLabel>
(1, false, Events::MouseDown | Events::MouseMoved, GetFont((int)Font::Message), (int)MenuItem::Easy);
msg->SetString(L"Ëåãêî");
msg->SetCharacterSize(60);
msg->SetFillColor(ColorStyle.base);
sf::FloatRect msgRect = msg->GetText().getGlobalBounds();
msg->SetPosition(sf::Vector2f({ center.x - 400, center.y - 200 }));
}
{
auto* msg = CreateGUInterface<GUiLabel>
(1, false, Events::MouseDown | Events::MouseMoved, GetFont((int)Font::Message), (int)MenuItem::Normal);
msg->SetString(L"Íîðìàëüíî");
msg->SetCharacterSize(60);
msg->SetFillColor(ColorStyle.base);
sf::FloatRect msgRect = msg->GetText().getGlobalBounds();
msg->SetPosition(sf::Vector2f({ center.x - 400, center.y - 100}));
}
{
auto* msg = CreateGUInterface<GUiLabel>
(1, false, Events::MouseDown | Events::MouseMoved, GetFont((int)Font::Message), (int)MenuItem::Hard);
msg->SetString(L"Ñëîæíî");
msg->SetCharacterSize(60);
msg->SetFillColor(ColorStyle.base);
sf::FloatRect msgRect = msg->GetText().getGlobalBounds();
msg->SetPosition(sf::Vector2f({ center.x - 400, center.y }));
}
// Îïèñàíèå óðîâíåé ñëîæíîñòè
{
auto* settingText = Scene::CreateGUInterface<GUiText>(1, false, GetFont((int)Font::Message), -1);
settingText->SetString(LR"(Ïîçèöèÿ èíäèðàòîðà ñîîòâåòñòâóåò ïîçèöèè â êîäå,
öâåòà íå ïîâòîðÿþòñÿ.)");
settingText->SetCharacterSize(30);
settingText->SetFillColor(ColorStyle.base);
sf::FloatRect msgRect = settingText->GetText().getGlobalBounds();
settingText->SetPosition(sf::Vector2f({ center.x - 50, center.y - 200 }));
}
{
auto* settingText = Scene::CreateGUInterface<GUiText>(1, false, GetFont((int)Font::Message), -1);
settingText->SetString(LR"(Èíäèêàòîðû íå ïðèâÿçàíû ê ïîçèöèÿì â êîäå,
öâåòà íå ïîâòîðÿþòñÿ.)");
settingText->SetCharacterSize(30);
settingText->SetFillColor(ColorStyle.base);
sf::FloatRect msgRect = settingText->GetText().getGlobalBounds();
settingText->SetPosition(sf::Vector2f({ center.x - 50, center.y - 100 }));
}
{
auto* settingText = Scene::CreateGUInterface<GUiText>(1, false, GetFont((int)Font::Message), -1);
settingText->SetString(LR"(Èíäèêàòîðû íå ïðèâÿçàíû ê ïîçèöèÿì â êîäå,
öâåòà â êîäå ìîãóò ïîâòîðÿòüñÿ.)");
settingText->SetCharacterSize(30);
settingText->SetFillColor(ColorStyle.base);
sf::FloatRect msgRect = settingText->GetText().getGlobalBounds();
settingText->SetPosition(sf::Vector2f({ center.x - 50, center.y }));
}
}
MenuScene::Difficulty MenuScene::GetDifficulty()
{
return difficulty_;
}
void MenuScene::MousePushCallBack(const int labelId)
{
switch (static_cast<MenuItem>(labelId))
{
case MenuItem::NewGame:
exitCode_ = ExitSceneCode::NewScene;
break;
case MenuItem::Rule:
window_->setView(ruleView_);
break;
case MenuItem::Settings:
window_->setView(settingsView_);
break;
case MenuItem::GoMenu:
window_->setView(window_->getDefaultView());
break;
case MenuItem::Easy:
window_->setView(window_->getDefaultView());
difficulty_ = Difficulty::Easy;
break;
case MenuItem::Normal:
window_->setView(window_->getDefaultView());
difficulty_ = Difficulty::Normal;
break;
case MenuItem::Hard:
window_->setView(window_->getDefaultView());
difficulty_ = Difficulty::Hard;
break;
default:
break;
}
}
} // namespace gamecore