2class ContextMenu
extends ScriptedWidgetEventHandler
4 const int ITEMS_COUNT = 27;
5 private Widget m_context_menu_root_widget;
6 private Widget m_context_menu_panel_widget;
8 private int m_max_item_width;
21 delete m_context_menu_root_widget;
24 void Init(Widget layoutRoot)
26 m_context_menu_root_widget =
GetGame().GetWorkspace().CreateWidgets(
"gui/layouts/day_z_inventory_context_menu.layout", layoutRoot);
27 m_context_menu_panel_widget = m_context_menu_root_widget.FindAnyWidget(
"PanelWidget");
28 m_context_menu_root_widget.Show(
false);
29 m_context_menu_root_widget.SetHandler(
this);
35 if ( m_count == 0)
return;
36 int screen_w, screen_h;
45 float button_height_percent = 0.04;
46 float button_height = screen_h * button_height_percent;
47 for (
int i = 0; i < m_count; i++)
49 ButtonWidget menu_button = ButtonWidget.Cast( m_context_menu_root_widget.FindAnyWidget(
String(
"Button" + (i+1).
ToString() ) ) );
50 menu_button.SetSize(0.92, button_height);
55 m_context_menu_panel_widget.GetScript(spacer);
61 m_context_menu_root_widget.GetSize(w, h);
62 m_context_menu_panel_widget.GetSize(sx, sy);
63 m_context_menu_root_widget.SetSize(w, sy);
66 m_context_menu_root_widget.GetScreenSize(w,h);
70 int right_edge =
x + w - offset_x;
71 if (right_edge > screen_w)
73 x = screen_w - w - offset_x;
80 int bottom_edge =
y + h - offset_y;
81 if (bottom_edge > screen_h)
90 m_context_menu_root_widget.SetPos(
x,
y);
91 m_context_menu_root_widget.Show(
true);
95 void ShowBackdrop(
bool show)
99 m_context_menu_root_widget.FindAnyWidget(
"BackdropImageWidget").Show(
true);
103 m_context_menu_root_widget.FindAnyWidget(
"BackdropImageWidget").Show(
false);
110 m_context_menu_root_widget.Show(
false);
117 return m_context_menu_root_widget.IsVisible();
123 super.OnMouseLeave(w, enterW,
x,
y);
125 if ( enterW && m_context_menu_panel_widget && enterW != m_context_menu_panel_widget && enterW.GetParent() != m_context_menu_panel_widget )
136 super.OnMouseButtonDown(w,
x,
y, button);
138 if (button ==
MouseState.LEFT && w.GetUserID() > -1 && w.GetUserID() < m_commands.Count())
152 void Add(
string label,
Class obj,
string fn_name,
Param params )
155 ButtonWidget menu_button = ButtonWidget.Cast( m_context_menu_root_widget.FindAnyWidget(
String(
"Button" + (count+1).
ToString() ) ) );
159 menu_button.SetText( label );
160 menu_button.Show(
true );
162 int item_width = label.Length();
163 if (m_max_item_width < item_width)
165 m_max_item_width = item_width;
168 m_count = m_count + 1;
174 void Remove(
int index)
176 if (index < m_commands.Count())
178 m_commands.RemoveOrdered(index);
179 ButtonWidget menu_button = ButtonWidget.Cast( m_context_menu_root_widget.FindAnyWidget(
String(
"Button" + ( index + 1 ).
ToString() ) ) );
180 menu_button.Show(
false );
181 menu_button.SetText(
"" );
182 m_count = m_count - 1;
189 return m_commands.Count();
199 for ( i = 0; i < ITEMS_COUNT; i++)
201 ButtonWidget menu_button = ButtonWidget.Cast( m_context_menu_root_widget.FindAnyWidget(
String(
"Button" + (i+1).
ToString() ) ) );
204 menu_button.Show(
false );
205 menu_button.SetText(
"" );
209 m_max_item_width = 0;
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
Super root of all classes in Enforce script.
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()
string String(string s)
Helper for passing string expression to functions with void parameter. Example: Print(String("Hello "...
proto void GetScreenSize(out int x, out int y)
bool OnMouseButtonDown(Widget w, int x, int y, int button)
void Clear(bool clearFile=false)
void Add(string name, string value)