ui_addbots.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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. ADD BOTS 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_FIGHT0 "menu/art/accept_0"
  28. #define ART_FIGHT1 "menu/art/accept_1"
  29. #define ART_BACKGROUND "menu/art/addbotframe"
  30. #define ART_ARROWS "menu/art/arrows_vert_0"
  31. #define ART_ARROWUP "menu/art/arrows_vert_top"
  32. #define ART_ARROWDOWN "menu/art/arrows_vert_bot"
  33. #define ID_BACK 10
  34. #define ID_GO 11
  35. #define ID_LIST 12
  36. #define ID_UP 13
  37. #define ID_DOWN 14
  38. #define ID_SKILL 15
  39. #define ID_TEAM 16
  40. #define ID_BOTNAME0 20
  41. #define ID_BOTNAME1 21
  42. #define ID_BOTNAME2 22
  43. #define ID_BOTNAME3 23
  44. #define ID_BOTNAME4 24
  45. #define ID_BOTNAME5 25
  46. #define ID_BOTNAME6 26
  47. typedef struct {
  48. menuframework_s menu;
  49. menubitmap_s arrows;
  50. menubitmap_s up;
  51. menubitmap_s down;
  52. menutext_s bots[7];
  53. menulist_s skill;
  54. menulist_s team;
  55. menubitmap_s go;
  56. menubitmap_s back;
  57. int numBots;
  58. int delay;
  59. int baseBotNum;
  60. int selectedBotNum;
  61. int sortedBotNums[MAX_BOTS];
  62. char botnames[7][32];
  63. } addBotsMenuInfo_t;
  64. static addBotsMenuInfo_t addBotsMenuInfo;
  65. /*
  66. =================
  67. UI_AddBotsMenu_FightEvent
  68. =================
  69. */
  70. static void UI_AddBotsMenu_FightEvent( void* ptr, int event ) {
  71. const char *team;
  72. int skill;
  73. if (event != QM_ACTIVATED) {
  74. return;
  75. }
  76. team = addBotsMenuInfo.team.itemnames[addBotsMenuInfo.team.curvalue];
  77. skill = addBotsMenuInfo.skill.curvalue + 1;
  78. trap_Cmd_ExecuteText( EXEC_APPEND, va("addbot %s %i %s %i\n",
  79. addBotsMenuInfo.botnames[addBotsMenuInfo.selectedBotNum], skill, team, addBotsMenuInfo.delay) );
  80. addBotsMenuInfo.delay += 1500;
  81. }
  82. /*
  83. =================
  84. UI_AddBotsMenu_BotEvent
  85. =================
  86. */
  87. static void UI_AddBotsMenu_BotEvent( void* ptr, int event ) {
  88. if (event != QM_ACTIVATED) {
  89. return;
  90. }
  91. addBotsMenuInfo.bots[addBotsMenuInfo.selectedBotNum].color = color_orange;
  92. addBotsMenuInfo.selectedBotNum = ((menucommon_s*)ptr)->id - ID_BOTNAME0;
  93. addBotsMenuInfo.bots[addBotsMenuInfo.selectedBotNum].color = color_white;
  94. }
  95. /*
  96. =================
  97. UI_AddBotsMenu_BackEvent
  98. =================
  99. */
  100. static void UI_AddBotsMenu_BackEvent( void* ptr, int event ) {
  101. if (event != QM_ACTIVATED) {
  102. return;
  103. }
  104. UI_PopMenu();
  105. }
  106. /*
  107. =================
  108. UI_AddBotsMenu_SetBotNames
  109. =================
  110. */
  111. static void UI_AddBotsMenu_SetBotNames( void ) {
  112. int n;
  113. const char *info;
  114. for ( n = 0; n < 7; n++ ) {
  115. info = UI_GetBotInfoByNumber( addBotsMenuInfo.sortedBotNums[addBotsMenuInfo.baseBotNum + n] );
  116. Q_strncpyz( addBotsMenuInfo.botnames[n], Info_ValueForKey( info, "name" ), sizeof(addBotsMenuInfo.botnames[n]) );
  117. }
  118. }
  119. /*
  120. =================
  121. UI_AddBotsMenu_UpEvent
  122. =================
  123. */
  124. static void UI_AddBotsMenu_UpEvent( void* ptr, int event ) {
  125. if (event != QM_ACTIVATED) {
  126. return;
  127. }
  128. if( addBotsMenuInfo.baseBotNum > 0 ) {
  129. addBotsMenuInfo.baseBotNum--;
  130. UI_AddBotsMenu_SetBotNames();
  131. }
  132. }
  133. /*
  134. =================
  135. UI_AddBotsMenu_DownEvent
  136. =================
  137. */
  138. static void UI_AddBotsMenu_DownEvent( void* ptr, int event ) {
  139. if (event != QM_ACTIVATED) {
  140. return;
  141. }
  142. if( addBotsMenuInfo.baseBotNum + 7 < addBotsMenuInfo.numBots ) {
  143. addBotsMenuInfo.baseBotNum++;
  144. UI_AddBotsMenu_SetBotNames();
  145. }
  146. }
  147. /*
  148. =================
  149. UI_AddBotsMenu_GetSortedBotNums
  150. =================
  151. */
  152. static int QDECL UI_AddBotsMenu_SortCompare( const void *arg1, const void *arg2 ) {
  153. int num1, num2;
  154. const char *info1, *info2;
  155. const char *name1, *name2;
  156. num1 = *(int *)arg1;
  157. num2 = *(int *)arg2;
  158. info1 = UI_GetBotInfoByNumber( num1 );
  159. info2 = UI_GetBotInfoByNumber( num2 );
  160. name1 = Info_ValueForKey( info1, "name" );
  161. name2 = Info_ValueForKey( info2, "name" );
  162. return Q_stricmp( name1, name2 );
  163. }
  164. static void UI_AddBotsMenu_GetSortedBotNums( void ) {
  165. int n;
  166. // initialize the array
  167. for( n = 0; n < addBotsMenuInfo.numBots; n++ ) {
  168. addBotsMenuInfo.sortedBotNums[n] = n;
  169. }
  170. qsort( addBotsMenuInfo.sortedBotNums, addBotsMenuInfo.numBots, sizeof(addBotsMenuInfo.sortedBotNums[0]), UI_AddBotsMenu_SortCompare );
  171. }
  172. /*
  173. =================
  174. UI_AddBotsMenu_Draw
  175. =================
  176. */
  177. static void UI_AddBotsMenu_Draw( void ) {
  178. UI_DrawBannerString( 320, 16, "ADD BOTS", UI_CENTER, color_white );
  179. UI_DrawNamedPic( 320-233, 240-166, 466, 332, ART_BACKGROUND );
  180. // standard menu drawing
  181. Menu_Draw( &addBotsMenuInfo.menu );
  182. }
  183. /*
  184. =================
  185. UI_AddBotsMenu_Init
  186. =================
  187. */
  188. static const char *skillNames[] = {
  189. "I Can Win",
  190. "Bring It On",
  191. "Hurt Me Plenty",
  192. "Hardcore",
  193. "Nightmare!",
  194. 0
  195. };
  196. static const char *teamNames1[] = {
  197. "Free",
  198. 0
  199. };
  200. static const char *teamNames2[] = {
  201. "Red",
  202. "Blue",
  203. 0
  204. };
  205. static void UI_AddBotsMenu_Init( void ) {
  206. int n;
  207. int y;
  208. int gametype;
  209. int count;
  210. char info[MAX_INFO_STRING];
  211. trap_GetConfigString(CS_SERVERINFO, info, MAX_INFO_STRING);
  212. gametype = atoi( Info_ValueForKey( info,"g_gametype" ) );
  213. memset( &addBotsMenuInfo, 0 ,sizeof(addBotsMenuInfo) );
  214. addBotsMenuInfo.menu.draw = UI_AddBotsMenu_Draw;
  215. addBotsMenuInfo.menu.fullscreen = qfalse;
  216. addBotsMenuInfo.menu.wrapAround = qtrue;
  217. addBotsMenuInfo.delay = 1000;
  218. UI_AddBots_Cache();
  219. addBotsMenuInfo.numBots = UI_GetNumBots();
  220. count = addBotsMenuInfo.numBots < 7 ? addBotsMenuInfo.numBots : 7;
  221. addBotsMenuInfo.arrows.generic.type = MTYPE_BITMAP;
  222. addBotsMenuInfo.arrows.generic.name = ART_ARROWS;
  223. addBotsMenuInfo.arrows.generic.flags = QMF_INACTIVE;
  224. addBotsMenuInfo.arrows.generic.x = 200;
  225. addBotsMenuInfo.arrows.generic.y = 128;
  226. addBotsMenuInfo.arrows.width = 64;
  227. addBotsMenuInfo.arrows.height = 128;
  228. addBotsMenuInfo.up.generic.type = MTYPE_BITMAP;
  229. addBotsMenuInfo.up.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
  230. addBotsMenuInfo.up.generic.x = 200;
  231. addBotsMenuInfo.up.generic.y = 128;
  232. addBotsMenuInfo.up.generic.id = ID_UP;
  233. addBotsMenuInfo.up.generic.callback = UI_AddBotsMenu_UpEvent;
  234. addBotsMenuInfo.up.width = 64;
  235. addBotsMenuInfo.up.height = 64;
  236. addBotsMenuInfo.up.focuspic = ART_ARROWUP;
  237. addBotsMenuInfo.down.generic.type = MTYPE_BITMAP;
  238. addBotsMenuInfo.down.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
  239. addBotsMenuInfo.down.generic.x = 200;
  240. addBotsMenuInfo.down.generic.y = 128+64;
  241. addBotsMenuInfo.down.generic.id = ID_DOWN;
  242. addBotsMenuInfo.down.generic.callback = UI_AddBotsMenu_DownEvent;
  243. addBotsMenuInfo.down.width = 64;
  244. addBotsMenuInfo.down.height = 64;
  245. addBotsMenuInfo.down.focuspic = ART_ARROWDOWN;
  246. for( n = 0, y = 120; n < count; n++, y += 20 ) {
  247. addBotsMenuInfo.bots[n].generic.type = MTYPE_PTEXT;
  248. addBotsMenuInfo.bots[n].generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
  249. addBotsMenuInfo.bots[n].generic.id = ID_BOTNAME0 + n;
  250. addBotsMenuInfo.bots[n].generic.x = 320 - 56;
  251. addBotsMenuInfo.bots[n].generic.y = y;
  252. addBotsMenuInfo.bots[n].generic.callback = UI_AddBotsMenu_BotEvent;
  253. addBotsMenuInfo.bots[n].string = addBotsMenuInfo.botnames[n];
  254. addBotsMenuInfo.bots[n].color = color_orange;
  255. addBotsMenuInfo.bots[n].style = UI_LEFT|UI_SMALLFONT;
  256. }
  257. y += 12;
  258. addBotsMenuInfo.skill.generic.type = MTYPE_SPINCONTROL;
  259. addBotsMenuInfo.skill.generic.flags = QMF_PULSEIFFOCUS|QMF_SMALLFONT;
  260. addBotsMenuInfo.skill.generic.x = 320;
  261. addBotsMenuInfo.skill.generic.y = y;
  262. addBotsMenuInfo.skill.generic.name = "Skill:";
  263. addBotsMenuInfo.skill.generic.id = ID_SKILL;
  264. addBotsMenuInfo.skill.itemnames = skillNames;
  265. addBotsMenuInfo.skill.curvalue = Com_Clamp( 0, 4, (int)trap_Cvar_VariableValue( "g_spSkill" ) - 1 );
  266. y += SMALLCHAR_HEIGHT;
  267. addBotsMenuInfo.team.generic.type = MTYPE_SPINCONTROL;
  268. addBotsMenuInfo.team.generic.flags = QMF_PULSEIFFOCUS|QMF_SMALLFONT;
  269. addBotsMenuInfo.team.generic.x = 320;
  270. addBotsMenuInfo.team.generic.y = y;
  271. addBotsMenuInfo.team.generic.name = "Team: ";
  272. addBotsMenuInfo.team.generic.id = ID_TEAM;
  273. if( gametype >= GT_TEAM ) {
  274. addBotsMenuInfo.team.itemnames = teamNames2;
  275. }
  276. else {
  277. addBotsMenuInfo.team.itemnames = teamNames1;
  278. addBotsMenuInfo.team.generic.flags = QMF_GRAYED;
  279. }
  280. addBotsMenuInfo.go.generic.type = MTYPE_BITMAP;
  281. addBotsMenuInfo.go.generic.name = ART_FIGHT0;
  282. addBotsMenuInfo.go.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
  283. addBotsMenuInfo.go.generic.id = ID_GO;
  284. addBotsMenuInfo.go.generic.callback = UI_AddBotsMenu_FightEvent;
  285. addBotsMenuInfo.go.generic.x = 320+128-128;
  286. addBotsMenuInfo.go.generic.y = 256+128-64;
  287. addBotsMenuInfo.go.width = 128;
  288. addBotsMenuInfo.go.height = 64;
  289. addBotsMenuInfo.go.focuspic = ART_FIGHT1;
  290. addBotsMenuInfo.back.generic.type = MTYPE_BITMAP;
  291. addBotsMenuInfo.back.generic.name = ART_BACK0;
  292. addBotsMenuInfo.back.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
  293. addBotsMenuInfo.back.generic.id = ID_BACK;
  294. addBotsMenuInfo.back.generic.callback = UI_AddBotsMenu_BackEvent;
  295. addBotsMenuInfo.back.generic.x = 320-128;
  296. addBotsMenuInfo.back.generic.y = 256+128-64;
  297. addBotsMenuInfo.back.width = 128;
  298. addBotsMenuInfo.back.height = 64;
  299. addBotsMenuInfo.back.focuspic = ART_BACK1;
  300. addBotsMenuInfo.baseBotNum = 0;
  301. addBotsMenuInfo.selectedBotNum = 0;
  302. addBotsMenuInfo.bots[0].color = color_white;
  303. UI_AddBotsMenu_GetSortedBotNums();
  304. UI_AddBotsMenu_SetBotNames();
  305. Menu_AddItem( &addBotsMenuInfo.menu, &addBotsMenuInfo.arrows );
  306. Menu_AddItem( &addBotsMenuInfo.menu, &addBotsMenuInfo.up );
  307. Menu_AddItem( &addBotsMenuInfo.menu, &addBotsMenuInfo.down );
  308. for( n = 0; n < count; n++ ) {
  309. Menu_AddItem( &addBotsMenuInfo.menu, &addBotsMenuInfo.bots[n] );
  310. }
  311. Menu_AddItem( &addBotsMenuInfo.menu, &addBotsMenuInfo.skill );
  312. Menu_AddItem( &addBotsMenuInfo.menu, &addBotsMenuInfo.team );
  313. Menu_AddItem( &addBotsMenuInfo.menu, &addBotsMenuInfo.go );
  314. Menu_AddItem( &addBotsMenuInfo.menu, &addBotsMenuInfo.back );
  315. }
  316. /*
  317. =================
  318. UI_AddBots_Cache
  319. =================
  320. */
  321. void UI_AddBots_Cache( void ) {
  322. trap_R_RegisterShaderNoMip( ART_BACK0 );
  323. trap_R_RegisterShaderNoMip( ART_BACK1 );
  324. trap_R_RegisterShaderNoMip( ART_FIGHT0 );
  325. trap_R_RegisterShaderNoMip( ART_FIGHT1 );
  326. trap_R_RegisterShaderNoMip( ART_BACKGROUND );
  327. trap_R_RegisterShaderNoMip( ART_ARROWS );
  328. trap_R_RegisterShaderNoMip( ART_ARROWUP );
  329. trap_R_RegisterShaderNoMip( ART_ARROWDOWN );
  330. }
  331. /*
  332. =================
  333. UI_AddBotsMenu
  334. =================
  335. */
  336. void UI_AddBotsMenu( void ) {
  337. UI_AddBotsMenu_Init();
  338. UI_PushMenu( &addBotsMenuInfo.menu );
  339. }