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