浏览代码

Check that modal element is parented to root, as the input exclusion does not work right otherwise.
Allow currently modal element to unset its own modal status.

Lasse Öörni 12 年之前
父节点
当前提交
eb54a29d8f
共有 3 个文件被更改,包括 13 次插入9 次删除
  1. 10 6
      Engine/UI/UI.cpp
  2. 2 2
      Engine/UI/UI.h
  3. 1 1
      Engine/UI/Window.cpp

+ 10 - 6
Engine/UI/UI.cpp

@@ -171,17 +171,21 @@ void UI::SetFocusElement(UIElement* element)
     SendEvent(E_FOCUSCHANGED, eventData);
 }
 
-bool UI::SetModalElement(UIElement* modalElement)
+bool UI::SetModalElement(UIElement* modalElement, bool enable)
 {
-    // Only allow one modal element at a time
-    if (modalElement_)
+    // Only allow one modal element at a time, only the currently active modal element can disable itself
+    if (modalElement_ && modalElement != modalElement_)
         return false;
-
+    
+    // The modal element must be parented to root
+    if (modalElement->GetParent() != rootElement_)
+        return false;
+    
     // Currently only allow modal window
     if (modalElement && modalElement->GetType() != Window::GetTypeStatic())
         return false;
-
-    modalElement_ = modalElement;
+    
+    modalElement_ = enable ? modalElement : 0;
     return true;
 }
 

+ 2 - 2
Engine/UI/UI.h

@@ -52,8 +52,8 @@ public:
     void SetCursor(Cursor* cursor);
     /// Set focused UI element.
     void SetFocusElement(UIElement* element);
-    /// Set modal element. Until it is dismissed, all the inputs and events are only sent to this modal element. Return true when successful.
-    bool SetModalElement(UIElement* modalElement);
+    /// Set modal element. Until it is dismissed, all the inputs and events are only sent to this modal element. Return true when successful. Only the current modal element can clear its modal status.
+    bool SetModalElement(UIElement* modalElement, bool enable);
     /// Clear the UI (excluding the cursor.)
     void Clear();
     /// Update the UI logic. Called by HandlePostUpdate().

+ 1 - 1
Engine/UI/Window.cpp

@@ -225,7 +225,7 @@ void Window::SetResizeBorder(const IntRect& rect)
 void Window::SetModal(bool modal)
 {
     UI* ui = GetSubsystem<UI>();
-    if (ui->SetModalElement(modal ? this : 0))
+    if (ui->SetModalElement(this, modal))
         modal_ = modal;
 }