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 "VictoryState.h"
20 #include <sstream>
21 #include "../Engine/Game.h"
22 #include "../Resource/ResourcePack.h"
23 #include "../Engine/Language.h"
24 #include "../Engine/Palette.h"
25 #include "../Interface/Text.h"
26 #include "../Engine/InteractiveSurface.h"
27 #include "../Savegame/SavedGame.h"
28 #include "../Menu/MainMenuState.h"
29 #include "../Engine/Music.h"
30 #include "../Engine/Timer.h"
31 #include "../Engine/CrossPlatform.h"
32 #include "../Engine/Options.h"
33 #include "../Engine/Screen.h"
34 
35 namespace OpenXcom
36 {
37 
38 /**
39  * Initializes all the elements in the Victory screen.
40  * @param game Pointer to the core game.
41  */
VictoryState(Game * game)42 VictoryState::VictoryState(Game *game) : State(game), _screen(-1)
43 {
44 	Options::baseXResolution = Screen::ORIGINAL_WIDTH;
45 	Options::baseYResolution = Screen::ORIGINAL_HEIGHT;
46 	game->getScreen()->resetDisplay(false);
47 	const char *files[] = {"PICT1.LBM", "PICT2.LBM", "PICT3.LBM", "PICT6.LBM", "PICT7.LBM"};
48 
49 	_timer = new Timer(30000);
50 
51 	_text[0] = new Text(195, 56, 5, 0);
52 	_text[1] = new Text(232, 64, 88, 136);
53 	_text[2] = new Text(254, 48, 66, 152);
54 	_text[3] = new Text(300, 200, 5, 0);
55 	_text[4] = new Text(310, 42, 5, 158);
56 
57 	for (int i = 0; i < SCREENS; ++i)
58 	{
59 		Surface *screen = _game->getResourcePack()->getSurface(files[i]);
60 		_bg[i] = new InteractiveSurface(320, 200, 0, 0);
61 
62 		setPalette(screen->getPalette());
63 
64 		add(_bg[i]);
65 		add(_text[i]);
66 
67 		screen->blit(_bg[i]);
68 		_bg[i]->setVisible(false);
69 		_bg[i]->onMouseClick((ActionHandler)&VictoryState::screenClick);
70 
71 		std::ostringstream ss;
72 		ss << "STR_VICTORY_" << i + 1;
73 		_text[i]->setText(tr(ss.str()));
74 		_text[i]->setColor(Palette::blockOffset(15)+9);
75 		_text[i]->setWordWrap(true);
76 		_text[i]->setVisible(false);
77 	}
78 
79 	_game->getResourcePack()->playMusic("GMWIN");
80 
81 	centerAllSurfaces();
82 
83 	_timer->onTimer((StateHandler)&VictoryState::screenClick);
84 	_timer->start();
85 
86 	screenClick(0);
87 
88 	// Ironman is over
89 	if (_game->getSavedGame()->isIronman())
90 	{
91 		std::string filename = CrossPlatform::sanitizeFilename(Language::wstrToFs(_game->getSavedGame()->getName())) + ".sav";
92 		CrossPlatform::deleteFile(Options::getUserFolder() + filename);
93 	}
94 }
95 
96 /**
97  *
98  */
~VictoryState()99 VictoryState::~VictoryState()
100 {
101 	delete _timer;
102 }
103 
104 /**
105  * Handle timers.
106  */
think()107 void VictoryState::think()
108 {
109 	_timer->think(this, 0);
110 }
111 
112 /**
113  * Shows the next screen in the slideshow
114  * or goes back to the Main Menu.
115  * @param action Pointer to an action.
116  */
screenClick(Action *)117 void VictoryState::screenClick(Action *)
118 {
119 	if (_screen >= 0)
120 	{
121 		_bg[_screen]->setVisible(false);
122 		_text[_screen]->setVisible(false);
123 	}
124 
125 	++_screen;
126 
127 	// next screen
128 	if (_screen < SCREENS)
129 	{
130 		setPalette(_bg[_screen]->getPalette());
131 		_bg[_screen]->setVisible(true);
132 		_text[_screen]->setVisible(true);
133 		init();
134 	}
135 	// quit game
136 	else
137 	{
138 		_game->popState();
139 		Screen::updateScale(Options::geoscapeScale, Options::geoscapeScale, Options::baseXGeoscape, Options::baseYGeoscape, true);
140 		_game->getScreen()->resetDisplay(false);
141 		_game->setState(new MainMenuState(_game));
142 		_game->setSavedGame(0);
143 	}
144 }
145 
146 }
147