private void GameChanged() { if (Game.SelectedUnit != null && Game.SelectedUnit != _LastSelectedUnit) { if (Game.SelectedUnit.Player == Game.CurrentPlayer && CurrentOrder != Order.Move) { if (Game.SelectedUnit != null && Game.SelectedUnit.Type.Abilities.Contains(Order.Move)) { CurrentOrder = Order.Move; } } } _LastSelectedUnit = Game.SelectedUnit; if (CurrentOrder == Order.SearchMines) { _ToolTip.Show(Game.SearchMines(Game.SelectedUnit).ToString() + " mine(s) found.", this, MapToDisplay(Game.SelectedUnit.Position), 2000); CurrentOrder = null; } Invalidate(); OrdersDisplay.GameChanged(); }
protected override void OnPaint(PaintEventArgs pe) { if (Game == null) { return; } var USACounter = Bitmaps.Get("Data\\USACounter.png"); var germanyCounter = Bitmaps.Get("Data\\GermanyCounter.png"); var japanCounter = Bitmaps.Get("Data\\JapanCounter.png"); var englandCounter = Bitmaps.Get("Data\\EnglandCounter.png"); var neutralCounter = Bitmaps.Get("Data\\NeutralCounter.png"); var selected = Bitmaps.Get("Data\\Selected.png"); DrawMap(pe.Graphics); // Draw Mines foreach (Mine mine in Game.Mines) { Point displayPos = MapToDisplay(mine.Position); if (mine.IsVisible || Game.CurrentPlayer != null && Game.CurrentPlayer.Faction == mine.Faction) { if (displayPos.X > -CameraScale || displayPos.Y > -CameraScale) { if (displayPos.X < Width + CameraScale || displayPos.Y < Height + CameraScale) { Rectangle counterRect = new Rectangle(displayPos, new Size(CameraScale, CameraScale)); counterRect.Inflate(0 - counterRect.Width / 5, 0 - counterRect.Height / 5); switch (mine.Faction) { case Faction.USA: pe.Graphics.DrawImage(USACounter, counterRect); break; case Faction.Germany: pe.Graphics.DrawImage(germanyCounter, counterRect); break; case Faction.Japan: pe.Graphics.DrawImage(japanCounter, counterRect); break; case Faction.England: pe.Graphics.DrawImage(englandCounter, counterRect); break; case Faction.Neutral: pe.Graphics.DrawImage(neutralCounter, counterRect); break; } pe.Graphics.DrawImage(Bitmaps.Get("Data\\Mine.png"), counterRect); } } } } // Draw Units if (Game.CurrentPlayer != null) { foreach (Unit unit in Game.Units) { if (Game.IsUnitVisibleForPlayer(Game.CurrentPlayer, unit) || unit.Type.AlwaysVisible) { Point displayPos = MapToDisplay(unit.Position); if (displayPos.X > -CameraScale || displayPos.Y > -CameraScale) { if (displayPos.X < Width + CameraScale || displayPos.Y < Height + CameraScale) { switch (unit.Player.Faction) { case Faction.USA: pe.Graphics.DrawImage(USACounter, new Rectangle(displayPos, new Size(CameraScale, CameraScale))); break; case Faction.Germany: pe.Graphics.DrawImage(germanyCounter, new Rectangle(displayPos, new Size(CameraScale, CameraScale))); break; case Faction.Japan: pe.Graphics.DrawImage(japanCounter, new Rectangle(displayPos, new Size(CameraScale, CameraScale))); break; case Faction.England: pe.Graphics.DrawImage(englandCounter, new Rectangle(displayPos, new Size(CameraScale, CameraScale))); break; case Faction.Neutral: pe.Graphics.DrawImage(neutralCounter, new Rectangle(displayPos, new Size(CameraScale, CameraScale))); break; } pe.Graphics.DrawImage(unit.Type.Bitmap, new Rectangle(new Point(displayPos.X, displayPos.Y), new Size(CameraScale, CameraScale))); RectangleF stringRectangle = new RectangleF(new Point(displayPos.X, displayPos.Y), new Size(CameraScale, CameraScale)); stringRectangle.Inflate(-0.1f * CameraScale, -0.1f * CameraScale); StringFormat bottomStringFormat = new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Far }; Font nameFont = GetFontFromSize(stringRectangle.Width, unit.Name, 0.1f * CameraScale, 0.16f * CameraScale, pe.Graphics); pe.Graphics.DrawString(unit.Name, nameFont, Brushes.Black, stringRectangle, bottomStringFormat); if (!string.IsNullOrEmpty(unit.Information)) { StringFormat topStringFormat = new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Near, }; Font infoFont = GetFontFromSize(stringRectangle.Width, unit.Information, 0.1f * CameraScale, nameFont.Size, pe.Graphics); pe.Graphics.DrawString(unit.Information, infoFont, Brushes.Black, stringRectangle, topStringFormat); } if (Game.SelectedUnit == unit) { Rectangle rectangle = new Rectangle(displayPos, new Size(CameraScale, CameraScale)); rectangle.Inflate((int)Math.Round(CameraScale / 16f), (int)Math.Round(CameraScale / 16f)); pe.Graphics.DrawImage(selected, rectangle); } if (unit.MovesLeft >= 1) { Rectangle rectangle = new Rectangle(displayPos.X, displayPos.Y, CameraScale / 8, CameraScale / 8); pe.Graphics.FillEllipse(Brushes.White, rectangle); pe.Graphics.DrawEllipse(Pens.Black, rectangle); } } } } } } OrdersDisplay.Invalidate(); }