using UnityEngine;
using System.Collections;

public class Controller_Button : Widget
	{

	public string symbol; // Name of the symbol send by this object
	public string input_keyName = null; // (optionnal) button name to trigger this object

	public Material on_material;
	public Material off_material;

	void OnMouseDown()
		{
		emit ();
		audio.Play ();
		renderer.material = on_material;
		//ignore sound experiments below
		//clickSound.pitch = 2.3f;
		//clickSound.Play ();
		}

	void OnMouseUp()
		{
		renderer.material = off_material;
		}

	void emit()
	{

        if (this.trackToReportTo != null)
            this.trackToReportTo.handleWidgetUpdate(this);
        else
        {
            //Debug.Log("Reporting Invalid Widget Use in Controller_Button.emit");
            gameController.reportInvalidWidgetUse();
        }
	}

	new void Start ()
		{
		base.Start();
		isOutput = false;
		}

    public override void Update()
	    {
		if( input_keyName != null && input_keyName!="" )
			{
			if( Input.GetKeyDown(input_keyName) )
				OnMouseDown();
			if( Input.GetKeyUp(input_keyName) )
				OnMouseUp();
			}
		}

    public override void createTargetValue(Track listeningTrack)
    {
        this.trackToReportTo = listeningTrack;
        //buttons don't need a value- they trigger while pressed    
        this.isAvailable = false;
    }

    public override void clearTargetValue()
    {
        this.trackToReportTo = null;
        this.isAvailable = true;
    }

    public override string getTargetValueInstruction()
    {
        return "push " + this.symbol;
    }

	}