2008-12-05 15:38:50 +00:00
|
|
|
|
|
|
|
#region ================== Copyright (c) 2007 Pascal vd Heiden
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
|
|
|
* This program is released under GNU General Public License
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Globalization;
|
|
|
|
using System.Text;
|
|
|
|
using System.Windows.Forms;
|
|
|
|
using System.IO;
|
|
|
|
using System.Reflection;
|
2009-01-09 22:37:11 +00:00
|
|
|
using CodeImp.DoomBuilder.Data;
|
2008-12-05 15:38:50 +00:00
|
|
|
using CodeImp.DoomBuilder.Windows;
|
|
|
|
using CodeImp.DoomBuilder.IO;
|
|
|
|
using CodeImp.DoomBuilder.Map;
|
|
|
|
using CodeImp.DoomBuilder.Rendering;
|
|
|
|
using CodeImp.DoomBuilder.Geometry;
|
|
|
|
using CodeImp.DoomBuilder.Editing;
|
|
|
|
using CodeImp.DoomBuilder.VisualModes;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.BuilderModes
|
|
|
|
{
|
2008-12-15 18:32:36 +00:00
|
|
|
internal abstract class BaseVisualGeometrySector : VisualGeometry, IVisualEventReceiver
|
2008-12-05 15:38:50 +00:00
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
2008-12-17 10:58:57 +00:00
|
|
|
protected BaseVisualMode mode;
|
2009-01-09 22:37:11 +00:00
|
|
|
protected long setuponloadedtexture;
|
|
|
|
|
2008-12-05 15:38:50 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
2008-12-24 14:21:54 +00:00
|
|
|
|
|
|
|
new public BaseVisualSector Sector { get { return (BaseVisualSector)base.Sector; } }
|
|
|
|
|
2008-12-05 15:38:50 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Destructor
|
|
|
|
|
|
|
|
// Constructor
|
2008-12-17 10:58:57 +00:00
|
|
|
public BaseVisualGeometrySector(BaseVisualMode mode, VisualSector vs) : base(vs)
|
2008-12-05 15:38:50 +00:00
|
|
|
{
|
2008-12-17 10:58:57 +00:00
|
|
|
this.mode = mode;
|
2008-12-05 15:38:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
2008-12-06 00:28:49 +00:00
|
|
|
// This changes the height
|
2008-12-24 14:21:54 +00:00
|
|
|
protected abstract void ChangeHeight(int amount);
|
2009-01-28 09:43:35 +00:00
|
|
|
|
|
|
|
// This updates the secotr and neightbours if needed
|
|
|
|
protected void UpdateSectorGeometry(bool includeneighbours)
|
|
|
|
{
|
|
|
|
// Rebuild sector
|
|
|
|
Sector.Rebuild();
|
2008-12-06 00:28:49 +00:00
|
|
|
|
2009-01-28 09:43:35 +00:00
|
|
|
// Go for all things in this sector
|
|
|
|
foreach(Thing t in General.Map.Map.Things)
|
|
|
|
{
|
|
|
|
if(t.Sector == Sector.Sector)
|
|
|
|
{
|
|
|
|
if(mode.VisualThingExists(t))
|
|
|
|
{
|
|
|
|
// Update thing
|
|
|
|
BaseVisualThing vt = (mode.GetVisualThing(t) as BaseVisualThing);
|
|
|
|
vt.Setup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(includeneighbours)
|
|
|
|
{
|
|
|
|
// Also rebuild surrounding sectors, because outside sidedefs may need to be adjusted
|
|
|
|
Dictionary<Sector, int> rebuilt = new Dictionary<Sector, int>();
|
|
|
|
foreach(Sidedef sd in Sector.Sector.Sidedefs)
|
|
|
|
{
|
|
|
|
if((sd.Other != null) && !rebuilt.ContainsKey(sd.Other.Sector))
|
|
|
|
{
|
|
|
|
if(mode.VisualSectorExists(sd.Other.Sector))
|
|
|
|
{
|
|
|
|
BaseVisualSector bvs = (BaseVisualSector)mode.GetVisualSector(sd.Other.Sector);
|
|
|
|
rebuilt.Add(sd.Other.Sector, 1);
|
|
|
|
bvs.Rebuild();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-05 15:38:50 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Events
|
2008-12-15 18:32:36 +00:00
|
|
|
|
|
|
|
// Unused
|
2009-01-09 22:37:11 +00:00
|
|
|
public abstract bool Setup();
|
2008-12-15 18:32:36 +00:00
|
|
|
public virtual void OnSelectBegin() { }
|
|
|
|
public virtual void OnSelectEnd() { }
|
|
|
|
public virtual void OnEditBegin() { }
|
2008-12-17 15:30:50 +00:00
|
|
|
public virtual void OnMouseMove(MouseEventArgs e) { }
|
2008-12-24 18:27:13 +00:00
|
|
|
public virtual void OnChangeTextureOffset(int horizontal, int vertical) { }
|
2008-12-31 00:44:04 +00:00
|
|
|
public virtual void OnTextureAlign(bool alignx, bool aligny) { }
|
|
|
|
public virtual void OnToggleUpperUnpegged() { }
|
|
|
|
public virtual void OnToggleLowerUnpegged() { }
|
2009-01-04 18:51:32 +00:00
|
|
|
public virtual void OnResetTextureOffset() { }
|
2008-12-27 00:22:31 +00:00
|
|
|
protected virtual void SetTexture(string texturename) { }
|
2009-01-12 22:00:31 +00:00
|
|
|
public virtual void OnTextureFloodfill() { }
|
2008-12-27 00:22:31 +00:00
|
|
|
|
2009-01-09 22:37:11 +00:00
|
|
|
// Processing
|
|
|
|
public virtual void OnProcess(double deltatime)
|
|
|
|
{
|
|
|
|
// If the texture was not loaded, but is loaded now, then re-setup geometry
|
|
|
|
if(setuponloadedtexture != 0)
|
|
|
|
{
|
|
|
|
ImageData t = General.Map.Data.GetFlatImage(setuponloadedtexture);
|
|
|
|
if(t != null)
|
|
|
|
{
|
|
|
|
if(t.IsImageLoaded)
|
|
|
|
{
|
|
|
|
setuponloadedtexture = 0;
|
|
|
|
Setup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-27 00:22:31 +00:00
|
|
|
// Select texture
|
|
|
|
public virtual void OnSelectTexture()
|
|
|
|
{
|
2009-01-07 10:44:38 +00:00
|
|
|
if(General.Interface.IsActiveWindow)
|
2008-12-27 00:22:31 +00:00
|
|
|
{
|
2009-01-06 09:51:14 +00:00
|
|
|
string oldtexture = GetTextureName();
|
|
|
|
string newtexture = General.Interface.BrowseFlat(General.Interface, oldtexture);
|
|
|
|
if(newtexture != oldtexture)
|
|
|
|
{
|
|
|
|
General.Map.UndoRedo.CreateUndo("Change flat " + newtexture);
|
|
|
|
SetTexture(newtexture);
|
|
|
|
}
|
2008-12-27 00:22:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy texture
|
|
|
|
public virtual void OnCopyTexture()
|
|
|
|
{
|
2009-02-10 12:14:56 +00:00
|
|
|
BuilderPlug.Me.CopiedFlat = GetTextureName();
|
|
|
|
if(General.Map.Config.MixTexturesFlats) BuilderPlug.Me.CopiedTexture = GetTextureName();
|
2008-12-27 00:22:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public virtual void OnPasteTexture() { }
|
|
|
|
|
|
|
|
// Return texture name
|
|
|
|
public virtual string GetTextureName() { return ""; }
|
2008-12-05 15:38:50 +00:00
|
|
|
|
|
|
|
// Edit button released
|
2008-12-15 18:32:36 +00:00
|
|
|
public virtual void OnEditEnd()
|
2008-12-05 15:38:50 +00:00
|
|
|
{
|
2008-12-27 00:22:31 +00:00
|
|
|
// Not using any modifier buttons
|
|
|
|
if(!General.Interface.ShiftState && !General.Interface.CtrlState && !General.Interface.AltState)
|
|
|
|
{
|
2009-01-07 10:44:38 +00:00
|
|
|
if(General.Interface.IsActiveWindow)
|
2009-01-06 09:51:14 +00:00
|
|
|
{
|
|
|
|
List<Sector> sectors = new List<Sector>();
|
|
|
|
sectors.Add(this.Sector.Sector);
|
|
|
|
DialogResult result = General.Interface.ShowEditSectors(sectors);
|
2009-01-28 09:43:35 +00:00
|
|
|
if(result == DialogResult.OK)
|
|
|
|
{
|
|
|
|
// Rebuild sector
|
|
|
|
UpdateSectorGeometry(true);
|
|
|
|
}
|
2009-01-06 09:51:14 +00:00
|
|
|
}
|
2008-12-27 00:22:31 +00:00
|
|
|
}
|
2008-12-05 15:38:50 +00:00
|
|
|
}
|
2008-12-24 14:21:54 +00:00
|
|
|
|
|
|
|
// Sector height change
|
|
|
|
public virtual void OnChangeTargetHeight(int amount)
|
|
|
|
{
|
|
|
|
ChangeHeight(amount);
|
2008-12-24 18:27:13 +00:00
|
|
|
|
2009-01-28 09:43:35 +00:00
|
|
|
// Rebuild sector
|
|
|
|
UpdateSectorGeometry(true);
|
2008-12-24 14:21:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2009-01-28 09:43:35 +00:00
|
|
|
UpdateSectorGeometry(false);
|
2008-12-24 14:21:54 +00:00
|
|
|
}
|
2008-12-05 15:38:50 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|