diff --git a/Minecraft.Client/RmlManager.cpp b/Minecraft.Client/RmlManager.cpp index f1cd4e99..eec82a9c 100644 --- a/Minecraft.Client/RmlManager.cpp +++ b/Minecraft.Client/RmlManager.cpp @@ -17,9 +17,6 @@ extern ID3D11Device* g_pd3dDevice; extern ID3D11DeviceContext* g_pImmediateContext; extern ID3D11RenderTargetView* g_pRenderTargetView; -extern int g_iScreenWidth; -extern int g_iScreenHeight; - RmlManager& RmlManager::Get() { static RmlManager instance; @@ -37,7 +34,7 @@ RmlManager::~RmlManager() Shutdown(); } -bool RmlManager::Init() +bool RmlManager::Init(int width, int height) { if (m_initialised) return true; @@ -72,7 +69,7 @@ bool RmlManager::Init() if (!Rml::LoadFontFace(assetPath + "/fonts/MinecraftTen.ttf", "Minecraft Default", Rml::Style::FontStyle::Normal, Rml::Style::FontWeight::Bold, true)) app.DebugPrintf("[RmlManager] FAILED loading MinecraftTen.ttf\n"); - m_context = Rml::CreateContext("main", Rml::Vector2i(g_iScreenWidth, g_iScreenHeight)); + m_context = Rml::CreateContext("main", Rml::Vector2i(width, height)); if (!m_context) { app.DebugPrintf("[RmlManager] Failed to create RmlUi context\n"); @@ -80,14 +77,14 @@ bool RmlManager::Init() return false; } - app.DebugPrintf("[RmlManager] Context created (%dx%d)\n", g_iScreenWidth, g_iScreenHeight); + app.DebugPrintf("[RmlManager] Context created (%dx%d)\n", width, height); - m_renderer->SetViewport(g_iScreenWidth, g_iScreenHeight); + m_renderer->SetViewport(width, height); m_initialised = true; - app.DebugPrintf("[RmlManager] Initialised (%dx%d)\n", g_iScreenWidth, g_iScreenHeight); + app.DebugPrintf("[RmlManager] Initialised (%dx%d)\n", width, height); - UpdateDpRatio(); + UpdateDpRatio(width, height); return true; } @@ -167,19 +164,20 @@ void RmlManager::OnResize(int width, int height) m_context->SetDimensions(Rml::Vector2i(width, height)); m_renderer->SetViewport(width, height); + UpdateDpRatio(width, height); } -void RmlManager::UpdateDpRatio() +void RmlManager::UpdateDpRatio(int width, int height) { if (!m_context) return; - float scale_x = static_cast(g_iScreenWidth) / 1920; - float scale_y = static_cast(g_iScreenHeight) / 1080; + float scale_x = static_cast(width) / 1920; + float scale_y = static_cast(height) / 1080; float base_ratio = (scale_x < scale_y) ? scale_x : scale_y; float auto_dp = base_ratio; - float viewport_cap = 0.88f * static_cast(g_iScreenHeight) / 850.0f; + float viewport_cap = 0.88f * static_cast(height) / 850.0f; if (auto_dp > viewport_cap) auto_dp = viewport_cap; diff --git a/Minecraft.Client/RmlManager.h b/Minecraft.Client/RmlManager.h index e5898582..11b045d6 100644 --- a/Minecraft.Client/RmlManager.h +++ b/Minecraft.Client/RmlManager.h @@ -21,7 +21,7 @@ class RmlManager public: static RmlManager& Get(); - bool Init(); + bool Init(int width, int height); void Shutdown(); void Update(); @@ -31,7 +31,7 @@ public: RenderInterface_D3D11* GetRenderInterface() const { return m_renderer.get(); } void OnResize(int width, int height); - void UpdateDpRatio(); + void UpdateDpRatio(int width, int height); void OnLanguageChanged(); diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index 9c3d8c86..4976b5a1 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -915,6 +915,8 @@ static bool ResizeD3D(int newW, int newH) ui.updateRenderTargets(g_pRenderTargetView, g_pDepthStencilView); ui.updateScreenSize(bbW, bbH); + RmlManager::Get().OnResize(bbW, bbH); + // Track actual backbuffer dimensions for the rest of the engine g_iScreenWidth = bbW; g_iScreenHeight = bbH; @@ -969,6 +971,7 @@ postReset: g_iScreenWidth = recW; g_iScreenHeight = recH; ui.updateScreenSize(recW, recH); + RmlManager::Get().OnResize(recW, recH); } app.DebugPrintf("[RESIZE] FAILED but recovered views at %dx%d\n", g_iScreenWidth, g_iScreenHeight); @@ -1069,8 +1072,11 @@ static Minecraft* InitialiseMinecraftRuntime() RenderManager.Initialise(g_pd3dDevice, g_pSwapChain); app.loadStringTable(); + ui.init(g_pd3dDevice, g_pImmediateContext, g_pRenderTargetView, g_pDepthStencilView, g_iScreenWidth, g_iScreenHeight); + RmlManager::Get().Init(g_iScreenWidth, g_iScreenHeight); + InputManager.Initialise(1, 3, MINECRAFT_ACTION_MAX, ACTION_MAX_MENU); g_KBMInput.Init(); DefineActions(); @@ -1504,9 +1510,10 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, } #endif ui.tick(); - RmlManager::Get().Update(); ui.render(); + RmlManager::Get().Render(); + g_DiscordPresence.Tick(); pMinecraft->gameRenderer->ApplyGammaPostProcess(); diff --git a/Minecraft.Client/Windows64/Windows64_UIController.cpp b/Minecraft.Client/Windows64/Windows64_UIController.cpp index 492a78e2..b5637a9f 100644 --- a/Minecraft.Client/Windows64/Windows64_UIController.cpp +++ b/Minecraft.Client/Windows64/Windows64_UIController.cpp @@ -61,10 +61,6 @@ void ConsoleUIController::init(ID3D11Device *dev, ID3D11DeviceContext *ctx, ID3D // Shared init postInit(); - - // Initialise RmlUi (menus) - if (!RmlManager::Get().Init()) - app.DebugPrintf("ConsoleUIController::init - RmlManager::Init failed\n"); #endif } @@ -88,9 +84,6 @@ void ConsoleUIController::render() renderScenes(); - // Render RmlUi menus on top of the Iggy scenes - RmlManager::Get().Render(); - /* Finally we're ready to display the frame. We call GDraw to let it know we're done rendering, so it can do any finalization it needs to do. */ diff --git a/Minecraft.Server/RmlManagerStub.cpp b/Minecraft.Server/RmlManagerStub.cpp index 6f490baf..20c5caea 100644 --- a/Minecraft.Server/RmlManagerStub.cpp +++ b/Minecraft.Server/RmlManagerStub.cpp @@ -9,7 +9,7 @@ RmlManager& RmlManager::Get() RmlManager::RmlManager() : m_initialised(false), m_context(nullptr) {} RmlManager::~RmlManager() {} -bool RmlManager::Init(int viewport_width, int viewport_height) +bool RmlManager::Init(int width, int height) { return true; } @@ -17,6 +17,6 @@ bool RmlManager::Init(int viewport_width, int viewport_height) void RmlManager::Shutdown() {} void RmlManager::Update() {} void RmlManager::Render() {} -void RmlManager::OnResize() {} -void RmlManager::UpdateDpRatio() {} +void RmlManager::OnResize(int width, int height) {} +void RmlManager::UpdateDpRatio(int width, int height) {} void RmlManager::OnLanguageChanged() {} \ No newline at end of file