Beispiel #1
0
 public override void Setup(AbstractView view)
 {
     _button           = GetComponent <Button>();
     _buttonTransition = _button.transition;
     _button.onClick.AddListener(ButtonClicked);
     base.Setup(view);
 }
Beispiel #2
0
 public override void Setup(AbstractView view)
 {
     _registeredInputDownCallbacks            = new List <Action <AbstractButton> >();
     _registeredInputDownCallbacksNoButton    = new List <Action>();
     _registeredInputPressedCallbacks         = new List <Action <AbstractButton> >();
     _registeredInputPressedCallbacksNoButton = new List <Action>();
     base.Setup(view);
 }
 /// <summary>
 /// Requests all open overlays to be forced close.
 /// </summary>
 public void RequestOverlayForceCloseAll()
 {
     foreach (Type t in _currentOverlays.Keys)
     {
         AbstractView view = _currentOverlays[t];
         view.OnHideComplete();
     }
 }
 /// <summary>
 /// Requests the overlay to force close.
 /// This will skip the HideStart() method of the target overlay.
 /// </summary>
 /// <param name="overlayType">Overlay type.</param>
 public void RequestOverlayForceClose(Type overlayType)
 {
     if (_currentOverlays.ContainsKey(overlayType))
     {
         AbstractView view = _currentOverlays[overlayType];
         view.OnHideComplete();
     }
 }
        /// <summary>
        /// Requests the screen with data.
        /// </summary>
        /// <param name="screenType">Screen type.</param>
        /// <param name="data">Data.</param>
        public void RequestView(Type screenType, SObject data)
        {
            if (_targetScreen == null || (_targetScreen.GetType() != screenType && !_targetScreen.IsSettingUp))
            {
                GameObject obj = GameObject.Instantiate(Resources.Load(_scaffoldingConfig.ViewPrefabPath(screenType.Name) + screenType.Name)) as GameObject;

                                #if UNITY_4_6 || UNITY_5
                obj.transform.SetParent(_scaffoldingConfig.DetermineParentGameObjectPath().transform);
                                #else
                obj.transform.parent = _scaffoldingConfig.DetermineParentGameObjectPath().transform;
                                #endif
                obj.transform.name = screenType.Name;

                _targetScreen = obj.GetComponent <AbstractView>();

                string s = screenType.Name + "Model";
                Type   t = ScaffoldingConfig.GetType(s);

                if (t != null)
                {
                    AbstractModel model = FindObjectOfType(t) as AbstractModel;
                    if (model != null)
                    {
                        model.RegisterView(_targetScreen);
                    }
                }

                if (_scaffoldingConfig.ScaffoldingEnableAllGameobjects)
                {
                    _targetScreen.gameObject.EnableAllChildren();
                }
                _targetScreen.Setup(this);


                obj.SetActive(false);

                _lastScreen = _currentScreen;

                _targetScreenData = data;

                if (_currentScreen != null)
                {
                    if (_targetScreen.showingType == AbstractView.ShowingTypes.ShowImmediately)
                    {
                        ScreenClose(_currentScreen.GetType());
                        ScreenOpen();
                    }
                    else
                    {
                        ScreenClose(_currentScreen.GetType());
                    }
                }
                else
                {
                    ScreenOpen();
                }
            }
        }
        private void OverlayHide(Type screenType)
        {
            AbstractView view = _currentOverlays[screenType];

            view.OnHideStart();
            if (OverlayClosed != null)
            {
                OverlayClosed(view);
            }
        }
Beispiel #7
0
 /// <summary>
 /// Gets called when the view associated with this model is closed.
 /// </summary>
 public virtual void ViewClosed(AbstractView view)
 {
     if (knownViews.Contains(view))
     {
         view.ViewEvent       -= HandleViewEvent;
         view.ViewClosedEvent -= HandleViewClosedEvent;
         knownViews.Remove(view);
         view = null;
     }
 }
Beispiel #8
0
        /// <summary>
        /// When the view associated with this model is opened, it gets registered with the model here.
        /// This also registers the default ViewEvent delegate, for quick communication between registered views and the model.
        /// </summary>
        /// <param name="view">View.</param>
        public virtual void RegisterView(AbstractView view)
        {
            if (knownViews == null)
            {
                knownViews = new List <AbstractView>();
            }

            knownViews.Add(view);
            view.ViewEvent       += HandleViewEvent;
            view.ViewClosedEvent += HandleViewClosedEvent;
        }
        /// <summary>
        /// Requests the overlay open with data.
        /// </summary>
        /// <param name="overlayType">Overlay type.</param>
        /// <param name="data">Data.</param>
        public void RequestOverlay(Type overlayType, SObject viewData)
        {
            if (!_currentOverlays.ContainsKey(overlayType))
            {
                GameObject obj = GameObject.Instantiate(Resources.Load(_scaffoldingConfig.ViewPrefabPath(overlayType.Name) + overlayType.Name)) as GameObject;

                                #if UNITY_4_6 || UNITY_5
                obj.transform.SetParent(_scaffoldingConfig.DetermineParentGameObjectPath().transform);
                                #else
                obj.transform.parent = _scaffoldingConfig.DetermineParentGameObjectPath().transform;
                                #endif

                obj.transform.name = overlayType.Name;

                string s = overlayType.Name + "Model";
                Type   t = ScaffoldingConfig.GetType(s);

                if (t != null)
                {
                    AbstractModel model = FindObjectOfType(t) as AbstractModel;
                    if (model != null)
                    {
                        model.RegisterView(_targetScreen);
                    }
                }

                _targetOverlay = obj.GetComponent <AbstractView>();

                if (_scaffoldingConfig.ScaffoldingEnableAllGameobjects)
                {
                    _targetOverlay.gameObject.EnableAllChildren();
                }
                _targetOverlay.Setup(this);
                obj.SetActive(false);

                if (viewData != null && viewData.GetBool("Scaffolding:DisableInputsOnOverlay"))
                {
                    if (_disabledInputsOnView.ContainsKey(_currentScreen.GetType()))
                    {
                        _disabledInputsOnView[_currentScreen.GetType()].Add(overlayType);
                    }
                    else
                    {
                        List <Type> overlays = new List <Type>();
                        overlays.Add(overlayType);
                        _disabledInputsOnView.Add(_currentScreen.GetType(), overlays);
                    }
                    _currentScreen.DisableAllInputs();
                }

                _currentOverlays.Add(overlayType, _targetOverlay);
                OverlayOpen(_targetOverlay.GetType(), viewData);
            }
        }
 internal void ScreenShowComplete(Type screenType)
 {
     if (_currentOverlays.ContainsKey(screenType))
     {
         _currentOverlays[screenType].OnShowComplete();
     }
     else
     {
         _lastScreen    = _currentScreen;
         _currentScreen = _targetScreen;
         _targetScreen.OnShowComplete();
     }
 }
        /// <summary>
        /// Request to reopen an already open view
        /// </summary>
        /// <param name="screenType">Screen type.</param>
        /// <param name="viewData">View data.</param>
        public void RequestForceReopenView(Type screenType, SObject viewData)
        {
            Type tp = screenType;

            //essentially resetting the view system here.
            //resetting everything back to nothing.
            if (tp == _currentScreen.GetType())
            {
                _lastScreen = _currentScreen;
                ScreenClosedComplete(tp);
            }
            _targetScreen  = null;
            _currentScreen = null;
            RequestView(tp, viewData);
        }
        private void OverlayOpen(Type screenType, SObject data)
        {
            AbstractView view = _currentOverlays[screenType];

            view.gameObject.SetActive(true);
            view.OnShowStart(data);

            if (_loadingOverlay == screenType)
            {
                RequestView(_loadingOverlayTargetView, _loadingOverlayTargetViewData);
            }

            if (OverlayOpened != null)
            {
                OverlayOpened(view);
            }
        }
        /************************************************
        * for override
        ************************************************/
        /// <summary>
        /// Run by the view during it's setup phase.
        /// </summary>
        public virtual void Setup(AbstractView view)
        {
            _view         = view;
            _inputManager = GameObject.FindObjectOfType(typeof(InputManager)) as InputManager;

            if (_inputManager == null)
            {
                GameObject go = new GameObject();
                go.name = "InputManager";
                go.AddComponent <InputManager>();
                _inputManager = go.GetComponent <InputManager>();
            }

            _inputManager.EventPressed      += HandleEventPressed;
            _inputManager.EventReleased     += HandleEventReleased;
            _inputManager.EventDragged      += HandleEventDragged;
            _inputManager.EventDraggedDelta += HandleEventDraggedDelta;
        }
        /************************************************
        * PinchThisInput setup.
        ************************************************/
        /// <summary>
        /// Run by the view during it's setup phase.
        /// </summary>
        /// <param name="view">View.</param>
        public override void Setup(AbstractView view)
        {
            base.Setup(view);
            RegisterPinchCallback(HandlePinch);

            _collider = gameObject.GetComponent <Collider>();
            if (_collider == null)
            {
                _collider = gameObject.AddComponent <BoxCollider>();
            }

            _inputCamera = GameObject.Find(inputCamera).GetComponent <Camera>();

            if (_inputCamera == null)
            {
                _inputCamera = Camera.main;
            }
        }
Beispiel #15
0
        /// <summary>
        /// The startup sequence. Scaffolding starts from here.
        /// </summary>
        public void Init()
        {
            if (DontDestroyThisOnLoad)
            {
                GameObject.DontDestroyOnLoad(gameObject);
            }

            _scaffoldingConfig    = Resources.Load <ScaffoldingConfig>("SCConfig");
            _disabledInputsOnView = new Dictionary <Type, List <Type> >();

            _currentOverlays = new Dictionary <Type, AbstractView>();
            ScaffoldingStartingView sv = _scaffoldingConfig.GetViewDataForScene(Application.loadedLevelName);
            Type t = ScaffoldingConfig.GetType(sv.StartingViewName);

            if (t != null && GameObject.FindObjectOfType <AbstractView>() == null)
            {
                switch (sv.StartingViewType)
                {
                case ViewType.View:
                    RequestView(t);
                    break;

                case ViewType.Overlay:
                    RequestOverlay(t);
                    break;
                }
            }
            else
            {
                AbstractView v = GameObject.FindObjectOfType <AbstractView>();
                if (v != null)
                {
                    Destroy(v.gameObject);
                    RequestView(v.GetType());
                }
                else
                {
                    Debug.LogWarning("Scaffolding -- ViewManager: No views assigned to start with!");
                }
            }
        }
Beispiel #16
0
        /// <summary>
        /// The startup sequence. Scaffolding starts from here.
        /// </summary>
        public void Init()
        {
            _scaffoldingConfig    = Resources.Load <ScaffoldingConfig>("SCConfig");
            _disabledInputsOnView = new Dictionary <Type, List <Type> >();

            _currentOverlays = new Dictionary <Type, AbstractView>();

            Type t = System.Type.GetType(_scaffoldingConfig.StartingView);

            if (t != null && GameObject.FindObjectOfType <AbstractView>() == null)
            {
                switch (_scaffoldingConfig.StartingViewType)
                {
                case ViewType.View:
                    RequestView(t);
                    break;

                case ViewType.Overlay:
                    RequestOverlay(t);
                    break;
                }
            }
            else
            {
                AbstractView v = GameObject.FindObjectOfType <AbstractView>();
                if (v != null)
                {
                    Destroy(v.gameObject);
                    RequestView(v.GetType());
                }
                else
                {
                    Debug.LogWarning("Scaffolding -- ViewManager: No views assigned to start with!");
                }
            }
        }
Beispiel #17
0
 public virtual void RegisterViewToModel(AbstractView view, AbstractModel model)
 {
     _manager.RegisterViewToModel(view, model);
 }
Beispiel #18
0
 /// <summary>
 /// Handles the view event. Called by any view registered to the model.
 /// </summary>
 /// <param name="sender">Sender.</param>
 /// <param name="obj">Object.</param>
 public virtual void HandleViewEvent(AbstractView sender, SObject obj)
 {
 }
Beispiel #19
0
 /// <summary>
 /// Handles the view closed event. Automatically called when any view registered to this model is closed.
 /// This deregisters the view from the model.
 /// </summary>
 /// <param name="sender">Sender.</param>
 /// <param name="obj">Object.</param>
 public virtual void HandleViewClosedEvent(AbstractView sender, SObject obj)
 {
     ViewClosed(sender);
 }
 /// <summary>
 /// The inputs clean up phase.
 /// </summary>
 public virtual void Cleanup()
 {
     _view         = null;
     _inputManager = null;
     _collider     = null;
 }
Beispiel #21
0
        /************************************************
        * Button setup.
        ************************************************/
        /// <summary>
        /// Run by the view during it's setup phase.
        /// </summary>
        /// <param name="view">View.</param>
        public override void Setup(AbstractView view)
        {
            if (!transform.FindChild("_up"))
            {
                Debug.LogError("Scaffolding -- Button: MISSING THE UP BUTTON STATE ON " + this.name + " ON VIEW " + view.name);
            }
            else
            {
                _upObj = transform.FindChild("_up").gameObject;
            }

            if (!transform.FindChild("_down"))
            {
                Debug.LogError("Scaffolding -- Button: MISSING THE DOWN BUTTON STATE ON " + this.name + " ON VIEW " + view.name);
            }
            else
            {
                _downObj = transform.FindChild("_down").gameObject;
            }

            if (transform.FindChild("_inactive"))
            {
                _inactiveObj = transform.FindChild("_inactive").gameObject;
            }


            _upCollider = _upObj.GetComponentInChildren <Collider>();
            if (_upCollider == null)
            {
                Debug.LogError("Scaffolding -- Button: No collider found on the up state of button " + this.name + " on view " + view.name);
            }

            _downCollider = _downObj.GetComponentInChildren <Collider>();
            if (_downCollider == null)
            {
                Debug.LogError("Scaffolding -- Button: No collider found on the down state of button " + this.name + " on view " + view.name);
            }

            _collider = _upCollider;

            if (_collider == null)
            {
                Debug.LogError("Scaffolding -- Button: Cant find a collider to use in " + this.name + " on view " + view.name);
            }

            if (inputCamera == null)
            {
                inputCamera = Camera.main.transform.name;
            }

            _inputCamera = GameObject.Find(inputCamera).GetComponent <Camera>();

            if (_inputCamera == null)
            {
                _inputCamera = Camera.main;
            }

            ChangeState(ButtonState.Up);

            base.Setup(view);
        }
Beispiel #22
0
 /************************************************
 * RotateInput setup.
 ************************************************/
 /// <summary>
 /// Run by the view during it's setup phase.
 /// </summary>
 /// <param name="view">View.</param>
 public override void Setup(AbstractView view)
 {
     base.Setup(view);
     _trackers = new Dictionary <int, InputTracker>();
     _angle    = -1;
 }
        /************************************************
        * Model
        ************************************************/

        public void RegisterViewToModel(AbstractView view, AbstractModel model)
        {
            model.RegisterView(view);
        }
 public void UnRegisterViewFromModel(AbstractView view)
 {
     view.NotifyModelOfViewClosed();
 }