Skip to content

Commit 2416cd5

Browse files
author
hamstar0
committed
v5.0.0.1 - Fixed mouse alignment when interacting with elements
1 parent 4059b91 commit 2416cd5

File tree

7 files changed

+56
-54
lines changed

7 files changed

+56
-54
lines changed

HUDElementsLib/HUDElement_Interactions_Edit.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ internal bool UpdateEditModeInteractionsWithinEntireUI() {
1616

1717
if( isInteracting ) {
1818
Main.LocalPlayer.mouseInterface = true; // Locks control for this element
19-
//if( Main.LocalPlayer.mouseInterface ) {
20-
// Main.NewText( "HUD_Elem_PreUpdForInt 1" );
21-
//}
2219
}
2320

2421
return isInteracting;

HUDElementsLib/HUDElementsLib.csproj

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,4 @@
1313
<ItemGroup>
1414
<PackageReference Include="tModLoader.CodeAssist" Version="0.1.*" />
1515
</ItemGroup>
16-
<ItemGroup>
17-
<Reference Include="ModLibsCore">
18-
<HintPath>..\..\..\Mod Libs\Mod Libs Core\Project\ModLibsCore\bin\Release\net452\ModLibsCore.dll</HintPath>
19-
</Reference>
20-
</ItemGroup>
2116
</Project>

HUDElementsLib/HUDManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void LoadHUDElement( HUDElement element ) {
7575

7676
////////////////
7777

78-
internal void PreUpdateForInteractions() {
78+
internal void PreUpdateForInteractions( Vector2 mouseScrPos ) {
7979
foreach( HUDElement elem in this.Elements.Values ) {
8080
if( elem.UpdateEditModeInteractionsWithinEntireUI() ) {
8181
break;
@@ -86,15 +86,15 @@ internal void PreUpdateForInteractions() {
8686
bool hasInteracted = false;
8787

8888
foreach( HUDElement elem in this.Elements.Values ) {
89-
hasInteracted = this.UpdateInteractionsWithinEntireUI_If( elem );
89+
hasInteracted = this.UpdateInteractionsWithinEntireUI_If( elem, mouseScrPos );
9090

9191
if( hasInteracted ) {
9292
break;
9393
}
9494
}
9595

9696
if( !hasInteracted ) {
97-
this.ClearInteractionsIfAny();
97+
this.ClearInteractionsIfAny( mouseScrPos );
9898
}
9999
}
100100
}

HUDElementsLib/HUDManager_Interactivity.cs

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ partial class HUDManager {
3434

3535
////////////////
3636

37-
private bool UpdateInteractionsWithinEntireUI_If( HUDElement elem ) {
37+
private bool UpdateInteractionsWithinEntireUI_If( HUDElement elem, Vector2 mouseScrPos ) {
38+
int mouseX = (int)mouseScrPos.X;
39+
int mouseY = (int)mouseScrPos.Y;
40+
3841
if( !elem.IsEnabled() ) {
3942
return false;
4043
}
41-
if( !elem.GetHUDComputedArea(true).Contains(Main.mouseX, Main.mouseY) ) {
44+
if( !elem.GetHUDComputedArea(true).Contains(mouseX, mouseY) ) {
4245
return false;
4346
}
4447

@@ -47,18 +50,21 @@ private bool UpdateInteractionsWithinEntireUI_If( HUDElement elem ) {
4750
return false;
4851
}
4952

53+
//
54+
5055
this._ClickDisabledMillisecondsRemaining = Math.Max(
5156
0.0d,
5257
this._ClickDisabledMillisecondsRemaining - time.ElapsedGameTime.TotalMilliseconds
5358
);
5459

60+
//
61+
5562
if( this._ClickDisabledMillisecondsRemaining > 0.0d ) {
5663
return true;
5764
}
5865

5966
//
6067

61-
var mousePos = new Vector2( (float)Main.mouseX, (float)Main.mouseY );
6268
bool mouseLeftDown = Main.mouseLeft; //&& Main.hasFocus;
6369
bool mouseRightDown = Main.mouseRight; //&& Main.hasFocus;
6470
bool mouseMiddleDown = Main.mouseMiddle; //&& Main.hasFocus;
@@ -69,10 +75,10 @@ private bool UpdateInteractionsWithinEntireUI_If( HUDElement elem ) {
6975

7076
if( elem != this._LastElementHover ) {
7177
if( this._LastElementHover != null ) {
72-
this._LastElementHover.MouseOut( new UIMouseEvent(this._LastElementHover, mousePos) );
78+
this._LastElementHover.MouseOut( new UIMouseEvent(this._LastElementHover, mouseScrPos) );
7379
}
7480

75-
elem.MouseOver( new UIMouseEvent(elem, mousePos) );
81+
elem.MouseOver( new UIMouseEvent(elem, mouseScrPos) );
7682

7783
this._LastElementHover = elem;
7884
}
@@ -83,24 +89,24 @@ private bool UpdateInteractionsWithinEntireUI_If( HUDElement elem ) {
8389
if( mouseLeftDown && !this._WasMouseLeftDown ) {
8490
this._LastElementLeftDown = elem;
8591

86-
elem.MouseDown( new UIMouseEvent( elem, mousePos ) );
92+
elem.MouseDown( new UIMouseEvent(elem, mouseScrPos) );
8793

8894
double milliSinceLastMouseDown = time.TotalGameTime.TotalMilliseconds - this._LastMouseDownMilliseconds;
8995

9096
if( this._LastElementLeftClicked == elem && milliSinceLastMouseDown < 500.0 ) {
91-
elem.DoubleClick( new UIMouseEvent( elem, mousePos ) );
97+
elem.DoubleClick( new UIMouseEvent( elem, mouseScrPos ) );
9298
this._LastElementLeftClicked = null;
9399
}
94100

95101
this._LastMouseDownMilliseconds = time.TotalGameTime.TotalMilliseconds;
96102
} else if( this._LastElementLeftDown != null ) {
97-
if( this._LastElementLeftDown.GetHUDComputedArea(true).Contains(Main.mouseX, Main.mouseY) ) {
98-
this._LastElementLeftDown.Click( new UIMouseEvent(this._LastElementLeftDown, mousePos) );
103+
if( this._LastElementLeftDown.GetHUDComputedArea(true).Contains(mouseX, mouseY) ) {
104+
this._LastElementLeftDown.Click( new UIMouseEvent(this._LastElementLeftDown, mouseScrPos) );
99105

100106
this._LastElementLeftClicked = this._LastElementLeftDown;
101107
}
102108

103-
this._LastElementLeftDown.MouseUp( new UIMouseEvent(this._LastElementLeftDown, mousePos) );
109+
this._LastElementLeftDown.MouseUp( new UIMouseEvent(this._LastElementLeftDown, mouseScrPos) );
104110

105111
this._LastElementLeftDown = null;
106112
}
@@ -111,24 +117,24 @@ private bool UpdateInteractionsWithinEntireUI_If( HUDElement elem ) {
111117
if( mouseRightDown && !this._WasMouseRightDown ) {
112118
this._LastElementRightDown = elem;
113119

114-
elem.RightMouseDown( new UIMouseEvent( elem, mousePos ) );
120+
elem.RightMouseDown( new UIMouseEvent(elem, mouseScrPos) );
115121

116122
double milliSinceLastMouseRightDown = time.TotalGameTime.TotalMilliseconds - this._LastMouseRightDownMilliseconds;
117123

118124
if( this._LastElementRightClicked == elem && milliSinceLastMouseRightDown < 500.0 ) {
119-
elem.RightDoubleClick( new UIMouseEvent( elem, mousePos ) );
125+
elem.RightDoubleClick( new UIMouseEvent(elem, mouseScrPos) );
120126
this._LastElementRightClicked = null;
121127
}
122128

123129
this._LastMouseRightDownMilliseconds = time.TotalGameTime.TotalMilliseconds;
124130
} else if( this._LastElementRightDown != null ) {
125-
if( this._LastElementRightDown.GetHUDComputedArea( true ).Contains( Main.mouseX, Main.mouseY ) ) {
126-
this._LastElementRightDown.RightClick( new UIMouseEvent( this._LastElementRightDown, mousePos ) );
131+
if( this._LastElementRightDown.GetHUDComputedArea(true).Contains(mouseX, mouseY) ) {
132+
this._LastElementRightDown.RightClick( new UIMouseEvent(this._LastElementRightDown, mouseScrPos) );
127133

128134
this._LastElementRightClicked = this._LastElementRightDown;
129135
}
130136

131-
this._LastElementRightDown.RightMouseUp( new UIMouseEvent( this._LastElementRightDown, mousePos ) );
137+
this._LastElementRightDown.RightMouseUp( new UIMouseEvent(this._LastElementRightDown, mouseScrPos) );
132138

133139
this._LastElementRightDown = null;
134140
}
@@ -138,25 +144,25 @@ private bool UpdateInteractionsWithinEntireUI_If( HUDElement elem ) {
138144
if( mouseMiddleDown && !this._WasMouseMiddleDown ) {
139145
this._LastElementMiddleDown = elem;
140146

141-
elem.MiddleMouseDown( new UIMouseEvent( elem, mousePos ) );
147+
elem.MiddleMouseDown( new UIMouseEvent(elem, mouseScrPos) );
142148

143149
double milliSinceLastMouseMiddleDown = time.TotalGameTime.TotalMilliseconds - this._LastMouseMiddleDownMilliseconds;
144150

145151
if( this._LastElementMiddleClicked == elem && milliSinceLastMouseMiddleDown < 500.0 ) {
146-
elem.MiddleDoubleClick( new UIMouseEvent( elem, mousePos ) );
152+
elem.MiddleDoubleClick( new UIMouseEvent(elem, mouseScrPos) );
147153

148154
this._LastElementMiddleClicked = null;
149155
}
150156

151157
this._LastMouseMiddleDownMilliseconds = time.TotalGameTime.TotalMilliseconds;
152158
} else if( this._LastElementMiddleDown != null ) {
153-
if( this._LastElementMiddleDown.GetHUDComputedArea( true ).Contains( Main.mouseX, Main.mouseY ) ) {
154-
this._LastElementMiddleDown.MiddleClick( new UIMouseEvent( this._LastElementMiddleDown, mousePos ) );
159+
if( this._LastElementMiddleDown.GetHUDComputedArea(true).Contains(mouseX, mouseY) ) {
160+
this._LastElementMiddleDown.MiddleClick( new UIMouseEvent(this._LastElementMiddleDown, mouseScrPos) );
155161

156162
this._LastElementMiddleClicked = this._LastElementMiddleDown;
157163
}
158164

159-
this._LastElementMiddleDown.MiddleMouseUp( new UIMouseEvent( this._LastElementMiddleDown, mousePos ) );
165+
this._LastElementMiddleDown.MiddleMouseUp( new UIMouseEvent(this._LastElementMiddleDown, mouseScrPos) );
160166

161167
this._LastElementMiddleDown = null;
162168
}
@@ -166,25 +172,25 @@ private bool UpdateInteractionsWithinEntireUI_If( HUDElement elem ) {
166172
if( mouseXButton1Down && !this._WasMouseXButton1Down ) {
167173
this._LastElementXButton1Down = elem;
168174

169-
elem.XButton1MouseDown( new UIMouseEvent( elem, mousePos ) );
175+
elem.XButton1MouseDown( new UIMouseEvent(elem, mouseScrPos) );
170176

171177
double milliSinceLastX1Down = time.TotalGameTime.TotalMilliseconds - this._LastMouseXButton1DownMilliseconds;
172178

173179
if( this._LastElementXButton1Clicked == elem && milliSinceLastX1Down < 500.0 ) {
174-
elem.XButton1DoubleClick( new UIMouseEvent( elem, mousePos ) );
180+
elem.XButton1DoubleClick( new UIMouseEvent(elem, mouseScrPos) );
175181

176182
this._LastElementXButton1Clicked = null;
177183
}
178184

179185
this._LastMouseXButton1DownMilliseconds = time.TotalGameTime.TotalMilliseconds;
180186
} else if( this._LastElementXButton1Down != null ) {
181-
if( this._LastElementXButton1Down.GetHUDComputedArea( true ).Contains( Main.mouseX, Main.mouseY ) ) {
182-
this._LastElementXButton1Down.XButton1Click( new UIMouseEvent( this._LastElementXButton1Down, mousePos ) );
187+
if( this._LastElementXButton1Down.GetHUDComputedArea(true).Contains(mouseX, mouseY) ) {
188+
this._LastElementXButton1Down.XButton1Click( new UIMouseEvent(this._LastElementXButton1Down, mouseScrPos) );
183189

184190
this._LastElementXButton1Clicked = this._LastElementXButton1Down;
185191
}
186192

187-
this._LastElementXButton1Down.XButton1MouseUp( new UIMouseEvent( this._LastElementXButton1Down, mousePos ) );
193+
this._LastElementXButton1Down.XButton1MouseUp( new UIMouseEvent(this._LastElementXButton1Down, mouseScrPos) );
188194

189195
this._LastElementXButton1Down = null;
190196
}
@@ -194,33 +200,33 @@ private bool UpdateInteractionsWithinEntireUI_If( HUDElement elem ) {
194200
if( mouseXButton2Down && !this._WasMouseXButton2Down ) {
195201
this._LastElementXButton2Down = elem;
196202

197-
elem.XButton2MouseDown( new UIMouseEvent( elem, mousePos ) );
203+
elem.XButton2MouseDown( new UIMouseEvent(elem, mouseScrPos) );
198204

199205
double millisSinceLastX2Down = time.TotalGameTime.TotalMilliseconds - this._LastMouseXButton2DownMilliseconds;
200206

201207
if( this._LastElementXButton2Clicked == elem && millisSinceLastX2Down < 500.0 ) {
202208

203-
elem.XButton2DoubleClick( new UIMouseEvent( elem, mousePos ) );
209+
elem.XButton2DoubleClick( new UIMouseEvent(elem, mouseScrPos) );
204210
this._LastElementXButton2Clicked = null;
205211
}
206212

207213
this._LastMouseXButton2DownMilliseconds = time.TotalGameTime.TotalMilliseconds;
208214
} else if( this._LastElementXButton2Down != null ) {
209-
if( this._LastElementXButton2Down.GetHUDComputedArea( true ).Contains( Main.mouseX, Main.mouseY ) ) {
210-
this._LastElementXButton2Down.XButton2Click( new UIMouseEvent( this._LastElementXButton2Down, mousePos ) );
215+
if( this._LastElementXButton2Down.GetHUDComputedArea(true).Contains(mouseX, mouseY) ) {
216+
this._LastElementXButton2Down.XButton2Click( new UIMouseEvent(this._LastElementXButton2Down, mouseScrPos) );
211217

212218
this._LastElementXButton2Clicked = this._LastElementXButton2Down;
213219
}
214220

215-
this._LastElementXButton2Down.XButton2MouseUp( new UIMouseEvent( this._LastElementXButton2Down, mousePos ) );
221+
this._LastElementXButton2Down.XButton2MouseUp( new UIMouseEvent(this._LastElementXButton2Down, mouseScrPos) );
216222

217223
this._LastElementXButton2Down = null;
218224
}
219225

220226
//
221227

222228
if( PlayerInput.ScrollWheelDeltaForUI != 0 ) {
223-
elem.ScrollWheel( new UIScrollWheelEvent( elem, mousePos, PlayerInput.ScrollWheelDeltaForUI ) );
229+
elem.ScrollWheel( new UIScrollWheelEvent( elem, mouseScrPos, PlayerInput.ScrollWheelDeltaForUI ) );
224230
// PlayerInput.ScrollWheelDeltaForUI = 0; Moved after ModHooks.UpdateUI(gameTime);
225231
}
226232

@@ -238,13 +244,9 @@ private bool UpdateInteractionsWithinEntireUI_If( HUDElement elem ) {
238244

239245
////
240246

241-
private void ClearInteractionsIfAny() {
242-
var mousePos = new Vector2( (float)Main.mouseX, (float)Main.mouseY );
243-
244-
//
245-
247+
private void ClearInteractionsIfAny( Vector2 mouseScrPos ) {
246248
if( this._LastElementHover != null ) {
247-
this._LastElementHover.MouseOut( new UIMouseEvent( this._LastElementHover, mousePos ) );
249+
this._LastElementHover.MouseOut( new UIMouseEvent(this._LastElementHover, mouseScrPos) );
248250

249251
this._LastElementHover = null;
250252
}

HUDElementsLib/MyMod_UI.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,18 @@ out elems
7979
)
8080
);
8181
}*/
82+
this.HUDManager?.PreUpdateForInteractions( Main.MouseScreen ); //:blobshrug:
83+
84+
//
85+
8286
this.MyUI?.Update( Main._drawInterfaceGameTime ); //:blobshrug:
8387
this.MyUI?.Draw( Main.spriteBatch );
8488

8589
return true;
8690
};
8791

92+
//
93+
8894
int mouseTextIdx = layers.FindIndex( layer => layer.Name.Equals("Vanilla: Mouse Text") );
8995
if( mouseTextIdx >= 0 ) {
9096
var invOverLayer = new LegacyGameInterfaceLayer(

HUDElementsLib/MyPlayer.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,19 @@ public override TagCompound Save() {
9797

9898
////////////////
9999

100-
public override void PreUpdate() {
100+
/*public override void PreUpdate() {
101101
if( this.player.whoAmI == Main.myPlayer ) {
102-
this.PreUpdateLocal();
102+
this.PreUpdate_Local();
103103
}
104104
}
105105
106106
////
107107
108-
private void PreUpdateLocal() {
108+
private void PreUpdate_Local() {
109109
var mymod = ModContent.GetInstance<HUDElementsLibMod>();
110-
mymod.HUDManager?.PreUpdateForInteractions(); //:blobshrug:
111-
}
110+
Vector2 mouseScrPos = Main.MouseScreen;
111+
112+
mymod.HUDManager?.PreUpdateForInteractions( mouseScrPos ); //:blobshrug:
113+
}*/
112114
}
113115
}

HUDElementsLib/build.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
displayName = HUD Elements Lib
22
author = hamstar
3-
version = 5.0.0
3+
version = 5.0.0.1
44
buildIgnore = *.csproj, *.user, *.bat, obj\*, bin\*, .vs\*, .git\*
55
homepage = https://forums.terraria.org/index.php?threads/hud-elements-lib.103890/

0 commit comments

Comments
 (0)