ChatMessage.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "ChatMessage.h"
  2. #include "Globals.h"
  3. ChatMessage::ChatMessage(char* data)
  4. : TextFeld(),
  5. lastWidth(0)
  6. {
  7. setStyle(Style::VCenter | Style::Sichtbar | Style::Mehrzeilig | Style::AutoLineBreak);
  8. setSchriftZ(dynamic_cast<Schrift*>(uiFactory.initParam.schrift->getThis()));
  9. setSchriftSize(12);
  10. setAutoLineBreakSpacing(" ");
  11. __int64 time = *(__int64*)data;
  12. short mLen = *(short*)(data + 8);
  13. char* message = new char[mLen + 1];
  14. memcpy(message, data + 10, mLen);
  15. message[mLen] = 0;
  16. char channelLen = *(data + 10 + mLen);
  17. char* channel = new char[channelLen + 1];
  18. memcpy(channel, data + 11 + mLen, channelLen);
  19. channel[channelLen] = 0;
  20. Framework::Text channelT = channel;
  21. delete[] channel;
  22. Zeit converter(time);
  23. Text* timeT = converter.getZeit("d.m.y h:i:s");
  24. setSchriftFarbe(0xFFFFFFFF);
  25. if (channelT.istGleich("system:INFO"))
  26. {
  27. setSchriftFarbe(0xFFA0A0A0);
  28. channelT = "[INFO]";
  29. }
  30. else if (channelT.istGleich("system:WARNING"))
  31. {
  32. setSchriftFarbe(0xFFFF7700);
  33. channelT = "[WARNING]";
  34. }
  35. else if (channelT.istGleich("system:ERROR"))
  36. {
  37. setSchriftFarbe(0xFFFF0000);
  38. channelT = "[ERROR]";
  39. }
  40. else if (channelT.hatAt(0, "player:"))
  41. {
  42. Text* tmp = channelT.getTeilText(7);
  43. channelT = *tmp;
  44. tmp->release();
  45. }
  46. Text tmp = *timeT + " " + channelT + " " + message;
  47. tmp.ersetzen("\n", "\n ");
  48. setText(tmp);
  49. timeT->release();
  50. delete[] message;
  51. }
  52. bool ChatMessage::tick(double tickVal)
  53. {
  54. if (getBreite() != lastWidth)
  55. {
  56. lastWidth = getBreite();
  57. setHeight(getNeededHeight());
  58. }
  59. return ZeichnungHintergrund::tick(tickVal);
  60. }