| 1 |
/* |
| 2 |
=========================================================================== |
| 3 |
Copyright (C) 2009 Poul Sander |
| 4 |
|
| 5 |
This file is part of the Open Arena source code. |
| 6 |
|
| 7 |
Open Arena source code is free software; you can redistribute it |
| 8 |
and/or modify it under the terms of the GNU General Public License as |
| 9 |
published by the Free Software Foundation; either version 2 of the License, |
| 10 |
or (at your option) any later version. |
| 11 |
|
| 12 |
Open Arena source code is distributed in the hope that it will be |
| 13 |
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
GNU General Public License for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License |
| 18 |
along with Open Arena source code; if not, write to the Free Software |
| 19 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 |
=========================================================================== |
| 21 |
*/ |
| 22 |
|
| 23 |
#include "ui_local.h" |
| 24 |
|
| 25 |
|
| 26 |
#define ART_BACK0 "menu/art_blueish/back_0" |
| 27 |
#define ART_BACK1 "menu/art_blueish/back_1" |
| 28 |
#define ART_FIGHT0 "menu/art_blueish/accept_0" |
| 29 |
#define ART_FIGHT1 "menu/art_blueish/accept_1" |
| 30 |
#define ART_BACKGROUND "menu/art_blueish/addbotframe" |
| 31 |
#define ART_ARROWS "menu/art_blueish/arrows_vert_0" |
| 32 |
#define ART_ARROWUP "menu/art_blueish/arrows_vert_top" |
| 33 |
#define ART_ARROWDOWN "menu/art_blueish/arrows_vert_bot" |
| 34 |
|
| 35 |
#define ID_BACK 10 |
| 36 |
#define ID_GO 11 |
| 37 |
#define ID_LIST 12 |
| 38 |
#define ID_UP 13 |
| 39 |
#define ID_DOWN 14 |
| 40 |
#define ID_PLAYERNAME0 20 |
| 41 |
#define ID_PLAYERNAME1 21 |
| 42 |
#define ID_PLAYERNAME2 22 |
| 43 |
#define ID_PLAYERNAME3 23 |
| 44 |
#define ID_PLAYERNAME4 24 |
| 45 |
#define ID_PLAYERNAME5 25 |
| 46 |
#define ID_PLAYERNAME6 26 |
| 47 |
#define ID_PLAYERNAME7 27 |
| 48 |
#define ID_PLAYERNAME8 28 |
| 49 |
#define ID_PLAYERNAME9 29 |
| 50 |
#define SIZE_OF_LIST 10 |
| 51 |
//#define ID_PLAYERNAME10 30 |
| 52 |
|
| 53 |
#define SIZE_OF_NAME 32 |
| 54 |
|
| 55 |
#define VOTEKICK_MENU_VERTICAL_SPACING 20 |
| 56 |
|
| 57 |
typedef struct { |
| 58 |
int id; |
| 59 |
char name[SIZE_OF_NAME]; |
| 60 |
} player; |
| 61 |
|
| 62 |
typedef struct { |
| 63 |
menuframework_s menu; |
| 64 |
menubitmap_s arrows; |
| 65 |
menutext_s banner; |
| 66 |
menubitmap_s up; |
| 67 |
menubitmap_s down; |
| 68 |
menutext_s players[SIZE_OF_LIST]; |
| 69 |
menubitmap_s go; |
| 70 |
menubitmap_s back; |
| 71 |
|
| 72 |
int numPlayers; |
| 73 |
int selected; |
| 74 |
int startIndex; |
| 75 |
player players_profiles[MAX_CLIENTS]; |
| 76 |
} votemenu_kick_t; |
| 77 |
|
| 78 |
static votemenu_kick_t s_votemenu_kick; |
| 79 |
|
| 80 |
void UI_VoteKickMenuInternal( void ); |
| 81 |
|
| 82 |
static void populatePlayerList( void ) { |
| 83 |
int i; |
| 84 |
char playerinfo[MAX_INFO_STRING]; |
| 85 |
s_votemenu_kick.numPlayers = 0; |
| 86 |
|
| 87 |
for(i=0;i<MAX_CLIENTS;i++) { |
| 88 |
trap_GetConfigString( CS_PLAYERS + i, playerinfo, MAX_INFO_STRING ); |
| 89 |
if(strlen(playerinfo) ) { |
| 90 |
s_votemenu_kick.players_profiles[s_votemenu_kick.numPlayers].id = i; |
| 91 |
Q_strncpyz( s_votemenu_kick.players_profiles[s_votemenu_kick.numPlayers].name, Info_ValueForKey( playerinfo, "n" ), SIZE_OF_NAME - 2); |
| 92 |
s_votemenu_kick.numPlayers++; |
| 93 |
} |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
/* |
| 98 |
================= |
| 99 |
VoteKickMenu_Event |
| 100 |
================= |
| 101 |
*/ |
| 102 |
static void VoteKickMenu_Event( void* ptr, int event ) |
| 103 |
{ |
| 104 |
switch (((menucommon_s*)ptr)->id) |
| 105 |
{ |
| 106 |
case ID_BACK: |
| 107 |
if (event != QM_ACTIVATED) |
| 108 |
return; |
| 109 |
UI_PopMenu(); |
| 110 |
break; |
| 111 |
case ID_GO: |
| 112 |
if( event != QM_ACTIVATED ) { |
| 113 |
return; |
| 114 |
} |
| 115 |
if(!s_votemenu_kick.selected) |
| 116 |
return; |
| 117 |
trap_Cmd_ExecuteText( EXEC_APPEND, va("callvote clientkick %d",s_votemenu_kick.players_profiles[(s_votemenu_kick.selected-20)+s_votemenu_kick.startIndex].id) ); |
| 118 |
UI_PopMenu(); |
| 119 |
UI_PopMenu(); |
| 120 |
break; |
| 121 |
default: |
| 122 |
if( event != QM_ACTIVATED ) { |
| 123 |
return; |
| 124 |
} |
| 125 |
if(s_votemenu_kick.selected != ((menucommon_s*)ptr)->id) { |
| 126 |
s_votemenu_kick.selected = ((menucommon_s*)ptr)->id; |
| 127 |
UI_VoteKickMenuInternal(); |
| 128 |
} |
| 129 |
break; |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
/* |
| 134 |
================= |
| 135 |
UI_VoteKickMenu_UpEvent |
| 136 |
================= |
| 137 |
*/ |
| 138 |
static void UI_VoteKickMenu_UpEvent( void* ptr, int event ) { |
| 139 |
if (event != QM_ACTIVATED) { |
| 140 |
return; |
| 141 |
} |
| 142 |
|
| 143 |
if( s_votemenu_kick.startIndex > 0 ) { |
| 144 |
s_votemenu_kick.startIndex--; |
| 145 |
} |
| 146 |
|
| 147 |
UI_VoteKickMenuInternal(); |
| 148 |
} |
| 149 |
|
| 150 |
/* |
| 151 |
================= |
| 152 |
UI_VoteKickMenu_DownEvent |
| 153 |
================= |
| 154 |
*/ |
| 155 |
static void UI_VoteKickMenu_DownEvent( void* ptr, int event ) { |
| 156 |
if (event != QM_ACTIVATED) { |
| 157 |
return; |
| 158 |
} |
| 159 |
|
| 160 |
if( s_votemenu_kick.startIndex+SIZE_OF_LIST < s_votemenu_kick.numPlayers ) { |
| 161 |
s_votemenu_kick.startIndex++; |
| 162 |
} |
| 163 |
|
| 164 |
UI_VoteKickMenuInternal(); |
| 165 |
} |
| 166 |
|
| 167 |
/* |
| 168 |
================= |
| 169 |
UI_VoteKickMenu_Draw |
| 170 |
================= |
| 171 |
*/ |
| 172 |
static void UI_VoteKickMenu_Draw( void ) { |
| 173 |
UI_DrawBannerString( 320, 16, "CALL VOTE KICK", UI_CENTER, color_white ); |
| 174 |
UI_DrawNamedPic( 320-233, 240-166, 466, 332, ART_BACKGROUND ); |
| 175 |
|
| 176 |
// standard menu drawing |
| 177 |
Menu_Draw( &s_votemenu_kick.menu ); |
| 178 |
} |
| 179 |
|
| 180 |
/* |
| 181 |
================= |
| 182 |
VoteKickMenu_Cache |
| 183 |
================= |
| 184 |
*/ |
| 185 |
static void VoteKickMenu_Cache( void ) |
| 186 |
{ |
| 187 |
trap_R_RegisterShaderNoMip( ART_BACK0 ); |
| 188 |
trap_R_RegisterShaderNoMip( ART_BACK1 ); |
| 189 |
trap_R_RegisterShaderNoMip( ART_FIGHT0 ); |
| 190 |
trap_R_RegisterShaderNoMip( ART_FIGHT1 ); |
| 191 |
trap_R_RegisterShaderNoMip( ART_BACKGROUND ); |
| 192 |
trap_R_RegisterShaderNoMip( ART_ARROWS ); |
| 193 |
trap_R_RegisterShaderNoMip( ART_ARROWUP ); |
| 194 |
trap_R_RegisterShaderNoMip( ART_ARROWDOWN ); |
| 195 |
} |
| 196 |
|
| 197 |
static void setKickMenutext(menutext_s *menu,int y,int id,qboolean active,char *text) { |
| 198 |
menu->generic.type = MTYPE_PTEXT; |
| 199 |
menu->color = color_red; |
| 200 |
menu->generic.flags = QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS; |
| 201 |
if(!active) |
| 202 |
menu->generic.flags |= QMF_INACTIVE|QMF_GRAYED; |
| 203 |
else |
| 204 |
if(s_votemenu_kick.selected == id) |
| 205 |
menu->color = color_orange; |
| 206 |
menu->generic.x = 320; |
| 207 |
menu->generic.y = y; |
| 208 |
menu->generic.id = id; |
| 209 |
menu->generic.callback = VoteKickMenu_Event; |
| 210 |
menu->string = text; |
| 211 |
menu->style = UI_CENTER|UI_SMALLFONT; |
| 212 |
} |
| 213 |
|
| 214 |
/* |
| 215 |
================= |
| 216 |
UI_VoteKickMenuInternal |
| 217 |
*Used then forcing a redraw |
| 218 |
================= |
| 219 |
*/ |
| 220 |
void UI_VoteKickMenuInternal( void ) |
| 221 |
{ |
| 222 |
int y; |
| 223 |
|
| 224 |
s_votemenu_kick.menu.wrapAround = qtrue; |
| 225 |
s_votemenu_kick.menu.fullscreen = qfalse; |
| 226 |
s_votemenu_kick.menu.draw = UI_VoteKickMenu_Draw; |
| 227 |
|
| 228 |
s_votemenu_kick.banner.generic.type = MTYPE_BTEXT; |
| 229 |
s_votemenu_kick.banner.generic.x = 320; |
| 230 |
s_votemenu_kick.banner.generic.y = 16; |
| 231 |
s_votemenu_kick.banner.string = "CALL VOTE KICK"; |
| 232 |
s_votemenu_kick.banner.color = color_white; |
| 233 |
s_votemenu_kick.banner.style = UI_CENTER; |
| 234 |
|
| 235 |
s_votemenu_kick.arrows.generic.type = MTYPE_BITMAP; |
| 236 |
s_votemenu_kick.arrows.generic.name = ART_ARROWS; |
| 237 |
s_votemenu_kick.arrows.generic.flags = QMF_INACTIVE; |
| 238 |
s_votemenu_kick.arrows.generic.x = 200; |
| 239 |
s_votemenu_kick.arrows.generic.y = 128; |
| 240 |
s_votemenu_kick.arrows.width = 64; |
| 241 |
s_votemenu_kick.arrows.height = 128; |
| 242 |
|
| 243 |
y = 98; |
| 244 |
setKickMenutext(&s_votemenu_kick.players[0],y,ID_PLAYERNAME0,s_votemenu_kick.startIndex<s_votemenu_kick.numPlayers,s_votemenu_kick.players_profiles[s_votemenu_kick.startIndex].name); |
| 245 |
y+=VOTEKICK_MENU_VERTICAL_SPACING; |
| 246 |
setKickMenutext(&s_votemenu_kick.players[1],y,ID_PLAYERNAME1,s_votemenu_kick.startIndex+1<s_votemenu_kick.numPlayers,s_votemenu_kick.players_profiles[s_votemenu_kick.startIndex+1].name); |
| 247 |
y+=VOTEKICK_MENU_VERTICAL_SPACING; |
| 248 |
setKickMenutext(&s_votemenu_kick.players[2],y,ID_PLAYERNAME2,s_votemenu_kick.startIndex+2<s_votemenu_kick.numPlayers,s_votemenu_kick.players_profiles[s_votemenu_kick.startIndex+2].name); |
| 249 |
y+=VOTEKICK_MENU_VERTICAL_SPACING; |
| 250 |
setKickMenutext(&s_votemenu_kick.players[3],y,ID_PLAYERNAME3,s_votemenu_kick.startIndex+3<s_votemenu_kick.numPlayers,s_votemenu_kick.players_profiles[s_votemenu_kick.startIndex+3].name); |
| 251 |
y+=VOTEKICK_MENU_VERTICAL_SPACING; |
| 252 |
setKickMenutext(&s_votemenu_kick.players[4],y,ID_PLAYERNAME4,s_votemenu_kick.startIndex+4<s_votemenu_kick.numPlayers,s_votemenu_kick.players_profiles[s_votemenu_kick.startIndex+4].name); |
| 253 |
y+=VOTEKICK_MENU_VERTICAL_SPACING; |
| 254 |
setKickMenutext(&s_votemenu_kick.players[5],y,ID_PLAYERNAME5,s_votemenu_kick.startIndex+5<s_votemenu_kick.numPlayers,s_votemenu_kick.players_profiles[s_votemenu_kick.startIndex+5].name); |
| 255 |
y+=VOTEKICK_MENU_VERTICAL_SPACING; |
| 256 |
setKickMenutext(&s_votemenu_kick.players[6],y,ID_PLAYERNAME6,s_votemenu_kick.startIndex+6<s_votemenu_kick.numPlayers,s_votemenu_kick.players_profiles[s_votemenu_kick.startIndex+6].name); |
| 257 |
y+=VOTEKICK_MENU_VERTICAL_SPACING; |
| 258 |
setKickMenutext(&s_votemenu_kick.players[7],y,ID_PLAYERNAME7,s_votemenu_kick.startIndex+7<s_votemenu_kick.numPlayers,s_votemenu_kick.players_profiles[s_votemenu_kick.startIndex+7].name); |
| 259 |
y+=VOTEKICK_MENU_VERTICAL_SPACING; |
| 260 |
setKickMenutext(&s_votemenu_kick.players[8],y,ID_PLAYERNAME8,s_votemenu_kick.startIndex+8<s_votemenu_kick.numPlayers,s_votemenu_kick.players_profiles[s_votemenu_kick.startIndex+8].name); |
| 261 |
y+=VOTEKICK_MENU_VERTICAL_SPACING; |
| 262 |
setKickMenutext(&s_votemenu_kick.players[9],y,ID_PLAYERNAME9,s_votemenu_kick.startIndex+9<s_votemenu_kick.numPlayers,s_votemenu_kick.players_profiles[s_votemenu_kick.startIndex+9].name); |
| 263 |
|
| 264 |
s_votemenu_kick.up.generic.type = MTYPE_BITMAP; |
| 265 |
s_votemenu_kick.up.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS; |
| 266 |
s_votemenu_kick.up.generic.x = 200; |
| 267 |
s_votemenu_kick.up.generic.y = 128; |
| 268 |
s_votemenu_kick.up.generic.id = ID_UP; |
| 269 |
s_votemenu_kick.up.generic.callback = UI_VoteKickMenu_UpEvent; |
| 270 |
s_votemenu_kick.up.width = 64; |
| 271 |
s_votemenu_kick.up.height = 64; |
| 272 |
s_votemenu_kick.up.focuspic = ART_ARROWUP; |
| 273 |
|
| 274 |
s_votemenu_kick.down.generic.type = MTYPE_BITMAP; |
| 275 |
s_votemenu_kick.down.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS; |
| 276 |
s_votemenu_kick.down.generic.x = 200; |
| 277 |
s_votemenu_kick.down.generic.y = 128+64; |
| 278 |
s_votemenu_kick.down.generic.id = ID_DOWN; |
| 279 |
s_votemenu_kick.down.generic.callback = UI_VoteKickMenu_DownEvent; |
| 280 |
s_votemenu_kick.down.width = 64; |
| 281 |
s_votemenu_kick.down.height = 64; |
| 282 |
s_votemenu_kick.down.focuspic = ART_ARROWDOWN; |
| 283 |
|
| 284 |
s_votemenu_kick.go.generic.type = MTYPE_BITMAP; |
| 285 |
s_votemenu_kick.go.generic.name = ART_FIGHT0; |
| 286 |
s_votemenu_kick.go.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS; |
| 287 |
s_votemenu_kick.go.generic.id = ID_GO; |
| 288 |
s_votemenu_kick.go.generic.callback = VoteKickMenu_Event; |
| 289 |
s_votemenu_kick.go.generic.x = 320+128-128; |
| 290 |
s_votemenu_kick.go.generic.y = 256+128-64; |
| 291 |
s_votemenu_kick.go.width = 128; |
| 292 |
s_votemenu_kick.go.height = 64; |
| 293 |
s_votemenu_kick.go.focuspic = ART_FIGHT1; |
| 294 |
|
| 295 |
s_votemenu_kick.back.generic.type = MTYPE_BITMAP; |
| 296 |
s_votemenu_kick.back.generic.name = ART_BACK0; |
| 297 |
s_votemenu_kick.back.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS; |
| 298 |
s_votemenu_kick.back.generic.id = ID_BACK; |
| 299 |
s_votemenu_kick.back.generic.callback = VoteKickMenu_Event; |
| 300 |
s_votemenu_kick.back.generic.x = 320-128; |
| 301 |
s_votemenu_kick.back.generic.y = 256+128-64; |
| 302 |
s_votemenu_kick.back.width = 128; |
| 303 |
s_votemenu_kick.back.height = 64; |
| 304 |
s_votemenu_kick.back.focuspic = ART_BACK1; |
| 305 |
} |
| 306 |
|
| 307 |
/* |
| 308 |
================= |
| 309 |
UI_VoteKickMenu |
| 310 |
*Called from outside |
| 311 |
================= |
| 312 |
*/ |
| 313 |
void UI_VoteKickMenu( void ) { |
| 314 |
int i; |
| 315 |
VoteKickMenu_Cache(); |
| 316 |
memset( &s_votemenu_kick, 0 ,sizeof(votemenu_kick_t) ); |
| 317 |
populatePlayerList(); |
| 318 |
|
| 319 |
UI_VoteKickMenuInternal(); |
| 320 |
|
| 321 |
Menu_AddItem( &s_votemenu_kick.menu, (void*) &s_votemenu_kick.banner ); |
| 322 |
Menu_AddItem( &s_votemenu_kick.menu, (void*) &s_votemenu_kick.back ); |
| 323 |
Menu_AddItem( &s_votemenu_kick.menu, (void*) &s_votemenu_kick.go ); |
| 324 |
Menu_AddItem( &s_votemenu_kick.menu, (void*) &s_votemenu_kick.arrows ); |
| 325 |
Menu_AddItem( &s_votemenu_kick.menu, (void*) &s_votemenu_kick.down ); |
| 326 |
Menu_AddItem( &s_votemenu_kick.menu, (void*) &s_votemenu_kick.up ); |
| 327 |
for(i=0;i<SIZE_OF_LIST;i++) |
| 328 |
Menu_AddItem( &s_votemenu_kick.menu, (void*) &s_votemenu_kick.players[i] ); |
| 329 |
|
| 330 |
UI_PushMenu( &s_votemenu_kick.menu ); |
| 331 |
} |
| 332 |
|