|
@@ -3,6 +3,9 @@
|
|
|
|
|
|
#include "InventoryView.h"
|
|
#include "InventoryView.h"
|
|
#include "Globals.h"
|
|
#include "Globals.h"
|
|
|
|
+#include "DragController.h"
|
|
|
|
+#include "Globals.h"
|
|
|
|
+#include "Game.h"
|
|
|
|
|
|
using namespace Framework;
|
|
using namespace Framework;
|
|
|
|
|
|
@@ -21,16 +24,18 @@ Framework::Zeichnung* InventoryElement::parseElement(Framework::XML::Element& el
|
|
{
|
|
{
|
|
Text targetValue = element.getAttributeValue("target");
|
|
Text targetValue = element.getAttributeValue("target");
|
|
Vec3<int> blockPos(0, 0, 0);
|
|
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(','))
|
|
if (targetValue.hat(','))
|
|
{
|
|
{
|
|
Text* first = targetValue.getTeilText(0, targetValue.positionVon(",", 0) + 1);
|
|
Text* first = targetValue.getTeilText(0, targetValue.positionVon(",", 0) + 1);
|
|
Text* second = targetValue.getTeilText(targetValue.positionVon(",", 0) + 1, targetValue.positionVon(",", 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();
|
|
first->release();
|
|
second->release();
|
|
second->release();
|
|
third->release();
|
|
third->release();
|
|
|
|
+ forth->release();
|
|
}
|
|
}
|
|
return new InventoryView(element.getAttributeValue("id"), target, (int)element.getAttributeValue("rowSize"), element.getAttributeValue("slotNameFilter"));
|
|
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;
|
|
TextRenderer tr;
|
|
tr.setSchriftZ(dynamic_cast<Schrift*>(uiFactory.initParam.schrift->getThis()));
|
|
tr.setSchriftZ(dynamic_cast<Schrift*>(uiFactory.initParam.schrift->getThis()));
|
|
tr.setSchriftSize(12);
|
|
tr.setSchriftSize(12);
|
|
rObj.fillRegion(x, y, 52, 52, selected ? 0xFFFFFFFF : 0xFF52525E);
|
|
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)
|
|
if (itemCount > 0)
|
|
{
|
|
{
|
|
rObj.alphaBild(x + 1, y + 1, 50, 50, *zItem);
|
|
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(),
|
|
: ZeichnungHintergrund(),
|
|
rowSize(rowSize),
|
|
rowSize(rowSize),
|
|
target(target),
|
|
target(target),
|
|
slotNameFilter(slotNameFilter),
|
|
slotNameFilter(slotNameFilter),
|
|
id(id),
|
|
id(id),
|
|
- slots(0)
|
|
|
|
|
|
+ slots(0),
|
|
|
|
+ dragStartId(-1),
|
|
|
|
+ dragStopId(-1)
|
|
{
|
|
{
|
|
if (target.isA())
|
|
if (target.isA())
|
|
{
|
|
{
|
|
char* msg = new char[id.getLength() + slotNameFilter.getLength() + 3];
|
|
char* msg = new char[id.getLength() + slotNameFilter.getLength() + 3];
|
|
- msg[0] = 100;
|
|
|
|
|
|
+ msg[0] = 0;
|
|
msg[1] = (char)id.getLength();
|
|
msg[1] = (char)id.getLength();
|
|
memcpy(msg + 2, id.getText(), id.getLength());
|
|
memcpy(msg + 2, id.getText(), id.getLength());
|
|
msg[2 + id.getLength()] = (char)slotNameFilter.getLength();
|
|
msg[2 + id.getLength()] = (char)slotNameFilter.getLength();
|
|
memcpy(msg + 3 + id.getLength(), slotNameFilter.getText(), 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;
|
|
delete[] msg;
|
|
}
|
|
}
|
|
setStyle(ZeichnungHintergrund::Style::Sichtbar | ZeichnungHintergrund::Style::Erlaubt);
|
|
setStyle(ZeichnungHintergrund::Style::Sichtbar | ZeichnungHintergrund::Style::Erlaubt);
|
|
@@ -97,8 +104,18 @@ InventoryView::InventoryView(Text id, Either<int, Vec3<int>> target, int rowSize
|
|
|
|
|
|
InventoryView::~InventoryView()
|
|
InventoryView::~InventoryView()
|
|
{
|
|
{
|
|
|
|
+ DragController<InventoryDragSource, int>* controller = ((Game*)(Menu*)menuRegister->get("game"))->zInventoryDragController();
|
|
|
|
+ if (controller->getCurrentDragContainer() == this)
|
|
|
|
+ controller->stopDrag();
|
|
if (slots)
|
|
if (slots)
|
|
slots->release();
|
|
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)
|
|
void InventoryView::api(char* message)
|
|
@@ -133,6 +150,50 @@ void InventoryView::api(char* message)
|
|
});
|
|
});
|
|
break;
|
|
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;
|
|
int rowCount = 0;
|
|
for (SlotInfo info : *slots)
|
|
for (SlotInfo info : *slots)
|
|
{
|
|
{
|
|
- info.render(x, y, rObj, 0);
|
|
|
|
|
|
+ info.render(x, y, rObj, dragStartId == info.id, dragStopId == info.id);
|
|
x += 60;
|
|
x += 60;
|
|
if (++rowCount >= rowSize)
|
|
if (++rowCount >= rowSize)
|
|
{
|
|
{
|
|
@@ -168,5 +229,91 @@ void InventoryView::render(Bild& rObj)
|
|
|
|
|
|
void InventoryView::doMausEreignis(MausEreignis& me, bool userRet)
|
|
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);
|
|
ZeichnungHintergrund::doMausEreignis(me, userRet);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+Framework::Either<int, Framework::VecN<int, 4>> InventoryView::getInventoryTarget() const
|
|
|
|
+{
|
|
|
|
+ return target;
|
|
}
|
|
}
|