Simplify code in #3119
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
#include "Engine/Render2D/Font.h"
|
#include "Engine/Render2D/Font.h"
|
||||||
#include "Engine/Render2D/TextLayoutOptions.h"
|
#include "Engine/Render2D/TextLayoutOptions.h"
|
||||||
#include "Engine/Render2D/Render2D.h"
|
#include "Engine/Render2D/Render2D.h"
|
||||||
|
#include "Engine/Platform/FileSystem.h"
|
||||||
#include "Engine/Content/Content.h"
|
#include "Engine/Content/Content.h"
|
||||||
#include "FlaxEngine.Gen.h"
|
#include "FlaxEngine.Gen.h"
|
||||||
|
|
||||||
@@ -188,8 +189,7 @@ void SplashScreen::Show()
|
|||||||
|
|
||||||
// Setup
|
// Setup
|
||||||
_dpiScale = dpiScale;
|
_dpiScale = dpiScale;
|
||||||
_width = settings.Size.X;
|
_size = settings.Size;
|
||||||
_height = settings.Size.Y;
|
|
||||||
_startTime = DateTime::NowUTC();
|
_startTime = DateTime::NowUTC();
|
||||||
auto str = Globals::ProjectFolder;
|
auto str = Globals::ProjectFolder;
|
||||||
#if PLATFORM_WIN32
|
#if PLATFORM_WIN32
|
||||||
@@ -214,26 +214,11 @@ void SplashScreen::Show()
|
|||||||
font->OnLoaded.Bind<SplashScreen, &SplashScreen::OnFontLoaded>(this);
|
font->OnLoaded.Bind<SplashScreen, &SplashScreen::OnFontLoaded>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load Splash image
|
// Load custom image
|
||||||
String splashImagePath = String::Format(TEXT("{0}/{1}"), Globals::ProjectContentFolder, TEXT("SplashImage/SplashImage.flax"));
|
_splashTexture.Loaded.Bind<SplashScreen, &SplashScreen::OnSplashLoaded>(this);
|
||||||
#if PLATFORM_WIN32
|
String splashImagePath = Globals::ProjectContentFolder / TEXT("SplashImage.flax");
|
||||||
splashImagePath.Replace('/', '\\');
|
if (FileSystem::FileExists(splashImagePath))
|
||||||
#else
|
_splashTexture = Content::LoadAsync<Texture>(splashImagePath);
|
||||||
splashImagePath.Replace('\\', '/');
|
|
||||||
#endif
|
|
||||||
|
|
||||||
auto texture = Content::LoadAsync<Texture>(*splashImagePath);
|
|
||||||
if (texture == nullptr)
|
|
||||||
{
|
|
||||||
LOG(Info, "Cannot load splash Texture at {0}", splashImagePath);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (texture->IsLoaded())
|
|
||||||
OnTextureLoaded(texture);
|
|
||||||
else
|
|
||||||
texture->OnLoaded.Bind<SplashScreen, &SplashScreen::OnTextureLoaded>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
_window->Show();
|
_window->Show();
|
||||||
}
|
}
|
||||||
@@ -248,6 +233,10 @@ void SplashScreen::Close()
|
|||||||
// Close window
|
// Close window
|
||||||
_window->Close(ClosingReason::CloseEvent);
|
_window->Close(ClosingReason::CloseEvent);
|
||||||
_window = nullptr;
|
_window = nullptr;
|
||||||
|
|
||||||
|
_titleFont = nullptr;
|
||||||
|
_subtitleFont = nullptr;
|
||||||
|
_splashTexture = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SplashScreen::OnShown()
|
void SplashScreen::OnShown()
|
||||||
@@ -260,8 +249,8 @@ void SplashScreen::OnShown()
|
|||||||
void SplashScreen::OnDraw()
|
void SplashScreen::OnDraw()
|
||||||
{
|
{
|
||||||
const float s = _dpiScale;
|
const float s = _dpiScale;
|
||||||
const float width = _width;
|
const float width = _size.X;
|
||||||
const float height = _height;
|
const float height = _size.Y;
|
||||||
|
|
||||||
// Peek time
|
// Peek time
|
||||||
const float time = static_cast<float>((DateTime::NowUTC() - _startTime).GetTotalSeconds());
|
const float time = static_cast<float>((DateTime::NowUTC() - _startTime).GetTotalSeconds());
|
||||||
@@ -354,21 +343,13 @@ void SplashScreen::OnFontLoaded(Asset* asset)
|
|||||||
_subtitleFont = font->CreateFont(9 * s);
|
_subtitleFont = font->CreateFont(9 * s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SplashScreen::OnTextureLoaded(Asset* asset)
|
void SplashScreen::OnSplashLoaded()
|
||||||
{
|
{
|
||||||
ASSERT(asset && asset->IsLoaded());
|
// Resize window to be larger if texture is being used
|
||||||
auto texture = (Texture*)asset;
|
|
||||||
|
|
||||||
texture->OnLoaded.Unbind<SplashScreen, &SplashScreen::OnTextureLoaded>(this);
|
|
||||||
_splashTexture = texture;
|
|
||||||
|
|
||||||
// Resize window to be larger if texture is being used.
|
|
||||||
auto desktopSize = Platform::GetDesktopSize();
|
auto desktopSize = Platform::GetDesktopSize();
|
||||||
auto xSize = (desktopSize.X / (600.0f * 3.0f)) * 600.0f;
|
auto xSize = (desktopSize.X / (600.0f * 3.0f)) * 600.0f;
|
||||||
auto ySize = (desktopSize.Y / (200.0f * 3.0f)) * 200.0f;
|
auto ySize = (desktopSize.Y / (200.0f * 3.0f)) * 200.0f;
|
||||||
|
|
||||||
_window->SetClientSize(Float2(xSize, ySize));
|
_window->SetClientSize(Float2(xSize, ySize));
|
||||||
_width = _window->GetSize().X;
|
_size = _window->GetSize();
|
||||||
_height = _window->GetSize().Y;
|
_window->SetPosition((desktopSize - _size) * 0.5f);
|
||||||
_window->SetPosition((Platform::GetDesktopSize() - _window->GetSize()) / 2.0f);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Engine/Content/Assets/Texture.h"
|
#include "Engine/Content/Assets/Texture.h"
|
||||||
|
#include "Engine/Content/AssetReference.h"
|
||||||
#include "Engine/Core/Types/DateTime.h"
|
#include "Engine/Core/Types/DateTime.h"
|
||||||
#include "Engine/Platform/Window.h"
|
#include "Engine/Platform/Window.h"
|
||||||
|
|
||||||
@@ -19,11 +20,12 @@ private:
|
|||||||
Window* _window = nullptr;
|
Window* _window = nullptr;
|
||||||
Font* _titleFont = nullptr;
|
Font* _titleFont = nullptr;
|
||||||
Font* _subtitleFont = nullptr;
|
Font* _subtitleFont = nullptr;
|
||||||
Texture* _splashTexture = nullptr;
|
AssetReference<Texture> _splashTexture;
|
||||||
String _title;
|
String _title;
|
||||||
DateTime _startTime;
|
DateTime _startTime;
|
||||||
String _infoText;
|
String _infoText;
|
||||||
float _dpiScale, _width, _height;
|
float _dpiScale;
|
||||||
|
Float2 _size;
|
||||||
StringView _quote;
|
StringView _quote;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -80,5 +82,5 @@ private:
|
|||||||
void OnDraw();
|
void OnDraw();
|
||||||
bool HasLoadedFonts() const;
|
bool HasLoadedFonts() const;
|
||||||
void OnFontLoaded(Asset* asset);
|
void OnFontLoaded(Asset* asset);
|
||||||
void OnTextureLoaded(Asset* asset);
|
void OnSplashLoaded();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user