Пример #1
0
        public void FocusFirstElement()
        {
            var firstElement = _interactableElements.FirstOrDefault();

            if (firstElement == CurrentElement)
            {
                return;
            }

            CurrentElement?.Unfocus();

            _elementToGetFocus = firstElement;
        }
Пример #2
0
        public void ControllerOnMoveToPreviousElement()
        {
            var lastElement = CurrentElement;

            if (CurrentElement == null)
            {
                CurrentElement = _interactableElements.FirstOrDefault();
            }
            else
            {
                var index = _interactableElements.IndexOf(CurrentElement);
                CurrentElement = index == 0 ? _interactableElements[_interactableElements.Count - 1] : _interactableElements[index - 1];
            }

            if (lastElement != CurrentElement)
            {
                lastElement?.Unfocus();
                CurrentElement?.Focus();
            }
        }
Пример #3
0
        public virtual void Update(GameTime gameTime)
        {
            if (_rearrangeList)
            {
                _interactableElements.RemoveAll(e => !e.IsInteractable);
                _interactableElements.Sort((e1, e2) => e1.TabIndex.CompareTo(e2.TabIndex));
            }

            foreach (var inputController in InputControllers)
            {
                inputController.Update(this);
            }

            if (_elementToGetFocus != null && _elementToGetFocus.State == UiState.Active)
            {
                _elementToGetFocus.Focus();
                CurrentElement     = _elementToGetFocus;
                _elementToGetFocus = null;
            }
        }
Пример #4
0
        private void ControllerOnMoveToNextElement()
        {
            var lastElement = CurrentElement;

            if (CurrentElement == null)
            {
                CurrentElement = _interactableElements.FirstOrDefault();
            }
            else
            {
                var index = _interactableElements.IndexOf(CurrentElement);
                CurrentElement = index == _interactableElements.Count - 1 ? _interactableElements[0] : _interactableElements[index + 1];
            }

            if (lastElement != CurrentElement)
            {
                lastElement?.Unfocus();
                CurrentElement?.Focus();
            }
        }
Пример #5
0
 protected void AddUiElement(UiElement element)
 {
     _interactableElements.Add(element);
     _rearrangeList = true;
 }
Пример #6
0
 public UiFocusContainer()
 {
     _interactableElements = new List <UiElement>();
     InputControllers      = new List <OverlayInputController>();
     CurrentElement        = null;
 }
Пример #7
0
 private void ControllerOnOnAction(UiElement uiElement)
 {
     CurrentElement?.OnAction();
 }
Пример #8
0
 protected void RemoveChild(UiElement element)
 {
     _children.Remove(element);
 }
Пример #9
0
 /// <summary>
 /// Adds a child control to compound element.
 /// </summary>
 /// <param name="element"></param>
 protected void AddChildElement(UiElement element)
 {
     _children.Add(element);
 }
Пример #10
0
 protected void InvokeAction(UiElement element)
 {
     OnAction?.Invoke(element);
 }