-
Notifications
You must be signed in to change notification settings - Fork 606
/
ui_atoms.cpp
473 lines (384 loc) · 11 KB
/
ui_atoms.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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
/*
===========================================================================
Copyright (C) 1999 - 2005, Id Software, Inc.
Copyright (C) 2000 - 2013, Raven Software, Inc.
Copyright (C) 2001 - 2013, Activision, Inc.
Copyright (C) 2013 - 2015, OpenJK contributors
This file is part of the OpenJK source code.
OpenJK is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
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.
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.
===========================================================================
*/
/**********************************************************************
UI_ATOMS.C
User interface building blocks and support functions.
**********************************************************************/
#include "../server/exe_headers.h"
#include "ui_local.h"
#include "gameinfo.h"
#include "../qcommon/stv_version.h"
uiimport_t ui;
uiStatic_t uis;
//externs
static void UI_LoadMenu_f( void );
static void UI_SaveMenu_f( void );
//locals
/*
=================
UI_ForceMenuOff
=================
*/
void UI_ForceMenuOff (void)
{
ui.Key_SetCatcher( ui.Key_GetCatcher() & ~KEYCATCH_UI );
ui.Key_ClearStates();
ui.Cvar_Set( "cl_paused", "0" );
}
/*
=================
UI_SetActiveMenu -
this should be the ONLY way the menu system is brought up
=================
*/
void UI_SetActiveMenu( const char* menuname,const char *menuID )
{
// this should be the ONLY way the menu system is brought up (besides the UI_ConsoleCommand below)
if (cls.state != CA_DISCONNECTED && !ui.SG_GameAllowedToSaveHere(qtrue)) //don't check full sytem, only if incamera
{
return;
}
if ( !menuname ) {
UI_ForceMenuOff();
return;
}
//make sure force-speed and slowmodeath doesn't slow down menus - NOTE: they should reset the timescale when the game un-pauses
Cvar_SetValue( "timescale", 1.0f );
UI_Cursor_Show(qtrue);
// enusure minumum menu data is cached
Menu_Cache();
if ( Q_stricmp (menuname, "mainMenu") == 0 )
{
UI_MainMenu();
return;
}
if ( Q_stricmp (menuname, "ingame") == 0 )
{
ui.Cvar_Set( "cl_paused", "1" );
UI_InGameMenu(menuID);
return;
}
if ( Q_stricmp (menuname, "datapad") == 0 )
{
ui.Cvar_Set( "cl_paused", "1" );
UI_DataPadMenu();
return;
}
#ifndef JK2_MODE
if ( Q_stricmp (menuname, "missionfailed_menu") == 0 )
{
Menus_CloseAll();
Menus_ActivateByName("missionfailed_menu");
ui.Key_SetCatcher( KEYCATCH_UI );
return;
}
#endif
}
/*
=================
UI_Argv
=================
*/
static char *UI_Argv( int arg )
{
static char buffer[MAX_STRING_CHARS];
ui.Argv( arg, buffer, sizeof( buffer ) );
return buffer;
}
/*
=================
UI_Cvar_VariableString
=================
*/
char *UI_Cvar_VariableString( const char *var_name )
{
static char buffer[MAX_STRING_CHARS];
ui.Cvar_VariableStringBuffer( var_name, buffer, sizeof( buffer ) );
return buffer;
}
/*
=================
UI_Cache
=================
*/
static void UI_Cache_f( void )
{
Menu_Cache();
#ifndef JK2_MODE
extern const char *lukeForceStatusSounds[];
extern const char *kyleForceStatusSounds[];
for (int index = 0; index < 5; index++)
{
DC->registerSound(lukeForceStatusSounds[index], qfalse);
DC->registerSound(kyleForceStatusSounds[index], qfalse);
}
for (int index = 1; index <= 18; index++)
{
DC->registerSound(va("sound/chars/storyinfo/%d",index), qfalse);
}
trap_S_RegisterSound("sound/chars/kyle/04kyk001.mp3", qfalse);
trap_S_RegisterSound("sound/chars/kyle/05kyk001.mp3", qfalse);
trap_S_RegisterSound("sound/chars/kyle/07kyk001.mp3", qfalse);
trap_S_RegisterSound("sound/chars/kyle/14kyk001.mp3", qfalse);
trap_S_RegisterSound("sound/chars/kyle/21kyk001.mp3", qfalse);
trap_S_RegisterSound("sound/chars/kyle/24kyk001.mp3", qfalse);
trap_S_RegisterSound("sound/chars/kyle/25kyk001.mp3", qfalse);
trap_S_RegisterSound("sound/chars/luke/06luk001.mp3", qfalse);
trap_S_RegisterSound("sound/chars/luke/08luk001.mp3", qfalse);
trap_S_RegisterSound("sound/chars/luke/22luk001.mp3", qfalse);
trap_S_RegisterSound("sound/chars/luke/23luk001.mp3", qfalse);
trap_S_RegisterSound("sound/chars/protocol/12pro001.mp3", qfalse);
trap_S_RegisterSound("sound/chars/protocol/15pro001.mp3", qfalse);
trap_S_RegisterSound("sound/chars/protocol/16pro001.mp3", qfalse);
trap_S_RegisterSound("sound/chars/wedge/13wea001.mp3", qfalse);
Menus_ActivateByName("ingameMissionSelect1");
Menus_ActivateByName("ingameMissionSelect2");
Menus_ActivateByName("ingameMissionSelect3");
#endif
}
/*
=================
UI_ConsoleCommand
=================
*/
#ifndef JK2_MODE
void UI_Load(void); //in UI_main.cpp
#endif
qboolean UI_ConsoleCommand( void )
{
char *cmd;
if (!ui.SG_GameAllowedToSaveHere(qtrue)) //only check if incamera
{
return qfalse;
}
cmd = UI_Argv( 0 );
// ensure minimum menu data is available
Menu_Cache();
if ( Q_stricmp (cmd, "ui_cache") == 0 )
{
UI_Cache_f();
return qtrue;
}
if ( Q_stricmp (cmd, "levelselect") == 0 )
{
UI_LoadMenu_f();
return qtrue;
}
if ( Q_stricmp (cmd, "ui_teamOrders") == 0 )
{
UI_SaveMenu_f();
return qtrue;
}
if ( Q_stricmp (cmd, "ui_report") == 0 )
{
UI_Report();
return qtrue;
}
#ifndef JK2_MODE
if ( Q_stricmp (cmd, "ui_load") == 0 )
{
UI_Load();
return qtrue;
}
#endif
return qfalse;
}
/*
=================
UI_Init
=================
*/
void UI_Init( int apiVersion, uiimport_t *uiimport, qboolean inGameLoad )
{
ui = *uiimport;
if ( apiVersion != UI_API_VERSION ) {
ui.Error( ERR_FATAL, "Bad UI_API_VERSION: expected %i, got %i\n", UI_API_VERSION, apiVersion );
}
// get static data (glconfig, media)
ui.GetGlconfig( &uis.glconfig );
uis.scaley = uis.glconfig.vidHeight * (1.0/480.0);
uis.scalex = uis.glconfig.vidWidth * (1.0/640.0);
Menu_Cache( );
ui.Cvar_Create( "cg_drawCrosshair", "1", CVAR_ARCHIVE );
ui.Cvar_Create( "cg_marks", "1", CVAR_ARCHIVE );
ui.Cvar_Create ("s_language", "english", CVAR_ARCHIVE | CVAR_NORESTART);
#ifndef JK2_MODE
ui.Cvar_Create( "g_char_model", "jedi_tf", CVAR_ARCHIVE|CVAR_SAVEGAME|CVAR_NORESTART );
ui.Cvar_Create( "g_char_skin_head", "head_a1", CVAR_ARCHIVE|CVAR_SAVEGAME|CVAR_NORESTART );
ui.Cvar_Create( "g_char_skin_torso", "torso_a1", CVAR_ARCHIVE|CVAR_SAVEGAME|CVAR_NORESTART );
ui.Cvar_Create( "g_char_skin_legs", "lower_a1", CVAR_ARCHIVE|CVAR_SAVEGAME|CVAR_NORESTART );
ui.Cvar_Create( "g_char_color_red", "255", CVAR_ARCHIVE|CVAR_SAVEGAME|CVAR_NORESTART );
ui.Cvar_Create( "g_char_color_green", "255", CVAR_ARCHIVE|CVAR_SAVEGAME|CVAR_NORESTART );
ui.Cvar_Create( "g_char_color_blue", "255", CVAR_ARCHIVE|CVAR_SAVEGAME|CVAR_NORESTART );
ui.Cvar_Create( "g_saber_type", "single", CVAR_ARCHIVE|CVAR_SAVEGAME|CVAR_NORESTART );
ui.Cvar_Create( "g_saber", "single_1", CVAR_ARCHIVE|CVAR_SAVEGAME|CVAR_NORESTART );
ui.Cvar_Create( "g_saber2", "", CVAR_ARCHIVE|CVAR_SAVEGAME|CVAR_NORESTART );
ui.Cvar_Create( "g_saber_color", "yellow", CVAR_ARCHIVE|CVAR_SAVEGAME|CVAR_NORESTART );
ui.Cvar_Create( "g_saber2_color", "yellow", CVAR_ARCHIVE|CVAR_SAVEGAME|CVAR_NORESTART );
ui.Cvar_Create( "ui_forcepower_inc", "0", CVAR_ROM|CVAR_SAVEGAME|CVAR_NORESTART);
ui.Cvar_Create( "tier_storyinfo", "0", CVAR_ROM|CVAR_SAVEGAME|CVAR_NORESTART);
ui.Cvar_Create( "tiers_complete", "", CVAR_ROM|CVAR_SAVEGAME|CVAR_NORESTART);
ui.Cvar_Create( "ui_prisonerobj_currtotal", "0", CVAR_ROM|CVAR_SAVEGAME|CVAR_NORESTART);
ui.Cvar_Create( "ui_prisonerobj_mintotal", "0", CVAR_ROM|CVAR_SAVEGAME|CVAR_NORESTART);
ui.Cvar_Create( "g_dismemberment", "3", CVAR_ARCHIVE );//0 = none, 1 = arms and hands, 2 = legs, 3 = waist and head
ui.Cvar_Create( "cg_gunAutoFirst", "1", CVAR_ARCHIVE );
ui.Cvar_Create( "cg_crosshairIdentifyTarget", "1", CVAR_ARCHIVE );
ui.Cvar_Create( "g_subtitles", "0", CVAR_ARCHIVE );
ui.Cvar_Create( "cg_marks", "1", CVAR_ARCHIVE );
ui.Cvar_Create( "d_slowmodeath", "3", CVAR_ARCHIVE );
ui.Cvar_Create( "cg_shadows", "1", CVAR_ARCHIVE );
ui.Cvar_Create( "cg_runpitch", "0.002", CVAR_ARCHIVE );
ui.Cvar_Create( "cg_runroll", "0.005", CVAR_ARCHIVE );
ui.Cvar_Create( "cg_bobup", "0.005", CVAR_ARCHIVE );
ui.Cvar_Create( "cg_bobpitch", "0.002", CVAR_ARCHIVE );
ui.Cvar_Create( "cg_bobroll", "0.002", CVAR_ARCHIVE );
ui.Cvar_Create( "ui_disableWeaponSway", "0", CVAR_ARCHIVE );
#endif
_UI_Init(inGameLoad);
}
/*
================
UI_DrawNamedPic
=================
*/
void UI_DrawNamedPic( float x, float y, float width, float height, const char *picname )
{
qhandle_t hShader;
hShader = ui.R_RegisterShaderNoMip( picname );
ui.R_DrawStretchPic( x, y, width, height, 0, 0, 1, 1, hShader );
}
/*
================
UI_DrawHandlePic
=================
*/
void UI_DrawHandlePic( float x, float y, float w, float h, qhandle_t hShader )
{
float s0;
float s1;
float t0;
float t1;
if( w < 0 ) { // flip about horizontal
w = -w;
s0 = 1;
s1 = 0;
}
else {
s0 = 0;
s1 = 1;
}
if( h < 0 ) { // flip about vertical
h = -h;
t0 = 1;
t1 = 0;
}
else {
t0 = 0;
t1 = 1;
}
ui.R_DrawStretchPic( x, y, w, h, s0, t0, s1, t1, hShader );
}
/*
================
UI_FillRect
Coordinates are 640*480 virtual values
=================
*/
void UI_FillRect( float x, float y, float width, float height, const float *color )
{
ui.R_SetColor( color );
ui.R_DrawStretchPic( x, y, width, height, 0, 0, 0, 0, uis.whiteShader );
ui.R_SetColor( NULL );
}
/*
=================
UI_UpdateScreen
=================
*/
void UI_UpdateScreen( void )
{
ui.UpdateScreen();
}
/*
===============
UI_LoadMenu_f
===============
*/
static void UI_LoadMenu_f( void )
{
trap_Key_SetCatcher( KEYCATCH_UI );
Menus_ActivateByName("ingameloadMenu");
}
/*
===============
UI_SaveMenu_f
===============
*/
static void UI_SaveMenu_f( void )
{
#ifdef JK2_MODE
ui.PrecacheScreenshot();
#endif
trap_Key_SetCatcher( KEYCATCH_UI );
Menus_ActivateByName("ingamesaveMenu");
}
//--------------------------------------------
/*
=================
UI_SetColor
=================
*/
void UI_SetColor( const float *rgba )
{
trap_R_SetColor( rgba );
}
/*int registeredFontCount = 0;
#define MAX_FONTS 6
static fontInfo_t registeredFont[MAX_FONTS];
*/
/*
=================
UI_RegisterFont
=================
*/
int registeredFontsCount = 0;
int registeredFonts[MAX_FONTS];
int UI_RegisterFont(const char *fontName)
{
int iFontIndex = ui.R_RegisterFont(fontName);
if (iFontIndex == 0)
{
iFontIndex = ui.R_RegisterFont("ergoec"); // fall back
}
// Store font
if ( iFontIndex )
{
int i;
for ( i = 0; i < registeredFontsCount; i++ )
{
if ( registeredFonts[i] == iFontIndex ) break;
}
if ( i == registeredFontsCount )
{ // It's not in the list: add it
if ( registeredFontsCount >= MAX_FONTS ) Com_Printf( "^3UI_RegisterFont: MAX_FONTS (%i) exceeded\n", MAX_FONTS );
else registeredFonts[registeredFontsCount++] = iFontIndex;
}
}
return iFontIndex;
}