DebugWindowDialog.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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. #include "StdAfx.h"
  19. #include "DebugWindowDialog.h"
  20. DebugWindowDialog::DebugWindowDialog(UINT nIDTemplate, CWnd* pParentWnd) :
  21. CDialog(nIDTemplate, pParentWnd)
  22. {
  23. mStepping = false;
  24. mRunFast = false;
  25. mNumberOfStepsAllowed = -1;
  26. mMainWndHWND = ::FindWindow(NULL, "Command & Conquer: Generals");
  27. }
  28. int DebugWindowDialog::OnCreate(LPCREATESTRUCT lpCreateStruct)
  29. {
  30. return CDialog::OnCreate(lpCreateStruct);
  31. }
  32. HWND DebugWindowDialog::GetMainWndHWND(void)
  33. {
  34. return mMainWndHWND;
  35. }
  36. void DebugWindowDialog::ForcePause(void)
  37. {
  38. mNumberOfStepsAllowed = 0;
  39. _UpdatePauseButton();
  40. }
  41. void DebugWindowDialog::ForceContinue(void)
  42. {
  43. mNumberOfStepsAllowed = -1;
  44. _UpdatePauseButton();
  45. }
  46. void DebugWindowDialog::OnPause()
  47. {
  48. if (mNumberOfStepsAllowed < 0) {
  49. mNumberOfStepsAllowed = 0;
  50. } else {
  51. mNumberOfStepsAllowed = -1;
  52. }
  53. _UpdatePauseButton();
  54. }
  55. void DebugWindowDialog::OnStep()
  56. {
  57. mStepping = true;
  58. mNumberOfStepsAllowed = 1;
  59. _UpdatePauseButton();
  60. }
  61. void DebugWindowDialog::OnRunFast()
  62. {
  63. CButton *pButton = (CButton*)GetDlgItem(IDC_RUN_FAST);
  64. mRunFast = pButton->GetCheck() == 1;
  65. }
  66. void DebugWindowDialog::OnStepTen()
  67. {
  68. mStepping = true;
  69. mNumberOfStepsAllowed = 10;
  70. _UpdatePauseButton();
  71. }
  72. void DebugWindowDialog::OnClearWindows()
  73. {
  74. mMessages.clear();
  75. mVariables.clear();
  76. _RebuildMesgString();
  77. _RebuildVarsString();
  78. }
  79. bool DebugWindowDialog::CanProceed(void)
  80. {
  81. if (mNumberOfStepsAllowed < 0) {
  82. return true;
  83. } else if (mNumberOfStepsAllowed == 0) {
  84. if (mStepping) {
  85. mStepping = false;
  86. _UpdatePauseButton();
  87. }
  88. return false;
  89. }
  90. --mNumberOfStepsAllowed;
  91. return true;
  92. }
  93. bool DebugWindowDialog::RunAppFast(void)
  94. {
  95. return mRunFast;
  96. }
  97. void DebugWindowDialog::AppendMessage(const std::string& messageToAppend)
  98. {
  99. mMessages.push_back(messageToAppend);
  100. _RebuildMesgString();
  101. }
  102. void DebugWindowDialog::AdjustVariable(const std::string& varName, const std::string& varValue)
  103. {
  104. for (VecPairStringIt it = mVariables.begin(); it != mVariables.end(); it++) {
  105. if (it->first == varName) {
  106. it->second = varValue;
  107. _RebuildVarsString();
  108. return;
  109. }
  110. }
  111. PairString newPair;
  112. newPair.first = varName;
  113. newPair.second = varValue;
  114. mVariables.push_back(newPair);
  115. _RebuildVarsString();
  116. }
  117. void DebugWindowDialog::SetFrameNumber(int frameNumber)
  118. {
  119. static int numDigits;
  120. numDigits = frameNumber / 10 + 2; // 1 for 1 additional digit, 1 for \0
  121. mFrameNumber.resize(numDigits);
  122. sprintf(mFrameNumber.begin(), "%d", frameNumber);
  123. CWnd *pWnd = GetDlgItem(IDC_FrameNumber);
  124. if (pWnd) {
  125. pWnd->SetWindowText(mFrameNumber.begin());
  126. }
  127. }
  128. void DebugWindowDialog::_RebuildVarsString(void)
  129. {
  130. int cursorPosBeg, cursorPosEnd;
  131. ((CEdit*)GetDlgItem(IDC_Variables))->GetSel(cursorPosBeg, cursorPosEnd);
  132. mVariablesString = "";
  133. for (VecPairStringIt it = mVariables.begin(); it != mVariables.end(); it++) {
  134. mVariablesString += it->first;
  135. mVariablesString += " = ";
  136. mVariablesString += it->second;
  137. mVariablesString += "\r\n";
  138. }
  139. // Push the new string
  140. mVariablesDisplayString = mVariablesString.c_str();
  141. GetDlgItem(IDC_Variables)->SetWindowText(mVariablesDisplayString);
  142. ((CEdit*)GetDlgItem(IDC_Variables))->GetSel(cursorPosBeg, cursorPosEnd);
  143. }
  144. void DebugWindowDialog::_RebuildMesgString(void)
  145. {
  146. mMessagesString = "";
  147. for (VecStringIt it = mMessages.begin(); it != mMessages.end(); it++) {
  148. mMessagesString += (*it);
  149. mMessagesString += "\r\n";
  150. }
  151. // Push the new string
  152. mMessagesDisplayString = mMessagesString.c_str();
  153. GetDlgItem(IDC_Messages)->SetWindowText(mMessagesDisplayString);
  154. ((CEdit*)GetDlgItem(IDC_Messages))->SetSel(mMessagesString.length(), mMessagesString.length(), false);
  155. }
  156. void DebugWindowDialog::_UpdatePauseButton(void)
  157. {
  158. // huh huh huhuh he said pButt
  159. CButton* pButt = (CButton*) GetDlgItem(IDC_Pause);
  160. if (!pButt) {
  161. return;
  162. }
  163. // The state should of the button should reflect !mNumberOfStepsAllowed
  164. pButt->SetCheck((mNumberOfStepsAllowed ? FALSE : TRUE));
  165. }
  166. void DebugWindowDialog::OnClose()
  167. {
  168. ShowWindow(SW_MINIMIZE);
  169. }
  170. void DebugWindowDialog::OnSize(UINT nType, int cx, int cy)
  171. {
  172. CDialog::OnSize(nType, cx, cy);
  173. if (nType == SIZE_MINIMIZED) {
  174. if (mMainWndHWND) {
  175. ::SetFocus(mMainWndHWND);
  176. }
  177. }
  178. }
  179. BEGIN_MESSAGE_MAP(DebugWindowDialog, CDialog)
  180. ON_WM_CREATE( )
  181. ON_BN_CLICKED(IDC_Pause, OnPause)
  182. ON_BN_CLICKED(IDC_Step, OnStep)
  183. ON_BN_CLICKED(IDC_RUN_FAST, OnRunFast)
  184. ON_BN_CLICKED(IDC_StepTen, OnStepTen)
  185. ON_BN_CLICKED(IDC_ClearWindows, OnClearWindows)
  186. ON_WM_CLOSE()
  187. ON_WM_SIZE()
  188. END_MESSAGE_MAP()