using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DangionMap : MonoBehaviour
{
public GameObject dangionMapSystem;
GameObject[] dangeonRoots;
GameObject[,] roomImage = new GameObject[5,5];
GameObject[,] eventIcons = new GameObject[5, 5];
int[,] structOfDangeon = new int[5,5]{
{ 4, 1, 5, 4, 1 },
{14,12, 9,14,12 },
{14, 0, 0, 0,12 },
{14, 0, 0, 0,12 },
{ 3,13, 0,13, 2 },
};
int[,] posOfEvent = new int[5, 5] {
{ -1,-1, 3,-1,-1 },
{ 2,-1,-1,-1, 1 },
{ 0,-1,-1,-1,-1 },
{ -1,-1,-1, 2,-1 },
{ -1,-1,-1,-1,-1 },
};
void Start()
{
this.gameObject.SetActive(false);
}
public void ShowDangeonMap()
{
this.gameObject.SetActive(true);
SetDangion();
SetEvent();
}
public void HideDangeonMap()
{
this.gameObject.SetActive(false);
DestroyMapInfo();
}
public void SetDangion()
{
Transform parentRoomImage = transform.Find("Panel/roomImages");
Vector3 originPos = parentRoomImage.transform.position;
Vector3 pos = new Vector3(originPos.x - 200, originPos.y-200, 0);
for(int j = 0; j < 5; j++)
{
for(int i = 0; i < 5; i++)
{
roomImage[j,i] = new GameObject("roomImage" + j + "_" +i);
roomImage[j,i].transform.parent = parentRoomImage;
Image image = roomImage[j, i].AddComponent<Image>();
image.sprite = dangionMapSystem.GetComponent<DangionData>().roomImages[structOfDangeon[j,i]];
pos.x = originPos.x - 200 + i * 100;
pos.y = originPos.y + 200 + j * -100;
roomImage[j, i].transform.position = pos;
}
}
}
public void DestroyMapInfo()
{
for (int j = 0; j < 5; j++)
{
for (int i = 0; i < 5; i++)
{
Destroy( roomImage[j, i].gameObject);
Destroy(eventIcons[j, i].gameObject);
}
}
Array.Clear(roomImage,0,roomImage.Length);
}
public void SetEvent()
{
Transform parentImageIcons = transform.Find("Panel/eventIcons");
Vector3 originPos = parentImageIcons.transform.position;
Vector3 pos = new Vector3(originPos.x - 200, originPos.y - 200, 0);
for (int j = 0; j < 5; j++)
{
for (int i = 0; i < 5; i++)
{
eventIcons[j, i] = new GameObject("eventIcon" + j + "_" + i);
eventIcons[j, i].transform.parent = parentImageIcons;
Image icon = eventIcons[j, i].AddComponent<Image>();
if(posOfEvent[j, i] != -1)
{
icon.sprite = dangionMapSystem.GetComponent<DangionData>().eventIcons[posOfEvent[j, i]];
icon.SetNativeSize();
}
else
{
icon.color = new Color(1, 1, 1, 0);
}
pos.x = originPos.x - 200 + i * 100;
pos.y = originPos.y + 200 + j * -100;
eventIcons[j, i].transform.position = pos;
}
}
}
}