ChatOptions.cpp 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. #include "ChatOptions.h"
  2. #include <DateiSystem.h>
  3. #include "Globals.h"
  4. #include "Initialisierung.h"
  5. ChatOptions::ChatOptions()
  6. : Fenster()
  7. {
  8. LTDBDatei iconsDat;
  9. iconsDat.setDatei(new Text("data/images/gui_icons.ltdb"));
  10. iconsDat.leseDaten(0);
  11. setStyle(
  12. Fenster::Style::Erlaubt | Fenster::Style::Rahmen
  13. | Fenster::Style::BodyHAlpha | Fenster::Style::Titel
  14. | Fenster::Style::TitelHAlpha | Fenster::Style::Closable
  15. | Fenster::Style::ClosingHAlpha | Fenster::Style::ClosingKlickBuffer
  16. | Fenster::Style::TitelHintergrund | Fenster::Style::BodyHintergrund
  17. | Fenster::Style::ClosingHintergrund | Fenster::Style::MEIgnoreInside
  18. | Fenster::Style::Beweglich | Style::ClosingHBild
  19. | Style::ClosingBuffer);
  20. removeStyle(Fenster::Style::Sichtbar);
  21. setTitel("Chat options");
  22. setClosingMe([this](void* p, void* o, Framework::MausEreignis me) {
  23. if (me.id == Framework::ME_RLinks)
  24. {
  25. removeStyle(Fenster::Style::Sichtbar);
  26. }
  27. return 1;
  28. });
  29. setSize(262, 367);
  30. setPosition(5, uiFactory.initParam.bildschirm->getBackBufferSize().y - 680);
  31. setMausEreignis(Framework::_ret1ME);
  32. setTastaturEreignis(Framework::_ret1TE);
  33. setRBreite(1);
  34. setRFarbe(0xFF52525E);
  35. setKBgFarbe(0xA0000000);
  36. setTBgFarbe(0xA0000000);
  37. setSBgFarbe(0xA0000000);
  38. setTSchriftZ(
  39. dynamic_cast<Schrift*>(uiFactory.initParam.schrift->getThis()));
  40. zTTextFeld()->setSize(0, 20);
  41. zTTextFeld()->addStyle(TextFeld::Style::Center);
  42. setSAfStrength(10);
  43. setSAfFarbe(0x5F9C0A0A);
  44. setSBgBildZ(iconsDat.laden(0, new Text("close.png")));
  45. setSKAfFarbe(0xFF9C0A0A);
  46. setSKAfStrength(10);
  47. infoChannel = initKontrollKnopf(5,
  48. 5,
  49. 250,
  50. 20,
  51. Framework::KontrollKnopf::Style::Normal
  52. & ~Framework::KontrollKnopf::Style::Rahmen,
  53. "Show info messages");
  54. infoChannel->setNMausEreignis([this](void* p, void* o, MausEreignis me) {
  55. if (me.id == ME_RLinks)
  56. {
  57. char msg[13];
  58. msg[0]
  59. = infoChannel->hatStyle(KontrollKnopf::Style::Selected) ? 1 : 2;
  60. msg[1] = 11;
  61. memcpy(msg + 2, "system:INFO", 11);
  62. World::INSTANCE->zClient()->chatAPIRequest(msg, 13);
  63. }
  64. return 1;
  65. });
  66. addMember(infoChannel);
  67. warningChannel = initKontrollKnopf(5,
  68. 30,
  69. 250,
  70. 20,
  71. Framework::KontrollKnopf::Style::Normal
  72. & ~Framework::KontrollKnopf::Style::Rahmen,
  73. "Show warning messages");
  74. warningChannel->setNMausEreignis([this](void* p, void* o, MausEreignis me) {
  75. if (me.id == ME_RLinks)
  76. {
  77. char msg[16];
  78. msg[0] = warningChannel->hatStyle(KontrollKnopf::Style::Selected)
  79. ? 1
  80. : 2;
  81. msg[1] = 14;
  82. memcpy(msg + 2, "system:WARNING", 14);
  83. World::INSTANCE->zClient()->chatAPIRequest(msg, 16);
  84. }
  85. return 1;
  86. });
  87. addMember(warningChannel);
  88. errorChannel = initKontrollKnopf(5,
  89. 55,
  90. 250,
  91. 20,
  92. Framework::KontrollKnopf::Style::Normal
  93. & ~Framework::KontrollKnopf::Style::Rahmen,
  94. "Show error messages");
  95. errorChannel->setNMausEreignis([this](void* p, void* o, MausEreignis me) {
  96. if (me.id == ME_RLinks)
  97. {
  98. char msg[14];
  99. msg[0] = errorChannel->hatStyle(KontrollKnopf::Style::Selected) ? 1
  100. : 2;
  101. msg[1] = 12;
  102. memcpy(msg + 2, "system:ERROR", 12);
  103. World::INSTANCE->zClient()->chatAPIRequest(msg, 14);
  104. }
  105. return 1;
  106. });
  107. addMember(errorChannel);
  108. TextFeld* blackListLabel = initTextFeld(5,
  109. 90,
  110. 250,
  111. 20,
  112. Framework::TextFeld::Style::Text | Framework::TextFeld::Style::VCenter,
  113. "Ignored players:");
  114. addMember(blackListLabel);
  115. plus = iconsDat.laden(0, new Text("plus.png"));
  116. trash = iconsDat.laden(0, new Text("trash.png"));
  117. playerName = initTextFeld(
  118. 5, 115, 225, 20, Framework::TextFeld::Style::TextFeld, "");
  119. playerName->setTastaturEreignis(
  120. [this](void* o, void* p, TastaturEreignis te) {
  121. if (te.id == TE_Release && te.virtualKey == T_Enter)
  122. {
  123. if (playerName->zText()->getLength())
  124. {
  125. addIgnoredPlayer(playerName->zText()->getText(), 1);
  126. playerName->setText("");
  127. }
  128. }
  129. return 1;
  130. });
  131. addMember(playerName);
  132. addButton = initKnopf(235,
  133. 115,
  134. 20,
  135. 20,
  136. Framework::Knopf::Style::HBild | Framework::Knopf::Style::HAlpha
  137. | Framework::Knopf::Style::Hintergrund,
  138. "");
  139. addButton->setAlphaFeldFarbe(0x5F337AB7);
  140. addButton->setToolTipText("Add player to list of ignored players",
  141. uiFactory.initParam.bildschirm,
  142. uiFactory.initParam.schrift);
  143. addButton->setHintergrundBildZ(dynamic_cast<Bild*>(plus->getThis()));
  144. addButton->setMausEreignis([this](void* o, void* p, MausEreignis me) {
  145. if (me.id == ME_RLinks)
  146. {
  147. if (playerName->zText()->getLength())
  148. {
  149. addIgnoredPlayer(playerName->zText()->getText(), 1);
  150. playerName->setText("");
  151. }
  152. }
  153. return 1;
  154. });
  155. addMember(addButton);
  156. blackList = initObjTabelle(5,
  157. 140,
  158. 250,
  159. 200,
  160. Framework::ObjTabelle::Style::normal
  161. | Framework::ObjTabelle::Style::VScroll,
  162. {
  163. {"Player", 212, 212, 212},
  164. {"Remove", 20, 20, 20 }
  165. },
  166. 0);
  167. addMember(blackList);
  168. }
  169. ChatOptions::~ChatOptions()
  170. {
  171. if (plus) plus->release();
  172. if (trash) trash->release();
  173. }
  174. void ChatOptions::init(char* data)
  175. {
  176. infoChannel->removeStyle(KontrollKnopf::Style::Selected);
  177. warningChannel->removeStyle(KontrollKnopf::Style::Selected);
  178. errorChannel->removeStyle(KontrollKnopf::Style::Selected);
  179. int len = *(int*)data;
  180. data += 4;
  181. for (int i = 0; i < len; i++)
  182. {
  183. char len = *(data++);
  184. data += len;
  185. if (len == 11)
  186. {
  187. infoChannel->addStyle(KontrollKnopf::Style::Selected);
  188. }
  189. if (len == 12)
  190. {
  191. errorChannel->addStyle(KontrollKnopf::Style::Selected);
  192. }
  193. if (len == 14)
  194. {
  195. warningChannel->addStyle(KontrollKnopf::Style::Selected);
  196. }
  197. }
  198. uiFactory.initParam.bildschirm->postAction([this]() {
  199. while (blackList->getZeilenAnzahl())
  200. {
  201. blackList->removeZeile(0);
  202. }
  203. });
  204. len = *(int*)data;
  205. data += 4;
  206. for (int i = 0; i < len; i++)
  207. {
  208. char len = *(data++);
  209. char* name = new char[len + 1];
  210. memcpy(name, data, len);
  211. name[len] = 0;
  212. data += len;
  213. addIgnoredPlayer(name, 0);
  214. delete[] name;
  215. }
  216. }
  217. void ChatOptions::addIgnoredPlayer(Framework::Text playerName, bool msg)
  218. {
  219. if (blackList->getZeilenNummer(playerName) >= 0) return;
  220. if (msg)
  221. {
  222. char* msg = new char[2 + playerName.getLength()];
  223. msg[0] = 3;
  224. msg[1] = (char)playerName.getLength();
  225. memcpy(msg + 2, playerName, playerName.getLength());
  226. World::INSTANCE->zClient()->chatAPIRequest(
  227. msg, 2 + playerName.getLength());
  228. delete[] msg;
  229. }
  230. uiFactory.initParam.bildschirm->postAction([this, playerName]() {
  231. if (blackList->getZeilenNummer(playerName) >= 0) return;
  232. blackList->addZeile(playerName);
  233. blackList->setZeichnungZ("Player",
  234. playerName,
  235. initTextFeld(0,
  236. 0,
  237. 0,
  238. 0,
  239. TextFeld::Style::Text | TextFeld::Style::VCenter,
  240. playerName.getText()));
  241. Knopf* removeButton = initKnopf(0,
  242. 0,
  243. 0,
  244. 0,
  245. Framework::Knopf::Style::HBild | Framework::Knopf::Style::HAlpha
  246. | Framework::Knopf::Style::Hintergrund,
  247. "");
  248. removeButton->removeStyle(Knopf::Style::Rahmen);
  249. removeButton->setAlphaFeldFarbe(0x5F337AB7);
  250. removeButton->setToolTipText(
  251. "Remove player from list of ignored players",
  252. uiFactory.initParam.bildschirm,
  253. uiFactory.initParam.schrift);
  254. removeButton->setHintergrundBildZ(
  255. dynamic_cast<Bild*>(trash->getThis()));
  256. removeButton->setMausEreignis(
  257. [this, playerName](void* o, void* p, MausEreignis me) {
  258. if (me.id == ME_RLinks)
  259. {
  260. uiFactory.initParam.bildschirm->postAction(
  261. [this, playerName]() {
  262. char* msg = new char[2 + playerName.getLength()];
  263. msg[0] = 4;
  264. msg[1] = (char)playerName.getLength();
  265. memcpy(msg + 2, playerName, playerName.getLength());
  266. World::INSTANCE->zClient()->chatAPIRequest(
  267. msg, 2 + playerName.getLength());
  268. delete[] msg;
  269. blackList->removeZeile(playerName);
  270. });
  271. }
  272. return 1;
  273. });
  274. blackList->setZeichnungZ("Remove", playerName, removeButton);
  275. });
  276. }