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
|
using Raylib_cs;
using System.Collections.ObjectModel;
using System.Numerics;
namespace OnekoOnline;
abstract class Mouse : Drawable
{
public string Name = "Mouse";
public Bitmap Cursor;
protected static List<Mouse> allMice = [];
public static ReadOnlyCollection<Mouse> AllMice => allMice.AsReadOnly();
public static Action<Mouse>? Clicked;
protected readonly static byte[] FallbackImg = EmbeddedResources.GetResource("misc.cursor.png");
public Mouse() : base()
{
DrawOrder = 100;
allMice.Add(this);
string CursorPath = OnekoOnline.Config.GetValue("CursorSpritePath", "misc/cursor.png");
if (File.Exists(CursorPath) && new FileInfo(CursorPath).Length < 2500) {
Cursor = Bitmap.FromPNGMemory(File.ReadAllBytes(CursorPath), 32, 32);
} else {
Console.WriteLine("The cursor PNG was either mising or too big. Using the default.");
Cursor = Bitmap.FromPNGMemory(FallbackImg);
}
}
public Mouse(Bitmap cursor) : base()
{
DrawOrder = 100;
allMice.Add(this);
Cursor = cursor;
}
public override void Draw()
{
Vector2 NametagPosition = new(Position.X-(Name.Length*3)+4, Position.Y-13);
Raylib.DrawTextEx(OnekoOnline.DefaultFont, Name, NametagPosition+Directions.Down, 11, 0, Color.Black); //Shadow
Raylib.DrawTextEx(OnekoOnline.DefaultFont, Name, NametagPosition, 11, 0, Color.White);
Raylib.DrawTexture(Cursor.Texture, (int)Position.X, (int)Position.Y, Color.White);
}
protected override void Unload()
{
Cursor.Dispose();
allMice.Remove(this);
}
}
|