mirror of https://github.com/OpenRCT2/OpenRCT2.git
Move TitleSequencePlayer to libopenrct2ui
This commit is contained in:
parent
bc1d2252aa
commit
ae6af47341
|
@ -31,6 +31,7 @@
|
|||
#include <openrct2/localisation/StringIds.h>
|
||||
#include <openrct2/interface/Chat.h>
|
||||
#include <openrct2/platform/Platform2.h>
|
||||
#include <openrct2/title/TitleSequencePlayer.h>
|
||||
#include <openrct2/ui/UiContext.h>
|
||||
#include <openrct2/ui/WindowManager.h>
|
||||
#include <openrct2/Version.h>
|
||||
|
@ -48,6 +49,7 @@
|
|||
#include <openrct2-ui/interface/Window.h>
|
||||
|
||||
#include "interface/InGameConsole.h"
|
||||
#include "title/TitleSequencePlayer.h"
|
||||
|
||||
using namespace OpenRCT2;
|
||||
using namespace OpenRCT2::Drawing;
|
||||
|
@ -92,6 +94,7 @@ private:
|
|||
float _gestureRadius = 0;
|
||||
|
||||
InGameConsole _inGameConsole;
|
||||
std::unique_ptr<ITitleSequencePlayer> _titleSequencePlayer;
|
||||
|
||||
public:
|
||||
InGameConsole& GetInGameConsole() { return _inGameConsole; }
|
||||
|
@ -586,6 +589,17 @@ public:
|
|||
return (SDL_SetClipboardText(target) == 0);
|
||||
}
|
||||
|
||||
ITitleSequencePlayer * GetTitleSequencePlayer() override
|
||||
{
|
||||
if (_titleSequencePlayer == nullptr)
|
||||
{
|
||||
auto context = GetContext();
|
||||
auto scenarioRepository = context->GetScenarioRepository();
|
||||
auto gameState = context->GetGameState();
|
||||
_titleSequencePlayer = CreateTitleSequencePlayer(*scenarioRepository, *gameState);
|
||||
}
|
||||
return _titleSequencePlayer.get();
|
||||
}
|
||||
|
||||
private:
|
||||
void CreateWindow(sint32 x, sint32 y)
|
||||
|
|
|
@ -15,33 +15,35 @@
|
|||
#pragma endregion
|
||||
|
||||
#include <memory>
|
||||
#include "../common.h"
|
||||
#include "../Context.h"
|
||||
#include "../core/Console.hpp"
|
||||
#include "../core/Guard.hpp"
|
||||
#include "../core/Math.hpp"
|
||||
#include "../core/Path.hpp"
|
||||
#include "../core/String.hpp"
|
||||
#include "../object/ObjectManager.h"
|
||||
#include "../OpenRCT2.h"
|
||||
#include "../GameState.h"
|
||||
#include "../ParkImporter.h"
|
||||
#include "../scenario/ScenarioRepository.h"
|
||||
#include "../scenario/ScenarioSources.h"
|
||||
#include "TitleScreen.h"
|
||||
#include "TitleSequence.h"
|
||||
#include "TitleSequenceManager.h"
|
||||
#include <openrct2/common.h>
|
||||
#include <openrct2/Context.h>
|
||||
#include <openrct2/core/Console.hpp>
|
||||
#include <openrct2/core/Guard.hpp>
|
||||
#include <openrct2/core/Math.hpp>
|
||||
#include <openrct2/core/Path.hpp>
|
||||
#include <openrct2/core/String.hpp>
|
||||
#include <openrct2/object/ObjectManager.h>
|
||||
#include <openrct2/OpenRCT2.h>
|
||||
#include <openrct2/GameState.h>
|
||||
#include <openrct2/ParkImporter.h>
|
||||
#include <openrct2/scenario/ScenarioRepository.h>
|
||||
#include <openrct2/scenario/ScenarioSources.h>
|
||||
#include <openrct2/title/TitleScreen.h>
|
||||
#include <openrct2/title/TitleSequence.h>
|
||||
#include <openrct2/title/TitleSequenceManager.h>
|
||||
#include <openrct2/title/TitleSequencePlayer.h>
|
||||
#include <openrct2/Game.h>
|
||||
#include <openrct2/interface/Viewport.h>
|
||||
#include <openrct2/interface/Window.h>
|
||||
#include <openrct2/ui/UiContext.h>
|
||||
#include <openrct2/ui/WindowManager.h>
|
||||
#include <openrct2/management/NewsItem.h>
|
||||
#include <openrct2/windows/Intent.h>
|
||||
#include <openrct2/world/Map.h>
|
||||
#include <openrct2/world/Scenery.h>
|
||||
#include <openrct2/world/Sprite.h>
|
||||
#include "TitleSequencePlayer.h"
|
||||
|
||||
#include "../Game.h"
|
||||
#include "../interface/Viewport.h"
|
||||
#include "../interface/Window.h"
|
||||
#include "../interface/Window_internal.h"
|
||||
#include "../management/NewsItem.h"
|
||||
#include "../windows/Intent.h"
|
||||
#include "../world/Map.h"
|
||||
#include "../world/Scenery.h"
|
||||
#include "../world/Sprite.h"
|
||||
|
||||
using namespace OpenRCT2;
|
||||
|
||||
|
@ -502,36 +504,8 @@ private:
|
|||
|
||||
void PrepareParkForPlayback()
|
||||
{
|
||||
rct_window * w = window_get_main();
|
||||
if (w == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
w->viewport_target_sprite = SPRITE_INDEX_NULL;
|
||||
w->saved_view_x = gSavedViewX;
|
||||
w->saved_view_y = gSavedViewY;
|
||||
|
||||
sint8 zoomDifference = gSavedViewZoom - w->viewport->zoom;
|
||||
w->viewport->zoom = gSavedViewZoom;
|
||||
gCurrentRotation = gSavedViewRotation;
|
||||
if (zoomDifference != 0)
|
||||
{
|
||||
if (zoomDifference < 0)
|
||||
{
|
||||
zoomDifference = -zoomDifference;
|
||||
w->viewport->view_width >>= zoomDifference;
|
||||
w->viewport->view_height >>= zoomDifference;
|
||||
}
|
||||
else
|
||||
{
|
||||
w->viewport->view_width <<= zoomDifference;
|
||||
w->viewport->view_height <<= zoomDifference;
|
||||
}
|
||||
}
|
||||
w->saved_view_x -= w->viewport->view_width >> 1;
|
||||
w->saved_view_y -= w->viewport->view_height >> 1;
|
||||
|
||||
window_invalidate(w);
|
||||
auto windowManager = GetContext()->GetUiContext()->GetWindowManager();
|
||||
windowManager->SetMainView(gSavedViewX, gSavedViewY, gSavedViewZoom, gSavedViewRotation);
|
||||
reset_sprite_spatial_index();
|
||||
reset_all_sprite_quadrant_placements();
|
||||
auto intent = Intent(INTENT_ACTION_REFRESH_NEW_RIDES);
|
||||
|
@ -589,35 +563,7 @@ private:
|
|||
}
|
||||
};
|
||||
|
||||
ITitleSequencePlayer * CreateTitleSequencePlayer(IScenarioRepository& scenarioRepository, GameState& gameState)
|
||||
std::unique_ptr<ITitleSequencePlayer> CreateTitleSequencePlayer(IScenarioRepository& scenarioRepository, GameState& gameState)
|
||||
{
|
||||
return new TitleSequencePlayer(scenarioRepository, gameState);
|
||||
return std::make_unique<TitleSequencePlayer>(scenarioRepository, gameState);
|
||||
}
|
||||
|
||||
bool gPreviewingTitleSequenceInGame = false;
|
||||
|
||||
sint32 title_sequence_player_get_current_position(ITitleSequencePlayer * player)
|
||||
{
|
||||
return player->GetCurrentPosition();
|
||||
}
|
||||
|
||||
bool title_sequence_player_begin(ITitleSequencePlayer * player, uint32 titleSequenceId)
|
||||
{
|
||||
return player->Begin(titleSequenceId);
|
||||
}
|
||||
|
||||
void title_sequence_player_reset(ITitleSequencePlayer * player)
|
||||
{
|
||||
player->Reset();
|
||||
}
|
||||
|
||||
bool title_sequence_player_update(ITitleSequencePlayer * player)
|
||||
{
|
||||
return player->Update();
|
||||
}
|
||||
|
||||
void title_sequence_player_seek(ITitleSequencePlayer * player, uint32 position)
|
||||
{
|
||||
player->Seek(position);
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
#pragma region Copyright (c) 2018 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
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <openrct2/common.h>
|
||||
|
||||
interface ITitleSequencePlayer;
|
||||
interface IScenarioRepository;
|
||||
|
||||
namespace OpenRCT2
|
||||
{
|
||||
class GameState;
|
||||
}
|
||||
|
||||
std::unique_ptr<ITitleSequencePlayer> CreateTitleSequencePlayer(IScenarioRepository& scenarioRepository, OpenRCT2::GameState& gameState);
|
|
@ -28,7 +28,6 @@
|
|||
#include <openrct2/Context.h>
|
||||
#include <openrct2/windows/Intent.h>
|
||||
#include <openrct2-ui/windows/Window.h>
|
||||
|
||||
#include <openrct2/Game.h>
|
||||
#include <openrct2/Input.h>
|
||||
#include <openrct2-ui/interface/Widget.h>
|
||||
|
@ -37,6 +36,7 @@
|
|||
#include <openrct2/util/Util.h>
|
||||
#include <openrct2-ui/interface/Dropdown.h>
|
||||
#include <openrct2/scenario/Scenario.h>
|
||||
#include "../title/TitleSequencePlayer.h"
|
||||
|
||||
// clang-format off
|
||||
enum WINDOW_TITLE_EDITOR_TAB {
|
||||
|
@ -440,9 +440,9 @@ static void window_title_editor_mouseup(rct_window * w, rct_widgetindex widgetIn
|
|||
sint32 position = w->selected_list_item;
|
||||
if (title_is_previewing_sequence() && position != -1 && position < (sint32)_editingTitleSequence->NumCommands)
|
||||
{
|
||||
ITitleSequencePlayer * player = window_title_editor_get_player();
|
||||
title_sequence_player_seek(player, position);
|
||||
title_sequence_player_update(player);
|
||||
auto player = window_title_editor_get_player();
|
||||
player->Seek(position);
|
||||
player->Update();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -479,9 +479,9 @@ static void window_title_editor_mouseup(rct_window * w, rct_widgetindex widgetIn
|
|||
case WIDX_TITLE_EDITOR_REPLAY:
|
||||
if (title_is_previewing_sequence())
|
||||
{
|
||||
ITitleSequencePlayer * player = window_title_editor_get_player();
|
||||
title_sequence_player_reset(player);
|
||||
title_sequence_player_update(player);
|
||||
auto player = window_title_editor_get_player();
|
||||
player->Reset();
|
||||
player->Update();
|
||||
}
|
||||
break;
|
||||
case WIDX_TITLE_EDITOR_STOP:
|
||||
|
@ -506,14 +506,14 @@ static void window_title_editor_mouseup(rct_window * w, rct_widgetindex widgetIn
|
|||
case WIDX_TITLE_EDITOR_SKIP:
|
||||
if (title_is_previewing_sequence())
|
||||
{
|
||||
ITitleSequencePlayer * player = window_title_editor_get_player();
|
||||
sint32 position = title_sequence_player_get_current_position(player) + 1;
|
||||
auto player = window_title_editor_get_player();
|
||||
sint32 position = player->GetCurrentPosition() + 1;
|
||||
if (position >= (sint32)_editingTitleSequence->NumCommands)
|
||||
{
|
||||
position = 0;
|
||||
}
|
||||
title_sequence_player_seek(player, position);
|
||||
title_sequence_player_update(player);
|
||||
player->Seek(position);
|
||||
player->Update();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -927,8 +927,8 @@ static void window_title_editor_scrollpaint_commands(rct_window * w, rct_drawpix
|
|||
sint32 position = -1;
|
||||
if (title_is_previewing_sequence() && _selectedTitleSequence == title_get_current_sequence())
|
||||
{
|
||||
ITitleSequencePlayer * player = window_title_editor_get_player();
|
||||
position = title_sequence_player_get_current_position(player);
|
||||
auto player = window_title_editor_get_player();
|
||||
position = player->GetCurrentPosition();
|
||||
}
|
||||
|
||||
sint32 x = 0;
|
||||
|
|
|
@ -51,7 +51,6 @@
|
|||
#include "ride/Vehicle.h"
|
||||
#include "scenario/Scenario.h"
|
||||
#include "title/TitleScreen.h"
|
||||
#include "title/TitleSequencePlayer.h"
|
||||
#include "ui/UiContext.h"
|
||||
#include "ui/WindowManager.h"
|
||||
#include "util/SawyerCoding.h"
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include "world/MapAnimation.h"
|
||||
#include "world/Park.h"
|
||||
#include "world/Scenery.h"
|
||||
#include "ui/UiContext.h"
|
||||
|
||||
using namespace OpenRCT2;
|
||||
|
||||
|
@ -87,7 +88,11 @@ void GameState::Update()
|
|||
|
||||
if (game_is_not_paused() && gPreviewingTitleSequenceInGame)
|
||||
{
|
||||
title_sequence_player_update((ITitleSequencePlayer *) title_get_sequence_player());
|
||||
auto player = GetContext()->GetUiContext()->GetTitleSequencePlayer();
|
||||
if (player != nullptr)
|
||||
{
|
||||
player->Update();
|
||||
}
|
||||
}
|
||||
|
||||
// Determine how many times we need to update the game
|
||||
|
|
|
@ -35,10 +35,12 @@
|
|||
#include "../interface/Viewport.h"
|
||||
#include "../interface/Window.h"
|
||||
#include "../localisation/Localisation.h"
|
||||
#include "../ui/UiContext.h"
|
||||
|
||||
using namespace OpenRCT2;
|
||||
|
||||
// TODO Remove when no longer required.
|
||||
bool gPreviewingTitleSequenceInGame;
|
||||
static TitleScreen * _singleton = nullptr;
|
||||
|
||||
TitleScreen::TitleScreen(GameState& gameState)
|
||||
|
@ -49,7 +51,6 @@ TitleScreen::TitleScreen(GameState& gameState)
|
|||
|
||||
TitleScreen::~TitleScreen()
|
||||
{
|
||||
delete _sequencePlayer;
|
||||
_singleton = nullptr;
|
||||
}
|
||||
|
||||
|
@ -227,8 +228,7 @@ void TitleScreen::TitleInitialise()
|
|||
{
|
||||
if (_sequencePlayer == nullptr)
|
||||
{
|
||||
auto scenarioRepository = GetScenarioRepository();
|
||||
_sequencePlayer = CreateTitleSequencePlayer(*scenarioRepository, _gameState);
|
||||
_sequencePlayer = GetContext()->GetUiContext()->GetTitleSequencePlayer();
|
||||
}
|
||||
size_t seqId = title_get_config_sequence();
|
||||
if (seqId == SIZE_MAX)
|
||||
|
|
|
@ -59,6 +59,9 @@ namespace OpenRCT2
|
|||
};
|
||||
}
|
||||
|
||||
// When testing title sequences within a normal game
|
||||
extern bool gPreviewingTitleSequenceInGame;
|
||||
|
||||
void title_load();
|
||||
void title_create_windows();
|
||||
void * title_get_sequence_player();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#pragma region Copyright (c) 2014-2017 OpenRCT2 Developers
|
||||
#pragma region Copyright (c) 2014-2018 OpenRCT2 Developers
|
||||
/*****************************************************************************
|
||||
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
|
||||
*
|
||||
|
@ -18,13 +18,6 @@
|
|||
|
||||
#include "../common.h"
|
||||
|
||||
namespace OpenRCT2
|
||||
{
|
||||
class GameState;
|
||||
}
|
||||
|
||||
interface IScenarioRepository;
|
||||
|
||||
interface ITitleSequencePlayer
|
||||
{
|
||||
virtual ~ITitleSequencePlayer() = default;
|
||||
|
@ -37,14 +30,3 @@ interface ITitleSequencePlayer
|
|||
virtual void Seek(sint32 position) abstract;
|
||||
virtual void Eject() abstract;
|
||||
};
|
||||
|
||||
ITitleSequencePlayer * CreateTitleSequencePlayer(IScenarioRepository& scenarioRepository, OpenRCT2::GameState& gameState);
|
||||
|
||||
// When testing title sequences within a normal game
|
||||
extern bool gPreviewingTitleSequenceInGame;
|
||||
|
||||
sint32 title_sequence_player_get_current_position(ITitleSequencePlayer * player);
|
||||
bool title_sequence_player_begin(ITitleSequencePlayer * player, uint32 titleSequenceId);
|
||||
void title_sequence_player_reset(ITitleSequencePlayer * player);
|
||||
bool title_sequence_player_update(ITitleSequencePlayer * player);
|
||||
void title_sequence_player_seek(ITitleSequencePlayer * player, uint32 position);
|
||||
|
|
|
@ -104,6 +104,8 @@ namespace OpenRCT2::Ui
|
|||
return false;
|
||||
}
|
||||
|
||||
ITitleSequencePlayer * GetTitleSequencePlayer() override { return nullptr; }
|
||||
|
||||
~DummyUiContext() { delete _windowManager; }
|
||||
};
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "../interface/Cursors.h"
|
||||
|
||||
struct rct_drawpixelinfo;
|
||||
interface ITitleSequencePlayer;
|
||||
|
||||
namespace OpenRCT2
|
||||
{
|
||||
|
@ -142,6 +143,9 @@ namespace OpenRCT2
|
|||
|
||||
// Clipboard
|
||||
virtual bool SetClipboardText(const utf8* target) abstract;
|
||||
|
||||
// HACK Until all title logic is moved to libopenrct2ui, we will need to provide some services
|
||||
virtual ITitleSequencePlayer * GetTitleSequencePlayer() abstract;
|
||||
};
|
||||
|
||||
std::shared_ptr<IUiContext> CreateDummyUiContext();
|
||||
|
|
Loading…
Reference in New Issue