private void Build(BuildingMod mod) { try { status.SetStatus(Language.GetTextValue("tModLoader.Building", mod.Name)); List <LocalMod> refMods = null; BuildModForPlatform(mod, ref refMods, true); BuildModForPlatform(mod, ref refMods, false); if (Program.LaunchParameters.TryGetValue("-eac", out var eacValue)) { mod.properties.eacPath = Path.ChangeExtension(eacValue, "pdb"); status.SetStatus(Language.GetTextValue("tModLoader.EnabledEAC", mod.properties.eacPath)); } PackageMod(mod); ModLoader.GetMod(mod.Name)?.Close(); mod.modFile.Save(); ModLoader.EnableMod(mod.Name); } catch (Exception e) { e.Data["mod"] = mod.Name; throw; } }
private static void EnableListOnly(UIMouseEvent evt, UIElement listeningElement) { UIModPackItem modListItem = (UIModPackItem)listeningElement.Parent; foreach (var item in UIModPacks.mods) { ModLoader.DisableMod(item); } foreach (string modname in modListItem.mods) { if (UIModPacks.mods.Contains(modname)) { ModLoader.EnableMod(modname); } } Main.menuMode = Interface.reloadModsID; // should reload, which should refresh enabled counts if (modListItem.numModsMissing > 0) { string missing = ""; for (int i = 0; i < modListItem.mods.Length; i++) { if (modListItem.modMissing[i]) { missing += modListItem.mods[i] + "\n"; } } Interface.infoMessage.Show(Language.GetTextValue("tModLoader.ModPackModsMissing", missing), Interface.reloadModsID); } }
public override void Complete() { Success = true; base.Complete(); try { var mod = new TmodFile(ModHeader.path); using (mod.Open()) { } if (!ModHeader.Matches(mod)) { throw new Exception(Language.GetTextValue("tModLoader.MPErrorModHashMismatch")); } if (ModHeader.signed && !mod.ValidModBrowserSignature) { throw new Exception(Language.GetTextValue("tModLoader.MPErrorModNotSigned")); } ModLoader.EnableMod(mod.name); } catch (Exception e) { Cancel(); ShowError(e); } }
private static void EnableListOnly(UIMouseEvent evt, UIElement listeningElement) { UIModPackItem modListItem = (UIModPackItem)listeningElement.Parent; foreach (var item in UIModPacks.mods) { ModLoader.DisableMod(item); } foreach (string modname in modListItem.mods) { if (UIModPacks.mods.Contains(modname)) { ModLoader.EnableMod(modname); } } Main.menuMode = Interface.reloadModsID; // should reload, which should refresh enabled counts if (modListItem.numModsMissing > 0) { string missing = "The following mods were not found:\n"; for (int i = 0; i < modListItem.mods.Length; i++) { if (modListItem.modMissing[i]) { missing += modListItem.mods[i] + "\n"; } } Interface.infoMessage.SetMessage(missing); Interface.infoMessage.SetGotoMenu(Interface.reloadModsID); Main.menuMode = Interface.infoMessageID; } }
//public override void Update(GameTime gameTime) //{ // if (modsToDownload == null || modsToDownload.Count == 0) // Main.menuMode = Interface.modBrowserID; //} private void Client_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) { //Main.menuMode = Interface.modBrowserID; if (e.Error != null) { if (e.Cancelled) { Interface.modBrowser.ClearItems(); Main.menuMode = Interface.modBrowserID; } else { var errorKey = GetHttpStatusCode(e.Error) == HttpStatusCode.ServiceUnavailable ? "MBExceededBandwidth" : "MBUnknownMBError"; Interface.errorMessage.Show(Language.GetTextValue("tModLoader." + errorKey), 0); } File.Delete(ModLoader.ModPath + Path.DirectorySeparatorChar + "temporaryDownload.tmod"); } else if (!e.Cancelled) { // Downloaded OK File.Copy(ModLoader.ModPath + Path.DirectorySeparatorChar + "temporaryDownload.tmod", ModLoader.ModPath + Path.DirectorySeparatorChar + currentDownload.mod + ".tmod", true); File.Delete(ModLoader.ModPath + Path.DirectorySeparatorChar + "temporaryDownload.tmod"); if (!currentDownload.update) { Interface.modBrowser.aNewModDownloaded = true; } else { Interface.modBrowser.aModUpdated = true; } if (ModLoader.autoReloadAndEnableModsLeavingModBrowser) { ModLoader.EnableMod(currentDownload.mod); } // Start next download if (modsToDownload.Count != 0) { currentDownload = modsToDownload.Dequeue(); loadProgress.SetText(Language.GetTextValue("tModLoader.MBDownloadingMod", $"{name}: {currentDownload.displayname}")); loadProgress.SetProgress(0f); client.DownloadFileAsync(new Uri(currentDownload.download), ModLoader.ModPath + Path.DirectorySeparatorChar + "temporaryDownload.tmod"); } else { client.Dispose(); client = null; Interface.modBrowser.ClearItems(); Main.menuMode = Interface.modBrowserID; if (missingMods.Count > 0) { Interface.infoMessage.Show(Language.GetTextValue("tModLoader.MBModsNotFoundOnline", String.Join(",", missingMods)), Interface.modsMenuID); } } } else { File.Delete(ModLoader.ModPath + Path.DirectorySeparatorChar + "temporaryDownload.tmod"); } }
private void ProcessDownloadedMod() { bool modEnabled = ModLoader.GetMod(ModBrowserItem.ModName) != null; bool newMod = !ModBrowserItem.HasUpdate; if (modEnabled) { Interface.modBrowser.anEnabledModUpdated = true; } else if (newMod) { Interface.modBrowser.aNewModDownloaded = true; } else { Interface.modBrowser.aDisabledModUpdated = true; } if (ModLoader.autoReloadAndEnableModsLeavingModBrowser && newMod) { ModLoader.EnableMod(ModBrowserItem.ModName); } Interface.modBrowser.RemoveItem(ModBrowserItem); Interface.modBrowser.UpdateNeeded = true; }
private void ProcessDownloadedMod() { var mod = ModLoader.GetMod(ModBrowserItem.ModName); if (mod != null) { Interface.modBrowser.anEnabledModDownloaded = true; } if (!ModBrowserItem.HasUpdate) { Interface.modBrowser.aNewModDownloaded = true; } else { Interface.modBrowser.aModUpdated = true; } if (ModLoader.autoReloadAndEnableModsLeavingModBrowser) { ModLoader.EnableMod(ModBrowserItem.ModName); } Interface.modBrowser.RemoveItem(ModBrowserItem); Interface.modBrowser.UpdateNeeded = true; }
internal static void HandleFileAssociation(string file) { Console.WriteLine($"Attempting to install {file}"); if (File.Exists(file)) { string modName = Path.GetFileNameWithoutExtension(file); if (ModLoader.ModPath != Path.GetDirectoryName(file)) { File.Copy(file, Path.Combine(ModLoader.ModPath, Path.GetFileName(file)), true); File.Delete(file); Console.WriteLine($"{modName} installed successfully"); } ModLoader.EnableMod(modName); Console.WriteLine($"{modName} enabled"); } Console.WriteLine("Press any key to exit..."); Console.ReadKey(); Environment.Exit(0); }
internal void EnableDependencies(UIMouseEvent evt, UIElement listeningElement) { var modList = ModOrganizer.FindMods(); var missing = new List <string>(); foreach (var modRef in _modReferences) { ModLoader.EnableMod(modRef); if (modList.All(m => m.Name != modRef)) { missing.Add(modRef); } } Main.menuMode = Interface.modsMenuID; if (missing.Any()) { Interface.infoMessage.Show(Language.GetTextValue("tModLoader.ModDependencyModsNotFound", string.Join(",", missing)), Interface.modsMenuID); } }
private void EnableDepsRecursive(LocalMod[] modList, string[] modRefs, List <string> missingRefs) { foreach (var modRef in modRefs) { // To enable the ref, its own refs must also be enabled var refLocalMod = modList.FirstOrDefault(m => m.Name == modRef); if (refLocalMod != null) { // Enable refs recursively // This might trigger multiple "Enabling mod X" logs, but the enabled is a hash set so there will be no problems var modRefsOfModRef = refLocalMod.properties.modReferences.Select(x => x.mod).ToArray(); EnableDepsRecursive(modList, modRefsOfModRef, missingRefs); } else { missingRefs.Add(modRef); } ModLoader.EnableMod(modRef); Interface.modsMenu.FindUIModItem(modRef)?.Enable(); } }
public UIModItem(TmodFile mod) { this.mod = mod; this.BorderColor = new Color(89, 116, 213) * 0.7f; this.dividerTexture = TextureManager.Load("Images/UI/Divider"); this.innerPanelTexture = TextureManager.Load("Images/UI/InnerPanelBackground"); this.Height.Set(90f, 0f); this.Width.Set(0f, 1f); base.SetPadding(6f); //base.OnClick += this.ToggleEnabled; properties = BuildProperties.ReadModFile(mod); string text = properties.displayName.Length > 0 ? properties.displayName : mod.name; text += " v" + mod.version; if (mod.tModLoaderVersion < new Version(0, 10)) { text += " [c/FF0000:(Old mod, enable at own risk)]"; } int modIconAdjust = 0; if (mod.HasFile("icon.png")) { var modIconTexture = Texture2D.FromStream(Main.instance.GraphicsDevice, new MemoryStream(mod.GetFile("icon.png"))); if (modIconTexture.Width == 80 && modIconTexture.Height == 80) { modIcon = new UIImage(modIconTexture); modIcon.Left.Set(0f, 0f); modIcon.Top.Set(0f, 0f); Append(modIcon); modIconAdjust += 85; } } this.modName = new UIText(text, 1f, false); this.modName.Left.Set(modIconAdjust + 10f, 0f); this.modName.Top.Set(5f, 0f); base.Append(this.modName); this.enabled = ModLoader.IsEnabled(mod); UITextPanel <string> button = new UITextPanel <string>(Language.GetTextValue("tModLoader.ModsMoreInfo"), 1f, false); button.Width.Set(100f, 0f); button.Height.Set(30f, 0f); button.Left.Set(430f, 0f); button.Top.Set(40f, 0f); button.PaddingTop -= 2f; button.PaddingBottom -= 2f; button.OnMouseOver += UICommon.FadedMouseOver; button.OnMouseOut += UICommon.FadedMouseOut; button.OnClick += this.Moreinfo; base.Append(button); button2 = new UITextPanel <string>(this.enabled ? Language.GetTextValue("tModLoader.ModsDisable") : Language.GetTextValue("tModLoader.ModsEnable"), 1f, false); button2.Width.Set(100f, 0f); button2.Height.Set(30f, 0f); button2.Left.Set(button.Left.Pixels - button2.Width.Pixels - 5f, 0f); button2.Top.Set(40f, 0f); button2.PaddingTop -= 2f; button2.PaddingBottom -= 2f; button2.OnMouseOver += UICommon.FadedMouseOver; button2.OnMouseOut += UICommon.FadedMouseOut; button2.OnClick += this.ToggleEnabled; base.Append(button2); if (properties.modReferences.Length > 0 && !enabled) { string refs = String.Join(", ", properties.modReferences.Select(x => x.mod)); Texture2D icon = Texture2D.FromStream(Main.instance.GraphicsDevice, Assembly.GetExecutingAssembly().GetManifestResourceStream("Terraria.ModLoader.UI.ButtonExclamation.png")); UIHoverImage modReferenceIcon = new UIHoverImage(icon, "This mod depends on: " + refs + "\n (click to enable)"); modReferenceIcon.Left.Set(button2.Left.Pixels - 24f, 0f); modReferenceIcon.Top.Set(47f, 0f); modReferenceIcon.OnClick += (a, b) => { var referencedMods = properties.modReferences.Select(x => x.mod); var foundMods = ModLoader.FindMods(); var referencedtModFiles = foundMods.Where(x => referencedMods.Contains(x.name)); foreach (var referencedMod in referencedtModFiles) { ModLoader.EnableMod(referencedMod); } Main.menuMode = Interface.modsMenuID; var missingMods = referencedMods.Where(modstring => foundMods.All(modfile => modfile.name != modstring)); if (missingMods.Count() > 0) { Interface.infoMessage.SetMessage("The following mods were not found: " + String.Join(",", missingMods)); Interface.infoMessage.SetGotoMenu(Interface.modsMenuID); Main.menuMode = Interface.infoMessageID; } }; base.Append(modReferenceIcon); } if (mod.ValidModBrowserSignature) { keyImage = new UIHoverImage(Main.itemTexture[ID.ItemID.GoldenKey], Language.GetTextValue("tModLoader.ModsOriginatedFromModBrowser")); keyImage.Left.Set(-20, 1f); base.Append(keyImage); } if (ModLoader.ModLoaded(mod.name)) { Mod loadedMod = ModLoader.GetMod(mod.name); int[] values = { loadedMod.items.Count, loadedMod.npcs.Count, loadedMod.tiles.Count, loadedMod.walls.Count, loadedMod.buffs.Count, loadedMod.mountDatas.Count }; string[] strings = { " items", " NPCs", " tiles", " walls", " buffs", " mounts" }; int xOffset = -40; for (int i = 0; i < values.Length; i++) { if (values[i] > 0) { Texture2D iconTexture = Main.instance.infoIconTexture[i]; keyImage = new UIHoverImage(iconTexture, values[i] + strings[i]); keyImage.Left.Set(xOffset, 1f); base.Append(keyImage); xOffset -= 18; } } } }
public UIModItem(LocalMod mod) { this.mod = mod; 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); //base.OnClick += this.ToggleEnabled; string text = mod.DisplayName + " v" + mod.modFile.version; if (mod.tModLoaderVersion < new Version(0, 10)) { text += $" [c/FF0000:({Language.GetTextValue("tModLoader.ModOldWarning")})]"; } if (mod.modFile.HasFile("icon.png")) { try { Texture2D modIconTexture; using (mod.modFile.Open()) using (var s = mod.modFile.GetStream("icon.png")) modIconTexture = Texture2D.FromStream(Main.instance.GraphicsDevice, s); if (modIconTexture.Width == 80 && modIconTexture.Height == 80) { modIcon = new UIImage(modIconTexture) { Left = { Percent = 0f }, Top = { Percent = 0f } }; Append(modIcon); modIconAdjust += 85; } } catch { } } modName = new UIText(text) { Left = new StyleDimension(modIconAdjust + 10f, 0f), Top = { Pixels = 5 } }; Append(modName); var moreInfoButton = new UIAutoScaleTextTextPanel <string>(Language.GetTextValue("tModLoader.ModsMoreInfo")) { Width = { Pixels = 100 }, Height = { Pixels = 36 }, Left = { Pixels = 430 }, Top = { Pixels = 40 } }.WithFadedMouseOver(); moreInfoButton.PaddingTop -= 2f; moreInfoButton.PaddingBottom -= 2f; moreInfoButton.OnClick += Moreinfo; Append(moreInfoButton); toggleModEnabledButton = new UIAutoScaleTextTextPanel <string>(mod.Enabled ? Language.GetTextValue("tModLoader.ModsDisable") : Language.GetTextValue("tModLoader.ModsEnable")) { Width = { Pixels = 100 }, Height = { Pixels = 36 }, Top = { Pixels = 40 } }.WithFadedMouseOver(); toggleModEnabledButton.Left.Pixels = moreInfoButton.Left.Pixels - toggleModEnabledButton.Width.Pixels - 5f; toggleModEnabledButton.PaddingTop -= 2f; toggleModEnabledButton.PaddingBottom -= 2f; toggleModEnabledButton.OnClick += ToggleEnabled; Append(toggleModEnabledButton); Mod loadedMod = ModLoader.GetMod(mod.Name); if (loadedMod != null && ConfigManager.Configs.ContainsKey(loadedMod)) // and has config { configButton = new UITextPanel <string>("Config", 1f, false); configButton.Width.Set(100f, 0f); configButton.Height.Set(30f, 0f); configButton.Left.Set(toggleModEnabledButton.Left.Pixels - configButton.Width.Pixels - 5f, 0f); configButton.Top.Set(40f, 0f); configButton.PaddingTop -= 2f; configButton.PaddingBottom -= 2f; configButton.WithFadedMouseOver(); configButton.OnClick += this.OpenConfig; Append(configButton); if (ConfigManager.ModNeedsReload(loadedMod)) { configChangesRequireReload = true; } } var modRefs = mod.properties.modReferences.Select(x => x.mod).ToArray(); if (modRefs.Length > 0 && !mod.Enabled) { string refs = string.Join(", ", mod.properties.modReferences); var icon = Texture2D.FromStream(Main.instance.GraphicsDevice, Assembly.GetExecutingAssembly().GetManifestResourceStream("Terraria.ModLoader.UI.ButtonExclamation.png")); var modReferenceIcon = new UIHoverImage(icon, Language.GetTextValue("tModLoader.ModDependencyClickTooltip", refs)) { Left = new StyleDimension(toggleModEnabledButton.Left.Pixels - 24f, 0f), Top = { Pixels = 47 } }; modReferenceIcon.OnClick += (a, b) => { var modList = ModOrganizer.FindMods(); var missing = new List <string>(); foreach (var modRef in modRefs) { ModLoader.EnableMod(modRef); if (!modList.Any(m => m.Name == modRef)) { missing.Add(modRef); } } Main.menuMode = Interface.modsMenuID; if (missing.Any()) { Interface.infoMessage.Show(Language.GetTextValue("tModLoader.ModDependencyModsNotFound", String.Join(",", missing)), Interface.modsMenuID); } }; Append(modReferenceIcon); } if (mod.modFile.ValidModBrowserSignature) { keyImage = new UIHoverImage(Main.itemTexture[ID.ItemID.GoldenKey], Language.GetTextValue("tModLoader.ModsOriginatedFromModBrowser")) { Left = { Pixels = -20, Percent = 1f } }; Append(keyImage); } if (ModLoader.badUnloaders.Contains(mod.Name)) { keyImage = new UIHoverImage(Texture2D.FromStream(Main.instance.GraphicsDevice, Assembly.GetExecutingAssembly().GetManifestResourceStream("Terraria.ModLoader.UI.ButtonError.png")), "This mod did not fully unload during last unload.") { Left = { Pixels = modIconAdjust + 4 }, Top = { Pixels = 3 } }; Append(keyImage); modName.Left.Pixels += 20; } if (mod.properties.beta) { keyImage = new UIHoverImage(Main.itemTexture[ID.ItemID.ShadowKey], Language.GetTextValue("tModLoader.BetaModCantPublish")) { Left = { Pixels = -10, Percent = 1f } }; Append(keyImage); } if (loadedMod != null) { loaded = true; int[] values = { loadedMod.items.Count, loadedMod.npcs.Count, loadedMod.tiles.Count, loadedMod.walls.Count, loadedMod.buffs.Count, loadedMod.mountDatas.Count }; string[] localizationKeys = { "ModsXItems", "ModsXNPCs", "ModsXTiles", "ModsXWalls", "ModsXBuffs", "ModsXMounts" }; int xOffset = -40; for (int i = 0; i < values.Length; i++) { if (values[i] > 0) { Texture2D iconTexture = Main.instance.infoIconTexture[i]; keyImage = new UIHoverImage(iconTexture, Language.GetTextValue($"tModLoader.{localizationKeys[i]}", values[i])) { Left = { Pixels = xOffset, Percent = 1f } }; Append(keyImage); xOffset -= 18; } } } }
public UIModItem(LocalMod mod) { this.mod = mod; this.BorderColor = new Color(89, 116, 213) * 0.7f; this.dividerTexture = TextureManager.Load("Images/UI/Divider"); this.innerPanelTexture = TextureManager.Load("Images/UI/InnerPanelBackground"); this.Height.Set(90f, 0f); this.Width.Set(0f, 1f); base.SetPadding(6f); //base.OnClick += this.ToggleEnabled; string text = mod.DisplayName + " v" + mod.modFile.version; if (mod.tModLoaderVersion < new Version(0, 10)) { text += $" [c/FF0000:({Language.GetTextValue("tModLoader.ModOldWarning")})]"; } if (mod.modFile.HasFile("icon.png")) { try { Texture2D modIconTexture; using (mod.modFile.EnsureOpen()) using (var s = mod.modFile.GetStream("icon.png")) modIconTexture = Texture2D.FromStream(Main.instance.GraphicsDevice, s); if (modIconTexture.Width == 80 && modIconTexture.Height == 80) { modIcon = new UIImage(modIconTexture); modIcon.Left.Set(0f, 0f); modIcon.Top.Set(0f, 0f); Append(modIcon); modIconAdjust += 85; } } catch { } } this.modName = new UIText(text, 1f, false); this.modName.Left.Set(modIconAdjust + 10f, 0f); this.modName.Top.Set(5f, 0f); base.Append(this.modName); UIAutoScaleTextTextPanel <string> moreInfoButton = new UIAutoScaleTextTextPanel <string>(Language.GetTextValue("tModLoader.ModsMoreInfo"), 1f, false); moreInfoButton.Width.Set(100f, 0f); moreInfoButton.Height.Set(36f, 0f); moreInfoButton.Left.Set(430f, 0f); moreInfoButton.Top.Set(40f, 0f); moreInfoButton.PaddingTop -= 2f; moreInfoButton.PaddingBottom -= 2f; moreInfoButton.OnMouseOver += UICommon.FadedMouseOver; moreInfoButton.OnMouseOut += UICommon.FadedMouseOut; moreInfoButton.OnClick += this.Moreinfo; base.Append(moreInfoButton); toggleModEnabledButton = new UIAutoScaleTextTextPanel <string>(mod.Enabled ? Language.GetTextValue("tModLoader.ModsDisable") : Language.GetTextValue("tModLoader.ModsEnable"), 1f, false); toggleModEnabledButton.Width.Set(100f, 0f); toggleModEnabledButton.Height.Set(36f, 0f); toggleModEnabledButton.Left.Set(moreInfoButton.Left.Pixels - toggleModEnabledButton.Width.Pixels - 5f, 0f); toggleModEnabledButton.Top.Set(40f, 0f); toggleModEnabledButton.PaddingTop -= 2f; toggleModEnabledButton.PaddingBottom -= 2f; toggleModEnabledButton.OnMouseOver += UICommon.FadedMouseOver; toggleModEnabledButton.OnMouseOut += UICommon.FadedMouseOut; toggleModEnabledButton.OnClick += this.ToggleEnabled; base.Append(toggleModEnabledButton); var modRefs = mod.properties.modReferences.Select(x => x.mod).ToArray(); if (modRefs.Length > 0 && !mod.Enabled) { string refs = String.Join(", ", mod.properties.modReferences); Texture2D icon = Texture2D.FromStream(Main.instance.GraphicsDevice, Assembly.GetExecutingAssembly().GetManifestResourceStream("Terraria.ModLoader.UI.ButtonExclamation.png")); UIHoverImage modReferenceIcon = new UIHoverImage(icon, Language.GetTextValue("tModLoader.ModDependencyClickTooltip", refs)); modReferenceIcon.Left.Set(toggleModEnabledButton.Left.Pixels - 24f, 0f); modReferenceIcon.Top.Set(47f, 0f); modReferenceIcon.OnClick += (a, b) => { var modList = ModOrganizer.FindMods(); var missing = new List <string>(); foreach (var modRef in modRefs) { ModLoader.EnableMod(modRef); if (!modList.Any(m => m.Name == modRef)) { missing.Add(modRef); } } Main.menuMode = Interface.modsMenuID; if (missing.Any()) { Interface.infoMessage.SetMessage(Language.GetTextValue("tModLoader.ModDependencyModsNotFound", String.Join(",", missing))); Interface.infoMessage.SetGotoMenu(Interface.modsMenuID); Main.menuMode = Interface.infoMessageID; } }; base.Append(modReferenceIcon); } if (mod.modFile.ValidModBrowserSignature) { keyImage = new UIHoverImage(Main.itemTexture[ID.ItemID.GoldenKey], Language.GetTextValue("tModLoader.ModsOriginatedFromModBrowser")); keyImage.Left.Set(-20, 1f); base.Append(keyImage); } if (mod.properties.beta) { keyImage = new UIHoverImage(Main.itemTexture[ID.ItemID.ShadowKey], Language.GetTextValue("tModLoader.BetaModCantPublish")); keyImage.Left.Set(-10, 1f); Append(keyImage); } Mod loadedMod = ModLoader.GetMod(mod.Name); if (loadedMod != null) { loaded = true; int[] values = { loadedMod.items.Count, loadedMod.npcs.Count, loadedMod.tiles.Count, loadedMod.walls.Count, loadedMod.buffs.Count, loadedMod.mountDatas.Count }; string[] localizationKeys = { "ModsXItems", "ModsXNPCs", "ModsXTiles", "ModsXWalls", "ModsXBuffs", "ModsXMounts" }; int xOffset = -40; for (int i = 0; i < values.Length; i++) { if (values[i] > 0) { Texture2D iconTexture = Main.instance.infoIconTexture[i]; keyImage = new UIHoverImage(iconTexture, Language.GetTextValue($"tModLoader.{localizationKeys[i]}", values[i])); keyImage.Left.Set(xOffset, 1f); base.Append(keyImage); xOffset -= 18; } } } }
// TODO: Delete this. Use UIDownloadMods internal void DownloadMod(UIMouseEvent evt, UIElement listeningElement) { Main.PlaySound(SoundID.MenuTick); try { if (UIModBrowser.PlatformSupportsTls12) // Needed for downloads from Github { ServicePointManager.SecurityProtocol |= (SecurityProtocolType)3072; // SecurityProtocolType.Tls12 } using (WebClient client = new WebClient()) { ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => { return(true); }); Interface.modBrowser.selectedItem = this; Interface.downloadMod.SetDownloading(displayname); Interface.downloadMod.SetCancel(client.CancelAsync); client.DownloadProgressChanged += (s, e) => { Interface.downloadMod.SetProgress(e); }; client.DownloadFileCompleted += (s, e) => { Main.menuMode = Interface.modBrowserID; if (e.Error != null) { if (e.Cancelled) { } else { // TODO yuck HttpStatusCode httpStatusCode = GetHttpStatusCode(e.Error); if (httpStatusCode == HttpStatusCode.ServiceUnavailable) { Interface.errorMessage.Show(Language.GetTextValue("tModLoader.MBExceededBandwidth"), 0); } else { Interface.errorMessage.Show(Language.GetTextValue("tModLoader.MBUnknownMBError"), 0); } } } else if (!e.Cancelled) { // Downloaded OK File.Copy(ModLoader.ModPath + Path.DirectorySeparatorChar + "temporaryDownload.tmod", ModLoader.ModPath + Path.DirectorySeparatorChar + mod + ".tmod", true); if (!update) { Interface.modBrowser.aNewModDownloaded = true; } else { Interface.modBrowser.aModUpdated = true; } if (ModLoader.autoReloadAndEnableModsLeavingModBrowser) { ModLoader.EnableMod(mod); } RemoveChild(updateButton); } // Clean up: Delete temp File.Delete(ModLoader.ModPath + Path.DirectorySeparatorChar + "temporaryDownload.tmod"); }; client.DownloadFileAsync(new Uri(download), ModLoader.ModPath + Path.DirectorySeparatorChar + "temporaryDownload.tmod"); //client.DownloadFileAsync(new Uri(download), ModLoader.ModPath + Path.DirectorySeparatorChar + mod + ".tmod"); } Main.menuMode = Interface.downloadModID; } catch (WebException e) { UIModBrowser.LogModBrowserException(e); } }