radialquickbarmenu.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846
  1. enum RadialQuickbarCategory
  2. {
  3. DEFAULT,
  4. SPECIALIZED_LIGHTS
  5. }
  6. class RadialQuickbarItem
  7. {
  8. protected bool m_IsLightSourceExtra;
  9. protected bool m_IsNVG;
  10. protected int m_Id;
  11. protected int m_Category;
  12. protected int m_CategorySwitchID;
  13. protected EntityAI m_Item;
  14. protected string m_ItemName;
  15. //radial menu
  16. protected Widget m_RadialMenuSelector;
  17. protected Widget m_RadialMenuItemCard;
  18. void RadialQuickbarItem( int id, EntityAI item, string item_name, int category = RadialQuickbarCategory.DEFAULT, int category_switch = -1 )
  19. {
  20. m_Id = id;
  21. m_Item = item;
  22. m_ItemName = item_name;
  23. m_Category = category;
  24. m_CategorySwitchID = category_switch;
  25. //
  26. if (ItemBase.Cast(m_Item))
  27. {
  28. m_IsNVG = ItemBase.Cast(m_Item).IsNVG();
  29. m_IsLightSourceExtra = ItemBase.Cast(m_Item).IsLightSource();
  30. }
  31. }
  32. EntityAI GetItem()
  33. {
  34. return m_Item;
  35. }
  36. void SetItem( EntityAI item )
  37. {
  38. m_Item = item;
  39. }
  40. bool IsLightSourceExtra()
  41. {
  42. return m_IsLightSourceExtra;
  43. }
  44. bool IsNVGExtra()
  45. {
  46. return m_IsNVG;
  47. }
  48. int GetId()
  49. {
  50. return m_Id;
  51. }
  52. int GetItemCategory()
  53. {
  54. return m_Category;
  55. }
  56. int GetCategorySwitchID()
  57. {
  58. return m_CategorySwitchID;
  59. }
  60. Widget GetRadialItemCard()
  61. {
  62. return m_RadialMenuItemCard;
  63. }
  64. void SetRadialItemCard( Widget widget )
  65. {
  66. m_RadialMenuItemCard = widget;
  67. }
  68. string GetItemName()
  69. {
  70. return m_ItemName;
  71. }
  72. }
  73. class RadialQuickbarMenu extends UIScriptedMenu
  74. {
  75. protected Widget m_ItemCardPanel;
  76. protected ref array<ref RadialQuickbarItem> m_Items;
  77. protected Widget m_ToolbarPanel;
  78. protected bool m_IsMenuClosing;
  79. protected int m_CurrentCategory;
  80. //
  81. const string TEXT_ITEM_NAME = "ItemName";
  82. const string TEXT_ITEM_TITLE = "ItemTitle";
  83. //selections
  84. protected Widget m_SelectedItem;
  85. static EntityAI m_ItemToAssign;
  86. //instance
  87. static RadialQuickbarMenu instance;
  88. //============================================
  89. // RadialQuickbarMenu
  90. //============================================
  91. void RadialQuickbarMenu()
  92. {
  93. m_Items = new ref array<ref RadialQuickbarItem>;
  94. m_CurrentCategory = RadialQuickbarCategory.DEFAULT;
  95. if ( !instance )
  96. {
  97. instance = this;
  98. }
  99. GetGame().GetMission().GetOnInputPresetChanged().Insert(OnInputPresetChanged);
  100. }
  101. void ~RadialQuickbarMenu()
  102. {
  103. if (GetGame() && GetGame().GetMission())
  104. {
  105. GetGame().GetMission().RemoveActiveInputExcludes({"radialmenu"},false);
  106. }
  107. }
  108. static void SetItemToAssign( EntityAI item )
  109. {
  110. m_ItemToAssign = item;
  111. }
  112. static EntityAI GetItemToAssign()
  113. {
  114. return m_ItemToAssign;
  115. }
  116. static RadialQuickbarMenu GetMenuInstance()
  117. {
  118. return instance;
  119. }
  120. protected void OnInputPresetChanged()
  121. {
  122. #ifdef PLATFORM_CONSOLE
  123. UpdateControlsElements();
  124. #endif
  125. }
  126. //============================================
  127. // Menu Controls
  128. //============================================
  129. static void OpenMenu( UIScriptedMenu parent = NULL )
  130. {
  131. GetGame().GetUIManager().EnterScriptedMenu( MENU_RADIAL_QUICKBAR, parent );
  132. }
  133. static void CloseMenu()
  134. {
  135. GetGame().GetUIManager().Back();
  136. //GetGame().GetMission().RemoveActiveInputExcludes({"radialmenu"},false);
  137. }
  138. //============================================
  139. // Init & Widget Events
  140. //============================================
  141. override Widget Init()
  142. {
  143. layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/radial_menu/radial_quickbar/radial_quickbar_menu.layout");
  144. m_ItemCardPanel = layoutRoot.FindAnyWidget(RadialMenu.RADIAL_ITEM_CARD_CONTAINER);
  145. //register gestures menu
  146. RadialMenu.GetInstance().RegisterClass(this);
  147. //delay updates until fully initialized
  148. RadialMenu.GetInstance().SetWidgetInitialized(false);
  149. //set radial menu properties
  150. RadialMenu.GetInstance().SetWidgetProperties("gui/layouts/radial_menu/radial_quickbar/radial_quickbar_delimiter.layout");
  151. //create content (widgets) for items
  152. RefreshQuickbar();
  153. //set controller toolbar icons
  154. UpdateControlsElements();
  155. m_ToolbarPanel = layoutRoot.FindAnyWidget( "toolbar_bg" );
  156. m_ToolbarPanel.Show( true );
  157. return layoutRoot;
  158. }
  159. override void OnShow()
  160. {
  161. super.OnShow();
  162. Mission mission = GetGame().GetMission();
  163. if (mission)
  164. {
  165. IngameHud hud = IngameHud.Cast(mission.GetHud());
  166. if (hud)
  167. {
  168. hud.ShowQuickbarUI(false);
  169. }
  170. }
  171. SetFocus(layoutRoot);
  172. m_IsMenuClosing = false;
  173. }
  174. override void OnHide()
  175. {
  176. super.OnHide();
  177. Mission mission = GetGame().GetMission();
  178. if (mission)
  179. {
  180. IngameHud hud = IngameHud.Cast(mission.GetHud());
  181. if (hud)
  182. {
  183. hud.ShowQuickbarUI(true);
  184. }
  185. }
  186. //reset item to assign
  187. RadialQuickbarMenu.SetItemToAssign(NULL);
  188. m_IsMenuClosing = true;
  189. }
  190. override bool OnController( Widget w, int control, int value )
  191. {
  192. super.OnController( w, control, value );
  193. RadialMenu.GetInstance().SetControlType( RadialMenuControlType.CONTROLLER );
  194. return false;
  195. }
  196. override bool OnMouseEnter( Widget w, int x, int y )
  197. {
  198. super.OnMouseEnter( w, x, y );
  199. RadialMenu.GetInstance().SetControlType( RadialMenuControlType.MOUSE );
  200. return false;
  201. }
  202. override bool UseMouse()
  203. {
  204. return true;
  205. }
  206. override bool UseGamepad()
  207. {
  208. return true;
  209. }
  210. //============================================
  211. // Content
  212. //============================================
  213. //reset_selection - if false, selected quick bar item will be remembered after content refresh
  214. protected void RefreshQuickbar( bool reset_selection = true )
  215. {
  216. int selected_item_id = -1;
  217. if ( !reset_selection )
  218. {
  219. RadialQuickbarItem quickbar_item;
  220. if ( instance.m_SelectedItem )
  221. {
  222. instance.m_SelectedItem.GetUserData( quickbar_item );
  223. selected_item_id = quickbar_item.GetId();
  224. }
  225. }
  226. GetItems( m_Items );
  227. //CheckForLightsAndNVG( m_Items );
  228. CreateContent( selected_item_id );
  229. }
  230. //
  231. // ITEMS
  232. //
  233. protected void GetItems( out ref array<ref RadialQuickbarItem> items )
  234. {
  235. items.Clear();
  236. PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
  237. int size = player.GetQuickBarSize();
  238. EntityAI entity;
  239. for ( int i = 0; i < size; ++i )
  240. {
  241. entity = player.GetQuickBarEntity( i );
  242. items.Insert( new RadialQuickbarItem( i, entity, "" ) );
  243. }
  244. CheckForLightsAndNVG(m_Items,i);
  245. }
  246. protected void CheckForLightsAndNVG( out ref array<ref RadialQuickbarItem> items, int last_idx )
  247. {
  248. PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
  249. int count = 0;
  250. EntityAI entity;
  251. ItemBase headgear = ItemBase.Cast(player.FindAttachmentBySlotName("Headgear"));
  252. ItemBase eyewear = ItemBase.Cast(player.FindAttachmentBySlotName("Eyewear"));
  253. //nvg - headgear check
  254. if ( headgear )
  255. {
  256. entity = headgear.FindAttachmentBySlotName("NVG");
  257. if (entity)
  258. {
  259. items.Insert( new RadialQuickbarItem( count, entity, "", RadialQuickbarCategory.SPECIALIZED_LIGHTS ) );
  260. count++;
  261. }
  262. }
  263. //nvg/light - eyewear check
  264. if ( eyewear )
  265. {
  266. entity = eyewear.FindAttachmentBySlotName("NVG");
  267. if (entity)
  268. {
  269. items.Insert( new RadialQuickbarItem( count, entity, "", RadialQuickbarCategory.SPECIALIZED_LIGHTS ) );
  270. count++;
  271. }
  272. else if ( eyewear.IsLightSource() && eyewear.HasEnergyManager() && eyewear.GetCompEM().CanWork() )
  273. {
  274. entity = eyewear;
  275. items.Insert( new RadialQuickbarItem( count, entity, "", RadialQuickbarCategory.SPECIALIZED_LIGHTS ) );
  276. count++;
  277. }
  278. }
  279. //light
  280. if ( headgear )
  281. {
  282. if ( headgear.GetInventory().AttachmentCount() > 0 )
  283. {
  284. ItemBase attachment;
  285. for (int i = 0; i < headgear.GetInventory().AttachmentCount(); i++)
  286. {
  287. attachment = ItemBase.Cast(headgear.GetInventory().GetAttachmentFromIndex(i));
  288. if ( attachment && attachment.IsLightSource() && attachment.HasEnergyManager() && attachment.GetCompEM().CanWork() )
  289. {
  290. entity = attachment;
  291. items.Insert( new RadialQuickbarItem( count, entity, "", RadialQuickbarCategory.SPECIALIZED_LIGHTS ) );
  292. count++;
  293. }
  294. }
  295. }
  296. }
  297. //Add a category switchers
  298. if (m_CurrentCategory == RadialQuickbarCategory.DEFAULT && count > 0)
  299. {
  300. items.InsertAt( new RadialQuickbarItem(32,null,"#toggle_lights",RadialQuickbarCategory.DEFAULT,RadialQuickbarCategory.SPECIALIZED_LIGHTS),0 );
  301. }
  302. else if (m_CurrentCategory == RadialQuickbarCategory.SPECIALIZED_LIGHTS)
  303. {
  304. items.InsertAt( new RadialQuickbarItem(32,null,"#menu_back",RadialQuickbarCategory.SPECIALIZED_LIGHTS,RadialQuickbarCategory.DEFAULT),0 );
  305. }
  306. }
  307. protected void CreateContent( int selected_item_id = -1 )
  308. {
  309. //delete existing content
  310. DeleteItems();
  311. int category_item_count;
  312. for ( int i = 0; i < m_Items.Count(); ++i )
  313. {
  314. RadialQuickbarItem quickbar_item = m_Items.Get( i );
  315. if (quickbar_item.GetItemCategory() == m_CurrentCategory)
  316. {
  317. //create item card
  318. Widget item_card_widget = Widget.Cast( GetGame().GetWorkspace().CreateWidgets( "gui/layouts/radial_menu/radial_quickbar/radial_quickbar_item_card.layout", m_ItemCardPanel ) );
  319. quickbar_item.SetRadialItemCard( item_card_widget );
  320. //update item card widget
  321. UpdateQuickbarItemCard( quickbar_item );
  322. //set data
  323. item_card_widget.SetUserData( quickbar_item );
  324. //set selection
  325. if ( quickbar_item.GetId() == selected_item_id )
  326. {
  327. MarkSelected( quickbar_item.GetRadialItemCard() );
  328. }
  329. category_item_count++;
  330. }
  331. }
  332. //adjust radial parameters for content
  333. if ( /*m_Items.Count()*/category_item_count > 0 )
  334. {
  335. RadialMenu radial_menu = RadialMenu.GetInstance();
  336. radial_menu.SetRadiusOffset( 0 );
  337. radial_menu.SetExecuteDistOffset( 0.5 );
  338. radial_menu.SetOffsetFromTop( 0 );
  339. radial_menu.SetItemCardRadiusOffset( 0.25 );
  340. radial_menu.ActivateControllerTimeout( false );
  341. }
  342. //refresh radial menu
  343. RadialMenu.GetInstance().Refresh( false );
  344. }
  345. protected void UpdateQuickbarItemCard( RadialQuickbarItem quickbar_item )
  346. {
  347. Widget item_card_widget = quickbar_item.GetRadialItemCard();
  348. //get content panels
  349. Widget item_details = item_card_widget.FindAnyWidget( "ItemDetails" );
  350. TextWidget item_title = TextWidget.Cast( item_card_widget.FindAnyWidget( "ItemTitle" ) );
  351. //set text
  352. TextWidget text_widget = TextWidget.Cast( item_card_widget.FindAnyWidget( TEXT_ITEM_NAME ) );
  353. EntityAI item = quickbar_item.GetItem();
  354. Widget quantity_panel = item_card_widget.FindAnyWidget( "QuantityPanel" );
  355. if ( item )
  356. {
  357. //item text
  358. text_widget.SetText( quickbar_item.GetItem().GetDisplayName() );
  359. //item preview
  360. ItemPreviewWidget item_preview = ItemPreviewWidget.Cast( item_card_widget.FindAnyWidget( "ItemPreview" ) );
  361. item_preview.SetItem( item );
  362. item_preview.SetView( item.GetViewIndex() );
  363. item_preview.SetModelOrientation( Vector( 0,0,0 ) );
  364. //item quantity
  365. Widget quantity_stack = quantity_panel.FindAnyWidget( "QuantityStackPanel" );
  366. ProgressBarWidget quantity_bar = ProgressBarWidget.Cast( quantity_panel.FindAnyWidget( "QuantityBar" ) );
  367. int has_quantity = QuantityConversions.HasItemQuantity( item );
  368. //calculate and set quantity
  369. if ( has_quantity == QUANTITY_HIDDEN )
  370. {
  371. quantity_panel.Show( false );
  372. }
  373. else if ( has_quantity == QUANTITY_COUNT )
  374. {
  375. //hide bar
  376. quantity_bar.Show( false );
  377. //show stack
  378. TextWidget quantity_text = TextWidget.Cast( quantity_stack.FindAnyWidget( "Quantity" ) );
  379. quantity_text.SetText( QuantityConversions.GetItemQuantityText( item ) );
  380. quantity_stack.Show( true );
  381. }
  382. else if ( has_quantity == QUANTITY_PROGRESS )
  383. {
  384. //hide stack
  385. quantity_stack.Show( false );
  386. //show bar
  387. float progress_max = quantity_bar.GetMax();
  388. int max = item.ConfigGetInt( "varQuantityMax" );
  389. int count = item.ConfigGetInt( "count" );
  390. float quantity = QuantityConversions.GetItemQuantity( ItemBase.Cast( item ) );
  391. if ( count > 0 )
  392. {
  393. max = count;
  394. }
  395. if ( max > 0 )
  396. {
  397. float value = Math.Round( ( quantity / max ) * 100 );
  398. quantity_bar.SetCurrent( value );
  399. }
  400. quantity_bar.Show( true );
  401. }
  402. //display content panels
  403. item_details.Show( true );
  404. item_title.Show( false );
  405. }
  406. else if ( quickbar_item.GetCategorySwitchID() != -1 )
  407. {
  408. item_title.SetText( quickbar_item.GetItemName() );
  409. item_details.Show( false );
  410. item_title.Show( true );
  411. }
  412. else
  413. {
  414. item_title.SetText( "#container_empty" );
  415. //display content panels
  416. item_details.Show( false );
  417. item_title.Show( true );
  418. }
  419. }
  420. //Common
  421. protected void DeleteItems()
  422. {
  423. Widget child;
  424. Widget child_to_destroy;
  425. child = m_ItemCardPanel.GetChildren();
  426. while ( child )
  427. {
  428. child_to_destroy = child;
  429. child = child.GetSibling();
  430. delete child_to_destroy;
  431. }
  432. }
  433. protected void ChangeCurrentCategory(int category)
  434. {
  435. m_CurrentCategory = category;
  436. RefreshQuickbar(false);
  437. UpdateControlsElements();
  438. }
  439. //============================================
  440. // Radial Menu Events
  441. //============================================
  442. //Common
  443. void OnControlsChanged( RadialMenuControlType type )
  444. {
  445. }
  446. //Mouse
  447. void OnMouseSelect( Widget w )
  448. {
  449. MarkSelected( w );
  450. }
  451. void OnMouseDeselect( Widget w )
  452. {
  453. UnmarkSelected( w );
  454. }
  455. void OnMouseExecute( Widget w )
  456. {
  457. }
  458. //! LMB
  459. void OnMousePressLeft( Widget w )
  460. {
  461. PrimaryAction( w );
  462. }
  463. //! RMB
  464. void OnMousePressRight( Widget w )
  465. {
  466. BackOneLevel();
  467. }
  468. //Controller
  469. void OnControllerSelect( Widget w )
  470. {
  471. MarkSelected( w );
  472. }
  473. void OnControllerDeselect( Widget w )
  474. {
  475. UnmarkSelected( w );
  476. }
  477. void OnControllerPressSelect( Widget w )
  478. {
  479. PrimaryAction( w );
  480. }
  481. void OnControllerPressBack( Widget w )
  482. {
  483. //SecondaryAction( w );
  484. BackOneLevel();
  485. }
  486. //Actions
  487. protected void MarkSelected( Widget w )
  488. {
  489. m_SelectedItem = w;
  490. if (w)
  491. {
  492. RadialQuickbarItem quickbar_item;
  493. w.GetUserData( quickbar_item );
  494. ItemBase item;
  495. if (quickbar_item && Class.CastTo(item,quickbar_item.GetItem()))
  496. {
  497. w.SetFlags(WidgetFlags.DISABLED);
  498. }
  499. else
  500. {
  501. w.ClearFlags(WidgetFlags.DISABLED);
  502. }
  503. /*
  504. //is not category
  505. if ( quickbar_item )
  506. {
  507. if ( quickbar_item.GetItem() )
  508. {
  509. //alter item visual
  510. TextWidget text_widget = TextWidget.Cast( quickbar_item.GetRadialItemCard().FindAnyWidget( TEXT_ITEM_NAME ) );
  511. text_widget.SetColor( ARGB( 255, 66, 175, 95 ) );
  512. }
  513. else
  514. {
  515. //alter item visual
  516. TextWidget title_widget = TextWidget.Cast( quickbar_item.GetRadialItemCard().FindAnyWidget( TEXT_ITEM_TITLE ) );
  517. title_widget.SetColor( ARGB( 255, 66, 175, 95 ) );
  518. }
  519. }
  520. */
  521. }
  522. }
  523. protected void UnmarkSelected( Widget w )
  524. {
  525. m_SelectedItem = NULL;
  526. /*
  527. if ( w )
  528. {
  529. RadialQuickbarItem quickbar_item;
  530. w.GetUserData( quickbar_item );
  531. //is not category
  532. if ( quickbar_item )
  533. {
  534. if ( quickbar_item.GetItem() )
  535. {
  536. //alter item visual
  537. TextWidget text_widget = TextWidget.Cast( quickbar_item.GetRadialItemCard().FindAnyWidget( TEXT_ITEM_NAME ) );
  538. text_widget.SetColor( ARGB( 255, 255, 255, 255 ) );
  539. }
  540. else
  541. {
  542. //alter item visual
  543. TextWidget title_widget = TextWidget.Cast( quickbar_item.GetRadialItemCard().FindAnyWidget( TEXT_ITEM_TITLE ) );
  544. title_widget.SetColor( ARGB( 255, 255, 255, 255 ) );
  545. }
  546. }
  547. }
  548. */
  549. }
  550. protected void PrimaryAction( Widget w )
  551. {
  552. if ( instance.m_SelectedItem )
  553. {
  554. if ( !GetGame().IsDedicatedServer() )
  555. {
  556. RadialQuickbarItem quickbar_item;
  557. instance.m_SelectedItem.GetUserData( quickbar_item );
  558. if ( quickbar_item )
  559. {
  560. PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
  561. //ASSIGN ACTION
  562. if ( GetItemToAssign() )
  563. {
  564. //assign item to slot
  565. if ( quickbar_item.GetItem() == GetItemToAssign() )
  566. {
  567. player.RemoveQuickBarEntityShortcut( GetItemToAssign() );
  568. }
  569. else
  570. {
  571. player.SetQuickBarEntityShortcut( GetItemToAssign(), quickbar_item.GetId() );
  572. }
  573. }
  574. //LIGHTS
  575. else if (m_CurrentCategory == RadialQuickbarCategory.SPECIALIZED_LIGHTS && quickbar_item.IsLightSourceExtra())
  576. {
  577. HandleLights(quickbar_item);
  578. }
  579. //NVG
  580. else if (m_CurrentCategory == RadialQuickbarCategory.SPECIALIZED_LIGHTS && quickbar_item.IsNVGExtra())
  581. {
  582. HandleNVG(quickbar_item);
  583. }
  584. //change quickbar category
  585. else if (quickbar_item.GetCategorySwitchID() != -1)
  586. {
  587. ChangeCurrentCategory(quickbar_item.GetCategorySwitchID());
  588. return;
  589. }
  590. //SWAP
  591. else
  592. {
  593. EntityAI item = quickbar_item.GetItem();
  594. if ( item )
  595. {
  596. //swap
  597. player.RadialQuickBarSingleUse( quickbar_item.GetId() + 1 ); //id must begin with 1 (simulating key press 1-9)
  598. }
  599. }
  600. RefreshQuickbar( false );
  601. }
  602. }
  603. }
  604. }
  605. protected void SecondaryAction( Widget w )
  606. {
  607. if ( instance.m_SelectedItem && m_CurrentCategory == RadialQuickbarCategory.DEFAULT )
  608. {
  609. if ( !GetGame().IsDedicatedServer() )
  610. {
  611. RadialQuickbarItem quickbar_item;
  612. instance.m_SelectedItem.GetUserData( quickbar_item );
  613. if ( quickbar_item )
  614. {
  615. PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
  616. EntityAI item = quickbar_item.GetItem();
  617. if ( item )
  618. {
  619. player.RadialQuickBarCombine( quickbar_item.GetId() + 1 ); //id must begin with 1 (simulating key press 1-9)
  620. RefreshQuickbar( false );
  621. }
  622. }
  623. }
  624. }
  625. }
  626. // returns to default, missing hierarchy to properly traverse ATM
  627. protected void BackOneLevel()
  628. {
  629. if (m_CurrentCategory != RadialQuickbarCategory.DEFAULT)
  630. {
  631. ChangeCurrentCategory(RadialQuickbarCategory.DEFAULT);
  632. }
  633. }
  634. //-------------------------------------------
  635. //NVG/Light handling extension
  636. //-------------------------------------------
  637. void HandleLights(RadialQuickbarItem quickbar_item)
  638. {
  639. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  640. ItemBase item = ItemBase.Cast(quickbar_item.GetItem());
  641. ActionManagerClient mngr_client = ActionManagerClient.Cast(player.GetActionManager());
  642. ActionTarget atrg;
  643. if ( Headtorch_ColorBase.Cast(item) )
  644. {
  645. atrg = new ActionTarget(item,null,-1,vector.Zero,-1.0);
  646. if ( mngr_client.GetAction(ActionTurnOnHeadtorch).Can(player,atrg,null) )
  647. {
  648. mngr_client.PerformActionStart(player.GetActionManager().GetAction(ActionTurnOnHeadtorch),atrg,null);
  649. }
  650. else if ( mngr_client.GetAction(ActionTurnOffHeadtorch).Can(player,atrg,null) )
  651. {
  652. mngr_client.PerformActionStart(player.GetActionManager().GetAction(ActionTurnOffHeadtorch),atrg,null);
  653. }
  654. }
  655. else if ( Mich2001Helmet.Cast(item.GetHierarchyParent()) )
  656. {
  657. atrg = new ActionTarget(item.GetHierarchyParent(),null,-1,vector.Zero,-1.0);
  658. if ( mngr_client.GetAction(ActionTurnOnHelmetFlashlight).Can(player,atrg,null) )
  659. {
  660. mngr_client.PerformActionStart(player.GetActionManager().GetAction(ActionTurnOnHelmetFlashlight),atrg,null);
  661. }
  662. else if ( mngr_client.GetAction(ActionTurnOffHelmetFlashlight).Can(player,atrg,null) )
  663. {
  664. mngr_client.PerformActionStart(player.GetActionManager().GetAction(ActionTurnOffHelmetFlashlight),atrg,null);
  665. }
  666. }
  667. }
  668. void HandleNVG(RadialQuickbarItem quickbar_item)
  669. {
  670. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  671. ActionManagerClient mngr_client = ActionManagerClient.Cast(player.GetActionManager());
  672. ActionTarget atrg;
  673. atrg = new ActionTarget(quickbar_item.GetItem().GetHierarchyParent(),null,-1,vector.Zero,-1.0);
  674. if ( mngr_client.GetAction(ActionToggleNVG).Can(player,atrg,null) )
  675. {
  676. mngr_client.PerformActionStart(player.GetActionManager().GetAction(ActionToggleNVG),atrg,null);
  677. }
  678. }
  679. bool IsMenuClosing()
  680. {
  681. return m_IsMenuClosing;
  682. }
  683. void SetMenuClosing(bool state)
  684. {
  685. m_IsMenuClosing = state;
  686. }
  687. protected void UpdateControlsElements()
  688. {
  689. Widget toolbarBackSpacer = layoutRoot.FindAnyWidget("BackSpacer");
  690. RichTextWidget toolbarSelectIcon = RichTextWidget.Cast(layoutRoot.FindAnyWidget("SelectIcon"));
  691. RichTextWidget toolbarBackIcon = RichTextWidget.Cast(layoutRoot.FindAnyWidget("BackIcon"));
  692. string selectAction;
  693. string backAction;
  694. int controllerID;
  695. if (GetGame().GetInput().IsEnabledMouseAndKeyboardEvenOnServer() && GetGame().GetInput().GetCurrentInputDevice() == EInputDeviceType.MOUSE_AND_KEYBOARD)
  696. {
  697. selectAction = "UAMenuSelect";
  698. backAction = "UAMenuBack";
  699. controllerID = EUAINPUT_DEVICE_KEYBOARDMOUSE;
  700. }
  701. else
  702. {
  703. selectAction = "UAUISelect";
  704. backAction = "UAUIBack";
  705. controllerID = EUAINPUT_DEVICE_CONTROLLER;
  706. }
  707. toolbarSelectIcon.SetText(InputUtils.GetRichtextButtonIconFromInputAction(selectAction, "", controllerID, InputUtils.ICON_SCALE_TOOLBAR));
  708. toolbarBackIcon.SetText(InputUtils.GetRichtextButtonIconFromInputAction(backAction, "", controllerID, InputUtils.ICON_SCALE_TOOLBAR));
  709. toolbarBackSpacer.Show(m_CurrentCategory != RadialQuickbarCategory.DEFAULT);
  710. }
  711. override void OnPlayerDeath()
  712. {
  713. super.OnPlayerDeath();
  714. // Close inventory menu when this menu got closed by the character death event as player could be assigning a item to the quickbar
  715. // in the moment he dies and the inventory menu is opened too.
  716. MissionGameplay missionGameplay = MissionGameplay.Cast(g_Game.GetMission());
  717. if (missionGameplay && missionGameplay.GetInventory())
  718. {
  719. missionGameplay.HideInventory();
  720. }
  721. }
  722. }