-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathelconfig.c
executable file
·4282 lines (3891 loc) · 159 KB
/
elconfig.c
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
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <limits.h>
#include <float.h>
#include <errno.h>
//For stat() etc.. below
#include <sys/types.h>
#include <sys/stat.h>
#ifndef _MSC_VER
#include <unistd.h>
#endif //_MSC_VER
#include "user_menus.h"
#ifdef MAP_EDITOR
#include "map_editor/global.h"
#include "map_editor/browser.h"
#include "map_editor/interface.h"
#include "load_gl_extensions.h"
#else
#include "achievements.h"
#include "alphamap.h"
#include "bags.h"
#include "buddy.h"
#include "chat.h"
#include "console.h"
#include "context_menu.h"
#include "counters.h"
#include "cursors.h"
#include "dialogues.h"
#include "draw_scene.h"
#include "emotes.h"
#include "errors.h"
#include "elwindows.h"
#include "filter.h"
#include "gamewin.h"
#include "gl_init.h"
#include "hud.h"
#include "hud_statsbar_window.h"
#include "hud_indicators.h"
#include "hud_misc_window.h"
#include "hud_quickbar_window.h"
#include "hud_quickspells_window.h"
#include "icon_window.h"
#include "init.h"
#include "interface.h"
#include "items.h"
#include "item_info.h"
#ifdef JSON_FILES
#include "json_io.h"
#endif
#include "loginwin.h"
#include "manufacture.h"
#include "map.h"
#include "mapwin.h"
#include "missiles.h"
#include "multiplayer.h"
#include "new_character.h"
#include "openingwin.h"
#include "particles.h"
#include "password_manager.h"
#include "pm_log.h"
#include "questlog.h"
#include "reflection.h"
#include "serverpopup.h"
#include "session.h"
#include "shadows.h"
#include "sound.h"
#include "spells.h"
#include "stats.h"
#include "storage.h"
#include "tabs.h"
#include "trade.h"
#include "trade_log.h"
#include "weather.h"
#include "minimap.h"
#ifdef NEW_ALPHA
#include "3d_objects.h"
#endif
#include "io/elpathwrapper.h"
#include "notepad.h"
#include "sky.h"
#ifdef OSX
#include "events.h"
#endif // OSX
#endif
#include "asc.h"
#include "elconfig.h"
#ifndef MAP_EDITOR
#include "text.h"
#include "consolewin.h"
#endif // !MAP_EDITOR
#include "url.h"
#if !defined(MAP_EDITOR)
#include "widgets.h"
#endif
#include "eye_candy_wrapper.h"
#include "sendvideoinfo.h"
#ifndef MAP_EDITOR
#include "actor_init.h"
#endif
#include "io/elpathwrapper.h"
#include "textures.h"
#ifdef FSAA
#include "fsaa/fsaa.h"
#endif /* FSAA */
#ifdef CUSTOM_UPDATE
#include "custom_update.h"
#endif /* CUSTOM_UPDATE */
// Defines for config variables
#define CONTROLS 0
#define HUD 1
#define CHAT 2
#define FONT 3
#define SERVER 4
#define AUDIO 5
#define VIDEO 6
#define GFX 7
#define CAMERA 8
#define TROUBLESHOOT 9
#ifdef DEBUG
#define DEBUGTAB 10
#define MAX_TABS 11
#else
#define MAX_TABS 10
#endif
const char * ini_filename = "el.ini";
#ifdef ELC
static int CHECKBOX_SIZE = 0;
static int SPACING = 0; //Space between widgets and labels and lines
#define MAX_LONG_DESC_LINES 3 //How many lines of text we can fit in LONG_DESC_SPACE
static int LONG_DESC_SPACE = 0; //Space to give to the long descriptions
static int TAB_TAG_HEIGHT = 0; // the height of the tab at the top of the window
// The config window is special, it is scaled on creation then frozen.
// This is because its too complex to resize and cannot simpely be destroyed and re-created.
static float elconf_scale = 0;
static float elconf_custom_scale = 1.0f;
static float elconf_desc_size = 0.0f;
static float elconf_desc_max_height = 0.0f;
static int recheck_window_scale = 0;
#define ELCONFIG_SCALED_VALUE(BASE) ((int)(0.5 + ((BASE) * elconf_scale)))
#endif
#define MULTI_LINE_HEIGHT (ELCONFIG_SCALED_VALUE(22) + SPACING)
typedef char input_line[256];
/*!
* Structure describing an option in a multi-elect widget. It contains the
* label, which is the text on the button presented to the user, and optionally a
* value. Using the value, options can also be sought by value rather than
* by index alone, and hence we don't have to rely on a particular ordering
* of elements, or on all elements being present.
*/
typedef struct
{
//! The user-visible lable for the option
const char* label;
//! The optional value associated with this option
const char* value;
} multi_element;
/*!
* var_struct stores the data for a single configuration entry.
*/
typedef struct
{
option_type type; /*!< type of the variable */
char *name; /*!< name of the variable */
int nlen; /*!< length of the \a name */
char *shortname; /*!< shortname of the variable */
int snlen; /*!< length of the \a shortname */
void (*func)(); /*!< routine to execute when this variable is selected. */
void (*validator_func)(); /*!< optional routine to execute to valid current value. */
void *var; /*!< data for this variable */
float default_val; /*!< the default value before the config file is read */
float config_file_val; /*!< the value after the config file is read */
int len; /*!< length of the variable */
int in_ini_file; /*!< true if the var was present when we read the ini file */
#ifdef JSON_FILES
int character_override; /*!< true if the var is in the list maintained per character, requires JSON file support */
#endif
int saved;
// char *message; /*!< In case you want a message to be written when a setting is changed */
dichar display;
struct {
int tab_id; /*!< The tab ID in which we find this option */
int label_id; /*!< The label ID associated with this option */
int widget_id; /*!< Widget ID for things like checkboxes */
} widgets;
union
{
struct { int min; int max; } imm;
struct { int (*min)(); int (*max)(); } immf;
struct { float min; float max; float interval; } fmmi;
struct { float (*min)(); float (*max)(); float interval; } fmmif;
struct { multi_element *elems; size_t count; } multi;
} args; /*!< The various versions of additional arguments used by configuration variables */
} var_struct;
/*!
* a list of variables of type \see var_struct
*/
struct variables
{
int no; /*!< current number of allocated \see var_struct in \a var */
var_struct * * var; /*!< fixed array of \a no \see var_struct structures */
} our_vars= {0,NULL};
/*!
* For some multi-select widgets (currently only the font selections, it seems),
* not all possible options are available at the time the ini file is read. Rather than
* blindly assuming the option will later be added, setting these options is
* deferred to a later stage after the widget has been fully initialized.
*/
typedef struct
{
//! The index of the multiselect variable in \see our_vars.
int var_idx;
//! The previously stored index of the selected option.
int opt_idx;
//! The previously stored value of the selected option, or NULL if not present.
char* value;
} deferred_option;
//! The list of multi-select options that still need to be set
static deferred_option *defers = NULL;
//! The size of the \see defers array
static int defers_size = 0;
//! The number of elements currently used in the \see defers array
static int defers_count = 0;
//! Whether to still defer options
static int do_defer = 1;
int write_ini_on_exit= 1;
// Window Handling
int force_elconfig_win_ontop = 0;
#ifdef ELC
static int elconfig_tab_collection_id= 1;
static int elconfig_free_widget_id= 2;
static unsigned char elconf_description_buffer[400]= {0};
static int last_description_idx = -1;
#endif
struct {
Sint32 tab;
Uint16 x;
Uint16 y;
} elconfig_tabs[MAX_TABS];
int windows_on_top= 0;
static int options_set= 0;
#ifdef ELC
static int delay_poor_man = 1;
static int shadow_map_size_multi= 0;
#endif
#ifdef FSAA
static int fsaa_index = 0;
#endif /* FSAA */
static float ui_scale = 1.0;
float get_global_scale(void) { return ui_scale; }
int you_sit= 0;
int sit_lock= 0;
int use_keypress_dialogue_boxes = 0, use_full_dialogue_window = 0;
int use_alpha_banner = 0;
int render_skeleton= 0;
int render_mesh= 1;
int render_bones_id = 0;
int render_bones_orientation = 0;
#ifdef NEW_CURSOR
int big_cursors = 0;
int sdl_cursors = 0;
float pointer_size = 1.0;
#endif // NEW_CURSOR
float water_tiles_extension = 200.0;
int show_game_seconds = 0;
int skybox_update_delay = 10;
int skybox_local_weather = 0;
#ifdef OSX // for probelem with rounded buttons on Intel graphics
int emulate3buttonmouse=0;
int square_buttons = 0;
#endif
int buddy_log_notice=1;
int video_mode_set=0;
int video_info_sent = 0;
int no_adjust_shadows=0;
int clouds_shadows=1;
int item_window_on_drop=1;
int mouse_limit=15;
int isometric=1;
int poor_man=0;
int max_fps = 0, limit_fps=0;
int special_effects=0;
char lang[10] = "en";
int auto_update= 1;
int clear_mod_keys_on_focus=1;
#ifdef CUSTOM_UPDATE
int custom_update= 1;
int custom_clothing= 1;
#endif //CUSTOM_UPDATE
#ifdef DEBUG
int enable_client_aiming = 0;
#endif // DEBUG
#ifdef ANTI_ALIAS
int anti_alias=0;
#endif //ANTI_ALIAS
#ifdef ELC
static int small_actor_texture_cache = 0;
static void consolidate_rotate_chat_log_status(void);
static int elconfig_menu_x_len= 0;
static int elconfig_menu_y_len= 0;
static int is_mouse_over_option = 0;
static int is_mouse_over_option_label = 0;
static char multiselect_find_str[32] = { 0 };
static size_t multiselect_find_str_len = 0;
static int multiselect_find_show = 0;
static int multiselect_find_casesensitive = 0;
static int multiselect_find_not_found = 0;
static int disable_auto_highdpi_scale = 0;
static int delay_update_highdpi_auto_scaling = 0;
// the elconfig local version of the font sizes, so we can auto scale if needed
static float local_ui_scale = 1.0f;
static float local_minimap_size_coefficient = 0.7f;
static size_t local_encyclopedia_font = 0;
// the chat and name fonts are not scaled by ui_scale
// so we need to scale them individually for high dpi support
static float chat_font_local_scale = 1.0;
static float name_font_local_scale = 1.0;
// default fonts will be replaced if values present the ini file
static char def_ui_font_str[80] = "20(Ubuntu-R.ttf)";
static char def_name_font_str[80] = "20(Ubuntu-R.ttf)";
static char def_chat_font_str[80] = "20(Ubuntu-R.ttf)";
static char def_note_font_str[80] = "20(Ubuntu-R.ttf)";
static char def_book_font_str[80] = "7(MarckScript-Regular.ttf)";
static char def_rules_font_str[80] = "20(Ubuntu-R.ttf)";
static char def_encyclopedia_font_str[80] = "8(UbuntuMono-R.ttf)";
#ifdef JSON_FILES
// Most of this code can be removed when json file use if the default of the only supported client
static int find_var (const char *str, var_name_type type);
static int use_json_user_files = 0;
static int ready_for_user_files = 0;
// Set when we initially login, before calling load functions
void set_ready_for_user_files(void)
{
ready_for_user_files = 1;
}
// Returns true if we are using json files.
int get_use_json_user_files(void)
{
static int first_time = 1;
// If this is the first time we have run with the use_json_user_files
// option then check if we should switch it on. The option is false
// by default.
if (first_time && !use_json_user_files)
{
int i = find_var("use_json_user_files_v1", INI_FILE_VAR);
first_time = 0;
// should always be fine as add_var() done earlier
if (i < 0)
return 0;
// if the option was not in the read ini file, check for previous use of json files or a clean install
if (!our_vars.var[i]->in_ini_file)
{
char filename[256];
struct stat json_file_stat, bin_file_stat;
int json_stat_ret, bin_stat_ret;
// Use the counters file as not replaceable and is always saved
safe_snprintf(filename, sizeof(filename), "%scounters_%s.json", get_path_config(), get_lowercase_username());
json_stat_ret = stat(filename, &json_file_stat);
safe_snprintf(filename, sizeof(filename), "%scounters_%s.dat", get_path_config(), get_lowercase_username());
bin_stat_ret = stat(filename, &bin_file_stat);
// No bin file so switch on json usage even if no json file either - prevous or clean install
if (bin_stat_ret == -1)
{
use_json_user_files = 1;
USE_JSON_DEBUG("Setting use_json_user_files as no binary file exists");
}
// If there are both json and binary files, pick the most recently modified or the json if the same
else if ((json_stat_ret == 0) && (json_file_stat.st_mtime >= bin_file_stat.st_mtime))
{
use_json_user_files = 1;
USE_JSON_DEBUG("Setting use_json_user_files as json file newer")
}
else // only binary files to leave option disabled
{
USE_JSON_DEBUG("Leaving set to binary");
}
// Make sure the option is saved to file, to avoid having to check again next run
set_var_unsaved("use_json_user_files_v1", INI_FILE_VAR);
}
}
return use_json_user_files;
}
#endif // JSON_FILES
#endif // ELC
void options_loaded(void)
{
size_t i;
// find any options not marked as saved, excluding ones we marked on purpose
for (i= 0; i < our_vars.no; i++)
if ((!our_vars.var[i]->saved) && (our_vars.var[i]->type!=OPT_BOOL_INI) && (our_vars.var[i]->type!=OPT_INT_INI))
our_vars.var[i]->saved = 1;
options_set = 1;
#ifdef ELC
get_rotate_chat_log();
consolidate_rotate_chat_log_status();
#endif
}
#ifdef ELC
static int int_zero_func(void)
{
return 0;
}
#endif
static __inline__ void check_option_var(const char* name);
static __inline__ void destroy_shadow_mapping(void)
{
if (gl_extensions_loaded)
{
CHECK_GL_ERRORS();
if (have_extension(ext_framebuffer_object))
{
#ifndef MAP_EDITOR
free_shadow_framebuffer();
#endif //MAP_EDITOR
}
else
{
if (depth_map_id != 0)
{
glDeleteTextures(1, &depth_map_id);
depth_map_id = 0;
}
}
CHECK_GL_ERRORS();
}
}
static __inline__ void destroy_fbos(void)
{
if (gl_extensions_loaded)
{
CHECK_GL_ERRORS();
if (have_extension(ext_framebuffer_object))
{
#ifndef MAP_EDITOR
destroy_shadow_mapping();
free_reflection_framebuffer();
#endif //MAP_EDITOR
}
CHECK_GL_ERRORS();
}
}
static __inline__ void build_fbos(void)
{
if (gl_extensions_loaded)
{
#ifndef MAP_EDITOR
if (have_extension(ext_framebuffer_object) && use_frame_buffer)
{
if ((water_shader_quality > 0) && show_reflection)
{
make_reflection_framebuffer(window_width, window_height);
}
}
#endif // MAP_EDITOR
check_option_var("shadow_map_size");
}
}
static __inline__ void update_fbos(void)
{
destroy_fbos();
build_fbos();
}
static void change_var(int * var)
{
*var= !*var;
}
#ifndef MAP_EDITOR
static void change_cursor_scale_factor(int * var, int value)
{
// check the range, an invalid setting in the ini file bypasses the bound checking of that var
if ((value > 0) && (value <= max_cursor_scale_factor))
{
*var= value;
if (current_cursor >= 0)
{
build_cursors();
change_cursor(current_cursor);
}
}
}
static void change_show_action_bar(int * var)
{
*var= !*var;
if (stats_bar_win >= 0)
init_stats_display();
}
static void change_minimap_scale(float * var, float * value)
{
int minimap_win = get_id_MW(MW_MINIMAP);
int shown = 0;
float last_minimap_size_coefficient = minimap_size_coefficient;
*var= *value;
minimap_size_coefficient = ((disable_auto_highdpi_scale)) ? *var : get_highdpi_scale() * *var;
if (last_minimap_size_coefficient != minimap_size_coefficient && minimap_win >= 0)
{
shown = get_show_window(minimap_win);
set_pos_MW(MW_MINIMAP, windows_list.window[minimap_win].cur_x, windows_list.window[minimap_win].cur_y);
destroy_window(minimap_win);
set_id_MW(MW_MINIMAP, -1);
}
if (shown)
display_minimap();
}
static void change_sky_var(int * var)
{
*var= !*var;
skybox_update_colors();
}
static void change_use_animation_program(int * var)
{
if (*var)
{
if (gl_extensions_loaded && have_extension(arb_vertex_buffer_object) &&
have_extension(arb_vertex_program))
{
unload_vertex_programs();
}
*var = 0;
}
else
{
if (!gl_extensions_loaded)
{
*var = 1;
}
else
{
if (have_extension(arb_vertex_buffer_object) &&
have_extension(arb_vertex_program))
{
*var = load_vertex_programs();
}
}
}
if (gl_extensions_loaded)
{
if (use_animation_program)
{
LOG_TO_CONSOLE(c_green2, "Using vertex program for actor animation.");
}
else
{
LOG_TO_CONSOLE(c_red1, "Not using vertex program for actor animation.");
}
}
}
#endif //MAP_EDITOR
#ifndef MAP_EDITOR
static void change_min_ec_framerate(float * var, float * value)
{
if(*value >= 0) {
if (*value < max_ec_framerate) {
*var = *value;
} else if (!max_ec_framerate) {
*var = *value;
} else {
*var = max_ec_framerate - 1;
}
} else {
*var= 0;
}
}
static void change_max_ec_framerate(float * var, float * value)
{
if(*value >= 1) {
if (*value > min_ec_framerate) {
*var = *value;
} else if (!min_ec_framerate) {
*var = *value;
} else {
*var = min_ec_framerate + 1;
}
} else {
*var= 1;
}
}
#endif //!MAP_EDITOR
static void change_int(int * var, int value)
{
if(value>=0) *var= value;
}
static void change_float(float * var, float * value)
{
*var= *value;
}
#ifdef ELC
static void change_string(char* var, const char* str, int len)
{
safe_strncpy(var, str, len);
}
static void change_ui_scale(float *var, float *value)
{
*var= *value;
ui_scale = ((disable_auto_highdpi_scale)) ? *var : get_highdpi_scale() * *var;
HUD_MARGIN_X = (int)ceilf(ui_scale * 64.0);
if (hud_x != 0)
hud_x = HUD_MARGIN_X;
HUD_MARGIN_Y = (int)ceilf(ui_scale * 49.0);
if (hud_y != 0)
hud_y = HUD_MARGIN_Y;
update_windows_scale(ui_scale);
update_console_input_size_and_position();
}
static void change_elconf_win_scale_factor(float *var, float *value)
{
*var= *value;
if (get_id_MW(MW_CONFIG) >= 0)
recheck_window_scale = 1;
}
static void change_win_scale_factor(float *var, float *value)
{
*var= *value;
update_windows_custom_scale(var);
}
static const float win_scale_min = 0.25f;
static const float win_scale_max = 3.0f;
static const float win_scale_step = 0.01f;
static var_struct * find_win_scale_factor(float *changed_window_custom_scale)
{
if (changed_window_custom_scale != NULL)
{
size_t i;
for (i = 0; i < our_vars.no; i++)
if (our_vars.var[i]->var == changed_window_custom_scale)
return our_vars.var[i];
}
return NULL;
}
void step_win_scale_factor(int increase, float *changed_window_custom_scale)
{
if (changed_window_custom_scale != NULL)
{
var_struct * var = find_win_scale_factor(changed_window_custom_scale);
float new_value = *changed_window_custom_scale + ((increase) ? win_scale_step : -win_scale_step);
if (new_value >= win_scale_min && new_value <= win_scale_max)
{
*changed_window_custom_scale = new_value;
update_windows_custom_scale(changed_window_custom_scale);
}
if (var != NULL)
var->saved = 0;
}
}
void limit_win_scale_to_default(float *changed_window_custom_scale)
{
var_struct * var = find_win_scale_factor(changed_window_custom_scale);
if ((var != NULL) && (*changed_window_custom_scale > var->default_val))
{
*changed_window_custom_scale = var->default_val;
update_windows_custom_scale(changed_window_custom_scale);
var->saved = 0;
}
}
void reset_win_scale_factor(int set_default, float *changed_window_custom_scale)
{
var_struct * var = find_win_scale_factor(changed_window_custom_scale);
if (var != NULL)
{
*changed_window_custom_scale = (set_default) ? var->default_val : var->config_file_val;
update_windows_custom_scale(changed_window_custom_scale);
var->saved = 0;
}
}
/*
* The chat logs are created very early on in the client start up, before the
* ini file is read at least. Because of this, a simple ini file variable
* can not be used to enabled/disable rotating chat log files. I suppose the init
* code could be changed but rather do that and unleash all kinds of grief, use a
* simple flag file when the chat logs are opened. The ini file setting now
* becomes the creater/remover of that file.
*/
static int rotate_chat_log_config_var = 0;
static int rotate_chat_log = -1;
static const char* rotate_chat_log_flag_file = "rotate_chat_log_enabled";
/* get the current value depending on if the flag file exists */
int get_rotate_chat_log(void)
{
if (rotate_chat_log == -1)
rotate_chat_log = (file_exists_config(rotate_chat_log_flag_file)==1) ?1: 0;
return rotate_chat_log;
}
/* create or delete the flag file to reflect the ini file rotate chat log value */
static void change_rotate_chat_log(int *value)
{
*value = !*value;
/* create the flag file if we are switching on chat log rotate */
if (*value && (file_exists_config(rotate_chat_log_flag_file)!=1))
{
FILE *fp = open_file_config(rotate_chat_log_flag_file,"w");
if ((fp == NULL) || (fclose(fp) != 0))
LOG_ERROR("%s: Failed to create [%s] [%s]\n", __FILE__, rotate_chat_log_flag_file, strerror(errno) );
else
LOG_TO_CONSOLE(c_green2, rotate_chat_log_restart_str);
}
/* remove the flag file if we are switching off chat log rotate */
else if (!(*value) && (file_exists_config(rotate_chat_log_flag_file)==1))
{
const char *config_dir = get_path_config();
char *name_buf = NULL;
if (config_dir != NULL)
{
size_t buf_len = strlen(config_dir) + strlen(rotate_chat_log_flag_file) + 1;
name_buf = (char *)malloc(buf_len);
if (name_buf != NULL)
{
safe_strncpy(name_buf, config_dir, buf_len);
safe_strcat(name_buf, rotate_chat_log_flag_file, buf_len);
if (unlink(name_buf) != 0)
LOG_ERROR("%s: Failed to remove [%s] [%s]\n", __FILE__, rotate_chat_log_flag_file, strerror(errno) );
else
LOG_TO_CONSOLE(c_green2, rotate_chat_log_restart_str);
free(name_buf);
}
}
}
}
/* called after the el.in file has been read, so we can consolidate the rotate chat log status */
static void consolidate_rotate_chat_log_status(void)
{
/* it is too late to use a newly set rotate log value, but we can set the ini flag if rotating is on */
if ((rotate_chat_log==1) && !rotate_chat_log_config_var)
{
rotate_chat_log_config_var = 1;
set_var_unsaved("rotate_chat_log", INI_FILE_VAR);
}
}
#ifdef NEW_SOUND
static void change_sound_level(float *var, float * value)
{
if(*value >= 0.0f && *value <= 1.0f+0.00001) {
*var= (float)*value;
} else {
*var=0;
}
}
#endif
static void update_max_actor_texture_handles(void)
{
if (poor_man == 1)
{
if (small_actor_texture_cache == 1)
{
max_actor_texture_handles = 1;
}
else
{
max_actor_texture_handles = 4;
}
}
else
{
if (small_actor_texture_cache == 1)
{
max_actor_texture_handles = 16;
}
else
{
max_actor_texture_handles = 32;
}
}
}
static void change_compiled_vertex_array(int *value)
{
if (*value) {
*value= 0;
}
else if (!gl_extensions_loaded || have_extension(ext_compiled_vertex_array))
{
// don't check if we have hardware support when OpenGL
// extensions are not initialized yet.
*value= 1;
}
else LOG_TO_CONSOLE(c_green2,disabled_compiled_vertex_arrays);
}
static void change_vertex_buffers(int *value)
{
if (*value) {
*value= 0;
}
else if (!gl_extensions_loaded || have_extension(arb_vertex_buffer_object))
{
// don't check if we have hardware support when OpenGL
// extensions are not initialized yet.
*value= 1;
}
// else LOG_TO_CONSOLE(c_green2,disabled_vertex_buffers);
}
static void change_clouds_shadows(int *value)
{
if (*value) {
*value= 0;
}
else if (!gl_extensions_loaded || (get_texture_units() >= 2))
{
// don't check if we have hardware support when OpenGL
// extensions are not initialized yet.
*value= 1;
}
// else LOG_TO_CONSOLE(c_green2,disabled_clouds_shadows);
}
static void change_small_actor_texture_cache(int *value)
{
if (*value)
{
*value = 0;
}
else
{
*value = 1;
}
update_max_actor_texture_handles();
}
static void change_eye_candy(int *value)
{
if (*value)
{
*value = 0;
}
else if (!gl_extensions_loaded || ((get_texture_units() >= 2) &&
supports_gl_version(1, 5)))
{
// don't check if we have hardware support when OpenGL
// extensions are not initialized yet.
*value = 1;
}
}
static void change_point_particles(int *value)
{
if (*value) {
*value= 0;
}
else if (!gl_extensions_loaded || have_extension(arb_point_sprite))
{
// don't check if we have hardware support when OpenGL
// extensions are not initialized yet.
*value= 1;
}
else
{
LOG_TO_CONSOLE(c_green2, disabled_point_particles);
}
}
static void change_fps(int * var, int value)
{
if(value>=0) max_fps = *var = value;
}
static void change_particles_percentage(int *pointer, int value)
{
if(value>0 && value <=100) {
particles_percentage= value;
}
else
{
particles_percentage= 0;
LOG_TO_CONSOLE(c_green2, disabled_particles_str);
}
}
static void change_new_selection(int *value)
{
if (*value)
{
*value = 0;
}
else
{
if (gl_extensions_loaded)
{
if ((supports_gl_version(1, 3) ||
have_extension(arb_texture_env_combine)) &&
(get_texture_units() > 1) && (bpp == 32))
{
*value = 1;
}
}
else
{
*value = 1;
}
}
}
static void switch_vidmode(int *pointer, int mode)
{
if(!video_mode_set) {
/* Video isn't ready yet, just remember the mode */
video_mode= mode;
} else {
full_screen = 0;
switch_video(mode, full_screen);
}
}
static void toggle_full_screen_mode(int * fs)
{
if(!video_mode_set) {
*fs= !*fs;
} else {
toggle_full_screen();
}
}
#ifdef NEW_CURSOR
static void change_sdl_cursor(int * fs)
{
if(!*fs) {
SDL_ShowCursor(1);
} else {
SDL_ShowCursor(0);
}
*fs = !*fs;
}
#endif // NEW_CURSOR