PresetGeneralTab.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. // PresetGeneralTab.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "leveledit.h"
  22. #include "PresetGeneralTab.h"
  23. #include "definition.h"
  24. #include "preset.h"
  25. #include "utils.h"
  26. #ifdef _DEBUG
  27. #define new DEBUG_NEW
  28. #undef THIS_FILE
  29. static char THIS_FILE[] = __FILE__;
  30. #endif
  31. /////////////////////////////////////////////////////////////////////////////
  32. //
  33. // PresetGeneralTabClass
  34. //
  35. /////////////////////////////////////////////////////////////////////////////
  36. PresetGeneralTabClass::PresetGeneralTabClass (PresetClass *preset)
  37. : m_Preset (preset),
  38. m_IsReadOnly (false),
  39. DockableFormClass(PresetGeneralTabClass::IDD)
  40. {
  41. //{{AFX_DATA_INIT(PresetGeneralTabClass)
  42. // NOTE: the ClassWizard will add member initialization here
  43. //}}AFX_DATA_INIT
  44. return ;
  45. }
  46. PresetGeneralTabClass::~PresetGeneralTabClass (void)
  47. {
  48. return ;
  49. }
  50. void
  51. PresetGeneralTabClass::DoDataExchange (CDataExchange *pDX)
  52. {
  53. DockableFormClass::DoDataExchange(pDX);
  54. //{{AFX_DATA_MAP(PresetGeneralTabClass)
  55. // NOTE: the ClassWizard will add DDX and DDV calls here
  56. //}}AFX_DATA_MAP
  57. return ;
  58. }
  59. BEGIN_MESSAGE_MAP(PresetGeneralTabClass, DockableFormClass)
  60. //{{AFX_MSG_MAP(PresetGeneralTabClass)
  61. // NOTE - the ClassWizard will add and remove mapping macros here.
  62. //}}AFX_MSG_MAP
  63. END_MESSAGE_MAP()
  64. /////////////////////////////////////////////////////////////////////////////
  65. // PresetGeneralTabClass diagnostics
  66. #ifdef _DEBUG
  67. void PresetGeneralTabClass::AssertValid() const
  68. {
  69. DockableFormClass::AssertValid();
  70. }
  71. void PresetGeneralTabClass::Dump(CDumpContext& dc) const
  72. {
  73. DockableFormClass::Dump(dc);
  74. }
  75. #endif //_DEBUG
  76. /////////////////////////////////////////////////////////////////////////////
  77. //
  78. // HandleInitDialog
  79. //
  80. /////////////////////////////////////////////////////////////////////////////
  81. void
  82. PresetGeneralTabClass::HandleInitDialog (void)
  83. {
  84. ASSERT (m_Preset != NULL);
  85. DefinitionClass *definition = m_Preset->Get_Definition ();
  86. if (definition != NULL) {
  87. //
  88. // Set the text of the respective dialog controls
  89. //
  90. SetDlgItemText (IDC_NAME_EDIT, definition->Get_Name ());
  91. SetDlgItemInt (IDC_PRESET_ID_EDIT, definition->Get_ID ());
  92. SetDlgItemText (IDC_COMMENTS_EDIT, m_Preset->Get_Comments ());
  93. }
  94. if (m_IsReadOnly) {
  95. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_NAME_EDIT), false);
  96. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_COMMENTS_EDIT), false);
  97. }
  98. // Put the focus into the edit control
  99. ::SetFocus (::GetDlgItem (m_hWnd, IDC_NAME_EDIT));
  100. return ;
  101. }
  102. /////////////////////////////////////////////////////////////////////////////
  103. //
  104. // Apply_Changes
  105. //
  106. /////////////////////////////////////////////////////////////////////////////
  107. bool
  108. PresetGeneralTabClass::Apply_Changes (void)
  109. {
  110. // Assume success
  111. bool retval = true;
  112. DefinitionClass *definition = m_Preset->Get_Definition ();
  113. if (definition != NULL) {
  114. // Pass the new name onto the base
  115. CString name;
  116. GetDlgItemText (IDC_NAME_EDIT, name);
  117. // Is the new name valid?
  118. if (name.GetLength () > 0) {
  119. definition->Set_Name (name);
  120. } else {
  121. // Let the user know they MUST enter a name for the base
  122. ::Message_Box (m_hWnd, IDS_BASE_INFO_NONAME_MSG, IDS_BASE_INFO_NONAME_TITLE);
  123. // Put the focus back to the control
  124. ::SetFocus (::GetDlgItem (m_hWnd, IDC_NAME_EDIT));
  125. retval = false;
  126. }
  127. // Pass the new comments onto the base
  128. CString comments;
  129. GetDlgItemText (IDC_COMMENTS_EDIT, comments);
  130. m_Preset->Set_Comments (comments);
  131. }
  132. // Return true to allow the dialog to close
  133. return retval;
  134. }