using CommonAI.ZoneClient;
using CommonAI.ZoneServer;
using CommonAIServer.Connector;
using CommonAIServer.Node;
using GameEditorPlugin.Win32.BattleClient;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace GameEditorPluginServer.Client
{
    public class FormTestClient : FormClient
    {
        // -----------------------------------------------------------------------------------------------------------------

        private Pen pen = new Pen(Color.FromArgb(128, 255, 255, 255));

        public void Init(ZoneNodeConfig cfg, string playerUUID, string roomID, string connectString, string netDriver, CreateUnitInfoR2B enter)
        {
            base.Init("", playerUUID, roomID,
                netDriver,
                connectString,
                cfg.GAME_UPDATE_INTERVAL_MS, // update interval
                cfg.CLIENT_SYNC_OBJECT_IN_RANGE, // sync range
                enter);
        }
        protected override void DisplayActor_OnRender(Graphics g, DisplayGameUnit unit)
        {
            var actor = unit.Data as ZoneActor;
            pen.Width = 1f / BattlePanel.DisplayWorld.getCameraScale();
            float r_in = actor.LoginData.ClientSyncObjectRange;
            float r_out = actor.LoginData.ClientSyncObjectOutRange;
            g.DrawArc(pen, -r_in, -r_in, r_in * 2, r_in * 2, 0, 360);
            g.DrawArc(pen, -r_out, -r_out, r_out * 2, r_out * 2, 0, 360);
        }
        
        public static FormLauncher StartLauncher(ZoneNodeConfig cfg, string playerUUID, string connectString, int sceneID, CreateUnitInfoR2B enter, TestClientLoader loader, FormLauncher.OnLaunchOverHandler handler)
        {
            FormLauncher ret = new FormLauncher("",
                playerUUID,
                sceneID.ToString(),
                typeof(CommonNetwork.Sockets.NetSession).FullName,
                connectString,
                cfg.GAME_UPDATE_INTERVAL_MS,
                cfg.CLIENT_SYNC_OBJECT_IN_RANGE,
                enter.UnitTemplateID,
                enter.Force,
                sceneID,
                loader);
            ret.OnLaunchOver += handler;
            return ret;
        }

        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // BattlePanel
            // 
            this.BattlePanel.Size = new System.Drawing.Size(840, 662);
            // 
            // FormTestClient
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
            this.ClientSize = new System.Drawing.Size(840, 662);
            this.Name = "FormTestClient";
            this.ResumeLayout(false);

        }
    }
}