상속: Terraria.GameContent.UI.Elements.UIImage
예제 #1
0
        protected override void DrawSelf(SpriteBatch spriteBatch)
        {
            base.DrawSelf(spriteBatch);
            CalculatedStyle innerDimensions = GetInnerDimensions();
            Vector2         drawPos         = new Vector2(innerDimensions.X + 5f, innerDimensions.Y + 30f);

            spriteBatch.Draw(_dividerTexture, drawPos, null, Color.White, 0f, Vector2.Zero, new Vector2((innerDimensions.Width - 10f) / 8f, 1f), SpriteEffects.None, 0f);

            // This code here rather than ctor since the delay for dozens of mod source folders is noticable.
            if (!_upgradePotentialChecked)
            {
                _upgradePotentialChecked = true;
                string modFolderName = Path.GetFileName(_mod);
                string csprojFile    = Path.Combine(_mod, $"{modFolderName}.csproj");
                if (!File.Exists(csprojFile) || !File.ReadAllText(csprojFile).Contains("tModLoader.targets"))
                {
                    var icon = UICommon.ButtonExclamationTexture;
                    var upgradeCSProjButton = new UIHoverImage(icon, Language.GetTextValue("tModLoader.MSUpgradeCSProj"))
                    {
                        Left = { Pixels = -26, Percent = 1f },
                        Top  = { Pixels = 4 }
                    };
                    upgradeCSProjButton.OnClick += (s, e) => {
                        File.WriteAllText(csprojFile, Interface.createMod.GetModCsproj(modFolderName));
                        string propertiesFolder = Path.Combine(_mod, "Properties");
                        Directory.CreateDirectory(propertiesFolder);
                        File.WriteAllText(Path.Combine(propertiesFolder, $"launchSettings.json"), Interface.createMod.GetLaunchSettings());
                        Main.PlaySound(SoundID.MenuOpen);
                        Main.menuMode = Interface.modSourcesID;
                    };
                    Append(upgradeCSProjButton);
                }
            }
        }
예제 #2
0
        public override void OnInitialize()
        {
            base.OnInitialize();

            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 (Exception e) {
                    Logging.tML.Error("Unknown error", e);
                }
            }

            _modName = new UIText(text)
            {
                Left = new StyleDimension(_modIconAdjust, 0f),
                Top  = { Pixels = 5 }
            };
            Append(_modName);

            _uiModStateText = new UIModStateText(_mod.Enabled)
            {
                Top  = { Pixels = 40 },
                Left = { Pixels = _modIconAdjust }
            };
            _uiModStateText.OnClick += ToggleEnabled;
            Append(_uiModStateText);

            _moreInfoButton = new UIImage(UICommon.ButtonModInfoTexture)
            {
                Width  = { Pixels = 36 },
                Height = { Pixels = 36 },
                Left   = { Pixels = -36, Precent = 1 },
                Top    = { Pixels = 40 }
            };
            _moreInfoButton.OnClick += ShowMoreInfo;
            Append(_moreInfoButton);

            Mod loadedMod = ModLoader.GetMod(_mod.Name);

            if (loadedMod != null && ConfigManager.Configs.ContainsKey(loadedMod))
            {
                _configButton = new UIImage(UICommon.ButtonModConfigTexture)
                {
                    Width  = { Pixels = 36 },
                    Height = { Pixels = 36f },
                    Left   = { Pixels = _moreInfoButton.Left.Pixels - 36 - PADDING, Precent = 1f },
                    Top    = { Pixels = 40f }
                };
                _configButton.OnClick += OpenConfig;
                Append(_configButton);
                if (ConfigManager.ModNeedsReload(loadedMod))
                {
                    _configChangesRequireReload = true;
                }
            }

            _modReferences = _mod.properties.modReferences.Select(x => x.mod).ToArray();
            if (_modReferences.Length > 0 && !_mod.Enabled)
            {
                string refs = string.Join(", ", _mod.properties.modReferences);
                var    icon = UICommon.ButtonExclamationTexture;
                _modReferenceIcon = new UIHoverImage(icon, Language.GetTextValue("tModLoader.ModDependencyClickTooltip", refs))
                {
                    Left = new StyleDimension(_uiModStateText.Left.Pixels + _uiModStateText.Width.Pixels + PADDING, 0f),
                    Top  = { Pixels = 42.5f }
                };
                _modReferenceIcon.OnClick += EnableDependencies;
                Append(_modReferenceIcon);
            }
            if (_mod.modFile.ValidModBrowserSignature)
            {
                _keyImage = new UIHoverImage(Main.itemTexture[ItemID.GoldenKey], Language.GetTextValue("tModLoader.ModsOriginatedFromModBrowser"))
                {
                    Left = { Pixels = -20, Percent = 1f }
                };
                Append(_keyImage);
            }
            if (ModLoader.badUnloaders.Contains(_mod.Name))
            {
                _keyImage = new UIHoverImage(UICommon.ButtonErrorTexture, "This mod did not fully unload during last unload.")
                {
                    Left = { Pixels = _modIconAdjust + PADDING },
                    Top  = { Pixels = 3 }
                };
                Append(_keyImage);
                _modName.Left.Pixels += _keyImage.Width.Pixels + PADDING * 2f;
            }
            if (_mod.properties.beta)
            {
                _keyImage = new UIHoverImage(Main.itemTexture[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;
                    }
                }
            }

            OnDoubleClick += (e, el) => {
                // Only trigger if we didn't target the ModStateText, otherwise we trigger this behavior twice
                if (e.Target.GetType() != typeof(UIModStateText))
                {
                    _uiModStateText.Click(e);
                }
            };
        }
예제 #3
0
		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 += new UIElement.MouseEvent(this.ToggleEnabled);
			properties = BuildProperties.ReadModFile(mod);
			string text = properties.displayName.Length > 0 ? properties.displayName : mod.name;
			text += " v" + mod.version;
			if (properties.author.Length > 0)
			{
				text += " - by " + properties.author;
			}
			this.modName = new UIText(text, 1f, false);
			this.modName.Left.Set(10f, 0f);
			this.modName.Top.Set(5f, 0f);
			base.Append(this.modName);
			this.enabled = ModLoader.IsEnabled(mod);
			UITextPanel button = new UITextPanel("More info", 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 += new UIElement.MouseEvent(FadedMouseOver);
			button.OnMouseOut += new UIElement.MouseEvent(FadedMouseOut);
			button.OnClick += new UIElement.MouseEvent(this.Moreinfo);
			base.Append(button);
			button2 = new UITextPanel(this.enabled ? "Click to Disable" : "Click to Enable", 1f, false);
			button2.Width.Set(100f, 0f);
			button2.Height.Set(30f, 0f);
			button2.Left.Set(275f, 0f);
			button2.Top.Set(40f, 0f);
			button2.PaddingTop -= 2f;
			button2.PaddingBottom -= 2f;
			button2.OnMouseOver += new UIElement.MouseEvent(FadedMouseOver);
			button2.OnMouseOut += new UIElement.MouseEvent(FadedMouseOut);
			button2.OnClick += new UIElement.MouseEvent(this.ToggleEnabled);
			base.Append(button2);
			if (mod.ValidModBrowserSignature)
			{
				keyImage = new UIHoverImage(Main.itemTexture[ID.ItemID.GoldenKey], "This mod originated from the Mod Browser");
				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 = ModLoader.GetTexture("Terraria/UI" + Path.DirectorySeparatorChar + "InfoIcon_" + i);
						keyImage = new UIHoverImage(iconTexture, values[i] + strings[i]);
						keyImage.Left.Set(xOffset, 1f);
						base.Append(keyImage);
						xOffset -= 18;
					}
				}
			}
		}
예제 #4
0
        public UIModDownloadItem(string displayname, string name, string version, string author, string modreferences, ModSide modside, string modIconURL, string download, int downloads, int hot, string timeStamp, bool update, bool updateIsDowngrade, LocalMod installed)
        {
            this.displayname       = displayname;
            this.mod               = name;
            this.version           = version;
            this.author            = author;
            this.modreferences     = modreferences;
            this.modside           = modside;
            this.modIconURL        = modIconURL;
            this.download          = download;
            this.downloads         = downloads;
            this.hot               = hot;
            this.timeStamp         = timeStamp;
            this.update            = update;
            this.updateIsDowngrade = updateIsDowngrade;
            this.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);

            left = HasModIcon ? 85f : 0f;
            string text = displayname + " " + version;

            modName = new UIText(text)
            {
                Left = new StyleDimension(left + 5, 0f),
                Top  = { Pixels = 5 }
            };
            Append(modName);

            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 (update || installed == null)
            {
                updateButton = new UIAutoScaleTextTextPanel <string>(this.update ? (updateIsDowngrade ? Language.GetTextValue("tModLoader.MBDowngrade") : Language.GetTextValue("tModLoader.MBUpdate")) : Language.GetTextValue("tModLoader.MBDownload"), 1f,
                                                                     false);
                updateButton.CopyStyle(moreInfoButton);
                updateButton.Width.Pixels = HasModIcon ? 120 : 200;
                updateButton.Left.Pixels  = moreInfoButton.Width.Pixels + moreInfoButton.Left.Pixels + 5f;
                updateButton.WithFadedMouseOver();
                updateButton.OnClick += DownloadMod;
                Append(updateButton);
            }
            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 = -149, Percent = 1f },
                    Top  = { Pixels = 48 }
                };
                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;
        }
예제 #5
0
        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;
                    }
                }
            }
        }
예제 #6
0
        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;
                    }
                }
            }
        }
예제 #7
0
        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;
                    }
                }
            }
        }
예제 #8
0
        public UIModDownloadItem(string displayname, string name, string version, string author, string modreferences, ModSide modside, string download, int downloads, int hot, string timeStamp, bool update, bool updateIsDowngrade, bool exists)
        {
            this.displayname       = displayname;
            this.mod               = name;
            this.version           = version;
            this.author            = author;
            this.modreferences     = modreferences;
            this.modside           = modside;
            this.download          = download;
            this.downloads         = downloads;
            this.hot               = hot;
            this.timeStamp         = timeStamp;
            this.update            = update;
            this.updateIsDowngrade = updateIsDowngrade;
            this.exists            = exists;
            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);
            string text = displayname + " " + version;

            this.modName = new UIText(text, 1f, false);
            this.modName.Left.Set(10f, 0f);
            this.modName.Top.Set(5f, 0f);
            base.Append(this.modName);
            UITextPanel <string> button = new UITextPanel <string>("More info", 1f, false);

            button.Width.Set(100f, 0f);
            button.Height.Set(30f, 0f);
            button.Left.Set(5f, 0f);
            button.Top.Set(40f, 0f);
            button.PaddingTop    -= 2f;
            button.PaddingBottom -= 2f;
            button.OnMouseOver   += UICommon.FadedMouseOver;
            button.OnMouseOut    += UICommon.FadedMouseOut;
            button.OnClick       += RequestMoreinfo;
            base.Append(button);
            if (update || !exists)
            {
                updateButton = new UITextPanel <string>(this.update ? (updateIsDowngrade ? "Downgrade" : "Update") : "Download", 1f,
                                                        false);
                updateButton.CopyStyle(button);
                updateButton.Width.Set(200f, 0f);
                updateButton.Left.Set(button.Width.Pixels + button.Left.Pixels * 2f + 5f, 0f);
                updateButton.OnMouseOver += UICommon.FadedMouseOver;
                updateButton.OnMouseOut  += UICommon.FadedMouseOut;
                updateButton.OnClick     += this.DownloadMod;
                base.Append(updateButton);
            }
            if (modreferences.Length > 0)
            {
                UIHoverImage modReferenceIcon = new UIHoverImage(Main.quicksIconTexture, "This mod depends on: " + modreferences);
                modReferenceIcon.Left.Set(-135f, 1f);
                modReferenceIcon.Top.Set(50f, 0f);
                modReferenceIcon.OnClick += (s, e) =>
                {
                    UIModDownloadItem modListItem = (UIModDownloadItem)e.Parent;
                    Interface.modBrowser.SpecialModPackFilter        = modListItem.modreferences.Split(',').ToList();
                    Interface.modBrowser.SpecialModPackFilterTitle   = "Dependencies";                   // Toolong of \n" + modListItem.modName.Text;
                    Interface.modBrowser.filterTextBox.currentString = "";
                    Interface.modBrowser.SortList();
                    Main.PlaySound(SoundID.MenuOpen);
                };
                Append(modReferenceIcon);
            }
            base.OnDoubleClick += RequestMoreinfo;
        }
예제 #9
0
        public override void OnInitialize()
        {
            base.OnInitialize();

            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 {
                    Asset <Texture2D> modIconTexture;

                    using (_mod.modFile.Open())
                        using (var s = _mod.modFile.GetStream("icon.png"))
                            modIconTexture = ModLoader.ManifestAssets.CreateUntrackedAsset(
                                $"Terraria.ModLoader.UI.Browser.{_mod.Name}.icon.png",
                                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 (Exception e) {
                    Logging.tML.Error("Unknown error", e);
                }
            }

            _modName = new UIText(text)
            {
                Left = new StyleDimension(_modIconAdjust, 0f),
                Top  = { Pixels = 5 }
            };
            Append(_modName);

            _uiModStateText = new UIModStateText(_mod.Enabled)
            {
                Top  = { Pixels = 40 },
                Left = { Pixels = _modIconAdjust }
            };
            _uiModStateText.OnClick += ToggleEnabled;
            Append(_uiModStateText);

            _moreInfoButton = new UIImage(UICommon.ButtonModInfoTexture)
            {
                Width  = { Pixels = 36 },
                Height = { Pixels = 36 },
                Left   = { Pixels = -36, Precent = 1 },
                Top    = { Pixels = 40 }
            };
            _moreInfoButton.OnClick += ShowMoreInfo;
            Append(_moreInfoButton);

            if (ModLoader.TryGetMod(ModName, out var loadedMod) && ConfigManager.Configs.ContainsKey(loadedMod))
            {
                _configButton = new UIImage(UICommon.ButtonModConfigTexture)
                {
                    Width  = { Pixels = 36 },
                    Height = { Pixels = 36f },
                    Left   = { Pixels = _moreInfoButton.Left.Pixels - 36 - PADDING, Precent = 1f },
                    Top    = { Pixels = 40f }
                };
                _configButton.OnClick += OpenConfig;
                Append(_configButton);
                if (ConfigManager.ModNeedsReload(loadedMod))
                {
                    _configChangesRequireReload = true;
                }
            }

            _modReferences = _mod.properties.modReferences.Select(x => x.mod).ToArray();

            if (_modReferences.Length > 0 && !_mod.Enabled)
            {
                string refs = string.Join(", ", _mod.properties.modReferences);
                var    icon = UICommon.ButtonExclamationTexture;
                _modReferenceIcon = new UIHoverImage(icon, Language.GetTextValue("tModLoader.ModDependencyClickTooltip", refs))
                {
                    Left = new StyleDimension(_uiModStateText.Left.Pixels + _uiModStateText.Width.Pixels + PADDING, 0f),
                    Top  = { Pixels = 42.5f }
                };
                _modReferenceIcon.OnClick += EnableDependencies;

                Append(_modReferenceIcon);
            }

            if (_mod.modFile.ValidModBrowserSignature)
            {
                _keyImage = new UIHoverImage(Main.Assets.Request <Texture2D>(TextureAssets.Item[ItemID.GoldenKey].Name), Language.GetTextValue("tModLoader.ModsOriginatedFromModBrowser"))
                {
                    Left = { Pixels = -20, Percent = 1f }
                };

                Append(_keyImage);
            }

            if (ModCompile.DeveloperMode && ModLoader.badUnloaders.Contains(ModName))
            {
                _keyImage = new UIHoverImage(UICommon.ButtonErrorTexture, Language.GetTextValue("tModLoader.ModDidNotFullyUnloadWarning"))
                {
                    Left = { Pixels = _modIconAdjust + PADDING },
                    Top  = { Pixels = 3 }
                };

                Append(_keyImage);

                _modName.Left.Pixels += _keyImage.Width.Pixels + PADDING * 2f;
            }

            if (_mod.properties.beta)
            {
                _keyImage = new UIHoverImage(Main.Assets.Request <Texture2D>(TextureAssets.Item[ItemID.ShadowKey].Name), Language.GetTextValue("tModLoader.BetaModCantPublish"))
                {
                    Left = { Pixels = -10, Percent = 1f }
                };

                Append(_keyImage);
            }

            if (loadedMod != null)
            {
                _loaded = true;
                // TODO: refactor and add nicer icons (and maybe not iterate 6 times)
                int[]    values           = { loadedMod.GetContent <ModItem>().Count(), loadedMod.GetContent <ModNPC>().Count(), loadedMod.GetContent <ModTile>().Count(), loadedMod.GetContent <ModWall>().Count(), loadedMod.GetContent <ModBuff>().Count(), loadedMod.GetContent <ModMount>().Count() };
                string[] localizationKeys = { "ModsXItems", "ModsXNPCs", "ModsXTiles", "ModsXWalls", "ModsXBuffs", "ModsXMounts" };
                int      xOffset          = -40;

                for (int i = 0; i < values.Length; i++)
                {
                    if (values[i] > 0)
                    {
                        _keyImage = new UIHoverImage(Main.Assets.Request <Texture2D>(TextureAssets.InfoIcon[i].Name), Language.GetTextValue($"tModLoader.{localizationKeys[i]}", values[i]))
                        {
                            Left = { Pixels = xOffset, Percent = 1f }
                        };

                        Append(_keyImage);
                        xOffset -= 18;
                    }
                }
            }

            OnDoubleClick += (e, el) => {
                // Only trigger if we didn't target the ModStateText, otherwise we trigger this behavior twice
                if (e.Target.GetType() != typeof(UIModStateText))
                {
                    _uiModStateText.Click(e);
                }
            };

            if (!_loaded)
            {
                _deleteModButton = new UIImage(TextureAssets.Trash)
                {
                    Width  = { Pixels = 36 },
                    Height = { Pixels = 36 },
                    Left   = { Pixels = _moreInfoButton.Left.Pixels - 36 - PADDING, Precent = 1 },
                    Top    = { Pixels = 42.5f }
                };
                _deleteModButton.OnClick += QuickModDelete;
                Append(_deleteModButton);
            }
        }
예제 #10
0
        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 (properties.author.Length > 0)
            {
                text += " - by " + properties.author;
            }
            this.modName = new UIText(text, 1f, false);
            this.modName.Left.Set(10f, 0f);
            this.modName.Top.Set(5f, 0f);
            base.Append(this.modName);
            this.enabled = ModLoader.IsEnabled(mod);
            UITextPanel <string> button = new UITextPanel <string>("More info", 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 ? "Click to Disable" : "Click to Enable", 1f, false);
            button2.Width.Set(100f, 0f);
            button2.Height.Set(30f, 0f);
            button2.Left.Set(275f, 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 (mod.ValidModBrowserSignature)
            {
                keyImage = new UIHoverImage(Main.itemTexture[ID.ItemID.GoldenKey], "This mod originated from the Mod Browser");
                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 = ModLoader.GetTexture("Terraria/UI" + Path.DirectorySeparatorChar + "InfoIcon_" + i);
                        keyImage = new UIHoverImage(iconTexture, values[i] + strings[i]);
                        keyImage.Left.Set(xOffset, 1f);
                        base.Append(keyImage);
                        xOffset -= 18;
                    }
                }
            }
        }
예제 #11
0
        public UIModDownloadItem(string displayname, string name, string version, string author, string modreferences, ModSide modside, string modIconURL, string download, int downloads, int hot, string timeStamp, bool update, bool updateIsDowngrade, LocalMod installed)
        {
            this.displayname       = displayname;
            this.mod               = name;
            this.version           = version;
            this.author            = author;
            this.modreferences     = modreferences;
            this.modside           = modside;
            this.modIconURL        = modIconURL;
            this.download          = download;
            this.downloads         = downloads;
            this.hot               = hot;
            this.timeStamp         = timeStamp;
            this.update            = update;
            this.updateIsDowngrade = updateIsDowngrade;
            this.installed         = installed;
            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);

            this.left = HasModIcon ? 85f : 0f;
            string text = displayname + " " + version;

            this.modName = new UIText(text, 1f, false);
            this.modName.Left.Set(this.left + 5, 0f);
            this.modName.Top.Set(5f, 0f);
            base.Append(this.modName);

            moreInfoButton = new UITextPanel <string>(Language.GetTextValue("tModLoader.ModsMoreInfo"), 1f, false);
            moreInfoButton.Width.Set(100f, 0f);
            moreInfoButton.Height.Set(30f, 0f);
            moreInfoButton.Left.Set(this.left, 0f);
            moreInfoButton.Top.Set(40f, 0f);
            moreInfoButton.PaddingTop    -= 2f;
            moreInfoButton.PaddingBottom -= 2f;
            moreInfoButton.OnMouseOver   += UICommon.FadedMouseOver;
            moreInfoButton.OnMouseOut    += UICommon.FadedMouseOut;
            moreInfoButton.OnClick       += RequestMoreinfo;
            Append(moreInfoButton);

            if (update || installed == null)
            {
                updateButton = new UITextPanel <string>(this.update ? (updateIsDowngrade ? Language.GetTextValue("tModLoader.MBDowngrade") : Language.GetTextValue("tModLoader.MBUpdate")) : Language.GetTextValue("tModLoader.MBDownload"), 1f,
                                                        false);
                updateButton.CopyStyle(moreInfoButton);
                updateButton.Width.Set(HasModIcon ? 120f : 200f, 0f);
                updateButton.Left.Set(moreInfoButton.Width.Pixels + moreInfoButton.Left.Pixels + 5f, 0f);
                updateButton.OnMouseOver += UICommon.FadedMouseOver;
                updateButton.OnMouseOut  += UICommon.FadedMouseOut;
                updateButton.OnClick     += this.DownloadMod;
                Append(updateButton);
            }
            if (modreferences.Length > 0)
            {
                Texture2D icon = Texture2D.FromStream(Main.instance.GraphicsDevice,
                                                      Assembly.GetExecutingAssembly().GetManifestResourceStream("Terraria.ModLoader.UI.ButtonExclamation.png"));
                UIHoverImage modReferenceIcon = new UIHoverImage(icon, "Click to view dependency mods:\n" + string.Join("\n", modreferences.Split(',').Select(x => x.Trim())));
                modReferenceIcon.Left.Set(-149f, 1f);
                modReferenceIcon.Top.Set(48f, 0f);
                modReferenceIcon.OnClick += (s, e) =>
                {
                    UIModDownloadItem modListItem = (UIModDownloadItem)e.Parent;
                    Interface.modBrowser.SpecialModPackFilter        = modListItem.modreferences.Split(',').Select(x => x.Trim()).ToList();
                    Interface.modBrowser.SpecialModPackFilterTitle   = "Dependencies";                   // Toolong of \n" + modListItem.modName.Text;
                    Interface.modBrowser.filterTextBox.currentString = "";
                    Interface.modBrowser.updateNeeded = true;
                    Main.PlaySound(SoundID.MenuOpen);
                };
                Append(modReferenceIcon);
            }
            OnDoubleClick += RequestMoreinfo;
        }
예제 #12
0
        public UIModDownloadItem(string displayname, string name, string version, string author, string modreferences, ModSide modside, string modIconURL, string download, int downloads, int hot, string timeStamp, bool update, bool updateIsDowngrade, TmodFile installed)
        {
            this.displayname       = displayname;
            this.mod               = name;
            this.version           = version;
            this.author            = author;
            this.modreferences     = modreferences;
            this.modside           = modside;
            this.modIconURL        = modIconURL;
            this.download          = download;
            this.downloads         = downloads;
            this.hot               = hot;
            this.timeStamp         = timeStamp;
            this.update            = update;
            this.updateIsDowngrade = updateIsDowngrade;
            this.installed         = installed;
            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);

            float left = 0f;

            if (modIconURL != null)
            {
                left += 85;
            }

            string text = displayname + " " + version;

            this.modName = new UIText(text, 1f, false);
            this.modName.Left.Set(left + 5, 0f);
            this.modName.Top.Set(5f, 0f);
            base.Append(this.modName);

            UITextPanel <string> moreInfoButton = new UITextPanel <string>(Language.GetTextValue("tModLoader.ModsMoreInfo"), 1f, false);

            moreInfoButton.Width.Set(100f, 0f);
            moreInfoButton.Height.Set(30f, 0f);
            moreInfoButton.Left.Set(left, 0f);
            moreInfoButton.Top.Set(40f, 0f);
            moreInfoButton.PaddingTop    -= 2f;
            moreInfoButton.PaddingBottom -= 2f;
            moreInfoButton.OnMouseOver   += UICommon.FadedMouseOver;
            moreInfoButton.OnMouseOut    += UICommon.FadedMouseOut;
            moreInfoButton.OnClick       += RequestMoreinfo;
            Append(moreInfoButton);

            if (update || installed == null)
            {
                updateButton = new UITextPanel <string>(this.update ? (updateIsDowngrade ? Language.GetTextValue("tModLoader.MBDowngrade") : Language.GetTextValue("tModLoader.MBUpdate")) : Language.GetTextValue("tModLoader.MBDownload"), 1f,
                                                        false);
                updateButton.CopyStyle(moreInfoButton);
                updateButton.Width.Set(modIconURL != null ? 120f : 200f, 0f);
                updateButton.Left.Set(moreInfoButton.Width.Pixels + moreInfoButton.Left.Pixels + 5f, 0f);
                updateButton.OnMouseOver += UICommon.FadedMouseOver;
                updateButton.OnMouseOut  += UICommon.FadedMouseOut;
                updateButton.OnClick     += this.DownloadMod;
                Append(updateButton);
            }
            if (modreferences.Length > 0)
            {
                UIHoverImage modReferenceIcon = new UIHoverImage(Main.quicksIconTexture, "This mod depends on: " + modreferences);
                modReferenceIcon.Left.Set(-135f, 1f);
                modReferenceIcon.Top.Set(50f, 0f);
                modReferenceIcon.OnClick += (s, e) =>
                {
                    UIModDownloadItem modListItem = (UIModDownloadItem)e.Parent;
                    Interface.modBrowser.SpecialModPackFilter        = modListItem.modreferences.Split(',').ToList();
                    Interface.modBrowser.SpecialModPackFilterTitle   = "Dependencies";                   // Toolong of \n" + modListItem.modName.Text;
                    Interface.modBrowser.filterTextBox.currentString = "";
                    Interface.modBrowser.updateNeeded = true;
                    Main.PlaySound(SoundID.MenuOpen);
                };
                Append(modReferenceIcon);
            }
            OnDoubleClick += RequestMoreinfo;
        }
예제 #13
0
        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)]";
            }
            this.modName = new UIText(text, 1f, false);
            this.modName.Left.Set(10f, 0f);
            this.modName.Top.Set(5f, 0f);
            base.Append(this.modName);
            this.enabled = ModLoader.IsEnabled(mod);
            UITextPanel <string> button = new UITextPanel <string>("More info", 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 ? "Disable" : "Enable", 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));
                UIHoverImage modReferenceIcon = new UIHoverImage(Main.quicksIconTexture, "This mod depends on: " + refs);
                modReferenceIcon.Left.Set(button2.Left.Pixels - 10f, 0f);
                modReferenceIcon.Top.Set(50f, 0f);
                base.Append(modReferenceIcon);
            }
            if (mod.ValidModBrowserSignature)
            {
                keyImage = new UIHoverImage(Main.itemTexture[ID.ItemID.GoldenKey], "This mod originated from the Mod Browser");
                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;
                    }
                }
            }
        }