コード例 #1
0
        ////////////////

        public override int CompareTo(object obj)
        {
            if (this.Mod.Name == HamstarHelpersMod.Instance.Name)
            {
                return(-1);
            }

            if (obj != null && obj is UIModData)
            {
                var other = (UIModData)obj;

                try {
                    if (ModMetaDataManager.HasGithub(this.Mod) && !ModMetaDataManager.HasGithub(other.Mod))
                    {
                        return(-1);
                    }
                    if (ModMetaDataManager.HasConfig(this.Mod) && !ModMetaDataManager.HasConfig(other.Mod))
                    {
                        return(-1);
                    }
                } catch (Exception) { }

                return(string.Compare(this.Mod.Name, other.Mod.Name));
            }

            return(-1);
        }
コード例 #2
0
        public UIModData(UITheme theme, int?idx, Mod mod, bool will_draw_own_hover_elements = true)
        {
            var      self    = this;
            TmodFile modfile = mod.File;

            this.Mod = mod;
            this.WillDrawOwnHoverElements = will_draw_own_hover_elements;

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

            if (HamstarHelpersMod.Instance.Config.IsCheckingModVersions)
            {
                BuildPropertiesEditor props = modfile != null?
                                              BuildPropertiesEditor.GetBuildPropertiesForModFile(modfile) :
                                                  (BuildPropertiesEditor)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 title_offset = 72f;

            // Mod index

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

                title_offset += 16f;
            }

            // Mod title

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

            if (!String.IsNullOrEmpty(this.HomepageUrl))
            {
                this.TitleElem = new UIWebUrl(theme, mod_title, this.HomepageUrl, false);
            }
            else
            {
                this.TitleElem = new UIText(mod_title);
            }
            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(title_offset, 0f);
                this.Append((UIElement)this.AuthorElem);
            }

            // Mod icon

            if (modfile != null && modfile.HasFile("icon.png"))
            {
                var stream   = new MemoryStream(modfile.GetFile("icon.png"));
                var icon_tex = Texture2D.FromStream(Main.graphics.GraphicsDevice, stream);

                if (icon_tex.Width == 80 && icon_tex.Height == 80)
                {
                    this.IconElem = new UIImage(icon_tex);
                    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);
                }
            }

            // Mod config button

            if (ModMetaDataManager.HasConfig(mod))
            {
                var config_button = new UITextPanelButton(theme, "Open Config File");
                config_button.Width.Set(160f, 0f);
                config_button.HAlign = 1f;
                config_button.VAlign = 1f;
                this.Append(config_button);

                this.ConfigButton = config_button;

                this.ConfigButton.OnClick += delegate(UIMouseEvent evt, UIElement from_elem) {
                    string path     = ModMetaDataManager.GetConfigRelativePath(mod);
                    string fullpath = Main.SavePath + Path.DirectorySeparatorChar + path;

                    try {
                        Process.Start(fullpath);
                    } catch (Exception e) {
                        try {
                            string dir = new FileInfo(fullpath).Directory.FullName;
                            Process.Start(dir);
                        } catch (Exception) { }

                        Main.NewText("Couldn't open config file " + path + ": " + e.Message, Color.Red);
                    }
                };
            }
        }