ui_cdkey.c (7252B)
1 /* 2 =========================================================================== 3 Copyright (C) 1999-2005 Id Software, Inc. 4 5 This file is part of Quake III Arena source code. 6 7 Quake III 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 Quake III 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 Foobar; if not, write to the Free Software 19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 =========================================================================== 21 */ 22 // 23 /* 24 ======================================================================= 25 26 CD KEY MENU 27 28 ======================================================================= 29 */ 30 31 32 #include "ui_local.h" 33 34 35 #define ART_FRAME "menu/art/cut_frame" 36 #define ART_ACCEPT0 "menu/art/accept_0" 37 #define ART_ACCEPT1 "menu/art/accept_1" 38 #define ART_BACK0 "menu/art/back_0" 39 #define ART_BACK1 "menu/art/back_1" 40 41 #define ID_CDKEY 10 42 #define ID_ACCEPT 11 43 #define ID_BACK 12 44 45 46 typedef struct { 47 menuframework_s menu; 48 49 menutext_s banner; 50 menubitmap_s frame; 51 52 menufield_s cdkey; 53 54 menubitmap_s accept; 55 menubitmap_s back; 56 } cdkeyMenuInfo_t; 57 58 static cdkeyMenuInfo_t cdkeyMenuInfo; 59 60 61 /* 62 =============== 63 UI_CDKeyMenu_Event 64 =============== 65 */ 66 static void UI_CDKeyMenu_Event( void *ptr, int event ) { 67 if( event != QM_ACTIVATED ) { 68 return; 69 } 70 71 switch( ((menucommon_s*)ptr)->id ) { 72 case ID_ACCEPT: 73 if( cdkeyMenuInfo.cdkey.field.buffer[0] ) { 74 trap_SetCDKey( cdkeyMenuInfo.cdkey.field.buffer ); 75 } 76 UI_PopMenu(); 77 break; 78 79 case ID_BACK: 80 UI_PopMenu(); 81 break; 82 } 83 } 84 85 86 /* 87 ================= 88 UI_CDKeyMenu_PreValidateKey 89 ================= 90 */ 91 static int UI_CDKeyMenu_PreValidateKey( const char *key ) { 92 char ch; 93 94 if( strlen( key ) != 16 ) { 95 return 1; 96 } 97 98 while( ( ch = *key++ ) ) { 99 switch( ch ) { 100 case '2': 101 case '3': 102 case '7': 103 case 'a': 104 case 'b': 105 case 'c': 106 case 'd': 107 case 'g': 108 case 'h': 109 case 'j': 110 case 'l': 111 case 'p': 112 case 'r': 113 case 's': 114 case 't': 115 case 'w': 116 continue; 117 default: 118 return -1; 119 } 120 } 121 122 return 0; 123 } 124 125 126 /* 127 ================= 128 UI_CDKeyMenu_DrawKey 129 ================= 130 */ 131 static void UI_CDKeyMenu_DrawKey( void *self ) { 132 menufield_s *f; 133 qboolean focus; 134 int style; 135 char c; 136 float *color; 137 int x, y; 138 int val; 139 140 f = (menufield_s *)self; 141 142 focus = (f->generic.parent->cursor == f->generic.menuPosition); 143 144 style = UI_LEFT; 145 if( focus ) { 146 color = color_yellow; 147 } 148 else { 149 color = color_orange; 150 } 151 152 x = 320 - 8 * BIGCHAR_WIDTH; 153 y = 240 - BIGCHAR_HEIGHT / 2; 154 UI_FillRect( x, y, 16 * BIGCHAR_WIDTH, BIGCHAR_HEIGHT, listbar_color ); 155 UI_DrawString( x, y, f->field.buffer, style, color ); 156 157 // draw cursor if we have focus 158 if( focus ) { 159 if ( trap_Key_GetOverstrikeMode() ) { 160 c = 11; 161 } else { 162 c = 10; 163 } 164 165 style &= ~UI_PULSE; 166 style |= UI_BLINK; 167 168 UI_DrawChar( x + f->field.cursor * BIGCHAR_WIDTH, y, c, style, color_white ); 169 } 170 171 val = UI_CDKeyMenu_PreValidateKey( f->field.buffer ); 172 if( val == 1 ) { 173 UI_DrawProportionalString( 320, 376, "Please enter your CD Key", UI_CENTER|UI_SMALLFONT, color_yellow ); 174 } 175 else if ( val == 0 ) { 176 UI_DrawProportionalString( 320, 376, "The CD Key appears to be valid, thank you", UI_CENTER|UI_SMALLFONT, color_white ); 177 } 178 else { 179 UI_DrawProportionalString( 320, 376, "The CD Key is not valid", UI_CENTER|UI_SMALLFONT, color_red ); 180 } 181 } 182 183 184 /* 185 =============== 186 UI_CDKeyMenu_Init 187 =============== 188 */ 189 static void UI_CDKeyMenu_Init( void ) { 190 trap_Cvar_Set( "ui_cdkeychecked", "1" ); 191 192 UI_CDKeyMenu_Cache(); 193 194 memset( &cdkeyMenuInfo, 0, sizeof(cdkeyMenuInfo) ); 195 cdkeyMenuInfo.menu.wrapAround = qtrue; 196 cdkeyMenuInfo.menu.fullscreen = qtrue; 197 198 cdkeyMenuInfo.banner.generic.type = MTYPE_BTEXT; 199 cdkeyMenuInfo.banner.generic.x = 320; 200 cdkeyMenuInfo.banner.generic.y = 16; 201 cdkeyMenuInfo.banner.string = "CD KEY"; 202 cdkeyMenuInfo.banner.color = color_white; 203 cdkeyMenuInfo.banner.style = UI_CENTER; 204 205 cdkeyMenuInfo.frame.generic.type = MTYPE_BITMAP; 206 cdkeyMenuInfo.frame.generic.name = ART_FRAME; 207 cdkeyMenuInfo.frame.generic.flags = QMF_INACTIVE; 208 cdkeyMenuInfo.frame.generic.x = 142; 209 cdkeyMenuInfo.frame.generic.y = 118; 210 cdkeyMenuInfo.frame.width = 359; 211 cdkeyMenuInfo.frame.height = 256; 212 213 cdkeyMenuInfo.cdkey.generic.type = MTYPE_FIELD; 214 cdkeyMenuInfo.cdkey.generic.name = "CD Key:"; 215 cdkeyMenuInfo.cdkey.generic.flags = QMF_LOWERCASE; 216 cdkeyMenuInfo.cdkey.generic.x = 320 - BIGCHAR_WIDTH * 2.5; 217 cdkeyMenuInfo.cdkey.generic.y = 240 - BIGCHAR_HEIGHT / 2; 218 cdkeyMenuInfo.cdkey.field.widthInChars = 16; 219 cdkeyMenuInfo.cdkey.field.maxchars = 16; 220 cdkeyMenuInfo.cdkey.generic.ownerdraw = UI_CDKeyMenu_DrawKey; 221 222 cdkeyMenuInfo.accept.generic.type = MTYPE_BITMAP; 223 cdkeyMenuInfo.accept.generic.name = ART_ACCEPT0; 224 cdkeyMenuInfo.accept.generic.flags = QMF_RIGHT_JUSTIFY|QMF_PULSEIFFOCUS; 225 cdkeyMenuInfo.accept.generic.id = ID_ACCEPT; 226 cdkeyMenuInfo.accept.generic.callback = UI_CDKeyMenu_Event; 227 cdkeyMenuInfo.accept.generic.x = 640; 228 cdkeyMenuInfo.accept.generic.y = 480-64; 229 cdkeyMenuInfo.accept.width = 128; 230 cdkeyMenuInfo.accept.height = 64; 231 cdkeyMenuInfo.accept.focuspic = ART_ACCEPT1; 232 233 cdkeyMenuInfo.back.generic.type = MTYPE_BITMAP; 234 cdkeyMenuInfo.back.generic.name = ART_BACK0; 235 cdkeyMenuInfo.back.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS; 236 cdkeyMenuInfo.back.generic.id = ID_BACK; 237 cdkeyMenuInfo.back.generic.callback = UI_CDKeyMenu_Event; 238 cdkeyMenuInfo.back.generic.x = 0; 239 cdkeyMenuInfo.back.generic.y = 480-64; 240 cdkeyMenuInfo.back.width = 128; 241 cdkeyMenuInfo.back.height = 64; 242 cdkeyMenuInfo.back.focuspic = ART_BACK1; 243 244 Menu_AddItem( &cdkeyMenuInfo.menu, &cdkeyMenuInfo.banner ); 245 Menu_AddItem( &cdkeyMenuInfo.menu, &cdkeyMenuInfo.frame ); 246 Menu_AddItem( &cdkeyMenuInfo.menu, &cdkeyMenuInfo.cdkey ); 247 Menu_AddItem( &cdkeyMenuInfo.menu, &cdkeyMenuInfo.accept ); 248 if( uis.menusp ) { 249 Menu_AddItem( &cdkeyMenuInfo.menu, &cdkeyMenuInfo.back ); 250 } 251 252 trap_GetCDKey( cdkeyMenuInfo.cdkey.field.buffer, cdkeyMenuInfo.cdkey.field.maxchars + 1 ); 253 if( trap_VerifyCDKey( cdkeyMenuInfo.cdkey.field.buffer, NULL ) == qfalse ) { 254 cdkeyMenuInfo.cdkey.field.buffer[0] = 0; 255 } 256 } 257 258 259 /* 260 ================= 261 UI_CDKeyMenu_Cache 262 ================= 263 */ 264 void UI_CDKeyMenu_Cache( void ) { 265 trap_R_RegisterShaderNoMip( ART_ACCEPT0 ); 266 trap_R_RegisterShaderNoMip( ART_ACCEPT1 ); 267 trap_R_RegisterShaderNoMip( ART_BACK0 ); 268 trap_R_RegisterShaderNoMip( ART_BACK1 ); 269 trap_R_RegisterShaderNoMip( ART_FRAME ); 270 } 271 272 273 /* 274 =============== 275 UI_CDKeyMenu 276 =============== 277 */ 278 void UI_CDKeyMenu( void ) { 279 UI_CDKeyMenu_Init(); 280 UI_PushMenu( &cdkeyMenuInfo.menu ); 281 } 282 283 284 /* 285 =============== 286 UI_CDKeyMenu_f 287 =============== 288 */ 289 void UI_CDKeyMenu_f( void ) { 290 UI_CDKeyMenu(); 291 }