MenuScreen_PDA_Inventory.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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. static const int NUM_INVENTORY_ITEMS_VISIBLE = 9;
  24. /*
  25. ========================
  26. idMenuScreen_PDA_Inventory::Initialize
  27. ========================
  28. */
  29. void idMenuScreen_PDA_Inventory::Initialize( idMenuHandler * data ) {
  30. AddEventAction( WIDGET_EVENT_TAB_NEXT ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_TAB_NEXT, WIDGET_EVENT_TAB_NEXT ) );
  31. AddEventAction( WIDGET_EVENT_TAB_PREV ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_TAB_PREV, WIDGET_EVENT_TAB_PREV ) );
  32. if ( data != NULL ) {
  33. menuGUI = data->GetGUI();
  34. }
  35. SetSpritePath( "menuItems" );
  36. if ( menuGUI != NULL ) {
  37. idSWFScriptObject & root = menuGUI->GetRootObject();
  38. BindSprite( root );
  39. }
  40. infoBox.SetSpritePath( GetSpritePath(), "info", "details" );
  41. infoBox.Initialize( data );
  42. infoBox.SetNoAutoFree( true );
  43. itemList.SetSpritePath( GetSpritePath(), "info", "options" );
  44. itemList.SetNumVisibleOptions( NUM_INVENTORY_ITEMS_VISIBLE );
  45. itemList.SetNoAutoFree( true );
  46. while ( itemList.GetChildren().Num() < NUM_INVENTORY_ITEMS_VISIBLE ) {
  47. idMenuWidget_Button * const buttonWidget = new (TAG_SWF) idMenuWidget_Button();
  48. buttonWidget->Initialize( data );
  49. buttonWidget->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_SELECT_PDA_ITEM, itemList.GetChildren().Num() );
  50. itemList.AddChild( buttonWidget );
  51. }
  52. itemList.Initialize( data );
  53. AddChild( &itemList );
  54. AddChild( &infoBox );
  55. //AddChild( assignment );
  56. AddEventAction( WIDGET_EVENT_SCROLL_LEFT ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_SCROLL_LEFT_START_REPEATER, WIDGET_EVENT_SCROLL_LEFT ) );
  57. AddEventAction( WIDGET_EVENT_SCROLL_RIGHT ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_SCROLL_RIGHT_START_REPEATER, WIDGET_EVENT_SCROLL_RIGHT ) );
  58. AddEventAction( WIDGET_EVENT_SCROLL_LEFT_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_LEFT_RELEASE ) );
  59. AddEventAction( WIDGET_EVENT_SCROLL_RIGHT_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_RIGHT_RELEASE ) );
  60. AddEventAction( WIDGET_EVENT_SCROLL_LEFT_LSTICK ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_SCROLL_LEFT_START_REPEATER, WIDGET_EVENT_SCROLL_LEFT_LSTICK ) );
  61. AddEventAction( WIDGET_EVENT_SCROLL_RIGHT_LSTICK ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_SCROLL_RIGHT_START_REPEATER, WIDGET_EVENT_SCROLL_RIGHT_LSTICK ) );
  62. AddEventAction( WIDGET_EVENT_SCROLL_LEFT_LSTICK_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_LEFT_LSTICK_RELEASE ) );
  63. AddEventAction( WIDGET_EVENT_SCROLL_RIGHT_LSTICK_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_RIGHT_LSTICK_RELEASE ) );
  64. idMenuScreen::Initialize( data );
  65. }
  66. /*
  67. ========================
  68. idMenuScreen_PDA_Inventory::ShowScreen
  69. ========================
  70. */
  71. void idMenuScreen_PDA_Inventory::ShowScreen( const mainMenuTransition_t transitionType ) {
  72. idPlayer * player = gameLocal.GetLocalPlayer();
  73. if ( player != NULL ) {
  74. int numItems = player->GetInventory().items.Num();
  75. for ( int j = 0; j < numItems; j++ ) {
  76. idDict *item = player->GetInventory().items[j];
  77. if ( !item->GetBool( "inv_pda" ) ) {
  78. const char *iname = item->GetString( "inv_name" );
  79. const char *iicon = item->GetString( "inv_icon" );
  80. const char *itext = item->GetString( "inv_text" );
  81. iname = iname;
  82. iicon = iicon;
  83. itext = itext;
  84. const idKeyValue *kv = item->MatchPrefix( "inv_id", NULL );
  85. if ( kv ) {
  86. //objectiveSystem->SetStateString( va( "inv_id_%i", j ), kv->GetValue() );
  87. }
  88. }
  89. }
  90. idList<const idMaterial *> weaponIcons;
  91. for ( int j = 0; j < MAX_WEAPONS; j++ ) {
  92. const char * weap = GetWeaponName( j );
  93. if ( weap == NULL || *weap == NULL ){
  94. continue;
  95. }
  96. if ( !IsVisibleWeapon( j ) ) {
  97. continue;
  98. }
  99. const idDeclEntityDef * weaponDef = gameLocal.FindEntityDef( weap, false );
  100. if ( weaponDef != NULL ) {
  101. weaponIcons.Append( declManager->FindMaterial( weaponDef->dict.GetString( "hudIcon" ), false ) );
  102. }
  103. }
  104. itemList.SetListImages( weaponIcons );
  105. itemList.SetViewIndex( 0 );
  106. itemList.SetMoveToIndex( 0 );
  107. itemList.SetMoveDiff( 0 );
  108. }
  109. idMenuScreen::ShowScreen( transitionType );
  110. }
  111. /*
  112. ========================
  113. idMenuScreen_PDA_Inventory::HideScreen
  114. ========================
  115. */
  116. void idMenuScreen_PDA_Inventory::HideScreen( const mainMenuTransition_t transitionType ) {
  117. idMenuScreen::HideScreen( transitionType );
  118. }
  119. /*
  120. ========================
  121. idMenuScreen_PDA_Inventory::GetWeaponName
  122. ========================
  123. */
  124. const char * idMenuScreen_PDA_Inventory::GetWeaponName( int index ) {
  125. idPlayer * player = gameLocal.GetLocalPlayer();
  126. if ( player == NULL ) {
  127. return NULL;
  128. }
  129. const char * weaponDefName = va( "def_weapon%d", index );
  130. if ( player->GetInventory().weapons & ( 1 << index ) ) {
  131. return player->spawnArgs.GetString( weaponDefName );
  132. }
  133. return NULL;
  134. }
  135. /*
  136. ========================
  137. idMenuScreen_PDA_Inventory::GetWeaponName
  138. ========================
  139. */
  140. bool idMenuScreen_PDA_Inventory::IsVisibleWeapon( int index ) {
  141. idPlayer * player = gameLocal.GetLocalPlayer();
  142. if ( player == NULL ) {
  143. return false;
  144. }
  145. if ( player->GetInventory().weapons & ( 1 << index ) ) {
  146. return player->spawnArgs.GetBool( va( "weapon%d_visible", index ) );
  147. }
  148. return false;
  149. }
  150. /*
  151. ========================
  152. idMenuScreen_PDA_Inventory::Update
  153. ========================
  154. */
  155. void idMenuScreen_PDA_Inventory::Update() {
  156. idPlayer * player = gameLocal.GetLocalPlayer();
  157. if ( player == NULL ) {
  158. idMenuScreen::Update();
  159. return;
  160. }
  161. int validIndex = 0;
  162. for ( int j = 0; j < MAX_WEAPONS; j++ ) {
  163. const char * weap = GetWeaponName( j );
  164. if ( weap == NULL || *weap == NULL ){
  165. continue;
  166. }
  167. if ( !IsVisibleWeapon( j ) ) {
  168. return;
  169. }
  170. const idDeclEntityDef * weaponDef = gameLocal.FindEntityDef( weap, false );
  171. if ( weaponDef == NULL ) {
  172. continue;
  173. }
  174. if ( validIndex == itemList.GetMoveToIndex() ) {
  175. idStr itemName = weaponDef->dict.GetString( "display_name" );
  176. idStr itemDesc = weaponDef->dict.GetString( "inv_desc" );
  177. infoBox.SetHeading( idLocalization::GetString( itemName.c_str() ) );
  178. infoBox.SetBody( idLocalization::GetString( itemDesc.c_str() ) );
  179. break;
  180. }
  181. validIndex++;
  182. }
  183. if ( GetSprite() != NULL ) {
  184. idSWFSpriteInstance * dpad = GetSprite()->GetScriptObject()->GetNestedSprite( "info", "dpad" );
  185. if ( dpad != NULL ) {
  186. dpad->SetVisible( false );
  187. }
  188. }
  189. if ( menuData != NULL ) {
  190. idMenuWidget_CommandBar * cmdBar = dynamic_cast< idMenuWidget_CommandBar * const >( menuData->GetChildFromIndex( PDA_WIDGET_CMD_BAR ) );
  191. if ( cmdBar != NULL ) {
  192. cmdBar->ClearAllButtons();
  193. idMenuWidget_CommandBar::buttonInfo_t * buttonInfo;
  194. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY2 );
  195. if ( menuData->GetPlatform() != 2 ) {
  196. buttonInfo->label = "#str_01345";
  197. }
  198. buttonInfo->action.Set( WIDGET_ACTION_GO_BACK );
  199. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY3 );
  200. buttonInfo->label = "#str_SWF_EQUIP";
  201. buttonInfo->action.Set( WIDGET_ACTION_JOY3_ON_PRESS );
  202. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_TAB );
  203. buttonInfo->label = "";
  204. buttonInfo->action.Set( WIDGET_ACTION_GO_BACK );
  205. }
  206. }
  207. idMenuScreen::Update();
  208. }
  209. /*
  210. ========================
  211. idMenuScreen_PDA_Inventory::EquipWeapon
  212. ========================
  213. */
  214. void idMenuScreen_PDA_Inventory::EquipWeapon() {
  215. if ( itemList.GetViewIndex() != itemList.GetMoveToIndex() ) {
  216. return;
  217. }
  218. idPlayer * player = gameLocal.GetLocalPlayer();
  219. if ( player == NULL ) {
  220. return;
  221. }
  222. int validIndex = 0;
  223. for ( int j = 0; j < MAX_WEAPONS; j++ ) {
  224. const char * weap = GetWeaponName( j );
  225. if ( weap == NULL || *weap == NULL ){
  226. continue;
  227. }
  228. if ( !IsVisibleWeapon( j ) ) {
  229. continue;
  230. }
  231. if ( validIndex == itemList.GetMoveToIndex() ) {
  232. int slot = player->SlotForWeapon( weap );
  233. player->SetPreviousWeapon( slot );
  234. break;
  235. }
  236. validIndex++;
  237. }
  238. player->TogglePDA();
  239. }
  240. /*
  241. ========================
  242. idMenuScreen_PDA_Inventory::HandleAction
  243. ========================
  244. */
  245. bool idMenuScreen_PDA_Inventory::HandleAction( idWidgetAction & action, const idWidgetEvent & event, idMenuWidget * widget, bool forceHandled ) {
  246. if ( menuData == NULL ) {
  247. return true;
  248. }
  249. if ( menuData->ActiveScreen() != PDA_AREA_INVENTORY ) {
  250. return false;
  251. }
  252. widgetAction_t actionType = action.GetType();
  253. const idSWFParmList & parms = action.GetParms();
  254. switch ( actionType ) {
  255. case WIDGET_ACTION_JOY3_ON_PRESS: {
  256. EquipWeapon();
  257. return true;
  258. }
  259. case WIDGET_ACTION_GO_BACK: {
  260. menuData->SetNextScreen( PDA_AREA_INVALID, MENU_TRANSITION_ADVANCE );
  261. return true;
  262. }
  263. case WIDGET_ACTION_START_REPEATER: {
  264. idWidgetAction repeatAction;
  265. widgetAction_t repeatActionType = static_cast< widgetAction_t >( parms[ 0 ].ToInteger() );
  266. assert( parms.Num() == 2 );
  267. repeatAction.Set( repeatActionType, parms[ 1 ] );
  268. menuData->StartWidgetActionRepeater( widget, repeatAction, event );
  269. return true;
  270. }
  271. case WIDGET_ACTION_SELECT_PDA_ITEM: {
  272. if ( itemList.GetMoveDiff() > 0 ) {
  273. itemList.MoveToIndex( itemList.GetMoveToIndex(), true );
  274. }
  275. int index = parms[0].ToInteger();
  276. if ( index != 0 ) {
  277. itemList.MoveToIndex( index );
  278. Update();
  279. }
  280. return true;
  281. }
  282. case WIDGET_ACTION_STOP_REPEATER: {
  283. menuData->ClearWidgetActionRepeater();
  284. return true;
  285. }
  286. case WIDGET_ACTION_SCROLL_HORIZONTAL: {
  287. if ( itemList.GetTotalNumberOfOptions() <= 1 ) {
  288. return true;
  289. }
  290. if ( itemList.GetMoveDiff() > 0 ) {
  291. itemList.MoveToIndex( itemList.GetMoveToIndex(), true );
  292. }
  293. int direction = parms[0].ToInteger();
  294. if ( direction == 1 ) {
  295. if ( itemList.GetViewIndex() == itemList.GetTotalNumberOfOptions() - 1 ) {
  296. return true;
  297. } else {
  298. itemList.MoveToIndex( 1 );
  299. }
  300. } else {
  301. if ( itemList.GetViewIndex() == 0 ) {
  302. return true;
  303. } else {
  304. itemList.MoveToIndex( ( itemList.GetNumVisibleOptions() / 2 ) + 1 );
  305. }
  306. }
  307. Update();
  308. return true;
  309. }
  310. }
  311. return idMenuWidget::HandleAction( action, event, widget, forceHandled );
  312. }