2014-09-28 00:48:42 +02:00
|
|
|
/*****************************************************************************
|
2022-10-01 09:42:14 +02:00
|
|
|
* Copyright (c) 2014-2022 OpenRCT2 developers
|
2014-09-28 00:48:42 +02: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-28 00:48:42 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
2014-09-28 00:48:42 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2018-08-12 13:50:40 +02:00
|
|
|
#include <algorithm>
|
2018-06-22 23:21:44 +02:00
|
|
|
#include <openrct2-ui/interface/Widget.h>
|
|
|
|
#include <openrct2-ui/windows/Window.h>
|
2017-09-12 21:27:54 +02:00
|
|
|
#include <openrct2/Context.h>
|
2018-06-22 23:21:44 +02:00
|
|
|
#include <openrct2/drawing/Drawing.h>
|
2021-12-12 00:06:06 +01:00
|
|
|
#include <openrct2/localisation/Formatter.h>
|
2018-01-06 18:32:25 +01:00
|
|
|
#include <openrct2/localisation/Localisation.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>
|
2014-12-16 16:33:32 +01:00
|
|
|
|
2022-07-31 14:22:58 +02:00
|
|
|
static constexpr const StringId WINDOW_TITLE = STR_STRING;
|
2020-05-05 22:26:14 +02:00
|
|
|
static constexpr const int32_t WH = 44;
|
|
|
|
static constexpr const int32_t WW = 250;
|
2021-08-01 12:55:44 +02:00
|
|
|
static constexpr const int32_t WH_DELETE_PROMPT = 74;
|
|
|
|
static constexpr const int32_t WW_DELETE_PROMPT = 250;
|
2022-07-26 18:12:46 +02:00
|
|
|
static constexpr const int32_t TrackDesignNameMaxLength = 127;
|
2019-10-19 04:02:31 +02:00
|
|
|
|
2014-12-16 16:33:32 +01:00
|
|
|
#pragma region Widgets
|
|
|
|
|
2018-05-16 20:41:29 +02:00
|
|
|
// clang-format off
|
2014-12-16 16:33:32 +01:00
|
|
|
enum {
|
2017-06-06 23:24:18 +02:00
|
|
|
WIDX_BACKGROUND,
|
|
|
|
WIDX_TITLE,
|
|
|
|
WIDX_CLOSE,
|
|
|
|
WIDX_RENAME,
|
|
|
|
WIDX_DELETE,
|
|
|
|
|
|
|
|
WIDX_PROMPT_DELETE = 3,
|
|
|
|
WIDX_PROMPT_CANCEL = 4,
|
2014-12-16 16:33:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static rct_widget window_track_manage_widgets[] = {
|
2020-05-09 16:44:21 +02:00
|
|
|
WINDOW_SHIM(WINDOW_TITLE, WW, WH),
|
2020-11-27 04:14:20 +01:00
|
|
|
MakeWidget({ 10, 24}, {110, 12}, WindowWidgetType::Button, WindowColour::Primary, STR_TRACK_MANAGE_RENAME),
|
|
|
|
MakeWidget({130, 24}, {110, 12}, WindowWidgetType::Button, WindowColour::Primary, STR_TRACK_MANAGE_DELETE),
|
2021-09-26 11:11:42 +02:00
|
|
|
WIDGETS_END,
|
2014-12-16 16:33:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static rct_widget window_track_delete_prompt_widgets[] = {
|
2021-08-01 12:55:44 +02:00
|
|
|
WINDOW_SHIM(STR_DELETE_FILE, WW_DELETE_PROMPT, WH_DELETE_PROMPT),
|
2020-11-27 04:14:20 +01:00
|
|
|
MakeWidget({ 10, 54}, {110, 12}, WindowWidgetType::Button, WindowColour::Primary, STR_TRACK_MANAGE_DELETE),
|
|
|
|
MakeWidget({130, 54}, {110, 12}, WindowWidgetType::Button, WindowColour::Primary, STR_CANCEL ),
|
2021-09-26 11:11:42 +02:00
|
|
|
WIDGETS_END,
|
2014-12-16 16:33:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#pragma endregion
|
|
|
|
|
2022-10-29 22:34:39 +02:00
|
|
|
class TrackDesignManageWindow final : public Window
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
TrackDesignFileRef* _trackDesignFileReference{nullptr};
|
2014-12-16 16:33:32 +01:00
|
|
|
|
2022-10-29 22:34:39 +02:00
|
|
|
public:
|
|
|
|
TrackDesignManageWindow(TrackDesignFileRef* tdFileRef) : _trackDesignFileReference(tdFileRef){}
|
2014-12-16 16:33:32 +01:00
|
|
|
|
2022-10-29 22:34:39 +02:00
|
|
|
void OnOpen() override;
|
|
|
|
void OnClose() override;
|
|
|
|
void OnMouseUp(WidgetIndex widgetIndex) override;
|
|
|
|
void OnTextInput(WidgetIndex widgetIndex, std::string_view text) override;
|
|
|
|
void OnDraw(rct_drawpixelinfo& dpi) override;
|
|
|
|
};
|
2014-12-16 16:33:32 +01:00
|
|
|
|
2022-10-29 22:34:39 +02:00
|
|
|
class TrackDeletePromptWindow final : public Window
|
2020-09-28 20:36:15 +02:00
|
|
|
{
|
2022-10-29 22:34:39 +02:00
|
|
|
private:
|
|
|
|
TrackDesignFileRef* _trackDesignFileReference{nullptr};
|
2014-12-16 16:33:32 +01:00
|
|
|
|
2022-10-29 22:34:39 +02:00
|
|
|
public:
|
|
|
|
TrackDeletePromptWindow(TrackDesignFileRef* tdFileRef) : _trackDesignFileReference(tdFileRef){}
|
2014-12-16 16:33:32 +01:00
|
|
|
|
2022-10-29 22:34:39 +02:00
|
|
|
void OnOpen() override;
|
|
|
|
void OnMouseUp(WidgetIndex widgetIndex) override;
|
|
|
|
void OnDraw(rct_drawpixelinfo& dpi) override;
|
|
|
|
};
|
2016-05-01 22:58:02 +02:00
|
|
|
|
2022-10-29 22:34:39 +02:00
|
|
|
static void WindowTrackDeletePromptOpen(TrackDesignFileRef* tdFileRef);
|
2021-11-23 14:18:07 +01:00
|
|
|
static void WindowTrackDesignListReloadTracks();
|
2014-09-28 00:48:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x006D348F
|
|
|
|
*/
|
2022-07-26 18:12:46 +02:00
|
|
|
rct_window* WindowTrackManageOpen(TrackDesignFileRef* tdFileRef)
|
2014-09-28 00:48:42 +02:00
|
|
|
{
|
2022-08-21 18:38:25 +02:00
|
|
|
window_close_by_class(WindowClass::ManageTrackDesign);
|
2022-10-29 22:34:39 +02:00
|
|
|
auto trackDesignManageWindow = std::make_unique<TrackDesignManageWindow>(tdFileRef);
|
|
|
|
auto* window = WindowCreate(
|
|
|
|
std::move(trackDesignManageWindow), WindowClass::ManageTrackDesign, {}, WW, WH,
|
|
|
|
WF_STICK_TO_FRONT | WF_TRANSPARENT | WF_CENTRE_SCREEN | WF_AUTO_POSITION);
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2022-10-29 22:34:39 +02:00
|
|
|
return window;
|
|
|
|
}
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2022-10-29 22:34:39 +02:00
|
|
|
void TrackDesignManageWindow::OnOpen()
|
|
|
|
{
|
|
|
|
widgets = window_track_manage_widgets;
|
|
|
|
WindowInitScrollWidgets(*this);
|
|
|
|
|
|
|
|
auto* trackDesignListWindow = window_find_by_class(WindowClass::TrackDesignList);
|
2018-06-22 23:21:44 +02:00
|
|
|
if (trackDesignListWindow != nullptr)
|
|
|
|
{
|
2017-07-31 13:05:52 +02:00
|
|
|
trackDesignListWindow->track_list.track_list_being_updated = true;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2014-12-16 16:33:32 +01:00
|
|
|
}
|
|
|
|
|
2022-10-29 22:34:39 +02:00
|
|
|
void TrackDesignManageWindow::OnClose()
|
2014-12-16 16:33:32 +01:00
|
|
|
{
|
2022-08-21 18:38:25 +02:00
|
|
|
rct_window* trackDesignListWindow = window_find_by_class(WindowClass::TrackDesignList);
|
2018-06-22 23:21:44 +02:00
|
|
|
if (trackDesignListWindow != nullptr)
|
|
|
|
{
|
2017-07-31 13:05:52 +02:00
|
|
|
trackDesignListWindow->track_list.track_list_being_updated = false;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2014-12-16 16:33:32 +01:00
|
|
|
}
|
|
|
|
|
2022-10-29 22:34:39 +02:00
|
|
|
void TrackDesignManageWindow::OnMouseUp(WidgetIndex widgetIndex)
|
2014-12-16 16:33:32 +01:00
|
|
|
{
|
2018-06-22 23:21:44 +02:00
|
|
|
switch (widgetIndex)
|
|
|
|
{
|
|
|
|
case WIDX_CLOSE:
|
2022-08-21 18:38:25 +02:00
|
|
|
window_close_by_class(WindowClass::TrackDeletePrompt);
|
2022-10-29 22:34:39 +02:00
|
|
|
Close();
|
2018-06-22 23:21:44 +02:00
|
|
|
break;
|
|
|
|
case WIDX_RENAME:
|
2021-11-23 14:18:07 +01:00
|
|
|
WindowTextInputRawOpen(
|
2022-10-29 22:34:39 +02:00
|
|
|
this, widgetIndex, STR_TRACK_DESIGN_RENAME_TITLE, STR_TRACK_DESIGN_RENAME_DESC, {},
|
2022-07-26 18:12:46 +02:00
|
|
|
_trackDesignFileReference->name.c_str(), TrackDesignNameMaxLength);
|
2018-06-22 23:21:44 +02:00
|
|
|
break;
|
|
|
|
case WIDX_DELETE:
|
2022-10-29 22:34:39 +02:00
|
|
|
WindowTrackDeletePromptOpen(_trackDesignFileReference);
|
2018-06-22 23:21:44 +02:00
|
|
|
break;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2014-12-16 16:33:32 +01:00
|
|
|
}
|
|
|
|
|
2022-10-29 22:34:39 +02:00
|
|
|
void TrackDesignManageWindow::OnTextInput(WidgetIndex widgetIndex, std::string_view text)
|
2014-12-16 16:33:32 +01:00
|
|
|
{
|
2022-10-29 22:34:39 +02:00
|
|
|
if (widgetIndex != WIDX_RENAME)
|
2018-06-22 23:21:44 +02:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
return;
|
|
|
|
}
|
2022-10-29 22:34:39 +02:00
|
|
|
else if (text.empty())
|
2018-06-22 23:21:44 +02:00
|
|
|
{
|
2022-11-06 21:49:07 +01:00
|
|
|
ContextShowError(STR_CANT_RENAME_TRACK_DESIGN, STR_NONE, {});
|
2017-06-06 23:24:18 +02:00
|
|
|
return;
|
|
|
|
}
|
2022-10-29 22:34:39 +02:00
|
|
|
else if (!Platform::IsFilenameValid(text))
|
2018-06-22 23:21:44 +02:00
|
|
|
{
|
2022-11-06 21:49:07 +01:00
|
|
|
ContextShowError(STR_CANT_RENAME_TRACK_DESIGN, STR_NEW_NAME_CONTAINS_INVALID_CHARACTERS, {});
|
2017-06-06 23:24:18 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-10-29 22:34:39 +02:00
|
|
|
if (track_repository_rename(_trackDesignFileReference->path, std::string(text)))
|
2018-06-22 23:21:44 +02:00
|
|
|
{
|
2022-08-21 18:38:25 +02:00
|
|
|
window_close_by_class(WindowClass::TrackDeletePrompt);
|
2022-10-29 22:34:39 +02:00
|
|
|
Close();
|
2021-11-23 14:18:07 +01:00
|
|
|
WindowTrackDesignListReloadTracks();
|
2018-06-22 23:21:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-11-06 21:49:07 +01:00
|
|
|
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
|
|
|
}
|
2014-12-16 16:33:32 +01:00
|
|
|
}
|
|
|
|
|
2022-10-29 22:34:39 +02:00
|
|
|
void TrackDesignManageWindow::OnDraw(rct_drawpixelinfo& dpi)
|
2014-12-16 16:33:32 +01:00
|
|
|
{
|
2022-07-26 18:12:46 +02:00
|
|
|
Formatter::Common().Add<const utf8*>(_trackDesignFileReference->name.c_str());
|
2022-10-29 22:34:39 +02:00
|
|
|
DrawWidgets(dpi);
|
2014-12-16 16:33:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x006D35CD
|
|
|
|
*/
|
2022-10-29 22:34:39 +02:00
|
|
|
static void WindowTrackDeletePromptOpen(TrackDesignFileRef* tdFileRef)
|
2014-12-16 16:33:32 +01:00
|
|
|
{
|
2022-08-21 18:38:25 +02:00
|
|
|
window_close_by_class(WindowClass::TrackDeletePrompt);
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2022-11-06 21:49:07 +01:00
|
|
|
int32_t screenWidth = ContextGetWidth();
|
|
|
|
int32_t screenHeight = ContextGetHeight();
|
2022-10-29 22:34:39 +02:00
|
|
|
auto trackDeletePromptWindow = std::make_unique<TrackDeletePromptWindow>(tdFileRef);
|
|
|
|
WindowCreate(
|
|
|
|
std::move(trackDeletePromptWindow), WindowClass::TrackDeletePrompt, ScreenCoordsXY(
|
|
|
|
std::max(TOP_TOOLBAR_HEIGHT + 1, (screenWidth - WW_DELETE_PROMPT) / 2), (screenHeight - WH_DELETE_PROMPT) / 2), WW_DELETE_PROMPT, WH_DELETE_PROMPT,
|
|
|
|
WF_STICK_TO_FRONT | WF_TRANSPARENT);
|
2014-12-16 16:33:32 +01:00
|
|
|
}
|
|
|
|
|
2022-10-29 22:34:39 +02:00
|
|
|
void TrackDeletePromptWindow::OnOpen()
|
|
|
|
{
|
|
|
|
widgets = window_track_delete_prompt_widgets;
|
|
|
|
WindowInitScrollWidgets(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TrackDeletePromptWindow::OnMouseUp(WidgetIndex widgetIndex)
|
2014-12-16 16:33:32 +01:00
|
|
|
{
|
2018-06-22 23:21:44 +02:00
|
|
|
switch (widgetIndex)
|
|
|
|
{
|
|
|
|
case WIDX_CLOSE:
|
|
|
|
case WIDX_PROMPT_CANCEL:
|
2022-10-29 22:34:39 +02:00
|
|
|
Close();
|
2018-06-22 23:21:44 +02:00
|
|
|
break;
|
|
|
|
case WIDX_PROMPT_DELETE:
|
2022-10-29 22:34:39 +02:00
|
|
|
// tdPath has to be saved before window is closed, as that would blank it out.
|
|
|
|
auto tdPath = _trackDesignFileReference->path;
|
|
|
|
Close();
|
|
|
|
if (track_repository_delete(tdPath))
|
2018-06-22 23:21:44 +02:00
|
|
|
{
|
2022-08-21 18:38:25 +02:00
|
|
|
window_close_by_class(WindowClass::ManageTrackDesign);
|
2021-11-23 14:18:07 +01:00
|
|
|
WindowTrackDesignListReloadTracks();
|
2018-06-22 23:21:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-11-06 21:49:07 +01:00
|
|
|
ContextShowError(STR_CANT_DELETE_TRACK_DESIGN, STR_FILE_IS_WRITE_PROTECTED_OR_LOCKED, {});
|
2018-06-22 23:21:44 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2014-12-16 16:33:32 +01:00
|
|
|
}
|
|
|
|
|
2022-10-29 22:34:39 +02:00
|
|
|
void TrackDeletePromptWindow::OnDraw(rct_drawpixelinfo& dpi)
|
2014-12-16 16:33:32 +01:00
|
|
|
{
|
2022-10-29 22:34:39 +02:00
|
|
|
DrawWidgets(dpi);
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2021-08-21 09:42:05 +02:00
|
|
|
auto ft = Formatter();
|
2022-07-26 18:12:46 +02:00
|
|
|
ft.Add<const utf8*>(_trackDesignFileReference->name.c_str());
|
2021-02-27 17:17:17 +01:00
|
|
|
DrawTextWrapped(
|
2022-10-29 22:34:39 +02:00
|
|
|
&dpi, { windowPos.x + (WW_DELETE_PROMPT / 2), windowPos.y + ((WH_DELETE_PROMPT / 2) - 9) }, (WW_DELETE_PROMPT - 4),
|
2021-08-21 09:42:05 +02:00
|
|
|
STR_ARE_YOU_SURE_YOU_WANT_TO_PERMANENTLY_DELETE_TRACK, ft, { TextAlignment::CENTRE });
|
2015-12-06 18:22:33 +01:00
|
|
|
}
|
2016-10-23 01:42:22 +02:00
|
|
|
|
2021-11-23 14:18:07 +01:00
|
|
|
static void WindowTrackDesignListReloadTracks()
|
2016-10-23 01:42:22 +02:00
|
|
|
{
|
2022-08-21 18:38:25 +02:00
|
|
|
rct_window* trackListWindow = window_find_by_class(WindowClass::TrackDesignList);
|
2018-06-22 23:21:44 +02:00
|
|
|
if (trackListWindow != nullptr)
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
trackListWindow->track_list.reload_track_designs = true;
|
|
|
|
}
|
2016-10-23 01:42:22 +02:00
|
|
|
}
|