class RipperdocBarTooltip extends AGenericTooltipController
{
	[ category = "Main" ]
	private editable var m_statsHolder : inkWidgetRef;
	[ category = "Main" ]
	private editable var m_perksHolder : inkWidgetRef;
	[ category = "Main" ]
	private editable var m_capacityDescription : inkWidgetRef;
	[ category = "Main" ]
	private editable var m_armorDescription : inkWidgetRef;
	[ category = "Main" ]
	private editable var m_armorReductionDescription : inkTextRef;
	[ category = "Title" ]
	private editable var m_titleHolder : inkWidgetRef;
	[ category = "Title" ]
	private editable var m_titleName : inkTextRef;
	[ category = "Title" ]
	private editable var m_titleTotalValue : inkTextRef;
	[ category = "Title" ]
	private editable var m_titleMaxValue : inkTextRef;
	[ category = "Stats" ]
	private editable var m_stats1 : inkWidgetRef;
	[ category = "Stats" ]
	private editable var m_stats1Name : inkTextRef;
	[ category = "Stats" ]
	private editable var m_stats1Value : inkTextRef;
	[ category = "Stats" ]
	private editable var m_stats2 : inkWidgetRef;
	[ category = "Stats" ]
	private editable var m_stats2Name : inkTextRef;
	[ category = "Stats" ]
	private editable var m_stats2Value : inkTextRef;
	[ category = "Stats" ]
	private editable var m_stats3 : inkWidgetRef;
	[ category = "Stats" ]
	private editable var m_stats3Name : inkTextRef;
	[ category = "Stats" ]
	private editable var m_stats3Value : inkTextRef;
	[ category = "Perks" ]
	private editable var m_perkTypeName : inkTextRef;
	[ category = "Perks" ]
	private editable var m_perk1 : inkWidgetRef;
	[ category = "Perks" ]
	private editable var m_perk1Icon : inkImageRef;
	[ category = "Perks" ]
	private editable var m_perk1Name : inkTextRef;
	[ category = "Perks" ]
	private editable var m_perk2 : inkWidgetRef;
	[ category = "Perks" ]
	private editable var m_perk2Icon : inkImageRef;
	[ category = "Perks" ]
	private editable var m_perk2Name : inkTextRef;
	[ category = "Perks" ]
	private editable var m_perkTreeInput : inkWidgetRef;
	[ category = "Perks" ]
	private editable var m_perkTreeIcon : inkImageRef;
	[ category = "Resources Capacity" ]
	private editable var m_capacityTitleNameLocKey : CName;
	[ category = "Resources Capacity" ]
	private editable var m_capacityStat1LocKey : CName;
	[ category = "Resources Capacity" ]
	private editable var m_capacityStat2LocKey : CName;
	[ category = "Resources Capacity" ]
	private editable var m_capacityStat3LocKey : CName;
	[ category = "Resources Capacity" ]
	private editable var m_capacityPerkTitleLocKey : CName;
	[ category = "Resources Capacity" ]
	private editable var m_capacityPerk1IconsName : CName;
	[ category = "Resources Capacity" ]
	private editable var m_capacityPerk1LocKey : CName;
	[ category = "Resources Capacity" ]
	private editable var m_capacityPerk2IconsName : CName;
	[ category = "Resources Capacity" ]
	private editable var m_capacityPerk2LocKey : CName;
	[ category = "Resources Armor" ]
	private editable var m_armorTitleNameLocKey : CName;
	[ category = "Resources Armor" ]
	private editable var m_armorStat1LocKey : CName;
	[ category = "Resources Armor" ]
	private editable var m_armorStat2LocKey : CName;
	[ category = "Resources Armor" ]
	private editable var m_armorStat3LocKey : CName;
	[ category = "Resources Armor" ]
	private editable var m_armorPerkTitleLocKey : CName;
	[ category = "Resources Armor" ]
	private editable var m_armorPerk1IconsName : CName;
	[ category = "Resources Armor" ]
	private editable var m_armorPerk1LocKey : CName;

	public override function SetData( tooltipData : ATooltipData )
	{
		var i : Int32;
		var val : Int32;
		var isCapacityOverallocated : Bool;
		var data : RipperdocBarTooltipTooltipData;
		data = ( ( RipperdocBarTooltipTooltipData )( tooltipData ) );
		isCapacityOverallocated = false;
		inkWidgetRef.SetVisible( m_capacityDescription, false );
		inkWidgetRef.SetVisible( m_armorDescription, false );
		inkTextRef.SetVisible( m_armorReductionDescription, false );
		if( data )
		{
			inkTextRef.SetText( m_titleTotalValue, IntToString( data.totalValue ) );
			inkTextRef.SetText( m_titleMaxValue, IntToString( data.maxValue ) );
			if( data.barType == BarType.CurrentCapacity )
			{
				inkTextRef.SetLocalizedText( m_titleName, m_capacityTitleNameLocKey );
				inkWidgetRef.SetVisible( m_capacityDescription, true );
				inkTextRef.SetLocalizedText( m_perkTypeName, m_capacityPerkTitleLocKey );
				if( data.capacityPerk1Bought )
				{
					for( i = 0; i < data.statsData.Size(); i += 1 )
					{
						if( data.statsData[ i ].type == gamedataStatType.HumanityAllocated )
						{
							inkTextRef.SetText( m_titleTotalValue, IntToString( data.statsData[ i ].value ) );
						}
						if( data.statsData[ i ].type == gamedataStatType.HumanityTotalMaxValue )
						{
							inkTextRef.SetText( m_titleMaxValue, IntToString( data.statsData[ i ].value ) );
						}
						if( data.statsData[ i ].type == gamedataStatType.HumanityOverallocated )
						{
							inkTextRef.SetLocalizedText( m_stats1Name, m_capacityStat1LocKey );
							inkTextRef.SetText( m_stats1Value, IntToString( data.statsData[ i ].value ) );
							isCapacityOverallocated = data.statsData[ i ].value > 0;
							inkTextRef.SetLocalizedText( m_stats3Name, m_capacityStat3LocKey );
							inkTextRef.SetText( m_stats3Value, FloatToStringPrec( data.statsData[ i ].valueF * 0.1, 1 ) + "%" );
						}
						if( data.statsData[ i ].type == gamedataStatType.EdgerunnerHealthReduction )
						{
							inkTextRef.SetLocalizedText( m_stats2Name, m_capacityStat2LocKey );
							if( FloatIsEqual( data.statsData[ i ].valueF, 0.0 ) )
							{
								inkTextRef.SetText( m_stats2Value, IntToString( 0 ) );
							}
							else
							{
								val = RoundMath( ( data.health / ( 1.0 - data.statsData[ i ].valueF ) ) * data.statsData[ i ].valueF );
								inkTextRef.SetText( m_stats2Value, "-" + IntToString( val ) );
							}
						}
					}
					inkWidgetRef.SetVisible( m_statsHolder, false );
				}
				else
				{
					inkWidgetRef.SetVisible( m_statsHolder, false );
				}
				( ( isCapacityOverallocated ) ? ( inkWidgetRef.SetState( m_titleHolder, 'Edgerunner' ) ) : ( inkWidgetRef.SetState( m_titleHolder, 'Default' ) ) );
				( ( isCapacityOverallocated ) ? ( inkWidgetRef.SetState( m_stats1, 'Edgerunner' ) ) : ( inkWidgetRef.SetState( m_stats1, 'Default' ) ) );
				( ( isCapacityOverallocated ) ? ( inkWidgetRef.SetState( m_stats2, 'Edgerunner' ) ) : ( inkWidgetRef.SetState( m_stats2, 'Default' ) ) );
				inkWidgetRef.SetVisible( m_perk1, true );
				inkTextRef.SetLocalizedText( m_perk1Name, m_capacityPerk1LocKey );
				inkImageRef.SetTexturePart( m_perk1Icon, m_capacityPerk1IconsName );
				( ( data.capacityPerk1Bought ) ? ( inkWidgetRef.SetState( m_perk1, 'Bought' ) ) : ( inkWidgetRef.SetState( m_perk1, 'Default' ) ) );
				inkWidgetRef.SetVisible( m_perk2, true );
				inkTextRef.SetLocalizedText( m_perk2Name, m_capacityPerk2LocKey );
				inkImageRef.SetTexturePart( m_perk2Icon, m_capacityPerk2IconsName );
				( ( data.capacityPerk2Bought ) ? ( inkWidgetRef.SetState( m_perk2, 'Bought' ) ) : ( inkWidgetRef.SetState( m_perk2, 'Default' ) ) );
			}
			else if( data.barType == BarType.Armor )
			{
				inkTextRef.SetLocalizedText( m_titleName, m_armorTitleNameLocKey );
				inkWidgetRef.SetState( m_titleHolder, 'Default' );
				inkWidgetRef.SetVisible( m_armorDescription, true );
				inkTextRef.SetLocalizedText( m_perkTypeName, m_armorPerkTitleLocKey );
				inkWidgetRef.SetVisible( m_statsHolder, false );
				ShowArmorReduction( data.maxDamageReduction );
				inkTextRef.SetLocalizedText( m_stats1Name, m_armorStat1LocKey );
				inkTextRef.SetText( m_stats1Value, IntToString( data.statValue ) );
				inkWidgetRef.SetState( m_stats1, 'Default' );
				for( i = 0; i < data.statsData.Size(); i += 1 )
				{
					if( data.statsData[ i ].type == gamedataStatType.Armor )
					{
						inkTextRef.SetText( m_titleTotalValue, IntToString( data.statsData[ i ].value ) );
					}
					if( data.statsData[ i ].type == gamedataStatType.MitigationChance )
					{
						inkTextRef.SetText( m_stats2Name, GetLocalizedText( data.statsData[ i ].statName ) );
						inkTextRef.SetText( m_stats2Value, FloatToStringPrec( data.statsData[ i ].valueF, 1 ) + "%" );
						inkWidgetRef.SetState( m_stats2, 'Default' );
					}
					if( data.statsData[ i ].type == gamedataStatType.MitigationStrength )
					{
						inkTextRef.SetText( m_stats3Name, GetLocalizedText( data.statsData[ i ].statName ) );
						inkTextRef.SetText( m_stats3Value, FloatToStringPrec( data.statsData[ i ].valueF, 0 ) + "%" );
					}
				}
				inkWidgetRef.SetVisible( m_perk1, true );
				inkTextRef.SetText( m_perk1Name, GetPerkNameLevel( m_armorPerk1IconsName, 2 ) );
				inkImageRef.SetTexturePart( m_perk1Icon, m_armorPerk1IconsName );
				( ( data.armorPerk1Bought ) ? ( inkWidgetRef.SetState( m_perk1, 'Bought' ) ) : ( inkWidgetRef.SetState( m_perk1, 'Default' ) ) );
				inkWidgetRef.SetVisible( m_perk2, false );
			}
			else if( data.barType == BarType.Edgerunner )
			{
				inkTextRef.SetLocalizedText( m_titleName, m_capacityPerk1LocKey );
				inkWidgetRef.SetVisible( m_capacityDescription, false );
				inkTextRef.SetLocalizedText( m_perkTypeName, m_capacityPerkTitleLocKey );
				if( data.capacityPerk1Bought )
				{
					for( i = 0; i < data.statsData.Size(); i += 1 )
					{
						if( data.statsData[ i ].type == gamedataStatType.HumanityAllocated )
						{
							inkTextRef.SetText( m_titleTotalValue, IntToString( data.statsData[ i ].value ) );
						}
						if( data.statsData[ i ].type == gamedataStatType.HumanityTotalMaxValue )
						{
							inkTextRef.SetText( m_titleMaxValue, IntToString( data.statsData[ i ].value ) );
						}
						if( data.statsData[ i ].type == gamedataStatType.HumanityOverallocated )
						{
							inkTextRef.SetLocalizedText( m_stats1Name, m_capacityStat1LocKey );
							inkTextRef.SetText( m_stats1Value, IntToString( data.statsData[ i ].value ) );
							isCapacityOverallocated = data.statsData[ i ].value > 0;
							inkTextRef.SetLocalizedText( m_stats3Name, m_capacityStat3LocKey );
							inkTextRef.SetText( m_stats3Value, FloatToStringPrec( data.statsData[ i ].valueF * 0.1, 1 ) + "%" );
						}
						if( data.statsData[ i ].type == gamedataStatType.EdgerunnerHealthReduction )
						{
							inkTextRef.SetLocalizedText( m_stats2Name, m_capacityStat2LocKey );
							if( FloatIsEqual( data.statsData[ i ].valueF, 0.0 ) )
							{
								inkTextRef.SetText( m_stats2Value, IntToString( 0 ) );
							}
							else
							{
								val = RoundMath( ( data.health / ( 1.0 - data.statsData[ i ].valueF ) ) * data.statsData[ i ].valueF );
								inkTextRef.SetText( m_stats2Value, "-" + IntToString( val ) );
							}
						}
					}
					inkWidgetRef.SetVisible( m_statsHolder, isCapacityOverallocated );
				}
				else
				{
					inkWidgetRef.SetVisible( m_statsHolder, false );
				}
				( ( isCapacityOverallocated ) ? ( inkWidgetRef.SetState( m_titleHolder, 'Edgerunner' ) ) : ( inkWidgetRef.SetState( m_titleHolder, 'Default' ) ) );
				( ( isCapacityOverallocated ) ? ( inkWidgetRef.SetState( m_stats1, 'Edgerunner' ) ) : ( inkWidgetRef.SetState( m_stats1, 'Default' ) ) );
				( ( isCapacityOverallocated ) ? ( inkWidgetRef.SetState( m_stats2, 'Edgerunner' ) ) : ( inkWidgetRef.SetState( m_stats2, 'Default' ) ) );
				inkWidgetRef.SetVisible( m_perk1, true );
				inkTextRef.SetLocalizedText( m_perk1Name, m_capacityPerk1LocKey );
				inkImageRef.SetTexturePart( m_perk1Icon, m_capacityPerk1IconsName );
				( ( data.capacityPerk1Bought ) ? ( inkWidgetRef.SetState( m_perk1, 'Bought' ) ) : ( inkWidgetRef.SetState( m_perk1, 'Default' ) ) );
				inkWidgetRef.SetVisible( m_perk2, true );
				inkTextRef.SetLocalizedText( m_perk2Name, m_capacityPerk2LocKey );
				inkImageRef.SetTexturePart( m_perk2Icon, m_capacityPerk2IconsName );
				( ( data.capacityPerk2Bought ) ? ( inkWidgetRef.SetState( m_perk2, 'Bought' ) ) : ( inkWidgetRef.SetState( m_perk2, 'Default' ) ) );
			}
		}
	}

	private function ShowArmorReduction( damageReduction : Float )
	{
		var parameters : inkTextParams;
		parameters = new inkTextParams;
		parameters.AddNumber( "float_0", damageReduction );
		inkTextRef.SetLocalizedTextScript( m_armorReductionDescription, "LocKey#93545", parameters );
		inkTextRef.SetVisible( m_armorReductionDescription, true );
	}

	private function GetPerkNameLevel( name : CName, level : Int32 ) : String
	{
		var text : String;
		text = GetLocalizedItemNameByCName( m_armorPerk1LocKey );
		text += " (";
		text += GetLocalizedItemNameByCName( 'Gameplay-RPG-Skills-LevelName' );
		text += " ";
		text += IntToString( level );
		text += ")";
		return text;
	}

}

class RipperdocBarTooltipTooltipData extends ATooltipData
{
	var barType : BarType;
	var totalValue : Int32;
	var maxValue : Int32;
	var maxDamageReduction : Float;
	var capacityPerk1Bought : Bool;
	var capacityPerk2Bought : Bool;
	var armorPerk1Bought : Bool;
	var statsData : array< StatViewData >;
	var statValue : Int32;
	var health : Float;
}

enum BarType
{
	Armor = 0,
	CurrentCapacity = 1,
	Edgerunner = 2,
}

