OpenRCT2/src/openrct2-ui/windows/TitleMenu.cpp

239 lines
8.7 KiB
C++
Raw Normal View History

/*****************************************************************************
2020-07-21 15:04:34 +02:00
* 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.
*****************************************************************************/
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>
#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>
#include <openrct2/PlatformEnvironment.h>
Split actions hpp files into separate h and cpp files (#13548) * Split up SmallSceneryPlace/Remove Added undo function for Remove Scenery * Refactor: Balloon and Banner actions hpp=>h/cpp * Refactor: rename all action *.hpp files to *.cpp This is preparation for separation in later commits. Note that without the complete set of commits in this branch, the code will not build. * Refactor Clear, Climate, Custom, and Footpath actions hpp=>h/cpp * VSCode: add src subdirectories to includePath * Refactor Guest actions hpp=>h/cpp * Refactor Land actions hpp=>h/cpp * Refactor LargeScenery actions hpp=>h/cpp * Refactor Load, Maze, Network actions hpp=>h/cpp * Refactor Park actions hpp=>h/cpp * Refactor/style: move private function declarations in actions *.h Previous action .h files included private function declarations with private member variables, before public function declarations. This commit re-orders the header files to the following order: - public member variables - private member variables - public functions - private functions * Refactor Pause action hpp=>h/cpp * Refactor Peep, Place, Player actions hpp=>h/cpp * Refactor Ride actions hpp=>h/cpp * Refactor Scenario, Set*, Sign* actions hpp=>h/cpp * Refactor SmallScenerySetColourAction hpp=>h/cpp * Refactor Staff actions hpp=>h/cpp * Refactor Surface, Tile, Track* actions hpp=>h/cpp * Refactor Wall and Water actions hpp=>h/cpp * Fix various includes and other compile errors Update includes for tests. Move static function declarations to .h files Add explicit includes to various files that were previously implicit (the required header was a nested include in an action hpp file, and the action .h file does not include that header) Move RideSetStatus string enum to the cpp file to avoid unused imports * Xcode: modify project file for actions refactor * Cleanup whitespace and end-of-file newlines Co-authored-by: duncanspumpkin <duncans_pumpkin@hotmail.co.uk>
2020-12-10 07:39:10 +01:00
#include <openrct2/actions/LoadOrQuitAction.h>
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>
#include <openrct2/sprites.h>
#include <openrct2/ui/UiContext.h>
// clang-format off
enum {
WIDX_START_NEW_GAME,
WIDX_CONTINUE_SAVED_GAME,
WIDX_MULTIPLAYER,
WIDX_GAME_TOOLS,
WIDX_NEW_VERSION,
};
static ScreenRect _filterRect;
static constexpr ScreenSize MenuButtonDims = { 82, 82 };
static constexpr ScreenSize UpdateButtonDims = { MenuButtonDims.width * 4, 28 };
static rct_widget window_title_menu_widgets[] = {
MakeWidget({0, UpdateButtonDims.height}, MenuButtonDims, WindowWidgetType::ImgBtn, WindowColour::Tertiary, SPR_MENU_NEW_GAME, STR_START_NEW_GAME_TIP),
MakeWidget({0, UpdateButtonDims.height}, MenuButtonDims, WindowWidgetType::ImgBtn, WindowColour::Tertiary, SPR_MENU_LOAD_GAME, STR_CONTINUE_SAVED_GAME_TIP),
MakeWidget({0, UpdateButtonDims.height}, MenuButtonDims, WindowWidgetType::ImgBtn, WindowColour::Tertiary, SPR_G2_MENU_MULTIPLAYER, STR_SHOW_MULTIPLAYER_TIP),
MakeWidget({0, UpdateButtonDims.height}, MenuButtonDims, WindowWidgetType::ImgBtn, WindowColour::Tertiary, SPR_MENU_TOOLBOX, STR_GAME_TOOLS_TIP),
MakeWidget({0, 0}, UpdateButtonDims, WindowWidgetType::Empty, WindowColour::Secondary, STR_UPDATE_AVAILABLE),
{ WIDGETS_END },
};
2017-05-01 15:41:45 +02:00
static void window_title_menu_mouseup(rct_window *w, rct_widgetindex widgetIndex);
static void window_title_menu_mousedown(rct_window *w, rct_widgetindex widgetIndex, rct_widget* widget);
static void window_title_menu_dropdown(rct_window *w, rct_widgetindex widgetIndex, int32_t dropdownIndex);
static void window_title_menu_cursor(rct_window *w, rct_widgetindex widgetIndex, const ScreenCoordsXY& screenCoords, CursorID *cursorId);
static void window_title_menu_invalidate(rct_window *w);
static void window_title_menu_paint(rct_window *w, rct_drawpixelinfo *dpi);
2014-04-09 15:43:27 +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;
});
// clang-format on
/**
* 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()
{
rct_window* window;
const uint16_t windowHeight = MenuButtonDims.height + UpdateButtonDims.height;
window = WindowCreate(
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);
window->widgets = window_title_menu_widgets;
2018-06-22 23:21:44 +02:00
window->enabled_widgets
= ((1ULL << WIDX_START_NEW_GAME) | (1ULL << WIDX_CONTINUE_SAVED_GAME) |
#ifndef DISABLE_NETWORK
(1ULL << WIDX_MULTIPLAYER) |
#endif
(1ULL << WIDX_GAME_TOOLS));
rct_widgetindex i = 0;
int32_t x = 0;
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
{
widget->left = x;
widget->right = x + MenuButtonDims.width - 1;
x += MenuButtonDims.width;
2018-06-22 23:21:44 +02:00
}
else
{
widget->type = WindowWidgetType::Empty;
}
i++;
}
window->width = x;
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;
window->colours[1] = TRANSLUCENT(COLOUR_LIGHT_ORANGE);
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)
{
context_load_park_from_file(path);
game_load_scripts();
}
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;
case WIDX_NEW_VERSION:
context_open_window_view(WV_NEW_VERSION_INFO);
break;
}
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)
{
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;
WindowDropdownShowText(
{ w->windowPos.x + widget->left, w->windowPos.y + widget->top }, widget->height() + 1, TRANSLUCENT(w->colours[0]),
Dropdown::Flag::StayOpen, 5);
}
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;
case 4:
{
auto context = OpenRCT2::GetContext();
2018-09-04 18:05:11 +02:00
auto env = context->GetPlatformEnvironment();
auto uiContext = context->GetUiContext();
uiContext->OpenFolder(env->GetDirectoryPath(OpenRCT2::DIRBASE::USER));
break;
}
}
}
2014-04-09 15:43:27 +02:00
}
static void window_title_menu_cursor(
rct_window* w, rct_widgetindex widgetIndex, const ScreenCoordsXY& screenCoords, CursorID* cursorId)
2014-04-09 15:43:27 +02:00
{
gTooltipTimeout = 2000;
2014-04-09 15:43:27 +02:00
}
static void window_title_menu_invalidate(rct_window* w)
{
_filterRect = { w->windowPos.x, w->windowPos.y + UpdateButtonDims.height, w->windowPos.x + w->width - 1,
w->windowPos.y + MenuButtonDims.height + UpdateButtonDims.height - 1 };
if (OpenRCT2::GetContext()->HasNewVersionInfo())
{
w->enabled_widgets |= (1ULL << WIDX_NEW_VERSION);
w->widgets[WIDX_NEW_VERSION].type = WindowWidgetType::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
{
gfx_filter_rect(dpi, _filterRect, FilterPaletteID::Palette51);
WindowDrawWidgets(w, dpi);
}