MenuScreen_PDA_UserEmails.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  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. /*
  24. ========================
  25. idMenuScreen_PDA_UserEmails::Initialize
  26. ========================
  27. */
  28. void idMenuScreen_PDA_UserEmails::Initialize( idMenuHandler * data ) {
  29. idMenuScreen::Initialize( data );
  30. if ( data != NULL ) {
  31. menuGUI = data->GetGUI();
  32. }
  33. SetSpritePath( "menuEmail" );
  34. pdaInbox.SetSpritePath( GetSpritePath(), "info", "inbox" );
  35. pdaInbox.Initialize( data );
  36. pdaInbox.SetNoAutoFree( true );
  37. emailScrollbar.SetSpritePath( GetSpritePath(), "info", "email", "info", "scrollbar" );
  38. emailScrollbar.Initialize( data );
  39. emailScrollbar.SetNoAutoFree( true );
  40. emailInfo.SetSpritePath( GetSpritePath(), "info", "email" );
  41. emailInfo.Initialize( data );
  42. emailInfo.SetScrollbar( &emailScrollbar );
  43. emailInfo.AddChild( &emailScrollbar );
  44. emailInfo.RegisterEventObserver( this );
  45. emailInfo.AddEventAction( WIDGET_EVENT_ROLL_OVER ).Set( WIDGET_ACTION_EMAIL_HOVER, 1 );
  46. emailInfo.AddEventAction( WIDGET_EVENT_ROLL_OUT ).Set( WIDGET_ACTION_EMAIL_HOVER, 0 );
  47. emailInfo.SetNoAutoFree( true );
  48. AddChild( &pdaInbox );
  49. AddChild( &emailInfo );
  50. if ( pdaInbox.GetEmailList() != NULL ) {
  51. pdaInbox.GetEmailList()->RegisterEventObserver( &emailInfo );
  52. pdaInbox.GetEmailList()->RegisterEventObserver( &emailScrollbar );
  53. for ( int i = 0; i < pdaInbox.GetEmailList()->GetChildren().Num(); ++i ) {
  54. idMenuWidget & child = pdaInbox.GetEmailList()->GetChildByIndex( i );
  55. idMenuWidget_Button * const button = dynamic_cast< idMenuWidget_Button * >( &child );
  56. if ( button != NULL ) {
  57. button->RegisterEventObserver( &emailInfo );
  58. }
  59. }
  60. }
  61. AddEventAction( WIDGET_EVENT_SCROLL_DOWN_RSTICK ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_SCROLL_DOWN_START_REPEATER, WIDGET_EVENT_SCROLL_DOWN_RSTICK ) );
  62. AddEventAction( WIDGET_EVENT_SCROLL_UP_RSTICK ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_SCROLL_UP_START_REPEATER, WIDGET_EVENT_SCROLL_UP_RSTICK ) );
  63. AddEventAction( WIDGET_EVENT_SCROLL_DOWN_RSTICK_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_DOWN_RSTICK_RELEASE ) );
  64. AddEventAction( WIDGET_EVENT_SCROLL_UP_RSTICK_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_UP_RSTICK_RELEASE ) );
  65. AddEventAction( WIDGET_EVENT_SCROLL_DOWN ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_SCROLL_DOWN_START_REPEATER, WIDGET_EVENT_SCROLL_DOWN ) );
  66. AddEventAction( WIDGET_EVENT_SCROLL_UP ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_SCROLL_UP_START_REPEATER, WIDGET_EVENT_SCROLL_UP ) );
  67. AddEventAction( WIDGET_EVENT_SCROLL_DOWN_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_DOWN_RELEASE ) );
  68. AddEventAction( WIDGET_EVENT_SCROLL_UP_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_UP_RELEASE ) );
  69. AddEventAction( WIDGET_EVENT_SCROLL_DOWN_LSTICK ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_SCROLL_DOWN_START_REPEATER, WIDGET_EVENT_SCROLL_DOWN_LSTICK ) );
  70. AddEventAction( WIDGET_EVENT_SCROLL_UP_LSTICK ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_SCROLL_UP_START_REPEATER, WIDGET_EVENT_SCROLL_UP_LSTICK ) );
  71. AddEventAction( WIDGET_EVENT_SCROLL_DOWN_LSTICK_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_DOWN_LSTICK_RELEASE ) );
  72. AddEventAction( WIDGET_EVENT_SCROLL_UP_LSTICK_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_UP_LSTICK_RELEASE ) );
  73. AddEventAction( WIDGET_EVENT_TAB_NEXT ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_TAB_NEXT, WIDGET_EVENT_TAB_NEXT ) );
  74. AddEventAction( WIDGET_EVENT_TAB_PREV ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_TAB_PREV, WIDGET_EVENT_TAB_PREV ) );
  75. class idInfoBoxRefresh : public idSWFScriptFunction_RefCounted {
  76. public:
  77. idInfoBoxRefresh( idMenuWidget_InfoBox * _widget ) :
  78. widget( _widget ) {
  79. }
  80. idSWFScriptVar Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  81. if ( widget == NULL ) {
  82. return idSWFScriptVar();
  83. }
  84. widget->Update();
  85. return idSWFScriptVar();
  86. }
  87. private:
  88. idMenuWidget_InfoBox * widget;
  89. };
  90. if ( GetSWFObject() != NULL ) {
  91. GetSWFObject()->SetGlobal( "refreshInfoBox", new (TAG_SWF) idInfoBoxRefresh( &emailInfo ) );
  92. }
  93. }
  94. /*
  95. ========================
  96. idMenuScreen_PDA_UserEmails::ShowScreen
  97. ========================
  98. */
  99. void idMenuScreen_PDA_UserEmails::ShowScreen( const mainMenuTransition_t transitionType ) {
  100. if ( menuGUI != NULL ) {
  101. readingEmails = false;
  102. idSWFScriptObject & root = menuGUI->GetRootObject();
  103. idSWFSpriteInstance * pdaSprite = root.GetNestedSprite( "pda_persons" );
  104. if ( pdaSprite != NULL && menuData != NULL && menuData->ActiveScreen() != PDA_AREA_USER_DATA ) {
  105. pdaSprite->SetVisible( true );
  106. pdaSprite->PlayFrame( "rollOn" );
  107. }
  108. menuGUI->SetGlobal( "emailRollback", false );
  109. if ( pdaInbox.BindSprite( root ) && pdaInbox.GetSprite() ) {
  110. pdaInbox.GetSprite()->StopFrame( 1 );
  111. }
  112. if ( emailInfo.BindSprite( root ) && emailInfo.GetSprite() ) {
  113. emailInfo.GetSprite()->StopFrame( 1 );
  114. }
  115. }
  116. scrollEmailInfo = false;
  117. idMenuScreen::ShowScreen( transitionType );
  118. }
  119. /*
  120. ========================
  121. idMenuScreen_PDA_UserEmails::Update
  122. ========================
  123. */
  124. void idMenuScreen_PDA_UserEmails::Update() {
  125. if ( menuData != NULL ) {
  126. if ( menuData->NextScreen() != PDA_AREA_USER_EMAIL ) {
  127. return;
  128. }
  129. idMenuWidget_CommandBar * cmdBar = dynamic_cast< idMenuWidget_CommandBar * const >( menuData->GetChildFromIndex( PDA_WIDGET_CMD_BAR ) );
  130. if ( cmdBar != NULL ) {
  131. cmdBar->ClearAllButtons();
  132. idMenuWidget_CommandBar::buttonInfo_t * buttonInfo;
  133. if ( readingEmails ) {
  134. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY2 );
  135. if ( menuData->GetPlatform() != 2 ) {
  136. buttonInfo->label = "#str_00395";
  137. }
  138. buttonInfo->action.Set( WIDGET_ACTION_GO_BACK );
  139. } else {
  140. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY2 );
  141. if ( menuData->GetPlatform() != 2 ) {
  142. buttonInfo->label = "#str_01345";
  143. }
  144. buttonInfo->action.Set( WIDGET_ACTION_GO_BACK );
  145. idMenuWidget_DynamicList * pdaList = dynamic_cast< idMenuWidget_DynamicList * >( menuData->GetChildFromIndex( PDA_WIDGET_PDA_LIST ) );
  146. if ( pdaList != NULL ) {
  147. int pdaIndex = pdaList->GetViewIndex();
  148. idPlayer * player = gameLocal.GetLocalPlayer();
  149. if ( player != NULL ) {
  150. if ( pdaIndex < player->GetInventory().pdas.Num() ) {
  151. const idDeclPDA * pda = player->GetInventory().pdas[ pdaIndex ];
  152. if ( pda != NULL && pdaInbox.GetEmailList() != NULL ) {
  153. idStr pdaFullName = pda->GetFullName();
  154. int emailIndex = pdaInbox.GetEmailList()->GetViewIndex();
  155. if ( emailIndex < pda->GetNumEmails() ) {
  156. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY1 );
  157. if ( menuData->GetPlatform() != 2 ) {
  158. buttonInfo->label = "#str_01102";
  159. }
  160. buttonInfo->action.Set( WIDGET_ACTION_PDA_SELECT_EMAIL );
  161. }
  162. }
  163. }
  164. }
  165. }
  166. }
  167. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_TAB );
  168. buttonInfo->label = "";
  169. buttonInfo->action.Set( WIDGET_ACTION_PDA_CLOSE );
  170. }
  171. }
  172. UpdateEmail();
  173. idMenuScreen::Update();
  174. }
  175. /*
  176. ========================
  177. idMenuScreen_PDA_UserEmails::HideScreen
  178. ========================
  179. */
  180. void idMenuScreen_PDA_UserEmails::HideScreen( const mainMenuTransition_t transitionType ) {
  181. if ( menuGUI != NULL ) {
  182. idSWFScriptObject & root = menuGUI->GetRootObject();
  183. idSWFSpriteInstance * pdaSprite = root.GetNestedSprite( "pda_persons" );
  184. if ( pdaSprite != NULL && menuData != NULL ) {
  185. if ( menuData->NextScreen() != PDA_AREA_USER_DATA ) {
  186. pdaSprite->SetVisible( true );
  187. pdaSprite->PlayFrame( "rollOff" );
  188. readingEmails = false;
  189. } else {
  190. if ( readingEmails ) {
  191. readingEmails = false;
  192. pdaSprite->SetVisible( true );
  193. pdaSprite->PlayFrame( "rollOn" );
  194. }
  195. }
  196. }
  197. }
  198. idMenuScreen::HideScreen( transitionType );
  199. }
  200. /*
  201. ========================
  202. idMenuScreen_PDA_UserEmails::UpdateEmail
  203. ========================
  204. */
  205. void idMenuScreen_PDA_UserEmails::UpdateEmail() {
  206. idMenuWidget_DynamicList * pdaList = dynamic_cast< idMenuWidget_DynamicList * >( menuData->GetChildFromIndex( PDA_WIDGET_PDA_LIST ) );
  207. if ( pdaList != NULL ) {
  208. int pdaIndex = pdaList->GetViewIndex();
  209. idPlayer * player = gameLocal.GetLocalPlayer();
  210. if ( player == NULL ) {
  211. return;
  212. }
  213. if ( pdaIndex > player->GetInventory().pdas.Num() ) {
  214. return;
  215. }
  216. const idDeclPDA * pda = player->GetInventory().pdas[ pdaIndex ];
  217. if ( pda != NULL && pdaInbox.GetEmailList() != NULL ) {
  218. idStr pdaFullName = pda->GetFullName();
  219. int emailIndex = pdaInbox.GetEmailList()->GetViewIndex();
  220. if ( emailIndex < pda->GetNumEmails() ) {
  221. const idDeclEmail * email = pda->GetEmailByIndex( emailIndex );
  222. if ( email != NULL ) {
  223. emailInfo.SetHeading( email->GetSubject() );
  224. emailInfo.SetBody( email->GetBody() );
  225. emailInfo.Update();
  226. }
  227. }
  228. }
  229. }
  230. }
  231. /*
  232. ========================
  233. idMenuScreen_PDA_UserEmails::HandleAction
  234. ========================
  235. */
  236. bool idMenuScreen_PDA_UserEmails::ScrollCorrectList( idWidgetAction & action, const idWidgetEvent & event, idMenuWidget * widget ) {
  237. bool handled = false;
  238. bool leftScroll = false;
  239. if ( event.type == WIDGET_EVENT_SCROLL_UP_LSTICK || event.type == WIDGET_EVENT_SCROLL_DOWN_LSTICK ||
  240. event.type == WIDGET_EVENT_SCROLL_UP || event.type == WIDGET_EVENT_SCROLL_DOWN ) {
  241. leftScroll = true;
  242. }
  243. if ( readingEmails ) {
  244. if ( leftScroll && !scrollEmailInfo ) {
  245. idMenuWidget_DynamicList * inbox = pdaInbox.GetEmailList();
  246. if ( inbox != NULL ){
  247. inbox->HandleAction( action, event, inbox );
  248. UpdateEmail();
  249. handled = true;
  250. }
  251. } else {
  252. emailInfo.HandleAction( action, event, &emailInfo );
  253. handled = true;
  254. }
  255. } else if ( !leftScroll ) {
  256. idMenuWidget_DynamicList * inbox = pdaInbox.GetEmailList();
  257. if ( inbox != NULL ){
  258. inbox->HandleAction( action, event, inbox );
  259. UpdateEmail();
  260. handled = true;
  261. }
  262. } else if ( menuData != NULL ) {
  263. idMenuWidget_DynamicList * pdaList = dynamic_cast< idMenuWidget_DynamicList * const >( menuData->GetChildFromIndex( PDA_WIDGET_PDA_LIST ) );
  264. if ( pdaList != NULL ) {
  265. pdaList->HandleAction( action, event, pdaList );
  266. handled = true;
  267. }
  268. }
  269. return handled;
  270. }
  271. /*
  272. ========================
  273. idMenuScreen_PDA_UserEmails::HandleAction
  274. ========================
  275. */
  276. void idMenuScreen_PDA_UserEmails::ShowEmail( bool show ) {
  277. idSWFSpriteInstance * pdaSprite = NULL;
  278. if ( menuGUI != NULL ) {
  279. idSWFScriptObject & root = menuGUI->GetRootObject();
  280. pdaSprite = root.GetNestedSprite( "pda_persons" );
  281. if ( show && !readingEmails ) {
  282. scrollEmailInfo = false;
  283. if ( pdaSprite != NULL ) {
  284. pdaSprite->SetVisible( true );
  285. pdaSprite->PlayFrame( "rollOff" );
  286. }
  287. if ( emailInfo.BindSprite( root ) && emailInfo.GetSprite() != NULL ) {
  288. emailInfo.GetSprite()->PlayFrame( "rollOn" );
  289. emailInfo.Update();
  290. }
  291. if ( pdaInbox.BindSprite( root ) && pdaInbox.GetSprite() != NULL ) {
  292. pdaInbox.GetSprite()->PlayFrame( "rollOff" );
  293. }
  294. } else if ( !show && readingEmails ) {
  295. if ( emailInfo.BindSprite( root ) && emailInfo.GetSprite() != NULL ) {
  296. emailInfo.GetSprite()->PlayFrame( "rollOff" );
  297. }
  298. if ( pdaInbox.BindSprite( root ) && pdaInbox.GetSprite() != NULL ) {
  299. pdaInbox.GetSprite()->PlayFrame( "rollOn" );
  300. }
  301. if ( pdaSprite != NULL ) {
  302. pdaSprite->SetVisible( true );
  303. pdaSprite->PlayFrame( "rollOn" );
  304. if ( menuData != NULL ) {
  305. idMenuWidget_DynamicList * pdaList = dynamic_cast< idMenuWidget_DynamicList * const >( menuData->GetChildFromIndex( PDA_WIDGET_PDA_LIST ) );
  306. if ( pdaList != NULL ) {
  307. pdaList->SetFocusIndex( pdaList->GetFocusIndex() );
  308. }
  309. }
  310. }
  311. }
  312. }
  313. readingEmails = show;
  314. Update();
  315. }
  316. /*
  317. ========================
  318. idMenuScreen_PDA_UserEmails::HandleAction
  319. ========================
  320. */
  321. bool idMenuScreen_PDA_UserEmails::HandleAction( idWidgetAction & action, const idWidgetEvent & event, idMenuWidget * widget, bool forceHandled ) {
  322. if ( menuData == NULL ) {
  323. return true;
  324. }
  325. if ( menuData->ActiveScreen() != PDA_AREA_USER_EMAIL ) {
  326. return false;
  327. }
  328. widgetAction_t actionType = action.GetType();
  329. const idSWFParmList & parms = action.GetParms();
  330. switch ( actionType ) {
  331. case WIDGET_ACTION_PDA_CLOSE: {
  332. menuData->SetNextScreen( PDA_AREA_INVALID, MENU_TRANSITION_ADVANCE );
  333. return true;
  334. }
  335. case WIDGET_ACTION_GO_BACK: {
  336. if ( readingEmails ) {
  337. ShowEmail( false );
  338. } else {
  339. menuData->SetNextScreen( PDA_AREA_INVALID, MENU_TRANSITION_ADVANCE );
  340. }
  341. return true;
  342. }
  343. case WIDGET_ACTION_REFRESH: {
  344. UpdateEmail();
  345. return true;
  346. }
  347. case WIDGET_ACTION_PDA_SELECT_EMAIL: {
  348. if ( widget->GetParent() != NULL ) {
  349. idMenuWidget_DynamicList * emailList = dynamic_cast< idMenuWidget_DynamicList * >( widget->GetParent() );
  350. int index = parms[0].ToInteger();
  351. if ( emailList != NULL ) {
  352. emailList->SetViewIndex( emailList->GetViewOffset() + index );
  353. emailList->SetFocusIndex( index );
  354. }
  355. }
  356. ShowEmail( true );
  357. return true;
  358. }
  359. case WIDGET_ACTION_EMAIL_HOVER: {
  360. scrollEmailInfo = parms[0].ToBool();
  361. return true;
  362. }
  363. case WIDGET_ACTION_SCROLL_VERTICAL: {
  364. if ( ScrollCorrectList( action, event, widget ) ) {
  365. return true;
  366. }
  367. UpdateEmail();
  368. break;
  369. }
  370. }
  371. return idMenuWidget::HandleAction( action, event, widget, forceHandled );
  372. }
  373. /*
  374. ========================
  375. idMenuScreen_PDA_UserEmails::ObserveEvent
  376. ========================
  377. */
  378. void idMenuScreen_PDA_UserEmails::ObserveEvent( const idMenuWidget & widget, const idWidgetEvent & event ) {
  379. if ( menuData != NULL && menuData->ActiveScreen() != PDA_AREA_USER_EMAIL ) {
  380. return;
  381. }
  382. const idMenuWidget_Button * const button = dynamic_cast< const idMenuWidget_Button * >( &widget );
  383. if ( button == NULL ) {
  384. return;
  385. }
  386. const idMenuWidget * const listWidget = button->GetParent();
  387. if ( listWidget == NULL ) {
  388. return;
  389. }
  390. switch ( event.type ) {
  391. case WIDGET_EVENT_FOCUS_ON: {
  392. Update();
  393. break;
  394. }
  395. }
  396. }