moved almost all hardcoded constants to "define.dat"
[k8-i-v-a-n.git] / src / game / iconf.cpp
bloba7b3733f8485d13a80a7f964ff7635056ce8928b
1 /*
3 * Iter Vehemens ad Necem (IVAN)
4 * Copyright (C) Timo Kiviluoto
5 * Released under the GNU General
6 * Public License
8 * See LICENSING which should be included
9 * along with this file for more details
12 #include "iconf.h"
13 #include "game.h"
14 #include "fesave.h"
15 #include "feparse.h"
16 #include "feio.h"
17 #include "area.h"
18 #include "graphics.h"
19 #include "bitmap.h"
20 #include "igraph.h"
21 #include "felist.h"
23 #include "message.h"
24 #include "command.h"
27 stringoption ivanconfig::DefaultName("DefaultName", "player's default name", "", &configsystem::NormalStringDisplayer, &DefaultNameChangeInterface);
28 stringoption ivanconfig::DefaultPetName("DefaultPetName", "starting pet's default name", CONST_S("Kenny"), &configsystem::NormalStringDisplayer, &DefaultPetNameChangeInterface);
29 numberoption ivanconfig::AutoSaveInterval("AutoSaveInterval", "autosave interval", 100, &AutoSaveIntervalDisplayer, &AutoSaveIntervalChangeInterface, &AutoSaveIntervalChanger);
30 scrollbaroption ivanconfig::Contrast("Contrast", "contrast", 100, &ContrastDisplayer, &ContrastChangeInterface, &ContrastChanger, &ContrastHandler);
31 truthoption ivanconfig::WarnAboutDanger("WarnAboutVeryDangerousMonsters", "Warn about very dangerous monsters", true);
32 truthoption ivanconfig::AutoDropLeftOvers("AutoDropLeftOvers", "drop food leftovers automatically", true);
33 truthoption ivanconfig::AutoDropBottles("AutoDropBottles", "automatically drop empty bottles after drinking", true);
34 truthoption ivanconfig::AutoDropCans("AutoDropCans", "automatically drop empty cans after eating/drinking", false);
35 truthoption ivanconfig::LookZoom("LookZoom", "zoom feature in look mode", false);
36 truthoption ivanconfig::UseAlternativeKeys("UseAlternativeKeys", "use alternative direction keys", false);
37 truthoption ivanconfig::BeNice("BeNice", "be nice to pets", true);
38 truthoption ivanconfig::FullScreenMode("FullScreenMode", "run the game in full screen mode", false, &configsystem::NormalTruthDisplayer, &configsystem::NormalTruthChangeInterface, &FullScreenModeChanger);
39 /*k8*/
40 scrollbaroption ivanconfig::DoubleResModifier("DoubleResModifier", "resolution multiplier (1+n/10)", 10, &ResModDisp, &ResModChangeIntf, &ResModChanger, &ResModHandler);
41 truthoption ivanconfig::KickDownDoors("KickDownDoors", "kick closed doors", false);
42 truthoption ivanconfig::AutoCenterMap("AutoCenterMap", "automatically center map when player moves", true);
43 truthoption ivanconfig::AutoCenterMapOnLook("AutoCenterMapOnLook", "automatically center map when player looks", true);
44 truthoption ivanconfig::FastListMode("FastLists", "instantly select list items with alpha keys", true, &configsystem::NormalTruthDisplayer, &configsystem::NormalTruthChangeInterface, &FastListChanger);
45 truthoption ivanconfig::PlaySounds("PlaySounds", "use sounds", false);
46 scrollbaroption ivanconfig::SoundVolume("SoundVolume", "sound volume", 128, &SoundVolumeDisplayer, &SoundVolumeChangeInterface, &ContrastChanger, &SoundVolumeHandler);
47 truthoption ivanconfig::ConfirmCorpses("ConfirmCorpses", "confirm corpse pickup", true);
48 truthoption ivanconfig::StopOnCorpses("StopOnCorpses", "abort going on corpses", false);
49 truthoption ivanconfig::StopOnSeenItems("StopOnSeenItems", "abort going on seen items", false);
50 truthoption ivanconfig::StopOnSeenDoors("StopOnSeenDoors", "abort going on seen doors", false);
51 truthoption ivanconfig::ConfirmScrollReading("ConfirmScrollReading", "confirm scroll reading", false);
52 numberoption ivanconfig::GoingDelay("GoingDelay", "delay betwen steps in 'go' command", 100, &GoingDelayDisplayer, &GoingDelayChangeInterface, &GoingDelayChanger);
53 truthoption ivanconfig::UseMaximumCompression("UseMaximumCompression", "use maximum compression", false);
54 truthoption ivanconfig::ShowFullItemDesc("ShowFullItemDesc", "show detailed description of lying item", false);
57 void ivanconfig::SoundVolumeDisplayer (const numberoption *O, festring &Entry) {
58 Entry << O->Value << "/128";
62 truth ivanconfig::SoundVolumeChangeInterface (numberoption *O) {
63 iosystem::ScrollBarQuestion(CONST_S("Set new sound volume (0-128, '<' and '>' move the slider):"),
64 GetQuestionPos(), O->Value, 16, 0, 128, O->Value, WHITE, LIGHT_GRAY, DARK_GRAY, game::GetMoveCommandKey(KEY_LEFT_INDEX), game::GetMoveCommandKey(KEY_RIGHT_INDEX), !game::IsRunning(), static_cast<scrollbaroption*>(O)->BarHandler);
65 if (game::IsRunning()) igraph::BlitBackGround(v2(16, 6), v2(game::GetScreenXSize() << 4, 23));
66 return false;
70 void ivanconfig::SoundVolumeChanger (numberoption *O, sLong What) {
71 if (What < 0) What = 0;
72 if (What > 128) What = 128;
73 O->Value = What;
74 soundsystem::setVolume(What);
78 void ivanconfig::SoundVolumeHandler (sLong Value) {
79 SoundVolumeChanger(&SoundVolume, Value);
81 /*k8*/
84 col24 ivanconfig::ContrastLuminance = NORMAL_LUMINANCE;
85 v2 ivanconfig::GetQuestionPos () { return game::IsRunning() ? v2(16, 6) : v2(30, 30); }
86 void ivanconfig::BackGroundDrawer () { game::DrawEverythingNoBlit(); }
89 void ivanconfig::AutoSaveIntervalDisplayer (const numberoption *O, festring &Entry) {
90 if (O->Value) {
91 Entry << O->Value << " turn";
92 if (O->Value != 1) Entry << 's';
93 } else {
94 Entry << "disabled";
99 void ivanconfig::ResModDisp (const numberoption *O, festring &Entry) {
100 Entry << O->Value << "/10";
103 truth ivanconfig::ResModChangeIntf (numberoption *O) {
104 iosystem::ScrollBarQuestion(CONST_S("Set new multiplier value (0-10, '<' and '>' move the slider):"), GetQuestionPos(), O->Value, 1, 0, 10, O->Value, WHITE, LIGHT_GRAY, DARK_GRAY, game::GetMoveCommandKey(KEY_LEFT_INDEX), game::GetMoveCommandKey(KEY_RIGHT_INDEX), !game::IsRunning(), static_cast<scrollbaroption*>(O)->BarHandler);
105 return false;
108 void ivanconfig::ResModChanger (numberoption *O, sLong What) {
109 if (What < 0) What = 0;
110 if (What > 10) What = 10;
111 O->Value = What;
112 graphics::ReinitMode(What);
115 void ivanconfig::ResModHandler (sLong Value) {
116 ResModChanger(&DoubleResModifier, Value);
117 if (game::IsRunning()) {
118 game::GetCurrentArea()->SendNewDrawRequest();
119 game::DrawEverythingNoBlit();
124 void ivanconfig::ContrastDisplayer (const numberoption *O, festring &Entry) {
125 Entry << O->Value << "/100";
129 truth ivanconfig::DefaultNameChangeInterface (stringoption *O) {
130 festring String;
131 if (iosystem::StringQuestion(String, CONST_S("Set new default name (1-20 letters):"), GetQuestionPos(), WHITE, 0, 20, !game::IsRunning(), true) == NORMAL_EXIT)
132 O->ChangeValue(String);
133 if (game::IsRunning()) igraph::BlitBackGround(v2(16, 6), v2(game::GetScreenXSize() << 4, 23));
134 return false;
138 truth ivanconfig::DefaultPetNameChangeInterface (stringoption *O) {
139 festring String;
140 if (iosystem::StringQuestion(String, CONST_S("Set new default name for the starting pet (1-20 letters):"), GetQuestionPos(), WHITE, 0, 20, !game::IsRunning(), true) == NORMAL_EXIT)
141 O->ChangeValue(String);
142 if (game::IsRunning()) igraph::BlitBackGround(v2(16, 6), v2(game::GetScreenXSize() << 4, 23));
143 return false;
147 truth ivanconfig::AutoSaveIntervalChangeInterface (numberoption *O) {
148 O->ChangeValue(iosystem::NumberQuestion(CONST_S("Set new autosave interval (1-50000 turns, 0 for never):"), GetQuestionPos(), WHITE, !game::IsRunning()));
149 if (game::IsRunning()) igraph::BlitBackGround(v2(16, 6), v2(game::GetScreenXSize() << 4, 23));
150 return false;
154 truth ivanconfig::ContrastChangeInterface (numberoption *O) {
155 iosystem::ScrollBarQuestion(CONST_S("Set new contrast value (0-200, '<' and '>' move the slider):"), GetQuestionPos(), O->Value, 5, 0, 200, O->Value, WHITE, LIGHT_GRAY, DARK_GRAY, game::GetMoveCommandKey(KEY_LEFT_INDEX), game::GetMoveCommandKey(KEY_RIGHT_INDEX), !game::IsRunning(), static_cast<scrollbaroption*>(O)->BarHandler);
156 if (game::IsRunning()) igraph::BlitBackGround(v2(16, 6), v2(game::GetScreenXSize() << 4, 23));
157 return false;
161 void ivanconfig::AutoSaveIntervalChanger (numberoption *O, sLong What) {
162 if (What < 0) What = 0;
163 if (What > 50000) What = 50000;
164 O->Value = What;
168 void ivanconfig::ContrastChanger (numberoption *O, sLong What) {
169 if (What < 0) What = 0;
170 if (What > 200) What = 200;
171 O->Value = What;
172 CalculateContrastLuminance();
176 void ivanconfig::FullScreenModeChanger (truthoption *, truth) {
177 graphics::SwitchMode();
181 void ivanconfig::FastListChanger (truthoption *O, truth value) {
182 //fprintf(stderr, "FLC: %s\n", value ? "TAN" : "ona");
183 FastListMode.Value = !FastListMode.Value;
184 felist::SetFastListMode(!FastListMode.Value);
188 void ivanconfig::Show () {
189 configsystem::Show(&BackGroundDrawer, &game::SetStandardListAttributes, game::IsRunning());
193 void ivanconfig::ContrastHandler (sLong Value) {
194 ContrastChanger(&Contrast, Value);
195 if (game::IsRunning()) {
196 game::GetCurrentArea()->SendNewDrawRequest();
197 game::DrawEverythingNoBlit();
202 void ivanconfig::SwitchModeHandler () {
203 FullScreenMode.Value = !FullScreenMode.Value;
204 Save();
208 void ivanconfig::CalculateContrastLuminance () {
209 int Element = Min<sLong>((GetContrast() << 7) / 100, 255);
210 ContrastLuminance = MakeRGB24(Element, Element, Element);
214 void ivanconfig::GoingDelayDisplayer (const numberoption *O, festring &Entry) {
215 if (O->Value) {
216 Entry << O->Value << " ms";
217 } else {
218 Entry << "disabled";
223 truth ivanconfig::GoingDelayChangeInterface (numberoption *O) {
224 O->ChangeValue(iosystem::NumberQuestion(CONST_S("Set new 'go' delay (0-2000):"), GetQuestionPos(), WHITE, !game::IsRunning()));
225 if (game::IsRunning()) igraph::BlitBackGround(v2(16, 6), v2(game::GetScreenXSize() << 4, 23));
226 return false;
230 void ivanconfig::GoingDelayChanger (numberoption *O, sLong What) {
231 if (What < 0) What = 0;
232 if (What > 2000) What = 2000;
233 O->Value = What;
237 festring ivanconfig::GetMyDir (void) { return inputfile::GetMyDir(); }
240 static festring getConfigPath () {
241 festring path;
242 #ifdef LOCAL_SAVES
243 path << ivanconfig::GetMyDir();
244 #else
245 path << getenv("HOME");
246 #endif
247 return path;
251 void ivanconfig::Initialize () {
252 configsystem::AddOption(&DefaultName);
253 configsystem::AddOption(&DefaultPetName);
254 configsystem::AddOption(&AutoSaveInterval);
255 configsystem::AddOption(&Contrast);
256 configsystem::AddOption(&WarnAboutDanger);
257 configsystem::AddOption(&AutoDropLeftOvers);
258 configsystem::AddOption(&AutoDropBottles);
259 configsystem::AddOption(&AutoDropCans);
260 configsystem::AddOption(&LookZoom);
261 configsystem::AddOption(&UseAlternativeKeys);
262 configsystem::AddOption(&BeNice);
263 configsystem::AddOption(&FullScreenMode);
264 /*k8*/
265 configsystem::AddOption(&DoubleResModifier);
266 configsystem::AddOption(&KickDownDoors);
267 configsystem::AddOption(&AutoCenterMap);
268 configsystem::AddOption(&AutoCenterMapOnLook);
269 configsystem::AddOption(&FastListMode);
270 configsystem::AddOption(&PlaySounds);
271 configsystem::AddOption(&SoundVolume);
272 configsystem::AddOption(&ConfirmCorpses);
273 configsystem::AddOption(&StopOnCorpses);
274 configsystem::AddOption(&StopOnSeenItems);
275 configsystem::AddOption(&StopOnSeenDoors);
276 configsystem::AddOption(&ConfirmScrollReading);
277 configsystem::AddOption(&GoingDelay);
278 configsystem::AddOption(&UseMaximumCompression);
279 configsystem::AddOption(&ShowFullItemDesc);
280 /*k8*/
281 DoubleResModifier.Value = 0;
282 configsystem::SetConfigFileName(getConfigPath()+"/.ivan.rc");
283 configsystem::Load();
284 felist::SetFastListMode(!FastListMode.Value);
285 CalculateContrastLuminance();
287 commandsystem::ConfigureKeys();
288 commandsystem::SaveKeys(false);