using System;
using System.Collections.Generic;
using UnityEngine;

public class GameScene : BaseScene
{
    protected override void Init()
    {
        base.Init();
        
        _sceneType = Define.Scene.Game;
        
        Manager.UI.UIList = new List<string>
        {
            "Panel", "Bar_EXP" , "JoyStick", "Btn_Attack", "Btn_Menu", "Menu_Setting"
        };
        
        Manager.UI.SwitchOnObject<Joystick>("JoyStick", true);
        
        UIButton atkbtn = Manager.UI.SwitchOnObject<UIButton>("Btn_Attack", true);
        
        if (atkbtn != null)
        {
            atkbtn.SetButtonContents(null,"공", false, true);
            atkbtn.SetButtonRect("Btn_Attack",
                new Vector2(-100f - 180f / 2, 100f + 180f / 2),
                180.0f,180.0f,
                new Vector2(1, 0),
                new Vector2(0.5f, 0.5f)
            );
            atkbtn.OnButtonClicked += Manager.Input.OnClicked;
        }
        
        UIButton menubtn = Manager.UI.SwitchOnObject<UIButton>("Btn_Menu", true);
        
        if (menubtn != null)
        {
            menubtn.SetButtonContents(null,null, true, false);
            menubtn.SetButtonRect("Btn_Menu", 
                new Vector2(-100f, -100f),
                80.0f,80.0f,
                new Vector2(1, 1),
                new Vector2(1,1)
            );
            menubtn.OnButtonClicked += Manager.Input.OnClicked;
        }
        
        UIBar expBar = Manager.UI.SwitchOnObject<UIBar>("Bar_EXP", true);
        if (expBar != null)
        {
            expBar.SwitchObject(true,true);
        }
        
        
        
        
        CreateSpawner();
    }

    void CreateSpawner()
    {
        GameObject spawner = Manager.Resource.Instantiate("Prefabs/UI/Spawner", GameObject.Find("@Scene").transform);

        var spawn = spawner.AddComponent<SpawnController>();
        spawn.EnemyPrefabPath = "Prefabs/Characters/Test_Enemy";
        spawn.EnemyDataPath = "Data/E_Test1";
    }

    private void Start()
    {
        Manager.Input.RegisterAction("Btn_Menu", OnMenu);
        Manager.Input.RegisterAction("Btn_Menu", OnSetMenu);
    }

    public void OnSetMenu()
    {
        MenuSetting menuSetting = Manager.UI.SwitchOnObject<MenuSetting>("Menu_Setting", true);
        if (menuSetting != null)
        {
            GameObject MenuObject = menuSetting.gameObject;
            MenuObject.transform.SetAsLastSibling();
        }
    }

    public override void OffMenu()
    {
        base.OffMenu();
        MenuSetting menuSetting = Manager.UI.SwitchOnObject<MenuSetting>("Menu_Setting", false);
    }

    public override void Clear()
    {

    }


}


