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
4.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "CreateTokenDialog.h"
  8. #include "LocalizationDialog.h"
  9. #include "vgui_controls/TextEntry.h"
  10. #include "vgui_controls/Button.h"
  11. #include "vgui_controls/MessageBox.h"
  12. #include "tier1/KeyValues.h"
  13. #include "vgui/ILocalize.h"
  14. using namespace vgui;
  15. //-----------------------------------------------------------------------------
  16. // Purpose: Cosntructor
  17. //-----------------------------------------------------------------------------
  18. CCreateTokenDialog::CCreateTokenDialog( CLocalizationDialog *pLocalizationDialog ) : Frame(NULL, "CreateTokenDialog"),
  19. m_pLocalizationDialog( m_pLocalizationDialog )
  20. {
  21. Assert( m_pLocalizationDialog );
  22. MakePopup();
  23. SetTitle("Create New Token - Localizer", true);
  24. m_pSkipButton = new Button(this, "SkipButton", "&Skip Token");
  25. m_pTokenName = new TextEntry(this, "TokenName");
  26. m_pTokenValue = new TextEntry(this, "TokenValue");
  27. m_pTokenValue->SetMultiline(true);
  28. m_pTokenValue->SetCatchEnterKey(true);
  29. m_pSkipButton->SetCommand("SkipToken");
  30. m_pSkipButton->SetVisible(false);
  31. LoadControlSettings("Resource/CreateTokenDialog.res");
  32. }
  33. //-----------------------------------------------------------------------------
  34. // Purpose: Destructor
  35. //-----------------------------------------------------------------------------
  36. CCreateTokenDialog::~CCreateTokenDialog()
  37. {
  38. }
  39. //-----------------------------------------------------------------------------
  40. // Purpose: prompts user to create a single token
  41. //-----------------------------------------------------------------------------
  42. void CCreateTokenDialog::CreateSingleToken()
  43. {
  44. // bring us to the front
  45. SetVisible(true);
  46. RequestFocus();
  47. MoveToFront();
  48. m_pTokenName->RequestFocus();
  49. m_pSkipButton->SetVisible(false);
  50. m_bMultiToken = false;
  51. }
  52. //-----------------------------------------------------------------------------
  53. // Purpose: loads a file to create multiple tokens
  54. //-----------------------------------------------------------------------------
  55. void CCreateTokenDialog::CreateMultipleTokens()
  56. {
  57. SetVisible(true);
  58. RequestFocus();
  59. MoveToFront();
  60. m_pTokenValue->RequestFocus();
  61. m_pSkipButton->SetVisible(true);
  62. m_bMultiToken = true;
  63. //!! read tokens from file, prompt user to each in turn
  64. }
  65. //-----------------------------------------------------------------------------
  66. // Purpose: Handles an OK message, creating the current token
  67. //-----------------------------------------------------------------------------
  68. void CCreateTokenDialog::OnOK()
  69. {
  70. // get the data
  71. char tokenName[1024], tokenValue[1024];
  72. m_pTokenName->GetText( tokenName, sizeof( tokenName ) );
  73. m_pTokenValue->GetText( tokenValue, sizeof( tokenValue ) );
  74. if ( Q_strlen( tokenName ) < 4 )
  75. {
  76. MessageBox *box = new MessageBox("Create Token Error", "Could not create token.\nToken names need to be at least 4 characters long.");
  77. box->DoModal();
  78. }
  79. else
  80. {
  81. // create the token
  82. wchar_t unicodeString[1024];
  83. g_pVGuiLocalize->ConvertANSIToUnicode(tokenValue, unicodeString, sizeof(unicodeString) / sizeof(wchar_t));
  84. g_pVGuiLocalize->AddString(tokenName, unicodeString, m_pLocalizationDialog->GetFileName() );
  85. // notify the dialog creator
  86. PostActionSignal(new KeyValues("TokenCreated", "name", tokenName));
  87. // close
  88. if (!m_bMultiToken)
  89. {
  90. PostMessage(this, new KeyValues("Close"));
  91. }
  92. }
  93. }
  94. //-----------------------------------------------------------------------------
  95. // Purpose: skips the current token in the multitoken edit mode
  96. //-----------------------------------------------------------------------------
  97. void CCreateTokenDialog::OnSkip()
  98. {
  99. }
  100. //-----------------------------------------------------------------------------
  101. // Purpose: handles a button command
  102. // Input : *command -
  103. //-----------------------------------------------------------------------------
  104. void CCreateTokenDialog::OnCommand(const char *command)
  105. {
  106. if (!stricmp(command, "OK"))
  107. {
  108. OnOK();
  109. }
  110. else if (!stricmp(command, "SkipToken"))
  111. {
  112. OnSkip();
  113. }
  114. else
  115. {
  116. BaseClass::OnCommand(command);
  117. }
  118. }
  119. //-----------------------------------------------------------------------------
  120. // Purpose: handles the close message
  121. //-----------------------------------------------------------------------------
  122. void CCreateTokenDialog::OnClose()
  123. {
  124. BaseClass::OnClose();
  125. MarkForDeletion();
  126. }