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;
22 delete m_context_menu_root_widget;
27 if (!m_context_menu_root_widget)
29 m_context_menu_root_widget =
GetGame().GetWorkspace().CreateWidgets(
"gui/layouts/day_z_inventory_context_menu.layout", layoutRoot);
30 m_context_menu_panel_widget = m_context_menu_root_widget.FindAnyWidget(
"PanelWidget");
31 m_context_menu_root_widget.Show(
false);
32 m_context_menu_root_widget.SetHandler(
this);
39 if ( m_count == 0)
return;
40 int screen_w, screen_h;
49 float button_height_percent = 0.02;
50 float button_height = screen_h * button_height_percent;
52 for (
int i = 0; i < m_count; i++)
54 ButtonWidget menu_button = ButtonWidget.Cast( m_context_menu_root_widget.FindAnyWidget(
String(
"Button" + (i+1).
ToString() ) ) );
57 menu_button.SetSize(0.90, button_height);
58 menu_button.Show(
true);
64 m_context_menu_panel_widget.GetScript(spacer);
70 m_context_menu_root_widget.GetSize(w, h);
71 m_context_menu_panel_widget.GetSize(sx, sy);
72 m_context_menu_root_widget.SetSize(w, sy);
75 m_context_menu_root_widget.GetScreenSize(w,h);
79 int right_edge =
x + w - offset_x;
80 if (right_edge > screen_w)
82 x = screen_w - w - offset_x;
89 int bottom_edge =
y + h - offset_y;
90 if (bottom_edge > screen_h)
99 m_context_menu_root_widget.SetPos(
x,
y);
100 m_context_menu_root_widget.Show(
true);
104 void ShowBackdrop(
bool show)
108 m_context_menu_root_widget.FindAnyWidget(
"BackdropImageWidget").Show(
true);
112 m_context_menu_root_widget.FindAnyWidget(
"BackdropImageWidget").Show(
false);
119 m_context_menu_root_widget.Show(
false);
127 return m_context_menu_root_widget.IsVisible();
133 super.OnMouseLeave(w, enterW,
x,
y);
135 if ( enterW && m_context_menu_panel_widget && enterW != m_context_menu_panel_widget && enterW.GetParent() != m_context_menu_panel_widget )
146 super.OnMouseButtonDown(w,
x,
y, button);
148 if (button ==
MouseState.LEFT && w.GetUserID() > -1 && w.GetUserID() < m_commands.Count())
169 void Add(
string label,
Class obj,
string fn_name,
Param params)
171 AddEx(label, FadeColors.LIGHT_GREY, obj, fn_name, params);
174 void AddEx(
string label,
int labelColor,
Class obj,
string funcName,
Param params)
177 ButtonWidget menuButton = ButtonWidget.Cast(m_context_menu_root_widget.FindAnyWidget(
string.Format(
"Button%1", count + 1)));
181 menuButton.SetText(label);
182 menuButton.SetTextColor(labelColor);
183 menuButton.Show(
true);
185 menuButton.SetFlags(menuButton.GetFlags() |
WidgetFlags.IGNOREPOINTER);
187 int itemWidth = label.Length();
188 if (m_max_item_width < itemWidth)
189 m_max_item_width = itemWidth;
199 if (index < m_commands.Count())
201 m_commands.RemoveOrdered(index);
202 ButtonWidget menu_button = ButtonWidget.Cast( m_context_menu_root_widget.FindAnyWidget(
String(
"Button" + ( index + 1 ).
ToString() ) ) );
203 menu_button.Show(
false );
204 menu_button.SetText(
"" );
212 return m_commands.Count();
222 Widget child = m_context_menu_panel_widget.GetChildren();
225 ButtonWidget button = ButtonWidget.Cast(child);
230 child = child.GetSibling();
235 m_max_item_width = 0;