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 "DeleteGameState.h"
20 #include "../Engine/CrossPlatform.h"
21 #include "../Engine/Game.h"
22 #include "../Engine/Language.h"
23 #include "../Engine/Palette.h"
24 #include "../Interface/Text.h"
25 #include "../Interface/Window.h"
26 #include "../Interface/TextButton.h"
27 #include "../Resource/ResourcePack.h"
28 #include "ListGamesState.h"
29 #include "../Engine/Options.h"
30 #include "../Engine/Exception.h"
31 #include "ErrorMessageState.h"
32 
33 namespace OpenXcom
34 {
35 
36 /**
37  * Initializes all the elements in the Confirmation screen.
38  * @param game Pointer to the core game.
39  * @param origin Game section that originated this state.
40  * @param save Name of the save file to delete.
41  */
DeleteGameState(Game * game,OptionsOrigin origin,const std::string & save)42 DeleteGameState::DeleteGameState(Game *game, OptionsOrigin origin, const std::string &save) : State(game), _origin(origin)
43 {
44 	_filename = Options::getUserFolder() + save;
45 	_screen = false;
46 
47 	// Create objects
48 	_window = new Window(this, 256, 100, 32, 50, POPUP_BOTH);
49 	_btnYes = new TextButton(60, 18, 60, 122);
50 	_btnNo = new TextButton(60, 18, 200, 122);
51 	_txtMessage = new Text(246, 32, 37, 70);
52 
53 	// Set palette
54 	if (_origin == OPT_BATTLESCAPE)
55 	{
56 		setPalette("PAL_BATTLESCAPE");
57 	}
58 	else
59 	{
60 		setPalette("PAL_GEOSCAPE", 6);
61 	}
62 
63 	add(_window);
64 	add(_btnYes);
65 	add(_btnNo);
66 	add(_txtMessage);
67 
68 	centerAllSurfaces();
69 
70 	// Set up objects
71 	_window->setColor(Palette::blockOffset(8)+10);
72 	_window->setBackground(game->getResourcePack()->getSurface("BACK01.SCR"));
73 
74 	_btnYes->setColor(Palette::blockOffset(8)+10);
75 	_btnYes->setText(tr("STR_YES"));
76 	_btnYes->onMouseClick((ActionHandler)&DeleteGameState::btnYesClick);
77 	_btnYes->onKeyboardPress((ActionHandler)&DeleteGameState::btnYesClick, Options::keyOk);
78 
79 	_btnNo->setColor(Palette::blockOffset(8)+10);
80 	_btnNo->setText(tr("STR_NO"));
81 	_btnNo->onMouseClick((ActionHandler)&DeleteGameState::btnNoClick);
82 	_btnNo->onKeyboardPress((ActionHandler)&DeleteGameState::btnNoClick, Options::keyCancel);
83 
84 	_txtMessage->setColor(Palette::blockOffset(8)+10);
85 	_txtMessage->setAlign(ALIGN_CENTER);
86 	_txtMessage->setBig();
87 	_txtMessage->setWordWrap(true);
88 	_txtMessage->setText(tr("STR_IS_IT_OK_TO_DELETE_THE_SAVED_GAME"));
89 
90 	if (_origin == OPT_BATTLESCAPE)
91 	{
92 		applyBattlescapeTheme();
93 	}
94 }
95 
96 /**
97  *
98  */
~DeleteGameState()99 DeleteGameState::~DeleteGameState()
100 {
101 
102 }
103 
btnNoClick(Action *)104 void DeleteGameState::btnNoClick(Action *)
105 {
106 	_game->popState();
107 }
108 
btnYesClick(Action *)109 void DeleteGameState::btnYesClick(Action *)
110 {
111 	_game->popState();
112 	if (!CrossPlatform::deleteFile(_filename))
113 	{
114 		std::wstring error = tr("STR_DELETE_UNSUCCESSFUL");
115 		if (_origin != OPT_BATTLESCAPE)
116 			_game->pushState(new ErrorMessageState(_game, error, _palette, Palette::blockOffset(8)+10, "BACK01.SCR", 6));
117 		else
118 			_game->pushState(new ErrorMessageState(_game, error, _palette, Palette::blockOffset(0), "TAC00.SCR", -1));
119 	}
120 }
121 
122 }
123