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.

87 lines
2.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #include "ChatPanel.h"
  8. #include "RemoteServer.h"
  9. #include <vgui/IVGui.h>
  10. #include <KeyValues.h>
  11. #include <vgui_controls/TextEntry.h>
  12. #include <vgui_controls/RichText.h>
  13. #include <vgui_controls/Button.h>
  14. #include <vgui_controls/PHandle.h>
  15. #include <stdio.h>
  16. using namespace vgui;
  17. //-----------------------------------------------------------------------------
  18. // Purpose: Constructor
  19. //-----------------------------------------------------------------------------
  20. CChatPanel::CChatPanel(vgui::Panel *parent, const char *name) : PropertyPage(parent, name)
  21. {
  22. m_pServerChatPanel = new RichText(this, "ServerChatText");
  23. m_pServerChatPanel->SetMaximumCharCount(8000);
  24. m_pEnterChatPanel = new TextEntry(this,"ChatMessage");
  25. m_pSendChatButton = new Button(this, "SendChat", "#Chat_Panel_Send");
  26. m_pSendChatButton->SetCommand(new KeyValues("SendChat"));
  27. m_pSendChatButton->SetAsDefaultButton(true);
  28. LoadControlSettings("Admin/ChatPanel.res", "PLATFORM");
  29. }
  30. //-----------------------------------------------------------------------------
  31. // Purpose: Destructor
  32. //-----------------------------------------------------------------------------
  33. CChatPanel::~CChatPanel()
  34. {
  35. }
  36. //-----------------------------------------------------------------------------
  37. // Purpose: Activates the page
  38. //-----------------------------------------------------------------------------
  39. void CChatPanel::OnPageShow()
  40. {
  41. BaseClass::OnPageShow();
  42. }
  43. //-----------------------------------------------------------------------------
  44. // Purpose: Hides the page
  45. //-----------------------------------------------------------------------------
  46. void CChatPanel::OnPageHide()
  47. {
  48. BaseClass::OnPageHide();
  49. }
  50. //-----------------------------------------------------------------------------
  51. // Purpose: inserts a new string into the main chat panel
  52. //-----------------------------------------------------------------------------
  53. void CChatPanel::DoInsertString(const char *str)
  54. {
  55. m_pServerChatPanel->InsertString(str);
  56. }
  57. //-----------------------------------------------------------------------------
  58. // Purpose: run when the send button is pressed, send a rcon "say" to the server
  59. //-----------------------------------------------------------------------------
  60. void CChatPanel::OnSendChat()
  61. {
  62. // build a chat command and send it to the server
  63. char chat_text[512];
  64. strcpy(chat_text, "say ");
  65. m_pEnterChatPanel->GetText(chat_text + 4, sizeof(chat_text) - 4);
  66. if (strlen("say ") != strlen(chat_text))
  67. {
  68. RemoteServer().SendCommand(chat_text);
  69. // the message is sent, zero the text
  70. m_pEnterChatPanel->SetText("");
  71. }
  72. }