Repository navigation
Expand file tree
/
Copy pathStartState.cpp
More file actions
119 lines (107 loc) · 2.81 KB
/
Copy pathStartState.cpp
File metadata and controls
119 lines (107 loc) · 2.81 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
/*
* Copyright 2010 Daniel Albano
*
* 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 <iostream>
#include "SDL.h"
#include "SDL_gfxPrimitives.h"
#include "../Engine/Game.h"
#include "../Resource/XcomResourcePack.h"
#include "../Ruleset/XcomRuleset.h"
#include "../Engine/Surface.h"
#include "TestState.h"
#include "LanguageState.h"
#define DATA_FOLDER "./DATA/"
/**
* 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
stringColor(_surface->getSurface(), 120, 96, "Loading...", 0xFFFFFFFF);
}
/**
*
*/
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
{
_game->setResourcePack(new XcomResourcePack(DATA_FOLDER));
_game->setRuleset(new XcomRuleset());
_load = LOADING_SUCCESSFUL;
}
catch (const char* c)
{
cout << c << endl;
_load = LOADING_FAILED;
_surface->clear();
stringColor(_surface->getSurface(), 0, 0, c, 0xFFFFFFFF);
stringColor(_surface->getSurface(), 0, 16, "Make sure X-Com is in the DATA subfolder", 0xFFFFFFFF);
stringColor(_surface->getSurface(), 0, 192, "Press any key to quit", 0xFFFFFFFF);
}
break;
case LOADING_NONE:
_load = LOADING_STARTED;
break;
case LOADING_SUCCESSFUL:
//_game->setState(new TestState(_game));
_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 ev Pointer to a SDL_Event.
* @param scale Current screen scale (used to correct mouse input).
*/
void StartState::handle(SDL_Event *ev, int scale)
{
if (_load == LOADING_FAILED)
{
if (ev->type == SDL_KEYDOWN)
_game->quit();
}
}