using System;
using System.Collections.Generic;
using MrWu.Debug;
using Server;
using Server.Core;

namespace GlobalSever.Form
{
    public partial class GameInfoTable : ServerTable
    {
        public override string tableText => "游戏信息";

        private UILog _uiLog;
        
        public GameInfoTable(ServerProxy server)
        {
            this.server = server;
            InitializeComponent();
            _uiLog = new UILog(textBox1);
        }

        private void button1_Click_(object sender, EventArgs e)
        {
            textBox1.Clear();
            Type[] types = ReferencePool.GetPoolTypes();
            textBox1.AppendText($"引用池数量:{types.Length}\r\n");

            List<TypePoolCnt> typePoolCnts = new List<TypePoolCnt>();
            for (int i = 0; i < types.Length; i++)
            {
                int cnt = ReferencePool.GetPoolCnt(types[i]);
                typePoolCnts.Add(new TypePoolCnt(types[i],cnt));
            }

            int maxIdx = 0;
            for (int i = 0; i < typePoolCnts.Count; i++)
            {
                maxIdx = i;
                for (int j = i+1; j <  typePoolCnts.Count; j++)
                {
                    if (typePoolCnts[j].Cnt > maxIdx)
                    {
                        maxIdx = j;
                    }
                }

                if (maxIdx != i)
                {
                    //交换位置
                    (typePoolCnts[i], typePoolCnts[maxIdx]) = (typePoolCnts[maxIdx], typePoolCnts[i]);
                }
                textBox1.AppendText($"{typePoolCnts[i].PoolType.Name}:{typePoolCnts[i].Cnt}\r\n");
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            GlobalManager.instance.IsReloadTable = true;
            _uiLog.Debug("发送重新加载配置命令！");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            _uiLog.Clear();
        }
    }
}