UIDialog.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "UIDialog.h"
  2. #include "Game.h"
  3. #include "NetworkMessage.h"
  4. UIDialog::UIDialog(
  5. Framework::Text id, int playerId, Framework::XML::Element* uiml)
  6. : ReferenceCounter(),
  7. id(id),
  8. playerId(playerId),
  9. uiml(uiml)
  10. {}
  11. UIDialog::~UIDialog()
  12. {
  13. uiml->release();
  14. }
  15. void UIDialog::api(Framework::StreamReader* zRequest,
  16. NetworkMessage* zResponse)
  17. {}
  18. bool UIDialog::open() const
  19. {
  20. Entity* zEntity = Game::INSTANCE->zEntity(playerId);
  21. if (zEntity)
  22. {
  23. Game::INSTANCE->zQuestManager()->processEvent(new QuestEventOpenDialog(
  24. dynamic_cast<Entity*>(zEntity->getThis()), id));
  25. NetworkMessage* msg = new NetworkMessage();
  26. msg->openDialog(id, uiml->toString());
  27. Game::INSTANCE->sendMessage(msg, zEntity);
  28. return 1;
  29. }
  30. return 0;
  31. }
  32. bool UIDialog::update() const {
  33. Entity* zEntity = Game::INSTANCE->zEntity(playerId);
  34. if (zEntity)
  35. {
  36. Game::INSTANCE->zQuestManager()->processEvent(new QuestEventOpenDialog(
  37. dynamic_cast<Entity*>(zEntity->getThis()), id));
  38. NetworkMessage* msg = new NetworkMessage();
  39. msg->updateDialog(id, uiml->toString());
  40. Game::INSTANCE->sendMessage(msg, zEntity);
  41. return 1;
  42. }
  43. return 0;
  44. }
  45. const Framework::Text& UIDialog::getId() const
  46. {
  47. return id;
  48. }
  49. int UIDialog::getPlayerId() const
  50. {
  51. return playerId;
  52. }