4 private Widget m_context_menu_root_widget;
5 private Widget m_context_menu_panel_widget;
7 private int m_max_item_width;
9 const int ITEMS_COUNT = 27;
21 delete m_context_menu_root_widget;
26 if(!m_context_menu_root_widget)
28 m_context_menu_root_widget =
GetGame().GetWorkspace().CreateWidgets(
"gui/layouts/day_z_inventory_context_menu.layout", layoutRoot);
29 m_context_menu_panel_widget = m_context_menu_root_widget.FindAnyWidget(
"PanelWidget");
30 m_context_menu_root_widget.Show(
false);
31 m_context_menu_root_widget.SetHandler(
this);
38 if ( m_count == 0)
return;
39 int screen_w, screen_h;
48 float button_height_percent = 0.02;
49 float button_height = screen_h * button_height_percent;
51 for (
int i = 0; i < m_count; i++)
53 ButtonWidget menu_button = ButtonWidget.Cast( m_context_menu_root_widget.FindAnyWidget(
String(
"Button" + (i+1).
ToString() ) ) );
56 menu_button.SetSize(0.90, button_height);
57 menu_button.Show(
true);
63 m_context_menu_panel_widget.GetScript(spacer);
69 m_context_menu_root_widget.GetSize(w, h);
70 m_context_menu_panel_widget.GetSize(sx, sy);
71 m_context_menu_root_widget.SetSize(w, sy);
74 m_context_menu_root_widget.GetScreenSize(w,h);
78 int right_edge =
x + w - offset_x;
79 if (right_edge > screen_w)
81 x = screen_w - w - offset_x;
88 int bottom_edge =
y + h - offset_y;
89 if (bottom_edge > screen_h)
98 m_context_menu_root_widget.SetPos(
x,
y);
99 m_context_menu_root_widget.Show(
true);
103 void ShowBackdrop(
bool show)
107 m_context_menu_root_widget.FindAnyWidget(
"BackdropImageWidget").Show(
true);
111 m_context_menu_root_widget.FindAnyWidget(
"BackdropImageWidget").Show(
false);
118 m_context_menu_root_widget.Show(
false);
126 return m_context_menu_root_widget.IsVisible();
132 super.OnMouseLeave(w, enterW,
x,
y);
134 if ( enterW && m_context_menu_panel_widget && enterW != m_context_menu_panel_widget && enterW.GetParent() != m_context_menu_panel_widget )
145 super.OnMouseButtonDown(w,
x,
y, button);
147 if (button ==
MouseState.LEFT && w.GetUserID() > -1 && w.GetUserID() < m_commands.Count())
161 void Add(
string label,
Class obj,
string fn_name,
Param params)
163 AddEx(label, FadeColors.LIGHT_GREY, obj, fn_name, params);
166 void AddEx(
string label,
int labelColor,
Class obj,
string funcName,
Param params)
169 ButtonWidget menuButton = ButtonWidget.Cast(m_context_menu_root_widget.FindAnyWidget(
string.Format(
"Button%1", count + 1)));
173 menuButton.SetText(label);
174 menuButton.SetTextColor(labelColor);
175 menuButton.Show(
true);
177 menuButton.SetFlags(menuButton.GetFlags() |
WidgetFlags.IGNOREPOINTER);
179 int itemWidth = label.Length();
180 if (m_max_item_width < itemWidth)
181 m_max_item_width = itemWidth;
191 if (index < m_commands.Count())
193 m_commands.RemoveOrdered(index);
194 ButtonWidget menu_button = ButtonWidget.Cast( m_context_menu_root_widget.FindAnyWidget(
String(
"Button" + ( index + 1 ).
ToString() ) ) );
195 menu_button.Show(
false );
196 menu_button.SetText(
"" );
204 return m_commands.Count();
214 Widget child = m_context_menu_panel_widget.GetChildren();
217 ButtonWidget button = ButtonWidget.Cast(child);
222 child = child.GetSibling();
227 m_max_item_width = 0;