From 9f28b66eece3d46fe8af186ef2d9d868e5581d78 Mon Sep 17 00:00:00 2001 From: Ted John Date: Thu, 24 Mar 2022 01:03:08 +0000 Subject: [PATCH 1/3] Remove title editor --- data/language/en-GB.txt | 83 -- src/openrct2-ui/interface/Theme.cpp | 1 - src/openrct2-ui/libopenrct2ui.vcxproj | 2 - src/openrct2-ui/windows/Options.cpp | 5 - src/openrct2-ui/windows/Themes.cpp | 5 +- .../windows/TitleCommandEditor.cpp | 859 ------------ src/openrct2-ui/windows/TitleEditor.cpp | 1163 ----------------- src/openrct2-ui/windows/Window.h | 2 - src/openrct2/interface/InteractiveConsole.cpp | 4 - src/openrct2/interface/Window.h | 2 - src/openrct2/localisation/StringIds.h | 86 +- 11 files changed, 3 insertions(+), 2209 deletions(-) delete mode 100644 src/openrct2-ui/windows/TitleCommandEditor.cpp delete mode 100644 src/openrct2-ui/windows/TitleEditor.cpp diff --git a/data/language/en-GB.txt b/data/language/en-GB.txt index 3d7c108fc3..6910ceefc6 100644 --- a/data/language/en-GB.txt +++ b/data/language/en-GB.txt @@ -2553,8 +2553,6 @@ STR_5250 :Title Exit Button STR_5251 :Title Options Button STR_5252 :Title Scenario Selection STR_5253 :Park Information -STR_5254 :Create -STR_5255 :Create a new title sequence from scratch STR_5256 :Create a new theme to make changes to STR_5257 :Create a new theme based on the current one STR_5258 :Delete the current theme @@ -2649,75 +2647,10 @@ STR_5373 :Name {STRINGID} STR_5374 :Date {STRINGID} STR_5375 :▲ STR_5376 :▼ -STR_5377 :Saves -STR_5378 :Script -STR_5379 :Skip to next wait command -STR_5380 :Start playing title sequence -STR_5381 :Stop playing title sequence -STR_5382 :Restart title sequence -STR_5383 :Create a new title sequence based on the current one -STR_5384 :Delete the current title sequence -STR_5385 :Rename the current title sequence -STR_5386 :Insert a new command -STR_5387 :Edit the selected command -STR_5388 :Delete the selected command -STR_5389 :Skip to the selected command in the title sequence -STR_5390 :Move the selected command down -STR_5391 :Move the selected command up -STR_5392 :Add a save to the title sequence -STR_5393 :Remove the selected save from the title sequence -STR_5394 :Rename the selected save -STR_5395 :Load the selected save in game -STR_5396 :Reload the title sequence if changes have been made to it outside of the game -STR_5397 :Can only be used on the title screen -STR_5398 :Cannot edit title sequence while it’s playing -STR_5399 :Press the stop button to continue editing -STR_5400 :Can’t change this title sequence -STR_5401 :Create a new title sequence to make changes to -STR_5402 :Failed to load title sequence -STR_5403 :There may be no Load or Wait command or a save may be invalid STR_5404 :Name already exists -STR_5405 :Enter a name for the save -STR_5406 :Enter a name for the title sequence -STR_5407 :Add -STR_5408 :Remove -STR_5409 :Insert -STR_5410 :Edit -STR_5411 :Reload -STR_5412 :Skip to -STR_5413 :Load -STR_5415 :Load{MOVE_X}{87}{STRING} -STR_5416 :Load{MOVE_X}{87}No save selected -STR_5417 :Location -STR_5418 :Location{MOVE_X}{87}{COMMA16} {COMMA16} -STR_5419 :Rotate -STR_5420 :Rotate{MOVE_X}{87}{COMMA16} -STR_5421 :Zoom -STR_5422 :Zoom{MOVE_X}{87}{COMMA16} -STR_5423 :Wait -STR_5424 :Wait{MOVE_X}{87}{UINT16} -STR_5425 :Restart -STR_5426 :End -STR_5427 :Coordinates: -STR_5428 :Anticlockwise rotations: -STR_5429 :Zoom level: -STR_5430 :Milliseconds to wait: -STR_5431 :Save to load: -STR_5432 :Command: -STR_5433 :Title Sequences -STR_5434 :Command Editor -STR_5435 :Rename save -STR_5436 :Edit Title Sequences… -STR_5437 :No save selected -STR_5438 :Can’t make changes while command editor is open -STR_5439 :A wait command with at least 4 seconds is required with a restart command STR_5440 :Minimise fullscreen on focus loss STR_5441 :Identifies rides by track type{NEWLINE}so vehicles can be changed{NEWLINE}afterwards (RCT1 behaviour) STR_5442 :Force park rating: -STR_5443 :Speed{MOVE_X}{87}{STRINGID} -STR_5444 :Speed: -STR_5445 :Speed -STR_5446 :Get STR_5447 :Type {STRINGID} STR_5448 :Ride / Vehicle {STRINGID} STR_5449 :Reduce game speed @@ -3073,7 +3006,6 @@ STR_5844 :Stay connected to a multiplayer server{NEWLINE}even if a desync or STR_5845 :Adds a button for{NEWLINE}debugging tools to the toolbar.{NEWLINE}Enables keyboard shortcut for developer console STR_5846 :Set how often OpenRCT2 automatically saves STR_5847 :Select park sequence used on the title screen.{NEWLINE}Title sequences from RCT1/2 require imported scenarios to function -STR_5848 :Create and manage custom title sequences STR_5849 :Automatically place{NEWLINE}newly hired staff members STR_5851 :Sets the default inspection interval{NEWLINE}on newly built rides STR_5853 :Toggle sound effects on/off @@ -3387,23 +3319,8 @@ STR_6170 :Interface Tweaks STR_6171 :Search STR_6172 :Search STR_6173 :Please provide the name to search: -STR_6174 :Load Save -STR_6175 :Load Scenario -STR_6176 :Scenario to load: -STR_6177 :Load{MOVE_X}{87}No scenario selected -STR_6178 :Load{MOVE_X}{87}{RED}Missing scenario -STR_6179 :Select -STR_6180 :No scenario selected -STR_6181 :{RED}Missing scenario -STR_6182 :Follow{MOVE_X}{87}{STRING} -STR_6183 :Follow{MOVE_X}{87}No sprite selected -STR_6184 :Follow Sprite -STR_6185 :Select Sprite -STR_6186 :No sprite selected -STR_6187 :{OUTLINE}{WINDOW_COLOUR_2}{STRING} STR_6188 :Vomit STR_6189 :Duck -STR_6190 :You cannot select a sprite while the main title screen is active. STR_6191 :Surface STR_6192 :Wall STR_6193 :{COMMA16} guest diff --git a/src/openrct2-ui/interface/Theme.cpp b/src/openrct2-ui/interface/Theme.cpp index 02b2eb3bf2..7fdf4da5a0 100644 --- a/src/openrct2-ui/interface/Theme.cpp +++ b/src/openrct2-ui/interface/Theme.cpp @@ -171,7 +171,6 @@ static constexpr const WindowThemeDesc WindowThemeDescriptors[] = { THEME_WC(WC_STAFF), STR_THEMES_WINDOW_STAFF, COLOURS_3(COLOUR_GREY, COLOUR_LIGHT_PURPLE, COLOUR_LIGHT_PURPLE ) }, { THEME_WC(WC_EDITOR_TRACK_BOTTOM_TOOLBAR), STR_THEMES_WINDOW_BOTTOM_TOOLBAR_TRACK_EDITOR, COLOURS_3(TRANSLUCENT(COLOUR_LIGHT_BLUE), TRANSLUCENT(COLOUR_LIGHT_BLUE), TRANSLUCENT(COLOUR_LIGHT_BLUE) ) }, { THEME_WC(WC_EDITOR_SCENARIO_BOTTOM_TOOLBAR), STR_THEMES_WINDOW_BOTTOM_TOOLBAR_SCENARIO_EDITOR, COLOURS_3(TRANSLUCENT(COLOUR_LIGHT_BROWN), TRANSLUCENT(COLOUR_LIGHT_BROWN), TRANSLUCENT(COLOUR_MOSS_GREEN) ) }, - { THEME_WC(WC_TITLE_EDITOR), STR_TITLE_EDITOR_TITLE, COLOURS_3(COLOUR_GREY, COLOUR_OLIVE_GREEN, COLOUR_OLIVE_GREEN ) }, { THEME_WC(WC_TILE_INSPECTOR), STR_TILE_INSPECTOR_TITLE, COLOURS_2(COLOUR_LIGHT_BLUE, COLOUR_LIGHT_BLUE ) }, { THEME_WC(WC_VIEW_CLIPPING), STR_VIEW_CLIPPING_TITLE, COLOURS_1(COLOUR_DARK_GREEN ) }, { THEME_WC(WC_PATROL_AREA), STR_SET_PATROL_AREA, COLOURS_3(COLOUR_LIGHT_PURPLE, COLOUR_LIGHT_PURPLE, COLOUR_LIGHT_PURPLE ) }, diff --git a/src/openrct2-ui/libopenrct2ui.vcxproj b/src/openrct2-ui/libopenrct2ui.vcxproj index a0a67bf64c..dbf6d068a8 100644 --- a/src/openrct2-ui/libopenrct2ui.vcxproj +++ b/src/openrct2-ui/libopenrct2ui.vcxproj @@ -180,8 +180,6 @@ - - diff --git a/src/openrct2-ui/windows/Options.cpp b/src/openrct2-ui/windows/Options.cpp index f724d39390..41b5875d28 100644 --- a/src/openrct2-ui/windows/Options.cpp +++ b/src/openrct2-ui/windows/Options.cpp @@ -176,7 +176,6 @@ enum WindowOptionsWidgetIdx { WIDX_TITLE_SEQUENCE_LABEL, WIDX_TITLE_SEQUENCE, WIDX_TITLE_SEQUENCE_DROPDOWN, - WIDX_TITLE_SEQUENCE_BUTTON, WIDX_SCENARIO_GROUP, WIDX_SCENARIO_GROUPING_LABEL, WIDX_SCENARIO_GROUPING, @@ -352,7 +351,6 @@ static rct_widget window_options_misc_widgets[] = { MakeWidget({ 10, TITLE_SEQUENCE_START + 33}, {125, 12}, WindowWidgetType::Label, WindowColour::Secondary, STR_TITLE_SEQUENCE, STR_TITLE_SEQUENCE_TIP ), MakeWidget({135, TITLE_SEQUENCE_START + 32}, {165, 12}, WindowWidgetType::DropdownMenu, WindowColour::Secondary, STR_STRING ), // Title sequence dropdown MakeWidget({288, TITLE_SEQUENCE_START + 33}, { 11, 12}, WindowWidgetType::Button, WindowColour::Secondary, STR_DROPDOWN_GLYPH, STR_TITLE_SEQUENCE_TIP ), // Title sequence dropdown button - MakeWidget({135, TITLE_SEQUENCE_START + 48}, {165, 13}, WindowWidgetType::Button, WindowColour::Secondary, STR_EDIT_TITLE_SEQUENCES_BUTTON, STR_EDIT_TITLE_SEQUENCES_BUTTON_TIP), // Edit title sequences button #undef TITLE_SEQUENCE_START #define SCENARIO_START 122 MakeWidget({ 5, SCENARIO_START + 0}, {300, 51}, WindowWidgetType::Groupbox, WindowColour::Secondary, STR_OPTIONS_SCENARIO_SELECTION ), @@ -1645,9 +1643,6 @@ private: config_save_default(); Invalidate(); break; - case WIDX_TITLE_SEQUENCE_BUTTON: - WindowTitleEditorOpen(0); - break; case WIDX_SCENARIO_UNLOCKING: gConfigGeneral.scenario_unlocking_enabled ^= 1; config_save_default(); diff --git a/src/openrct2-ui/windows/Themes.cpp b/src/openrct2-ui/windows/Themes.cpp index 2e2a2d4c81..1fce4fc112 100644 --- a/src/openrct2-ui/windows/Themes.cpp +++ b/src/openrct2-ui/windows/Themes.cpp @@ -116,7 +116,7 @@ static rct_widget window_themes_widgets[] = { MakeWidget({219, 46}, { 97, 15}, WindowWidgetType::TableHeader, WindowColour::Secondary, STR_THEMES_HEADER_PALETTE ), // Palette header MakeWidget({125, 60}, {175, 12}, WindowWidgetType::DropdownMenu, WindowColour::Secondary ), // Preset colour schemes MakeWidget({288, 61}, { 11, 10}, WindowWidgetType::Button, WindowColour::Secondary, STR_DROPDOWN_GLYPH ), - MakeWidget({ 10, 82}, { 91, 12}, WindowWidgetType::Button, WindowColour::Secondary, STR_TITLE_EDITOR_ACTION_DUPLICATE, STR_THEMES_ACTION_DUPLICATE_TIP ), // Duplicate button + MakeWidget({ 10, 82}, { 91, 12}, WindowWidgetType::Button, WindowColour::Secondary, STR_THEMES_ACTION_DUPLICATE, STR_THEMES_ACTION_DUPLICATE_TIP ), // Duplicate button MakeWidget({110, 82}, { 91, 12}, WindowWidgetType::Button, WindowColour::Secondary, STR_TRACK_MANAGE_DELETE, STR_THEMES_ACTION_DELETE_TIP ), // Delete button MakeWidget({210, 82}, { 91, 12}, WindowWidgetType::Button, WindowColour::Secondary, STR_TRACK_MANAGE_RENAME, STR_THEMES_ACTION_RENAME_TIP ), // Rename button MakeWidget({ 0, 0}, { 1, 1}, WindowWidgetType::ColourBtn, WindowColour::Secondary ), // colour button mask @@ -224,7 +224,6 @@ static rct_windowclass window_themes_tab_6_classes[] = { WC_VIEW_CLIPPING, WC_TRANSPARENCY, WC_THEMES, - WC_TITLE_EDITOR, WC_OPTIONS, WC_KEYBOARD_SHORTCUT_LIST, WC_CHANGE_KEYBOARD_SHORTCUT, @@ -355,7 +354,7 @@ static void WindowThemesMouseup(rct_window* w, rct_widgetindex widgetIndex) activeAvailableThemeIndex = ThemeManagerGetAvailableThemeIndex(); activeThemeName = ThemeManagerGetAvailableThemeName(activeAvailableThemeIndex); WindowTextInputOpen( - w, widgetIndex, STR_TITLE_EDITOR_ACTION_DUPLICATE, STR_THEMES_PROMPT_ENTER_THEME_NAME, {}, STR_STRING, + w, widgetIndex, STR_THEMES_ACTION_DUPLICATE, STR_THEMES_PROMPT_ENTER_THEME_NAME, {}, STR_STRING, reinterpret_cast(activeThemeName), 64); break; case WIDX_THEMES_DELETE_BUTTON: diff --git a/src/openrct2-ui/windows/TitleCommandEditor.cpp b/src/openrct2-ui/windows/TitleCommandEditor.cpp deleted file mode 100644 index 2d8e223bf9..0000000000 --- a/src/openrct2-ui/windows/TitleCommandEditor.cpp +++ /dev/null @@ -1,859 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2014-2020 OpenRCT2 developers - * - * For a complete list of all authors, please refer to contributors.md - * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 - * - * OpenRCT2 is licensed under the GNU General Public License version 3. - *****************************************************************************/ - -#include "../interface/Theme.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// clang-format off -struct TitleCommandOrder { - TitleScript command; - rct_string_id nameStringId; - rct_string_id descStringId; -}; - -static TitleCommandOrder _window_title_command_editor_orders[] = { - { TitleScript::Load, STR_TITLE_EDITOR_ACTION_LOAD_SAVE, STR_TITLE_EDITOR_ARGUMENT_SAVEFILE }, - { TitleScript::LoadSc, STR_TITLE_EDITOR_ACTION_LOAD_SCENARIO, STR_TITLE_EDITOR_ARGUMENT_SCENARIO }, - { TitleScript::Location, STR_TITLE_EDITOR_COMMAND_TYPE_LOCATION, STR_TITLE_EDITOR_ARGUMENT_COORDINATES }, - { TitleScript::Rotate, STR_TITLE_EDITOR_COMMAND_TYPE_ROTATE, STR_TITLE_EDITOR_ARGUMENT_ROTATIONS }, - { TitleScript::Zoom, STR_TITLE_EDITOR_COMMAND_TYPE_ZOOM, STR_TITLE_EDITOR_ARGUMENT_ZOOM_LEVEL }, - { TitleScript::Speed, STR_TITLE_EDITOR_COMMAND_TYPE_SPEED, STR_TITLE_EDITOR_ARGUMENT_SPEED }, - { TitleScript::Follow, STR_TITLE_EDITOR_COMMAND_TYPE_FOLLOW, STR_NONE }, - { TitleScript::Wait, STR_TITLE_EDITOR_COMMAND_TYPE_WAIT, STR_TITLE_EDITOR_ARGUMENT_WAIT_SECONDS }, - { TitleScript::Restart, STR_TITLE_EDITOR_RESTART, STR_NONE }, - { TitleScript::End, STR_TITLE_EDITOR_END, STR_NONE }, -}; - -#define NUM_COMMANDS std::size(_window_title_command_editor_orders) - -enum WindowTitleCommandEditorWidgetIdx { - WIDX_BACKGROUND, - WIDX_TITLE, - WIDX_CLOSE, - WIDX_COMMAND, - WIDX_COMMAND_DROPDOWN, - WIDX_TEXTBOX_FULL, - WIDX_TEXTBOX_X, - WIDX_TEXTBOX_Y, - WIDX_INPUT, - WIDX_INPUT_DROPDOWN, - WIDX_GET, - WIDX_SELECT_SCENARIO, - WIDX_SELECT_SPRITE, - WIDX_VIEWPORT, - WIDX_OKAY, - WIDX_CANCEL -}; - -static constexpr rct_string_id WINDOW_TITLE = STR_TITLE_COMMAND_EDITOR_TITLE; -static constexpr const int32_t WW = 200; -static constexpr const int32_t WH = 120; -static constexpr int32_t BY = 32; -static constexpr int32_t BY2 = 70; -static constexpr int32_t WS = 16; - -static bool _window_title_command_editor_insert; -static int32_t _window_title_command_editor_index; -constexpr size_t BUF_SIZE = 50; -static char textbox1Buffer[BUF_SIZE]; -static char textbox2Buffer[BUF_SIZE]; -static TitleCommand _command = { TitleScript::Load, { 0 } }; -static TitleSequence * _sequence = nullptr; - -static rct_widget window_title_command_editor_widgets[] = { - WINDOW_SHIM(WINDOW_TITLE, WW, WH), - MakeWidget({ 16, 32}, { 168, 12}, WindowWidgetType::DropdownMenu, WindowColour::Secondary ), // Command dropdown - MakeWidget({172, 33}, { 11, 12}, WindowWidgetType::Button, WindowColour::Secondary, STR_DROPDOWN_GLYPH ), - MakeWidget({ 16, 70}, { 168, 12}, WindowWidgetType::TextBox, WindowColour::Secondary ), // full textbox - - MakeWidget({ 16, 70}, { 81, 12}, WindowWidgetType::TextBox, WindowColour::Secondary ), // x textbox - MakeWidget({103, 70}, { 81, 12}, WindowWidgetType::TextBox, WindowColour::Secondary ), // y textbox - - MakeWidget({ 16, 70}, { 168, 12}, WindowWidgetType::DropdownMenu, WindowColour::Secondary ), // Save dropdown - MakeWidget({172, 71}, { 11, 10}, WindowWidgetType::Button, WindowColour::Secondary, STR_DROPDOWN_GLYPH ), - - MakeWidget({103, 56}, { 81, 12}, WindowWidgetType::Button, WindowColour::Secondary, STR_TITLE_COMMAND_EDITOR_ACTION_GET_LOCATION ), // Get location/zoom/etc - MakeWidget({112, 56}, { 72, 12}, WindowWidgetType::Button, WindowColour::Secondary, STR_TITLE_COMMAND_EDITOR_ACTION_SELECT_SCENARIO), // Select scenario - - MakeWidget({ 16, 56}, { 168, 12}, WindowWidgetType::Button, WindowColour::Secondary, STR_TITLE_COMMAND_EDITOR_SELECT_SPRITE ), // Select sprite - MakeWidget({ 16, 70}, { 168, 24}, WindowWidgetType::Viewport, WindowColour::Secondary ), // Viewport - - MakeWidget({ 10, 99}, { 71, 14}, WindowWidgetType::Button, WindowColour::Secondary, STR_OK ), // OKAY - MakeWidget({120, 99}, { 71, 14}, WindowWidgetType::Button, WindowColour::Secondary, STR_CANCEL ), // Cancel - WIDGETS_END, -}; - -static void WindowTitleCommandEditorClose(rct_window * w); -static void WindowTitleCommandEditorMouseup(rct_window * w, rct_widgetindex widgetIndex); -static void WindowTitleCommandEditorMousedown(rct_window * w, rct_widgetindex widgetIndex, rct_widget * widget); -static void WindowTitleCommandEditorDropdown(rct_window * w, rct_widgetindex widgetIndex, int32_t dropdownIndex); -static void WindowTitleCommandEditorUpdate(rct_window * w); -static void WindowTitleCommandEditorToolDown(rct_window * w, rct_widgetindex widgetIndex, const ScreenCoordsXY& screenCoords); -static void WindowTitleCommandEditorInvalidate(rct_window * w); -static void WindowTitleCommandEditorPaint(rct_window * w, rct_drawpixelinfo * dpi); -static void WindowTitleCommandEditorTextinput(rct_window * w, rct_widgetindex widgetIndex, char * text); -static void ScenarioSelectCallback(const utf8 * path); -static int32_t GetCommandInfoIndex(TitleScript commandType); -static TitleCommandOrder GetCommandInfo(TitleScript commandType); -static TileCoordsXY GetLocation(); -static uint8_t GetZoom(); - -static rct_window_event_list window_title_command_editor_events([](auto& events) -{ - events.close = &WindowTitleCommandEditorClose; - events.mouse_up = &WindowTitleCommandEditorMouseup; - events.mouse_down = &WindowTitleCommandEditorMousedown; - events.dropdown = &WindowTitleCommandEditorDropdown; - events.update = &WindowTitleCommandEditorUpdate; - events.tool_down = &WindowTitleCommandEditorToolDown; - events.text_input = &WindowTitleCommandEditorTextinput; - events.invalidate = &WindowTitleCommandEditorInvalidate; - events.paint = &WindowTitleCommandEditorPaint; -}); -// clang-format on - -static void ScenarioSelectCallback(const utf8* path) -{ - if (_command.Type == TitleScript::LoadSc) - { - const auto fileName = Path::GetFileName(path); - auto scenario = GetScenarioRepository()->GetByFilename(fileName); - safe_strcpy(_command.Scenario, scenario->internal_name, sizeof(_command.Scenario)); - } -} - -static int32_t GetCommandInfoIndex(TitleScript commandType) -{ - for (int32_t i = 0; i < static_cast(NUM_COMMANDS); i++) - { - if (_window_title_command_editor_orders[i].command == commandType) - return i; - } - return 0; -} - -static TitleCommandOrder GetCommandInfo(TitleScript commandType) -{ - for (int32_t i = 0; i < static_cast(NUM_COMMANDS); i++) - { - if (_window_title_command_editor_orders[i].command == commandType) - return _window_title_command_editor_orders[i]; - } - return _window_title_command_editor_orders[0]; -} - -static TileCoordsXY GetLocation() -{ - TileCoordsXY tileCoord = {}; - rct_window* w = window_get_main(); - if (w != nullptr) - { - auto info = get_map_coordinates_from_pos_window( - w, { w->viewport->view_width / 2, w->viewport->view_height / 2 }, EnumsToFlags(ViewportInteractionItem::Terrain)); - auto mapCoord = info.Loc; - mapCoord.x -= 16; - mapCoord.y -= 16; - tileCoord = TileCoordsXY{ mapCoord }; - tileCoord.x++; - tileCoord.y++; - } - return tileCoord; -} - -static uint8_t GetZoom() -{ - uint8_t zoom = 0; - rct_window* w = window_get_main(); - if (w != nullptr) - { - zoom = static_cast(w->viewport->zoom); - } - return zoom; -} - -static bool SpriteSelectorToolIsActive() -{ - if (!(input_test_flag(INPUT_FLAG_TOOL_ACTIVE))) - return false; - if (gCurrentToolWidget.window_classification != WC_TITLE_COMMAND_EDITOR) - return false; - return true; -} - -void WindowTitleCommandEditorOpen(TitleSequence* sequence, int32_t index, bool insert) -{ - _sequence = sequence; - - // Check if window is already open - if (window_find_by_class(WC_TITLE_COMMAND_EDITOR) != nullptr) - return; - - rct_window* window = WindowCreateCentred( - WW, WH, &window_title_command_editor_events, WC_TITLE_COMMAND_EDITOR, WF_STICK_TO_FRONT); - window_title_command_editor_widgets[WIDX_TEXTBOX_FULL].string = textbox1Buffer; - window_title_command_editor_widgets[WIDX_TEXTBOX_X].string = textbox1Buffer; - window_title_command_editor_widgets[WIDX_TEXTBOX_Y].string = textbox2Buffer; - window->widgets = window_title_command_editor_widgets; - WindowInitScrollWidgets(window); - - rct_widget* const viewportWidget = &window_title_command_editor_widgets[WIDX_VIEWPORT]; - const auto focus = Focus(CoordsXYZ{ 0, 0, 0 }); - viewport_create( - window, window->windowPos + ScreenCoordsXY{ viewportWidget->left + 1, viewportWidget->top + 1 }, - viewportWidget->width() - 1, viewportWidget->height() - 1, focus); - - _window_title_command_editor_index = index; - _window_title_command_editor_insert = insert; - if (!insert) - { - _command = _sequence->Commands[index]; - } - - switch (_command.Type) - { - case TitleScript::Load: - if (_command.SaveIndex >= _sequence->Saves.size()) - _command.SaveIndex = SAVE_INDEX_INVALID; - break; - case TitleScript::Location: - snprintf(textbox1Buffer, BUF_SIZE, "%d", _command.Location.X); - snprintf(textbox2Buffer, BUF_SIZE, "%d", _command.Location.Y); - break; - case TitleScript::Rotate: - case TitleScript::Zoom: - snprintf(textbox1Buffer, BUF_SIZE, "%d", _command.Rotations); - break; - case TitleScript::Wait: - snprintf(textbox1Buffer, BUF_SIZE, "%d", _command.Milliseconds); - break; - case TitleScript::Follow: - if (!_command.Follow.SpriteIndex.IsNull()) - { - window_follow_sprite(window, _command.Follow.SpriteIndex); - } - break; - case TitleScript::Undefined: - break; - case TitleScript::Restart: - break; - case TitleScript::End: - break; - case TitleScript::Speed: - break; - case TitleScript::Loop: - break; - case TitleScript::EndLoop: - break; - case TitleScript::LoadSc: - break; - } -} - -static void WindowTitleCommandEditorClose(rct_window* w) -{ - if (SpriteSelectorToolIsActive()) - { - tool_cancel(); - } -} - -static void WindowTitleCommandEditorMouseup(rct_window* w, rct_widgetindex widgetIndex) -{ - switch (widgetIndex) - { - case WIDX_CLOSE: - case WIDX_CANCEL: - window_close(w); - break; - case WIDX_TEXTBOX_FULL: - // The only commands that use TEXTBOX_FULL currently are Wait, Rotate, and Zoom. Rotate and Zoom have single-digit - // maximum values, while Wait has 5-digit maximum values. - if (_command.Type == TitleScript::Wait) - { - window_start_textbox(w, widgetIndex, STR_STRING, textbox1Buffer, 6); - } - else - { - window_start_textbox(w, widgetIndex, STR_STRING, textbox1Buffer, 2); - } - break; - case WIDX_TEXTBOX_X: - window_start_textbox(w, widgetIndex, STR_STRING, textbox1Buffer, 4); - break; - case WIDX_TEXTBOX_Y: - window_start_textbox(w, widgetIndex, STR_STRING, textbox2Buffer, 4); - break; - case WIDX_GET: - if (_command.Type == TitleScript::Location) - { - auto tileCoord = GetLocation(); - _command.Location.X = static_cast(tileCoord.x); - _command.Location.Y = static_cast(tileCoord.y); - snprintf(textbox1Buffer, BUF_SIZE, "%d", _command.Location.X); - snprintf(textbox2Buffer, BUF_SIZE, "%d", _command.Location.Y); - } - else if (_command.Type == TitleScript::Zoom) - { - uint8_t zoom = GetZoom(); - _command.Zoom = zoom; - snprintf(textbox1Buffer, BUF_SIZE, "%d", _command.Zoom); - } - w->Invalidate(); - break; - case WIDX_SELECT_SCENARIO: - WindowScenarioselectOpen(ScenarioSelectCallback, true); - break; - case WIDX_SELECT_SPRITE: - if (!SpriteSelectorToolIsActive()) - { - tool_set(w, WIDX_BACKGROUND, Tool::Crosshair); - } - else - { - tool_cancel(); - } - break; - case WIDX_OKAY: - if (_window_title_command_editor_insert) - { - size_t insertIndex = _window_title_command_editor_index; - _sequence->Commands.insert(_sequence->Commands.begin() + insertIndex, _command); - } - else - { - _sequence->Commands[_window_title_command_editor_index] = _command; - } - TitleSequenceSave(*_sequence); - - rct_window* title_editor_w = window_find_by_class(WC_TITLE_EDITOR); - if (title_editor_w != nullptr) - { - title_editor_w->selected_list_item = _window_title_command_editor_index; - } - window_close(w); - break; - } -} - -static void WindowTitleCommandEditorMousedown(rct_window* w, rct_widgetindex widgetIndex, rct_widget* widget) -{ - widget--; - switch (widgetIndex) - { - case WIDX_COMMAND_DROPDOWN: - { - size_t numItems = NUM_COMMANDS; - for (size_t i = 0; i < numItems; i++) - { - gDropdownItems[i].Format = STR_DROPDOWN_MENU_LABEL; - gDropdownItems[i].Args = _window_title_command_editor_orders[i].nameStringId; - } - - WindowDropdownShowTextCustomWidth( - { w->windowPos.x + widget->left, w->windowPos.y + widget->top }, widget->height() + 1, w->colours[1], 0, - Dropdown::Flag::StayOpen, numItems, widget->width() - 3); - - Dropdown::SetChecked(GetCommandInfoIndex(_command.Type), true); - break; - } - case WIDX_INPUT_DROPDOWN: - if (_command.Type == TitleScript::Speed) - { - int32_t numItems = 4; - for (int32_t i = 0; i < numItems; i++) - { - gDropdownItems[i].Format = STR_DROPDOWN_MENU_LABEL; - gDropdownItems[i].Args = SpeedNames[i]; - } - - WindowDropdownShowTextCustomWidth( - { w->windowPos.x + widget->left, w->windowPos.y + widget->top }, widget->height() + 1, w->colours[1], 0, - Dropdown::Flag::StayOpen, numItems, widget->width() - 3); - - Dropdown::SetChecked(_command.Speed - 1, true); - } - else if (_command.Type == TitleScript::Load) - { - int32_t numItems = static_cast(_sequence->Saves.size()); - for (int32_t i = 0; i < numItems; i++) - { - gDropdownItems[i].Format = STR_OPTIONS_DROPDOWN_ITEM; - gDropdownItems[i].Args = reinterpret_cast(_sequence->Saves[i].c_str()); - } - - WindowDropdownShowTextCustomWidth( - { w->windowPos.x + widget->left, w->windowPos.y + widget->top }, widget->height() + 1, w->colours[1], 0, - Dropdown::Flag::StayOpen, numItems, widget->width() - 3); - - Dropdown::SetChecked(_command.SaveIndex, true); - } - break; - } -} - -static void WindowTitleCommandEditorDropdown(rct_window* w, rct_widgetindex widgetIndex, int32_t dropdownIndex) -{ - if (dropdownIndex == -1) - return; - - // Cancel sprite selector tool if it's active - if (SpriteSelectorToolIsActive()) - { - tool_cancel(); - } - - switch (widgetIndex) - { - case WIDX_COMMAND_DROPDOWN: - if (!_command.Follow.SpriteIndex.IsNull()) - { - window_unfollow_sprite(w); - } - if (dropdownIndex == GetCommandInfoIndex(_command.Type)) - { - break; - } - _command.Type = _window_title_command_editor_orders[dropdownIndex].command; - switch (_command.Type) - { - case TitleScript::Location: - { - auto tileCoord = GetLocation(); - _command.Location.X = static_cast(tileCoord.x); - _command.Location.Y = static_cast(tileCoord.y); - snprintf(textbox1Buffer, BUF_SIZE, "%d", _command.Location.X); - snprintf(textbox2Buffer, BUF_SIZE, "%d", _command.Location.Y); - break; - } - case TitleScript::Rotate: - _command.Rotations = 1; - snprintf(textbox1Buffer, BUF_SIZE, "%d", _command.Rotations); - break; - case TitleScript::Undefined: - break; - case TitleScript::Restart: - break; - case TitleScript::End: - break; - case TitleScript::Loop: - break; - case TitleScript::EndLoop: - break; - case TitleScript::Zoom: - _command.Zoom = 0; - snprintf(textbox1Buffer, BUF_SIZE, "%d", _command.Zoom); - break; - case TitleScript::Follow: - _command.Follow.SpriteIndex = EntityId::GetNull(); - _command.Follow.SpriteName[0] = '\0'; - window_unfollow_sprite(w); - // This is incorrect - w->viewport->flags &= ~VIEWPORT_FLAG_GRIDLINES; - break; - case TitleScript::Speed: - _command.Speed = 1; - break; - case TitleScript::Wait: - _command.Milliseconds = 10000; - snprintf(textbox1Buffer, BUF_SIZE, "%d", _command.Milliseconds); - break; - case TitleScript::Load: - _command.SaveIndex = 0; - if (_command.SaveIndex >= _sequence->Saves.size()) - { - _command.SaveIndex = 0xFF; - } - break; - case TitleScript::LoadSc: - _command.Scenario[0] = '\0'; - } - w->Invalidate(); - break; - case WIDX_INPUT_DROPDOWN: - switch (_command.Type) - { - case TitleScript::Speed: - if (dropdownIndex != _command.Speed - 1) - { - _command.Speed = static_cast(dropdownIndex + 1); - w->Invalidate(); - } - break; - case TitleScript::Load: - if (dropdownIndex != _command.SaveIndex) - { - _command.SaveIndex = static_cast(dropdownIndex); - w->Invalidate(); - } - break; - case TitleScript::Restart: - break; - case TitleScript::End: - break; - case TitleScript::Loop: - break; - case TitleScript::EndLoop: - break; - case TitleScript::Undefined: - break; - case TitleScript::Location: - break; - case TitleScript::Wait: - break; - case TitleScript::Rotate: - break; - case TitleScript::Zoom: - break; - case TitleScript::Follow: - break; - case TitleScript::LoadSc: - break; - } - break; - } -} - -static void WindowTitleCommandEditorTextinput(rct_window* w, rct_widgetindex widgetIndex, char* text) -{ - char* end; - int32_t value = strtol(widgetIndex != WIDX_TEXTBOX_Y ? textbox1Buffer : textbox2Buffer, &end, 10); - if (value < 0) - value = 0; - // The Wait command is the only one with acceptable values greater than 255. - if (value > 255 && _command.Type != TitleScript::Wait) - value = 255; - switch (widgetIndex) - { - case WIDX_TEXTBOX_FULL: - if (text == nullptr) - { - if (*end == '\0') - { - if (_command.Type == TitleScript::Wait) - { - if (value < 100) - value = 100; - if (value > 65000) - value = 65000; - _command.Milliseconds = static_cast(value); - snprintf(textbox1Buffer, BUF_SIZE, "%d", _command.Milliseconds); - } - else - { - // Both Rotate and Zoom have a maximum value of 3, but Rotate has a min value of 1 not 0. - if (value > 3) - value = 3; - if (value < 1 && _command.Type == TitleScript::Rotate) - value = 1; - _command.Rotations = static_cast(value); - snprintf(textbox1Buffer, BUF_SIZE, "%d", _command.Rotations); - } - } - w->Invalidate(); - } - else - { - safe_strcpy(textbox1Buffer, text, sizeof(textbox1Buffer)); - } - break; - case WIDX_TEXTBOX_X: - if (text == nullptr) - { - if (*end == '\0') - { - _command.Location.X = static_cast(value); - } - snprintf(textbox1Buffer, BUF_SIZE, "%d", _command.Location.X); - w->Invalidate(); - } - else - { - safe_strcpy(textbox1Buffer, text, sizeof(textbox1Buffer)); - } - break; - case WIDX_TEXTBOX_Y: - if (text == nullptr) - { - if (*end == '\0') - { - _command.Location.Y = static_cast(value); - } - snprintf(textbox2Buffer, BUF_SIZE, "%d", _command.Location.Y); - w->Invalidate(); - } - else - { - safe_strcpy(textbox2Buffer, text, sizeof(textbox2Buffer)); - } - break; - } -} - -static void WindowTitleCommandEditorUpdate(rct_window* w) -{ - if (gCurrentTextBox.window.classification == w->classification && gCurrentTextBox.window.number == w->number) - { - window_update_textbox_caret(); - widget_invalidate(w, gCurrentTextBox.widget_index); - } -} - -static void WindowTitleCommandEditorToolDown(rct_window* w, rct_widgetindex widgetIndex, const ScreenCoordsXY& screenCoords) -{ - auto info = ViewportInteractionGetItemLeft(screenCoords); - - if (info.SpriteType == ViewportInteractionItem::Entity) - { - auto entity = info.Entity; - bool validSprite = false; - auto peep = entity->As(); - auto vehicle = entity->As(); - auto litter = entity->As(); - auto duck = entity->As(); - auto balloon = entity->As(); - if (peep != nullptr) - { - validSprite = true; - Formatter ft; - peep->FormatNameTo(ft); - format_string(_command.Follow.SpriteName, USER_STRING_MAX_LENGTH, STR_STRINGID, &peep->Id); - } - else if (vehicle != nullptr) - { - validSprite = true; - - auto ride = vehicle->GetRide(); - if (ride != nullptr) - { - Formatter ft; - ride->FormatNameTo(ft); - format_string(_command.Follow.SpriteName, USER_STRING_MAX_LENGTH, STR_STRINGID, ft.Data()); - } - } - else if (litter != nullptr) - { - auto name = litter->GetName(); - if (name != STR_NONE) - { - validSprite = true; - format_string(_command.Follow.SpriteName, USER_STRING_MAX_LENGTH, name, nullptr); - } - } - else if (balloon != nullptr) - { - validSprite = true; - format_string(_command.Follow.SpriteName, USER_STRING_MAX_LENGTH, STR_SHOP_ITEM_SINGULAR_BALLOON, nullptr); - } - else if (duck != nullptr) - { - validSprite = true; - format_string(_command.Follow.SpriteName, USER_STRING_MAX_LENGTH, STR_DUCK, nullptr); - } - - if (validSprite) - { - _command.Follow.SpriteIndex = entity->sprite_index; - window_follow_sprite(w, _command.Follow.SpriteIndex); - tool_cancel(); - w->Invalidate(); - } - } -} - -static void WindowTitleCommandEditorInvalidate(rct_window* w) -{ - ColourSchemeUpdateByClass(w, WC_TITLE_EDITOR); - - window_title_command_editor_widgets[WIDX_TEXTBOX_FULL].type = WindowWidgetType::Empty; - window_title_command_editor_widgets[WIDX_TEXTBOX_X].type = WindowWidgetType::Empty; - window_title_command_editor_widgets[WIDX_TEXTBOX_Y].type = WindowWidgetType::Empty; - window_title_command_editor_widgets[WIDX_INPUT].type = WindowWidgetType::Empty; - window_title_command_editor_widgets[WIDX_INPUT_DROPDOWN].type = WindowWidgetType::Empty; - window_title_command_editor_widgets[WIDX_GET].type = WindowWidgetType::Empty; - window_title_command_editor_widgets[WIDX_SELECT_SCENARIO].type = WindowWidgetType::Empty; - window_title_command_editor_widgets[WIDX_SELECT_SPRITE].type = WindowWidgetType::Empty; - window_title_command_editor_widgets[WIDX_VIEWPORT].type = WindowWidgetType::Empty; - switch (_command.Type) - { - case TitleScript::Load: - case TitleScript::Speed: - window_title_command_editor_widgets[WIDX_INPUT].type = WindowWidgetType::DropdownMenu; - window_title_command_editor_widgets[WIDX_INPUT_DROPDOWN].type = WindowWidgetType::Button; - break; - case TitleScript::LoadSc: - window_title_command_editor_widgets[WIDX_INPUT].type = WindowWidgetType::DropdownMenu; - window_title_command_editor_widgets[WIDX_SELECT_SCENARIO].type = WindowWidgetType::Button; - break; - case TitleScript::Location: - window_title_command_editor_widgets[WIDX_TEXTBOX_X].type = WindowWidgetType::TextBox; - window_title_command_editor_widgets[WIDX_TEXTBOX_Y].type = WindowWidgetType::TextBox; - window_title_command_editor_widgets[WIDX_GET].type = WindowWidgetType::Button; - break; - case TitleScript::Rotate: - case TitleScript::Wait: - window_title_command_editor_widgets[WIDX_TEXTBOX_FULL].type = WindowWidgetType::TextBox; - break; - case TitleScript::Zoom: - window_title_command_editor_widgets[WIDX_GET].type = WindowWidgetType::Button; - window_title_command_editor_widgets[WIDX_TEXTBOX_FULL].type = WindowWidgetType::TextBox; - break; - case TitleScript::Undefined: - break; - case TitleScript::Restart: - break; - case TitleScript::End: - break; - case TitleScript::Loop: - break; - case TitleScript::EndLoop: - break; - case TitleScript::Follow: - window_title_command_editor_widgets[WIDX_SELECT_SPRITE].type = WindowWidgetType::Button; - window_title_command_editor_widgets[WIDX_VIEWPORT].type = WindowWidgetType::Viewport; - - // Draw button pressed while the tool is active - if (SpriteSelectorToolIsActive()) - w->pressed_widgets |= (1ULL << WIDX_SELECT_SPRITE); - else - w->pressed_widgets &= ~(1ULL << WIDX_SELECT_SPRITE); - - break; - } - - if ((gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) == SCREEN_FLAGS_TITLE_DEMO) - { - w->disabled_widgets |= (1ULL << WIDX_GET) | (1ULL << WIDX_SELECT_SPRITE); - window_title_command_editor_widgets[WIDX_SELECT_SPRITE].tooltip = STR_TITLE_COMMAND_EDITOR_SELECT_SPRITE_TOOLTIP; - } - else - { - w->disabled_widgets &= ~((1ULL << WIDX_GET) | (1ULL << WIDX_SELECT_SPRITE)); - window_title_command_editor_widgets[WIDX_SELECT_SPRITE].tooltip = STR_NONE; - } -} - -static void WindowTitleCommandEditorPaint(rct_window* w, rct_drawpixelinfo* dpi) -{ - WindowDrawWidgets(w, dpi); - - TitleCommandOrder command_info = GetCommandInfo(_command.Type); - - // "Command:" label - DrawTextBasic( - dpi, w->windowPos + ScreenCoordsXY{ WS, BY - 14 }, STR_TITLE_COMMAND_EDITOR_COMMAND_LABEL, {}, { w->colours[1] }); - - // Command dropdown name - DrawTextEllipsised( - dpi, { w->windowPos.x + w->widgets[WIDX_COMMAND].left + 1, w->windowPos.y + w->widgets[WIDX_COMMAND].top }, - w->widgets[WIDX_COMMAND_DROPDOWN].left - w->widgets[WIDX_COMMAND].left - 4, command_info.nameStringId, {}, - { w->colours[1] }); - - // Label (e.g. "Location:") - DrawTextBasic(dpi, w->windowPos + ScreenCoordsXY{ WS, BY2 - 14 }, command_info.descStringId, {}, { w->colours[1] }); - - if (_command.Type == TitleScript::Speed) - { - DrawTextEllipsised( - dpi, { w->windowPos.x + w->widgets[WIDX_INPUT].left + 1, w->windowPos.y + w->widgets[WIDX_INPUT].top }, - w->widgets[WIDX_INPUT_DROPDOWN].left - w->widgets[WIDX_INPUT].left - 4, SpeedNames[_command.Speed - 1], {}, - { w->colours[1] }); - } - if (_command.Type == TitleScript::Follow) - { - uint8_t colour = COLOUR_BLACK; - rct_string_id spriteString = STR_TITLE_COMMAND_EDITOR_FORMAT_SPRITE_NAME; - auto ft = Formatter(); - if (!_command.Follow.SpriteIndex.IsNull()) - { - window_draw_viewport(dpi, w); - ft.Add(_command.Follow.SpriteName); - } - else - { - colour = w->colours[1]; - spriteString = STR_TITLE_COMMAND_EDITOR_FOLLOW_NO_SPRITE; - } - - gfx_set_dirty_blocks( - { { w->windowPos + ScreenCoordsXY{ w->widgets[WIDX_VIEWPORT].left, w->widgets[WIDX_VIEWPORT].top } }, - { w->windowPos + ScreenCoordsXY{ w->widgets[WIDX_VIEWPORT].right, w->widgets[WIDX_VIEWPORT].bottom } } }); - DrawTextEllipsised( - dpi, { w->windowPos.x + w->widgets[WIDX_VIEWPORT].left + 2, w->windowPos.y + w->widgets[WIDX_VIEWPORT].top + 1 }, - w->widgets[WIDX_VIEWPORT].width() - 2, spriteString, ft, { colour }); - } - else if (_command.Type == TitleScript::Load) - { - if (_command.SaveIndex == SAVE_INDEX_INVALID) - { - DrawTextEllipsised( - dpi, { w->windowPos.x + w->widgets[WIDX_INPUT].left + 1, w->windowPos.y + w->widgets[WIDX_INPUT].top }, - w->widgets[WIDX_INPUT_DROPDOWN].left - w->widgets[WIDX_INPUT].left - 4, - STR_TITLE_COMMAND_EDITOR_NO_SAVE_SELECTED, {}, { w->colours[1] }); - } - else - { - auto ft = Formatter(); - ft.Add(_sequence->Saves[_command.SaveIndex].c_str()); - DrawTextEllipsised( - dpi, { w->windowPos.x + w->widgets[WIDX_INPUT].left + 1, w->windowPos.y + w->widgets[WIDX_INPUT].top }, - w->widgets[WIDX_INPUT_DROPDOWN].left - w->widgets[WIDX_INPUT].left - 4, STR_STRING, ft, { w->colours[1] }); - } - } - else if (_command.Type == TitleScript::LoadSc) - { - if (_command.Scenario[0] == '\0') - { - DrawTextEllipsised( - dpi, { w->windowPos.x + w->widgets[WIDX_INPUT].left + 1, w->windowPos.y + w->widgets[WIDX_INPUT].top }, - w->widgets[WIDX_INPUT_DROPDOWN].left - w->widgets[WIDX_INPUT].left - 4, - STR_TITLE_COMMAND_EDITOR_NO_SCENARIO_SELECTED, {}, { w->colours[1] }); - } - else - { - const char* name = ""; - rct_string_id nameString = STR_STRING; - auto scenario = GetScenarioRepository()->GetByInternalName(_command.Scenario); - if (scenario != nullptr) - { - name = scenario->name; - } - else - { - nameString = STR_TITLE_COMMAND_EDITOR_MISSING_SCENARIO; - } - auto ft = Formatter(); - ft.Add(name); - DrawTextEllipsised( - dpi, { w->windowPos.x + w->widgets[WIDX_INPUT].left + 1, w->windowPos.y + w->widgets[WIDX_INPUT].top }, - w->widgets[WIDX_INPUT_DROPDOWN].left - w->widgets[WIDX_INPUT].left - 4, nameString, ft, { w->colours[1] }); - } - } -} diff --git a/src/openrct2-ui/windows/TitleEditor.cpp b/src/openrct2-ui/windows/TitleEditor.cpp deleted file mode 100644 index 725b3dd2a9..0000000000 --- a/src/openrct2-ui/windows/TitleEditor.cpp +++ /dev/null @@ -1,1163 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2014-2020 OpenRCT2 developers - * - * For a complete list of all authors, please refer to contributors.md - * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 - * - * OpenRCT2 is licensed under the GNU General Public License version 3. - *****************************************************************************/ - -#include "../title/TitleSequencePlayer.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace OpenRCT2; - -enum WindowTitleEditorTab -{ - WINDOW_TITLE_EDITOR_TAB_PRESETS, - WINDOW_TITLE_EDITOR_TAB_SAVES, - WINDOW_TITLE_EDITOR_TAB_SCRIPT, - WINDOW_TITLE_EDITOR_TAB_COUNT -}; - -static void WindowTitleEditorClose(rct_window* w); -static void WindowTitleEditorMouseup(rct_window* w, rct_widgetindex widgetIndex); -static void WindowTitleEditorResize(rct_window* w); -static void WindowTitleEditorMousedown(rct_window* w, rct_widgetindex widgetIndex, rct_widget* widget); -static void WindowTitleEditorDropdown(rct_window* w, rct_widgetindex widgetIndex, int32_t dropdownIndex); -static void WindowTitleEditorUpdate(rct_window* w); -static void WindowTitleEditorScrollgetsize(rct_window* w, int32_t scrollIndex, int32_t* width, int32_t* height); -static void WindowTitleEditorScrollmousedown(rct_window* w, int32_t scrollIndex, const ScreenCoordsXY& screenCoords); -static void WindowTitleEditorScrollmouseover(rct_window* w, int32_t scrollIndex, const ScreenCoordsXY& screenCoords); -static void WindowTitleEditorTextinput(rct_window* w, rct_widgetindex widgetIndex, char* text); -static void WindowTitleEditorInvalidate(rct_window* w); -static void WindowTitleEditorPaint(rct_window* w, rct_drawpixelinfo* dpi); -static void WindowTitleEditorScrollpaint(rct_window* w, rct_drawpixelinfo* dpi, int32_t scrollIndex); -static void WindowTitleEditorScrollpaintSaves(rct_window* w, rct_drawpixelinfo* dpi); -static void WindowTitleEditorScrollpaintCommands(rct_window* w, rct_drawpixelinfo* dpi); -static void WindowTitleEditorDrawTabImages(rct_drawpixelinfo* dpi, rct_window* w); -static void WindowTitleEditorLoadSequence(size_t index); -static ITitleSequencePlayer* WindowTitleEditorGetPlayer(); -static bool WindowTitleEditorCheckCanEdit(); -static void WindowTitleEditorAddParkCallback(int32_t result, const utf8* path); -static void WindowTitleEditorRenamePark(size_t index, const utf8* name); - -static rct_window_event_list window_title_editor_events([](auto& events) { - events.close = &WindowTitleEditorClose; - events.mouse_up = &WindowTitleEditorMouseup; - events.resize = &WindowTitleEditorResize; - events.mouse_down = &WindowTitleEditorMousedown; - events.dropdown = &WindowTitleEditorDropdown; - events.update = &WindowTitleEditorUpdate; - events.get_scroll_size = &WindowTitleEditorScrollgetsize; - events.scroll_mousedown = &WindowTitleEditorScrollmousedown; - events.scroll_mouseover = &WindowTitleEditorScrollmouseover; - events.text_input = &WindowTitleEditorTextinput; - events.invalidate = &WindowTitleEditorInvalidate; - events.paint = &WindowTitleEditorPaint; - events.scroll_paint = &WindowTitleEditorScrollpaint; -}); - -enum WindowTitleEditorWidgetIdx -{ - WIDX_TITLE_EDITOR_BACKGROUND, - WIDX_TITLE_EDITOR_TITLE, - WIDX_TITLE_EDITOR_CLOSE, - WIDX_TITLE_EDITOR_TAB_CONTENT_PANEL, - WIDX_TITLE_EDITOR_PRESETS_TAB, - WIDX_TITLE_EDITOR_SAVES_TAB, - WIDX_TITLE_EDITOR_SCRIPT_TAB, - WIDX_TITLE_EDITOR_LIST, - - // Presets Tab - WIDX_TITLE_EDITOR_PRESETS, - WIDX_TITLE_EDITOR_PRESETS_DROPDOWN, - WIDX_TITLE_EDITOR_NEW_BUTTON, - WIDX_TITLE_EDITOR_DUPLICATE_BUTTON, - WIDX_TITLE_EDITOR_DELETE_BUTTON, - WIDX_TITLE_EDITOR_RENAME_BUTTON, - - // Saves Tab - WIDX_TITLE_EDITOR_ADD_SAVE, - WIDX_TITLE_EDITOR_REMOVE_SAVE, - WIDX_TITLE_EDITOR_RENAME_SAVE, - WIDX_TITLE_EDITOR_LOAD_SAVE, - - // Script Tab - WIDX_TITLE_EDITOR_INSERT, - WIDX_TITLE_EDITOR_EDIT, - WIDX_TITLE_EDITOR_DELETE, - // WIDX_TITLE_EDITOR_RELOAD, - WIDX_TITLE_EDITOR_SKIP_TO, - - WIDX_TITLE_EDITOR_MOVE_DOWN, - WIDX_TITLE_EDITOR_MOVE_UP, - - WIDX_TITLE_EDITOR_REPLAY, - WIDX_TITLE_EDITOR_STOP, - WIDX_TITLE_EDITOR_PLAY, - WIDX_TITLE_EDITOR_SKIP, -}; - -// Increase BW if certain languages do not fit -// BW should be a multiple of 4 -static constexpr const rct_string_id WINDOW_TITLE = STR_TITLE_EDITOR_TITLE; -static constexpr const int32_t WW = 320; -static constexpr const int32_t WH = 270; -static constexpr const int32_t WH2 = 127; -static constexpr const ScreenSize ACTION_BTN = { 91, 14 }; -static constexpr const ScreenSize EDIT_BTN = { 72, 14 }; -static constexpr const ScreenSize PLAYBACK_BTN = { 18, 17 }; -static constexpr const ScreenSize REORDER_BTN = { 36, 14 }; - -static constexpr int32_t SCROLL_WIDTH = 350; - -// clang-format off -static rct_widget window_title_editor_widgets[] = { - WINDOW_SHIM(WINDOW_TITLE, WW, WH), - MakeWidget({ 0, 43}, { 320, 84}, WindowWidgetType::Resize, WindowColour::Secondary ), // tab content panel - MakeTab ({ 3, 17}, STR_THEMES_TAB_SETTINGS_TIP ), // presets tab - MakeTab ({ 34, 17}, STR_TITLE_EDITOR_SAVES_TAB_TIP ), // saves tab - MakeTab ({ 65, 17}, STR_TITLE_EDITOR_SCRIPT_TAB_TIP ), // script tab - MakeWidget({ 89, 48}, { 228, 219}, WindowWidgetType::Scroll, WindowColour::Secondary, SCROLL_BOTH), // command/save list - - // Presets Tab - MakeWidget ({ 125, 60}, { 175, 14}, WindowWidgetType::DropdownMenu, WindowColour::Secondary ), // Preset title sequences - MakeWidget ({ 288, 61}, { 11, 10}, WindowWidgetType::Button, WindowColour::Secondary, STR_DROPDOWN_GLYPH ), - MakeWidget ({ 10, 82}, ACTION_BTN, WindowWidgetType::Button, WindowColour::Secondary, STR_TITLE_EDITOR_ACTION_CREATE, STR_TITLE_EDITOR_ACTION_CREATE_SEQUENCE_TIP ), // Create button - MakeWidget ({ 10, 102}, ACTION_BTN, WindowWidgetType::Button, WindowColour::Secondary, STR_TITLE_EDITOR_ACTION_DUPLICATE, STR_TITLE_EDITOR_ACTION_DUPLICATE_SEQUENCE_TIP), // Duplicate button - MakeWidget ({ 110, 82}, ACTION_BTN, WindowWidgetType::Button, WindowColour::Secondary, STR_TRACK_MANAGE_DELETE, STR_TITLE_EDITOR_ACTION_DELETE_SEQUENCE_TIP ), // Delete button - MakeWidget ({ 210, 82}, ACTION_BTN, WindowWidgetType::Button, WindowColour::Secondary, STR_TRACK_MANAGE_RENAME, STR_TITLE_EDITOR_ACTION_RENAME_SEQUENCE_TIP ), // Rename button - - // Saves Tab - MakeWidget ({ 8, 52}, EDIT_BTN, WindowWidgetType::Button, WindowColour::Secondary, STR_TITLE_EDITOR_ACTION_ADD, STR_TITLE_EDITOR_ACTION_ADD_TIP ), // Add - MakeWidget ({ 8, 70}, EDIT_BTN, WindowWidgetType::Button, WindowColour::Secondary, STR_TITLE_EDITOR_ACTION_REMOVE, STR_TITLE_EDITOR_ACTION_REMOVE_TIP ), // Remove - MakeWidget ({ 8, 88}, EDIT_BTN, WindowWidgetType::Button, WindowColour::Secondary, STR_TRACK_MANAGE_RENAME, STR_TITLE_EDITOR_ACTION_RENAME_TIP ), // Rename - MakeWidget ({ 8, 106}, EDIT_BTN, WindowWidgetType::Button, WindowColour::Secondary, STR_TITLE_EDITOR_ACTION_LOAD, STR_TITLE_EDITOR_ACTION_LOAD_TIP ), // Load - - // Script Tab - MakeWidget ({ 8, 52}, EDIT_BTN, WindowWidgetType::Button, WindowColour::Secondary, STR_TITLE_EDITOR_ACTION_INSERT, STR_TITLE_EDITOR_ACTION_INSERT_TIP ), // Insert - MakeWidget ({ 8, 70}, EDIT_BTN, WindowWidgetType::Button, WindowColour::Secondary, STR_TITLE_EDITOR_ACTION_EDIT, STR_TITLE_EDITOR_ACTION_EDIT_TIP ), // Edit - MakeWidget ({ 8, 88}, EDIT_BTN, WindowWidgetType::Button, WindowColour::Secondary, STR_TRACK_MANAGE_DELETE, STR_TITLE_EDITOR_ACTION_DELETE_TIP ), // Delete - // MakeWidget ({ 8, 106}, EDIT_BTN, WindowWidgetType::DropdownMenu_BUTTON, WindowColour::Secondary, STR_TITLE_EDITOR_ACTION_RELOAD, STR_TITLE_EDITOR_ACTION_RELOAD_TIP ), // Reload - MakeWidget ({ 8, 106}, EDIT_BTN, WindowWidgetType::Button, WindowColour::Secondary, STR_TITLE_EDITOR_ACTION_SKIP_TO, STR_TITLE_EDITOR_ACTION_SKIP_TO_TIP ), // Skip to - - MakeWidget ({ 8, 142}, REORDER_BTN, WindowWidgetType::Button, WindowColour::Secondary, STR_DOWN, STR_TITLE_EDITOR_ACTION_MOVE_DOWN_TIP ), // Move down - MakeWidget ({ 44, 142}, REORDER_BTN, WindowWidgetType::Button, WindowColour::Secondary, STR_UP, STR_TITLE_EDITOR_ACTION_MOVE_UP_TIP ), // Move up - - MakeWidget ({ 8, 238}, PLAYBACK_BTN, WindowWidgetType::ImgBtn, WindowColour::Secondary, SPR_G2_TITLE_RESTART, STR_TITLE_EDITOR_ACTION_REPLAY_TIP ), // Replay - MakeWidget ({ 26, 238}, PLAYBACK_BTN, WindowWidgetType::ImgBtn, WindowColour::Secondary, SPR_G2_TITLE_STOP, STR_TITLE_EDITOR_ACTION_STOP_TIP ), // Stop - MakeWidget ({ 44, 238}, PLAYBACK_BTN, WindowWidgetType::ImgBtn, WindowColour::Secondary, SPR_G2_TITLE_PLAY, STR_TITLE_EDITOR_ACTION_PLAY_TIP ), // Play - MakeWidget ({ 62, 238}, PLAYBACK_BTN, WindowWidgetType::ImgBtn, WindowColour::Secondary, SPR_G2_TITLE_SKIP, STR_TITLE_EDITOR_ACTION_SKIP_TIP ), // Skip - WIDGETS_END, -}; -// clang-format on - -static size_t _selectedTitleSequence = SIZE_MAX; -static bool _isSequenceReadOnly; -static std::unique_ptr _editingTitleSequence; -static const utf8* _sequenceName; - -static u8string _renameSavePath = u8string(); - -static int16_t _window_title_editor_highlighted_index; - -static int32_t window_title_editor_tab_animation_loops[] = { - 64, - 1, - 28, -}; -static int32_t window_title_editor_tab_animation_divisor[] = { - 4, - 1, - 4, -}; -static int32_t window_title_editor_tab_sprites[] = { - SPR_TAB_RIDE_0, - SPR_FLOPPY, - SPR_TAB_STATS_0, -}; - -void WindowTitleEditorOpen(int32_t tab) -{ - rct_window* window; - - // Check if window is already open - window = window_bring_to_front_by_class(WC_TITLE_EDITOR); - if (window != nullptr) - return; - - if (_selectedTitleSequence == SIZE_MAX) - _selectedTitleSequence = title_get_config_sequence(); - - window = WindowCreateAutoPos(WW, WH2, &window_title_editor_events, WC_TITLE_EDITOR, WF_10 | WF_RESIZABLE); - window->widgets = window_title_editor_widgets; - - WindowInitScrollWidgets(window); - window->list_information_type = 0; - - window->selected_tab = tab; - window->selected_list_item = -1; - _window_title_editor_highlighted_index = -1; - window->scrolls[0].v_top = 0; - window->scrolls[0].h_left = 0; - - window->min_width = WW; - window->min_height = WH; - window->max_width = 500; - window->max_height = 450; - - if (_selectedTitleSequence >= title_sequence_manager_get_count()) - _selectedTitleSequence = 0; - - WindowTitleEditorLoadSequence(_selectedTitleSequence); -} - -static void WindowTitleEditorClose(rct_window* w) -{ - title_stop_previewing_sequence(); - - // Close the related windows - window_close_by_class(WC_TITLE_COMMAND_EDITOR); - - _editingTitleSequence = nullptr; - _sequenceName = nullptr; - - _renameSavePath.clear(); -} - -static void WindowTitleEditorMouseup(rct_window* w, rct_widgetindex widgetIndex) -{ - bool commandEditorOpen = (window_find_by_class(WC_TITLE_COMMAND_EDITOR) != nullptr); - switch (widgetIndex) - { - case WIDX_TITLE_EDITOR_CLOSE: - window_close(w); - break; - - ////////////////////////////////////////////////////////////////////////////////////////////////////// - // Presets tab - ////////////////////////////////////////////////////////////////////////////////////////////////////// - case WIDX_TITLE_EDITOR_NEW_BUTTON: - if (!commandEditorOpen) - { - WindowTextInputOpen( - w, widgetIndex, STR_TITLE_EDITOR_ACTION_CREATE, STR_TITLE_EDITOR_ENTER_NAME_FOR_SEQUENCE, {}, STR_NONE, 0, - 64); - } - break; - case WIDX_TITLE_EDITOR_DUPLICATE_BUTTON: - if (!commandEditorOpen && _editingTitleSequence != nullptr) - { - WindowTextInputOpen( - w, widgetIndex, STR_TITLE_EDITOR_ACTION_DUPLICATE, STR_TITLE_EDITOR_ENTER_NAME_FOR_SEQUENCE, {}, STR_STRING, - reinterpret_cast(_sequenceName), 64); - } - break; - case WIDX_TITLE_EDITOR_DELETE_BUTTON: - if (WindowTitleEditorCheckCanEdit()) - { - title_sequence_manager_delete(_selectedTitleSequence); - WindowTitleEditorLoadSequence(0); - } - break; - case WIDX_TITLE_EDITOR_RENAME_BUTTON: - if (WindowTitleEditorCheckCanEdit() && _editingTitleSequence != nullptr) - { - WindowTextInputOpen( - w, widgetIndex, STR_TRACK_MANAGE_RENAME, STR_TITLE_EDITOR_ENTER_NAME_FOR_SEQUENCE, {}, STR_STRING, - reinterpret_cast(_sequenceName), 64); - } - break; - - ////////////////////////////////////////////////////////////////////////////////////////////////////// - // Editor tab - ////////////////////////////////////////////////////////////////////////////////////////////////////// - case WIDX_TITLE_EDITOR_ADD_SAVE: - if (!_isSequenceReadOnly && !title_is_previewing_sequence() && !commandEditorOpen) - { - auto intent = Intent(WC_LOADSAVE); - intent.putExtra(INTENT_EXTRA_LOADSAVE_TYPE, LOADSAVETYPE_LOAD | LOADSAVETYPE_GAME); - intent.putExtra(INTENT_EXTRA_CALLBACK, reinterpret_cast(WindowTitleEditorAddParkCallback)); - context_open_intent(&intent); - } - break; - case WIDX_TITLE_EDITOR_REMOVE_SAVE: - if (WindowTitleEditorCheckCanEdit()) - { - if (w->selected_list_item != -1) - { - TitleSequenceRemovePark(*_editingTitleSequence, w->selected_list_item); - if (w->selected_list_item >= static_cast(_editingTitleSequence->Saves.size())) - { - w->selected_list_item--; - } - } - } - break; - case WIDX_TITLE_EDITOR_RENAME_SAVE: - if (WindowTitleEditorCheckCanEdit()) - { - if (w->selected_list_item != -1) - { - WindowTextInputOpen( - w, widgetIndex, STR_FILEBROWSER_RENAME_SAVE_TITLE, STR_TITLE_EDITOR_ENTER_NAME_FOR_SAVE, {}, STR_STRING, - reinterpret_cast(_editingTitleSequence->Saves[w->selected_list_item].c_str()), 52 - 1); - } - } - break; - case WIDX_TITLE_EDITOR_LOAD_SAVE: - if (w->selected_list_item >= 0 && w->selected_list_item < static_cast(_editingTitleSequence->Saves.size())) - { - auto handle = TitleSequenceGetParkHandle(*_editingTitleSequence, w->selected_list_item); - bool isScenario = ParkImporter::ExtensionIsScenario(handle->HintPath); - try - { - auto& objectMgr = OpenRCT2::GetContext()->GetObjectManager(); - auto parkImporter = ParkImporter::Create(handle->HintPath); - auto result = parkImporter->LoadFromStream(handle->Stream.get(), isScenario); - objectMgr.LoadObjects(result.RequiredObjects); - parkImporter->Import(); - - if (isScenario) - scenario_begin(); - else - game_load_init(); - - WindowTitleEditorOpen(WINDOW_TITLE_EDITOR_TAB_SAVES); - } - catch (const std::exception&) - { - context_show_error(ERROR_TYPE_FILE_LOAD, STR_FILE_CONTAINS_INVALID_DATA, {}); - } - } - break; - - ////////////////////////////////////////////////////////////////////////////////////////////////////// - // Commands tab - ////////////////////////////////////////////////////////////////////////////////////////////////////// - case WIDX_TITLE_EDITOR_INSERT: - if (WindowTitleEditorCheckCanEdit()) - { - if (w->selected_list_item != -1) - WindowTitleCommandEditorOpen(_editingTitleSequence.get(), w->selected_list_item + 1, true); - else - WindowTitleCommandEditorOpen( - _editingTitleSequence.get(), static_cast(_editingTitleSequence->Commands.size()), true); - } - break; - case WIDX_TITLE_EDITOR_EDIT: - if (WindowTitleEditorCheckCanEdit()) - { - if (w->selected_list_item != -1 - && w->selected_list_item < static_cast(_editingTitleSequence->Commands.size())) - { - WindowTitleCommandEditorOpen(_editingTitleSequence.get(), w->selected_list_item, false); - } - } - break; - case WIDX_TITLE_EDITOR_DELETE: - if (WindowTitleEditorCheckCanEdit()) - { - if (w->selected_list_item != -1 - && w->selected_list_item < static_cast(_editingTitleSequence->Commands.size())) - { - _editingTitleSequence->Commands.erase(_editingTitleSequence->Commands.begin() + w->selected_list_item); - if (w->selected_list_item >= static_cast(_editingTitleSequence->Commands.size())) - { - w->selected_list_item--; - } - TitleSequenceSave(*_editingTitleSequence); - } - } - break; - case WIDX_TITLE_EDITOR_SKIP_TO: - { - int32_t position = w->selected_list_item; - if (title_is_previewing_sequence() && position != -1 - && position < static_cast(_editingTitleSequence->Commands.size())) - { - auto player = WindowTitleEditorGetPlayer(); - player->Seek(position); - player->Update(); - } - break; - } - case WIDX_TITLE_EDITOR_MOVE_DOWN: - if (WindowTitleEditorCheckCanEdit()) - { - if (w->selected_list_item != -1 - && w->selected_list_item < static_cast(_editingTitleSequence->Commands.size()) - 1) - { - std::swap( - _editingTitleSequence->Commands[w->selected_list_item], - _editingTitleSequence->Commands[w->selected_list_item + 1]); - w->selected_list_item++; - TitleSequenceSave(*_editingTitleSequence); - } - } - break; - case WIDX_TITLE_EDITOR_MOVE_UP: - if (WindowTitleEditorCheckCanEdit()) - { - if (w->selected_list_item > 0 - && w->selected_list_item < static_cast(_editingTitleSequence->Commands.size())) - { - std::swap( - _editingTitleSequence->Commands[w->selected_list_item - 1], - _editingTitleSequence->Commands[w->selected_list_item]); - w->selected_list_item--; - TitleSequenceSave(*_editingTitleSequence); - } - } - break; - case WIDX_TITLE_EDITOR_REPLAY: - if (title_is_previewing_sequence()) - { - auto player = WindowTitleEditorGetPlayer(); - player->Reset(); - player->Update(); - } - break; - case WIDX_TITLE_EDITOR_STOP: - if (title_is_previewing_sequence()) - { - title_stop_previewing_sequence(); - } - break; - case WIDX_TITLE_EDITOR_PLAY: - if (!title_is_previewing_sequence() || _selectedTitleSequence != title_get_current_sequence()) - { - if (!title_preview_sequence(_selectedTitleSequence)) - { - context_show_error(STR_ERR_FAILED_TO_LOAD_TITLE_SEQUENCE, STR_NONE, {}); - } - else if (!(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)) - { - gPreviewingTitleSequenceInGame = true; - } - } - break; - case WIDX_TITLE_EDITOR_SKIP: - if (title_is_previewing_sequence()) - { - auto player = WindowTitleEditorGetPlayer(); - int32_t position = player->GetCurrentPosition() + 1; - if (position >= static_cast(_editingTitleSequence->Commands.size())) - { - position = 0; - } - player->Seek(position); - player->Update(); - } - break; - } -} - -static void WindowTitleEditorResize(rct_window* w) -{ - if (w->selected_tab == WINDOW_TITLE_EDITOR_TAB_PRESETS) - window_set_resize(w, WW, WH2, 500, WH2); - else - window_set_resize(w, WW, WH, 500, 580); -} - -static void WindowTitleEditorMousedown(rct_window* w, rct_widgetindex widgetIndex, rct_widget* widget) -{ - switch (widgetIndex) - { - case WIDX_TITLE_EDITOR_PRESETS_TAB: - case WIDX_TITLE_EDITOR_SAVES_TAB: - case WIDX_TITLE_EDITOR_SCRIPT_TAB: - { - int32_t newSelectedTab = widgetIndex - WIDX_TITLE_EDITOR_PRESETS_TAB; - if (w->selected_tab != newSelectedTab) - { - w->selected_tab = newSelectedTab; - w->selected_list_item = -1; - _window_title_editor_highlighted_index = -1; - w->scrolls[0].v_top = 0; - w->frame_no = 0; - window_event_resize_call(w); - w->Invalidate(); - } - break; - } - case WIDX_TITLE_EDITOR_PRESETS_DROPDOWN: - if (window_find_by_class(WC_TITLE_COMMAND_EDITOR) != nullptr) - { - context_show_error(STR_TITLE_EDITOR_ERR_CANT_CHANGE_WHILE_EDITOR_IS_OPEN, STR_NONE, {}); - } - else - { - int32_t numItems = static_cast(title_sequence_manager_get_count()); - for (int32_t i = 0; i < numItems; i++) - { - gDropdownItems[i].Format = STR_OPTIONS_DROPDOWN_ITEM; - gDropdownItems[i].Args = reinterpret_cast(title_sequence_manager_get_name(i)); - } - - widget--; - WindowDropdownShowTextCustomWidth( - { w->windowPos.x + widget->left, w->windowPos.y + widget->top }, widget->height() + 1, w->colours[1], 0, - Dropdown::Flag::StayOpen, numItems, widget->width() - 3); - Dropdown::SetChecked(static_cast(_selectedTitleSequence), true); - } - break; - } -} - -static void WindowTitleEditorDropdown(rct_window* w, rct_widgetindex widgetIndex, int32_t dropdownIndex) -{ - if (dropdownIndex == -1) - return; - - if (widgetIndex == WIDX_TITLE_EDITOR_PRESETS_DROPDOWN) - { - WindowTitleEditorLoadSequence(dropdownIndex); - w->Invalidate(); - } -} - -static void WindowTitleEditorUpdate(rct_window* w) -{ - w->frame_no++; - if (w->frame_no >= window_title_editor_tab_animation_loops[w->selected_tab]) - { - w->frame_no = 0; - } - - if (!WidgetIsHighlighted(w, WIDX_TITLE_EDITOR_LIST)) - { - _window_title_editor_highlighted_index = -1; - widget_invalidate(w, WIDX_TITLE_EDITOR_LIST); - } - - widget_invalidate(w, WIDX_TITLE_EDITOR_PRESETS_TAB + w->selected_tab); -} - -static void WindowTitleEditorScrollgetsize(rct_window* w, int32_t scrollIndex, int32_t* width, int32_t* height) -{ - size_t lineCount = 1; - if (w->selected_tab == WINDOW_TITLE_EDITOR_TAB_SAVES) - lineCount = _editingTitleSequence->Saves.size(); - else if (w->selected_tab == WINDOW_TITLE_EDITOR_TAB_SCRIPT) - lineCount = _editingTitleSequence->Commands.size(); - - *height = static_cast(lineCount * SCROLLABLE_ROW_HEIGHT); - int32_t i = *height - window_title_editor_widgets[WIDX_TITLE_EDITOR_LIST].bottom - + window_title_editor_widgets[WIDX_TITLE_EDITOR_LIST].top + 21; - if (i < 0) - { - i = 0; - } - if (i < w->scrolls[0].v_top) - { - w->scrolls[0].v_top = i; - w->Invalidate(); - } - - *width = SCROLL_WIDTH; -} - -static void WindowTitleEditorScrollmousedown(rct_window* w, int32_t scrollIndex, const ScreenCoordsXY& screenCoords) -{ - int32_t index = screenCoords.y / SCROLLABLE_ROW_HEIGHT; - w->selected_list_item = -1; - switch (w->selected_tab) - { - case WINDOW_TITLE_EDITOR_TAB_SAVES: - if (index < static_cast(_editingTitleSequence->Saves.size())) - { - w->selected_list_item = index; - widget_invalidate(w, WIDX_TITLE_EDITOR_LIST); - } - break; - case WINDOW_TITLE_EDITOR_TAB_SCRIPT: - if (index < static_cast(_editingTitleSequence->Commands.size())) - { - w->selected_list_item = index; - widget_invalidate(w, WIDX_TITLE_EDITOR_LIST); - } - break; - } -} - -static void WindowTitleEditorScrollmouseover(rct_window* w, int32_t scrollIndex, const ScreenCoordsXY& screenCoords) -{ - int32_t index = screenCoords.y / SCROLLABLE_ROW_HEIGHT; - switch (w->selected_tab) - { - case WINDOW_TITLE_EDITOR_TAB_SAVES: - if (index < static_cast(_editingTitleSequence->Saves.size())) - _window_title_editor_highlighted_index = static_cast(index); - break; - case WINDOW_TITLE_EDITOR_TAB_SCRIPT: - if (index < static_cast(_editingTitleSequence->Commands.size())) - _window_title_editor_highlighted_index = static_cast(index); - break; - } - widget_invalidate(w, WIDX_TITLE_EDITOR_LIST); -} - -static void WindowTitleEditorTextinput(rct_window* w, rct_widgetindex widgetIndex, char* text) -{ - if (str_is_null_or_empty(text)) - return; - - switch (widgetIndex) - { - case WIDX_TITLE_EDITOR_NEW_BUTTON: - case WIDX_TITLE_EDITOR_DUPLICATE_BUTTON: - case WIDX_TITLE_EDITOR_RENAME_BUTTON: - if (Platform::IsFilenameValid(text)) - { - if (title_sequence_manager_get_index_for_name(text) == SIZE_MAX) - { - if (!title_sequence_manager_is_name_reserved(text)) - { - if (widgetIndex == WIDX_TITLE_EDITOR_NEW_BUTTON) - { - size_t newIndex = title_sequence_manager_create(text); - WindowTitleEditorLoadSequence(newIndex); - } - else if (widgetIndex == WIDX_TITLE_EDITOR_DUPLICATE_BUTTON) - { - size_t newIndex = title_sequence_manager_duplicate(_selectedTitleSequence, text); - WindowTitleEditorLoadSequence(newIndex); - } - else - { - size_t newIndex = title_sequence_manager_rename(_selectedTitleSequence, text); - WindowTitleEditorLoadSequence(newIndex); - } - config_save_default(); - w->Invalidate(); - } - else - { - context_show_error(STR_ERROR_RESERVED_NAME, STR_NONE, {}); - } - } - else - { - context_show_error(STR_ERROR_EXISTING_NAME, STR_NONE, {}); - } - } - else - { - context_show_error(STR_ERROR_INVALID_CHARACTERS, STR_NONE, {}); - } - break; - case WIDX_TITLE_EDITOR_RENAME_SAVE: - WindowTitleEditorRenamePark(w->selected_list_item, text); - break; - } -} - -static void WindowTitleEditorInvalidate(rct_window* w) -{ - int32_t pressed_widgets = w->pressed_widgets - & ~((1LL << WIDX_TITLE_EDITOR_PRESETS_TAB) | (1LL << WIDX_TITLE_EDITOR_SAVES_TAB) - | (1LL << WIDX_TITLE_EDITOR_SCRIPT_TAB)); - rct_widgetindex widgetIndex = w->selected_tab + WIDX_TITLE_EDITOR_PRESETS_TAB; - - w->pressed_widgets = pressed_widgets | (1 << widgetIndex); - - window_title_editor_widgets[WIDX_TITLE_EDITOR_LIST].type = WindowWidgetType::Empty; - - window_title_editor_widgets[WIDX_TITLE_EDITOR_PRESETS].type = WindowWidgetType::Empty; - window_title_editor_widgets[WIDX_TITLE_EDITOR_PRESETS_DROPDOWN].type = WindowWidgetType::Empty; - window_title_editor_widgets[WIDX_TITLE_EDITOR_NEW_BUTTON].type = WindowWidgetType::Empty; - window_title_editor_widgets[WIDX_TITLE_EDITOR_DUPLICATE_BUTTON].type = WindowWidgetType::Empty; - window_title_editor_widgets[WIDX_TITLE_EDITOR_DELETE_BUTTON].type = WindowWidgetType::Empty; - window_title_editor_widgets[WIDX_TITLE_EDITOR_RENAME_BUTTON].type = WindowWidgetType::Empty; - - window_title_editor_widgets[WIDX_TITLE_EDITOR_ADD_SAVE].type = WindowWidgetType::Empty; - window_title_editor_widgets[WIDX_TITLE_EDITOR_REMOVE_SAVE].type = WindowWidgetType::Empty; - window_title_editor_widgets[WIDX_TITLE_EDITOR_RENAME_SAVE].type = WindowWidgetType::Empty; - window_title_editor_widgets[WIDX_TITLE_EDITOR_LOAD_SAVE].type = WindowWidgetType::Empty; - - window_title_editor_widgets[WIDX_TITLE_EDITOR_INSERT].type = WindowWidgetType::Empty; - window_title_editor_widgets[WIDX_TITLE_EDITOR_EDIT].type = WindowWidgetType::Empty; - window_title_editor_widgets[WIDX_TITLE_EDITOR_DELETE].type = WindowWidgetType::Empty; - // window_title_editor_widgets[WIDX_TITLE_EDITOR_RELOAD].type = WindowWidgetType::Empty; - window_title_editor_widgets[WIDX_TITLE_EDITOR_SKIP_TO].type = WindowWidgetType::Empty; - window_title_editor_widgets[WIDX_TITLE_EDITOR_MOVE_UP].type = WindowWidgetType::Empty; - window_title_editor_widgets[WIDX_TITLE_EDITOR_MOVE_DOWN].type = WindowWidgetType::Empty; - window_title_editor_widgets[WIDX_TITLE_EDITOR_PLAY].type = WindowWidgetType::Empty; - window_title_editor_widgets[WIDX_TITLE_EDITOR_STOP].type = WindowWidgetType::Empty; - window_title_editor_widgets[WIDX_TITLE_EDITOR_REPLAY].type = WindowWidgetType::Empty; - window_title_editor_widgets[WIDX_TITLE_EDITOR_SKIP].type = WindowWidgetType::Empty; - - switch (w->selected_tab) - { - case WINDOW_TITLE_EDITOR_TAB_PRESETS: - window_title_editor_widgets[WIDX_TITLE_EDITOR_PRESETS].type = WindowWidgetType::DropdownMenu; - window_title_editor_widgets[WIDX_TITLE_EDITOR_PRESETS_DROPDOWN].type = WindowWidgetType::Button; - window_title_editor_widgets[WIDX_TITLE_EDITOR_NEW_BUTTON].type = WindowWidgetType::Button; - window_title_editor_widgets[WIDX_TITLE_EDITOR_DUPLICATE_BUTTON].type = WindowWidgetType::Button; - window_title_editor_widgets[WIDX_TITLE_EDITOR_DELETE_BUTTON].type = WindowWidgetType::Button; - window_title_editor_widgets[WIDX_TITLE_EDITOR_RENAME_BUTTON].type = WindowWidgetType::Button; - break; - case WINDOW_TITLE_EDITOR_TAB_SAVES: - window_title_editor_widgets[WIDX_TITLE_EDITOR_LIST].type = WindowWidgetType::Scroll; - window_title_editor_widgets[WIDX_TITLE_EDITOR_ADD_SAVE].type = WindowWidgetType::Button; - window_title_editor_widgets[WIDX_TITLE_EDITOR_REMOVE_SAVE].type = WindowWidgetType::Button; - window_title_editor_widgets[WIDX_TITLE_EDITOR_RENAME_SAVE].type = WindowWidgetType::Button; - window_title_editor_widgets[WIDX_TITLE_EDITOR_LOAD_SAVE].type = WindowWidgetType::Button; - window_title_editor_widgets[WIDX_TITLE_EDITOR_PLAY].type = WindowWidgetType::ImgBtn; - window_title_editor_widgets[WIDX_TITLE_EDITOR_STOP].type = WindowWidgetType::ImgBtn; - window_title_editor_widgets[WIDX_TITLE_EDITOR_REPLAY].type = WindowWidgetType::ImgBtn; - window_title_editor_widgets[WIDX_TITLE_EDITOR_SKIP].type = WindowWidgetType::ImgBtn; - break; - case WINDOW_TITLE_EDITOR_TAB_SCRIPT: - window_title_editor_widgets[WIDX_TITLE_EDITOR_LIST].type = WindowWidgetType::Scroll; - window_title_editor_widgets[WIDX_TITLE_EDITOR_INSERT].type = WindowWidgetType::Button; - window_title_editor_widgets[WIDX_TITLE_EDITOR_EDIT].type = WindowWidgetType::Button; - window_title_editor_widgets[WIDX_TITLE_EDITOR_DELETE].type = WindowWidgetType::Button; - // window_title_editor_widgets[WIDX_TITLE_EDITOR_RELOAD].type = WindowWidgetType::DropdownMenu_BUTTON; - window_title_editor_widgets[WIDX_TITLE_EDITOR_SKIP_TO].type = WindowWidgetType::Button; - window_title_editor_widgets[WIDX_TITLE_EDITOR_MOVE_UP].type = WindowWidgetType::Button; - window_title_editor_widgets[WIDX_TITLE_EDITOR_MOVE_DOWN].type = WindowWidgetType::Button; - window_title_editor_widgets[WIDX_TITLE_EDITOR_PLAY].type = WindowWidgetType::ImgBtn; - window_title_editor_widgets[WIDX_TITLE_EDITOR_STOP].type = WindowWidgetType::ImgBtn; - window_title_editor_widgets[WIDX_TITLE_EDITOR_REPLAY].type = WindowWidgetType::ImgBtn; - window_title_editor_widgets[WIDX_TITLE_EDITOR_SKIP].type = WindowWidgetType::ImgBtn; - break; - } - - window_title_editor_widgets[WIDX_TITLE_EDITOR_BACKGROUND].right = w->width - 1; - window_title_editor_widgets[WIDX_TITLE_EDITOR_BACKGROUND].bottom = w->height - 1; - window_title_editor_widgets[WIDX_TITLE_EDITOR_TAB_CONTENT_PANEL].right = w->width - 1; - window_title_editor_widgets[WIDX_TITLE_EDITOR_TAB_CONTENT_PANEL].bottom = w->height - 1; - window_title_editor_widgets[WIDX_TITLE_EDITOR_TITLE].right = w->width - 2; - window_title_editor_widgets[WIDX_TITLE_EDITOR_CLOSE].left = w->width - 2 - 0x0B; - window_title_editor_widgets[WIDX_TITLE_EDITOR_CLOSE].right = w->width - 2 - 0x0B + 0x0A; - window_title_editor_widgets[WIDX_TITLE_EDITOR_LIST].right = w->width - 4; - window_title_editor_widgets[WIDX_TITLE_EDITOR_LIST].bottom = w->height - 16; - - window_title_editor_widgets[WIDX_TITLE_EDITOR_REPLAY].top = w->height - 32; - window_title_editor_widgets[WIDX_TITLE_EDITOR_REPLAY].bottom = w->height - 16; - window_title_editor_widgets[WIDX_TITLE_EDITOR_STOP].top = w->height - 32; - window_title_editor_widgets[WIDX_TITLE_EDITOR_STOP].bottom = w->height - 16; - window_title_editor_widgets[WIDX_TITLE_EDITOR_PLAY].top = w->height - 32; - window_title_editor_widgets[WIDX_TITLE_EDITOR_PLAY].bottom = w->height - 16; - window_title_editor_widgets[WIDX_TITLE_EDITOR_SKIP].top = w->height - 32; - window_title_editor_widgets[WIDX_TITLE_EDITOR_SKIP].bottom = w->height - 16; - - if (!(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) && gScreenFlags != SCREEN_FLAGS_PLAYING) - w->disabled_widgets |= (1ULL << WIDX_TITLE_EDITOR_PLAY); - else - w->disabled_widgets &= ~(1ULL << WIDX_TITLE_EDITOR_PLAY); - if (!title_is_previewing_sequence()) - w->disabled_widgets |= (1ULL << WIDX_TITLE_EDITOR_REPLAY) | (1ULL << WIDX_TITLE_EDITOR_STOP) - | (1ULL << WIDX_TITLE_EDITOR_SKIP) | (1ULL << WIDX_TITLE_EDITOR_SKIP_TO); - else - w->disabled_widgets &= ~( - (1ULL << WIDX_TITLE_EDITOR_REPLAY) | (1ULL << WIDX_TITLE_EDITOR_STOP) | (1ULL << WIDX_TITLE_EDITOR_SKIP) - | (1ULL << WIDX_TITLE_EDITOR_SKIP_TO)); -} - -static void WindowTitleEditorPaint(rct_window* w, rct_drawpixelinfo* dpi) -{ - // Widgets - WindowDrawWidgets(w, dpi); - WindowTitleEditorDrawTabImages(dpi, w); - - // Draw strings - switch (w->selected_tab) - { - case WINDOW_TITLE_EDITOR_TAB_PRESETS: - { - DrawTextBasic( - dpi, w->windowPos + ScreenCoordsXY{ 10, window_title_editor_widgets[WIDX_TITLE_EDITOR_PRESETS].top + 1 }, - STR_TITLE_SEQUENCE, {}, { w->colours[1] }); - - auto ft = Formatter(); - ft.Add(_sequenceName); - - ScreenCoordsXY screenPos = { w->windowPos.x + window_title_editor_widgets[WIDX_TITLE_EDITOR_PRESETS].left + 1, - w->windowPos.y + window_title_editor_widgets[WIDX_TITLE_EDITOR_PRESETS].top }; - auto width = w->windowPos.x + window_title_editor_widgets[WIDX_TITLE_EDITOR_PRESETS_DROPDOWN].left - - window_title_editor_widgets[WIDX_TITLE_EDITOR_PRESETS].left - 4; - - DrawTextEllipsised(dpi, screenPos, width, STR_STRING, ft, { w->colours[1] }); - break; - } - case WINDOW_TITLE_EDITOR_TAB_SAVES: - break; - case WINDOW_TITLE_EDITOR_TAB_SCRIPT: - break; - } -} - -static void WindowTitleEditorScrollpaint(rct_window* w, rct_drawpixelinfo* dpi, int32_t scrollIndex) -{ - gfx_fill_rect( - dpi, { { dpi->x, dpi->y }, { dpi->x + dpi->width - 1, dpi->y + dpi->height - 1 } }, - ColourMapA[w->colours[1]].mid_light); - switch (w->selected_tab) - { - case WINDOW_TITLE_EDITOR_TAB_SAVES: - WindowTitleEditorScrollpaintSaves(w, dpi); - break; - case WINDOW_TITLE_EDITOR_TAB_SCRIPT: - WindowTitleEditorScrollpaintCommands(w, dpi); - break; - } -} - -static void WindowTitleEditorScrollpaintSaves(rct_window* w, rct_drawpixelinfo* dpi) -{ - int32_t currentSaveIndex = -1; - auto screenCoords = ScreenCoordsXY{ 0, 0 }; - if (_editingTitleSequence == nullptr) - return; - - for (int32_t i = 0; i < static_cast(_editingTitleSequence->Saves.size()); - i++, screenCoords.y += SCROLLABLE_ROW_HEIGHT) - { - bool selected = false; - bool hover = false; - auto fillRect = ScreenRect{ screenCoords, - screenCoords + ScreenCoordsXY{ SCROLL_WIDTH + 100, SCROLLABLE_ROW_HEIGHT - 1 } }; - if (i == w->selected_list_item) - { - selected = true; - gfx_fill_rect(dpi, fillRect, ColourMapA[w->colours[1]].dark); - } - else if (i == _window_title_editor_highlighted_index || i == currentSaveIndex) - { - hover = true; - gfx_fill_rect(dpi, fillRect, ColourMapA[w->colours[1]].mid_dark); - } - else if (i & 1) - { - gfx_fill_rect(dpi, fillRect, ColourMapA[w->colours[1]].lighter | 0x1000000); - } - - auto saveName = _editingTitleSequence->Saves[i].c_str(); - auto ft = Formatter(); - if (selected || hover) - { - ft.Add(STR_STRING); - } - else - { - ft.Add(STR_BLACK_STRING); - ft.Add(STR_STRING); - } - ft.Add(saveName); - DrawTextBasic(dpi, screenCoords + ScreenCoordsXY{ 5, 0 }, STR_STRINGID, ft, { w->colours[1] }); - } -} - -static void WindowTitleEditorScrollpaintCommands(rct_window* w, rct_drawpixelinfo* dpi) -{ - int32_t position = -1; - if (title_is_previewing_sequence() && _selectedTitleSequence == title_get_current_sequence()) - { - auto player = WindowTitleEditorGetPlayer(); - position = player->GetCurrentPosition(); - } - - auto screenCoords = ScreenCoordsXY{ 0, 0 }; - for (int32_t i = 0; i < static_cast(_editingTitleSequence->Commands.size()); - i++, screenCoords.y += SCROLLABLE_ROW_HEIGHT) - { - TitleCommand& command = _editingTitleSequence->Commands[i]; - bool selected = false; - bool hover = false; - bool error = false; - - auto fillRect = ScreenRect{ screenCoords, - screenCoords + ScreenCoordsXY{ SCROLL_WIDTH + 100, SCROLLABLE_ROW_HEIGHT - 1 } }; - if (i == w->selected_list_item) - { - selected = true; - gfx_fill_rect(dpi, fillRect, ColourMapA[w->colours[1]].dark); - } - else if (i == static_cast(_window_title_editor_highlighted_index) || i == position) - { - hover = true; - gfx_fill_rect(dpi, fillRect, ColourMapA[w->colours[1]].mid_dark); - } - else if (i & 1) - { - gfx_fill_rect(dpi, fillRect, ColourMapA[w->colours[1]].lighter | 0x1000000); - } - - if (command.Type == TitleScript::Load && command.SaveIndex == SAVE_INDEX_INVALID) - error = true; - - auto ft = Formatter(); - if (error) - { - ft.Add(selected || hover ? STR_LIGHTPINK_STRINGID : STR_RED_STRINGID); - } - else - { - ft.Add(selected || hover ? STR_STRINGID : STR_BLACK_STRING); - } - - switch (command.Type) - { - case TitleScript::Load: - { - auto commandName = STR_TITLE_EDITOR_COMMAND_LOAD_FILE; - if (command.SaveIndex == SAVE_INDEX_INVALID) - { - commandName = STR_TITLE_EDITOR_COMMAND_LOAD_NO_SAVE; - ft.Add(commandName); - } - else - { - ft.Add(commandName); - ft.Add(_editingTitleSequence->Saves[command.SaveIndex].c_str()); - } - break; - } - case TitleScript::Location: - { - auto commandName = STR_TITLE_EDITOR_COMMAND_LOCATION; - ft.Add(commandName); - ft.Add(command.Location.X); - ft.Add(command.Location.Y); - break; - } - case TitleScript::Rotate: - { - auto commandName = STR_TITLE_EDITOR_COMMAND_ROTATE; - ft.Add(commandName); - ft.Add(command.Rotations); - break; - } - case TitleScript::Zoom: - { - auto commandName = STR_TITLE_EDITOR_COMMAND_ZOOM; - ft.Add(commandName); - ft.Add(command.Zoom); - break; - } - case TitleScript::Speed: - { - auto commandName = STR_TITLE_EDITOR_COMMAND_SPEED; - ft.Add(commandName); - ft.Add(SpeedNames[command.Speed - 1]); - break; - } - case TitleScript::Follow: - { - auto commandName = STR_TITLE_EDITOR_COMMAND_FOLLOW; - if (command.Follow.SpriteIndex.IsNull()) - { - commandName = STR_TITLE_EDITOR_COMMAND_FOLLOW_NO_SPRITE; - ft.Add(commandName); - } - else - { - ft.Add(commandName); - ft.Add(command.Follow.SpriteName); - } - break; - } - case TitleScript::Wait: - { - auto commandName = STR_TITLE_EDITOR_COMMAND_WAIT; - ft.Add(commandName); - ft.Add(command.Milliseconds); - break; - } - case TitleScript::Restart: - { - auto commandName = STR_TITLE_EDITOR_RESTART; - ft.Add(commandName); - break; - } - case TitleScript::End: - { - auto commandName = STR_TITLE_EDITOR_END; - ft.Add(commandName); - break; - } - case TitleScript::LoadSc: - { - auto commandName = STR_TITLE_EDITOR_COMMAND_LOAD_FILE; - const char* name = ""; - auto scenario = GetScenarioRepository()->GetByInternalName(command.Scenario); - if (command.Scenario[0] == '\0') - { - commandName = STR_TITLE_EDITOR_COMMAND_LOAD_NO_SCENARIO; - } - else if (scenario != nullptr) - { - name = scenario->name; - } - else - { - commandName = STR_TITLE_EDITOR_COMMAND_LOAD_MISSING_SCENARIO; - } - ft.Add(commandName); - ft.Add(name); - break; - } - default: - { - ft.Add(STR_NONE); - log_warning("Unknown command %d", command.Type); - } - } - DrawTextBasic(dpi, screenCoords + ScreenCoordsXY{ 5, 0 }, STR_STRINGID, ft, { w->colours[1] }); - } -} - -static void WindowTitleEditorDrawTabImages(rct_drawpixelinfo* dpi, rct_window* w) -{ - for (int32_t i = 0; i < WINDOW_TITLE_EDITOR_TAB_COUNT; i++) - { - auto screenCoords = ScreenCoordsXY{ 0, 0 }; - int32_t spriteId = window_title_editor_tab_sprites[i]; - if (w->selected_tab == i) - { - spriteId += w->frame_no / window_title_editor_tab_animation_divisor[w->selected_tab]; - } - if (i == 1) - { - screenCoords = ScreenCoordsXY{ 4, 1 }; - } - gfx_draw_sprite( - dpi, ImageId(spriteId), - w->windowPos + screenCoords - + ScreenCoordsXY{ w->widgets[WIDX_TITLE_EDITOR_PRESETS_TAB + i].left, - w->widgets[WIDX_TITLE_EDITOR_PRESETS_TAB + i].top }); - } -} - -static void WindowTitleEditorLoadSequence(size_t index) -{ - if (index >= title_sequence_manager_get_count()) - return; - - const char* path = title_sequence_manager_get_path(index); - auto titleSequence = LoadTitleSequence(path); - if (titleSequence == nullptr) - { - context_show_error(STR_FAILED_TO_LOAD_FILE_CONTAINS_INVALID_DATA, STR_NONE, {}); - return; - } - - _selectedTitleSequence = index; - size_t predefinedIndex = title_sequence_manager_get_predefined_index(index); - _isSequenceReadOnly = (predefinedIndex != SIZE_MAX); - _sequenceName = title_sequence_manager_get_name(index); - _editingTitleSequence = std::move(titleSequence); - - window_close_by_class(WC_TITLE_COMMAND_EDITOR); -} - -static ITitleSequencePlayer* WindowTitleEditorGetPlayer() -{ - return static_cast(title_get_sequence_player()); -} - -static bool WindowTitleEditorCheckCanEdit() -{ - bool commandEditorOpen = (window_find_by_class(WC_TITLE_COMMAND_EDITOR) != nullptr); - - if (_isSequenceReadOnly) - context_show_error(STR_ERROR_CANT_CHANGE_TITLE_SEQUENCE, STR_NONE, {}); - else if (title_is_previewing_sequence()) - context_show_error(STR_TITLE_EDITOR_ERR_CANT_EDIT_WHILE_PLAYING, STR_TITLE_EDITOR_PRESS_STOP_TO_CONTINUE_EDITING, {}); - else if (commandEditorOpen) - context_show_error(STR_TITLE_EDITOR_ERR_CANT_CHANGE_WHILE_EDITOR_IS_OPEN, STR_NONE, {}); - else - return true; - - return false; -} - -static bool SaveFilenameExists(const utf8* filename) -{ - auto& seq = _editingTitleSequence; - for (size_t i = 0; i < seq->Saves.size(); i++) - { - const auto& savePath = seq->Saves[i]; - - if (_stricmp(savePath.c_str(), filename) == 0) - return true; - } - return false; -} - -static void WindowTitleEditorAddParkCallback(int32_t result, const utf8* path) -{ - auto extension = get_file_extension_type(path); - if (extension != FileExtension::SV4 && extension != FileExtension::SV6 && extension != FileExtension::PARK) - return; - - const auto filename = Path::GetFileName(path); - if (SaveFilenameExists(filename.c_str())) - { - _renameSavePath = filename; - rct_window* w = window_find_by_class(WC_TITLE_EDITOR); - WindowTextInputOpen( - w, WIDX_TITLE_EDITOR_RENAME_SAVE, STR_FILEBROWSER_RENAME_SAVE_TITLE, STR_ERROR_EXISTING_NAME, {}, STR_STRING, - reinterpret_cast(_renameSavePath.c_str()), 52 - 1); - return; - } - - TitleSequenceAddPark(*_editingTitleSequence, path, filename.c_str()); -} - -static void WindowTitleEditorRenamePark(size_t index, const utf8* name) -{ - if (!Platform::IsFilenameValid(name)) - { - context_show_error(STR_ERROR_INVALID_CHARACTERS, STR_NONE, {}); - return; - } - - for (size_t i = 0; i < _editingTitleSequence->Saves.size(); i++) - { - if (i != index) - { - const auto& savePath = _editingTitleSequence->Saves[i]; - if (_strcmpi(savePath.c_str(), name) == 0) - { - context_show_error(STR_ERROR_EXISTING_NAME, STR_NONE, {}); - return; - } - } - } - - if (TitleSequenceRenamePark(*_editingTitleSequence, index, name)) - { - TitleSequenceSave(*_editingTitleSequence); - } -} diff --git a/src/openrct2-ui/windows/Window.h b/src/openrct2-ui/windows/Window.h index b1509a0fe4..43bce5976d 100644 --- a/src/openrct2-ui/windows/Window.h +++ b/src/openrct2-ui/windows/Window.h @@ -99,8 +99,6 @@ void WindowGuestListRefreshList(); rct_window* WindowGuestListOpen(); rct_window* WindowGuestListOpenWithFilter(GuestListFilterType type, int32_t index); rct_window* WindowStaffFirePromptOpen(Peep* peep); -void WindowTitleEditorOpen(int32_t tab); -void WindowTitleCommandEditorOpen(struct TitleSequence* sequence, int32_t command, bool insert); rct_window* WindowScenarioselectOpen(scenarioselect_callback callback, bool titleEditor); rct_window* WindowScenarioselectOpen(std::function callback, bool titleEditor, bool disableLocking); diff --git a/src/openrct2/interface/InteractiveConsole.cpp b/src/openrct2/interface/InteractiveConsole.cpp index 41b8814113..ec29676464 100644 --- a/src/openrct2/interface/InteractiveConsole.cpp +++ b/src/openrct2/interface/InteractiveConsole.cpp @@ -1343,10 +1343,6 @@ static int32_t cc_open(InteractiveConsole& console, const arguments_t& argv) { context_open_window(WC_THEMES); } - else if (argv[0] == "title_sequences") - { - context_open_window(WC_TITLE_EDITOR); - } else if (invalidTitle) { console.WriteLineError("Cannot open this window in the title screen."); diff --git a/src/openrct2/interface/Window.h b/src/openrct2/interface/Window.h index 17a355b77d..6ec65ce72f 100644 --- a/src/openrct2/interface/Window.h +++ b/src/openrct2/interface/Window.h @@ -451,8 +451,6 @@ enum WC_THEMES = 119, WC_TILE_INSPECTOR = 120, WC_CHANGELOG = 121, - WC_TITLE_EDITOR = 122, - WC_TITLE_COMMAND_EDITOR = 123, WC_MULTIPLAYER = 124, WC_PLAYER = 125, WC_NETWORK_STATUS = 126, diff --git a/src/openrct2/localisation/StringIds.h b/src/openrct2/localisation/StringIds.h index a7254c3466..c1bafca155 100644 --- a/src/openrct2/localisation/StringIds.h +++ b/src/openrct2/localisation/StringIds.h @@ -2667,7 +2667,7 @@ enum : uint16_t STR_THEMES_HEADER_WINDOW = 5236, STR_THEMES_HEADER_PALETTE = 5237, STR_THEMES_LABEL_CURRENT_THEME = 5238, - STR_TITLE_EDITOR_ACTION_DUPLICATE = 5239, + STR_THEMES_ACTION_DUPLICATE = 5239, STR_THEMES_PROMPT_ENTER_THEME_NAME = 5240, STR_THEMES_ERR_CANT_CHANGE_THIS_THEME = 5241, STR_THEMES_ERR_NAME_ALREADY_EXISTS = 5242, @@ -2682,8 +2682,6 @@ enum : uint16_t STR_THEMES_WINDOW_TITLE_MENU_OPTIONS = 5251, STR_THEMES_WINDOW_TITLE_MENU_SCENARIO_SELECTION = 5252, STR_THEMES_WINDOW_PARK_INFORMATION = 5253, - STR_TITLE_EDITOR_ACTION_CREATE = 5254, - STR_TITLE_EDITOR_ACTION_CREATE_SEQUENCE_TIP = 5255, STR_THEMES_DESC_CANT_CHANGE_THIS_THEME = 5256, STR_THEMES_ACTION_DUPLICATE_TIP = 5257, STR_THEMES_ACTION_DELETE_TIP = 5258, @@ -2779,75 +2777,10 @@ enum : uint16_t STR_DATE = 5374, STR_UP = 5375, STR_DOWN = 5376, - STR_TITLE_EDITOR_SAVES_TAB_TIP = 5377, - STR_TITLE_EDITOR_SCRIPT_TAB_TIP = 5378, - STR_TITLE_EDITOR_ACTION_SKIP_TIP = 5379, - STR_TITLE_EDITOR_ACTION_PLAY_TIP = 5380, - STR_TITLE_EDITOR_ACTION_STOP_TIP = 5381, - STR_TITLE_EDITOR_ACTION_REPLAY_TIP = 5382, - STR_TITLE_EDITOR_ACTION_DUPLICATE_SEQUENCE_TIP = 5383, - STR_TITLE_EDITOR_ACTION_DELETE_SEQUENCE_TIP = 5384, - STR_TITLE_EDITOR_ACTION_RENAME_SEQUENCE_TIP = 5385, - STR_TITLE_EDITOR_ACTION_INSERT_TIP = 5386, - STR_TITLE_EDITOR_ACTION_EDIT_TIP = 5387, - STR_TITLE_EDITOR_ACTION_DELETE_TIP = 5388, - STR_TITLE_EDITOR_ACTION_SKIP_TO_TIP = 5389, - STR_TITLE_EDITOR_ACTION_MOVE_DOWN_TIP = 5390, - STR_TITLE_EDITOR_ACTION_MOVE_UP_TIP = 5391, - STR_TITLE_EDITOR_ACTION_ADD_TIP = 5392, - STR_TITLE_EDITOR_ACTION_REMOVE_TIP = 5393, - STR_TITLE_EDITOR_ACTION_RENAME_TIP = 5394, - STR_TITLE_EDITOR_ACTION_LOAD_TIP = 5395, - STR_TITLE_EDITOR_ACTION_RELOAD_TIP = 5396, - - STR_TITLE_EDITOR_ERR_CANT_EDIT_WHILE_PLAYING = 5398, - STR_TITLE_EDITOR_PRESS_STOP_TO_CONTINUE_EDITING = 5399, - STR_ERROR_CANT_CHANGE_TITLE_SEQUENCE = 5400, - // STR_5401 :Create a new title sequence to make changes to - STR_ERR_FAILED_TO_LOAD_TITLE_SEQUENCE = 5402, - // STR_5403 :There may be no Load or Wait command or a save may be invalid STR_ERROR_EXISTING_NAME = 5404, - STR_TITLE_EDITOR_ENTER_NAME_FOR_SAVE = 5405, - STR_TITLE_EDITOR_ENTER_NAME_FOR_SEQUENCE = 5406, - STR_TITLE_EDITOR_ACTION_ADD = 5407, - STR_TITLE_EDITOR_ACTION_REMOVE = 5408, - STR_TITLE_EDITOR_ACTION_INSERT = 5409, - STR_TITLE_EDITOR_ACTION_EDIT = 5410, - STR_TITLE_EDITOR_ACTION_RELOAD = 5411, // unused (commented out) - STR_TITLE_EDITOR_ACTION_SKIP_TO = 5412, - STR_TITLE_EDITOR_ACTION_LOAD = 5413, - STR_TITLE_EDITOR_COMMAND_LOAD_FILE = 5415, - STR_TITLE_EDITOR_COMMAND_LOAD_NO_SAVE = 5416, - STR_TITLE_EDITOR_COMMAND_TYPE_LOCATION = 5417, - STR_TITLE_EDITOR_COMMAND_LOCATION = 5418, - STR_TITLE_EDITOR_COMMAND_TYPE_ROTATE = 5419, - STR_TITLE_EDITOR_COMMAND_ROTATE = 5420, - STR_TITLE_EDITOR_COMMAND_TYPE_ZOOM = 5421, - STR_TITLE_EDITOR_COMMAND_ZOOM = 5422, - STR_TITLE_EDITOR_COMMAND_TYPE_WAIT = 5423, - STR_TITLE_EDITOR_COMMAND_WAIT = 5424, - STR_TITLE_EDITOR_RESTART = 5425, - STR_TITLE_EDITOR_END = 5426, - STR_TITLE_EDITOR_ARGUMENT_COORDINATES = 5427, - STR_TITLE_EDITOR_ARGUMENT_ROTATIONS = 5428, - STR_TITLE_EDITOR_ARGUMENT_ZOOM_LEVEL = 5429, - STR_TITLE_EDITOR_ARGUMENT_WAIT_SECONDS = 5430, - STR_TITLE_EDITOR_ARGUMENT_SAVEFILE = 5431, - STR_TITLE_COMMAND_EDITOR_COMMAND_LABEL = 5432, - STR_TITLE_EDITOR_TITLE = 5433, - STR_TITLE_COMMAND_EDITOR_TITLE = 5434, - STR_FILEBROWSER_RENAME_SAVE_TITLE = 5435, - STR_EDIT_TITLE_SEQUENCES_BUTTON = 5436, - STR_TITLE_COMMAND_EDITOR_NO_SAVE_SELECTED = 5437, - STR_TITLE_EDITOR_ERR_CANT_CHANGE_WHILE_EDITOR_IS_OPEN = 5438, - STR_TITLE_EDITOR_ERR_RESTART_REQUIRES_WAIT = 5439, STR_MINIMISE_FULLSCREEN_ON_FOCUS_LOSS = 5440, STR_FORCE_PARK_RATING = 5442, - STR_TITLE_EDITOR_COMMAND_SPEED = 5443, - STR_TITLE_EDITOR_ARGUMENT_SPEED = 5444, - STR_TITLE_EDITOR_COMMAND_TYPE_SPEED = 5445, - STR_TITLE_COMMAND_EDITOR_ACTION_GET_LOCATION = 5446, STR_OBJECTS_SORT_TYPE = 5447, STR_OBJECTS_SORT_RIDE = 5448, STR_SHORTCUT_REDUCE_GAME_SPEED = 5449, @@ -3201,7 +3134,6 @@ enum : uint16_t STR_ENABLE_DEBUGGING_TOOLS_TIP = 5845, STR_AUTOSAVE_FREQUENCY_TIP = 5846, STR_TITLE_SEQUENCE_TIP = 5847, - STR_EDIT_TITLE_SEQUENCES_BUTTON_TIP = 5848, STR_AUTO_STAFF_PLACEMENT_TIP = 5849, STR_HANDYMEN_MOW_BY_DEFAULT_TIP = 5850, STR_DEFAULT_INSPECTION_INTERVAL_TIP = 5851, @@ -3559,24 +3491,8 @@ enum : uint16_t STR_GUESTS_FILTER_BY_NAME_TIP = 6172, STR_GUESTS_ENTER_NAME_TO_SEARCH = 6173, - STR_TITLE_EDITOR_ACTION_LOAD_SAVE = 6174, - STR_TITLE_EDITOR_ACTION_LOAD_SCENARIO = 6175, - STR_TITLE_EDITOR_ARGUMENT_SCENARIO = 6176, - STR_TITLE_EDITOR_COMMAND_LOAD_NO_SCENARIO = 6177, - STR_TITLE_EDITOR_COMMAND_LOAD_MISSING_SCENARIO = 6178, - STR_TITLE_COMMAND_EDITOR_ACTION_SELECT_SCENARIO = 6179, - STR_TITLE_COMMAND_EDITOR_NO_SCENARIO_SELECTED = 6180, - STR_TITLE_COMMAND_EDITOR_MISSING_SCENARIO = 6181, - - STR_TITLE_EDITOR_COMMAND_FOLLOW = 6182, - STR_TITLE_EDITOR_COMMAND_FOLLOW_NO_SPRITE = 6183, - STR_TITLE_EDITOR_COMMAND_TYPE_FOLLOW = 6184, - STR_TITLE_COMMAND_EDITOR_SELECT_SPRITE = 6185, - STR_TITLE_COMMAND_EDITOR_FOLLOW_NO_SPRITE = 6186, - STR_TITLE_COMMAND_EDITOR_FORMAT_SPRITE_NAME = 6187, STR_LITTER_VOMIT = 6188, STR_DUCK = 6189, - STR_TITLE_COMMAND_EDITOR_SELECT_SPRITE_TOOLTIP = 6190, STR_TILE_INSPECTOR_SURFACE = 6191, STR_TILE_INSPECTOR_WALL = 6192, From e9799aa243b1f185db1e8e4f3dc0cd1af470fb99 Mon Sep 17 00:00:00 2001 From: Ted John Date: Tue, 5 Apr 2022 22:01:58 +0100 Subject: [PATCH 2/3] Update changelog --- distribution/changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index f39891d6e1..48bdaeb6ef 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -1,6 +1,7 @@ 0.4.1 (in development) ------------------------------------------------------------------------ - Fix: [#16974] Small scenery ghosts can be deleted. +- Removed: [#16864] Title sequence editor (replaced by plug-in). 0.4.0 (2022-04-25) ------------------------------------------------------------------------ From e3ee511a0ccbaec8307e1e2edbab8a00ae187af6 Mon Sep 17 00:00:00 2001 From: Ted John Date: Tue, 5 Apr 2022 23:06:47 +0100 Subject: [PATCH 3/3] Update options UI --- src/openrct2-ui/windows/Options.cpp | 84 +++++++++++++++------------ src/openrct2/interface/Widget.h | 21 +++++++ src/openrct2/localisation/StringIds.h | 2 +- 3 files changed, 69 insertions(+), 38 deletions(-) diff --git a/src/openrct2-ui/windows/Options.cpp b/src/openrct2-ui/windows/Options.cpp index 41b5875d28..ef341af83d 100644 --- a/src/openrct2-ui/windows/Options.cpp +++ b/src/openrct2-ui/windows/Options.cpp @@ -172,8 +172,6 @@ enum WindowOptionsWidgetIdx { // Misc WIDX_TITLE_SEQUENCE_GROUP = WIDX_PAGE_START, - WIDX_TITLE_SEQUENCE_RANDOM, - WIDX_TITLE_SEQUENCE_LABEL, WIDX_TITLE_SEQUENCE, WIDX_TITLE_SEQUENCE_DROPDOWN, WIDX_SCENARIO_GROUP, @@ -343,27 +341,25 @@ static rct_widget window_options_controls_and_interface_widgets[] = { #undef TOOLBAR_GROUP_START }; +#define TITLE_SEQUENCE_START 53 +#define SCENARIO_START (TITLE_SEQUENCE_START + 35) +#define SCENARIO_OPTIONS_START (SCENARIO_START + 55) +#define TWEAKS_START (SCENARIO_OPTIONS_START + 39) + static rct_widget window_options_misc_widgets[] = { MAIN_OPTIONS_WIDGETS, -#define TITLE_SEQUENCE_START 53 - MakeWidget({ 5, TITLE_SEQUENCE_START + 0}, {300, 65}, WindowWidgetType::Groupbox, WindowColour::Secondary, STR_OPTIONS_TITLE_SEQUENCE ), - MakeWidget({ 10, TITLE_SEQUENCE_START + 15}, {290, 16}, WindowWidgetType::Checkbox, WindowColour::Tertiary , STR_OPTIONS_RANDOM_TITLE_SEQUENCE ), // Random Title Sequence - MakeWidget({ 10, TITLE_SEQUENCE_START + 33}, {125, 12}, WindowWidgetType::Label, WindowColour::Secondary, STR_TITLE_SEQUENCE, STR_TITLE_SEQUENCE_TIP ), - MakeWidget({135, TITLE_SEQUENCE_START + 32}, {165, 12}, WindowWidgetType::DropdownMenu, WindowColour::Secondary, STR_STRING ), // Title sequence dropdown - MakeWidget({288, TITLE_SEQUENCE_START + 33}, { 11, 12}, WindowWidgetType::Button, WindowColour::Secondary, STR_DROPDOWN_GLYPH, STR_TITLE_SEQUENCE_TIP ), // Title sequence dropdown button -#undef TITLE_SEQUENCE_START -#define SCENARIO_START 122 + MakeWidget( { 5, TITLE_SEQUENCE_START + 0}, {300, 31}, WindowWidgetType::Groupbox, WindowColour::Secondary, STR_OPTIONS_TITLE_SEQUENCE ), + MakeDropdownWidgets({ 10, TITLE_SEQUENCE_START + 15}, {290, 12}, WindowWidgetType::DropdownMenu, WindowColour::Secondary, STR_STRINGID, STR_TITLE_SEQUENCE_TIP), // Title sequence dropdown + MakeWidget({ 5, SCENARIO_START + 0}, {300, 51}, WindowWidgetType::Groupbox, WindowColour::Secondary, STR_OPTIONS_SCENARIO_SELECTION ), MakeWidget({ 10, SCENARIO_START + 16}, {165, 12}, WindowWidgetType::Label, WindowColour::Secondary, STR_OPTIONS_SCENARIO_GROUPING, STR_SCENARIO_GROUPING_TIP ), MakeWidget({175, SCENARIO_START + 15}, {125, 12}, WindowWidgetType::DropdownMenu, WindowColour::Secondary ), // Scenario select mode MakeWidget({288, SCENARIO_START + 16}, { 11, 10}, WindowWidgetType::Button, WindowColour::Secondary, STR_DROPDOWN_GLYPH, STR_SCENARIO_GROUPING_TIP ), MakeWidget({ 25, SCENARIO_START + 30}, {275, 16}, WindowWidgetType::Checkbox, WindowColour::Tertiary , STR_OPTIONS_SCENARIO_UNLOCKING, STR_SCENARIO_UNLOCKING_TIP), // Unlocking of scenarios -#undef SCENARIO_START -#define SCENARIO_OPTIONS_START 177 + MakeWidget({ 5, SCENARIO_OPTIONS_START + 0}, {300, 35}, WindowWidgetType::Groupbox, WindowColour::Secondary, STR_SCENARIO_OPTIONS ), MakeWidget({10, SCENARIO_OPTIONS_START + 15}, {290, 15}, WindowWidgetType::Checkbox, WindowColour::Tertiary , STR_ALLOW_EARLY_COMPLETION, STR_EARLY_COMPLETION_TIP), // Allow early scenario completion -#undef SCENARIO_OPTIONS_START -#define TWEAKS_START 216 + MakeWidget({ 5, TWEAKS_START + 0}, {300, 81}, WindowWidgetType::Groupbox, WindowColour::Secondary, STR_OPTIONS_TWEAKS ), MakeWidget({ 10, TWEAKS_START + 15}, {290, 15}, WindowWidgetType::Checkbox, WindowColour::Tertiary , STR_REAL_NAME, STR_REAL_NAME_TIP ), // Show 'real' names of guests MakeWidget({ 10, TWEAKS_START + 30}, {290, 15}, WindowWidgetType::Checkbox, WindowColour::Tertiary , STR_AUTO_STAFF_PLACEMENT, STR_AUTO_STAFF_PLACEMENT_TIP ), // Auto staff placement @@ -371,10 +367,14 @@ static rct_widget window_options_misc_widgets[] = { MakeWidget({ 10, TWEAKS_START + 62}, {165, 12}, WindowWidgetType::Label, WindowColour::Secondary, STR_DEFAULT_INSPECTION_INTERVAL, STR_DEFAULT_INSPECTION_INTERVAL_TIP), MakeWidget({175, TWEAKS_START + 61}, {125, 12}, WindowWidgetType::DropdownMenu, WindowColour::Secondary ), // Default inspection time dropdown MakeWidget({288, TWEAKS_START + 62}, { 11, 10}, WindowWidgetType::Button, WindowColour::Secondary, STR_DROPDOWN_GLYPH, STR_DEFAULT_INSPECTION_INTERVAL_TIP ), // Default inspection time dropdown button -#undef TWEAKS_START WIDGETS_END, }; +#undef TWEAKS_START +#undef SCENARIO_OPTIONS_START +#undef SCENARIO_START +#undef TITLE_SEQUENCE_START + static rct_widget window_options_advanced_widgets[] = { MAIN_OPTIONS_WIDGETS, MakeWidget ({ 10, 54}, {290, 12}, WindowWidgetType::Checkbox, WindowColour::Tertiary , STR_ENABLE_DEBUGGING_TOOLS, STR_ENABLE_DEBUGGING_TOOLS_TIP ), // Enable debugging tools @@ -404,6 +404,7 @@ static rct_widget *window_options_page_widgets[] = { }; #pragma endregion +// clang-format on class OptionsWindow final : public Window { @@ -1648,11 +1649,6 @@ private: config_save_default(); window_close_by_class(WC_SCENARIO_SELECT); break; - case WIDX_TITLE_SEQUENCE_RANDOM: - gConfigInterface.random_title_sequence ^= 1; - config_save_default(); - Invalidate(); - break; case WIDX_AUTO_OPEN_SHOPS: gConfigGeneral.auto_open_shops = !gConfigGeneral.auto_open_shops; config_save_default(); @@ -1689,11 +1685,20 @@ private: gDropdownItems[i].Args = reinterpret_cast(title_sequence_manager_get_name(i)); } + gDropdownItems[numItems].Format = 0; + numItems++; + gDropdownItems[numItems].Format = STR_DROPDOWN_MENU_LABEL; + gDropdownItems[numItems].Args = STR_TITLE_SEQUENCE_RANDOM; + numItems++; + WindowDropdownShowText( { windowPos.x + widget->left, windowPos.y + widget->top }, widget->height() + 1, colours[1], Dropdown::Flag::StayOpen, numItems); - Dropdown::SetChecked(static_cast(title_get_current_sequence()), true); + auto selectedIndex = gConfigInterface.random_title_sequence + ? numItems - 1 + : static_cast(title_get_current_sequence()); + Dropdown::SetChecked(selectedIndex, true); break; } case WIDX_SCENARIO_GROUPING_DROPDOWN: @@ -1730,13 +1735,23 @@ private: switch (widgetIndex) { case WIDX_TITLE_SEQUENCE_DROPDOWN: - if (dropdownIndex != static_cast(title_get_current_sequence())) + { + auto numItems = static_cast(title_sequence_manager_get_count()); + if (dropdownIndex < numItems && dropdownIndex != static_cast(title_get_current_sequence())) { + gConfigInterface.random_title_sequence = false; title_sequence_change_preset(static_cast(dropdownIndex)); config_save_default(); Invalidate(); } + else if (dropdownIndex == numItems + 1) + { + gConfigInterface.random_title_sequence = true; + config_save_default(); + Invalidate(); + } break; + } case WIDX_DEFAULT_INSPECTION_INTERVAL_DROPDOWN: if (dropdownIndex != gConfigGeneral.default_inspection_interval) { @@ -1760,9 +1775,17 @@ private: void MiscPrepareDraw() { - const utf8* name = title_sequence_manager_get_name(title_get_config_sequence()); auto ft = Formatter::Common(); - ft.Add(name); + if (gConfigInterface.random_title_sequence) + { + ft.Add(STR_TITLE_SEQUENCE_RANDOM); + } + else + { + auto name = title_sequence_manager_get_name(title_get_config_sequence()); + ft.Add(STR_STRING); + ft.Add(name); + } // The real name setting of clients is fixed to that of the server // and the server cannot change the setting during gameplay to prevent desyncs @@ -1783,21 +1806,8 @@ private: SetCheckboxValue(WIDX_REAL_NAME_CHECKBOX, gConfigGeneral.show_real_names_of_guests); SetCheckboxValue(WIDX_AUTO_STAFF_PLACEMENT, gConfigGeneral.auto_staff_placement); SetCheckboxValue(WIDX_AUTO_OPEN_SHOPS, gConfigGeneral.auto_open_shops); - SetCheckboxValue(WIDX_TITLE_SEQUENCE_RANDOM, gConfigInterface.random_title_sequence); SetCheckboxValue(WIDX_ALLOW_EARLY_COMPLETION, gConfigGeneral.allow_early_completion); - // Disable title sequence dropdown if set to random - if (gConfigInterface.random_title_sequence) - { - disabled_widgets |= (1ULL << WIDX_TITLE_SEQUENCE_DROPDOWN); - disabled_widgets |= (1ULL << WIDX_TITLE_SEQUENCE); - } - else - { - disabled_widgets &= ~(1ULL << WIDX_TITLE_SEQUENCE_DROPDOWN); - disabled_widgets &= ~(1ULL << WIDX_TITLE_SEQUENCE); - } - if (gConfigGeneral.scenario_select_mode == SCENARIO_SELECT_MODE_DIFFICULTY) widgets[WIDX_SCENARIO_GROUPING].text = STR_OPTIONS_SCENARIO_DIFFICULTY; else diff --git a/src/openrct2/interface/Widget.h b/src/openrct2/interface/Widget.h index 4906d9e5b6..8a287d9c26 100644 --- a/src/openrct2/interface/Widget.h +++ b/src/openrct2/interface/Widget.h @@ -123,6 +123,27 @@ constexpr rct_widget MakeSpinnerIncreaseWidget( return MakeWidget({ xPos, yPos }, { width, height }, WindowWidgetType::Button, colour, STR_NUMERIC_UP, tooltip); } +#define MakeDropdownWidgets(...) MakeDropdownBoxWidget(__VA_ARGS__), MakeDropdownButtonWidget(__VA_ARGS__) + +constexpr rct_widget MakeDropdownBoxWidget( + const ScreenCoordsXY& origin, const ScreenSize& size, [[maybe_unused]] WindowWidgetType type, WindowColour colour, + [[maybe_unused]] uint32_t content = 0xFFFFFFFF, rct_string_id tooltip = STR_NONE) +{ + return MakeWidget(origin, size, type, colour, content); +} + +constexpr rct_widget MakeDropdownButtonWidget( + const ScreenCoordsXY& origin, const ScreenSize& size, [[maybe_unused]] WindowWidgetType type, WindowColour colour, + [[maybe_unused]] uint32_t content = 0xFFFFFFFF, rct_string_id tooltip = STR_NONE) +{ + const int16_t xPos = origin.x + size.width - 11; + const int16_t yPos = origin.y + 1; + const uint16_t width = 11; + const uint16_t height = 10; + + return MakeWidget({ xPos, yPos }, { width, height }, WindowWidgetType::Button, colour, STR_DROPDOWN_GLYPH, tooltip); +} + void WidgetScrollUpdateThumbs(rct_window* w, rct_widgetindex widget_index); void WidgetDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex); diff --git a/src/openrct2/localisation/StringIds.h b/src/openrct2/localisation/StringIds.h index c1bafca155..726e518ff2 100644 --- a/src/openrct2/localisation/StringIds.h +++ b/src/openrct2/localisation/StringIds.h @@ -2734,7 +2734,7 @@ enum : uint16_t STR_TITLE_SEQUENCE_RCT1_AA_LL = 5307, STR_TITLE_SEQUENCE_RCT2 = 5308, STR_TITLE_SEQUENCE_OPENRCT2 = 5309, - STR_TITLE_SEQUENCE_RANDOM = 5310, // Unused + STR_TITLE_SEQUENCE_RANDOM = 5310, STR_DEBUG_TIP = 5311, STR_DEBUG_DROPDOWN_CONSOLE = 5312, STR_DEBUG_DROPDOWN_TILE_INSPECTOR = 5313,