Skip to content

Commit 347273f

Browse files
authored
Merge pull request #262 from donnierussellii/portable-prefs
Portable prefs option + Add more settings to prefs
2 parents f1c41e4 + 065df10 commit 347273f

File tree

3 files changed

+66
-32
lines changed

3 files changed

+66
-32
lines changed

Diff for: src/GameSrc/gamewrap.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ errtype interpret_qvars(void) {
314314
recompute_digifx_level(QUESTVAR_GET(SFX_VOLUME_QVAR));
315315
#ifdef AUDIOLOGS
316316
recompute_audiolog_level(QUESTVAR_GET(ALOG_VOLUME_QVAR));
317-
audiolog_setting = QUESTVAR_GET(ALOG_OPT_QVAR);
317+
//audiolog_setting = QUESTVAR_GET(ALOG_OPT_QVAR); //moved to prefs file
318318
#endif
319319
fullscrn_vitals = QUESTVAR_GET(FULLSCRN_VITAL_QVAR);
320320
fullscrn_icons = QUESTVAR_GET(FULLSCRN_ICON_QVAR);

Diff for: src/GameSrc/wrapper.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1957,7 +1957,7 @@ void options_screen_init(void) {
19571957
standard_button_rect(&r, 0, 2, 2, 2);
19581958
r.ul.x -= 2;
19591959
multi_init(i, keys[i], REF_STR_OptionsText + 2, REF_STR_TerseText, REF_STR_TerseFeedback,
1960-
sizeof(player_struct.terseness), &player_struct.terseness, 2, NULL, &r);
1960+
sizeof(gShockPrefs.goMsgLength), &(gShockPrefs.goMsgLength), 2, NULL, &r);
19611961
i++;
19621962

19631963
i++;
@@ -2078,12 +2078,12 @@ void wrapper_start(void (*init)(void)) {
20782078
fv = full_visible;
20792079
full_visible = 0;
20802080
#endif
2081+
render_run(); //move here to fix ghost mouse cursor
20812082
uiHideMouse(NULL);
20822083
if (full_game_3d) {
20832084
#ifdef SVGA_SUPPORT
20842085
uchar old_over = gr2ss_override;
20852086
#endif
2086-
render_run();
20872087
gr_push_canvas(grd_screen_canvas);
20882088
#ifdef SVGA_SUPPORT
20892089
gr2ss_override = OVERRIDE_ALL;

Diff for: src/MacSrc/Prefs.c

+63-29
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ extern uchar curr_vol_lev;
6363
extern uchar curr_sfx_vol;
6464
extern uchar curr_alog_vol;
6565

66+
extern uchar audiolog_setting;
67+
6668
static const char *PREF_LANGUAGE = "language";
6769
static const char *PREF_CAPTUREMOUSE = "capture-mouse";
6870
static const char *PREF_MUSIC_VOL = "music-volume";
@@ -75,6 +77,8 @@ static const char *PREF_USE_OPENGL = "use-opengl";
7577
static const char *PREF_LIN_SCALING = "linear-scaling";
7678
static const char *PREF_ONSCR_HELP = "onscreen-help";
7779
static const char *PREF_GAMMA = "gamma";
80+
static const char *PREF_MSG_LENGTH = "message-length";
81+
static const char *PREF_ALOG_SETTING = "alog-setting";
7882

7983
static void SetShockGlobals(void);
8084

@@ -85,7 +89,6 @@ void SetDefaultPrefs(void) {
8589

8690
gShockPrefs.prefVer = 0;
8791
gShockPrefs.prefPlayIntro = 1; // First time through, play the intro
88-
gShockPrefs.goMsgLength = 0; // Normal
8992
gShockPrefs.goPopupLabels = true;
9093
gShockPrefs.soBackMusic = true;
9194
gShockPrefs.soSoundFX = true;
@@ -105,16 +108,30 @@ void SetDefaultPrefs(void) {
105108
gShockPrefs.doLinearScaling = false;
106109
gShockPrefs.goOnScreenHelp = true;
107110
gShockPrefs.doGamma = 29; // Default gamma (29 out of 100).
111+
gShockPrefs.goMsgLength = 0; // Normal
112+
audiolog_setting = 1;
108113

109114
SetShockGlobals();
110115
}
111116

112-
static FILE *open_prefs(const char *mode) {
113-
char fullname[512];
114-
char *path = SDL_GetPrefPath("Interrupt", "SystemShock");
115-
snprintf(fullname, sizeof(fullname), "%s%s", path, PREFS_FILENAME);
116-
free(path);
117-
return fopen(fullname, mode);
117+
static char *GetPrefsPathFilename(void)
118+
{
119+
static char filename[512];
120+
121+
FILE *f = fopen(PREFS_FILENAME, "r");
122+
if (f != NULL)
123+
{
124+
fclose(f);
125+
strcpy(filename, PREFS_FILENAME);
126+
}
127+
else
128+
{
129+
char *p = SDL_GetPrefPath("Interrupt", "SystemShock");
130+
snprintf(filename, sizeof(filename), "%s%s", p, PREFS_FILENAME);
131+
free(p);
132+
}
133+
134+
return filename;
118135
}
119136

120137
static char *trim(char *s) {
@@ -134,7 +151,7 @@ static bool is_true(const char *s) {
134151
// Locate the preferences file and load them to set our global pref settings.
135152
//--------------------------------------------------------------------
136153
OSErr LoadPrefs(void) {
137-
FILE *f = open_prefs("r");
154+
FILE *f = fopen(GetPrefsPathFilename(), "r");
138155
if (!f) {
139156
// file can't be open, write default preferences
140157
return SavePrefs();
@@ -192,6 +209,14 @@ OSErr LoadPrefs(void) {
192209
if (gamma < 10) gamma = 10;
193210
if (gamma > 100) gamma = 100;
194211
gShockPrefs.doGamma = gamma;
212+
} else if (strcasecmp(key, PREF_MSG_LENGTH) == 0) {
213+
int ml = atoi(value);
214+
if (ml >= 0 && ml <= 1)
215+
gShockPrefs.goMsgLength = ml;
216+
} else if (strcasecmp(key, PREF_ALOG_SETTING) == 0) {
217+
int as = atoi(value);
218+
if (as >= 0 && as <= 2)
219+
audiolog_setting = as;
195220
}
196221
}
197222

@@ -206,7 +231,7 @@ OSErr LoadPrefs(void) {
206231
OSErr SavePrefs(void) {
207232
INFO("Saving preferences");
208233

209-
FILE *f = open_prefs("w");
234+
FILE *f = fopen(GetPrefsPathFilename(), "w");
210235
if (!f) {
211236
printf("ERROR: Failed to open preferences file\n");
212237
return -1;
@@ -224,6 +249,8 @@ OSErr SavePrefs(void) {
224249
fprintf(f, "%s = %s\n", PREF_LIN_SCALING, gShockPrefs.doLinearScaling ? "yes" : "no");
225250
fprintf(f, "%s = %s\n", PREF_ONSCR_HELP, gShockPrefs.goOnScreenHelp ? "yes" : "no");
226251
fprintf(f, "%s = %d\n", PREF_GAMMA, gShockPrefs.doGamma);
252+
fprintf(f, "%s = %d\n", PREF_MSG_LENGTH, gShockPrefs.goMsgLength);
253+
fprintf(f, "%s = %d\n", PREF_ALOG_SETTING, audiolog_setting);
227254
fclose(f);
228255
return 0;
229256
}
@@ -543,6 +570,28 @@ int FireKeys[MAX_FIRE_KEYS+1]; //see input.c
543570

544571

545572

573+
static char *GetKeybindsPathFilename(void)
574+
{
575+
static char filename[512];
576+
577+
FILE *f = fopen(KEYBINDS_FILENAME, "r");
578+
if (f != NULL)
579+
{
580+
fclose(f);
581+
strcpy(filename, KEYBINDS_FILENAME);
582+
}
583+
else
584+
{
585+
char *p = SDL_GetPrefPath("Interrupt", "SystemShock");
586+
snprintf(filename, sizeof(filename), "%s%s", p, KEYBINDS_FILENAME);
587+
free(p);
588+
}
589+
590+
return filename;
591+
}
592+
593+
594+
546595
//all hotkey initialization and hotkey_add()s are done in this function
547596
//also handles setting fire keybinds
548597
void LoadHotkeyKeybinds(void)
@@ -563,12 +612,7 @@ void LoadHotkeyKeybinds(void)
563612
i++;
564613
}
565614

566-
//get path and filename of keybinds file
567-
p = SDL_GetPrefPath("Interrupt", "SystemShock");
568-
snprintf(temp, sizeof(temp), "%s%s", p, KEYBINDS_FILENAME);
569-
free(p);
570-
571-
f = fopen(temp, "r");
615+
f = fopen(GetKeybindsPathFilename(), "r");
572616
if (f)
573617
{
574618
//scan keybinds file line by line
@@ -887,12 +931,7 @@ void LoadMoveKeybinds(void)
887931
//keep track of which moves are specified so we can add default ones for those that are missing
888932
memset(move_used, 0, NUM_MOVES);
889933

890-
//get path and filename of keybinds file
891-
p = SDL_GetPrefPath("Interrupt", "SystemShock");
892-
snprintf(temp, sizeof(temp), "%s%s", p, KEYBINDS_FILENAME);
893-
free(p);
894-
895-
f = fopen(temp, "r");
934+
f = fopen(GetKeybindsPathFilename(), "r");
896935
if (f)
897936
{
898937
//scan keybinds file line by line
@@ -1086,20 +1125,15 @@ static void WriteMoveName(int move, FILE *f)
10861125
void CreateDefaultKeybindsFile(void)
10871126
{
10881127
FILE *f;
1089-
char temp[512], *p;
1128+
char *filename = GetKeybindsPathFilename();
10901129
int i, ch;
10911130

1092-
//get path and filename of keybinds file
1093-
p = SDL_GetPrefPath("Interrupt", "SystemShock");
1094-
snprintf(temp, sizeof(temp), "%s%s", p, KEYBINDS_FILENAME);
1095-
free(p);
1096-
10971131
//check if file already exists; if so, return
1098-
f = fopen(temp, "r");
1132+
f = fopen(filename, "r");
10991133
if (f != NULL) {fclose(f); return;}
11001134

11011135
//open new file for writing
1102-
f = fopen(temp, "w");
1136+
f = fopen(filename, "w");
11031137
if (f == NULL) return;
11041138

11051139
//write default hotkey keybinds

0 commit comments

Comments
 (0)