Browse Source

Add tooltip to explain why controls are disabled

kiwec 2 months ago
parent
commit
6f93935193
2 changed files with 17 additions and 2 deletions
  1. 13 1
      src/GUI/CBaseUIElement.cpp
  2. 4 1
      src/GUI/CBaseUIElement.h

+ 13 - 1
src/GUI/CBaseUIElement.cpp

@@ -2,6 +2,8 @@
 
 #include "Engine.h"
 #include "Mouse.h"
+#include "Osu.h"
+#include "TooltipOverlay.h"
 
 void CBaseUIElement::mouse_update(bool *propagate_clicks) {
     // check if mouse is inside element
@@ -18,7 +20,17 @@ void CBaseUIElement::mouse_update(bool *propagate_clicks) {
         }
     }
 
-    if(!m_bVisible || !m_bEnabled) return;
+    if(!m_bVisible) return;
+
+    if(!m_bEnabled) {
+        if(m_bMouseInside && disabled_reason != NULL) {
+            osu->getTooltipOverlay()->begin();
+            osu->getTooltipOverlay()->addLine(disabled_reason);
+            osu->getTooltipOverlay()->end();
+        }
+
+        return;
+    }
 
     if(engine->getMouse()->isLeftDown() && *propagate_clicks) {
         m_bMouseUpCheck = true;

+ 4 - 1
src/GUI/CBaseUIElement.h

@@ -123,12 +123,13 @@ class CBaseUIElement : public KeyboardListener {
         m_bKeepActive = keepActive;
         return this;
     }
-    virtual CBaseUIElement *setEnabled(bool enabled) {
+    virtual CBaseUIElement *setEnabled(bool enabled, const char *reason = NULL) {
         if(enabled != m_bEnabled) {
             m_bEnabled = enabled;
             if(m_bEnabled) {
                 onEnabled();
             } else {
+                disabled_reason = reason;
                 onDisabled();
             }
         }
@@ -184,6 +185,8 @@ class CBaseUIElement : public KeyboardListener {
     Vector2 m_vSize;
     Vector2 m_vmSize;
 
+    const char *disabled_reason = NULL;
+
    private:
     bool m_bMouseInsideCheck = false;
     bool m_bMouseUpCheck = false;