2014-04-03 18:52:25 +02:00
|
|
|
/*****************************************************************************
|
2020-07-21 15:04:34 +02:00
|
|
|
* Copyright (c) 2014-2020 OpenRCT2 developers
|
2014-04-03 04:08:06 +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-04-03 04:08:06 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
2014-04-03 04:08:06 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
#include <openrct2-ui/interface/Dropdown.h>
|
|
|
|
#include <openrct2-ui/interface/Widget.h>
|
2017-08-06 21:20:05 +02:00
|
|
|
#include <openrct2-ui/windows/Window.h>
|
2018-06-22 23:21:44 +02:00
|
|
|
#include <openrct2/Context.h>
|
2017-09-22 07:56:24 +02:00
|
|
|
#include <openrct2/Editor.h>
|
2017-11-30 18:17:06 +01:00
|
|
|
#include <openrct2/Game.h>
|
2017-12-12 14:52:57 +01:00
|
|
|
#include <openrct2/Input.h>
|
2018-06-22 23:21:44 +02:00
|
|
|
#include <openrct2/ParkImporter.h>
|
2018-09-04 18:21:00 +02:00
|
|
|
#include <openrct2/PlatformEnvironment.h>
|
2019-02-21 10:34:30 +01:00
|
|
|
#include <openrct2/actions/LoadOrQuitAction.hpp>
|
2018-06-22 23:21:44 +02:00
|
|
|
#include <openrct2/config/Config.h>
|
2018-01-06 18:32:25 +01:00
|
|
|
#include <openrct2/localisation/Localisation.h>
|
2017-09-18 17:05:28 +02:00
|
|
|
#include <openrct2/sprites.h>
|
2018-09-04 18:21:00 +02:00
|
|
|
#include <openrct2/ui/UiContext.h>
|
2014-04-03 04:08:06 +02:00
|
|
|
|
2018-05-16 20:41:29 +02:00
|
|
|
// clang-format off
|
2014-04-03 04:08:06 +02:00
|
|
|
enum {
|
2017-06-06 23:24:18 +02:00
|
|
|
WIDX_START_NEW_GAME,
|
|
|
|
WIDX_CONTINUE_SAVED_GAME,
|
|
|
|
WIDX_MULTIPLAYER,
|
2020-08-02 23:38:00 +02:00
|
|
|
WIDX_GAME_TOOLS,
|
|
|
|
WIDX_NEW_VERSION,
|
2014-04-03 04:08:06 +02:00
|
|
|
};
|
|
|
|
|
2020-08-02 23:38:00 +02:00
|
|
|
static ScreenRect _filterRect;
|
2020-08-30 23:30:02 +02:00
|
|
|
static constexpr ScreenSize MenuButtonDims = { 82, 82 };
|
|
|
|
static constexpr ScreenSize UpdateButtonDims = { MenuButtonDims.width * 4, 28 };
|
2020-08-02 23:38:00 +02:00
|
|
|
|
2014-04-03 04:08:06 +02:00
|
|
|
static rct_widget window_title_menu_widgets[] = {
|
2020-08-30 23:30:02 +02:00
|
|
|
MakeWidget({0, UpdateButtonDims.height}, MenuButtonDims, WWT_IMGBTN, WindowColour::Tertiary, SPR_MENU_NEW_GAME, STR_START_NEW_GAME_TIP),
|
|
|
|
MakeWidget({0, UpdateButtonDims.height}, MenuButtonDims, WWT_IMGBTN, WindowColour::Tertiary, SPR_MENU_LOAD_GAME, STR_CONTINUE_SAVED_GAME_TIP),
|
|
|
|
MakeWidget({0, UpdateButtonDims.height}, MenuButtonDims, WWT_IMGBTN, WindowColour::Tertiary, SPR_G2_MENU_MULTIPLAYER, STR_SHOW_MULTIPLAYER_TIP),
|
|
|
|
MakeWidget({0, UpdateButtonDims.height}, MenuButtonDims, WWT_IMGBTN, WindowColour::Tertiary, SPR_MENU_TOOLBOX, STR_GAME_TOOLS_TIP),
|
|
|
|
MakeWidget({0, 0}, UpdateButtonDims, WWT_EMPTY, WindowColour::Secondary, STR_UPDATE_AVAILABLE),
|
2017-06-06 23:24:18 +02:00
|
|
|
{ WIDGETS_END },
|
2014-04-03 04:08:06 +02:00
|
|
|
};
|
|
|
|
|
2017-05-01 15:41:45 +02:00
|
|
|
static void window_title_menu_mouseup(rct_window *w, rct_widgetindex widgetIndex);
|
2017-07-03 23:09:46 +02:00
|
|
|
static void window_title_menu_mousedown(rct_window *w, rct_widgetindex widgetIndex, rct_widget* widget);
|
2018-06-20 17:28:51 +02:00
|
|
|
static void window_title_menu_dropdown(rct_window *w, rct_widgetindex widgetIndex, int32_t dropdownIndex);
|
2020-10-11 18:01:14 +02:00
|
|
|
static void window_title_menu_cursor(rct_window *w, rct_widgetindex widgetIndex, const ScreenCoordsXY& screenCoords, CursorID *cursorId);
|
2020-08-02 23:38:00 +02:00
|
|
|
static void window_title_menu_invalidate(rct_window *w);
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_title_menu_paint(rct_window *w, rct_drawpixelinfo *dpi);
|
2014-04-09 15:43:27 +02:00
|
|
|
|
2020-09-28 20:36:15 +02:00
|
|
|
static rct_window_event_list window_title_menu_events([](auto& events)
|
|
|
|
{
|
|
|
|
events.mouse_up = &window_title_menu_mouseup;
|
|
|
|
events.mouse_down = &window_title_menu_mousedown;
|
|
|
|
events.dropdown = &window_title_menu_dropdown;
|
|
|
|
events.cursor = &window_title_menu_cursor;
|
|
|
|
events.invalidate = &window_title_menu_invalidate;
|
|
|
|
events.paint = &window_title_menu_paint;
|
|
|
|
});
|
2018-05-16 20:41:29 +02:00
|
|
|
// clang-format on
|
2014-04-03 20:49:00 +02:00
|
|
|
|
2014-04-03 04:08:06 +02:00
|
|
|
/**
|
|
|
|
* Creates the window containing the menu buttons on the title screen.
|
|
|
|
* rct2: 0x0066B5C0 (part of 0x0066B3E8)
|
|
|
|
*/
|
2018-06-22 23:21:44 +02:00
|
|
|
rct_window* window_title_menu_open()
|
2014-04-03 04:08:06 +02:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
rct_window* window;
|
|
|
|
|
2020-08-30 23:30:02 +02:00
|
|
|
const uint16_t windowHeight = MenuButtonDims.height + UpdateButtonDims.height;
|
2020-11-04 05:52:23 +01:00
|
|
|
window = WindowCreate(
|
2020-08-30 23:30:02 +02:00
|
|
|
ScreenCoordsXY(0, context_get_height() - 182), 0, windowHeight, &window_title_menu_events, WC_TITLE_MENU,
|
2018-06-22 23:21:44 +02:00
|
|
|
WF_STICK_TO_BACK | WF_TRANSPARENT | WF_NO_BACKGROUND);
|
2020-08-30 23:30:02 +02:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
window->widgets = window_title_menu_widgets;
|
2018-06-22 23:21:44 +02:00
|
|
|
window->enabled_widgets
|
|
|
|
= ((1 << WIDX_START_NEW_GAME) | (1 << WIDX_CONTINUE_SAVED_GAME) |
|
2015-12-26 18:09:15 +01:00
|
|
|
#ifndef DISABLE_NETWORK
|
2018-06-22 23:21:44 +02:00
|
|
|
(1 << WIDX_MULTIPLAYER) |
|
2015-12-26 18:09:15 +01:00
|
|
|
#endif
|
2018-06-22 23:21:44 +02:00
|
|
|
(1 << WIDX_GAME_TOOLS));
|
2017-06-06 23:24:18 +02:00
|
|
|
|
|
|
|
rct_widgetindex i = 0;
|
2018-06-20 17:28:51 +02:00
|
|
|
int32_t x = 0;
|
2020-08-02 23:38:00 +02:00
|
|
|
for (rct_widget* widget = window->widgets; widget != &window->widgets[WIDX_NEW_VERSION]; widget++)
|
2018-06-22 23:21:44 +02:00
|
|
|
{
|
2020-11-03 22:29:22 +01:00
|
|
|
if (WidgetIsEnabled(window, i))
|
2018-06-22 23:21:44 +02:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
widget->left = x;
|
2020-08-30 23:30:02 +02:00
|
|
|
widget->right = x + MenuButtonDims.width - 1;
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2020-08-30 23:30:02 +02:00
|
|
|
x += MenuButtonDims.width;
|
2018-06-22 23:21:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
widget->type = WWT_EMPTY;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
window->width = x;
|
2020-08-02 23:38:00 +02:00
|
|
|
window->widgets[WIDX_NEW_VERSION].right = window->width;
|
2020-03-01 20:32:35 +01:00
|
|
|
window->windowPos.x = (context_get_width() - window->width) / 2;
|
2020-08-02 23:38:00 +02:00
|
|
|
window->colours[1] = TRANSLUCENT(COLOUR_LIGHT_ORANGE);
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2020-11-04 05:52:23 +01:00
|
|
|
WindowInitScrollWidgets(window);
|
2017-08-06 05:22:00 +02:00
|
|
|
|
|
|
|
return window;
|
2014-04-09 15:43:27 +02:00
|
|
|
}
|
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_title_menu_scenarioselect_callback(const utf8* path)
|
2016-02-10 19:44:00 +01:00
|
|
|
{
|
2017-08-23 08:04:36 +02:00
|
|
|
context_load_park_from_file(path);
|
2020-02-22 23:18:22 +01:00
|
|
|
game_load_scripts();
|
2016-02-10 19:44:00 +01:00
|
|
|
}
|
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_title_menu_mouseup(rct_window* w, rct_widgetindex widgetIndex)
|
2014-04-09 15:43:27 +02:00
|
|
|
{
|
2018-06-22 23:21:44 +02:00
|
|
|
rct_window* windowToOpen = nullptr;
|
|
|
|
|
|
|
|
switch (widgetIndex)
|
|
|
|
{
|
|
|
|
case WIDX_START_NEW_GAME:
|
|
|
|
windowToOpen = window_find_by_class(WC_SCENARIO_SELECT);
|
|
|
|
if (windowToOpen != nullptr)
|
|
|
|
{
|
|
|
|
window_bring_to_front(windowToOpen);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
window_close_by_class(WC_LOADSAVE);
|
|
|
|
window_close_by_class(WC_SERVER_LIST);
|
|
|
|
window_scenarioselect_open(window_title_menu_scenarioselect_callback, false);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WIDX_CONTINUE_SAVED_GAME:
|
|
|
|
windowToOpen = window_find_by_class(WC_LOADSAVE);
|
|
|
|
if (windowToOpen != nullptr)
|
|
|
|
{
|
|
|
|
window_bring_to_front(windowToOpen);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
window_close_by_class(WC_SCENARIO_SELECT);
|
|
|
|
window_close_by_class(WC_SERVER_LIST);
|
2019-02-21 10:34:30 +01:00
|
|
|
auto loadOrQuitAction = LoadOrQuitAction(LoadOrQuitModes::OpenSavePrompt);
|
|
|
|
GameActions::Execute(&loadOrQuitAction);
|
2018-06-22 23:21:44 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WIDX_MULTIPLAYER:
|
|
|
|
windowToOpen = window_find_by_class(WC_SERVER_LIST);
|
|
|
|
if (windowToOpen != nullptr)
|
|
|
|
{
|
|
|
|
window_bring_to_front(windowToOpen);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
window_close_by_class(WC_SCENARIO_SELECT);
|
|
|
|
window_close_by_class(WC_LOADSAVE);
|
|
|
|
context_open_window(WC_SERVER_LIST);
|
|
|
|
}
|
|
|
|
break;
|
2020-08-02 23:38:00 +02:00
|
|
|
case WIDX_NEW_VERSION:
|
2020-08-13 22:57:14 +02:00
|
|
|
context_open_window_view(WV_NEW_VERSION_INFO);
|
2020-08-02 23:38:00 +02:00
|
|
|
break;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2014-04-09 15:43:27 +02:00
|
|
|
}
|
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_title_menu_mousedown(rct_window* w, rct_widgetindex widgetIndex, rct_widget* widget)
|
2014-04-09 15:43:27 +02:00
|
|
|
{
|
2018-06-22 23:21:44 +02:00
|
|
|
if (widgetIndex == WIDX_GAME_TOOLS)
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
gDropdownItemsFormat[0] = STR_SCENARIO_EDITOR;
|
|
|
|
gDropdownItemsFormat[1] = STR_CONVERT_SAVED_GAME_TO_SCENARIO;
|
|
|
|
gDropdownItemsFormat[2] = STR_ROLLER_COASTER_DESIGNER;
|
|
|
|
gDropdownItemsFormat[3] = STR_TRACK_DESIGNS_MANAGER;
|
2018-09-04 22:27:23 +02:00
|
|
|
gDropdownItemsFormat[4] = STR_OPEN_USER_CONTENT_FOLDER;
|
2020-11-03 09:16:06 +01:00
|
|
|
WindowDropdownShowText(
|
2020-06-25 03:44:00 +02:00
|
|
|
{ w->windowPos.x + widget->left, w->windowPos.y + widget->top }, widget->height() + 1, TRANSLUCENT(w->colours[0]),
|
2020-11-03 09:16:06 +01:00
|
|
|
Dropdown::Flag::StayOpen, 5);
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2014-04-09 15:43:27 +02:00
|
|
|
}
|
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_title_menu_dropdown(rct_window* w, rct_widgetindex widgetIndex, int32_t dropdownIndex)
|
2014-04-09 15:43:27 +02:00
|
|
|
{
|
2018-06-22 23:21:44 +02:00
|
|
|
if (widgetIndex == WIDX_GAME_TOOLS)
|
|
|
|
{
|
|
|
|
switch (dropdownIndex)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
Editor::Load();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
Editor::ConvertSaveToScenario();
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
Editor::LoadTrackDesigner();
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
Editor::LoadTrackManager();
|
|
|
|
break;
|
2018-09-04 11:40:51 +02:00
|
|
|
case 4:
|
2020-07-21 23:22:48 +02:00
|
|
|
{
|
2018-09-04 18:21:00 +02:00
|
|
|
auto context = OpenRCT2::GetContext();
|
2018-09-04 18:05:11 +02:00
|
|
|
auto env = context->GetPlatformEnvironment();
|
|
|
|
auto uiContext = context->GetUiContext();
|
2018-09-04 18:21:00 +02:00
|
|
|
uiContext->OpenFolder(env->GetDirectoryPath(OpenRCT2::DIRBASE::USER));
|
2018-09-04 11:40:51 +02:00
|
|
|
break;
|
2020-07-21 23:22:48 +02:00
|
|
|
}
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
}
|
2014-04-09 15:43:27 +02:00
|
|
|
}
|
|
|
|
|
2020-02-29 03:43:29 +01:00
|
|
|
static void window_title_menu_cursor(
|
2020-10-11 18:01:14 +02:00
|
|
|
rct_window* w, rct_widgetindex widgetIndex, const ScreenCoordsXY& screenCoords, CursorID* cursorId)
|
2014-04-09 15:43:27 +02:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
gTooltipTimeout = 2000;
|
2014-04-09 15:43:27 +02:00
|
|
|
}
|
|
|
|
|
2020-08-02 23:38:00 +02:00
|
|
|
static void window_title_menu_invalidate(rct_window* w)
|
|
|
|
{
|
2020-08-30 23:30:02 +02:00
|
|
|
_filterRect = { w->windowPos.x, w->windowPos.y + UpdateButtonDims.height, w->windowPos.x + w->width - 1,
|
|
|
|
w->windowPos.y + MenuButtonDims.height + UpdateButtonDims.height - 1 };
|
2020-08-02 23:38:00 +02:00
|
|
|
if (OpenRCT2::GetContext()->HasNewVersionInfo())
|
|
|
|
{
|
|
|
|
w->enabled_widgets |= (1ULL << WIDX_NEW_VERSION);
|
|
|
|
w->widgets[WIDX_NEW_VERSION].type = WWT_BUTTON;
|
|
|
|
_filterRect.Point1.y = w->windowPos.y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_title_menu_paint(rct_window* w, rct_drawpixelinfo* dpi)
|
2014-04-09 15:43:27 +02:00
|
|
|
{
|
2020-08-02 23:38:00 +02:00
|
|
|
gfx_filter_rect(dpi, _filterRect, PALETTE_51);
|
2020-11-04 05:52:23 +01:00
|
|
|
WindowDrawWidgets(w, dpi);
|
2014-04-21 11:27:48 +02:00
|
|
|
}
|