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