~ubuntu-branches/debian/stretch/opentyrian/stretch

« back to all changes in this revision

Viewing changes to src/menus.c

  • Committer: Package Import Robot
  • Author(s): Etienne Millon
  • Date: 2015-03-31 08:48:54 UTC
  • Revision ID: package-import@ubuntu.com-20150331084854-f5a4uoz7uv3vopk6
Tags: upstream-2.1.20130907+dfsg
ImportĀ upstreamĀ versionĀ 2.1.20130907+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * OpenTyrian: A modern cross-platform port of Tyrian
 
3
 * Copyright (C) 2007-2009  The OpenTyrian Development Team
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU General Public License
 
7
 * as published by the Free Software Foundation; either version 2
 
8
 * of the License, or (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
18
 */
 
19
#include "config.h"
 
20
#include "episodes.h"
 
21
#include "fonthand.h"
 
22
#include "keyboard.h"
 
23
#include "menus.h"
 
24
#include "nortsong.h"
 
25
#include "opentyr.h"
 
26
#include "palette.h"
 
27
#include "picload.h"
 
28
#include "setup.h"
 
29
#include "sprite.h"
 
30
#include "video.h"
 
31
 
 
32
char episode_name[6][31], difficulty_name[7][21], gameplay_name[GAMEPLAY_NAME_COUNT][26];
 
33
 
 
34
bool select_gameplay( void )
 
35
{
 
36
        JE_loadPic(VGAScreen, 2, false);
 
37
        JE_dString(VGAScreen, JE_fontCenter(gameplay_name[0], FONT_SHAPES), 20, gameplay_name[0], FONT_SHAPES);
 
38
 
 
39
        int gameplay = 1,
 
40
            gameplay_max = GAMEPLAY_NAME_COUNT - 1;
 
41
 
 
42
        bool fade_in = true;
 
43
        for (; ; )
 
44
        {
 
45
                for (int i = 1; i <= gameplay_max; i++)
 
46
                {
 
47
                        JE_outTextAdjust(VGAScreen, JE_fontCenter(gameplay_name[i], SMALL_FONT_SHAPES), i * 24 + 30, gameplay_name[i], 15, -4 + (i == gameplay ? 2 : 0) - (i == (GAMEPLAY_NAME_COUNT - 1) ? 4 : 0), SMALL_FONT_SHAPES, true);
 
48
                }
 
49
                JE_showVGA();
 
50
 
 
51
                if (fade_in)
 
52
                {
 
53
                        fade_palette(colors, 10, 0, 255);
 
54
                        fade_in = false;
 
55
                }
 
56
 
 
57
                JE_word temp = 0;
 
58
                JE_textMenuWait(&temp, false);
 
59
 
 
60
                if (newkey)
 
61
                {
 
62
                        switch (lastkey_sym)
 
63
                        {
 
64
                        case SDLK_UP:
 
65
                                if (--gameplay < 1)
 
66
                                        gameplay = gameplay_max;
 
67
                                JE_playSampleNum(S_CURSOR);
 
68
                                break;
 
69
                        case SDLK_DOWN:
 
70
                                if (++gameplay > gameplay_max)
 
71
                                        gameplay = 1;
 
72
                                JE_playSampleNum(S_CURSOR);
 
73
                                break;
 
74
 
 
75
                        case SDLK_RETURN:
 
76
                                if (gameplay == GAMEPLAY_NAME_COUNT - 1)
 
77
                                {
 
78
                                        JE_playSampleNum(S_SPRING);
 
79
                                        /* TODO: NETWORK */
 
80
                                        fprintf(stderr, "error: networking via menu not implemented\n");
 
81
                                        break;
 
82
                                }
 
83
                                JE_playSampleNum(S_SELECT);
 
84
                                fade_black(10);
 
85
 
 
86
                                onePlayerAction = (gameplay == 2);
 
87
                                twoPlayerMode = (gameplay == GAMEPLAY_NAME_COUNT - 2);
 
88
                                return true;
 
89
 
 
90
                        case SDLK_ESCAPE:
 
91
                                JE_playSampleNum(S_SPRING);
 
92
                                /* fading handled elsewhere
 
93
                                fade_black(10); */
 
94
 
 
95
                                return false;
 
96
 
 
97
                        default:
 
98
                                break;
 
99
                        }
 
100
                }
 
101
        }
 
102
}
 
103
 
 
104
bool select_episode( void )
 
105
{
 
106
        JE_loadPic(VGAScreen, 2, false);
 
107
        JE_dString(VGAScreen, JE_fontCenter(episode_name[0], FONT_SHAPES), 20, episode_name[0], FONT_SHAPES);
 
108
 
 
109
        int episode = 1, episode_max = EPISODE_AVAILABLE;
 
110
 
 
111
        bool fade_in = true;
 
112
        for (; ; )
 
113
        {
 
114
                for (int i = 1; i <= episode_max; i++)
 
115
                {
 
116
                        JE_outTextAdjust(VGAScreen, 20, i * 30 + 20, episode_name[i], 15, -4 + (i == episode ? 2 : 0) - (!episodeAvail[i - 1] ? 4 : 0), SMALL_FONT_SHAPES, true);
 
117
                }
 
118
                JE_showVGA();
 
119
 
 
120
                if (fade_in)
 
121
                {
 
122
                        fade_palette(colors, 10, 0, 255);
 
123
                        fade_in = false;
 
124
                }
 
125
 
 
126
                JE_word temp = 0;
 
127
                JE_textMenuWait(&temp, false);
 
128
 
 
129
                if (newkey)
 
130
                {
 
131
                        switch (lastkey_sym)
 
132
                        {
 
133
                        case SDLK_UP:
 
134
                                episode--;
 
135
                                if (episode < 1)
 
136
                                {
 
137
                                        episode = episode_max;
 
138
                                }
 
139
                                JE_playSampleNum(S_CURSOR);
 
140
                                break;
 
141
                        case SDLK_DOWN:
 
142
                                episode++;
 
143
                                if (episode > episode_max)
 
144
                                {
 
145
                                        episode = 1;
 
146
                                }
 
147
                                JE_playSampleNum(S_CURSOR);
 
148
                                break;
 
149
 
 
150
                        case SDLK_RETURN:
 
151
                                if (!episodeAvail[episode - 1])
 
152
                                {
 
153
                                        JE_playSampleNum(S_SPRING);
 
154
                                        break;
 
155
                                }
 
156
                                JE_playSampleNum(S_SELECT);
 
157
                                fade_black(10);
 
158
 
 
159
                                JE_initEpisode(episode);
 
160
                                initial_episode_num = episodeNum;
 
161
                                return true;
 
162
 
 
163
                        case SDLK_ESCAPE:
 
164
                                JE_playSampleNum(S_SPRING);
 
165
                                /* fading handled elsewhere
 
166
                                fade_black(10); */
 
167
 
 
168
                                return false;
 
169
 
 
170
                        default:
 
171
                                break;
 
172
                        }
 
173
                }
 
174
        }
 
175
}
 
176
 
 
177
bool select_difficulty( void )
 
178
{
 
179
        JE_loadPic(VGAScreen, 2, false);
 
180
        JE_dString(VGAScreen, JE_fontCenter(difficulty_name[0], FONT_SHAPES), 20, difficulty_name[0], FONT_SHAPES);
 
181
 
 
182
        difficultyLevel = 2;
 
183
        int difficulty_max = 3;
 
184
 
 
185
        bool fade_in = true;
 
186
        for (; ; )
 
187
        {
 
188
                for (int i = 1; i <= difficulty_max; i++)
 
189
                {
 
190
                        JE_outTextAdjust(VGAScreen, JE_fontCenter(difficulty_name[i], SMALL_FONT_SHAPES), i * 24 + 30, difficulty_name[i], 15, -4 + (i == difficultyLevel ? 2 : 0), SMALL_FONT_SHAPES, true);
 
191
                }
 
192
                JE_showVGA();
 
193
 
 
194
                if (fade_in)
 
195
                {
 
196
                        fade_palette(colors, 10, 0, 255);
 
197
                        fade_in = false;
 
198
                }
 
199
 
 
200
                JE_word temp = 0;
 
201
                JE_textMenuWait(&temp, false);
 
202
 
 
203
                if (SDL_GetModState() & KMOD_SHIFT)
 
204
                {
 
205
                        if ((difficulty_max < 4 && keysactive[SDLK_g]) ||
 
206
                            (difficulty_max == 4 && keysactive[SDLK_RIGHTBRACKET]))
 
207
                        {
 
208
                                difficulty_max++;
 
209
                        }
 
210
                } else if (difficulty_max == 5 && keysactive[SDLK_l] && keysactive[SDLK_o] && keysactive[SDLK_r] && keysactive[SDLK_d]) {
 
211
                        difficulty_max++;
 
212
                }
 
213
 
 
214
                if (newkey)
 
215
                {
 
216
                        switch (lastkey_sym)
 
217
                        {
 
218
                        case SDLK_UP:
 
219
                                difficultyLevel--;
 
220
                                if (difficultyLevel < 1)
 
221
                                {
 
222
                                        difficultyLevel = difficulty_max;
 
223
                                }
 
224
                                JE_playSampleNum(S_CURSOR);
 
225
                                break;
 
226
                        case SDLK_DOWN:
 
227
                                difficultyLevel++;
 
228
                                if (difficultyLevel > difficulty_max)
 
229
                                {
 
230
                                        difficultyLevel = 1;
 
231
                                }
 
232
                                JE_playSampleNum(S_CURSOR);
 
233
                                break;
 
234
 
 
235
                        case SDLK_RETURN:
 
236
                                JE_playSampleNum(S_SELECT);
 
237
                                /* fading handled elsewhere
 
238
                                fade_black(10); */
 
239
 
 
240
                                if (difficultyLevel == 6)
 
241
                                {
 
242
                                        difficultyLevel = 8;
 
243
                                } else if (difficultyLevel == 5) {
 
244
                                        difficultyLevel = 6;
 
245
                                }
 
246
                                return true;
 
247
 
 
248
                        case SDLK_ESCAPE:
 
249
                                JE_playSampleNum(S_SPRING);
 
250
                                /* fading handled elsewhere
 
251
                                fade_black(10); */
 
252
 
 
253
                                return false;
 
254
 
 
255
                        default:
 
256
                                break;
 
257
                        }
 
258
                }
 
259
        }
 
260
}
 
261