2014-09-27 23:48:42 +01:00
|
|
|
/*****************************************************************************
|
2024-12-31 20:30:04 +01:00
|
|
|
* Copyright (c) 2014-2025 OpenRCT2 developers
|
2014-09-27 23:48:42 +01:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* For a complete list of all authors, please refer to contributors.md
|
|
|
|
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
2014-09-27 23:48:42 +01:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
2014-09-27 23:48:42 +01:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
2018-01-03 00:13:37 +01:00
|
|
|
#include <openrct2-ui/interface/Widget.h>
|
2025-01-19 15:50:54 +01:00
|
|
|
#include <openrct2-ui/windows/Windows.h>
|
2018-06-22 23:21:44 +02:00
|
|
|
#include <openrct2/Context.h>
|
2018-03-19 23:28:40 +01:00
|
|
|
#include <openrct2/drawing/Drawing.h>
|
2021-12-11 18:06:06 -05:00
|
|
|
#include <openrct2/localisation/Formatter.h>
|
2024-07-12 14:59:00 +02:00
|
|
|
#include <openrct2/localisation/StringIds.h>
|
2022-03-16 21:02:42 +01:00
|
|
|
#include <openrct2/platform/Platform.h>
|
2018-06-22 23:21:44 +02:00
|
|
|
#include <openrct2/ride/TrackDesignRepository.h>
|
2025-01-19 10:58:28 +01:00
|
|
|
#include <openrct2/ui/WindowManager.h>
|
2014-12-16 15:33:32 +00:00
|
|
|
|
2024-03-10 13:52:35 +00:00
|
|
|
namespace OpenRCT2::Ui::Windows
|
|
|
|
|
{
|
2025-06-16 23:10:47 +02:00
|
|
|
static constexpr StringId kWindowTitle = STR_STRING;
|
|
|
|
|
static constexpr ScreenSize kWindowSize = { 250, 44 };
|
|
|
|
|
static constexpr ScreenSize kWindowSizeDeletePrompt = { 250, 74 };
|
|
|
|
|
static constexpr int32_t kTrackDesignNameMaxLength = 127;
|
2019-10-18 22:02:31 -04:00
|
|
|
|
2014-12-16 15:33:32 +00:00
|
|
|
#pragma region Widgets
|
|
|
|
|
|
2024-09-04 21:11:26 +02:00
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
WIDX_BACKGROUND,
|
|
|
|
|
WIDX_TITLE,
|
|
|
|
|
WIDX_CLOSE,
|
|
|
|
|
WIDX_RENAME,
|
|
|
|
|
WIDX_DELETE,
|
|
|
|
|
|
|
|
|
|
WIDX_PROMPT_DELETE = 3,
|
|
|
|
|
WIDX_PROMPT_CANCEL = 4,
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-10 13:52:35 +00:00
|
|
|
// clang-format off
|
2025-06-07 23:02:14 +02:00
|
|
|
static constexpr auto _trackManageWidgets = makeWidgets(
|
2025-06-16 23:10:47 +02:00
|
|
|
makeWindowShim(kWindowTitle, kWindowSize),
|
2025-06-10 19:55:12 +02:00
|
|
|
makeWidget({ 10, 24}, {110, 12}, WidgetType::button, WindowColour::primary, STR_TRACK_MANAGE_RENAME),
|
|
|
|
|
makeWidget({130, 24}, {110, 12}, WidgetType::button, WindowColour::primary, STR_TRACK_MANAGE_DELETE)
|
2025-06-07 23:02:14 +02:00
|
|
|
);
|
2014-12-16 15:33:32 +00:00
|
|
|
|
2025-06-07 23:02:14 +02:00
|
|
|
static constexpr auto _trackDeletePromptWidgets = makeWidgets(
|
2025-06-16 23:10:47 +02:00
|
|
|
makeWindowShim(STR_DELETE_FILE, kWindowSizeDeletePrompt),
|
2025-06-10 19:55:12 +02:00
|
|
|
makeWidget({ 10, 54}, {110, 12}, WidgetType::button, WindowColour::primary, STR_TRACK_MANAGE_DELETE),
|
|
|
|
|
makeWidget({130, 54}, {110, 12}, WidgetType::button, WindowColour::primary, STR_CANCEL )
|
2025-06-07 23:02:14 +02:00
|
|
|
);
|
2024-09-04 21:11:26 +02:00
|
|
|
// clang-format on
|
2014-12-16 15:33:32 +00:00
|
|
|
|
|
|
|
|
#pragma endregion
|
|
|
|
|
|
2024-03-10 13:52:35 +00:00
|
|
|
class TrackDesignManageWindow final : public Window
|
|
|
|
|
{
|
2022-10-29 17:34:39 -03:00
|
|
|
private:
|
2024-03-10 13:52:35 +00:00
|
|
|
TrackDesignFileRef* _trackDesignFileReference{ nullptr };
|
2014-12-16 15:33:32 +00:00
|
|
|
|
2022-10-29 17:34:39 -03:00
|
|
|
public:
|
2024-03-10 13:52:35 +00:00
|
|
|
TrackDesignManageWindow(TrackDesignFileRef* tdFileRef)
|
|
|
|
|
: _trackDesignFileReference(tdFileRef)
|
|
|
|
|
{
|
|
|
|
|
}
|
2022-10-29 17:34:39 -03:00
|
|
|
|
|
|
|
|
void OnOpen() override;
|
|
|
|
|
void OnClose() override;
|
|
|
|
|
void OnMouseUp(WidgetIndex widgetIndex) override;
|
|
|
|
|
void OnTextInput(WidgetIndex widgetIndex, std::string_view text) override;
|
2025-05-05 01:06:46 +03:00
|
|
|
void OnDraw(RenderTarget& rt) override;
|
2024-03-10 13:52:35 +00:00
|
|
|
};
|
2022-10-29 17:34:39 -03:00
|
|
|
|
2024-03-10 13:52:35 +00:00
|
|
|
class TrackDeletePromptWindow final : public Window
|
|
|
|
|
{
|
2022-10-29 17:34:39 -03:00
|
|
|
private:
|
2024-03-10 13:52:35 +00:00
|
|
|
TrackDesignFileRef* _trackDesignFileReference{ nullptr };
|
2014-12-16 15:33:32 +00:00
|
|
|
|
2022-10-29 17:34:39 -03:00
|
|
|
public:
|
2024-03-10 13:52:35 +00:00
|
|
|
TrackDeletePromptWindow(TrackDesignFileRef* tdFileRef)
|
|
|
|
|
: _trackDesignFileReference(tdFileRef)
|
|
|
|
|
{
|
|
|
|
|
}
|
2014-12-16 15:33:32 +00:00
|
|
|
|
2022-10-29 17:34:39 -03:00
|
|
|
void OnOpen() override;
|
|
|
|
|
void OnMouseUp(WidgetIndex widgetIndex) override;
|
2025-05-05 01:06:46 +03:00
|
|
|
void OnDraw(RenderTarget& rt) override;
|
2024-03-10 13:52:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void WindowTrackDeletePromptOpen(TrackDesignFileRef* tdFileRef);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* rct2: 0x006D348F
|
|
|
|
|
*/
|
2024-03-17 02:37:46 -04:00
|
|
|
WindowBase* TrackManageOpen(TrackDesignFileRef* tdFileRef)
|
2023-05-19 10:17:38 +02:00
|
|
|
{
|
2025-01-19 18:49:18 +01:00
|
|
|
auto* windowMgr = Ui::GetWindowManager();
|
|
|
|
|
windowMgr->CloseByClass(WindowClass::ManageTrackDesign);
|
2024-03-10 13:52:35 +00:00
|
|
|
auto trackDesignManageWindow = std::make_unique<TrackDesignManageWindow>(tdFileRef);
|
2025-01-19 10:58:28 +01:00
|
|
|
|
|
|
|
|
auto* window = windowMgr->Create(
|
2025-06-16 23:10:47 +02:00
|
|
|
std::move(trackDesignManageWindow), WindowClass::ManageTrackDesign, {}, kWindowSize,
|
2024-03-10 13:52:35 +00:00
|
|
|
WF_STICK_TO_FRONT | WF_TRANSPARENT | WF_CENTRE_SCREEN | WF_AUTO_POSITION);
|
|
|
|
|
|
|
|
|
|
return window;
|
2023-05-19 10:17:38 +02:00
|
|
|
}
|
2016-05-01 21:58:02 +01:00
|
|
|
|
2024-03-10 13:52:35 +00:00
|
|
|
void TrackDesignManageWindow::OnOpen()
|
2018-06-22 23:21:44 +02:00
|
|
|
{
|
2025-01-18 14:45:17 +02:00
|
|
|
SetWidgets(_trackManageWidgets);
|
2024-03-10 13:52:35 +00:00
|
|
|
WindowInitScrollWidgets(*this);
|
|
|
|
|
|
|
|
|
|
WindowTrackDesignListSetBeingUpdated(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TrackDesignManageWindow::OnClose()
|
|
|
|
|
{
|
|
|
|
|
WindowTrackDesignListSetBeingUpdated(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TrackDesignManageWindow::OnMouseUp(WidgetIndex widgetIndex)
|
|
|
|
|
{
|
|
|
|
|
switch (widgetIndex)
|
|
|
|
|
{
|
|
|
|
|
case WIDX_CLOSE:
|
2025-01-19 18:49:18 +01:00
|
|
|
{
|
|
|
|
|
auto* windowMgr = Ui::GetWindowManager();
|
|
|
|
|
windowMgr->CloseByClass(WindowClass::TrackDeletePrompt);
|
2024-03-10 13:52:35 +00:00
|
|
|
Close();
|
|
|
|
|
break;
|
2025-01-19 18:49:18 +01:00
|
|
|
}
|
2024-03-10 13:52:35 +00:00
|
|
|
case WIDX_RENAME:
|
|
|
|
|
WindowTextInputRawOpen(
|
|
|
|
|
this, widgetIndex, STR_TRACK_DESIGN_RENAME_TITLE, STR_TRACK_DESIGN_RENAME_DESC, {},
|
2025-06-16 23:10:47 +02:00
|
|
|
_trackDesignFileReference->name.c_str(), kTrackDesignNameMaxLength);
|
2024-03-10 13:52:35 +00:00
|
|
|
break;
|
|
|
|
|
case WIDX_DELETE:
|
|
|
|
|
WindowTrackDeletePromptOpen(_trackDesignFileReference);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TrackDesignManageWindow::OnTextInput(WidgetIndex widgetIndex, std::string_view text)
|
|
|
|
|
{
|
|
|
|
|
if (widgetIndex != WIDX_RENAME)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else if (text.empty())
|
|
|
|
|
{
|
2025-01-19 16:59:45 +01:00
|
|
|
ContextShowError(STR_CANT_RENAME_TRACK_DESIGN, kStringIdNone, {});
|
2024-03-10 13:52:35 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else if (!Platform::IsFilenameValid(text))
|
|
|
|
|
{
|
|
|
|
|
ContextShowError(STR_CANT_RENAME_TRACK_DESIGN, STR_NEW_NAME_CONTAINS_INVALID_CHARACTERS, {});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (TrackRepositoryRename(_trackDesignFileReference->path, std::string(text)))
|
|
|
|
|
{
|
2025-01-19 18:49:18 +01:00
|
|
|
auto* windowMgr = Ui::GetWindowManager();
|
|
|
|
|
windowMgr->CloseByClass(WindowClass::TrackDeletePrompt);
|
2022-10-29 17:34:39 -03:00
|
|
|
Close();
|
2024-03-10 13:52:35 +00:00
|
|
|
WindowTrackDesignListReloadTracks();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ContextShowError(STR_CANT_RENAME_TRACK_DESIGN, STR_ANOTHER_FILE_EXISTS_WITH_NAME_OR_FILE_IS_WRITE_PROTECTED, {});
|
|
|
|
|
}
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2016-10-22 17:06:27 +01:00
|
|
|
|
2025-05-05 01:06:46 +03:00
|
|
|
void TrackDesignManageWindow::OnDraw(RenderTarget& rt)
|
2024-03-10 13:52:35 +00:00
|
|
|
{
|
|
|
|
|
Formatter::Common().Add<const utf8*>(_trackDesignFileReference->name.c_str());
|
2025-05-05 01:06:46 +03:00
|
|
|
DrawWidgets(rt);
|
2024-03-10 13:52:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* rct2: 0x006D35CD
|
|
|
|
|
*/
|
|
|
|
|
static void WindowTrackDeletePromptOpen(TrackDesignFileRef* tdFileRef)
|
2018-06-22 23:21:44 +02:00
|
|
|
{
|
2025-01-19 18:49:18 +01:00
|
|
|
auto* windowMgr = Ui::GetWindowManager();
|
|
|
|
|
windowMgr->CloseByClass(WindowClass::TrackDeletePrompt);
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
|
|
|
auto trackDeletePromptWindow = std::make_unique<TrackDeletePromptWindow>(tdFileRef);
|
2025-01-19 10:58:28 +01:00
|
|
|
|
|
|
|
|
windowMgr->Create(
|
2025-06-16 23:10:47 +02:00
|
|
|
std::move(trackDeletePromptWindow), WindowClass::TrackDeletePrompt, {}, kWindowSizeDeletePrompt,
|
2025-04-19 14:44:24 +02:00
|
|
|
WF_STICK_TO_FRONT | WF_TRANSPARENT | WF_AUTO_POSITION | WF_CENTRE_SCREEN);
|
2018-06-22 23:21:44 +02:00
|
|
|
}
|
2024-03-10 13:52:35 +00:00
|
|
|
|
|
|
|
|
void TrackDeletePromptWindow::OnOpen()
|
2018-06-22 23:21:44 +02:00
|
|
|
{
|
2025-01-18 14:45:17 +02:00
|
|
|
SetWidgets(_trackDeletePromptWidgets);
|
2024-03-10 13:52:35 +00:00
|
|
|
WindowInitScrollWidgets(*this);
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2014-12-16 15:33:32 +00:00
|
|
|
|
2024-03-10 13:52:35 +00:00
|
|
|
void TrackDeletePromptWindow::OnMouseUp(WidgetIndex widgetIndex)
|
2018-06-22 23:21:44 +02:00
|
|
|
{
|
2024-03-10 13:52:35 +00:00
|
|
|
switch (widgetIndex)
|
|
|
|
|
{
|
|
|
|
|
case WIDX_CLOSE:
|
|
|
|
|
case WIDX_PROMPT_CANCEL:
|
|
|
|
|
Close();
|
|
|
|
|
break;
|
|
|
|
|
case WIDX_PROMPT_DELETE:
|
|
|
|
|
// tdPath has to be saved before window is closed, as that would blank it out.
|
|
|
|
|
auto tdPath = _trackDesignFileReference->path;
|
|
|
|
|
Close();
|
|
|
|
|
if (TrackRepositoryDelete(tdPath))
|
|
|
|
|
{
|
2025-01-19 18:49:18 +01:00
|
|
|
auto* windowMgr = Ui::GetWindowManager();
|
|
|
|
|
windowMgr->CloseByClass(WindowClass::ManageTrackDesign);
|
2024-03-10 13:52:35 +00:00
|
|
|
WindowTrackDesignListReloadTracks();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ContextShowError(STR_CANT_DELETE_TRACK_DESIGN, STR_FILE_IS_WRITE_PROTECTED_OR_LOCKED, {});
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2014-12-16 15:33:32 +00:00
|
|
|
|
2025-05-05 01:06:46 +03:00
|
|
|
void TrackDeletePromptWindow::OnDraw(RenderTarget& rt)
|
2024-03-10 13:52:35 +00:00
|
|
|
{
|
2025-05-05 01:06:46 +03:00
|
|
|
DrawWidgets(rt);
|
2016-10-23 00:42:22 +01:00
|
|
|
|
2025-07-21 22:55:11 +02:00
|
|
|
const auto titleBarBottom = widgets[WIDX_TITLE].bottom;
|
|
|
|
|
const auto buttonTop = widgets[WIDX_PROMPT_DELETE].top;
|
|
|
|
|
const auto fontHeight = FontGetLineHeight(FontStyle::Medium);
|
|
|
|
|
|
|
|
|
|
const auto maxMessageHeight = buttonTop - titleBarBottom;
|
|
|
|
|
const auto messageTop = titleBarBottom + (maxMessageHeight - fontHeight) / 2;
|
|
|
|
|
|
2024-03-10 13:52:35 +00:00
|
|
|
auto ft = Formatter();
|
|
|
|
|
ft.Add<const utf8*>(_trackDesignFileReference->name.c_str());
|
|
|
|
|
DrawTextWrapped(
|
2025-07-21 22:55:11 +02:00
|
|
|
rt, windowPos + ScreenCoordsXY{ width / 2, messageTop }, (width - 4),
|
|
|
|
|
STR_ARE_YOU_SURE_YOU_WANT_TO_PERMANENTLY_DELETE_TRACK, ft, { TextAlignment::CENTRE });
|
2024-03-10 13:52:35 +00:00
|
|
|
}
|
|
|
|
|
} // namespace OpenRCT2::Ui::Windows
|