Even More Modifiers  1.0.0.0
A mod for rolling various bonus stats on items
MysteriousWorkbench.cs
Go to the documentation of this file.
1 using System;
2 using Loot.Ext;
3 using Loot.UI.Common;
4 using Loot.UI.Tabs.Cubing;
5 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Graphics;
7 using Terraria;
8 using Terraria.DataStructures;
9 using Terraria.Enums;
10 using Terraria.ModLoader;
11 using Terraria.ObjectData;
12 
13 namespace Loot.Tiles
14 {
15  internal sealed class MysteriousWorkbench : ModTile
16  {
17  private const int Size = 16;
18  private const int Padding = 2;
19 
20  public override void SetDefaults()
21  {
22  Main.tileLighted[Type] = true;
23  Main.tileNoAttach[Type] = true;
24  Main.tileFrameImportant[Type] = true;
25  Main.tileSpelunker[Type] = true;
26  Main.tileShine2[Type] = true;
27  Main.tileShine[Type] = 1200;
28  //TileID.Sets.HasOutlines[Type] = true;
29 
30  TileObjectData.newTile.Width = 4;
31  TileObjectData.newTile.Height = 3;
32  TileObjectData.newTile.AnchorBottom = new AnchorData(AnchorType.SolidTile, TileObjectData.newTile.Width, 0);
33  TileObjectData.newTile.UsesCustomCanPlace = true;
34  TileObjectData.newTile.CoordinateWidth = Size;
35  TileObjectData.newTile.CoordinatePadding = Padding;
36  TileObjectData.newTile.CoordinateHeights = new int[] {Size, Size, Size};
37  //TileObjectData.newTile.HookPostPlaceMyPlayer = new PlacementHook(mod.GetTileEntity<DeconstructorTE>().Hook_AfterPlacement, -1, 0, true);
38  TileObjectData.newTile.Origin = new Point16(2, 2);
39  TileObjectData.newTile.DrawYOffset = 2;
40  TileObjectData.newTile.LavaDeath = false;
41 
42  TileObjectData.addTile(Type);
43  //AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTable);
44 
45  ModTranslation name = CreateMapEntryName();
46  name.SetDefault("MysteriousWorkbench");
47  AddMapEntry(new Color(50, 50, 50), name);
48 
49  disableSmartCursor = true;
50  }
51 
52  public override void MouseOver(int i, int j)
53  {
54  if (Main.LocalPlayer.mouseInterface) return;
55  Player player = Main.LocalPlayer;
56  Tile tile = Main.tile[i, j];
57  player.noThrow = 2;
58  player.showItemIcon = true;
59  // player.showItemIconText = "MysteriousWorkbench";
60  player.showItemIcon2 = ModContent.ItemType<MysteriousWorkbenchItem>();
61  }
62 
63  public override void MouseOverFar(int i, int j)
64  {
65  MouseOver(i, j);
66  Player player = Main.LocalPlayer;
67  if (player.showItemIconText == "")
68  {
69  player.showItemIcon = false;
70  player.showItemIcon2 = 0;
71  }
72  }
73 
74  public override bool NewRightClick(int i, int j)
75  {
76  Tile tile = Main.tile[i, j];
77  Main.mouseRightRelease = false;
78 
79  if (tile.type == Type && Main.LocalPlayer.Distance(new Point16(i, j).ToWorldCoordinates()) <= 15 * 16f)
80  {
81  Loot.Instance.GuiState.ToggleUI(Loot.Instance.GuiInterface);
82  return true;
83  }
84 
85  return false;
86  }
87 
88  public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b)
89  {
90  Color useColor = Color.White;
91  Tile tile = Main.tile[i, j];
92 
93  if (tile.type == Type)
94  {
95  var sine = (float) Math.Sin(Main.essScale * 0.50f);
96  r = 0.05f + 0.35f * sine * useColor.R * 0.01f;
97  g = 0.05f + 0.35f * sine * useColor.G * 0.01f;
98  b = 0.05f + 0.35f * sine * useColor.B * 0.01f;
99  }
100  }
101 
102  public override void DrawEffects(int i, int j, SpriteBatch spriteBatch, ref Color drawColor, ref int nextSpecialDrawIndex)
103  {
104  if (Loot.Instance.GuiState.Visible && Main.LocalPlayer.Distance(new Point16(i, j).ToWorldCoordinates()) > 15 * 16f)
105  {
106  Loot.Instance.GuiState.ToggleUI(Loot.Instance.GuiInterface);
107  }
108  }
109 
110  public override void KillMultiTile(int i, int j, int frameX, int frameY)
111  {
112  if (!Main.dedServ && Loot.Instance.GuiState.Visible)
113  {
114  // Kill UI
115  Loot.Instance.GuiState.ToggleUI(Loot.Instance.GuiInterface);
116  }
117 
118  Item.NewItem(i * 16, j * 16, 20, 28, ModContent.ItemType<MysteriousWorkbenchItem>());
119  //mod.GetTileEntity<DeconstructorTE>().Kill(i, j);
120  }
121 
122  private float frame;
123 
124  public override void PostDraw(int i, int j, SpriteBatch spriteBatch)
125  {
126  var tile = Main.tile[i, j];
127  // Only draw from top left tile
128  if (tile.type == Type
129  && tile.IsTopLeftFrame())
130  {
131  var top = tile.GetTopLeftFrame(i, j, Size, Padding);
132 
133  if (Loot.Instance.GuiState.Visible
134  && Loot.Instance.GuiState.GetCurrentTab() is GuiCubingTab tab
135  && !tab.ComponentButton.Item.IsAir)
136  {
137  Vector2 zero = Main.drawToScreen
138  ? Vector2.Zero
139  : new Vector2(Main.offScreenRange, Main.offScreenRange);
140 
141  Texture2D animTexture = Assets.Textures.GUI.LunarCubeTexture;
142  const int frameWidth = 20;
143  const int frameHeight = 28;
144  Vector2 offset = new Vector2(36f, 8f); // offset 2.5 tiles horizontal, 0.5 tile vertical
145  Vector2 position = new Vector2(i, j) * 16f - Main.screenPosition + offset;
146  Vector2 origin = new Vector2(frameHeight, frameWidth) * 0.5f;
147  // tiles draw every 5 ticks, so we can safely increment here
148  frame = (frame + 0.75f) % 8;
149  spriteBatch.Draw(animTexture, position + zero,
150  new Rectangle(0, frameHeight * (int) frame, frameWidth, frameHeight), Color.White, 0f, origin, 1f,
151  SpriteEffects.None, 0f);
152  }
153  }
154  }
155  }
156 }