Browse Source

Minor refactor to a cleaner fix for #341. Also fix DebugHud now.
Revert back changes to UI class as it should not need to know Console's innards.

Yao Wei Tjong 姚伟忠 11 năm trước cách đây
mục cha
commit
3ea3f8102b

+ 9 - 0
Source/Engine/Engine/Console.cpp

@@ -402,6 +402,15 @@ void Console::HandleLogMessage(StringHash eventType, VariantMap& eventData)
 
 void Console::HandlePostUpdate(StringHash eventType, VariantMap& eventData)
 {
+    // Ensure UI-elements are not detached
+    if (!background_->GetParent())
+    {
+        UI* ui = GetSubsystem<UI>();
+        UIElement* uiRoot = ui->GetRoot();
+        uiRoot->AddChild(background_);
+        uiRoot->AddChild(closeButton_);
+    }
+
     if (!rowContainer_->GetNumItems() || pendingRows_.Empty())
         return;
     

+ 10 - 0
Source/Engine/Engine/DebugHud.cpp

@@ -97,6 +97,16 @@ void DebugHud::Update()
     if (!renderer || !graphics)
         return;
 
+    // Ensure UI-elements are not detached
+    if (!statsText_->GetParent())
+    {
+        UI* ui = GetSubsystem<UI>();
+        UIElement* uiRoot = ui->GetRoot();
+        uiRoot->AddChild(statsText_);
+        uiRoot->AddChild(modeText_);
+        uiRoot->AddChild(profilerText_);
+    }
+
     if (statsText_->IsVisible())
     {
         unsigned primitives, batches;

+ 0 - 7
Source/Engine/UI/UI.cpp

@@ -22,7 +22,6 @@
 
 #include "Precompiled.h"
 #include "CheckBox.h"
-#include "Console.h"
 #include "Context.h"
 #include "CoreEvents.h"
 #include "Cursor.h"
@@ -289,12 +288,6 @@ void UI::Clear()
     rootModalElement_->RemoveAllChildren();
     if (cursor_)
         rootElement_->AddChild(cursor_);
-    Console* console = GetSubsystem<Console>();
-    if (console)
-    {
-        rootElement_->AddChild(console->GetBackground());
-        rootElement_->AddChild(console->GetCloseButton());
-    }
 }
 
 void UI::Update(float timeStep)