leftarea.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. class LeftArea: Container
  2. {
  3. protected Widget m_UpIcon;
  4. protected Widget m_DownIcon;
  5. protected Widget m_ContentParent;
  6. protected ref VicinityContainer m_VicinityContainer;
  7. protected ScrollWidget m_ScrollWidget;
  8. protected ref SizeToChild m_ContentResize;
  9. protected bool m_ShouldChangeSize = true;
  10. protected bool m_IsProcessing = false; // Prevents refreshing every time a child is added while it is still processing
  11. void LeftArea(LayoutHolder parent )
  12. {
  13. m_MainWidget.Show(true, false);
  14. m_ContentParent = m_MainWidget.FindAnyWidget("ContentParent");
  15. m_ContentParent.GetScript(m_ContentResize);
  16. m_ScrollWidget = ScrollWidget.Cast(m_MainWidget.FindAnyWidget("Scroller"));
  17. m_MainWidget = m_MainWidget.FindAnyWidget("Content");
  18. m_UpIcon = m_RootWidget.FindAnyWidget("Up");
  19. m_DownIcon = m_RootWidget.FindAnyWidget("Down");
  20. m_VicinityContainer = new VicinityContainer(this, false);
  21. m_Body.Insert(m_VicinityContainer);
  22. m_ActiveIndex = 0;
  23. WidgetEventHandler.GetInstance().RegisterOnChildAdd(m_MainWidget, this, "OnChildAdd");
  24. WidgetEventHandler.GetInstance().RegisterOnChildRemove(m_MainWidget, this, "OnChildRemove");
  25. RecomputeOpenedContainers();
  26. }
  27. override void UnfocusGrid()
  28. {
  29. Container active_container;
  30. for ( int i = 0; i < m_OpenedContainers.Count(); i++ )
  31. {
  32. active_container = Container.Cast( m_OpenedContainers.Get( i ) );
  33. active_container.UnfocusGrid();
  34. }
  35. }
  36. override bool IsActive()
  37. {
  38. if( m_OpenedContainers.Count() <= m_ActiveIndex )
  39. {
  40. m_ActiveIndex = 0;
  41. }
  42. Container active_container = Container.Cast( m_OpenedContainers.Get( m_ActiveIndex ) );
  43. return active_container.IsActive( );
  44. }
  45. override void SetActive( bool active )
  46. {
  47. super.SetActive( active );
  48. UpdateSelectionIcons();
  49. }
  50. override ScrollWidget GetScrollWidget()
  51. {
  52. return m_ScrollWidget;
  53. }
  54. override void UpdateSelectionIcons()
  55. {
  56. #ifdef PLATFORM_CONSOLE
  57. ScrollToActiveContainer();
  58. #endif
  59. m_UpIcon.Show( m_IsActive );
  60. m_DownIcon.Show( m_IsActive );
  61. if( m_IsActive )
  62. {
  63. float x, y;
  64. m_UpIcon.GetScreenSize( x, y );
  65. float top_y = GetCurrentContainerTopY();
  66. m_UpIcon.SetPos( 0, Math.Clamp( top_y, 0, 99999 ) );
  67. #ifndef PLATFORM_CONSOLE
  68. float x2, y2;
  69. m_DownIcon.GetScreenSize( x2, y2 );
  70. float bottom_y = GetCurrentContainerBottomY() - y2;
  71. float diff = bottom_y - ( top_y + y );
  72. if( diff < 0 )
  73. {
  74. top_y += diff / 2;
  75. bottom_y -= diff / 2;
  76. }
  77. m_DownIcon.SetPos( 0, bottom_y );
  78. #endif
  79. }
  80. }
  81. float GetCurrentContainerTopY()
  82. {
  83. float x, y, cont_screen_pos;
  84. m_MainWidget.GetScreenPos( x, y );
  85. if ( m_OpenedContainers.IsValidIndex( m_ActiveIndex ) )
  86. cont_screen_pos = Container.Cast( m_OpenedContainers.Get( m_ActiveIndex ) ).GetFocusedContainerYScreenPos();
  87. return cont_screen_pos - y;
  88. }
  89. float GetCurrentContainerBottomY()
  90. {
  91. float x, y, cont_screen_pos, cont_screen_height;
  92. m_MainWidget.GetScreenPos( x, y );
  93. if ( m_OpenedContainers.IsValidIndex( m_ActiveIndex ) )
  94. {
  95. cont_screen_pos = Container.Cast( m_OpenedContainers.Get( m_ActiveIndex ) ).GetFocusedContainerYScreenPos();
  96. cont_screen_height = Container.Cast( m_OpenedContainers.Get( m_ActiveIndex ) ).GetFocusedContainerHeight();
  97. }
  98. return cont_screen_pos - y + cont_screen_height;
  99. }
  100. override void SetSameLevelNextActive()
  101. {
  102. m_VicinityContainer.SetSameLevelNextActive();
  103. Refresh();
  104. }
  105. override void SetSameLevelPreviousActive()
  106. {
  107. m_VicinityContainer.SetSameLevelPreviousActive();
  108. Refresh();
  109. }
  110. override void ExpandCollapseContainer()
  111. {
  112. Container c = GetFocusedContainer();
  113. if (c)
  114. {
  115. c.ExpandCollapseContainer();
  116. }
  117. Refresh();
  118. }
  119. void OnLeftPanelDropReceived( Widget w, int x, int y, Widget receiver )
  120. {
  121. m_VicinityContainer.OnLeftPanelDropReceived( w, x, y, receiver );
  122. }
  123. override void DraggingOverHeader( Widget w, int x, int y, Widget receiver )
  124. {
  125. m_VicinityContainer.DraggingOverHeader( w, x, y, receiver );
  126. }
  127. override void SetLayoutName()
  128. {
  129. #ifdef PLATFORM_CONSOLE
  130. m_LayoutName = WidgetLayoutName.LeftAreaXbox;
  131. #else
  132. switch ( InventoryMenu.GetWidthType() )
  133. {
  134. case ScreenWidthType.NARROW:
  135. {
  136. m_LayoutName = WidgetLayoutName.LeftAreaNarrow;
  137. break;
  138. }
  139. case ScreenWidthType.MEDIUM:
  140. {
  141. m_LayoutName = WidgetLayoutName.LeftAreaMedium;
  142. break;
  143. }
  144. case ScreenWidthType.WIDE:
  145. {
  146. m_LayoutName = WidgetLayoutName.LeftAreaWide;
  147. break;
  148. }
  149. }
  150. #endif
  151. }
  152. override EntityAI GetFocusedItem()
  153. {
  154. EntityAI item = GetFocusedContainer().GetFocusedItem();
  155. return item;
  156. }
  157. VicinityContainer GetVicinityContainer()
  158. {
  159. return m_VicinityContainer;
  160. }
  161. override void SetParentWidget()
  162. {
  163. m_ParentWidget = m_Parent.GetMainWidget().FindAnyWidget( "LeftPanel" );
  164. }
  165. override void OnShow()
  166. {
  167. super.OnShow();
  168. Refresh();
  169. }
  170. override void Refresh()
  171. {
  172. super.Refresh();
  173. m_MainWidget.Update();
  174. m_RootWidget.Update();
  175. m_ScrollWidget.Update();
  176. UpdateSelectionIcons();
  177. m_ShouldChangeSize = true;
  178. }
  179. override void UpdateInterval()
  180. {
  181. m_IsProcessing = true;
  182. super.UpdateInterval();
  183. m_IsProcessing = false;
  184. float x, y;
  185. float x2, y2;
  186. m_ContentParent.GetScreenSize( x, y );
  187. m_MainWidget.GetScreenSize( x2, y2 );
  188. if ( y2 != y )
  189. m_ShouldChangeSize = true;
  190. bool changed_size;
  191. //if ( m_ShouldChangeSize )
  192. m_ContentResize.ResizeParentToChild( changed_size );
  193. if ( changed_size || m_ShouldChangeSize )
  194. {
  195. m_MainWidget.Update();
  196. m_RootWidget.Update();
  197. m_ScrollWidget.Update();
  198. m_ShouldChangeSize = false;
  199. }
  200. CheckScrollbarVisibility();
  201. }
  202. override bool OnChildRemove( Widget w, Widget child )
  203. {
  204. if (!m_IsProcessing)
  205. Refresh();
  206. return true;
  207. }
  208. override bool OnChildAdd( Widget w, Widget child )
  209. {
  210. if (!m_IsProcessing)
  211. Refresh();
  212. return true;
  213. }
  214. }