123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- class OptionSelectorBase extends ScriptedWidgetEventHandler
- {
- protected int m_SelectorType = 0;
- protected Widget m_Parent;
- protected Widget m_Root;
-
- protected bool m_Enabled;
-
- protected ScriptedWidgetEventHandler m_ParentClass;
-
- ref ScriptInvoker m_OptionFocused = new ScriptInvoker;
- ref ScriptInvoker m_OptionUnfocused = new ScriptInvoker;
- ref ScriptInvoker m_AttemptOptionChange = new ScriptInvoker;
- ref ScriptInvoker m_OptionChanged = new ScriptInvoker;
-
- void ~OptionSelectorBase()
- {
- delete m_Root;
- }
-
- Widget GetParent()
- {
- return m_Parent;
- }
-
- bool IsFocusable(Widget w)
- {
- if (w)
- {
- return w == m_Parent;
- }
- return false;
- }
-
- 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);
- #ifndef PLATFORM_CONSOLE
- m_ParentClass.OnMouseEnter(m_Root.GetParent().GetParent(), x, y);
- #endif
- }
-
- 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);
- }
-
- #ifndef PLATFORM_CONSOLE
- ColorHighlight(w);
- #else
- ColorHighlightConsole(w);
- if (m_ParentClass)
- {
- m_ParentClass.OnFocus(m_Root.GetParent(), -1, m_SelectorType);
- }
- #endif
-
- return true;
- }
-
- override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
- {
- #ifdef PLATFORM_CONSOLE
- if (IsFocusable(enterW))
- return true;
- #endif
-
- if (m_ParentClass)
- {
- m_ParentClass.OnFocus(null, x, y);
- #ifndef PLATFORM_CONSOLE
- m_ParentClass.OnMouseLeave(m_Root.GetParent().GetParent(), enterW, x, y);
- #endif
- }
-
- UIScriptedMenu menu = GetGame().GetUIManager().GetMenu();
-
- if (menu && menu.IsInherited(CharacterCreationMenu))
- {
- menu.OnFocus(null, x, y);
- menu.OnMouseLeave(m_Root.GetParent().GetParent(), enterW, x, y);
- }
-
- #ifndef PLATFORM_CONSOLE
- ColorNormal(w);
- #else
- ColorNormalConsole(w);
- if (m_ParentClass)
- {
- m_ParentClass.OnFocusLost(w, x, y);
- }
- #endif
-
- return true;
- }
-
- override bool OnFocus(Widget w, int x, int y)
- {
- if (IsFocusable(w))
- {
- ColorHighlightConsole(w);
- if (m_ParentClass)
- {
- m_ParentClass.OnFocus(m_Root.GetParent(), -1, m_SelectorType);
- }
- return true;
- }
- return false;
- }
-
- override bool OnFocusLost(Widget w, int x, int y)
- {
- ColorNormalConsole(w);
- if (m_ParentClass)
- {
- m_ParentClass.OnFocusLost(w, x, y);
- }
- return true;
- }
-
- void Focus()
- {
- #ifndef PLATFORM_CONSOLE
- SetFocus(m_Root);
- #else
- SetFocus(m_Parent);
- #endif
- }
-
- void Enable()
- {
- m_Enabled = true;
-
- m_Parent.ClearFlags(WidgetFlags.IGNOREPOINTER);
-
- #ifdef PLATFORM_CONSOLE
- ColorNormalConsole(m_Parent);
- #else
- ColorNormal(m_Parent);
- #endif
- }
-
- void Disable()
- {
- m_Enabled = false;
-
- m_Parent.SetFlags(WidgetFlags.IGNOREPOINTER);
-
- #ifdef PLATFORM_CONSOLE
- ColorDisabledConsole(m_Parent);
- #else
- ColorDisabled(m_Parent);
- #endif
- }
-
- void ColorHighlight(Widget w)
- {
- if (!w)
- return;
-
- ButtonSetColor(w, ARGB(255, 255, 0, 0));
- }
-
- void ColorNormal(Widget w)
- {
- if (!w)
- return;
-
- int color_pnl = ARGB(255, 255, 255, 255);
- int color_lbl = ARGB(255, 255, 255, 255);
-
- ButtonSetColor(w, color_pnl);
-
- Widget title_label = w.FindAnyWidget(w.GetName() + "_label");
- Widget option_label = w.FindAnyWidget("option_label");
-
- if (title_label)
- {
- title_label.SetColor(color_lbl);
- }
-
- if (option_label)
- {
- option_label.SetColor(color_lbl);
- }
- }
-
- void ColorDisabled(Widget w)
- {
- if (!w)
- return;
-
- int color_pnl = ARGB(0, 0, 0, 0);
- int color_lbl = ARGB(120, 255, 255, 255);
-
- ButtonSetColor(w, color_pnl);
-
- Widget title_label = w.FindAnyWidget(w.GetName() + "_label");
- Widget option_label = w.FindAnyWidget("option_label");
-
- if (title_label)
- {
- title_label.SetColor(color_lbl);
- }
-
- if (option_label)
- {
- option_label.SetColor(color_lbl);
- }
- }
-
- void ButtonSetColor(Widget w, int color)
- {
- Widget option = w.FindAnyWidget(w.GetName() + "_image");
-
- if (option)
- {
- option.SetColor(color);
- }
- }
-
- void ColorHighlightConsole(Widget w)
- {
- if (!w)
- return;
-
- int color_pnl = ARGB(255, 200, 0, 0);
- int color_lbl = ARGB(255, 255, 255, 255);
-
- ButtonSetColorConsole(w, color_pnl);
- ButtonSetAlphaAnimConsole(null);
- ButtonSetTextColorConsole(w, color_lbl);
- }
-
- void ColorNormalConsole(Widget w)
- {
- if (!w)
- return;
-
- int color_pnl = ARGB(0, 0, 0, 0);
- int color_lbl = ARGB(255, 255, 255, 255);
-
- ButtonSetColorConsole(w, color_pnl);
- ButtonSetAlphaAnimConsole(null);
- ButtonSetTextColorConsole(w, color_lbl);
- }
-
- void ColorDisabledConsole(Widget w)
- {
- if (!w)
- return;
-
- int color_pnl = ARGB(0, 0, 0, 0);
- int color_lbl = ARGB(120, 255, 255, 255);
-
- ButtonSetColorConsole(w, color_pnl);
- ButtonSetAlphaAnimConsole(null);
- ButtonSetTextColorConsole(w, color_lbl);
- }
-
- void ButtonSetColorConsole(Widget w, int color)
- {
- w.SetColor(color);
- }
-
- void ButtonSetAlphaAnimConsole(Widget w)
- {
- if (!w)
- return;
-
- Widget panel = w.FindAnyWidget(w.GetName() + "_panel");
-
- if (panel)
- {
- //m_Root.SetWidgetAnimAlpha(panel);
- }
- }
-
- void ButtonSetTextColorConsole(Widget w, int color)
- {
- if (!w)
- return;
- TextWidget label = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_label"));
- TextWidget text = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_text"));
- TextWidget text2 = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_text_1"));
-
- if (label)
- {
- label.SetColor(color);
- }
-
- if (text)
- {
- text.SetColor(color);
- }
-
- if (text2)
- {
- text2.SetColor(color);
- }
- }
- }
|