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