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