diff --git a/NHSE.Sprites/Field/FieldItemSpriteDrawer.cs b/NHSE.Sprites/Field/FieldItemSpriteDrawer.cs index 8f22fa6..f61ae58 100644 --- a/NHSE.Sprites/Field/FieldItemSpriteDrawer.cs +++ b/NHSE.Sprites/Field/FieldItemSpriteDrawer.cs @@ -37,11 +37,10 @@ public Bitmap GetBitmapLayer(FieldItemLayer layer) return result; } - public Bitmap GetBitmapLayerAcre(FieldItemLayer layer, int x0, int y0) + private static int[] GetBitmapLayerAcre(FieldItemLayer layer, int x0, int y0, out int width, out int height) { - var items = layer.Tiles; - var height = layer.MapHeight; - var width = items.Length / height; + height = layer.GridWidth; + width = layer.GridWidth; var bmpData = new int[width * height]; var stride = layer.GridWidth; @@ -57,31 +56,23 @@ public Bitmap GetBitmapLayerAcre(FieldItemLayer layer, int x0, int y0) } } - var result = new Bitmap(width, height, PixelFormat.Format32bppArgb); - var bData = result.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); - Marshal.Copy(bmpData, 0, bData.Scan0, bmpData.Length); - result.UnlockBits(bData); - return result; + return bmpData; } public Bitmap GetBitmapLayerAcre(FieldItemLayer layer, int x0, int y0, int scale) { - var map = GetBitmapLayerAcre(layer, x0, y0); - map = ImageUtil.ResizeImage(map, map.Width * scale, map.Height * scale); - - // Obtain raw data - var bData = map.LockBits(new Rectangle(0, 0, map.Width, map.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); - var ptr = bData.Scan0; - var data = new int[map.Width * map.Height]; - Marshal.Copy(ptr, data, 0, data.Length); + var map = GetBitmapLayerAcre(layer, x0, y0, out int mh, out int mw); + var data = ImageUtil.ScalePixelImage(map, scale, mw, mh, out var fw, out var fh); // draw symbols over special items now? // Slap on a grid - var w = map.Width; - var h = map.Height; - const int grid = -0x1000000; // 0xFF000000u - for (int x = scale; x < w; x += scale) + var w = fw; + var h = fh; + const int grid = -0x777778; // 0xFF888888u + + // Horizontal Lines + for (int x = 0; x < w; x++) { for (int y = scale; y < h; y += scale) { @@ -90,10 +81,18 @@ public Bitmap GetBitmapLayerAcre(FieldItemLayer layer, int x0, int y0, int scale } } + // Vertical Lines + for (int y = 0; y < h; y++) + { + for (int x = scale; x < w; x += scale) + { + var index = (y * w) + x; + data[index] = grid; + } + } + // Return final data - Marshal.Copy(data, 0, ptr, data.Length); - map.UnlockBits(bData); - return map; + return ImageUtil.GetBitmap(data, fw, fh); } public Bitmap GetBitmapLayer(FieldItemLayer layer, int x, int y, int scale = 1) diff --git a/NHSE.WinForms/Subforms/FieldItemEditor.Designer.cs b/NHSE.WinForms/Subforms/FieldItemEditor.Designer.cs index 1c3a925..ca7d0fa 100644 --- a/NHSE.WinForms/Subforms/FieldItemEditor.Designer.cs +++ b/NHSE.WinForms/Subforms/FieldItemEditor.Designer.cs @@ -31,7 +31,6 @@ private void InitializeComponent() this.components = new System.ComponentModel.Container(); this.B_Cancel = new System.Windows.Forms.Button(); this.B_Save = new System.Windows.Forms.Button(); - this.FLP_Tile = new System.Windows.Forms.FlowLayoutPanel(); this.PG_Tile = new System.Windows.Forms.PropertyGrid(); this.CB_Acre = new System.Windows.Forms.ComboBox(); this.L_Acre = new System.Windows.Forms.Label(); @@ -55,16 +54,18 @@ private void InitializeComponent() this.NUD_Layer = new System.Windows.Forms.NumericUpDown(); this.label1 = new System.Windows.Forms.Label(); this.TT_Hover = new System.Windows.Forms.ToolTip(this.components); + this.PB_Acre = new System.Windows.Forms.PictureBox(); this.CM_Click.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.PB_Map)).BeginInit(); this.CM_Picture.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.NUD_Layer)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.PB_Acre)).BeginInit(); this.SuspendLayout(); // // B_Cancel // this.B_Cancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.B_Cancel.Location = new System.Drawing.Point(899, 787); + this.B_Cancel.Location = new System.Drawing.Point(876, 535); this.B_Cancel.Name = "B_Cancel"; this.B_Cancel.Size = new System.Drawing.Size(72, 23); this.B_Cancel.TabIndex = 7; @@ -75,7 +76,7 @@ private void InitializeComponent() // B_Save // this.B_Save.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.B_Save.Location = new System.Drawing.Point(977, 787); + this.B_Save.Location = new System.Drawing.Point(954, 535); this.B_Save.Name = "B_Save"; this.B_Save.Size = new System.Drawing.Size(72, 23); this.B_Save.TabIndex = 6; @@ -83,28 +84,20 @@ private void InitializeComponent() this.B_Save.UseVisualStyleBackColor = true; this.B_Save.Click += new System.EventHandler(this.B_Save_Click); // - // FLP_Tile - // - this.FLP_Tile.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.FLP_Tile.Location = new System.Drawing.Point(12, 12); - this.FLP_Tile.Name = "FLP_Tile"; - this.FLP_Tile.Size = new System.Drawing.Size(802, 802); - this.FLP_Tile.TabIndex = 8; - // // PG_Tile // this.PG_Tile.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.PG_Tile.Location = new System.Drawing.Point(820, 12); + this.PG_Tile.Location = new System.Drawing.Point(799, 12); this.PG_Tile.Name = "PG_Tile"; - this.PG_Tile.Size = new System.Drawing.Size(229, 244); + this.PG_Tile.Size = new System.Drawing.Size(229, 217); this.PG_Tile.TabIndex = 9; // // CB_Acre // this.CB_Acre.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.CB_Acre.FormattingEnabled = true; - this.CB_Acre.Location = new System.Drawing.Point(978, 598); + this.CB_Acre.Location = new System.Drawing.Point(733, 352); this.CB_Acre.Name = "CB_Acre"; this.CB_Acre.Size = new System.Drawing.Size(49, 21); this.CB_Acre.TabIndex = 10; @@ -113,7 +106,7 @@ private void InitializeComponent() // L_Acre // this.L_Acre.AutoSize = true; - this.L_Acre.Location = new System.Drawing.Point(940, 601); + this.L_Acre.Location = new System.Drawing.Point(695, 355); this.L_Acre.Name = "L_Acre"; this.L_Acre.Size = new System.Drawing.Size(32, 13); this.L_Acre.TabIndex = 11; @@ -121,7 +114,7 @@ private void InitializeComponent() // // B_DumpAcre // - this.B_DumpAcre.Location = new System.Drawing.Point(820, 672); + this.B_DumpAcre.Location = new System.Drawing.Point(565, 472); this.B_DumpAcre.Name = "B_DumpAcre"; this.B_DumpAcre.Size = new System.Drawing.Size(112, 40); this.B_DumpAcre.TabIndex = 14; @@ -131,7 +124,7 @@ private void InitializeComponent() // // B_DumpAllAcres // - this.B_DumpAllAcres.Location = new System.Drawing.Point(820, 718); + this.B_DumpAllAcres.Location = new System.Drawing.Point(565, 518); this.B_DumpAllAcres.Name = "B_DumpAllAcres"; this.B_DumpAllAcres.Size = new System.Drawing.Size(112, 40); this.B_DumpAllAcres.TabIndex = 15; @@ -141,7 +134,7 @@ private void InitializeComponent() // // B_ImportAllAcres // - this.B_ImportAllAcres.Location = new System.Drawing.Point(937, 718); + this.B_ImportAllAcres.Location = new System.Drawing.Point(682, 518); this.B_ImportAllAcres.Name = "B_ImportAllAcres"; this.B_ImportAllAcres.Size = new System.Drawing.Size(112, 40); this.B_ImportAllAcres.TabIndex = 17; @@ -151,7 +144,7 @@ private void InitializeComponent() // // B_ImportAcre // - this.B_ImportAcre.Location = new System.Drawing.Point(937, 672); + this.B_ImportAcre.Location = new System.Drawing.Point(682, 472); this.B_ImportAcre.Name = "B_ImportAcre"; this.B_ImportAcre.Size = new System.Drawing.Size(112, 40); this.B_ImportAcre.TabIndex = 16; @@ -191,7 +184,7 @@ private void InitializeComponent() // // B_Up // - this.B_Up.Location = new System.Drawing.Point(868, 561); + this.B_Up.Location = new System.Drawing.Point(623, 315); this.B_Up.Name = "B_Up"; this.B_Up.Size = new System.Drawing.Size(32, 32); this.B_Up.TabIndex = 18; @@ -201,7 +194,7 @@ private void InitializeComponent() // // B_Left // - this.B_Left.Location = new System.Drawing.Point(838, 591); + this.B_Left.Location = new System.Drawing.Point(593, 345); this.B_Left.Name = "B_Left"; this.B_Left.Size = new System.Drawing.Size(32, 32); this.B_Left.TabIndex = 19; @@ -211,7 +204,7 @@ private void InitializeComponent() // // B_Right // - this.B_Right.Location = new System.Drawing.Point(898, 591); + this.B_Right.Location = new System.Drawing.Point(653, 345); this.B_Right.Name = "B_Right"; this.B_Right.Size = new System.Drawing.Size(32, 32); this.B_Right.TabIndex = 20; @@ -221,7 +214,7 @@ private void InitializeComponent() // // B_Down // - this.B_Down.Location = new System.Drawing.Point(868, 621); + this.B_Down.Location = new System.Drawing.Point(623, 375); this.B_Down.Name = "B_Down"; this.B_Down.Size = new System.Drawing.Size(32, 32); this.B_Down.TabIndex = 22; @@ -233,7 +226,7 @@ private void InitializeComponent() // this.PB_Map.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.PB_Map.ContextMenuStrip = this.CM_Picture; - this.PB_Map.Location = new System.Drawing.Point(821, 343); + this.PB_Map.Location = new System.Drawing.Point(565, 35); this.PB_Map.Name = "PB_Map"; this.PB_Map.Size = new System.Drawing.Size(226, 194); this.PB_Map.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; @@ -262,7 +255,7 @@ private void InitializeComponent() this.CHK_SnapToAcre.AutoSize = true; this.CHK_SnapToAcre.Checked = true; this.CHK_SnapToAcre.CheckState = System.Windows.Forms.CheckState.Checked; - this.CHK_SnapToAcre.Location = new System.Drawing.Point(820, 320); + this.CHK_SnapToAcre.Location = new System.Drawing.Point(564, 12); this.CHK_SnapToAcre.Name = "CHK_SnapToAcre"; this.CHK_SnapToAcre.Size = new System.Drawing.Size(167, 17); this.CHK_SnapToAcre.TabIndex = 24; @@ -272,7 +265,7 @@ private void InitializeComponent() // L_Coordinates // this.L_Coordinates.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.L_Coordinates.Location = new System.Drawing.Point(876, 540); + this.L_Coordinates.Location = new System.Drawing.Point(620, 232); this.L_Coordinates.Name = "L_Coordinates"; this.L_Coordinates.Size = new System.Drawing.Size(173, 15); this.L_Coordinates.TabIndex = 25; @@ -281,7 +274,7 @@ private void InitializeComponent() // // NUD_Layer // - this.NUD_Layer.Location = new System.Drawing.Point(978, 625); + this.NUD_Layer.Location = new System.Drawing.Point(733, 379); this.NUD_Layer.Maximum = new decimal(new int[] { 2, 0, @@ -304,7 +297,7 @@ private void InitializeComponent() // // label1 // - this.label1.Location = new System.Drawing.Point(919, 626); + this.label1.Location = new System.Drawing.Point(674, 380); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(53, 19); this.label1.TabIndex = 27; @@ -315,11 +308,24 @@ private void InitializeComponent() // this.TT_Hover.AutomaticDelay = 100; // + // PB_Acre + // + this.PB_Acre.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.PB_Acre.ContextMenuStrip = this.CM_Click; + this.PB_Acre.Location = new System.Drawing.Point(12, 12); + this.PB_Acre.Name = "PB_Acre"; + this.PB_Acre.Size = new System.Drawing.Size(546, 546); + this.PB_Acre.TabIndex = 28; + this.PB_Acre.TabStop = false; + this.PB_Acre.MouseClick += new System.Windows.Forms.MouseEventHandler(this.PB_Acre_MouseClick); + this.PB_Acre.MouseMove += new System.Windows.Forms.MouseEventHandler(this.PB_Acre_MouseMove); + // // FieldItemEditor // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1061, 822); + this.ClientSize = new System.Drawing.Size(1037, 570); + this.Controls.Add(this.PB_Acre); this.Controls.Add(this.label1); this.Controls.Add(this.NUD_Layer); this.Controls.Add(this.L_Coordinates); @@ -336,7 +342,6 @@ private void InitializeComponent() this.Controls.Add(this.L_Acre); this.Controls.Add(this.CB_Acre); this.Controls.Add(this.PG_Tile); - this.Controls.Add(this.FLP_Tile); this.Controls.Add(this.B_Cancel); this.Controls.Add(this.B_Save); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; @@ -350,6 +355,7 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.PB_Map)).EndInit(); this.CM_Picture.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.NUD_Layer)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.PB_Acre)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -359,7 +365,6 @@ private void InitializeComponent() private System.Windows.Forms.Button B_Cancel; private System.Windows.Forms.Button B_Save; - private System.Windows.Forms.FlowLayoutPanel FLP_Tile; private System.Windows.Forms.PropertyGrid PG_Tile; private System.Windows.Forms.ComboBox CB_Acre; private System.Windows.Forms.Label L_Acre; @@ -383,5 +388,6 @@ private void InitializeComponent() private System.Windows.Forms.NumericUpDown NUD_Layer; private System.Windows.Forms.Label label1; private System.Windows.Forms.ToolTip TT_Hover; + private System.Windows.Forms.PictureBox PB_Acre; } } \ No newline at end of file diff --git a/NHSE.WinForms/Subforms/FieldItemEditor.cs b/NHSE.WinForms/Subforms/FieldItemEditor.cs index e61c6ea..286ab32 100644 --- a/NHSE.WinForms/Subforms/FieldItemEditor.cs +++ b/NHSE.WinForms/Subforms/FieldItemEditor.cs @@ -1,5 +1,4 @@ using System; -using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Windows.Forms; @@ -11,14 +10,10 @@ namespace NHSE.WinForms public partial class FieldItemEditor : Form { private readonly MainSave SAV; - private readonly Button[] Grid; private readonly FieldItemManager Items; - private int GridWidth => Items.Layer1.GridWidth; - private int GridHeight => Items.Layer1.GridHeight; - - private const int SquareSize = 25; private const int MapScale = 1; + private const int AcreScale = 17; public FieldItemEditor(MainSave sav) { @@ -26,14 +21,13 @@ public FieldItemEditor(MainSave sav) InitializeComponent(); Items = new FieldItemManager(SAV.GetFieldItems()); - Grid = GenerateGrid(GridWidth, GridHeight); foreach (var acre in MapGrid.Acres) CB_Acre.Items.Add(acre.Name); PG_Tile.SelectedObject = new FieldItem(); CB_Acre.SelectedIndex = 0; - ReloadMap(); + LoadGrid(X, Y); } private int X; @@ -47,7 +41,6 @@ private void ChangeViewToAcre(int acre) { Items.Layer1.GetViewAnchorCoordinates(acre, out X, out Y); LoadGrid(X, Y); - UpdateArrowVisibility(acre); } private FieldItemLayer Layer => NUD_Layer.Value == 1 ? Items.Layer1 : Items.Layer2; @@ -59,84 +52,59 @@ private void ReloadMap() private void LoadGrid(int topX, int topY) { - var layer = Layer; - for (int x = 0; x < GridWidth; x++) - { - for (int y = 0; y < GridHeight; y++) - { - var controlIndex = (y * GridWidth) + x; - var b = Grid[controlIndex]; - - var rx = topX + x; - var ry = topY + y; - var tile = layer.GetTile(rx, ry); - RefreshTile(b, tile); - } - } + ReloadGrid(Layer, topX, topY); + UpdateArrowVisibility(); ReloadMap(); } - private void UpdateArrowVisibility(int index) + private void ReloadGrid(FieldItemLayer layer, int topX, int topY) { - B_Up.Enabled = index >= MapGrid.AcreWidth; - B_Down.Enabled = index < MapGrid.AcreWidth * (MapGrid.AcreHeight - 1); - B_Left.Enabled = index % MapGrid.AcreWidth != 0; - B_Right.Enabled = index % MapGrid.AcreWidth != MapGrid.AcreWidth - 1; + PB_Acre.Image = SpriteUtil.FieldItems.GetBitmapLayerAcre(layer, topX, topY, AcreScale); } - private Button[] GenerateGrid(int w, int h) + private void UpdateArrowVisibility() { - var grid = new Button[w * h]; - int i = 0; - for (int y = 0; y < h; y++) - { - for (int x = 0; x < w; x++) - { - var item = CreateGridItem(index: i, x, y); - FLP_Tile.Controls.Add(item); - grid[i++] = item; - } + B_Up.Enabled = Y != 0; + B_Down.Enabled = Y < Layer.MapHeight - Layer.GridHeight; + B_Left.Enabled = X != 0; + B_Right.Enabled = X < Layer.MapWidth - Layer.GridWidth; + } - var last = grid[i - 1]; - FLP_Tile.SetFlowBreak(last, true); + private void PB_Acre_MouseClick(object sender, MouseEventArgs e) + { + var tile = GetTile(Layer, e); + switch (ModifierKeys) + { + default: ViewTile(tile); return; + case Keys.Shift: SetTile(tile); return; + case Keys.Alt: DeleteTile(tile); return; } - - return grid; } - private Button CreateGridItem(int index, int x, int y) + private int HoverX; + private int HoverY; + + private FieldItem GetTile(FieldItemLayer layer, MouseEventArgs e) { - var button = new Button - { - Name = index.ToString(), - Text = $"{index:000} ({x},{y})", - Size = new Size(SquareSize, SquareSize), - Padding = Padding.Empty, - Margin = Padding.Empty, - ContextMenuStrip = CM_Click, - FlatStyle = FlatStyle.Flat, - }; + SetHoveredItem(e); + return layer.GetTile(X + HoverX, Y + HoverY); + } - button.Click += (sender, args) => - { - var tile = GetTile(Layer, index); - switch (ModifierKeys) - { - default: ViewTile(tile); return; - case Keys.Shift: SetTile(tile, button); return; - case Keys.Alt: DeleteTile(tile, button); return; - } - }; - button.MouseEnter += (sender, args) => - { - var tile = GetTile(Layer, index); - var str = GameInfo.Strings; - var name = str.GetItemName(tile.DisplayItemId); - TT_Hover.SetToolTip(button, name); - }; - button.MouseLeave += (sender, args) => TT_Hover.RemoveAll(); + private void SetHoveredItem(MouseEventArgs e) + { + HoverX = e.X / AcreScale; + HoverY = e.Y / AcreScale; + } - return button; + private void PB_Acre_MouseMove(object sender, MouseEventArgs e) + { + var oldTile = Layer.GetTile(X + HoverX, Y + HoverY); + var tile = GetTile(Layer, e); + if (tile == oldTile) + return; + var str = GameInfo.Strings; + var name = str.GetItemName(tile.DisplayItemId); + TT_Hover.SetToolTip(PB_Acre, name); } private void ViewTile(FieldItem tile) @@ -146,18 +114,18 @@ private void ViewTile(FieldItem tile) PG_Tile.SelectedObject = pgt; } - private void SetTile(FieldItem tile, Control obj) + private void SetTile(FieldItem tile) { var pgt = (FieldItem)PG_Tile.SelectedObject; tile.CopyFrom(pgt); - RefreshTile(obj, tile); + ReloadGrid(Layer, X, Y); ReloadMap(); } - private void DeleteTile(FieldItem tile, Control obj) + private void DeleteTile(FieldItem tile) { tile.Delete(); - RefreshTile(obj, tile); + ReloadGrid(Layer, X, Y); ReloadMap(); } @@ -172,50 +140,69 @@ private void B_Save_Click(object sender, EventArgs e) private void Menu_View_Click(object sender, EventArgs e) { - GetTile(sender, out var tile, out _); + var tile = Layer.GetTile(X + HoverX, Y + HoverY); ViewTile(tile); } private void Menu_Set_Click(object sender, EventArgs e) { - GetTile(sender, out var tile, out var obj); - SetTile(tile, obj); + var tile = Layer.GetTile(X + HoverX, Y + HoverY); + SetTile(tile); } private void Menu_Reset_Click(object sender, EventArgs e) { - GetTile(sender, out var tile, out var obj); - DeleteTile(tile, obj); + var tile = Layer.GetTile(X + HoverX, Y + HoverY); + DeleteTile(tile); } - private void GetTile(object sender, out FieldItem tile, out Button obj) + private void B_Up_Click(object sender, EventArgs e) { - obj = WinFormsUtil.GetUnderlyingControl