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

230 lines
7.2 KiB
C++
Raw Normal View History

/*****************************************************************************
* Copyright (c) 2014-2019 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>
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>
#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
};
static rct_widget window_title_menu_widgets[] = {
{ WWT_IMGBTN, 2, 0, 0, 0, 81, SPR_MENU_NEW_GAME, STR_START_NEW_GAME_TIP },
{ WWT_IMGBTN, 2, 0, 0, 0, 81, SPR_MENU_LOAD_GAME, STR_CONTINUE_SAVED_GAME_TIP },
{ WWT_IMGBTN, 2, 0, 0, 0, 81, SPR_G2_MENU_MULTIPLAYER, STR_SHOW_MULTIPLAYER_TIP },
{ WWT_IMGBTN, 2, 0, 0, 0, 81, SPR_MENU_TOOLBOX, STR_GAME_TOOLS_TIP },
{ 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, int32_t x, int32_t y, int32_t *cursorId);
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 = {
2017-08-15 10:07:44 +02:00
nullptr,
window_title_menu_mouseup,
2017-08-15 10:07:44 +02:00
nullptr,
window_title_menu_mousedown,
window_title_menu_dropdown,
2017-08-15 10:07:44 +02:00
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
window_title_menu_cursor,
2017-08-15 10:07:44 +02:00
nullptr,
nullptr,
window_title_menu_paint,
2017-08-15 10:07:44 +02:00
nullptr
};
// 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;
window = window_create(
0, context_get_height() - 154, 0, 100, &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
= ((1 << WIDX_START_NEW_GAME) | (1 << WIDX_CONTINUE_SAVED_GAME) |
#ifndef DISABLE_NETWORK
2018-06-22 23:21:44 +02:00
(1 << WIDX_MULTIPLAYER) |
#endif
2018-06-22 23:21:44 +02:00
(1 << WIDX_GAME_TOOLS));
rct_widgetindex i = 0;
int32_t x = 0;
2018-06-22 23:21:44 +02:00
for (rct_widget* widget = window->widgets; widget->type != WWT_LAST; widget++)
{
if (widget_is_enabled(window, i))
{
widget->left = x;
widget->right = x + 81;
x += 82;
2018-06-22 23:21:44 +02:00
}
else
{
widget->type = WWT_EMPTY;
}
i++;
}
window->width = x;
window->x = (context_get_width() - window->width) / 2;
window_init_scroll_widgets(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);
}
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;
}
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;
window_dropdown_show_text(
w->x + widget->left, w->y + widget->top, widget->bottom - widget->top + 1, TRANSLUCENT(w->colours[0]),
DROPDOWN_FLAG_STAY_OPEN, 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
}
2018-06-22 23:21:44 +02:00
static void window_title_menu_cursor(rct_window* w, rct_widgetindex widgetIndex, int32_t x, int32_t y, int32_t* cursorId)
2014-04-09 15:43:27 +02:00
{
gTooltipTimeout = 2000;
2014-04-09 15:43:27 +02:00
}
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, w->x, w->y, w->x + w->width - 1, w->y + 82 - 1, PALETTE_51);
window_draw_widgets(w, dpi);
}