From 9f597a271c18b5124f971fbffbe1872e53697b11 Mon Sep 17 00:00:00 2001 From: biwa <6475593+biwa@users.noreply.github.com> Date: Sat, 19 Jan 2019 08:56:13 +0100 Subject: [PATCH] Added paint selecting to visual mode (PR#248 by biwa) --- .../BuilderModes/Resources/Actions.cfg | 17 ++++- .../VisualModes/BaseVisualGeometrySector.cs | 60 +++++++++++++++++ .../VisualModes/BaseVisualGeometrySidedef.cs | 59 ++++++++++++++++- .../VisualModes/BaseVisualMode.cs | 50 +++++++++++++-- .../VisualModes/BaseVisualThing.cs | 64 ++++++++++++++++++- .../VisualModes/BaseVisualVertex.cs | 2 + .../VisualModes/IVisualEventReceiver.cs | 2 + .../VisualModes/NullVisualEventReceiver.cs | 2 + 8 files changed, 247 insertions(+), 9 deletions(-) diff --git a/Source/Plugins/BuilderModes/Resources/Actions.cfg b/Source/Plugins/BuilderModes/Resources/Actions.cfg index 1c66d15..8b78036 100644 --- a/Source/Plugins/BuilderModes/Resources/Actions.cfg +++ b/Source/Plugins/BuilderModes/Resources/Actions.cfg @@ -1422,4 +1422,19 @@ togglecolormaps allowmouse = true; allowscroll = false; default = 262211; //Alt+C -} \ No newline at end of file +} +} + +// biwa +visualpaintselect +{ + title = "Paint Selection"; + category = "visual"; + description = "Selects or deselects items by dragging the mouse. Hold shift while dragging to toggle additive selection. Hold Ctrl while dragging to enable subtractive selection"; + allowkeys = true; + allowmouse = true; + allowscroll = false; + disregardshift = true; + disregardcontrol = true; + disregardalt = true; +} diff --git a/Source/Plugins/BuilderModes/VisualModes/BaseVisualGeometrySector.cs b/Source/Plugins/BuilderModes/VisualModes/BaseVisualGeometrySector.cs index 2e973ba..f05c351 100644 --- a/Source/Plugins/BuilderModes/VisualModes/BaseVisualGeometrySector.cs +++ b/Source/Plugins/BuilderModes/VisualModes/BaseVisualGeometrySector.cs @@ -484,6 +484,7 @@ namespace CodeImp.DoomBuilder.BuilderModes public virtual void ApplyLinedefFlag(string flag, bool set) { } protected abstract void MoveTextureOffset(Point xy); protected abstract Point GetTextureOffset(); + public virtual void OnPaintSelectEnd() { } // biwa // Setup this plane public bool Setup() { return this.Setup(this.level, this.extrafloor); } @@ -536,6 +537,37 @@ namespace CodeImp.DoomBuilder.BuilderModes // Moving the mouse public virtual void OnMouseMove(MouseEventArgs e) { + // biwa. Paint selection going on? + if(mode.PaintSelectPressed) + { + // toggle selected state + if (mode.PaintSelectType == this.GetType().BaseType && mode.Highlighted != this) // using BaseType so that both floor and ceiling can be selected in one go + { + if (General.Interface.ShiftState ^ BuilderPlug.Me.AdditiveSelect) + { + this.selected = true; + mode.AddSelectedObject(this); + } + else if (General.Interface.CtrlState) + { + this.selected = false; + mode.RemoveSelectedObject(this); + + } + else + { + if (this.selected) + mode.RemoveSelectedObject(this); + else + mode.AddSelectedObject(this); + + this.selected = !this.selected; + } + } + + return; + } + if(!General.Map.UDMF) return; //mxd. Cannot change texture offsets in other map formats... // Dragging UV? @@ -968,6 +1000,34 @@ namespace CodeImp.DoomBuilder.BuilderModes ChangeTextureScale(incrementX, incrementY); } + + // biwa + public virtual void OnPaintSelectBegin() + { + mode.PaintSelectType = this.GetType().BaseType; // using BaseType so that both floor and ceiling can be selected in one go + + // toggle selected state + if (General.Interface.ShiftState ^ BuilderPlug.Me.AdditiveSelect) + { + this.selected = true; + mode.AddSelectedObject(this); + } + else if (General.Interface.CtrlState) + { + this.selected = false; + mode.RemoveSelectedObject(this); + + } + else + { + if (this.selected) + mode.RemoveSelectedObject(this); + else + mode.AddSelectedObject(this); + + this.selected = !this.selected; + } + } #endregion } diff --git a/Source/Plugins/BuilderModes/VisualModes/BaseVisualGeometrySidedef.cs b/Source/Plugins/BuilderModes/VisualModes/BaseVisualGeometrySidedef.cs index cfa0af4..5f4377a 100644 --- a/Source/Plugins/BuilderModes/VisualModes/BaseVisualGeometrySidedef.cs +++ b/Source/Plugins/BuilderModes/VisualModes/BaseVisualGeometrySidedef.cs @@ -762,7 +762,8 @@ namespace CodeImp.DoomBuilder.BuilderModes protected abstract void MoveTextureOffset(Point xy); protected abstract Point GetTextureOffset(); public virtual void OnTextureFit(FitTextureOptions options) { } //mxd - + public virtual void OnPaintSelectEnd() { } // biwa + // Insert middle texture public virtual void OnInsert() { @@ -1282,6 +1283,35 @@ namespace CodeImp.DoomBuilder.BuilderModes { UpdateDragUV(); } + else if (mode.PaintSelectPressed) // biwa. Paint selection going on? + { + if (mode.PaintSelectType == this.GetType().BaseType && mode.Highlighted != this) // using BaseType so that middle, upper, lower, etc can be selecting in one go + { + // toggle selected state + if (General.Interface.ShiftState ^ BuilderPlug.Me.AdditiveSelect) + { + this.selected = true; + mode.AddSelectedObject(this); + } + else if (General.Interface.CtrlState) + { + this.selected = false; + mode.RemoveSelectedObject(this); + + } + else + { + if (this.selected) + mode.RemoveSelectedObject(this); + else + mode.AddSelectedObject(this); + + this.selected = !this.selected; + } + } + + return; + } else { // Select button pressed? @@ -1542,6 +1572,33 @@ namespace CodeImp.DoomBuilder.BuilderModes mode.SetActionResult("Wall scale changed to " + scaleX.ToString("F03", CultureInfo.InvariantCulture) + ", " + scaleY.ToString("F03", CultureInfo.InvariantCulture) + " (" + (int)Math.Round(Texture.Width / scaleX) + " x " + (int)Math.Round(Texture.Height / scaleY) + ")."); } + // biwa + public virtual void OnPaintSelectBegin() + { + mode.PaintSelectType = this.GetType().BaseType; // using BaseType so that middle, upper, lower, etc can be selecting in one go + + // toggle selected state + if (General.Interface.ShiftState ^ BuilderPlug.Me.AdditiveSelect) + { + this.selected = true; + mode.AddSelectedObject(this); + } + else if (General.Interface.CtrlState) + { + this.selected = false; + mode.RemoveSelectedObject(this); + } + else + { + if (this.selected) + mode.RemoveSelectedObject(this); + else + mode.AddSelectedObject(this); + + this.selected = !this.selected; + } + } + #endregion } } diff --git a/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs b/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs index 3c9ee10..63f9f5c 100644 --- a/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs +++ b/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs @@ -50,6 +50,7 @@ namespace CodeImp.DoomBuilder.BuilderModes #region ================== Constants // Object picking private const float PICK_INTERVAL = 80.0f; + private const float PICK_INTERVAL_PAINT_SELECT = 10.0f; // biwa private const float PICK_RANGE = 0.98f; // Gravity @@ -99,8 +100,13 @@ namespace CodeImp.DoomBuilder.BuilderModes private BSP bsp; private bool useblockmap; - //mxd. Moved here from Tools - private struct SidedefAlignJob + // biwa. Info for paint selection + protected bool paintselectpressed; + protected Type paintselecttype = null; + protected IVisualPickable highlighted; // biwa + + //mxd. Moved here from Tools + private struct SidedefAlignJob { public Sidedef sidedef; @@ -170,9 +176,13 @@ namespace CodeImp.DoomBuilder.BuilderModes public BSP BSP { get { return bsp; } } public bool UseBlockmap { get { return useblockmap; } } - #endregion + public bool PaintSelectPressed { get { return paintselectpressed; } } // biwa + public Type PaintSelectType { get { return paintselecttype; } set { paintselecttype = value; } } // biwa + public IVisualPickable Highlighted { get { return highlighted; } } // biwa - #region ================== Constructor / Disposer + #endregion + + #region ================== Constructor / Disposer // Constructor public BaseVisualMode() @@ -1281,6 +1291,7 @@ namespace CodeImp.DoomBuilder.BuilderModes // Processing public override void OnProcess(float deltatime) { + float pickinterval = PICK_INTERVAL; // biwa // Process things? base.ProcessThings = (BuilderPlug.Me.ShowVisualThings != 0); @@ -1354,9 +1365,13 @@ namespace CodeImp.DoomBuilder.BuilderModes { g.OnProcess(deltatime); } + + // biwa. Use a lower pick interval for paint selection, to make it more reliable + if (paintselectpressed) + pickinterval = PICK_INTERVAL_PAINT_SELECT; // Time to pick a new target? - if(Clock.CurrentTime > (lastpicktime + PICK_INTERVAL)) + if(Clock.CurrentTime > (lastpicktime + pickinterval)) { PickTargetUnlocked(); lastpicktime = Clock.CurrentTime; @@ -1570,6 +1585,14 @@ namespace CodeImp.DoomBuilder.BuilderModes lasthighlighttype = o.GetType(); } + + // biwa + if (o is NullVisualEventReceiver) + highlighted = null; + else if (o is VisualGeometry) + highlighted = (VisualGeometry)o; + else if (o is VisualThing) + highlighted = (VisualThing)o; } // Undo performed @@ -4058,6 +4081,23 @@ namespace CodeImp.DoomBuilder.BuilderModes General.Interface.DisplayStatus(StatusType.Action, "Toggled Slope for " + toUpdate.Count + (toUpdate.Count == 1 ? " surface." : " surfaces.")); } + // biwa + [BeginAction("visualpaintselect")] + protected virtual void OnPaintSelectBegin() + { + paintselectpressed = true; + GetTargetEventReceiver(true).OnPaintSelectBegin(); + } + + // biwa + [EndAction("visualpaintselect")] + protected virtual void OnPaintSelectEnd() + { + paintselectpressed = false; + paintselecttype = null; + GetTargetEventReceiver(true).OnPaintSelectEnd(); + } + #endregion #region ================== Texture Alignment diff --git a/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs b/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs index 6ae6df2..d16f9a0 100644 --- a/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs +++ b/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs @@ -658,7 +658,6 @@ namespace CodeImp.DoomBuilder.BuilderModes // Unused public void OnSelectBegin() { } public void OnEditBegin() { } - public void OnMouseMove(MouseEventArgs e) { } public void OnChangeTargetBrightness(bool up) { } public void OnChangeTextureOffset(int horizontal, int vertical, bool doSurfaceAngleCorrection) { } public void OnSelectTexture() { } @@ -678,7 +677,8 @@ namespace CodeImp.DoomBuilder.BuilderModes public void ApplyTexture(string texture) { } public void ApplyLinedefFlag(string flag, bool set) { } public void SelectNeighbours(bool select, bool withSameTexture, bool withSameHeight) { } //mxd - + public virtual void OnPaintSelectEnd() { } // biwa + // Return texture name public string GetTextureName() { return ""; } @@ -890,6 +890,66 @@ namespace CodeImp.DoomBuilder.BuilderModes this.Changed = true; } + // biwa. Moving the mouse + public virtual void OnMouseMove(MouseEventArgs e) + { + // biwa. Paint selection going on? + if (mode.PaintSelectPressed) + { + // toggle selected state + if (mode.PaintSelectType == this.GetType() && mode.Highlighted != this) + { + if (General.Interface.ShiftState ^ BuilderPlug.Me.AdditiveSelect) + { + this.selected = true; + mode.AddSelectedObject(this); + } + else if (General.Interface.CtrlState) + { + this.selected = false; + mode.RemoveSelectedObject(this); + + } + else + { + if (this.selected) + mode.RemoveSelectedObject(this); + else + mode.AddSelectedObject(this); + + this.selected = !this.selected; + } + } + } + } + + // biwa + public virtual void OnPaintSelectBegin() + { + mode.PaintSelectType = this.GetType(); + + // toggle selected state + if (General.Interface.ShiftState ^ BuilderPlug.Me.AdditiveSelect) + { + this.selected = true; + mode.AddSelectedObject(this); + } + else if (General.Interface.CtrlState) + { + this.selected = false; + mode.RemoveSelectedObject(this); + } + else + { + if (this.selected) + mode.RemoveSelectedObject(this); + else + mode.AddSelectedObject(this); + + this.selected = !this.selected; + } + } + //mxd public void SetAngle(int newangle) { diff --git a/Source/Plugins/BuilderModes/VisualModes/BaseVisualVertex.cs b/Source/Plugins/BuilderModes/VisualModes/BaseVisualVertex.cs index b800f5e..918e68f 100644 --- a/Source/Plugins/BuilderModes/VisualModes/BaseVisualVertex.cs +++ b/Source/Plugins/BuilderModes/VisualModes/BaseVisualVertex.cs @@ -263,6 +263,8 @@ namespace CodeImp.DoomBuilder.BuilderModes public void ApplyLinedefFlag(string flag, bool set) { } public string GetTextureName() { return ""; } public void SelectNeighbours(bool select, bool withSameTexture, bool withSameHeight) { } //mxd + public virtual void OnPaintSelectBegin() { } // biwa + public virtual void OnPaintSelectEnd() { } // biwa #endregion diff --git a/Source/Plugins/BuilderModes/VisualModes/IVisualEventReceiver.cs b/Source/Plugins/BuilderModes/VisualModes/IVisualEventReceiver.cs index cf2c2c4..c3b6134 100644 --- a/Source/Plugins/BuilderModes/VisualModes/IVisualEventReceiver.cs +++ b/Source/Plugins/BuilderModes/VisualModes/IVisualEventReceiver.cs @@ -53,6 +53,8 @@ namespace CodeImp.DoomBuilder.BuilderModes void OnProcess(float deltatime); void OnInsert(); void OnDelete(); + void OnPaintSelectBegin(); // biwa + void OnPaintSelectEnd(); // biwa // Assist functions void ApplyTexture(string texture); diff --git a/Source/Plugins/BuilderModes/VisualModes/NullVisualEventReceiver.cs b/Source/Plugins/BuilderModes/VisualModes/NullVisualEventReceiver.cs index c51feef..83ffa54 100644 --- a/Source/Plugins/BuilderModes/VisualModes/NullVisualEventReceiver.cs +++ b/Source/Plugins/BuilderModes/VisualModes/NullVisualEventReceiver.cs @@ -53,6 +53,8 @@ namespace CodeImp.DoomBuilder.BuilderModes public void OnProcess(float deltatime) { } public void OnInsert() { } public void OnDelete() { } + public void OnPaintSelectBegin() { } // biwa + public void OnPaintSelectEnd() { } // biwa public void ApplyTexture(string texture) { } public void ApplyLinedefFlag(string flag, bool set) { } public string GetTextureName() { return ""; }