فهرست منبع

add inventory uiml tooltips

Kolja Strohm 2 سال پیش
والد
کامیت
7d1d400d57

+ 78 - 2
FactoryCraft/CraftingGrid.cpp

@@ -4,6 +4,7 @@
 #include "Globals.h"
 #include "DragController.h"
 #include "Game.h"
+#include "UIMLToolTip.h"
 
 using namespace Framework;
 
@@ -55,7 +56,9 @@ CraftingGridView::CraftingGridView(Text id, int rowSize, int colSize, int numOut
 	outputs(0),
 	id(id),
 	dragStartId(-1),
-	dragStopId(-1)
+	dragStopId(-1),
+	currentTooltipSlot(-1),
+	requestetTooltipSlot(-1)
 {
 	craft = uiFactory.createKnopf(uiFactory.initParam);
 	craft->setPosition(rowSize * 60, 10);
@@ -84,13 +87,34 @@ CraftingGridView::CraftingGridView(Text id, int rowSize, int colSize, int numOut
 		});
 	setStyle(ZeichnungHintergrund::Style::Sichtbar | ZeichnungHintergrund::Style::Erlaubt);
 	char* msg = new char[id.getLength() + 12 + 3];
-	msg[0] = 0; // request inventory content
+	msg[0] = 0; // request inventory tooltip
 	msg[1] = (char)id.getLength();
 	memcpy(msg + 2, id.getText(), id.getLength());
 	msg[2 + id.getLength()] = (char)12;
 	memcpy(msg + 3 + id.getLength(), "CraftingGrid", 12);
 	network->zFactoryClient()->inventoryAPIRequest(target, msg, id.getLength() + 12 + 3);
 	delete[] msg;
+	setNeedToolTipEvent([this](Zeichnung* z, Punkt p)
+		{
+			int slot = getSlotByLocalPos(p);
+			if (currentTooltipSlot != slot)
+			{
+				this->setToolTipZ(0);
+				currentTooltipSlot = -1;
+			}
+			else
+				return;
+			if (requestetTooltipSlot != slot)
+			{
+				requestetTooltipSlot = slot;
+				char* msg = new char[this->id.getLength() + 6];
+				msg[0] = 2; // request inventory tooltip
+				msg[1] = (char)this->id.getLength();
+				memcpy(msg + 2, this->id.getText(), this->id.getLength());
+				*(int*)(msg + 2 + this->id.getLength()) = slot;
+				network->zFactoryClient()->inventoryAPIRequest(this->target, msg, this->id.getLength() + 6);
+			}
+		});
 }
 
 CraftingGridView::~CraftingGridView()
@@ -111,6 +135,32 @@ CraftingGridView::~CraftingGridView()
 	craft->release();
 }
 
+int CraftingGridView::getSlotByLocalPos(Punkt pos)
+{
+	int x = 0;
+	int y = 0;
+	int rowCount = 0;
+	int slot = 0;
+	dragStopId = -1;
+	if (slots)
+	{
+		for (SlotInfo info : *slots)
+		{
+			if (pos.x >= x && pos.x < x + 50 && pos.y >= y && pos.y < y + 50)
+				return info.id;
+			x += 60;
+			if (++rowCount >= rowSize)
+			{
+				y += 60;
+				x = 0;
+				rowCount = 0;
+			}
+			slot++;
+		}
+	}
+	return -1;
+}
+
 void CraftingGridView::api(char* message)
 {
 	switch (message[0])
@@ -191,6 +241,24 @@ void CraftingGridView::api(char* message)
 		}
 		break;
 	}
+	case 3: // receive tooltip uiml
+	{
+		int slotId = *(int*)(message + 1);
+		if (slotId == requestetTooltipSlot)
+		{
+			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;
+		}
+		break;
+	}
 	case 100: // set crafting result
 	{
 		Array<SlotInfo>* outputs = new Array<SlotInfo>();
@@ -280,6 +348,14 @@ void CraftingGridView::doMausEreignis(MausEreignis& me, bool userRet)
 {
 	if (!slots)
 		return;
+	if (me.id == ME_Bewegung)
+	{
+		if (getSlotByLocalPos(Punkt(me.mx, me.my)) != currentTooltipSlot)
+		{
+			setToolTipZ(0);
+			currentTooltipSlot = -1;
+		}
+	}
 	craft->doPublicMausEreignis(me);
 	DragController<InventoryDragSource, int>* controller = ((Game*)(Menu*)menuRegister->get("game"))->zInventoryDragController();
 	int x = 0;

+ 3 - 0
FactoryCraft/CraftingGrid.h

@@ -34,6 +34,9 @@ private:
 	int dragStartId;
 	int dragStopId;
 	Framework::Knopf* craft;
+	int currentTooltipSlot;
+	int requestetTooltipSlot;
+	int getSlotByLocalPos(Framework::Punkt pos);
 
 public:
 	CraftingGridView(Framework::Text id, int rowSize, int colSize, int numOutputSlots, Framework::Either<int, Framework::VecN<int, 4>> target);

+ 20 - 20
FactoryCraft/CustomUIDX11PixelShader.h

@@ -373,10 +373,10 @@ ret
 
 const BYTE CustomUIDX11PixelShader[] =
 {
-     68,  88,  66,  67, 163,  34, 
-    211, 186,  80,  77, 115, 205, 
-    140, 245, 103,  55, 224,  90, 
-    206, 234,   1,   0,   0,   0, 
+     68,  88,  66,  67, 106, 225, 
+    185, 123,  45, 143, 202, 134, 
+     48, 116,  50, 123,  61, 214, 
+      0, 179,   1,   0,   0,   0, 
      16, 135,   0,   0,   6,   0, 
       0,   0,  56,   0,   0,   0, 
     192,   6,   0,   0, 104,   7, 
@@ -1869,11 +1869,11 @@ const BYTE CustomUIDX11PixelShader[] =
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
-    148,  46,  49,   1, 151, 233, 
-    139,  98,   1,   0,   0,   0, 
-    206, 172, 162, 213, 219, 221, 
-     43,  76, 166, 114,  60,  97, 
-     59, 236, 194,  42,   0,   0, 
+    148,  46,  49,   1,  76, 230, 
+    173,  98,   1,   0,   0,   0, 
+    101, 231,   8, 104, 190, 233, 
+    161,  79, 170,  94,  31, 240, 
+    101, 252, 195, 219,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       1,   0,   0,   0,   1,   0, 
       0,   0,   0,   0,   0,   0, 
@@ -2045,9 +2045,9 @@ const BYTE CustomUIDX11PixelShader[] =
       1,   0,  43, 236,   3,   0, 
      28,  19,   2,   0,  65,  36, 
       1,   0, 236, 179,   1,   0, 
-    102, 213,   0,   0, 125,  10, 
+    130,  86,   0,   0, 125,  10, 
       2,   0, 125, 181,   2,   0, 
-    232, 119,   1,   0, 193,  33, 
+      8, 246,   1,   0, 193,  33, 
       3,   0,  65, 185,   2,   0, 
       9, 241,   2,   0, 146, 230, 
       3,   0, 125, 218,   1,   0, 
@@ -2979,8 +2979,8 @@ const BYTE CustomUIDX11PixelShader[] =
      32,  32,  32,  32,  32,  32, 
      32,  32,  32,  32,  32,  32, 
      32,  32,  27, 226,  48,   1, 
-    128,   0,   0,   0, 154, 141, 
-    247, 199, 224, 110, 216,   1, 
+    128,   0,   0,   0, 150,  50, 
+    193, 206,  34, 131, 216,   1, 
       1,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
@@ -4310,14 +4310,14 @@ const BYTE CustomUIDX11PixelShader[] =
       6,  16,   0,   0,  23,   0, 
       1,   0,   5,  16,   0,   0, 
      14,   0,  23,  21,   0,  16, 
-      0,   0,   3,   2, 160, 178, 
+      0,   0,   3,   2,   0, 168, 
       0,   0, 242, 241,  10,   0, 
      24,  21,   8,  16,   0,   0, 
       1,   0,   1,   0,  10,   0, 
      24,  21,   9,  16,   0,   0, 
       1,   0,   0,   2,  14,   0, 
      23,  21,   0,   0,   0,   0, 
-     10,   2, 160, 178,   0,   0, 
+     10,   2,   0, 168,   0,   0, 
     242, 241,  10,   0,  24,  21, 
      11,  16,   0,   0,   1,   0, 
       1,   0,  10,   0,  24,  21, 
@@ -5539,10 +5539,10 @@ const BYTE CustomUIDX11PixelShader[] =
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0, 148,  46,  49,   1, 
-    151, 233, 139,  98,   1,   0, 
-      0,   0, 206, 172, 162, 213, 
-    219, 221,  43,  76, 166, 114, 
-     60,  97,  59, 236, 194,  42, 
+     76, 230, 173,  98,   1,   0, 
+      0,   0, 101, 231,   8, 104, 
+    190, 233, 161,  79, 170,  94, 
+     31, 240, 101, 252, 195, 219, 
     174,   0,   0,   0,  47,  76, 
     105, 110, 107,  73, 110, 102, 
     111,   0,  47, 110,  97, 109, 
@@ -5642,7 +5642,7 @@ const BYTE CustomUIDX11PixelShader[] =
       0,   0,   0,   0,   2,   0, 
       9,   0,  80,   9,   0,   0, 
       0,   0,   0,   0, 124,  15, 
-      0,   0,   1,   0, 207, 250, 
+      0,   0,   1,   0, 230, 162, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
      84, 101, 120, 116, 117, 114, 

+ 16 - 16
FactoryCraft/CustomUIDX11VertexShader.h

@@ -204,10 +204,10 @@ ret
 
 const BYTE CustomUIDX11VertexShader[] =
 {
-     68,  88,  66,  67,  29, 231, 
-    141,  33, 141, 128, 253, 136, 
-    129, 210,  29,  70,  82,  79, 
-     89, 114,   1,   0,   0,   0, 
+     68,  88,  66,  67, 143, 216, 
+     40, 130, 135, 133, 159,  47, 
+     80,  61, 122, 110, 122,  63, 
+    233,  71,   1,   0,   0,   0, 
     252,  91,   0,   0,   6,   0, 
       0,   0,  56,   0,   0,   0, 
      84,   3,   0,   0,  12,   4, 
@@ -1228,10 +1228,10 @@ const BYTE CustomUIDX11VertexShader[] =
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0, 148,  46,  49,   1, 
-    151, 233, 139,  98,   1,   0, 
-      0,   0, 213, 193, 158, 200, 
-     94,  44, 123,  71, 165, 179, 
-    128,  32, 182, 163, 132, 123, 
+     77, 230, 173,  98,   1,   0, 
+      0,   0,  31, 211,  72,  14, 
+    223,  99, 248,  65, 178, 123, 
+    161, 152, 215, 128, 184,  34, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   1,   0,   0,   0, 
       1,   0,   0,   0,   0,   0, 
@@ -1996,8 +1996,8 @@ const BYTE CustomUIDX11VertexShader[] =
      10, 125,  13,  10,  13,  10, 
      99,  98, 117, 102, 102, 101, 
     114,  32,  27, 226,  48,   1, 
-    128,   0,   0,   0,  24,  84, 
-     69, 200, 224, 110, 216,   1, 
+    128,   0,   0,   0, 123, 219, 
+      0, 207,  34, 131, 216,   1, 
       1,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
@@ -3702,11 +3702,11 @@ const BYTE CustomUIDX11VertexShader[] =
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
-    148,  46,  49,   1, 151, 233, 
-    139,  98,   1,   0,   0,   0, 
-    213, 193, 158, 200,  94,  44, 
-    123,  71, 165, 179, 128,  32, 
-    182, 163, 132, 123, 175,   0, 
+    148,  46,  49,   1,  77, 230, 
+    173,  98,   1,   0,   0,   0, 
+     31, 211,  72,  14, 223,  99, 
+    248,  65, 178, 123, 161, 152, 
+    215, 128, 184,  34, 175,   0, 
       0,   0,  47,  76, 105, 110, 
     107,  73, 110, 102, 111,   0, 
      47, 110,  97, 109, 101, 115, 
@@ -3806,7 +3806,7 @@ const BYTE CustomUIDX11VertexShader[] =
       0,   0,   2,   0,   9,   0, 
      64,   6,   0,   0,   0,   0, 
       0,   0, 244,   6,   0,   0, 
-      1,   0, 161, 142,   0,   0, 
+      1,   0, 199, 222,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,  84, 101, 
     120, 116, 117, 114, 101,  86, 

+ 2 - 0
FactoryCraft/FactoryCraft.vcxproj

@@ -200,6 +200,7 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
     <ClCompile Include="NetworkHandler.cpp" />
     <ClCompile Include="PlayerKam.cpp" />
     <ClCompile Include="StaticInitializerOrder.cpp" />
+    <ClCompile Include="UIMLToolTip.cpp" />
     <ClCompile Include="World.cpp" />
     <ClCompile Include="WorldUpdate.cpp" />
   </ItemGroup>
@@ -236,6 +237,7 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
     <ClInclude Include="PlayerKam.h" />
     <ClInclude Include="Registries.h" />
     <ClInclude Include="StaticRegistry.h" />
+    <ClInclude Include="UIMLToolTip.h" />
     <ClInclude Include="WorldUpdate.h" />
     <ClInclude Include="World.h" />
   </ItemGroup>

+ 9 - 0
FactoryCraft/FactoryCraft.vcxproj.filters

@@ -47,6 +47,9 @@
     <Filter Include="graphics\shader">
       <UniqueIdentifier>{d6d24212-c40d-4486-b3c2-e26df0f37295}</UniqueIdentifier>
     </Filter>
+    <Filter Include="Menu\uiml\ToolTip">
+      <UniqueIdentifier>{6b6b7dea-e3f2-4812-ae3f-24c8ea365780}</UniqueIdentifier>
+    </Filter>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Main.cpp">
@@ -145,6 +148,9 @@
     <ClCompile Include="CustomDX11API.cpp">
       <Filter>graphics</Filter>
     </ClCompile>
+    <ClCompile Include="UIMLToolTip.cpp">
+      <Filter>Menu\uiml\ToolTip</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="Area.h">
@@ -249,6 +255,9 @@
     <ClInclude Include="CustomDX11API.h">
       <Filter>graphics</Filter>
     </ClInclude>
+    <ClInclude Include="UIMLToolTip.h">
+      <Filter>Menu\uiml\ToolTip</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <FxCompile Include="DX11CustomVertexShader.hlsl">

+ 76 - 1
FactoryCraft/InventoryView.cpp

@@ -6,6 +6,7 @@
 #include "DragController.h"
 #include "Globals.h"
 #include "Game.h"
+#include "UIMLToolTip.h"
 
 using namespace Framework;
 
@@ -86,7 +87,9 @@ InventoryView::InventoryView(Text id, Either<int, VecN<int, 4>> target, int rowS
 	id(id),
 	slots(0),
 	dragStartId(-1),
-	dragStopId(-1)
+	dragStopId(-1),
+	currentTooltipSlot(-1),
+	requestetTooltipSlot(-1)
 {
 	setStyle(ZeichnungHintergrund::Style::Sichtbar | ZeichnungHintergrund::Style::Erlaubt);
 	char* msg = new char[id.getLength() + slotNameFilter.getLength() + 3];
@@ -97,6 +100,27 @@ InventoryView::InventoryView(Text id, Either<int, VecN<int, 4>> target, int rowS
 	memcpy(msg + 3 + id.getLength(), slotNameFilter.getText(), slotNameFilter.getLength());
 	network->zFactoryClient()->inventoryAPIRequest(target, msg, id.getLength() + slotNameFilter.getLength() + 3);
 	delete[] msg;
+	setNeedToolTipEvent([this](Zeichnung* z, Punkt p)
+		{
+			int slot = getSlotByLocalPos(p);
+			if (currentTooltipSlot != slot)
+			{
+				this->setToolTipZ(0);
+				currentTooltipSlot = -1;
+			}
+			else
+				return;
+			if (requestetTooltipSlot != slot)
+			{
+				requestetTooltipSlot = slot;
+				char* msg = new char[this->id.getLength() + 6];
+				msg[0] = 2; // request inventory tooltip
+				msg[1] = (char)this->id.getLength();
+				memcpy(msg + 2, this->id.getText(), this->id.getLength());
+				*(int*)(msg + 2 + this->id.getLength()) = slot;
+				network->zFactoryClient()->inventoryAPIRequest(this->target, msg, this->id.getLength() + 6);
+			}
+		});
 }
 
 InventoryView::~InventoryView()
@@ -114,6 +138,32 @@ InventoryView::~InventoryView()
 	delete[] msg;
 }
 
+int InventoryView::getSlotByLocalPos(Punkt pos)
+{
+	int x = 0;
+	int y = 0;
+	int rowCount = 0;
+	int slot = 0;
+	dragStopId = -1;
+	if (slots)
+	{
+		for (SlotInfo info : *slots)
+		{
+			if (pos.x >= x && pos.x < x + 50 && pos.y >= y && pos.y < y + 50)
+				return info.id;
+			x += 60;
+			if (++rowCount >= rowSize)
+			{
+				y += 60;
+				x = 0;
+				rowCount = 0;
+			}
+			slot++;
+		}
+	}
+	return -1;
+}
+
 void InventoryView::api(char* message)
 {
 	switch (message[0])
@@ -194,6 +244,23 @@ void InventoryView::api(char* message)
 		}
 		break;
 	}
+	case 3: // receive tooltip uiml
+	{
+		int slotId = *(int*)(message + 1);
+		if (slotId == requestetTooltipSlot)
+		{
+			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;
+		}
+	}
 	}
 }
 
@@ -231,6 +298,14 @@ void InventoryView::doMausEreignis(MausEreignis& me, bool userRet)
 {
 	if (!slots)
 		return;
+	if (me.id == ME_Bewegung)
+	{
+		if (getSlotByLocalPos(Punkt(me.mx, me.my)) != currentTooltipSlot)
+		{
+			setToolTipZ(0);
+			currentTooltipSlot = -1;
+		}
+	}
 	DragController<InventoryDragSource, int>* controller = ((Game*)(Menu*)menuRegister->get("game"))->zInventoryDragController();
 	int x = 0;
 	int y = 0;

+ 3 - 0
FactoryCraft/InventoryView.h

@@ -48,6 +48,9 @@ private:
 	Framework::Array<SlotInfo>* slots;
 	int dragStartId;
 	int dragStopId;
+	int currentTooltipSlot;
+	int requestetTooltipSlot;
+	int getSlotByLocalPos(Framework::Punkt pos);
 
 public:
 	InventoryView(Framework::Text id, Framework::Either<int, Framework::VecN<int, 4>> target, int rowSize, Framework::Text slotNameFilter);

+ 6 - 0
FactoryCraft/NetworkHandler.cpp

@@ -96,10 +96,16 @@ bool NetworkHandler::connect(Text ip, short port)
 	if (!gsc)
 		gsc = msc->createMinigameServerClient();
 	if (!gsc)
+	{
+		std::cout << "could not create minigame server client.\n";
 		return 0;
+	}
 	Text* secret = gsc->getSecret();
 	if (!secret)
+	{
+		std::cout << "could not get secret from minigame server.\n";
 		return 0;
+	}
 	if (!fc)
 		fc = new FactoryClient();
 	bool ok = fc->connect(ip, port, accountId, *secret);

+ 26 - 0
FactoryCraft/UIMLToolTip.cpp

@@ -0,0 +1,26 @@
+#include "UIMLToolTip.h"
+#include "Globals.h"
+
+using namespace Framework;
+
+UIMLToolTip::UIMLToolTip()
+	: ToolTip(window->zBildschirm())
+{
+	view = new UIMLView("", uiFactory);
+	addMember(view);
+	view->setStyle(UIMLView::Style::Sichtbar);
+	addStyle(ZeichnungHintergrund::Style::Hintergrund | ZeichnungHintergrund::Style::HAlpha | ZeichnungHintergrund::Style::Rahmen | ZeichnungHintergrund::Style::Sichtbar);
+	setHintergrundFarbe(0xA0000000);
+	setRahmenFarbe(0xFFFFFFFF);
+	setRahmenBreite(1);
+}
+
+UIMLToolTip::~UIMLToolTip()
+{}
+
+void UIMLToolTip::setUIML(const char* uiml)
+{
+	view->setUIML(uiml);
+	view->layout();
+	view->setSize(view->calculateContentSize());
+}

+ 15 - 0
FactoryCraft/UIMLToolTip.h

@@ -0,0 +1,15 @@
+#pragma once
+
+#include <ToolTip.h>
+#include <UIMLView.h>
+
+class UIMLToolTip : public Framework::ToolTip
+{
+private:
+	Framework::UIMLView *view;
+
+public:
+	UIMLToolTip();
+	~UIMLToolTip();
+	void setUIML(const char* uiml);
+};