2014-09-27 23:48:42 +01:00
|
|
|
/*****************************************************************************
|
2020-07-21 15:04:34 +02:00
|
|
|
* Copyright (c) 2014-2020 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-08-12 12:50:40 +01:00
|
|
|
#include <algorithm>
|
2018-01-03 00:13:37 +01:00
|
|
|
#include <openrct2-ui/interface/Widget.h>
|
2018-06-22 23:21:44 +02:00
|
|
|
#include <openrct2-ui/windows/Window.h>
|
|
|
|
|
#include <openrct2/Context.h>
|
2018-03-19 23:28:40 +01:00
|
|
|
#include <openrct2/drawing/Drawing.h>
|
2018-06-22 23:21:44 +02:00
|
|
|
#include <openrct2/localisation/Localisation.h>
|
|
|
|
|
#include <openrct2/ride/TrackDesignRepository.h>
|
|
|
|
|
#include <openrct2/util/Util.h>
|
2014-12-16 15:33:32 +00:00
|
|
|
|
2020-05-05 22:26:14 +02:00
|
|
|
static constexpr const rct_string_id WINDOW_TITLE = STR_STRING;
|
|
|
|
|
static constexpr const int32_t WH = 44;
|
|
|
|
|
static constexpr const int32_t WW = 250;
|
2019-10-18 22:02:31 -04:00
|
|
|
|
2014-12-16 15:33:32 +00:00
|
|
|
#pragma region Widgets
|
|
|
|
|
|
2018-05-16 20:41:29 +02:00
|
|
|
// clang-format off
|
2014-12-16 15:33:32 +00:00
|
|
|
enum {
|
2017-06-06 23:24:18 +02:00
|
|
|
WIDX_BACKGROUND,
|
|
|
|
|
WIDX_TITLE,
|
|
|
|
|
WIDX_CLOSE,
|
|
|
|
|
WIDX_RENAME,
|
|
|
|
|
WIDX_DELETE,
|
2014-12-16 15:33:32 +00:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
WIDX_PROMPT_DELETE = 3,
|
|
|
|
|
WIDX_PROMPT_CANCEL = 4,
|
2014-12-16 15:33:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static rct_widget window_track_manage_widgets[] = {
|
2020-05-09 16:44:21 +02:00
|
|
|
WINDOW_SHIM(WINDOW_TITLE, WW, WH),
|
2020-11-26 22:14:20 -05: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),
|
2017-06-06 23:24:18 +02:00
|
|
|
{ WIDGETS_END }
|
2014-12-16 15:33:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static rct_widget window_track_delete_prompt_widgets[] = {
|
2020-05-09 16:44:21 +02:00
|
|
|
WINDOW_SHIM(WINDOW_TITLE, WW, WH),
|
2020-11-26 22:14:20 -05: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 ),
|
2017-06-06 23:24:18 +02:00
|
|
|
{ WIDGETS_END }
|
2014-12-16 15:33:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#pragma endregion
|
|
|
|
|
|
|
|
|
|
#pragma region Events
|
|
|
|
|
|
2015-07-10 01:39:16 +01:00
|
|
|
static void window_track_manage_close(rct_window *w);
|
2017-05-01 15:41:45 +02:00
|
|
|
static void window_track_manage_mouseup(rct_window *w, rct_widgetindex widgetIndex);
|
|
|
|
|
static void window_track_manage_textinput(rct_window *w, rct_widgetindex widgetIndex, char *text);
|
2015-07-10 01:39:16 +01:00
|
|
|
static void window_track_manage_paint(rct_window *w, rct_drawpixelinfo *dpi);
|
2014-12-16 15:33:32 +00:00
|
|
|
|
2017-05-01 15:41:45 +02:00
|
|
|
static void window_track_delete_prompt_mouseup(rct_window *w, rct_widgetindex widgetIndex);
|
2015-07-10 01:39:16 +01:00
|
|
|
static void window_track_delete_prompt_paint(rct_window *w, rct_drawpixelinfo *dpi);
|
2014-12-16 15:33:32 +00:00
|
|
|
|
|
|
|
|
// 0x009940EC
|
2020-09-28 20:36:15 +02:00
|
|
|
static rct_window_event_list window_track_manage_events([](auto& events)
|
|
|
|
|
{
|
|
|
|
|
events.close = &window_track_manage_close;
|
|
|
|
|
events.mouse_up = &window_track_manage_mouseup;
|
|
|
|
|
events.text_input = &window_track_manage_textinput;
|
|
|
|
|
events.paint = &window_track_manage_paint;
|
|
|
|
|
});
|
2014-12-16 15:33:32 +00:00
|
|
|
|
|
|
|
|
// 0x0099415C
|
2020-09-28 20:36:15 +02:00
|
|
|
static rct_window_event_list window_track_delete_prompt_events([](auto& events)
|
|
|
|
|
{
|
|
|
|
|
events.mouse_up = &window_track_delete_prompt_mouseup;
|
|
|
|
|
events.paint = &window_track_delete_prompt_paint;
|
|
|
|
|
});
|
2018-05-16 20:41:29 +02:00
|
|
|
// clang-format on
|
2014-12-16 15:33:32 +00:00
|
|
|
|
|
|
|
|
#pragma endregion
|
|
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
static track_design_file_ref* _trackDesignFileReference;
|
2016-05-01 21:58:02 +01:00
|
|
|
|
2014-12-16 15:33:32 +00:00
|
|
|
static void window_track_delete_prompt_open();
|
2016-10-23 00:42:22 +01:00
|
|
|
static void window_track_design_list_reload_tracks();
|
2014-09-27 23:48:42 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* rct2: 0x006D348F
|
|
|
|
|
*/
|
2018-06-22 23:21:44 +02:00
|
|
|
rct_window* window_track_manage_open(track_design_file_ref* tdFileRef)
|
2014-09-27 23:48:42 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
window_close_by_class(WC_MANAGE_TRACK_DESIGN);
|
2014-12-16 15:33:32 +00:00
|
|
|
|
2020-11-03 21:52:23 -07:00
|
|
|
rct_window* w = WindowCreateCentred(
|
2018-06-22 23:21:44 +02:00
|
|
|
250, 44, &window_track_manage_events, WC_MANAGE_TRACK_DESIGN, WF_STICK_TO_FRONT | WF_TRANSPARENT);
|
2017-06-06 23:24:18 +02:00
|
|
|
w->widgets = window_track_manage_widgets;
|
2018-06-22 23:21:44 +02:00
|
|
|
w->enabled_widgets = (1 << WIDX_CLOSE) | (1 << WIDX_RENAME) | (1 << WIDX_DELETE);
|
2020-11-03 21:52:23 -07:00
|
|
|
WindowInitScrollWidgets(w);
|
2014-12-16 15:33:32 +00:00
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
rct_window* trackDesignListWindow = window_find_by_class(WC_TRACK_DESIGN_LIST);
|
|
|
|
|
if (trackDesignListWindow != nullptr)
|
|
|
|
|
{
|
2017-07-31 12:05:52 +01:00
|
|
|
trackDesignListWindow->track_list.track_list_being_updated = true;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2016-05-01 21:58:02 +01:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
_trackDesignFileReference = tdFileRef;
|
2017-09-20 00:13:19 +02:00
|
|
|
|
|
|
|
|
return w;
|
2014-12-16 15:33:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* rct2: 0x006D364C
|
|
|
|
|
*/
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_track_manage_close(rct_window* w)
|
2014-12-16 15:33:32 +00:00
|
|
|
{
|
2018-06-22 23:21:44 +02:00
|
|
|
rct_window* trackDesignListWindow = window_find_by_class(WC_TRACK_DESIGN_LIST);
|
|
|
|
|
if (trackDesignListWindow != nullptr)
|
|
|
|
|
{
|
2017-07-31 12:05:52 +01:00
|
|
|
trackDesignListWindow->track_list.track_list_being_updated = false;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2014-12-16 15:33:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* rct2: 0x006D3523
|
|
|
|
|
*/
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_track_manage_mouseup(rct_window* w, rct_widgetindex widgetIndex)
|
2014-12-16 15:33:32 +00:00
|
|
|
{
|
2018-06-22 23:21:44 +02:00
|
|
|
switch (widgetIndex)
|
|
|
|
|
{
|
|
|
|
|
case WIDX_CLOSE:
|
|
|
|
|
window_close(w);
|
|
|
|
|
break;
|
|
|
|
|
case WIDX_RENAME:
|
|
|
|
|
window_text_input_raw_open(
|
2018-07-21 13:51:54 +02:00
|
|
|
w, widgetIndex, STR_TRACK_DESIGN_RENAME_TITLE, STR_TRACK_DESIGN_RENAME_DESC, _trackDesignFileReference->name,
|
2018-06-22 23:21:44 +02:00
|
|
|
127);
|
|
|
|
|
break;
|
|
|
|
|
case WIDX_DELETE:
|
|
|
|
|
window_track_delete_prompt_open();
|
|
|
|
|
break;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2014-12-16 15:33:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* rct2: 0x006D3523
|
|
|
|
|
*/
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_track_manage_textinput(rct_window* w, rct_widgetindex widgetIndex, char* text)
|
2014-12-16 15:33:32 +00:00
|
|
|
{
|
2018-06-22 23:21:44 +02:00
|
|
|
if (widgetIndex != WIDX_RENAME || str_is_null_or_empty(text))
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2014-12-16 15:33:32 +00:00
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
if (str_is_null_or_empty(text))
|
|
|
|
|
{
|
2020-08-27 00:01:15 +02:00
|
|
|
context_show_error(STR_CANT_RENAME_TRACK_DESIGN, STR_NONE, {});
|
2017-06-06 23:24:18 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2016-10-22 17:06:27 +01:00
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
if (!filename_valid_characters(text))
|
|
|
|
|
{
|
2020-08-27 00:01:15 +02:00
|
|
|
context_show_error(STR_CANT_RENAME_TRACK_DESIGN, STR_NEW_NAME_CONTAINS_INVALID_CHARACTERS, {});
|
2017-06-06 23:24:18 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2016-10-22 17:06:27 +01:00
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
if (track_repository_rename(_trackDesignFileReference->path, text))
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
window_close_by_class(WC_TRACK_DELETE_PROMPT);
|
|
|
|
|
window_close(w);
|
|
|
|
|
window_track_design_list_reload_tracks();
|
2018-06-22 23:21:44 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-08-27 00:01:15 +02:00
|
|
|
context_show_error(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 15:33:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* rct2: 0x006D3523
|
|
|
|
|
*/
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_track_manage_paint(rct_window* w, rct_drawpixelinfo* dpi)
|
2014-12-16 15:33:32 +00:00
|
|
|
{
|
2020-04-21 16:16:27 -03:00
|
|
|
Formatter::Common().Add<char*>(_trackDesignFileReference->name);
|
2020-11-03 21:52:23 -07:00
|
|
|
WindowDrawWidgets(w, dpi);
|
2014-12-16 15:33:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* rct2: 0x006D35CD
|
|
|
|
|
*/
|
|
|
|
|
static void window_track_delete_prompt_open()
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
window_close_by_class(WC_TRACK_DELETE_PROMPT);
|
2014-12-16 15:33:32 +00:00
|
|
|
|
2018-06-20 17:28:51 +02:00
|
|
|
int32_t screenWidth = context_get_width();
|
|
|
|
|
int32_t screenHeight = context_get_height();
|
2020-11-03 21:52:23 -07:00
|
|
|
rct_window* w = WindowCreate(
|
2019-10-19 08:07:03 -03:00
|
|
|
ScreenCoordsXY(std::max(TOP_TOOLBAR_HEIGHT + 1, (screenWidth - 250) / 2), (screenHeight - 44) / 2), 250, 74,
|
2018-07-21 13:51:54 +02:00
|
|
|
&window_track_delete_prompt_events, WC_TRACK_DELETE_PROMPT, WF_STICK_TO_FRONT);
|
2017-06-06 23:24:18 +02:00
|
|
|
w->widgets = window_track_delete_prompt_widgets;
|
2018-06-22 23:21:44 +02:00
|
|
|
w->enabled_widgets = (1 << WIDX_CLOSE) | (1 << WIDX_RENAME) | (1 << WIDX_DELETE);
|
2020-11-03 21:52:23 -07:00
|
|
|
WindowInitScrollWidgets(w);
|
2017-06-06 23:24:18 +02:00
|
|
|
w->flags |= WF_TRANSPARENT;
|
2014-12-16 15:33:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* rct2: 0x006D3823
|
|
|
|
|
*/
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_track_delete_prompt_mouseup(rct_window* w, rct_widgetindex widgetIndex)
|
2014-12-16 15:33:32 +00:00
|
|
|
{
|
2018-06-22 23:21:44 +02:00
|
|
|
switch (widgetIndex)
|
|
|
|
|
{
|
|
|
|
|
case WIDX_CLOSE:
|
|
|
|
|
case WIDX_PROMPT_CANCEL:
|
|
|
|
|
window_close(w);
|
|
|
|
|
break;
|
|
|
|
|
case WIDX_PROMPT_DELETE:
|
|
|
|
|
window_close(w);
|
|
|
|
|
if (track_repository_delete(_trackDesignFileReference->path))
|
|
|
|
|
{
|
|
|
|
|
window_close_by_class(WC_MANAGE_TRACK_DESIGN);
|
|
|
|
|
window_track_design_list_reload_tracks();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-08-27 00:01:15 +02:00
|
|
|
context_show_error(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 15:33:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* rct2: 0x006D37EE
|
|
|
|
|
*/
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_track_delete_prompt_paint(rct_window* w, rct_drawpixelinfo* dpi)
|
2014-12-16 15:33:32 +00:00
|
|
|
{
|
2020-11-03 21:52:23 -07:00
|
|
|
WindowDrawWidgets(w, dpi);
|
2014-12-16 15:33:32 +00:00
|
|
|
|
2021-02-27 17:17:17 +01:00
|
|
|
DrawTextWrapped(
|
|
|
|
|
dpi, { w->windowPos.x + 125, w->windowPos.y + 28 }, 246, STR_ARE_YOU_SURE_YOU_WANT_TO_PERMANENTLY_DELETE_TRACK,
|
|
|
|
|
&_trackDesignFileReference->name, { TextAlignment::CENTRE });
|
2015-12-06 18:22:33 +01:00
|
|
|
}
|
2016-10-23 00:42:22 +01:00
|
|
|
|
|
|
|
|
static void window_track_design_list_reload_tracks()
|
|
|
|
|
{
|
2018-06-22 23:21:44 +02:00
|
|
|
rct_window* trackListWindow = window_find_by_class(WC_TRACK_DESIGN_LIST);
|
|
|
|
|
if (trackListWindow != nullptr)
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
trackListWindow->track_list.reload_track_designs = true;
|
|
|
|
|
}
|
2016-10-23 00:42:22 +01:00
|
|
|
}
|