class PerksMenuAttributeDisplayController extends BaseButtonView
{
	protected editable var m_widgetWrapper : inkWidgetRef;
	protected editable var m_foregroundWrapper : inkWidgetRef;
	protected editable var m_attributeName : inkTextRef;
	protected editable var m_attributeIcon : inkImageRef;
	protected editable var m_attributeLevel : inkTextRef;
	protected editable var m_frameHovered : inkWidgetRef;
	protected editable var m_accent1Hovered : inkWidgetRef;
	protected editable var m_accent1BGHovered : inkWidgetRef;
	protected editable var m_accent2Hovered : inkWidgetRef;
	protected editable var m_accent2BGHovered : inkWidgetRef;
	protected editable var m_topConnectionContainer : inkWidgetRef;
	protected editable var m_bottomConnectionContainer : inkWidgetRef;
	protected editable var m_levelContainer : inkWidgetRef;
	protected var m_dataManager : PlayerDevelopmentDataManager;
	protected var m_attribute : PerkMenuAttribute;
	protected var m_attributeData : AttributeData;

	protected event OnInitialize()
	{
		ResetHoverOpacity();
		super.OnInitialize();
	}

	public function Setup( attribute : PerkMenuAttribute, dataManager : PlayerDevelopmentDataManager )
	{
		m_dataManager = dataManager;
		m_attribute = attribute;
		m_attributeData = dataManager.GetAttribute( m_dataManager.GetAttributeRecordIDFromEnum( attribute ) );
		inkWidgetRef.SetVisible( m_levelContainer, attribute != PerkMenuAttribute.Espionage );
		GetRootWidget().SetState( ( ( attribute != PerkMenuAttribute.Espionage ) ? ( 'Default' ) : ( 'Espionage' ) ) );
		ResetHoverOpacity();
		Update();
	}

	public function UpdateData( attributeData : AttributeData )
	{
		m_attributeData = attributeData;
		Update();
	}

	public function GetStatType() : gamedataStatType
	{
		return m_attributeData.type;
	}

	public function SetHovered( value : Bool )
	{
		PlayHoverAnimation( value );
		inkWidgetRef.SetState( m_widgetWrapper, ( ( value ) ? ( 'Hovered' ) : ( 'Default' ) ) );
		if( m_attribute == PerkMenuAttribute.Johnny )
		{
			inkWidgetRef.Get( m_widgetWrapper ).SetEffectEnabled( inkEffectType.Glitch, 'Glitch_0', value );
		}
	}

	public function GetAttributeData() : AttributeData
	{
		return m_attributeData;
	}

	protected function Update()
	{
		UpdateConnections();
		if( m_attribute == PerkMenuAttribute.Johnny )
		{
			return;
		}
		UpdateIcon();
		UpdateName();
		UpdateLevel();
	}

	protected function UpdateIcon()
	{
		var relicIcon : ResRef;
		var attributeIcon : ResRef;
		relicIcon = R"base\gameplay\gui\fullscreen\perks\atlas_perks.inkatlas";
		attributeIcon = R"base\gameplay\gui\common\icons\attributes_icons.inkatlas";
		if( m_attribute == PerkMenuAttribute.Espionage )
		{
			inkImageRef.SetAtlasResource( m_attributeIcon, relicIcon );
			inkImageRef.SetTexturePart( m_attributeIcon, 'ico_atrib_relic' );
		}
		else
		{
			inkImageRef.SetAtlasResource( m_attributeIcon, attributeIcon );
			inkImageRef.SetTexturePart( m_attributeIcon, PerkAttributeHelper.GetIconAtlasPart( m_attribute ) );
		}
	}

	protected function UpdateName()
	{
		inkTextRef.SetText( m_attributeName, m_attributeData.label );
	}

	protected function UpdateLevel()
	{
		inkTextRef.SetText( m_attributeLevel, IntToString( m_attributeData.value ) );
	}

	protected function UpdateConnections()
	{
		inkWidgetRef.SetState( m_topConnectionContainer, PerkAttributeHelper.GetTopConnectionState( m_attribute ) );
		inkWidgetRef.SetState( m_bottomConnectionContainer, PerkAttributeHelper.GetBottomConnectionState( m_attribute ) );
	}

	protected function PlayHoverAnimation( value : Bool )
	{
		var transparencyAnimation : inkAnimDef;
		var transparencyInterpolator : inkAnimTransparency;
		var transparencyAnimation2 : inkAnimDef;
		var transparencyInterpolator2 : inkAnimTransparency;
		transparencyAnimation = new inkAnimDef;
		transparencyAnimation2 = new inkAnimDef;
		transparencyInterpolator = new inkAnimTransparency;
		transparencyInterpolator.SetDuration( 0.34999999 );
		transparencyInterpolator.SetDirection( inkanimInterpolationDirection.To );
		transparencyInterpolator.SetType( inkanimInterpolationType.Linear );
		transparencyInterpolator.SetMode( inkanimInterpolationMode.EasyIn );
		transparencyInterpolator.SetEndTransparency( ( ( value ) ? ( 1.0 ) : ( 0.002 ) ) );
		transparencyInterpolator2 = new inkAnimTransparency;
		transparencyInterpolator2.SetDuration( 0.34999999 );
		transparencyInterpolator2.SetDirection( inkanimInterpolationDirection.To );
		transparencyInterpolator2.SetType( inkanimInterpolationType.Linear );
		transparencyInterpolator2.SetMode( inkanimInterpolationMode.EasyIn );
		transparencyInterpolator2.SetEndTransparency( ( ( value ) ? ( 0.133 ) : ( 0.002 ) ) );
		transparencyAnimation.AddInterpolator( transparencyInterpolator );
		transparencyAnimation2.AddInterpolator( transparencyInterpolator2 );
		inkWidgetRef.PlayAnimation( m_frameHovered, transparencyAnimation );
		inkWidgetRef.PlayAnimation( m_accent1Hovered, transparencyAnimation );
		inkWidgetRef.PlayAnimation( m_accent2Hovered, transparencyAnimation );
		inkWidgetRef.PlayAnimation( m_accent1BGHovered, transparencyAnimation2 );
		inkWidgetRef.PlayAnimation( m_accent2BGHovered, transparencyAnimation2 );
	}

	public function PlayAnimation( animation : CName ) : inkAnimProxy
	{
		return PlayLibraryAnimation( animation );
	}

	private function ResetHoverOpacity()
	{
		inkWidgetRef.SetOpacity( m_frameHovered, 0.0 );
		inkWidgetRef.SetOpacity( m_accent1Hovered, 0.0 );
		inkWidgetRef.SetOpacity( m_accent2Hovered, 0.0 );
		inkWidgetRef.SetOpacity( m_accent1BGHovered, 0.0 );
		inkWidgetRef.SetOpacity( m_accent2BGHovered, 0.0 );
	}

}

struct PerkAttributeHelper
{

	public static function GetTopConnectionState( attribute : PerkMenuAttribute ) : CName
	{
		switch( attribute )
		{
			case PerkMenuAttribute.Body:
			case PerkMenuAttribute.Reflex:
			case PerkMenuAttribute.Technical_Ability:
				return 'Text';
			case PerkMenuAttribute.Cool:
			case PerkMenuAttribute.Intelligence:
			case PerkMenuAttribute.Johnny:
				return 'Image';
		}
		return 'Default';
	}

	public static function GetBottomConnectionState( attribute : PerkMenuAttribute ) : CName
	{
		switch( attribute )
		{
			case PerkMenuAttribute.Body:
			case PerkMenuAttribute.Reflex:
			case PerkMenuAttribute.Technical_Ability:
				return 'Image';
			case PerkMenuAttribute.Cool:
			case PerkMenuAttribute.Intelligence:
			case PerkMenuAttribute.Johnny:
				return 'Text';
		}
		return 'Default';
	}

	public static function GetName( attribute : PerkMenuAttribute ) : String
	{
		switch( attribute )
		{
			case PerkMenuAttribute.Body:
				return "Body";
			case PerkMenuAttribute.Reflex:
				return "Reflex";
			case PerkMenuAttribute.Technical_Ability:
				return "Technical Ability";
			case PerkMenuAttribute.Cool:
				return "Cool";
			case PerkMenuAttribute.Intelligence:
				return "Intelligence";
			case PerkMenuAttribute.Espionage:
				return "Espionage";
		}
		return "";
	}

	public static function GetIconAtlasPart( attribute : PerkMenuAttribute ) : CName
	{
		switch( attribute )
		{
			case PerkMenuAttribute.Body:
				return 'ico_body';
			case PerkMenuAttribute.Reflex:
				return 'ico_ref';
			case PerkMenuAttribute.Technical_Ability:
				return 'ico_tech';
			case PerkMenuAttribute.Cool:
				return 'ico_cool';
			case PerkMenuAttribute.Intelligence:
				return 'ico_int';
			case PerkMenuAttribute.Espionage:
				return 'ico_ep1_tree';
		}
		return 'undiscovered';
	}

	public static function GetShortNameLocKey( attribute : PerkMenuAttribute ) : String
	{
		switch( attribute )
		{
			case PerkMenuAttribute.Body:
				return "LocKey#43676";
			case PerkMenuAttribute.Reflex:
				return "LocKey#43679";
			case PerkMenuAttribute.Technical_Ability:
				return "LocKey#43680";
			case PerkMenuAttribute.Cool:
				return "LocKey#43677";
			case PerkMenuAttribute.Intelligence:
				return "LocKey#43678";
		}
		return "";
	}

	public static function BaseStatToAttribute( statType : gamedataStatType ) : TweakDBID
	{
		switch( statType )
		{
			case gamedataStatType.Strength:
				return T"NewPerks.BodyAttributeData";
			case gamedataStatType.Reflexes:
				return T"NewPerks.ReflexesAttributeData";
			case gamedataStatType.Intelligence:
				return T"NewPerks.IntelligenceAttributeData";
			case gamedataStatType.TechnicalAbility:
				return T"NewPerks.TechnicalAbilityAttributeData";
			case gamedataStatType.Cool:
				return T"NewPerks.CoolAttributeData";
			case gamedataStatType.Espionage:
				return T"NewPerks.EspionageAttributeData";
		}
		return TDBID.None();
	}

	public static function BaseStatToPerkMenuAttribute( statType : gamedataStatType ) : PerkMenuAttribute
	{
		switch( statType )
		{
			case gamedataStatType.Strength:
				return PerkMenuAttribute.Body;
			case gamedataStatType.Reflexes:
				return PerkMenuAttribute.Reflex;
			case gamedataStatType.Intelligence:
				return PerkMenuAttribute.Intelligence;
			case gamedataStatType.TechnicalAbility:
				return PerkMenuAttribute.Technical_Ability;
			case gamedataStatType.Cool:
				return PerkMenuAttribute.Cool;
			case gamedataStatType.Espionage:
				return PerkMenuAttribute.Espionage;
		}
		return PerkMenuAttribute.Invalid;
	}

	public static function PerkMenuAttributeToStat( perkMenuAttribute : PerkMenuAttribute ) : gamedataStatType
	{
		switch( perkMenuAttribute )
		{
			case PerkMenuAttribute.Body:
				return gamedataStatType.Strength;
			case PerkMenuAttribute.Reflex:
				return gamedataStatType.Reflexes;
			case PerkMenuAttribute.Intelligence:
				return gamedataStatType.Intelligence;
			case PerkMenuAttribute.Technical_Ability:
				return gamedataStatType.TechnicalAbility;
			case PerkMenuAttribute.Cool:
				return gamedataStatType.Cool;
			case PerkMenuAttribute.Espionage:
				return gamedataStatType.Espionage;
		}
		return gamedataStatType.Invalid;
	}

	public static function PerkMenuAttributeToAttributeDataType( perkMenuAttribute : PerkMenuAttribute ) : gamedataAttributeDataType
	{
		switch( perkMenuAttribute )
		{
			case PerkMenuAttribute.Body:
				return gamedataAttributeDataType.BodyAttributeData;
			case PerkMenuAttribute.Reflex:
				return gamedataAttributeDataType.ReflexesAttributeData;
			case PerkMenuAttribute.Intelligence:
				return gamedataAttributeDataType.IntelligenceAttributeData;
			case PerkMenuAttribute.Technical_Ability:
				return gamedataAttributeDataType.TechnicalAbilityAttributeData;
			case PerkMenuAttribute.Cool:
				return gamedataAttributeDataType.CoolAttributeData;
			case PerkMenuAttribute.Espionage:
				return gamedataAttributeDataType.EspionageAttributeData;
		}
		return gamedataAttributeDataType.Invalid;
	}

}

