/// <summary>
        /// Draws a dot and the name of the star if a star exists in the current position.
        /// </summary>
        /// <param name="e"></param>
        private void DrawStar(object sender, SingleHexagonDrawEventArgs e)
        {
            Star star;
            int  halfStar = starDotDiameter / 2;

            using (SectorContext db = new SectorContext())
            {
                star = (from s in db.stars
                        where ((s.locX == e.column) && (s.locY == e.row))
                        select s).FirstOrDefault();
            }

            if (star != null)
            {
                e.gr.FillEllipse(Brushes.Black,
                                 e.hex.center.X - halfStar, e.hex.center.Y - halfStar,
                                 starDotDiameter, starDotDiameter);

                using (StringFormat sf = new StringFormat())
                {
                    sf.Alignment     = StringAlignment.Center;
                    sf.LineAlignment = StringAlignment.Center;

                    PointF textPoint = e.hex.center;
                    textPoint.Y += halfStar + starTextOffset + (grid.font.Size / 2);

                    e.gr.DrawString(star.name, grid.font, Brushes.Black, textPoint, sf);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Save the trade route.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            using (SectorContext db = new SectorContext())
            {
                TradeRoute toSave;

                if (currentRouteId == -1)
                {
                    toSave = new TradeRoute();
                    db.routes.Add(toSave);
                }
                else
                {
                    toSave =
                        (from t in db.routes
                         where (t.id == currentRouteId)
                         select t).FirstOrDefault();
                }

                if (toSave != null)
                {
                    toSave.star1X = (int)nud1X.Value;
                    toSave.star1Y = (int)nud1Y.Value;
                    toSave.star2X = (int)nud2X.Value;
                    toSave.star2Y = (int)nud2Y.Value;

                    db.SaveChanges();

                    currentRouteId = toSave.id;
                }
            }

            UpdateListbox();
        }
        /// <summary>
        /// Draws all the given trade routes.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DrawTradeRoutes(object sender, HexagonGridDrawEventArgs e)
        {
            TradeRoute[] routes;
            PointF       start = new PointF();
            PointF       end   = new PointF();

            using (SectorContext db = new SectorContext())
            {
                if (db.routes.Count() > 0)
                {
                    //routes = (from r in db.routes
                    //		  select r).ToArray();
                    routes = db.routes.ToArray();
                }
                else
                {
                    routes = null;
                    //throw new Exception("Route count is zero!");
                }
            }

            if (routes != null)
            {
                foreach (TradeRoute r in routes)
                {
                    RegularHexagon hex1 = e.grid.Hexagons[r.star1Y, r.star1X];
                    RegularHexagon hex2 = e.grid.Hexagons[r.star2Y, r.star2X];

                    start = PointBetween(hex1.center, hex2.center, routePercentFromCenter);
                    end   = PointBetween(hex2.center, hex1.center, routePercentFromCenter);

                    e.gr.DrawLine(routePen, start, end);
                }
            }
        }
        /// <summary>
        /// Save our current star.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            using (SectorContext db = new SectorContext())
            {
                Star toSave;

                if (currentStarId == -1)
                {
                    toSave = new Star();
                    db.stars.Add(toSave);
                }
                else
                {
                    toSave =
                        (from s in db.stars
                         where (s.id == currentStarId)
                         select s).FirstOrDefault();
                }

                if (toSave != null)
                {
                    toSave.name = txtName.Text;
                    toSave.locX = (int)nudX.Value;
                    toSave.locY = (int)nudY.Value;

                    db.SaveChanges();

                    currentStarId = toSave.id;
                }
            }

            UpdateListbox();
        }
示例#5
0
        /// <summary>
        /// Updates the location combobox.
        /// </summary>
        private void UpdateCombobox()
        {
            cbxLocation.Items.Clear();

            using (SectorContext db = new SectorContext())
            {
                foreach (Star s in db.stars)
                {
                    cbxLocation.Items.Add(s);
                }
            }
        }
        /// <summary>
        /// Update the display when the index is changed.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lbxStars_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lbxStars.SelectedItem != null)
            {
                currentStarId = ((Star)lbxStars.SelectedItem).id;

                using (SectorContext db = new SectorContext())
                {
                    UpdateData((from s in db.stars
                                where (s.id == currentStarId)
                                select s).FirstOrDefault());
                }
            }
        }
示例#7
0
        /// <summary>
        /// When a new planet is selected, update the id.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lbxPlanets_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lbxPlanets.SelectedItem != null)
            {
                currentPlanetId = ((Planet)lbxPlanets.SelectedItem).id;

                using (SectorContext db = new SectorContext())
                {
                    UpdateData((from p in db.planets
                                where (p.id == currentPlanetId)
                                select p).FirstOrDefault());
                }
            }
        }
示例#8
0
        /// <summary>
        /// Update the display when the index is changed.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lbxRoutes_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lbxRoutes.SelectedItem != null)
            {
                currentRouteId = ((TradeRoute)lbxRoutes.SelectedItem).id;

                using (SectorContext db = new SectorContext())
                {
                    UpdateData((from t in db.routes
                                where (t.id == currentRouteId)
                                select t).FirstOrDefault());
                }
            }
        }
        /// <summary>
        /// Delete the currently selected star.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDelete_Click(object sender, EventArgs e)
        {
            using (SectorContext db = new SectorContext())
            {
                if (db.stars.Count() > 0)
                {
                    db.stars.Remove((from s in db.stars
                                     where (s.id == currentStarId)
                                     select s).FirstOrDefault());

                    db.SaveChanges();
                }
            }

            ResetListboxAndData();
        }
示例#10
0
        /// <summary>
        /// Save the planet to the database.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            using (SectorContext db = new SectorContext())
            {
                Planet toSave;

                if (currentPlanetId == -1)
                {
                    toSave = new Planet();
                    db.planets.Add(toSave);
                }
                else
                {
                    toSave =
                        (from p in db.planets
                         where (p.id == currentPlanetId)
                         select p).FirstOrDefault();
                }

                if (toSave != null)
                {
                    toSave.name                 = txtName.Text;
                    toSave.locId                = (cbxLocation.SelectedItem != null) ? ((Star)cbxLocation.SelectedItem).id : -1;
                    toSave.atmosphere           = txtAtmosphere.Text;
                    toSave.temperature          = txtTemperature.Text;
                    toSave.biosphere            = txtBiosphere.Text;
                    toSave.population           = txtPopulation.Text;
                    toSave.techLevel            = txtTechLevel.Text;
                    toSave.tags                 = txtTags.Text;
                    toSave.capitalAndGovernment = txtCapitalAndGovernment.Text;
                    toSave.culturalNotes        = txtCulturalNotes.Text;
                    toSave.friends              = txtFriends.Text;
                    toSave.enemies              = txtEnemies.Text;
                    toSave.complications        = txtComplications.Text;
                    toSave.places               = txtPlaces.Text;
                    toSave.things               = txtThings.Text;
                    toSave.partyActivities      = txtPartyActivities.Text;
                    toSave.notes                = txtNotes.Text;

                    db.SaveChanges();

                    currentPlanetId = toSave.id;
                }
            }

            UpdateListbox();
        }
        /// <summary>
        /// Reset the listbox and data area.
        /// </summary>
        private void ResetListboxAndData()
        {
            using (SectorContext db = new SectorContext())
            {
                if (db.stars.Count() > 0)
                {
                    Star current = (from s in db.stars
                                    orderby s.id ascending
                                    select s).FirstOrDefault();

                    currentStarId = current.id;
                    UpdateGUI(current);
                }
                else
                {
                    UpdateListbox();
                }
            }
        }
示例#12
0
        /// <summary>
        /// Reset the listbox and data area.
        /// </summary>
        private void ResetListboxAndData()
        {
            using (SectorContext db = new SectorContext())
            {
                if (db.routes.Count() > 0)
                {
                    TradeRoute current = (from r in db.routes
                                          orderby r.id ascending
                                          select r).FirstOrDefault();

                    currentRouteId = current.id;
                    UpdateGUI(current);
                }
                else
                {
                    UpdateListbox();
                }
            }
        }
示例#13
0
        /// <summary>
        /// Reset the listbox and data area.
        /// </summary>
        private void ResetListboxAndData()
        {
            using (SectorContext db = new SectorContext())
            {
                if (db.planets.Count() > 0)
                {
                    Planet current = (from p in db.planets
                                      orderby p.id ascending
                                      select p).FirstOrDefault();

                    currentPlanetId = current.id;
                    UpdateGUI(current);
                }
                else
                {
                    UpdateListbox();
                    UpdateCombobox();
                }
            }
        }
        /// <summary>
        /// Updates the listbox with all the current stars.
        /// </summary>
        private void UpdateListbox()
        {
            lbxStars.Items.Clear();

            using (SectorContext db = new SectorContext())
            {
                foreach (Star s in db.stars)
                {
                    lbxStars.Items.Add(s);
                }
            }

            if (currentStarId != -1)
            {
                lbxStars.SelectedItem = (from Star s in lbxStars.Items
                                         where (s.id == currentStarId)
                                         select s).FirstOrDefault();
            }
            else
            {
                lbxStars.ClearSelected();
            }
        }
示例#15
0
        /// <summary>
        /// Updates the listbox with all the current planets.
        /// </summary>
        private void UpdateListbox()
        {
            lbxPlanets.Items.Clear();

            using (SectorContext db = new SectorContext())
            {
                foreach (Planet p in db.planets)
                {
                    lbxPlanets.Items.Add(p);
                }
            }

            if (currentPlanetId != -1)
            {
                lbxPlanets.SelectedItem = (from Planet p in lbxPlanets.Items
                                           where (p.id == currentPlanetId)
                                           select p).FirstOrDefault();
            }
            else
            {
                lbxPlanets.ClearSelected();
            }
        }
示例#16
0
        /// <summary>
        /// Updates the listbox with all the current stars.
        /// </summary>
        private void UpdateListbox()
        {
            lbxRoutes.Items.Clear();

            using (SectorContext db = new SectorContext())
            {
                foreach (TradeRoute r in db.routes)
                {
                    lbxRoutes.Items.Add(r);
                }
            }

            if (currentRouteId != -1)
            {
                lbxRoutes.SelectedItem = (from TradeRoute r in lbxRoutes.Items
                                          where (r.id == currentRouteId)
                                          select r).FirstOrDefault();
            }
            else
            {
                lbxRoutes.ClearSelected();
            }
        }