コード例 #1
0
ファイル: GourdUICore.cs プロジェクト: mjstephens/GourdUI
 bool IGourdUI.UIViewIsValidForDevice(UIViewConfigData viewData, AppDeviceData deviceData)
 {
     return(UIViewFilterResolver.ViewFilterResult(
                viewData.filterData.positiveFilters.ToArray(),
                viewData.filterData.negativeFilters.ToArray(),
                deviceData));
 }
コード例 #2
0
        /// <summary>
        /// Filters view based on platform.
        /// </summary>
        /// <param name="filter">Filter data for view.</param>
        /// <param name="data">Current device data to filter against.</param>
        /// <returns>Returns true if view passes validation for platform.</returns>
        /// <exception cref="ArgumentOutOfRangeException">Thrown in event of invalid switch.</exception>
        private static bool ViewPlatformFilterIsValid(
            UIViewFilterPlatformConfigData filter,
            AppDeviceData data)
        {
            bool valid;

            switch (data.platform)
            {
            case CoreDevice.DevicePlatform.Desktop:
                valid = filter.desktop;
                break;

            case CoreDevice.DevicePlatform.Console:
                valid = filter.console;
                break;

            case CoreDevice.DevicePlatform.Mobile:
                valid = filter.mobile;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(valid);
        }
コード例 #3
0
ファイル: GourdUICore.cs プロジェクト: mjstephens/GourdUI
 void IGourdUI.OnAppDeviceUpdated(AppDeviceData deviceData)
 {
     foreach (var screen in _currentUIScreens)
     {
         screen.OnAppDeviceDataUpdated(deviceData);
     }
 }
コード例 #4
0
        /// <summary>
        /// Sets the valid UIView as active once it's been found.
        /// </summary>
        /// <param name="deviceData"></param>
        /// <param name="viewData"></param>
        private void SetValidUIView(AppDeviceData deviceData, UIViewConfigData viewData)
        {
            // Make sure we're not setting the same UI view
            if (_viewContract != null)
            {
                if (_currentViewData.prefab != viewData.prefab)
                {
                    DestroyCurrentView();
                }
                else
                {
                    _viewContract.OnAppDeviceDataUpdated(deviceData);
                    return;
                }
            }

            // Instantiate new view
            _currentViewData = viewData;

            // Instantiate the view prefab, hook up contract
            GameObject vObj = Instantiate(viewData.prefab, transform);

            _viewContract = vObj.GetComponent <V>();
            vObj.GetComponent <UIView <C, S> >().screenContract = this as C;
            _viewContract.OnViewInstantiated(deviceData, !_screenHasBeenInstantiated);

            // We can optionally reset the state between view changes
            if (_configBaseData.resetStateBetweenViewChanges)
            {
                ResetScreenState();
            }

            _viewContract.ApplyScreenStateToView(state);
            _viewContract.Show();
        }
コード例 #5
0
        /// <summary>
        /// Filters view based on input device.
        /// </summary>
        /// <param name="filter">Filter data for view.</param>
        /// <param name="data">Current device data to filter against.</param>
        /// <returns>Returns true if view passes validation for input.</returns>
        /// <exception cref="ArgumentOutOfRangeException">Thrown in event of invalid switch.</exception>
        private static bool ViewInputFilterIsValid(
            UIViewFilterInputConfigData filter,
            AppDeviceData data)
        {
            bool valid;

            switch (data.input)
            {
            case CoreDevice.DeviceInput.MouseKB:
                valid = filter.mouseKB;
                break;

            case CoreDevice.DeviceInput.Controller:
                valid = filter.controller;
                break;

            case CoreDevice.DeviceInput.Touchscreen:
                valid = filter.touchscreen;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(valid);
        }
コード例 #6
0
        public virtual void OnViewInstantiated(AppDeviceData deviceData, bool isScreenInstantiation)
        {
            // Gather view canvas
            viewCanvas = GetComponent <Canvas>();

            // Gather filter components in hierarchy
            _filterComponents = GetComponentsInChildren <UIViewFilterComponent>();
            FilterComponents(deviceData);
        }
コード例 #7
0
 /// <summary>
 /// Cycles through filter components in this view and evaluates
 /// </summary>
 /// <param name="deviceData"></param>
 private void FilterComponents(AppDeviceData deviceData)
 {
     foreach (var c in _filterComponents)
     {
         c.gameObject.SetActive(
             UIViewFilterResolver.ViewFilterResult(
                 c.filterData.positiveFilters.ToArray(),
                 c.filterData.negativeFilters.ToArray(),
                 deviceData));
     }
 }
コード例 #8
0
ファイル: CoreDevice.cs プロジェクト: mjstephens/GourdUI
        /// <summary>
        /// Sets the current device data.
        /// </summary>
        /// <returns></returns>
        private static bool SetDeviceData(
            bool doCheckPlatform,
            bool doCheckOrientation,
            bool doCheckInput)
        {
            AppDeviceData thisData = _currentDeviceData;

            // Check current device
            if (doCheckPlatform)
            {
                thisData.platform = TranslateToDevicePlatform();
            }
            else
            {
                thisData.platform = _currentDeviceData.platform;
            }

            // Check current orientation
            if (doCheckOrientation)
            {
                thisData.orientation = TranslateToDeviceOrientation();
            }
            else
            {
                thisData.orientation = _currentDeviceData.orientation;
            }

            // Check current input specs
            if (doCheckInput)
            {
                thisData.input = TranslateToDeviceInput(thisData.platform);
            }
            else
            {
                thisData.input = _currentDeviceData.input;
            }

            // Has our device data updated at all?
            bool hasChanged = (thisData.platform != _currentDeviceData.platform ||
                               thisData.orientation != _currentDeviceData.orientation ||
                               thisData.input != _currentDeviceData.input);

            if (hasChanged)
            {
                _currentDeviceData = thisData;
                return(true);
            }
            return(false);
        }
コード例 #9
0
        /// <summary>
        /// Filters view based on orientation.
        /// </summary>
        /// <param name="filter">Filter data for view.</param>
        /// <param name="data">Current device data to filter against.</param>
        /// <returns>Returns true if view passes validation for orientation.</returns>
        /// <exception cref="ArgumentOutOfRangeException">Thrown in event of invalid switch.</exception>
        private static bool ViewOrientationFilterIsValid(
            UIViewFilterOrientationConfigData filter,
            AppDeviceData data)
        {
            bool valid;

            switch (data.orientation)
            {
            case CoreDevice.DeviceOrientation.Landscape:
                valid = filter.landscape;
                break;

            case CoreDevice.DeviceOrientation.Portrait:
                valid = filter.portrait;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(valid);
        }
コード例 #10
0
        /// <summary>
        /// Sets the proper view for this screen based on AppDevice data.
        /// </summary>
        /// <param name="deviceData"></param>
        private void FindValidUIView(AppDeviceData deviceData)
        {
            // Find based on filters
            List <UIViewConfigData> _validViews = new List <UIViewConfigData>();

            foreach (var view in _configBaseData.views)
            {
                if (GourdUI.Core.UIViewIsValidForDevice(view, deviceData))
                {
                    _validViews.Add(view);
                }
            }

            // TODO: implement some sort of priority/points system to resolve multiple passing views
            if (_validViews.Count > 0)
            {
                SetValidUIView(deviceData, _validViews[0]);
            }
            else
            {
                DestroyCurrentView();
            }
        }
コード例 #11
0
 void IUIView <S> .OnAppDeviceDataUpdated(AppDeviceData deviceData)
 {
     FilterComponents(deviceData);
 }
コード例 #12
0
 void IUIScreen.OnAppDeviceDataUpdated(AppDeviceData deviceData)
 {
     FindValidUIView(deviceData);
 }
コード例 #13
0
        /// <summary>
        /// Compares a filter collection against the current device data.
        /// </summary>
        /// <param name="positiveFilters"></param>
        /// <param name="negativeFilters"></param>
        /// <param name="deviceData"></param>
        public static bool ViewFilterResult(
            UIViewFilterBaseConfigData[] positiveFilters,
            UIViewFilterBaseConfigData[] negativeFilters,
            AppDeviceData deviceData)
        {
            bool positiveValid = true;

            if (positiveFilters != null && positiveFilters.Length > 0)
            {
                foreach (var filter in positiveFilters)
                {
                    if (!positiveValid)
                    {
                        break;
                    }

                    switch (filter)
                    {
                    case UIViewFilterPlatformConfigData f:
                        positiveValid = ViewPlatformFilterIsValid(f, deviceData);
                        break;

                    case UIViewFilterOrientationConfigData f:
                        positiveValid = ViewOrientationFilterIsValid(f, deviceData);
                        break;

                    case UIViewFilterInputConfigData f:
                        positiveValid = ViewInputFilterIsValid(f, deviceData);
                        break;
                    }
                }
            }

            bool negativeValid = true;

            if (negativeFilters != null && negativeFilters.Length > 0)
            {
                foreach (var filter in negativeFilters)
                {
                    if (!negativeValid)
                    {
                        break;
                    }

                    switch (filter)
                    {
                    case UIViewFilterPlatformConfigData f:
                        negativeValid = !ViewPlatformFilterIsValid(f, deviceData);
                        break;

                    case UIViewFilterOrientationConfigData f:
                        negativeValid = !ViewOrientationFilterIsValid(f, deviceData);
                        break;

                    case UIViewFilterInputConfigData f:
                        negativeValid = !ViewInputFilterIsValid(f, deviceData);
                        break;
                    }
                }
            }

            return(positiveValid && negativeValid);
        }