ui_demo2.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /*
  2. ===========================================================================
  3. Copyright (C) 1999-2005 Id Software, Inc.
  4. This file is part of Quake III Arena source code.
  5. Quake III Arena source code is free software; you can redistribute it
  6. and/or modify it under the terms of the GNU General Public License as
  7. published by the Free Software Foundation; either version 2 of the License,
  8. or (at your option) any later version.
  9. Quake III Arena source code is distributed in the hope that it will be
  10. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Foobar; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. ===========================================================================
  17. */
  18. //
  19. /*
  20. =======================================================================
  21. DEMOS MENU
  22. =======================================================================
  23. */
  24. #include "ui_local.h"
  25. #define ART_BACK0 "menu/art/back_0"
  26. #define ART_BACK1 "menu/art/back_1"
  27. #define ART_GO0 "menu/art/play_0"
  28. #define ART_GO1 "menu/art/play_1"
  29. #define ART_FRAMEL "menu/art/frame2_l"
  30. #define ART_FRAMER "menu/art/frame1_r"
  31. #define ART_ARROWS "menu/art/arrows_horz_0"
  32. #define ART_ARROWLEFT "menu/art/arrows_horz_left"
  33. #define ART_ARROWRIGHT "menu/art/arrows_horz_right"
  34. #define MAX_DEMOS 128
  35. #define NAMEBUFSIZE ( MAX_DEMOS * 16 )
  36. #define ID_BACK 10
  37. #define ID_GO 11
  38. #define ID_LIST 12
  39. #define ID_RIGHT 13
  40. #define ID_LEFT 14
  41. #define ARROWS_WIDTH 128
  42. #define ARROWS_HEIGHT 48
  43. typedef struct {
  44. menuframework_s menu;
  45. menutext_s banner;
  46. menubitmap_s framel;
  47. menubitmap_s framer;
  48. menulist_s list;
  49. menubitmap_s arrows;
  50. menubitmap_s left;
  51. menubitmap_s right;
  52. menubitmap_s back;
  53. menubitmap_s go;
  54. int numDemos;
  55. char names[NAMEBUFSIZE];
  56. char *demolist[MAX_DEMOS];
  57. } demos_t;
  58. static demos_t s_demos;
  59. /*
  60. ===============
  61. Demos_MenuEvent
  62. ===============
  63. */
  64. static void Demos_MenuEvent( void *ptr, int event ) {
  65. if( event != QM_ACTIVATED ) {
  66. return;
  67. }
  68. switch( ((menucommon_s*)ptr)->id ) {
  69. case ID_GO:
  70. UI_ForceMenuOff ();
  71. trap_Cmd_ExecuteText( EXEC_APPEND, va( "demo %s\n",
  72. s_demos.list.itemnames[s_demos.list.curvalue]) );
  73. break;
  74. case ID_BACK:
  75. UI_PopMenu();
  76. break;
  77. case ID_LEFT:
  78. ScrollList_Key( &s_demos.list, K_LEFTARROW );
  79. break;
  80. case ID_RIGHT:
  81. ScrollList_Key( &s_demos.list, K_RIGHTARROW );
  82. break;
  83. }
  84. }
  85. /*
  86. =================
  87. UI_DemosMenu_Key
  88. =================
  89. */
  90. static sfxHandle_t UI_DemosMenu_Key( int key ) {
  91. menucommon_s *item;
  92. item = Menu_ItemAtCursor( &s_demos.menu );
  93. return Menu_DefaultKey( &s_demos.menu, key );
  94. }
  95. /*
  96. ===============
  97. Demos_MenuInit
  98. ===============
  99. */
  100. static void Demos_MenuInit( void ) {
  101. int i;
  102. int len;
  103. char *demoname, extension[32];
  104. memset( &s_demos, 0 ,sizeof(demos_t) );
  105. s_demos.menu.key = UI_DemosMenu_Key;
  106. Demos_Cache();
  107. s_demos.menu.fullscreen = qtrue;
  108. s_demos.menu.wrapAround = qtrue;
  109. s_demos.banner.generic.type = MTYPE_BTEXT;
  110. s_demos.banner.generic.x = 320;
  111. s_demos.banner.generic.y = 16;
  112. s_demos.banner.string = "DEMOS";
  113. s_demos.banner.color = color_white;
  114. s_demos.banner.style = UI_CENTER;
  115. s_demos.framel.generic.type = MTYPE_BITMAP;
  116. s_demos.framel.generic.name = ART_FRAMEL;
  117. s_demos.framel.generic.flags = QMF_INACTIVE;
  118. s_demos.framel.generic.x = 0;
  119. s_demos.framel.generic.y = 78;
  120. s_demos.framel.width = 256;
  121. s_demos.framel.height = 329;
  122. s_demos.framer.generic.type = MTYPE_BITMAP;
  123. s_demos.framer.generic.name = ART_FRAMER;
  124. s_demos.framer.generic.flags = QMF_INACTIVE;
  125. s_demos.framer.generic.x = 376;
  126. s_demos.framer.generic.y = 76;
  127. s_demos.framer.width = 256;
  128. s_demos.framer.height = 334;
  129. s_demos.arrows.generic.type = MTYPE_BITMAP;
  130. s_demos.arrows.generic.name = ART_ARROWS;
  131. s_demos.arrows.generic.flags = QMF_INACTIVE;
  132. s_demos.arrows.generic.x = 320-ARROWS_WIDTH/2;
  133. s_demos.arrows.generic.y = 400;
  134. s_demos.arrows.width = ARROWS_WIDTH;
  135. s_demos.arrows.height = ARROWS_HEIGHT;
  136. s_demos.left.generic.type = MTYPE_BITMAP;
  137. s_demos.left.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS|QMF_MOUSEONLY;
  138. s_demos.left.generic.x = 320-ARROWS_WIDTH/2;
  139. s_demos.left.generic.y = 400;
  140. s_demos.left.generic.id = ID_LEFT;
  141. s_demos.left.generic.callback = Demos_MenuEvent;
  142. s_demos.left.width = ARROWS_WIDTH/2;
  143. s_demos.left.height = ARROWS_HEIGHT;
  144. s_demos.left.focuspic = ART_ARROWLEFT;
  145. s_demos.right.generic.type = MTYPE_BITMAP;
  146. s_demos.right.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS|QMF_MOUSEONLY;
  147. s_demos.right.generic.x = 320;
  148. s_demos.right.generic.y = 400;
  149. s_demos.right.generic.id = ID_RIGHT;
  150. s_demos.right.generic.callback = Demos_MenuEvent;
  151. s_demos.right.width = ARROWS_WIDTH/2;
  152. s_demos.right.height = ARROWS_HEIGHT;
  153. s_demos.right.focuspic = ART_ARROWRIGHT;
  154. s_demos.back.generic.type = MTYPE_BITMAP;
  155. s_demos.back.generic.name = ART_BACK0;
  156. s_demos.back.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
  157. s_demos.back.generic.id = ID_BACK;
  158. s_demos.back.generic.callback = Demos_MenuEvent;
  159. s_demos.back.generic.x = 0;
  160. s_demos.back.generic.y = 480-64;
  161. s_demos.back.width = 128;
  162. s_demos.back.height = 64;
  163. s_demos.back.focuspic = ART_BACK1;
  164. s_demos.go.generic.type = MTYPE_BITMAP;
  165. s_demos.go.generic.name = ART_GO0;
  166. s_demos.go.generic.flags = QMF_RIGHT_JUSTIFY|QMF_PULSEIFFOCUS;
  167. s_demos.go.generic.id = ID_GO;
  168. s_demos.go.generic.callback = Demos_MenuEvent;
  169. s_demos.go.generic.x = 640;
  170. s_demos.go.generic.y = 480-64;
  171. s_demos.go.width = 128;
  172. s_demos.go.height = 64;
  173. s_demos.go.focuspic = ART_GO1;
  174. s_demos.list.generic.type = MTYPE_SCROLLLIST;
  175. s_demos.list.generic.flags = QMF_PULSEIFFOCUS;
  176. s_demos.list.generic.callback = Demos_MenuEvent;
  177. s_demos.list.generic.id = ID_LIST;
  178. s_demos.list.generic.x = 118;
  179. s_demos.list.generic.y = 130;
  180. s_demos.list.width = 16;
  181. s_demos.list.height = 14;
  182. Com_sprintf(extension, sizeof(extension), "dm_%d", (int)trap_Cvar_VariableValue( "protocol" ) );
  183. s_demos.list.numitems = trap_FS_GetFileList( "demos", extension, s_demos.names, NAMEBUFSIZE );
  184. s_demos.list.itemnames = (const char **)s_demos.demolist;
  185. s_demos.list.columns = 3;
  186. if (!s_demos.list.numitems) {
  187. strcpy( s_demos.names, "No Demos Found." );
  188. s_demos.list.numitems = 1;
  189. //degenerate case, not selectable
  190. s_demos.go.generic.flags |= (QMF_INACTIVE|QMF_HIDDEN);
  191. }
  192. else if (s_demos.list.numitems > MAX_DEMOS)
  193. s_demos.list.numitems = MAX_DEMOS;
  194. demoname = s_demos.names;
  195. for ( i = 0; i < s_demos.list.numitems; i++ ) {
  196. s_demos.list.itemnames[i] = demoname;
  197. // strip extension
  198. len = strlen( demoname );
  199. if (!Q_stricmp(demoname + len - 4,".dm3"))
  200. demoname[len-4] = '\0';
  201. Q_strupr(demoname);
  202. demoname += len + 1;
  203. }
  204. Menu_AddItem( &s_demos.menu, &s_demos.banner );
  205. Menu_AddItem( &s_demos.menu, &s_demos.framel );
  206. Menu_AddItem( &s_demos.menu, &s_demos.framer );
  207. Menu_AddItem( &s_demos.menu, &s_demos.list );
  208. Menu_AddItem( &s_demos.menu, &s_demos.arrows );
  209. Menu_AddItem( &s_demos.menu, &s_demos.left );
  210. Menu_AddItem( &s_demos.menu, &s_demos.right );
  211. Menu_AddItem( &s_demos.menu, &s_demos.back );
  212. Menu_AddItem( &s_demos.menu, &s_demos.go );
  213. }
  214. /*
  215. =================
  216. Demos_Cache
  217. =================
  218. */
  219. void Demos_Cache( void ) {
  220. trap_R_RegisterShaderNoMip( ART_BACK0 );
  221. trap_R_RegisterShaderNoMip( ART_BACK1 );
  222. trap_R_RegisterShaderNoMip( ART_GO0 );
  223. trap_R_RegisterShaderNoMip( ART_GO1 );
  224. trap_R_RegisterShaderNoMip( ART_FRAMEL );
  225. trap_R_RegisterShaderNoMip( ART_FRAMER );
  226. trap_R_RegisterShaderNoMip( ART_ARROWS );
  227. trap_R_RegisterShaderNoMip( ART_ARROWLEFT );
  228. trap_R_RegisterShaderNoMip( ART_ARROWRIGHT );
  229. }
  230. /*
  231. ===============
  232. UI_DemosMenu
  233. ===============
  234. */
  235. void UI_DemosMenu( void ) {
  236. Demos_MenuInit();
  237. UI_PushMenu( &s_demos.menu );
  238. }