ui_cdkey.c 7.1 KB

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