Chat.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #include "Chat.h"
  2. #include <AsynchronCall.h>
  3. #include <DateiSystem.h>
  4. #include "ChatMessage.h"
  5. #include "Game.h"
  6. #include "Globals.h"
  7. Chat::Chat()
  8. : OptionsWindow([this]() { options->addStyle(Fenster::Style::Sichtbar); }),
  9. optionsAdded(0)
  10. {
  11. addStyle( Fenster::Style::LeftPositionFixed
  12. | Fenster::Style::BottomPositionFixed);
  13. removeStyle(Fenster::Style::Beweglich);
  14. setTitel("Chat");
  15. setClosingMe([this](void* p, void* o, Framework::MausEreignis me) {
  16. if (me.id == Framework::ME_RLinks)
  17. {
  18. removeStyle(Fenster::Style::Sichtbar);
  19. ((Game*)(Menu*)menuRegister->get("game"))->makeChatButtonVisible();
  20. }
  21. return 1;
  22. });
  23. setSize(500, 300);
  24. setPosition(5, uiFactory.initParam.bildschirm->getBackBufferSize().y - 305);
  25. setKMin(200, 100);
  26. options = new ChatOptions();
  27. history = new ChatHistory();
  28. history->setSize(getInnenBreite(), getInnenHeight() - 20);
  29. addMember(history);
  30. commandLine = uiFactory.createTextFeld(uiFactory.initParam);
  31. commandLine->setText("");
  32. commandLine->setSize(getInnenBreite() - 20, 20);
  33. commandLine->setPosition(0, getInnenHeight() - 20);
  34. commandLine->setStyle(Framework::TextFeld::Style::TextFeld);
  35. commandLine->setTastaturEreignis(
  36. [this](void* p, void* o, Framework::TastaturEreignis te) {
  37. if (te.id == Framework::TE_Release
  38. && te.virtualKey == Framework::T_Enter)
  39. {
  40. if (commandLine->zText()->getLength() > 0)
  41. {
  42. Text* msg = new Text(*commandLine->zText());
  43. commandLine->setText("");
  44. new AsynchronCall([msg]() {
  45. World::INSTANCE->zClient()->sendChatMessage(*msg);
  46. msg->release();
  47. });
  48. }
  49. }
  50. return 1;
  51. });
  52. addMember(commandLine);
  53. LTDBDatei iconsDat;
  54. iconsDat.setDatei(new Text("data/images/gui_icons.ltdb"));
  55. iconsDat.leseDaten(0);
  56. sendButton = uiFactory.createKnopf(uiFactory.initParam);
  57. sendButton->setAlphaFeldFarbe(0x5F337AB7);
  58. sendButton->setToolTipText(
  59. "Send", uiFactory.initParam.bildschirm, uiFactory.initParam.schrift);
  60. sendButton->setSize(20, 20);
  61. sendButton->setPosition(getInnenBreite() - 20, getInnenHeight() - 20);
  62. sendButton->addStyle(Framework::Knopf::Style::HBild
  63. | Framework::Knopf::Style::HAlpha
  64. | Framework::Knopf::Style::Hintergrund);
  65. sendButton->setHintergrundBildZ(iconsDat.laden(0, new Text("send.png")));
  66. sendButton->setMausEreignis(
  67. [this](void* p, void* o, Framework::MausEreignis me) {
  68. if (me.id == ME_RLinks)
  69. {
  70. if (commandLine->zText()->getLength() > 0)
  71. {
  72. Text* msg = new Text(*commandLine->zText());
  73. commandLine->setText("");
  74. new AsynchronCall([msg]() {
  75. World::INSTANCE->zClient()->sendChatMessage(*msg);
  76. msg->release();
  77. });
  78. }
  79. }
  80. return 1;
  81. });
  82. addMember(sendButton);
  83. }
  84. Chat ::~Chat()
  85. {
  86. options->release();
  87. }
  88. void Chat::addMessage(char* data)
  89. {
  90. history->addMessage(new ChatMessage(data));
  91. }
  92. void Chat::initOptions(char* data)
  93. {
  94. options->init(data);
  95. }
  96. bool Chat::tick(double time)
  97. {
  98. if (!optionsAdded)
  99. {
  100. optionsAdded = 1;
  101. uiFactory.initParam.bildschirm->addMember(
  102. dynamic_cast<Zeichnung*>(options->getThis()));
  103. }
  104. return OptionsWindow::tick(time);
  105. }
  106. void Chat::render(Framework::Bild& rObj)
  107. {
  108. history->setSize(getInnenBreite(), getInnenHeight() - 20);
  109. commandLine->setSize(getInnenBreite() - 20, 20);
  110. commandLine->setPosition(0, getInnenHeight() - 20);
  111. sendButton->setPosition(getInnenBreite() - 20, getInnenHeight() - 20);
  112. OptionsWindow::render(rObj);
  113. }