1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-06 06:32:56 +01:00

Make TitleScreen a class (#5971)

This commit is contained in:
Ted John
2017-07-22 23:42:14 +01:00
committed by GitHub
parent 7fcb39c833
commit bc88cb9c2b
7 changed files with 249 additions and 133 deletions

View File

@@ -214,7 +214,7 @@ static void shortcut_remove_top_bottom_toolbar_toggle()
window_close(window_find_by_class(WC_TITLE_OPTIONS));
window_close(window_find_by_class(WC_TITLE_MENU));
window_close(window_find_by_class(WC_TITLE_EXIT));
gTitleHideVersionInfo = true;
title_set_hide_version_info(true);
} else {
title_create_windows();
}

View File

@@ -88,6 +88,9 @@ namespace OpenRCT2
ITrackDesignRepository * _trackDesignRepository = nullptr;
IScenarioRepository * _scenarioRepository = nullptr;
// Game states
TitleScreen * _titleScreen = nullptr;
bool _initialised = false;
bool _isWindowMinimised = false;
uint32 _lastTick = 0;
@@ -127,6 +130,8 @@ namespace OpenRCT2
#endif // DISABLE_NETWORK
rct2_interop_dispose();
delete _titleScreen;
delete _scenarioRepository;
delete _trackDesignRepository;
delete _objectManager;
@@ -266,6 +271,8 @@ namespace OpenRCT2
input_reset_place_obj_modifier();
viewport_init_all();
game_init_all(150);
_titleScreen = new TitleScreen();
return true;
}
@@ -540,7 +547,7 @@ namespace OpenRCT2
}
else if ((gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) && !gOpenRCT2Headless)
{
title_update();
_titleScreen->Update();
}
else
{

View File

@@ -55,7 +55,7 @@ void Painter::Paint(IDrawingEngine * de)
chat_draw(dpi);
console_draw(dpi);
if ((gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) && !gTitleHideVersionInfo)
if ((gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) && !title_should_hide_version_info())
{
DrawOpenRCT2(dpi, 0, _uiContext->GetHeight() - 20);
}

View File

@@ -14,8 +14,9 @@
*****************************************************************************/
#pragma endregion
#include "../core/Console.hpp"
#include "../config/Config.h"
#include "../Context.h"
#include "../core/Console.hpp"
#include "../interface/Screenshot.h"
#include "../network/network.h"
#include "../OpenRCT2.h"
@@ -28,36 +29,159 @@
extern "C"
{
#include "../audio/audio.h"
#include "../config/Config.h"
#include "../drawing/drawing.h"
#include "../game.h"
#include "../input.h"
#include "../interface/viewport.h"
#include "../interface/window.h"
#include "../localisation/localisation.h"
#include "../management/news_item.h"
#include "../peep/staff.h"
#include "../world/Climate.h"
#include "../world/scenery.h"
}
extern "C"
// TODO Remove when no longer required.
static TitleScreen * _singleton;
TitleScreen::TitleScreen()
{
bool gTitleHideVersionInfo = false;
uint16 gTitleCurrentSequence;
_singleton = this;
}
static uint16 _loadedTitleSequenceId = UINT16_MAX;
static ITitleSequencePlayer * _sequencePlayer = nullptr;
TitleScreen::~TitleScreen()
{
_singleton = nullptr;
}
static void TitleInitialise();
static void TryLoadSequence();
ITitleSequencePlayer * TitleScreen::GetSequencePlayer()
{
return _sequencePlayer;
}
uint16 TitleScreen::GetCurrentSequence()
{
return _currentSequence;
}
void TitleScreen::SetCurrentSequence(uint16 value)
{
_currentSequence = value;
}
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;
network_close();
audio_stop_all_music_and_sounds();
game_init_all(150);
viewport_init_all();
window_main_open();
CreateWindows();
TitleInitialise();
audio_start_title_music();
if (gOpenRCT2ShowChangelog)
{
gOpenRCT2ShowChangelog = false;
window_changelog_open();
}
if (_sequencePlayer != nullptr)
{
_sequencePlayer->Reset();
// 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()
{
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;
}
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);
_currentSequence = preset;
window_invalidate_all();
}
/**
*
* rct2: 0x00678680
* Creates the windows shown on the title screen; New game, load game,
* tutorial, toolbox and exit.
*/
static void TitleInitialise()
void TitleScreen::CreateWindows()
{
window_title_menu_open();
window_title_exit_open();
window_title_options_open();
window_title_logo_open();
window_resize_gui(context_get_width(), context_get_height());
_hideVersionInfo = false;
}
void TitleScreen::TitleInitialise()
{
if (_sequencePlayer == nullptr)
{
@@ -77,30 +201,30 @@ static void TitleInitialise()
TryLoadSequence();
}
static void TryLoadSequence()
void TitleScreen::TryLoadSequence()
{
if (_loadedTitleSequenceId != gTitleCurrentSequence)
if (_loadedTitleSequenceId != _currentSequence)
{
uint16 numSequences = (uint16)TitleSequenceManager::GetCount();
if (numSequences > 0)
{
uint16 targetSequence = gTitleCurrentSequence;
uint16 targetSequence = _currentSequence;
do
{
if (_sequencePlayer->Begin(targetSequence) && _sequencePlayer->Update())
{
_loadedTitleSequenceId = targetSequence;
gTitleCurrentSequence = targetSequence;
_currentSequence = targetSequence;
gfx_invalidate_screen();
return;
}
targetSequence = (targetSequence + 1) % numSequences;
}
while (targetSequence != gTitleCurrentSequence);
while (targetSequence != _currentSequence);
}
Console::Error::WriteLine("Unable to play any title sequences.");
_sequencePlayer->Eject();
gTitleCurrentSequence = UINT16_MAX;
_currentSequence = UINT16_MAX;
_loadedTitleSequenceId = UINT16_MAX;
game_init_all(150);
}
@@ -108,99 +232,74 @@ static void TryLoadSequence()
extern "C"
{
/**
*
* rct2: 0x0068E8DA
*/
void title_load()
{
log_verbose("loading title");
if (gGamePaused & GAME_PAUSED_NORMAL)
pause_toggle();
gScreenFlags = SCREEN_FLAGS_TITLE_DEMO;
#ifndef DISABLE_NETWORK
network_close();
#endif
audio_stop_all_music_and_sounds();
game_init_all(150);
viewport_init_all();
window_main_open();
title_create_windows();
TitleInitialise();
gfx_invalidate_screen();
audio_start_title_music();
gScreenAge = 0;
if (gOpenRCT2ShowChangelog) {
gOpenRCT2ShowChangelog = false;
window_changelog_open();
}
if (_sequencePlayer != nullptr)
if (_singleton != nullptr)
{
_sequencePlayer->Reset();
// Force the title sequence to load / update so we
// don't see a blank screen for a split second.
TryLoadSequence();
_sequencePlayer->Update();
_singleton->Load();
}
log_verbose("loading title finished");
}
/**
* Creates the windows shown on the title screen; New game, load game,
* tutorial, toolbox and exit.
* rct2: 0x0066B5C0 (part of 0x0066B3E8)
*/
void title_create_windows()
{
window_title_menu_open();
window_title_exit_open();
window_title_options_open();
window_title_logo_open();
window_resize_gui(context_get_width(), context_get_height());
gTitleHideVersionInfo = false;
if (_singleton != nullptr)
{
_singleton->CreateWindows();
}
}
void title_update()
void * title_get_sequence_player()
{
gInUpdateCode = true;
screenshot_check();
title_handle_keyboard_input();
if (game_is_not_paused())
void * result = nullptr;
if (_singleton != nullptr)
{
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();
result = _singleton->GetSequencePlayer();
}
return result;
}
input_set_flag(INPUT_FLAG_VIEWPORT_SCROLLING, false);
void title_sequence_change_preset(sint32 preset)
{
if (_singleton != nullptr)
{
_singleton->ChangeSequence(preset);
}
}
window_map_tooltip_update_visibility();
window_dispatch_update_all();
bool title_should_hide_version_info()
{
bool result = false;
if (_singleton != nullptr)
{
result = _singleton->ShouldHideVersionInfo();
}
return result;
}
gSavedAge++;
void title_set_hide_version_info(bool value)
{
if (_singleton != nullptr)
{
_singleton->SetHideVersionInfo(value);
}
}
game_handle_input();
uint16 title_get_current_sequence()
{
uint16 result = 0;
if (_singleton != nullptr)
{
result = _singleton->GetCurrentSequence();
}
return result;
}
gInUpdateCode = false;
void title_set_current_sequence(uint16 value)
{
if (_singleton != nullptr)
{
_singleton->SetCurrentSequence(value);
}
}
void DrawOpenRCT2(rct_drawpixelinfo * dpi, sint32 x, sint32 y)
@@ -221,24 +320,4 @@ extern "C"
snprintf(ch, 256 - (ch - buffer), "%s (%s)", OPENRCT2_PLATFORM, OPENRCT2_ARCHITECTURE);
gfx_draw_string(dpi, buffer, COLOUR_BLACK, x + 5, y + 5);
}
void * title_get_sequence_player()
{
return _sequencePlayer;
}
void title_sequence_change_preset(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);
gTitleCurrentSequence = preset;
window_invalidate_all();
}
}

View File

@@ -16,22 +16,52 @@
#pragma once
#include "../common.h"
#ifdef __cplusplus
interface ITitleSequencePlayer;
class TitleScreen final
{
public:
ITitleSequencePlayer * GetSequencePlayer();
uint16 GetCurrentSequence();
void SetCurrentSequence(uint16 value);
bool ShouldHideVersionInfo();
void SetHideVersionInfo(bool value);
TitleScreen();
~TitleScreen();
void Load();
void Update();
void CreateWindows();
void ChangeSequence(sint32 preset);
private:
ITitleSequencePlayer * _sequencePlayer = nullptr;
uint16 _loadedTitleSequenceId = UINT16_MAX;
uint16 _currentSequence;
bool _hideVersionInfo;
void TitleInitialise();
void TryLoadSequence();
};
#endif
#ifdef __cplusplus
extern "C"
{
#endif
#include "../drawing/drawing.h"
extern bool gTitleHideVersionInfo;
extern uint16 gTitleCurrentSequence;
void title_load();
void title_create_windows();
void title_update();
void DrawOpenRCT2(rct_drawpixelinfo *dpi, sint32 x, sint32 y);
void * title_get_sequence_player();
void title_sequence_change_preset(sint32 preset);
bool title_should_hide_version_info();
void title_set_hide_version_info(bool value);
uint16 title_get_current_sequence();
void title_set_current_sequence(uint16 value);
void DrawOpenRCT2(rct_drawpixelinfo *dpi, sint32 x, sint32 y);
#ifdef __cplusplus
}
#endif

View File

@@ -1229,7 +1229,7 @@ static void window_options_mousedown(rct_window *w, rct_widgetindex widgetIndex,
num_items
);
dropdown_set_checked(gTitleCurrentSequence, true);
dropdown_set_checked(title_get_current_sequence(), true);
break;
case WIDX_DEFAULT_INSPECTION_INTERVAL_DROPDOWN:
for (size_t i = 0; i < 7; i++) {
@@ -1471,7 +1471,7 @@ static void window_options_dropdown(rct_window *w, rct_widgetindex widgetIndex,
}
break;
case WIDX_TITLE_SEQUENCE_DROPDOWN:
if (dropdownIndex != gTitleCurrentSequence) {
if (dropdownIndex != title_get_current_sequence()) {
title_sequence_change_preset(dropdownIndex);
config_save_default();
window_invalidate(w);
@@ -1952,7 +1952,7 @@ static void window_options_paint(rct_window *w, rct_drawpixelinfo *dpi)
w->y + window_options_misc_widgets[WIDX_AUTOSAVE].top
);
const utf8 * name = title_sequence_manager_get_name(gTitleCurrentSequence);
const utf8 * name = title_sequence_manager_get_name(title_get_current_sequence());
set_format_arg(0, uintptr_t, (uintptr_t)name);
gfx_draw_string_left(dpi, STR_TITLE_SEQUENCE, w, w->colours[1], w->x + 10, w->y + window_options_misc_widgets[WIDX_TITLE_SEQUENCE].top + 1);
gfx_draw_string_left_clipped(

View File

@@ -448,13 +448,13 @@ static void window_title_editor_mouseup(rct_window *w, rct_widgetindex widgetInd
break;
case WIDX_TITLE_EDITOR_STOP:
if (_isSequencePlaying) {
gTitleCurrentSequence = 0;
title_set_current_sequence(0);
_isSequencePlaying = false;
}
break;
case WIDX_TITLE_EDITOR_PLAY:
if (!_isSequencePlaying && (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)) {
gTitleCurrentSequence = (uint16)_selectedTitleSequence;
title_set_current_sequence((uint16)_selectedTitleSequence);
_isSequencePlaying = true;
}
break;