|
@@ -0,0 +1,158 @@
|
|
|
+#include <XML.h>
|
|
|
+#include <Bild.h>
|
|
|
+
|
|
|
+#include "ItemBar.h"
|
|
|
+#include "Globals.h"
|
|
|
+
|
|
|
+using namespace Framework;
|
|
|
+
|
|
|
+ItemBarElement::ItemBarElement()
|
|
|
+ : UIMLElement()
|
|
|
+{}
|
|
|
+
|
|
|
+//! prüft, ob dieses UIML Element für ein bestimmtes xml Element zuständig ist
|
|
|
+bool ItemBarElement::isApplicableFor(Framework::XML::Element& element)
|
|
|
+{
|
|
|
+ return element.getName().istGleich("itemBar");
|
|
|
+}
|
|
|
+
|
|
|
+//! erstellt eine neue Zeichnung zu einem gegebenen xml Element
|
|
|
+Framework::Zeichnung* ItemBarElement::parseElement(Framework::XML::Element& element, Framework::UIMLContainer& generalFactory)
|
|
|
+{
|
|
|
+ return new ItemBarView(element.getAttributeValue("id"), (int)element.getAttributeValue("rowSize"), (int)element.getAttributeValue("target"), element.getAttributeValue("slotNameFilter"));
|
|
|
+}
|
|
|
+
|
|
|
+//! wendet die layout parameter zu einer Zeichnung an
|
|
|
+void ItemBarElement::layout(Framework::XML::Element& element, Framework::Zeichnung& z, int pWidth, int pHeight, Framework::UIMLContainer& generalLayouter)
|
|
|
+{
|
|
|
+ UIMLElement::layout(element, z, pWidth, pHeight, generalLayouter);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+ItemBarView::ItemBarView(Framework::Text id, int rowSize, int targetEntity, Framework::Text slotNameFilter)
|
|
|
+ : ZeichnungHintergrund(),
|
|
|
+ id(id),
|
|
|
+ rowSize(rowSize),
|
|
|
+ targetEntity(targetEntity),
|
|
|
+ slotNameFilter(slotNameFilter),
|
|
|
+ slots(0),
|
|
|
+ leftHandPos(0)
|
|
|
+{
|
|
|
+ char* msg = new char[id.getLength() + slotNameFilter.getLength() + 3];
|
|
|
+ msg[0] = 100;
|
|
|
+ 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);
|
|
|
+ delete[] msg;
|
|
|
+}
|
|
|
+
|
|
|
+ItemBarView::~ItemBarView()
|
|
|
+{
|
|
|
+ if (slots)
|
|
|
+ slots->release();
|
|
|
+}
|
|
|
+
|
|
|
+void ItemBarView::api(char* message)
|
|
|
+{
|
|
|
+ switch (message[0])
|
|
|
+ {
|
|
|
+ case 0:
|
|
|
+ // send inventory content
|
|
|
+ {
|
|
|
+ Array<SlotInfo>* slots = new Array<SlotInfo>();
|
|
|
+ int count = *(int*)(++message);
|
|
|
+ for (int i = 0; i < count; i++)
|
|
|
+ {
|
|
|
+ SlotInfo info;
|
|
|
+ info.id = *(int*)(message += 4);
|
|
|
+ info.itemCount = *(int*)(message += 4);
|
|
|
+ if (info.itemCount > 0)
|
|
|
+ {
|
|
|
+ info.damage = *(float*)(message += 4);
|
|
|
+ info.maxDamage = *(float*)(message += 4);
|
|
|
+ info.durability = *(float*)(message += 4);
|
|
|
+ info.maxDurability = *(float*)(message += 4);
|
|
|
+ info.zItem = itemIcons->z(*(int*)(message += 4));
|
|
|
+ }
|
|
|
+ slots->add(info);
|
|
|
+ }
|
|
|
+ postAction([this, slots]()
|
|
|
+ {
|
|
|
+ if (this->slots)
|
|
|
+ this->slots->release();
|
|
|
+ this->slots = slots;
|
|
|
+ });
|
|
|
+ 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;
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ case 3: // set selected slot
|
|
|
+ {
|
|
|
+ leftHandPos = *(int*)(message + 1);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void ItemBarView::render(Bild& rObj)
|
|
|
+{
|
|
|
+ ZeichnungHintergrund::render(rObj);
|
|
|
+ if (!rObj.setDrawOptions(pos.x, pos.y, gr.x, gr.y))
|
|
|
+ return;
|
|
|
+ if (slots)
|
|
|
+ {
|
|
|
+ int x = 0;
|
|
|
+ int y = 0;
|
|
|
+ int rowCount = 0;
|
|
|
+ int index = 0;
|
|
|
+ for (SlotInfo info : *slots)
|
|
|
+ {
|
|
|
+ info.render(x, y, rObj, index == leftHandPos);
|
|
|
+ x += 60;
|
|
|
+ if (++rowCount >= rowSize)
|
|
|
+ {
|
|
|
+ y += 60;
|
|
|
+ x = 0;
|
|
|
+ rowCount = 0;
|
|
|
+ }
|
|
|
+ index++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ rObj.releaseDrawOptions();
|
|
|
+}
|