Repository navigation
Expand file tree
/
Copy pathStartState.cpp
More file actions
152 lines (139 loc) · 3.68 KB
/
Copy pathStartState.cpp
File metadata and controls
152 lines (139 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
* Copyright 2010-2012 OpenXcom Developers.
*
* This file is part of OpenXcom.
*
* OpenXcom is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenXcom is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
*/
#include "StartState.h"
#include <SDL.h>
#include "../Engine/Game.h"
#include "../Engine/Action.h"
#include "../Resource/XcomResourcePack.h"
#include "../Ruleset/XcomRuleset.h"
#include "../Engine/Surface.h"
#include "../Engine/Exception.h"
#include "../Engine/Options.h"
#include "../Engine/Language.h"
#include "TestState.h"
#include "NoteState.h"
#include "LanguageState.h"
#include "MainMenuState.h"
namespace OpenXcom
{
/**
* Initializes all the elements in the Loading screen.
* @param game Pointer to the core game.
*/
StartState::StartState(Game *game) : State(game), _load(LOADING_NONE)
{
// Create objects
_surface = new Surface(320, 200, 0, 0);
// Set palette
SDL_Color bnw[2];
bnw[0].r = 0;
bnw[0].g = 0;
bnw[0].b = 0;
bnw[1].r = 255;
bnw[1].g = 255;
bnw[1].b = 255;
_game->setPalette(bnw, 0, 2);
add(_surface);
// Set up objects
_surface->drawString(120, 96, "Loading...", 1);
}
/**
*
*/
StartState::~StartState()
{
}
/**
* Waits a cycle to load the resources so the screen is blitted first.
* If the loading fails, it shows an error, otherwise moves on to the game.
*/
void StartState::think()
{
State::think();
switch (_load)
{
case LOADING_STARTED:
try
{
std::cout << "Loading resources..." << std::endl;
_game->setResourcePack(new XcomResourcePack());
std::cout << "Resources loaded successfully." << std::endl;
std::cout << "Loading ruleset..." << std::endl;
_game->setRuleset(new XcomRuleset());
std::cout << "Ruleset loaded successfully." << std::endl;
std::vector<std::string> langs = Language::getList(0);
if (langs.empty())
{
throw Exception("No languages available");
}
_load = LOADING_SUCCESSFUL;
}
catch (Exception &e)
{
_load = LOADING_FAILED;
_surface->clear();
_surface->drawString(0, 0, "ERROR:", 1);
_surface->drawString(0, 8, e.what(), 1);
_surface->drawString(0, 32, "Can't find a required X-Com data file.", 1);
_surface->drawString(0, 40, "Make sure you installed OpenXcom", 1);
_surface->drawString(0, 48, "correctly.", 1);
_surface->drawString(0, 72, "Check the README for more details.", 1);
_surface->drawString(76, 192, "Press any key to quit", 1);
}
break;
case LOADING_NONE:
_load = LOADING_STARTED;
break;
case LOADING_SUCCESSFUL:
std::cout << std::endl << "OpenXcom started successfully. Enjoy!" << std::endl;
if (Options::getString("language") == "" || Options::getString("language") == "~")
{
_game->setState(new NoteState(_game));
}
else
{
try
{
_game->loadLanguage(Options::getString("language"));
_game->setState(new MainMenuState(_game));
}
catch (Exception e)
{
_game->setState(new LanguageState(_game));
}
}
break;
default:
break;
}
}
/**
* The game quits if the player presses any key when an error
* message is on display.
* @param action Pointer to an action.
*/
void StartState::handle(Action *action)
{
if (_load == LOADING_FAILED)
{
if (action->getDetails()->type == SDL_KEYDOWN)
_game->quit();
}
}
}