private void DrawTimeText(SpriteBatch spriteBatch, Vector2 drawPos) { if (_timeStamp == "0000-00-00 00:00:00") { return; } const int baseWidth = 125; // something like 1 days ago is ~110px, XX minutes ago is ~120 px (longest) spriteBatch.Draw(_innerPanelTexture, drawPos, new Rectangle(0, 0, 8, _innerPanelTexture.Height), Color.White); spriteBatch.Draw(_innerPanelTexture, new Vector2(drawPos.X + 8f, drawPos.Y), new Rectangle(8, 0, 8, _innerPanelTexture.Height), Color.White, 0f, Vector2.Zero, new Vector2((baseWidth - 16f) / 8f, 1f), SpriteEffects.None, 0f); spriteBatch.Draw(_innerPanelTexture, new Vector2(drawPos.X + baseWidth - 8f, drawPos.Y), new Rectangle(16, 0, 8, _innerPanelTexture.Height), Color.White); drawPos += new Vector2(0f, 2f); try { var myDateTime = DateTime.Parse(_timeStamp); // parse date string text = TimeHelper.HumanTimeSpanString(myDateTime); // get time text int textWidth = (int)Main.fontMouseText.MeasureString(text).X; // measure text width int diffWidth = baseWidth - textWidth; // get difference drawPos.X += diffWidth * 0.5f; // add difference as padding Utils.DrawBorderString(spriteBatch, text, drawPos, Color.White); } catch (Exception e) { Logging.tML.Error("Problem during drawing of time text", e); } }
private void DrawTimeText(SpriteBatch spriteBatch, Vector2 drawPos, int baseWidth) { if (timeStamp == "0000-00-00 00:00:00") { return; } try { var MyDateTime = DateTime.Parse(timeStamp); // parse date string text = TimeHelper.HumanTimeSpanString(MyDateTime); // get time text int textWidth = (int)Main.fontMouseText.MeasureString(text).X; // measure text width int diffWidth = baseWidth - textWidth; // get difference drawPos.X += diffWidth * 0.5f; // add difference as padding Utils.DrawBorderString(spriteBatch, text, drawPos, Color.White, 1f, 0f, 0f, -1); } catch { } }
public UIModDownloadItem(string displayName, string name, string version, string author, string modReferences, ModSide modSide, string modIconUrl, string downloadUrl, int downloads, int hot, string timeStamp, bool hasUpdate, bool updateIsDowngrade, LocalMod installed) { ModName = name; DisplayName = displayName; DownloadUrl = downloadUrl; _version = version; _author = author; _modReferences = modReferences; _modSide = modSide; _modIconUrl = modIconUrl; _downloads = downloads; _hot = hot; _timeStamp = timeStamp; HasUpdate = hasUpdate; UpdateIsDowngrade = updateIsDowngrade; Installed = installed; BorderColor = new Color(89, 116, 213) * 0.7f; _dividerTexture = TextureManager.Load("Images/UI/Divider"); _innerPanelTexture = TextureManager.Load("Images/UI/InnerPanelBackground"); Height.Pixels = 120; Width.Percent = 1f; SetPadding(6f); float left = HasModIcon ? 85f : 0f; _modName = new UIText(displayName) { Left = new StyleDimension(left + 5, 0f), Top = { Pixels = 5 } }; Append(_modName); _authorText = new UIText(Language.GetTextValue("tModLoader.ModsByline", author)) { Top = { Pixels = 83 } }; Append(_authorText); if (_timeStamp != "0000-00-00 00:00:00") { try { var myDateTime = DateTime.Parse(_timeStamp); string text = TimeHelper.HumanTimeSpanString(myDateTime); int textWidth = (int)Main.fontMouseText.MeasureString(text).X; _authorText.Left.Set(125 + 5, 0f); } catch (Exception e) { Logging.tML.Error(e.ToString()); } } _moreInfoButton = new UIAutoScaleTextTextPanel <string>(Language.GetTextValue("tModLoader.ModsMoreInfo")) { Width = { Pixels = 100 }, Height = { Pixels = 36 }, Left = { Pixels = left }, Top = { Pixels = 40 } }.WithFadedMouseOver(); _moreInfoButton.PaddingTop -= 2f; _moreInfoButton.PaddingBottom -= 2f; _moreInfoButton.OnClick += RequestMoreInfo; Append(_moreInfoButton); if (hasUpdate || installed == null) { _updateButton = new UIAutoScaleTextTextPanel <string>(UpdateText).WithFadedMouseOver(); _updateButton.CopyStyle(_moreInfoButton); _updateButton.Width.Pixels = 120; _updateButton.Left.Pixels = _moreInfoButton.Width.Pixels + _moreInfoButton.Left.Pixels + 5f; _updateButton.OnClick += DownloadMod; Append(_updateButton); if (_modReferences.Length > 0) { _updateWithDepsButton = new UIAutoScaleTextTextPanel <string>(UpdateWithDepsText).WithFadedMouseOver(); _updateWithDepsButton.CopyStyle(_updateButton); _updateWithDepsButton.Width.Pixels = 220; _updateWithDepsButton.Left.Pixels = _updateButton.Width.Pixels + _updateButton.Left.Pixels + 5f; _updateWithDepsButton.OnClick += DownloadWithDeps; Append(_updateWithDepsButton); } } if (modReferences.Length > 0) { var icon = Texture2D.FromStream(Main.instance.GraphicsDevice, Assembly.GetExecutingAssembly().GetManifestResourceStream("Terraria.ModLoader.UI.ButtonExclamation.png")); var modReferenceIcon = new UIHoverImage(icon, Language.GetTextValue("tModLoader.MBClickToViewDependencyMods", string.Join("\n", modReferences.Split(',').Select(x => x.Trim())))) { Left = { Pixels = -icon.Width, Percent = 1f }, Top = { Pixels = 83 } }; modReferenceIcon.OnClick += (s, e) => { var modListItem = (UIModDownloadItem)e.Parent; Interface.modBrowser.SpecialModPackFilter = modListItem._modReferences.Split(',').Select(x => x.Trim()).ToList(); Interface.modBrowser.SpecialModPackFilterTitle = Language.GetTextValue("tModLoader.MBFilterDependencies"); // Toolong of \n" + modListItem.modName.Text; Interface.modBrowser.FilterTextBox.Text = ""; Interface.modBrowser.UpdateNeeded = true; Main.PlaySound(SoundID.MenuOpen); }; Append(modReferenceIcon); } OnDoubleClick += RequestMoreInfo; }
public UIModDownloadItem(string displayName, string name, string version, string author, string modReferences, ModSide modSide, string modIconUrl, string downloadUrl, int downloads, int hot, string timeStamp, bool hasUpdate, bool updateIsDowngrade, LocalMod installed, string modloaderversion) { ModName = name; DisplayName = displayName; DownloadUrl = downloadUrl; _version = version; _author = author; _modReferences = modReferences; _modSide = modSide; _modIconUrl = modIconUrl; _downloads = downloads; _hot = hot; _timeStamp = timeStamp; HasUpdate = hasUpdate; UpdateIsDowngrade = updateIsDowngrade; Installed = installed; BorderColor = new Color(89, 116, 213) * 0.7f; _dividerTexture = TextureManager.Load("Images/UI/Divider"); _innerPanelTexture = TextureManager.Load("Images/UI/InnerPanelBackground"); Height.Pixels = 90; Width.Percent = 1f; SetPadding(6f); float left = HasModIcon ? 85f : 0f; _modName = new UIText(displayName) { Left = new StyleDimension(left + 5, 0f), Top = { Pixels = 5 } }; Append(_modName); if (_timeStamp != "0000-00-00 00:00:00") { try { var myDateTime = DateTime.Parse(_timeStamp); string text = TimeHelper.HumanTimeSpanString(myDateTime); int textWidth = (int)Main.fontMouseText.MeasureString(text).X; } catch (Exception e) { Logging.tML.Error(e.ToString()); } } _moreInfoButton = new UIAutoScaleTextTextPanel <string>(Language.GetTextValue("tModLoader.ModsMoreInfo")) { Width = { Pixels = 100 }, Height = { Pixels = 36 }, Left = { Pixels = left }, Top = { Pixels = 40 } }.WithFadedMouseOver(); _moreInfoButton.PaddingTop -= 2f; _moreInfoButton.PaddingBottom -= 2f; _moreInfoButton.OnClick += RequestMoreInfo; Append(_moreInfoButton); if (modloaderversion != null) { tMLUpdateRequired = new UIAutoScaleTextTextPanel <string>(Language.GetTextValue("tModLoader.MBRequiresTMLUpdate", modloaderversion)).WithFadedMouseOver(Color.Orange, Color.Orange * 0.7f); tMLUpdateRequired.BackgroundColor = Color.Orange * 0.7f; tMLUpdateRequired.CopyStyle(_moreInfoButton); tMLUpdateRequired.Width.Pixels = 340; tMLUpdateRequired.Left.Pixels = _moreInfoButton.Width.Pixels + _moreInfoButton.Left.Pixels + 5f; tMLUpdateRequired.OnClick += (a, b) => { Process.Start("https://github.com/tModLoader/tModLoader/releases/latest"); }; Append(tMLUpdateRequired); } else if (hasUpdate || installed == null) { _updateButton = new UIImage(UICommon.buttonDownloadTexture); _updateButton.Top.Pixels = 40; _updateButton.Left.Set(-166, 1f); _updateButton.OnClick += DownloadMod; Append(_updateButton); if (_modReferences.Length > 0) { _updateButton.Left.Set(_updateButton.Left.Pixels - _updateButton.Width.Pixels - 6, 1f); _updateWithDepsButton = new UIImage(UICommon.buttonDownloadMultipleTexture); _updateWithDepsButton.CopyStyle(_updateButton); _updateWithDepsButton.Left.Pixels = _updateButton.Width.Pixels + _updateButton.Left.Pixels + 5f; _updateWithDepsButton.OnClick += DownloadWithDeps; Append(_updateWithDepsButton); } } if (modReferences.Length > 0) { var icon = UICommon.buttonExclamationTexture; var modReferenceIcon = new UIHoverImage(icon, Language.GetTextValue("tModLoader.MBClickToViewDependencyMods", string.Join("\n", modReferences.Split(',').Select(x => x.Trim())))) { Left = { Pixels = -icon.Width, Percent = 1f } }; modReferenceIcon.OnClick += (s, e) => { var modListItem = (UIModDownloadItem)e.Parent; Interface.modBrowser.SpecialModPackFilter = modListItem._modReferences.Split(',').Select(x => x.Trim()).ToList(); Interface.modBrowser.SpecialModPackFilterTitle = Language.GetTextValue("tModLoader.MBFilterDependencies"); // Toolong of \n" + modListItem.modName.Text; Interface.modBrowser.FilterTextBox.Text = ""; Interface.modBrowser.UpdateNeeded = true; Main.PlaySound(SoundID.MenuOpen); }; Append(modReferenceIcon); } OnDoubleClick += RequestMoreInfo; }