UIDialog.cpp 1.4 KB

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