Skip to content

Commit bd0ce4f

Browse files
committed
working on a game name screen;
1 parent 3d42c0f commit bd0ce4f

File tree

2 files changed

+78
-5
lines changed

2 files changed

+78
-5
lines changed

src/Screens/IntroScreen.cpp

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ namespace tt
1515
namespace
1616
{
1717

18-
1918
void createMenu(TextList& menuItems,
2019
const std::vector<std::string>& textlist,
2120
sf::RenderTarget& window,
@@ -177,7 +176,8 @@ IntroScreen::IntroScreen( ResourceManager& resmgr,
177176
//
178177
createMenu(_menuItems,
179178
{
180-
"Play Game",
179+
"New Game",
180+
"Load Game",
181181
"Settings",
182182
"Exit Game"
183183
}, _window, _font);
@@ -193,8 +193,27 @@ IntroScreen::IntroScreen( ResourceManager& resmgr,
193193
tt::AudioLocator::sound()->cacheAudio(TOMWILLKILL_SOUND);
194194
}
195195

196+
void IntroScreen::draw()
197+
{
198+
Screen::draw();
199+
if (_gui) _gui->draw();
200+
}
201+
196202
PollResult IntroScreen::poll(const sf::Event& e)
197203
{
204+
if (_gui)
205+
{
206+
_gui->handleEvent(e);
207+
208+
if (e.type == sf::Event::KeyReleased
209+
&& e.key.code == sf::Keyboard::Escape)
210+
{
211+
_gui.reset();
212+
}
213+
214+
return {};
215+
}
216+
198217
if (e.type == sf::Event::KeyReleased
199218
&& e.key.code == sf::Keyboard::Up)
200219
{
@@ -225,17 +244,65 @@ PollResult IntroScreen::poll(const sf::Event& e)
225244
default:
226245
break;
227246

228-
case 0: // play game
247+
case 0: // new game
229248
{
230249
return {true, { ScreenActionType::CHANGE_SCREEN, SCREEN_LOADING }};
231250
}
232251

233-
case 1: // settings
252+
case 1: // load game
253+
{
254+
_gui = std::make_unique<tgui::Gui>(_window);
255+
256+
auto windowSize = _window.getSize();
257+
auto halfWindowWidth = windowSize.x / 2;
258+
259+
auto child = tgui::ChildWindow::create();
260+
child->setClientSize({500, 200});
261+
auto xpos = (_window.getSize().x / 2) - (child->getSize().x / 2);
262+
auto ypos = (_window.getSize().y / 2) - (child->getSize().y / 2);
263+
child->setPosition(xpos, ypos);
264+
child->setTitleButtons(tgui::ChildWindow::TitleButton::None);
265+
_gui->add(child);
266+
267+
auto editLbl = tgui::Label::create("Enter name for new game");
268+
editLbl->setPosition(20,20);
269+
editLbl->setTextSize(30);
270+
child->add(editLbl);
271+
272+
auto editBox = tgui::EditBox::create();
273+
editBox->setPosition(20,75);
274+
editBox->setTextSize(30);
275+
editBox->setSize(460,35);
276+
child->add(editBox);
277+
278+
auto okBtn = tgui::Button::create("Ok");
279+
okBtn->setWidgetName("sds");
280+
okBtn->setSize(50, 45);
281+
xpos = (child->getSize().x / 2) - (okBtn->getSize().x + 20);
282+
okBtn->setPosition(xpos, 125);
283+
child->add(okBtn);
284+
285+
auto cancelBtn = tgui::Button::create("Cancel");
286+
cancelBtn->setSize(65, 45);
287+
xpos = (child->getSize().x / 2) + 20;
288+
cancelBtn->setPosition(xpos, 125);
289+
cancelBtn->onPress([=]
290+
{
291+
_gui.reset();
292+
});
293+
child->add(cancelBtn);
294+
295+
editBox->setFocused(true);
296+
297+
break;
298+
}
299+
300+
case 2: // settings
234301
{
235302
return {true, { ScreenActionType::CHANGE_SCREEN, SCREEN_SETTINGS }};
236303
}
237304

238-
case 2: // exit
305+
case 3: // exit
239306
{
240307
tt::AudioLocator::music()->stop(BACKGROUND_SONG);
241308
tt::AudioLocator::sound()->play(TOMWILLKILL_SOUND);

src/Screens/IntroScreen.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include <SFML/Audio.hpp>
44

5+
#include <TGUI/TGUI.hpp>
6+
57
#include "Screen.h"
68

79
#include "../TooterLogger.h"
@@ -21,7 +23,9 @@ class IntroScreen : public Screen
2123

2224
IntroScreen(ResourceManager& res, sf::RenderTarget& target);
2325

26+
void draw() override;
2427
PollResult poll(const sf::Event& e) override;
28+
2529
ScreenAction update() override;
2630
void close() override;
2731

@@ -39,6 +43,8 @@ class IntroScreen : public Screen
3943
std::vector<SpritePtr> _sprite;
4044

4145
sf::Clock _clock;
46+
47+
std::unique_ptr<tgui::Gui> _gui;
4248
};
4349

4450

0 commit comments

Comments
 (0)