private void AddSwitchToSuggestions()
        {
            var firstElement = new ApplicationRobotAction(ApplicationRobotActionTarget.Suggestion, 0, 0, false);

            var actions = new List <ApplicationRobotAction>();

            for (var index = 1; index < _model.SuggestionLists.Count; index++)
            {
                var element = new ApplicationRobotAction(ApplicationRobotActionTarget.Suggestion, index, 0, false);
                actions.Add(element);
            }

            for (var index = 0; index < _model.SuggestionLists.Count; index++)
            {
                var list  = _model.SuggestionLists[index];
                var count = list.Count();
                if (1 < count)
                {
                    var element = new ApplicationRobotAction(ApplicationRobotActionTarget.Suggestion, index, list.Count() - 1, false);
                    actions.Add(element);
                }
            }

            AddRectangle(() => { _switchTarget = ApplicationRobotActionTarget.Suggestion; ShowSwitchInterface(); }, firstElement, actions.ToArray());
        }
        private void AddSwitchToHead()
        {
            var headElement = new ApplicationRobotAction(ApplicationRobotActionTarget.Head, 0, 0, false);
            var tailElement = new ApplicationRobotAction(ApplicationRobotActionTarget.Tail, _model.TailItems.Count - 1, 0, false);

            AddRectangle(() => { _switchTarget = ApplicationRobotActionTarget.Head; ShowSwitchInterface(); }, headElement, tailElement);
        }
예제 #3
0
        public TRect GetTargetRect(TControl target, ApplicationRobotAction action)
        {
            TControl control;

            switch (action.Target)
            {
            case ApplicationRobotActionTarget.Head:
                control = _headPanelHelper.GetControl(action.Index);
                break;

            case ApplicationRobotActionTarget.Tail:
                control = _tailPanelHelper.GetControl(action.Index);
                break;

            case ApplicationRobotActionTarget.Interstitial:
                control = _interstitialPanelHelper.GetControl(action.Index);
                break;

            case ApplicationRobotActionTarget.Suggestion:
            default:
                Debug.Assert(action.Target == ApplicationRobotActionTarget.Suggestion);
                control = _suggestionsPanelHelper.GetControl(action.Index, action.SubIndex);
                break;
            }

            var rect = _panel.GetControlRect(target, control);

            return(rect);
        }
        private void AddRectangle(Action action, ApplicationRobotAction robotAction, params ApplicationRobotAction[] otherRobotActions)
        {
            var overallRect = _panel.GetTargetRect(SwitchPanel, robotAction);

            foreach (var otherRobotAction in otherRobotActions)
            {
                var otherRect = _panel.GetTargetRect(SwitchPanel, otherRobotAction);
                overallRect.Union(otherRect);
            }

            AddRectangle(action, overallRect);
        }
        private void ShowSwitchInterface()
        {
            _switchClickCount     = 0;
            _switchTimer.Interval = TimeSpan.FromSeconds(10);
            _switchTimer.Start();

            SwitchPanel.Children.Clear();
            _targets.Clear();

            switch (_switchTarget)
            {
            case ApplicationRobotActionTarget.Head:
            {
                AddSwitchToInterstitials();

                AddSwitchToSuggestions();

                for (var index = 0; index < _model.HeadItems.Count; index++)
                {
                    var element = new ApplicationRobotAction(ApplicationRobotActionTarget.Head, index, 0, false);
                    AddRectangle(element);
                }

                for (var index = 0; index < _model.TailItems.Count; index++)
                {
                    var element = new ApplicationRobotAction(ApplicationRobotActionTarget.Tail, index, 0, false);
                    AddRectangle(element);
                }
            }
            break;

            case ApplicationRobotActionTarget.Tail:
            {
                AddSwitchToSuggestions();

                var list = _model.SuggestionLists[_switchSuggestionListsIndex];
                for (var subIndex = 0; subIndex < list.Count(); subIndex++)
                {
                    var element = new ApplicationRobotAction(ApplicationRobotActionTarget.Suggestion, _switchSuggestionListsIndex, subIndex, false);
                    AddRectangle(element);
                }
            }
            break;

            case ApplicationRobotActionTarget.Suggestion:
            {
                AddSwitchToHead();

                AddSwitchToInterstitials();

                for (var index = 0; index < _model.SuggestionLists.Count; index++)
                {
                    var element = new ApplicationRobotAction(ApplicationRobotActionTarget.Suggestion, index, 0, false);

                    var list  = _model.SuggestionLists[index];
                    var count = list.Count();

                    if (1 < count)
                    {
                        var lastElement = new ApplicationRobotAction(ApplicationRobotActionTarget.Suggestion, index, count - 1, false);

                        var uncapturedIndex = index;
                        AddRectangle(() => { _switchTarget = ApplicationRobotActionTarget.Tail; _switchSuggestionListsIndex = uncapturedIndex; ShowSwitchInterface(); }, element, lastElement);
                    }
                    else
                    {
                        AddRectangle(element);
                    }
                }
            }
            break;

            case ApplicationRobotActionTarget.Interstitial:
            default:
            {
                Debug.Assert(_switchTarget == ApplicationRobotActionTarget.Interstitial);

                AddSwitchToSuggestions();

                AddSwitchToHead();

                for (var index = 0; index < _model.SuggestionInterstitials.Count; index++)
                {
                    var element = new ApplicationRobotAction(ApplicationRobotActionTarget.Interstitial, index, 0, false);
                    AddRectangle(element);
                }
            }
            break;
            }
        }
        private void AddRectangle(ApplicationRobotAction robotAction)
        {
            Action action = () => robotAction.ExecuteItem(_model);

            AddRectangle(action, robotAction);
        }