OpenRCT2/src/openrct2/title/TitleScreen.cpp

332 lines
8.3 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
2017-07-23 00:42:14 +02:00
#include "../config/Config.h"
#include "../Context.h"
2017-07-23 00:42:14 +02:00
#include "../core/Console.hpp"
2017-06-09 00:02:39 +02:00
#include "../interface/Screenshot.h"
#include "../network/network.h"
2016-12-16 00:16:02 +01:00
#include "../OpenRCT2.h"
#include "../scenario/ScenarioRepository.h"
#include "TitleScreen.h"
#include "TitleSequence.h"
#include "TitleSequenceManager.h"
#include "TitleSequencePlayer.h"
#include "../audio/audio.h"
#include "../drawing/drawing.h"
#include "../game.h"
#include "../input.h"
#include "../interface/viewport.h"
#include "../interface/window.h"
#include "../localisation/localisation.h"
2017-07-23 00:42:14 +02:00
// TODO Remove when no longer required.
static TitleScreen * _singleton = nullptr;
2017-07-23 00:42:14 +02:00
TitleScreen::TitleScreen()
{
_singleton = this;
}
TitleScreen::~TitleScreen()
{
delete _sequencePlayer;
2017-07-23 00:42:14 +02:00
_singleton = nullptr;
}
ITitleSequencePlayer * TitleScreen::GetSequencePlayer()
{
return _sequencePlayer;
}
uint16 TitleScreen::GetCurrentSequence()
{
return _currentSequence;
}
Feature: Preview title sequences in-game Title sequences can now be played back in-game, allowing for much easier editing. Improved title sequence playback in general. Clicking play while on a different title sequence will play the new one. Clicking stop will make the title screen go back to the config title sequence. And the closing the title sequence window will also make the game go back to the config title sequence, and reload the sequence if it was modified. Changes made to title sequences in-game are now correctly loaded in the title screen. Starting a title sequence within the editor will now always reset it even if it's the current playing sequence. (Not for playing in the editor though). Get Location in title sequence command editor now has 100% accuracy compared to before where it would usually get some offset value. Added `get_map_coordinates_from_pos_window` which will allow getting the viewport coordinates of a specific window even if the input coordinates are under another window. This has use with getting 2D positions from the main window without the other windows getting in the way. Options window will now always specify the config title sequence in the dropdown and not the current title sequence. Made a global variable `gLoadKeepWindowsOpen`, in game.h to keep windows open when loading a park. When loading a title sequence park in-game. The sequence player will force-close all park-specific windows ahead of time. Skipping while testing title sequences no longer needs to reload the park if the current playback position is already before the target position and ahead of the load position. Added changelog entry.
2017-10-30 12:07:01 +01:00
void TitleScreen::SetCurrentSequence(uint16 value, bool loadSequence)
2017-07-23 00:42:14 +02:00
{
_currentSequence = value;
Feature: Preview title sequences in-game Title sequences can now be played back in-game, allowing for much easier editing. Improved title sequence playback in general. Clicking play while on a different title sequence will play the new one. Clicking stop will make the title screen go back to the config title sequence. And the closing the title sequence window will also make the game go back to the config title sequence, and reload the sequence if it was modified. Changes made to title sequences in-game are now correctly loaded in the title screen. Starting a title sequence within the editor will now always reset it even if it's the current playing sequence. (Not for playing in the editor though). Get Location in title sequence command editor now has 100% accuracy compared to before where it would usually get some offset value. Added `get_map_coordinates_from_pos_window` which will allow getting the viewport coordinates of a specific window even if the input coordinates are under another window. This has use with getting 2D positions from the main window without the other windows getting in the way. Options window will now always specify the config title sequence in the dropdown and not the current title sequence. Made a global variable `gLoadKeepWindowsOpen`, in game.h to keep windows open when loading a park. When loading a title sequence park in-game. The sequence player will force-close all park-specific windows ahead of time. Skipping while testing title sequences no longer needs to reload the park if the current playback position is already before the target position and ahead of the load position. Added changelog entry.
2017-10-30 12:07:01 +01:00
if (loadSequence)
{
TryLoadSequence();
}
2017-07-23 00:42:14 +02:00
}
bool TitleScreen::ShouldHideVersionInfo()
{
return _hideVersionInfo;
}
void TitleScreen::SetHideVersionInfo(bool value)
{
_hideVersionInfo = value;
}
void TitleScreen::Load()
{
log_verbose("TitleScreen::Load()");
if (game_is_paused())
{
pause_toggle();
}
gScreenFlags = SCREEN_FLAGS_TITLE_DEMO;
gScreenAge = 0;
gCurrentLoadedPath[0] = '\0';
2017-07-23 00:42:14 +02:00
network_close();
audio_stop_all_music_and_sounds();
game_init_all(150);
viewport_init_all();
2017-08-12 23:06:12 +02:00
context_open_window(WC_MAIN_WINDOW);
2017-07-23 00:42:14 +02:00
CreateWindows();
TitleInitialise();
audio_start_title_music();
if (gOpenRCT2ShowChangelog)
{
gOpenRCT2ShowChangelog = false;
2017-08-06 05:22:00 +02:00
context_open_window(WC_CHANGELOG);
2017-07-23 00:42:14 +02:00
}
if (_sequencePlayer != nullptr)
{
Feature: Preview title sequences in-game Title sequences can now be played back in-game, allowing for much easier editing. Improved title sequence playback in general. Clicking play while on a different title sequence will play the new one. Clicking stop will make the title screen go back to the config title sequence. And the closing the title sequence window will also make the game go back to the config title sequence, and reload the sequence if it was modified. Changes made to title sequences in-game are now correctly loaded in the title screen. Starting a title sequence within the editor will now always reset it even if it's the current playing sequence. (Not for playing in the editor though). Get Location in title sequence command editor now has 100% accuracy compared to before where it would usually get some offset value. Added `get_map_coordinates_from_pos_window` which will allow getting the viewport coordinates of a specific window even if the input coordinates are under another window. This has use with getting 2D positions from the main window without the other windows getting in the way. Options window will now always specify the config title sequence in the dropdown and not the current title sequence. Made a global variable `gLoadKeepWindowsOpen`, in game.h to keep windows open when loading a park. When loading a title sequence park in-game. The sequence player will force-close all park-specific windows ahead of time. Skipping while testing title sequences no longer needs to reload the park if the current playback position is already before the target position and ahead of the load position. Added changelog entry.
2017-10-30 12:07:01 +01:00
_sequencePlayer->Begin(_currentSequence);
2017-07-23 00:42:14 +02:00
// Force the title sequence to load / update so we
// don't see a blank screen for a split second.
TryLoadSequence();
_sequencePlayer->Update();
}
log_verbose("TitleScreen::Load() finished");
}
void TitleScreen::Update()
{
2017-07-23 00:42:14 +02:00
gInUpdateCode = true;
screenshot_check();
title_handle_keyboard_input();
if (game_is_not_paused())
{
TryLoadSequence();
_sequencePlayer->Update();
sint32 numUpdates = 1;
if (gGameSpeed > 1) {
numUpdates = 1 << (gGameSpeed - 1);
}
for (sint32 i = 0; i < numUpdates; i++)
{
game_logic_update();
}
update_palette_effects();
// update_rain_animation();
}
input_set_flag(INPUT_FLAG_VIEWPORT_SCROLLING, false);
window_map_tooltip_update_visibility();
window_dispatch_update_all();
gSavedAge++;
game_handle_input();
gInUpdateCode = false;
}
2017-07-23 00:42:14 +02:00
void TitleScreen::ChangeSequence(sint32 preset)
{
sint32 count = (sint32)title_sequence_manager_get_count();
if (preset < 0 || preset >= count)
{
return;
}
const utf8 * configId = title_sequence_manager_get_config_id(preset);
SafeFree(gConfigInterface.current_title_sequence_preset);
gConfigInterface.current_title_sequence_preset = _strdup(configId);
2017-07-23 00:42:14 +02:00
_currentSequence = preset;
window_invalidate_all();
}
/**
2017-07-23 00:42:14 +02:00
* Creates the windows shown on the title screen; New game, load game,
* tutorial, toolbox and exit.
*/
2017-07-23 00:42:14 +02:00
void TitleScreen::CreateWindows()
{
2017-08-06 05:22:00 +02:00
context_open_window(WC_TITLE_MENU);
context_open_window(WC_TITLE_EXIT);
context_open_window(WC_TITLE_OPTIONS);
context_open_window(WC_TITLE_LOGO);
2017-07-23 00:42:14 +02:00
window_resize_gui(context_get_width(), context_get_height());
_hideVersionInfo = false;
}
void TitleScreen::TitleInitialise()
{
if (_sequencePlayer == nullptr)
{
IScenarioRepository * scenarioRepository = GetScenarioRepository();
_sequencePlayer = CreateTitleSequencePlayer(scenarioRepository);
}
Feature: Preview title sequences in-game Title sequences can now be played back in-game, allowing for much easier editing. Improved title sequence playback in general. Clicking play while on a different title sequence will play the new one. Clicking stop will make the title screen go back to the config title sequence. And the closing the title sequence window will also make the game go back to the config title sequence, and reload the sequence if it was modified. Changes made to title sequences in-game are now correctly loaded in the title screen. Starting a title sequence within the editor will now always reset it even if it's the current playing sequence. (Not for playing in the editor though). Get Location in title sequence command editor now has 100% accuracy compared to before where it would usually get some offset value. Added `get_map_coordinates_from_pos_window` which will allow getting the viewport coordinates of a specific window even if the input coordinates are under another window. This has use with getting 2D positions from the main window without the other windows getting in the way. Options window will now always specify the config title sequence in the dropdown and not the current title sequence. Made a global variable `gLoadKeepWindowsOpen`, in game.h to keep windows open when loading a park. When loading a title sequence park in-game. The sequence player will force-close all park-specific windows ahead of time. Skipping while testing title sequences no longer needs to reload the park if the current playback position is already before the target position and ahead of the load position. Added changelog entry.
2017-10-30 12:07:01 +01:00
size_t seqId = title_get_config_sequence();
if (seqId == SIZE_MAX)
{
seqId = title_sequence_manager_get_index_for_config_id("*OPENRCT2");
if (seqId == SIZE_MAX)
{
seqId = 0;
}
}
2017-01-04 22:17:08 +01:00
title_sequence_change_preset((sint32)seqId);
TryLoadSequence();
}
2017-07-23 00:42:14 +02:00
void TitleScreen::TryLoadSequence()
{
2017-07-23 00:42:14 +02:00
if (_loadedTitleSequenceId != _currentSequence)
{
uint16 numSequences = (uint16)TitleSequenceManager::GetCount();
if (numSequences > 0)
{
2017-07-23 00:42:14 +02:00
uint16 targetSequence = _currentSequence;
do
{
if (_sequencePlayer->Begin(targetSequence) && _sequencePlayer->Update())
{
_loadedTitleSequenceId = targetSequence;
2017-07-23 00:42:14 +02:00
_currentSequence = targetSequence;
gfx_invalidate_screen();
return;
}
targetSequence = (targetSequence + 1) % numSequences;
}
2017-07-23 00:42:14 +02:00
while (targetSequence != _currentSequence);
}
Console::Error::WriteLine("Unable to play any title sequences.");
_sequencePlayer->Eject();
2017-07-23 00:42:14 +02:00
_currentSequence = UINT16_MAX;
_loadedTitleSequenceId = UINT16_MAX;
game_init_all(150);
}
}
extern "C"
{
void title_load()
{
2017-07-23 00:42:14 +02:00
if (_singleton != nullptr)
{
2017-07-23 00:42:14 +02:00
_singleton->Load();
}
}
void title_create_windows()
{
2017-07-23 00:42:14 +02:00
if (_singleton != nullptr)
{
_singleton->CreateWindows();
}
}
2017-07-23 00:42:14 +02:00
void * title_get_sequence_player()
{
2017-07-23 00:42:14 +02:00
void * result = nullptr;
if (_singleton != nullptr)
{
2017-07-23 00:42:14 +02:00
result = _singleton->GetSequencePlayer();
}
2017-07-23 00:42:14 +02:00
return result;
}
2017-07-23 00:42:14 +02:00
void title_sequence_change_preset(sint32 preset)
{
if (_singleton != nullptr)
{
_singleton->ChangeSequence(preset);
}
}
2017-07-23 00:42:14 +02:00
bool title_should_hide_version_info()
{
bool result = false;
if (_singleton != nullptr)
{
result = _singleton->ShouldHideVersionInfo();
}
return result;
}
2017-07-23 00:42:14 +02:00
void title_set_hide_version_info(bool value)
{
if (_singleton != nullptr)
{
_singleton->SetHideVersionInfo(value);
}
}
Feature: Preview title sequences in-game Title sequences can now be played back in-game, allowing for much easier editing. Improved title sequence playback in general. Clicking play while on a different title sequence will play the new one. Clicking stop will make the title screen go back to the config title sequence. And the closing the title sequence window will also make the game go back to the config title sequence, and reload the sequence if it was modified. Changes made to title sequences in-game are now correctly loaded in the title screen. Starting a title sequence within the editor will now always reset it even if it's the current playing sequence. (Not for playing in the editor though). Get Location in title sequence command editor now has 100% accuracy compared to before where it would usually get some offset value. Added `get_map_coordinates_from_pos_window` which will allow getting the viewport coordinates of a specific window even if the input coordinates are under another window. This has use with getting 2D positions from the main window without the other windows getting in the way. Options window will now always specify the config title sequence in the dropdown and not the current title sequence. Made a global variable `gLoadKeepWindowsOpen`, in game.h to keep windows open when loading a park. When loading a title sequence park in-game. The sequence player will force-close all park-specific windows ahead of time. Skipping while testing title sequences no longer needs to reload the park if the current playback position is already before the target position and ahead of the load position. Added changelog entry.
2017-10-30 12:07:01 +01:00
uint16 title_get_config_sequence()
{
return (uint16)title_sequence_manager_get_index_for_config_id(gConfigInterface.current_title_sequence_preset);
}
2017-07-23 00:42:14 +02:00
uint16 title_get_current_sequence()
{
uint16 result = 0;
if (_singleton != nullptr)
{
result = _singleton->GetCurrentSequence();
}
return result;
}
Feature: Preview title sequences in-game Title sequences can now be played back in-game, allowing for much easier editing. Improved title sequence playback in general. Clicking play while on a different title sequence will play the new one. Clicking stop will make the title screen go back to the config title sequence. And the closing the title sequence window will also make the game go back to the config title sequence, and reload the sequence if it was modified. Changes made to title sequences in-game are now correctly loaded in the title screen. Starting a title sequence within the editor will now always reset it even if it's the current playing sequence. (Not for playing in the editor though). Get Location in title sequence command editor now has 100% accuracy compared to before where it would usually get some offset value. Added `get_map_coordinates_from_pos_window` which will allow getting the viewport coordinates of a specific window even if the input coordinates are under another window. This has use with getting 2D positions from the main window without the other windows getting in the way. Options window will now always specify the config title sequence in the dropdown and not the current title sequence. Made a global variable `gLoadKeepWindowsOpen`, in game.h to keep windows open when loading a park. When loading a title sequence park in-game. The sequence player will force-close all park-specific windows ahead of time. Skipping while testing title sequences no longer needs to reload the park if the current playback position is already before the target position and ahead of the load position. Added changelog entry.
2017-10-30 12:07:01 +01:00
void title_set_current_sequence(uint16 value, bool loadSequence)
2017-07-23 00:42:14 +02:00
{
if (_singleton != nullptr)
{
Feature: Preview title sequences in-game Title sequences can now be played back in-game, allowing for much easier editing. Improved title sequence playback in general. Clicking play while on a different title sequence will play the new one. Clicking stop will make the title screen go back to the config title sequence. And the closing the title sequence window will also make the game go back to the config title sequence, and reload the sequence if it was modified. Changes made to title sequences in-game are now correctly loaded in the title screen. Starting a title sequence within the editor will now always reset it even if it's the current playing sequence. (Not for playing in the editor though). Get Location in title sequence command editor now has 100% accuracy compared to before where it would usually get some offset value. Added `get_map_coordinates_from_pos_window` which will allow getting the viewport coordinates of a specific window even if the input coordinates are under another window. This has use with getting 2D positions from the main window without the other windows getting in the way. Options window will now always specify the config title sequence in the dropdown and not the current title sequence. Made a global variable `gLoadKeepWindowsOpen`, in game.h to keep windows open when loading a park. When loading a title sequence park in-game. The sequence player will force-close all park-specific windows ahead of time. Skipping while testing title sequences no longer needs to reload the park if the current playback position is already before the target position and ahead of the load position. Added changelog entry.
2017-10-30 12:07:01 +01:00
_singleton->SetCurrentSequence(value, loadSequence);
2017-07-23 00:42:14 +02:00
}
}
2017-01-04 22:17:08 +01:00
void DrawOpenRCT2(rct_drawpixelinfo * dpi, sint32 x, sint32 y)
{
utf8 buffer[256];
// Write format codes
utf8 *ch = buffer;
ch = utf8_write_codepoint(ch, FORMAT_MEDIUMFONT);
ch = utf8_write_codepoint(ch, FORMAT_OUTLINE);
ch = utf8_write_codepoint(ch, FORMAT_WHITE);
// Write name and version information
openrct2_write_full_version_info(ch, sizeof(buffer) - (ch - buffer));
gfx_draw_string(dpi, buffer, COLOUR_BLACK, x + 5, y + 5 - 13);
// Write platform information
snprintf(ch, 256 - (ch - buffer), "%s (%s)", OPENRCT2_PLATFORM, OPENRCT2_ARCHITECTURE);
gfx_draw_string(dpi, buffer, COLOUR_BLACK, x + 5, y + 5);
}
}