aboutsummaryrefslogtreecommitdiffstats
path: root/code/q3_ui/ui_saveconfig.c
blob: e9884639741ce4c6a3918386df8c3f39ce0427e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*
===========================================================================
Copyright (C) 1999-2005 Id Software, Inc.

This file is part of Quake III Arena source code.

Quake III Arena source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.

Quake III Arena source code is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Quake III Arena source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
===========================================================================
*/
//
/*
=============================================================================

SAVE CONFIG MENU

=============================================================================
*/

#include "ui_local.h"


#define ART_BACK0			"menu/art/back_0"
#define ART_BACK1			"menu/art/back_1"	
#define ART_SAVE0			"menu/art/save_0"
#define ART_SAVE1			"menu/art/save_1"
#define ART_BACKGROUND		"menu/art/cut_frame"

#define ID_NAME			10
#define ID_BACK			11
#define ID_SAVE			12


typedef struct {
	menuframework_s	menu;

	menutext_s		banner;
	menubitmap_s	background;
	menufield_s		savename;
	menubitmap_s	back;
	menubitmap_s	save;
} saveConfig_t;

static saveConfig_t		saveConfig;


/*
===============
UI_SaveConfigMenu_BackEvent
===============
*/
static void UI_SaveConfigMenu_BackEvent( void *ptr, int event ) {
	if( event != QM_ACTIVATED ) {
		return;
	}

	UI_PopMenu();
}


/*
===============
UI_SaveConfigMenu_SaveEvent
===============
*/
static void UI_SaveConfigMenu_SaveEvent( void *ptr, int event ) {
	char	configname[MAX_QPATH];

	if( event != QM_ACTIVATED ) {
		return;
	}

	if( !saveConfig.savename.field.buffer[0] ) {
		return;
	}

	COM_StripExtension(saveConfig.savename.field.buffer, configname );
	trap_Cmd_ExecuteText( EXEC_APPEND, va( "writeconfig %s.cfg\n", configname ) );
	UI_PopMenu();
}


/*
===============
UI_SaveConfigMenu_SavenameDraw
===============
*/
static void UI_SaveConfigMenu_SavenameDraw( void *self ) {
	menufield_s		*f;
	int				style;
	float			*color;

	f = (menufield_s *)self;

	if( f == Menu_ItemAtCursor( &saveConfig.menu ) ) {
		style = UI_LEFT|UI_PULSE|UI_SMALLFONT;
		color = text_color_highlight;
	}
	else {
		style = UI_LEFT|UI_SMALLFONT;
		color = colorRed;
	}

	UI_DrawProportionalString( 320, 192, "Enter filename:", UI_CENTER|UI_SMALLFONT, color_orange );
	UI_FillRect( f->generic.x, f->generic.y, f->field.widthInChars*SMALLCHAR_WIDTH, SMALLCHAR_HEIGHT, colorBlack );
	MField_Draw( &f->field, f->generic.x, f->generic.y, style, color );
}


/*
=================
UI_SaveConfigMenu_Init
=================
*/
static void UI_SaveConfigMenu_Init( void ) {
	memset( &saveConfig, 0, sizeof(saveConfig) );

	UI_SaveConfigMenu_Cache();
	saveConfig.menu.wrapAround = qtrue;
	saveConfig.menu.fullscreen = qtrue;

	saveConfig.banner.generic.type		= MTYPE_BTEXT;
	saveConfig.banner.generic.x			= 320;
	saveConfig.banner.generic.y			= 16;
	saveConfig.banner.string			= "SAVE CONFIG";
	saveConfig.banner.color				= color_white;
	saveConfig.banner.style				= UI_CENTER;

	saveConfig.background.generic.type		= MTYPE_BITMAP;
	saveConfig.background.generic.name		= ART_BACKGROUND;
	saveConfig.background.generic.flags		= QMF_INACTIVE;
	saveConfig.background.generic.x			= 142;
	saveConfig.background.generic.y			= 118;
	saveConfig.background.width				= 359;
	saveConfig.background.height			= 256;

	saveConfig.savename.generic.type		= MTYPE_FIELD;
	saveConfig.savename.generic.flags		= QMF_NODEFAULTINIT|QMF_UPPERCASE;
	saveConfig.savename.generic.ownerdraw	= UI_SaveConfigMenu_SavenameDraw;
	saveConfig.savename.field.widthInChars	= 20;
	saveConfig.savename.field.maxchars		= 20;
	saveConfig.savename.generic.x			= 240;
	saveConfig.savename.generic.y			= 155+72;
	saveConfig.savename.generic.left		= 240;
	saveConfig.savename.generic.top			= 155+72;
	saveConfig.savename.generic.right		= 233 + 20*SMALLCHAR_WIDTH;
	saveConfig.savename.generic.bottom		= 155+72 + SMALLCHAR_HEIGHT+2;

	saveConfig.back.generic.type		= MTYPE_BITMAP;
	saveConfig.back.generic.name		= ART_BACK0;
	saveConfig.back.generic.flags		= QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
	saveConfig.back.generic.id			= ID_BACK;
	saveConfig.back.generic.callback	= UI_SaveConfigMenu_BackEvent;
	saveConfig.back.generic.x			= 0;
	saveConfig.back.generic.y			= 480-64;
	saveConfig.back.width				= 128;
	saveConfig.back.height				= 64;
	saveConfig.back.focuspic			= ART_BACK1;

	saveConfig.save.generic.type		= MTYPE_BITMAP;
	saveConfig.save.generic.name		= ART_SAVE0;
	saveConfig.save.generic.flags		= QMF_RIGHT_JUSTIFY|QMF_PULSEIFFOCUS;
	saveConfig.save.generic.id			= ID_SAVE;
	saveConfig.save.generic.callback	= UI_SaveConfigMenu_SaveEvent;
	saveConfig.save.generic.x			= 640;
	saveConfig.save.generic.y			= 480-64;
	saveConfig.save.width  				= 128;
	saveConfig.save.height  		    = 64;
	saveConfig.save.focuspic			= ART_SAVE1;

	Menu_AddItem( &saveConfig.menu, &saveConfig.banner );
	Menu_AddItem( &saveConfig.menu, &saveConfig.background );
	Menu_AddItem( &saveConfig.menu, &saveConfig.savename );
	Menu_AddItem( &saveConfig.menu, &saveConfig.back );
	Menu_AddItem( &saveConfig.menu, &saveConfig.save );
}


/*
=================
UI_SaveConfigMenu_Cache
=================
*/
void UI_SaveConfigMenu_Cache( void ) {
	trap_R_RegisterShaderNoMip( ART_BACK0 );
	trap_R_RegisterShaderNoMip( ART_BACK1 );
	trap_R_RegisterShaderNoMip( ART_SAVE0 );
	trap_R_RegisterShaderNoMip( ART_SAVE1 );
	trap_R_RegisterShaderNoMip( ART_BACKGROUND );
}


/*
===============
UI_SaveConfigMenu
===============
*/
void UI_SaveConfigMenu( void ) {
	UI_SaveConfigMenu_Init();
	UI_PushMenu( &saveConfig.menu );
}