-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
399 additions
and
24 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using Microsoft.Xna.Framework; | ||
using Microsoft.Xna.Framework.Graphics; | ||
using System; | ||
using Terraria; | ||
using Terraria.UI; | ||
|
||
namespace RecipeBrowser.UIElements | ||
{ | ||
internal class UICycleImage : UIElement | ||
{ | ||
private Texture2D texture; | ||
private int _drawWidth; | ||
private int _drawHeight; | ||
private int padding; | ||
private int textureOffsetX; | ||
private int textureOffsetY; | ||
private int states; | ||
internal string[] hoverTexts; | ||
|
||
public event EventHandler OnStateChanged; | ||
|
||
private int currentState = 0; | ||
public int CurrentState | ||
{ | ||
get { return currentState; } | ||
set | ||
{ | ||
if (value != currentState) | ||
{ | ||
currentState = value; | ||
OnStateChanged?.Invoke(this, EventArgs.Empty); | ||
} | ||
} | ||
} | ||
|
||
public UICycleImage(Texture2D texture, int states, string[] hoverTexts, int width, int height, int textureOffsetX = 0, int textureOffsetY = 0, int padding = 2) | ||
{ | ||
this.texture = texture; | ||
this._drawWidth = width; | ||
this._drawHeight = height; | ||
this.textureOffsetX = textureOffsetX; | ||
this.textureOffsetY = textureOffsetY; | ||
this.Width.Set((float)width, 0f); | ||
this.Height.Set((float)height, 0f); | ||
this.states = states; | ||
this.padding = padding; | ||
this.hoverTexts = hoverTexts; | ||
} | ||
|
||
protected override void DrawSelf(SpriteBatch spriteBatch) | ||
{ | ||
CalculatedStyle dimensions = base.GetDimensions(); | ||
Point point = new Point(textureOffsetX, textureOffsetY + ((padding + _drawHeight) * currentState)); | ||
Color color = base.IsMouseHovering ? Color.White : Color.Silver; | ||
spriteBatch.Draw(texture, new Rectangle((int)dimensions.X, (int)dimensions.Y, this._drawWidth, this._drawHeight), new Rectangle?(new Rectangle(point.X, point.Y, this._drawWidth, this._drawHeight)), color); | ||
if (IsMouseHovering) | ||
{ | ||
Main.hoverItemName = hoverTexts[CurrentState]; | ||
} | ||
} | ||
|
||
public override void Click(UIMouseEvent evt) | ||
{ | ||
CurrentState = (currentState + 1) % states; | ||
base.Click(evt); | ||
} | ||
|
||
public override void RightClick(UIMouseEvent evt) | ||
{ | ||
CurrentState = (currentState + states - 1) % states; | ||
base.RightClick(evt); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.