]> git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/preferences.h
Add support for W:ET to the game setup dialog
[xonotic/netradiant.git] / radiant / preferences.h
1 /*
2    Copyright (C) 1999-2007 id Software, Inc. and contributors.
3    For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5    This file is part of GtkRadiant.
6
7    GtkRadiant is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    GtkRadiant is distributed in the hope that it will be useful,
13    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 GtkRadiant; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21
22 #ifndef _PREFERENCES_H_
23 #define _PREFERENCES_H_
24
25 #include "dialog.h"
26 #include "gtkr_list.h"
27 //#include "profile.h"
28
29 #ifdef _WIN32
30 #define NVIDIA_AERO_HACK
31 #endif
32
33 #define MAX_TEXTURE_QUALITY 3
34
35 enum PrefTypes_t
36 {
37         PREF_STR,
38         PREF_INT,
39         PREF_BOOL,
40         PREF_FLOAT,
41         PREF_VEC3,
42         PREF_WNDPOS,
43 };
44
45 /*!
46    a preference assignment, name, type and pointer to value
47    we don't store the xmlNodePtr because the document itself can be thrown away upon any LoadPref
48    (see CGameDialog::UpdatePrefTree)
49  */
50 class CPrefAssignment
51 {
52 public:
53 Str mName;
54 PrefTypes_t mType;
55 void *mVal;
56
57 CPrefAssignment( const char *name, PrefTypes_t Type, void *Val ){
58         mName = name; mType = Type; mVal = Val;
59 }
60 CPrefAssignment() { mVal = NULL; }
61 CPrefAssignment( const CPrefAssignment& ass );
62 virtual ~CPrefAssignment() { }
63 virtual CPrefAssignment& operator =( const CPrefAssignment& ass );
64 };
65
66
67 /*!
68    generic preferences storage class, using xml files
69  */
70 class CXMLPropertyBag
71 {
72 private:
73 /*!
74    local prefs file
75  */
76 xmlDocPtr mpDoc;
77 xmlNodePtr mpDocNode;
78
79 /*!
80    prefs assignments (what pref name, what type, what variable)
81  */
82 list<CPrefAssignment> mPrefAssignments;
83
84 /*!
85    name of file to load/save as
86  */
87 Str mStrFilename;
88
89 /*!
90    store assignment in the property list if not already there
91  */
92 void PushAssignment( const char *name, PrefTypes_t type, void *pV );
93
94 /*!
95    find the xmlnode relating to the epair name
96  */
97 xmlNodePtr EpairForName( const char *name );
98
99 public:
100 CXMLPropertyBag();
101 virtual ~CXMLPropertyBag(){
102         if ( InUse() ) {
103                 Clear();
104         }
105 };
106
107 /*!
108    read a pref setting, if doesn't exist, will add it to the xml tree (using default value provided)
109    \arg name the name of the pref
110    \arg pV pointer to the value
111    \arg V default value
112    those functions will fill in the list of preferences assignments
113    (name, type and pointer to value)
114    this is used in UpdatePrefTree
115  */
116 void GetPref( const char *name, Str *pV, const char *V );
117 void GetPref( const char *name, int *pV, int V );
118 void GetPref( const char *name, bool *pV, bool V );
119 void GetPref( const char *name, float *pV, float V );
120 void GetPref( const char *name, float *pV, float* V );
121 void GetPref( const char *name, window_position_t* pV, window_position_t V );
122
123 /*!
124    returns whether or not the property bag is already open
125  */
126 qboolean InUse() { return ( mpDoc != NULL ); };
127
128 /*!
129    unload the xml doc, and free the tree
130  */
131 void Clear();
132
133 /*|
134    read data from our XML file
135  */
136 void ReadXMLFile( const char* pFilename );
137
138 /*|
139    write out the property bag to an XML data file
140    return is success/fail
141  */
142 qboolean WriteXMLFile( const char* pFilename );
143
144 /*!
145    update the xml tree with data form the property list, usually in preparation for a write
146  */
147 void UpdatePrefTree();
148
149 /*!
150    did the file have any data or not?
151  */
152 qboolean mbEmpty;
153 };
154
155 /*!
156    holds information for a given game
157    I'm a bit unclear on that still
158    it holds game specific configuration stuff
159    such as base names, engine names, some game specific features to activate in the various modules
160    it is not strictly a prefs thing since the user is not supposed to edit that (unless he is hacking
161    support for a new game)
162
163    what we do now is fully generate the information for this during the setup. We might want to
164    generate a piece that just says "the game pack is there", but put the rest of the config somwhere
165    else (i.e. not generated, copied over during setup .. for instance in the game tools directory)
166  */
167 class CGameDescription
168 {
169 public:
170 xmlDocPtr mpDoc;   ///< the game description xml tree
171 Str mGameToolsPath;   ///< the explicit path to the game-dependent modules
172 Str mGameName;   ///< name of the game used in dialogs
173 Str mGameFile;   ///< the .game file that describes this game
174 Str mBaseGame;   ///< basegame directory
175 Str mEnginePath;   ///< path to the engine
176 Str mEngine;   ///< engine name
177 Str mMultiplayerEngine;   ///< engine name
178 #if defined ( __linux__ ) || defined ( __APPLE__ )
179 Str mUserPathPrefix;   ///< prefix for ~/.q3a ~/.wolf init, only on *nix
180 #endif
181 Str mShaderPath;   ///< the path in which to look for shaders
182 Str mShaderlist;   ///< shaderlist file
183 float mTextureDefaultScale;   ///< default scale (0.5 in q3, 1.0 in q1/q2, 0.25 in JK2 ..)
184 bool mEClassSingleLoad;   ///< only load a single eclass definition file
185 bool mNoPatch;   ///< this game doesn't support patch technology
186 Str mCaulkShader;   ///< the shader to use for caulking
187 bool quake2;   ///< set this to true to get quake2
188 bool noMapsInHome;   ///< set this if you want to open the engine path/base dir/maps dir for map open/save dialoges */
189
190 CGameDescription() { mpDoc = NULL; }
191 /*!
192    \todo parse basic info from the node
193    user-friendly name of the game
194    essential parameters (such as the start dir)
195  */
196 CGameDescription( xmlDocPtr pDoc, const Str &GameFile );
197 virtual ~CGameDescription() { xmlFreeDoc( mpDoc ); }
198
199 void Dump();
200 };
201
202 /*!
203    select games, copy editing assets and write out configuration files
204  */
205
206 #define Q3_PACK "Q3Pack"
207 #define URT_PACK "UrTPack"
208 #define UFOAI_PACK "UFOAIPack"
209 #define Q2W_PACK "Q2WPack"
210 #define WARSOW_PACK "WarsowPack"
211 #define NEXUIZ_PACK "NexuizPack"
212 #define Q2_PACK "Q2Pack"
213 #define TREMULOUS_PACK "TremulousPack"
214 #define JA_PACK "JAPack"
215 #define REACTION_PACK "ReactionPack"
216 #define ET_PACK "ETPack"
217
218 class CGameInstall : public Dialog {
219 public:
220 CGameInstall();
221 void ScanGames();
222 void Run();
223 void BuildDialog();
224
225 static void OnBtnBrowseEngine( GtkWidget *widget, gpointer data );
226 static void OnGameSelectChanged( GtkWidget *widget, gpointer data );
227
228 enum gameType_e {
229         GAME_NONE = 0,
230         GAME_Q3 = 1,
231         GAME_URT,
232         GAME_UFOAI,
233         GAME_Q2W,
234         GAME_WARSOW,
235         GAME_NEXUIZ,
236         GAME_Q2,
237         GAME_TREMULOUS,
238         GAME_JA,
239         GAME_REACTION,
240         GAME_ET,
241         GAME_COUNT
242 };
243
244 protected:
245 Str m_strName;
246 Str m_strMod;
247 Str m_strEngine;
248 int m_nComboSelect;
249
250 // maps from m_nComboSelect to the games
251 int m_availGames[GAME_COUNT];
252 };
253
254 /*!
255    standalone dialog for games selection, and more generally global settings
256  */
257 class CGameDialog : public Dialog
258 {
259 GtkWidget *mFrame;   ///< this is built on-demand first time it's used
260 GtkWidget *mTopBox;   ///< top level box used to store the dialog frame, must unhook after modal use
261
262 GtkComboBox   *mGameCombo;      // combo box holds the selection of available game
263
264 /*!
265    global prefs storage
266  */
267 CXMLPropertyBag mGlobalPrefs;
268
269 #ifdef _WIN32
270 /*!
271    run from a network share
272    this one is not being saved out in prefs, since we need to know before we load prefs
273    we use a dummy file NETRUN_FILENAME as flag
274    all done with static stuff
275  */
276 static bool m_bNetRun;
277 #endif
278
279 bool m_bDoGameInstall;
280
281 CGameInstall mGameInstall;
282
283 protected:
284
285 int m_nComboSelect;   ///< intermediate int value for combo in dialog box
286
287 public:
288
289 /*!
290    those settings are saved in the global prefs file
291    I'm too lazy to wrap behind protected access, not sure this needs to be public
292    NOTE: those are preference settings. if you change them it is likely that you would
293    have to restart the editor for them to take effect
294  */
295 /*@{*/
296 /*!
297    what game has been selected
298    this is the name of the .game file
299  */
300 Str m_sGameFile;
301 /*!
302    auto-load the game on startup
303    this is linked to auto-load checkbox
304  */
305 bool m_bAutoLoadGame;
306 /*!
307    log console to radiant.log
308    m_bForceLogConsole is an obscure forced latching situation
309  */
310 bool m_bLogConsole;
311 bool m_bForceLogConsole;
312 /*@}*/
313
314 /*!
315    points somewhere in mGames, set once at startup
316  */
317 CGameDescription *m_pCurrentGameDescription;
318
319 /*!
320    the list of game descriptions we scanned from the game/ dir
321  */
322 list<CGameDescription *> mGames;
323
324 CGameDialog() {
325         mFrame = NULL;
326         m_pCurrentGameDescription = NULL;
327         m_bLogConsole = false;
328         m_bForceLogConsole = false;
329         m_bDoGameInstall = true;    // go through DoModal at least once
330         mGameCombo = NULL;
331 }
332 virtual ~CGameDialog();
333
334 void AddPacksURL( Str &s );
335
336 /*!
337    intialize the game dialog, called at CPrefsDlg::Init
338    will scan for games, load prefs, and do game selection dialog if needed
339  */
340 void Init();
341
342 /*!
343    reset the global settings by removing the file
344  */
345 void Reset();
346
347 /*!
348    run the dialog UI for the list of games
349  */
350 void DoGameDialog();
351
352 /*!
353    call out to the game installation dialog
354  */
355 void DoGameInstall();
356
357 /*!
358    Dialog API
359    this is only called when the dialog is built at startup for main engine select
360  */
361 void BuildDialog();
362 void UpdateData( bool retrieve );
363
364 /*!
365    construction of the dialog frame
366    this is the part to be re-used in prefs dialog
367    for the standalone dialog, we include this in a modal box
368    for prefs, we hook the frame in the main notebook
369    build the frame on-demand (only once)
370  */
371 GtkWidget *GetGlobalFrame();
372
373 /*!
374    global preferences subsystem
375    XML-based this time, hopefully this will generalize to other prefs
376    LoadPrefs has hardcoded defaults
377    NOTE: it may not be strictly 'CGameDialog' to put the global prefs here
378    could have named the class differently I guess
379  */
380 /*@{*/
381 void LoadPrefs();   ///< load from file into variables
382 void SavePrefs();   ///< save pref variables to file
383 /*@}*/
384
385 /*!
386    read or set netrun (check file)
387    \param retrieve
388    if false, will check if netrun file is present and will set m_bNetRun
389    if true, will create/erase the netrun file depending on m_bNetRun
390    NOTE: this is not backwards, 'retrieve' means 'retrieve from settings dialog' - in terms of UI
391  */
392 static void UpdateNetrun( bool retrieve );
393 /*!
394    get current netrun setting
395  */
396 static bool GetNetrun();
397
398 private:
399 /*!
400    scan for .game files, load them
401  */
402 void ScanForGames();
403
404 /*!
405    inits g_PrefsDlg.m_global_rc_path
406  */
407 void InitGlobalPrefPath();
408
409 /*!
410    uses m_nComboItem to find the right mGames
411  */
412 CGameDescription *GameDescriptionForComboItem();
413
414 /*!
415    callback for the game install button
416  */
417 static void SInstallCallback( GtkWidget *widget, gpointer data );
418
419 void UpdateGameCombo();
420 };
421
422 typedef struct {
423         int nEntitySplit1;
424         int nEntitySplit2;
425
426         window_position_t position;
427
428         window_position_t posEntityWnd;
429         window_position_t posMapInfoWnd;
430         window_position_t posCamWnd;
431         window_position_t posZWnd;
432         window_position_t posXYWnd;
433         window_position_t posXZWnd;
434         window_position_t posYZWnd;
435         window_position_t posPatchWnd;
436         window_position_t posSurfaceWnd;
437         window_position_t posEntityInfoWnd;
438
439         int nXYHeight;
440         int nZWidth;
441         int nXYWidth;
442         int nCamWidth;
443         int nCamHeight;
444         int nZFloatWidth;
445         int nState;
446 } windowPosInfo_t;
447
448 class PrefsDlg : public Dialog
449 {
450
451 public:
452 /*!
453    local prefs file
454  */
455 CXMLPropertyBag mLocalPrefs;
456
457 // will enable/disable stuff according to the situation
458 void DoSensitivity();
459 void PreModal() { DoSensitivity(); }
460
461 // enable/disable custom editor entry
462 void DoEditorSensitivity();
463
464 /*!
465    this holds global level preferences
466  */
467 CGameDialog mGamesDialog;
468 protected:
469 // warning about old project files
470 bool m_bWarn;
471 list<CGameDescription *> mGames;
472
473 public:
474 // last light intensity used in the CLightPrompt dialog, stored in registry
475 int m_iLastLightIntensity;
476 // these mirror what goes in the combo box
477 // see PrefDlg::m_nShader, tells wether to load NONE / COMMON or ALL shaders at parsing stage
478 enum {SHADER_NONE = 0, SHADER_COMMON, SHADER_ALL};
479
480 // Gef: updated preferences dialog
481 /*! Preference notebook page numbers */
482 enum {PTAB_FRONT = 0, PTAB_GAME_SETTINGS, PTAB_2D, PTAB_CAMERA, PTAB_TEXTURE, PTAB_LAYOUT, PTAB_MOUSE,
483           PTAB_EDITING, PTAB_STARTUP, PTAB_PATHS, PTAB_BRUSH, PTAB_MISC, PTAB_BSPMONITOR} pref_tabs;
484
485 GtkWidget *notebook;
486
487 void UpdateTextureCompression();
488
489 #ifdef ATIHACK_812
490 void UpdateATIHack();
491 #endif
492
493 #ifdef NVIDIA_AERO_HACK
494 void UpdateNvidiaAeroHack();
495 #endif
496
497 void LoadPrefs();
498 void SavePrefs();
499 void LoadTexdefPref( texdef_t* pTexdef, const char* pName );
500
501 PrefsDlg ();
502 virtual ~PrefsDlg (){
503         g_string_free( m_rc_path, true );
504         g_string_free( m_inipath, true );
505 }
506
507 /*!
508    path for global settings
509    win32: g_strAppPath
510    linux: ~/.radiant/<version>/
511  */
512 GString *m_global_rc_path;
513
514 /*!
515    path to per-game settings
516    used for various game dependant storage
517    win32: g_strGameToolsPath
518    linux: ~/.radiant/<version>/<gamename>/
519  */
520 GString *m_rc_path;
521
522 /*!
523    holds per-game settings
524    m_rc_path+"local.pref"
525    \todo FIXME at some point this should become XML property bag code too
526  */
527 GString *m_inipath;
528
529 // initialize the above paths
530 void Init();
531
532 #if 0
533 // DEPRECATED: use engine path from the current game description instead
534 // path to the top-level installation
535 Str m_strEnginePath;
536 // name of executable
537 // quake2 quake3 etc
538 Str m_strEngine;
539 // we use this Str to store the full path to the engine: m_strEnginePath + m_strEngine
540 // it's not stored in the registry or anything, just ued for display in prefs
541 Str m_strPrefsDlgEngine;
542 #endif
543
544 // Dialog Data
545 int m_nMouse;
546 MainFrame::EViewStyle m_nView;
547 bool m_bTextureLock;
548 bool m_bLoadLast;
549 // path to the project loaded at startup
550 // if g_PrefsDlg can't find the information in the ini file
551 // it will try to guess and eventually ask the user
552 Str m_strLastProject;
553 /*!
554    version of last loaded project file
555    says -1 if there's no version loaded
556    if it's a manually constructed project file, will be 0
557    otherwise the actual 'version' epair
558  */
559 int m_nLastProjectVer;
560 Str m_strLastMap;
561 bool m_bInternalBSP;
562 bool m_bRightClick;
563 bool m_bSetGame;
564 bool m_bAutoSave;
565 bool m_bLoadLastMap;
566 bool m_bTextureWindow;
567 bool m_bSnapShots;
568 float m_fTinySize;
569 bool m_bCleanTiny;
570 bool m_bCamXYUpdate;
571 int m_nCamDragMultiSelect;
572 bool m_bCamDragMultiSelect;
573 bool m_bCamFreeLook;
574 bool m_bCamFreeLookStrafe;
575 bool m_bCamInverseMouse;
576 bool m_bCamDiscrete;
577 bool m_bNewLightDraw;
578 Str m_strPrefabPath;
579 int m_nWhatGame;
580 bool m_bALTEdge;
581 bool m_bFaceColors;
582 bool m_bXZVis;
583 bool m_bYZVis;
584 bool m_bZVis;
585 bool m_bSizePaint;
586 bool m_bDLLEntities;
587 bool m_bRotateLock;
588 bool m_bDetachableMenus;
589 bool m_bPatchToolbar;
590 bool m_bWideToolbar;
591 bool m_bPluginToolbar;
592 bool m_bNoClamp;
593 //++timo this is most likely broken, I don't know what it's supposed to do
594 bool m_bSnap;
595 Str m_strUserPath;
596 int m_nRotation;
597 bool m_bChaseMouse;
598 bool m_bTextureScrollbar;
599 bool m_bDisplayLists;
600 bool m_bAntialiasedPointsAndLines;    // Fishman - Add antialiazed points and lines support. 09/03/00
601 bool m_bShowShaders;
602 int m_nShader;
603 bool m_bNoStipple;
604 int m_nUndoLevels;
605 bool m_bVertexSplit;
606
607 int m_nMouseButtons;
608 int m_nAngleSpeed;
609 int m_nMoveSpeed;
610 int m_nAutoSave;
611 bool m_bCubicClipping;
612 int m_nCubicScale;
613 bool m_bSelectCurves;
614 bool m_bSelectModels;
615 int m_nEntityShowState;
616 int m_nTextureScale;
617 bool m_bNormalizeColors;
618 bool m_bSwitchClip;
619 bool m_bSelectWholeEntities;
620 int m_nTextureQuality;
621 bool m_bGLLighting;
622 bool m_bTexturesShaderlistOnly;
623 int m_nSubdivisions;
624 float m_fDefTextureScale;
625 bool m_bFloatingZ;
626 bool m_bLatchedFloatingZ;
627 // Gef: Kyro GL_POINT workaround
628 bool m_bGlPtWorkaround;
629
630 // how many menus in the texture thing before we split?
631 int m_nTextureMenuSplit;
632
633 // watch the BSP process through network connections
634 // true: trigger the BSP steps one by one and monitor them through the network
635 // false: create a BAT / .sh file and execute it. don't bother monitoring it.
636 bool m_bWatchBSP;
637 // do we stop the compilation process if we come accross a leak?
638 bool m_bLeakStop;
639 // timeout when beginning a step (in seconds)
640 // if we don't get a connection quick enough we assume something failed and go back to idling
641 int m_iTimeout;
642 bool m_bRunQuake;
643 // store prefs setting for automatic sleep mode activation
644 bool m_bDoSleep;
645
646 bool m_bClipCaulk;
647
648 // make the texture increments match the grid changes
649 bool m_bSnapTToGrid;
650
651 // try to fix the target/targetname conflicts when importing a map (default true)
652 bool m_bDoTargetFix;
653
654 // the increment step we use against the wheel mouse
655 int m_nWheelInc;
656
657 #ifdef _WIN32
658 // use the file associations to open files instead of builtin Gtk editor
659 bool m_bUseWin32Editor;
660 #else
661 // custom shader editor
662 bool m_bUseCustomEditor;
663 Str m_strEditorCommand;     // this is the command executed
664 #endif
665
666 #ifdef _WIN32
667 bool m_bNativeGUI;
668 bool m_bStartOnPrimMon;
669 #endif
670
671 bool m_bPatchBBoxSelect;
672
673 // RR2DO2: latched data, for settings that require a restart. We don't want to set
674 // these directly in case users set them under preferences and then continue working
675 // with the editor.
676 MainFrame::EViewStyle m_nLatchedView;
677 int m_nMRUCount;
678 Str m_strMRUFiles[4];
679
680 windowPosInfo_t mWindowInfo;
681
682 bool m_bLatchedDetachableMenus;
683 bool m_bLatchedPatchToolbar;
684 bool m_bLatchedWideToolbar;
685 bool m_bLatchedPluginToolbar;
686 int m_nLatchedShader;
687 int m_nLatchedTextureQuality;
688
689 // RIANT
690 // texture compression format
691 int m_nTextureCompressionFormat;
692
693 int m_nLightRadiuses;
694
695 bool m_bQ3Map2Texturing;
696
697 #ifdef ATIHACK_812
698 bool m_bGlATIHack;
699 #endif
700
701 #ifdef NVIDIA_AERO_HACK
702 bool m_bGlNvidiaAeroHack;
703 int m_bGlNvidiaAeroHackPrevState;
704 #endif
705
706 void UpdateData( bool retrieve );
707
708 /*! Utility function for swapping notebook pages for tree list selections */
709 void showPrefPage( int prefpage );
710
711 protected:
712 /*! Scan for game description files and build a list */
713 void ScanForGames();
714
715 /*! Dialog API */
716 void BuildDialog();
717 void PostModal( int code );
718 };
719
720 #endif // _PREFERENCES_H_