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

        /// <param name="theme">Appearance style.</param>
        /// <param name="label">Display text.</param>
        /// <param name="url">URL.</param>
        /// <param name="hoverUrl">Indicates if the current element handles its own mouse hover URL display behavior.</param>
        /// <param name="scale">Size multiplier of display text.</param>
        /// <param name="large">'Large' state of display text.</param>
        public UIWebUrl(UITheme theme, string label, string url, bool hoverUrl = true, float scale = 0.85f, bool large = false)
            : base(theme, true)
        {
            this.IsVisited           = false;
            this.Url                 = url;
            this.WillDrawOwnHoverUrl = hoverUrl;
            this.Scale               = scale;
            this.Large               = large;

            this.TextElem           = new UIText(label, scale, large);
            this.TextElem.TextColor = theme.UrlColor;
            this.Append(this.TextElem);

            this.LineElem           = UIWebUrl.GetLineElement(label, scale, large);
            this.LineElem.TextColor = theme.UrlColor;
            this.Append(this.LineElem);

            CalculatedStyle labelSize = this.TextElem.GetDimensions();

            this.Width.Set(labelSize.Width, 0f);
            this.Height.Set(labelSize.Height, 0f);

            UIText textElem = this.TextElem;
            UIText lineElem = this.LineElem;

            this.OnMouseOver += delegate(UIMouseEvent evt, UIElement fromElem) {
                if (textElem.TextColor != theme.UrlVisitColor)
                {
                    textElem.TextColor = theme.UrlLitColor;
                    textElem.TextColor = theme.UrlLitColor;
                }
            };
            this.OnMouseOut += delegate(UIMouseEvent evt, UIElement fromElem) {
                if (textElem.TextColor != theme.UrlVisitColor)
                {
                    textElem.TextColor = theme.UrlColor;
                    textElem.TextColor = theme.UrlColor;
                }
            };

            this.OnClick += delegate(UIMouseEvent evt, UIElement fromElem) {
                try {
                    SystemHelpers.OpenUrl(this.Url);
                    //System.Diagnostics.Process.Start( this.Url );

                    this.IsVisited = true;

                    textElem.TextColor = theme.UrlVisitColor;
                    lineElem.TextColor = theme.UrlVisitColor;
                } catch (Exception e) {
                    Main.NewText(e.Message);
                }
            };

            this.RefreshTheme();
        }
コード例 #2
0
        public UIWebUrl(UITheme theme, string label, string url, bool hover_url = true, float scale = 0.85f, bool large = false) : base()
        {
            this.Theme = theme;

            this.WillDrawOwnHoverUrl = hover_url;
            this.Url = url;

            this.TextElem           = new UIText(label, scale, large);
            this.TextElem.TextColor = theme.UrlColor;
            this.Append(this.TextElem);

            CalculatedStyle label_size     = this.TextElem.GetDimensions();
            float           underscore_len = Main.fontMouseText.MeasureString("_").X;
            float           text_len       = Main.fontMouseText.MeasureString(label).X;
            int             line_len       = (int)Math.Max(1f, Math.Round(text_len / (underscore_len - 2)));

            this.LineElem           = new UIText(new String('_', line_len), scale, large);
            this.LineElem.TextColor = theme.UrlColor;
            this.Append(this.LineElem);

            this.Width.Set(label_size.Width, 0f);
            this.Height.Set(label_size.Height, 0f);

            UIText text_elem = this.TextElem;
            UIText line_elem = this.LineElem;

            this.OnMouseOver += delegate(UIMouseEvent evt, UIElement from_elem) {
                if (text_elem.TextColor != theme.UrlVisitColor)
                {
                    text_elem.TextColor = theme.UrlLitColor;
                    text_elem.TextColor = theme.UrlLitColor;
                }
            };
            this.OnMouseOut += delegate(UIMouseEvent evt, UIElement from_elem) {
                if (text_elem.TextColor != theme.UrlVisitColor)
                {
                    text_elem.TextColor = theme.UrlColor;
                    text_elem.TextColor = theme.UrlColor;
                }
            };

            this.OnClick += delegate(UIMouseEvent evt, UIElement from_elem) {
                try {
                    SystemHelpers.OpenUrl(this.Url);
                    //System.Diagnostics.Process.Start( this.Url );

                    text_elem.TextColor = theme.UrlVisitColor;
                    line_elem.TextColor = theme.UrlVisitColor;
                } catch (Exception e) {
                    Main.NewText(e.Message);
                }
            };
        }
コード例 #3
0
        public override void Load()
        {
            //ErrorLogger.Log( "Loading Mod Helpers. Ensure you have .NET Framework v4.6+ installed, if you're having problems." );
            if (Environment.Version < new Version(4, 0, 30319, 42000))
            {
                SystemHelpers.OpenUrl("https://dotnet.microsoft.com/download/dotnet-framework-runtime");
                throw new FileNotFoundException("Mod Helpers " + this.Version + " requires .NET Framework v4.6+ to work.");
            }

            this.LoadInner();

            InboxMessages.SetMessage("ModHelpers:ControlPanelTags",
                                     "Mod tag lists have now been added to the Control Panel. Mod tags can be modified in the Mod Info menu page via. the main menu.",
                                     false
                                     );
        }
コード例 #4
0
        ////////////////

        /// <param name="theme">Appearance style.</param>
        /// <param name="image">Display image.</param>
        /// <param name="url">URL.</param>
        /// <param name="hoverUrl">Indicates if the current element handles its own mouse hover URL display behavior.</param>
        public UIImageUrl(UITheme theme, Texture2D image, string url, bool hoverUrl = true)
            : base(theme, true)
        {
            this.IsVisited           = false;
            this.Url                 = url;
            this.WillDrawOwnHoverUrl = hoverUrl;

            this.ImageElement = new UIImageButton(image);
            this.ImageElement.SetVisibility(1f, 0.75f);
            this.Append(this.ImageElement);

            this.Width.Pixels   = this.ImageElement.Width.Pixels;
            this.Width.Percent  = this.ImageElement.Width.Percent;
            this.Height.Pixels  = this.ImageElement.Height.Pixels;
            this.Height.Percent = this.ImageElement.Height.Percent;

            this.OnMouseOver += (evt, __) => {
                if (!this.ImageElement.IsMouseHovering)
                {
                    this.ImageElement.MouseOver(evt);
                }
            };
            this.OnMouseOut += (evt, __) => {
                if (this.ImageElement.IsMouseHovering)
                {
                    this.ImageElement.MouseOut(evt);
                }
            };
            this.OnClick += (_, __) => {
                try {
                    SystemHelpers.OpenUrl(this.Url);
                    //System.Diagnostics.Process.Start( this.Url );

                    this.IsVisited = true;
                } catch (Exception e) {
                    Main.NewText(e.Message);
                }
            };

            this.RefreshTheme();
        }
        public static void ReportIssue(Mod mod, string issueTitle, string issueBody,
                                       Action <Exception, string> onError,
                                       Action <bool, string> onCompletion)
        {
            if (!ModFeaturesHelpers.HasGithub(mod))
            {
                throw new ModHelpersException("Mod is not eligable for submitting issues.");
            }

            int maxLines = ModHelpersMod.Config.ModIssueReportErrorLogMaxLines;

            IEnumerable <Mod> mods       = ModListHelpers.GetAllLoadedModsPreferredOrder();
            string            bodyInfo   = string.Join("\n \n", FormattedGameInfoHelpers.GetFormattedGameInfo(mods).ToArray());
            string            bodyErrors = string.Join("\n", GameInfoHelpers.GetErrorLog(maxLines).ToArray());

            string url   = "http://hamstar.pw/hamstarhelpers/issue_submit/";
            string title = "Reported from in-game: " + issueTitle;
            string body  = bodyInfo;

            body += "\n \n \n \n" + "Recent error logs:\n```\n" + bodyErrors + "\n```";
            body += "\n \n" + issueBody;

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

            Action <bool, string> wrappedOnCompletion = (success, output) => {
                string processedOutput = "";

                if (success)
                {
                    JObject respJson = JObject.Parse(output);
                    JToken  data     = respJson.SelectToken("Data.html_url");
                    JToken  msg      = respJson.SelectToken("Msg");

                    if (data != null)
                    {
                        string issueUrl = data.ToObject <string>();
                        if (!string.IsNullOrEmpty(issueUrl))
                        {
                            SystemHelpers.OpenUrl(issueUrl);
                        }
                    }

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

                onCompletion(success, processedOutput);
            };

            Action <Exception, string> wrappedOnError = (Exception e, string str) => {
                LogHelpers.Log("!ModHelpers.PostGithubModIssueReports.ReportIssue - Failed for POST to " + url + " : " + jsonStr);
                onError(e, str);
            };

            WebConnectionHelpers.MakePostRequestAsync(url, jsonStr, e => wrappedOnError(e, ""), wrappedOnCompletion);
        }