Beispiel #1
0
        public static bool SetFocus(MaterialFocusGroup p_container)
        {
            MaterialFocusGroup v_oldFocus = GetFocus();

            if (p_container != null)
            {
                if (v_oldFocus != p_container)
                {
                    var v_index = FocusOrder.IndexOf(p_container);
                    if (v_index >= 0)
                    {
                        FocusOrder.RemoveAt(v_index);
                    }

                    if (FocusOrder.Count > 0)
                    {
                        FocusOrder.Insert(0, p_container);
                    }
                    else
                    {
                        FocusOrder.Add(p_container);
                    }
                    //Call Focus Events
                    if (v_oldFocus != null)
                    {
                        v_oldFocus.HandleOnLoseFocus();
                    }

                    p_container.HandleOnGainFocus();

                    return(true);
                }
            }
            return(false);
        }
 protected override void ValidateKeyTriggers(MaterialFocusGroup p_materialKeyFocus)
 {
     if (p_materialKeyFocus != null)
     {
         p_materialKeyFocus.KeyTriggers.Clear();
     }
 }
Beispiel #3
0
 public static bool ContainFocus(MaterialFocusGroup p_container)
 {
     if (p_container != null && p_container == GetFocus())
     {
         return(true);
     }
     return(false);
 }
Beispiel #4
0
 public static bool ParentContainFocus(GameObject p_child)
 {
     if (p_child != null)
     {
         MaterialFocusGroup v_directParentFocus = GetDirectFocusGroupComponent(p_child);
         return(ContainFocus(v_directParentFocus));
     }
     return(false);
 }
Beispiel #5
0
 //If Any Parent or Self contain Focus, Or Focus equal null and panel is Opened or GameObject is Active
 public static bool IsUnderFocus(GameObject p_object)
 {
     if (p_object != null)
     {
         MaterialFocusGroup v_focus = MaterialFocusGroup.GetFocus();
         var v_state = v_focus == null ? true : v_focus.GetGroupVisibilityInHierarchy();
         if (v_state && (MaterialFocusGroup.GetDirectFocusGroupComponent(p_object) == v_focus))
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #6
0
        public static MaterialFocusGroup GetFocus()
        {
            for (int i = 0; i < FocusOrder.Count; i++)
            {
                if (FocusOrder[i] == null || !FocusOrder[i].enabled)
                {
                    FocusOrder.RemoveAt(i);
                    i--;
                }
            }
            MaterialFocusGroup v_container = FocusOrder.Count > 0 ? FocusOrder[0] : null;

            return(v_container);
        }
Beispiel #7
0
        protected virtual void ValidateKeyTriggers(MaterialFocusGroup p_materialKeyFocus)
        {
            if (p_materialKeyFocus != null)
            {
                var v_cancelTrigger = new MaterialFocusGroup.KeyTriggerData();
                v_cancelTrigger.Name        = "Escape KeyDown";
                v_cancelTrigger.Key         = KeyCode.Escape;
                v_cancelTrigger.TriggerType = MaterialFocusGroup.KeyTriggerData.KeyTriggerType.KeyDown;
                AddEventListener(v_cancelTrigger.OnCallTrigger, Hide);

                p_materialKeyFocus.KeyTriggers = new System.Collections.Generic.List <MaterialFocusGroup.KeyTriggerData> {
                    v_cancelTrigger
                };
            }
        }
Beispiel #8
0
        public static bool RemoveFocus(MaterialFocusGroup p_container, bool p_keepInList)
        {
            if (p_container != null)
            {
                if (!p_container.enabled)
                {
                    p_keepInList = false;
                }
                MaterialFocusGroup v_oldFocus = GetFocus();
                var v_index = FocusOrder.IndexOf(p_container);
                if (v_index >= 0)
                {
                    FocusOrder.RemoveAt(v_index);
                }
                if (p_keepInList)
                {
                    FocusOrder.Add(p_container);
                    var v_newIndex = FocusOrder.IndexOf(p_container);
                    //Focus cant change because we have only one object in list
                    if (v_newIndex == v_index)
                    {
                        return(false);
                    }
                }
                //Call Focus Events
                if (v_oldFocus == p_container)
                {
                    MaterialFocusGroup v_newFocus = GetFocus();
                    if (v_oldFocus != null)
                    {
                        v_oldFocus.HandleOnLoseFocus();
                    }

                    if (v_newFocus != null)
                    {
                        v_newFocus.HandleOnGainFocus();
                    }

                    return(true);
                }
                else if (v_oldFocus != null)
                {
                    v_oldFocus.StartKeyTriggerUpdateRoutine();
                }
            }
            return(false);
        }
Beispiel #9
0
 public static MaterialFocusGroup GetDirectFocusGroupComponent(GameObject p_child)
 {
     if (p_child != null)
     {
         MaterialFocusGroup[] v_parentsFocus      = p_child.GetComponentsInParent <MaterialFocusGroup>();
         MaterialFocusGroup   v_directParentFocus = null;
         foreach (MaterialFocusGroup v_parentFocus in v_parentsFocus)
         {
             if (v_parentFocus != null && v_parentFocus.enabled)
             {
                 v_directParentFocus = v_parentFocus;
                 break;
             }
         }
         return(v_directParentFocus);
     }
     return(null);
 }
Beispiel #10
0
 protected virtual void CheckFocus(bool p_active, bool p_ignoreChildrenFocus, bool p_keepInFocusList)
 {
     if (p_active && enabled)
     {
         MaterialFocusGroup v_currentFocus = MaterialFocusGroup.GetFocus();
         bool v_canIgnoreCurrentFocus      = p_ignoreChildrenFocus || v_currentFocus == null || !MaterialFocusGroup.IsChildObject(this.gameObject, v_currentFocus.gameObject, false);
         if (v_canIgnoreCurrentFocus)
         {
             if (!MaterialFocusGroup.SetFocus(this))
             {
                 StartKeyTriggerUpdateRoutine();
             }
         }
         else
         {
             //Find index to add self to Focus (Index after your last children)
             int v_indexToAddThis = 0;
             var v_index          = MaterialFocusGroup.FocusOrder.IndexOf(this);
             if (v_index >= 0)
             {
                 MaterialFocusGroup.FocusOrder.RemoveAt(v_index);
             }
             for (int i = 0; i < MaterialFocusGroup.FocusOrder.Count; i++)
             {
                 MaterialFocusGroup v_container = MaterialFocusGroup.FocusOrder[i];
                 bool v_isChildrenContainer     = v_container != null && MaterialFocusGroup.IsChildObject(this.gameObject, v_container.gameObject, false);
                 if (v_isChildrenContainer)
                 {
                     v_indexToAddThis = i + 1;
                 }
             }
             MaterialFocusGroup.FocusOrder.Insert(v_indexToAddThis, this);
             StartKeyTriggerUpdateRoutine();
         }
     }
     else
     {
         if (!MaterialFocusGroup.RemoveFocus(this, p_keepInFocusList))
         {
             CancelKeyTriggerUpdateRoutine();
         }
     }
 }
Beispiel #11
0
        protected override void ValidateKeyTriggers(MaterialFocusGroup p_materialKeyFocus)
        {
            if (p_materialKeyFocus != null)
            {
                var v_affirmativeTrigger = new MaterialFocusGroup.KeyTriggerData();
                v_affirmativeTrigger.Name        = "Return KeyDown";
                v_affirmativeTrigger.Key         = KeyCode.Return;
                v_affirmativeTrigger.TriggerType = MaterialFocusGroup.KeyTriggerData.KeyTriggerType.KeyDown;
                MaterialActivity.AddEventListener(v_affirmativeTrigger.OnCallTrigger, AffirmativeButtonClicked);

                var v_cancelTrigger = new MaterialFocusGroup.KeyTriggerData();
                v_cancelTrigger.Name        = "Escape KeyDown";
                v_cancelTrigger.Key         = KeyCode.Escape;
                v_cancelTrigger.TriggerType = MaterialFocusGroup.KeyTriggerData.KeyTriggerType.KeyDown;
                MaterialActivity.AddEventListener(v_cancelTrigger.OnCallTrigger, DismissiveButtonClicked);

                p_materialKeyFocus.KeyTriggers = new System.Collections.Generic.List <MaterialFocusGroup.KeyTriggerData> {
                    v_affirmativeTrigger, v_cancelTrigger
                };
            }
        }