AddServerMenu.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #include "AddServerMenu.h"
  2. #include "Initialisierung.h"
  3. #include "Globals.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, center.y - 50, 100, 20, TextFeld::Style::Text | TextFeld::Style::VCenter, "Name:");
  10. elements.add(nameLabel);
  11. name = initTextFeld(nameLabel->getPosition().x + nameLabel->getBreite(), nameLabel->getPosition().y, 200, 20, TextFeld::Style::TextFeld, "");
  12. name->setTastaturEreignis([this](void* p, void* o, TastaturEreignis te)
  13. {
  14. if (te.id == TE_Release && te.virtualKey == T_Tab)
  15. {
  16. name->removeStyle(Zeichnung::Style::Fokus);
  17. address->addStyle(Zeichnung::Style::Fokus);
  18. }
  19. return te.virtualKey != T_Tab;
  20. });
  21. elements.add(name);
  22. TextFeld* addressLabel = initTextFeld(center.x - 150, center.y - 25, 100, 20, TextFeld::Style::Text | TextFeld::Style::VCenter, "Server Address:");
  23. elements.add(addressLabel);
  24. address = initTextFeld(addressLabel->getPosition().x + addressLabel->getBreite(), addressLabel->getPosition().y, 200, 20, TextFeld::Style::TextFeld, "");
  25. address->setTastaturEreignis([this](void* p, void* o, TastaturEreignis te)
  26. {
  27. if (te.id == TE_Release && te.virtualKey == T_Tab)
  28. {
  29. address->removeStyle(Zeichnung::Style::Fokus);
  30. sslPort->addStyle(Zeichnung::Style::Fokus);
  31. }
  32. return te.virtualKey != T_Tab;
  33. });
  34. elements.add(address);
  35. TextFeld* sslPortLabel = initTextFeld(center.x - 150, center.y, 100, 20, TextFeld::Style::Text | TextFeld::Style::VCenter, "SSL Server Port:");
  36. elements.add(sslPortLabel);
  37. sslPort = initTextFeld(sslPortLabel->getPosition().x + sslPortLabel->getBreite(), sslPortLabel->getPosition().y, 200, 20, TextFeld::Style::TextFeld, "");
  38. sslPort->setTastaturEreignis([this](void* p, void* o, TastaturEreignis te)
  39. {
  40. if (te.id == TE_Release && te.virtualKey == T_Tab)
  41. {
  42. sslPort->removeStyle(Zeichnung::Style::Fokus);
  43. port->addStyle(Zeichnung::Style::Fokus);
  44. }
  45. return te.virtualKey != T_Tab && _nurNummernTE(p, o, te);
  46. });
  47. elements.add(sslPort);
  48. TextFeld* portLabel = initTextFeld(center.x - 150, center.y + 25, 100, 20, TextFeld::Style::Text | TextFeld::Style::VCenter, "Server Port:");
  49. elements.add(portLabel);
  50. port = initTextFeld(portLabel->getPosition().x + portLabel->getBreite(), portLabel->getPosition().y, 200, 20, TextFeld::Style::TextFeld, "");
  51. port->setTastaturEreignis(_nurNummernTE);
  52. elements.add(port);
  53. add = initKnopf(center.x + 50, center.y + 50, 100, 20, Knopf::Style::Normal, "Add");
  54. add->setMausEreignis([this](void* p, void* o, MausEreignis me)
  55. {
  56. if (me.id == ME_RLinks)
  57. {
  58. if (name->zText()->getLength() && address->zText()->getLength() && port->zText()->getLength())
  59. {
  60. if (!((ServerSelectionMenu*)(Menu*)menuRegister->get("serverSelection"))->hasServer(name->zText()->getText()))
  61. {
  62. hide();
  63. menuRegister->get("serverSelection")->show();
  64. ((ServerSelectionMenu*)(Menu*)menuRegister->get("serverSelection"))->addServer(name->zText()->getText(), address->zText()->getText(), (unsigned short)(int)*sslPort->zText(), (unsigned short)(int)*port->zText());
  65. name->zText()->setText("");
  66. address->zText()->setText("");
  67. port->zText()->setText("");
  68. sslPort->zText()->setText("");
  69. name->setAlphaFeldFarbe(0xFF3d3d3d);
  70. address->setAlphaFeldFarbe(0xFF3d3d3d);
  71. port->setAlphaFeldFarbe(0xFF3d3d3d);
  72. sslPort->setAlphaFeldFarbe(0xFF3d3d3d);
  73. }
  74. else
  75. name->setAlphaFeldFarbe(0xFF3d0000);
  76. }
  77. else
  78. {
  79. if(!name->zText()->getLength())
  80. name->setAlphaFeldFarbe(0xFF3d0000);
  81. if (!address->zText()->getLength())
  82. address->setAlphaFeldFarbe(0xFF3d0000);
  83. if (!port->zText()->getLength())
  84. port->setAlphaFeldFarbe(0xFF3d0000);
  85. if (!sslPort->zText()->getLength())
  86. sslPort->setAlphaFeldFarbe(0xFF3d0000);
  87. }
  88. }
  89. return 1;
  90. });
  91. elements.add(add);
  92. abort = initKnopf(center.x - 150, center.y + 50, 100, 20, Knopf::Style::Normal, "Abort");
  93. abort->setMausEreignis([this](void* p, void* o, MausEreignis me)
  94. {
  95. if (me.id == ME_RLinks)
  96. {
  97. hide();
  98. menuRegister->get("serverSelection")->show();
  99. name->zText()->setText("");
  100. address->zText()->setText("");
  101. port->zText()->setText("");
  102. name->setAlphaFeldFarbe(0xFF3d3d3d);
  103. address->setAlphaFeldFarbe(0xFF3d3d3d);
  104. port->setAlphaFeldFarbe(0xFF3d3d3d);
  105. sslPort->setAlphaFeldFarbe(0xFF3d3d3d);
  106. }
  107. return 1;
  108. });
  109. elements.add(abort);
  110. }