File size: 3,259 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 |
class OptionSelectorEditbox extends OptionSelectorBase
{
protected EditBoxWidget m_EditBox;
void OptionSelectorEditbox(Widget parent, string value, ScriptedWidgetEventHandler parent_menu, bool disabled)
{
m_Root = GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/option_editbox.layout", parent);
#ifdef PLATFORM_CONSOLE
m_Parent = parent.GetParent().GetParent();
#else
#ifdef PLATFORM_WINDOWS
m_Parent = parent.GetParent();
#endif
#endif
m_SelectorType = 1;
m_ParentClass = parent_menu;
m_EditBox = EditBoxWidget.Cast(m_Root.FindAnyWidget("option_value"));
SetValue(value);
Enable();
m_Parent.SetHandler(this);
}
void ~OptionSelectorEditbox()
{
delete m_Root;
}
override void Enable()
{
super.Enable();
m_EditBox.ClearFlags(WidgetFlags.IGNOREPOINTER);
}
override void Disable()
{
super.Disable();
m_EditBox.SetFlags(WidgetFlags.IGNOREPOINTER);
}
override bool OnMouseEnter(Widget w, int x, int y)
{
if (!IsFocusable(w))
return true;
if (m_ParentClass)
{
m_ParentClass.OnFocus(m_Root.GetParent(), -1, m_SelectorType);
m_ParentClass.OnMouseEnter(m_Root.GetParent().GetParent(), x, y);
}
UIScriptedMenu menu = GetGame().GetUIManager().GetMenu();
if (menu && menu.IsInherited(CharacterCreationMenu))
{
menu.OnFocus(m_Root.GetParent(), -1, m_SelectorType);
menu.OnMouseEnter(m_Root.GetParent().GetParent(), x, y);
}
ColorHighlight(w);
return true;
}
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
{
if (IsFocusable(enterW))
return true;
if (m_ParentClass)
{
m_ParentClass.OnFocus(null, x, y);
m_ParentClass.OnMouseLeave(m_Root.GetParent().GetParent(), enterW, x, y);
}
UIScriptedMenu menu = GetGame().GetUIManager().GetMenu();
if (menu && menu.IsInherited(CharacterCreationMenu))
{
menu.OnFocus(null, x, y);
menu.OnMouseLeave(m_Root.GetParent().GetParent(), enterW, x, y);
}
ColorNormal(w);
return true;
}
override bool OnChange(Widget w, int x, int y, bool finished)
{
if (w == m_EditBox)
{
m_OptionChanged.Invoke(GetValue());
return true;
}
return false;
}
override bool IsFocusable(Widget w)
{
if (w)
{
return (w == m_Parent || w == m_EditBox);
}
return false;
}
override bool OnFocus(Widget w, int x, int y)
{
if (GetFocus() != m_EditBox)
{
SetFocus(m_EditBox);
m_Parent.Enable(false);
}
return super.OnFocus(m_Parent, x, y);
}
override bool OnFocusLost(Widget w, int x, int y)
{
if (w == m_EditBox)
{
m_Parent.Enable(true);
return super.OnFocusLost(m_Parent, x, y);
}
return false;
}
void SetValue(string value, bool update = true)
{
m_EditBox.SetText(value);
if (update)
m_OptionChanged.Invoke(GetValue());
}
string GetValue()
{
return m_EditBox.GetText();
}
override void ColorHighlight(Widget w)
{
if (!w)
return;
if (m_EditBox)
{
SetFocus(m_EditBox);
m_EditBox.SetColor(ARGB(255, 200, 0, 0));
}
super.ColorHighlight(w);
}
override void ColorNormal(Widget w)
{
if (!w)
return;
if (m_EditBox)
{
m_EditBox.SetColor(ARGB(140, 255, 255, 255));
}
super.ColorNormal(w);
}
} |