diff options
Diffstat (limited to 'source/ui/elements/game/tooltips')
4 files changed, 188 insertions, 0 deletions
diff --git a/source/ui/elements/game/tooltips/CraftingTooltipDisplay.cs b/source/ui/elements/game/tooltips/CraftingTooltipDisplay.cs new file mode 100644 index 0000000..a7c6e2f --- /dev/null +++ b/source/ui/elements/game/tooltips/CraftingTooltipDisplay.cs @@ -0,0 +1,97 @@ +using Celesteia.Resources.Types; +using Celesteia.UI.Properties; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace Celesteia.UI.Elements.Game.Tooltips { + public class CraftingTooltipDisplay : TooltipDisplay + { + private const float OUTER_SPACING = 16f; + private const float INNER_SPACING = 8f; + public readonly Container Content; + public readonly Label Title; + public readonly ItemDisplay Item; + public Container Recipe; + + public CraftingTooltipDisplay(Rect rect, Texture2D background) : base(rect) { + AddChild(new Image(Rect.RelativeFull(new Rect( + AbsoluteUnit.WithValue(0f), + AbsoluteUnit.WithValue(0f), + AbsoluteUnit.WithValue(256f + (2 * OUTER_SPACING)), + AbsoluteUnit.WithValue(64f + (1 * INNER_SPACING) + (2 * OUTER_SPACING)) + ))).SetTexture(background).MakePatches(4).SetColor(Color.White)); + + Content = new Container(new Rect( + AbsoluteUnit.WithValue(OUTER_SPACING), + AbsoluteUnit.WithValue(OUTER_SPACING), + AbsoluteUnit.WithValue(256f), + AbsoluteUnit.WithValue(64f + (1 * INNER_SPACING)) + )); + + Container titleCard = new Container(new Rect( + AbsoluteUnit.WithValue(0f), + AbsoluteUnit.WithValue(0f), + new RelativeUnit(1f, Content.GetRect(), RelativeUnit.Orientation.Horizontal), + AbsoluteUnit.WithValue(32f) + )); + titleCard.AddChild(Item = new ItemDisplay(new Rect( + AbsoluteUnit.WithValue(0f), + AbsoluteUnit.WithValue(0f), + AbsoluteUnit.WithValue(32f), + AbsoluteUnit.WithValue(32f) + )) { + Text = new TextProperties().Standard().SetTextAlignment(TextAlignment.Bottom | TextAlignment.Right) + }); + titleCard.AddChild(Title = new Label(new Rect( + AbsoluteUnit.WithValue(72f), + AbsoluteUnit.WithValue(0f), + AbsoluteUnit.WithValue(150f), + AbsoluteUnit.WithValue(32f) + )).SetTextProperties(new Properties.TextProperties().Standard().SetTextAlignment(TextAlignment.Left)).SetPivotPoint(new Vector2(0f, 0f))); + Content.AddChild(titleCard); + + Recipe = new Container(new Rect( + new RelativeUnit(.5f, Content.GetRect(), RelativeUnit.Orientation.Horizontal), + AbsoluteUnit.WithValue(32f + INNER_SPACING), + new RelativeUnit(1f, Content.GetRect(), RelativeUnit.Orientation.Horizontal), + AbsoluteUnit.WithValue(32f) + )); + Content.AddChild(Recipe); + + AddChild(Content); + + SetEnabled(false); + } + + public void SetRecipe(Recipe recipe) { + Item.Item = recipe.Result.GetItemType(); + Title.SetText(recipe.Result.GetItemType().Name); + + if (Recipe != null) Recipe.Dispose(); + Recipe = new Container(new Rect( + new RelativeUnit(0f, Content.GetRect(), RelativeUnit.Orientation.Horizontal), + AbsoluteUnit.WithValue(32f + INNER_SPACING), + new RelativeUnit(1f, Content.GetRect(), RelativeUnit.Orientation.Horizontal), + AbsoluteUnit.WithValue(32f) + )); + Recipe.SetPivot(new Vector2(0f, 0f)); + + for (int i = 0; i < recipe.Ingredients.Count; i++) + Recipe.AddChild(new ItemDisplay(new Rect( + AbsoluteUnit.WithValue((i * INNER_SPACING) + (i * 32)), + AbsoluteUnit.WithValue(0f), + AbsoluteUnit.WithValue(32f), + AbsoluteUnit.WithValue(32f) + )) { + Item = recipe.Ingredients[i].GetItemType(), + Amount = recipe.Ingredients[i].Amount, + Text = new TextProperties().Standard() + .SetTextAlignment(TextAlignment.Bottom | TextAlignment.Right) + .SetFontSize(12f) + .SetText(recipe.Ingredients[i].Amount.ToString()) + }); + + Content.AddChild(Recipe); + } + } +}
\ No newline at end of file diff --git a/source/ui/elements/game/tooltips/ItemDisplay.cs b/source/ui/elements/game/tooltips/ItemDisplay.cs new file mode 100644 index 0000000..d3b1524 --- /dev/null +++ b/source/ui/elements/game/tooltips/ItemDisplay.cs @@ -0,0 +1,21 @@ +using Celesteia.Resources.Types; +using Celesteia.UI.Properties; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using MonoGame.Extended.TextureAtlases; + +namespace Celesteia.UI.Elements.Game.Tooltips { + public class ItemDisplay : Element { + public ItemType Item; + public int Amount; + public TextProperties Text; + + public ItemDisplay(Rect rect) => SetRect(rect); + + public override void Draw(SpriteBatch spriteBatch) + { + spriteBatch.Draw(Item.Sprite, GetRectangle(), Color.White, null); + if (Amount > 1) TextUtilities.DrawAlignedText(spriteBatch, GetRectangle(), Text); + } + } +}
\ No newline at end of file diff --git a/source/ui/elements/game/tooltips/ItemTooltipDisplay.cs b/source/ui/elements/game/tooltips/ItemTooltipDisplay.cs new file mode 100644 index 0000000..9b62af4 --- /dev/null +++ b/source/ui/elements/game/tooltips/ItemTooltipDisplay.cs @@ -0,0 +1,62 @@ +using Celesteia.Resources.Types; +using Celesteia.UI.Properties; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace Celesteia.UI.Elements.Game.Tooltips { + public class ItemTooltipDisplay : TooltipDisplay + { + private const float OUTER_SPACING = 16f; + private const float INNER_SPACING = 8f; + public readonly Container Content; + public readonly Label Title; + public readonly ItemDisplay Item; + + public ItemTooltipDisplay(Rect rect, Texture2D background) : base(rect) { + AddChild(new Image(Rect.RelativeFull(new Rect( + AbsoluteUnit.WithValue(0f), + AbsoluteUnit.WithValue(0f), + AbsoluteUnit.WithValue(256f + (2 * OUTER_SPACING)), + AbsoluteUnit.WithValue(32f + (2 * OUTER_SPACING)) + ))).SetTexture(background).MakePatches(4).SetColor(Color.White)); + + Content = new Container(new Rect( + AbsoluteUnit.WithValue(OUTER_SPACING), + AbsoluteUnit.WithValue(OUTER_SPACING), + AbsoluteUnit.WithValue(256f), + AbsoluteUnit.WithValue(32f) + )); + + Container titleCard = new Container(new Rect( + AbsoluteUnit.WithValue(0f), + AbsoluteUnit.WithValue(0f), + new RelativeUnit(1f, Content.GetRect(), RelativeUnit.Orientation.Horizontal), + AbsoluteUnit.WithValue(32f) + )); + titleCard.AddChild(Item = new ItemDisplay(new Rect( + AbsoluteUnit.WithValue(0f), + AbsoluteUnit.WithValue(0f), + AbsoluteUnit.WithValue(32f), + AbsoluteUnit.WithValue(32f) + )) { + Text = new TextProperties().Standard().SetTextAlignment(TextAlignment.Bottom | TextAlignment.Right) + }); + titleCard.AddChild(Title = new Label(new Rect( + AbsoluteUnit.WithValue(72f), + AbsoluteUnit.WithValue(0f), + AbsoluteUnit.WithValue(150f), + AbsoluteUnit.WithValue(32f) + )).SetTextProperties(new Properties.TextProperties().Standard().SetTextAlignment(TextAlignment.Left)).SetPivotPoint(new Vector2(0f, 0f))); + Content.AddChild(titleCard); + + AddChild(Content); + + SetEnabled(false); + } + + public void SetItem(ItemType type) { + Item.Item = type; + Title.SetText(type.Name); + } + } +}
\ No newline at end of file diff --git a/source/ui/elements/game/tooltips/TooltipDisplay.cs b/source/ui/elements/game/tooltips/TooltipDisplay.cs new file mode 100644 index 0000000..2ff051d --- /dev/null +++ b/source/ui/elements/game/tooltips/TooltipDisplay.cs @@ -0,0 +1,8 @@ +using Microsoft.Xna.Framework; + +namespace Celesteia.UI.Elements.Game.Tooltips { + public class TooltipDisplay : Container + { + public TooltipDisplay(Rect rect) : base(rect) {} + } +}
\ No newline at end of file |
