2009-04-19 18:07:22 +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;
|
|
|
|
using CodeImp.DoomBuilder.Data;
|
|
|
|
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
|
|
|
|
{
|
|
|
|
internal abstract class BaseVisualGeometrySector : VisualGeometry, IVisualEventReceiver
|
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
protected BaseVisualMode mode;
|
|
|
|
protected long setuponloadedtexture;
|
2009-05-01 20:31:17 +00:00
|
|
|
|
|
|
|
// This is only used to see if this object has already received a change
|
|
|
|
// in a multiselection. The Changed property on the BaseVisualSector is
|
|
|
|
// used to indicate a rebuild is needed.
|
|
|
|
protected bool changed;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
new public BaseVisualSector Sector { get { return (BaseVisualSector)base.Sector; } }
|
2009-05-05 11:26:50 +00:00
|
|
|
public bool Changed { get { return changed; } set { changed = value; } }
|
2009-05-01 20:31:17 +00:00
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Destructor
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
public BaseVisualGeometrySector(BaseVisualMode mode, VisualSector vs) : base(vs)
|
|
|
|
{
|
|
|
|
this.mode = mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
|
|
|
// This changes the height
|
|
|
|
protected abstract void ChangeHeight(int amount);
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Events
|
|
|
|
|
|
|
|
// Unused
|
|
|
|
public abstract bool Setup();
|
2009-05-01 20:31:17 +00:00
|
|
|
public virtual void OnSelectBegin(){ }
|
2009-04-19 18:07:22 +00:00
|
|
|
public virtual void OnEditBegin() { }
|
|
|
|
public virtual void OnMouseMove(MouseEventArgs e) { }
|
|
|
|
public virtual void OnChangeTextureOffset(int horizontal, int vertical) { }
|
|
|
|
public virtual void OnTextureAlign(bool alignx, bool aligny) { }
|
|
|
|
public virtual void OnToggleUpperUnpegged() { }
|
|
|
|
public virtual void OnToggleLowerUnpegged() { }
|
|
|
|
public virtual void OnResetTextureOffset() { }
|
|
|
|
public virtual void OnCopyTextureOffsets() { }
|
|
|
|
public virtual void OnPasteTextureOffsets() { }
|
|
|
|
public virtual void OnInsert() { }
|
|
|
|
public virtual void OnDelete() { }
|
|
|
|
protected virtual void SetTexture(string texturename) { }
|
2009-05-03 19:22:32 +00:00
|
|
|
public virtual void ApplyUpperUnpegged(bool set) { }
|
|
|
|
public virtual void ApplyLowerUnpegged(bool set) { }
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2009-05-01 20:31:17 +00:00
|
|
|
// Select or deselect
|
|
|
|
public virtual void OnSelectEnd()
|
|
|
|
{
|
|
|
|
this.selected = !this.selected;
|
2009-05-02 14:59:05 +00:00
|
|
|
mode.SelectionChanged = true;
|
2009-05-01 20:31:17 +00:00
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Flood-fill textures
|
|
|
|
public virtual void OnTextureFloodfill()
|
|
|
|
{
|
|
|
|
if(BuilderPlug.Me.CopiedFlat != null)
|
|
|
|
{
|
|
|
|
string oldtexture = GetTextureName();
|
|
|
|
long oldtexturelong = Lump.MakeLongName(oldtexture);
|
|
|
|
string newtexture = BuilderPlug.Me.CopiedFlat;
|
|
|
|
if(newtexture != oldtexture)
|
|
|
|
{
|
|
|
|
// Get the texture
|
|
|
|
ImageData newtextureimage = General.Map.Data.GetFlatImage(newtexture);
|
|
|
|
if(newtextureimage != null)
|
|
|
|
{
|
|
|
|
bool fillceilings = (this is VisualCeiling);
|
|
|
|
|
|
|
|
if(fillceilings)
|
|
|
|
{
|
2009-05-03 19:22:32 +00:00
|
|
|
mode.CreateUndo("Flood-fill ceilings with " + newtexture);
|
2009-05-02 14:59:05 +00:00
|
|
|
mode.SetActionResult("Flood-filled ceilings with " + newtexture + ".");
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-05-03 19:22:32 +00:00
|
|
|
mode.CreateUndo("Flood-fill floors with " + newtexture);
|
2009-05-02 14:59:05 +00:00
|
|
|
mode.SetActionResult("Flood-filled floors with " + newtexture + ".");
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mode.Renderer.SetCrosshairBusy(true);
|
|
|
|
General.Interface.RedrawDisplay();
|
|
|
|
|
2009-06-12 09:44:38 +00:00
|
|
|
if(mode.IsSingleSelection)
|
|
|
|
{
|
|
|
|
// Clear all marks, this will align everything it can
|
|
|
|
General.Map.Map.ClearMarkedSectors(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Limit the alignment to selection only
|
|
|
|
General.Map.Map.ClearMarkedSectors(true);
|
|
|
|
List<Sector> sectors = mode.GetSelectedSectors();
|
|
|
|
foreach(Sector s in sectors) s.Marked = false;
|
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Do the fill
|
2009-06-12 09:44:38 +00:00
|
|
|
Tools.FloodfillFlats(this.Sector.Sector, fillceilings, oldtexturelong, newtextureimage, false);
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Get the changed sectors
|
|
|
|
List<Sector> changes = General.Map.Map.GetMarkedSectors(true);
|
|
|
|
foreach(Sector s in changes)
|
|
|
|
{
|
|
|
|
// Update the visual sector
|
|
|
|
if(mode.VisualSectorExists(s))
|
|
|
|
{
|
|
|
|
BaseVisualSector vs = (mode.GetVisualSector(s) as BaseVisualSector);
|
|
|
|
if(fillceilings)
|
|
|
|
vs.Ceiling.Setup();
|
|
|
|
else
|
|
|
|
vs.Floor.Setup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
General.Map.Data.UpdateUsedTextures();
|
|
|
|
mode.Renderer.SetCrosshairBusy(false);
|
|
|
|
mode.ShowTargetInfo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy properties
|
|
|
|
public virtual void OnCopyProperties()
|
|
|
|
{
|
|
|
|
BuilderPlug.Me.CopiedSectorProps = new SectorProperties(Sector.Sector);
|
2009-05-02 14:59:05 +00:00
|
|
|
mode.SetActionResult("Copied sector properties.");
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Paste properties
|
|
|
|
public virtual void OnPasteProperties()
|
|
|
|
{
|
|
|
|
if(BuilderPlug.Me.CopiedSectorProps != null)
|
|
|
|
{
|
2009-05-03 19:22:32 +00:00
|
|
|
mode.CreateUndo("Paste sector properties");
|
2009-05-02 14:59:05 +00:00
|
|
|
mode.SetActionResult("Pasted sector properties.");
|
2009-04-19 18:07:22 +00:00
|
|
|
BuilderPlug.Me.CopiedSectorProps.Apply(Sector.Sector);
|
2009-05-09 13:41:26 +00:00
|
|
|
Sector.UpdateSectorGeometry(true);
|
2009-04-19 18:07:22 +00:00
|
|
|
mode.ShowTargetInfo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Select texture
|
|
|
|
public virtual void OnSelectTexture()
|
|
|
|
{
|
|
|
|
if(General.Interface.IsActiveWindow)
|
|
|
|
{
|
|
|
|
string oldtexture = GetTextureName();
|
|
|
|
string newtexture = General.Interface.BrowseFlat(General.Interface, oldtexture);
|
|
|
|
if(newtexture != oldtexture)
|
|
|
|
{
|
2009-05-03 19:22:32 +00:00
|
|
|
mode.ApplySelectTexture(newtexture, true);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-05-03 19:22:32 +00:00
|
|
|
|
|
|
|
// Apply Texture
|
|
|
|
public virtual void ApplyTexture(string texture)
|
|
|
|
{
|
|
|
|
mode.CreateUndo("Change flat " + texture);
|
|
|
|
SetTexture(texture);
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Copy texture
|
|
|
|
public virtual void OnCopyTexture()
|
|
|
|
{
|
|
|
|
BuilderPlug.Me.CopiedFlat = GetTextureName();
|
|
|
|
if(General.Map.Config.MixTexturesFlats) BuilderPlug.Me.CopiedTexture = GetTextureName();
|
2009-05-02 14:59:05 +00:00
|
|
|
mode.SetActionResult("Copied flat " + GetTextureName() + ".");
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public virtual void OnPasteTexture() { }
|
|
|
|
|
|
|
|
// Return texture name
|
|
|
|
public virtual string GetTextureName() { return ""; }
|
|
|
|
|
|
|
|
// Edit button released
|
|
|
|
public virtual void OnEditEnd()
|
|
|
|
{
|
|
|
|
// Not using any modifier buttons
|
|
|
|
if(!General.Interface.ShiftState && !General.Interface.CtrlState && !General.Interface.AltState)
|
|
|
|
{
|
|
|
|
if(General.Interface.IsActiveWindow)
|
|
|
|
{
|
2009-05-03 19:22:32 +00:00
|
|
|
List<Sector> sectors = mode.GetSelectedSectors();
|
2009-04-19 18:07:22 +00:00
|
|
|
DialogResult result = General.Interface.ShowEditSectors(sectors);
|
|
|
|
if(result == DialogResult.OK)
|
|
|
|
{
|
|
|
|
// Rebuild sector
|
2009-05-03 19:22:32 +00:00
|
|
|
foreach(Sector s in sectors)
|
|
|
|
{
|
|
|
|
VisualSector vs = mode.GetVisualSector(s);
|
|
|
|
if(vs != null)
|
2009-05-09 13:41:26 +00:00
|
|
|
(vs as BaseVisualSector).UpdateSectorGeometry(true);
|
2009-05-03 19:22:32 +00:00
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sector height change
|
|
|
|
public virtual void OnChangeTargetHeight(int amount)
|
|
|
|
{
|
2009-05-03 19:22:32 +00:00
|
|
|
changed = true;
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
ChangeHeight(amount);
|
|
|
|
|
|
|
|
// Rebuild sector
|
2009-05-09 13:41:26 +00:00
|
|
|
Sector.UpdateSectorGeometry(true);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Sector brightness change
|
|
|
|
public virtual void OnChangeTargetBrightness(bool up)
|
|
|
|
{
|
2009-05-03 19:22:32 +00:00
|
|
|
mode.CreateUndo("Change sector brightness", UndoGroup.SectorBrightnessChange, Sector.Sector.FixedIndex);
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
if(up)
|
|
|
|
Sector.Sector.Brightness = General.Map.Config.BrightnessLevels.GetNextHigher(Sector.Sector.Brightness);
|
|
|
|
else
|
|
|
|
Sector.Sector.Brightness = General.Map.Config.BrightnessLevels.GetNextLower(Sector.Sector.Brightness);
|
|
|
|
|
2009-05-02 14:59:05 +00:00
|
|
|
mode.SetActionResult("Changed sector brightness to " + Sector.Sector.Brightness + ".");
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
Sector.Sector.UpdateCache();
|
|
|
|
|
|
|
|
// Rebuild sector
|
2009-05-09 13:41:26 +00:00
|
|
|
Sector.UpdateSectorGeometry(false);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|