File size: 5,295 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
class LayoutHolder extends ScriptedWidgetEventHandler
{
	protected Widget				m_MainWidget;
	protected Widget				m_RootWidget;
	protected Widget				m_ParentWidget;
	protected LayoutHolder			m_Parent;
	protected string				m_LayoutName;
	
	protected bool					m_IsActive;
	protected bool					m_ImmedUpdate;
	protected bool					m_TooltipOwner;
	
	protected EntityAI				m_am_entity1, m_am_entity2;

	void UpdateInterval();
	void SetLayoutName();
	
	// Override this and set m_ImmedUpdate to true if you need the widget to update on construction
	// Had to be done this way since adding it to the constructor parameters would break mods..
	void SetImmedUpdate()
	{
		m_ImmedUpdate = false;
	}
	
	void OnSelectAction(ItemBase item, int actionId)
	{
		PlayerBase m_player = PlayerBase.Cast( GetGame().GetPlayer() );
		m_player.GetActionManager().OnInstantAction(ActionDebug,new Param2<ItemBase,int>(item,actionId));
	}
	
	void OnSelectActionEx(EntityAI item, int actionId)
	{
		PlayerBase m_player = PlayerBase.Cast( GetGame().GetPlayer() );
		m_player.GetActionManager().OnInstantAction(ActionDebug,new Param2<EntityAI,int>(item,actionId));
	}
	
	void ShowActionMenu(InventoryItem item)
	{
		PlayerBase m_player = PlayerBase.Cast( GetGame().GetPlayer() );
		HideOwnedTooltip();
		m_am_entity1 = item;
		m_am_entity2 = null;
		ContextMenu cmenu = ContextMenu.Cast(GetGame().GetUIManager().GetMenu().GetContextMenu());

		cmenu.Hide();
		cmenu.Clear();

		if (m_am_entity1 == null)
			return;

		TSelectableActionInfoArrayEx customActions = new TSelectableActionInfoArrayEx();
		ItemBase itemBase = ItemBase.Cast(item);
		itemBase.GetDebugActions(customActions);

		if (ItemBase.GetDebugActionsMask() & DebugActionType.PLAYER_AGENTS)
		{
			m_player.GetDebugActions(customActions);
		}

		int actionsCount = customActions.Count();
		for (int i = 0; i < customActions.Count(); i++)
		{
			TSelectableActionInfoWithColor actionInfo = TSelectableActionInfoWithColor.Cast(customActions.Get(i));
			if (actionInfo)
			{
				int actionId 		= actionInfo.param2;
				int textColor		= actionInfo.param4;
				string actionText 	= actionInfo.param3;

				if (actionId == EActions.SEPARATOR)
					cmenu.AddEx(actionText, textColor, this, "", null);
				else
					cmenu.AddEx(actionText, textColor, this, "OnSelectActionEx", new Param3<EntityAI, int, int>(itemBase, actionId, textColor));
			}
		}

		int actionMenuPosX, actionMenuPosY;
		GetMousePos(actionMenuPosX, actionMenuPosY);
		actionMenuPosX -= 5;
		actionMenuPosY -= 5;
		cmenu.Show(actionMenuPosX, actionMenuPosY);
	}
	
	
	void LayoutHolder( LayoutHolder parent )
	{		
		m_Parent = parent;
		
		SetLayoutName();
		SetParentWidget();
		SetImmedUpdate();
		
		m_TooltipOwner = false;
		
		if ( m_LayoutName != "" )
		{
			m_MainWidget = GetGame().GetWorkspace().CreateWidgets( m_LayoutName, null, false );
			m_MainWidget.Show( true, false );
		}
		
		m_RootWidget = m_MainWidget;
		
		if ( m_ParentWidget )
		{
			m_ParentWidget.Show( true, false );
			if ( m_MainWidget )
			{
				m_ParentWidget.AddChild( m_MainWidget, false );
			}
		}
		
		if ( m_ImmedUpdate )
		{
			if ( m_MainWidget )
				m_MainWidget.Update();
		}
	}
	
	void ~LayoutHolder()
	{
		HideOwnedTooltip();
		delete m_RootWidget;
	}	
		
	LayoutHolder GetRoot()
	{
		if ( m_Parent )
		{
			ref LayoutHolder container = m_Parent.GetRoot();
			return container;
		}
		else
		{
			return this;
		}
	}
	
	void SetParentWidget()
	{
		if ( m_Parent )
			m_ParentWidget = m_Parent.GetMainWidget();
	}
	
	LayoutHolder GetParent()
	{
		return m_Parent;
	}
	
	void SetActive(bool active)
	{
		m_IsActive = active;
	}
	
	void SetLastActive();
	void SetFirstActive();

	bool IsActive()
	{
		return m_IsActive;
	}

	Widget GetMainWidget()
	{
		return m_MainWidget;
	}
	
	Widget GetRootWidget()
	{
		return m_RootWidget;
	}
	
	bool IsDisplayable()
	{
		return true;
	}
	
	bool IsVisible()
	{
		if (m_RootWidget)
		{
			return m_RootWidget.IsVisible();
		}
		return false;
	}

	void OnShow()
	{
		m_RootWidget.Show( true );
		if ( m_ParentWidget )
			m_ParentWidget.Show( true );
	}

	void OnHide()
	{
		m_RootWidget.Show( false );
	}

	void Refresh()
	{
		m_RootWidget.Update();
	}
	
	void InspectItem( EntityAI item )
	{
		InventoryMenu menu = InventoryMenu.Cast( GetGame().GetUIManager().FindMenu(MENU_INVENTORY) );
		InspectMenuNew inspect_menu = InspectMenuNew.Cast( menu.EnterScriptedMenu(MENU_INSPECT) );
		if ( inspect_menu )
		{
			GetGame().GetMission().GetHud().ShowHudUI( false );
			GetGame().GetMission().GetHud().ShowQuickbarUI( false );
			inspect_menu.SetItem( item );
		}
	}
	
	void UpdateSelectionIcons()
	{}
	
	void PrepareOwnedTooltip(EntityAI item/*, Widget w*/, int x = 0, int y = 0)
	{
		ItemManager.GetInstance().PrepareTooltip(item,x,y);
		m_TooltipOwner = true;
	}
	
	void PrepareOwnedSlotsTooltip(Widget w, string name, string desc, int x = 0, int y = 0)
	{
		ItemManager.GetInstance().SetTooltipWidget(w);
		ItemManager.GetInstance().PrepareSlotsTooltip(name,desc,x,y);
		m_TooltipOwner = true;
	}
	
	void HideOwnedTooltip()
	{
		if (m_TooltipOwner)
		{
			ItemManager.GetInstance().HideTooltip();
			m_TooltipOwner = false;
		}
	}
	
	void HideOwnedSlotsTooltip()
	{
		if (m_TooltipOwner)
		{
			ItemManager.GetInstance().HideTooltipSlot();
			m_TooltipOwner = false;
		}
	}
}