projectedcrosshair.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. class ProjectedCrosshair extends ScriptedWidgetEventHandler
  2. {
  3. protected Widget m_Root;
  4. protected vector m_Position;
  5. protected bool m_Visible;
  6. protected bool m_Debug;
  7. protected PlayerBase m_Player;
  8. protected Weapon_Base m_Weapon;
  9. void ProjectedCrosshair()
  10. {
  11. m_Player = NULL;
  12. m_Weapon = NULL;
  13. m_Visible = false;
  14. m_Debug = false;
  15. GetGame().GetUpdateQueue(CALL_CATEGORY_GUI).Insert(this.Update);
  16. }
  17. void ~ProjectedCrosshair()
  18. {
  19. GetGame().GetUpdateQueue(CALL_CATEGORY_GUI).Remove(this.Update);
  20. }
  21. void OnWidgetScriptInit(Widget w)
  22. {
  23. m_Root = w;
  24. m_Root.SetHandler(this);
  25. m_Root.Update();
  26. }
  27. //! Update
  28. protected void Update()
  29. {
  30. #ifdef DIAG_DEVELOPER
  31. m_Debug = DiagMenu.GetBool( DiagMenuIDs.WEAPON_DEBUG );
  32. #endif
  33. if (!m_Debug) return;
  34. if (!m_Player) GetPlayer();
  35. if ( m_Player && m_Player.IsPlayerSelected() && m_Player.IsRaised() && !m_Player.IsInIronsights() && !GetGame().IsInventoryOpen() )
  36. {
  37. float sx, sy;
  38. GetCrosshairPosition();
  39. vector screenSpace = GetGame().GetScreenPos(m_Position);
  40. m_Root.GetSize(sx, sy);
  41. screenSpace[0] = screenSpace[0] - sx/2;
  42. screenSpace[1] = screenSpace[1] - sy/2;
  43. m_Root.SetPos(screenSpace[0], screenSpace[1]);
  44. m_Root.Show(m_Visible);
  45. }
  46. else
  47. {
  48. m_Root.Show(false);
  49. m_Position = vector.Zero;
  50. }
  51. }
  52. // getters
  53. protected void GetPlayer()
  54. {
  55. Class.CastTo(m_Player, GetGame().GetPlayer());
  56. }
  57. protected void GetCrosshairPosition()
  58. {
  59. m_Visible = false;
  60. ItemBase itemInHands;
  61. itemInHands = m_Player.GetItemInHands();
  62. if ( itemInHands && itemInHands.IsWeapon() )
  63. {
  64. if( Class.CastTo(m_Weapon, itemInHands) )
  65. {
  66. //m_Visible = MiscGameplayFunctions.GetProjectedCursorPos3d(m_Position, m_Weapon);
  67. }
  68. }
  69. }
  70. };