4 protected static ref ContextMenu m_ContextMenuInstance;
6 Widget m_context_menu_root_widget;
7 private Widget m_context_menu_panel_widget;
9 private int m_max_item_width;
11 private bool m_builtIn =
false;
12 const int ITEMS_COUNT = 27;
25 delete m_context_menu_root_widget;
28 void Init(
Widget layoutRoot,
bool builtIn =
false)
31 if (!m_context_menu_root_widget)
33 m_context_menu_root_widget =
GetGame().GetWorkspace().CreateWidgets(
"gui/layouts/day_z_inventory_context_menu.layout", layoutRoot);
34 m_context_menu_panel_widget = m_context_menu_root_widget.FindAnyWidget(
"PanelWidget");
35 m_context_menu_root_widget.Show(
false);
36 m_context_menu_root_widget.SetHandler(
this);
43 if ( m_count == 0)
return;
44 int screen_w, screen_h;
53 float button_height_percent = 0.02;
54 float button_height = screen_h * button_height_percent;
56 for (
int i = 0; i < m_count; i++)
58 ButtonWidget menu_button = ButtonWidget.Cast( m_context_menu_root_widget.FindAnyWidget(
String(
"Button" + (i+1).
ToString() ) ) );
61 menu_button.SetSize(0.90, button_height);
62 menu_button.Show(
true);
68 m_context_menu_panel_widget.GetScript(spacer);
74 m_context_menu_root_widget.GetSize(w, h);
75 m_context_menu_panel_widget.GetSize(sx, sy);
76 m_context_menu_root_widget.SetSize(w, sy);
79 m_context_menu_root_widget.GetScreenSize(w,h);
83 int right_edge =
x + w - offset_x;
84 if (right_edge > screen_w)
86 x = screen_w - w - offset_x;
93 int bottom_edge =
y + h - offset_y;
94 if (bottom_edge > screen_h)
103 m_context_menu_root_widget.SetPos(
x,
y);
104 m_context_menu_root_widget.Show(
true);
109 m_context_menu_root_widget.SetSize(
x,
y);
113 void ShowBackdrop(
bool show)
117 m_context_menu_root_widget.FindAnyWidget(
"BackdropImageWidget").Show(
true);
121 m_context_menu_root_widget.FindAnyWidget(
"BackdropImageWidget").Show(
false);
128 m_context_menu_root_widget.Show(
false);
136 return m_context_menu_root_widget.IsVisible();
142 super.OnMouseLeave(w, enterW,
x,
y);
144 if ( !m_builtIn && enterW && m_context_menu_panel_widget && enterW != m_context_menu_panel_widget && enterW.GetParent() != m_context_menu_panel_widget )
155 super.OnMouseButtonDown(w,
x,
y, button);
157 if (button ==
MouseState.LEFT && w.GetUserID() > -1 && w.GetUserID() < m_commands.Count())
178 void Add(
string label,
Class obj,
string fn_name,
Param params)
180 AddEx(label, FadeColors.LIGHT_GREY, obj, fn_name, params);
183 void AddEx(
string label,
int labelColor,
Class obj,
string funcName,
Param params)
186 ButtonWidget menuButton = ButtonWidget.Cast(m_context_menu_root_widget.FindAnyWidget(
string.Format(
"Button%1", count + 1)));
190 menuButton.SetText(label);
191 menuButton.SetTextColor(labelColor);
192 menuButton.Show(
true);
194 menuButton.SetFlags(menuButton.GetFlags() |
WidgetFlags.IGNOREPOINTER);
196 int itemWidth = label.Length();
197 if (m_max_item_width < itemWidth)
198 m_max_item_width = itemWidth;
208 if (index < m_commands.Count())
210 m_commands.RemoveOrdered(index);
211 ButtonWidget menu_button = ButtonWidget.Cast( m_context_menu_root_widget.FindAnyWidget(
String(
"Button" + ( index + 1 ).
ToString() ) ) );
212 menu_button.Show(
false );
213 menu_button.SetText(
"" );
221 return m_commands.Count();
231 if (!m_context_menu_panel_widget)
233 Widget child = m_context_menu_panel_widget.GetChildren();
236 ButtonWidget button = ButtonWidget.Cast(child);
241 child = child.GetSibling();
246 m_max_item_width = 0;
253 TSelectableActionInfoArrayEx customActions =
new TSelectableActionInfoArrayEx();
254 entity.GetDebugActions(customActions);
256 int actionsCount = customActions.Count();
257 for (
int i = 0; i < customActions.Count(); i++)
262 int actionId = actionInfo.param2;
263 int textColor = actionInfo.param4;
264 string actionText = actionInfo.param3;
267 AddEx(actionText, textColor,
null,
"",
null);
275 static void DisplayContextMenu(
int x,
int y, notnull
EntityAI entity, notnull
Widget rootWidget,
Class target)
277 m_ContextMenuInstance =
new ContextMenu();
278 if (m_ContextMenuInstance)
280 m_ContextMenuInstance.Init(rootWidget);
281 m_ContextMenuInstance.BuildContextMenu(entity, rootWidget, target);
283 m_ContextMenuInstance.SetSize(1,1);
284 m_ContextMenuInstance.Show(
x,
y);