Forráskód Böngészése

fix inventoty item tooltips sometimes not appearing

Kolja Strohm 2 éve
szülő
commit
585c46ad37

+ 32 - 14
FactoryCraft/CraftingGrid.cpp

@@ -118,15 +118,15 @@ CraftingGridView::CraftingGridView(Text id,
     delete[] msg;
     setNeedToolTipEvent([this](Zeichnung* z, Punkt p) {
         int slot = getSlotByLocalPos(p);
-        if (currentTooltipSlot != slot)
+        if (currentTooltipSlot != slot && currentTooltipSlot != -1)
         {
+            std::cout << "closing tooltip\n";
             this->setToolTipZ(0);
             currentTooltipSlot = -1;
         }
-        else
-            return;
-        if (requestetTooltipSlot != slot)
+        if (requestetTooltipSlot != slot && slot != -1)
         {
+            std::cout << "requesting tooltip for slot " << slot << "\n";
             requestetTooltipSlot = slot;
             char* msg = new char[this->id.getLength() + 6];
             msg[0] = 2; // request inventory tooltip
@@ -135,7 +135,9 @@ CraftingGridView::CraftingGridView(Text id,
             *(int*)(msg + 2 + this->id.getLength()) = slot;
             World::INSTANCE->zClient()->inventoryAPIRequest(
                 this->target, msg, this->id.getLength() + 6);
+            return 1;
         }
+        return 0;
     });
 }
 
@@ -267,16 +269,24 @@ void CraftingGridView::api(char* message)
             int slotId = *(int*)(message + 1);
             if (slotId == requestetTooltipSlot)
             {
+                std::cout << "tooltip loaded for slot " << slotId << "\n";
                 short len = *(short*)(message + 5);
-                char* uiml = new char[len + 1];
-                memcpy(uiml, message + 7, len);
-                uiml[len] = 0;
-                UIMLToolTip* tip = new UIMLToolTip();
-                tip->setUIML(uiml);
-                setToolTipZ(tip);
-                delete[] uiml;
-                currentTooltipSlot = slotId;
-                requestetTooltipSlot = -1;
+                if (len > 0)
+                {
+                    char* uiml = new char[len + 1];
+                    memcpy(uiml, message + 7, len);
+                    uiml[len] = 0;
+                    UIMLToolTip* tip = new UIMLToolTip();
+                    tip->setUIML(uiml);
+                    tip->setWarten(0);
+                    tip->setPosition(mausPos.x, mausPos.y + 15);
+                    setToolTipZ(tip);
+                    delete[] uiml;
+                    currentTooltipSlot = slotId;
+                    requestetTooltipSlot = -1;
+                }
+                else
+                    toolTipRequested = 0;
             }
             break;
         }
@@ -368,12 +378,20 @@ void CraftingGridView::render(Bild& rObj)
 
 void CraftingGridView::doMausEreignis(MausEreignis& me, bool userRet)
 {
+    mausPos.x = me.originalX;
+    mausPos.y = me.originalY;
     if (!slots) return;
     if (me.id == ME_Bewegung)
     {
         if (getSlotByLocalPos(Punkt(me.mx, me.my)) != currentTooltipSlot)
         {
-            setToolTipZ(0);
+            if (currentTooltipSlot != -1)
+            {
+                std::cout << "closing tooltip\n";
+                setToolTipZ(0);
+            }
+            else
+                toolTipRequested = 0;
             currentTooltipSlot = -1;
         }
     }

+ 1 - 0
FactoryCraft/CraftingGrid.h

@@ -38,6 +38,7 @@ private:
     Framework::Array<SlotInfo>* slots;
     Framework::Array<SlotInfo>* outputs;
     Framework::Text id;
+    Framework::Punkt mausPos;
     int dragStartId;
     int dragStopId;
     Framework::Knopf* craft;

+ 32 - 14
FactoryCraft/InventoryView.cpp

@@ -132,15 +132,15 @@ InventoryView::InventoryView(
     delete[] msg;
     setNeedToolTipEvent([this](Zeichnung* z, Punkt p) {
         int slot = getSlotByLocalPos(p);
-        if (currentTooltipSlot != slot)
+        if (currentTooltipSlot != slot && currentTooltipSlot != -1)
         {
+            std::cout << "closing tooltip\n";
             this->setToolTipZ(0);
             currentTooltipSlot = -1;
         }
-        else
-            return;
-        if (requestetTooltipSlot != slot)
+        if (requestetTooltipSlot != slot && slot != -1)
         {
+            std::cout << "requesting tooltip for slot " << slot << "\n";
             requestetTooltipSlot = slot;
             char* msg = new char[this->id.getLength() + 6];
             msg[0] = 2; // request inventory tooltip
@@ -149,7 +149,9 @@ InventoryView::InventoryView(
             *(int*)(msg + 2 + this->id.getLength()) = slot;
             World::INSTANCE->zClient()->inventoryAPIRequest(
                 this->target, msg, this->id.getLength() + 6);
+            return 1;
         }
+        return 0;
     });
 }
 
@@ -279,16 +281,24 @@ void InventoryView::api(char* message)
             int slotId = *(int*)(message + 1);
             if (slotId == requestetTooltipSlot)
             {
+                std::cout << "tooltip loaded for slot " << slotId << "\n";
                 short len = *(short*)(message + 5);
-                char* uiml = new char[len + 1];
-                memcpy(uiml, message + 7, len);
-                uiml[len] = 0;
-                UIMLToolTip* tip = new UIMLToolTip();
-                tip->setUIML(uiml);
-                setToolTipZ(tip);
-                delete[] uiml;
-                currentTooltipSlot = slotId;
-                requestetTooltipSlot = -1;
+                if (len > 0)
+                {
+                    char* uiml = new char[len + 1];
+                    memcpy(uiml, message + 7, len);
+                    uiml[len] = 0;
+                    UIMLToolTip* tip = new UIMLToolTip();
+                    tip->setUIML(uiml);
+                    tip->setWarten(0);
+                    tip->setPosition(mausPos.x, mausPos.y + 15);
+                    setToolTipZ(tip);
+                    delete[] uiml;
+                    currentTooltipSlot = slotId;
+                    requestetTooltipSlot = -1;
+                }
+                else
+                    toolTipRequested = 0;
             }
         }
     }
@@ -326,12 +336,20 @@ void InventoryView::render(Bild& rObj)
 
 void InventoryView::doMausEreignis(MausEreignis& me, bool userRet)
 {
+    mausPos.x = me.originalX;
+    mausPos.y = me.originalY;
     if (!slots) return;
     if (me.id == ME_Bewegung)
     {
         if (getSlotByLocalPos(Punkt(me.mx, me.my)) != currentTooltipSlot)
         {
-            setToolTipZ(0);
+            if (currentTooltipSlot != -1)
+            {
+                std::cout << "closing tooltip\n";
+                setToolTipZ(0);
+            }
+            else
+                toolTipRequested = 0;
             currentTooltipSlot = -1;
         }
     }

+ 1 - 0
FactoryCraft/InventoryView.h

@@ -59,6 +59,7 @@ private:
     Framework::Text slotNameFilter;
     Framework::Text id;
     Framework::Array<SlotInfo>* slots;
+    Framework::Punkt mausPos;
     int dragStartId;
     int dragStopId;
     int currentTooltipSlot;

+ 1 - 0
FactoryCraft/Main.cpp

@@ -57,6 +57,7 @@ int KSGStart Framework::Start(Framework::Startparam p)
 
     RenderTh rTh;
     rTh.setMaxFps(120);
+    rTh.setQuiet(1);
     rTh.setBildschirm(dynamic_cast<Bildschirm*>(screen.getThis()));
 
     rTh.beginn();