MenuScreen_Shell_Stereoscopics.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code 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. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #pragma hdrstop
  21. #include "../../idLib/precompiled.h"
  22. #include "../Game_local.h"
  23. const static int NUM_SYSTEM_OPTIONS_OPTIONS = 4;
  24. // TRC requires a maximum interoccular distance of 6.5cm even though human adults can easily have an interoccular distance of over 7.5cm
  25. const static float MAX_INTEROCCULAR_DISTANCE = 6.5f;
  26. // This should line up with stereo3DMode_t
  27. static const char * stereoRender_enable_text[] = {
  28. "#str_00641",
  29. "#str_swf_stereo_side_by_side",
  30. "#str_swf_stereo_top_and_bottom",
  31. "#str_swf_stereo_side_by_side_full",
  32. "#str_swf_stereo_interlaced",
  33. "#str_swf_stereo_quad"
  34. };
  35. static const int NUM_STEREO_ENABLE = sizeof( stereoRender_enable_text ) / sizeof( stereoRender_enable_text[0] );
  36. /*
  37. ========================
  38. idMenuScreen_Shell_Stereoscopics::Initialize
  39. ========================
  40. */
  41. void idMenuScreen_Shell_Stereoscopics::Initialize( idMenuHandler * data ) {
  42. idMenuScreen::Initialize( data );
  43. if ( data != NULL ) {
  44. menuGUI = data->GetGUI();
  45. }
  46. SetSpritePath( "menuStereoscopics" );
  47. options = new (TAG_SWF) idMenuWidget_DynamicList();
  48. options->SetNumVisibleOptions( NUM_SYSTEM_OPTIONS_OPTIONS );
  49. options->SetSpritePath( GetSpritePath(), "info", "options" );
  50. options->SetWrappingAllowed( true );
  51. options->SetControlList( true );
  52. options->Initialize( data );
  53. AddChild( options );
  54. btnBack = new (TAG_SWF) idMenuWidget_Button();
  55. btnBack->Initialize( data );
  56. btnBack->SetLabel( "#str_swf_settings" );
  57. btnBack->SetSpritePath( GetSpritePath(), "info", "btnBack" );
  58. btnBack->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_GO_BACK );
  59. AddChild( btnBack );
  60. idMenuWidget_ControlButton * control;
  61. control = new (TAG_SWF) idMenuWidget_ControlButton();
  62. control->SetOptionType( OPTION_SLIDER_TEXT );
  63. control->SetLabel( "#str_swf_stereoscopic_rendering" ); // Stereoscopics
  64. control->SetDataSource( &stereoData, idMenuDataSource_StereoSettings::STEREO_FIELD_ENABLE );
  65. control->SetupEvents( DEFAULT_REPEAT_TIME, options->GetChildren().Num() );
  66. control->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_PRESS_FOCUSED, options->GetChildren().Num() );
  67. options->AddChild( control );
  68. control = new (TAG_SWF) idMenuWidget_ControlButton();
  69. control->SetOptionType( OPTION_SLIDER_BAR );
  70. control->SetLabel( "#str_swf_stereo_seperation" ); // View Offset
  71. control->SetDataSource( &stereoData, idMenuDataSource_StereoSettings::STEREO_FIELD_SEPERATION );
  72. control->SetupEvents( 2, options->GetChildren().Num() );
  73. control->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_PRESS_FOCUSED, options->GetChildren().Num() );
  74. options->AddChild( control );
  75. control = new (TAG_SWF) idMenuWidget_ControlButton();
  76. control->SetOptionType( OPTION_SLIDER_TOGGLE );
  77. control->SetLabel( "#str_swf_stereo_eye_swap" ); // Swap Eyes
  78. control->SetDataSource( &stereoData, idMenuDataSource_StereoSettings::STEREO_FIELD_SWAP_EYES );
  79. control->SetupEvents( DEFAULT_REPEAT_TIME, options->GetChildren().Num() );
  80. control->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_PRESS_FOCUSED, options->GetChildren().Num() );
  81. options->AddChild( control );
  82. options->AddEventAction( WIDGET_EVENT_SCROLL_DOWN ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_DOWN_START_REPEATER, WIDGET_EVENT_SCROLL_DOWN ) );
  83. options->AddEventAction( WIDGET_EVENT_SCROLL_UP ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_UP_START_REPEATER, WIDGET_EVENT_SCROLL_UP ) );
  84. options->AddEventAction( WIDGET_EVENT_SCROLL_DOWN_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_DOWN_RELEASE ) );
  85. options->AddEventAction( WIDGET_EVENT_SCROLL_UP_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_UP_RELEASE ) );
  86. options->AddEventAction( WIDGET_EVENT_SCROLL_DOWN_LSTICK ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_DOWN_START_REPEATER, WIDGET_EVENT_SCROLL_DOWN_LSTICK ) );
  87. options->AddEventAction( WIDGET_EVENT_SCROLL_UP_LSTICK ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_UP_START_REPEATER, WIDGET_EVENT_SCROLL_UP_LSTICK ) );
  88. options->AddEventAction( WIDGET_EVENT_SCROLL_DOWN_LSTICK_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_DOWN_LSTICK_RELEASE ) );
  89. options->AddEventAction( WIDGET_EVENT_SCROLL_UP_LSTICK_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_UP_LSTICK_RELEASE ) );
  90. leftEyeMat = declManager->FindMaterial( "doomLeftEye" );
  91. rightEyeMat = declManager->FindMaterial( "doomRightEye" );
  92. }
  93. /*
  94. ========================
  95. idMenuScreen_Shell_Stereoscopics::Update
  96. ========================
  97. */
  98. void idMenuScreen_Shell_Stereoscopics::Update() {
  99. if ( menuData != NULL ) {
  100. idMenuWidget_CommandBar * cmdBar = menuData->GetCmdBar();
  101. if ( cmdBar != NULL ) {
  102. cmdBar->ClearAllButtons();
  103. idMenuWidget_CommandBar::buttonInfo_t * buttonInfo;
  104. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY2 );
  105. if ( menuData->GetPlatform() != 2 ) {
  106. buttonInfo->label = "#str_00395";
  107. }
  108. buttonInfo->action.Set( WIDGET_ACTION_GO_BACK );
  109. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY1 );
  110. buttonInfo->action.Set( WIDGET_ACTION_PRESS_FOCUSED );
  111. }
  112. }
  113. idSWFScriptObject & root = GetSWFObject()->GetRootObject();
  114. if ( BindSprite( root ) ) {
  115. idSWFTextInstance * heading = GetSprite()->GetScriptObject()->GetNestedText( "info", "txtHeading" );
  116. if ( heading != NULL ) {
  117. heading->SetText( "#str_swf_stereoscopics_heading" ); // STEREOSCOPIC RENDERING
  118. heading->SetStrokeInfo( true, 0.75f, 1.75f );
  119. }
  120. idSWFSpriteInstance * gradient = GetSprite()->GetScriptObject()->GetNestedSprite( "info", "gradient" );
  121. if ( gradient != NULL && heading != NULL ) {
  122. gradient->SetXPos( heading->GetTextLength() );
  123. }
  124. }
  125. if ( btnBack != NULL ) {
  126. btnBack->BindSprite( root );
  127. }
  128. idMenuScreen::Update();
  129. }
  130. /*
  131. ========================
  132. idMenuScreen_Shell_Stereoscopics::ShowScreen
  133. ========================
  134. */
  135. void idMenuScreen_Shell_Stereoscopics::ShowScreen( const mainMenuTransition_t transitionType ) {
  136. stereoData.LoadData();
  137. idMenuScreen::ShowScreen( transitionType );
  138. if ( GetSprite() != NULL ) {
  139. idSWFSpriteInstance * leftEye = GetSprite()->GetScriptObject()->GetNestedSprite( "info", "leftEye" );
  140. idSWFSpriteInstance * rightEye = GetSprite()->GetScriptObject()->GetNestedSprite( "info", "rightEye" );
  141. if ( leftEye != NULL && leftEyeMat != NULL ) {
  142. leftEye->SetMaterial( leftEyeMat );
  143. }
  144. if ( rightEye != NULL && rightEyeMat != NULL ) {
  145. rightEye->SetMaterial( rightEyeMat );
  146. }
  147. }
  148. }
  149. /*
  150. ========================
  151. idMenuScreen_Shell_Stereoscopics::HideScreen
  152. ========================
  153. */
  154. void idMenuScreen_Shell_Stereoscopics::HideScreen( const mainMenuTransition_t transitionType ) {
  155. if ( stereoData.IsRestartRequired() ) {
  156. class idSWFScriptFunction_Restart : public idSWFScriptFunction_RefCounted {
  157. public:
  158. idSWFScriptFunction_Restart( gameDialogMessages_t _msg, bool _restart ) {
  159. msg = _msg;
  160. restart = _restart;
  161. }
  162. idSWFScriptVar Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  163. common->Dialog().ClearDialog( msg );
  164. if ( restart ) {
  165. idStr cmdLine = Sys_GetCmdLine();
  166. if ( cmdLine.Find( "com_skipIntroVideos" ) < 0 ) {
  167. cmdLine.Append( " +set com_skipIntroVideos 1" );
  168. }
  169. Sys_ReLaunch( (void*)cmdLine.c_str(), cmdLine.Length() );
  170. }
  171. return idSWFScriptVar();
  172. }
  173. private:
  174. gameDialogMessages_t msg;
  175. bool restart;
  176. };
  177. idStaticList<idSWFScriptFunction *, 4> callbacks;
  178. idStaticList<idStrId, 4> optionText;
  179. callbacks.Append( new idSWFScriptFunction_Restart( GDM_GAME_RESTART_REQUIRED, false ) );
  180. callbacks.Append( new idSWFScriptFunction_Restart( GDM_GAME_RESTART_REQUIRED, true ) );
  181. optionText.Append( idStrId( "#str_00100113" ) ); // Continue
  182. optionText.Append( idStrId( "#str_02487" ) ); // Restart Now
  183. common->Dialog().AddDynamicDialog( GDM_GAME_RESTART_REQUIRED, callbacks, optionText, true, idStr() );
  184. }
  185. if ( stereoData.IsDataChanged() ) {
  186. stereoData.CommitData();
  187. }
  188. idMenuScreen::HideScreen( transitionType );
  189. }
  190. /*
  191. ========================
  192. idMenuScreen_Shell_Stereoscopics::HandleAction h
  193. ========================
  194. */
  195. bool idMenuScreen_Shell_Stereoscopics::HandleAction( idWidgetAction & action, const idWidgetEvent & event, idMenuWidget * widget, bool forceHandled ) {
  196. if ( menuData != NULL ) {
  197. if ( menuData->ActiveScreen() != SHELL_AREA_STEREOSCOPICS ) {
  198. return false;
  199. }
  200. }
  201. widgetAction_t actionType = action.GetType();
  202. const idSWFParmList & parms = action.GetParms();
  203. switch ( actionType ) {
  204. case WIDGET_ACTION_GO_BACK: {
  205. if ( menuData != NULL ) {
  206. menuData->SetNextScreen( SHELL_AREA_SETTINGS, MENU_TRANSITION_SIMPLE );
  207. }
  208. return true;
  209. }
  210. case WIDGET_ACTION_PRESS_FOCUSED: {
  211. if ( options == NULL ) {
  212. return true;
  213. }
  214. int selectionIndex = options->GetFocusIndex();
  215. if ( parms.Num() > 0 ) {
  216. selectionIndex = parms[0].ToInteger();
  217. }
  218. if ( selectionIndex != options->GetFocusIndex() ) {
  219. options->SetViewIndex( options->GetViewOffset() + selectionIndex );
  220. options->SetFocusIndex( selectionIndex );
  221. }
  222. stereoData.AdjustField( selectionIndex, 1 );
  223. options->Update();
  224. return true;
  225. }
  226. case WIDGET_ACTION_START_REPEATER: {
  227. if ( options == NULL ) {
  228. return true;
  229. }
  230. if ( parms.Num() == 4 ) {
  231. int selectionIndex = parms[3].ToInteger();
  232. if ( selectionIndex != options->GetFocusIndex() ) {
  233. options->SetViewIndex( options->GetViewOffset() + selectionIndex );
  234. options->SetFocusIndex( selectionIndex );
  235. }
  236. }
  237. break;
  238. }
  239. }
  240. return idMenuWidget::HandleAction( action, event, widget, forceHandled );
  241. }
  242. /////////////////////////////////
  243. // SCREEN SETTINGS
  244. /////////////////////////////////
  245. extern idCVar stereoRender_interOccularCentimeters;
  246. extern idCVar stereoRender_swapEyes;
  247. /*
  248. ========================
  249. idMenuScreen_Shell_Stereoscopics::idMenuDataSource_StereoSettings::idMenuDataSource_StereoSettings
  250. ========================
  251. */
  252. idMenuScreen_Shell_Stereoscopics::idMenuDataSource_StereoSettings::idMenuDataSource_StereoSettings() {
  253. fields.SetNum( MAX_STEREO_FIELDS );
  254. originalFields.SetNum( MAX_STEREO_FIELDS );
  255. }
  256. /*
  257. ========================
  258. idMenuScreen_Shell_Stereoscopics::idMenuDataSource_StereoSettings::LoadData
  259. ========================
  260. */
  261. void idMenuScreen_Shell_Stereoscopics::idMenuDataSource_StereoSettings::LoadData() {
  262. fields[ STEREO_FIELD_ENABLE ].SetInteger( renderSystem->GetStereoScopicRenderingMode() );
  263. fields[ STEREO_FIELD_SEPERATION ].SetFloat( 100.0f * ( stereoRender_interOccularCentimeters.GetFloat() / MAX_INTEROCCULAR_DISTANCE ) );
  264. fields[ STEREO_FIELD_SWAP_EYES ].SetBool( stereoRender_swapEyes.GetBool() );
  265. originalFields = fields;
  266. }
  267. /*
  268. ========================
  269. idMenuScreen_Shell_Stereoscopics::idMenuDataSource_StereoSettings::CommitData
  270. ========================
  271. */
  272. void idMenuScreen_Shell_Stereoscopics::idMenuDataSource_StereoSettings::CommitData() {
  273. if ( IsDataChanged() ) {
  274. cvarSystem->SetModifiedFlags( CVAR_ARCHIVE );
  275. }
  276. // make the committed fields into the backup fields
  277. originalFields = fields;
  278. }
  279. /*
  280. ========================
  281. idMenuScreen_Shell_Stereoscopics::idMenuDataSource_StereoSettings::AdjustField
  282. ========================
  283. */
  284. void idMenuScreen_Shell_Stereoscopics::idMenuDataSource_StereoSettings::AdjustField( const int fieldIndex, const int adjustAmount ) {
  285. if ( fieldIndex == STEREO_FIELD_ENABLE ) {
  286. int numOptions = NUM_STEREO_ENABLE;
  287. if ( !renderSystem->HasQuadBufferSupport() ) {
  288. numOptions--;
  289. }
  290. int adjusted = fields[ fieldIndex ].ToInteger() + adjustAmount;
  291. adjusted += numOptions;
  292. adjusted %= numOptions;
  293. fields[fieldIndex].SetInteger( adjusted );
  294. renderSystem->EnableStereoScopicRendering( (stereo3DMode_t)adjusted );
  295. gameLocal.Shell_ClearRepeater();
  296. } else if ( fieldIndex == STEREO_FIELD_SWAP_EYES ) {
  297. fields[ fieldIndex ].SetBool( !fields[ fieldIndex ].ToBool() );
  298. stereoRender_swapEyes.SetBool( fields[ fieldIndex ].ToBool() );
  299. } else if ( fieldIndex == STEREO_FIELD_SEPERATION ) {
  300. float newValue = idMath::ClampFloat( 0.0f, 100.0f, fields[ fieldIndex ].ToFloat() + adjustAmount );
  301. fields[ fieldIndex ].SetFloat( newValue );
  302. stereoRender_interOccularCentimeters.SetFloat( ( fields[ STEREO_FIELD_SEPERATION ].ToFloat() / 100.0f ) * MAX_INTEROCCULAR_DISTANCE );
  303. }
  304. // do this so we don't save every time we modify a setting. Only save once when we leave the screen
  305. cvarSystem->ClearModifiedFlags( CVAR_ARCHIVE );
  306. }
  307. /*
  308. ========================
  309. idMenuScreen_Shell_Stereoscopics::idMenuDataSource_StereoSettings::IsDataChanged
  310. ========================
  311. */
  312. idSWFScriptVar idMenuScreen_Shell_Stereoscopics::idMenuDataSource_StereoSettings::GetField( const int fieldIndex ) const {
  313. if ( fieldIndex == STEREO_FIELD_ENABLE ) {
  314. return idSWFScriptVar( stereoRender_enable_text[fields[fieldIndex].ToInteger()] );
  315. }
  316. return fields[ fieldIndex ];
  317. }
  318. /*
  319. ========================
  320. idMenuScreen_Shell_Stereoscopics::idMenuDataSource_StereoSettings::IsDataChanged
  321. ========================
  322. */
  323. bool idMenuScreen_Shell_Stereoscopics::idMenuDataSource_StereoSettings::IsDataChanged() const {
  324. if ( fields[ STEREO_FIELD_SWAP_EYES ].ToBool() != originalFields[ STEREO_FIELD_SWAP_EYES ].ToBool() ) {
  325. return true;
  326. }
  327. if ( fields[ STEREO_FIELD_ENABLE ].ToInteger() != originalFields[ STEREO_FIELD_ENABLE ].ToInteger() ) {
  328. return true;
  329. }
  330. if ( fields[ STEREO_FIELD_SEPERATION ].ToFloat() != originalFields[ STEREO_FIELD_SEPERATION ].ToFloat() ) {
  331. return true;
  332. }
  333. return false;
  334. }
  335. /*
  336. ========================
  337. idMenuScreen_Shell_Stereoscopics::idMenuDataSource_StereoSettings::IsRestartRequired
  338. ========================
  339. */
  340. bool idMenuScreen_Shell_Stereoscopics::idMenuDataSource_StereoSettings::IsRestartRequired() const {
  341. if ( fields[ STEREO_FIELD_ENABLE ].ToInteger() != originalFields[ STEREO_FIELD_ENABLE ].ToInteger() ) {
  342. if ( fields[ STEREO_FIELD_ENABLE ].ToInteger() == STEREO3D_QUAD_BUFFER || originalFields[ STEREO_FIELD_ENABLE ].ToInteger() == STEREO3D_QUAD_BUFFER ) {
  343. return true;
  344. }
  345. }
  346. return false;
  347. }