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