| 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 |
#define ART_BACK0 "menu/art_blueish/back_0" |
| 26 |
#define ART_BACK1 "menu/art_blueish/back_1" |
| 27 |
#define ART_FIGHT0 "menu/art_blueish/accept_0" |
| 28 |
#define ART_FIGHT1 "menu/art_blueish/accept_1" |
| 29 |
#define ART_BACKGROUND "menu/art_blueish/addbotframe" |
| 30 |
#define ART_ARROWS "menu/art_blueish/arrows_vert_0" |
| 31 |
#define ART_ARROWUP "menu/art_blueish/arrows_vert_top" |
| 32 |
#define ART_ARROWDOWN "menu/art_blueish/arrows_vert_bot" |
| 33 |
|
| 34 |
#define ID_BACK 10 |
| 35 |
#define ID_GO 11 |
| 36 |
#define ID_LIST 12 |
| 37 |
#define ID_UP 13 |
| 38 |
#define ID_DOWN 14 |
| 39 |
#define ID_MAPNAME0 20 |
| 40 |
#define ID_MAPNAME1 21 |
| 41 |
#define ID_MAPNAME2 22 |
| 42 |
#define ID_MAPNAME3 23 |
| 43 |
#define ID_MAPNAME4 24 |
| 44 |
#define ID_MAPNAME5 25 |
| 45 |
#define ID_MAPNAME6 26 |
| 46 |
#define ID_MAPNAME7 27 |
| 47 |
#define ID_MAPNAME8 28 |
| 48 |
#define ID_MAPNAME9 29 |
| 49 |
#define SIZE_OF_LIST 10 |
| 50 |
|
| 51 |
#define SIZE_OF_NAME 32 |
| 52 |
|
| 53 |
#define VOTEMAP_MENU_VERTICAL_SPACING 20 |
| 54 |
|
| 55 |
typedef struct { |
| 56 |
menuframework_s menu; |
| 57 |
menubitmap_s arrows; |
| 58 |
menutext_s banner; |
| 59 |
menutext_s info; |
| 60 |
menubitmap_s up; |
| 61 |
menubitmap_s down; |
| 62 |
menubitmap_s go; |
| 63 |
menubitmap_s back; |
| 64 |
|
| 65 |
menutext_s maps[SIZE_OF_LIST]; |
| 66 |
|
| 67 |
int selected; |
| 68 |
} votemenu_map_t; |
| 69 |
|
| 70 |
static votemenu_map_t s_votemenu_map; |
| 71 |
|
| 72 |
/* |
| 73 |
================= |
| 74 |
VoteMapMenu_Event |
| 75 |
================= |
| 76 |
*/ |
| 77 |
static void VoteMapMenu_Event( void* ptr, int event ) |
| 78 |
{ |
| 79 |
switch (((menucommon_s*)ptr)->id) |
| 80 |
{ |
| 81 |
case ID_BACK: |
| 82 |
if (event != QM_ACTIVATED) |
| 83 |
return; |
| 84 |
UI_PopMenu(); |
| 85 |
break; |
| 86 |
case ID_GO: |
| 87 |
if( event != QM_ACTIVATED ) { |
| 88 |
return; |
| 89 |
} |
| 90 |
if(!s_votemenu_map.selected || mappage.mapname[s_votemenu_map.selected-ID_MAPNAME0][0] == 0) |
| 91 |
return; |
| 92 |
if(!Q_stricmp(mappage.mapname[s_votemenu_map.selected-ID_MAPNAME0],"---")) |
| 93 |
return; //Blank spaces have string "---" |
| 94 |
trap_Cmd_ExecuteText( EXEC_APPEND, va("callvote map %s", mappage.mapname[s_votemenu_map.selected-ID_MAPNAME0]) ); |
| 95 |
UI_PopMenu(); |
| 96 |
UI_PopMenu(); |
| 97 |
break; |
| 98 |
default: |
| 99 |
if( event != QM_ACTIVATED ) { |
| 100 |
return; |
| 101 |
} |
| 102 |
if(s_votemenu_map.selected != ((menucommon_s*)ptr)->id) { |
| 103 |
s_votemenu_map.selected = ((menucommon_s*)ptr)->id; |
| 104 |
UI_VoteMapMenuInternal(); |
| 105 |
} |
| 106 |
break; |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
/* |
| 111 |
================= |
| 112 |
UI_VoteMapMenu_UpEvent |
| 113 |
================= |
| 114 |
*/ |
| 115 |
static void UI_VoteMapMenu_UpEvent( void* ptr, int event ) { |
| 116 |
if (event != QM_ACTIVATED || mappage.pagenumber<1) { |
| 117 |
return; |
| 118 |
} |
| 119 |
|
| 120 |
trap_Cmd_ExecuteText( EXEC_APPEND,va("getmappage %d",mappage.pagenumber-1) ); |
| 121 |
} |
| 122 |
|
| 123 |
/* |
| 124 |
================= |
| 125 |
UI_VoteMapMenu_DownEvent |
| 126 |
================= |
| 127 |
*/ |
| 128 |
static void UI_VoteMapMenu_DownEvent( void* ptr, int event ) { |
| 129 |
if (event != QM_ACTIVATED) { |
| 130 |
return; |
| 131 |
} |
| 132 |
|
| 133 |
trap_Cmd_ExecuteText( EXEC_APPEND,va("getmappage %d",mappage.pagenumber+1) ); |
| 134 |
} |
| 135 |
|
| 136 |
/* |
| 137 |
================= |
| 138 |
UI_VoteMapMenu_Draw |
| 139 |
================= |
| 140 |
*/ |
| 141 |
static void UI_VoteMapMenu_Draw( void ) { |
| 142 |
UI_DrawBannerString( 320, 16, "CALL VOTE MAP", UI_CENTER, color_white ); |
| 143 |
UI_DrawNamedPic( 320-233, 240-166, 466, 332, ART_BACKGROUND ); |
| 144 |
|
| 145 |
// standard menu drawing |
| 146 |
Menu_Draw( &s_votemenu_map.menu ); |
| 147 |
} |
| 148 |
|
| 149 |
/* |
| 150 |
================= |
| 151 |
VoteMapMenu_Cache |
| 152 |
================= |
| 153 |
*/ |
| 154 |
static void VoteMapMenu_Cache( void ) |
| 155 |
{ |
| 156 |
trap_R_RegisterShaderNoMip( ART_BACK0 ); |
| 157 |
trap_R_RegisterShaderNoMip( ART_BACK1 ); |
| 158 |
trap_R_RegisterShaderNoMip( ART_FIGHT0 ); |
| 159 |
trap_R_RegisterShaderNoMip( ART_FIGHT1 ); |
| 160 |
trap_R_RegisterShaderNoMip( ART_BACKGROUND ); |
| 161 |
trap_R_RegisterShaderNoMip( ART_ARROWS ); |
| 162 |
trap_R_RegisterShaderNoMip( ART_ARROWUP ); |
| 163 |
trap_R_RegisterShaderNoMip( ART_ARROWDOWN ); |
| 164 |
} |
| 165 |
|
| 166 |
static void setMapMenutext(menutext_s *menu,int y,int id,char * text) { |
| 167 |
menu->generic.type = MTYPE_PTEXT; |
| 168 |
menu->color = color_red; |
| 169 |
menu->generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS; |
| 170 |
if(s_votemenu_map.selected == id) |
| 171 |
menu->color = color_orange; |
| 172 |
menu->generic.x = 320-80; |
| 173 |
menu->generic.y = y; |
| 174 |
menu->generic.id = id; |
| 175 |
menu->generic.callback = VoteMapMenu_Event; |
| 176 |
menu->string = text; |
| 177 |
menu->style = UI_LEFT|UI_SMALLFONT; |
| 178 |
} |
| 179 |
|
| 180 |
/* |
| 181 |
================= |
| 182 |
UI_VoteMapMenuInternal |
| 183 |
*Used then forcing a redraw |
| 184 |
================= |
| 185 |
*/ |
| 186 |
void UI_VoteMapMenuInternal( void ) |
| 187 |
{ |
| 188 |
int y,i; |
| 189 |
|
| 190 |
s_votemenu_map.menu.wrapAround = qtrue; |
| 191 |
s_votemenu_map.menu.fullscreen = qfalse; |
| 192 |
s_votemenu_map.menu.draw = UI_VoteMapMenu_Draw; |
| 193 |
|
| 194 |
s_votemenu_map.banner.generic.type = MTYPE_BTEXT; |
| 195 |
s_votemenu_map.banner.generic.x = 320; |
| 196 |
s_votemenu_map.banner.generic.y = 16; |
| 197 |
s_votemenu_map.banner.string = "CALL VOTE MAP"; |
| 198 |
s_votemenu_map.banner.color = color_white; |
| 199 |
s_votemenu_map.banner.style = UI_CENTER; |
| 200 |
|
| 201 |
s_votemenu_map.info.generic.type = MTYPE_TEXT; |
| 202 |
s_votemenu_map.info.generic.x = 320; |
| 203 |
s_votemenu_map.info.generic.y = 48; |
| 204 |
s_votemenu_map.info.string = va("Page %d",mappage.pagenumber+1); |
| 205 |
s_votemenu_map.info.color = color_white; |
| 206 |
s_votemenu_map.info.style = UI_CENTER; |
| 207 |
|
| 208 |
s_votemenu_map.arrows.generic.type = MTYPE_BITMAP; |
| 209 |
s_votemenu_map.arrows.generic.name = ART_ARROWS; |
| 210 |
s_votemenu_map.arrows.generic.flags = QMF_INACTIVE; |
| 211 |
s_votemenu_map.arrows.generic.x = 200-40; |
| 212 |
s_votemenu_map.arrows.generic.y = 128+30; |
| 213 |
s_votemenu_map.arrows.width = 64; |
| 214 |
s_votemenu_map.arrows.height = 128; |
| 215 |
|
| 216 |
y = 98; |
| 217 |
setMapMenutext(&s_votemenu_map.maps[0],y,ID_MAPNAME0,mappage.mapname[0]); |
| 218 |
for(i=1;i<SIZE_OF_LIST;i++) { |
| 219 |
y+=VOTEMAP_MENU_VERTICAL_SPACING; |
| 220 |
setMapMenutext(&s_votemenu_map.maps[i],y,ID_MAPNAME0+i,mappage.mapname[i]); |
| 221 |
} |
| 222 |
y+=VOTEMAP_MENU_VERTICAL_SPACING+8; |
| 223 |
s_votemenu_map.info.generic.y = y; |
| 224 |
|
| 225 |
s_votemenu_map.up.generic.type = MTYPE_BITMAP; |
| 226 |
s_votemenu_map.up.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS; |
| 227 |
s_votemenu_map.up.generic.x = 200-40; |
| 228 |
s_votemenu_map.up.generic.y = 128+30; |
| 229 |
s_votemenu_map.up.generic.id = ID_UP; |
| 230 |
s_votemenu_map.up.generic.callback = UI_VoteMapMenu_UpEvent; |
| 231 |
s_votemenu_map.up.width = 64; |
| 232 |
s_votemenu_map.up.height = 64; |
| 233 |
s_votemenu_map.up.focuspic = ART_ARROWUP; |
| 234 |
|
| 235 |
s_votemenu_map.down.generic.type = MTYPE_BITMAP; |
| 236 |
s_votemenu_map.down.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS; |
| 237 |
s_votemenu_map.down.generic.x = 200-40; |
| 238 |
s_votemenu_map.down.generic.y = 128+30+64; |
| 239 |
s_votemenu_map.down.generic.id = ID_DOWN; |
| 240 |
s_votemenu_map.down.generic.callback = UI_VoteMapMenu_DownEvent; |
| 241 |
s_votemenu_map.down.width = 64; |
| 242 |
s_votemenu_map.down.height = 64; |
| 243 |
s_votemenu_map.down.focuspic = ART_ARROWDOWN; |
| 244 |
|
| 245 |
s_votemenu_map.go.generic.type = MTYPE_BITMAP; |
| 246 |
s_votemenu_map.go.generic.name = ART_FIGHT0; |
| 247 |
s_votemenu_map.go.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS; |
| 248 |
s_votemenu_map.go.generic.id = ID_GO; |
| 249 |
s_votemenu_map.go.generic.callback = VoteMapMenu_Event; |
| 250 |
s_votemenu_map.go.generic.x = 320+128-128; |
| 251 |
s_votemenu_map.go.generic.y = 256+128-64; |
| 252 |
s_votemenu_map.go.width = 128; |
| 253 |
s_votemenu_map.go.height = 64; |
| 254 |
s_votemenu_map.go.focuspic = ART_FIGHT1; |
| 255 |
|
| 256 |
s_votemenu_map.back.generic.type = MTYPE_BITMAP; |
| 257 |
s_votemenu_map.back.generic.name = ART_BACK0; |
| 258 |
s_votemenu_map.back.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS; |
| 259 |
s_votemenu_map.back.generic.id = ID_BACK; |
| 260 |
s_votemenu_map.back.generic.callback = VoteMapMenu_Event; |
| 261 |
s_votemenu_map.back.generic.x = 320-128; |
| 262 |
s_votemenu_map.back.generic.y = 256+128-64; |
| 263 |
s_votemenu_map.back.width = 128; |
| 264 |
s_votemenu_map.back.height = 64; |
| 265 |
s_votemenu_map.back.focuspic = ART_BACK1; |
| 266 |
} |
| 267 |
|
| 268 |
t_mappage mappage; |
| 269 |
|
| 270 |
/* |
| 271 |
================= |
| 272 |
UI_VoteMapMenu |
| 273 |
*Called from outside |
| 274 |
================= |
| 275 |
*/ |
| 276 |
void UI_VoteMapMenu( void ) { |
| 277 |
int i; |
| 278 |
VoteMapMenu_Cache(); |
| 279 |
memset( &s_votemenu_map, 0 ,sizeof(votemenu_map_t) ); |
| 280 |
|
| 281 |
UI_VoteMapMenuInternal(); |
| 282 |
|
| 283 |
//We need to initialize the list or it will be impossible to click on the items |
| 284 |
for(i=0;i<SIZE_OF_LIST;i++) { |
| 285 |
Q_strncpyz(mappage.mapname[i],"----",5); |
| 286 |
} |
| 287 |
trap_Cmd_ExecuteText( EXEC_APPEND,"getmappage 0" ); |
| 288 |
trap_Cvar_Set( "cl_paused", "0" ); //We cannot send server commands while paused! |
| 289 |
|
| 290 |
Menu_AddItem( &s_votemenu_map.menu, (void*) &s_votemenu_map.banner ); |
| 291 |
Menu_AddItem( &s_votemenu_map.menu, (void*) &s_votemenu_map.info ); |
| 292 |
Menu_AddItem( &s_votemenu_map.menu, (void*) &s_votemenu_map.back ); |
| 293 |
Menu_AddItem( &s_votemenu_map.menu, (void*) &s_votemenu_map.go ); |
| 294 |
Menu_AddItem( &s_votemenu_map.menu, (void*) &s_votemenu_map.arrows ); |
| 295 |
Menu_AddItem( &s_votemenu_map.menu, (void*) &s_votemenu_map.down ); |
| 296 |
Menu_AddItem( &s_votemenu_map.menu, (void*) &s_votemenu_map.up ); |
| 297 |
for(i=0;i<SIZE_OF_LIST;i++) |
| 298 |
Menu_AddItem( &s_votemenu_map.menu, (void*) &s_votemenu_map.maps[i] ); |
| 299 |
|
| 300 |
UI_PushMenu( &s_votemenu_map.menu ); |
| 301 |
} |