Exemple #1
0
        /// <summary>Pushes a view to the stack and fires the necessary events.</summary>
        public void PushView(IBrowserView view)
        {
            Debug.Assert(view != null);
            Debug.Assert(view.gameObject.GetComponent <Canvas>() != null);

            if (this.m_viewStack.Contains(view))
            {
                return;
            }

            if (this.currentFocus != null)
            {
                this.onBeforeDefocusView.Invoke(this.currentFocus);
            }

            this.onBeforeShowView.Invoke(view);

            // NOTE(@jackson): The order here is important. Some views may check the view stack
            // OnEnable, and the gameObject must be active for the SetSortOrder to function correctly
            this.m_viewStack.Add(view);
            view.gameObject.SetActive(true);

            this.SetSortOrder(view, this.m_viewStack.Count - 1);
            this.onAfterFocusView.Invoke(view);
        }
Exemple #2
0
        /// <summary>Closes and hides a view.</summary>
        public void CloseWindowedView(IBrowserView view)
        {
            if (view == null || !view.gameObject.activeSelf)
            {
                return;
            }

            int viewIndex = this.m_viewStack.IndexOf(view);

            if (viewIndex >= 0)
            {
                if (this.currentFocus == view)
                {
                    this.PopView();
                }
                else
                {
                    this.onBeforeHideView.Invoke(view);

                    // NOTE(@jackson): The order here is important. Some views may check the view
                    // stack OnDisable.
                    this.m_viewStack.RemoveAt(viewIndex);
                    view.gameObject.SetActive(false);

                    for (int i = viewIndex; i < this.m_viewStack.Count; ++i)
                    {
                        this.SetSortOrder(this.m_viewStack[i], i);
                    }
                }
            }
        }
        public void ConstructorSuccess(IBrowserView browserView, ISocialNetBotEventService socialNetBotEventService)
        {
            var socialNetAuthorization =
                new SocialNetAuthorization(browserView, socialNetBotEventService);

            Assert.NotNull(socialNetAuthorization);
        }
 public void ConstructorFailed(
     IBrowserView browserView,
     ISocialNetBotEventService socialNetBotEventService)
 {
     Assert.Throws <ArgumentNullException>(()
                                           => new SocialNetAuthorization(browserView, socialNetBotEventService));
 }
        /// <summary>Gets the primary selection element for a given view.</summary>
        public GameObject ReacquireSelectionForView(IBrowserView view)
        {
            GameObject selection = null;

            if (this.m_lastViewSelection.TryGetValue(view, out selection) &&
                NavigationManager.IsValidSelection(selection))
            {
                return(selection);
            }

            foreach (var selectionPriority in view.onFocusPriority)
            {
                if (NavigationManager.IsValidSelection(selectionPriority.gameObject))
                {
                    return(selectionPriority.gameObject);
                }
            }

            foreach (var sel in view.gameObject.GetComponentsInChildren <Selectable>())
            {
                if (sel.IsActive() && sel.interactable)
                {
                    return(sel.gameObject);
                }
            }

            return(null);
        }
 public HomePagePresenter(GetItemsInteractor getItemsInteractor, Executor executor, IBrowserView view, ItemMapper maper)
 {
     _getItemsInteractor = getItemsInteractor;
     _executor           = executor;
     _view  = view;
     _maper = maper;
 }
Exemple #7
0
 public void SetUp()
 {
     _itemsGateway = Substitute.For <IItemsGateway>();
     _itemsMaper   = new ItemMapper();
     _view         = Substitute.For <IBrowserView>();
     _presenter    = new HomePagePresenter(new GetItemsInteractor(_itemsGateway),
                                           new Executor(),
                                           _view,
                                           _itemsMaper);
 }
Exemple #8
0
        // ---------[ Utility ]---------
        /// <summary>Sets the sorting order for the view.</summary>
        private void SetSortOrder(IBrowserView view, int stackIndex)
        {
            /**
             * NOTE(@jackson): overrideSorting MUST be set before the sortingOrder, otherwise the
             * sortingOrder value won't update until the next time the object is disabled->enabled
             **/
            Canvas viewCanvas = view.gameObject.GetComponent <Canvas>();

            viewCanvas.overrideSorting = true;
            viewCanvas.sortingOrder    = this.m_rootViewSortOrder + stackIndex * ViewManager.SORTORDER_SPACING;
        }
        /************************************************
         * Constructors
         ***********************************************/
        /// <summary>
        /// Initializes a new <see cref="BrowserViewPresenter"/> instance.
        /// </summary>
        /// <param name="view">
        /// The view the presenter will control.
        /// </param>
        /// <param name="regionManager">
        /// The region manager that can be used to place views.
        /// </param>
        /// <param name="searchEngine">
        /// The search engine that will provide results.
        /// </param>
        public BrowserViewPresenter(IBrowserView view, IRegionManagerService regionManager, ISearchEngine searchEngine)
        {
            // Store locally
            this.view = view;
            this.regionManager = regionManager;
            this.searchEngine = searchEngine;

            // Subscribe to selection events from the view to bubble up
            view.SelectedResultChanged += new EventHandler(view_SelectedResultChanged);

            // Subscribe to search result notifications
            searchEngine.SearchComplete += new EventHandler<SearchCompleteEventArgs>(searchEngine_SearchComplete);
        }
 public BrowserPresenter(IBrowserLogic logic, IBrowserView view) {
     this._logic = logic;
     this._view = view;
     this._progress.ProgressChanged += (sender, progress) => {
                                           this._view.UpdateProgress(
                                               progress.ShowPercent
                                                   ? string.Format("{0}%",
                                                       progress.PercentDone.ToString(
                                                           CultureInfo.InvariantCulture))
                                                   : string.Empty,
                                               progress.OperationText, progress.Cancellable);
                                           this._downloadedLocation = progress.DownloadedPath;
                                       };
 }
 public BrowserPresenter(IBrowserLogic logic, IBrowserView view)
 {
     _logic = logic;
     _view  = view;
     _progress.ProgressChanged += (sender, progress) => {
         _view.UpdateProgress(
             progress.ShowPercent
                                              ? string.Format("{0}%",
                                                              progress.PercentDone.ToString(
                                                                  CultureInfo.InvariantCulture))
                                              : string.Empty,
             progress.OperationText, progress.Cancellable);
         _downloadedLocation = progress.DownloadedPath;
     };
 }
        // ---------[ Event Handlers ]---------
        /// <summary>Makes the view uninteractable and deselects/dehighlights objects.</summary>
        public void OnDefocusView(IBrowserView view)
        {
            if (EventSystem.current.currentSelectedGameObject != null)
            {
                EventSystem.current.SetSelectedGameObject(null);
            }

            if (this.isMouseMode && this.m_currentHoverSelectable != null)
            {
                ExecuteEvents.Execute(this.m_currentHoverSelectable.gameObject,
                                      new PointerEventData(EventSystem.current),
                                      ExecuteEvents.pointerExitHandler);
            }

            view.canvasGroup.interactable = false;
        }
Exemple #13
0
        /// <summary>Pops a view from the stack and fires the necessary events.</summary>
        public void PopView()
        {
            Debug.Assert(this.m_viewStack.Count > 0);

            IBrowserView view = this.currentFocus;

            this.onBeforeDefocusView.Invoke(view);
            this.onBeforeHideView.Invoke(view);

            // NOTE(@jackson): The order here is important. Some views may check the view stack OnDisable
            this.m_viewStack.RemoveAt(this.m_viewStack.Count - 1);
            view.gameObject.SetActive(false);

            if (this.currentFocus != null)
            {
                this.onAfterFocusView.Invoke(this.currentFocus);
            }
        }
Exemple #14
0
        /// <summary>Focuses the given view, showing and hiding views as necessary.</summary>
        public void FocusView(IBrowserView view)
        {
            if (view == null || view == this.currentFocus)
            {
                return;
            }

            if (this.currentFocus != null)
            {
                this.onBeforeDefocusView.Invoke(this.currentFocus);
            }

            // knock off views above the desired one
            if (view.isRootView || this.m_viewStack.Contains(view))
            {
                while (this.m_viewStack.Count > 0 &&
                       this.currentFocus != view)
                {
                    IBrowserView closingView = this.currentFocus;

                    this.onBeforeHideView.Invoke(closingView);

                    // NOTE(@jackson): The order here is important. Some views may check the view stack OnDisable
                    this.m_viewStack.RemoveAt(this.m_viewStack.Count - 1);
                    closingView.gameObject.SetActive(false);
                }
            }

            // push the view if necessary
            if (this.currentFocus != view)
            {
                this.onBeforeShowView.Invoke(view);

                // NOTE(@jackson): The order here is important. Some views may check the view stack
                // OnEnable, and the gameObject must be active for the SetSortOrder to function correctly
                this.m_viewStack.Add(view);
                view.gameObject.SetActive(true);

                this.SetSortOrder(view, this.m_viewStack.Count - 1);
            }

            this.onAfterFocusView.Invoke(view);
        }
Exemple #15
0
        /// <summary>Sets the sorting order of the attached canvas to be directly behind the open window.</summary>
        public void UpdateSortingOrder(IBrowserView view)
        {
            bool validView = false;

            if (view != null &&
                !view.isRootView &&
                view.gameObject != null)
            {
                Canvas viewCanvas = view.gameObject.GetComponent <Canvas>();

                if (viewCanvas != null)
                {
                    int targetSortOrder = viewCanvas.sortingOrder - 1;
                    this.canvas.sortingOrder = targetSortOrder;

                    validView = true;
                }
            }

            this.gameObject.SetActive(validView);
        }
        /// <summary>Handles any necessary selection corrections and storage.</summary>
        private void LateUpdate()
        {
            IBrowserView currentView = ViewManager.instance.currentFocus;

            if (currentView == null)
            {
                return;
            }

            GameObject currentSelection = EventSystem.current.currentSelectedGameObject;

            // mouse mode
            if (this.isMouseMode)
            {
                this.m_currentHoverSelectable = NavigationManager.GetHoveredSelectable();

                if (this.m_currentHoverSelectable != null &&
                    NavigationManager.IsValidSelection(this.m_currentHoverSelectable.gameObject) &&
                    this.m_currentHoverSelectable.navigation.mode != Navigation.Mode.None)
                {
                    currentSelection = this.m_currentHoverSelectable.gameObject;
                }
            }
            // controller/keyboard mode
            else
            {
                // on controller/keyboard input reset selection
                if (!NavigationManager.IsValidSelection(currentSelection))
                {
                    currentSelection = this.ReacquireSelectionForView(currentView);
                    EventSystem.current.SetSelectedGameObject(currentSelection);
                }
            }

            // store
            if (currentSelection != null)
            {
                this.m_lastViewSelection[ViewManager.instance.currentFocus] = currentSelection;
            }
        }
Exemple #17
0
        /// <summary>Sends events at the end of the frame.</summary>
        private System.Collections.IEnumerator DelayedViewFocusOnStart(List <IBrowserView> viewStack)
        {
            yield return(null);

            if (this != null && viewStack != null && viewStack.Count > 0)
            {
                IBrowserView view = null;
                this.m_viewStack = viewStack;

                for (int i = 0; i < viewStack.Count - 1; ++i)
                {
                    view = viewStack[i];

                    this.SetSortOrder(view, i);
                    this.onBeforeDefocusView.Invoke(view);
                }

                view = viewStack[viewStack.Count - 1];

                this.SetSortOrder(view, viewStack.Count - 1);
                this.onAfterFocusView.Invoke(view);
            }
        }
        /// <summary>Set the selection for a change in focus.</summary>
        public void OnFocusView(IBrowserView view)
        {
            view.canvasGroup.interactable = true;

            if (this.menuBar != null)
            {
                this.menuBar.interactable = view.isRootView;
            }

            GameObject newSelection = EventSystem.current.currentSelectedGameObject;

            if (this.isMouseMode)
            {
                this.m_currentHoverSelectable = NavigationManager.GetHoveredSelectable();
                if (this.m_currentHoverSelectable != null)
                {
                    ExecuteEvents.Execute(this.m_currentHoverSelectable.gameObject,
                                          new PointerEventData(EventSystem.current),
                                          ExecuteEvents.pointerEnterHandler);
                }

                newSelection = null;
            }
            else
            {
                if (!NavigationManager.IsValidSelection(newSelection))
                {
                    newSelection = this.ReacquireSelectionForView(view);
                }
            }

            if (newSelection != EventSystem.current.currentSelectedGameObject)
            {
                EventSystem.current.SetSelectedGameObject(newSelection);
            }
        }
        /// <summary>Passes any of the necessary inputs onto the View.</summary>
        public void ProcessViewInputs(IBrowserView view)
        {
            Debug.Assert(view != null);

            ViewControlBindings bindings = view.gameObject.GetComponent <ViewControlBindings>();

            if (bindings != null)
            {
                // process button bindings
                foreach (ViewControlBindings.ButtonBinding buttonBinding in bindings.buttonBindings)
                {
                    #if UNITY_EDITOR
                    try
                    {
                        Input.GetButton(buttonBinding.inputName);
                    }
                    catch (System.ArgumentException e)
                    {
                        Debug.LogWarning("[mod.io] The ViewControlBindings for " + view.gameObject.name
                                         + " contain a button not defined in the Input Manager.\n"
                                         + e.Message,
                                         view.gameObject);
                        continue;
                    }
                    #endif

                    var condition = ViewControlBindings.ButtonTriggerCondition.OnDown;
                    if ((buttonBinding.condition & condition) == condition &&
                        Input.GetButtonDown(buttonBinding.inputName))
                    {
                        buttonBinding.actions.Invoke();
                    }

                    condition = ViewControlBindings.ButtonTriggerCondition.OnHeld;
                    if ((buttonBinding.condition & condition) == condition &&
                        Input.GetButton(buttonBinding.inputName))
                    {
                        buttonBinding.actions.Invoke();
                    }

                    condition = ViewControlBindings.ButtonTriggerCondition.OnUp;
                    if ((buttonBinding.condition & condition) == condition &&
                        Input.GetButtonUp(buttonBinding.inputName))
                    {
                        buttonBinding.actions.Invoke();
                    }
                }

                // process keycode bindings
                foreach (ViewControlBindings.KeyCodeBinding keyBinding in bindings.keyCodeBindings)
                {
                    var condition = ViewControlBindings.ButtonTriggerCondition.OnDown;
                    if ((keyBinding.condition & condition) == condition &&
                        Input.GetKeyDown(keyBinding.keyCode))
                    {
                        keyBinding.actions.Invoke();
                    }

                    condition = ViewControlBindings.ButtonTriggerCondition.OnHeld;
                    if ((keyBinding.condition & condition) == condition &&
                        Input.GetKey(keyBinding.keyCode))
                    {
                        keyBinding.actions.Invoke();
                    }

                    condition = ViewControlBindings.ButtonTriggerCondition.OnUp;
                    if ((keyBinding.condition & condition) == condition &&
                        Input.GetKeyUp(keyBinding.keyCode))
                    {
                        keyBinding.actions.Invoke();
                    }
                }

                // process axis bindings
                foreach (ViewControlBindings.AxisBinding axisBinding in bindings.axisBindings)
                {
                    #if UNITY_EDITOR
                    try
                    {
                        Input.GetAxis(axisBinding.inputName);
                    }
                    catch (System.ArgumentException e)
                    {
                        Debug.LogWarning("[mod.io] The ViewControlBindings for " + view.gameObject.name
                                         + " contain an axis not defined in the Input Manager.\n"
                                         + e.Message,
                                         view.gameObject);
                        continue;
                    }
                    #endif

                    // get values
                    float axisValue     = Input.GetAxisRaw(axisBinding.inputName);
                    float previousValue = 0f;
                    if (!this.m_lastAxisValues.TryGetValue(axisBinding.inputName, out previousValue))
                    {
                        previousValue = axisValue;
                    }
                    this.m_lastAxisValues[axisBinding.inputName] = axisValue;

                    // process
                    bool isGreater  = axisValue > axisBinding.thresholdValue;
                    bool wasGreater = previousValue > axisBinding.thresholdValue;
                    bool isLess     = axisValue < axisBinding.thresholdValue;
                    bool wasLess    = previousValue < axisBinding.thresholdValue;
                    bool isEqual    = !isGreater && !isLess;
                    bool wasEqual   = !wasGreater && !wasLess;


                    var condition = ViewControlBindings.AxisTriggerCondition.BecameGreaterThan;
                    if ((axisBinding.condition & condition) == condition &&
                        isGreater && !wasGreater)
                    {
                        axisBinding.actions.Invoke(axisValue);
                    }

                    condition = ViewControlBindings.AxisTriggerCondition.BecameLessThan;
                    if ((axisBinding.condition & condition) == condition &&
                        isLess && !wasLess)
                    {
                        axisBinding.actions.Invoke(axisValue);
                    }

                    condition = ViewControlBindings.AxisTriggerCondition.BecameEqualTo;
                    if ((axisBinding.condition & condition) == condition &&
                        isEqual && !wasEqual)
                    {
                        axisBinding.actions.Invoke(axisValue);
                    }

                    condition = ViewControlBindings.AxisTriggerCondition.IsGreaterThan;
                    if ((axisBinding.condition & condition) == condition &&
                        isGreater)
                    {
                        axisBinding.actions.Invoke(axisValue);
                    }

                    condition = ViewControlBindings.AxisTriggerCondition.IsLessThan;
                    if ((axisBinding.condition & condition) == condition &&
                        isLess)
                    {
                        axisBinding.actions.Invoke(axisValue);
                    }

                    condition = ViewControlBindings.AxisTriggerCondition.IsEqualTo;
                    if ((axisBinding.condition & condition) == condition &&
                        isEqual)
                    {
                        axisBinding.actions.Invoke(axisValue);
                    }
                }
            }
        }
Exemple #20
0
 public SocialNetAuthorization(IBrowserView browserView, ISocialNetBotEventService eventService)
 {
     _browserView  = browserView ?? throw new ArgumentNullException(nameof(browserView));
     _eventService = eventService ?? throw new ArgumentNullException(nameof(eventService));
 }
Exemple #21
0
        /// <summary>Gathers the views in the scene.</summary>
        private void Start()
        {
            this.FindViews();

            // - get the parent canvas for the views -
            IBrowserView firstView = this.m_views[0];

            Debug.Assert(firstView != null,
                         "[mod.io] No views found in the scene."
                         + " Please ensure the scene contains at least one IBrowserView component"
                         + " before using the ViewManager.", this);

            Transform firstViewParent = firstView.gameObject.transform.parent;

            Debug.Assert(firstViewParent != null,
                         "[mod.io] The first found view in the scene appears to be a root object."
                         + " ViewManager expects the views to be contained under a canvas object to"
                         + " function correctly.", firstView.gameObject);

            Canvas parentCanvas = firstViewParent.GetComponentInParent <Canvas>();

            Debug.Assert(parentCanvas != null,
                         "[mod.io] The first found view in the scene has no parent canvas component."
                         + " ViewManager expects the views to be contained under a canvas object to"
                         + " function correctly.", firstView.gameObject);

            #if UNITY_EDITOR
            if (this.m_views.Length > 1)
            {
                foreach (IBrowserView view in this.m_views)
                {
                    Transform parentTransform = view.gameObject.transform.parent;
                    if (parentTransform == null ||
                        parentCanvas != parentTransform.GetComponentInParent <Canvas>())
                    {
                        Debug.LogError("[mod.io] All the views must have the same parent canvas"
                                       + " in order for the ViewManager to function correctly.", this);

                        this.enabled = false;
                        return;
                    }
                }
            }
            #endif

            // set the sorting order base
            this.m_rootViewSortOrder = parentCanvas.sortingOrder + ViewManager.SORTORDER_SPACING;

            // add canvas + raycaster components to views
            foreach (IBrowserView view in this.m_views)
            {
                Canvas viewCanvas = view.gameObject.GetComponent <Canvas>();

                if (viewCanvas == null)
                {
                    viewCanvas = view.gameObject.AddComponent <Canvas>();
                    viewCanvas.overridePixelPerfect     = false;
                    viewCanvas.additionalShaderChannels = AdditionalCanvasShaderChannels.None;
                }

                GraphicRaycaster raycaster = view.gameObject.GetComponent <GraphicRaycaster>();

                if (raycaster == null)
                {
                    raycaster = view.gameObject.AddComponent <GraphicRaycaster>();
                    raycaster.ignoreReversedGraphics = true;
                    raycaster.blockingObjects        = GraphicRaycaster.BlockingObjects.None;
                }
            }

            // - create the initial view stack -
            List <IBrowserView> initViewStack = new List <IBrowserView>();

            if (this.explorerView != null &&
                this.explorerView.isActiveAndEnabled)
            {
                initViewStack.Add(this.explorerView);
            }

            if (this.subscriptionsView != null &&
                this.subscriptionsView.isActiveAndEnabled)
            {
                if (initViewStack.Count == 1)
                {
                    initViewStack[0] = this.subscriptionsView;
                    this.explorerView.gameObject.SetActive(false);
                }
                else
                {
                    initViewStack.Add(this.subscriptionsView);
                }
            }

            if (initViewStack.Count == 0)
            {
                if (this.explorerView != null)
                {
                    initViewStack.Add(this.explorerView);

                    this.explorerView.gameObject.SetActive(true);
                }
                else if (this.subscriptionsView != null)
                {
                    initViewStack.Add(this.subscriptionsView);

                    this.subscriptionsView.gameObject.SetActive(true);
                }
                #if DEBUG
                else
                {
                    Debug.Log("[mod.io] No main view found in the scene."
                              + " Please consider adding either an ExplorerView or"
                              + " a SubscriptionsView to the scene.", this);
                }
                #endif
            }

            if (this.inspectorView != null &&
                this.inspectorView.isActiveAndEnabled)
            {
                initViewStack.Add(this.inspectorView);
            }

            if (this.loginDialog != null &&
                this.loginDialog.isActiveAndEnabled)
            {
                initViewStack.Add(this.loginDialog);
            }

            this.StartCoroutine(DelayedViewFocusOnStart(initViewStack));
        }