#include #include #include "InventoryView.h" #include "Globals.h" using namespace Framework; InventoryElement::InventoryElement() : UIMLElement() {} //! prüft, ob dieses UIML Element für ein bestimmtes xml Element zuständig ist bool InventoryElement::isApplicableFor(Framework::XML::Element& element) { return element.getName().istGleich("inventory"); } //! erstellt eine neue Zeichnung zu einem gegebenen xml Element Framework::Zeichnung* InventoryElement::parseElement(Framework::XML::Element& element, Framework::UIMLContainer& generalFactory) { Text targetValue = element.getAttributeValue("target"); Vec3 blockPos(0, 0, 0); Framework::Either> 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>(Vec3((int)*first, (int)*second, (int)*third)); first->release(); second->release(); third->release(); } return new InventoryView(element.getAttributeValue("id"), target, (int)element.getAttributeValue("rowSize"), element.getAttributeValue("slotNameFilter")); } //! wendet die layout parameter zu einer Zeichnung an void InventoryElement::layout(Framework::XML::Element& element, Framework::Zeichnung& z, int pWidth, int pHeight, Framework::UIMLContainer& generalLayouter) { UIMLElement::layout(element, z, pWidth, pHeight, generalLayouter); } void SlotInfo::render(int x, int y, Framework::Bild& rObj) { TextRenderer tr; tr.setSchriftZ(dynamic_cast(uiFactory.initParam.schrift->getThis())); tr.setSchriftSize(12); rObj.fillRegion(x, y, 52, 52, 0xFF52525E); rObj.fillRegion(x + 1, y + 1, 50, 50, 0xFF222222); if (itemCount > 0) { rObj.alphaBild(x + 1, y + 1, 50, 50, *zItem); if (damage < maxDamage) { rObj.fillRegion(x + 1, y + 47, 50, 2, 0xFF000000); rObj.fillRegion(x + 1, y + 47, (int)((damage / maxDamage) * 50), 2, 0xFFFF0000); } if (durability < maxDurability) { rObj.fillRegion(x + 1, y + 49, 50, 2, 0xFF000000); rObj.fillRegion(x + 1, y + 49, (int)((durability / maxDurability) * 50), 2, 0xFF00FF00); } const char* units[] = { "", "K", "M", "G", "T", "P" }; int i = 0; for (; i < 6 && itemCount > 1024; i++) itemCount = itemCount / 1024; Text count = itemCount; count += units[i]; tr.renderText(x + 45 - tr.getTextBreite(count), y + 45 - tr.getTextHeight(count), count, rObj, 0xFFFFFFFF); } } InventoryView::InventoryView(Text id, Either> target, int rowSize, Text slotNameFilter) : ZeichnungHintergrund(), rowSize(rowSize), target(target), slotNameFilter(slotNameFilter), id(id), slots(0) { if (target.isA()) { 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(target, msg, id.getLength() + slotNameFilter.getLength() + 3); delete[] msg; } setStyle(ZeichnungHintergrund::Style::Sichtbar | ZeichnungHintergrund::Style::Erlaubt); } InventoryView::~InventoryView() { if (slots) slots->release(); } void InventoryView::api(char* message) { switch (message[0]) { case 0: // send inventory content { Array* slots = new Array(); 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; }); } } } bool InventoryView::tick(double tickVal) { return ZeichnungHintergrund::tick(tickVal); } void InventoryView::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; for (SlotInfo info : *slots) { info.render(x, y, rObj); x += 60; if (++rowCount >= rowSize) { y += 60; x = 0; rowCount = 0; } } } rObj.releaseDrawOptions(); } void InventoryView::doMausEreignis(MausEreignis& me, bool userRet) { ZeichnungHintergrund::doMausEreignis(me, userRet); }