-
Notifications
You must be signed in to change notification settings - Fork 2
/
regist.cpp
215 lines (183 loc) · 6.3 KB
/
regist.cpp
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/* --------------------------------------------------------------------
EXTREME TUXRACER
Copyright (C) 1999-2001 Jasmin F. Patry (Tuxracer)
Copyright (C) 2010 Extreme Tuxracer Team
This program 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 2
of the License, or (at your option) any later version.
This program 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.
---------------------------------------------------------------------*/
#include "regist.h"
#include "ogl.h"
#include "textures.h"
#include "audio.h"
#include "gui.h"
#include "course.h"
#include "tux.h"
#include "env.h"
#include "particles.h"
#include "credits.h"
#include "font.h"
#include "game_ctrl.h"
#include "translation.h"
static TVector2 cursor_pos = {0, 0};
static int curr_focus = 0;
static TCharacter *CharList;
static int curr_character = 0;
static int last_character;
//static int xleft, ytop;
static int curr_player = 0;
static int last_player;
static int old_last;
void QuitRegistration () {
Players.ResetControls ();
Players.AllocControl (curr_player);
g_game.player_id = curr_player;
g_game.char_id = curr_character;
Winsys.SetMode (GAME_TYPE_SELECT);
}
void ChangeRegistSelection (int focus, int dir) {
if (dir == 0) {
switch (focus) {
case 0: if (curr_player > 0) curr_player--; break;
case 1: if (curr_character > 0) curr_character--; break;
}
} else {
switch (focus) {
case 0: if (curr_player < last_player) curr_player++; break;
case 1: if (curr_character < last_character) curr_character++; break;
}
}
}
void RegistKeys (unsigned int key, bool special, bool release, int x, int y) {
if (release) return;
switch (key) {
case SDLK_ESCAPE: Winsys.Quit (); break;
case SDLK_RETURN:
if (curr_focus == 3) {
old_last = last_player;
Winsys.SetMode (NEWPLAYER);
} else QuitRegistration (); break;
case SDLK_TAB:
curr_focus++;
if (curr_focus > 3) curr_focus = 0;
break;
case SDLK_DOWN: ChangeRegistSelection (curr_focus, 1); break;
case SDLK_UP: ChangeRegistSelection (curr_focus, 0); break;
}
}
void RegistMouseFunc (int button, int state, int x, int y) {
int foc, dir;
if (state == 1) {
GetFocus (x, y, &foc, &dir);
switch (foc) {
case 0: ChangeRegistSelection (foc, dir); break;
case 1: ChangeRegistSelection (foc, dir); break;
case 2: QuitRegistration (); break;
case 3: old_last = last_player; Winsys.SetMode (NEWPLAYER); break;
}
}
}
void RegistMotionFunc (int x, int y ){
TVector2 old_pos;
int sc, dir;
if (Winsys.ModePending ()) return;
GetFocus (x, y, &sc, &dir);
if (sc >= 0) curr_focus = sc;
y = param.y_resolution - y;
old_pos = cursor_pos;
cursor_pos = MakeVector2 (x, y);
if (old_pos.x != x || old_pos.y != y) {
if (param.ui_snow) push_ui_snow (cursor_pos);
}
}
static int framewidth, frameheight, arrowwidth, sumwidth;
static TArea area;
static double scale, texsize;
void RegistInit (void) {
Winsys.ShowCursor (!param.ice_cursor);
init_ui_snow ();
Music.Play (param.menu_music, -1);
scale = param.scale;
framewidth = (int)(scale * 280);
frameheight = (int)(scale * 50);
arrowwidth = 50;
sumwidth = framewidth * 2 + arrowwidth * 2;
area = AutoAreaN (30, 80, sumwidth);
texsize = 128 * scale;
ResetWidgets ();
AddArrow (area.left + framewidth + 8, area.top, 0, 0);
AddArrow (area.left + framewidth + 8, area.top + 18, 1, 0);
AddArrow (area.left + framewidth * 2 + arrowwidth + 8, area.top, 0, 1);
AddArrow (area.left + framewidth * 2 + arrowwidth + 8, area.top + 18, 1, 1);
int siz = FT.AutoSizeN (5);
AddTextButton ("Enter", CENTER, AutoYPosN (62), 2, siz);
AddTextButton ("Register a new player", CENTER, AutoYPosN (70), 3, siz);
curr_focus = 0;
g_game.loopdelay = 10;
CharList = Char.CharList;
last_character = Char.numCharacters - 1;
last_player = Players.numPlayers - 1;
if (g_game.prev_mode == NEWPLAYER && old_last != last_player) {
curr_player = last_player;
} else curr_player = g_game.start_player;
}
void RegistLoop (double timestep ){
int ww = param.x_resolution;
int hh = param.y_resolution;
Music.Update ();
check_gl_error();
ClearRenderContext ();
set_gl_options (GUI);
SetupGuiDisplay ();
TColor col;
update_ui_snow (timestep);
draw_ui_snow();
Tex.Draw (BOTTOM_LEFT, 0, hh - 256, 1);
Tex.Draw (BOTTOM_RIGHT, ww-256, hh-256, 1);
Tex.Draw (TOP_LEFT, 0, 0, 1);
Tex.Draw (TOP_RIGHT, ww-256, 0, 1);
Tex.Draw (T_TITLE_SMALL, CENTER, AutoYPosN (5), scale);
// DrawFrameX (area.left, area.top, area.right-area.left, area.bottom - area.top,
// 0, colMBackgr, col, 0.2);
FT.AutoSizeN (3);
FT.SetColor (colWhite);
int top = AutoYPosN (24);
FT.DrawString (area.left, top, "Select your player name:");
FT.DrawString (area.left + framewidth + arrowwidth, top, "Select a character:");
FT.AutoSizeN (4);
if (curr_focus == 0) col = colDYell; else col = colWhite;
DrawFrameX (area.left, area.top, framewidth, frameheight, 3, colMBackgr, col, 1.0);
FT.SetColor (col);
FT.DrawString (area.left + 20, area.top, Players.GetName (curr_player));
Tex.DrawDirectFrame (Players.GetAvatarID (curr_player),
area.left + 60, AutoYPosN (40), texsize, texsize, 3, colWhite);
if (curr_focus == 1) col = colDYell; else col = colWhite;
DrawFrameX (area.left + framewidth + arrowwidth, area.top,
framewidth, frameheight, 3, colMBackgr, col, 1.0);
FT.SetColor (col);
FT.DrawString (area.left + framewidth + arrowwidth + 20,
area.top, CharList[curr_character].name);
Tex.DrawDirectFrame (CharList[curr_character].preview,
area.right - texsize - 60 - arrowwidth,
AutoYPosN (40), texsize, texsize, 3, colWhite);
FT.SetColor (colWhite);
PrintArrow (0, (curr_player > 0));
PrintArrow (1, (curr_player < last_player));
PrintArrow (2, (curr_character > 0));
PrintArrow (3, (curr_character < last_character));
PrintTextButton (0, curr_focus);
PrintTextButton (1, curr_focus);
if (param.ice_cursor) DrawCursor ();
Winsys.SwapBuffers();
}
void RegistTerm () {
}
void regist_register() {
Winsys.SetModeFuncs (REGIST, RegistInit, RegistLoop, RegistTerm,
RegistKeys, RegistMouseFunc, RegistMotionFunc, NULL, NULL, NULL);
}