using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

public class TempGroupInfos
{
    public Color rgb;
    public int gid;

    public short size = 0;
    public short show = 0;
    public float Jindu
    {
        get { return (float)show / (float)size; }
    }

}

public class AreaAnimationDiffuse
{
    public short m_x;
    public short m_y;
    public short m_aid;
    public short m_fpsStart = 1;//r 开始
    public short m_fpsEnd = 25;//r 结束
    //key beginStart 值 value 这个圆环的像素
    public ConcurrentDictionary<short, List<short>> m_datas = new ConcurrentDictionary<short, List<short>>();
    public int nowState = 0;//0 尚未开始 1 处理中 2 处理完成
    public AreaAnimationDiffuse(short x, short y, short aid)
    {
        m_x = x;
        m_y = y;
        m_aid = aid;
    }
}
public class Vector2Short
{
    public short x;
    public short y;
    public Vector2Short(short x, short y)
    {
        this.x = x;
        this.y = y;
    }
}
public class RectInt
{
    public int left = int.MaxValue;
    public int top = int.MaxValue;
    public int right = int.MinValue;
    public int dowm = int.MinValue;
    public RectInt() { }
    public RectInt(RectInt rectInt)
    {
        left = rectInt.left;
        top = rectInt.top;
        right = rectInt.right;
        dowm = rectInt.dowm;
    }
}
public class GroupByAreaPtInfos
{
    //public Dictionary<short, List<Vector2Short>> datas = new Dictionary<short, List<Vector2Short>>();
    public Dictionary<short, bool> datasBool = new Dictionary<short, bool>();
    private Dictionary<short, bool> lines = new Dictionary<short, bool>();
    public static Dictionary<short, List<int>> mapAllDatas = new Dictionary<short, List<int>>();
    public static int width;
    public static int height;
    public bool getDataByAid(short aid, ref List<Vector2Short> data, bool isReBack = false)
    {
        if (datasBool.ContainsKey(aid) && (datasBool[aid] || isReBack))
        {
            data.Clear();
            for (int i = 0; i < mapAllDatas[aid].Count; i++)
            {
                int a = mapAllDatas[aid][i];
                data.Add(new Vector2Short((short)(a % width), (short)(a / width)));
            }
            return true;
        }
        return false;
    }
    public int getLenByAid(short aid)
    {
        if (datasBool.ContainsKey(aid) && datasBool[aid])
        {
            return mapAllDatas[aid].Count;
        }
        return 0;
    }
    public bool getIndexPosByIndex(short aid, int index, ref int value)
    {
        value = mapAllDatas[aid][index];
        return true;
    }
    public bool getIndexPosByIndex(short aid, int index, ref int x, ref int y)
    {
        int value = 0;
        getIndexPosByIndex(aid, index, ref value);
        y = value % width;
        x = value / width;
        return true;
    }
    public bool getLineByAid(short aid, ref List<Vector2Short> data)
    {
        if (lines.ContainsKey(aid) == false)
            return false;
        return false;
        //data = lines[aid];
        //return true;
    }
    public short[] getDataAllKey(bool isSelect = false)
    {
        if (isSelect == false)
        {
            return datasBool.Keys.ToArray();
        }
        else
        {
            List<short> ret = new List<short>();
            foreach (var item in datasBool)
            {
                if (item.Value == true)
                {
                    ret.Add(item.Key);
                }
            }
            return ret.ToArray();
        }

    }
    public void initByAid(short aid)
    {
        if (datasBool.ContainsKey(aid) == false)
        {
            datasBool.Add(aid, true);
        }
        else
        {
            datasBool[aid] = true;
        }
        if (lines.ContainsKey(aid) == false)
        {
            lines.Add(aid, true);
        }
        else
        {
            lines[aid] = true;
        }
    }

    public void appendLinePos(short aid, short x, short y)
    {
        return;
    }
    public void removeAid(short aid)
    {
        if (datasBool.ContainsKey(aid) == false) return;
        datasBool[aid] = false;
    }
}
public class ColorIndexTables
{
    Dictionary<uint, Color> colors = new Dictionary<uint, Color>();
    uint[,] indexs;
    int width;
    int height;
    public ColorIndexTables(int width, int height)
    {
        indexs = new uint[width, height];
        this.width = width;
        this.height = height;
    }
    public bool setColor(int x, int y, Color color)
    {
        double key1 = color.r * 256f * 256f + color.g * 256f + color.b * 50f + color.a;
        uint key = Convert.ToUInt32(key1);
        if (colors.ContainsKey(key) == false)
        {
            colors.Add(key, color);
        }
        indexs[x, y] = key;
        return true;
    }
    public bool getColor(int x, int y, ref Color color)
    {
        if (x < 0 || x >= width || y < 0 || y >= height) { return false; }
        uint key = indexs[x, y];
        Color temp = colors[key];
        color = new Color(temp.r, temp.g, temp.b, temp.a);
        return true;
    }
    public bool getTiledColor(int x, int y, ref Color color)
    {
        if (x < 0)
        {
            return false;
        }
        //if (x < 0 || y < 0) return false;
        return getColor(x % width, y % height, ref color);
    }
}
public class mainGameViewHelp
{
}
