Răsfoiți Sursa

fix dialog close notification were not send if the dialog was closed via escape key

Kolja Strohm 2 ani în urmă
părinte
comite
3405d50d6d
3 a modificat fișierele cu 36 adăugiri și 29 ștergeri
  1. 34 24
      FactoryCraft/Dialog.cpp
  2. 1 0
      FactoryCraft/Dialog.h
  3. 1 5
      FactoryCraft/Game.cpp

+ 34 - 24
FactoryCraft/Dialog.cpp

@@ -92,33 +92,38 @@ UIMLDialog::UIMLDialog(
     setSize(view->getBreite() + 4, view->getHeight() + 24);
     setPosition(window->zBildschirm()->getBackBufferSize() / 2 - getSize() / 2);
     setRBreite(2);
-    setClosingMe([onClose,
-                     notifyOnClose,
-                     notifyOnCloseDimension,
-                     notifyOnCloseBlock,
-                     this](void* p, void* o, MausEreignis me) {
-        if (me.id == ME_RLinks)
-        {
-            if (notifyOnClose)
-            {
-                if (notifyOnCloseDimension >= 0)
-                {
-                    char* msg = new char[name.getLength() + 3];
-                    msg[0] = 1; // dialog closed
-                    *(short*)(msg + 1) = (short)name.getLength();
-                    memcpy(msg + 3, name.getText(), name.getLength());
-                    World::INSTANCE->zClient()->blockAPIRequest(
+    this->onClose = [onClose,
+                        notifyOnClose,
                         notifyOnCloseDimension,
                         notifyOnCloseBlock,
-                        msg,
-                        name.getLength() + 3);
-                    delete[] msg;
-                } // TODO: else entity notification
-            }
-            onClose(this);
+                        this](UIMLDialog* self) {
+        if (notifyOnClose)
+        {
+            if (notifyOnCloseDimension >= 0)
+            {
+                char* msg = new char[name.getLength() + 3];
+                msg[0] = 1; // dialog closed
+                *(short*)(msg + 1) = (short)name.getLength();
+                memcpy(msg + 3, name.getText(), name.getLength());
+                World::INSTANCE->zClient()->blockAPIRequest(
+                    notifyOnCloseDimension,
+                    notifyOnCloseBlock,
+                    msg,
+                    name.getLength() + 3);
+                delete[] msg;
+            } // TODO: else entity notification
         }
-        return 1;
-    });
+        onClose(this);
+    };
+    setClosingMe(
+        [notifyOnClose, notifyOnCloseDimension, notifyOnCloseBlock, this](
+            void* p, void* o, MausEreignis me) {
+            if (me.id == ME_RLinks)
+            {
+                this->close();
+            }
+            return 1;
+        });
     setRFarbe(0xFF52525E);
     setTitel(xml->getAttributeValue("title"));
     setTSchriftZ(
@@ -150,4 +155,9 @@ void UIMLDialog::api(char* message)
 const Framework::Text& UIMLDialog::getName() const
 {
     return name;
+}
+
+void UIMLDialog::close()
+{
+    onClose(this);
 }

+ 1 - 0
FactoryCraft/Dialog.h

@@ -19,4 +19,5 @@ public:
     ~UIMLDialog();
     void api(char* message) override;
     const Framework::Text& getName() const;
+    void close();
 };

+ 1 - 5
FactoryCraft/Game.cpp

@@ -212,11 +212,7 @@ void Game::closeCurrentDialog()
     if (dialogs.getEintragAnzahl() > 0)
     {
         UIMLDialog* d = dialogs.get(dialogs.getEintragAnzahl() - 1);
-        window->zBildschirm()->removeMember(d);
-        dialogs.remove(dialogs.getEintragAnzahl() - 1);
-        World::INSTANCE->zKamera()->setControlEnabled(
-            dialogs.getEintragAnzahl() == 0);
-        updateRecipieVisibility();
+        d->close();
     }
 }