1 /*
2  * Copyright 2011-2012 Arx Libertatis Team (see the AUTHORS file)
3  *
4  * This file is part of Arx Libertatis.
5  *
6  * Arx Libertatis is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Arx Libertatis is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Arx Libertatis.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef ARX_CORE_CONFIG_H
21 #define ARX_CORE_CONFIG_H
22 
23 #include <string>
24 
25 #include "input/InputKey.h"
26 
27 #include "io/fs/FilePath.h"
28 
29 #include "math/MathFwd.h"
30 #include "math/Vector2.h"
31 
32 //! Enum for all the controlling actions
33 enum ControlAction {
34 
35 	CONTROLS_CUST_JUMP = 0,
36 	CONTROLS_CUST_MAGICMODE,
37 	CONTROLS_CUST_STEALTHMODE,
38 	CONTROLS_CUST_WALKFORWARD,
39 	CONTROLS_CUST_WALKBACKWARD,
40 	CONTROLS_CUST_STRAFELEFT,
41 	CONTROLS_CUST_STRAFERIGHT,
42 	CONTROLS_CUST_LEANLEFT,
43 	CONTROLS_CUST_LEANRIGHT,
44 	CONTROLS_CUST_CROUCH,
45 	CONTROLS_CUST_MOUSELOOK,
46 	CONTROLS_CUST_ACTION,
47 	CONTROLS_CUST_INVENTORY,
48 	CONTROLS_CUST_BOOK,
49 	CONTROLS_CUST_BOOKCHARSHEET,
50 	CONTROLS_CUST_BOOKSPELL,
51 	CONTROLS_CUST_BOOKMAP,
52 	CONTROLS_CUST_BOOKQUEST,
53 	CONTROLS_CUST_DRINKPOTIONLIFE,
54 	CONTROLS_CUST_DRINKPOTIONMANA,
55 	CONTROLS_CUST_TORCH,
56 
57 	CONTROLS_CUST_PRECAST1,
58 	CONTROLS_CUST_PRECAST2,
59 	CONTROLS_CUST_PRECAST3,
60 	CONTROLS_CUST_WEAPON,
61 	CONTROLS_CUST_QUICKLOAD,
62 	CONTROLS_CUST_QUICKSAVE,
63 
64 	CONTROLS_CUST_TURNLEFT,
65 	CONTROLS_CUST_TURNRIGHT,
66 	CONTROLS_CUST_LOOKUP,
67 	CONTROLS_CUST_LOOKDOWN,
68 
69 	CONTROLS_CUST_STRAFE,
70 	CONTROLS_CUST_CENTERVIEW,
71 
72 	CONTROLS_CUST_FREELOOK,
73 
74 	CONTROLS_CUST_PREVIOUS,
75 	CONTROLS_CUST_NEXT,
76 
77 	CONTROLS_CUST_CROUCHTOGGLE,
78 
79 	CONTROLS_CUST_UNEQUIPWEAPON,
80 
81 	CONTROLS_CUST_CANCELCURSPELL,
82 
83 	CONTROLS_CUST_MINIMAP,
84 
85 	CONTROLS_CUST_TOGGLE_FULLSCREEN,
86 
87 	NUM_ACTION_KEY
88 };
89 
90 struct ActionKey {
91 
92 	ActionKey(InputKeyId key_0 = -1, InputKeyId key_1 = -1) {
93 		key[0] = key_0;
94 		key[1] = key_1;
95 	}
96 
97 	InputKeyId key[2];
98 
99 };
100 
101 class Config {
102 
103 public:
104 
105 	// section 'language'
106 	std::string language;
107 
108 	// section 'video'
109 	struct {
110 
111 		Vec2i resolution;
112 		int bpp;
113 
114 		bool fullscreen;
115 		int levelOfDetail;
116 		float fogDistance;
117 		bool showCrosshair;
118 		bool antialiasing;
119 		bool vsync;
120 	} video;
121 
122 	// section 'window'
123 	struct {
124 
125 		Vec2i size;
126 
127 		std::string framework;
128 
129 	} window;
130 
131 	// section 'audio'
132 	struct {
133 
134 		float volume;
135 		float sfxVolume;
136 		float speechVolume;
137 		float ambianceVolume;
138 
139 		bool eax;
140 
141 		std::string backend;
142 
143 	} audio;
144 
145 	// section 'input'
146 	struct {
147 
148 		bool invertMouse;
149 		bool autoReadyWeapon;
150 		bool mouseLookToggle;
151 		bool autoDescription;
152 		int mouseSensitivity;
153 		bool linkMouseLookToUse;
154 
155 		std::string backend;
156 
157 	} input;
158 
159 	// section 'key'
160 	ActionKey actions[NUM_ACTION_KEY];
161 
162 	enum MigrationStatus {
163 		OriginalAssets = 0,
164 		CaseSensitiveFilenames = 1
165 	};
166 
167 	// section 'misc'
168 	struct {
169 
170 		bool forceToggle; // should be in input?
171 
172 		MigrationStatus migration;
173 
174 		int quicksaveSlots;
175 
176 		std::string debug; //!< Logger debug levels.
177 
178 	} misc;
179 
180 public:
181 
182 	bool setActionKey(ControlAction action, int index, InputKeyId key);
183 	void setDefaultActionKeys();
184 
185 	/*!
186 	 * Saves all config entries to a file.
187 	 * @return true if the config was saved successfully.
188 	 */
189 	bool save();
190 
191 	bool init(const fs::path & file);
192 
193 	void setOutputFile(const fs::path & _file);
194 
195 private:
196 
197 	fs::path file;
198 };
199 
200 extern Config config;
201 
202 #endif // ARX_CORE_CONFIG_H
203