Debian Codegraph @

src/game/menu/confirmationmenu.cpp

raw symbols SCIP
1 // This file is part of Dust Racing 2D.
2 // Copyright (C) 2012 Jussi Lind <[email protected]>
3 //
4 // Dust Racing 2D is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 // Dust Racing 2D is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Dust Racing 2D. If not, see <http://www.gnu.org/licenses/>.
15
16 #include "confirmationmenu.hpp"
17 #include "game.hpp"
18 #include "textmenuitemview.hpp"
19
20 #include <MenuItemView>
21 #include <MenuManager>
22
23 #include <MCAssetManager>
24 #include <MCTextureFont>
25 #include <MCTextureText>
26
27 #include <QObject>
28
29 ConfirmationMenu::ConfirmationMenu(std::string id, int width, int height)
30 : SurfaceMenu("settingsBack", id, width, height, MTFH::Menu::Style::HorizontalList, false)
31 , m_acceptItem(std::make_shared<MTFH::MenuItem>(width / 4, height, QObject::tr("Ok").toStdWString()))
32 , m_cancelItem(std::make_shared<MTFH::MenuItem>(width / 4, height, QObject::tr("Cancel").toStdWString()))
33 , m_text(L"")
34 {
35 m_acceptItem->setView(std::make_shared<TextMenuItemView>(20, *m_acceptItem));
36 m_cancelItem->setView(std::make_shared<TextMenuItemView>(20, *m_cancelItem));
37
38 addItem(m_acceptItem);
39 addItem(m_cancelItem);
40 }
41
42 void ConfirmationMenu::setAcceptAction(MTFH::MenuItemActionPtr action)
43 {
44 m_acceptItem->setAction(action);
45 }
46
47 void ConfirmationMenu::setAcceptAction(std::function<void()> actionFunction)
48 {
49 m_acceptItem->setAction(actionFunction);
50 }
51
52 void ConfirmationMenu::setCancelAction(MTFH::MenuItemActionPtr action)
53 {
54 m_cancelItem->setAction(action);
55 }
56
57 void ConfirmationMenu::setCancelAction(std::function<void()> actionFunction)
58 {
59 m_cancelItem->setAction(actionFunction);
60 }
61
62 void ConfirmationMenu::setText(std::wstring text)
63 {
64 m_text = text;
65 }
66
67 void ConfirmationMenu::selectCurrentItem()
68 {
69 Menu::selectCurrentItem();
70 exit();
71 }
72
73 void ConfirmationMenu::render()
74 {
75 SurfaceMenu::render();
76
77 MCTextureText text(m_text);
78 text.setColor(MCGLColor(0.25, 0.75, 1.0, 1.0));
79 text.setGlyphSize(20, 20);
80 const int shadowY = -2;
81 const int shadowX = 2;
82 text.setShadowOffset(shadowX, shadowY);
83
84 auto && font = MCAssetManager::textureFontManager().font(Game::instance().fontName());
85 text.render(x() + width() / 2 - text.width(font) / 2 + 20, y() + height() / 2 + 60, nullptr, font);
86 }