Selaa lähdekoodia

items in inventory views can now moved to different slots

Kolja Strohm 2 vuotta sitten
vanhempi
commit
b282a3912a

+ 6 - 4
FactoryCraft/CraftingGrid.cpp

@@ -19,16 +19,18 @@ Framework::Zeichnung* CraftingGridElement::parseElement(Framework::XML::Element&
 {
 	Text targetValue = element.getAttributeValue("target");
 	Vec3<int> blockPos(0, 0, 0);
-	Framework::Either<int, Vec3<int>> target((int)targetValue);
+	Framework::Either<int, VecN<int, 4>> target((int)targetValue);
 	if (targetValue.hat(','))
 	{
 		Text* first = targetValue.getTeilText(0, targetValue.positionVon(",", 0) + 1);
 		Text* second = targetValue.getTeilText(targetValue.positionVon(",", 0) + 1, targetValue.positionVon(",", 1));
-		Text* third = targetValue.getTeilText(targetValue.positionVon(",", 1) + 1);
-		target = Framework::Either<int, Vec3<int>>(Vec3<int>((int)*first, (int)*second, (int)*third));
+		Text* third = targetValue.getTeilText(targetValue.positionVon(",", 1) + 1, targetValue.positionVon(",", 2));
+		Text* forth = targetValue.getTeilText(targetValue.positionVon(",", 2) + 1);
+		target = Framework::Either<int, VecN<int, 4>>(VecN<int, 4>({ (int)*first, (int)*second, (int)*third, (int)*forth }));
 		first->release();
 		second->release();
 		third->release();
+		forth->release();
 	}
 	return new CraftingGridView((int)element.getAttributeValue("rowSize"), (int)element.getAttributeValue("colSize"), (int)element.getAttributeValue("numOutputSlots"), target);
 }
@@ -40,7 +42,7 @@ void CraftingGridElement::layout(Framework::XML::Element& element, Framework::Ze
 }
 
 
-CraftingGridView::CraftingGridView(int rowSize, int colSize, int numOutputSlots, Either<int, Vec3<int>> target)
+CraftingGridView::CraftingGridView(int rowSize, int colSize, int numOutputSlots, Either<int, VecN<int, 4>> target)
 	: ZeichnungHintergrund(),
 	rowSize(rowSize),
 	colSize(colSize),

+ 3 - 2
FactoryCraft/CraftingGrid.h

@@ -4,6 +4,7 @@
 
 #include <UIMLView.h>
 #include <Either.h>
+#include <VecN.h>
 
 class CraftingGridElement : public Framework::UIMLElement
 {
@@ -24,10 +25,10 @@ private:
 	int colSize;
 	int numOutputSlots;
 	// entity id or block position
-	Framework::Either<int, Framework::Vec3<int>> target;
+	Framework::Either<int, Framework::VecN<int, 4>> target;
 
 public:
-	CraftingGridView(int rowSize, int colSize, int numOutputSlots, Framework::Either<int, Framework::Vec3<int>> target);
+	CraftingGridView(int rowSize, int colSize, int numOutputSlots, Framework::Either<int, Framework::VecN<int, 4>> target);
 	void api(char* message) override;
 	bool tick(double tickVal) override;
 	void render(Framework::Bild& rObj) override;

+ 3 - 1
FactoryCraft/Dialog.cpp

@@ -15,6 +15,8 @@ UIMLDialog::UIMLDialog(Framework::Text uiml, std::function<void(UIMLDialog* self
 {
 	XML::Element* xml = new XML::Element(uiml);
 	view = new UIMLView("<v/>", uiFactory);
+	view->setStyle(UIMLView::Style::Erlaubt | UIMLView::Style::Sichtbar);
+	view->setMausEreignis(_ret1ME);
 	view->addKnownElement(new InventoryElement());
 	view->addKnownElement(new EquipmentElement());
 	view->addKnownElement(new CraftingGridElement());
@@ -24,7 +26,7 @@ UIMLDialog::UIMLDialog(Framework::Text uiml, std::function<void(UIMLDialog* self
 	view->layout();
 	addMember(view);
 
-	setStyle(Fenster::Style::Sichtbar | Fenster::Style::Erlaubt | Fenster::Style::Rahmen | Fenster::Style::BodyHAlpha | Fenster::Style::Beweglich | Fenster::Style::Titel | Fenster::Style::TitelHAlpha | Fenster::Style::Closable | Fenster::Style::ClosingHAlpha | Fenster::Style::ClosingKlickBuffer | Fenster::Style::TitelHintergrund | Fenster::Style::BodyHintergrund | Fenster::Style::ClosingHintergrund);
+	setStyle(Fenster::Style::Sichtbar | Fenster::Style::Erlaubt | Fenster::Style::Rahmen | Fenster::Style::BodyHAlpha | Fenster::Style::Beweglich | Fenster::Style::Titel | Fenster::Style::TitelHAlpha | Fenster::Style::Closable | Fenster::Style::ClosingHAlpha | Fenster::Style::ClosingKlickBuffer | Fenster::Style::TitelHintergrund | Fenster::Style::BodyHintergrund | Fenster::Style::ClosingHintergrund | Fenster::Style::MEIgnoreInside);
 	setKBgFarbe(0xA0000000);
 	setTBgFarbe(0xA0000000);
 	setSBgFarbe(0xA0000000);

+ 62 - 0
FactoryCraft/DragController.h

@@ -0,0 +1,62 @@
+#pragma once
+
+#include <Zeichnung.h>
+#include "DragElement.h"
+
+template<typename Source, typename Element>
+class DragController : public Framework::ReferenceCounter
+{
+private:
+	Source* container;
+	Element currentElement;
+	DragElement* drag;
+	std::function<void()> onDragEnd;
+
+public:
+	DragController()
+		: ReferenceCounter()
+	{
+		container = 0;
+		currentElement = 0;
+		drag = new DragElement();
+	}
+
+	~DragController()
+	{
+		if (this->container)
+			stopDrag();
+		drag->release();
+	}
+
+	void beginDrag(Source* container, Element element, Framework::Bild* zDragDisplay, std::function<void()> onDragEnd)
+	{
+		if (this->container)
+			stopDrag();
+		((BildZ*)drag)->setBildZ(dynamic_cast<Bild*>(zDragDisplay->getThis()));
+		window->zBildschirm()->addMember(dynamic_cast<Zeichnung*>(drag->getThis()));
+		this->container = container;
+		this->currentElement = element;
+		this->onDragEnd = onDragEnd;
+	}
+
+	Source* getCurrentDragContainer() const
+	{
+		return container;
+	}
+
+	Element getCurrentDaragElement() const
+	{
+		return currentElement;
+	}
+
+	void stopDrag()
+	{
+		if (container)
+		{
+			window->zBildschirm()->removeMember(drag);
+			onDragEnd();
+			container = 0;
+			currentElement = 0;
+		}
+	}
+};

+ 18 - 0
FactoryCraft/DragElement.cpp

@@ -0,0 +1,18 @@
+#include <MausEreignis.h>
+
+#include "DragElement.h"
+
+using namespace Framework;
+
+DragElement::DragElement()
+	: BildZ()
+{
+	setStyle(BildZ::Style::Sichtbar | BildZ::Style::Alpha | BildZ::Style::Skalliert | BildZ::Style::Erlaubt | BildZ::Style::MEIgnoreVerarbeitet | BildZ::Style::MEIgnoreInside | BildZ::Style::MEIgnoreParentInside);
+	setSize(50, 50);
+	setMausEreignis(_ret1ME);
+}
+
+void DragElement::doMausEreignis(Framework::MausEreignis& me, bool userRet)
+{
+	setPosition(pos.x + me.mx, pos.y + me.my);
+}

+ 11 - 0
FactoryCraft/DragElement.h

@@ -0,0 +1,11 @@
+#pragma once
+
+#include <Bild.h>
+
+
+class DragElement : public Framework::BildZ
+{
+public:
+	DragElement();
+	void doMausEreignis(Framework::MausEreignis& me, bool userRet) override;
+};

+ 28 - 0
FactoryCraft/FactoryClient.cpp

@@ -229,4 +229,32 @@ void FactoryClient::entityAPIRequest(int entityId, char* message, unsigned short
 	foreground->sende((char*)&entityId, 4);
 	foreground->sende(message, length - 5);
 	cs.unlock();
+}
+
+void FactoryClient::inventoryAPIRequest(Framework::Either<int, Framework::VecN<int, 4>> target, char* message, unsigned short length)
+{
+	if (!foreground)
+		return;
+	cs.lock();
+	length += target.isA() ? 6 : 18;
+	foreground->sende((char*)&length, 2);
+	char msgId = 4;
+	foreground->sende(&msgId, 1);
+	bool isEntity = target.isA();
+	foreground->sende((char*)&isEntity, 1);
+	if (target.isA())
+	{
+		int id = target.getA();
+		foreground->sende((char*)&id, 4);
+	}
+	else
+	{
+		for (int i = 0; i < 4; i++)
+		{
+			int v = target.getB()[i];
+			foreground->sende((char*)&v, 4);
+		}
+	}
+	foreground->sende(message, length - (target.isA() ? 6 : 18));
+	cs.unlock();
 }

+ 3 - 0
FactoryCraft/FactoryClient.h

@@ -5,6 +5,8 @@
 #include <Text.h>
 #include <Thread.h>
 #include <Critical.h>
+#include <VecN.h>
+#include <Either.h>
 
 class FactoryClient : public Framework::ReferenceCounter
 {
@@ -30,4 +32,5 @@ public:
 	void endMessageReading(bool bg);
 	void sendPlayerAction(char* data, unsigned short length);
 	void entityAPIRequest(int entityId, char* message, unsigned short length);
+	void inventoryAPIRequest(Framework::Either<int, Framework::VecN<int, 4>> target, char* message, unsigned short length);
 };

+ 3 - 0
FactoryCraft/FactoryCraft.vcxproj

@@ -181,6 +181,7 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
     <ClCompile Include="Dialog.cpp" />
     <ClCompile Include="Dimension.cpp" />
     <ClCompile Include="DirectConnect.cpp" />
+    <ClCompile Include="DragElement.cpp" />
     <ClCompile Include="Entity.cpp" />
     <ClCompile Include="EntityRemovedUpdate.cpp" />
     <ClCompile Include="EntityType.cpp" />
@@ -216,6 +217,8 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
     <ClInclude Include="Dialog.h" />
     <ClInclude Include="Dimension.h" />
     <ClInclude Include="DirectConnect.h" />
+    <ClInclude Include="DragController.h" />
+    <ClInclude Include="DragElement.h" />
     <ClInclude Include="Entity.h" />
     <ClInclude Include="EntityRemovedUpdate.h" />
     <ClInclude Include="EntityType.h" />

+ 12 - 0
FactoryCraft/FactoryCraft.vcxproj.filters

@@ -38,6 +38,9 @@
     <Filter Include="Menu\uiml\playerGUI">
       <UniqueIdentifier>{bc1fa16a-bbbf-4627-873b-f6689d2e756b}</UniqueIdentifier>
     </Filter>
+    <Filter Include="Menu\Drag">
+      <UniqueIdentifier>{ac72ca6e-ed3e-47c4-bc20-6847eff39cbc}</UniqueIdentifier>
+    </Filter>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Main.cpp">
@@ -139,6 +142,9 @@
     <ClCompile Include="ItemBar.cpp">
       <Filter>Menu\uiml\playerGUI</Filter>
     </ClCompile>
+    <ClCompile Include="DragElement.cpp">
+      <Filter>Menu\Drag</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="Area.h">
@@ -243,5 +249,11 @@
     <ClInclude Include="ItemBar.h">
       <Filter>Menu\uiml\playerGUI</Filter>
     </ClInclude>
+    <ClInclude Include="DragController.h">
+      <Filter>Menu\Drag</Filter>
+    </ClInclude>
+    <ClInclude Include="DragElement.h">
+      <Filter>Menu\Drag</Filter>
+    </ClInclude>
   </ItemGroup>
 </Project>

+ 9 - 1
FactoryCraft/Game.cpp

@@ -9,6 +9,7 @@
 Game::Game(Bildschirm* zScreen)
 	: Menu(zScreen)
 {
+	inventoryDragController = new DragController<InventoryDragSource, int>();
 	logout = initKnopf(10, 10, 200, 20, Knopf::Style::Normal, "Verlassen");
 	logout->setMausEreignis([this, zScreen](void* p, void* o, MausEreignis me)
 		{
@@ -42,7 +43,9 @@ Game::Game(Bildschirm* zScreen)
 }
 
 Game::~Game()
-{}
+{
+	inventoryDragController->release();
+}
 
 void Game::updatePosition(Vec3<float> position, bool target, Vec3<int> targetPos)
 {
@@ -156,4 +159,9 @@ void Game::closeCurrentDialog()
 		dialogs.remove(dialogs.getEintragAnzahl() - 1);
 		currentGame->zKamera()->setControlEnabled(dialogs.getEintragAnzahl() == 0);
 	}
+}
+
+DragController<InventoryDragSource, int>* Game::zInventoryDragController()
+{
+	return inventoryDragController;
 }

+ 4 - 0
FactoryCraft/Game.h

@@ -5,8 +5,10 @@
 
 #include "Menu.h"
 #include "Dialog.h"
+#include "DragController.h"
 
 class Player;
+class InventoryDragSource;
 
 class Game : public Menu
 {
@@ -15,6 +17,7 @@ private:
 	Framework::TextFeld* debug;
 	Framework::Array<UIMLDialog*> dialogs;
 	Framework::UIMLView* guiView;
+	DragController<InventoryDragSource, int>* inventoryDragController;
 
 public:
 	// Konstruktor
@@ -24,4 +27,5 @@ public:
 	void updatePosition(Vec3<float> position, bool target, Vec3<int> targetPos);
 	void api(char* data);
 	void closeCurrentDialog();
+	DragController<InventoryDragSource, int>* zInventoryDragController();
 };

+ 157 - 10
FactoryCraft/InventoryView.cpp

@@ -3,6 +3,9 @@
 
 #include "InventoryView.h"
 #include "Globals.h"
+#include "DragController.h"
+#include "Globals.h"
+#include "Game.h"
 
 using namespace Framework;
 
@@ -21,16 +24,18 @@ Framework::Zeichnung* InventoryElement::parseElement(Framework::XML::Element& el
 {
 	Text targetValue = element.getAttributeValue("target");
 	Vec3<int> blockPos(0, 0, 0);
-	Framework::Either<int, Vec3<int>> target((int)targetValue);
+	Framework::Either<int, VecN<int, 4>> target((int)targetValue);
 	if (targetValue.hat(','))
 	{
 		Text* first = targetValue.getTeilText(0, targetValue.positionVon(",", 0) + 1);
 		Text* second = targetValue.getTeilText(targetValue.positionVon(",", 0) + 1, targetValue.positionVon(",", 1));
-		Text* third = targetValue.getTeilText(targetValue.positionVon(",", 1) + 1);
-		target = Framework::Either<int, Vec3<int>>(Vec3<int>((int)*first, (int)*second, (int)*third));
+		Text* third = targetValue.getTeilText(targetValue.positionVon(",", 1) + 1, targetValue.positionVon(",", 2));
+		Text* forth = targetValue.getTeilText(targetValue.positionVon(",", 2) + 1);
+		target = Framework::Either<int, VecN<int, 4>>(Framework::VecN<int, 4>({ (int)*first, (int)*second, (int)*third, (int)*forth }));
 		first->release();
 		second->release();
 		third->release();
+		forth->release();
 	}
 	return new InventoryView(element.getAttributeValue("id"), target, (int)element.getAttributeValue("rowSize"), element.getAttributeValue("slotNameFilter"));
 }
@@ -42,13 +47,13 @@ void InventoryElement::layout(Framework::XML::Element& element, Framework::Zeich
 }
 
 
-void SlotInfo::render(int x, int y, Framework::Bild& rObj, bool selected)
+void SlotInfo::render(int x, int y, Framework::Bild& rObj, bool selected, bool lightBackground)
 {
 	TextRenderer tr;
 	tr.setSchriftZ(dynamic_cast<Schrift*>(uiFactory.initParam.schrift->getThis()));
 	tr.setSchriftSize(12);
 	rObj.fillRegion(x, y, 52, 52, selected ? 0xFFFFFFFF : 0xFF52525E);
-	rObj.fillRegion(x + 1, y + 1, 50, 50, 0xFF222222);
+	rObj.fillRegion(x + 1, y + 1, 50, 50, lightBackground ? 0xFF42424E : 0xFF222222);
 	if (itemCount > 0)
 	{
 		rObj.alphaBild(x + 1, y + 1, 50, 50, *zItem);
@@ -73,23 +78,25 @@ void SlotInfo::render(int x, int y, Framework::Bild& rObj, bool selected)
 }
 
 
-InventoryView::InventoryView(Text id, Either<int, Vec3<int>> target, int rowSize, Text slotNameFilter)
+InventoryView::InventoryView(Text id, Either<int, VecN<int, 4>> target, int rowSize, Text slotNameFilter)
 	: ZeichnungHintergrund(),
 	rowSize(rowSize),
 	target(target),
 	slotNameFilter(slotNameFilter),
 	id(id),
-	slots(0)
+	slots(0),
+	dragStartId(-1),
+	dragStopId(-1)
 {
 	if (target.isA())
 	{
 		char* msg = new char[id.getLength() + slotNameFilter.getLength() + 3];
-		msg[0] = 100;
+		msg[0] = 0;
 		msg[1] = (char)id.getLength();
 		memcpy(msg + 2, id.getText(), id.getLength());
 		msg[2 + id.getLength()] = (char)slotNameFilter.getLength();
 		memcpy(msg + 3 + id.getLength(), slotNameFilter.getText(), slotNameFilter.getLength());
-		network->zFactoryClient()->entityAPIRequest(target, msg, id.getLength() + slotNameFilter.getLength() + 3);
+		network->zFactoryClient()->inventoryAPIRequest(target, msg, id.getLength() + slotNameFilter.getLength() + 3);
 		delete[] msg;
 	}
 	setStyle(ZeichnungHintergrund::Style::Sichtbar | ZeichnungHintergrund::Style::Erlaubt);
@@ -97,8 +104,18 @@ InventoryView::InventoryView(Text id, Either<int, Vec3<int>> target, int rowSize
 
 InventoryView::~InventoryView()
 {
+	DragController<InventoryDragSource, int>* controller = ((Game*)(Menu*)menuRegister->get("game"))->zInventoryDragController();
+	if (controller->getCurrentDragContainer() == this)
+		controller->stopDrag();
 	if (slots)
 		slots->release();
+	char* msg = new char[id.getLength() + 2];
+	msg[0] = 1;
+	msg[1] = (char)id.getLength();
+	memcpy(msg + 2, id.getText(), id.getLength());
+	msg[2 + id.getLength()] = (char)slotNameFilter.getLength();
+	network->zFactoryClient()->inventoryAPIRequest(target, msg, id.getLength() + 2);
+	delete[] msg;
 }
 
 void InventoryView::api(char* message)
@@ -133,6 +150,50 @@ void InventoryView::api(char* message)
 			});
 		break;
 	}
+	case 1: // set count of items
+	{
+		int id = *(int*)(message + 1);
+		int count = *(int*)(message + 5);
+		for (int i = 0; i < slots->getEintragAnzahl(); i++)
+		{
+			if (slots->get(i).id == id)
+			{
+				SlotInfo info = slots->get(i);
+				info.itemCount = count;
+				if (info.itemCount == 0)
+				{
+					DragController<InventoryDragSource, int>* controller = ((Game*)(Menu*)menuRegister->get("game"))->zInventoryDragController();
+					if (controller && controller->getCurrentDragContainer() == this && controller->getCurrentDaragElement() == info.id)
+					{
+						controller->stopDrag();
+					}
+				}
+				slots->set(info, i);
+				break;
+			}
+		}
+		break;
+	}
+	case 2: // add new stack
+	{
+		int id = *(int*)(message + 1);
+		for (int i = 0; i < slots->getEintragAnzahl(); i++)
+		{
+			if (slots->get(i).id == id)
+			{
+				SlotInfo info = slots->get(i);
+				info.itemCount = *(int*)(message + 5);
+				info.damage = *(float*)(message + 9);
+				info.maxDamage = *(float*)(message + 13);
+				info.durability = *(float*)(message + 17);
+				info.maxDurability = *(float*)(message + 21);
+				info.zItem = itemIcons->z(*(int*)(message + 25));
+				slots->set(info, i);
+				break;
+			}
+		}
+		break;
+	}
 	}
 }
 
@@ -153,7 +214,7 @@ void InventoryView::render(Bild& rObj)
 		int rowCount = 0;
 		for (SlotInfo info : *slots)
 		{
-			info.render(x, y, rObj, 0);
+			info.render(x, y, rObj, dragStartId == info.id, dragStopId == info.id);
 			x += 60;
 			if (++rowCount >= rowSize)
 			{
@@ -168,5 +229,91 @@ void InventoryView::render(Bild& rObj)
 
 void InventoryView::doMausEreignis(MausEreignis& me, bool userRet)
 {
+	DragController<InventoryDragSource, int>* controller = ((Game*)(Menu*)menuRegister->get("game"))->zInventoryDragController();
+	int x = 0;
+	int y = 0;
+	int rowCount = 0;
+	int slot = 0;
+	dragStopId = -1;
+	for (SlotInfo info : *slots)
+	{
+		if (me.mx >= x && me.mx < x + 50 && me.my >= y && me.my < y + 50)
+		{
+			if (me.id == ME_RLinks)
+			{
+				if (!controller->getCurrentDragContainer() && info.itemCount > 0)
+				{
+					controller->beginDrag(this, info.id, info.zItem, [this]()
+						{
+							dragStartId = -1;
+						});
+					dragStartId = info.id;
+				}
+				else if (controller->getCurrentDragContainer())
+				{
+					// request to transfer items from source to target slot
+					Framework::Either<int, Framework::VecN<int, 4>> source = controller->getCurrentDragContainer()->getInventoryTarget();
+					int len = 2 + (source.isA() ? 4 : 16) + 5 + (target.isA() ? 4 : 16) + 4;
+					char* msg = new char[len];
+					int index = 0;
+					msg[index++] = 6;
+					msg[index++] = (char)source.isA();
+					if (source.isA())
+					{
+						*(int*)(msg + index) = source.getA();
+						index += 4;
+					}
+					else
+					{
+						*(int*)(msg + index) = source.getB()[0];
+						*(int*)(msg + index + 4) = source.getB()[1];
+						*(int*)(msg + index + 8) = source.getB()[2];
+						*(int*)(msg + index + 12) = source.getB()[3];
+						index += 16;
+					}
+					*(int*)(msg + index) = controller->getCurrentDaragElement();
+					index += 4;
+					msg[index++] = target.isA();
+					if (target.isA())
+					{
+						*(int*)(msg + index) = target.getA();
+						index += 4;
+					}
+					else
+					{
+						*(int*)(msg + index) = target.getB()[0];
+						*(int*)(msg + index + 4) = target.getB()[1];
+						*(int*)(msg + index + 8) = target.getB()[2];
+						*(int*)(msg + index + 12) = target.getB()[3];
+						index += 16;
+					}
+					*(int*)(msg + index) = info.id;
+					network->zFactoryClient()->sendPlayerAction(msg, len);
+					delete[] msg;
+				}
+			}
+			else
+			{
+				if (controller->getCurrentDragContainer() && (controller->getCurrentDragContainer() != this || controller->getCurrentDaragElement() != info.id))
+				{
+					dragStopId = info.id;
+				}
+			}
+			break;
+		}
+		x += 60;
+		if (++rowCount >= rowSize)
+		{
+			y += 60;
+			x = 0;
+			rowCount = 0;
+		}
+		slot++;
+	}
 	ZeichnungHintergrund::doMausEreignis(me, userRet);
+}
+
+Framework::Either<int, Framework::VecN<int, 4>> InventoryView::getInventoryTarget() const
+{
+	return target;
 }

+ 14 - 4
FactoryCraft/InventoryView.h

@@ -2,6 +2,7 @@
 
 #include <UIMLView.h>
 #include <Either.h>
+#include <VecN.h>
 
 #include "NetworkAPIProcessor.h"
 
@@ -27,24 +28,33 @@ struct SlotInfo
 	float maxDurability;
 	Framework::Bild* zItem;
 
-	void render(int x, int y, Framework::Bild& rObj, bool selected);
+	void render(int x, int y, Framework::Bild& rObj, bool selected, bool lightBackground);
 };
 
-class InventoryView : public Framework::ZeichnungHintergrund, public NetworkAPIProcessor
+class InventoryDragSource
+{
+public:
+	virtual Framework::Either<int, Framework::VecN<int, 4>> getInventoryTarget() const = 0;
+};
+
+class InventoryView : public Framework::ZeichnungHintergrund, public NetworkAPIProcessor, public InventoryDragSource
 {
 private:
 	int rowSize;
 	// entity id or block position
-	Framework::Either<int, Framework::Vec3<int>> target;
+	Framework::Either<int, Framework::VecN<int, 4>> target;
 	Framework::Text slotNameFilter;
 	Framework::Text id;
 	Framework::Array<SlotInfo>* slots;
+	int dragStartId;
+	int dragStopId;
 
 public:
-	InventoryView(Framework::Text id, Framework::Either<int, Framework::Vec3<int>> target, int rowSize, Framework::Text slotNameFilter);
+	InventoryView(Framework::Text id, Framework::Either<int, Framework::VecN<int, 4>> target, int rowSize, Framework::Text slotNameFilter);
 	~InventoryView();
 	void api(char* message) override;
 	bool tick(double tickVal) override;
 	void render(Framework::Bild& rObj) override;
 	void doMausEreignis(Framework::MausEreignis& me, bool userRet) override;
+	Framework::Either<int, Framework::VecN<int, 4>> getInventoryTarget() const override;
 };

+ 10 - 3
FactoryCraft/ItemBar.cpp

@@ -39,12 +39,12 @@ ItemBarView::ItemBarView(Framework::Text id, int rowSize, int targetEntity, Fram
 	leftHandPos(0)
 {
 	char* msg = new char[id.getLength() + slotNameFilter.getLength() + 3];
-	msg[0] = 100;
+	msg[0] = 0;
 	msg[1] = (char)id.getLength();
 	memcpy(msg + 2, id.getText(), id.getLength());
 	msg[2 + id.getLength()] = (char)slotNameFilter.getLength();
 	memcpy(msg + 3 + id.getLength(), slotNameFilter.getText(), slotNameFilter.getLength());
-	network->zFactoryClient()->entityAPIRequest(targetEntity, msg, id.getLength() + slotNameFilter.getLength() + 3);
+	network->zFactoryClient()->inventoryAPIRequest(targetEntity, msg, id.getLength() + slotNameFilter.getLength() + 3);
 	delete[] msg;
 }
 
@@ -52,6 +52,13 @@ ItemBarView::~ItemBarView()
 {
 	if (slots)
 		slots->release();
+	char* msg = new char[id.getLength() + 2];
+	msg[0] = 1;
+	msg[1] = (char)id.getLength();
+	memcpy(msg + 2, id.getText(), id.getLength());
+	msg[2 + id.getLength()] = (char)slotNameFilter.getLength();
+	network->zFactoryClient()->inventoryAPIRequest(targetEntity, msg, id.getLength() + 2);
+	delete[] msg;
 }
 
 void ItemBarView::api(char* message)
@@ -143,7 +150,7 @@ void ItemBarView::render(Bild& rObj)
 		int index = 0;
 		for (SlotInfo info : *slots)
 		{
-			info.render(x, y, rObj, index == leftHandPos);
+			info.render(x, y, rObj, index == leftHandPos, index == (leftHandPos + 1) % slots->getEintragAnzahl());
 			x += 60;
 			if (++rowCount >= rowSize)
 			{