Esempio n. 1
0
        /// <summary>
        /// Adds the mod update date to the mods menu.
        /// </summary>
        /// <param name="modEntry">The entry in the mod menu.</param>
        /// <param name="outdated">The mods which are out of date.</param>
        internal static void AddModUpdateButton(ICollection <ModToUpdate> outdated,
                                                Traverse modEntry)
        {
            int index       = modEntry.GetField <int>("mod_index");
            var rowInstance = modEntry.GetField <RectTransform>("rect_transform")?.gameObject;
            var mods        = Global.Instance.modManager?.mods;

            if (rowInstance != null && mods != null && index >= 0 && index < mods.Count)
            {
                var mod       = mods[index];
                var tooltip   = new StringBuilder(128);
                var localDate = mod.GetLocalLastModified();
                var updated   = ModStatus.Disabled;
                // A nice colorful button with a warning or checkmark icon
                var updButton = new PButton("UpdateMod")
                {
                    Margin = BUTTON_MARGIN, SpriteSize = ICON_SIZE,
                    MaintainSpriteAspect = true
                };
                if (mod.label.distribution_platform == Label.DistributionPlatform.Steam)
                {
                    var modUpdate = new ModToUpdate(mod);
                    updated = AddSteamUpdate(tooltip, modUpdate, localDate, updButton);
                    if (updated == ModStatus.Outdated)
                    {
                        outdated.Add(modUpdate);
                    }
                }
                else
                {
                    tooltip.AppendFormat(UISTRINGS.LOCAL_UPDATE, localDate.ToLocalTime());
                }
                // Icon, color, and tooltip
                updButton.Sprite = (updated == ModStatus.UpToDate || updated == ModStatus.
                                    Disabled) ? PUITuning.Images.Checked : PUITuning.Images.GetSpriteByName(
                    "iconWarning");
                updButton.Color = (updated == ModStatus.Outdated) ? COLOR_OUTDATED :
                                  COLOR_UPDATED;
                updButton.ToolTip = tooltip.ToString();
                // Just before subscription button, and after the Options button
                PButton.SetButtonEnabled(updButton.AddTo(rowInstance, 3), updated != ModStatus.
                                         Disabled);
            }
        }
        /// <summary>
        /// Adds the mod update date to the mods menu.
        /// </summary>
        /// <param name="outdated">The mods which are out of date.</param>
        /// <param name="modEntry">The entry in the mod menu.</param>
        internal static void AddModUpdateButton(ICollection <ModToUpdate> outdated,
                                                object modEntry)
        {
            int index    = -1;
            var type     = modEntry.GetType();
            var indexVal = type.GetFieldSafe("mod_index", false)?.GetValue(modEntry);

            if (indexVal is int intVal)
            {
                index = intVal;
            }
            var rowInstance = (type.GetFieldSafe("rect_transform", false)?.GetValue(
                                   modEntry) as RectTransform)?.gameObject;
            var mods = Global.Instance.modManager?.mods;

            if (rowInstance != null && mods != null && index >= 0 && index < mods.Count)
            {
                var mod       = mods[index];
                var tooltip   = new StringBuilder(128);
                var localDate = mod.GetLocalLastModified();
                var updated   = ModStatus.Disabled;
                // A nice colorful button with a warning or checkmark icon
                var updButton = new PButton("UpdateMod")
                {
                    Margin = BUTTON_MARGIN, SpriteSize = ICON_SIZE,
                    MaintainSpriteAspect = true
                };
                // Format DateTime to the current Klei culture (otherwise it uses
                // CurrentCulture which defaults to the Steam culture)
                if (cultureInfo == null)
                {
                    var langCode = Localization.GetLocale()?.Code;
                    if (string.IsNullOrEmpty(langCode))
                    {
                        langCode = Localization.GetCurrentLanguageCode();
                    }
                    if (string.IsNullOrEmpty(langCode))
                    {
                        cultureInfo = CultureInfo.CurrentCulture;
                    }
                    else
                    {
                        cultureInfo = new CultureInfo(langCode);
                    }
                }
                if (mod.label.distribution_platform == Label.DistributionPlatform.Steam)
                {
                    var modUpdate = new ModToUpdate(mod);
                    updated = AddSteamUpdate(tooltip, modUpdate, localDate, updButton);
                    if (updated == ModStatus.Outdated)
                    {
                        outdated.Add(modUpdate);
                    }
                }
                else
                {
                    tooltip.AppendFormat(cultureInfo, UISTRINGS.LOCAL_UPDATE, localDate.
                                         ToLocalTime());
                }
                // Icon, color, and tooltip
                updButton.Sprite = (updated == ModStatus.UpToDate || updated == ModStatus.
                                    Disabled) ? PUITuning.Images.Checked : PUITuning.Images.GetSpriteByName(
                    "iconWarning");
                updButton.Color = (updated == ModStatus.Outdated) ? COLOR_OUTDATED :
                                  COLOR_UPDATED;
                updButton.ToolTip = tooltip.ToString();
                // Just before subscription button, and after the Options button
                PButton.SetButtonEnabled(updButton.AddTo(rowInstance, 4), updated != ModStatus.
                                         Disabled);
            }
        }