modsmenudetailed.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. class ModsMenuDetailed extends ScriptedWidgetEventHandler
  2. {
  3. protected Widget m_Root;
  4. protected Widget m_Content;
  5. protected Widget m_CloseButton;
  6. protected ScrollWidget m_Scroll;
  7. protected ref map<ref ModInfo, ref ModsMenuDetailedEntry> m_Data;
  8. protected ModInfo m_Highlighted;
  9. //protected MainMenu m_Menu;
  10. protected UIScriptedMenu m_Menu;
  11. protected ModsMenuTooltip m_Tooltip;
  12. protected ref Timer m_TooltipTimer;
  13. protected ModInfo m_TooltipMod;
  14. void ModsMenuDetailed(array<ref ModInfo> data, Widget parent, ModsMenuTooltip tooltip, UIScriptedMenu menu_parent)
  15. {
  16. m_Root = GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/mods_menu/mods_menu_detailed.layout", parent);
  17. m_Content = m_Root.FindAnyWidget("ModsDetailedContent");
  18. m_Scroll = ScrollWidget.Cast(m_Root.FindAnyWidget("ModsDetailedScroller"));
  19. m_CloseButton = m_Root.FindAnyWidget("ModsDetailedHeaderButton");
  20. m_Menu = menu_parent;
  21. m_Data = new map<ref ModInfo, ref ModsMenuDetailedEntry>;
  22. m_Tooltip = tooltip;
  23. m_Root.SetHandler(this);
  24. LoadEntries(data);
  25. }
  26. void ~ModsMenuDetailed()
  27. {
  28. delete m_Root;
  29. }
  30. void Open()
  31. {
  32. if ( !m_Root.IsVisible() )
  33. m_Scroll.VScrollToPos( 0 );
  34. m_Root.Show( true );
  35. GetGame().GetMission().GetOnModMenuVisibilityChanged().Invoke(false);
  36. }
  37. void Close()
  38. {
  39. Highlight( null );
  40. m_Root.Show( false );
  41. GetGame().GetMission().GetOnModMenuVisibilityChanged().Invoke(true);
  42. }
  43. bool IsOpen()
  44. {
  45. return m_Root.IsVisible();
  46. }
  47. ModInfo GetHighlighted()
  48. {
  49. return m_Highlighted;
  50. }
  51. void HighlightFirst()
  52. {
  53. Highlight( m_Data.GetKey( 0 ) );
  54. }
  55. void Highlight( ModInfo mod_ref )
  56. {
  57. if ( m_Highlighted )
  58. {
  59. m_Data.Get( m_Highlighted ).Deselect();
  60. m_Content.Update();
  61. }
  62. m_Highlighted = mod_ref;
  63. if ( m_Highlighted )
  64. {
  65. m_Data.Get( m_Highlighted ).Select();
  66. m_Content.Update();
  67. ScrollToMod( m_Highlighted );
  68. }
  69. }
  70. void ScrollToMod( ModInfo mod_ref )
  71. {
  72. /*
  73. if( mod_ref )
  74. {
  75. float scroll_pos_x, scroll_pos_y;
  76. float scroll_size_x, scroll_size_y;
  77. float mod_pos_x, mod_pos_y;
  78. float mod_size_x, mod_size_y;
  79. Widget mod_widget = m_Data.Get( mod_ref ).GetWidget();
  80. if( mod_widget )
  81. {
  82. m_Content.Update();
  83. m_Scroll.Update();
  84. m_Scroll.GetScreenPos( scroll_pos_x, scroll_pos_y );
  85. m_Scroll.GetScreenSize( scroll_size_x, scroll_size_y );
  86. mod_widget.GetScreenPos( mod_pos_x, mod_pos_y );
  87. mod_widget.GetScreenSize( mod_size_x, mod_size_y );
  88. if( mod_pos_y + mod_size_y >= scroll_pos_y + scroll_size_y )
  89. {
  90. m_Scroll.VScrollToPos( mod_pos_y + mod_size_y - scroll_pos_y );
  91. }
  92. else if( mod_pos_y <= scroll_pos_y )
  93. {
  94. m_Scroll.VScrollToPos( mod_pos_y - scroll_pos_y );
  95. }
  96. m_Scroll.VScrollToPos( mod_pos_y - scroll_pos_y );
  97. }
  98. }
  99. */
  100. }
  101. void Select( ModInfo mod_ref, bool show )
  102. {
  103. if ( mod_ref )
  104. {
  105. if ( show )
  106. {
  107. m_Highlighted = mod_ref;
  108. m_Data.Get( mod_ref ).Select();
  109. }
  110. else
  111. {
  112. m_Data.Get( mod_ref ).Deselect();
  113. if ( m_Highlighted == mod_ref )
  114. {
  115. m_Highlighted = null;
  116. }
  117. }
  118. }
  119. ScrollToMod( m_Highlighted );
  120. }
  121. void PrepareTooltip( ModInfo mod_ref )
  122. {
  123. if ( m_Tooltip )
  124. {
  125. m_TooltipMod = mod_ref;
  126. if ( !m_TooltipTimer )
  127. m_TooltipTimer = new Timer(CALL_CATEGORY_GUI);
  128. m_TooltipTimer.Run( 1, this, "ShowTooltip" );
  129. }
  130. }
  131. void ShowTooltip()
  132. {
  133. if ( m_Tooltip )
  134. m_Tooltip.ShowTooltip( m_TooltipMod );
  135. }
  136. void HideTooltip()
  137. {
  138. if ( m_TooltipTimer )
  139. m_TooltipTimer.Stop();
  140. m_TooltipMod = null;
  141. if ( m_Tooltip )
  142. m_Tooltip.HideTooltip();
  143. }
  144. void LoadEntries( array<ref ModInfo> data )
  145. {
  146. foreach (ModInfo var : data)
  147. {
  148. ModsMenuDetailedEntry entry = new ModsMenuDetailedEntry(var, m_Content, this);
  149. m_Data.Insert(var, entry);
  150. }
  151. m_Content.Update();
  152. float y_c = m_Scroll.GetContentHeight();
  153. float x, y;
  154. m_Content.GetScreenSize( x, y );
  155. if ( y > y_c )
  156. {
  157. m_Scroll.SetAlpha( 1 );
  158. }
  159. }
  160. override bool OnMouseButtonUp(Widget w, int x, int y, int button)
  161. {
  162. if ( w == m_CloseButton )
  163. {
  164. Close();
  165. return true;
  166. }
  167. return false;
  168. }
  169. }