Home Unreal Engine
The BRAWL² Tournament Challenge has been announced!

It starts May 12, and ends Sept 12. Let's see what you got!

https://polycount.com/discussion/237047/the-brawl²-tournament

Adding the mouse cursor to HUD?

Hello,

I'm new to UScript and a friend of mine pointed me to a tutorial on the UDN that shows how to get the mouse cursor to show up and interact with a level in UDK. I'm slowly going through this tutorial, but I seem to be having a couple of issues. I'm getting 3 errors that I'm not sure how to fix. I don't want to open UDK until these can be fixed. I don't want to mess up my project or UDK in general. I've already had to reinstall UDK multiple times due to various issues.

Any help would be greatly appreciated. Thank you!!

Errors:
th_Mouse_interaction_UDK_errors.png

MouseInterfaceInteractionInterface.uc
  1. class MouseInterfaceInteractionInterface extends Object;
  2.  
  3. interface MouseInterfaceInteractionInterface
  4.  
  5. // Called when the left mouse button is pressed
  6. function MouseLeftPressed(Vector MouseWorldOrigin, Vector MouseWorldDirection, Vector HitLocation, Vector HitNormal);
  7.  
  8. // Called when the left mouse button is released
  9. function MouseLeftReleased(Vector MouseWorldOrigin, Vector MouseWorldDirection);
  10.  
  11. // Called when the right mouse button is pressed
  12. function MouseRightPressed(Vector MouseWorldOrigin, Vector MouseWorldDirection, Vector HitLocation, Vector HitNormal);
  13.  
  14. // Called when the right mouse button is released
  15. function MouseRightReleased(Vector MouseWorldOrigin, Vector MouseWorldDirection);
  16.  
  17. // Called when the middle mouse button is pressed
  18. function MouseMiddlePressed(Vector MouseWorldOrigin, Vector MouseWorldDirection, Vector HitLocation, Vector HitNormal);
  19.  
  20. // Called when the middle mouse button is released
  21. function MouseMiddleReleased(Vector MouseWorldOrigin, Vector MouseWorldDirection);
  22.  
  23. // Called when the middle mouse button is scrolled up
  24. function MouseScrollUp(Vector MouseWorldOrigin, Vector MouseWorldDirection);
  25.  
  26. // Called when the middle mouse button is scrolled down
  27. function MouseScrollDown(Vector MouseWorldOrigin, Vector MouseWorldDirection);
  28.  
  29. // Called when the mouse is moved over the actor
  30. function MouseOver(Vector MouseWorldOrigin, Vector MouseWorldDirection);
  31.  
  32. // Called when the mouse is moved out from the actor (when it was previously over it)
  33. function MouseOut(Vector MouseWorldOrigin, Vector MouseWorldDirection);
  34.  
  35. // Returns the hit location of the mouse trace
  36. function Vector GetHitLocation();
  37.  
  38. // Returns the hit normal of the mouse trace
  39. function Vector GetHitNormal();
  40.  
  41. // Returns the mouse world origin calculated by the deprojection within the canvas
  42. function Vector GetMouseWorldOrigin();
  43.  
  44. // Returns the mouse world direction calculated by the deprojection within the canvas
  45. function Vector GetMouseWorldDirection();
  46.  
  47. DefaultProperties
  48. {
  49. }

MouseInterfaceKActor.uc
  1. class MouseInterfaceKActor extends KActor
  2. Implements(MouseInterfaceInteractionInterface);
  3.  
  4. var Vector CachedMouseHitLocation;
  5. var Vector CachedMouseHitNormal;
  6. var Vector CachedMouseWorldOrigin;
  7. var Vector CachedMouseWorldDirection;
  8.  
  9. // ===
  10. // MouseInterfaceInteractionInterface implementation
  11. // ===
  12. function MouseLeftPressed(Vector MouseWorldOrigin, Vector MouseWorldDirection, Vector HitLocation, Vector HitNormal)
  13. {
  14. CachedMouseWorldOrigin = MouseWorldOrigin;
  15. CachedMouseWorldDirection = MouseWorldDirection;
  16. CachedMouseHitLocation = HitLocation;
  17. CachedMouseHitNormal = HitNormal;
  18. TriggerEventClass(class'SeqEvent_MouseInput', Self, 0);
  19. }
  20.  
  21. function MouseLeftReleased(Vector MouseWorldOrigin, Vector MouseWorldDirection)
  22. {
  23. CachedMouseWorldOrigin = MouseWorldOrigin;
  24. CachedMouseWorldDirection = MouseWorldDirection;
  25. CachedMouseHitLocation = Vect(0.f, 0.f, 0.f);
  26. CachedMouseHitNormal = Vect(0.f, 0.f, 0.f);
  27. TriggerEventClass(class'SeqEvent_MouseInput', Self, 1);
  28. }
  29.  
  30. function MouseRightPressed(Vector MouseWorldOrigin, Vector MouseWorldDirection, Vector HitLocation, Vector HitNormal)
  31. {
  32. CachedMouseWorldOrigin = MouseWorldOrigin;
  33. CachedMouseWorldDirection = MouseWorldDirection;
  34. CachedMouseHitLocation = HitLocation;
  35. CachedMouseHitNormal = HitNormal;
  36. TriggerEventClass(class'SeqEvent_MouseInput', Self, 2);
  37. }
  38.  
  39. function MouseRightReleased(Vector MouseWorldOrigin, Vector MouseWorldDirection)
  40. {
  41. CachedMouseWorldOrigin = MouseWorldOrigin;
  42. CachedMouseWorldDirection = MouseWorldDirection;
  43. CachedMouseHitLocation = Vect(0.f, 0.f, 0.f);
  44. CachedMouseHitNormal = Vect(0.f, 0.f, 0.f);
  45. TriggerEventClass(class'SeqEvent_MouseInput', Self, 3);
  46. }
  47.  
  48. function MouseMiddlePressed(Vector MouseWorldOrigin, Vector MouseWorldDirection, Vector HitLocation, Vector HitNormal)
  49. {
  50. CachedMouseWorldOrigin = MouseWorldOrigin;
  51. CachedMouseWorldDirection = MouseWorldDirection;
  52. CachedMouseHitLocation = HitLocation;
  53. CachedMouseHitNormal = HitNormal;
  54. TriggerEventClass(class'SeqEvent_MouseInput', Self, 4);
  55. }
  56.  
  57. function MouseMiddleReleased(Vector MouseWorldOrigin, Vector MouseWorldDirection)
  58. {
  59. CachedMouseWorldOrigin = MouseWorldOrigin;
  60. CachedMouseWorldDirection = MouseWorldDirection;
  61. CachedMouseHitLocation = Vect(0.f, 0.f, 0.f);
  62. CachedMouseHitNormal = Vect(0.f, 0.f, 0.f);
  63. TriggerEventClass(class'SeqEvent_MouseInput', Self, 5);
  64. }
  65.  
  66. function MouseScrollUp(Vector MouseWorldOrigin, Vector MouseWorldDirection)
  67. {
  68. CachedMouseWorldOrigin = MouseWorldOrigin;
  69. CachedMouseWorldDirection = MouseWorldDirection;
  70. CachedMouseHitLocation = Vect(0.f, 0.f, 0.f);
  71. CachedMouseHitNormal = Vect(0.f, 0.f, 0.f);
  72. TriggerEventClass(class'SeqEvent_MouseInput', Self, 6);
  73. }
  74.  
  75. function MouseScrollDown(Vector MouseWorldOrigin, Vector MouseWorldDirection)
  76. {
  77. CachedMouseWorldOrigin = MouseWorldOrigin;
  78. CachedMouseWorldDirection = MouseWorldDirection;
  79. CachedMouseHitLocation = Vect(0.f, 0.f, 0.f);
  80. CachedMouseHitNormal = Vect(0.f, 0.f, 0.f);
  81. TriggerEventClass(class'SeqEvent_MouseInput', Self, 7);
  82. }
  83.  
  84. function MouseOver(Vector MouseWorldOrigin, Vector MouseWorldDirection)
  85. {
  86. CachedMouseWorldOrigin = MouseWorldOrigin;
  87. CachedMouseWorldDirection = MouseWorldDirection;
  88. CachedMouseHitLocation = Vect(0.f, 0.f, 0.f);
  89. CachedMouseHitNormal = Vect(0.f, 0.f, 0.f);
  90. TriggerEventClass(class'SeqEvent_MouseInput', Self, 8);
  91. }
  92.  
  93. function MouseOut(Vector MouseWorldOrigin, Vector MouseWorldDirection)
  94. {
  95. CachedMouseWorldOrigin = MouseWorldOrigin;
  96. CachedMouseWorldDirection = MouseWorldDirection;
  97. CachedMouseHitLocation = Vect(0.f, 0.f, 0.f);
  98. CachedMouseHitNormal = Vect(0.f, 0.f, 0.f);
  99. TriggerEventClass(class'SeqEvent_MouseInput', Self, 9);
  100. }
  101.  
  102. function Vector GetHitLocation()
  103. {
  104. return CachedMouseHitLocation;
  105. }
  106.  
  107. function Vector GetHitNormal()
  108. {
  109. return CachedMouseHitNormal;
  110. }
  111.  
  112. function Vector GetMouseWorldOrigin()
  113. {
  114. return CachedMouseWorldOrigin;
  115. }
  116.  
  117. function Vector GetMouseWorldDirection()
  118. {
  119. return CachedMouseWorldDirection;
  120. }
  121.  
  122. defaultproperties
  123. {
  124. SupportedEvents(4)=class'SeqEvent_MouseInput'
  125. }

MouseInterfacePlayerInput.uc
  1. class MouseInterfacePlayerInput extends PlayerInput;
  2.  
  3. // Stored mouse position. Set to private write as we don't want other classes to modify it, but still allow other classes to access it.
  4. var IntPoint MousePosition;
  5.  
  6. event PlayerInput(float DeltaTime)
  7. {
  8. // Handle mouse
  9. // Ensure we have a valid HUD
  10. if (myHUD != None)
  11. {
  12. // Add the aMouseX to the mouse position and clamp it within the viewport width
  13. MousePosition.X = Clamp(MousePosition.X + aMouseX, 0, myHUD.SizeX);
  14. // Add the aMouseY to the mouse position and clamp it within the viewport height
  15. MousePosition.Y = Clamp(MousePosition.Y - aMouseY, 0, myHUD.SizeY);
  16. }
  17.  
  18. Super.PlayerInput(DeltaTime);
  19. }
  20.  
  21. defaultproperties
  22. {
  23. }

MouseInterfacePlayerController.uc
  1. class MouseInterfacePlayerController extends PlayerController;
  2.  
  3. // Null this function
  4. function UpdateRotation(float DeltaTime);
  5.  
  6. defaultproperties
  7. {
  8. // Set the input class to the mouse interface player input
  9. InputClass=class'MouseInterfacePlayerInput'
  10. }

MouseInterfaceHUD.uc
  1. class MouseInterfaceHUD extends HUD;
  2.  
  3. // The texture which represents the cursor on the screen
  4. var const Texture2D CursorTexture;
  5. // The color of the cursor
  6. var const Color CursorColor;
  7. // Pending left mouse button pressed event
  8. var bool PendingLeftPressed;
  9. // Pending left mouse button released event
  10. var bool PendingLeftReleased;
  11. // Pending right mouse button pressed event
  12. var bool PendingRightPressed;
  13. // Pending right mouse button released event
  14. var bool PendingRightReleased;
  15. // Pending middle mouse button pressed event
  16. var bool PendingMiddlePressed;
  17. // Pending middle mouse button released event
  18. var bool PendingMiddleReleased;
  19. // Pending mouse wheel scroll up event
  20. var bool PendingScrollUp;
  21. // Pending mouse wheel scroll down event
  22. var bool PendingScrollDown;
  23. // Cached mouse world origin
  24. var Vector CachedMouseWorldOrigin;
  25. // Cached mouse world direction
  26. var Vector CachedMouseWorldDirection;
  27. // Last mouse interaction interface
  28. var MouseInterfaceInteractionInterface LastMouseInteractionInterface;
  29.  
  30. event PostRender()
  31. {
  32. local MouseInterfacePlayerInput MouseInterfacePlayerInput;
  33. local MouseInterfaceInteractionInterface MouseInteractionInterface;
  34. local Vector HitLocation, HitNormal;
  35.  
  36. Super.PostRender();
  37.  
  38. // Ensure that we aren't using ScaleForm and that we have a valid cursor
  39. if (!UsingScaleForm && CursorTexture != None)
  40. {
  41. // Ensure that we have a valid PlayerOwner
  42. if (PlayerOwner != None)
  43. {
  44. // Cast to get the MouseInterfacePlayerInput
  45. MouseInterfacePlayerInput = MouseInterfacePlayerInput(PlayerOwner.PlayerInput);
  46.  
  47. // If we're not using scale form and we have a valid cursor texture, render it
  48. if (MouseInterfacePlayerInput != None)
  49. {
  50. // Set the canvas position to the mouse position
  51. Canvas.SetPos(MouseInterfacePlayerInput.MousePosition.X, MouseInterfacePlayerInput.MousePosition.Y);
  52. // Set the cursor color
  53. Canvas.DrawColor = CursorColor;
  54. // Draw the texture on the screen
  55. Canvas.DrawTile(CursorTexture, CursorTexture.SizeX, CursorTexture.SizeY, 0.f, 0.f, CursorTexture.SizeX, CursorTexture.SizeY,, true);
  56. }
  57. }
  58. }
  59.  
  60. // Get the current mouse interaction interface
  61. MouseInteractionInterface = GetMouseActor(HitLocation, HitNormal);
  62.  
  63. // Handle mouse over and mouse out
  64. // Did we previously had a mouse interaction interface?
  65. if (LastMouseInteractionInterface != None)
  66. {
  67. // If the last mouse interaction interface differs to the current mouse interaction
  68. if (LastMouseInteractionInterface != MouseInteractionInterface)
  69. {
  70. // Call the mouse out function
  71. LastMouseInteractionInterface.MouseOut(CachedMouseWorldOrigin, CachedMouseWorldDirection);
  72. // Assign the new mouse interaction interface
  73. LastMouseInteractionInterface = MouseInteractionInterface;
  74.  
  75. // If the last mouse interaction interface is not none
  76. if (LastMouseInteractionInterface != None)
  77. {
  78. // Call the mouse over function
  79. LastMouseInteractionInterface.MouseOver(CachedMouseWorldOrigin, CachedMouseWorldDirection); // Call mouse over
  80. }
  81. }
  82. }
  83. else if (MouseInteractionInterface != None)
  84. {
  85. // Assign the new mouse interaction interface
  86. LastMouseInteractionInterface = MouseInteractionInterface;
  87. // Call the mouse over function
  88. LastMouseInteractionInterface.MouseOver(CachedMouseWorldOrigin, CachedMouseWorldDirection);
  89. }
  90.  
  91. if (LastMouseInteractionInterface != None)
  92. {
  93. // Handle left mouse button
  94. if (PendingLeftPressed)
  95. {
  96. if (PendingLeftReleased)
  97. {
  98. // This is a left click, so discard
  99. PendingLeftPressed = false;
  100. PendingLeftReleased = false;
  101. }
  102. else
  103. {
  104. // Left is pressed
  105. PendingLeftPressed = false;
  106. LastMouseInteractionInterface.MouseLeftPressed(CachedMouseWorldOrigin, CachedMouseWorldDirection, HitLocation, HitNormal);
  107. }
  108. }
  109. else if (PendingLeftReleased)
  110. {
  111. // Left is released
  112. PendingLeftReleased = false;
  113. LastMouseInteractionInterface.MouseLeftReleased(CachedMouseWorldOrigin, CachedMouseWorldDirection);
  114. }
  115.  
  116. // Handle right mouse button
  117. if (PendingRightPressed)
  118. {
  119. if (PendingRightReleased)
  120. {
  121. // This is a right click, so discard
  122. PendingRightPressed = false;
  123. PendingRightReleased = false;
  124. }
  125. else
  126. {
  127. // Right is pressed
  128. PendingRightPressed = false;
  129. LastMouseInteractionInterface.MouseRightPressed(CachedMouseWorldOrigin, CachedMouseWorldDirection, HitLocation, HitNormal);
  130. }
  131. }
  132. else if (PendingRightReleased)
  133. {
  134. // Right is released
  135. PendingRightReleased = false;
  136. LastMouseInteractionInterface.MouseRightReleased(CachedMouseWorldOrigin, CachedMouseWorldDirection);
  137. }
  138.  
  139. // Handle middle mouse button
  140. if (PendingMiddlePressed)
  141. {
  142. if (PendingMiddleReleased)
  143. {
  144. // This is a middle click, so discard
  145. PendingMiddlePressed = false;
  146. PendingMiddleReleased = false;
  147. }
  148. else
  149. {
  150. // Middle is pressed
  151. PendingMiddlePressed = false;
  152. LastMouseInteractionInterface.MouseMiddlePressed(CachedMouseWorldOrigin, CachedMouseWorldDirection, HitLocation, HitNormal);
  153. }
  154. }
  155. else if (PendingMiddleReleased)
  156. {
  157. PendingMiddleReleased = false;
  158. LastMouseInteractionInterface.MouseMiddleReleased(CachedMouseWorldOrigin, CachedMouseWorldDirection);
  159. }
  160.  
  161. // Handle middle mouse button scroll up
  162. if (PendingScrollUp)
  163. {
  164. PendingScrollUp = false;
  165. LastMouseInteractionInterface.MouseScrollUp(CachedMouseWorldOrigin, CachedMouseWorldDirection);
  166. }
  167.  
  168. // Handle middle mouse button scroll down
  169. if (PendingScrollDown)
  170. {
  171. PendingScrollDown = false;
  172. LastMouseInteractionInterface.MouseScrollDown(CachedMouseWorldOrigin, CachedMouseWorldDirection);
  173. }
  174. }
  175. }
  176.  
  177. function MouseInterfaceInteractionInterface GetMouseActor(optional out Vector HitLocation, optional out Vector HitNormal)
  178. {
  179. local MouseInterfaceInteractionInterface MouseInteractionInterface;
  180. local MouseInterfacePlayerInput MouseInterfacePlayerInput;
  181. local Vector2D MousePosition;
  182. local Actor HitActor;
  183.  
  184. // Ensure that we have a valid canvas and player owner
  185. if (Canvas == None || PlayerOwner == None)
  186. {
  187. return None;
  188. }
  189.  
  190. // Type cast to get the new player input
  191. MouseInterfacePlayerInput = MouseInterfacePlayerInput(PlayerOwner.PlayerInput);
  192.  
  193. // Ensure that the player input is valid
  194. if (MouseInterfacePlayerInput == None)
  195. {
  196. return None;
  197. }
  198.  
  199. // We stored the mouse position as an IntPoint, but it's needed as a Vector2D
  200. MousePosition.X = MouseInterfacePlayerInput.MousePosition.X;
  201. MousePosition.Y = MouseInterfacePlayerInput.MousePosition.Y;
  202. // Deproject the mouse position and store it in the cached vectors
  203. Canvas.DeProject(MousePosition, CachedMouseWorldOrigin, CachedMouseWorldDirection);
  204.  
  205. // Perform a trace actor interator. An interator is used so that we get the top most mouse interaction
  206. // interface. This covers cases when other traceable objects (such as static meshes) are above mouse
  207. // interaction interfaces.
  208. ForEach TraceActors(class'Actor', HitActor, HitLocation, HitNormal, CachedMouseWorldOrigin + CachedMouseWorldDirection * 65536.f, CachedMouseWorldOrigin,,, TRACEFLAG_Bullet)
  209. {
  210. // Type cast to see if the HitActor implements that mouse interaction interface
  211. MouseInteractionInterface = MouseInterfaceInteractionInterface(HitActor);
  212. if (MouseInteractionInterface != None)
  213. {
  214. return MouseInteractionInterface;
  215. }
  216. }
  217.  
  218. return None;
  219. }
  220.  
  221. function Vector GetMouseWorldLocation()
  222. {
  223. local MouseInterfacePlayerInput MouseInterfacePlayerInput;
  224. local Vector2D MousePosition;
  225. local Vector MouseWorldOrigin, MouseWorldDirection, HitLocation, HitNormal;
  226.  
  227. // Ensure that we have a valid canvas and player owner
  228. if (Canvas == None || PlayerOwner == None)
  229. {
  230. return Vect(0, 0, 0);
  231. }
  232.  
  233. // Type cast to get the new player input
  234. MouseInterfacePlayerInput = MouseInterfacePlayerInput(PlayerOwner.PlayerInput);
  235.  
  236. // Ensure that the player input is valid
  237. if (MouseInterfacePlayerInput == None)
  238. {
  239. return Vect(0, 0, 0);
  240. }
  241.  
  242. // We stored the mouse position as an IntPoint, but it's needed as a Vector2D
  243. MousePosition.X = MouseInterfacePlayerInput.MousePosition.X;
  244. MousePosition.Y = MouseInterfacePlayerInput.MousePosition.Y;
  245. // Deproject the mouse position and store it in the cached vectors
  246. Canvas.DeProject(MousePosition, MouseWorldOrigin, MouseWorldDirection);
  247.  
  248. // Perform a trace to get the actual mouse world location.
  249. Trace(HitLocation, HitNormal, MouseWorldOrigin + MouseWorldDirection * 65536.f, MouseWorldOrigin , true,,, TRACEFLAG_Bullet);
  250. return HitLocation;
  251. }
  252.  
  253. defaultproperties
  254. {
  255. CursorColor=(R=255,G=255,B=255,A=255)
  256. CursorTexture=Texture2D'EngineResources.Cursors.Arrow'
  257. }

Replies

  • Raptor-chan
    I got the MouseInterfaceInteractionInterface file fixed (had to remove the class line).I created my own HUD so I don't need any references to Scaleform or GFx. I've been removing those parts of the code and come up with this error:

    th_scaleform_error.png

    Is there a way to delete the reference to scaleform without hurting the rest of my files? Any help would be greatly appreciated. Thank you!
Sign In or Register to comment.