ui_atoms.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. /**********************************************************************
  2. UI_ATOMS.C
  3. User interface building blocks and support functions.
  4. **********************************************************************/
  5. // leave this at the top of all UI_xxxx files for PCH reasons...
  6. //
  7. #include "../server/exe_headers.h"
  8. #include "ui_local.h"
  9. #include "gameinfo.h"
  10. #include "../qcommon/stv_version.h"
  11. uiimport_t ui;
  12. uiStatic_t uis;
  13. //externs
  14. static void UI_LoadMenu_f( void );
  15. static void UI_SaveMenu_f( void );
  16. //locals
  17. /*
  18. =================
  19. UI_ForceMenuOff
  20. =================
  21. */
  22. void UI_ForceMenuOff (void)
  23. {
  24. ui.Key_SetCatcher( ui.Key_GetCatcher() & ~KEYCATCH_UI );
  25. ui.Key_ClearStates();
  26. ui.Cvar_Set( "cl_paused", "0" );
  27. }
  28. /*
  29. =================
  30. UI_SetActiveMenu -
  31. this should be the ONLY way the menu system is brought up
  32. =================
  33. */
  34. extern void S_StopAllSoundsExceptMusic( void );
  35. void UI_SetActiveMenu( const char* menuname,const char *menuID )
  36. {
  37. // Sooper-hack. After we play the ja08 cutscene, the game renders for a couple frames.
  38. // So the cinematic code turns off Present(), and we have to turn it back on here:
  39. extern bool connectSwapOverride;
  40. connectSwapOverride = false;
  41. // this should be the ONLY way the menu system is brought up (besides the UI_ConsoleCommand below)
  42. if (cls.state != CA_DISCONNECTED && !ui.SG_GameAllowedToSaveHere(qtrue)) //don't check full sytem, only if incamera
  43. {
  44. return;
  45. }
  46. if ( !menuname ) {
  47. UI_ForceMenuOff();
  48. return;
  49. }
  50. //make sure force-speed and slowmodeath doesn't slow down menus - NOTE: they should reset the timescale when the game un-pauses
  51. Cvar_SetValue( "timescale", 1.0f );
  52. UI_Cursor_Show(qtrue);
  53. // enusure minumum menu data is cached
  54. Menu_Cache();
  55. if ( Q_stricmp (menuname, "mainMenu") == 0 )
  56. {
  57. UI_MainMenu();
  58. return;
  59. }
  60. if ( Q_stricmp (menuname, "ingame") == 0 )
  61. {
  62. ui.Cvar_Set( "cl_paused", "1" );
  63. // S_StopAllSounds();
  64. //NOT USED
  65. //JLF usually called with menuID == NULL but if 'noController' is the menuID
  66. // this forces the pause menu open first and then opens the 'noController' menu
  67. //basically forces the 'ingameMainMenu' open first
  68. // if (menuID)
  69. // UI_InGameMenu(NULL);
  70. //END NOT USED
  71. UI_InGameMenu(menuID);
  72. return;
  73. }
  74. if ( Q_stricmp (menuname, "datapad") == 0 )
  75. {
  76. ui.Cvar_Set( "cl_paused", "1" );
  77. S_StopAllSoundsExceptMusic();
  78. UI_DataPadMenu();
  79. return;
  80. }
  81. if ( Q_stricmp (menuname, "missionfailed_menu") == 0 )
  82. {
  83. Menus_CloseAll();
  84. Menus_ActivateByName("missionfailed_menu");
  85. ui.Key_SetCatcher( KEYCATCH_UI );
  86. return;
  87. }
  88. //allows the 'noController' menu and similar menus to 'popup' over existing menu
  89. if ( Q_stricmp (menuname, "ui_popup") == 0 )
  90. {
  91. Menus_ActivateByName(menuID);
  92. return;
  93. }
  94. //JLF SPLASHMAIN MPSKIPPED
  95. #ifdef _XBOX
  96. {
  97. Menus_CloseAll();
  98. if (Menus_ActivateByName(menuname))
  99. ui.Key_SetCatcher( KEYCATCH_UI );
  100. else
  101. UI_MainMenu();
  102. }
  103. #endif
  104. }
  105. /*
  106. =================
  107. UI_Argv
  108. =================
  109. */
  110. static char *UI_Argv( int arg )
  111. {
  112. static char buffer[MAX_STRING_CHARS];
  113. ui.Argv( arg, buffer, sizeof( buffer ) );
  114. return buffer;
  115. }
  116. /*
  117. =================
  118. UI_Cvar_VariableString
  119. =================
  120. */
  121. char *UI_Cvar_VariableString( const char *var_name )
  122. {
  123. static char buffer[MAX_STRING_CHARS];
  124. ui.Cvar_VariableStringBuffer( var_name, buffer, sizeof( buffer ) );
  125. return buffer;
  126. }
  127. /*
  128. =================
  129. UI_Cache
  130. =================
  131. */
  132. static void UI_Cache_f( void )
  133. {
  134. int index;
  135. Menu_Cache();
  136. extern const char *lukeForceStatusSounds[];
  137. extern const char *kyleForceStatusSounds[];
  138. for (index = 0; index < 5; index++)
  139. {
  140. DC->registerSound(lukeForceStatusSounds[index], qfalse);
  141. DC->registerSound(kyleForceStatusSounds[index], qfalse);
  142. }
  143. for (index = 1; index <= 18; index++)
  144. {
  145. DC->registerSound(va("sound/chars/storyinfo/%d",index), qfalse);
  146. }
  147. trap_S_RegisterSound("sound/chars/kyle/04kyk001.mp3", qfalse);
  148. trap_S_RegisterSound("sound/chars/kyle/05kyk001.mp3", qfalse);
  149. trap_S_RegisterSound("sound/chars/kyle/07kyk001.mp3", qfalse);
  150. trap_S_RegisterSound("sound/chars/kyle/14kyk001.mp3", qfalse);
  151. trap_S_RegisterSound("sound/chars/kyle/21kyk001.mp3", qfalse);
  152. trap_S_RegisterSound("sound/chars/kyle/24kyk001.mp3", qfalse);
  153. trap_S_RegisterSound("sound/chars/kyle/25kyk001.mp3", qfalse);
  154. trap_S_RegisterSound("sound/chars/luke/06luk001.mp3", qfalse);
  155. trap_S_RegisterSound("sound/chars/luke/08luk001.mp3", qfalse);
  156. trap_S_RegisterSound("sound/chars/luke/22luk001.mp3", qfalse);
  157. trap_S_RegisterSound("sound/chars/luke/23luk001.mp3", qfalse);
  158. trap_S_RegisterSound("sound/chars/protocol/12pro001.mp3", qfalse);
  159. trap_S_RegisterSound("sound/chars/protocol/15pro001.mp3", qfalse);
  160. trap_S_RegisterSound("sound/chars/protocol/16pro001.mp3", qfalse);
  161. trap_S_RegisterSound("sound/chars/wedge/13wea001.mp3", qfalse);
  162. Menus_ActivateByName("ingameMissionSelect1");
  163. Menus_ActivateByName("ingameMissionSelect2");
  164. Menus_ActivateByName("ingameMissionSelect3");
  165. }
  166. /*
  167. =================
  168. UI_ConsoleCommand
  169. =================
  170. */
  171. void UI_Load(void); //in UI_main.cpp
  172. qboolean UI_ConsoleCommand( void )
  173. {
  174. char *cmd;
  175. if (!ui.SG_GameAllowedToSaveHere(qtrue)) //only check if incamera
  176. {
  177. return qfalse;
  178. }
  179. cmd = UI_Argv( 0 );
  180. // ensure minimum menu data is available
  181. Menu_Cache();
  182. if ( Q_stricmp (cmd, "ui_cache") == 0 )
  183. {
  184. UI_Cache_f();
  185. return qtrue;
  186. }
  187. if ( Q_stricmp (cmd, "levelselect") == 0 )
  188. {
  189. UI_LoadMenu_f();
  190. return qtrue;
  191. }
  192. if ( Q_stricmp (cmd, "ui_teamOrders") == 0 )
  193. {
  194. UI_SaveMenu_f();
  195. return qtrue;
  196. }
  197. if ( Q_stricmp (cmd, "ui_report") == 0 )
  198. {
  199. UI_Report();
  200. return qtrue;
  201. }
  202. if ( Q_stricmp (cmd, "ui_load") == 0 )
  203. {
  204. UI_Load();
  205. return qtrue;
  206. }
  207. return qfalse;
  208. }
  209. /*
  210. =================
  211. UI_Init
  212. =================
  213. */
  214. void UI_Init( int apiVersion, uiimport_t *uiimport, qboolean inGameLoad )
  215. {
  216. ui = *uiimport;
  217. if ( apiVersion != UI_API_VERSION ) {
  218. ui.Error( ERR_FATAL, "Bad UI_API_VERSION: expected %i, got %i\n", UI_API_VERSION, apiVersion );
  219. }
  220. // get static data (glconfig, media)
  221. ui.GetGlconfig( &uis.glconfig );
  222. uis.scaley = uis.glconfig.vidHeight * (1.0/480.0);
  223. uis.scalex = uis.glconfig.vidWidth * (1.0/640.0);
  224. Menu_Cache( );
  225. ui.Cvar_Create( "cg_drawCrosshair", "1", CVAR_ARCHIVE );
  226. ui.Cvar_Create( "cg_marks", "1", CVAR_ARCHIVE );
  227. // ui.Cvar_Create ("s_language", "english", CVAR_ARCHIVE | CVAR_NORESTART);
  228. ui.Cvar_Create( "g_char_model", "jedi_tf", CVAR_ARCHIVE|CVAR_SAVEGAME|CVAR_NORESTART );
  229. ui.Cvar_Create( "g_char_skin_head", "head_a1", CVAR_ARCHIVE|CVAR_SAVEGAME|CVAR_NORESTART );
  230. ui.Cvar_Create( "g_char_skin_torso", "torso_a1", CVAR_ARCHIVE|CVAR_SAVEGAME|CVAR_NORESTART );
  231. ui.Cvar_Create( "g_char_skin_legs", "lower_a1", CVAR_ARCHIVE|CVAR_SAVEGAME|CVAR_NORESTART );
  232. ui.Cvar_Create( "g_char_color_red", "255", CVAR_ARCHIVE|CVAR_SAVEGAME|CVAR_NORESTART );
  233. ui.Cvar_Create( "g_char_color_green", "255", CVAR_ARCHIVE|CVAR_SAVEGAME|CVAR_NORESTART );
  234. ui.Cvar_Create( "g_char_color_blue", "255", CVAR_ARCHIVE|CVAR_SAVEGAME|CVAR_NORESTART );
  235. ui.Cvar_Create( "g_saber_type", "single", CVAR_ARCHIVE|CVAR_SAVEGAME|CVAR_NORESTART );
  236. ui.Cvar_Create( "g_saber", "single_1", CVAR_ARCHIVE|CVAR_SAVEGAME|CVAR_NORESTART );
  237. ui.Cvar_Create( "g_saber2", "", CVAR_ARCHIVE|CVAR_SAVEGAME|CVAR_NORESTART );
  238. ui.Cvar_Create( "g_saber_color", "yellow", CVAR_ARCHIVE|CVAR_SAVEGAME|CVAR_NORESTART );
  239. ui.Cvar_Create( "g_saber2_color", "yellow", CVAR_ARCHIVE|CVAR_SAVEGAME|CVAR_NORESTART );
  240. ui.Cvar_Create( "ui_forcepower_inc", "0", CVAR_ROM|CVAR_SAVEGAME|CVAR_NORESTART);
  241. ui.Cvar_Create( "tier_storyinfo", "0", CVAR_ROM|CVAR_SAVEGAME|CVAR_NORESTART);
  242. ui.Cvar_Create( "tiers_complete", "", CVAR_ROM|CVAR_SAVEGAME|CVAR_NORESTART);
  243. ui.Cvar_Create( "ui_prisonerobj_currtotal", "0", CVAR_ROM|CVAR_SAVEGAME|CVAR_NORESTART);
  244. ui.Cvar_Create( "ui_prisonerobj_mintotal", "0", CVAR_ROM|CVAR_SAVEGAME|CVAR_NORESTART);
  245. ui.Cvar_Create( "g_dismemberment", "3", CVAR_ARCHIVE );//0 = none, 1 = arms and hands, 2 = legs, 3 = waist and head, 4 = mega dismemberment
  246. ui.Cvar_Create( "cg_gunAutoFirst", "1", CVAR_ARCHIVE );
  247. ui.Cvar_Create( "cg_crosshairIdentifyTarget", "1", CVAR_ARCHIVE );
  248. ui.Cvar_Create( "g_subtitles", "0", CVAR_ARCHIVE );
  249. ui.Cvar_Create( "cg_marks", "1", CVAR_ARCHIVE );
  250. ui.Cvar_Create( "d_slowmodeath", "3", CVAR_ARCHIVE );
  251. ui.Cvar_Create( "cg_shadows", "1", CVAR_ARCHIVE );
  252. ui.Cvar_Create( "cg_runpitch", "0.002", CVAR_ARCHIVE );
  253. ui.Cvar_Create( "cg_runroll", "0.005", CVAR_ARCHIVE );
  254. ui.Cvar_Create( "cg_bobup", "0.005", CVAR_ARCHIVE );
  255. ui.Cvar_Create( "cg_bobpitch", "0.002", CVAR_ARCHIVE );
  256. ui.Cvar_Create( "cg_bobroll", "0.002", CVAR_ARCHIVE );
  257. ui.Cvar_Create( "ui_disableWeaponSway", "0", CVAR_ARCHIVE );
  258. _UI_Init(inGameLoad);
  259. }
  260. // these are only here so the functions in q_shared.c can link
  261. #ifndef UI_HARD_LINKED
  262. /*
  263. ================
  264. Com_Error
  265. =================
  266. */
  267. /*
  268. void Com_Error( int level, const char *error, ... )
  269. {
  270. va_list argptr;
  271. char text[1024];
  272. va_start (argptr, error);
  273. vsprintf (text, error, argptr);
  274. va_end (argptr);
  275. ui.Error( level, "%s", text);
  276. }
  277. */
  278. /*
  279. ================
  280. Com_Printf
  281. =================
  282. */
  283. /*
  284. void Com_Printf( const char *msg, ... )
  285. {
  286. va_list argptr;
  287. char text[1024];
  288. va_start (argptr, msg);
  289. vsprintf (text, msg, argptr);
  290. va_end (argptr);
  291. ui.Printf( "%s", text);
  292. }
  293. */
  294. #endif
  295. /*
  296. ================
  297. UI_DrawNamedPic
  298. =================
  299. */
  300. void UI_DrawNamedPic( float x, float y, float width, float height, const char *picname )
  301. {
  302. qhandle_t hShader;
  303. hShader = ui.R_RegisterShaderNoMip( picname );
  304. ui.R_DrawStretchPic( x, y, width, height, 0, 0, 1, 1, hShader );
  305. }
  306. /*
  307. ================
  308. UI_DrawHandlePic
  309. =================
  310. */
  311. void UI_DrawHandlePic( float x, float y, float w, float h, qhandle_t hShader )
  312. {
  313. float s0;
  314. float s1;
  315. float t0;
  316. float t1;
  317. if( w < 0 ) { // flip about horizontal
  318. w = -w;
  319. s0 = 1;
  320. s1 = 0;
  321. }
  322. else {
  323. s0 = 0;
  324. s1 = 1;
  325. }
  326. if( h < 0 ) { // flip about vertical
  327. h = -h;
  328. t0 = 1;
  329. t1 = 0;
  330. }
  331. else {
  332. t0 = 0;
  333. t1 = 1;
  334. }
  335. ui.R_DrawStretchPic( x, y, w, h, s0, t0, s1, t1, hShader );
  336. }
  337. /*
  338. ================
  339. UI_FillRect
  340. Coordinates are 640*480 virtual values
  341. =================
  342. */
  343. void UI_FillRect( float x, float y, float width, float height, const float *color )
  344. {
  345. ui.R_SetColor( color );
  346. ui.R_DrawStretchPic( x, y, width, height, 0, 0, 0, 0, uis.whiteShader );
  347. ui.R_SetColor( NULL );
  348. }
  349. /*
  350. =================
  351. UI_UpdateScreen
  352. =================
  353. */
  354. void UI_UpdateScreen( void )
  355. {
  356. ui.UpdateScreen();
  357. }
  358. /*
  359. ===============
  360. UI_LoadMenu_f
  361. ===============
  362. */
  363. static void UI_LoadMenu_f( void )
  364. {
  365. trap_Key_SetCatcher( KEYCATCH_UI );
  366. Menus_ActivateByName("ingameloadMenu");
  367. }
  368. /*
  369. ===============
  370. UI_SaveMenu_f
  371. ===============
  372. */
  373. static void UI_SaveMenu_f( void )
  374. {
  375. // ui.PrecacheScreenshot();
  376. trap_Key_SetCatcher( KEYCATCH_UI );
  377. Menus_ActivateByName("ingamesaveMenu");
  378. }
  379. //--------------------------------------------
  380. /*
  381. =================
  382. UI_SetColor
  383. =================
  384. */
  385. void UI_SetColor( const float *rgba )
  386. {
  387. trap_R_SetColor( rgba );
  388. }
  389. /*int registeredFontCount = 0;
  390. #define MAX_FONTS 6
  391. static fontInfo_t registeredFont[MAX_FONTS];
  392. */
  393. /*
  394. =================
  395. UI_RegisterFont
  396. =================
  397. */
  398. int UI_RegisterFont(const char *fontName)
  399. {
  400. int iFontIndex = ui.R_RegisterFont(fontName);
  401. if (iFontIndex == 0)
  402. {
  403. iFontIndex = ui.R_RegisterFont("ergoec"); // fall back
  404. }
  405. return iFontIndex;
  406. }