Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
3.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #include "DialogServerPassword.h"
  8. #include <VGUI_Button.h>
  9. #include <VGUI_KeyValues.h>
  10. #include <VGUI_Label.h>
  11. #include <VGUI_TextEntry.h>
  12. #include <VGUI_Controls.h>
  13. #include <VGUI_ISurface.h>
  14. using namespace vgui;
  15. //-----------------------------------------------------------------------------
  16. // Purpose: Constructor
  17. //-----------------------------------------------------------------------------
  18. CDialogServerPassword::CDialogServerPassword() : Frame(NULL, "DialogServerPassword")
  19. {
  20. m_iServerID = -1;
  21. SetSize(320, 240);
  22. m_pInfoLabel = new Label(this, "InfoLabel", "This server requires a password to join.");
  23. m_pGameLabel = new Label(this, "GameLabel", "<game label>");
  24. m_pPasswordEntry = new TextEntry(this, "PasswordEntry");
  25. m_pConnectButton = new Button(this, "ConnectButton", "&Connect");
  26. m_pPasswordEntry->SetTextHidden(true);
  27. LoadControlSettings("Admin\\DialogServerPassword.res");
  28. SetTitle("Server Requires Password - Servers", true);
  29. // set our initial position in the middle of the workspace
  30. MoveToCenterOfScreen();
  31. }
  32. //-----------------------------------------------------------------------------
  33. // Purpose: Destructor
  34. //-----------------------------------------------------------------------------
  35. CDialogServerPassword::~CDialogServerPassword()
  36. {
  37. }
  38. //-----------------------------------------------------------------------------
  39. // Purpose: initializes the dialog and brings it to the foreground
  40. //-----------------------------------------------------------------------------
  41. void CDialogServerPassword::Activate(const char *serverName, unsigned int serverID)
  42. {
  43. m_pGameLabel->SetText(serverName);
  44. m_iServerID = serverID;
  45. m_pConnectButton->SetAsDefaultButton(true);
  46. MakePopup();
  47. MoveToFront();
  48. m_pPasswordEntry->RequestFocus();
  49. RequestFocus();
  50. }
  51. //-----------------------------------------------------------------------------
  52. // Purpose:
  53. // Input : *command -
  54. //-----------------------------------------------------------------------------
  55. void CDialogServerPassword::OnCommand(const char *command)
  56. {
  57. bool bClose = false;
  58. if (!stricmp(command, "Connect"))
  59. {
  60. KeyValues *msg = new KeyValues("JoinServerWithPassword");
  61. char buf[64];
  62. m_pPasswordEntry->GetText(0, buf, sizeof(buf)-1);
  63. msg->SetString("password", buf);
  64. msg->SetInt("serverID", m_iServerID);
  65. PostActionSignal(msg);
  66. bClose = true;
  67. }
  68. else if (!stricmp(command, "Close"))
  69. {
  70. bClose = true;
  71. }
  72. else
  73. {
  74. BaseClass::OnCommand(command);
  75. }
  76. if (bClose)
  77. {
  78. PostMessage(this, new KeyValues("Close"));
  79. MarkForDeletion();
  80. }
  81. }
  82. //-----------------------------------------------------------------------------
  83. // Purpose:
  84. //-----------------------------------------------------------------------------
  85. void CDialogServerPassword::PerformLayout()
  86. {
  87. BaseClass::PerformLayout();
  88. }
  89. //-----------------------------------------------------------------------------
  90. // Purpose: deletes the dialog on close
  91. //-----------------------------------------------------------------------------
  92. void CDialogServerPassword::OnClose()
  93. {
  94. BaseClass::OnClose();
  95. MarkForDeletion();
  96. }