123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- #include "UIController.h"
- #include "Entity.h"
- UIController::UIController()
- : ReferenceCounter()
- {}
- void UIController::addDialog(UIDialog* dialog)
- {
- if (dialog->open())
- {
- activeDialogs.add(dialog);
- }
- else
- {
- dialog->release();
- }
- }
- void UIController::api(Framework::StreamReader* zRequest,
- NetworkMessage* zResponse,
- Entity* zSource)
- {
- unsigned short length;
- zRequest->lese((char*)&length, 2);
- char* id = new char[length + 1];
- zRequest->lese(id, length);
- id[length] = 0;
- char type;
- zRequest->lese(&type, 1);
- switch (type)
- {
- case 0: // element message
- {
- int entityId = zSource->getId();
- for (auto dialog = activeDialogs.begin(); dialog; dialog++)
- {
- if (dialog->getId().istGleich(id)
- && dialog->getPlayerId() == entityId)
- {
- dialog->api(zRequest, zResponse);
- }
- }
- break;
- }
- case 1: // close dialog
- {
- int entityId = zSource->getId();
- for (auto dialog = activeDialogs.begin(); dialog;)
- {
- if (dialog->getId().istGleich(id)
- && dialog->getPlayerId() == entityId)
- {
- dialog.remove();
- }
- else
- {
- dialog++;
- }
- }
- break;
- }
- }
- delete[] id;
- }
- void UIController::removePlayerDialogs(int playerId)
- {
- for (auto dialog = activeDialogs.begin(); dialog;)
- {
- if (dialog->getPlayerId() == playerId)
- {
- dialog.remove();
- }
- else
- {
- dialog++;
- }
- }
- }
|