Skip to content

Commit

Permalink
0.3.0.2, ModIcon peek
Browse files Browse the repository at this point in the history
  • Loading branch information
JavidPack committed Sep 18, 2017
1 parent dbe3558 commit ee6d2b2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
18 changes: 15 additions & 3 deletions RecipeBrowserUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public override void OnInitialize()
TileLookupRadioButton.SetDisabled(true);
mainPanel.Append(TileLookupRadioButton);

var modFilterButton = new UIHoverImageButton(RecipeBrowser.instance.GetTexture("Images/filterMod"), "Mod Filter: All");
var modFilterButton = new UIHoverImageButtonMod(RecipeBrowser.instance.GetTexture("Images/filterMod"), "Mod Filter: All");
modFilterButton.Left.Set(-208, 1f);
modFilterButton.Top.Set(-4, 0f);
modFilterButton.OnClick += ModFilterButton_OnClick;
Expand Down Expand Up @@ -276,18 +276,30 @@ private void NearbyIngredientsRadioBitton_OnSelectedChanged(object sender, Event
private static int modIndex;
private void ModFilterButton_OnClick(UIMouseEvent evt, UIElement listeningElement)
{
UIHoverImageButton button = (evt.Target as UIHoverImageButton);
UIHoverImageButtonMod button = (evt.Target as UIHoverImageButtonMod);
button.hoverText = "Mod Filter: " + GetModFilterTooltip(true);
UpdateModHoverImage(button);
updateNeeded = true;
}

private void ModFilterButton_OnRightClick(UIMouseEvent evt, UIElement listeningElement)
{
UIHoverImageButton button = (evt.Target as UIHoverImageButton);
UIHoverImageButtonMod button = (evt.Target as UIHoverImageButtonMod);
button.hoverText = "Mod Filter: " + GetModFilterTooltip(false);
UpdateModHoverImage(button);
updateNeeded = true;
}

private void UpdateModHoverImage(UIHoverImageButtonMod button)
{
button.texture = null;
Mod otherMod = ModLoader.GetMod(mods[modIndex]);
if(otherMod != null && otherMod.TextureExists("icon"))
{
button.texture = otherMod.GetTexture("icon");
}
}

private string GetModFilterTooltip(bool increment)
{
modIndex = increment ? (modIndex + 1) % mods.Length : (mods.Length + modIndex - 1) % mods.Length;
Expand Down
27 changes: 27 additions & 0 deletions UIElements/UIHoverImageButtonMod.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.GameContent.UI.Elements;

namespace RecipeBrowser
{
internal class UIHoverImageButtonMod : UIHoverImageButton
{
internal Texture2D texture;
Vector2 offset = new Vector2(0, 12);

public UIHoverImageButtonMod(Texture2D texture, string hoverText) : base(texture, hoverText)
{
}

protected override void DrawSelf(SpriteBatch spriteBatch)
{
base.DrawSelf(spriteBatch);
if (IsMouseHovering && texture != null)
{
Rectangle hitbox = GetInnerDimensions().ToRectangle();
spriteBatch.Draw(texture, new Vector2(hitbox.X + hitbox.Width/2 - 40, hitbox.Y - 80), Color.White);
}
}
}
}
2 changes: 1 addition & 1 deletion build.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
author = jopojelly
version = 0.3.0.1
version = 0.3.0.2
displayName = Recipe Browser
homepage = http://forums.terraria.org/index.php?threads/cheat-sheet.41407/
buildIgnore = .vs\*, Properties\*, *.csproj, *.user, obj\*, bin\*, *.config, unused\*, .git\*,
Expand Down

0 comments on commit ee6d2b2

Please sign in to comment.