internal void Populate() { if (SynchronizationContext.Current == null) { SynchronizationContext.SetSynchronizationContext(new SynchronizationContext()); } Task.Factory.StartNew( delegate { var modSources = ModLoader.FindModSources(); var modFiles = ModLoader.FindMods(); return(Tuple.Create(modSources, modFiles)); }) .ContinueWith(task => { var modSources = task.Result.Item1; var modFiles = task.Result.Item2; foreach (string sourcePath in modSources) { var builtMod = modFiles.SingleOrDefault(m => m.Name == Path.GetFileName(sourcePath)); items.Add(new UIModSourceItem(sourcePath, builtMod)); } updateNeeded = true; }, TaskScheduler.FromCurrentSynchronizationContext()); }
private void Publish(UIMouseEvent evt, UIElement listeningElement) { Main.PlaySound(10, -1, -1, 1); try { TmodFile[] modFiles = ModLoader.FindMods(); bool ok = false; TmodFile theTModFile = null; foreach (TmodFile tModFile in modFiles) { if (Path.GetFileName(tModFile.Name).Equals(@Path.GetFileName(mod) + @".tmod")) { ok = true; theTModFile = tModFile; } } if (!ok) { throw new Exception(); } System.Net.ServicePointManager.Expect100Continue = false; string filename = @ModLoader.ModPath + @Path.DirectorySeparatorChar + @Path.GetFileName(mod) + @".tmod"; string url = "http://javid.ddns.net/tModLoader/publishmod.php"; using (var stream = File.Open(filename, FileMode.Open)) { var files = new[] { new IO.UploadFile { Name = "file", Filename = Path.GetFileName(filename), // ContentType = "text/plain", Stream = stream } }; BuildProperties bp = BuildProperties.ReadModFile(theTModFile); var values = new NameValueCollection { { "displayname", bp.displayName }, { "name", Path.GetFileNameWithoutExtension(filename) }, { "version", bp.version }, { "author", bp.author }, { "homepage", bp.homepage }, { "description", bp.description }, { "steamid64", Steamworks.SteamUser.GetSteamID().ToString() }, { "modloaderversion", bp.modBuildVersion }, }; byte[] result = IO.UploadFile.UploadFiles(url, files, values); string s = System.Text.Encoding.UTF8.GetString(result, 0, result.Length); ErrorLogger.LogModPublish(s); } } catch (WebException e) { ErrorLogger.LogModBrowserException(e); } }
public override void OnActivate() { modList.Clear(); items.Clear(); string[] mods = ModLoader.FindMods(); foreach (string mod in mods) { UIModItem modItem = new UIModItem(mod); modList.Add(modItem); items.Add(modItem); } }
public UIModSourceItem(string mod) { this.mod = mod; this.BorderColor = new Color(89, 116, 213) * 0.7f; this.dividerTexture = TextureManager.Load("Images/UI/Divider"); this.Height.Set(90f, 0f); this.Width.Set(0f, 1f); base.SetPadding(6f); this.modName = new UIText(Path.GetFileName(mod), 1f, false); this.modName.Left.Set(10f, 0f); this.modName.Top.Set(5f, 0f); base.Append(this.modName); UITextPanel button = new UITextPanel("Build", 1f, false); button.Width.Set(100f, 0f); button.Height.Set(30f, 0f); button.Left.Set(10f, 0f); button.Top.Set(40f, 0f); button.PaddingTop -= 2f; button.PaddingBottom -= 2f; button.OnMouseOver += new UIElement.MouseEvent(FadedMouseOver); button.OnMouseOut += new UIElement.MouseEvent(FadedMouseOut); button.OnClick += new UIElement.MouseEvent(this.BuildMod); base.Append(button); UITextPanel button2 = new UITextPanel("Build + Reload", 1f, false); button2.CopyStyle(button); button2.Width.Set(200f, 0f); button2.Left.Set(150f, 0f); button2.OnMouseOver += new UIElement.MouseEvent(FadedMouseOver); button2.OnMouseOut += new UIElement.MouseEvent(FadedMouseOut); button2.OnClick += new UIElement.MouseEvent(this.BuildAndReload); base.Append(button2); TmodFile[] modFiles = ModLoader.FindMods(); foreach (TmodFile file in modFiles) { if (Path.GetFileNameWithoutExtension(file.Name).Equals(Path.GetFileName(mod))) { UITextPanel button3 = new UITextPanel("Publish", 1f, false); button3.CopyStyle(button2); button3.Width.Set(100f, 0f); button3.Left.Set(390f, 0f); button3.OnMouseOver += new UIElement.MouseEvent(FadedMouseOver); button3.OnMouseOut += new UIElement.MouseEvent(FadedMouseOut); button3.OnClick += new UIElement.MouseEvent(this.Publish); base.Append(button3); } } base.OnDoubleClick += new UIElement.MouseEvent(this.BuildAndReload); }
public override void OnActivate() { Main.clrInput(); modListAll.Clear(); items.Clear(); TmodFile[] mods = ModLoader.FindMods(); foreach (TmodFile mod in mods) { UIModItem modItem = new UIModItem(mod); modListAll.Add(modItem); items.Add(modItem); } FilterList(); }
public static void SaveModList(string filename) { // TODO //Main.menuMode = Interface.modsMenuID; //Main.PlaySound(10, -1, -1, 1); Directory.CreateDirectory(ModListSaveDirectory); string path = ModListSaveDirectory + Path.DirectorySeparatorChar + filename + ".json"; var foundMods = ModLoader.FindMods().Select(x => x.Name).Intersect(ModLoader.EnabledMods).ToList(); string json = JsonConvert.SerializeObject(foundMods, Formatting.Indented); File.WriteAllText(path, json); Main.menuMode = Interface.modPacksMenuID; // should reload }
public override void OnActivate() { if (!scrollPanel.HasChild(uiLoader)) { scrollPanel.Append(uiLoader); } modListList.Clear(); if (SynchronizationContext.Current == null) { SynchronizationContext.SetSynchronizationContext(new SynchronizationContext()); } Task.Factory .StartNew(delegate { mods = ModLoader.FindMods(); return(FindModLists()); }) .ContinueWith(task => { string[] modListsFullPath = task.Result; foreach (string modListFilePath in modListsFullPath) { string[] mods = { }; //string path = ModListSaveDirectory + Path.DirectorySeparatorChar + modListFilePath + ".json"; if (File.Exists(modListFilePath)) { using (StreamReader r = new StreamReader(modListFilePath)) { string json = r.ReadToEnd(); mods = JsonConvert.DeserializeObject <string[]>(json); } } UIModPackItem modItem = new UIModPackItem(Path.GetFileNameWithoutExtension(modListFilePath), mods); modListList.Add(modItem); } if (scrollPanel.HasChild(uiLoader)) { scrollPanel.RemoveChild(uiLoader); } }, TaskScheduler.FromCurrentSynchronizationContext()); }
public override void OnActivate() { modList.Clear(); string[] mods = ModLoader.FindModSources(); TmodFile[] modFiles = ModLoader.FindMods(); foreach (string mod in mods) { bool publishable = false; foreach (TmodFile file in modFiles) { if (Path.GetFileNameWithoutExtension(file.Name).Equals(Path.GetFileName(mod))) { publishable = true; break; } } modList.Add(new UIModSourceItem(mod, publishable)); } }
internal void Populate() { loading = true; if (SynchronizationContext.Current == null) { SynchronizationContext.SetSynchronizationContext(new SynchronizationContext()); } Task.Factory .StartNew(delegate { var mods = ModLoader.FindModSources(); var modFiles = ModLoader.FindMods(); return(new Tuple <string[], TmodFile[]>(mods, modFiles)); }) .ContinueWith(task => { string[] mods = task.Result.Item1; TmodFile[] modFiles = task.Result.Item2; foreach (string mod in mods) { bool publishable = false; DateTime lastBuildTime = new DateTime(); foreach (TmodFile file in modFiles) { var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file.path); if (fileNameWithoutExtension != null && fileNameWithoutExtension.Equals(Path.GetFileName(mod))) { lastBuildTime = File.GetLastWriteTime(file.path); publishable = true; break; } } modList.Add(new UIModSourceItem(mod, publishable, lastBuildTime)); } if (uIPanel.HasChild(uiLoader)) { uIPanel.RemoveChild(uiLoader); } loading = false; }, TaskScheduler.FromCurrentSynchronizationContext()); }
public static void SaveModList(string filename) { // TODO //Main.menuMode = Interface.modsMenuID; string[] enabledMods = ModLoader.FindMods() .Where(ModLoader.IsEnabled) .Select(mod => mod.name) .ToArray(); //Main.PlaySound(10, -1, -1, 1); Directory.CreateDirectory(ModListSaveDirectory); string path = ModListSaveDirectory + Path.DirectorySeparatorChar + filename + ".json"; string json = JsonConvert.SerializeObject(enabledMods, Newtonsoft.Json.Formatting.Indented); File.WriteAllText(path, json); Main.menuMode = Interface.modPacksMenuID; // should reload }
public void UploadComplete(Object sender, UploadValuesCompletedEventArgs e) { if (e.Error != null) { if (e.Cancelled) { } else { HttpStatusCode httpStatusCode = GetHttpStatusCode(e.Error); if (httpStatusCode == HttpStatusCode.ServiceUnavailable) { SetHeading("Mod Browser OFFLINE (Busy)"); } else { SetHeading("Mod Browser OFFLINE (Unknown)"); } } } else if (!e.Cancelled) { byte[] result = e.Result; string response = System.Text.Encoding.UTF8.GetString(result); // TODO: UI will still be unresponsive here TmodFile[] modFiles = ModLoader.FindMods(); List <BuildProperties> modBuildProperties = new List <BuildProperties>(); foreach (TmodFile tmodfile in modFiles) { modBuildProperties.Add(BuildProperties.ReadModFile(tmodfile)); } PopulateFromJSON(modBuildProperties, response); } loading = false; reloadButton.SetText("Reload Mods"); }
public override void OnActivate() { mods = ModLoader.FindMods(); modListList.Clear(); string[] modListsFullPath = FindModLists(); foreach (string modListFilePath in modListsFullPath) { string[] mods = { }; //string path = ModListSaveDirectory + Path.DirectorySeparatorChar + modListFilePath + ".json"; if (File.Exists(modListFilePath)) { using (StreamReader r = new StreamReader(modListFilePath)) { string json = r.ReadToEnd(); mods = JsonConvert.DeserializeObject <string[]>(json); } } UIModPackItem modItem = new UIModPackItem(Path.GetFileNameWithoutExtension(modListFilePath), mods); modListList.Add(modItem); } }
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.modFile.tModLoaderVersion < new Version(0, 10)) { text += $" [c/FF0000:({Language.GetTextValue("tModLoader.ModOldWarning")})]"; } if (mod.modFile.HasFile("icon.png")) { try { var modIconTexture = Texture2D.FromStream(Main.instance.GraphicsDevice, new MemoryStream(mod.modFile.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; } } 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); 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>(mod.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); 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(button2.Left.Pixels - 24f, 0f); modReferenceIcon.Top.Set(47f, 0f); modReferenceIcon.OnClick += (a, b) => { var modList = ModLoader.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; } } } }
private void Publish(UIMouseEvent evt, UIElement listeningElement) { if (ModLoader.modBrowserPassphrase == "") { Main.menuMode = Interface.enterPassphraseMenuID; Interface.enterPassphraseMenu.SetGotoMenu(Interface.modSourcesID); return; } Main.PlaySound(10, -1, -1, 1); try { TmodFile[] modFiles = ModLoader.FindMods(); bool ok = false; TmodFile theTModFile = null; foreach (TmodFile tModFile in modFiles) { if (Path.GetFileName(tModFile.path).Equals(@Path.GetFileName(mod) + @".tmod")) { ok = true; theTModFile = tModFile; } } if (!ok) { throw new Exception(); } System.Net.ServicePointManager.Expect100Continue = false; string filename = @ModLoader.ModPath + @Path.DirectorySeparatorChar + @Path.GetFileName(mod) + @".tmod"; string url = "http://javid.ddns.net/tModLoader/publishmod.php"; using (var iconStream = theTModFile.HasFile("icon.png") ? new MemoryStream(theTModFile.GetFile("icon.png")) : null) using (var stream = File.Open(filename, FileMode.Open)) { var files = new List <UploadFile>(); files.Add(new IO.UploadFile { Name = "file", Filename = Path.GetFileName(filename), // ContentType = "text/plain", Stream = stream } ); if (iconStream != null) { files.Add(new IO.UploadFile { Name = "iconfile", Filename = "icon.png", Stream = iconStream } ); } BuildProperties bp = BuildProperties.ReadModFile(theTModFile); var values = new NameValueCollection { { "displayname", bp.displayName }, { "name", Path.GetFileNameWithoutExtension(filename) }, { "version", "v" + bp.version }, { "author", bp.author }, { "homepage", bp.homepage }, { "description", bp.description }, { "steamid64", ModLoader.SteamID64 }, { "modloaderversion", "tModLoader v" + theTModFile.tModLoaderVersion }, { "passphrase", ModLoader.modBrowserPassphrase }, { "modreferences", String.Join(", ", bp.modReferences.Select(x => x.mod)) }, { "modside", bp.side.ToFriendlyString() }, }; using (PatientWebClient client = new PatientWebClient()) { ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => { return(true); }); Interface.uploadMod.SetDownloading(Path.GetFileNameWithoutExtension(filename)); Interface.uploadMod.SetCancel(() => { Main.menuMode = Interface.modSourcesID; client.CancelAsync(); }); client.UploadProgressChanged += (s, e) => Interface.uploadMod.SetProgress(e); client.UploadDataCompleted += (s, e) => PublishUploadDataComplete(s, e, theTModFile); var boundary = "---------------------------" + DateTime.Now.Ticks.ToString("x", System.Globalization.NumberFormatInfo.InvariantInfo); client.Headers["Content-Type"] = "multipart/form-data; boundary=" + boundary; boundary = "--" + boundary; byte[] data = IO.UploadFile.GetUploadFilesRequestData(files, values); client.UploadDataAsync(new Uri(url), data); } Main.menuMode = Interface.uploadModID; } } catch (WebException e) { ErrorLogger.LogModBrowserException(e); } }
public override void OnActivate() { if (!loaded) { uITextPanel.SetText("Mod Browser", 0.8f, true); modListAll.Clear(); TmodFile[] modFiles = ModLoader.FindMods(); List <BuildProperties> modBuildProperties = new List <BuildProperties>(); foreach (TmodFile tmodfile in modFiles) { modBuildProperties.Add(BuildProperties.ReadModFile(tmodfile)); } XmlDocument xmlDoc = new XmlDocument(); try { // xmlDoc = GetDataFromUrl("http://javid.ddns.net/tModLoader/listmods.php"); System.Net.ServicePointManager.Expect100Continue = false; string url = "http://javid.ddns.net/tModLoader/listmods.php"; IO.UploadFile[] files = new IO.UploadFile[0]; var values = new NameValueCollection { { "modloaderversion", ModLoader.version }, }; byte[] result = IO.UploadFile.UploadFiles(url, files, values); xmlDoc.LoadXml(System.Text.Encoding.UTF8.GetString(result, 0, result.Length)); } catch (WebException e) { if (e.Status == WebExceptionStatus.Timeout) { uITextPanel.SetText("Mod Browser OFFLINE (Busy)", 0.8f, true); return; } if (e.Status == WebExceptionStatus.ProtocolError) { var resp = (HttpWebResponse)e.Response; if (resp.StatusCode == HttpStatusCode.NotFound) { uITextPanel.SetText("Mod Browser OFFLINE (404)", 0.8f, true); return; } uITextPanel.SetText("Mod Browser OFFLINE..", 0.8f, true); return; } } catch (Exception e) { ErrorLogger.LogModBrowserException(e); return; } try { foreach (XmlNode xmlNode in xmlDoc.DocumentElement) { if (xmlNode.Name.Equals("update")) { updateAvailable = true; updateText = xmlNode.SelectSingleNode("message").InnerText; updateURL = xmlNode.SelectSingleNode("url").InnerText; } else if (xmlNode.Name.Equals("modlist")) { foreach (XmlNode xmlNode2 in xmlNode) { string displayname = xmlNode2.SelectSingleNode("displayname").InnerText; string name = xmlNode2.SelectSingleNode("name").InnerText; string version = xmlNode2.SelectSingleNode("version").InnerText; string author = xmlNode2.SelectSingleNode("author").InnerText; string description = xmlNode2.SelectSingleNode("description").InnerText; string homepage = xmlNode2.SelectSingleNode("homepage").InnerText; string download = xmlNode2.SelectSingleNode("download").InnerText; string timeStamp = xmlNode2.SelectSingleNode("updateTimeStamp").InnerText; int downloads; Int32.TryParse(xmlNode2.SelectSingleNode("downloads").InnerText, out downloads); bool exists = false; bool update = false; foreach (BuildProperties bp in modBuildProperties) { if (bp.displayName.Equals(displayname)) { exists = true; if (!bp.version.Equals(version)) { update = true; } } } UIModDownloadItem modItem = new UIModDownloadItem(displayname, name, version, author, description, homepage, download, downloads, timeStamp, update, exists); modListAll.Add(modItem); } SortList(null, null); } } } catch (Exception e) { ErrorLogger.LogModBrowserException(e); return; } loaded = true; } }
private void Publish(UIMouseEvent evt, UIElement listeningElement) { if (ModLoader.modBrowserPassphrase == "") { Main.menuMode = Interface.enterPassphraseMenuID; Interface.enterPassphraseMenu.SetGotoMenu(Interface.modSourcesID); return; } Main.PlaySound(10, -1, -1, 1); try { TmodFile[] modFiles = ModLoader.FindMods(); bool ok = false; TmodFile theTModFile = null; foreach (TmodFile tModFile in modFiles) { if (Path.GetFileName(tModFile.path).Equals(@Path.GetFileName(mod) + @".tmod")) { ok = true; theTModFile = tModFile; } } if (!ok) { throw new Exception(); } System.Net.ServicePointManager.Expect100Continue = false; string filename = @ModLoader.ModPath + @Path.DirectorySeparatorChar + @Path.GetFileName(mod) + @".tmod"; string url = "http://javid.ddns.net/tModLoader/publishmod.php"; byte[] result; using (var stream = File.Open(filename, FileMode.Open)) { var files = new[] { new IO.UploadFile { Name = "file", Filename = Path.GetFileName(filename), // ContentType = "text/plain", Stream = stream } }; BuildProperties bp = BuildProperties.ReadModFile(theTModFile); var values = new NameValueCollection { { "displayname", bp.displayName }, { "name", Path.GetFileNameWithoutExtension(filename) }, { "version", "v" + bp.version }, { "author", bp.author }, { "homepage", bp.homepage }, { "description", bp.description }, { "steamid64", ModLoader.SteamID64 }, { "modloaderversion", "tModLoader v" + theTModFile.tModLoaderVersion }, { "passphrase", ModLoader.modBrowserPassphrase } }; result = IO.UploadFile.UploadFiles(url, files, values); } int responseLength = result.Length; if (result.Length > 256 && result[result.Length - 256 - 1] == '~') { Array.Copy(result, result.Length - 256, theTModFile.signature, 0, 256); theTModFile.Save(); responseLength -= 257; } string s = System.Text.Encoding.UTF8.GetString(result, 0, responseLength); ErrorLogger.LogModPublish(s); } catch (WebException e) { ErrorLogger.LogModBrowserException(e); } }
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 override void OnActivate() { if (!loaded) { modList.Clear(); TmodFile[] modFiles = ModLoader.FindMods(); List <BuildProperties> modBuildProperties = new List <BuildProperties>(); foreach (TmodFile tmodfile in modFiles) { modBuildProperties.Add(BuildProperties.ReadModFile(tmodfile)); } XmlDocument xmlDoc = new XmlDocument(); try { xmlDoc = GetDataFromUrl("http://javid.ddns.net/tModLoader/listmods.php"); } catch (WebException e) { if (e.Status == WebExceptionStatus.Timeout) { uITextPanel.SetText("Mod Browser OFFLINE", 0.8f, true); return; } } catch (Exception e) { ErrorLogger.LogModBrowserException(e); return; } foreach (XmlNode xmlNode in xmlDoc.DocumentElement) { string displayname = xmlNode.SelectSingleNode("displayname").InnerText; string name = xmlNode.SelectSingleNode("name").InnerText; string version = xmlNode.SelectSingleNode("version").InnerText; string author = xmlNode.SelectSingleNode("author").InnerText; string description = xmlNode.SelectSingleNode("description").InnerText; string download = xmlNode.SelectSingleNode("download").InnerText; string timeStamp = xmlNode.SelectSingleNode("updateTimeStamp").InnerText; int downloads; Int32.TryParse(xmlNode.SelectSingleNode("downloads").InnerText, out downloads); bool exists = false; bool update = false; foreach (BuildProperties bp in modBuildProperties) { if (bp.displayName.Equals(displayname)) { exists = true; if (!bp.version.Equals(version)) { update = true; } } } // if (!exists || update) // { UIModDownloadItem modItem = new UIModDownloadItem(/*this, */ displayname, name, version, author, description, download, downloads, timeStamp, update, exists); modList.Add(modItem); // } } loaded = true; } }