mainmenutransition.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Combat *
  23. * *
  24. * $Archive:: /Commando/Code/commando/mainmenutransition.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 12/20/01 7:25p $*
  29. * *
  30. * $Revision:: 8 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "mainmenutransition.h"
  36. #include "camera.h"
  37. #include "stylemgr.h"
  38. #include "assetmgr.h"
  39. #include "hanim.h"
  40. #include "rendobj.h"
  41. #include "ww3d.h"
  42. #include "dialogresource.h"
  43. #include "render2d.h"
  44. #include "dialogcontrol.h"
  45. #include "dialogbase.h"
  46. #include "resource.h"
  47. #include "wwaudio.h"
  48. ////////////////////////////////////////////////////////////////
  49. // Local constants
  50. ////////////////////////////////////////////////////////////////
  51. static const float IN_START_FRAME = 27.0F;
  52. static const float IN_END_FRAME = 65.0F;
  53. static const float OUT_START_FRAME = 66.0F;
  54. static const float OUT_END_FRAME = 99.0F;
  55. static const char *ANIM_NAME = "IF_TITLETRANS.IF_TITLETRANS";
  56. ////////////////////////////////////////////////////////////////
  57. //
  58. // MainMenuTransitionClass
  59. //
  60. ////////////////////////////////////////////////////////////////
  61. MainMenuTransitionClass::MainMenuTransitionClass (void) :
  62. Model (NULL),
  63. Dialog (NULL),
  64. OtherDlg (NULL),
  65. Camera (NULL),
  66. CurrentFrame (0),
  67. TargetFrame (0),
  68. TransitionAnim (NULL)
  69. {
  70. return ;
  71. }
  72. ////////////////////////////////////////////////////////////////
  73. //
  74. // ~MainMenuTransitionClass
  75. //
  76. ////////////////////////////////////////////////////////////////
  77. MainMenuTransitionClass::~MainMenuTransitionClass (void)
  78. {
  79. REF_PTR_RELEASE (Model);
  80. REF_PTR_RELEASE (TransitionAnim);
  81. return ;
  82. }
  83. ////////////////////////////////////////////////////////////////
  84. //
  85. // Set_Dialogs
  86. //
  87. ////////////////////////////////////////////////////////////////
  88. void
  89. MainMenuTransitionClass::Set_Dialogs (DialogBaseClass *dialog, DialogBaseClass *other_dlg)
  90. {
  91. Dialog = dialog;
  92. OtherDlg = other_dlg;
  93. return ;
  94. }
  95. ////////////////////////////////////////////////////////////////
  96. //
  97. // Set_Model
  98. //
  99. ////////////////////////////////////////////////////////////////
  100. void
  101. MainMenuTransitionClass::Set_Model (RenderObjClass *model)
  102. {
  103. REF_PTR_SET (Model, model);
  104. if (TransitionAnim == NULL) {
  105. TransitionAnim = WW3DAssetManager::Get_Instance ()->Get_HAnim (ANIM_NAME);
  106. }
  107. return ;
  108. }
  109. ////////////////////////////////////////////////////////////////
  110. //
  111. // Set_Type
  112. //
  113. ////////////////////////////////////////////////////////////////
  114. void
  115. MainMenuTransitionClass::Set_Type (TYPE type)
  116. {
  117. DialogTransitionClass::Set_Type (type);
  118. if (type == SCREEN_IN) {
  119. CurrentFrame = IN_START_FRAME;
  120. TargetFrame = IN_END_FRAME;
  121. WWAudioClass::Get_Instance ()->Simple_Play_2D_Sound_Effect ("interface_mainmove.wav", 1.0F, 0.8F);
  122. } else if (type == SCREEN_OUT) {
  123. CurrentFrame = OUT_START_FRAME;
  124. TargetFrame = OUT_END_FRAME;
  125. WWAudioClass::Get_Instance ()->Simple_Play_2D_Sound_Effect ("interface_movezoom.wav", 1.0F, 0.8F);
  126. }
  127. return ;
  128. }
  129. ////////////////////////////////////////////////////////////////
  130. //
  131. // On_Frame_Update
  132. //
  133. ////////////////////////////////////////////////////////////////
  134. void
  135. MainMenuTransitionClass::On_Frame_Update (void)
  136. {
  137. if (Model != NULL && TransitionAnim != NULL) {
  138. //
  139. // Do we need to keep animating?
  140. //
  141. if (CurrentFrame < TargetFrame) {
  142. //
  143. // Get the frame rate
  144. //
  145. float frame_rate = TransitionAnim->Get_Frame_Rate ();
  146. //
  147. // Adjust the current frame counter
  148. //
  149. CurrentFrame += (frame_rate * (WW3D::Get_Frame_Time () / 1000.0F));
  150. CurrentFrame = min (CurrentFrame, TargetFrame);
  151. //
  152. // Update the animation
  153. //
  154. Model->Set_Animation (TransitionAnim, CurrentFrame);
  155. //
  156. // Move the controls with the animation
  157. //
  158. Update_Controls ();
  159. //
  160. // Remove the model if we've finished animating
  161. //
  162. if (CurrentFrame >= TargetFrame && Type == SCREEN_OUT) {
  163. Model->Remove ();
  164. }
  165. }
  166. }
  167. DialogTransitionClass::On_Frame_Update ();
  168. return ;
  169. }
  170. ////////////////////////////////////////////////////////////////
  171. //
  172. // Update_Controls
  173. //
  174. ////////////////////////////////////////////////////////////////
  175. void
  176. MainMenuTransitionClass::Update_Controls (void)
  177. {
  178. const int ENTRIES = 6;
  179. const int ControlIDArray[ENTRIES] =
  180. {
  181. IDC_MENU_START_SP_GAME_BUTTON,
  182. //C_MENU_START_SKIRMISH_GAME_BUTTON,
  183. IDC_MENU_MP_INTERNET_GAME_BUTTON,
  184. IDC_MENU_MP_LAN_GAME_BUTTON,
  185. IDC_MENU_START_PRACTICE_GAME_BUTTON,
  186. IDC_MENU_OPTIONS_BUTTON,
  187. IDC_MENU_QUIT_BUTTON
  188. };
  189. //
  190. // Get the half dimensions of the screen
  191. //
  192. const RectClass &screen_rect = Render2DClass::Get_Screen_Resolution ();
  193. float half_width = screen_rect.Width () / 2.0F;
  194. float half_height = screen_rect.Height () / 2.0F;
  195. //
  196. // Update the position of each control
  197. //
  198. for (int index = 0; index < ENTRIES; index ++) {
  199. //
  200. // Get the current position of the bone
  201. //
  202. StringClass bone_name;
  203. bone_name.Format ("IF_MMTF%d", index + 1);
  204. const Matrix3D &tm = Model->Get_Bone_Transform (bone_name);
  205. //
  206. // Transform the position into screen space
  207. //
  208. Vector3 cam_space_pos (0, 0, 0);
  209. Camera->Transform_To_View_Space (cam_space_pos, tm.Get_Translation ());
  210. Vector3 new_pos (0, 0, 0);
  211. Camera->Project_Camera_Space_Point (new_pos, cam_space_pos);
  212. //
  213. // Convert the normalized screen space position to pixel coordinates
  214. //
  215. new_pos.X = half_width * (new_pos.X + 1.0F);
  216. new_pos.Y = half_height * (1.0F - new_pos.Y);
  217. //
  218. // Move each control to the left of the bone a little
  219. //
  220. new_pos.X -= StyleMgrClass::Get_X_Scale () * 100.0F;
  221. //
  222. // Move the dialog control
  223. //
  224. DialogControlClass *control = Dialog->Get_Dlg_Item (ControlIDArray[index]);
  225. const RectClass &control_rect = control->Get_Window_Rect ();
  226. new_pos.Y -= (control_rect.Height () / 2);
  227. control->Set_Window_Pos (Vector2 (new_pos.X, new_pos.Y));
  228. }
  229. return ;
  230. }
  231. ////////////////////////////////////////////////////////////////
  232. //
  233. // Is_Valid
  234. //
  235. ////////////////////////////////////////////////////////////////
  236. bool
  237. MainMenuTransitionClass::Is_Valid (void) const
  238. {
  239. bool retval = false;
  240. //
  241. // Check to see if the model and animation are valid
  242. //
  243. if (Model != NULL && TransitionAnim != NULL) {
  244. retval = true;
  245. }
  246. return retval;
  247. }