1 /*
2 * Copyright 2010-2014 OpenXcom Developers.
3 *
4 * This file is part of OpenXcom.
5 *
6 * OpenXcom is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * OpenXcom is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #include <sstream>
20 #include "PsiTrainingState.h"
21 #include "../Engine/Game.h"
22 #include "../Engine/Screen.h"
23 #include "../Engine/Action.h"
24 #include "../Resource/ResourcePack.h"
25 #include "../Engine/Language.h"
26 #include "../Engine/Palette.h"
27 #include "../Interface/TextButton.h"
28 #include "../Interface/Window.h"
29 #include "../Interface/Text.h"
30 #include "../Savegame/SavedGame.h"
31 #include "../Savegame/Base.h"
32 #include "GeoscapeState.h"
33 #include "AllocatePsiTrainingState.h"
34 #include "../Engine/Options.h"
35
36 namespace OpenXcom
37 {
38
39 /**
40 * Initializes all the elements in the Psi Training screen.
41 * @param game Pointer to the core game.
42 */
PsiTrainingState(Game * game)43 PsiTrainingState::PsiTrainingState(Game *game) : State(game)
44 {
45 // Create objects
46 _window = new Window(this, 320, 200, 0, 0);
47 _txtTitle = new Text(300, 17, 10, 16);
48 _btnOk = new TextButton(160, 14, 80, 174);
49
50 // Set palette
51 setPalette("PAL_BASESCAPE", 7);
52
53 add(_window);
54 add(_btnOk);
55 add(_txtTitle);
56
57 // Set up objects
58 _window->setColor(Palette::blockOffset(15)+6);
59 _window->setBackground(_game->getResourcePack()->getSurface("BACK01.SCR"));
60
61 _btnOk->setColor(Palette::blockOffset(13)+10);
62 _btnOk->setText(tr("STR_OK"));
63 _btnOk->onMouseClick((ActionHandler)&PsiTrainingState::btnOkClick);
64 _btnOk->onKeyboardPress((ActionHandler)&PsiTrainingState::btnOkClick, Options::keyCancel);
65
66 _txtTitle->setColor(Palette::blockOffset(13)+10);
67 _txtTitle->setBig();
68 _txtTitle->setAlign(ALIGN_CENTER);
69 _txtTitle->setText(tr("STR_PSIONIC_TRAINING"));
70
71 int buttons = 0;
72 for(std::vector<Base*>::const_iterator b = _game->getSavedGame()->getBases()->begin(); b != _game->getSavedGame()->getBases()->end(); ++b)
73 {
74 if((*b)->getAvailablePsiLabs())
75 {
76 TextButton *btnBase = new TextButton(160, 14, 80, 40 + 16 * buttons);
77 btnBase->setColor(Palette::blockOffset(15) + 6);
78 btnBase->onMouseClick((ActionHandler)&PsiTrainingState::btnBaseXClick);
79 btnBase->setText((*b)->getName());
80 add(btnBase);
81 _bases.push_back(*b);
82 _btnBases.push_back(btnBase);
83 ++buttons;
84 if (buttons >= 8)
85 {
86 break;
87 }
88 }
89 }
90
91 centerAllSurfaces();
92 }
93 /**
94 *
95 */
~PsiTrainingState()96 PsiTrainingState::~PsiTrainingState()
97 {
98
99 }
100
101 /**
102 * Returns to the previous screen.
103 * @param action Pointer to an action.
104 */
btnOkClick(Action *)105 void PsiTrainingState::btnOkClick(Action *)
106 {
107 _game->popState();
108 }
109
110 /**
111 * Goes to the allocation screen for the corresponding base.
112 * @param action Pointer to an action.
113 */
btnBaseXClick(Action * action)114 void PsiTrainingState::btnBaseXClick(Action *action)
115 {
116 for (size_t i = 0; i < _btnBases.size(); ++i)
117 {
118 if (action->getSender() == _btnBases[i])
119 {
120 _game->pushState(new AllocatePsiTrainingState(_game, _bases.at(i)));
121 break;
122 }
123 }
124 }
125
126 }
127