Debian Codegraph @

code/q3_ui/ui_password.c

raw
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 SPECIFY PASSWORD
27 *********************************************************************************/
28
29 #define SPECIFYPASSWORD_FRAMEL "menu/art_blueish/frame2_l"
30 #define SPECIFYPASSWORD_FRAMER "menu/art_blueish/frame1_r"
31 #define SPECIFYPASSWORD_BACK0 "menu/art_blueish/back_0"
32 #define SPECIFYPASSWORD_BACK1 "menu/art_blueish/back_1"
33 #define SPECIFYPASSWORD_FIGHT0 "menu/art_blueish/fight_0"
34 #define SPECIFYPASSWORD_FIGHT1 "menu/art_blueish/fight_1"
35
36 #define ID_SPECIFYPASSWORDBACK 102
37 #define ID_SPECIFYPASSWORDGO 103
38
39 static char* specifypassword_artlist[] =
40 {
41 SPECIFYPASSWORD_FRAMEL,
42 SPECIFYPASSWORD_FRAMER,
43 SPECIFYPASSWORD_BACK0,
44 SPECIFYPASSWORD_BACK1,
45 SPECIFYPASSWORD_FIGHT0,
46 SPECIFYPASSWORD_FIGHT1,
47 NULL
48 };
49
50 typedef struct
51 {
52 menuframework_s menu;
53 menutext_s banner;
54 menubitmap_s framel;
55 menubitmap_s framer;
56 menutext_s info;
57 menufield_s password;
58 menubitmap_s go;
59 menubitmap_s back;
60
61 char *connectstring;
62 char servername[32];
63 } specifypassword_t;
64
65 static specifypassword_t s_specifypassword;
66
67 /*
68 =================
69 SpecifyPassword_Event
70 =================
71 */
72 static void SpecifyPassword_Event( void* ptr, int event )
73 {
74 switch (((menucommon_s*)ptr)->id)
75 {
76 case ID_SPECIFYPASSWORDGO:
77 if (event != QM_ACTIVATED)
78 break;
79
80 if (s_specifypassword.password.field.buffer[0])
81 {
82 trap_Cvar_Set("password",s_specifypassword.password.field.buffer);
83 trap_Cmd_ExecuteText( EXEC_APPEND, s_specifypassword.connectstring );
84 }
85 break;
86
87 case ID_SPECIFYPASSWORDBACK:
88 if (event != QM_ACTIVATED)
89 break;
90
91 UI_PopMenu();
92 break;
93 }
94 }
95
96 /*
97 =================
98 SpecifyPassword_MenuInit
99 =================
100 */
101 void SpecifyPassword_MenuInit( void )
102 {
103 // zero set all our globals
104 memset( &s_specifypassword, 0 ,sizeof(specifypassword_t) );
105
106 SpecifyPassword_Cache();
107
108 s_specifypassword.menu.wrapAround = qtrue;
109 s_specifypassword.menu.fullscreen = qtrue;
110
111 s_specifypassword.banner.generic.type = MTYPE_BTEXT;
112 s_specifypassword.banner.generic.x = 320;
113 s_specifypassword.banner.generic.y = 16;
114 s_specifypassword.banner.string = "SPECIFY PASSWORD";
115 s_specifypassword.banner.color = color_white;
116 s_specifypassword.banner.style = UI_CENTER;
117
118 s_specifypassword.framel.generic.type = MTYPE_BITMAP;
119 s_specifypassword.framel.generic.name = SPECIFYPASSWORD_FRAMEL;
120 s_specifypassword.framel.generic.flags = QMF_INACTIVE;
121 s_specifypassword.framel.generic.x = 0;
122 s_specifypassword.framel.generic.y = 78;
123 s_specifypassword.framel.width = 256;
124 s_specifypassword.framel.height = 329;
125
126 s_specifypassword.framer.generic.type = MTYPE_BITMAP;
127 s_specifypassword.framer.generic.name = SPECIFYPASSWORD_FRAMER;
128 s_specifypassword.framer.generic.flags = QMF_INACTIVE;
129 s_specifypassword.framer.generic.x = 376;
130 s_specifypassword.framer.generic.y = 76;
131 s_specifypassword.framer.width = 256;
132 s_specifypassword.framer.height = 334;
133
134 s_specifypassword.info.generic.type = MTYPE_TEXT;
135 s_specifypassword.info.generic.x = 320;
136 s_specifypassword.info.generic.y = 160;
137 s_specifypassword.info.color = color_white;
138 s_specifypassword.info.style = UI_CENTER;
139 s_specifypassword.info.string = s_specifypassword.servername;
140
141 s_specifypassword.password.generic.type = MTYPE_FIELD;
142 s_specifypassword.password.generic.name = "Password:";
143 s_specifypassword.password.generic.flags = QMF_PULSEIFFOCUS|QMF_SMALLFONT;
144 s_specifypassword.password.generic.x = 206;
145 s_specifypassword.password.generic.y = 220;
146 s_specifypassword.password.field.widthInChars = 38;
147 s_specifypassword.password.field.maxchars = 80;
148 trap_Cvar_VariableStringBuffer("password",s_specifypassword.password.field.buffer,80);
149
150 s_specifypassword.go.generic.type = MTYPE_BITMAP;
151 s_specifypassword.go.generic.name = SPECIFYPASSWORD_FIGHT0;
152 s_specifypassword.go.generic.flags = QMF_RIGHT_JUSTIFY|QMF_PULSEIFFOCUS;
153 s_specifypassword.go.generic.callback = SpecifyPassword_Event;
154 s_specifypassword.go.generic.id = ID_SPECIFYPASSWORDGO;
155 s_specifypassword.go.generic.x = 640;
156 s_specifypassword.go.generic.y = 480-64;
157 s_specifypassword.go.width = 128;
158 s_specifypassword.go.height = 64;
159 s_specifypassword.go.focuspic = SPECIFYPASSWORD_FIGHT1;
160
161 s_specifypassword.back.generic.type = MTYPE_BITMAP;
162 s_specifypassword.back.generic.name = SPECIFYPASSWORD_BACK0;
163 s_specifypassword.back.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
164 s_specifypassword.back.generic.callback = SpecifyPassword_Event;
165 s_specifypassword.back.generic.id = ID_SPECIFYPASSWORDBACK;
166 s_specifypassword.back.generic.x = 0;
167 s_specifypassword.back.generic.y = 480-64;
168 s_specifypassword.back.width = 128;
169 s_specifypassword.back.height = 64;
170 s_specifypassword.back.focuspic = SPECIFYPASSWORD_BACK1;
171
172 Menu_AddItem( &s_specifypassword.menu, &s_specifypassword.banner );
173 Menu_AddItem( &s_specifypassword.menu, &s_specifypassword.info );
174 Menu_AddItem( &s_specifypassword.menu, &s_specifypassword.framel );
175 Menu_AddItem( &s_specifypassword.menu, &s_specifypassword.framer );
176 Menu_AddItem( &s_specifypassword.menu, &s_specifypassword.password );
177 Menu_AddItem( &s_specifypassword.menu, &s_specifypassword.go );
178 Menu_AddItem( &s_specifypassword.menu, &s_specifypassword.back );
179 }
180
181 /*
182 =================
183 SpecifyPassword_Cache
184 =================
185 */
186 void SpecifyPassword_Cache( void )
187 {
188 int i;
189
190 // touch all our pics
191 for (i=0; ;i++)
192 {
193 if (!specifypassword_artlist[i])
194 break;
195 trap_R_RegisterShaderNoMip(specifypassword_artlist[i]);
196 }
197 }
198
199 /*
200 =================
201 UI_SpecifyPasswordMenu
202 =================
203 */
204 void UI_SpecifyPasswordMenu( char* string, char *name )
205 {
206 SpecifyPassword_MenuInit();
207 s_specifypassword.connectstring = string;
208 Q_strncpyz(s_specifypassword.servername,name,32);
209 UI_PushMenu( &s_specifypassword.menu );
210 }
211
212