Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.12 KB | None | 0 0
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using static CorinnaMod.LogicUtilities;
  4. using static CorinnaMod.Graphics.Spritesheets.UI.UISpriteIDs;
  5. using static CorinnaMod.EntityData.PlayerData.PlayerInfo;
  6.  
  7. namespace CorinnaMod.UI.UIData
  8. {
  9.     public class PlayerHotBar
  10.     {
  11.         /// <summary>
  12.         /// Amount of item background inventory slots to be drawn.
  13.         /// </summary>
  14.         private static int AmountofItemSlots
  15.             => 10;
  16.  
  17.         /// <summary>
  18.         /// Horizontal offset to begin drawing the hotbar squares.
  19.         /// </summary>
  20.         private static int HotBarXOffset
  21.             => (int)(0.1f * ScreenW);
  22.  
  23.         /// <summary>
  24.         /// Vertical offset to begin drawing the hotbar Squares.
  25.         /// </summary>
  26.         private static float HotBarYOffSet
  27.             => 0.8f * ScreenH;
  28.  
  29.         public static Vector2 HotBarPosition
  30.             => new Vector2(HotBarXOffset, HotBarYOffSet);
  31.  
  32.         /// <summary>
  33.         /// Space between the hotbar squares.
  34.         /// </summary>
  35.         private static int Padding
  36.             => 6;
  37.  
  38.         public static void DrawHotBar(SpriteBatch spriteBatch)
  39.         {
  40.             for (int Index = 0; Index < AmountofItemSlots; Index++)
  41.             {
  42.                 DrawItemSlot(spriteBatch, Index);
  43.                 DrawItemOverSlot(spriteBatch, Index);
  44.             }
  45.  
  46.         }
  47.  
  48.         public static Vector2 CalculateHotBarPosition(int Index)
  49.             => new Vector2(((Index * Padding) + (Index * ItemSlot.Width)) + HotBarXOffset, HotBarYOffSet);
  50.  
  51.  
  52.         public static Vector2 CalculateItemPosition(int Index, Vector2 HotBarPosition)
  53.             => ScaleTexture(GetInventoryItemSlotTexture(Index)) == 0.5f ?
  54.                HotBarPosition.AddXY(CenterMargins(ItemSlot.Width, GetInventoryItemSlotTexture(Index).Width * 0.5f),
  55.                                     CenterMargins(ItemSlot.Height, GetInventoryItemSlotTexture(Index).Height * 0.5f)):
  56.                HotBarPosition.AddXY(CenterMargins(ItemSlot.Width, GetInventoryItemSlotTexture(Index).Width),
  57.                                     CenterMargins(ItemSlot.Height, GetInventoryItemSlotTexture(Index).Height));
  58.  
  59.         /// <summary>
  60.         /// Scales down textures if they're too big to fit in the hotbar background icon.
  61.         /// </summary>
  62.         /// <param name="Texture">The texture.</param>
  63.         /// <returns>A float to scale down the texture if needed.</returns>
  64.         public static float ScaleTexture(Texture2D Texture)
  65.             => Texture.Width < ItemSlot.Width && Texture.Height < ItemSlot.Height ? 1 : 0.5f;
  66.  
  67.         private static void DrawItemSlot(SpriteBatch Batch, int Index)
  68.             => Batch.Draw(ItemSlot, CalculateHotBarPosition(Index), Color.White);
  69.        
  70.         private static void DrawItemOverSlot(SpriteBatch Batch, int Index)
  71.             => Batch.DrawtoScale(GetInventoryItemSlotTexture(Index),
  72.                                  CalculateItemPosition(Index, CalculateHotBarPosition(Index)),
  73.                                  ScaleTexture(GetInventoryItemSlotTexture(Index)));
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement