]> git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/preferences.h
51c9ccb4e903247523be8038eff05af7d5390476
[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   {
59     mName = name; mType = Type; mVal = Val;
60   }
61   CPrefAssignment() { mVal = NULL; }
62   CPrefAssignment(const CPrefAssignment& ass);
63   virtual ~CPrefAssignment() { }
64   virtual CPrefAssignment& operator =(const CPrefAssignment& ass);
65 };
66
67
68 /*!
69 generic preferences storage class, using xml files
70 */
71 class CXMLPropertyBag
72 {
73 private:
74   /*!
75   local prefs file
76   */
77   xmlDocPtr mpDoc;
78   xmlNodePtr mpDocNode;
79
80   /*!
81   prefs assignments (what pref name, what type, what variable)
82   */
83   list<CPrefAssignment> mPrefAssignments;
84
85   /*!
86   name of file to load/save as
87   */
88   Str mStrFilename;
89
90   /*!
91   store assignment in the property list if not already there
92   */
93   void PushAssignment(const char *name, PrefTypes_t type, void *pV);
94
95   /*!
96   find the xmlnode relating to the epair name
97   */
98   xmlNodePtr EpairForName(const char *name);
99
100 public:
101   CXMLPropertyBag();
102   virtual ~CXMLPropertyBag()
103   {
104     if (InUse())
105       Clear();
106   };
107
108   /*!
109   read a pref setting, if doesn't exist, will add it to the xml tree (using default value provided)
110   \arg name the name of the pref
111   \arg pV pointer to the value
112   \arg V default value
113   those functions will fill in the list of preferences assignments
114     (name, type and pointer to value)
115     this is used in UpdatePrefTree
116   */
117   void GetPref(const char *name, Str *pV, const char *V);
118   void GetPref(const char *name, int *pV, int V);
119   void GetPref(const char *name, bool *pV, bool V);
120   void GetPref(const char *name, float *pV, float V);
121   void GetPref(const char *name, float *pV, float* V);
122   void GetPref(const char *name, window_position_t* pV, window_position_t V);
123
124   /*!
125   returns whether or not the property bag is already open
126   */
127   qboolean InUse() { return (mpDoc != NULL); };
128
129   /*!
130   unload the xml doc, and free the tree
131   */
132   void Clear();
133
134   /*|
135   read data from our XML file
136   */
137   void ReadXMLFile(const char* pFilename);
138
139   /*|
140   write out the property bag to an XML data file
141   return is success/fail
142   */
143   qboolean WriteXMLFile(const char* pFilename);
144
145   /*!
146   update the xml tree with data form the property list, usually in preparation for a write
147   */
148   void UpdatePrefTree();
149
150   /*!
151   did the file have any data or not?
152   */
153   qboolean mbEmpty;
154 };
155
156 /*!
157 holds information for a given game
158 I'm a bit unclear on that still
159 it holds game specific configuration stuff
160 such as base names, engine names, some game specific features to activate in the various modules
161 it is not strictly a prefs thing since the user is not supposed to edit that (unless he is hacking
162 support for a new game)
163
164 what we do now is fully generate the information for this during the setup. We might want to
165 generate a piece that just says "the game pack is there", but put the rest of the config somwhere
166 else (i.e. not generated, copied over during setup .. for instance in the game tools directory)
167 */
168 class CGameDescription
169 {
170 public:
171   xmlDocPtr mpDoc; ///< the game description xml tree
172   Str mGameToolsPath; ///< the explicit path to the game-dependent modules
173   Str mGameName; ///< name of the game used in dialogs
174   Str mGameFile; ///< the .game file that describes this game
175   Str mBaseGame; ///< basegame directory
176   Str mEnginePath; ///< path to the engine
177   Str mEngine; ///< engine name
178   Str mMultiplayerEngine; ///< engine name
179 #if defined (__linux__) || defined (__APPLE__)
180   Str mUserPathPrefix; ///< prefix for ~/.q3a ~/.wolf init, only on *nix
181 #endif
182   Str mShaderPath; ///< the path in which to look for shaders
183   Str mShaderlist; ///< shaderlist file
184   float mTextureDefaultScale; ///< default scale (0.5 in q3, 1.0 in q1/q2, 0.25 in JK2 ..)
185   bool mEClassSingleLoad; ///< only load a single eclass definition file
186   bool mNoPatch; ///< this game doesn't support patch technology
187   Str mCaulkShader; ///< the shader to use for caulking
188   bool quake2; ///< set this to true to get quake2
189   bool noMapsInHome; ///< set this if you want to open the engine path/base dir/maps dir for map open/save dialoges */
190
191   CGameDescription() { mpDoc = NULL; }
192   /*!
193   \todo parse basic info from the node
194   user-friendly name of the game
195   essential parameters (such as the start dir)
196   */
197   CGameDescription(xmlDocPtr pDoc, const Str &GameFile);
198   virtual ~CGameDescription() { xmlFreeDoc(mpDoc); }
199
200   void Dump();
201 };
202
203 /*!
204 select games, copy editing assets and write out configuration files
205  */
206
207 #define Q3_PACK "Q3Pack"
208 #define URT_PACK "UrTPack"
209 #define UFOAI_PACK "UFOAIPack"
210 #define Q2W_PACK "Q2WPack"
211 #define WARSOW_PACK "WarsowPack"
212 #define NEXUIZ_PACK "NexuizPack"
213 #define Q2_PACK "Q2Pack"
214 #define TREMULOUS_PACK "TremulousPack"
215 #define JA_PACK "JAPack"
216 #define REACTION_PACK "ReactionPack"
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_COUNT
241         };
242
243 protected:
244         Str             m_strName;
245         Str             m_strMod;
246         Str             m_strEngine;
247         int             m_nComboSelect;
248
249         // maps from m_nComboSelect to the games
250         int     m_availGames[GAME_COUNT];
251 };
252
253 /*!
254 standalone dialog for games selection, and more generally global settings
255 */
256 class CGameDialog : public Dialog
257 {
258   GtkWidget *mFrame; ///< this is built on-demand first time it's used
259   GtkWidget *mTopBox; ///< top level box used to store the dialog frame, must unhook after modal use
260
261   GtkComboBox   *mGameCombo;    // combo box holds the selection of available game
262
263   /*!
264   global prefs storage
265   */
266   CXMLPropertyBag mGlobalPrefs;
267
268 #ifdef _WIN32
269   /*!
270   run from a network share
271   this one is not being saved out in prefs, since we need to know before we load prefs
272   we use a dummy file NETRUN_FILENAME as flag
273   all done with static stuff
274   */
275   static bool m_bNetRun;
276 #endif
277
278   bool m_bDoGameInstall;
279
280   CGameInstall mGameInstall;
281
282 protected:
283
284   int m_nComboSelect; ///< intermediate int value for combo in dialog box
285
286 public:
287
288   /*!
289   those settings are saved in the global prefs file
290   I'm too lazy to wrap behind protected access, not sure this needs to be public
291   NOTE: those are preference settings. if you change them it is likely that you would
292   have to restart the editor for them to take effect
293   */
294   /*@{*/
295   /*!
296   what game has been selected
297   this is the name of the .game file
298   */
299   Str m_sGameFile;
300   /*!
301   auto-load the game on startup
302   this is linked to auto-load checkbox
303   */
304   bool m_bAutoLoadGame;
305   /*!
306   log console to radiant.log
307   m_bForceLogConsole is an obscure forced latching situation
308   */
309   bool m_bLogConsole;
310   bool m_bForceLogConsole;
311   /*@}*/
312
313   /*!
314   points somewhere in mGames, set once at startup
315   */
316   CGameDescription *m_pCurrentGameDescription;
317
318   /*!
319   the list of game descriptions we scanned from the game/ dir
320   */
321   list<CGameDescription *> mGames;
322
323   CGameDialog() {
324           mFrame = NULL;
325           m_pCurrentGameDescription = NULL;
326           m_bLogConsole = false;
327           m_bForceLogConsole = false;
328           m_bDoGameInstall = true;      // go through DoModal at least once
329           mGameCombo = NULL;
330   }
331   virtual ~CGameDialog();
332
333   void AddPacksURL( Str &s );
334
335   /*!
336   intialize the game dialog, called at CPrefsDlg::Init
337   will scan for games, load prefs, and do game selection dialog if needed
338   */
339   void Init();
340
341   /*!
342   reset the global settings by removing the file
343   */
344   void Reset();
345
346   /*!
347   run the dialog UI for the list of games
348   */
349   void DoGameDialog();
350
351   /*!
352         call out to the game installation dialog
353   */
354   void DoGameInstall();
355
356   /*!
357   Dialog API
358   this is only called when the dialog is built at startup for main engine select
359   */
360   void BuildDialog();
361   void UpdateData( bool retrieve );
362
363   /*!
364   construction of the dialog frame
365   this is the part to be re-used in prefs dialog
366   for the standalone dialog, we include this in a modal box
367   for prefs, we hook the frame in the main notebook
368   build the frame on-demand (only once)
369   */
370   GtkWidget *GetGlobalFrame();
371
372   /*!
373   global preferences subsystem
374   XML-based this time, hopefully this will generalize to other prefs
375   LoadPrefs has hardcoded defaults
376   NOTE: it may not be strictly 'CGameDialog' to put the global prefs here
377     could have named the class differently I guess
378   */
379   /*@{*/
380   void LoadPrefs(); ///< load from file into variables
381   void SavePrefs(); ///< save pref variables to file
382   /*@}*/
383
384   /*!
385   read or set netrun (check file)
386   \param retrieve
387     if false, will check if netrun file is present and will set m_bNetRun
388     if true, will create/erase the netrun file depending on m_bNetRun
389     NOTE: this is not backwards, 'retrieve' means 'retrieve from settings dialog' - in terms of UI
390   */
391   static void UpdateNetrun(bool retrieve);
392   /*!
393   get current netrun setting
394   */
395   static bool GetNetrun();
396
397 private:
398   /*!
399   scan for .game files, load them
400   */
401   void ScanForGames();
402
403   /*!
404   inits g_PrefsDlg.m_global_rc_path
405   */
406   void InitGlobalPrefPath();
407
408   /*!
409   uses m_nComboItem to find the right mGames
410   */
411   CGameDescription *GameDescriptionForComboItem();
412
413   /*!
414         callback for the game install button
415   */
416   static void SInstallCallback( GtkWidget *widget, gpointer data );
417
418   void UpdateGameCombo();
419 };
420
421 typedef struct {
422   int nEntitySplit1;
423   int nEntitySplit2;
424
425   window_position_t position;
426
427   window_position_t posEntityWnd;
428   window_position_t posMapInfoWnd;
429   window_position_t posCamWnd;
430   window_position_t posZWnd;
431   window_position_t posXYWnd;
432   window_position_t posXZWnd;
433   window_position_t posYZWnd;
434   window_position_t posPatchWnd;
435   window_position_t posSurfaceWnd;
436   window_position_t posEntityInfoWnd;
437
438   int nXYHeight;
439   int nZWidth;
440   int nXYWidth;
441   int nCamWidth;
442   int nCamHeight;
443   int nZFloatWidth;
444   int nState;
445 } windowPosInfo_t;
446
447 class PrefsDlg : public Dialog
448 {
449
450 public:
451   /*!
452   local prefs file
453   */
454   CXMLPropertyBag mLocalPrefs;
455
456   // will enable/disable stuff according to the situation
457   void DoSensitivity();
458   void PreModal() { DoSensitivity(); }
459
460   // enable/disable custom editor entry
461   void DoEditorSensitivity();
462
463   /*!
464   this holds global level preferences
465   */
466   CGameDialog mGamesDialog;
467 protected:
468   // warning about old project files
469   bool m_bWarn;
470   list<CGameDescription *> mGames;
471
472 public:
473   // last light intensity used in the CLightPrompt dialog, stored in registry
474   int m_iLastLightIntensity;
475   // these mirror what goes in the combo box
476   // see PrefDlg::m_nShader, tells wether to load NONE / COMMON or ALL shaders at parsing stage
477   enum {SHADER_NONE = 0, SHADER_COMMON, SHADER_ALL};
478
479   // Gef: updated preferences dialog
480   /*! Preference notebook page numbers */
481   enum {PTAB_FRONT = 0, PTAB_GAME_SETTINGS, PTAB_2D, PTAB_CAMERA, PTAB_TEXTURE, PTAB_LAYOUT, PTAB_MOUSE,
482         PTAB_EDITING, PTAB_STARTUP, PTAB_PATHS, PTAB_BRUSH, PTAB_MISC, PTAB_BSPMONITOR} pref_tabs;
483
484   GtkWidget *notebook;
485
486   void UpdateTextureCompression();
487
488 #ifdef ATIHACK_812
489   void UpdateATIHack();
490 #endif
491
492 #ifdef NVIDIA_AERO_HACK
493   void UpdateNvidiaAeroHack();
494 #endif
495
496   void LoadPrefs();
497   void SavePrefs();
498   void LoadTexdefPref(texdef_t* pTexdef, char* pName);
499
500   PrefsDlg ();
501   virtual ~PrefsDlg ()
502   {
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_