inventorymenu.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. enum ScreenWidthType
  2. {
  3. NARROW,
  4. MEDIUM,
  5. WIDE
  6. }
  7. class InventoryMenu extends UIScriptedMenu
  8. {
  9. ref Inventory m_Inventory;
  10. private ref ContextMenu m_context_menu;
  11. protected bool m_IsOpened;
  12. protected bool m_OnlyFirstTime;
  13. protected int m_LastDisplayLanguage;
  14. protected static ScreenWidthType m_WidthType;
  15. protected static int m_Width;
  16. protected static int m_Height;
  17. void InventoryMenu()
  18. {
  19. CheckWidth();
  20. m_Inventory = new Inventory(null);
  21. m_Inventory.Reset();
  22. m_Inventory.UpdateInterval();
  23. m_context_menu = new ContextMenu();
  24. m_LastDisplayLanguage = g_Game.GetCurrentDisplayLanguageIdx();
  25. }
  26. override Widget Init()
  27. {
  28. m_Inventory.Init();
  29. m_context_menu.Init(layoutRoot);
  30. layoutRoot = m_Inventory.GetMainWidget();
  31. return layoutRoot;
  32. }
  33. void CheckWidth()
  34. {
  35. GetScreenSize( m_Width, m_Height );
  36. if( m_Height > 0 )
  37. {
  38. float ratio = m_Width / m_Height;
  39. if( ratio > 1.75 )
  40. m_WidthType = ScreenWidthType.WIDE;
  41. else if( ratio > 1.5 )
  42. m_WidthType = ScreenWidthType.MEDIUM;
  43. else
  44. m_WidthType = ScreenWidthType.NARROW;
  45. }
  46. }
  47. static ScreenWidthType GetWidthType()
  48. {
  49. return m_WidthType;
  50. }
  51. static int GetWidth()
  52. {
  53. return m_Width;
  54. }
  55. static int GetHeight()
  56. {
  57. return m_Height;
  58. }
  59. static float GetHeightMultiplied( float value )
  60. {
  61. float height = m_Height;
  62. return height / 1080 * value;
  63. }
  64. void RefreshQuickbar()
  65. {
  66. m_Inventory.RefreshQuickbar();
  67. }
  68. override ContextMenu GetContextMenu()
  69. {
  70. return m_context_menu;
  71. }
  72. void InitContainers(EntityAI target)
  73. {
  74. }
  75. override void Update( float timeslice )
  76. {
  77. if( m_Inventory )
  78. {
  79. m_Inventory.Update(timeslice);
  80. }
  81. }
  82. override void Refresh()
  83. {
  84. super.Refresh();
  85. m_Inventory.UpdateConsoleToolbar();
  86. }
  87. override void OnShow()
  88. {
  89. super.OnShow();
  90. m_IsOpened = true;
  91. PPERequesterBank.GetRequester(PPERequesterBank.REQ_INVENTORYBLUR).Start();
  92. VicinityItemManager.GetInstance().RefreshVicinityItems();
  93. if(m_Inventory)
  94. m_Inventory.OnShow();
  95. SetFocus( layoutRoot );
  96. MissionGameplay mission = MissionGameplay.Cast( GetGame().GetMission() );
  97. if( mission )
  98. {
  99. mission.MoveHudForInventory( true );
  100. }
  101. ItemManager.GetInstance().SetItemMicromanagmentMode( false );
  102. ItemManager.GetInstance().SetSelectedItemEx(null, null, null);
  103. m_Inventory.Refresh();
  104. }
  105. override bool OnController( Widget w, int control, int value )
  106. {
  107. if( m_IsOpened )
  108. return m_Inventory.Controller( w, control, value );
  109. return false;
  110. }
  111. bool IsOpened()
  112. {
  113. return m_IsOpened;
  114. }
  115. override void OnHide()
  116. {
  117. super.OnHide();
  118. m_context_menu.Hide();
  119. m_IsOpened = false;
  120. PPERequesterBank.GetRequester(PPERequesterBank.REQ_INVENTORYBLUR).Stop();
  121. if(m_Inventory)
  122. m_Inventory.OnHide();
  123. MissionGameplay mission = MissionGameplay.Cast(GetGame().GetMission());
  124. if(mission)
  125. {
  126. mission.MoveHudForInventory( false );
  127. }
  128. ItemManager.GetInstance().SetItemMicromanagmentMode( false );
  129. ItemManager.GetInstance().SetSelectedItemEx(null, null, null);
  130. ItemManager.GetInstance().HideTooltip();
  131. }
  132. int GetLastDisplayLanguage()
  133. {
  134. return m_LastDisplayLanguage;
  135. }
  136. bool LanguageChanged()
  137. {
  138. return g_Game.GetCurrentDisplayLanguageIdx() != m_LastDisplayLanguage;
  139. }
  140. override void OnPlayerDeath()
  141. {
  142. super.OnPlayerDeath();
  143. MissionGameplay mission = MissionGameplay.Cast(GetGame().GetMission());
  144. if (mission)
  145. {
  146. mission.HideInventory();
  147. }
  148. }
  149. }