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