From: Holger Schemel Date: Fri, 6 Oct 2017 16:09:04 +0000 (+0200) Subject: added '.hide' suffix to default program config to hide (some) setup options X-Git-Tag: 4.0.1.1~45 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=813b68c363112696ab7a5354c665448491a7da33;p=rocksndiamonds.git added '.hide' suffix to default program config to hide (some) setup options --- diff --git a/src/files.c b/src/files.c index 226f052a..8ccd97d9 100644 --- a/src/files.c +++ b/src/files.c @@ -8520,11 +8520,50 @@ static void setSetupInfoToDefaults_EditorCascade(struct SetupInfo *si) si->editor_cascade.el_dynamic = FALSE; } +#define MAX_HIDE_SETUP_TOKEN_SIZE 20 + +static char *getHideSetupToken(void *setup_value) +{ + static char hide_setup_token[MAX_HIDE_SETUP_TOKEN_SIZE]; + + if (setup_value != NULL) + snprintf(hide_setup_token, MAX_HIDE_SETUP_TOKEN_SIZE, "%p", setup_value); + + return hide_setup_token; +} + +static void setHideSetupEntry(void *setup_value_raw) +{ + /* !!! DIRTY WORKAROUND; TO BE FIXED AFTER THE MM ENGINE RELEASE !!! */ + void *setup_value = setup_value_raw - (void *)&si + (void *)&setup; + + char *hide_setup_token = getHideSetupToken(setup_value); + + if (setup_value != NULL) + setHashEntry(hide_setup_hash, hide_setup_token, ""); +} + +boolean hideSetupEntry(void *setup_value) +{ + char *hide_setup_token = getHideSetupToken(setup_value); + + return (setup_value != NULL && + getHashEntry(hide_setup_hash, hide_setup_token) != NULL); +} + static void setSetupInfoFromTokenText(SetupFileHash *setup_file_hash, struct TokenInfo *token_info, int token_nr, char *token_text) { + char *token_hide_text = getStringCat2(token_text, ".hide"); + char *token_hide_value = getHashEntry(setup_file_hash, token_hide_text); + + /* set the value of this setup option in the setup option structure */ setSetupInfo(token_info, token_nr, getHashEntry(setup_file_hash, token_text)); + + /* check if this setup option should be hidden in the setup menu */ + if (token_hide_value != NULL && get_boolean_from_string(token_hide_value)) + setHideSetupEntry(token_info[token_nr].value); } static void setSetupInfoFromTokenInfo(SetupFileHash *setup_file_hash, @@ -8542,6 +8581,9 @@ static void decodeSetupFileHash(SetupFileHash *setup_file_hash) if (!setup_file_hash) return; + if (hide_setup_hash == NULL) + hide_setup_hash = newSetupFileHash(); + /* global setup */ si = setup; for (i = 0; i < NUM_GLOBAL_SETUP_TOKENS; i++) diff --git a/src/files.h b/src/files.h index 1db49886..f12faca9 100644 --- a/src/files.h +++ b/src/files.h @@ -65,6 +65,8 @@ void SaveSetup_EditorCascade(); void SaveSetup_AddGameControllerMapping(char *); +boolean hideSetupEntry(void *); + void LoadCustomElementDescriptions(); void InitMenuDesignSettings_Static(); void LoadMenuDesignSettings(); diff --git a/src/main.c b/src/main.c index 690296dd..200b954c 100644 --- a/src/main.c +++ b/src/main.c @@ -183,6 +183,7 @@ SetupFileHash *image_config_hash = NULL; SetupFileHash *element_token_hash = NULL; SetupFileHash *graphic_token_hash = NULL; SetupFileHash *font_token_hash = NULL; +SetupFileHash *hide_setup_hash = NULL; /* ------------------------------------------------------------------------- */ diff --git a/src/main.h b/src/main.h index 217ea876..9545b705 100644 --- a/src/main.h +++ b/src/main.h @@ -3180,6 +3180,7 @@ extern SetupFileHash *image_config_hash; extern SetupFileHash *element_token_hash; extern SetupFileHash *graphic_token_hash; extern SetupFileHash *font_token_hash; +extern SetupFileHash *hide_setup_hash; extern struct ConfigTypeInfo image_config_suffix[]; extern struct ConfigTypeInfo sound_config_suffix[]; extern struct ConfigTypeInfo music_config_suffix[]; diff --git a/src/screens.c b/src/screens.c index af53b7f8..52ec5b4b 100644 --- a/src/screens.c +++ b/src/screens.c @@ -2138,6 +2138,10 @@ static void drawMenuInfoList(int first_entry, int num_page_entries, (value_ptr == &scaling_type_text && !video.window_scaling_available)) si->type |= TYPE_GHOSTED; + /* set some entries to "unchangeable" that should be hidden */ + if (hideSetupEntry(value_ptr)) + si->type |= TYPE_GHOSTED; + if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST)) initCursor(i, IMG_MENU_BUTTON_ENTER_MENU); else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST)) @@ -5631,7 +5635,9 @@ static Key getSetupKey() static int getSetupValueFont(int type, void *value) { - if (type & TYPE_KEY) + if (type & TYPE_GHOSTED) + return FONT_OPTION_OFF; + else if (type & TYPE_KEY) return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1); else if (type & TYPE_STRING) return FONT_VALUE_2;