forked from CleverRaven/Cataclysm-DDA
/
options.cpp
828 lines (670 loc) · 30.8 KB
/
options.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
#include "game.h"
#include "options.h"
#include "output.h"
#include "debug.h"
#include "keypress.h"
#include "translations.h"
#include <stdlib.h>
#include <fstream>
#include <string>
bool trigdist;
bool use_tiles;
std::map<std::string, cOpt> OPTIONS;
std::vector<std::pair<std::string, std::string> > vPages;
std::map<int, std::vector<std::string> > mPageItems;
std::map<std::string, std::string> optionNames;
//Default constructor
cOpt::cOpt() {
sType = "VOID";
sPage = "";
}
//string constructor
cOpt::cOpt(const std::string sPageIn, const std::string sMenuTextIn, const std::string sTooltipIn, const std::string sItemsIn, std::string sDefaultIn) {
sPage = sPageIn;
sMenuText = sMenuTextIn;
sTooltip = sTooltipIn;
sType = "string";
std::stringstream ssTemp(sItemsIn);
std::string sItem;
while (std::getline(ssTemp, sItem, ',')) {
vItems.push_back(sItem);
}
if (getItemPos(sDefaultIn) == -1) {
sDefaultIn = vItems[0];
}
sDefault = sDefaultIn;
sSet = sDefaultIn;
}
//bool constructor
cOpt::cOpt(const std::string sPageIn, const std::string sMenuTextIn, const std::string sTooltipIn, const bool bDefaultIn) {
sPage = sPageIn;
sMenuText = sMenuTextIn;
sTooltip = sTooltipIn;
sType = "bool";
bDefault = bDefaultIn;
bSet = bDefaultIn;
}
//int constructor
cOpt::cOpt(const std::string sPageIn, const std::string sMenuTextIn, const std::string sTooltipIn, const int iMinIn, int iMaxIn, int iDefaultIn) {
sPage = sPageIn;
sMenuText = sMenuTextIn;
sTooltip = sTooltipIn;
sType = "int";
if (iMinIn > iMaxIn) {
iMaxIn = iMinIn;
}
iMin = iMinIn;
iMax = iMaxIn;
if (iDefaultIn < iMinIn || iDefaultIn > iMaxIn) {
iDefaultIn = iMinIn ;
}
iDefault = iDefaultIn;
iSet = iDefaultIn;
}
//float constructor
cOpt::cOpt(const std::string sPageIn, const std::string sMenuTextIn, const std::string sTooltipIn,
const float fMinIn, float fMaxIn, float fDefaultIn, float fStepIn) {
sPage = sPageIn;
sMenuText = sMenuTextIn;
sTooltip = sTooltipIn;
sType = "float";
if (fMinIn > fMaxIn) {
fMaxIn = fMinIn;
}
fMin = fMinIn;
fMax = fMaxIn;
fStep = fStepIn;
if (fDefaultIn < fMinIn || fDefaultIn > fMaxIn) {
fDefaultIn = fMinIn ;
}
fDefault = fDefaultIn;
fSet = fDefaultIn;
}
//helper functions
std::string cOpt::getPage() {
return sPage;
}
std::string cOpt::getMenuText() {
return sMenuText;
}
std::string cOpt::getTooltip() {
return sTooltip;
}
std::string cOpt::getType() {
return sType;
}
std::string cOpt::getValue() {
if (sType == "string") {
return sSet;
} else if (sType == "bool") {
return (bSet) ? "true" : "false";
} else if (sType == "int") {
std::stringstream ssTemp;
ssTemp << iSet;
return ssTemp.str();
} else if (sType == "float") {
std::stringstream ssTemp;
ssTemp.precision(1);
ssTemp << std::fixed << fSet;
return ssTemp.str();
}
return "";
}
std::string cOpt::getName() {
if (sType == "string") {
return optionNames[sSet];
} else if (sType == "bool") {
return (bSet) ? _("True") : _("False");
}
return getValue();
}
std::string cOpt::getDefaultText() {
if (sType == "string") {
std::string sItems = "";
for (int i = 0; i < vItems.size(); i++) {
if (sItems != "") {
sItems += _(", ");
}
sItems += optionNames[vItems[i]];
}
return string_format(_("Default: %s - Values: %s"), optionNames[sDefault].c_str(), sItems.c_str());
} else if (sType == "bool") {
return (bDefault) ? _("Default: True") : _("Default: False");
} else if (sType == "int") {
return string_format(_("Default: %d - Min: %d, Max %d"), iDefault, iMin, iMax);
} else if (sType == "float") {
return string_format(_("Default: %f - Min: %f, Max %f"), fDefault, fMin, fMax);
}
return "";
}
int cOpt::getItemPos(const std::string sSearch) {
if (sType == "string") {
for (int i = 0; i < vItems.size(); i++) {
if (vItems[i] == sSearch) {
return i;
}
}
}
return -1;
}
//set to next item
void cOpt::setNext() {
if (sType == "string") {
int iNext = getItemPos(sSet)+1;
if (iNext >= vItems.size()) {
iNext = 0;
}
sSet = vItems[iNext];
} else if (sType == "bool") {
bSet = !bSet;
} else if (sType == "int") {
iSet++;
if (iSet > iMax) {
iSet = iMin;
}
} else if (sType == "float") {
fSet += fStep;
if (fSet > fMax) {
fSet = fMin;
}
}
}
//set to prev item
void cOpt::setPrev() {
if (sType == "string") {
int iPrev = getItemPos(sSet)-1;
if (iPrev < 0) {
iPrev = vItems.size()-1;
}
sSet = vItems[iPrev];
} else if (sType == "bool") {
bSet = !bSet;
} else if (sType == "int") {
iSet--;
if (iSet < iMin) {
iSet = iMax;
}
} else if (sType == "float") {
fSet -= fStep;
if (fSet < fMin) {
fSet = fMax;
}
}
}
//set value
void cOpt::setValue(std::string sSetIn) {
if (sType == "string") {
if (getItemPos(sSetIn) != -1) {
sSet = sSetIn;
}
} else if (sType == "bool") {
bSet = (sSetIn == "True" || sSetIn == "true" || sSetIn == "T" || sSetIn == "t");
} else if (sType == "int") {
iSet = atoi(sSetIn.c_str());
if ( iSet < iMin || iSet > iMax ) {
iSet = iDefault;
}
} else if (sType == "float") {
fSet = atof(sSetIn.c_str());
if ( fSet < fMin || fSet > fMax ) {
fSet = fDefault;
}
}
}
//Set default class behaviour to float
cOpt::operator float() const {
if (sType == "string") {
return (sSet != "" && sSet == sDefault) ? 1.0 : 0.0;
} else if (sType == "bool") {
return (bSet) ? 1.0 : 0.0;
} else if (sType == "int") {
return (float)iSet;
} else if (sType == "float") {
return fSet;
}
return 0.0;
}
// if (class == "string")
bool cOpt::operator==(const std::string sCompare) const {
if ( sType == "string" && sSet == sCompare ) {
return true;
}
return false;
}
// if (class != "string")
bool cOpt::operator!=(const std::string sCompare) const {
return !(*this == sCompare);
}
void initOptions() {
vPages.clear();
vPages.push_back(std::make_pair("general", _("General")));
vPages.push_back(std::make_pair("interface", _("Interface")));
vPages.push_back(std::make_pair("debug", _("Debug")));
OPTIONS.clear();
optionNames["fahrenheit"] = _("Fahrenheit");
optionNames["celsius"] = _("Celsius");
OPTIONS["USE_CELSIUS"] = cOpt("interface", _("Temperature units"),
_("Switch between Celsius and Fahrenheit."),
"fahrenheit,celsius", "fahrenheit"
);
optionNames["mph"] = _("mph");
optionNames["km/h"] = _("km/h");
OPTIONS["USE_METRIC_SPEEDS"] = cOpt("interface", _("Speed units"),
_("Switch between km/h and mph."),
"mph,km/h", "mph"
);
optionNames["lbs"] = _("lbs");
optionNames["kg"] = _("kg");
OPTIONS["USE_METRIC_WEIGHTS"] = cOpt("interface", _("Mass units"),
_("Switch between kg and lbs."),
"lbs,kg", "lbs"
);
OPTIONS["FORCE_CAPITAL_YN"] = cOpt("interface", _("Force Y/N in prompts"),
_("If true, Y/N prompts are case- sensitive and y and n are not accepted."),
true
);
OPTIONS["NO_BRIGHT_BACKGROUNDS"] = cOpt("interface", _("No bright backgrounds"),
_("If true, bright backgrounds are not used--some consoles are not compatible."),
false
);
//~ 12h time, e.g. 11:59pm
optionNames["12h"] = _("12h");
//~ Military time, e.g. 2359
optionNames["military"] = _("Military");
//~ 24h time, e.g. 23:59
optionNames["24h"] = _("24h");
OPTIONS["24_HOUR"] = cOpt("interface", _("24 hour time"),
_("12h: AM/PM, eg: 7:31 AM - Military: 24h Military, eg: 0731 - 24h: Normal 24h, eg: 7:31"),
"12h,military,24h", "12h"
);
OPTIONS["SNAP_TO_TARGET"] = cOpt("interface", _("Snap to target"),
_("If true, automatically follow the crosshair when firing/throwing."),
false
);
OPTIONS["SAFEMODE"] = cOpt("general", _("Safemode on by default"),
_("If true, safemode will be on after starting a new game or loading."),
true
);
OPTIONS["SAFEMODEPROXIMITY"] = cOpt("general", _("Safemode proximity distance"),
_("If safemode is enabled, distance to hostiles when safemode should show a warning. 0 = Max player viewdistance."),
0, 50, 0
);
OPTIONS["AUTOSAFEMODE"] = cOpt("general", _("Auto-safemode on by default"),
_("If true, auto-safemode will be on after starting a new game or loading."),
false
);
OPTIONS["AUTOSAFEMODETURNS"] = cOpt("general", _("Turns to reenable safemode"),
_("Number of turns after safemode is reenabled if no hostiles are in safemodeproximity distance."),
1, 100, 50
);
OPTIONS["AUTOSAVE"] = cOpt("general", _("Periodically autosave"),
_("If true, game will periodically save the map."),
false
);
OPTIONS["AUTOSAVE_TURNS"] = cOpt("general", _("Game turns between autosaves"),
_("Number of game turns between autosaves"),
1, 30, 5
);
OPTIONS["AUTOSAVE_MINUTES"] = cOpt("general", _("Real minutes between autosaves"),
_("Number of real time minutes between autosaves"),
0, 127, 5
);
OPTIONS["RAIN_ANIMATION"] = cOpt("interface", _("Rain animation"),
_("If true, will display weather animations."),
true
);
OPTIONS["CIRCLEDIST"] = cOpt("general", _("Circular distances"),
_("If true, the game will calculate range in a realistic way: light sources will be circles diagonal movement will cover more ground and take longer. If disabled, everything is square: moving to the northwest corner of a building takes as long as moving to the north wall."),
false
);
OPTIONS["QUERY_DISASSEMBLE"] = cOpt("interface", _("Query on disassembly"),
_("If true, will query before disassembling items."),
true
);
optionNames["no"] = _("No");
//~ containers
optionNames["watertight"] = _("Watertight");
optionNames["all"] = _("All");
OPTIONS["DROP_EMPTY"] = cOpt("general", _("Drop empty containers"),
_("Set to drop empty containers after use. No: Don't drop any. - Watertight: All except watertight containers. - All: Drop all containers."),
"no,watertight,all", "no"
);
//~ plain, default, normal
optionNames["vanilla"] = _("Vanilla");
//~ capped at a value
optionNames["capped"] = _("Capped");
//~ based on intelligence
optionNames["int"] = _("Int");
//~ based on intelligence and capped
optionNames["intcap"] = _("IntCap");
optionNames["off"] = _("Off");
OPTIONS["SKILL_RUST"] = cOpt("debug", _("Skill rust"),
_("Set the level of skill rust. Vanilla: Vanilla Cataclysm - Capped: Capped at skill levels 2 - Int: Intelligence dependent - IntCap: Intelligence dependent, capped - Off: None at all."),
"vanilla,capped,int,intcap,off", "vanilla"
);
optionNames["no"] = _("No");
optionNames["yes"] = _("Yes");
optionNames["query"] = _("Query");
OPTIONS["DELETE_WORLD"] = cOpt("general", _("Delete world"),
_("Delete world upon player death."),
"no,yes,query", "no"
);
OPTIONS["INITIAL_POINTS"] = cOpt("debug", _("Initial points"),
_("Initial points available on character generation."),
0, 25, 6
);
OPTIONS["MAX_TRAIT_POINTS"] = cOpt("debug", _("Maximum trait points"),
_("Maximum trait points available for character generation."),
0, 25, 12
);
OPTIONS["SPAWN_DENSITY"] = cOpt("general", _("Spawn rate scaling factor"),
_("A scaling factor that determines density of monster spawns."),
0.0, 50.0, 1.0, 0.1
);
OPTIONS["CITY_SIZE"] = cOpt("general", _("Size of cities"),
_("A number determining how large cities are. Warning, large numbers lead to very slow mapgen."),
4, 16, 4
);
OPTIONS["INITIAL_TIME"] = cOpt("debug", _("Initial time"),
_("Initial starting time of day on character generation."),
0, 23, 8
);
OPTIONS["VIEWPORT_X"] = cOpt("interface", _("Viewport width"),
_("SDL ONLY: Set the expansion of the viewport along the X axis. Requires restart. POSIX systems will use terminal size at startup."),
12, 93, 12
);
OPTIONS["VIEWPORT_Y"] = cOpt("interface", _("Viewport height"),
_("SDL ONLY: Set the expansion of the viewport along the Y axis. Requires restart. POSIX systems will use terminal size at startup."),
12, 93, 12
);
optionNames["standard"] = _("Standard");
//~ sidebar style
optionNames["narrow"] = _("Narrow");
OPTIONS["SIDEBAR_STYLE"] = cOpt("interface", _("Sidebar style"),
_("Switch between the standard or a narrower and taller sidebar. Requires restart."),
"standard,narrow", "standard"
);
OPTIONS["MOVE_VIEW_OFFSET"] = cOpt("interface", _("Move view offset"),
_("Move view by how many squares per keypress."),
1, 50, 1
);
OPTIONS["STATIC_SPAWN"] = cOpt("debug", _("Static spawn"),
_("Spawn zombies at game start instead of during game. Must reset world directory after changing for it to take effect."),
true
);
OPTIONS["CLASSIC_ZOMBIES"] = cOpt("debug", _("Classic zombies"),
_("Only spawn classic zombies and natural wildlife. Requires a reset of save folder to take effect. This disables certain buildings."),
false
);
OPTIONS["SEASON_LENGTH"] = cOpt("debug", _("Season length"),
_("Season length, in days."),
14, 127, 14
);
OPTIONS["STATIC_NPC"] = cOpt("debug", _("Static npcs"),
_("If true, the game will spawn static NPC at the start of the game, requires world reset."),
false
);
OPTIONS["RANDOM_NPC"] = cOpt("debug", _("Random npcs"),
_("If true, the game will randomly spawn NPC during gameplay."),
false
);
OPTIONS["RAD_MUTATION"] = cOpt("general", _("Mutations by radiation"),
_("If true, radiation causes the player to mutate."),
true
);
OPTIONS["SAVE_SLEEP"] = cOpt("interface", _("Ask to save before sleeping"),
_("If true, game will ask to save the map before sleeping."),
false
);
//~ show mouse cursor
optionNames["show"] = _("Show");
//~ hide mouse cursor
optionNames["hide"] = _("Hide");
//~ hide mouse cursor when keyboard is used
optionNames["hidekb"] = _("HideKB");
OPTIONS["HIDE_CURSOR"] = cOpt("interface", _("Hide mouse cursor"),
_("Always: Cursor is always shown. Hidden: Cursor is hidden. HiddenKB: Cursor is hidden on keyboard input and unhidden on mouse movement."),
"show,hide,hidekb", "show"
);
OPTIONS["MENU_SCROLL"] = cOpt("interface", _("Centered menu scrolling"),
_("If true, menus will start scrolling in the center of the list, and keep the list centered."),
true
);
OPTIONS["AUTO_PICKUP"] = cOpt("general", _("Enable item auto pickup"),
_("Enable item auto pickup. Change pickup rules with the Auto Pickup Manager in the Help Menu ?3"),
false
);
OPTIONS["AUTO_PICKUP_ZERO"] = cOpt("general", _("Auto pickup 0 vol light items"),
_("Auto pickup items with 0 Volume, and weight less than or equal to [option] * 50 grams. '0' disables this option"),
0, 20, 0
);
OPTIONS["AUTO_PICKUP_SAFEMODE"] = cOpt("general", _("Auto pickup safemode"),
_("Auto pickup is disabled as long as you can see monsters nearby. This is affected by Safemode proximity distance."),
false
);
OPTIONS["DANGEROUS_PICKUPS"] = cOpt("general", _("Dangerous pickups"),
_("If false will cause player to drop new items that cause them to exceed the weight limit."),
false
);
OPTIONS["SHIFT_LIST_ITEM_VIEW"] = cOpt("interface", _("Shift list item view"),
_("If true, shift the view toward the selected item if it is outside of your current viewport."),
true
);
OPTIONS["USE_TILES"] = cOpt("interface", _("Use tiles"),
_("If true, replaces some TTF rendered text with Tiles. Only applicable on SDL builds. Requires restart."),
true
);
for (std::map<std::string, cOpt>::iterator iter = OPTIONS.begin(); iter != OPTIONS.end(); ++iter) {
for (int i=0; i < vPages.size(); ++i) {
if (vPages[i].first == (iter->second).getPage()) {
mPageItems[i].push_back(iter->first);
break;
}
}
}
}
void game::show_options()
{
std::map<std::string, cOpt> OPTIONS_OLD = OPTIONS;
const int iTooltipHeight = 3;
const int iContentHeight = FULL_SCREEN_HEIGHT-3-iTooltipHeight;
const int iOffsetX = (TERMX > FULL_SCREEN_WIDTH) ? (TERMX-FULL_SCREEN_WIDTH)/2 : 0;
const int iOffsetY = (TERMY > FULL_SCREEN_HEIGHT) ? (TERMY-FULL_SCREEN_HEIGHT)/2 : 0;
std::map<int, bool> mapLines;
mapLines[3] = true;
mapLines[60] = true;
//mapLines[68] = true;
WINDOW* w_options_border = newwin(FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, iOffsetY, iOffsetX);
WINDOW* w_options_tooltip = newwin(iTooltipHeight, FULL_SCREEN_WIDTH - 2, 1 + iOffsetY, 1 + iOffsetX);
WINDOW* w_options_header = newwin(1, FULL_SCREEN_WIDTH - 2, 1 + iTooltipHeight + iOffsetY, 1 + iOffsetX);
WINDOW* w_options = newwin(iContentHeight, FULL_SCREEN_WIDTH - 2, iTooltipHeight + 2 + iOffsetY, 1 + iOffsetX);
wborder(w_options_border, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX, LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX);
mvwputch(w_options_border, 4, 0, c_ltgray, LINE_XXXO); // |-
mvwputch(w_options_border, 4, 79, c_ltgray, LINE_XOXX); // -|
for (std::map<int, bool>::iterator iter = mapLines.begin(); iter != mapLines.end(); ++iter) {
mvwputch(w_options_border, FULL_SCREEN_HEIGHT-1, iter->first + 1, c_ltgray, LINE_XXOX); // _|_
}
mvwprintz(w_options_border, 0, 36, c_ltred, _(" OPTIONS "));
wrefresh(w_options_border);
for (int i = 0; i < 78; i++) {
if (mapLines[i]) {
mvwputch(w_options_header, 0, i, c_ltgray, LINE_OXXX);
} else {
mvwputch(w_options_header, 0, i, c_ltgray, LINE_OXOX); // Draw header line
}
}
//mvwprintz(w_options_header, 3, 0, c_white, "#");
//mvwprintz(w_options_header, 3, 7, c_white, _("Option"));
//mvwprintz(w_options_header, 3, 52, c_white, _("Value"));
wrefresh(w_options_header);
int iCurrentPage = 0;
int iCurrentLine = 0;
int iStartPos = 0;
bool bStuffChanged = false;
char ch = ' ';
std::stringstream sTemp;
do {
//Clear the lines
for (int i = 0; i < iContentHeight; i++) {
for (int j = 0; j < 79; j++) {
if (mapLines[j]) {
mvwputch(w_options, i, j, c_ltgray, LINE_XOXO);
} else {
mvwputch(w_options, i, j, c_black, ' ');
}
if (i < iTooltipHeight) {
mvwputch(w_options_tooltip, i, j, c_black, ' ');
}
}
}
calcStartPos(iStartPos, iCurrentLine, iContentHeight, mPageItems[iCurrentPage].size());
//Draw options
for (int i = iStartPos; i < iStartPos + ((iContentHeight > mPageItems[iCurrentPage].size()) ? mPageItems[iCurrentPage].size() : iContentHeight); i++) {
nc_color cLineColor = c_ltgreen;
sTemp.str("");
sTemp << i + 1;
mvwprintz(w_options, i - iStartPos, 0, c_white, sTemp.str().c_str());
mvwprintz(w_options, i - iStartPos, 4, c_white, "");
if (iCurrentLine == i) {
wprintz(w_options, c_yellow, ">> ");
} else {
wprintz(w_options, c_yellow, " ");
}
wprintz(w_options, c_white, "%s", (OPTIONS[mPageItems[iCurrentPage][i]].getMenuText()).c_str());
if (OPTIONS[mPageItems[iCurrentPage][i]].getValue() == "false") {
cLineColor = c_ltred;
}
mvwprintz(w_options, i - iStartPos, 62, (iCurrentLine == i) ? hilite(cLineColor) : cLineColor, "%s", (OPTIONS[mPageItems[iCurrentPage][i]].getName()).c_str());
}
//Draw Scrollbar
draw_scrollbar(w_options_border, iCurrentLine, iContentHeight, mPageItems[iCurrentPage].size(), 5);
//Draw Tabs
mvwprintz(w_options_header, 0, 7, c_white, "");
for (int i = 0; i < vPages.size(); i++) {
if (mPageItems[i].size() > 0) { //skip empty pages
wprintz(w_options_header, c_white, "[");
wprintz(w_options_header, (iCurrentPage == i) ? hilite(c_ltgreen) : c_ltgreen, (vPages[i].second).c_str());
wprintz(w_options_header, c_white, "]");
wputch(w_options_header, c_white, LINE_OXOX);
}
}
wrefresh(w_options_header);
fold_and_print(w_options_tooltip, 0, 0, 78, c_white, "%s", (OPTIONS[mPageItems[iCurrentPage][iCurrentLine]].getTooltip() + " #" + OPTIONS[mPageItems[iCurrentPage][iCurrentLine]].getDefaultText()).c_str());
wrefresh(w_options_tooltip);
wrefresh(w_options);
ch = input();
if (mPageItems[iCurrentPage].size() > 0 || ch == '\t') {
switch(ch) {
case 'j': //move down
iCurrentLine++;
if (iCurrentLine >= mPageItems[iCurrentPage].size()) {
iCurrentLine = 0;
}
break;
case 'k': //move up
iCurrentLine--;
if (iCurrentLine < 0) {
iCurrentLine = mPageItems[iCurrentPage].size()-1;
}
break;
case 'l': //set to prev value
OPTIONS[mPageItems[iCurrentPage][iCurrentLine]].setNext();
bStuffChanged = true;
break;
case 'h': //set to next value
OPTIONS[mPageItems[iCurrentPage][iCurrentLine]].setPrev();
bStuffChanged = true;
break;
case '>':
case '\t': //Switch to next Page
iCurrentLine = 0;
do { //skip empty pages
iCurrentPage++;
if (iCurrentPage >= vPages.size()) {
iCurrentPage = 0;
}
} while(mPageItems[iCurrentPage].size() == 0);
break;
case '<':
iCurrentLine = 0;
do { //skip empty pages
iCurrentPage--;
if (iCurrentPage < 0) {
iCurrentPage = vPages.size()-1;
}
} while(mPageItems[iCurrentPage].size() == 0);
break;
}
}
} while(ch != 'q' && ch != 'Q' && ch != KEY_ESCAPE);
if (bStuffChanged) {
if(query_yn(_("Save changes?"))) {
save_options();
} else {
OPTIONS = OPTIONS_OLD;
}
}
werase(w_options);
werase(w_options_border);
werase(w_options_header);
werase(w_options_tooltip);
}
void load_options()
{
std::ifstream fin;
fin.open("data/options.txt");
if(!fin.is_open()) {
fin.close();
save_options();
fin.open("data/options.txt");
if(!fin.is_open()) {
DebugLog() << "Could neither read nor create ./data/options.txt\n";
return;
}
}
std::string sLine;
while(!fin.eof()) {
getline(fin, sLine);
if(sLine != "" && sLine[0] != '#' && std::count(sLine.begin(), sLine.end(), ' ') == 1) {
int iPos = sLine.find(' ');
OPTIONS[sLine.substr(0, iPos)].setValue(sLine.substr(iPos+1, sLine.length()));
}
}
fin.close();
trigdist = OPTIONS["CIRCLEDIST"]; // cache to global due to heavy usage.
use_tiles = OPTIONS["USE_TILES"]; // cache to global due to heavy usage.
}
std::string options_header()
{
return "\
# This is the options file. It works similarly to keymap.txt: the format is\n\
# <option name> <option value>\n\
# <option value> may be any number, positive or negative. If you use a\n\
# negative sign, do not put a space between it and the number.\n\
#\n\
# If # is at the start of a line, it is considered a comment and is ignored.\n\
# In-line commenting is not allowed. I think.\n\
#\n\
# If you want to restore the default options, simply delete this file.\n\
# A new options.txt will be created next time you play.\n\
\n\
";
}
void save_options()
{
std::ofstream fout;
fout.open("data/options.txt");
if(!fout.is_open()) {
return;
}
fout << options_header() << std::endl;
for(int j = 0; j < vPages.size(); j++) {
for(int i = 0; i < mPageItems[j].size(); i++) {
fout << "#" << OPTIONS[mPageItems[j][i]].getTooltip() << std::endl;
fout << "#" << OPTIONS[mPageItems[j][i]].getDefaultText() << std::endl;
fout << mPageItems[j][i] << " " << OPTIONS[mPageItems[j][i]].getValue() << std::endl << std::endl;
}
}
fout.close();
trigdist = OPTIONS["CIRCLEDIST"]; // update trigdist as well
}