소스 검색

add inventory tooltips

Kolja Strohm 2 년 전
부모
커밋
de23ca92ba
4개의 변경된 파일40개의 추가작업 그리고 0개의 파일을 삭제
  1. 2 0
      FactoryCraft/FactoryCraft.vcxproj
  2. 31 0
      FactoryCraft/Inventory.cpp
  3. 6 0
      FactoryCraft/Item.cpp
  4. 1 0
      FactoryCraft/Item.h

+ 2 - 0
FactoryCraft/FactoryCraft.vcxproj

@@ -220,6 +220,8 @@
     </Link>
     <ClCompile>
       <CppLanguageStandard>c++17</CppLanguageStandard>
+      <AdditionalIncludeDirectories>../../../Framework/debug;../../../Network/debug/Network;../../../KsgScript/debug/KsgScript</AdditionalIncludeDirectories>
+      <ObjectFileName>/home/kolja/projects/Server/FactoryCraft/debug/%(filename).o</ObjectFileName>
     </ClCompile>
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">

+ 31 - 0
FactoryCraft/Inventory.cpp

@@ -621,6 +621,7 @@ void Inventory::inventoryApi(Framework::StreamReader* zRequest, NetworkMessage*
 		break;
 	}
 	case 1: // remove Observer
+	{
 		char idLen;
 		zRequest->lese(&idLen, 1);
 		char* id = new char[idLen + 1];
@@ -630,6 +631,36 @@ void Inventory::inventoryApi(Framework::StreamReader* zRequest, NetworkMessage*
 		delete[] id;
 		break;
 	}
+	case 2: // request item tooltip
+	{
+		char idLen;
+		zRequest->lese(&idLen, 1);
+		char* id = new char[idLen + 1];
+		zRequest->lese(id, idLen);
+		id[(int)idLen] = 0;
+		zResponse->addressGui(id);
+		delete[] id;
+		int slotId;
+		zRequest->lese((char*)&slotId, 4);
+		Text uiml;
+		for (ItemSlot* slot : *pullSlotsOrder)
+		{
+			if (slot->getId() == slotId)
+			{
+				if (slot->zStack() && slot->zStack()->zItem())
+					uiml = slot->zStack()->zItem()->getTooltipUIML();
+			}
+		}
+		short len = (short)uiml.getLength();
+		char* buffer = new char[uiml.getLength() + 7];
+		buffer[0] = 3;
+		*(int*)(buffer + 1) = slotId;
+		*(short*)(buffer + 5) = len;
+		memcpy(buffer + 7, uiml, len);
+		zResponse->setMessage(buffer, len + 7);
+		break;
+	}
+	}
 }
 
 void Inventory::registerAfterPullStackCall(std::function<void(ItemSlot* zSlot, Direction dir, const Item* zItem, int count)> call)

+ 6 - 0
FactoryCraft/Item.cpp

@@ -1,4 +1,5 @@
 #include "Item.h"
+#include <Text.h>
 
 
 Item::Item(const ItemType* zType, const char* name)
@@ -106,6 +107,11 @@ void Item::onPlaced()
 	hp = 0;
 }
 
+Framework::Text Item::getTooltipUIML() const
+{
+	return Framework::Text("<tip><text width=\"auto\" height=\"auto\">") + name + "</text></tip>";
+}
+
 void Item::applyInventoryEffects(Entity* zTarget)
 {}
 

+ 1 - 0
FactoryCraft/Item.h

@@ -43,6 +43,7 @@ public:
 	float getMaxHp() const;
 	virtual bool canBeStackedWith(const Item* zItem) const;
 	virtual void onPlaced();
+	virtual Framework::Text getTooltipUIML() const;
 
 	virtual void applyInventoryEffects(Entity* zTarget);
 	virtual void removeInventoryEffects(Entity* zTarget);