UIController.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "UIController.h"
  2. #include "Entity.h"
  3. UIController::UIController()
  4. : ReferenceCounter()
  5. {}
  6. void UIController::addDialog(UIDialog* dialog)
  7. {
  8. if (dialog->open())
  9. {
  10. activeDialogs.add(dialog);
  11. }
  12. else
  13. {
  14. dialog->release();
  15. }
  16. }
  17. void UIController::api(Framework::StreamReader* zRequest,
  18. NetworkMessage* zResponse,
  19. Entity* zSource)
  20. {
  21. unsigned short length;
  22. zRequest->lese((char*)&length, 2);
  23. char* id = new char[length + 1];
  24. zRequest->lese(id, length);
  25. id[length] = 0;
  26. char type;
  27. zRequest->lese(&type, 1);
  28. switch (type)
  29. {
  30. case 0: // element message
  31. {
  32. int entityId = zSource->getId();
  33. for (auto dialog = activeDialogs.begin(); dialog; dialog++)
  34. {
  35. if (dialog->getId().istGleich(id)
  36. && dialog->getPlayerId() == entityId)
  37. {
  38. dialog->api(zRequest, zResponse);
  39. }
  40. }
  41. break;
  42. }
  43. case 1: // close dialog
  44. {
  45. int entityId = zSource->getId();
  46. for (auto dialog = activeDialogs.begin(); dialog; dialog++)
  47. {
  48. if (dialog->getId().istGleich(id)
  49. && dialog->getPlayerId() == entityId)
  50. {
  51. dialog.remove();
  52. }
  53. }
  54. break;
  55. }
  56. }
  57. delete[] id;
  58. }
  59. void UIController::removePlayerDialogs(int playerId)
  60. {
  61. for (auto dialog = activeDialogs.begin(); dialog; dialog++)
  62. {
  63. if (dialog->getPlayerId() == playerId)
  64. {
  65. dialog.remove();
  66. }
  67. }
  68. }