From 6ae1c9724b891fbd047deb2d50b4b1b63793c77c Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 10 May 2020 14:13:45 -0700 Subject: [PATCH] add click-drag on acre picturebox to move the viewport hold control to drag the viewport faster does not move items; that would probably have to be a toggle -- if ever implemented --- NHSE.Core/Structures/Misc/MapView.cs | 11 ++- .../Subforms/Map/FieldItemEditor.Designer.cs | 59 +++++++------- NHSE.WinForms/Subforms/Map/FieldItemEditor.cs | 79 ++++++++++++++++++- 3 files changed, 113 insertions(+), 36 deletions(-) diff --git a/NHSE.Core/Structures/Misc/MapView.cs b/NHSE.Core/Structures/Misc/MapView.cs index 1fb0d2d..0b9508b 100644 --- a/NHSE.Core/Structures/Misc/MapView.cs +++ b/NHSE.Core/Structures/Misc/MapView.cs @@ -54,10 +54,15 @@ public bool ArrowDown() return true; } - public void SetViewTo(in int x, in int y) + public bool SetViewTo(in int x, in int y) { - X = x; - Y = y; + var info = Map.CurrentLayer; + var newX = Math.Max(0, Math.Min(x, info.MapWidth - info.GridWidth)); + var newY = Math.Max(0, Math.Min(y, info.MapHeight - info.GridHeight)); + bool diff = X != newX || Y != newY; + X = newX; + Y = newY; + return diff; } public void SetViewToAcre(in int acre) diff --git a/NHSE.WinForms/Subforms/Map/FieldItemEditor.Designer.cs b/NHSE.WinForms/Subforms/Map/FieldItemEditor.Designer.cs index 8a83d52..92ce240 100644 --- a/NHSE.WinForms/Subforms/Map/FieldItemEditor.Designer.cs +++ b/NHSE.WinForms/Subforms/Map/FieldItemEditor.Designer.cs @@ -45,6 +45,8 @@ private void InitializeComponent() this.PB_Map = new System.Windows.Forms.PictureBox(); this.CM_Picture = new System.Windows.Forms.ContextMenuStrip(this.components); this.Menu_SavePNG = new System.Windows.Forms.ToolStripMenuItem(); + this.Menu_SavePNGItems = new System.Windows.Forms.ToolStripMenuItem(); + this.Menu_SavePNGTerrain = new System.Windows.Forms.ToolStripMenuItem(); this.CHK_SnapToAcre = new System.Windows.Forms.CheckBox(); this.L_Coordinates = new System.Windows.Forms.Label(); this.NUD_Layer = new System.Windows.Forms.NumericUpDown(); @@ -69,6 +71,7 @@ private void InitializeComponent() this.GB_Remove = new System.Windows.Forms.Label(); this.TC_Editor = new System.Windows.Forms.TabControl(); this.Tab_Item = new System.Windows.Forms.TabPage(); + this.ItemEdit = new NHSE.WinForms.ItemEditor(); this.B_DumpLoadField = new System.Windows.Forms.Button(); this.CM_DLField = new System.Windows.Forms.ContextMenuStrip(this.components); this.B_DumpAcre = new System.Windows.Forms.ToolStripMenuItem(); @@ -134,9 +137,6 @@ private void InitializeComponent() this.RB_Item = new System.Windows.Forms.RadioButton(); this.RB_Terrain = new System.Windows.Forms.RadioButton(); this.L_TileMode = new System.Windows.Forms.Label(); - this.Menu_SavePNGItems = new System.Windows.Forms.ToolStripMenuItem(); - this.Menu_SavePNGTerrain = new System.Windows.Forms.ToolStripMenuItem(); - this.ItemEdit = new NHSE.WinForms.ItemEditor(); this.CHK_RedirectExtensionLoad = new System.Windows.Forms.CheckBox(); this.CM_Click.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.PB_Map)).BeginInit(); @@ -312,6 +312,24 @@ private void InitializeComponent() this.Menu_SavePNG.Text = "Save .png"; this.Menu_SavePNG.Click += new System.EventHandler(this.Menu_SavePNG_Click); // + // Menu_SavePNGItems + // + this.Menu_SavePNGItems.Checked = true; + this.Menu_SavePNGItems.CheckOnClick = true; + this.Menu_SavePNGItems.CheckState = System.Windows.Forms.CheckState.Checked; + this.Menu_SavePNGItems.Name = "Menu_SavePNGItems"; + this.Menu_SavePNGItems.Size = new System.Drawing.Size(151, 22); + this.Menu_SavePNGItems.Text = "Include Items"; + // + // Menu_SavePNGTerrain + // + this.Menu_SavePNGTerrain.Checked = true; + this.Menu_SavePNGTerrain.CheckOnClick = true; + this.Menu_SavePNGTerrain.CheckState = System.Windows.Forms.CheckState.Checked; + this.Menu_SavePNGTerrain.Name = "Menu_SavePNGTerrain"; + this.Menu_SavePNGTerrain.Size = new System.Drawing.Size(151, 22); + this.Menu_SavePNGTerrain.Text = "Include Terrain"; + // // CHK_SnapToAcre // this.CHK_SnapToAcre.AutoSize = true; @@ -378,6 +396,7 @@ private void InitializeComponent() 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.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PB_Acre_MouseDown); this.PB_Acre.MouseMove += new System.Windows.Forms.MouseEventHandler(this.PB_Acre_MouseMove); // // TR_Transparency @@ -549,6 +568,14 @@ private void InitializeComponent() this.Tab_Item.Text = "Items"; this.Tab_Item.UseVisualStyleBackColor = true; // + // ItemEdit + // + this.ItemEdit.Dock = System.Windows.Forms.DockStyle.Top; + this.ItemEdit.Location = new System.Drawing.Point(3, 3); + this.ItemEdit.Name = "ItemEdit"; + this.ItemEdit.Size = new System.Drawing.Size(238, 390); + this.ItemEdit.TabIndex = 40; + // // B_DumpLoadField // this.B_DumpLoadField.ContextMenuStrip = this.CM_DLField; @@ -1238,32 +1265,6 @@ private void InitializeComponent() this.L_TileMode.Text = "Tile Editor Mode"; this.L_TileMode.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // - // Menu_SavePNGItems - // - this.Menu_SavePNGItems.Checked = true; - this.Menu_SavePNGItems.CheckOnClick = true; - this.Menu_SavePNGItems.CheckState = System.Windows.Forms.CheckState.Checked; - this.Menu_SavePNGItems.Name = "Menu_SavePNGItems"; - this.Menu_SavePNGItems.Size = new System.Drawing.Size(151, 22); - this.Menu_SavePNGItems.Text = "Include Items"; - // - // Menu_SavePNGTerrain - // - this.Menu_SavePNGTerrain.Checked = true; - this.Menu_SavePNGTerrain.CheckOnClick = true; - this.Menu_SavePNGTerrain.CheckState = System.Windows.Forms.CheckState.Checked; - this.Menu_SavePNGTerrain.Name = "Menu_SavePNGTerrain"; - this.Menu_SavePNGTerrain.Size = new System.Drawing.Size(151, 22); - this.Menu_SavePNGTerrain.Text = "Include Terrain"; - // - // ItemEdit - // - this.ItemEdit.Dock = System.Windows.Forms.DockStyle.Top; - this.ItemEdit.Location = new System.Drawing.Point(3, 3); - this.ItemEdit.Name = "ItemEdit"; - this.ItemEdit.Size = new System.Drawing.Size(238, 390); - this.ItemEdit.TabIndex = 40; - // // CHK_RedirectExtensionLoad // this.CHK_RedirectExtensionLoad.AutoSize = true; diff --git a/NHSE.WinForms/Subforms/Map/FieldItemEditor.cs b/NHSE.WinForms/Subforms/Map/FieldItemEditor.cs index b3438ae..cf5a2e0 100644 --- a/NHSE.WinForms/Subforms/Map/FieldItemEditor.cs +++ b/NHSE.WinForms/Subforms/Map/FieldItemEditor.cs @@ -19,6 +19,9 @@ public sealed partial class FieldItemEditor : Form private int HoverX; private int HoverY; + private int DragX = -1; + private int DragY = -1; + private bool Dragging; public FieldItemEditor(MainSave sav) { @@ -135,12 +138,25 @@ private void UpdateArrowVisibility() private void PB_Acre_MouseClick(object sender, MouseEventArgs e) { + if (Dragging) + { + ResetDrag(); + return; + } + if (RB_Item.Checked) OmniTile(e); else if (RB_Terrain.Checked) OmniTileTerrain(e); } + private void ResetDrag() + { + DragX = -1; + DragY = -1; + Dragging = false; + } + private void OmniTile(MouseEventArgs e) { var tile = GetTile(Map.CurrentLayer, e, out var x, out var y); @@ -196,14 +212,30 @@ private Item GetTile(FieldItemLayer layer, MouseEventArgs e, out int x, out int private void SetHoveredItem(MouseEventArgs e) { + GetAcreCoordinates(e, out HoverX, out HoverY); + // Mouse event may fire with a slightly too large x/y; clamp just in case. - HoverX = (e.X / View.AcreScale) & 0x1F; - HoverY = (e.Y / View.AcreScale) & 0x1F; + HoverX &= 0x1F; + HoverY &= 0x1F; } + private void GetAcreCoordinates(MouseEventArgs e, out int x, out int y) + { + x = e.X / View.AcreScale; + y = e.Y / View.AcreScale; + } + + private void PB_Acre_MouseDown(object sender, MouseEventArgs e) => ResetDrag(); + private void PB_Acre_MouseMove(object sender, MouseEventArgs e) { var l = Map.CurrentLayer; + if (e.Button == MouseButtons.Left) + { + MoveDrag(e); + return; + } + var oldTile = l.GetTile(View.X + HoverX, View.Y + HoverY); var tile = GetTile(l, e, out var x, out var y); if (tile == oldTile) @@ -214,6 +246,45 @@ private void PB_Acre_MouseMove(object sender, MouseEventArgs e) SetCoordinateText(x, y); } + private void MoveDrag(MouseEventArgs e) + { + GetAcreCoordinates(e, out var nhX, out var nhY); + + if (DragX == -1) + { + DragX = nhX; + DragY = nhY; + return; + } + + var dX = DragX - nhX; + var dY = DragY - nhY; + + if (ModifierKeys == Keys.Control) + { + dX *= 2; + dY *= 2; + } + + if ((dX & 1) == 1) + dX ^= 1; + if ((dY & 1) == 1) + dY ^= 1; + + var aX = Math.Abs(dX); + var aY = Math.Abs(dY); + if (aX < 2 && aY < 2) + return; + + DragX = nhX; + DragY = nhY; + if (!View.SetViewTo(View.X + dX, View.Y + dY)) + return; + + Dragging = true; + LoadItemGridAcre(); + } + private void ViewTile(Item tile, int x, int y) { if (CHK_RedirectExtensionLoad.Checked && tile.IsExtension) @@ -534,8 +605,8 @@ private void ClickMapAt(MouseEventArgs e, bool skipLagCheck) if (!CHK_SnapToAcre.Checked) { - View.SetViewTo(x, y); - LoadItemGridAcre(); + if (View.SetViewTo(x, y)) + LoadItemGridAcre(); return; }