Files
OpenRCT2-Web/src/openrct2-ui/WindowManager.cpp
T

293 lines
10 KiB
C++
Raw Normal View History

#pragma region Copyright (c) 2014-2017 OpenRCT2 Developers
/*****************************************************************************
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
*
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* A full copy of the GNU General Public License can be found in licence.txt
*****************************************************************************/
#pragma endregion
#include <openrct2/ui/WindowManager.h>
2017-08-06 05:22:00 +02:00
#include <openrct2-ui/windows/Window.h>
2017-09-15 21:57:57 +02:00
#include <openrct2/core/Console.hpp>
2017-10-07 01:28:00 +02:00
#include <openrct2/config/Config.h>
2017-10-10 12:38:52 +02:00
#include "input/Input.h"
#include "input/KeyboardShortcuts.h"
#include "WindowManager.h"
using namespace OpenRCT2::Ui;
class WindowManager final : public IWindowManager
{
public:
2017-09-10 11:02:16 +02:00
void Init() override
{
window_guest_list_init_vars();
2017-10-07 01:28:00 +02:00
window_new_ride_init_vars();
2017-09-10 11:02:16 +02:00
}
rct_window * OpenWindow(rct_windowclass wc) override
{
2017-10-07 01:28:00 +02:00
switch (wc)
{
2017-08-06 05:22:00 +02:00
case WC_ABOUT:
return window_about_open();
case WC_CHANGELOG:
return window_changelog_open();
case WC_CHEATS:
return window_cheats_open();
2017-08-12 23:06:12 +02:00
case WC_CLEAR_SCENERY:
return window_clear_scenery_open();
2017-08-06 05:22:00 +02:00
case WC_CUSTOM_CURRENCY_CONFIG:
return custom_currency_window_open();
case WC_DEBUG_PAINT:
return window_debug_paint_open();
2017-08-12 23:06:12 +02:00
case WC_EDITOR_INVENTION_LIST:
return window_editor_inventions_list_open();
case WC_EDTIOR_OBJECTIVE_OPTIONS:
return window_editor_objective_options_open();
case WC_EDITOR_SCENARIO_OPTIONS:
return window_editor_scenario_options_open();
2017-09-05 20:55:18 +02:00
case WC_FINANCES:
return window_finances_open();
2017-08-12 23:06:12 +02:00
case WC_FOOTPATH:
return window_footpath_open();
2017-09-20 20:28:57 +02:00
case WC_GUEST_LIST:
return window_guest_list_open();
2017-08-12 23:06:12 +02:00
case WC_LAND:
return window_land_open();
2017-08-06 05:22:00 +02:00
case WC_LAND_RIGHTS:
return window_land_rights_open();
2017-08-12 23:06:12 +02:00
case WC_MAIN_WINDOW:
return window_main_open();
2017-10-06 23:03:48 +02:00
case WC_MAP:
return window_map_open();
2017-08-06 05:22:00 +02:00
case WC_MAPGEN:
return window_mapgen_open();
case WC_MULTIPLAYER:
return window_multiplayer_open();
case WC_MUSIC_CREDITS:
return window_music_credits_open();
2017-10-07 01:28:00 +02:00
case WC_CONSTRUCT_RIDE:
return window_new_ride_open();
2017-09-05 20:55:18 +02:00
case WC_PARK_INFORMATION:
return window_park_entrance_open();
2017-08-06 05:22:00 +02:00
case WC_RECENT_NEWS:
return window_news_open();
2017-10-07 01:28:00 +02:00
case WC_RESEARCH:
return window_research_open();
2017-10-08 22:15:41 +02:00
case WC_RIDE_LIST:
return window_ride_list_open();
2017-08-06 05:22:00 +02:00
case WC_NOTIFICATION_OPTIONS:
return window_news_options_open();
case WC_OPTIONS:
return window_options_open();
case WC_SAVE_PROMPT:
return window_save_prompt_open();
case WC_SERVER_LIST:
return window_server_list_open();
case WC_SERVER_START:
return window_server_start_open();
case WC_KEYBOARD_SHORTCUT_LIST:
return window_shortcut_keys_open();
2017-08-12 23:06:12 +02:00
case WC_STAFF_LIST:
return window_staff_list_open();
2017-08-06 05:22:00 +02:00
case WC_THEMES:
return window_themes_open();
case WC_TITLE_EXIT:
return window_title_exit_open();
case WC_TITLE_LOGO:
return window_title_logo_open();
case WC_TITLE_MENU:
return window_title_menu_open();
case WC_TITLE_OPTIONS:
return window_title_options_open();
2017-08-12 23:06:12 +02:00
case WC_VIEW_CLIPPING:
return window_view_clipping_open();
2017-08-06 05:22:00 +02:00
case WC_VIEWPORT:
return window_viewport_open();
2017-08-12 23:06:12 +02:00
case WC_WATER:
return window_water_open();
default:
2017-09-15 21:57:57 +02:00
Console::Error::WriteLine("Unhandled window class (%d)", wc);
return nullptr;
}
}
2017-06-11 16:31:54 +01:00
2017-09-05 20:55:18 +02:00
rct_window * OpenView(uint8 view) override
{
2017-10-07 01:28:00 +02:00
switch (view)
{
2017-09-05 20:55:18 +02:00
case WV_PARK_AWARDS:
return window_park_awards_open();
case WV_PARK_RATING:
return window_park_rating_open();
case WV_PARK_OBJECTIVE:
return window_park_objective_open();
case WV_PARK_GUESTS:
return window_park_guests_open();
case WV_FINANCES_RESEARCH:
return window_finances_research_open();
2017-10-07 01:28:00 +02:00
case WV_RIDE_RESEARCH:
if (gConfigInterface.toolbar_show_research)
{
return this->OpenWindow(WC_RESEARCH);
}
else
{
return window_new_ride_open_research();
}
2017-10-21 18:12:15 +02:00
case WV_MAZE_CONSTRUCTION:
return window_maze_construction_open();
2017-09-05 20:55:18 +02:00
default:
return nullptr;
}
}
2017-09-06 15:09:18 +02:00
rct_window * OpenDetails(uint8 type, sint32 id) override
{
switch (type)
{
case WD_BANNER:
return window_banner_open(id);
case WD_DEMOLISH_RIDE:
return window_ride_demolish_prompt_open(id);
case WD_NEW_CAMPAIGN:
return window_new_campaign_open(id);
2017-09-06 15:09:18 +02:00
case WD_SIGN:
return window_sign_open(id);
case WD_SIGN_SMALL:
return window_sign_small_open(id);
case WD_PLAYER:
return window_player_open(id);
default:
return nullptr;
}
}
rct_window * ShowError(rct_string_id title, rct_string_id message) override
{
return window_error_open(title, message);
}
2017-09-05 20:55:18 +02:00
2017-09-10 11:02:16 +02:00
rct_window * OpenIntent(Intent * intent) override
{
2017-10-07 01:28:00 +02:00
switch (intent->GetWindowClass())
{
2017-10-06 23:21:00 +02:00
case WC_PEEP:
return window_guest_open((rct_peep*)intent->GetPointerExtra(INTENT_EXTRA_PEEP));
2017-09-10 11:02:16 +02:00
case WC_FIRE_PROMPT:
2017-09-12 21:21:39 +02:00
return window_staff_fire_prompt_open((rct_peep*)intent->GetPointerExtra(INTENT_EXTRA_PEEP));
2017-09-10 11:02:16 +02:00
case WC_INSTALL_TRACK:
2017-10-07 13:53:06 +02:00
return window_install_track_open(intent->GetStringExtra(INTENT_EXTRA_PATH).c_str());
2017-09-10 11:02:16 +02:00
case WC_GUEST_LIST:
2017-09-12 21:21:39 +02:00
return window_guest_list_open_with_filter(intent->GetSIntExtra(INTENT_EXTRA_GUEST_LIST_FILTER), intent->GetSIntExtra(INTENT_EXTRA_RIDE_ID));
2017-09-15 21:57:41 +02:00
case WC_LOADSAVE:
{
uint32 type = intent->GetUIntExtra(INTENT_EXTRA_LOADSAVE_TYPE);
2017-10-07 13:53:06 +02:00
std::string defaultName = intent->GetStringExtra(INTENT_EXTRA_PATH);
2017-09-20 00:13:19 +02:00
loadsave_callback callback = (loadsave_callback) intent->GetPointerExtra(INTENT_EXTRA_CALLBACK);
2017-10-07 13:53:06 +02:00
rct_window *w = window_loadsave_open(type, defaultName.c_str());
2017-09-15 21:57:41 +02:00
window_loadsave_set_loadsave_callback(callback);
2017-09-10 11:02:16 +02:00
2017-09-15 21:57:41 +02:00
return w;
}
case WC_MANAGE_TRACK_DESIGN:
return window_track_manage_open((track_design_file_ref *) intent->GetPointerExtra(INTENT_EXTRA_TRACK_DESIGN));
2017-10-21 16:03:33 +02:00
case WC_RIDE:
return window_ride_main_open(intent->GetSIntExtra(INTENT_EXTRA_RIDE_ID));
2017-09-15 21:57:41 +02:00
case WC_TRACK_DESIGN_PLACE:
return window_track_place_open((track_design_file_ref *) intent->GetPointerExtra(INTENT_EXTRA_TRACK_DESIGN));
2017-10-21 16:37:30 +02:00
case WC_TRACK_DESIGN_LIST:
{
ride_list_item rideItem;
rideItem.type = intent->GetUIntExtra(INTENT_EXTRA_RIDE_TYPE);
rideItem.entry_index = intent->GetUIntExtra(INTENT_EXTRA_RIDE_ENTRY_INDEX);
return window_track_list_open(rideItem);
}
2017-09-15 21:57:41 +02:00
case WC_SCENARIO_SELECT:
return window_scenarioselect_open((scenarioselect_callback) intent->GetPointerExtra(INTENT_EXTRA_CALLBACK));
2017-10-21 16:03:33 +02:00
case WD_VEHICLE:
return window_ride_open_vehicle((rct_vehicle *) intent->GetPointerExtra(INTENT_EXTRA_VEHICLE));
case WD_TRACK:
return window_ride_open_track((rct_tile_element *) intent->GetPointerExtra(INTENT_EXTRA_TILE_ELEMENT));
2017-10-07 01:28:00 +02:00
case INTENT_ACTION_NEW_RIDE_OF_TYPE:
{
// Open ride list window
auto w = window_new_ride_open();
// Switch to right tab and scroll to ride location
ride_list_item rideItem;
rideItem.type = intent->GetUIntExtra(INTENT_EXTRA_RIDE_TYPE);
rideItem.entry_index = intent->GetUIntExtra(INTENT_EXTRA_RIDE_ENTRY_INDEX);
window_new_ride_focus(rideItem);
return w;
}
break;
2017-09-10 11:02:16 +02:00
default:
2017-09-15 21:57:57 +02:00
Console::Error::WriteLine("Unhandled window class for intent (%d)", intent->GetWindowClass());
2017-09-10 11:02:16 +02:00
return nullptr;
}
}
2017-10-06 23:03:48 +02:00
void BroadcastIntent(Intent * intent) override
{
2017-10-07 01:28:00 +02:00
switch (intent->GetWindowClass())
{
2017-10-06 23:03:48 +02:00
case INTENT_ACTION_MAP:
window_map_reset();
break;
2017-10-07 01:28:00 +02:00
case INTENT_ACTION_REFRESH_NEW_RIDES:
window_new_ride_init_vars();
break;
2017-10-08 22:15:41 +02:00
case INTENT_ACTION_REFRESH_RIDE_LIST:
{
auto window = window_find_by_class(WC_RIDE_LIST);
if (window != nullptr)
{
window_ride_list_refresh_list(window);
}
break;
}
2017-10-21 18:12:15 +02:00
case INTENT_ACTION_UPDATE_MAZE_CONSTRUCTION:
window_maze_construction_update_pressed_widgets();
break;
2017-10-06 23:03:48 +02:00
}
}
2017-10-21 17:57:37 +02:00
void UpdateMapTooltip() override
{
window_map_tooltip_update_visibility();
}
2017-06-11 19:04:50 +01:00
void HandleKeyboard(bool isTitle) override
2017-06-11 16:31:54 +01:00
{
2017-06-11 19:04:50 +01:00
input_handle_keyboard(isTitle);
2017-06-11 16:31:54 +01:00
}
std::string GetKeyboardShortcutString(sint32 shortcut) override
{
utf8 buffer[256];
keyboard_shortcuts_format_string(buffer, sizeof(buffer), shortcut);
return std::string(buffer);
}
};
IWindowManager * OpenRCT2::Ui::CreateWindowManager()
{
return new WindowManager();
}