AddServerMenu.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #include "AddServerMenu.h"
  2. #include "Globals.h"
  3. #include "Initialisierung.h"
  4. #include "ServerSelection.h"
  5. AddServerMenu::AddServerMenu(Bildschirm* zScreen)
  6. : Menu(zScreen)
  7. {
  8. Punkt center = zScreen->getBackBufferSize() / 2;
  9. TextFeld* nameLabel = initTextFeld(center.x - 150,
  10. center.y - 50,
  11. 100,
  12. 20,
  13. TextFeld::Style::Text | TextFeld::Style::VCenter,
  14. "Name:");
  15. elements.add(nameLabel);
  16. name = initTextFeld(nameLabel->getPosition().x + nameLabel->getBreite(),
  17. nameLabel->getPosition().y,
  18. 200,
  19. 20,
  20. TextFeld::Style::TextFeld,
  21. "");
  22. name->setTastaturEreignis([this](void* p, void* o, TastaturEreignis te) {
  23. if (te.id == TE_Release && te.virtualKey == T_Tab)
  24. {
  25. name->removeStyle(Zeichnung::Style::Fokus);
  26. address->addStyle(Zeichnung::Style::Fokus);
  27. }
  28. return te.virtualKey != T_Tab;
  29. });
  30. elements.add(name);
  31. TextFeld* addressLabel = initTextFeld(center.x - 150,
  32. center.y - 25,
  33. 100,
  34. 20,
  35. TextFeld::Style::Text | TextFeld::Style::VCenter,
  36. "Server Address:");
  37. elements.add(addressLabel);
  38. address = initTextFeld(
  39. addressLabel->getPosition().x + addressLabel->getBreite(),
  40. addressLabel->getPosition().y,
  41. 200,
  42. 20,
  43. TextFeld::Style::TextFeld,
  44. "");
  45. address->setTastaturEreignis([this](void* p, void* o, TastaturEreignis te) {
  46. if (te.id == TE_Release && te.virtualKey == T_Tab)
  47. {
  48. address->removeStyle(Zeichnung::Style::Fokus);
  49. sslPort->addStyle(Zeichnung::Style::Fokus);
  50. }
  51. return te.virtualKey != T_Tab;
  52. });
  53. elements.add(address);
  54. TextFeld* sslPortLabel = initTextFeld(center.x - 150,
  55. center.y,
  56. 100,
  57. 20,
  58. TextFeld::Style::Text | TextFeld::Style::VCenter,
  59. "SSL Server Port:");
  60. elements.add(sslPortLabel);
  61. sslPort = initTextFeld(
  62. sslPortLabel->getPosition().x + sslPortLabel->getBreite(),
  63. sslPortLabel->getPosition().y,
  64. 200,
  65. 20,
  66. TextFeld::Style::TextFeld,
  67. "");
  68. sslPort->setTastaturEreignis([this](void* p, void* o, TastaturEreignis te) {
  69. if (te.id == TE_Release && te.virtualKey == T_Tab)
  70. {
  71. sslPort->removeStyle(Zeichnung::Style::Fokus);
  72. port->addStyle(Zeichnung::Style::Fokus);
  73. }
  74. return te.virtualKey != T_Tab && _nurNummernTE(p, o, te);
  75. });
  76. elements.add(sslPort);
  77. TextFeld* portLabel = initTextFeld(center.x - 150,
  78. center.y + 25,
  79. 100,
  80. 20,
  81. TextFeld::Style::Text | TextFeld::Style::VCenter,
  82. "Server Port:");
  83. elements.add(portLabel);
  84. port = initTextFeld(portLabel->getPosition().x + portLabel->getBreite(),
  85. portLabel->getPosition().y,
  86. 200,
  87. 20,
  88. TextFeld::Style::TextFeld,
  89. "");
  90. port->setTastaturEreignis(_nurNummernTE);
  91. elements.add(port);
  92. add = initKnopf(
  93. center.x + 50, center.y + 50, 100, 20, Knopf::Style::Normal, "Add");
  94. add->setMausEreignis([this](void* p, void* o, MausEreignis me) {
  95. if (me.id == ME_RLinks)
  96. {
  97. if (name->zText()->getLength() && address->zText()->getLength()
  98. && port->zText()->getLength())
  99. {
  100. if (!((ServerSelectionMenu*)(Menu*)menuRegister->get(
  101. "serverSelection"))
  102. ->hasServer(name->zText()->getText()))
  103. {
  104. hide();
  105. menuRegister->get("serverSelection")->show();
  106. ((ServerSelectionMenu*)(Menu*)menuRegister->get(
  107. "serverSelection"))
  108. ->addServer(name->zText()->getText(),
  109. address->zText()->getText(),
  110. (unsigned short)(int)*sslPort->zText(),
  111. (unsigned short)(int)*port->zText());
  112. name->zText()->setText("");
  113. address->zText()->setText("");
  114. port->zText()->setText("");
  115. sslPort->zText()->setText("");
  116. name->setAlphaFeldFarbe(0xFF3d3d3d);
  117. address->setAlphaFeldFarbe(0xFF3d3d3d);
  118. port->setAlphaFeldFarbe(0xFF3d3d3d);
  119. sslPort->setAlphaFeldFarbe(0xFF3d3d3d);
  120. }
  121. else
  122. name->setAlphaFeldFarbe(0xFF3d0000);
  123. }
  124. else
  125. {
  126. if (!name->zText()->getLength())
  127. name->setAlphaFeldFarbe(0xFF3d0000);
  128. if (!address->zText()->getLength())
  129. address->setAlphaFeldFarbe(0xFF3d0000);
  130. if (!port->zText()->getLength())
  131. port->setAlphaFeldFarbe(0xFF3d0000);
  132. if (!sslPort->zText()->getLength())
  133. sslPort->setAlphaFeldFarbe(0xFF3d0000);
  134. }
  135. }
  136. return 1;
  137. });
  138. elements.add(add);
  139. abort = initKnopf(
  140. center.x - 150, center.y + 50, 100, 20, Knopf::Style::Normal, "Abort");
  141. abort->setMausEreignis([this](void* p, void* o, MausEreignis me) {
  142. if (me.id == ME_RLinks)
  143. {
  144. hide();
  145. menuRegister->get("serverSelection")->show();
  146. name->zText()->setText("");
  147. address->zText()->setText("");
  148. port->zText()->setText("");
  149. name->setAlphaFeldFarbe(0xFF3d3d3d);
  150. address->setAlphaFeldFarbe(0xFF3d3d3d);
  151. port->setAlphaFeldFarbe(0xFF3d3d3d);
  152. sslPort->setAlphaFeldFarbe(0xFF3d3d3d);
  153. }
  154. return 1;
  155. });
  156. elements.add(abort);
  157. }