Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename);
+ if (!setup.editor.use_template_for_new_levels)
+ return;
+
/* if level file not found, try to initialize level data from template */
filename = getGlobalLevelTemplateFilename();
si->editor.show_element_token = FALSE;
+ si->editor.use_template_for_new_levels = TRUE;
+
si->shortcut.save_game = DEFAULT_KEY_SAVE_GAME;
si->shortcut.load_game = DEFAULT_KEY_LOAD_GAME;
si->shortcut.toggle_pause = DEFAULT_KEY_TOGGLE_PAUSE;
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,
+ struct TokenInfo *token_info,
+ int token_nr)
+{
+ setSetupInfoFromTokenText(setup_file_hash, token_info, token_nr,
+ token_info[token_nr].text);
+}
+
static void decodeSetupFileHash(SetupFileHash *setup_file_hash)
{
int i, pnr;
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++)
- setSetupInfo(global_setup_tokens, i,
- getHashEntry(setup_file_hash, global_setup_tokens[i].text));
+ setSetupInfoFromTokenInfo(setup_file_hash, global_setup_tokens, i);
setup = si;
/* editor setup */
sei = setup.editor;
for (i = 0; i < NUM_EDITOR_SETUP_TOKENS; i++)
- setSetupInfo(editor_setup_tokens, i,
- getHashEntry(setup_file_hash,editor_setup_tokens[i].text));
+ setSetupInfoFromTokenInfo(setup_file_hash, editor_setup_tokens, i);
setup.editor = sei;
/* shortcut setup */
ssi = setup.shortcut;
for (i = 0; i < NUM_SHORTCUT_SETUP_TOKENS; i++)
- setSetupInfo(shortcut_setup_tokens, i,
- getHashEntry(setup_file_hash,shortcut_setup_tokens[i].text));
+ setSetupInfoFromTokenInfo(setup_file_hash, shortcut_setup_tokens, i);
setup.shortcut = ssi;
/* player setup */
char full_token[100];
sprintf(full_token, "%s%s", prefix, player_setup_tokens[i].text);
- setSetupInfo(player_setup_tokens, i,
- getHashEntry(setup_file_hash, full_token));
+ setSetupInfoFromTokenText(setup_file_hash, player_setup_tokens, i,
+ full_token);
}
setup.input[pnr] = sii;
}
/* system setup */
syi = setup.system;
for (i = 0; i < NUM_SYSTEM_SETUP_TOKENS; i++)
- setSetupInfo(system_setup_tokens, i,
- getHashEntry(setup_file_hash, system_setup_tokens[i].text));
+ setSetupInfoFromTokenInfo(setup_file_hash, system_setup_tokens, i);
setup.system = syi;
/* internal setup */
sxi = setup.internal;
for (i = 0; i < NUM_INTERNAL_SETUP_TOKENS; i++)
- setSetupInfo(internal_setup_tokens, i,
- getHashEntry(setup_file_hash, internal_setup_tokens[i].text));
+ setSetupInfoFromTokenInfo(setup_file_hash, internal_setup_tokens, i);
setup.internal = sxi;
/* debug setup */
sdi = setup.debug;
for (i = 0; i < NUM_DEBUG_SETUP_TOKENS; i++)
- setSetupInfo(debug_setup_tokens, i,
- getHashEntry(setup_file_hash, debug_setup_tokens[i].text));
+ setSetupInfoFromTokenInfo(setup_file_hash, debug_setup_tokens, i);
setup.debug = sdi;
/* options setup */
soi = setup.options;
for (i = 0; i < NUM_OPTIONS_SETUP_TOKENS; i++)
- setSetupInfo(options_setup_tokens, i,
- getHashEntry(setup_file_hash, options_setup_tokens[i].text));
+ setSetupInfoFromTokenInfo(setup_file_hash, options_setup_tokens, i);
setup.options = soi;
}
}
else
{
- Error(ERR_WARN, "using default setup values");
+ Error(ERR_DEBUG, "using default setup values");
}
}
free(filename);
}
+static void addGameControllerMappingToHash(SetupFileHash *mappings_hash,
+ char *mapping_line)
+{
+ char mapping_guid[MAX_LINE_LEN];
+ char *mapping_start, *mapping_end;
+
+ // get GUID from game controller mapping line: copy complete line
+ strncpy(mapping_guid, mapping_line, MAX_LINE_LEN - 1);
+ mapping_guid[MAX_LINE_LEN - 1] = '\0';
+
+ // get GUID from game controller mapping line: cut after GUID part
+ mapping_start = strchr(mapping_guid, ',');
+ if (mapping_start != NULL)
+ *mapping_start = '\0';
+
+ // cut newline from game controller mapping line
+ mapping_end = strchr(mapping_line, '\n');
+ if (mapping_end != NULL)
+ *mapping_end = '\0';
+
+ // add mapping entry to game controller mappings hash
+ setHashEntry(mappings_hash, mapping_guid, mapping_line);
+}
+
+static void LoadSetup_ReadGameControllerMappings(SetupFileHash *mappings_hash,
+ char *filename)
+{
+ FILE *file;
+
+ if (!(file = fopen(filename, MODE_READ)))
+ {
+ Error(ERR_WARN, "cannot read game controller mappings file '%s'", filename);
+
+ return;
+ }
+
+ while (!feof(file))
+ {
+ char line[MAX_LINE_LEN];
+
+ if (!fgets(line, MAX_LINE_LEN, file))
+ break;
+
+ addGameControllerMappingToHash(mappings_hash, line);
+ }
+
+ fclose(file);
+}
+
void SaveSetup()
{
char *filename = getSetupFilename();
free(filename);
}
+static void SaveSetup_WriteGameControllerMappings(SetupFileHash *mappings_hash,
+ char *filename)
+{
+ FILE *file;
+
+ if (!(file = fopen(filename, MODE_WRITE)))
+ {
+ Error(ERR_WARN, "cannot write game controller mappings file '%s'",filename);
+
+ return;
+ }
+
+ BEGIN_HASH_ITERATION(mappings_hash, itr)
+ {
+ fprintf(file, "%s\n", HASH_ITERATION_VALUE(itr));
+ }
+ END_HASH_ITERATION(mappings_hash, itr)
+
+ fclose(file);
+}
+
+void SaveSetup_AddGameControllerMapping(char *mapping)
+{
+ char *filename = getPath2(getSetupDir(), GAMECONTROLLER_BASENAME);
+ SetupFileHash *mappings_hash = newSetupFileHash();
+
+ InitUserDataDirectory();
+
+ // load existing personal game controller mappings
+ LoadSetup_ReadGameControllerMappings(mappings_hash, filename);
+
+ // add new mapping to personal game controller mappings
+ addGameControllerMappingToHash(mappings_hash, mapping);
+
+ // save updated personal game controller mappings
+ SaveSetup_WriteGameControllerMappings(mappings_hash, filename);
+
+ freeSetupFileHash(mappings_hash);
+ free(filename);
+}
+
void LoadCustomElementDescriptions()
{
char *filename = getCustomArtworkConfigFilename(ARTWORK_TYPE_GRAPHICS);