1 /*
2  * Holotz's Castle
3  * Copyright (C) 2004 Juan Carlos Seijo P�rez
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the Free
7  * Software Foundation; either version 2 of the License, or (at your option)
8  * any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc., 59
17  * Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Juan Carlos Seijo P�rez
20  * jacob@mainreactor.net
21  */
22 
23 /** Preferences file for Holotz's Castle.
24  * @file    HCPreferences.h
25  * @author  Juan Carlos Seijo P�rez
26  * @date    24/08/2004
27  * @version 0.0.1 - 24/08/2004 - First version.
28  */
29 
30 #ifndef _HCPREFERENCES_INCLUDED
31 #define _HCPREFERENCES_INCLUDED
32 
33 #include <vector>
34 #include <JLib/Util/JTextFile.h>
35 #include <JLib/Util/JUtil.h>
36 #include <JLib/Util/JTypes.h>
37 
38 #define HCPREFERENCES_TOY               5           // Toy difficulty level
39 #define HCPREFERENCES_EASY              4           // Easy difficulty level
40 #define HCPREFERENCES_NORMAL            2           // Normal difficulty level
41 #define HCPREFERENCES_HARD              1           // Hard difficulty level
42 
43 #define HCPREFERENCES_DEFFILENAME       "preferences.txt"
44 #define HCPREFERENCES_DEFLANGUAGE       0
45 #define HCPREFERENCES_DEFVIDEOMODE      0
46 #define HCPREFERENCES_DEFBPP            16
47 #define HCPREFERENCES_DEFFULLSCREEN     false
48 #define HCPREFERENCES_DEFSOUND          true
49 #define HCPREFERENCES_LANGFILE          "languages.txt"
50 #define HCPREFERENCES_DEFDIFFICULTY     HCPREFERENCES_NORMAL
51 
52 class HCPreferences
53 {
54  protected:
55 	char **langs;                         /**< Available languages strings. */
56 	char **langCodes;                     /**< Country codes strings for available languages (es, en, de, etc.). */
57 	s32 numLangs;                         /**< Number of different languages. */
58 	s32 curLang;                          /**< Current language index/country code. */
59 	s32 videoMode;                        /**< Video mode from the list of video modes supported. */
60 	JVideoMode *videoModes;               /**< Available video modes. */
61 	s32 numVideoModes;                    /**< Number of available video modes. */
62 	s32 bpp;                              /**< Color depth in bits per pixel. */
63 	bool fullscreen;                      /**< Fullscreen/windowed flag. */
64 	bool sound;                           /**< Sound on/off flag. */
65 	s32 difficulty;                       /**< Level of difficulty (Easy/Medium/Hard). */
66 	static HCPreferences *instance;       /**< Unique instance of the object. */
67 
68  public:
69 	/** Creates an empty preferences object.
70 	 */
71 	HCPreferences();
72 
73 	/** Returns the instance of this preference object.
74 	 * @return Instance ob this object.
75 	 */
Prefs()76 	static HCPreferences * Prefs() {return instance;}
77 
78 	/** Sets the language.
79 	 * @param  lang Index of the available languages to use.
80 	 */
CurLang(s32 curLanguage)81 	void CurLang(s32 curLanguage) {curLang = curLanguage; JClamp(curLang, 0, numLangs);}
82 
83 	/** Gets the current language index.
84 	 * @return Current language index.
85 	 */
CurLang()86 	s32 CurLang() {return curLang;}
87 
88 	/** Gets the available languages strings.
89 	 * @return Available languages strings.
90 	 */
Langs()91 	char **Langs() {return langs;}
92 
93 	/** Gets the available language country codes.
94 	 * @return Available language country codes.
95 	 */
LangCodes()96 	char **LangCodes() {return langCodes;}
97 
98 	/** Gets the number of available languages.
99 	 * @return Number of available languages.
100 	 */
NumLangs()101 	s32 NumLangs() {return numLangs;}
102 
103 	/** Gets the number of available video modes.
104 	 * @return Number of available video modes.
105 	 */
NumVideoModes()106 	s32 NumVideoModes() {return numVideoModes;}
107 
108 	/** Gets the available video modes.
109 	 * @return Available video modes or 0 if none exist.
110 	 */
VideoModes()111 	JVideoMode * VideoModes() {return videoModes;}
112 
113 	/** Sets the video mode number.
114 	 * @param  Ordinal of the video mode to use, based upon the available modes.
115 	 */
VideoMode(s32 mode)116 	void VideoMode(s32 mode) {videoMode = mode;}
117 
118 	/** Gets the video mode number.
119 	 * @return Video mode number.
120 	 */
VideoMode()121 	s32 VideoMode() {return videoMode;}
122 
123 	/** Sets color depth.
124 	 * @param  New color depth. Supports 8, 16, 24 and 32 bits.
125 	 */
126 	void BPP(s32 newBPP);
127 
128 	/** Gets the color depth.
129 	 * @return Color depth.
130 	 */
BPP()131 	s32 BPP() {return bpp;}
132 
133 	/** Sets windowed or fullscreen mode.
134 	 * @param  <b>true</b> to use fullscreen mode, <b>false</b> for windowed mode.
135 	 */
Fullscreen(bool fs)136 	void Fullscreen(bool fs) {fullscreen = fs;}
137 
138 	/** Gets the playing mode (windowed or full screen).
139 	 * @return <b>true</b> if fullscreen mode, <b>false</b> if windowed mode.
140 	 */
Fullscreen()141 	bool Fullscreen() {return fullscreen;}
142 
143 	/** Sets sound mode.
144 	 * @param  <b>true</b> activates sound, <b>false</b> deactivates it.
145 	 */
Sound(bool fs)146 	void Sound(bool fs) {sound = fs;}
147 
148 	/** Gets the sound mode.
149 	 * @return <b>true</b> if sound is active, <b>false</b> if not.
150 	 */
Sound()151 	bool Sound() {return sound;}
152 
153 	/** Sets the level of difficulty.
154 	 * @param  Level of difficulty, one of HCPREFERENCES_EASY, HCPREFERENCES_NORMAL, HCPREFERENCES_HARD.
155 	 */
Difficulty(s32 newDiff)156 	void Difficulty(s32 newDiff) {difficulty = newDiff; JClamp(difficulty, HCPREFERENCES_HARD, HCPREFERENCES_TOY);}
157 
158 	/** Gets the level of difficulty.
159 	 * @return Current level of difficulty, one of HCPREFERENCES_EASY, HCPREFERENCES_NORMAL, HCPREFERENCES_HARD.
160 	 */
Difficulty()161 	s32 Difficulty() {return difficulty;}
162 
163 	/** Resets to defaults.
164 	 */
165 	void Reset();
166 
167 	/** Load the preferences file.
168 	 * @param  filename Name of the file to use or 0 (the default) to use the default file name.
169 	 * @return 0 if loading succeeded, 1 if I/O error, 2 if integrity error.
170 	 */
171 	s32 Load(const char *filename = 0);
172 
173 	/** Saves the preferences file.
174 	 * @param  filename Name of the file to use or 0 (the default) to use the default file name.
175 	 * @return 0 if saving succeeded, 1 if I/O error, 2 if integrity error.
176 	 */
177 	s32 Save(const char *filename = 0);
178 
179 	/** Destroys this object.
180 	 */
181 	void Destroy();
182 
183 	/** Destroys this object.
184 	 */
~HCPreferences()185 	virtual ~HCPreferences() {Destroy();}
186 };
187 
188 #endif // _HCPREFERENCES_INCLUDED
189