5
5
6
6
namespace HUDElementsLib {
7
7
public partial class HUDElement : UIElement {
8
+ public static Vector2 ComputeScreenPosition ( Vector2 positionOffset , Vector2 positionPercent ) {
9
+ return new Vector2 (
10
+ ( positionPercent . X * ( float ) Main . screenWidth ) + ( float ) positionOffset . X ,
11
+ ( positionPercent . Y * ( float ) Main . screenHeight ) + ( float ) positionOffset . Y
12
+ ) ;
13
+ }
14
+
15
+ public static void FitOffsetToScreen ( ref Vector2 positionOffset , Vector2 positionPercent , Vector2 dim ) {
16
+ Vector2 origScrPos = HUDElement . ComputeScreenPosition ( positionOffset , positionPercent ) ;
17
+ Vector2 origEdges = origScrPos + dim ;
18
+
19
+ if ( origScrPos . X < 0f ) {
20
+ positionOffset . X += - origScrPos . X ;
21
+ } else if ( origEdges . X > Main . screenWidth ) {
22
+ positionOffset . X += origEdges . X - Main . screenWidth ;
23
+ }
24
+
25
+ if ( origScrPos . Y < 0f ) {
26
+ positionOffset . Y += - origScrPos . Y ;
27
+ } else if ( origEdges . Y > Main . screenHeight ) {
28
+ positionOffset . Y += origEdges . Y - Main . screenHeight ;
29
+ }
30
+ }
31
+
32
+
33
+
34
+ ////////////////
35
+
8
36
public virtual bool AutoAnchors ( ) {
9
37
return true ;
10
38
}
@@ -17,18 +45,15 @@ public virtual bool AutoAnchors() {
17
45
/// </summary>
18
46
/// <returns></returns>
19
47
public virtual ( Vector2 relative , Vector2 percent ) GetIntendedPosition ( ) {
20
- return ( this . CurrentRelativePosition , this . CurrentPositionPercent ) ;
48
+ return ( this . CurrentPositionOffset , this . CurrentPositionPercent ) ;
21
49
}
22
50
23
51
/// <summary>
24
52
/// Gets intended screen position of element.
25
53
/// </summary>
26
54
/// <returns></returns>
27
55
public virtual Vector2 GetComputedIntendedPosition ( ) {
28
- return new Vector2 (
29
- ( this . CurrentPositionPercent . X * ( float ) Main . screenWidth ) + ( float ) this . CurrentRelativePosition . X ,
30
- ( this . CurrentPositionPercent . Y * ( float ) Main . screenHeight ) + ( float ) this . CurrentRelativePosition . Y
31
- ) ;
56
+ return HUDElement . ComputeScreenPosition ( this . CurrentPositionOffset , this . CurrentPositionPercent ) ;
32
57
}
33
58
34
59
/// <summary>
@@ -37,12 +62,12 @@ public virtual Vector2 GetComputedIntendedPosition() {
37
62
/// <param name="applyDisplacement">Gets the position of the element after being displaced by collisions.</param>
38
63
/// <returns></returns>
39
64
public virtual Vector2 GetHUDComputedPosition ( bool applyDisplacement ) {
40
- Vector2 pos = this . GetComputedIntendedPosition ( ) ;
65
+ Vector2 scrPos = this . GetComputedIntendedPosition ( ) ;
41
66
42
67
if ( applyDisplacement && this . DisplacedOffset . HasValue ) {
43
- return pos + this . DisplacedOffset . Value ;
68
+ return scrPos + this . DisplacedOffset . Value ;
44
69
} else {
45
- return pos ;
70
+ return scrPos ;
46
71
}
47
72
}
48
73
@@ -105,7 +130,7 @@ public void SetIntendedPosition( Vector2 screenPos, bool conveyPercent ) {
105
130
/// <param name="relPos"></param>
106
131
/// <param name="percPos"></param>
107
132
public void SetIntendedPosition ( Vector2 relPos , Vector2 percPos ) {
108
- this . CurrentRelativePosition = relPos ;
133
+ this . CurrentPositionOffset = relPos ;
109
134
this . CurrentPositionPercent = percPos ;
110
135
}
111
136
0 commit comments