Ejemplo n.º 1
0
        protected virtual void DisplayProfiles(IList <ModProfile> profileCollection, ModContainer modContainer)
        {
            Debug.Assert(modContainer != null);

            if (profileCollection == null)
            {
                profileCollection = new ModProfile[0];
            }

            // init vars
            int displayCount = profileCollection.Count;

            ModProfile[]    displayProfiles = new ModProfile[displayCount];
            ModStatistics[] displayStats    = new ModStatistics[displayCount];

            // build arrays
            for (int i = 0;
                 i < displayCount;
                 ++i)
            {
                ModProfile    profile = profileCollection[i];
                ModStatistics stats   = null;
                if (profile != null)
                {
                    stats = profile.statistics;
                }

                displayProfiles[i] = profile;
                displayStats[i]    = stats;
            }

            // display
            modContainer.DisplayMods(displayProfiles, displayStats);
        }
Ejemplo n.º 2
0
        private IEnumerator TransitionPageCoroutine(float mainPaneTargetX, float transitionPaneStartX,
                                                    float transitionLength, Action onTransitionCompleted)
        {
            m_isTransitioning = true;

            this.m_transitionPageContainer.gameObject.SetActive(true);

            float transitionTime = 0f;

            // transition
            while (transitionTime < transitionLength)
            {
                float transPos = Mathf.Lerp(0f, mainPaneTargetX, transitionTime / transitionLength);

                this.m_modPageContainer.GetComponent <RectTransform>().anchoredPosition        = new Vector2(transPos, 0f);
                this.m_transitionPageContainer.GetComponent <RectTransform>().anchoredPosition = new Vector2(transPos + transitionPaneStartX, 0f);

                transitionTime += Time.unscaledDeltaTime;

                yield return(null);
            }

            // flip
            var tempContainer = this.m_modPageContainer;

            this.m_modPageContainer        = this.m_transitionPageContainer;
            this.m_transitionPageContainer = tempContainer;

            var tempPage = modPage;

            this.m_modPage        = this.m_transitionPage;
            this.m_transitionPage = tempPage;

            // finalize
            this.m_modPageContainer.GetComponent <RectTransform>().anchoredPosition = Vector2.zero;
            this.m_transitionPageContainer.gameObject.SetActive(false);

            m_isTransitioning = false;

            // notify, etc
            this.UpdatePageButtonInteractibility();
            if (this.onModPageChanged != null)
            {
                this.onModPageChanged.Invoke(this.m_modPage);
            }

            if (onTransitionCompleted != null)
            {
                onTransitionCompleted();
            }
        }
Ejemplo n.º 3
0
        /// <summary>Checks a ModContainer's template structure.</summary>
        public static bool HasValidTemplate(ModContainer container, out string helpMessage)
        {
            helpMessage = null;
            bool isValid = true;

            ModView itemTemplate = null;

            // null check
            if (container.containerTemplate == null)
            {
                helpMessage = ("Invalid template:"
                               + " The container template is unassigned.");
                isValid = false;
            }
            // containerTemplate is child of Component
            else if (!container.containerTemplate.IsChildOf(container.transform) ||
                     container.containerTemplate == container.transform)
            {
                helpMessage = ("Invalid template:"
                               + " The container template must be a child of this object.");
                isValid = false;
            }
            // ModView is found under containerTemplate
            else if ((itemTemplate = container.containerTemplate.gameObject.GetComponentInChildren <ModView>()) == null)
            {
                helpMessage = ("Invalid template:"
                               + " No ModView component found in the children of the container template.");
                isValid = false;
            }
            // ModView is on same gameObject as containerTemplate
            else if (itemTemplate.transform == container.containerTemplate)
            {
                helpMessage = ("Invalid template:"
                               + " The ModView component cannot share a GameObject with the container template.");
                isValid = false;
            }

            return(isValid);
        }
Ejemplo n.º 4
0
        protected virtual void DisplayProfiles(IList <ModProfile> profileCollection, ModContainer modContainer)
        {
            Debug.Assert(modContainer != null);

            if (profileCollection == null)
            {
                profileCollection = new ModProfile[0];
            }

            // init vars
            int displayCount = profileCollection.Count;

            ModProfile[]    displayProfiles  = new ModProfile[displayCount];
            ModStatistics[] displayStats     = new ModStatistics[displayCount];
            List <int>      missingStatsData = new List <int>(displayCount);

            // build arrays
            for (int i = 0;
                 i < displayCount;
                 ++i)
            {
                ModProfile    profile = profileCollection[i];
                ModStatistics stats   = null;

                if (profile != null)
                {
                    stats = ModStatisticsRequestManager.instance.TryGetValid(profile.id);

                    if (stats == null)
                    {
                        missingStatsData.Add(profile.id);
                    }
                }

                displayProfiles[i] = profile;
                displayStats[i]    = stats;
            }

            // display
            modContainer.DisplayMods(displayProfiles, displayStats);

            // fetch missing stats
            if (missingStatsData.Count > 0)
            {
                ModStatisticsRequestManager.instance.RequestModStatistics(missingStatsData,
                                                                          (statsArray) =>
                {
                    if (this != null &&
                        modContainer != null)
                    {
                        // verify still valid
                        bool doPushStats = (displayProfiles.Length == modContainer.modProfiles.Length);
                        for (int i = 0;
                             doPushStats && i < displayProfiles.Length;
                             ++i)
                        {
                            // check profiles match
                            ModProfile profile = displayProfiles[i];
                            doPushStats        = (profile == modContainer.modProfiles[i]);

                            if (doPushStats &&
                                profile != null &&
                                displayStats[i] == null)
                            {
                                // get missing stats
                                foreach (ModStatistics stats in statsArray)
                                {
                                    if (stats != null &&
                                        stats.modId == profile.id)
                                    {
                                        displayStats[i] = stats;
                                        break;
                                    }
                                }
                            }
                        }

                        // push display data
                        if (doPushStats)
                        {
                            modContainer.DisplayMods(displayProfiles, displayStats);
                        }
                    }
                },
                                                                          WebRequestError.LogAsWarning);
            }
        }
Ejemplo n.º 5
0
        // ---------[ INITIALIZATION ]---------
        /// <summary>Asserts values and initializes templates.</summary>
        protected virtual void Start()
        {
            Debug.Assert(this.gameObject != this.pageTemplate.gameObject,
                         "[mod.io] The Explorer View and its Container Template cannot be the same"
                         + " Game Object. Please create a separate Game Object for the container template.");

            #if UNITY_EDITOR
            ExplorerView[] nested = this.gameObject.GetComponentsInChildren <ExplorerView>(true);
            if (nested.Length > 1)
            {
                ExplorerView nestedView = nested[1];
                if (nestedView == this)
                {
                    nestedView = nested[0];
                }

                Debug.LogError("[mod.io] Nesting ExplorerViews is currently not supported due to the"
                               + " way IExplorerViewElement component parenting works."
                               + "\nThe nested ExplorerViews must be removed to allow ExplorerView functionality."
                               + "\nthis=" + this.gameObject.name
                               + "\nnested=" + nestedView.gameObject.name,
                               this);
                return;
            }
            #endif

            // -- initialize template ---
            this.pageTemplate.gameObject.SetActive(false);

            GameObject templateCopyGO;

            // current page
            templateCopyGO = GameObject.Instantiate(this.pageTemplate.gameObject,
                                                    this.pageTemplate.transform.parent);
            templateCopyGO.name = "Mod Page A";
            // TODO(@jackson): Change this...
            templateCopyGO.SetActive(true);
            templateCopyGO.transform.SetSiblingIndex(this.pageTemplate.transform.GetSiblingIndex() + 1);
            this.m_modPageContainer = templateCopyGO.GetComponent <ModContainer>();
            this.m_modPageContainer.onItemLimitChanged += (i) => this.Refresh();

            // transition page
            templateCopyGO = GameObject.Instantiate(this.pageTemplate.gameObject,
                                                    this.pageTemplate.transform.parent);
            templateCopyGO.name = "Mod Page B";
            templateCopyGO.SetActive(false);
            templateCopyGO.transform.SetSiblingIndex(this.pageTemplate.transform.GetSiblingIndex() + 2);
            this.m_transitionPageContainer = templateCopyGO.GetComponent <ModContainer>();

            // assign view elements to this
            var viewElementChildren = this.gameObject.GetComponentsInChildren <IExplorerViewElement>(true);
            foreach (IExplorerViewElement viewElement in viewElementChildren)
            {
                viewElement.SetExplorerView(this);
            }

            // - create pages -
            this.UpdateModPageDisplay();
            this.UpdatePageButtonInteractibility();

            // - perform initial fetch -
            this.Refresh();
        }
Ejemplo n.º 6
0
        /// <summary>Initialize template.</summary>
        protected virtual void Start()
        {
            // check template
            #if DEBUG
            string message;
            if (!ModContainer.HasValidTemplate(this, out message))
            {
                Debug.LogError("[mod.io] " + message, this);
                return;
            }
            #endif

            // get template vars
            Transform templateParent         = this.containerTemplate.parent;
            string    templateInstance_name  = this.containerTemplate.gameObject.name + " (Instance)";
            int       templateInstance_index = this.containerTemplate.GetSiblingIndex() + 1;

            // NOTE(@jackson): The canvas group is required to hide the unused
            // ModViews in the case of this.m_fillToLimit
            this.m_itemTemplate = this.containerTemplate.GetComponentInChildren <ModView>(true);
            if (this.m_itemTemplate.gameObject.GetComponent <CanvasGroup>() == null)
            {
                this.m_itemTemplate.gameObject.AddComponent <CanvasGroup>();
            }

            // duplication protection
            bool isInstantiated = (templateParent.childCount > templateInstance_index &&
                                   templateParent.GetChild(templateInstance_index).gameObject.name == templateInstance_name);
            if (isInstantiated)
            {
                this.m_templateClone = templateParent.GetChild(templateInstance_index).gameObject;
                ModView[] viewInstances = this.m_templateClone.GetComponentsInChildren <ModView>(true);

                if (viewInstances == null ||
                    viewInstances.Length == 0)
                {
                    isInstantiated = false;
                    GameObject.Destroy(this.m_templateClone);
                }
                else
                {
                    this.m_container = (RectTransform)viewInstances[0].transform.parent;

                    foreach (ModView view in viewInstances)
                    {
                        GameObject.Destroy(view.gameObject);
                    }
                }
            }

            if (!isInstantiated)
            {
                this.m_templateClone = GameObject.Instantiate(this.containerTemplate.gameObject, templateParent);
                this.m_templateClone.transform.SetSiblingIndex(templateInstance_index);
                this.m_templateClone.name = templateInstance_name;

                ModView viewInstance = this.m_templateClone.GetComponentInChildren <ModView>(true);
                this.m_container = (RectTransform)viewInstance.transform.parent;
                GameObject.Destroy(viewInstance.gameObject);

                this.m_templateClone.SetActive(true);
            }

            this.DisplayMods(this.m_modProfiles, this.m_modStatistics);
        }