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 years ago
parent
commit
3ea3f8102b
3 changed files with 19 additions and 7 deletions
  1. 9 0
      Source/Engine/Engine/Console.cpp
  2. 10 0
      Source/Engine/Engine/DebugHud.cpp
  3. 0 7
      Source/Engine/UI/UI.cpp

+ 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)
 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())
     if (!rowContainer_->GetNumItems() || pendingRows_.Empty())
         return;
         return;
     
     

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

@@ -97,6 +97,16 @@ void DebugHud::Update()
     if (!renderer || !graphics)
     if (!renderer || !graphics)
         return;
         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())
     if (statsText_->IsVisible())
     {
     {
         unsigned primitives, batches;
         unsigned primitives, batches;

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

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