-
Notifications
You must be signed in to change notification settings - Fork 8
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
9 changed files
with
131 additions
and
11 deletions.
There are no files selected for viewing
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
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,85 @@ | ||
using Microsoft.Xna.Framework; | ||
using Microsoft.Xna.Framework.Graphics; | ||
using System; | ||
using Terraria; | ||
using Terraria.GameContent.UI.Elements; | ||
using Terraria.UI; | ||
|
||
namespace AutoTrash | ||
{ | ||
internal class UICheckbox : UIText | ||
{ | ||
public static Texture2D checkboxTexture; | ||
public static Texture2D checkmarkTexture; | ||
|
||
public event EventHandler OnSelectedChanged; | ||
|
||
private bool selected = false; | ||
private bool disabled = false; | ||
internal string hoverText; | ||
|
||
public bool Selected | ||
{ | ||
get { return selected; } | ||
set | ||
{ | ||
if (value != selected) | ||
{ | ||
selected = value; | ||
OnSelectedChanged?.Invoke(this, EventArgs.Empty); | ||
} | ||
} | ||
} | ||
|
||
public UICheckbox(string text, string hoverText, float textScale = 1, bool large = false) : base(text, textScale, large) | ||
{ | ||
this.Left.Pixels += 20; | ||
//TextColor = Color.Blue; | ||
text = " " + text; | ||
this.hoverText = hoverText; | ||
SetText(text); | ||
OnClick += UICheckbox_onLeftClick; | ||
Recalculate(); | ||
} | ||
|
||
private void UICheckbox_onLeftClick(UIMouseEvent evt, UIElement listeningElement) | ||
{ | ||
if (disabled) return; | ||
this.Selected = !Selected; | ||
} | ||
|
||
public void SetDisabled(bool disabled = true) | ||
{ | ||
this.disabled = disabled; | ||
if (disabled) | ||
{ | ||
Selected = false; | ||
} | ||
TextColor = disabled ? Color.Gray : Color.White; | ||
} | ||
public void SetHoverText(string hoverText) | ||
{ | ||
this.hoverText = hoverText; | ||
} | ||
|
||
protected override void DrawSelf(SpriteBatch spriteBatch) | ||
{ | ||
base.DrawSelf(spriteBatch); | ||
|
||
CalculatedStyle innerDimensions = base.GetInnerDimensions(); | ||
Vector2 pos = new Vector2(innerDimensions.X, innerDimensions.Y - 5); | ||
|
||
//Rectangle hitbox = GetInnerDimensions().ToRectangle(); | ||
//Main.spriteBatch.Draw(Main.magicPixel, hitbox, Color.Red * 0.6f); | ||
|
||
spriteBatch.Draw(checkboxTexture, pos, null, disabled ? Color.Gray : Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); | ||
if (Selected) | ||
spriteBatch.Draw(checkmarkTexture, pos, null, disabled ? Color.Gray : Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); | ||
|
||
if (IsMouseHovering) | ||
{ | ||
Main.hoverItemName = hoverText; | ||
} | ||
} | ||
} | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.