-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathTouchOptions.cpp
463 lines (381 loc) · 11.9 KB
/
TouchOptions.cpp
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
/*
Copyright (C) 1997-2001 Id Software, Inc.
This program 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.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "Framework.h"
#include "Bitmap.h"
#include "Slider.h"
#include "PicButton.h"
#include "CheckBox.h"
#include "Table.h"
#include "SpinControl.h"
#include "Field.h"
#include "YesNoMessageBox.h"
#include "StringArrayModel.h"
namespace ui {
#define ART_BANNER "gfx/shell/head_touch_options"
static class CMenuTouchOptions : public CMenuFramework
{
private:
void _Init();
void _VidInit();
public:
CMenuTouchOptions() : CMenuFramework( "CMenuTouchOptions" ) { }
void DeleteProfileCb( );
void ResetButtonsCb();
void SaveAndPopMenu();
void GetConfig();
void ResetMsgBox();
void DeleteMsgBox();
void Apply();
void Save();
class CProfiliesListModel : public CStringArrayModel
{
public:
CProfiliesListModel() : CStringArrayModel( (const char*)profileDesc, 95, 0 ) {}
void Update();
const char *GetText( int line ) { return profileDesc[line]; }
char profileDesc[UI_MAXGAMES][95];
int iHighlight;
int firstProfile;
} model;
CMenuPicButton done;
CMenuSlider lookX;
CMenuSlider lookY;
CMenuSlider moveX;
CMenuSlider moveY;
CMenuCheckBox enable;
CMenuCheckBox grid;
CMenuCheckBox nomouse;
CMenuPicButton reset;
CMenuPicButton save;
CMenuPicButton remove;
CMenuPicButton apply;
CMenuField profilename;
CMenuTable profiles;
CMenuSpinControl gridsize;
CMenuCheckBox acceleration;
CMenuSlider power;
CMenuSlider multiplier;
CMenuSlider exponent;
// prompt dialog
CMenuYesNoMessageBox msgBox;
void UpdateProfilies();
} uiTouchOptions;
void CMenuTouchOptions::CProfiliesListModel::Update( void )
{
char **filenames;
int i = 0, numFiles, j = 0;
const char *curprofile;
Q_strncpy( profileDesc[i], "Presets:", CS_SIZE );
i++;
filenames = EngFuncs::GetFilesList( "touch_presets/*.cfg", &numFiles, TRUE );
for ( ; j < numFiles; i++, j++ )
{
if( i >= UI_MAXGAMES ) break;
// strip path, leave only filename (empty slots doesn't have savename)
COM_FileBase( filenames[j], profileDesc[i] );
}
// Overwrite "Presets:" line if there is no presets
if( i == 1 )
i = 0;
filenames = EngFuncs::GetFilesList( "touch_profiles/*.cfg", &numFiles, TRUE );
j = 0;
curprofile = EngFuncs::GetCvarString("touch_config_file");
Q_strncpy( profileDesc[i], "Profiles:", CS_SIZE );
i++;
Q_strncpy( profileDesc[i], "default", CS_SIZE );
iHighlight = firstProfile = i;
i++;
for ( ; j < numFiles; i++, j++ )
{
if( i >= UI_MAXGAMES ) break;
COM_FileBase( filenames[j], profileDesc[i] );
if( !strcmp( filenames[j], curprofile ) )
iHighlight = i;
}
m_iCount = i;
}
/*
=================
UI_TouchOptions_SetConfig
=================
*/
void CMenuTouchOptions::SaveAndPopMenu( void )
{
grid.WriteCvar();
gridsize.WriteCvar();
lookX.WriteCvar();
lookY.WriteCvar();
moveX.WriteCvar();
moveY.WriteCvar();
enable.WriteCvar();
nomouse.WriteCvar();
acceleration.WriteCvar();
power.WriteCvar();
multiplier.WriteCvar();
exponent.WriteCvar();
CMenuFramework::SaveAndPopMenu();
}
void CMenuTouchOptions::GetConfig( void )
{
grid.UpdateEditable();
gridsize.UpdateEditable();
lookX.UpdateEditable();
lookY.UpdateEditable();
moveX.UpdateEditable();
moveY.UpdateEditable();
enable.UpdateEditable();
nomouse.UpdateEditable();
acceleration.UpdateEditable();
power.UpdateEditable();
multiplier.UpdateEditable();
exponent.UpdateEditable();
}
void CMenuTouchOptions::ResetMsgBox()
{
msgBox.SetMessage( "Reset sensitivity options?");
msgBox.onPositive = VoidCb( &CMenuTouchOptions::ResetButtonsCb );
msgBox.Show();
}
void CMenuTouchOptions::DeleteMsgBox()
{
msgBox.SetMessage( "Delete selected profile?");
msgBox.onPositive = VoidCb( &CMenuTouchOptions::DeleteProfileCb );
msgBox.Show();
}
void CMenuTouchOptions::Apply()
{
int i = profiles.GetCurrentIndex();
// preset selected
if( i > 0 && i < model.firstProfile - 1 )
{
char command[256];
const char *curconfig = EngFuncs::GetCvarString( "touch_config_file" );
snprintf( command, 256, "exec \"touch_presets/%s\"\n", model.profileDesc[ i ] );
EngFuncs::ClientCmd( 1, command );
while( EngFuncs::FileExists( curconfig, TRUE ) )
{
char copystring[256];
char filebase[256];
COM_FileBase( curconfig, filebase );
if( snprintf( copystring, 256, "touch_profiles/%s (new).cfg", filebase ) > 255 )
break;
EngFuncs::CvarSetString( "touch_config_file", copystring );
curconfig = EngFuncs::GetCvarString( "touch_config_file" );
}
}
else if( i == model.firstProfile )
EngFuncs::ClientCmd( 1, "exec touch.cfg\n" );
else if( i > model.firstProfile )
{
char command[256];
snprintf( command, 256, "exec \"touch_profiles/%s\"\n", model.profileDesc[ i ] );
EngFuncs::ClientCmd( 1, command );
}
// try save config
EngFuncs::ClientCmd( 1, "touch_writeconfig\n" );
// check if it failed ant reset profile to default if it is
if( !EngFuncs::FileExists( EngFuncs::GetCvarString( "touch_config_file" ), TRUE ) )
{
EngFuncs::CvarSetString( "touch_config_file", "touch.cfg" );
profiles.SetCurrentIndex( model.firstProfile );
}
model.Update();
GetConfig();
}
void CMenuTouchOptions::Save()
{
char name[512];
if( profilename.GetBuffer()[0] )
{
snprintf(name, sizeof( name ), "touch_profiles/%s.cfg", profilename.GetBuffer() );
EngFuncs::CvarSetString("touch_config_file", name );
}
EngFuncs::ClientCmd( 1, "touch_writeconfig\n" );
model.Update();
profilename.Clear();
}
void CMenuTouchOptions::UpdateProfilies()
{
char curprofile[256];
int isCurrent;
int idx = profiles.GetCurrentIndex();
COM_FileBase( EngFuncs::GetCvarString( "touch_config_file" ), curprofile );
isCurrent = !strcmp( curprofile, model.profileDesc[ idx ]);
// Scrolllist changed, update available options
remove.SetGrayed( true );
if( ( idx > model.firstProfile ) && !isCurrent )
remove.SetGrayed( false );
apply.SetGrayed( false );
if( idx == 0 || idx == model.firstProfile - 1 )
profiles.SetCurrentIndex( idx + 1 );
if( isCurrent )
apply.SetGrayed( true );
}
void CMenuTouchOptions::DeleteProfileCb()
{
char command[256];
if( profiles.GetCurrentIndex() <= model.firstProfile )
return;
snprintf(command, 256, "touch_deleteprofile \"%s\"\n", model.profileDesc[ profiles.GetCurrentIndex() ] );
EngFuncs::ClientCmd( TRUE, command );
model.Update();
}
void CMenuTouchOptions::ResetButtonsCb()
{
EngFuncs::ClientCmd( FALSE, "touch_pitch 90\n" );
EngFuncs::ClientCmd( FALSE, "touch_yaw 120\n" );
EngFuncs::ClientCmd( FALSE, "touch_forwardzone 0.06\n" );
EngFuncs::ClientCmd( FALSE, "touch_sidezone 0.06\n" );
EngFuncs::ClientCmd( FALSE, "touch_grid 1\n" );
EngFuncs::ClientCmd( FALSE, "touch_grid_count 50\n" );
EngFuncs::ClientCmd( FALSE, "touch_nonlinear_look 0\n" );
EngFuncs::ClientCmd( FALSE, "touch_pow_factor 1.3\n" );
EngFuncs::ClientCmd( FALSE, "touch_pow_mult 400\n" );
EngFuncs::ClientCmd( TRUE, "touch_exp_mult 0\n" );
GetConfig();
}
/*
=================
UI_TouchOptions_Init
=================
*/
void CMenuTouchOptions::_Init( void )
{
banner.SetPicture(ART_BANNER);
done.SetNameAndStatus( "Done", "Go back to the Touch Menu" );
done.SetPicture( PC_DONE );
done.onActivated = VoidCb( &CMenuTouchOptions::SaveAndPopMenu );
lookX.SetNameAndStatus( "Look X", "Horizontal look sensitivity" );
lookX.Setup( 50, 500, 5 );
lookX.LinkCvar( "touch_yaw" );
lookY.SetNameAndStatus( "Look Y", "Vertical look sensitivity" );
lookY.Setup( 50, 500, 5 );
lookY.LinkCvar( "touch_pitch" );
moveX.SetNameAndStatus( "Side", "Side move sensitivity" );
moveX.Setup( 0.02, 1.0, 0.05 );
moveX.LinkCvar( "touch_sidezone" );
moveY.SetNameAndStatus( "Forward", "Forward move sensitivity" );
moveY.Setup( 0.02, 1.0, 0.05 );
moveY.LinkCvar( "touch_forwardzone" );
gridsize.szStatusText = "Set grid size";
gridsize.Setup( 25, 100, 5 );
gridsize.LinkCvar( "touch_grid_count", CMenuEditable::CVAR_VALUE );
grid.SetNameAndStatus( "Grid", "Enable/disable grid" );
grid.LinkCvar( "touch_grid_enable" );
enable.SetNameAndStatus( "Enable touch", "enable/disable touch controls" );
enable.LinkCvar( "touch_enable" );
nomouse.SetNameAndStatus( "Ignore Mouse", "Ignore mouse input" );
nomouse.LinkCvar( "m_ignore" );
acceleration.SetNameAndStatus( "Enable acceleration", "Nonlinear looking (touch_nonlinear_look)");
acceleration.LinkCvar( "touch_nonlinear_look" );
power.SetNameAndStatus( "Power factor", "Power acceleration factor (touch_pow_factor)" );
power.Setup( 1, 1.7, 0.05 );
power.LinkCvar( "touch_pow_factor" );
multiplier.SetNameAndStatus( "Power multiplier", "Pre-multiplier for pow (touch_pow_mult)" );
multiplier.Setup( 100, 1000, 1 );
multiplier.LinkCvar( "touch_pow_mult" );
exponent.SetNameAndStatus( "Exponent", "Exponent factor, more agressive (touch_exp_mult)" );
exponent.Setup( 0, 100, 1 );
exponent.LinkCvar( "touch_exp_mult" );
profiles.SetModel( &model );
UpdateProfilies();
profiles.onChanged = VoidCb( &CMenuTouchOptions::UpdateProfilies );
profilename.szName = "New Profile:";
profilename.iMaxLength = 16;
reset.SetNameAndStatus( "Reset", "Reset sensitivity settings" );
reset.SetPicture("gfx/shell/btn_touch_reset");
reset.onActivated = VoidCb( &CMenuTouchOptions::ResetMsgBox );
remove.SetNameAndStatus( "Delete", "Delete saved game" );
remove.SetPicture( PC_DELETE );
remove.onActivated = VoidCb( &CMenuTouchOptions::DeleteMsgBox );
apply.SetNameAndStatus( "Activate", "Apply selected profile" );
apply.SetPicture( PC_ACTIVATE );
apply.onActivated = VoidCb( &CMenuTouchOptions::Apply );
save.SetNameAndStatus( "Save", "Save new profile" );
save.SetPicture("gfx/shell/btn_touch_save");
save.onActivated = VoidCb( &CMenuTouchOptions::Save );
msgBox.SetPositiveButton( "Ok", PC_OK );
msgBox.Link( this );
AddItem( background );
AddItem( banner );
AddItem( done );
AddItem( lookX );
AddItem( lookY );
AddItem( moveX );
AddItem( moveY );
AddItem( reset );
AddItem( profiles );
AddItem( save );
AddItem( profilename );
AddItem( remove );
AddItem( apply );
AddItem( grid );
AddItem( gridsize );
AddItem( enable );
AddItem( nomouse );
AddItem( acceleration );
AddItem( power );
AddItem( multiplier );
AddItem( exponent );
}
void CMenuTouchOptions::_VidInit( void )
{
int sliders_x = 72;
int sliders_w = 210;
int profile_x = 330;
int profile_w = 320 + uiStatic.width - 1024;
int other_x = 680 + uiStatic.width - 1024;
lookX.SetCoord( sliders_x, 280 );
lookY.SetCoord( sliders_x, 340 );
moveX.SetCoord( sliders_x, 400 );
moveY.SetCoord( sliders_x, 460 );
gridsize.SetRect( sliders_x, 580, sliders_w, 30 );
grid.SetCoord( sliders_x, 520 );
done.SetCoord ( sliders_x, 680 );
reset.SetCoord( sliders_x, 630 );
profiles.SetRect( profile_x, 230, profile_w, 270 );
profilename.SetRect( profile_x, 610, 205, 32 );
save.SetCoord( profile_x + 220, 610 );
remove.SetCoord( profile_x + profile_w - 120, 510 );
remove.size.w = 100;
apply.SetCoord( profile_x + 30, 510 );
apply.size.w = 120;
enable.SetCoord( other_x, 255 );
nomouse.SetCoord( other_x, 305 );
acceleration.SetCoord( other_x, 355 );
power.SetCoord( other_x, 455 );
multiplier.SetCoord( other_x, 555 );
exponent.SetCoord( other_x, 655 );
}
/*
=================
UI_TouchOptions_Precache
=================
*/
void UI_TouchOptions_Precache( void )
{
EngFuncs::PIC_Load( ART_BANNER );
}
/*
=================
UI_TouchOptions_Menu
=================
*/
void UI_TouchOptions_Menu( void )
{
uiTouchOptions.Show();
}
ADD_MENU( menu_touchoptions, UI_TouchOptions_Precache, UI_TouchOptions_Menu );
}