public NewSectorObject(String typeName, TreeView t1, SectorWindow s1)
 {
     tree = t1;
     sectorObjectsSQL = mainFrm.sectorObjects;
     type = typeName;
     _s1 = s1;
     mainFrm.selectedObjectID = 0;
     InitializeComponent();
 }
        public SectorWindow(PCanvas pcanvas, DataRow[] sectorRows, PropertyGrid pg, DataGridView dgv)
        {
            canvas = pcanvas;
            dr = sectorRows[0];
            _pg = pg;
            _dgv = dgv;

            //Setup Mouse Wheel Zoom type based on user settings.
            int zoomType = Properties.Settings.Default.zoomSelection;

            switch (zoomType)
            {
                case 0:
                    new MouseWheelZoomController(canvas.Camera);
                    break;
            }

            //Setup Default Background Color
            canvas.BackColor = Color.Black;

            //Create the master Layer
            masterLayer = canvas.Layer;

            //Initialize object Layers
            boundsLayer = new PLayer();
            mobsLayer = new PLayer();
            planetsLayer = new PLayer();
            stargatesLayer = new PLayer();
            starbasesLayer = new PLayer();
            decorationsLayer = new PLayer();
            harvestableLayer = new PLayer();

            //Retrieve Properties from sql row.
            String sectorName = sectorRows[0]["name"].ToString();
            int sectorID = int.Parse(sectorRows[0]["sector_id"].ToString());
            float xmin = float.Parse(sectorRows[0]["x_min"].ToString());
            float xmax = float.Parse(sectorRows[0]["x_max"].ToString());
            float ymin = float.Parse(sectorRows[0]["y_min"].ToString());
            float ymax = float.Parse(sectorRows[0]["y_max"].ToString());
            float zmin = float.Parse(sectorRows[0]["z_min"].ToString());
            float zmax = float.Parse(sectorRows[0]["z_max"].ToString());
            int gridx = int.Parse(sectorRows[0]["grid_x"].ToString());
            int gridy = int.Parse(sectorRows[0]["grid_y"].ToString());
            int gridz = int.Parse(sectorRows[0]["grid_z"].ToString());
            float fognear = float.Parse(sectorRows[0]["fog_near"].ToString());
            float fogfar = float.Parse(sectorRows[0]["fog_far"].ToString());
            int debrismode = int.Parse(sectorRows[0]["debris_mode"].ToString());
            bool lightbackdrop = (Boolean) sectorRows[0]["light_backdrop"];
            bool fogbackdrop = (Boolean) sectorRows[0]["fog_backdrop"];
            bool swapbackdrop = (Boolean) sectorRows[0]["swap_backdrop"];
            float backdropfognear = float.Parse(sectorRows[0]["backdrop_fog_near"].ToString());
            float backdropfogfar = float.Parse(sectorRows[0]["backdrop_fog_far"].ToString());
            float maxtilt = float.Parse(sectorRows[0]["max_tilt"].ToString());
            bool autolevel = (Boolean) sectorRows[0]["auto_level"];
            float impulserate = float.Parse(sectorRows[0]["impulse_rate"].ToString());
            float decayvelocity = float.Parse(sectorRows[0]["decay_velocity"].ToString());
            float decayspin = float.Parse(sectorRows[0]["decay_spin"].ToString());
            int backdropasset = int.Parse(sectorRows[0]["backdrop_asset"].ToString());
            String greetings = sectorRows[0]["greetings"].ToString();
            String notes = sectorRows[0]["notes"].ToString();
            int systemid = int.Parse(sectorRows[0]["system_id"].ToString());
            float galaxyx = float.Parse(sectorRows[0]["galaxy_x"].ToString());
            float galaxyy = float.Parse(sectorRows[0]["galaxy_y"].ToString());
            float galaxyz = float.Parse(sectorRows[0]["galaxy_z"].ToString());
            int sector_type = int.Parse(sectorRows[0]["sector_type"].ToString());

            //Load Sector Object Sql.
            so = new SectorObjectsSql(sectorName);
            DataTable sot = so.getSectorObject();

            float width = xmax - xmin;
            float height = ymax - ymin;
            float depth = zmax - zmin;

            //Populate Properties
            sp = new SectorProps();
            sp.Name = sectorName;
            sp.SectorID = sectorID;
            sp.Width = width;
            sp.Height = height;
            sp.Depth = depth;
            sp.GridX = gridx;
            sp.GridY = gridy;
            sp.GridZ = gridz;
            sp.FogNear = fognear;
            sp.FogFar = fogfar;
            sp.DebrisMode = debrismode;
            sp.LightBackdrop = lightbackdrop;
            sp.FogBackdrop = fogbackdrop;
            sp.SwapBackdrop = swapbackdrop;
            sp.BackdropFogNear = backdropfognear;
            sp.BackdropFogFar = backdropfogfar;
            sp.MaxTilt = maxtilt;
            sp.AutoLevel = autolevel;
            sp.ImpulseRate = impulserate;
            sp.DecayVelocity = decayvelocity;
            sp.DecaySpin = decayspin;
            sp.BackdropAsset = backdropasset;
            sp.Greetings = greetings;
            sp.Notes = notes;
            sp.SystemID = systemid;
            sp.GalaxyX = galaxyx;
            sp.GalaxyY = galaxyy;
            sp.GalaxyZ = galaxyz;

            String oSector = "";
            switch (sector_type)
            {
                case 0:
                    oSector = "Space Sector";
                    break;
                case 1:
                    oSector = "Rocky Planet Surface";
                    break;
                case 2:
                    oSector = "Gas Giant Surface";
                    break; ;
            }

            sp.SectorType = oSector;

            pg.SelectedObject = sp;

            //Create Sector Bounds
            new SectorBoundsSprite(boundsLayer, xmin, ymin, xmax, ymax);

            //Create All Sector Object sprites
            foreach (DataRow r in sot.Rows)
            {
                int type = int.Parse(r["type"].ToString());

                switch (type)
                {
                    case 0:
                        new MobSprite(mobsLayer, r, pg, dgv);
                        break;
                    case 3:
                        new PlanetSprite(planetsLayer, r, pg, dgv);
                        break;
                    case 11:
                        new StargateSprite(stargatesLayer, r, pg, dgv);
                        break;
                    case 12:
                        new StarbaseSprite(starbasesLayer, r, pg, dgv);
                        break;
                    case 37:
                        new DecorationSprite(decorationsLayer, r, pg, dgv);
                        break;
                    case 38:
                        new HarvestableSprite(harvestableLayer, r, pg, dgv);
                        break;

                }
            }

            //Attach all layers to their master
            masterLayer.AddChild(boundsLayer);
            masterLayer.AddChild(mobsLayer);
            masterLayer.AddChild(planetsLayer);
            masterLayer.AddChild(stargatesLayer);
            masterLayer.AddChild(starbasesLayer);
            masterLayer.AddChild(decorationsLayer);
            masterLayer.AddChild(harvestableLayer);

            //create events
            masterLayer.MouseDown += new PInputEventHandler(MasterLayer_OnMouseDown);

            canvas.Camera.MouseDown += new PInputEventHandler(canvasCamera_MouseDown);

            //Zoom all the way out.
            canvas.Camera.ViewScale = .375f;
        }