-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathElectronicsManualButton.cs
75 lines (63 loc) · 1.74 KB
/
ElectronicsManualButton.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.GameContent.UI.Elements;
using WireMod.Devices;
namespace WireMod.UI
{
public class ElectronicsManualButton : UIImageButton
{
public string Name { get; set; }
public int ToolCat { get; set; }
public int Tool { get; set; }
public ElectronicsManualButton(string name, Texture2D texture) : base(texture)
{
this.Name = name;
}
protected override void DrawSelf(SpriteBatch spriteBatch)
{
var modPlayer = Main.LocalPlayer.GetModPlayer<WireModPlayer>();
if (modPlayer == null)
{
base.DrawSelf(spriteBatch);
return;
}
var hovering = this.ContainsPoint(Main.MouseScreen);
// Set button opacity
if (this.ToolCat == modPlayer.ToolCategoryMode && this.Tool == modPlayer.ToolMode && modPlayer.ToolMode + modPlayer.ToolCategoryMode > 0)
{
this.SetVisibility(1f, 1f);
}
else if (hovering)
{
this.SetVisibility(0.75f, 0.75f);
}
else
{
this.SetVisibility(0.5f, 0.5f);
}
if (hovering)
{
Main.instance.MouseText(Constants.ToolNames[this.Name]);
// Click
if (!Main.mouseLeftRelease || !Main.mouseLeft)
{
base.DrawSelf(spriteBatch);
return;
}
modPlayer.PlacingDevice = null;
modPlayer.ConnectingPin = null;
modPlayer.ToolCategoryMode = this.ToolCat;
modPlayer.ToolMode = this.Tool;
if (this.ToolCat <= 0)
{
base.DrawSelf(spriteBatch);
return;
}
modPlayer.PlacingDevice = (Device)Activator.CreateInstance(Type.GetType("WireMod.Devices." + Constants.Tools[this.ToolCat][this.Tool]) ?? throw new InvalidOperationException("Device not found!"));
modPlayer.PlacingDevice.SetPins();
}
base.DrawSelf(spriteBatch);
}
}
}