-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollabLobbyUIUtils.cs
More file actions
63 lines (55 loc) · 2.34 KB
/
CollabLobbyUIUtils.cs
File metadata and controls
63 lines (55 loc) · 2.34 KB
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
using System;
using Microsoft.Xna.Framework;
using Monocle;
using Color = Microsoft.Xna.Framework.Color;
namespace Celeste.Mod.CollabLobbyUI {
static class CollabLobbyUIUtils
{
public static readonly MTexture Gui_Arrow = GFX.Gui["dotarrow_outline"];
public static readonly MTexture Gui_Cross = GFX.Gui["x"];
public static bool GetClampedScreenPos(Entity e, Level l, out Vector2 pos)
{
if (e == null || l == null)
{
pos = Vector2.Zero;
return false;
}
return GetClampedScreenPos(e.Center, l, out pos);
}
public static bool GetClampedScreenPos(Vector2 p, Level l, out Vector2 pos) {
if (l == null) {
pos = Vector2.Zero;
return false;
}
Vector2 posScreen = l.WorldToScreen(p);
pos = posScreen.Clamp(
32f, 32f,
1920f - 32f, 1080f - 32f
);
return pos.Equals(posScreen);
}
}
public static class ComparableExtensions {
/// <summary>
/// Same as CompareTo but returns null instead of 0 if both items are equal.
/// </summary>
/// <typeparam name="T">IComparable type.</typeparam>
/// <param name="this">This instance.</param>
/// <param name="other">The other instance.</param>
/// <returns>Lexical relation between this and the other instance or null if both are equal.</returns>
///
/// Source: https://stackoverflow.com/a/26890988
public static int? NullableCompareTo<T>(this T obj, T other) where T : IComparable {
var result = obj?.CompareTo(other);
return result != 0 ? result : null;
}
}
public static class MTextureExtensions {
public static void DrawOnCenterLine( this MTexture tex, Vector2 position, float scale = 1f, Color? color = null, float justifyX = 0f) {
tex.Draw(position, new(justifyX * tex.Width, tex.Height / 2f), color ?? Color.White, scale);
}
public static void DrawOnCenterLineScaled(this MTexture tex, Vector2 position, float targetWidth, Color? color = null, float justifyX = 0f) {
tex.Draw(position, new(justifyX * tex.Width, tex.Height / 2f), color ?? Color.White, targetWidth / tex.Width);
}
}
}