Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

ui_cdkey.c

Go to the documentation of this file.
00001 /*
00002 ===========================================================================
00003 Copyright (C) 1999-2005 Id Software, Inc.
00004 
00005 This file is part of Quake III Arena source code.
00006 
00007 Quake III Arena source code is free software; you can redistribute it
00008 and/or modify it under the terms of the GNU General Public License as
00009 published by the Free Software Foundation; either version 2 of the License,
00010 or (at your option) any later version.
00011 
00012 Quake III Arena source code is distributed in the hope that it will be
00013 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Foobar; if not, write to the Free Software
00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020 ===========================================================================
00021 */
00022 //
00023 /*
00024 =======================================================================
00025 
00026 CD KEY MENU
00027 
00028 =======================================================================
00029 */
00030 
00031 
00032 #include "ui_local.h"
00033 
00034 
00035 #define ART_FRAME       "menu/art/cut_frame"
00036 #define ART_ACCEPT0     "menu/art/accept_0"
00037 #define ART_ACCEPT1     "menu/art/accept_1" 
00038 #define ART_BACK0       "menu/art/back_0"
00039 #define ART_BACK1       "menu/art/back_1"   
00040 
00041 #define ID_CDKEY        10
00042 #define ID_ACCEPT       11
00043 #define ID_BACK         12
00044 
00045 
00046 typedef struct {
00047     menuframework_s menu;
00048 
00049     menutext_s      banner;
00050     menubitmap_s    frame;
00051 
00052     menufield_s     cdkey;
00053 
00054     menubitmap_s    accept;
00055     menubitmap_s    back;
00056 } cdkeyMenuInfo_t;
00057 
00058 static cdkeyMenuInfo_t  cdkeyMenuInfo;
00059 
00060 
00061 /*
00062 ===============
00063 UI_CDKeyMenu_Event
00064 ===============
00065 */
00066 static void UI_CDKeyMenu_Event( void *ptr, int event ) {
00067     if( event != QM_ACTIVATED ) {
00068         return;
00069     }
00070 
00071     switch( ((menucommon_s*)ptr)->id ) {
00072     case ID_ACCEPT:
00073         if( cdkeyMenuInfo.cdkey.field.buffer[0] ) {
00074             trap_SetCDKey( cdkeyMenuInfo.cdkey.field.buffer );
00075         }
00076         UI_PopMenu();
00077         break;
00078 
00079     case ID_BACK:
00080         UI_PopMenu();
00081         break;
00082     }
00083 }
00084 
00085 
00086 /*
00087 =================
00088 UI_CDKeyMenu_PreValidateKey
00089 =================
00090 */
00091 static int UI_CDKeyMenu_PreValidateKey( const char *key ) {
00092     char    ch;
00093 
00094     if( strlen( key ) != 16 ) {
00095         return 1;
00096     }
00097 
00098     while( ( ch = *key++ ) ) {
00099         switch( ch ) {
00100         case '2':
00101         case '3':
00102         case '7':
00103         case 'a':
00104         case 'b':
00105         case 'c':
00106         case 'd':
00107         case 'g':
00108         case 'h':
00109         case 'j':
00110         case 'l':
00111         case 'p':
00112         case 'r':
00113         case 's':
00114         case 't':
00115         case 'w':
00116             continue;
00117         default:
00118             return -1;
00119         }
00120     }
00121 
00122     return 0;
00123 }
00124 
00125 
00126 /*
00127 =================
00128 UI_CDKeyMenu_DrawKey
00129 =================
00130 */
00131 static void UI_CDKeyMenu_DrawKey( void *self ) {
00132     menufield_s     *f;
00133     qboolean        focus;
00134     int             style;
00135     char            c;
00136     float           *color;
00137     int             x, y;
00138     int             val;
00139 
00140     f = (menufield_s *)self;
00141 
00142     focus = (f->generic.parent->cursor == f->generic.menuPosition);
00143 
00144     style = UI_LEFT;
00145     if( focus ) {
00146         color = color_yellow;
00147     }
00148     else {
00149         color = color_orange;
00150     }
00151 
00152     x = 320 - 8 * BIGCHAR_WIDTH;
00153     y = 240 - BIGCHAR_HEIGHT / 2;
00154     UI_FillRect( x, y, 16 * BIGCHAR_WIDTH, BIGCHAR_HEIGHT, listbar_color );
00155     UI_DrawString( x, y, f->field.buffer, style, color );
00156 
00157     // draw cursor if we have focus
00158     if( focus ) {
00159         if ( trap_Key_GetOverstrikeMode() ) {
00160             c = 11;
00161         } else {
00162             c = 10;
00163         }
00164 
00165         style &= ~UI_PULSE;
00166         style |= UI_BLINK;
00167 
00168         UI_DrawChar( x + f->field.cursor * BIGCHAR_WIDTH, y, c, style, color_white );
00169     }
00170 
00171     val = UI_CDKeyMenu_PreValidateKey( f->field.buffer );
00172     if( val == 1 ) {
00173         UI_DrawProportionalString( 320, 376, "Please enter your CD Key", UI_CENTER|UI_SMALLFONT, color_yellow );
00174     }
00175     else if ( val == 0 ) {
00176         UI_DrawProportionalString( 320, 376, "The CD Key appears to be valid, thank you", UI_CENTER|UI_SMALLFONT, color_white );
00177     }
00178     else {
00179         UI_DrawProportionalString( 320, 376, "The CD Key is not valid", UI_CENTER|UI_SMALLFONT, color_red );
00180     }
00181 }
00182 
00183 
00184 /*
00185 ===============
00186 UI_CDKeyMenu_Init
00187 ===============
00188 */
00189 static void UI_CDKeyMenu_Init( void ) {
00190     trap_Cvar_Set( "ui_cdkeychecked", "1" );
00191 
00192     UI_CDKeyMenu_Cache();
00193 
00194     memset( &cdkeyMenuInfo, 0, sizeof(cdkeyMenuInfo) );
00195     cdkeyMenuInfo.menu.wrapAround = qtrue;
00196     cdkeyMenuInfo.menu.fullscreen = qtrue;
00197 
00198     cdkeyMenuInfo.banner.generic.type               = MTYPE_BTEXT;
00199     cdkeyMenuInfo.banner.generic.x                  = 320;
00200     cdkeyMenuInfo.banner.generic.y                  = 16;
00201     cdkeyMenuInfo.banner.string                     = "CD KEY";
00202     cdkeyMenuInfo.banner.color                      = color_white;
00203     cdkeyMenuInfo.banner.style                      = UI_CENTER;
00204 
00205     cdkeyMenuInfo.frame.generic.type                = MTYPE_BITMAP;
00206     cdkeyMenuInfo.frame.generic.name                = ART_FRAME;
00207     cdkeyMenuInfo.frame.generic.flags               = QMF_INACTIVE;
00208     cdkeyMenuInfo.frame.generic.x                   = 142;
00209     cdkeyMenuInfo.frame.generic.y                   = 118;
00210     cdkeyMenuInfo.frame.width                       = 359;
00211     cdkeyMenuInfo.frame.height                      = 256;
00212 
00213     cdkeyMenuInfo.cdkey.generic.type                = MTYPE_FIELD;
00214     cdkeyMenuInfo.cdkey.generic.name                = "CD Key:";
00215     cdkeyMenuInfo.cdkey.generic.flags               = QMF_LOWERCASE;
00216     cdkeyMenuInfo.cdkey.generic.x                   = 320 - BIGCHAR_WIDTH * 2.5;
00217     cdkeyMenuInfo.cdkey.generic.y                   = 240 - BIGCHAR_HEIGHT / 2;
00218     cdkeyMenuInfo.cdkey.field.widthInChars          = 16;
00219     cdkeyMenuInfo.cdkey.field.maxchars              = 16;
00220     cdkeyMenuInfo.cdkey.generic.ownerdraw           = UI_CDKeyMenu_DrawKey;
00221 
00222     cdkeyMenuInfo.accept.generic.type               = MTYPE_BITMAP;
00223     cdkeyMenuInfo.accept.generic.name               = ART_ACCEPT0;
00224     cdkeyMenuInfo.accept.generic.flags              = QMF_RIGHT_JUSTIFY|QMF_PULSEIFFOCUS;
00225     cdkeyMenuInfo.accept.generic.id                 = ID_ACCEPT;
00226     cdkeyMenuInfo.accept.generic.callback           = UI_CDKeyMenu_Event;
00227     cdkeyMenuInfo.accept.generic.x                  = 640;
00228     cdkeyMenuInfo.accept.generic.y                  = 480-64;
00229     cdkeyMenuInfo.accept.width                      = 128;
00230     cdkeyMenuInfo.accept.height                     = 64;
00231     cdkeyMenuInfo.accept.focuspic                   = ART_ACCEPT1;
00232 
00233     cdkeyMenuInfo.back.generic.type                 = MTYPE_BITMAP;
00234     cdkeyMenuInfo.back.generic.name                 = ART_BACK0;
00235     cdkeyMenuInfo.back.generic.flags                = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
00236     cdkeyMenuInfo.back.generic.id                   = ID_BACK;
00237     cdkeyMenuInfo.back.generic.callback             = UI_CDKeyMenu_Event;
00238     cdkeyMenuInfo.back.generic.x                    = 0;
00239     cdkeyMenuInfo.back.generic.y                    = 480-64;
00240     cdkeyMenuInfo.back.width                        = 128;
00241     cdkeyMenuInfo.back.height                       = 64;
00242     cdkeyMenuInfo.back.focuspic                     = ART_BACK1;
00243 
00244     Menu_AddItem( &cdkeyMenuInfo.menu, &cdkeyMenuInfo.banner );
00245     Menu_AddItem( &cdkeyMenuInfo.menu, &cdkeyMenuInfo.frame );
00246     Menu_AddItem( &cdkeyMenuInfo.menu, &cdkeyMenuInfo.cdkey );
00247     Menu_AddItem( &cdkeyMenuInfo.menu, &cdkeyMenuInfo.accept );
00248     if( uis.menusp ) {
00249         Menu_AddItem( &cdkeyMenuInfo.menu, &cdkeyMenuInfo.back );
00250     }
00251 
00252     trap_GetCDKey( cdkeyMenuInfo.cdkey.field.buffer, cdkeyMenuInfo.cdkey.field.maxchars + 1 );
00253     if( trap_VerifyCDKey( cdkeyMenuInfo.cdkey.field.buffer, NULL ) == qfalse ) {
00254         cdkeyMenuInfo.cdkey.field.buffer[0] = 0;
00255     }
00256 }
00257 
00258 
00259 /*
00260 =================
00261 UI_CDKeyMenu_Cache
00262 =================
00263 */
00264 void UI_CDKeyMenu_Cache( void ) {
00265     trap_R_RegisterShaderNoMip( ART_ACCEPT0 );
00266     trap_R_RegisterShaderNoMip( ART_ACCEPT1 );
00267     trap_R_RegisterShaderNoMip( ART_BACK0 );
00268     trap_R_RegisterShaderNoMip( ART_BACK1 );
00269     trap_R_RegisterShaderNoMip( ART_FRAME );
00270 }
00271 
00272 
00273 /*
00274 ===============
00275 UI_CDKeyMenu
00276 ===============
00277 */
00278 void UI_CDKeyMenu( void ) {
00279     UI_CDKeyMenu_Init();
00280     UI_PushMenu( &cdkeyMenuInfo.menu );
00281 }
00282 
00283 
00284 /*
00285 ===============
00286 UI_CDKeyMenu_f
00287 ===============
00288 */
00289 void UI_CDKeyMenu_f( void ) {
00290     UI_CDKeyMenu();
00291 }

Generated on Thu Aug 25 12:37:39 2005 for Quake III Arena by  doxygen 1.3.9.1