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.

181 lines
5.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #include "ConfigPanel.h"
  8. //#include "Info.h"
  9. #include <vgui/ISystem.h>
  10. #include <vgui/ISurface.h>
  11. #include <vgui/IVGui.h>
  12. #include <KeyValues.h>
  13. #include <vgui_controls/Label.h>
  14. #include <vgui_controls/TextEntry.h>
  15. #include <vgui_controls/Button.h>
  16. #include <vgui_controls/ToggleButton.h>
  17. #include <vgui_controls/CheckButton.h>
  18. #include <vgui_controls/MessageBox.h>
  19. #include <vgui_controls/RadioButton.h>
  20. #include <stdio.h>
  21. using namespace vgui;
  22. static const long RETRY_TIME = 10000; // refresh server every 10 seconds
  23. //-----------------------------------------------------------------------------
  24. // Purpose: Constructor
  25. //-----------------------------------------------------------------------------
  26. CConfigPanel::CConfigPanel(vgui::Panel *parent, bool autorefresh,bool savercon,int refreshtime,
  27. bool graphs, int graphsrefreshtime,bool getlogs) : Frame(parent, "ConfigPanel")
  28. {
  29. 196, 181, 80,
  30. SetMinimumSize(400,240);
  31. SetSizeable(false);
  32. MakePopup();
  33. m_pOkayButton = new Button(this, "Okay", "#Okay_Button");
  34. m_pCloseButton = new Button(this, "Close", "#Close_Button");
  35. m_pRefreshCheckButton = new CheckButton(this, "RefreshCheckButton", "");
  36. m_pRconCheckButton = new CheckButton(this, "RconCheckButton", "");
  37. m_pRefreshTextEntry= new TextEntry(this,"RefreshTextEntry");
  38. m_pGraphsButton = new CheckButton(this, "GraphsButton", "");
  39. m_pGraphsRefreshTimeTextEntry= new TextEntry(this,"GraphsRefreshTimeTextEntry");
  40. m_pLogsButton = new CheckButton(this, "LogsButton", "");
  41. SetTitle("My servers - Options",true);
  42. LoadControlSettings("Admin\\ConfigPanel.res", "PLATFORM");
  43. m_pRefreshCheckButton->SetSelected(autorefresh);
  44. m_pRconCheckButton->SetSelected(savercon);
  45. m_pGraphsButton->SetSelected(graphs);
  46. m_pLogsButton->SetSelected(getlogs);
  47. m_pRefreshTextEntry->SetEnabled(m_pRefreshCheckButton->IsSelected());
  48. m_pRefreshTextEntry->SetEditable(m_pRefreshCheckButton->IsSelected());
  49. m_pGraphsRefreshTimeTextEntry->SetEnabled(m_pGraphsButton->IsSelected());
  50. m_pGraphsRefreshTimeTextEntry->SetEditable(m_pGraphsButton->IsSelected());
  51. char refreshText[20];
  52. _snprintf(refreshText,20,"%i",refreshtime);
  53. m_pRefreshTextEntry->SetText(refreshText);
  54. _snprintf(refreshText,20,"%i",graphsrefreshtime);
  55. m_pGraphsRefreshTimeTextEntry->SetText(refreshText);
  56. SetVisible(true);
  57. }
  58. //-----------------------------------------------------------------------------
  59. // Purpose: Destructor
  60. //-----------------------------------------------------------------------------
  61. CConfigPanel::~CConfigPanel()
  62. {
  63. }
  64. //-----------------------------------------------------------------------------
  65. // Purpose: Activates the dialog
  66. //-----------------------------------------------------------------------------
  67. void CConfigPanel::Run()
  68. {
  69. RequestFocus();
  70. }
  71. //-----------------------------------------------------------------------------
  72. // Purpose: Deletes the dialog when it's closed
  73. //-----------------------------------------------------------------------------
  74. void CConfigPanel::OnClose()
  75. {
  76. BaseClass::OnClose();
  77. MarkForDeletion();
  78. }
  79. //-----------------------------------------------------------------------------
  80. // Purpose: turn on and off components when check boxes are checked
  81. //-----------------------------------------------------------------------------
  82. void CConfigPanel::OnButtonToggled(Panel *panel)
  83. {
  84. if (panel == m_pRefreshCheckButton)
  85. // you can only edit the refresh time if you allow auto refresh
  86. {
  87. m_pRefreshTextEntry->SetEnabled(m_pRefreshCheckButton->IsSelected());
  88. m_pRefreshTextEntry->SetEditable(m_pRefreshCheckButton->IsSelected());
  89. }
  90. else if (panel == m_pGraphsButton)
  91. // you can only edit the refresh time if you allow auto refresh
  92. {
  93. m_pGraphsRefreshTimeTextEntry->SetEnabled(m_pGraphsButton->IsSelected());
  94. m_pGraphsRefreshTimeTextEntry->SetEditable(m_pGraphsButton->IsSelected());
  95. }
  96. InvalidateLayout();
  97. }
  98. //-----------------------------------------------------------------------------
  99. // Purpose: Sets the text of a control by name
  100. //-----------------------------------------------------------------------------
  101. void CConfigPanel::SetControlText(const char *textEntryName, const char *text)
  102. {
  103. TextEntry *entry = dynamic_cast<TextEntry *>(FindChildByName(textEntryName));
  104. if (entry)
  105. {
  106. entry->SetText(text);
  107. }
  108. }
  109. //-----------------------------------------------------------------------------
  110. // Purpose: Parse posted messages
  111. //
  112. //-----------------------------------------------------------------------------
  113. void CConfigPanel::OnCommand(const char *command)
  114. {
  115. if(!stricmp(command,"okay"))
  116. { // save away the new settings
  117. char timeText[20];
  118. int time,timeGraphs;
  119. m_pRefreshTextEntry->GetText(timeText,20);
  120. sscanf(timeText,"%i",&time);
  121. memset(timeText, 0x0, sizeof(timeText));
  122. m_pGraphsRefreshTimeTextEntry->GetText(timeText, 20);
  123. sscanf(timeText,"%i",&timeGraphs);
  124. if(time>0 && time < 9999 && timeGraphs>0 && timeGraphs< 9999)
  125. {
  126. OnClose();
  127. }
  128. else
  129. {
  130. MessageBox *dlg = new MessageBox ("#Config_Panel", "#Config_Time_Error");
  131. dlg->DoModal();
  132. }
  133. }
  134. else if(!stricmp(command,"close") )
  135. {
  136. Close();
  137. }
  138. }