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

        private void SubmitIssue()
        {
            if (this.CurrentModListItem == null)
            {
                return;
            }
            if (!ModMetaDataManager.HasGithub(this.CurrentModListItem.Mod))
            {
                return;
            }

            UIControlPanel self        = this;
            string         issue_title = this.IssueTitleInput.Text;
            string         issue_body  = this.IssueBodyInput.Text;

            if (string.IsNullOrEmpty(issue_title) || string.IsNullOrEmpty(issue_body))
            {
                return;
            }

            this.AwaitingReport = true;
            this.DisableIssueInput();

            self.Logic.ReportIssue(self.CurrentModListItem.Mod, issue_title, issue_body, delegate {
                self.AwaitingReport   = false;
                self.ResetIssueInput  = true;
                self.SetDialogToClose = true;
            });
        }
コード例 #2
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);
        }
コード例 #3
0
        public static void ReportIssue(Mod mod, string issue_title, string issue_body, Action <string> on_success, Action <Exception, string> on_error, Action on_completion = null)
        {
            if (!ModMetaDataManager.HasGithub(mod))
            {
                throw new Exception("Mod is not eligable for submitting issues.");
            }

            int max_lines = HamstarHelpersMod.Instance.Config.ModIssueReportErrorLogMaxLines;

            IEnumerable <Mod> mods        = ModHelpers.GetAllMods();
            string            body_info   = string.Join("\n \n", InfoHelpers.GetGameData(mods).ToArray());
            string            body_errors = string.Join("\n", InfoHelpers.GetErrorLog(max_lines).ToArray());

            string url   = "http://hamstar.pw/hamstarhelpers/issue_submit/";
            string title = "In-game: " + issue_title;
            string body  = body_info;

            body += "\n \n \n \n" + "Recent error logs:\n```\n" + body_errors + "\n```";
            body += "\n \n" + issue_body;

            var json = new GithubModIssueReportData {
                githubuser    = ModMetaDataManager.GetGithubUserName(mod),
                githubproject = ModMetaDataManager.GetGithubProjectName(mod),
                title         = title,
                body          = body
            };
            string json_str = JsonConvert.SerializeObject(json, Formatting.Indented);

            byte[] json_bytes = Encoding.UTF8.GetBytes(json_str);

            Action <String> on_response = (output) => {
                JObject resp_json = JObject.Parse(output);
                //JToken data = resp_json.SelectToken( "Data.html_url" );
                JToken msg = resp_json.SelectToken("Msg");

                /*if( data != null ) {
                 *      string post_at_url = data.ToObject<string>();
                 *      if( !string.IsNullOrEmpty( post_at_url ) ) {
                 *              SystemHelpers.Start( post_at_url );
                 *      }
                 * }*/

                if (msg == null)
                {
                    on_success("Failure.");
                }
                else
                {
                    on_success(msg.ToObject <string>());
                }
            };

            NetHelpers.NetHelpers.MakePostRequestAsync(url, json_bytes, on_response, on_error, on_completion);
        }
コード例 #4
0
        public static void RefreshConfigs()
        {
            if (Main.netMode != 0)
            {
                throw new UsageException("Cannot refresh configs in multiplayer.", Color.Red);
            }

            var mymod = HamstarHelpersMod.Instance;

            foreach (var kv in mymod.ModMetaDataManager.ConfigMods)
            {
                ModMetaDataManager.ReloadConfigFromFile(kv.Value);
            }
        }
コード例 #5
0
        ////////////////

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            if (!this.IsOpen)
            {
                return;
            }

            if (Main.playerInventory || Main.npcChatText != "")
            {
                this.Close();
                return;
            }

            if (this.OuterContainer.IsMouseHovering)
            {
                Main.LocalPlayer.mouseInterface = true;
            }

            if (this.AwaitingReport || this.CurrentModListItem == null || !ModMetaDataManager.HasGithub(this.CurrentModListItem.Mod))
            {
                this.DisableIssueInput();
            }
            else
            {
                this.EnableIssueInput();
            }

            if (this.ResetIssueInput)
            {
                this.ResetIssueInput = false;
                this.IssueTitleInput.SetText("");
                this.IssueBodyInput.SetText("");
            }

            if (this.SetDialogToClose)
            {
                this.SetDialogToClose = false;
                this.Close();
                return;
            }

            this.UpdateElements(HamstarHelpersMod.Instance);
        }
コード例 #6
0
        ////////////////

        private void SelectModFromList(UIModData list_item)
        {
            Mod mod = list_item.Mod;

            if (this.CurrentModListItem != null)
            {
                this.Theme.ApplyListItem(this.CurrentModListItem);
            }
            this.Theme.ApplyListItemSelected(list_item);
            this.CurrentModListItem = list_item;

            this.Logic.SetCurrentMod(mod);

            if (!ModMetaDataManager.HasGithub(mod))
            {
                this.DisableIssueInput();
            }
            else
            {
                this.EnableIssueInput();
            }
        }
コード例 #7
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);
                    }
                };
            }
        }