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