playerpreview.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. class PlayerPreview: LayoutHolder
  2. {
  3. protected ref PlayerPreviewWidget m_CharacterPanelWidget;
  4. protected int m_CharacterRotationX;
  5. protected int m_CharacterRotationY;
  6. protected int m_CharacterScaleDelta;
  7. protected vector m_CharacterOrientation;
  8. protected bool m_IsHolding;
  9. void PlayerPreview( LayoutHolder parent )
  10. {
  11. m_CharacterPanelWidget = PlayerPreviewWidget.Cast( m_Parent.GetMainWidget().FindAnyWidget( "CharacterPanelWidget" ) );
  12. WidgetEventHandler.GetInstance().RegisterOnMouseButtonDown( m_Parent.GetMainWidget().FindAnyWidget( "CharacterPanel" ), this, "MouseButtonDown" );
  13. WidgetEventHandler.GetInstance().RegisterOnMouseWheel( m_Parent.GetMainWidget().FindAnyWidget( "CharacterPanel" ), this, "MouseWheel" );
  14. m_CharacterScaleDelta = 1;
  15. m_CharacterPanelWidget.SetPlayer( GetGame().GetPlayer() );
  16. m_CharacterPanelWidget.SetModelPosition( "0 0 0.605" );
  17. m_CharacterPanelWidget.SetSize( 1.34, 1.34 ); // default scale
  18. UpdateScale();
  19. }
  20. void RefreshPlayerPreview()
  21. {
  22. m_CharacterPanelWidget.Refresh();
  23. }
  24. void UpdateRotation( int mouse_x, int mouse_y, bool is_dragging )
  25. {
  26. if ( m_CharacterPanelWidget )
  27. {
  28. vector orientation = m_CharacterOrientation;
  29. orientation[1] = orientation[1] - ( m_CharacterRotationX - mouse_x );
  30. m_CharacterPanelWidget.SetModelOrientation( orientation );
  31. if ( !is_dragging )
  32. {
  33. m_CharacterOrientation = orientation;
  34. }
  35. }
  36. }
  37. void UpdateScale()
  38. {
  39. if ( m_CharacterPanelWidget )
  40. {
  41. float w, h;
  42. m_CharacterPanelWidget.GetSize( w, h );
  43. w = w + ( m_CharacterScaleDelta / 25 );
  44. h = h + ( m_CharacterScaleDelta / 25 );
  45. if ( w > 0.62 && w < 3 )
  46. {
  47. m_CharacterPanelWidget.SetSize( w, h );
  48. }
  49. else if ( w < 0.62 )
  50. {
  51. m_CharacterPanelWidget.SetSize( 0.62, 0.62 );
  52. }
  53. else if ( w > 3 )
  54. {
  55. m_CharacterPanelWidget.SetSize( 3, 3 );
  56. }
  57. }
  58. }
  59. bool MouseButtonDown(Widget w, int x, int y, int button)
  60. {
  61. GetMousePos( m_CharacterRotationX, m_CharacterRotationY );
  62. m_IsHolding = true;
  63. return true;
  64. }
  65. bool MouseWheel(Widget w, int x, int y, int wheel)
  66. {
  67. m_CharacterScaleDelta = wheel;
  68. UpdateScale();
  69. return true;
  70. }
  71. override void UpdateInterval()
  72. {
  73. // item in hands update
  74. m_CharacterPanelWidget.UpdateItemInHands(GetGame().GetPlayer().GetHumanInventory().GetEntityInHands());
  75. PlayerBase realPlayer = PlayerBase.Cast(GetGame().GetPlayer());
  76. DayZPlayer dummyPlayer = m_CharacterPanelWidget.GetDummyPlayer();
  77. if ( realPlayer && dummyPlayer )
  78. {
  79. // injury animation update
  80. HumanCommandAdditives hca = dummyPlayer.GetCommandModifier_Additives();
  81. //dummyPlayer.UpdateDummyPlayerProxyVisibility(realPlayer.FindAttachmentBySlotName("Shoulder"), realPlayer.FindAttachmentBySlotName("Melee"));
  82. if ( hca && realPlayer.m_InjuryHandler )
  83. hca.SetInjured(realPlayer.m_InjuryHandler.GetInjuryAnimValue(), realPlayer.m_InjuryHandler.IsInjuryAnimEnabled());
  84. }
  85. if ( m_IsHolding )
  86. {
  87. int mouse_x;
  88. int mouse_y;
  89. GetMousePos(mouse_x, mouse_y);
  90. if ( GetMouseState(MouseState.LEFT) & 0x80000000 )
  91. {
  92. UpdateRotation( mouse_x, mouse_y, true );
  93. }
  94. else
  95. {
  96. UpdateRotation( mouse_x, mouse_y, false );
  97. m_IsHolding = false;
  98. }
  99. }
  100. }
  101. }