File size: 2,152 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
class ModsMenuSimple extends ScriptedWidgetEventHandler
{
	protected const int 									MOD_DISPLAY_COUNT_MAX = 3;
	
	protected Widget										m_Root;
	protected Widget										m_MoreButton;
	protected Widget										m_MoreHighlight;
	protected ref map<ModInfo, ref ModsMenuSimpleEntry>		m_Data;
	protected ModsMenuDetailed								m_DetailMenu;
	
	void ModsMenuSimple(array<ref ModInfo> data, Widget parent, ModsMenuDetailed detail_menu)
	{
		m_Root = GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/mods_menu/mods_menu_simple.layout", parent);
		m_MoreButton = m_Root.FindAnyWidget("ModMore");
		m_MoreHighlight = m_Root.FindAnyWidget("ModMoreOverlay");
		m_Data = new map<ModInfo, ref ModsMenuSimpleEntry>;
		m_DetailMenu = detail_menu;
		
		m_Root.SetHandler(this);
		LoadEntries(data);
	}
	
	void ~ModsMenuSimple()
	{
		delete m_Root;
	}

	void LoadEntries(array<ref ModInfo> data)
	{
		m_MoreButton.Show(data.Count() > MOD_DISPLAY_COUNT_MAX);
		int count = Math.Clamp(data.Count(),0,MOD_DISPLAY_COUNT_MAX);
		
		for (int i = 0; i < count; i++)
		{
			ref ModsMenuSimpleEntry entry = new ModsMenuSimpleEntry(data[i], i, m_Root, this);
			m_Data.Insert(data[i], entry);
		}
	}
	
	void Select(ModInfo mod)
	{
		m_DetailMenu.Open();
		m_DetailMenu.Highlight(mod);
	}
	
	override bool OnMouseButtonUp(Widget w, int x, int y, int button)
	{
		if (w == m_MoreButton)
		{
			if (m_DetailMenu.IsOpen())
				m_DetailMenu.Close();
			else
				m_DetailMenu.Open();
			return true;
		}
		return false;
	}
	
	override bool OnMouseEnter(Widget w, int x, int y)
	{
		if (w == m_MoreButton)
		{
			m_MoreHighlight.Show(true);
			return true;
		}
		return false;
	}
	
	override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
	{
		if (enterW != m_MoreButton)
		{
			m_MoreHighlight.Show(false);
			return true;
		}
		return false;
	}
	
	override bool OnFocus(Widget w, int x, int y)
	{
		if (w == m_MoreButton)
		{
			m_MoreHighlight.Show(true);
			return true;
		}
		return false;
	}
	
	override bool OnFocusLost(Widget w, int x, int y)
	{
		if (w == m_MoreButton)
		{
			m_MoreHighlight.Show(false);
			return true;
		}
		return false;
	}
}