]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/preferences.h
Merge pull request #47 from mrwonko/MapLoading
[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
217 class CGameInstall : public Dialog {
218 public:
219 CGameInstall();
220 void ScanGames();
221 void Run();
222 void BuildDialog();
223
224 static void OnBtnBrowseEngine( GtkWidget *widget, gpointer data );
225 static void OnGameSelectChanged( GtkWidget *widget, gpointer data );
226
227 enum gameType_e {
228         GAME_NONE = 0,
229         GAME_Q3 = 1,
230         GAME_URT,
231         GAME_UFOAI,
232         GAME_Q2W,
233         GAME_WARSOW,
234         GAME_NEXUIZ,
235         GAME_Q2,
236         GAME_TREMULOUS,
237         GAME_JA,
238         GAME_REACTION,
239         GAME_COUNT
240 };
241
242 protected:
243 Str m_strName;
244 Str m_strMod;
245 Str m_strEngine;
246 int m_nComboSelect;
247
248 // maps from m_nComboSelect to the games
249 int m_availGames[GAME_COUNT];
250 };
251
252 /*!
253    standalone dialog for games selection, and more generally global settings
254  */
255 class CGameDialog : public Dialog
256 {
257 GtkWidget *mFrame;   ///< this is built on-demand first time it's used
258 GtkWidget *mTopBox;   ///< top level box used to store the dialog frame, must unhook after modal use
259
260 GtkComboBox   *mGameCombo;      // combo box holds the selection of available game
261
262 /*!
263    global prefs storage
264  */
265 CXMLPropertyBag mGlobalPrefs;
266
267 #ifdef _WIN32
268 /*!
269    run from a network share
270    this one is not being saved out in prefs, since we need to know before we load prefs
271    we use a dummy file NETRUN_FILENAME as flag
272    all done with static stuff
273  */
274 static bool m_bNetRun;
275 #endif
276
277 bool m_bDoGameInstall;
278
279 CGameInstall mGameInstall;
280
281 protected:
282
283 int m_nComboSelect;   ///< intermediate int value for combo in dialog box
284
285 public:
286
287 /*!
288    those settings are saved in the global prefs file
289    I'm too lazy to wrap behind protected access, not sure this needs to be public
290    NOTE: those are preference settings. if you change them it is likely that you would
291    have to restart the editor for them to take effect
292  */
293 /*@{*/
294 /*!
295    what game has been selected
296    this is the name of the .game file
297  */
298 Str m_sGameFile;
299 /*!
300    auto-load the game on startup
301    this is linked to auto-load checkbox
302  */
303 bool m_bAutoLoadGame;
304 /*!
305    log console to radiant.log
306    m_bForceLogConsole is an obscure forced latching situation
307  */
308 bool m_bLogConsole;
309 bool m_bForceLogConsole;
310 /*@}*/
311
312 /*!
313    points somewhere in mGames, set once at startup
314  */
315 CGameDescription *m_pCurrentGameDescription;
316
317 /*!
318    the list of game descriptions we scanned from the game/ dir
319  */
320 list<CGameDescription *> mGames;
321
322 CGameDialog() {
323         mFrame = NULL;
324         m_pCurrentGameDescription = NULL;
325         m_bLogConsole = false;
326         m_bForceLogConsole = false;
327         m_bDoGameInstall = true;    // go through DoModal at least once
328         mGameCombo = NULL;
329 }
330 virtual ~CGameDialog();
331
332 void AddPacksURL( Str &s );
333
334 /*!
335    intialize the game dialog, called at CPrefsDlg::Init
336    will scan for games, load prefs, and do game selection dialog if needed
337  */
338 void Init();
339
340 /*!
341    reset the global settings by removing the file
342  */
343 void Reset();
344
345 /*!
346    run the dialog UI for the list of games
347  */
348 void DoGameDialog();
349
350 /*!
351    call out to the game installation dialog
352  */
353 void DoGameInstall();
354
355 /*!
356    Dialog API
357    this is only called when the dialog is built at startup for main engine select
358  */
359 void BuildDialog();
360 void UpdateData( bool retrieve );
361
362 /*!
363    construction of the dialog frame
364    this is the part to be re-used in prefs dialog
365    for the standalone dialog, we include this in a modal box
366    for prefs, we hook the frame in the main notebook
367    build the frame on-demand (only once)
368  */
369 GtkWidget *GetGlobalFrame();
370
371 /*!
372    global preferences subsystem
373    XML-based this time, hopefully this will generalize to other prefs
374    LoadPrefs has hardcoded defaults
375    NOTE: it may not be strictly 'CGameDialog' to put the global prefs here
376    could have named the class differently I guess
377  */
378 /*@{*/
379 void LoadPrefs();   ///< load from file into variables
380 void SavePrefs();   ///< save pref variables to file
381 /*@}*/
382
383 /*!
384    read or set netrun (check file)
385    \param retrieve
386    if false, will check if netrun file is present and will set m_bNetRun
387    if true, will create/erase the netrun file depending on m_bNetRun
388    NOTE: this is not backwards, 'retrieve' means 'retrieve from settings dialog' - in terms of UI
389  */
390 static void UpdateNetrun( bool retrieve );
391 /*!
392    get current netrun setting
393  */
394 static bool GetNetrun();
395
396 private:
397 /*!
398    scan for .game files, load them
399  */
400 void ScanForGames();
401
402 /*!
403    inits g_PrefsDlg.m_global_rc_path
404  */
405 void InitGlobalPrefPath();
406
407 /*!
408    uses m_nComboItem to find the right mGames
409  */
410 CGameDescription *GameDescriptionForComboItem();
411
412 /*!
413    callback for the game install button
414  */
415 static void SInstallCallback( GtkWidget *widget, gpointer data );
416
417 void UpdateGameCombo();
418 };
419
420 typedef struct {
421         int nEntitySplit1;
422         int nEntitySplit2;
423
424         window_position_t position;
425
426         window_position_t posEntityWnd;
427         window_position_t posMapInfoWnd;
428         window_position_t posCamWnd;
429         window_position_t posZWnd;
430         window_position_t posXYWnd;
431         window_position_t posXZWnd;
432         window_position_t posYZWnd;
433         window_position_t posPatchWnd;
434         window_position_t posSurfaceWnd;
435         window_position_t posEntityInfoWnd;
436
437         int nXYHeight;
438         int nZWidth;
439         int nXYWidth;
440         int nCamWidth;
441         int nCamHeight;
442         int nZFloatWidth;
443         int nState;
444 } windowPosInfo_t;
445
446 class PrefsDlg : public Dialog
447 {
448
449 public:
450 /*!
451    local prefs file
452  */
453 CXMLPropertyBag mLocalPrefs;
454
455 // will enable/disable stuff according to the situation
456 void DoSensitivity();
457 void PreModal() { DoSensitivity(); }
458
459 // enable/disable custom editor entry
460 void DoEditorSensitivity();
461
462 /*!
463    this holds global level preferences
464  */
465 CGameDialog mGamesDialog;
466 protected:
467 // warning about old project files
468 bool m_bWarn;
469 list<CGameDescription *> mGames;
470
471 public:
472 // last light intensity used in the CLightPrompt dialog, stored in registry
473 int m_iLastLightIntensity;
474 // these mirror what goes in the combo box
475 // see PrefDlg::m_nShader, tells wether to load NONE / COMMON or ALL shaders at parsing stage
476 enum {SHADER_NONE = 0, SHADER_COMMON, SHADER_ALL};
477
478 // Gef: updated preferences dialog
479 /*! Preference notebook page numbers */
480 enum {PTAB_FRONT = 0, PTAB_GAME_SETTINGS, PTAB_2D, PTAB_CAMERA, PTAB_TEXTURE, PTAB_LAYOUT, PTAB_MOUSE,
481           PTAB_EDITING, PTAB_STARTUP, PTAB_PATHS, PTAB_BRUSH, PTAB_MISC, PTAB_BSPMONITOR} pref_tabs;
482
483 GtkWidget *notebook;
484
485 void UpdateTextureCompression();
486
487 #ifdef ATIHACK_812
488 void UpdateATIHack();
489 #endif
490
491 #ifdef NVIDIA_AERO_HACK
492 void UpdateNvidiaAeroHack();
493 #endif
494
495 void LoadPrefs();
496 void SavePrefs();
497 void LoadTexdefPref( texdef_t* pTexdef, const char* pName );
498
499 PrefsDlg ();
500 virtual ~PrefsDlg (){
501         g_string_free( m_rc_path, true );
502         g_string_free( m_inipath, true );
503 }
504
505 /*!
506    path for global settings
507    win32: g_strAppPath
508    linux: ~/.radiant/<version>/
509  */
510 GString *m_global_rc_path;
511
512 /*!
513    path to per-game settings
514    used for various game dependant storage
515    win32: g_strGameToolsPath
516    linux: ~/.radiant/<version>/<gamename>/
517  */
518 GString *m_rc_path;
519
520 /*!
521    holds per-game settings
522    m_rc_path+"local.pref"
523    \todo FIXME at some point this should become XML property bag code too
524  */
525 GString *m_inipath;
526
527 // initialize the above paths
528 void Init();
529
530 #if 0
531 // DEPRECATED: use engine path from the current game description instead
532 // path to the top-level installation
533 Str m_strEnginePath;
534 // name of executable
535 // quake2 quake3 etc
536 Str m_strEngine;
537 // we use this Str to store the full path to the engine: m_strEnginePath + m_strEngine
538 // it's not stored in the registry or anything, just ued for display in prefs
539 Str m_strPrefsDlgEngine;
540 #endif
541
542 // Dialog Data
543 int m_nMouse;
544 MainFrame::EViewStyle m_nView;
545 bool m_bTextureLock;
546 bool m_bLoadLast;
547 // path to the project loaded at startup
548 // if g_PrefsDlg can't find the information in the ini file
549 // it will try to guess and eventually ask the user
550 Str m_strLastProject;
551 /*!
552    version of last loaded project file
553    says -1 if there's no version loaded
554    if it's a manually constructed project file, will be 0
555    otherwise the actual 'version' epair
556  */
557 int m_nLastProjectVer;
558 Str m_strLastMap;
559 bool m_bInternalBSP;
560 bool m_bRightClick;
561 bool m_bSetGame;
562 bool m_bAutoSave;
563 bool m_bLoadLastMap;
564 bool m_bTextureWindow;
565 bool m_bSnapShots;
566 float m_fTinySize;
567 bool m_bCleanTiny;
568 bool m_bCamXYUpdate;
569 int m_nCamDragMultiSelect;
570 bool m_bCamDragMultiSelect;
571 bool m_bCamFreeLook;
572 bool m_bCamFreeLookStrafe;
573 bool m_bCamInverseMouse;
574 bool m_bCamDiscrete;
575 bool m_bNewLightDraw;
576 Str m_strPrefabPath;
577 int m_nWhatGame;
578 bool m_bALTEdge;
579 bool m_bFaceColors;
580 bool m_bXZVis;
581 bool m_bYZVis;
582 bool m_bZVis;
583 bool m_bSizePaint;
584 bool m_bDLLEntities;
585 bool m_bRotateLock;
586 bool m_bDetachableMenus;
587 bool m_bPatchToolbar;
588 bool m_bWideToolbar;
589 bool m_bPluginToolbar;
590 bool m_bNoClamp;
591 //++timo this is most likely broken, I don't know what it's supposed to do
592 bool m_bSnap;
593 Str m_strUserPath;
594 int m_nRotation;
595 bool m_bChaseMouse;
596 bool m_bTextureScrollbar;
597 bool m_bDisplayLists;
598 bool m_bAntialiasedPointsAndLines;    // Fishman - Add antialiazed points and lines support. 09/03/00
599 bool m_bShowShaders;
600 int m_nShader;
601 bool m_bNoStipple;
602 int m_nUndoLevels;
603 bool m_bVertexSplit;
604
605 int m_nMouseButtons;
606 int m_nAngleSpeed;
607 int m_nMoveSpeed;
608 int m_nAutoSave;
609 bool m_bCubicClipping;
610 int m_nCubicScale;
611 bool m_bSelectCurves;
612 bool m_bSelectModels;
613 int m_nEntityShowState;
614 int m_nTextureScale;
615 bool m_bNormalizeColors;
616 bool m_bSwitchClip;
617 bool m_bSelectWholeEntities;
618 int m_nTextureQuality;
619 bool m_bGLLighting;
620 bool m_bTexturesShaderlistOnly;
621 int m_nSubdivisions;
622 float m_fDefTextureScale;
623 bool m_bFloatingZ;
624 bool m_bLatchedFloatingZ;
625 // Gef: Kyro GL_POINT workaround
626 bool m_bGlPtWorkaround;
627
628 // how many menus in the texture thing before we split?
629 int m_nTextureMenuSplit;
630
631 // watch the BSP process through network connections
632 // true: trigger the BSP steps one by one and monitor them through the network
633 // false: create a BAT / .sh file and execute it. don't bother monitoring it.
634 bool m_bWatchBSP;
635 // do we stop the compilation process if we come accross a leak?
636 bool m_bLeakStop;
637 // timeout when beginning a step (in seconds)
638 // if we don't get a connection quick enough we assume something failed and go back to idling
639 int m_iTimeout;
640 bool m_bRunQuake;
641 // store prefs setting for automatic sleep mode activation
642 bool m_bDoSleep;
643
644 bool m_bClipCaulk;
645
646 // make the texture increments match the grid changes
647 bool m_bSnapTToGrid;
648
649 // try to fix the target/targetname conflicts when importing a map (default true)
650 bool m_bDoTargetFix;
651
652 // the increment step we use against the wheel mouse
653 int m_nWheelInc;
654
655 #ifdef _WIN32
656 // use the file associations to open files instead of builtin Gtk editor
657 bool m_bUseWin32Editor;
658 #else
659 // custom shader editor
660 bool m_bUseCustomEditor;
661 Str m_strEditorCommand;     // this is the command executed
662 #endif
663
664 #ifdef _WIN32
665 bool m_bNativeGUI;
666 bool m_bStartOnPrimMon;
667 #endif
668
669 bool m_bPatchBBoxSelect;
670
671 // RR2DO2: latched data, for settings that require a restart. We don't want to set
672 // these directly in case users set them under preferences and then continue working
673 // with the editor.
674 MainFrame::EViewStyle m_nLatchedView;
675 int m_nMRUCount;
676 Str m_strMRUFiles[4];
677
678 windowPosInfo_t mWindowInfo;
679
680 bool m_bLatchedDetachableMenus;
681 bool m_bLatchedPatchToolbar;
682 bool m_bLatchedWideToolbar;
683 bool m_bLatchedPluginToolbar;
684 int m_nLatchedShader;
685 int m_nLatchedTextureQuality;
686
687 // RIANT
688 // texture compression format
689 int m_nTextureCompressionFormat;
690
691 int m_nLightRadiuses;
692
693 bool m_bQ3Map2Texturing;
694
695 #ifdef ATIHACK_812
696 bool m_bGlATIHack;
697 #endif
698
699 #ifdef NVIDIA_AERO_HACK
700 bool m_bGlNvidiaAeroHack;
701 int m_bGlNvidiaAeroHackPrevState;
702 #endif
703
704 void UpdateData( bool retrieve );
705
706 /*! Utility function for swapping notebook pages for tree list selections */
707 void showPrefPage( int prefpage );
708
709 protected:
710 /*! Scan for game description files and build a list */
711 void ScanForGames();
712
713 /*! Dialog API */
714 void BuildDialog();
715 void PostModal( int code );
716 };
717
718 #endif // _PREFERENCES_H_