mirror of https://github.com/OpenRCT2/OpenRCT2.git
Fix #6470: Title sequence naming issues
Predefined title sequence filenames are now treated as "reserved". Custom title sequences cannot use reserved names and an error will appear if the user tries. Duplicating predefined title sequence now uses default text of predefined sequence's proper name instead of filename. Renamed `WIDX_TITLE_EDITOR_RENAME_SAVE_BUTTON` to `WIDX_TITLE_EDITOR_RENAME_BUTTON` to follow formatting of other preset button ids. Added string id 6154, `STR_ERROR_RESERVED_NAME`, "Name is reserved".
This commit is contained in:
parent
d6ee66acb4
commit
ec22d04089
|
@ -4464,7 +4464,7 @@ STR_6152 :Invalid response from master server (no JSON array)
|
|||
STR_6153 :Pay to enter park / Pay per ride
|
||||
STR_6154 :It is not recommended to run OpenRCT2 with elevated permissions.
|
||||
STR_6155 :Neither KDialog nor Zenity are installed. Please install one, or configure from the command line.
|
||||
|
||||
STR_6156 :Name is reserved
|
||||
|
||||
#############
|
||||
# Scenarios #
|
||||
|
|
|
@ -111,7 +111,7 @@ enum WINDOW_TITLE_EDITOR_WIDGET_IDX {
|
|||
WIDX_TITLE_EDITOR_NEW_BUTTON,
|
||||
WIDX_TITLE_EDITOR_DUPLICATE_BUTTON,
|
||||
WIDX_TITLE_EDITOR_DELETE_BUTTON,
|
||||
WIDX_TITLE_EDITOR_RENAME_SAVE_BUTTON,
|
||||
WIDX_TITLE_EDITOR_RENAME_BUTTON,
|
||||
|
||||
// Saves Tab
|
||||
WIDX_TITLE_EDITOR_ADD_SAVE,
|
||||
|
@ -237,7 +237,7 @@ void window_title_editor_open(sint32 tab)
|
|||
(1 << WIDX_TITLE_EDITOR_NEW_BUTTON) |
|
||||
(1 << WIDX_TITLE_EDITOR_DUPLICATE_BUTTON) |
|
||||
(1 << WIDX_TITLE_EDITOR_DELETE_BUTTON) |
|
||||
(1 << WIDX_TITLE_EDITOR_RENAME_SAVE_BUTTON) |
|
||||
(1 << WIDX_TITLE_EDITOR_RENAME_BUTTON) |
|
||||
|
||||
(1 << WIDX_TITLE_EDITOR_ADD_SAVE) |
|
||||
(1 << WIDX_TITLE_EDITOR_REMOVE_SAVE) |
|
||||
|
@ -309,7 +309,7 @@ static void window_title_editor_mouseup(rct_window *w, rct_widgetindex widgetInd
|
|||
break;
|
||||
case WIDX_TITLE_EDITOR_DUPLICATE_BUTTON:
|
||||
if (!commandEditorOpen && _editingTitleSequence != nullptr) {
|
||||
window_text_input_open(w, widgetIndex, STR_TITLE_EDITOR_ACTION_DUPLICATE, STR_TITLE_EDITOR_ENTER_NAME_FOR_SEQUENCE, STR_STRING, (uintptr_t)_editingTitleSequence->Name, 64);
|
||||
window_text_input_open(w, widgetIndex, STR_TITLE_EDITOR_ACTION_DUPLICATE, STR_TITLE_EDITOR_ENTER_NAME_FOR_SEQUENCE, STR_STRING, (uintptr_t)_sequenceName, 64);
|
||||
}
|
||||
break;
|
||||
case WIDX_TITLE_EDITOR_DELETE_BUTTON:
|
||||
|
@ -318,9 +318,9 @@ static void window_title_editor_mouseup(rct_window *w, rct_widgetindex widgetInd
|
|||
window_title_editor_load_sequence(0);
|
||||
}
|
||||
break;
|
||||
case WIDX_TITLE_EDITOR_RENAME_SAVE_BUTTON:
|
||||
case WIDX_TITLE_EDITOR_RENAME_BUTTON:
|
||||
if (window_title_editor_check_can_edit() && _editingTitleSequence != nullptr) {
|
||||
window_text_input_open(w, widgetIndex, STR_TRACK_MANAGE_RENAME, STR_TITLE_EDITOR_ENTER_NAME_FOR_SEQUENCE, STR_STRING, (uintptr_t)_editingTitleSequence->Name, 64);
|
||||
window_text_input_open(w, widgetIndex, STR_TRACK_MANAGE_RENAME, STR_TITLE_EDITOR_ENTER_NAME_FOR_SEQUENCE, STR_STRING, (uintptr_t)_sequenceName, 64);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -617,21 +617,25 @@ static void window_title_editor_textinput(rct_window *w, rct_widgetindex widgetI
|
|||
switch (widgetIndex) {
|
||||
case WIDX_TITLE_EDITOR_NEW_BUTTON:
|
||||
case WIDX_TITLE_EDITOR_DUPLICATE_BUTTON:
|
||||
case WIDX_TITLE_EDITOR_RENAME_SAVE_BUTTON:
|
||||
case WIDX_TITLE_EDITOR_RENAME_BUTTON:
|
||||
if (filename_valid_characters(text)) {
|
||||
if (title_sequence_manager_get_index_for_name(text) == SIZE_MAX) {
|
||||
if (widgetIndex == WIDX_TITLE_EDITOR_NEW_BUTTON) {
|
||||
size_t newIndex = title_sequence_manager_create(text);
|
||||
window_title_editor_load_sequence(newIndex);
|
||||
} else if (widgetIndex == WIDX_TITLE_EDITOR_DUPLICATE_BUTTON) {
|
||||
size_t newIndex = title_sequence_manager_duplicate(_selectedTitleSequence, text);
|
||||
window_title_editor_load_sequence(newIndex);
|
||||
if (!title_sequence_manager_is_name_reserved(text)) {
|
||||
if (widgetIndex == WIDX_TITLE_EDITOR_NEW_BUTTON) {
|
||||
size_t newIndex = title_sequence_manager_create(text);
|
||||
window_title_editor_load_sequence(newIndex);
|
||||
} else if (widgetIndex == WIDX_TITLE_EDITOR_DUPLICATE_BUTTON) {
|
||||
size_t newIndex = title_sequence_manager_duplicate(_selectedTitleSequence, text);
|
||||
window_title_editor_load_sequence(newIndex);
|
||||
} else {
|
||||
size_t newIndex = title_sequence_manager_rename(_selectedTitleSequence, text);
|
||||
window_title_editor_load_sequence(newIndex);
|
||||
}
|
||||
config_save_default();
|
||||
window_invalidate(w);
|
||||
} else {
|
||||
size_t newIndex = title_sequence_manager_rename(_selectedTitleSequence, text);
|
||||
window_title_editor_load_sequence(newIndex);
|
||||
context_show_error(STR_ERROR_RESERVED_NAME, STR_NONE);
|
||||
}
|
||||
config_save_default();
|
||||
window_invalidate(w);
|
||||
} else {
|
||||
context_show_error(STR_ERROR_EXISTING_NAME, STR_NONE);
|
||||
}
|
||||
|
@ -668,7 +672,7 @@ static void window_title_editor_invalidate(rct_window *w)
|
|||
window_title_editor_widgets[WIDX_TITLE_EDITOR_NEW_BUTTON].type = WWT_EMPTY;
|
||||
window_title_editor_widgets[WIDX_TITLE_EDITOR_DUPLICATE_BUTTON].type = WWT_EMPTY;
|
||||
window_title_editor_widgets[WIDX_TITLE_EDITOR_DELETE_BUTTON].type = WWT_EMPTY;
|
||||
window_title_editor_widgets[WIDX_TITLE_EDITOR_RENAME_SAVE_BUTTON].type = WWT_EMPTY;
|
||||
window_title_editor_widgets[WIDX_TITLE_EDITOR_RENAME_BUTTON].type = WWT_EMPTY;
|
||||
|
||||
window_title_editor_widgets[WIDX_TITLE_EDITOR_ADD_SAVE].type = WWT_EMPTY;
|
||||
window_title_editor_widgets[WIDX_TITLE_EDITOR_REMOVE_SAVE].type = WWT_EMPTY;
|
||||
|
@ -694,7 +698,7 @@ static void window_title_editor_invalidate(rct_window *w)
|
|||
window_title_editor_widgets[WIDX_TITLE_EDITOR_NEW_BUTTON].type = WWT_DROPDOWN_BUTTON;
|
||||
window_title_editor_widgets[WIDX_TITLE_EDITOR_DUPLICATE_BUTTON].type = WWT_DROPDOWN_BUTTON;
|
||||
window_title_editor_widgets[WIDX_TITLE_EDITOR_DELETE_BUTTON].type = WWT_DROPDOWN_BUTTON;
|
||||
window_title_editor_widgets[WIDX_TITLE_EDITOR_RENAME_SAVE_BUTTON].type = WWT_DROPDOWN_BUTTON;
|
||||
window_title_editor_widgets[WIDX_TITLE_EDITOR_RENAME_BUTTON].type = WWT_DROPDOWN_BUTTON;
|
||||
break;
|
||||
case WINDOW_TITLE_EDITOR_TAB_SAVES:
|
||||
window_title_editor_widgets[WIDX_TITLE_EDITOR_LIST].type = WWT_SCROLL;
|
||||
|
|
|
@ -3809,6 +3809,8 @@ enum {
|
|||
STR_ADMIN_NOT_RECOMMENDED = 6154,
|
||||
STR_MISSING_DIALOG_APPLICATION_ERROR = 6155,
|
||||
|
||||
STR_ERROR_RESERVED_NAME = 6156,
|
||||
|
||||
// Have to include resource strings (from scenarios and objects) for the time being now that language is partially working
|
||||
STR_COUNT = 32768
|
||||
};
|
||||
|
|
|
@ -57,6 +57,7 @@ namespace TitleSequenceManager
|
|||
static std::string GetNameFromSequencePath(const std::string &path);
|
||||
static void GetDataSequencesPath(utf8 * buffer, size_t bufferSize);
|
||||
static void GetUserSequencesPath(utf8 * buffer, size_t bufferSize);
|
||||
static bool IsNameReserved(const std::string &name);
|
||||
|
||||
size_t GetCount()
|
||||
{
|
||||
|
@ -267,6 +268,12 @@ namespace TitleSequenceManager
|
|||
rct_string_id stringId = PredefinedSequences[item.PredefinedIndex].StringId;
|
||||
item.Name = language_get_string(stringId);
|
||||
}
|
||||
else if (IsNameReserved(item.Name))
|
||||
{
|
||||
// Reserved names are not allowed because they map to the
|
||||
// actual predefined names and also prevent editing
|
||||
return;
|
||||
}
|
||||
item.IsZip = isZip;
|
||||
_items.push_back(item);
|
||||
}
|
||||
|
@ -290,6 +297,21 @@ namespace TitleSequenceManager
|
|||
platform_get_user_directory(buffer, "title sequences", bufferSize);
|
||||
platform_ensure_directory_exists(buffer);
|
||||
}
|
||||
|
||||
static bool IsNameReserved(const std::string &name)
|
||||
{
|
||||
for (const auto &pseq : TitleSequenceManager::PredefinedSequences)
|
||||
{
|
||||
const utf8 * predefinedName = Path::GetFileNameWithoutExtension(pseq.Filename);
|
||||
std::string reservedName = std::string(predefinedName);
|
||||
Memory::Free(predefinedName);
|
||||
if (String::Equals(name, reservedName, true))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C"
|
||||
|
@ -376,6 +398,11 @@ extern "C"
|
|||
return SIZE_MAX;
|
||||
}
|
||||
|
||||
bool title_sequence_manager_is_name_reserved(const utf8 * name)
|
||||
{
|
||||
return TitleSequenceManager::IsNameReserved(name);
|
||||
}
|
||||
|
||||
void title_sequence_manager_scan()
|
||||
{
|
||||
TitleSequenceManager::Scan();
|
||||
|
|
|
@ -53,6 +53,7 @@ extern "C" {
|
|||
uint16 title_sequence_manager_get_predefined_index(size_t index);
|
||||
size_t title_sequence_manager_get_index_for_config_id(const utf8 * configId);
|
||||
size_t title_sequence_manager_get_index_for_name(const utf8 * name);
|
||||
bool title_sequence_manager_is_name_reserved(const utf8 * name);
|
||||
void title_sequence_manager_scan();
|
||||
void title_sequence_manager_delete(size_t i);
|
||||
size_t title_sequence_manager_rename(size_t i, const utf8 * name);
|
||||
|
|
Loading…
Reference in New Issue