class GameplayMappinController extends QuestMappinController
{
	private var anim : inkAnimProxy;
	private var m_isVisibleThroughWalls : Bool;

	protected event OnUpdate()
	{
		super.OnUpdate();
		SetClampVisibility();
	}

	protected override function UpdateTrackedState()
	{
		var isTagged : Bool;
		var i : Int32;
		isTagged = IsTagged();
		if( isTagged && m_runtimeMappin )
		{
			isTagged = !( m_runtimeMappin.GetOwnerObjectMarkerPossibility() );
		}
		for( i = 0; i < m_taggedWidgets.Size(); i += 1 )
		{
			inkWidgetRef.SetVisible( m_taggedWidgets[ i ], isTagged );
		}
	}

	private override function UpdateVisibility()
	{
		if( m_mappin )
		{
			SetRootVisible( m_mappin.IsVisible() );
		}
	}

	private function GetTexturePartForGameplayRole( gameplayRole : EGameplayRole ) : CName
	{
		switch( gameplayRole )
		{
			case EGameplayRole.Alarm:
				return 'trigger_alarm1';
			case EGameplayRole.ControlNetwork:
				return 'control_network_device1';
			case EGameplayRole.ControlOtherDevice:
				return 'control_network_device2';
			case EGameplayRole.ControlSelf:
				return 'control_network_device3';
			case EGameplayRole.CutPower:
				return 'cut_power1';
			case EGameplayRole.Distract:
				return 'distract_enemy3';
			case EGameplayRole.DropPoint:
				return 'drop_point1';
			case EGameplayRole.ExplodeLethal:
				return 'explosive_lethal1';
			case EGameplayRole.ExplodeNoneLethal:
				return 'explosive_non-lethal1';
			case EGameplayRole.Fall:
				return 'fall2';
			case EGameplayRole.GrantInformation:
				return 'grants_information1';
			case EGameplayRole.Clue:
				return 'clue';
			case EGameplayRole.HideBody:
				return 'dispose_body1';
			case EGameplayRole.Loot:
				return 'loot1';
			case EGameplayRole.OpenPath:
				return 'open_path1';
			case EGameplayRole.ClearPath:
				return 'movable1';
			case EGameplayRole.ServicePoint:
				return 'use_servicepoint1';
			case EGameplayRole.Shoot:
				return 'shoots2';
			case EGameplayRole.SpreadGas:
				return 'gas_spread1';
			case EGameplayRole.StoreItems:
				return 'storage1';
			case EGameplayRole.GenericRole:
				return 'distract_enemy3';
		}
		return '';
	}

	private function GetTexturePartForDeviceEffect( mappinVariant : gamedataMappinVariant, braindanceLayer : braindanceVisionMode ) : CName
	{
		switch( mappinVariant )
		{
			case gamedataMappinVariant.EffectAlarmVariant:
				return 'main_quest';
			case gamedataMappinVariant.EffectControlNetworkVariant:
				return 'hack1';
			case gamedataMappinVariant.EffectControlOtherDeviceVariant:
				return 'control_network_device3';
			case gamedataMappinVariant.EffectControlSelfVariant:
				return 'control_network_device3';
			case gamedataMappinVariant.EffectCutPowerVariant:
				return 'cut_power1';
			case gamedataMappinVariant.EffectDistractVariant:
				return 'distract_enemy3';
			case gamedataMappinVariant.EffectDropPointVariant:
				return 'drop_point1';
			case gamedataMappinVariant.EffectExplodeLethalVariant:
				return 'explosive_lethal1';
			case gamedataMappinVariant.EffectExplodeNonLethalVariant:
				return 'explosive_non-lethal1';
			case gamedataMappinVariant.EffectFallVariant:
				return 'fall2';
			case gamedataMappinVariant.EffectGrantInformationVariant:
				return 'grants_information1';
			case gamedataMappinVariant.EffectHideBodyVariant:
				return 'dispose_body1';
			case gamedataMappinVariant.EffectLootVariant:
				return 'loot1';
			case gamedataMappinVariant.EffectOpenPathVariant:
				return 'open_path1';
			case gamedataMappinVariant.EffectPushVariant:
				return 'movable1';
			case gamedataMappinVariant.EffectServicePointVariant:
				return 'use_servicepoint1';
			case gamedataMappinVariant.EffectShootVariant:
				return 'shoots2';
			case gamedataMappinVariant.EffectSpreadGasVariant:
				return 'gas_spread1';
			case gamedataMappinVariant.EffectStoreItemsVariant:
				return 'storage1';
			case gamedataMappinVariant.NetrunnerVariant:
				return 'hack1';
			case gamedataMappinVariant.SoloVariant:
				return 'solo1';
			case gamedataMappinVariant.TechieVariant:
				return 'techie1';
			case gamedataMappinVariant.NetrunnerSoloTechieVariant:
				return 'netrunner_solo_techie_variant1';
			case gamedataMappinVariant.NetrunnerSoloVariant:
				return 'netrunner_solo_variant1';
			case gamedataMappinVariant.NetrunnerTechieVariant:
				return 'netrunner_techie_variant1';
			case gamedataMappinVariant.SoloTechieVariant:
				return 'solo_techie_variant1';
			case gamedataMappinVariant.ImportantInteractionVariant:
				return 'skillcheck_device';
			case gamedataMappinVariant.NetrunnerSoloTechieVariant:
				return 'netrunner_solo_techie_variant1';
			case gamedataMappinVariant.NetrunnerSoloVariant:
				return 'netrunner_solo_variant1';
			case gamedataMappinVariant.NetrunnerTechieVariant:
				return 'netrunner_techie_variant1';
			case gamedataMappinVariant.SoloTechieVariant:
				return 'solo_techie_variant1';
			case gamedataMappinVariant.FastTravelVariant:
				return 'fast_travel';
			case gamedataMappinVariant.GenericRoleVariant:
				return 'interaction';
			case gamedataMappinVariant.NPCVariant:
				return 'distract_enemy4';
			case gamedataMappinVariant.LootVariant:
				return 'loot1';
			case gamedataMappinVariant.FocusClueVariant:
			{
				switch( braindanceLayer )
				{
					case braindanceVisionMode.Default:
						return 'clue';
					case braindanceVisionMode.Audio:
						return 'clue_audio';
					case braindanceVisionMode.Thermal:
						return 'clue_thermal';
				}
			}
			case gamedataMappinVariant.ImportantInteractionVariant:
				return 'interaction';
			case gamedataMappinVariant.NetrunnerSoloTechieVariant:
				return 'hack1';
			case gamedataMappinVariant.NetrunnerSoloVariant:
				return 'hack1';
			case gamedataMappinVariant.NetrunnerTechieVariant:
				return 'hack1';
			case gamedataMappinVariant.SoloTechieVariant:
				return 'solo1';
		}
		return '';
	}

	private override function ComputeRootState() : CName
	{
		var visualState : EMappinVisualState;
		var returnValue : CName;
		var quality : gamedataQuality;
		visualState = GetMappinVisualState();
		quality = GetQuality();
		if( IsShardRead() )
		{
			returnValue = 'ShardRead';
		}
		else if( IsQuest() )
		{
			returnValue = 'Quest';
		}
		else if( quality != gamedataQuality.Invalid && quality != gamedataQuality.Random )
		{
			if( IsIconic() )
			{
				returnValue = 'Iconic';
			}
			else
			{
				switch( quality )
				{
					case gamedataQuality.Common:
						returnValue = 'Common';
					break;
					case gamedataQuality.Epic:
						returnValue = 'Epic';
					break;
					case gamedataQuality.Legendary:
						returnValue = 'Legendary';
					break;
					case gamedataQuality.Rare:
						returnValue = 'Rare';
					break;
					case gamedataQuality.Uncommon:
						returnValue = 'Uncommon';
					break;
					case gamedataQuality.Iconic:
						returnValue = 'Iconic';
					break;
					default:
						returnValue = 'Default';
					break;
				}
			}
		}
		else
		{
			switch( visualState )
			{
				case EMappinVisualState.Inactive:
					returnValue = 'Inactive';
				break;
				case EMappinVisualState.Available:
					returnValue = 'Available';
				break;
				case EMappinVisualState.Unavailable:
					returnValue = 'Unavailable';
				break;
				case EMappinVisualState.Default:
					returnValue = 'Default';
				break;
			}
		}
		if( ShouldBeClamped() )
		{
			returnValue = 'Distraction';
		}
		UpdateVisibilityThroughWalls();
		return returnValue;
	}

	private function UpdateVisibilityThroughWalls()
	{
		var data : GameplayRoleMappinData;
		data = GetVisualData();
		if( data == NULL )
		{
			return;
		}
		if( data.m_visibleThroughWalls != m_isVisibleThroughWalls )
		{
			m_runtimeMappin.EnableVisibilityThroughWalls( data.m_visibleThroughWalls );
		}
		m_isVisibleThroughWalls = data.m_visibleThroughWalls;
	}

	private override function UpdateIcon()
	{
		var iconName : CName;
		var iconID : TweakDBID;
		var roleMappinData : GameplayRoleMappinData;
		if( m_mappin )
		{
			roleMappinData = ( ( GameplayRoleMappinData )( m_mappin.GetScriptData() ) );
		}
		if( roleMappinData && roleMappinData.m_isScanningCluesBlocked )
		{
			iconID = T"MappinIcons.ClueLaterMappin";
		}
		else if( roleMappinData )
		{
			iconID = roleMappinData.m_textureID;
		}
		if( !( TDBID.IsValid( iconID ) ) && m_mappin )
		{
			iconName = GetTexturePartForDeviceEffect( m_mappin.GetVariant(), roleMappinData.m_braindanceLayer );
			inkImageRef.SetTexturePart( iconWidget, iconName );
		}
		else
		{
			SetTexture( iconWidget, iconID );
		}
		if( ( IsNameValid( iconName ) || ( m_mappin && m_mappin.GetVariant() == gamedataMappinVariant.Invalid ) ) || TDBID.IsValid( iconID ) )
		{
			inkWidgetRef.SetVisible( m_scanningDiamond, false );
		}
		else
		{
			inkWidgetRef.SetVisible( m_scanningDiamond, true );
		}
		if( ShouldBeClamped() )
		{
			inkImageRef.SetVisible( iconWidget, false );
		}
		if( IsBroken() )
		{
			inkImageRef.SetVisible( iconWidget, false );
		}
	}

	private function GetGameplayRole() : EGameplayRole
	{
		return GetVisualData().m_gameplayRole;
	}

	private function SetClampVisibility()
	{
		var roleMappinData : GameplayRoleMappinData;
		if( m_mappin )
		{
			roleMappinData = ( ( GameplayRoleMappinData )( m_mappin.GetScriptData() ) );
		}
		if( roleMappinData && roleMappinData.m_hasOffscreenArrow )
		{
			OverrideClamp( true );
		}
	}

	private function ShouldBeClamped() : Bool
	{
		var roleMappinData : GameplayRoleMappinData;
		if( m_mappin )
		{
			roleMappinData = ( ( GameplayRoleMappinData )( m_mappin.GetScriptData() ) );
		}
		if( roleMappinData && roleMappinData.m_hasOffscreenArrow )
		{
			return true;
		}
		return false;
	}

}

