/
preferences.cpp
4022 lines (3386 loc) · 138 KB
/
preferences.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
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (C) 1991-2001 and beyond by Bungie Studios, Inc.
and the "Aleph One" developers.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This license is contained in the file "COPYING",
which is included with this source code; it is available online at
http://www.gnu.org/licenses/gpl.html
Feb 5, 2002 (Br'fin (Jeremy Parsons)):
Default to keyboard and mouse control under Carbon
for there are no InputSprockets
Apr 30, 2002 (Loren Petrich):
Converting to a MML-based preferences system
May 16, 2002 (Woody Zenfell):
Added UI/preferences elements for configurable mouse sensitivity
Support for "don't auto-recenter" behavior modifier
Routines to let other code disable/reenable/query behavior modification
Jul 21, 2002 (Loren Petrich):
AS had added some code to fix the OSX preferences behavior;
I modified it so that it would not be used in the Classic version
Apr 10-22, 2003 (Woody Zenfell):
Join hinting and autogathering have Preferences entries now
Being less obnoxious with unrecognized Prefs stuff
Macintosh Enviroprefs popup style can be set in Preferences file
May 22, 2003 (Woody Zenfell):
Support for preferences for multiple network game protocols; configurable local game port.
May 27, 2003 (Gregory Smith):
Preferences for speex netmic
August 27, 2003 (Woody Zenfell):
Preferences for netscript. Some reworking of index-based Mac FSSpec reading along the way.
*/
/*
* preferences.cpp - Preferences handling
*/
#include "cseries.h"
#include "FileHandler.h"
#include "map.h"
#include "shell.h" /* For the screen_mode structure */
#include "interface.h"
#include "SoundManager.h"
#include "preferences.h"
#include "wad.h"
#include "wad_prefs.h"
#include "game_errors.h"
#include "network.h" // for _ethernet, etc.
#include "find_files.h"
#include "game_wad.h" // for set_map_file
#include "screen.h"
#include "fades.h"
#include "extensions.h"
#include "Console.h"
#include "Plugins.h"
#include "InfoTree.h"
#include "StarGameProtocol.h"
#include "RingGameProtocol.h"
#include "tags.h"
#include "Logging.h"
#include <string.h>
#include <stdlib.h>
#include "sdl_dialogs.h"
#include "sdl_fonts.h"
#include "sdl_widgets.h"
#include "images.h"
#include "preference_dialogs.h"
#include "preferences_widgets_sdl.h"
#include "mouse.h"
#include "Music.h"
#include "HTTP.h"
#include "alephversion.h"
#include <cmath>
#include <sstream>
#include <boost/algorithm/hex.hpp>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef __WIN32__
#include <windows.h> // for GetUserName()
#endif
#include "joystick.h"
// 8-bit support is still here if you undefine this, but you'll need to fix it
#define TRUE_COLOR_ONLY 1
using namespace alephone;
static const char sPasswordMask[] = "reverof nohtaram";
static const char* sNetworkGameProtocolNames[] =
{ // These should match up with _network_game_protocol_ring, etc.
"ring",
"star"
};
static const size_t NUMBER_OF_NETWORK_GAME_PROTOCOL_NAMES = sizeof(sNetworkGameProtocolNames) / sizeof(sNetworkGameProtocolNames[0]);
// Have the prefs been inited?
static bool PrefsInited = false;
// Global preferences data
struct graphics_preferences_data *graphics_preferences = NULL;
struct network_preferences_data *network_preferences = NULL;
struct player_preferences_data *player_preferences = NULL;
struct input_preferences_data *input_preferences = NULL;
SoundManager::Parameters *sound_preferences = NULL;
struct environment_preferences_data *environment_preferences = NULL;
// LP: fake portable-files stuff
inline short memory_error() {return 0;}
static bool ethernet_active(void);
static std::string get_name_from_system(void);
// LP: getting rid of the (void *) mechanism as inelegant and non-type-safe
static void default_graphics_preferences(graphics_preferences_data *preferences);
static bool validate_graphics_preferences(graphics_preferences_data *preferences);
static void default_network_preferences(network_preferences_data *preferences);
static bool validate_network_preferences(network_preferences_data *preferences);
static void default_player_preferences(player_preferences_data *preferences);
static bool validate_player_preferences(player_preferences_data *preferences);
static void default_input_preferences(input_preferences_data *preferences);
static bool validate_input_preferences(input_preferences_data *preferences);
static void default_environment_preferences(environment_preferences_data *preferences);
static bool validate_environment_preferences(environment_preferences_data *preferences);
void parse_graphics_preferences(InfoTree root, std::string version);
void parse_player_preferences(InfoTree root, std::string version);
void parse_input_preferences(InfoTree root, std::string version);
void parse_sound_preferences(InfoTree root, std::string version);
void parse_network_preferences(InfoTree root, std::string version);
void parse_environment_preferences(InfoTree root, std::string version);
// Prototypes
static void player_dialog(void *arg);
static void online_dialog(void *arg);
static void graphics_dialog(void *arg);
static void sound_dialog(void *arg);
static void controls_dialog(void *arg);
static void environment_dialog(void *arg);
static void plugins_dialog(void *arg);
static void keyboard_dialog(void *arg);
//static void texture_options_dialog(void *arg);
/*
* Get user name
*/
static std::string get_name_from_system()
{
#if defined(unix) || (defined (__APPLE__) && defined (__MACH__)) || defined(__NetBSD__) || defined(__OpenBSD__)
const char *login_name = getlogin();
std::string login = (login_name ? login_name : "");
if (login.length())
return login;
#elif defined(__WIN32__)
char login[17];
DWORD len = 17;
bool hasName = (GetUserName((LPSTR)login, &len) == TRUE);
if (hasName && strpbrk(login, "\\/:*?\"<>|") == NULL) // Ignore illegal names
return login;
#else
//#error get_name_from_system() not implemented for this platform
#endif
return "Bob User";
}
/*
* Ethernet always available
*/
static bool ethernet_active(void)
{
return true;
}
/*
* Main preferences dialog
*/
void handle_preferences(void)
{
// Save the existing preferences, in case we have to reload them
write_preferences();
// Create top-level dialog
dialog d;
vertical_placer *placer = new vertical_placer;
w_title *w_header = new w_title("PREFERENCES");
d.add(w_header);
w_button *w_player = new w_button("PLAYER", player_dialog, &d);
d.add(w_player);
w_button *w_online = new w_button("INTERNET", online_dialog, &d);
d.add(w_online);
w_button *w_graphics = new w_button("GRAPHICS", graphics_dialog, &d);
d.add(w_graphics);
w_button *w_sound = new w_button("SOUND", sound_dialog, &d);
d.add(w_sound);
w_button *w_controls = new w_button("CONTROLS", controls_dialog, &d);
d.add(w_controls);
w_button *w_environment = new w_button("ENVIRONMENT", environment_dialog, &d);
d.add(w_environment);
w_button *w_return = new w_button("RETURN", dialog_cancel, &d);
d.add(w_return);
placer->add(w_header);
placer->add(new w_spacer, true);
placer->add(w_player);
placer->add(w_online);
placer->add(w_graphics);
placer->add(w_sound);
placer->add(w_controls);
placer->add(w_environment);
placer->add(new w_spacer, true);
placer->add(w_return);
d.set_widget_placer(placer);
// Clear menu screen
clear_screen();
// Run dialog
d.run();
// Redraw main menu
display_main_menu();
}
class CrosshairPref : public Bindable<int>
{
public:
CrosshairPref(short& pref) : m_pref(pref) { }
virtual int bind_export() {
return (m_pref - 1);
}
virtual void bind_import(int value) {
m_pref = value + 1;
}
protected:
short& m_pref;
};
class ColorComponentPref : public Bindable<int>
{
public:
ColorComponentPref(uint16& pref) : m_pref(pref) { }
virtual int bind_export() {
return (m_pref >> 12);
}
virtual void bind_import(int value) {
m_pref = value << 12;
}
protected:
uint16& m_pref;
};
class OpacityPref : public Bindable<int>
{
public:
OpacityPref(float& pref) : m_pref(pref) { }
virtual int bind_export() {
return (static_cast<int>(floor(m_pref * 16)));
}
virtual void bind_import(int value) {
m_pref = ((float) value / 16.0);
}
protected:
float& m_pref;
};
static const char *shape_labels[3] = {
"Cross", "Octagon", NULL
};
enum { kCrosshairWidget };
static std::unique_ptr<BinderSet> crosshair_binders;
struct update_crosshair_display
{
void operator()(dialog *d) {
crosshair_binders->migrate_all_first_to_second();
}
};
class w_crosshair_slider : public w_slider {
public:
w_crosshair_slider(int num_items, int sel) : w_slider(num_items, sel) {
init_formatted_value();
}
virtual std::string formatted_value(void) {
std::ostringstream ss;
ss << (selection + 1);
return ss.str();
}
};
static void crosshair_dialog(void *arg)
{
CrosshairData OldCrosshairs = player_preferences->Crosshairs;
crosshair_binders.reset(new BinderSet);
dialog *parent = (dialog *) arg;
(void)parent;
dialog d;
vertical_placer *placer = new vertical_placer;
w_title *w_header = new w_title("CROSSHAIR SETTINGS");
placer->dual_add(w_header, d);
placer->add(new w_spacer, true);
placer->dual_add(new w_static_text("HUD plugins may override these settings."), d);
placer->add(new w_spacer, true);
w_crosshair_display *crosshair_w = new w_crosshair_display();
placer->dual_add(crosshair_w, d);
placer->add(new w_spacer, true);
table_placer *table = new table_placer(2, get_theme_space(ITEM_WIDGET));
table->col_flags(0, placeable::kAlignRight);
// Shape
w_select *shape_w = new w_select(0, shape_labels);
SelectSelectorWidget shapeWidget(shape_w);
Int16Pref shapePref(player_preferences->Crosshairs.Shape);
crosshair_binders->insert<int> (&shapeWidget, &shapePref);
table->dual_add(shape_w->label("Shape"), d);
table->dual_add(shape_w, d);
table->add_row(new w_spacer(), true);
// Thickness
w_slider* thickness_w = new w_crosshair_slider(7, 0);
SliderSelectorWidget thicknessWidget(thickness_w);
CrosshairPref thicknessPref(player_preferences->Crosshairs.Thickness);
crosshair_binders->insert<int> (&thicknessWidget, &thicknessPref);
table->dual_add(thickness_w->label("Width"), d);
table->dual_add(thickness_w, d);
// From Center
w_slider *from_center_w = new w_slider(15, 0);
SliderSelectorWidget fromCenterWidget(from_center_w);
Int16Pref fromCenterPref(player_preferences->Crosshairs.FromCenter);
crosshair_binders->insert<int> (&fromCenterWidget, &fromCenterPref);
table->dual_add(from_center_w->label("Gap"), d);
table->dual_add(from_center_w, d);
// Length
w_slider *length_w = new w_crosshair_slider(15, 0);
SliderSelectorWidget lengthWidget(length_w);
CrosshairPref lengthPref(player_preferences->Crosshairs.Length);
crosshair_binders->insert<int> (&lengthWidget, &lengthPref);
table->dual_add(length_w->label("Size"), d);
table->dual_add(length_w, d);
table->add_row(new w_spacer(), true);
table->dual_add_row(new w_static_text("Color"), d);
// Color
w_slider *red_w = new w_percentage_slider(16, 0);
SliderSelectorWidget redWidget(red_w);
ColorComponentPref redPref(player_preferences->Crosshairs.Color.red);
crosshair_binders->insert<int> (&redWidget, &redPref);
table->dual_add(red_w->label("Red"), d);
table->dual_add(red_w, d);
w_slider *green_w = new w_percentage_slider(16, 0);
SliderSelectorWidget greenWidget(green_w);;
ColorComponentPref greenPref(player_preferences->Crosshairs.Color.green);
crosshair_binders->insert<int> (&greenWidget, &greenPref);
table->dual_add(green_w->label("Green"), d);
table->dual_add(green_w, d);
w_slider *blue_w = new w_percentage_slider(16, 0);
SliderSelectorWidget blueWidget(blue_w);
ColorComponentPref bluePref(player_preferences->Crosshairs.Color.blue);
crosshair_binders->insert<int> (&blueWidget, &bluePref);
table->dual_add(blue_w->label("Blue"), d);
table->dual_add(blue_w, d);
table->add_row(new w_spacer(), true);
table->dual_add_row(new w_static_text("OpenGL Only (no preview)"), d);
w_slider *opacity_w = new w_percentage_slider(16, 0);
SliderSelectorWidget opacityWidget(opacity_w);
OpacityPref opacityPref(player_preferences->Crosshairs.Opacity);
crosshair_binders->insert<int> (&opacityWidget, &opacityPref);
table->dual_add(opacity_w->label("Opacity"), d);
table->dual_add(opacity_w, d);
placer->add(table, true);
placer->add(new w_spacer, true);
horizontal_placer *button_placer = new horizontal_placer;
w_button *w_accept = new w_button("ACCEPT", dialog_ok, &d);
button_placer->dual_add(w_accept, d);
w_button *w_cancel = new w_button("CANCEL", dialog_cancel, &d);
button_placer->dual_add(w_cancel, d);
placer->add(button_placer, true);
d.set_widget_placer(placer);
d.set_processing_function(update_crosshair_display());
crosshair_binders->migrate_all_second_to_first();
clear_screen();
if (d.run() == 0) // Accepted
{
crosshair_binders->migrate_all_first_to_second();
player_preferences->Crosshairs.PreCalced = false;
write_preferences();
}
else
{
player_preferences->Crosshairs = OldCrosshairs;
}
crosshair_binders.reset(0);
}
/*
* Player dialog
*/
enum {
NAME_W
};
static void player_dialog(void *arg)
{
// Create dialog
dialog d;
vertical_placer *placer = new vertical_placer;
placer->dual_add(new w_title("PLAYER SETTINGS"), d);
placer->add(new w_spacer());
table_placer *table = new table_placer(2, get_theme_space(ITEM_WIDGET), true);
table->col_flags(0, placeable::kAlignRight);
table->col_flags(1, placeable::kAlignLeft);
w_select *level_w = new w_select(player_preferences->difficulty_level, NULL /*level_labels*/);
level_w->set_labels_stringset(kDifficultyLevelsStringSetID);
table->dual_add(level_w->label("Difficulty"), d);
table->dual_add(level_w, d);
table->add_row(new w_spacer(), true);
table->dual_add_row(new w_static_text("Appearance"), d);
w_text_entry *name_w = new w_text_entry(PREFERENCES_NAME_LENGTH, player_preferences->name);
name_w->set_identifier(NAME_W);
name_w->set_enter_pressed_callback(dialog_try_ok);
name_w->set_value_changed_callback(dialog_disable_ok_if_empty);
name_w->enable_mac_roman_input();
table->dual_add(name_w->label("Name"), d);
table->dual_add(name_w, d);
w_player_color *pcolor_w = new w_player_color(player_preferences->color);
table->dual_add(pcolor_w->label("Color"), d);
table->dual_add(pcolor_w, d);
w_player_color *tcolor_w = new w_player_color(player_preferences->team);
table->dual_add(tcolor_w->label("Team"), d);
table->dual_add(tcolor_w, d);
table->add_row(new w_spacer(), true);
w_toggle *crosshairs_active_w = new w_toggle(player_preferences->crosshairs_active);
table->dual_add(crosshairs_active_w->label("Show crosshairs"), d);
table->dual_add(crosshairs_active_w, d);
placer->add(table, true);
placer->add(new w_spacer(), true);
w_button *crosshair_button = new w_button("CROSSHAIR SETTINGS", crosshair_dialog, &d);
placer->dual_add(crosshair_button, d);
placer->add(new w_spacer(), true);
horizontal_placer *button_placer = new horizontal_placer;
w_button* ok_button = new w_button("ACCEPT", dialog_ok, &d);
ok_button->set_identifier(iOK);
button_placer->dual_add(ok_button, d);
button_placer->dual_add(new w_button("CANCEL", dialog_cancel, &d), d);
placer->add(button_placer, true);
d.set_widget_placer(placer);
// Clear screen
clear_screen();
// Run dialog
if (d.run() == 0) { // Accepted
bool changed = false;
const char *name = name_w->get_text();
if (strcmp(name, player_preferences->name)) {
strncpy(player_preferences->name, name, PREFERENCES_NAME_LENGTH);
player_preferences->name[PREFERENCES_NAME_LENGTH] = '\0';
changed = true;
}
int16 level = static_cast<int16>(level_w->get_selection());
assert(level >= 0);
if (level != player_preferences->difficulty_level) {
player_preferences->difficulty_level = level;
changed = true;
}
int16 color = static_cast<int16>(pcolor_w->get_selection());
assert(color >= 0);
if (color != player_preferences->color) {
player_preferences->color = color;
changed = true;
}
int16 team = static_cast<int16>(tcolor_w->get_selection());
assert(team >= 0);
if (team != player_preferences->team) {
player_preferences->team = team;
changed = true;
}
bool crosshair = crosshairs_active_w->get_selection();
if (crosshair != player_preferences->crosshairs_active) {
player_preferences->crosshairs_active = crosshair;
changed = true;
}
if (changed)
write_preferences();
}
}
/*
* Online (lhowon.org) dialog
*/
const int iONLINE_USERNAME_W = 10;
const int iONLINE_PASSWORD_W = 11;
const int iSIGNUP_EMAIL_W = 20;
const int iSIGNUP_USERNAME_W = 21;
const int iSIGNUP_PASSWORD_W = 22;
static void proc_account_link(void *arg)
{
dialog *d = static_cast<dialog *>(arg);
HTTPClient conn;
HTTPClient::parameter_map params;
w_text_entry *username_w = static_cast<w_text_entry *>(d->get_widget_by_id(iONLINE_USERNAME_W));
w_text_entry *password_w = static_cast<w_text_entry *>(d->get_widget_by_id(iONLINE_PASSWORD_W));
params["username"] = username_w->get_text();
params["password"] = password_w->get_text();
params["salt"] = "";
std::string url = A1_METASERVER_SETTINGS_URL;
if (conn.Post(A1_METASERVER_LOGIN_URL, params))
{
std::string token = boost::algorithm::hex(conn.Response());
url += "?token=" + token;
}
toggle_fullscreen(false);
launch_url_in_browser(url.c_str());
d->draw();
}
static void signup_dialog_ok(void *arg)
{
dialog *d = static_cast<dialog *>(arg);
w_text_entry *email_w = static_cast<w_text_entry *>(d->get_widget_by_id(iSIGNUP_EMAIL_W));
w_text_entry *login_w = static_cast<w_text_entry *>(d->get_widget_by_id(iSIGNUP_USERNAME_W));
w_password_entry *password_w = static_cast<w_password_entry *>(d->get_widget_by_id(iSIGNUP_PASSWORD_W));
// check that fields are filled out
if (strlen(email_w->get_text()) == 0)
{
alert_user("Please enter your email address.", infoError);
}
else if (strlen(login_w->get_text()) == 0)
{
alert_user("Please enter a username.", infoError);
}
else if (strlen(password_w->get_text()) == 0)
{
alert_user("Please enter a password.", infoError);
}
else
{
// send parameters to server
HTTPClient conn;
HTTPClient::parameter_map params;
params["email"] = email_w->get_text();
params["username"] = login_w->get_text();
params["password"] = password_w->get_text();
if (conn.Post(A1_METASERVER_SIGNUP_URL, params))
{
if (conn.Response() == "OK")
{
// account was created successfully, save username and password
strncpy(network_preferences->metaserver_login, login_w->get_text(), network_preferences_data::kMetaserverLoginLength);
strncpy(network_preferences->metaserver_password, password_w->get_text(), network_preferences_data::kMetaserverLoginLength);
write_preferences();
d->quit(0);
}
else
{
alert_user(conn.Response().c_str(), infoError);
}
}
else
{
alert_user("There was a problem contacting the server.", infoError);
}
}
}
static void signup_dialog(void *arg)
{
dialog d;
vertical_placer *placer = new vertical_placer;
placer->dual_add(new w_title("ACCOUNT SIGN UP"), d);
placer->add(new w_spacer());
table_placer *table = new table_placer(2, get_theme_space(ITEM_WIDGET), true);
table->col_flags(0, placeable::kAlignRight);
table->col_flags(1, placeable::kAlignLeft);
w_text_entry *email_w = new w_text_entry(256, "");
email_w->set_identifier(iSIGNUP_EMAIL_W);
table->dual_add(email_w->label("Email Address"), d);
table->dual_add(email_w, d);
w_text_entry *login_w = new w_text_entry(network_preferences_data::kMetaserverLoginLength, network_preferences->metaserver_login);
login_w->set_identifier(iSIGNUP_USERNAME_W);
table->dual_add(login_w->label("Username"), d);
table->dual_add(login_w, d);
w_password_entry *password_w = new w_password_entry(network_preferences_data::kMetaserverLoginLength, network_preferences->metaserver_password);
password_w->set_identifier(iSIGNUP_PASSWORD_W);
table->dual_add(password_w->label("Password"), d);
table->dual_add(password_w, d);
table->add_row(new w_spacer(), true);
placer->add(table, true);
horizontal_placer *button_placer = new horizontal_placer;
w_button* ok_button = new w_button("SIGN UP", signup_dialog_ok, &d);
ok_button->set_identifier(iOK);
button_placer->dual_add(ok_button, d);
button_placer->dual_add(new w_button("CANCEL", dialog_cancel, &d), d);
placer->add(button_placer, true);
d.set_widget_placer(placer);
clear_screen();
if (d.run() == 0)
{
// account was successfully created, update parent fields with new account info
dialog *parent = static_cast<dialog *>(arg);
w_text_entry *login_w = static_cast<w_text_entry *>(parent->get_widget_by_id(iONLINE_USERNAME_W));
login_w->set_text(network_preferences->metaserver_login);
w_password_entry *password_w = static_cast<w_password_entry *>(parent->get_widget_by_id(iONLINE_PASSWORD_W));
password_w->set_text(network_preferences->metaserver_password);
}
}
static void online_dialog(void *arg)
{
// Create dialog
dialog d;
vertical_placer *placer = new vertical_placer;
placer->dual_add(new w_title("INTERNET GAME SETUP"), d);
placer->add(new w_spacer());
tab_placer* tabs = new tab_placer();
std::vector<std::string> labels;
labels.push_back("ACCOUNT");
labels.push_back("PREGAME LOBBY");
labels.push_back("STATS");
w_tab *tab_w = new w_tab(labels, tabs);
placer->dual_add(tab_w, d);
placer->add(new w_spacer(), true);
vertical_placer *account = new vertical_placer();
table_placer *account_table = new table_placer(2, get_theme_space(ITEM_WIDGET), true);
account_table->col_flags(0, placeable::kAlignRight);
account_table->col_flags(1, placeable::kAlignLeft);
w_text_entry *login_w = new w_text_entry(network_preferences_data::kMetaserverLoginLength, network_preferences->metaserver_login);
login_w->set_identifier(iONLINE_USERNAME_W);
account_table->dual_add(login_w->label("Username"), d);
account_table->dual_add(login_w, d);
w_password_entry *password_w = new w_password_entry(network_preferences_data::kMetaserverLoginLength, network_preferences->metaserver_password);
password_w->set_identifier(iONLINE_PASSWORD_W);
account_table->dual_add(password_w->label("Password"), d);
account_table->dual_add(password_w, d);
w_hyperlink *account_link_w = new w_hyperlink("", "Visit my lhowon.org account page");
account_link_w->set_callback(proc_account_link, &d);
account_table->dual_add_row(account_link_w, d);
account_table->add_row(new w_spacer(), true);
w_button *signup_button = new w_button("SIGN UP", signup_dialog, &d);
account_table->dual_add_row(signup_button, d);
account_table->add_row(new w_spacer(), true);
account->add(account_table, true);
vertical_placer *lobby = new vertical_placer();
table_placer *lobby_table = new table_placer(2, get_theme_space(ITEM_WIDGET), true);
lobby_table->col_flags(0, placeable::kAlignRight);
lobby_table->col_flags(1, placeable::kAlignLeft);
w_text_entry *name_w = new w_text_entry(PREFERENCES_NAME_LENGTH, player_preferences->name);
name_w->set_identifier(NAME_W);
name_w->set_enter_pressed_callback(dialog_try_ok);
name_w->set_value_changed_callback(dialog_disable_ok_if_empty);
name_w->enable_mac_roman_input();
lobby_table->dual_add(name_w->label("Name"), d);
lobby_table->dual_add(name_w, d);
w_enabling_toggle *custom_colors_w = new w_enabling_toggle(network_preferences->use_custom_metaserver_colors);
lobby_table->dual_add(custom_colors_w->label("Custom Chat Colors"), d);
lobby_table->dual_add(custom_colors_w, d);
w_color_picker *primary_w = new w_color_picker(network_preferences->metaserver_colors[0]);
lobby_table->dual_add(primary_w->label("Primary"), d);
lobby_table->dual_add(primary_w, d);
w_color_picker *secondary_w = new w_color_picker(network_preferences->metaserver_colors[1]);
lobby_table->dual_add(secondary_w->label("Secondary"), d);
lobby_table->dual_add(secondary_w, d);
custom_colors_w->add_dependent_widget(primary_w);
custom_colors_w->add_dependent_widget(secondary_w);
w_toggle *mute_guests_w = new w_toggle(network_preferences->mute_metaserver_guests);
lobby_table->dual_add(mute_guests_w->label("Mute All Guest Chat"), d);
lobby_table->dual_add(mute_guests_w, d);
lobby_table->add_row(new w_spacer(), true);
w_toggle *join_meta_w = new w_toggle(network_preferences->join_metaserver_by_default);
lobby_table->dual_add(join_meta_w->label("Join Pregame Lobby by Default"), d);
lobby_table->dual_add(join_meta_w, d);
lobby_table->add_row(new w_spacer(), true);
lobby->add(lobby_table, true);
vertical_placer *stats = new vertical_placer();
stats->dual_add(new w_hyperlink(A1_LEADERBOARD_URL, "Visit the leaderboards"), d);
stats->add(new w_spacer(), true);
horizontal_placer *stats_box = new horizontal_placer();
w_toggle *allow_stats_w = new w_toggle(network_preferences->allow_stats);
stats_box->dual_add(allow_stats_w, d);
stats_box->dual_add(allow_stats_w->label("Send Stats to Lhowon.org"), d);
stats->add(stats_box, true);
stats->add(new w_spacer(), true);
stats->dual_add(new w_static_text("To compete on the leaderboards,"), d);
stats->dual_add(new w_static_text("you need an online account, and a"), d);
stats->dual_add(new w_static_text("Stats plugin installed and enabled."), d);
stats->add(new w_spacer(), true);
stats->dual_add(new w_button("PLUGINS", plugins_dialog, &d), d);
stats->add(new w_spacer(), true);
tabs->add(account, true);
tabs->add(lobby, true);
tabs->add(stats, true);
placer->add(tabs, true);
placer->add(new w_spacer(), true);
horizontal_placer *button_placer = new horizontal_placer;
w_button* ok_button = new w_button("ACCEPT", dialog_ok, &d);
ok_button->set_identifier(iOK);
button_placer->dual_add(ok_button, d);
button_placer->dual_add(new w_button("CANCEL", dialog_cancel, &d), d);
placer->add(button_placer, true);
d.set_widget_placer(placer);
// Clear screen
clear_screen();
// Run dialog
if (d.run() == 0) { // Accepted
bool changed = false;
const char *name = name_w->get_text();
if (strcmp(name, player_preferences->name)) {
strncpy(player_preferences->name, name, PREFERENCES_NAME_LENGTH);
player_preferences->name[PREFERENCES_NAME_LENGTH] = '\0';
changed = true;
}
const char *metaserver_login = login_w->get_text();
if (strcmp(metaserver_login, network_preferences->metaserver_login)) {
strncpy(network_preferences->metaserver_login, metaserver_login, network_preferences_data::kMetaserverLoginLength-1);
network_preferences->metaserver_login[network_preferences_data::kMetaserverLoginLength-1] = '\0';
changed = true;
}
// clear password if login has been cleared
if (!strlen(metaserver_login)) {
if (strlen(network_preferences->metaserver_password)) {
network_preferences->metaserver_password[0] = '\0';
changed = true;
}
} else {
const char *metaserver_password = password_w->get_text();
if (strcmp(metaserver_password, network_preferences->metaserver_password)) {
strncpy(network_preferences->metaserver_password, metaserver_password, network_preferences_data::kMetaserverLoginLength-1);
network_preferences->metaserver_password[network_preferences_data::kMetaserverLoginLength-1] = '\0';
changed = true;
}
}
bool use_custom_metaserver_colors = custom_colors_w->get_selection();
if (use_custom_metaserver_colors != network_preferences->use_custom_metaserver_colors)
{
network_preferences->use_custom_metaserver_colors = use_custom_metaserver_colors;
changed = true;
}
if (use_custom_metaserver_colors)
{
rgb_color primary_color = primary_w->get_selection();
if (primary_color.red != network_preferences->metaserver_colors[0].red || primary_color.green != network_preferences->metaserver_colors[0].green || primary_color.blue != network_preferences->metaserver_colors[0].blue)
{
network_preferences->metaserver_colors[0] = primary_color;
changed = true;
}
rgb_color secondary_color = secondary_w->get_selection();
if (secondary_color.red != network_preferences->metaserver_colors[1].red || secondary_color.green != network_preferences->metaserver_colors[1].green || secondary_color.blue != network_preferences->metaserver_colors[1].blue) {
network_preferences->metaserver_colors[1] = secondary_color;
changed = true;
}
}
bool mute_metaserver_guests = mute_guests_w->get_selection() == 1;
if (mute_metaserver_guests != network_preferences->mute_metaserver_guests)
{
network_preferences->mute_metaserver_guests = mute_metaserver_guests;
changed = true;
}
bool join_meta = join_meta_w->get_selection() == 1;
if (join_meta != network_preferences->join_metaserver_by_default)
{
network_preferences->join_metaserver_by_default = join_meta;
changed = true;
}
bool allow_stats = allow_stats_w->get_selection() == 1;
if (allow_stats != network_preferences->allow_stats)
{
network_preferences->allow_stats = allow_stats;
Plugins::instance()->invalidate();
changed = true;
}
if (changed)
write_preferences();
}
}
/*
* Handle graphics dialog
*/
#ifdef TRUE_COLOR_ONLY
static const char* depth_labels[3] = {
"16 Bit", "32 Bit", NULL
};
#else
static const char *depth_labels[4] = {
"8 Bit", "16 Bit", "32 Bit", NULL
};
#endif
static const char *resolution_labels[3] = {
"Low", "High", NULL
};
static const char *sw_alpha_blending_labels[4] = {
"Off", "Fast", "Nice", NULL
};
static const char *sw_sdl_driver_labels[5] = {
"Default", "None", "Direct3D", "OpenGL", NULL
};
static const char *gamma_labels[9] = {
"Darkest", "Darker", "Dark", "Normal", "Light", "Really Light", "Even Lighter", "Lightest", NULL
};
static const char* renderer_labels[] = {
"Software", "OpenGL (Classic)", "OpenGL (Shader)", NULL
};
static const char* hud_scale_labels[] = {
"Normal", "Double", "Largest", NULL
};
static const char* term_scale_labels[] = {
"Normal", "Double", "Largest", NULL
};
static const char* mouse_accel_labels[] = {
"Off", "Classic", NULL
};
static const char* max_saves_labels[] = {
"20", "100", "500", "Unlimited", NULL
};
static const uint32 max_saves_values[] = {
20, 100, 500, 0
};
enum {
iRENDERING_SYSTEM = 1000