Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
playerpreview.c
Go to the documentation of this file.
2 {
3  protected ref PlayerPreviewWidget m_CharacterPanelWidget;
4 
5  protected int m_CharacterRotationX;
6  protected int m_CharacterRotationY;
7  protected int m_CharacterScaleDelta;
8  protected vector m_CharacterOrientation;
9  protected bool m_IsHolding;
10 
11  void PlayerPreview( LayoutHolder parent )
12  {
13  m_CharacterPanelWidget = PlayerPreviewWidget.Cast( m_Parent.GetMainWidget().FindAnyWidget( "CharacterPanelWidget" ) );
14 
15  WidgetEventHandler.GetInstance().RegisterOnMouseButtonDown( m_Parent.GetMainWidget().FindAnyWidget( "CharacterPanel" ), this, "MouseButtonDown" );
16  WidgetEventHandler.GetInstance().RegisterOnMouseWheel( m_Parent.GetMainWidget().FindAnyWidget( "CharacterPanel" ), this, "MouseWheel" );
17 
18  m_CharacterScaleDelta = 1;
19  m_CharacterPanelWidget.SetPlayer( GetGame().GetPlayer() );
20  m_CharacterPanelWidget.SetModelPosition( "0 0 0.605" );
21  m_CharacterPanelWidget.SetSize( 1.34, 1.34 ); // default scale
22  UpdateScale();
23  }
24 
25  void RefreshPlayerPreview()
26  {
27  m_CharacterPanelWidget.Refresh();
28  }
29 
30  void UpdateRotation( int mouse_x, int mouse_y, bool is_dragging )
31  {
32  if ( m_CharacterPanelWidget )
33  {
34  vector orientation = m_CharacterOrientation;
35  orientation[1] = orientation[1] - ( m_CharacterRotationX - mouse_x );
36 
37  m_CharacterPanelWidget.SetModelOrientation( orientation );
38 
39  if ( !is_dragging )
40  {
41  m_CharacterOrientation = orientation;
42  }
43  }
44  }
45 
46  void UpdateScale()
47  {
48  if ( m_CharacterPanelWidget )
49  {
50  float w, h;
51  m_CharacterPanelWidget.GetSize( w, h );
52  w = w + ( m_CharacterScaleDelta / 25 );
53  h = h + ( m_CharacterScaleDelta / 25 );
54  if ( w > 0.62 && w < 3 )
55  {
56  m_CharacterPanelWidget.SetSize( w, h );
57  }
58  else if ( w < 0.62 )
59  {
60  m_CharacterPanelWidget.SetSize( 0.62, 0.62 );
61  }
62  else if ( w > 3 )
63  {
64  m_CharacterPanelWidget.SetSize( 3, 3 );
65  }
66  }
67  }
68 
69  bool MouseButtonDown(Widget w, int x, int y, int button)
70  {
71  GetMousePos( m_CharacterRotationX, m_CharacterRotationY );
72  m_IsHolding = true;
73  return true;
74  }
75 
76  bool MouseWheel(Widget w, int x, int y, int wheel)
77  {
78  m_CharacterScaleDelta = wheel;
79  UpdateScale();
80  return true;
81  }
82 
83  override void UpdateInterval()
84  {
85  // item in hands update
86  m_CharacterPanelWidget.UpdateItemInHands(GetGame().GetPlayer().GetHumanInventory().GetEntityInHands());
87 
88  PlayerBase realPlayer = PlayerBase.Cast(GetGame().GetPlayer());
89  DayZPlayer dummyPlayer = m_CharacterPanelWidget.GetDummyPlayer();
90  if ( realPlayer && dummyPlayer )
91  {
92  // injury animation update
93  HumanCommandAdditives hca = dummyPlayer.GetCommandModifier_Additives();
94  //dummyPlayer.UpdateDummyPlayerProxyVisibility(realPlayer.FindAttachmentBySlotName("Shoulder"), realPlayer.FindAttachmentBySlotName("Melee"));
95  if ( hca && realPlayer.m_InjuryHandler )
96  hca.SetInjured(realPlayer.m_InjuryHandler.GetInjuryAnimValue(), realPlayer.m_InjuryHandler.IsInjuryAnimEnabled());
97  }
98 
99  if ( m_IsHolding )
100  {
101  int mouse_x;
102  int mouse_y;
103 
104  GetMousePos(mouse_x, mouse_y);
105 
106  if ( GetMouseState(MouseState.LEFT) & 0x80000000 )
107  {
108  UpdateRotation( mouse_x, mouse_y, true );
109  }
110  else
111  {
112  UpdateRotation( mouse_x, mouse_y, false );
113  m_IsHolding = false;
114  }
115  }
116  }
117 }
GetGame
proto native CGame GetGame()
PlayerPreview
Definition: playerpreview.c:1
LayoutHolder
Definition: container.c:1
HumanCommandAdditives
class HumanCommandWeapons HumanCommandAdditives()
Definition: human.c:1099
PlayerPreviewWidget
Definition: gameplay.c:299
GetMousePos
proto void GetMousePos(out int x, out int y)
y
Icon y
m_Parent
protected Widget m_Parent
Definition: sizetochild.c:92
DayZPlayer
Definition: dayzplayerimplement.c:72
PlayerBase
Definition: playerbaseclient.c:1
vector
Definition: enconvert.c:105
GetMouseState
proto native int GetMouseState(MouseState index)
MouseState
MouseState
Definition: ensystem.c:310
x
Icon x
GetPlayer
protected void GetPlayer()
Definition: crosshairselector.c:127
Widget
Definition: enwidgets.c:189
WidgetEventHandler
Definition: widgeteventhandler.c:1