struct ElementData
{
	var id : String;
}

class NetworkMinigameElementController extends inkLogicController
{
	protected var m_data : ElementData;
	protected editable var m_text : inkTextRef;
	protected editable var m_textNormalColor : Color;
	protected editable var m_textHighlightColor : Color;
	protected editable var m_bg : inkRectangleRef;
	protected editable var m_colorAccent : inkWidgetRef;
	protected editable var m_dimmedOpacity : Float;
	protected editable var m_notDimmedOpacity : Float;
	protected var m_defaultFontSize : Int32;
	protected var m_wasConsumed : Bool;
	private var m_root : weak< inkWidget >;

	protected event OnInitialize()
	{
		m_root = GetRootWidget();
		inkTextRef.SetText( m_text, "" );
		m_wasConsumed = false;
		m_defaultFontSize = inkTextRef.GetFontSize( m_text );
		SetElementActive( false );
	}

	public virtual function SetContent( const toSet : ref< ElementData > )
	{
		m_data = toSet;
		inkTextRef.SetText( m_text, toSet.id );
		RefreshColorAccent();
	}

	public virtual function SetHighlightStatus( doHighlight : Bool )
	{
		inkTextRef.SetFontSize( m_text, ( ( doHighlight ) ? ( m_defaultFontSize + 4 ) : ( m_defaultFontSize ) ) );
		inkRectangleRef.SetVisible( m_bg, doHighlight );
		inkTextRef.SetTintColor( m_text, ( ( doHighlight ) ? ( m_textHighlightColor ) : ( m_textNormalColor ) ) );
	}

	public function GetContentWidget() : inkWidgetRef
	{
		return m_text;
	}

	public function GetContent() : ElementData
	{
		return m_data;
	}

	public virtual function Consume()
	{
		m_wasConsumed = true;
		inkTextRef.SetText( m_text, "XX" );
		m_root.SetOpacity( 0.5 );
		RefreshColorAccent();
	}

	public function RefreshColorAccent()
	{
		var toSet : CName;
		if( m_wasConsumed )
		{
			toSet = 'Default';
		}
		else
		{
			switch( m_data.id )
			{
				case "1C":
					toSet = 'Instruction1';
				break;
				case "55":
					toSet = 'Instruction2';
				break;
				case "BD":
					toSet = 'Instruction3';
				break;
				case "E9":
					toSet = 'Instruction4';
				break;
				default:
					toSet = 'Default';
				break;
			}
		}
		inkWidgetRef.SetState( m_colorAccent, toSet );
	}

	public function SetElementActive( isDimmed : Bool )
	{
		m_root.SetInteractive( !( isDimmed ) );
		inkRectangleRef.SetOpacity( m_bg, ( ( isDimmed ) ? ( m_dimmedOpacity ) : ( m_notDimmedOpacity ) ) );
		inkTextRef.SetOpacity( m_text, ( ( isDimmed ) ? ( m_dimmedOpacity ) : ( m_notDimmedOpacity ) ) );
		inkWidgetRef.SetOpacity( m_colorAccent, ( ( isDimmed ) ? ( m_dimmedOpacity ) : ( m_notDimmedOpacity ) ) );
	}

	public function SetAsBufferSlot()
	{
		inkRectangleRef.SetVisible( m_bg, true );
		inkRectangleRef.SetOpacity( m_bg, m_dimmedOpacity );
	}

}

class NetworkMinigameAnimatedElementController extends NetworkMinigameElementController
{
	protected editable var m_onConsumeAnimation : CName;
	protected editable var m_onSetContentAnimation : CName;
	protected editable var m_onHighlightOnAnimation : CName;
	protected editable var m_onHighlightOffAnimation : CName;

	public override function SetContent( const toSet : ref< ElementData > )
	{
		super.SetContent( toSet );
		PlayLibraryAnimation( m_onSetContentAnimation );
	}

	public override function SetHighlightStatus( doHighlight : Bool )
	{
		super.SetHighlightStatus( doHighlight );
		PlayLibraryAnimation( ( ( doHighlight ) ? ( m_onHighlightOnAnimation ) : ( m_onHighlightOffAnimation ) ) );
	}

	public override function Consume()
	{
		super.Consume();
		PlayLibraryAnimation( m_onConsumeAnimation );
	}

}

