Просмотр исходного кода

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 лет назад
Родитель
Сommit
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);
     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;
         return false;
-
+    
+    // The modal element must be parented to root
+    if (modalElement->GetParent() != rootElement_)
+        return false;
+    
     // Currently only allow modal window
     // Currently only allow modal window
     if (modalElement && modalElement->GetType() != Window::GetTypeStatic())
     if (modalElement && modalElement->GetType() != Window::GetTypeStatic())
         return false;
         return false;
-
-    modalElement_ = modalElement;
+    
+    modalElement_ = enable ? modalElement : 0;
     return true;
     return true;
 }
 }
 
 

+ 2 - 2
Engine/UI/UI.h

@@ -52,8 +52,8 @@ public:
     void SetCursor(Cursor* cursor);
     void SetCursor(Cursor* cursor);
     /// Set focused UI element.
     /// Set focused UI element.
     void SetFocusElement(UIElement* 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.)
     /// Clear the UI (excluding the cursor.)
     void Clear();
     void Clear();
     /// Update the UI logic. Called by HandlePostUpdate().
     /// 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)
 void Window::SetModal(bool modal)
 {
 {
     UI* ui = GetSubsystem<UI>();
     UI* ui = GetSubsystem<UI>();
-    if (ui->SetModalElement(modal ? this : 0))
+    if (ui->SetModalElement(this, modal))
         modal_ = modal;
         modal_ = modal;
 }
 }