Example #1
0
        private void toolStripButton_drawmap_Click(object sender, EventArgs e)
        {
            //Point startmappoint = new Point(0,200);
            canvasupdate();

            if (galaxy.sectors_dictionary.Count > 0)
            {
                selectSystemPrompt promptwindow = new selectSystemPrompt();
                selectsys_returnObj retobj = promptwindow.selectSystemPromptdlg(galaxy);

                SystemObj startSys = retobj.system;
                int depth = retobj.depth;
                bool resetlocs = retobj.resetloc;

                foreach (UserControl_System control in sys_usrCtrls)//clear usercontrols
                {
                    pictureBox1.Controls.Remove(control);
                    control.Dispose();
                }

                if (resetlocs)
                {
                    startSys.maploc = new Point(0,200);
                }

                sys_usrCtrls = new List<UserControl_System>();  //new usercontrol list
                mappedsystems = new Dictionary<string, SystemObj>(); //new mappedsystems dictionary
                mappedwormholes = new List<WormHoleObj>();
                systemPlaced = new List<SystemObj>();

                //startSys.maploc = startmappoint; //set first system location
                systemPlaced.Add(startSys);
                syslink_usrctrl = new UserControl_System(startSys, this, canvasdata); //first system usercontrol
                sys_usrCtrls.Add(syslink_usrctrl); //addthe user control to the usercontrol list

                mappedsystems.Add(startSys.location, startSys);//add the system to the mappedsystems dictionary

                pictureBox1.Controls.Add(syslink_usrctrl); //add teh control to the picturebox.
                Point loc = syslink_usrctrl.Location;
                placesystems(startSys, 180, depth, resetlocs);

            }
            refreshlines();
        }
Example #2
0
        private void placesystems(SystemObj parentsystem, int angle, int depth, bool resetlocs)
        {
            if (depth > 0)
            {
                //Dictionary<string, SystemObj> systemslinked = new Dictionary<string, SystemObj>();
                List<SystemObj> systemslinked = new List<SystemObj>();
                int icondistance = 100;
               // Point parentMaploc = parentsystem.maploc;
                bool resetthisloc = false;

                foreach (WormHoleObj wh in parentsystem.Wormholes) //foreach wormhole from this system.
                {

                    SystemObj linkedsys = wh.getlink(parentsystem);

                    //if (!systemslinked.Keys.Contains(linkedsys.location))
                    if (!systemslinked.Contains(linkedsys))
                    {
                        //systemslinked.Add(linkedsys.location, linkedsys);
                        systemslinked.Add(linkedsys);
                    }

                    if (!mappedwormholes.Contains(wh))
                    {
                        mappedwormholes.Add(wh);
                    }
                    if (!mappedsystems.Keys.Contains(linkedsys.location))
                    {

                        syslink_usrctrl = new UserControl_System(linkedsys, this, canvasdata);
                        sys_usrCtrls.Add(syslink_usrctrl);
                        mappedsystems.Add(linkedsys.location, linkedsys);
                        pictureBox1.Controls.Add(syslink_usrctrl);
                    }
                }
                //foreach (KeyValuePair<string, SystemObj> kvp_system in systemslinked)
                foreach (SystemObj linkedsys in systemslinked) //this list should not include the parent...
                {
                    if (!systemPlaced.Contains(linkedsys))
                    {
                        //SystemObj linkedsys = kvp_system.Value;
                        Point thismaploc = new Point();

                        //Point dloc = mappedsystems[linkedsys.location].maploc;
                        //if (dloc.X < 1 || dloc.Y < 1) { resetthisloc = true; }
                        int linkcount = systemslinked.Count;
                        //if (linkcount > 1) { linkcount -= 1; }
                        if (resetthisloc || resetlocs) //reset.
                        {
                            thismaploc = parentsystem.maploc;
                            angle += (360 / linkcount);
                            thismaploc = sides_ab(icondistance, angle, false);
                            thismaploc.X += parentsystem.maploc.X;
                            thismaploc.Y += parentsystem.maploc.Y;
                            linkedsys.maploc = thismaploc;
                            //

                        }
                        //mappedsystems[linkedsys.location].maploc = thismaploc;

                        systemPlaced.Add(linkedsys);
                    }
                    //placesystems(mappedsystems[linkedsys.location], angle, depth - 1, resetlocs);
                    placesystems(linkedsys, angle, depth - 1, resetlocs);

                }
            }
        }