added '.hide' suffix to default program config to hide (some) setup options
authorHolger Schemel <info@artsoft.org>
Fri, 6 Oct 2017 16:09:04 +0000 (18:09 +0200)
committerHolger Schemel <info@artsoft.org>
Fri, 6 Oct 2017 16:09:23 +0000 (18:09 +0200)
src/files.c
src/files.h
src/main.c
src/main.h
src/screens.c

index 226f052a4451e1dbbafcdcf7ef152cb592f646b6..8ccd97d9e08c4db80634732c107f0ae423c453b4 100644 (file)
@@ -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++)
index 1db4988681039db4743b9af83bd57add191209c2..f12faca99c9e2206074f4977e5d8d08847210782 100644 (file)
@@ -65,6 +65,8 @@ void SaveSetup_EditorCascade();
 
 void SaveSetup_AddGameControllerMapping(char *);
 
+boolean hideSetupEntry(void *);
+
 void LoadCustomElementDescriptions();
 void InitMenuDesignSettings_Static();
 void LoadMenuDesignSettings();
index 690296dded7266b0be70af083fe264a0f1588339..200b954c67c733e704169bf4ec70d77402d5b87b 100644 (file)
@@ -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;
 
 
 /* ------------------------------------------------------------------------- */
index 217ea876a24ba888c90f3a96a47612e571fc24b3..9545b70502020b11bc3044801a087a9ad0928cdd 100644 (file)
@@ -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[];
index af53b7f83651a5d9b2b733181182a891deee6078..52ec5b4bf9e9cba80fece3d4d02e0841a57a3a27 100644 (file)
@@ -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;