/// @private
        public static string GetVerboseModInfo(Mod mod, BuildPropertiesViewer editor)
        {
            string info = "";

            if (editor.ModReferences.Count > 0)
            {
                IEnumerable <string> depMods = editor.ModReferences.SafeSelect((kv2) => {
                    string depMod = kv2.Key;
                    if (kv2.Value != default(Version))
                    {
                        depMod += "@" + kv2.Value.ToString();
                    }
                    return(depMod);
                });

                info += "mod dependencies: [" + string.Join(", ", depMods) + "]";
            }

            if (editor.DllReferences.Length > 0)
            {
                info += ", dll dependencies: [" + string.Join(", ", editor.DllReferences) + "]";
            }

            return(info);
        }
        private void CheckForAndApplyLowEffortTag(string modName)
        {
            UITagMenuButton tagButton;

            if (!this.TagButtons.TryGetValue("Low Effort", out tagButton))
            {
                return;
            }
            if (tagButton.TagState == 1)
            {
                return;
            }

            BuildPropertiesViewer viewer = BuildPropertiesViewer.GetBuildPropertiesForActiveMod(modName);
            string desc = viewer?.Description ?? "";

            if (viewer == null || string.IsNullOrEmpty(desc))
            {
                if (!ModMenuHelpers.GetModDescriptionFromCurrentMenuUI(out desc))
                {
                    desc = "";
                }
            }

            if (desc == "" || desc.Contains("Modify this file with a description of your mod."))
            {
                tagButton.SetTagState(1);
            }
        }
        /// @private
        public static string GetBasicModInfo(Mod mod, BuildPropertiesViewer editor)
        {
            string info = mod.DisplayName + " v" + mod.Version + " by " + editor.Author;

            if (editor.Side != ModSide.Both)
            {
                info += " (" + Enum.GetName(typeof(ModSide), editor.Side) + " only)";
            }

            return(info);
        }
Esempio n. 4
0
        private bool InitializeMe(int?idx, Mod mod, bool willDrawOwnHoverElements = true)
        {
            var      self = this;
            TmodFile modfile;

            if (!ReflectionHelpers.Get(mod, "File", out modfile) || modfile == null)
            {
                LogHelpers.Warn("Could not find mod " + mod.Name + "'s File");
                return(false);
            }

            this.Mod = mod;
            this.WillDrawOwnHoverElements = willDrawOwnHoverElements;

            this.Author                 = null;
            this.HomepageUrl            = null;
            this.HasIconLoaded          = false;
            this.LatestAvailableVersion = default(Version);

            if (!ModHelpersMod.Config.DisableModMenuUpdates)
            {
                BuildPropertiesViewer props = modfile != null?
                                              BuildPropertiesViewer.GetBuildPropertiesForModFile(modfile) :
                                                  (BuildPropertiesViewer)null;

                if (props != null)
                {
                    this.Author      = (string)props.GetField("author");
                    this.HomepageUrl = (string)props.GetField("homepage");
                }
            }

            // Container

            this.SetPadding(4f);
            this.Width.Set(0f, 1f);
            this.Height.Set(64, 0f);

            float titleOffset = 72f;

            // Mod index

            if (idx != null)
            {
                var modIdxElem = new UIText((int)idx + "");
                modIdxElem.Left.Set(titleOffset, 0f);
                this.Append((UIElement)modIdxElem);

                titleOffset += 16f;
            }

            // Mod title

            string modTitle = this.Mod.DisplayName + " " + this.Mod.Version.ToString();

            if (!String.IsNullOrEmpty(this.HomepageUrl))
            {
                this.TitleElem = new UIWebUrl(this.Theme, modTitle, this.HomepageUrl, false);
            }
            else
            {
                this.TitleElem = new UIText(modTitle);
            }
            this.TitleElem.Left.Set(88f, 0f);
            this.Append((UIElement)this.TitleElem);

            // Mod author

            if (this.Author != null)
            {
                this.AuthorElem = new UIText("By: " + this.Author, 0.7f);
                this.AuthorElem.Top.Set(20f, 0f);
                this.AuthorElem.Left.Set(titleOffset, 0f);
                this.Append((UIElement)this.AuthorElem);
            }

            // Mod icon

            if (modfile != null && modfile.HasFile("icon.png"))
            {
                if (!Main.dedServ)                      //...?
                {
                    try {
                        var stream  = new MemoryStream(modfile.GetBytes("icon.png"));
                        var iconTex = Texture2D.FromStream(Main.graphics.GraphicsDevice, stream);

                        if (iconTex.Width == 80 && iconTex.Height == 80)
                        {
                            this.IconElem = new UIImage(iconTex);
                            this.IconElem.Top.Set(-4f, 0f);
                            this.IconElem.Left.Set(-4f, 0f);
                            this.IconElem.MarginTop  = -8f;
                            this.IconElem.MarginLeft = -4f;
                            this.IconElem.ImageScale = 0.7f;
                            this.Append(this.IconElem);
                        }
                    } catch (Exception e) {
                        LogHelpers.Warn(e.ToString());
                    }
                }
            }

            return(true);
        }