ui_specifyleague.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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. #include "ui_local.h"
  20. /*********************************************************************************
  21. SPECIFY SERVER
  22. *********************************************************************************/
  23. #define MAX_LISTBOXITEMS 128
  24. #define MAX_LISTBOXWIDTH 40
  25. #define MAX_LEAGUENAME 80
  26. #define SPECIFYLEAGUE_FRAMEL "menu/art/frame2_l"
  27. #define SPECIFYLEAGUE_FRAMER "menu/art/frame1_r"
  28. #define SPECIFYLEAGUE_BACK0 "menu/art/back_0"
  29. #define SPECIFYLEAGUE_BACK1 "menu/art/back_1"
  30. #define SPECIFYLEAGUE_ARROWS0 "menu/art/arrows_vert_0"
  31. #define SPECIFYLEAGUE_UP "menu/art/arrows_vert_top"
  32. #define SPECIFYLEAGUE_DOWN "menu/art/arrows_vert_bot"
  33. #define GLOBALRANKINGS_LOGO "menu/art/gr/grlogo"
  34. #define GLOBALRANKINGS_LETTERS "menu/art/gr/grletters"
  35. #define ID_SPECIFYLEAGUENAME 100
  36. #define ID_SPECIFYLEAGUELIST 101
  37. #define ID_SPECIFYLEAGUEUP 102
  38. #define ID_SPECIFYLEAGUEDOWN 103
  39. #define ID_SPECIFYLEAGUEBACK 104
  40. static char* specifyleague_artlist[] =
  41. {
  42. SPECIFYLEAGUE_FRAMEL,
  43. SPECIFYLEAGUE_FRAMER,
  44. SPECIFYLEAGUE_ARROWS0,
  45. SPECIFYLEAGUE_UP,
  46. SPECIFYLEAGUE_DOWN,
  47. SPECIFYLEAGUE_BACK0,
  48. SPECIFYLEAGUE_BACK1,
  49. GLOBALRANKINGS_LOGO,
  50. GLOBALRANKINGS_LETTERS,
  51. NULL
  52. };
  53. static char playername[80];
  54. typedef struct
  55. {
  56. menuframework_s menu;
  57. menutext_s banner;
  58. menubitmap_s framel;
  59. menubitmap_s framer;
  60. menufield_s rankname;
  61. menulist_s list;
  62. menubitmap_s arrows;
  63. menubitmap_s up;
  64. menubitmap_s down;
  65. menubitmap_s back;
  66. menubitmap_s grlogo;
  67. menubitmap_s grletters;
  68. } specifyleague_t;
  69. static specifyleague_t s_specifyleague;
  70. typedef struct {
  71. char buff[MAX_LISTBOXWIDTH];
  72. char leaguename[MAX_LEAGUENAME];
  73. } table_t;
  74. table_t league_table[MAX_LISTBOXITEMS];
  75. char *leaguename_items[MAX_LISTBOXITEMS];
  76. static void SpecifyLeague_GetList()
  77. {
  78. int count = 0;
  79. int i;
  80. /* The Player Name has changed. We need to perform another search */
  81. Q_strncpyz( playername,
  82. s_specifyleague.rankname.field.buffer,
  83. sizeof(playername) );
  84. count = trap_CL_UI_RankGetLeauges( playername );
  85. for(i = 0; i < count; i++)
  86. {
  87. char s[MAX_LEAGUENAME];
  88. const char *var;
  89. var = va( "leaguename%i", i+1 );
  90. trap_Cvar_VariableStringBuffer( var, s, sizeof(s) );
  91. Q_strncpyz(league_table[i].leaguename, s, sizeof(league_table[i].leaguename) );
  92. Q_strncpyz(league_table[i].buff, league_table[i].leaguename, sizeof(league_table[i].buff) );
  93. }
  94. s_specifyleague.list.numitems = count;
  95. }
  96. /*
  97. =================
  98. SpecifyLeague_Event
  99. =================
  100. */
  101. static void SpecifyLeague_Event( void* ptr, int event )
  102. {
  103. int id;
  104. id = ((menucommon_s*)ptr)->id;
  105. //if( event != QM_ACTIVATED && id != ID_SPECIFYLEAGUELIST ) {
  106. // return;
  107. //}
  108. switch (id)
  109. {
  110. case ID_SPECIFYLEAGUELIST:
  111. if( event == QM_GOTFOCUS ) {
  112. //ArenaServers_UpdatePicture();
  113. }
  114. break;
  115. case ID_SPECIFYLEAGUEUP:
  116. if( event == QM_ACTIVATED )
  117. ScrollList_Key( &s_specifyleague.list, K_UPARROW );
  118. break;
  119. case ID_SPECIFYLEAGUEDOWN:
  120. if( event == QM_ACTIVATED )
  121. ScrollList_Key( &s_specifyleague.list, K_DOWNARROW );
  122. break;
  123. case ID_SPECIFYLEAGUENAME:
  124. if( (event == QM_LOSTFOCUS) &&
  125. (Q_strncmp(playername,
  126. s_specifyleague.rankname.field.buffer,
  127. strlen(s_specifyleague.rankname.field.buffer)) != 0))
  128. {
  129. SpecifyLeague_GetList();
  130. }
  131. break;
  132. case ID_SPECIFYLEAGUEBACK:
  133. if( event == QM_ACTIVATED )
  134. {
  135. trap_Cvar_Set( "sv_leagueName", league_table[s_specifyleague.list.curvalue].leaguename);
  136. UI_PopMenu();
  137. }
  138. break;
  139. }
  140. }
  141. /*
  142. =================
  143. SpecifyLeague_MenuInit
  144. =================
  145. */
  146. void SpecifyLeague_MenuInit( void )
  147. {
  148. int i;
  149. // zero set all our globals
  150. memset( &s_specifyleague, 0 ,sizeof(specifyleague_t) );
  151. SpecifyLeague_Cache();
  152. s_specifyleague.menu.wrapAround = qtrue;
  153. s_specifyleague.menu.fullscreen = qtrue;
  154. s_specifyleague.banner.generic.type = MTYPE_BTEXT;
  155. s_specifyleague.banner.generic.x = 320;
  156. s_specifyleague.banner.generic.y = 16;
  157. s_specifyleague.banner.string = "CHOOSE LEAGUE";
  158. s_specifyleague.banner.color = color_white;
  159. s_specifyleague.banner.style = UI_CENTER;
  160. s_specifyleague.framel.generic.type = MTYPE_BITMAP;
  161. s_specifyleague.framel.generic.name = SPECIFYLEAGUE_FRAMEL;
  162. s_specifyleague.framel.generic.flags = QMF_INACTIVE;
  163. s_specifyleague.framel.generic.x = 0;
  164. s_specifyleague.framel.generic.y = 78;
  165. s_specifyleague.framel.width = 256;
  166. s_specifyleague.framel.height = 334;
  167. s_specifyleague.framer.generic.type = MTYPE_BITMAP;
  168. s_specifyleague.framer.generic.name = SPECIFYLEAGUE_FRAMER;
  169. s_specifyleague.framer.generic.flags = QMF_INACTIVE;
  170. s_specifyleague.framer.generic.x = 376;
  171. s_specifyleague.framer.generic.y = 76;
  172. s_specifyleague.framer.width = 256;
  173. s_specifyleague.framer.height = 334;
  174. s_specifyleague.grlogo.generic.type = MTYPE_BITMAP;
  175. s_specifyleague.grlogo.generic.name = GLOBALRANKINGS_LOGO;
  176. s_specifyleague.grlogo.generic.flags = QMF_INACTIVE;
  177. s_specifyleague.grlogo.generic.x = 0;
  178. s_specifyleague.grlogo.generic.y = 0;
  179. s_specifyleague.grlogo.width = 64;
  180. s_specifyleague.grlogo.height = 128;
  181. s_specifyleague.rankname.generic.type = MTYPE_FIELD;
  182. s_specifyleague.rankname.generic.name = "Player Name:";
  183. s_specifyleague.rankname.generic.flags = QMF_PULSEIFFOCUS|QMF_SMALLFONT;
  184. s_specifyleague.rankname.generic.callback = SpecifyLeague_Event;
  185. s_specifyleague.rankname.generic.id = ID_SPECIFYLEAGUENAME;
  186. s_specifyleague.rankname.generic.x = 226;
  187. s_specifyleague.rankname.generic.y = 128;
  188. s_specifyleague.rankname.field.widthInChars = 32;
  189. s_specifyleague.rankname.field.maxchars = 80;
  190. s_specifyleague.list.generic.type = MTYPE_SCROLLLIST;
  191. s_specifyleague.list.generic.flags = QMF_HIGHLIGHT_IF_FOCUS;
  192. s_specifyleague.list.generic.id = ID_SPECIFYLEAGUELIST;
  193. s_specifyleague.list.generic.callback = SpecifyLeague_Event;
  194. s_specifyleague.list.generic.x = 160;
  195. s_specifyleague.list.generic.y = 200;
  196. s_specifyleague.list.width = MAX_LISTBOXWIDTH;
  197. s_specifyleague.list.height = 8;
  198. s_specifyleague.list.itemnames = (const char **)leaguename_items;
  199. s_specifyleague.list.numitems = 0;
  200. for( i = 0; i < MAX_LISTBOXITEMS; i++ ) {
  201. league_table[i].buff[0] = 0;
  202. league_table[i].leaguename[0] = 0;
  203. leaguename_items[i] = league_table[i].buff;
  204. }
  205. s_specifyleague.arrows.generic.type = MTYPE_BITMAP;
  206. s_specifyleague.arrows.generic.name = SPECIFYLEAGUE_ARROWS0;
  207. s_specifyleague.arrows.generic.flags = QMF_LEFT_JUSTIFY|QMF_INACTIVE;
  208. s_specifyleague.arrows.generic.callback = SpecifyLeague_Event;
  209. s_specifyleague.arrows.generic.x = 512;
  210. s_specifyleague.arrows.generic.y = 240-64+16;
  211. s_specifyleague.arrows.width = 64;
  212. s_specifyleague.arrows.height = 128;
  213. s_specifyleague.up.generic.type = MTYPE_BITMAP;
  214. s_specifyleague.up.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS|QMF_MOUSEONLY;
  215. s_specifyleague.up.generic.callback = SpecifyLeague_Event;
  216. s_specifyleague.up.generic.id = ID_SPECIFYLEAGUEUP;
  217. s_specifyleague.up.generic.x = 512;
  218. s_specifyleague.up.generic.y = 240-64+16;
  219. s_specifyleague.up.width = 64;
  220. s_specifyleague.up.height = 64;
  221. s_specifyleague.up.focuspic = SPECIFYLEAGUE_UP;
  222. s_specifyleague.down.generic.type = MTYPE_BITMAP;
  223. s_specifyleague.down.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS|QMF_MOUSEONLY;
  224. s_specifyleague.down.generic.callback = SpecifyLeague_Event;
  225. s_specifyleague.down.generic.id = ID_SPECIFYLEAGUEDOWN;
  226. s_specifyleague.down.generic.x = 512;
  227. s_specifyleague.down.generic.y = 240+16;
  228. s_specifyleague.down.width = 64;
  229. s_specifyleague.down.height = 64;
  230. s_specifyleague.down.focuspic = SPECIFYLEAGUE_DOWN;
  231. s_specifyleague.back.generic.type = MTYPE_BITMAP;
  232. s_specifyleague.back.generic.name = SPECIFYLEAGUE_BACK0;
  233. s_specifyleague.back.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
  234. s_specifyleague.back.generic.callback = SpecifyLeague_Event;
  235. s_specifyleague.back.generic.id = ID_SPECIFYLEAGUEBACK;
  236. s_specifyleague.back.generic.x = 0;
  237. s_specifyleague.back.generic.y = 480-64;
  238. s_specifyleague.back.width = 128;
  239. s_specifyleague.back.height = 64;
  240. s_specifyleague.back.focuspic = SPECIFYLEAGUE_BACK1;
  241. Menu_AddItem( &s_specifyleague.menu, &s_specifyleague.banner );
  242. Menu_AddItem( &s_specifyleague.menu, &s_specifyleague.framel );
  243. Menu_AddItem( &s_specifyleague.menu, &s_specifyleague.framer );
  244. Menu_AddItem( &s_specifyleague.menu, &s_specifyleague.grlogo );
  245. Menu_AddItem( &s_specifyleague.menu, &s_specifyleague.rankname );
  246. Menu_AddItem( &s_specifyleague.menu, &s_specifyleague.list );
  247. Menu_AddItem( &s_specifyleague.menu, &s_specifyleague.arrows );
  248. Menu_AddItem( &s_specifyleague.menu, &s_specifyleague.up );
  249. Menu_AddItem( &s_specifyleague.menu, &s_specifyleague.down );
  250. Menu_AddItem( &s_specifyleague.menu, &s_specifyleague.back );
  251. // initialize any menu variables
  252. Q_strncpyz( s_specifyleague.rankname.field.buffer,
  253. UI_Cvar_VariableString("name"),
  254. sizeof(s_specifyleague.rankname.field.buffer) );
  255. Q_strncpyz( playername,
  256. UI_Cvar_VariableString("name"),
  257. sizeof(playername) );
  258. SpecifyLeague_GetList();
  259. }
  260. /*
  261. =================
  262. SpecifyLeague_Cache
  263. =================
  264. */
  265. void SpecifyLeague_Cache( void )
  266. {
  267. int i;
  268. // touch all our pics
  269. for (i=0; ;i++)
  270. {
  271. if (!specifyleague_artlist[i])
  272. break;
  273. trap_R_RegisterShaderNoMip(specifyleague_artlist[i]);
  274. }
  275. }
  276. /*
  277. =================
  278. UI_SpecifyLeagueMenu
  279. =================
  280. */
  281. void UI_SpecifyLeagueMenu( void )
  282. {
  283. SpecifyLeague_MenuInit();
  284. UI_PushMenu( &s_specifyleague.menu );
  285. }