using UnityEngine;
using System.Collections;
using pumpkin.events;
using pumpkin.display;
using System.Collections.Generic;
using pumpkin.ui;
using pumpkin.text;
using pumpkin.logging;
 
public class TestDynamicUI : MonoBehaviour {
 
    private Stage stage;
    private MovieClip mc;
    private Dictionary<string, string> dictionary;
 
 
    // Use this for initialization
    void Start () {
        dictionary = new Dictionary<string, string>();
        dictionary["AAA"] = "A-A-A";
        dictionary["BBB"] = "B-B-B";
        dictionary["CCC"] = "C-C-C";
        dictionary["DDD"] = "D-D-D";
        dictionary["EEE"] = "E-E-E";
 
        if (!MovieClipOverlayCameraBehaviour.instance)
            return;
 
        stage = MovieClipOverlayCameraBehaviour.instance.stage;
 
        //Debug.Log(stage.stageWidth + "---" + stage.stageHeight);
 
        mc = new MovieClip("uniSWF/Examples/Tutorial 06 - Dynamic UI/swf/tut06_ui_assets.swf:panel_info");
        mc.gotoAndStop(1);
 
        ScreenUtils.center(stage, mc);
        mc.x = mc.x + 100;
 
        int counts=0;
        int button_distance = 15;
 
        foreach (KeyValuePair<string,string> obj in dictionary)
        {
            
            MovieClip button = new MovieClip("uniSWF/Examples/Tutorial 06 - Dynamic UI/swf/tut06_ui_assets.swf:btn_generic");
            button.gotoAndStop(1);
 
            button.x = mc.x - 200;
            button.y = mc.y + (counts*(button.height + button_distance));
            button.name = obj.Key.ToString();
 
            TextField button_name = button.getChildByName<TextField>("txt");
            button_name.text = button.name;
 
            button.addEventListener(MouseEvent.CLICK, OnButtonClick);
            button.addEventListener(MouseEvent.MOUSE_ENTER, OnButtonEnter);
            button.addEventListener(MouseEvent.MOUSE_LEAVE, OnButtonLeave);
 
            stage.addChild(button);
 
            counts++;
        
        }
        //TextField
 
        stage.addChild(mc);
    
    }
    
    // Update is called once per frame
    void Update () {
    
    }
 
    private void OnButtonClick(CEvent e)
    {
        MovieClip btn = e.currentTarget as MovieClip;
        TextField textfield = mc.getChildByName<TextField>("txt");
        textfield.text = dictionary[btn.name];
    }
 
    private void OnButtonEnter(CEvent e)
    {
    }
 
    private void OnButtonLeave(CEvent e)
    {
    }
 
}