Example #1
0
static void window_loadsave_textinput(rct_window *w, int widgetIndex, char *text)
{
	char path[MAX_PATH];
	int i, overwrite;

	if (text == NULL || text[0] == 0)
		return;

	if (gLoadSaveTitleSequenceSave) {
		if (filename_valid_characters(text)) {
			if (!title_sequence_save_exists(gCurrentTitleSequence, text)) {
				title_sequence_add_save(gCurrentTitleSequence, path, text);
			}
			else {
				window_error_open(5404, STR_NONE);
			}
		}
		else {
			window_error_open(5243, STR_NONE);
		}
		return;
	}

	safe_strcpy(path, _directory, sizeof(path));
	strncat(path, text, sizeof(path) - strnlen(path, MAX_PATH) - 1);
	strncat(path, _extension, sizeof(path) - strnlen(path, MAX_PATH) - 1);

	overwrite = 0;
	for (i = 0; i < _listItemsCount; i++) {
		if (_stricmp(_listItems[i].path, path) == 0) {
			overwrite = 1;
			break;
		}
	}

	if (overwrite)
		window_overwrite_prompt_open(text, path);
	else
		window_loadsave_select(w, path);
}
Example #2
0
static void window_loadsave_select(rct_window *w, const char *path)
{
	SDL_RWops* rw;
	switch (_loadsaveType & 0x0F) {
	case (LOADSAVETYPE_LOAD | LOADSAVETYPE_GAME) :
		if (gLoadSaveTitleSequenceSave) {
			utf8 newName[MAX_PATH];
			char *extension = (char*)path_get_extension(path);
			safe_strcpy(newName, path_get_filename(path), MAX_PATH);
			if (_stricmp(extension, ".sv6") != 0 && _stricmp(extension, ".sc6") != 0)
				strcat(newName, ".sv6");
			if (title_sequence_save_exists(gCurrentTitleSequence, newName)) {
				RCT2_GLOBAL(RCT2_ADDRESS_COMMON_FORMAT_ARGS + 0, uint32) = (uint32)&_listItems[w->selected_list_item].name;
				window_text_input_open(w, WIDX_SCROLL, 5435, 5404, 1170, (uint32)_listItems[w->selected_list_item].name, TITLE_SEQUENCE_MAX_SAVE_LENGTH - 1);
			}
			else {
				title_sequence_add_save(gCurrentTitleSequence, path, newName);
				window_close(w);
			}
			window_loadsave_invoke_callback(MODAL_RESULT_OK);
		} else if (game_load_save(path)) {
			safe_strcpy(gScenarioSavePath, path, MAX_PATH);
			gFirstTimeSave = 0;

			window_close(w);
			gfx_invalidate_screen();
			window_loadsave_invoke_callback(MODAL_RESULT_OK);
		} else {
			// 1050, not the best message...
			window_error_open(STR_LOAD_GAME, 1050);
			window_loadsave_invoke_callback(MODAL_RESULT_FAIL);
		}
		break;
	case (LOADSAVETYPE_SAVE | LOADSAVETYPE_GAME) :
		rw = SDL_RWFromFile(path, "wb+");
		if (rw != NULL) {
			int success = scenario_save(rw, gConfigGeneral.save_plugin_data ? 1 : 0);
			SDL_RWclose(rw);
			if (success) {
				safe_strcpy(gScenarioSavePath, path, MAX_PATH);
				gFirstTimeSave = 0;

				window_close_by_class(WC_LOADSAVE);
				gfx_invalidate_screen();

				window_loadsave_invoke_callback(MODAL_RESULT_OK);
			} else {
				window_error_open(STR_SAVE_GAME, 1047);
				window_loadsave_invoke_callback(MODAL_RESULT_FAIL);
			}
		} else {
			window_error_open(STR_SAVE_GAME, 1047);
			window_loadsave_invoke_callback(MODAL_RESULT_FAIL);
		}
		break;
	case (LOADSAVETYPE_LOAD | LOADSAVETYPE_LANDSCAPE) :
		if (editor_load_landscape(path)) {
			gfx_invalidate_screen();
			window_loadsave_invoke_callback(MODAL_RESULT_OK);
		} else {
			// 1050, not the best message...
			window_error_open(STR_LOAD_LANDSCAPE, 1050);
			window_loadsave_invoke_callback(MODAL_RESULT_FAIL);
		}
		break;
	case (LOADSAVETYPE_SAVE | LOADSAVETYPE_LANDSCAPE) :
		rw = SDL_RWFromFile(path, "wb+");
		if (rw != NULL) {
			scenario_set_filename(path);
			int success = scenario_save(rw, gConfigGeneral.save_plugin_data ? 3 : 2);
			SDL_RWclose(rw);
			if (success) {
				window_close_by_class(WC_LOADSAVE);
				gfx_invalidate_screen();
				window_loadsave_invoke_callback(MODAL_RESULT_OK);
			} else {
				window_error_open(STR_SAVE_LANDSCAPE, 1049);
				window_loadsave_invoke_callback(MODAL_RESULT_FAIL);
			}
		} else {
			window_error_open(STR_SAVE_LANDSCAPE, 1049);
			window_loadsave_invoke_callback(MODAL_RESULT_FAIL);
		}
		break;
	case (LOADSAVETYPE_SAVE | LOADSAVETYPE_SCENARIO) :
	{
		rct_s6_info *s6Info = (rct_s6_info*)0x0141F570;
		int parkFlagsBackup = RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32);
		RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) &= ~PARK_FLAGS_18;
		s6Info->editor_step = 255;
		rw = SDL_RWFromFile(path, "wb+");
		int success = 0;
		if (rw != NULL) {
			scenario_set_filename(path);
			success = scenario_save(rw, gConfigGeneral.save_plugin_data ? 3 : 2);
			SDL_RWclose(rw);
		}
		RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) = parkFlagsBackup;

		if (success) {
			window_close_by_class(WC_LOADSAVE);
			window_loadsave_invoke_callback(MODAL_RESULT_OK);
			title_load();
		} else {
			window_error_open(STR_FILE_DIALOG_TITLE_SAVE_SCENARIO, STR_SCENARIO_SAVE_FAILED);
			s6Info->editor_step = EDITOR_STEP_OBJECTIVE_SELECTION;
			window_loadsave_invoke_callback(MODAL_RESULT_FAIL);
		}
		break;
	}
	case (LOADSAVETYPE_LOAD | LOADSAVETYPE_TRACK) :
		window_install_track_open(path);
		window_close_by_class(WC_LOADSAVE);
		window_loadsave_invoke_callback(MODAL_RESULT_OK);
		break;
	}
}
Example #3
0
void title_sequence_duplicate_preset(int duplicate, const char *name)
{
	if (duplicate >= 0 && duplicate < gConfigTitleSequences.num_presets && filename_valid_characters(name) && !title_sequence_name_exists(name)) {
		int preset = gConfigTitleSequences.num_presets;
		gConfigTitleSequences.num_presets++;
		gConfigTitleSequences.presets = realloc(gConfigTitleSequences.presets, sizeof(title_sequence) * (size_t)gConfigTitleSequences.num_presets);
		safe_strncpy(gConfigTitleSequences.presets[preset].name, name, TITLE_SEQUENCE_NAME_SIZE);
		gConfigTitleSequences.presets[preset].path[0] = 0;

		size_t savesSize = sizeof(char[TITLE_SEQUENCE_MAX_SAVE_LENGTH]) * gConfigTitleSequences.presets[duplicate].num_saves;
		size_t commandsSize = sizeof(title_command) * gConfigTitleSequences.presets[duplicate].num_commands;
		gConfigTitleSequences.presets[preset].saves = malloc(savesSize);
		gConfigTitleSequences.presets[preset].commands = malloc(commandsSize);
		memcpy(gConfigTitleSequences.presets[preset].saves, gConfigTitleSequences.presets[duplicate].saves, savesSize);
		memcpy(gConfigTitleSequences.presets[preset].commands, gConfigTitleSequences.presets[duplicate].commands, commandsSize);
		gConfigTitleSequences.presets[preset].num_saves = gConfigTitleSequences.presets[duplicate].num_saves;
		gConfigTitleSequences.presets[preset].num_commands = gConfigTitleSequences.presets[duplicate].num_commands;

		bool loadmm = false;
		for (int i = 0; i < gConfigTitleSequences.presets[preset].num_commands; i++) {
			if (gConfigTitleSequences.presets[preset].commands[i].command == TITLE_SCRIPT_LOADMM) {
				loadmm = true;
				gConfigTitleSequences.presets[preset].commands[i].command = TITLE_SCRIPT_LOAD;
				gConfigTitleSequences.presets[preset].commands[i].saveIndex = gConfigTitleSequences.presets[duplicate].num_saves;
			}
		}

		// Create the folder
		utf8 path[MAX_PATH], srcPath[MAX_PATH];
		platform_get_user_directory(path, "title sequences");
		strcat(path, gConfigTitleSequences.presets[preset].name);
		platform_file_delete(path);
		platform_ensure_directory_exists(path);

		// Copy the saves
		char separator = platform_get_path_separator();
		for (int i = 0; i < gConfigTitleSequences.presets[preset].num_saves; i++) {
			if (gConfigTitleSequences.presets[duplicate].path[0]) {
				safe_strncpy(srcPath, gConfigTitleSequences.presets[duplicate].path, MAX_PATH);
				strcat(srcPath, gConfigTitleSequences.presets[duplicate].saves[i]);
			}
			else {
				platform_get_user_directory(srcPath, "title sequences");
				strcat(srcPath, gConfigTitleSequences.presets[duplicate].name);
				strncat(srcPath, &separator, 1);
				strcat(srcPath, gConfigTitleSequences.presets[duplicate].saves[i]);
			}
			platform_get_user_directory(path, "title sequences");
			strcat(path, gConfigTitleSequences.presets[preset].name);
			strncat(path, &separator, 1);
			strcat(path, gConfigTitleSequences.presets[preset].saves[i]);

			platform_file_copy(srcPath, path, false);
		}

		if (loadmm) {
			title_sequence_add_save(preset, get_file_path(PATH_ID_SIXFLAGS_MAGICMOUNTAIN), "Six Flags Magic Mountain.SC6");
		}

		title_sequence_save_preset_script(preset);
		gCurrentTitleSequence = preset;
	}
}