class ContinueGameTooltip extends inkLogicController
{
	private editable var m_mainContainer : inkWidgetRef;
	private editable var m_imageReplacement : inkImageRef;
	private editable var m_networkStatusError : inkWidgetRef;
	private editable var m_networkSyncingIndicator : inkWidgetRef;
	private editable var m_label : inkTextRef;
	private editable var m_labelDate : inkTextRef;
	private editable var m_location : inkTextRef;
	private editable var m_quest : inkTextRef;
	private editable var m_level : inkTextRef;
	private editable var m_lifepath : inkImageRef;
	private editable var m_cloudStatus : inkImageRef;
	private editable var m_playTime : inkTextRef;
	private var m_saveFileStatus : inkSaveStatus;
	private var m_cloudSaveStatus : CloudSavesQueryStatus;
	private var m_metaDataLoaded : Bool;
	private var m_isOffline : Bool;
	private const var m_defaultAtlasPath : ResRef;
	default m_defaultAtlasPath = R"base\gameplay\gui\fullscreen\load_game\save_game.inkatlas";

	protected event OnInitialize()
	{
		inkWidgetRef.SetVisible( m_networkSyncingIndicator, true );
		inkWidgetRef.SetVisible( m_networkStatusError, false );
		inkWidgetRef.SetVisible( m_mainContainer, false );
	}

	public function SetMetadata( metadata : SaveMetadataInfo, optional isEp1Enabled : Bool )
	{
		var hrs, mins : Int32;
		var shrs, smins : String;
		var playthroughTime : Float;
		var finalString : String;
		var isEp1Save : Bool;
		isEp1Save = metadata.IsEp1Save();
		if( !( isEp1Enabled ) && isEp1Save )
		{
			inkTextRef.SetVisible( m_label, false );
			inkTextRef.SetLocalizedTextScript( m_quest, "LocKey#92500" );
			inkTextRef.SetVisible( m_location, false );
		}
		else
		{
			inkTextRef.SetText( m_label, metadata.internalName );
			inkTextRef.SetText( m_quest, metadata.trackedQuest );
			inkTextRef.SetText( m_location, metadata.locationName );
		}
		playthroughTime = MaxF( ( ( Float )( metadata.playthroughTime ) ), ( ( Float )( metadata.playTime ) ) );
		hrs = RoundF( playthroughTime / 3600.0 );
		mins = RoundF( ( playthroughTime % 3600.0 ) / 60.0 );
		if( hrs > 9 )
		{
			shrs = ( ( String )( hrs ) );
		}
		else
		{
			shrs = ( ( String )( hrs ) );
		}
		if( mins > 9 )
		{
			smins = ( ( String )( mins ) );
		}
		else
		{
			smins = ( ( String )( mins ) );
		}
		if( hrs != 0 )
		{
			finalString = shrs + GetLocalizedText( "UI-Labels-Units-Hours" );
		}
		if( mins != 0 )
		{
			finalString = ( ( hrs != 0 ) ? ( finalString + " " ) : ( finalString ) );
			finalString = ( finalString + smins ) + GetLocalizedText( "UI-Labels-Units-Minutes" );
		}
		inkTextRef.SetVisible( m_playTime, true );
		inkTextRef.SetText( m_playTime, finalString );
		inkTextRef.SetVisible( m_labelDate, true );
		inkTextRef.SetDateTimeByTimestamp( m_labelDate, metadata.timestamp );
		if( metadata.lifePath == inkLifePath.Corporate )
		{
			inkImageRef.SetTexturePart( m_lifepath, 'LifepathCorpo1' );
			inkTextRef.SetText( m_level, "Gameplay-LifePaths-Corporate" );
		}
		if( metadata.lifePath == inkLifePath.Nomad )
		{
			inkImageRef.SetTexturePart( m_lifepath, 'LifepathNomad1' );
			inkTextRef.SetText( m_level, "Gameplay-LifePaths-Nomad" );
		}
		if( metadata.lifePath == inkLifePath.StreetKid )
		{
			inkImageRef.SetTexturePart( m_lifepath, 'LifepathStreetKid1' );
			inkTextRef.SetText( m_level, "Gameplay-LifePaths-Streetkid" );
		}
		m_saveFileStatus = metadata.saveStatus;
		switch( metadata.saveStatus )
		{
			case inkSaveStatus.Invalid:
			case inkSaveStatus.Local:
				inkImageRef.SetVisible( m_cloudStatus, false );
			break;
			case inkSaveStatus.Upload:
				inkImageRef.SetTexturePart( m_cloudStatus, 'icon_cloud_upload' );
			inkImageRef.SetVisible( m_cloudStatus, true );
			break;
			case inkSaveStatus.Cloud:
				inkImageRef.SetTexturePart( m_cloudStatus, 'icon_cloud' );
			inkImageRef.SetVisible( m_cloudStatus, true );
			break;
			case inkSaveStatus.InSync:
				inkImageRef.SetTexturePart( m_cloudStatus, 'icon_cloud_insync' );
			inkImageRef.SetVisible( m_cloudStatus, true );
			break;
		}
		m_metaDataLoaded = true;
		inkWidgetRef.SetVisible( m_networkSyncingIndicator, false );
		inkWidgetRef.SetVisible( m_mainContainer, true );
	}

	public function UpdateNetworkStatus( status : CloudSavesQueryStatus )
	{
		m_cloudSaveStatus = status;
		UpdateStatus();
	}

	public function SetOfflineStatus( value : Bool )
	{
		m_isOffline = value;
		UpdateStatus();
	}

	public function SetInvalid( metadata : SaveMetadataInfo )
	{
		inkTextRef.SetVisible( m_labelDate, false );
		inkTextRef.SetVisible( m_playTime, false );
		inkTextRef.SetVisible( m_label, true );
		inkTextRef.SetVisible( m_quest, true );
		inkTextRef.SetText( m_label, "UI-Menus-Saving-CorruptedSaveTitle" );
		inkTextRef.SetText( m_quest, metadata.internalName );
		switch( metadata.saveStatus )
		{
			case inkSaveStatus.Invalid:
			case inkSaveStatus.Local:
			case inkSaveStatus.Upload:
				inkImageRef.SetVisible( m_cloudStatus, false );
			break;
			case inkSaveStatus.Cloud:
				inkImageRef.SetTexturePart( m_cloudStatus, 'icon_cloud' );
			inkImageRef.SetVisible( m_cloudStatus, true );
			break;
			case inkSaveStatus.InSync:
				inkImageRef.SetTexturePart( m_cloudStatus, 'icon_cloud_insync' );
			inkImageRef.SetVisible( m_cloudStatus, true );
			break;
		}
		m_metaDataLoaded = false;
		inkWidgetRef.SetVisible( m_networkSyncingIndicator, false );
		inkWidgetRef.SetVisible( m_mainContainer, true );
	}

	public function DisplayDataSyncIndicator( value : Bool )
	{
		inkWidgetRef.SetVisible( m_networkStatusError, false );
		inkWidgetRef.SetVisible( m_networkSyncingIndicator, value );
	}

	public function IsBusy() : Bool
	{
		return inkWidgetRef.IsVisible( m_networkSyncingIndicator );
	}

	public function GetPreviewImageWidget() : weak< inkImage >
	{
		return ( ( inkImage )( inkImageRef.Get( m_imageReplacement ) ) );
	}

	public function CheckThumbnailCensorship( IsBuildCensored : Bool )
	{
		if( IsBuildCensored && IsCloudSave() )
		{
			inkImageRef.SetAtlasResource( m_imageReplacement, m_defaultAtlasPath );
			inkImageRef.SetActiveTextureType( m_imageReplacement, inkTextureType.StaticTexture );
			inkImageRef.SetTexturePart( m_imageReplacement, 'cross_prog_icon' );
		}
	}

	public function IsCloudSave() : Bool
	{
		return m_saveFileStatus == inkSaveStatus.Cloud || m_saveFileStatus == inkSaveStatus.InSync;
	}

	private function UpdateStatus()
	{
		if( m_cloudSaveStatus == CloudSavesQueryStatus.FetchFailed || m_isOffline )
		{
			inkWidgetRef.SetVisible( m_networkStatusError, true );
			inkWidgetRef.SetVisible( m_networkSyncingIndicator, false );
		}
		else if( m_metaDataLoaded )
		{
			inkWidgetRef.SetVisible( m_networkSyncingIndicator, false );
		}
	}

}

