diff --git a/ItemChecklist.csproj b/ItemChecklist.csproj index d283424..410a3ae 100644 --- a/ItemChecklist.csproj +++ b/ItemChecklist.csproj @@ -72,6 +72,7 @@ + diff --git a/ItemChecklistGlobalItem.cs b/ItemChecklistGlobalItem.cs index 8ce009b..83cf349 100644 --- a/ItemChecklistGlobalItem.cs +++ b/ItemChecklistGlobalItem.cs @@ -35,7 +35,10 @@ namespace ItemChecklist itemChecklistPlayer.foundItem[item.type] = true; //ItemChecklist.instance.ItemChecklistUI.UpdateCheckboxes(); ItemChecklist.instance.ItemChecklistUI.UpdateNeeded(); - Main.NewText($"Congrats: You found your first {item.name}. Total Progress: {itemChecklistPlayer.totalItemsFound}/{itemChecklistPlayer.totalItemsToFind}"); + if (ItemChecklistUI.announce) + { + Main.NewText($"Congrats: You found your first {item.name}. Total Progress: {itemChecklistPlayer.totalItemsFound}/{itemChecklistPlayer.totalItemsToFind}"); + } } } } diff --git a/ItemChecklistUI.cs b/ItemChecklistUI.cs index edb9671..c85a598 100644 --- a/ItemChecklistUI.cs +++ b/ItemChecklistUI.cs @@ -16,14 +16,16 @@ namespace ItemChecklist.UI class ItemChecklistUI : UIState { public UIHoverImageButton toggleButton; + public UIToggleHoverImageButton muteButton; public UIPanel checklistPanel; //public UIList checklistList; public UIGrid checklistList; - // private FieldInfo uilistinnerlist; + // private FieldInfo uilistinnerlist; float spacing = 8f; public static bool visible = false; public static bool showCompleted = true; + public static bool announce = true; public static string hoverText = ""; ItemSlot[] itemSlots; @@ -32,7 +34,8 @@ namespace ItemChecklist.UI { // Is initialize called? (Yes it is called on reload) I want to reset nicely with new character or new loaded mods: visible = false; - // uilistinnerlist = typeof(UIList).GetField("_innerList", BindingFlags.Instance | BindingFlags.NonPublic); + // uilistinnerlist = typeof(UIList).GetField("_innerList", BindingFlags.Instance | BindingFlags.NonPublic); + announce = true; checklistPanel = new UIPanel(); checklistPanel.SetPadding(10); @@ -49,6 +52,12 @@ namespace ItemChecklist.UI //toggleButton.Top.Pixels = spacing; checklistPanel.Append(toggleButton); + muteButton = new UIToggleHoverImageButton(Main.itemTexture[ItemID.Megaphone], ItemChecklist.instance.GetTexture("closeButton"), "Toggle Messages", announce); + muteButton.OnClick += ToggleMuteButtonClicked; + muteButton.Left.Pixels = spacing * 2 + 28; + muteButton.Top.Pixels = 4; + checklistPanel.Append(muteButton); + checklistList = new UIGrid(5); checklistList.Top.Pixels = 32f + spacing; checklistList.Width.Set(-25f, 1f); @@ -86,6 +95,13 @@ namespace ItemChecklist.UI UpdateNeeded(); } + private void ToggleMuteButtonClicked(UIMouseEvent evt, UIElement listeningElement) + { + Main.PlaySound(10, -1, -1, 1); + announce = !announce; + muteButton.SetEnabled(announce); + } + private bool updateneeded; internal void UpdateNeeded() { @@ -131,13 +147,13 @@ namespace ItemChecklist.UI checklistList._items.Add(box); checklistList._innerList.Append(box); - // uilistinner.Append(box); + // uilistinner.Append(box); } } } checklistList.UpdateOrder(); checklistList._innerList.Recalculate(); -// uilistinner.Recalculate(); + // uilistinner.Recalculate(); } protected override void DrawSelf(SpriteBatch spriteBatch) diff --git a/UIToggleHoverImageButton.cs b/UIToggleHoverImageButton.cs new file mode 100644 index 0000000..9353bf9 --- /dev/null +++ b/UIToggleHoverImageButton.cs @@ -0,0 +1,62 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria.UI; +using ItemChecklist.UI; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Terraria; +using Terraria.GameContent.UI.Elements; + +namespace Terraria.GameContent.UI.Elements +{ + public class UIToggleHoverImageButton : UIImageButton + { + private Texture2D _texture; + private Texture2D overlay; + private float _visibilityActive = 1f; + private float _visibilityInactive = 0.4f; + bool enabled; + internal string hoverText; + + public UIToggleHoverImageButton(Texture2D texture, Texture2D overlay, string hoverText, bool enabled = false) : base(texture) + { + this._texture = texture; + this.overlay = overlay; + this.Width.Set((float)this._texture.Width, 0f); + this.Height.Set((float)this._texture.Height, 0f); + this.hoverText = hoverText; + this.enabled = enabled; + } + + public void SetEnabled(bool enabled) + { + this.enabled = enabled; + } + + protected override void DrawSelf(SpriteBatch spriteBatch) + { + CalculatedStyle dimensions = base.GetDimensions(); + spriteBatch.Draw(this._texture, dimensions.Position(), Color.White * (base.IsMouseHovering ? this._visibilityActive : this._visibilityInactive)); + if (!enabled) + { + spriteBatch.Draw(this.overlay, dimensions.Position(), Color.White * (base.IsMouseHovering ? this._visibilityActive : this._visibilityInactive)); + } + if (IsMouseHovering) + { + ItemChecklistUI.hoverText = hoverText; + } + } + + public override void MouseOver(UIMouseEvent evt) + { + base.MouseOver(evt); + Main.PlaySound(12, -1, -1, 1, 1f, 0f); + } + } +} \ No newline at end of file diff --git a/build.txt b/build.txt index 67690d9..25ac9af 100644 --- a/build.txt +++ b/build.txt @@ -1,5 +1,5 @@ author = jopojelly -version = 0.1 +version = 0.1.0.1 displayName = Item Checklist homepage = https://forums.terraria.org/index.php?threads/item-checklist-in-game-100-item-collection-checklist.52786/ hideCode = false diff --git a/closeButton.png b/closeButton.png new file mode 100644 index 0000000..90e5bde Binary files /dev/null and b/closeButton.png differ