/
Draggable.cs
69 lines (54 loc) · 1.67 KB
/
Draggable.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
using Intersect.Client.Core;
using Intersect.Client.Framework.File_Management;
using Intersect.Client.Framework.Graphics;
using Intersect.Client.Framework.Gwen.Control;
using Intersect.Client.Framework.Gwen.Input;
using Intersect.Client.Framework.Input;
using Intersect.Client.General;
namespace Intersect.Client.Interface.Game
{
class Draggable
{
public static Draggable Active = null;
ImagePanel mPnl;
public Draggable(int x, int y, GameTexture tex)
{
mPnl = new ImagePanel(Interface.GameUi.GameCanvas, "Draggable");
mPnl.LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString());
mPnl.SetPosition(
InputHandler.MousePosition.X - mPnl.Width / 2, InputHandler.MousePosition.Y - mPnl.Height / 2
);
mPnl.Texture = tex;
Active = this;
}
public int X
{
get => mPnl.X;
set => mPnl.X = value;
}
public int Y
{
get => mPnl.Y;
set => mPnl.Y = value;
}
public bool Update()
{
mPnl.SetPosition(
InputHandler.MousePosition.X - mPnl.Width / 2, InputHandler.MousePosition.Y - mPnl.Height / 2
);
if (!Globals.InputManager.MouseButtonDown(GameInput.MouseButtons.Left))
{
return true;
}
return false;
}
public void Dispose()
{
if (Active == this)
{
Active = null;
}
Interface.GameUi.GameCanvas.RemoveChild(mPnl, false);
}
}
}