123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- #include "Game.h"
- #include "Initialisierung.h"
- #include "Globals.h"
- #include <AsynchronCall.h>
- #include <Bildschirm.h>
- Game::Game(Bildschirm* zScreen)
- : Menu(zScreen)
- {
- logout = initKnopf(10, 10, 200, 20, Knopf::Style::Normal, "Verlassen");
- logout->setMausEreignis([this, zScreen](void* p, void* o, MausEreignis me)
- {
- if (me.id == ME_RLinks)
- {
- logout->removeStyle(Knopf::Style::Erlaubt);
- new AsynchronCall([this, zScreen]()
- {
- if (network->leaveGame())
- {
- currentGame->release();
- currentGame = 0;
- zScreen->lock();
- hide();
- menuRegister->get("directConnect")->show();
- zScreen->unlock();
- }
- logout->addStyle(Knopf::Style::Erlaubt);
- });
- }
- return 1;
- });
- elements.add(logout);
- debug = initTextFeld(10, 40, 500, 40, TextFeld::Style::Text | TextFeld::Style::Mehrzeilig, "");
- elements.add(debug);
- invB = new Bild();
- invB->neuBild(zScreen->getBackBufferSize().x - 20, 50, 0);
- invB->setAlpha3D(1);
- inventory = initBildZ(10, zScreen->getBackBufferSize().y - 60, zScreen->getBackBufferSize().x - 20, 50, BildZ::Style::Sichtbar | BildZ::Style::Alpha, invB);
- elements.add(inventory);
- }
- Game::~Game()
- {}
- void Game::updatePosition(Vec3<float> position, bool target, Vec3<int> targetPos)
- {
- Text txt = "Position: (";
- txt.setPrecision(2);
- txt += position.x;
- txt += ", ";
- txt += position.y;
- txt += ", ";
- txt += position.z;
- txt += ")";
- if (target)
- {
- txt += "\nTarget: (";
- txt += targetPos.x;
- txt += ", ";
- txt += targetPos.y;
- txt += ", ";
- txt += targetPos.z;
- txt += ")";
- }
- debug->setText(txt);
- }
- void Game::updateInventory(Framework::Array<ItemSlot*>& itemBar, int pos)
- {
- invB->fillRegion(0, 0, invB->getBreite(), invB->getHeight(), 0);
- TextRenderer tr;
- tr.setSchriftZ(dynamic_cast<Schrift*>(uiFactory.initParam.schrift->getThis()));
- tr.setSchriftSize(12);
- int index = 0;
- for (auto slot : itemBar)
- {
- if (pos == index)
- {
- invB->fillRegion(50 * index, 0, 50, 50, 0x7F202020);
- }
- if (slot && slot->zStack() && slot->zStack()->zItem())
- {
- Bild* icon = itemIcons->z(slot->zStack()->zItem()->zItemType()->getId());
- invB->alphaBild(50 * index, 0, 50, 50, *icon);
- tr.renderText(5 + index * 50, 5, slot->zStack()->zItem()->getName(), *invB, 0xFFFFFFFF);
- int size = slot->zStack()->getSize();
- const char* units[] = { "", "K", "M", "G", "T", "P" };
- int i = 0;
- for (; i < 6 && size > 1024; i++)
- size = size / 1024;
- Text count = size;
- count += units[i];
- tr.renderText(45 - tr.getTextBreite(count) + index * 50, 45 - tr.getTextHeight(count), count, *invB, 0xFFFFFFFF);
- }
- index++;
- }
- inventory->setRender();
- }
- void Game::api(char* data)
- {
- switch (data[0])
- {
- case 0: // open dialog
- {
- bool exists = 0;
- short len = *(short*)(data + 1);
- char* dialogName = new char[len + 1];
- memcpy(dialogName, data + 3, len);
- dialogName[len] = 0;
- for (UIMLDialog* dialog : dialogs)
- {
- if (dialog->getName().istGleich(dialogName))
- {
- exists = 1;
- break;
- }
- }
- delete[] dialogName;
- if (!exists)
- {
- int uimlLen = *(int*)(data + 4 + len);
- char* uiml = new char[uimlLen + 1];
- memcpy(uiml, data + 8 + len, uimlLen);
- uiml[uimlLen] = 0;
- UIMLDialog* dialog = new UIMLDialog(uiml, [this](UIMLDialog* dialog)
- {
- logout->postAction([this, dialog]()
- {
- int index = 0;
- for (UIMLDialog* d : dialogs)
- {
- if (d == dialog)
- {
- dialogs.remove(index);
- window->zBildschirm()->removeMember(d);
- break;
- }
- index++;
- }
- });
- });
- dialogs.add(dialog);
- window->zBildschirm()->addMember(dialog);
- delete[]uiml;
- }
- break;
- }
- case 1:
- { // element message
- for (UIMLDialog* dialog : dialogs)
- {
- dialog->api(data + 1);
- }
- break;
- }
- }
- }
|