public void ClearMessages()
 {
     this.m_NewMessageCount = 0;
     UITemplateManager.ClearInstances(kChirpTemplate);
 }
Example #2
0
        public static void RefreshPlugins()
        {
            if (improvedModsPanelExists)
            {
                return;
            }

            var modsList = GameObject.Find("ModsList");

            if (modsList == null)
            {
                return;
            }

            var uiView = GameObject.FindObjectOfType <UIView>();

            var plugins = PluginManager.instance.GetPluginsInfo();

            Dictionary <PluginManager.PluginInfo, string>   pluginNames                = new Dictionary <PluginManager.PluginInfo, string>();
            Dictionary <PluginManager.PluginInfo, string>   pluginDescriptions         = new Dictionary <PluginManager.PluginInfo, string>();
            Dictionary <PluginManager.PluginInfo, TimeSpan> pluginLastUpdatedTimeDelta = new Dictionary <PluginManager.PluginInfo, TimeSpan>();
            Dictionary <PluginManager.PluginInfo, TimeSpan> pluginSubscribedTimeDelta  = new Dictionary <PluginManager.PluginInfo, TimeSpan>();

            foreach (var current in plugins)
            {
                IUserMod[] instances = _pluginInstancesCache[current];
                if (instances.Length == 0)
                {
                    Debug.LogErrorFormat("User assembly \"{0}\" does not implement the IUserMod interface!");
                    continue;
                }

                pluginNames.Add(current, instances[0].Name);
                pluginDescriptions.Add(current, instances[0].Description);
                pluginLastUpdatedTimeDelta.Add(current, GetPluginLastModifiedDelta(current));
                pluginSubscribedTimeDelta.Add(current, GetPluginCreatedDelta(current));
            }

            UIComponent uIComponent = modsList.GetComponent <UIComponent>();

            UITemplateManager.ClearInstances("ModEntryTemplate");

            var pluginsSorted = PluginManager.instance.GetPluginsInfo().ToArray();

            if (sortMode == SortMode.Alphabetical)
            {
                Array.Sort(pluginsSorted, (a, b) => pluginNames[a].CompareTo(pluginNames[b]));
            }
            else if (sortMode == SortMode.LastUpdated)
            {
                Array.Sort(pluginsSorted, (a, b) => pluginLastUpdatedTimeDelta[a].CompareTo(pluginLastUpdatedTimeDelta[b]));
            }
            else if (sortMode == SortMode.LastSubscribed)
            {
                Array.Sort(pluginsSorted, (a, b) => pluginSubscribedTimeDelta[a].CompareTo(pluginSubscribedTimeDelta[b]));
            }

            int count = 0;

            foreach (var current in pluginsSorted)
            {
                if (!pluginNames.ContainsKey(current))
                {
                    continue;
                }

                PackageEntry packageEntry = UITemplateManager.Get <PackageEntry>("ModEntryTemplate");
                uIComponent.AttachUIComponent(packageEntry.gameObject);

                packageEntry.entryName       = String.Format("{0} (by {{0}})", pluginNames[current]);
                packageEntry.entryActive     = current.isEnabled;
                packageEntry.pluginInfo      = current;
                packageEntry.publishedFileId = current.publishedFileID;
                packageEntry.RequestDetails();

                var panel = packageEntry.gameObject.GetComponent <UIPanel>();
                panel.size  = new Vector2(panel.size.x, 24.0f);
                panel.color = count % 2 == 0 ? panel.color : new Color32
                                  ((byte)(panel.color.r * 0.60f), (byte)(panel.color.g * 0.60f), (byte)(panel.color.b * 0.60f), panel.color.a);

                var name = (UILabel)panel.Find("Name");
                name.textScale     = 0.85f;
                name.tooltip       = pluginDescriptions[current];
                name.textColor     = count % 2 == 0 ? blackColor : whiteColor;
                name.textScaleMode = UITextScaleMode.ControlSize;
                name.position      = new Vector3(30.0f, 2.0f, name.position.z);

                var view = (UIButton)panel.Find("View");
                view.size      = new Vector2(84.0f, 20.0f);
                view.textScale = 0.7f;
                view.text      = "WORKSHOP";
                view.position  = new Vector3(1011.0f, -2.0f, view.position.z);

                var share = (UIButton)panel.Find("Share");
                share.size      = new Vector2(84.0f, 20.0f);
                share.textScale = 0.7f;
                share.isVisible = false;
                share.position  = new Vector3(1103.0f, -2.0f, share.position.z);
                share.isVisible = true;

                var lastUpdated = (UILabel)panel.Find("LastUpdated");
                if (lastUpdated == null)
                {
                    lastUpdated = uiView.AddUIComponent(typeof(UILabel)) as UILabel;
                }

                lastUpdated.name          = "LastUpdated";
                lastUpdated.autoSize      = false;
                lastUpdated.size          = new Vector2(400.0f, 18.0f);
                lastUpdated.textAlignment = UIHorizontalAlignment.Right;
                lastUpdated.textColor     = blackColor;
                lastUpdated.textScale     = 0.8f;
                lastUpdated.text          = String.Format("Last update: {0}",
                                                          DateTimeUtil.TimeSpanToString(pluginLastUpdatedTimeDelta[current]));
                lastUpdated.AlignTo(panel, UIAlignAnchor.TopRight);
                lastUpdated.relativePosition = new Vector3(600.0f, 6.0f, 0.0f);

                var delete = (UIButton)panel.Find("Delete");
                delete.size     = new Vector2(24.0f, 24.0f);
                delete.position = new Vector3(1195.0f, delete.position.y, delete.position.z);

                var active = (UICheckBox)panel.Find("Active");
                active.position = new Vector3(4.0f, active.position.y, active.position.z);

                var onOff = (UILabel)active.Find("OnOff");
                onOff.enabled = false;

                count++;
            }

            refreshModContents = true;
        }