From 5032c587971f35ad97230790527910203dbb00ee Mon Sep 17 00:00:00 2001 From: codeimp Date: Wed, 24 Dec 2008 14:21:54 +0000 Subject: [PATCH] working on visual mode --- Source/BuilderModes/Resources/Actions.cfg | 60 +++++++++++++++++++ .../VisualModes/BaseVisualGeometrySector.cs | 36 ++++++++++- .../VisualModes/BaseVisualGeometrySidedef.cs | 12 ++++ .../VisualModes/BaseVisualMode.cs | 45 ++++++-------- .../VisualModes/BaseVisualThing.cs | 2 + .../VisualModes/IVisualEventReceiver.cs | 2 + .../BuilderModes/VisualModes/VisualCeiling.cs | 2 +- .../BuilderModes/VisualModes/VisualFloor.cs | 2 +- Source/Editing/UndoGroup.cs | 1 + Source/VisualModes/VisualMode.cs | 8 +-- Source/Windows/MainForm.cs | 31 +++++++--- 11 files changed, 158 insertions(+), 43 deletions(-) diff --git a/Source/BuilderModes/Resources/Actions.cfg b/Source/BuilderModes/Resources/Actions.cfg index 75334511..357af315 100644 --- a/Source/BuilderModes/Resources/Actions.cfg +++ b/Source/BuilderModes/Resources/Actions.cfg @@ -317,3 +317,63 @@ showvisualthings allowmouse = true; allowscroll = true; } + +lowerbrightness8 +{ + title = "Lower Brightness by 8"; + category = "visual"; + description = "Lowers the targeted or selected sector brightness level by 8."; + allowkeys = true; + allowmouse = true; + allowscroll = true; +} + +raisebrightness8 +{ + title = "Raise Brightness by 8"; + category = "visual"; + description = "Raises the targeted or selected sector brightness level by 8."; + allowkeys = true; + allowmouse = true; + allowscroll = true; +} + +movetextureleft +{ + title = "Move Texture Left"; + category = "visual"; + description = "Moves the offset of the targeted or selected textures to the left."; + allowkeys = true; + allowmouse = true; + allowscroll = true; +} + +movetextureright +{ + title = "Move Texture Right"; + category = "visual"; + description = "Moves the offset of the targeted or selected textures to the right."; + allowkeys = true; + allowmouse = true; + allowscroll = true; +} + +movetextureup +{ + title = "Move Texture Up"; + category = "visual"; + description = "Moves the offset of the targeted or selected textures up."; + allowkeys = true; + allowmouse = true; + allowscroll = true; +} + +movetexturedown +{ + title = "Move Texture Down"; + category = "visual"; + description = "Moves the offset of the targeted or selected textures down."; + allowkeys = true; + allowmouse = true; + allowscroll = true; +} diff --git a/Source/BuilderModes/VisualModes/BaseVisualGeometrySector.cs b/Source/BuilderModes/VisualModes/BaseVisualGeometrySector.cs index 7a7ec71b..ce1fe5b4 100644 --- a/Source/BuilderModes/VisualModes/BaseVisualGeometrySector.cs +++ b/Source/BuilderModes/VisualModes/BaseVisualGeometrySector.cs @@ -49,7 +49,9 @@ namespace CodeImp.DoomBuilder.BuilderModes #endregion #region ================== Properties - + + new public BaseVisualSector Sector { get { return (BaseVisualSector)base.Sector; } } + #endregion #region ================== Constructor / Destructor @@ -65,7 +67,7 @@ namespace CodeImp.DoomBuilder.BuilderModes #region ================== Methods // This changes the height - public abstract void ChangeHeight(int amount); + protected abstract void ChangeHeight(int amount); #endregion @@ -85,6 +87,36 @@ namespace CodeImp.DoomBuilder.BuilderModes DialogResult result = General.Interface.ShowEditSectors(sectors); if(result == DialogResult.OK) (this.Sector as BaseVisualSector).Rebuild(); } + + // Sector height change + public virtual void OnChangeTargetHeight(int amount) + { + ChangeHeight(amount); + + // Rebuild sector + Sector.Rebuild(); + + // Also rebuild surrounding sectors, because outside sidedefs may need to be adjusted + foreach(Sidedef sd in Sector.Sector.Sidedefs) + { + if((sd.Other != null) && mode.VisualSectorExists(sd.Other.Sector)) + { + BaseVisualSector bvs = (BaseVisualSector)mode.GetVisualSector(sd.Other.Sector); + bvs.Rebuild(); + } + } + } + + // Sector brightness change + public virtual void OnChangeTargetBrightness(int amount) + { + // Change brightness + General.Map.UndoRedo.CreateUndo("Change sector brightness", UndoGroup.SectorBrightnessChange, Sector.Sector.Index); + Sector.Sector.Brightness = General.Clamp(Sector.Sector.Brightness + amount, 0, 255); + + // Rebuild sector + Sector.Rebuild(); + } #endregion } diff --git a/Source/BuilderModes/VisualModes/BaseVisualGeometrySidedef.cs b/Source/BuilderModes/VisualModes/BaseVisualGeometrySidedef.cs index 69d27662..979e6ec0 100644 --- a/Source/BuilderModes/VisualModes/BaseVisualGeometrySidedef.cs +++ b/Source/BuilderModes/VisualModes/BaseVisualGeometrySidedef.cs @@ -107,6 +107,7 @@ namespace CodeImp.DoomBuilder.BuilderModes // Unused public virtual void OnEditBegin() { } + public virtual void OnChangeTargetHeight(int amount) { } // Select button pressed public virtual void OnSelectBegin() @@ -201,6 +202,17 @@ namespace CodeImp.DoomBuilder.BuilderModes if(parts.upper != null) parts.upper.Setup(); } + // Sector brightness change + public virtual void OnChangeTargetBrightness(int amount) + { + // Change brightness + General.Map.UndoRedo.CreateUndo("Change sector brightness", UndoGroup.SectorBrightnessChange, Sector.Sector.Index); + Sector.Sector.Brightness = General.Clamp(Sector.Sector.Brightness + amount, 0, 255); + + // Rebuild sector + Sector.Rebuild(); + } + #endregion } } diff --git a/Source/BuilderModes/VisualModes/BaseVisualMode.cs b/Source/BuilderModes/VisualModes/BaseVisualMode.cs index ac2a2a94..a8fa8bdc 100644 --- a/Source/BuilderModes/VisualModes/BaseVisualMode.cs +++ b/Source/BuilderModes/VisualModes/BaseVisualMode.cs @@ -187,29 +187,6 @@ namespace CodeImp.DoomBuilder.BuilderModes target = newtarget; } - // This changes the target's height - private void ChangeTargetHeight(int amount) - { - if(target.picked is BaseVisualGeometrySector) - { - BaseVisualGeometrySector vgs = (target.picked as BaseVisualGeometrySector); - vgs.ChangeHeight(amount); - - // Rebuild sector - (vgs.Sector as BaseVisualSector).Rebuild(); - - // Also rebuild surrounding sectors, because outside sidedefs may need to be adjusted - foreach(Sidedef sd in vgs.Sector.Sector.Sidedefs) - { - if((sd.Other != null) && VisualSectorExists(sd.Other.Sector)) - { - BaseVisualSector bvs = (BaseVisualSector)GetVisualSector(sd.Other.Sector); - bvs.Rebuild(); - } - } - } - } - #endregion #region ================== Events @@ -322,28 +299,28 @@ namespace CodeImp.DoomBuilder.BuilderModes public void RaiseSector8() { PickTargetUnlocked(); - ChangeTargetHeight(8); + if(target.picked != null) (target.picked as IVisualEventReceiver).OnChangeTargetHeight(8); } [BeginAction("lowersector8")] public void LowerSector8() { PickTargetUnlocked(); - ChangeTargetHeight(-8); + if(target.picked != null) (target.picked as IVisualEventReceiver).OnChangeTargetHeight(-8); } [BeginAction("raisesector1")] public void RaiseSector1() { PickTargetUnlocked(); - ChangeTargetHeight(1); + if(target.picked != null) (target.picked as IVisualEventReceiver).OnChangeTargetHeight(1); } [BeginAction("lowersector1")] public void LowerSector1() { PickTargetUnlocked(); - ChangeTargetHeight(-1); + if(target.picked != null) (target.picked as IVisualEventReceiver).OnChangeTargetHeight(-1); } [BeginAction("showvisualthings")] @@ -352,6 +329,20 @@ namespace CodeImp.DoomBuilder.BuilderModes BuilderPlug.Me.ShowVisualThings++; if(BuilderPlug.Me.ShowVisualThings > 2) BuilderPlug.Me.ShowVisualThings = 0; } + + [BeginAction("raisebrightness8")] + public void RaiseBrightness8() + { + PickTargetUnlocked(); + if(target.picked != null) (target.picked as IVisualEventReceiver).OnChangeTargetBrightness(8); + } + + [BeginAction("lowerbrightness8")] + public void LowerBrightness8() + { + PickTargetUnlocked(); + if(target.picked != null) (target.picked as IVisualEventReceiver).OnChangeTargetBrightness(-8); + } #endregion } diff --git a/Source/BuilderModes/VisualModes/BaseVisualThing.cs b/Source/BuilderModes/VisualModes/BaseVisualThing.cs index 00371a84..57f2db29 100644 --- a/Source/BuilderModes/VisualModes/BaseVisualThing.cs +++ b/Source/BuilderModes/VisualModes/BaseVisualThing.cs @@ -332,6 +332,8 @@ namespace CodeImp.DoomBuilder.BuilderModes public virtual void OnSelectEnd() { } public virtual void OnEditBegin() { } public virtual void OnMouseMove(MouseEventArgs e) { } + public virtual void OnChangeTargetHeight(int amount) { } + public virtual void OnChangeTargetBrightness(int amount) { } // Edit button released public virtual void OnEditEnd() diff --git a/Source/BuilderModes/VisualModes/IVisualEventReceiver.cs b/Source/BuilderModes/VisualModes/IVisualEventReceiver.cs index 179198ac..963f0134 100644 --- a/Source/BuilderModes/VisualModes/IVisualEventReceiver.cs +++ b/Source/BuilderModes/VisualModes/IVisualEventReceiver.cs @@ -44,5 +44,7 @@ namespace CodeImp.DoomBuilder.BuilderModes void OnEditBegin(); void OnEditEnd(); void OnMouseMove(MouseEventArgs e); + void OnChangeTargetHeight(int amount); + void OnChangeTargetBrightness(int amount); } } diff --git a/Source/BuilderModes/VisualModes/VisualCeiling.cs b/Source/BuilderModes/VisualModes/VisualCeiling.cs index bffd63a1..0f28d3d6 100644 --- a/Source/BuilderModes/VisualModes/VisualCeiling.cs +++ b/Source/BuilderModes/VisualModes/VisualCeiling.cs @@ -124,7 +124,7 @@ namespace CodeImp.DoomBuilder.BuilderModes #region ================== Methods // This changes the height - public override void ChangeHeight(int amount) + protected override void ChangeHeight(int amount) { General.Map.UndoRedo.CreateUndo("Change ceiling height", UndoGroup.CeilingHeightChange, this.Sector.Sector.Index); this.Sector.Sector.CeilHeight += amount; diff --git a/Source/BuilderModes/VisualModes/VisualFloor.cs b/Source/BuilderModes/VisualModes/VisualFloor.cs index d81407af..f1cb27ec 100644 --- a/Source/BuilderModes/VisualModes/VisualFloor.cs +++ b/Source/BuilderModes/VisualModes/VisualFloor.cs @@ -111,7 +111,7 @@ namespace CodeImp.DoomBuilder.BuilderModes #region ================== Methods // This changes the height - public override void ChangeHeight(int amount) + protected override void ChangeHeight(int amount) { General.Map.UndoRedo.CreateUndo("Change floor height", UndoGroup.FloorHeightChange, this.Sector.Sector.Index); this.Sector.Sector.FloorHeight += amount; diff --git a/Source/Editing/UndoGroup.cs b/Source/Editing/UndoGroup.cs index f8ce4482..4698ce20 100644 --- a/Source/Editing/UndoGroup.cs +++ b/Source/Editing/UndoGroup.cs @@ -35,5 +35,6 @@ namespace CodeImp.DoomBuilder.Editing None, FloorHeightChange, CeilingHeightChange, + SectorBrightnessChange, } } diff --git a/Source/VisualModes/VisualMode.cs b/Source/VisualModes/VisualMode.cs index 916b0cae..290ad563 100644 --- a/Source/VisualModes/VisualMode.cs +++ b/Source/VisualModes/VisualMode.cs @@ -699,22 +699,22 @@ namespace CodeImp.DoomBuilder.VisualModes /// /// This returns the VisualSector for the given Sector. /// - protected VisualSector GetVisualSector(Sector s) { return allsectors[s]; } + public VisualSector GetVisualSector(Sector s) { return allsectors[s]; } /// /// This returns the VisualThing for the given Thing. /// - protected VisualThing GetVisualThing(Thing t) { return allthings[t]; } + public VisualThing GetVisualThing(Thing t) { return allthings[t]; } /// /// Returns True when a VisualSector has been created for the specified Sector. /// - protected bool VisualSectorExists(Sector s) { return allsectors.ContainsKey(s); } + public bool VisualSectorExists(Sector s) { return allsectors.ContainsKey(s); } /// /// Returns True when a VisualThing has been created for the specified Thing. /// - protected bool VisualThingExists(Thing t) { return allthings.ContainsKey(t); } + public bool VisualThingExists(Thing t) { return allthings.ContainsKey(t); } /// /// This is called when the blockmap needs to be refilled, because it was invalidated. diff --git a/Source/Windows/MainForm.cs b/Source/Windows/MainForm.cs index 5b74c975..b23343aa 100644 --- a/Source/Windows/MainForm.cs +++ b/Source/Windows/MainForm.cs @@ -892,6 +892,11 @@ namespace CodeImp.DoomBuilder.Windows { int key = 0; + int mod = 0; + if(alt) mod |= (int)Keys.Alt; + if(shift) mod |= (int)Keys.Shift; + if(ctrl) mod |= (int)Keys.Control; + // Apply button mousebuttons |= e.Button; @@ -906,7 +911,7 @@ namespace CodeImp.DoomBuilder.Windows } // Invoke any actions associated with this key - General.Actions.KeyPressed(key); + General.Actions.KeyPressed(key | mod); // Invoke on editing mode if((General.Map != null) && (General.Editing.Mode != null)) General.Editing.Mode.OnMouseDown(e); @@ -936,7 +941,12 @@ namespace CodeImp.DoomBuilder.Windows private void display_MouseUp(object sender, MouseEventArgs e) { int key = 0; - + + int mod = 0; + if(alt) mod |= (int)Keys.Alt; + if(shift) mod |= (int)Keys.Shift; + if(ctrl) mod |= (int)Keys.Control; + // Apply button mousebuttons &= ~e.Button; @@ -949,9 +959,9 @@ namespace CodeImp.DoomBuilder.Windows case MouseButtons.XButton1: key = (int)Keys.XButton1; break; case MouseButtons.XButton2: key = (int)Keys.XButton2; break; } - + // Invoke any actions associated with this key - General.Actions.KeyReleased(key); + General.Actions.KeyReleased(key | mod); // Invoke on editing mode if((General.Map != null) && (General.Editing.Mode != null)) General.Editing.Mode.OnMouseUp(e); @@ -1065,21 +1075,26 @@ namespace CodeImp.DoomBuilder.Windows // When the mouse wheel is changed protected override void OnMouseWheel(MouseEventArgs e) { + int mod = 0; + if(alt) mod |= (int)Keys.Alt; + if(shift) mod |= (int)Keys.Shift; + if(ctrl) mod |= (int)Keys.Control; + // Scrollwheel up? if(e.Delta > 0) { // Invoke actions for scrollwheel //for(int i = 0; i < e.Delta; i += 120) - General.Actions.KeyPressed((int)SpecialKeys.MScrollUp); - General.Actions.KeyReleased((int)SpecialKeys.MScrollUp); + General.Actions.KeyPressed((int)SpecialKeys.MScrollUp | mod); + General.Actions.KeyReleased((int)SpecialKeys.MScrollUp | mod); } // Scrollwheel down? else if(e.Delta < 0) { // Invoke actions for scrollwheel //for(int i = 0; i > e.Delta; i -= 120) - General.Actions.KeyPressed((int)SpecialKeys.MScrollDown); - General.Actions.KeyReleased((int)SpecialKeys.MScrollDown); + General.Actions.KeyPressed((int)SpecialKeys.MScrollDown | mod); + General.Actions.KeyReleased((int)SpecialKeys.MScrollDown | mod); } // Let the base know