UIController.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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;)
  47. {
  48. if (dialog->getId().istGleich(id)
  49. && dialog->getPlayerId() == entityId)
  50. {
  51. dialog.remove();
  52. }
  53. else
  54. {
  55. dialog++;
  56. }
  57. }
  58. break;
  59. }
  60. }
  61. delete[] id;
  62. }
  63. void UIController::removePlayerDialogs(int playerId)
  64. {
  65. for (auto dialog = activeDialogs.begin(); dialog;)
  66. {
  67. if (dialog->getPlayerId() == playerId)
  68. {
  69. dialog.remove();
  70. }
  71. else
  72. {
  73. dialog++;
  74. }
  75. }
  76. }