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.

151 lines
3.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #include <stdio.h>
  8. #include "DialogCvarChange.h"
  9. #include <vgui/IInput.h>
  10. #include <vgui/ISurface.h>
  11. #include <KeyValues.h>
  12. #include <vgui_controls/Button.h>
  13. #include <vgui_controls/Panel.h>
  14. #include <vgui_controls/Label.h>
  15. #include <vgui_controls/TextEntry.h>
  16. using namespace vgui;
  17. //-----------------------------------------------------------------------------
  18. // Purpose: Constructor
  19. //-----------------------------------------------------------------------------
  20. CDialogCvarChange::CDialogCvarChange(vgui::Panel *parent) : Frame(parent, "DialogCvarChange")
  21. {
  22. SetSize(320, 200);
  23. m_bAddCvarText = true;
  24. m_pInfoLabel = new Label(this, "InfoLabel", "");
  25. m_pCvarLabel = new Label(this, "CvarLabel", "");
  26. m_pCvarEntry = new TextEntry(this, "CvarEntry");
  27. m_pOkayButton = new Button(this, "OkayButton", "#Okay_Button");
  28. LoadControlSettings("Admin/DialogCvarChange.res", "PLATFORM");
  29. SetTitle("#Cvar_Title", true);
  30. SetSizeable(false);
  31. // set our initial position in the middle of the workspace
  32. MoveToCenterOfScreen();
  33. }
  34. //-----------------------------------------------------------------------------
  35. // Purpose: Destructor
  36. //-----------------------------------------------------------------------------
  37. CDialogCvarChange::~CDialogCvarChange()
  38. {
  39. }
  40. //-----------------------------------------------------------------------------
  41. // Purpose: Hides value text
  42. //-----------------------------------------------------------------------------
  43. void CDialogCvarChange::MakePassword()
  44. {
  45. m_pCvarEntry->SetTextHidden(true);
  46. m_bAddCvarText = false; // this isn't asking about a cvar
  47. }
  48. //-----------------------------------------------------------------------------
  49. // Purpose: initializes the dialog and brings it to the foreground
  50. //-----------------------------------------------------------------------------
  51. void CDialogCvarChange::Activate(const char *cvarName, const char *curValue, const char *type, const char *question)
  52. {
  53. m_pCvarLabel->SetText(cvarName);
  54. if (!m_bAddCvarText)
  55. {
  56. m_pCvarLabel->SetVisible(false); // hide this
  57. }
  58. m_pInfoLabel->SetText(question);
  59. m_cType=type;
  60. m_pOkayButton->SetAsDefaultButton(true);
  61. MakePopup();
  62. MoveToFront();
  63. m_pCvarEntry->SetText(curValue);
  64. m_pCvarEntry->RequestFocus();
  65. RequestFocus();
  66. // make it modal
  67. input()->SetAppModalSurface(GetVPanel());
  68. SetVisible(true);
  69. BaseClass::Activate();
  70. }
  71. //-----------------------------------------------------------------------------
  72. // Purpose: Sets the text of a labell by name
  73. //-----------------------------------------------------------------------------
  74. void CDialogCvarChange::SetLabelText(const char *textEntryName, const char *text)
  75. {
  76. Label *entry = dynamic_cast<Label *>(FindChildByName(textEntryName));
  77. if (entry)
  78. {
  79. entry->SetText(text);
  80. }
  81. }
  82. //-----------------------------------------------------------------------------
  83. // Purpose: Handles button presses
  84. //-----------------------------------------------------------------------------
  85. void CDialogCvarChange::OnCommand(const char *command)
  86. {
  87. bool bClose = false;
  88. if (!stricmp(command, "Okay"))
  89. {
  90. KeyValues *msg = new KeyValues("CvarChangeValue");
  91. char buf[64];
  92. m_pCvarLabel->GetText(buf,64);
  93. msg->SetString("player", buf );
  94. m_pCvarEntry->GetText(buf, sizeof(buf)-1);
  95. msg->SetString("value", buf);
  96. msg->SetString("type",m_cType);
  97. PostActionSignal(msg);
  98. bClose = true;
  99. }
  100. else if (!stricmp(command, "Close"))
  101. {
  102. bClose = true;
  103. }
  104. else
  105. {
  106. BaseClass::OnCommand(command);
  107. }
  108. if (bClose)
  109. {
  110. Close();
  111. }
  112. }
  113. //-----------------------------------------------------------------------------
  114. // Purpose: deletes the dialog on close
  115. //-----------------------------------------------------------------------------
  116. void CDialogCvarChange::OnClose()
  117. {
  118. BaseClass::OnClose();
  119. MarkForDeletion();
  120. }