diff --git a/inf3.csproj b/inf3.csproj index eb5c186..534cde3 100644 --- a/inf3.csproj +++ b/inf3.csproj @@ -9,27 +9,26 @@ Exe inf3 inf3 - v4.0 - True + true full - False + false bin\Debug DEBUG; prompt 4 x86 - False + false none - True + true bin\Release prompt 4 x86 - False + false @@ -80,6 +79,7 @@ + diff --git a/src/Gui/Gui.cs b/src/Gui/Gui.cs index 7cae48f..e1ea5b7 100644 --- a/src/Gui/Gui.cs +++ b/src/Gui/Gui.cs @@ -8,12 +8,10 @@ namespace WorldOfPeacecraft { class Gui : Form, IGui { - private const int TileSize = 32; - private const int EntitySize = 10; private const int ChatWidth = 300; private IBackend Backend; - private Panel Board = new Panel(); + private MapPanel MapPanel; private ChatPanel ChatPanel; public Gui () @@ -36,11 +34,11 @@ namespace WorldOfPeacecraft public void InitializeComponents () { ChatPanel = new ChatPanel (Backend); + MapPanel = new MapPanel (Backend); this.SuspendLayout(); this.Size = new Size(400 + ChatWidth, 400); - Board.Location = new Point(0,0); - Board.Size = new Size(400, 400); - Board.Paint += DoPaint; + MapPanel.Location = new Point(0,0); + MapPanel.Size = new Size(400, 400); ChatPanel.Location = new Point (400, 0); ChatPanel.Size = new Size (300, 400); this.DoubleBuffered = true; @@ -49,7 +47,7 @@ namespace WorldOfPeacecraft this.Name = "WorldOfPeacecraft"; this.ShowIcon = false; - this.Controls.Add (Board); + this.Controls.Add (MapPanel); this.Controls.Add (ChatPanel); this.ResumeLayout(); @@ -61,89 +59,15 @@ namespace WorldOfPeacecraft Backend.Stop (); } - public void DoPaint (object source, PaintEventArgs args) - { - BufferedGraphics buffer = BufferedGraphicsManager.Current.Allocate (Board.CreateGraphics (), Board.DisplayRectangle); - Graphics g = buffer.Graphics; - lock (Backend) { - PaintMap (g); - PaintEntities (g); - } - buffer.Render(); - } - - public void PaintMap (Graphics g) - { - ITile[,] map = Backend.GetMap (); - if (map != null) { - for (int y = 0; y < map.GetLength(1); y++) { - for (int x = 0; x < map.GetLength(0); x++) { - PaintTile (g, map [x, y], x, y); - } - } - } - else { - g.FillRectangle(new SolidBrush(Color.White), Board.DisplayRectangle); - } - } - - public void PaintTile (Graphics g, ITile tile, int x, int y) - { - int posx = x * TileSize; - int posy = y * TileSize; - Color color; - if (tile.IsHuntable ()) { - color = Color.DarkGreen; - } // Stupid parenthesis - else if (tile.IsForest ()) { - color = Color.Green; - } else if (tile.IsWater ()) { - color = Color.Blue; - } else if (tile.IsWalkable ()) { - color = Color.Yellow; - } else if (tile.IsWall ()) { - color = Color.DarkGray; - } else { - color = Color.Black; - } - g.FillRectangle(new SolidBrush(color), posx, posy, TileSize, TileSize); - } - - public void PaintEntities (Graphics g) - { - IEnumerable dragons = Backend.GetDragons (); - IEnumerable players = Backend.GetPlayers (); - foreach (IPositionable dragon in dragons) { - PaintEntity (g, dragon); - } - foreach (IPositionable player in players) { - PaintEntity (g, player); - } - } - - public void PaintEntity (Graphics g, IPositionable entity) - { - int x = entity.GetX () * TileSize + TileSize / 2 - EntitySize / 2; - int y = entity.GetY () * TileSize + TileSize / 2 - EntitySize / 2; - g.FillRectangle (new SolidBrush (Color.Red), x, y, EntitySize, EntitySize); - g.DrawRectangle (new Pen( new SolidBrush (Color.Black)), x, y, EntitySize, EntitySize); - } - public void PerformRefresh () { this.BeginInvoke(new MethodInvoker(delegate { - ITile[,] map = Backend.GetMap(); - if (map == null) { - return; - } - int mapWidth = (map.GetLength(0)) * TileSize; - int mapHeight = (map.GetLength(1)) * TileSize; + MapPanel.PerformLayout (); this.SuspendLayout(); - this.SetClientSizeCore(mapWidth + ChatWidth, mapHeight); - Board.Size = new Size(mapWidth, mapHeight); - ChatPanel.Location = new Point (mapWidth, 0); - ChatPanel.Size = new Size (ChatWidth, mapHeight); + this.SetClientSizeCore(MapPanel.Width + ChatWidth, MapPanel.Height); + ChatPanel.Location = new Point (MapPanel.Width, 0); + ChatPanel.Size = new Size (ChatWidth, MapPanel.Height); this.ResumeLayout(); this.PerformLayout(); ChatPanel.UpdateData (); diff --git a/src/Gui/MapPanel.cs b/src/Gui/MapPanel.cs new file mode 100644 index 0000000..3e9e9d0 --- /dev/null +++ b/src/Gui/MapPanel.cs @@ -0,0 +1,99 @@ +using System.Collections.Generic; +using System.Drawing; +using System.Windows.Forms; + +namespace WorldOfPeacecraft +{ + public class MapPanel : Panel + { + private const int TileSize = 32; + private const int EntitySize = 10; + private IBackend Backend; + + public MapPanel (IBackend backend) + { + Backend = backend; + this.Paint += DoPaint; + } + + protected override void OnLayout (LayoutEventArgs levent) + { + ITile[,] map = Backend.GetMap (); + if (map != null) { + int mapWidth = (map.GetLength(0)) * TileSize; + int mapHeight = (map.GetLength(1)) * TileSize; + this.SetClientSizeCore(mapWidth, mapHeight); + } + base.OnLayout (levent); + } + + public void DoPaint (object source, PaintEventArgs args) + { + BufferedGraphics buffer = BufferedGraphicsManager.Current.Allocate (this.CreateGraphics (), this.DisplayRectangle); + Graphics g = buffer.Graphics; + lock (Backend) { + PaintMap (g); + PaintEntities (g); + } + buffer.Render(); + } + + public void PaintMap (Graphics g) + { + ITile[,] map = Backend.GetMap (); + if (map != null) { + for (int y = 0; y < map.GetLength(1); y++) { + for (int x = 0; x < map.GetLength(0); x++) { + PaintTile (g, map [x, y], x, y); + } + } + } + else { + g.FillRectangle(new SolidBrush(Color.White), this.DisplayRectangle); + } + } + + public void PaintTile (Graphics g, ITile tile, int x, int y) + { + int posx = x * TileSize; + int posy = y * TileSize; + Color color; + if (tile.IsHuntable ()) { + color = Color.DarkGreen; + } // Stupid parenthesis + else if (tile.IsForest ()) { + color = Color.Green; + } else if (tile.IsWater ()) { + color = Color.Blue; + } else if (tile.IsWalkable ()) { + color = Color.Yellow; + } else if (tile.IsWall ()) { + color = Color.DarkGray; + } else { + color = Color.Black; + } + g.FillRectangle(new SolidBrush(color), posx, posy, TileSize, TileSize); + } + + public void PaintEntities (Graphics g) + { + IEnumerable dragons = Backend.GetDragons (); + IEnumerable players = Backend.GetPlayers (); + foreach (IPositionable dragon in dragons) { + PaintEntity (g, dragon); + } + foreach (IPositionable player in players) { + PaintEntity (g, player); + } + } + + public void PaintEntity (Graphics g, IPositionable entity) + { + int x = entity.GetX () * TileSize + TileSize / 2 - EntitySize / 2; + int y = entity.GetY () * TileSize + TileSize / 2 - EntitySize / 2; + g.FillRectangle (new SolidBrush (Color.Red), x, y, EntitySize, EntitySize); + g.DrawRectangle (new Pen( new SolidBrush (Color.Black)), x, y, EntitySize, EntitySize); + } + } +} +