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;
|
2016-06-02 09:55:01 +00:00
|
|
|
using System.Collections.Generic;
|
2015-09-16 12:10:43 +00:00
|
|
|
using System.Drawing;
|
2009-04-19 18:07:22 +00:00
|
|
|
using System.IO;
|
2016-06-02 09:55:01 +00:00
|
|
|
using System.Linq;
|
2009-04-19 18:07:22 +00:00
|
|
|
using CodeImp.DoomBuilder.Actions;
|
|
|
|
using CodeImp.DoomBuilder.Plugins;
|
2016-06-02 09:55:01 +00:00
|
|
|
using CodeImp.DoomBuilder.Rendering;
|
2009-04-19 18:07:22 +00:00
|
|
|
using CodeImp.DoomBuilder.VisualModes;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Editing
|
|
|
|
{
|
|
|
|
internal class EditModeInfo : IComparable<EditModeInfo>
|
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
// Mode type
|
|
|
|
private Plugin plugin;
|
2015-09-16 12:10:43 +00:00
|
|
|
private readonly Type type;
|
|
|
|
private readonly EditModeAttribute attribs;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Mode switching
|
2015-09-16 12:10:43 +00:00
|
|
|
private readonly BeginActionAttribute switchactionattr;
|
2014-02-21 14:42:12 +00:00
|
|
|
private ActionDelegate switchactiondel;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Mode button
|
2015-09-16 12:10:43 +00:00
|
|
|
private readonly Image buttonimage;
|
|
|
|
private readonly string buttondesc;
|
|
|
|
private readonly int buttonorder = int.MaxValue;
|
|
|
|
|
|
|
|
//mxd. Disposing
|
|
|
|
private bool isdisposed;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
public Plugin Plugin { get { return plugin; } }
|
|
|
|
public Type Type { get { return type; } }
|
|
|
|
public bool IsOptional { get { return ((switchactionattr != null) || (buttonimage != null)) && attribs.Optional; } }
|
|
|
|
public BeginActionAttribute SwitchAction { get { return switchactionattr; } }
|
|
|
|
public Image ButtonImage { get { return buttonimage; } }
|
|
|
|
public string ButtonDesc { get { return buttondesc; } }
|
|
|
|
public EditModeAttribute Attributes { get { return attribs; } }
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
public EditModeInfo(Plugin plugin, Type type, EditModeAttribute attr)
|
|
|
|
{
|
|
|
|
// Initialize
|
|
|
|
this.plugin = plugin;
|
|
|
|
this.type = type;
|
|
|
|
this.attribs = attr;
|
|
|
|
|
|
|
|
// Make switch action info
|
2014-02-18 14:04:14 +00:00
|
|
|
if(!string.IsNullOrEmpty(attribs.SwitchAction))
|
2009-04-19 18:07:22 +00:00
|
|
|
switchactionattr = new BeginActionAttribute(attribs.SwitchAction);
|
|
|
|
|
|
|
|
// Make button info
|
2015-09-16 12:10:43 +00:00
|
|
|
if(!string.IsNullOrEmpty(attr.ButtonImage))
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2015-09-16 12:10:43 +00:00
|
|
|
using(Stream stream = plugin.GetResourceStream(attr.ButtonImage))
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2015-09-16 12:10:43 +00:00
|
|
|
if(stream != null)
|
|
|
|
{
|
|
|
|
buttonimage = Image.FromStream(stream);
|
|
|
|
buttondesc = attr.DisplayName;
|
|
|
|
buttonorder = attr.ButtonOrder;
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We have no destructor
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disposer
|
|
|
|
public void Dispose()
|
|
|
|
{
|
2015-09-16 12:10:43 +00:00
|
|
|
// Not already disposed?
|
|
|
|
if(!isdisposed)
|
|
|
|
{
|
|
|
|
// Dispose
|
|
|
|
UnbindSwitchAction();
|
|
|
|
if(buttonimage != null) buttonimage.Dispose();
|
|
|
|
|
|
|
|
// Clean up
|
|
|
|
plugin = null;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2015-09-16 12:10:43 +00:00
|
|
|
// Done
|
|
|
|
isdisposed = true;
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
|
|
|
// This binds the action to switch to this editing mode
|
|
|
|
public void BindSwitchAction()
|
|
|
|
{
|
|
|
|
if((switchactiondel == null) && (switchactionattr != null))
|
|
|
|
{
|
2014-02-21 14:42:12 +00:00
|
|
|
switchactiondel = UserSwitchToMode;
|
2009-04-19 18:07:22 +00:00
|
|
|
General.Actions.BindBeginDelegate(plugin.Assembly, switchactiondel, switchactionattr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This unbind the switch action
|
|
|
|
public void UnbindSwitchAction()
|
|
|
|
{
|
|
|
|
if(switchactiondel != null)
|
|
|
|
{
|
|
|
|
General.Actions.UnbindBeginDelegate(plugin.Assembly, switchactiondel, switchactionattr);
|
|
|
|
switchactiondel = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-05 22:06:56 +00:00
|
|
|
// This switches to the mode by user command (when user presses shortcut key)
|
2009-04-19 18:07:22 +00:00
|
|
|
public void UserSwitchToMode()
|
|
|
|
{
|
|
|
|
// Only when a map is opened
|
|
|
|
if(General.Map != null)
|
|
|
|
{
|
2016-06-05 22:06:56 +00:00
|
|
|
//mxd. Not the same mode?
|
|
|
|
if(type != General.Editing.Mode.GetType())
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2016-06-05 22:06:56 +00:00
|
|
|
// Switching from volatile mode to a different volatile mode?
|
|
|
|
if((General.Editing.Mode != null) && General.Editing.Mode.Attributes.Volatile && this.attribs.Volatile)
|
|
|
|
{
|
|
|
|
// First cancel previous volatile mode
|
|
|
|
General.Editing.CancelVolatileMode();
|
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Create instance
|
2014-02-26 14:11:06 +00:00
|
|
|
EditMode newmode = plugin.CreateObject<EditMode>(type);
|
2016-06-05 22:06:56 +00:00
|
|
|
|
2015-10-02 23:15:29 +00:00
|
|
|
//mxd. Switch mode?
|
|
|
|
if(newmode != null) General.Editing.ChangeMode(newmode);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
2016-06-05 22:06:56 +00:00
|
|
|
// When in VisualMode and switching to the same VisualMode, switch back to the previous classic mode
|
|
|
|
else if(General.Editing.Mode is VisualMode)
|
|
|
|
{
|
|
|
|
// Switch back to last classic mode
|
|
|
|
General.Editing.ChangeMode(General.Editing.PreviousClassicMode.Name);
|
|
|
|
}
|
2016-06-06 21:06:01 +00:00
|
|
|
//mxd. Switch between view floor and view ceiling textures?
|
|
|
|
else if(General.Editing.Mode is ClassicMode && General.Settings.SwitchViewModes)
|
|
|
|
{
|
|
|
|
ClassicMode.SetViewMode(General.Map.Renderer2D.ViewMode == ViewMode.FloorTextures ? ViewMode.CeilingTextures : ViewMode.FloorTextures);
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This switches to the mode
|
|
|
|
public void SwitchToMode()
|
|
|
|
{
|
|
|
|
// Only when a map is opened
|
|
|
|
if(General.Map != null)
|
|
|
|
{
|
|
|
|
// Create instance
|
2014-02-26 14:11:06 +00:00
|
|
|
EditMode newmode = plugin.CreateObject<EditMode>(type);
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2015-10-02 23:15:29 +00:00
|
|
|
//mxd. Switch mode?
|
|
|
|
if(newmode != null) General.Editing.ChangeMode(newmode);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This switches to the mode with arguments
|
|
|
|
public void SwitchToMode(object[] args)
|
|
|
|
{
|
|
|
|
// Only when a map is opened
|
|
|
|
if(General.Map != null)
|
|
|
|
{
|
|
|
|
// Create instance
|
2014-02-26 14:11:06 +00:00
|
|
|
EditMode newmode = plugin.CreateObjectA<EditMode>(type, args);
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Switch mode
|
|
|
|
if(!General.Editing.ChangeMode(newmode))
|
|
|
|
{
|
|
|
|
// When cancelled, dispose mode
|
|
|
|
newmode.Dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// String representation
|
|
|
|
public override string ToString()
|
|
|
|
{
|
2009-07-09 15:15:49 +00:00
|
|
|
return attribs.DisplayName;
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Compare by button order
|
|
|
|
public int CompareTo(EditModeInfo other)
|
|
|
|
{
|
|
|
|
if(this.buttonorder > other.buttonorder) return 1;
|
2014-02-26 14:11:06 +00:00
|
|
|
if(this.buttonorder < other.buttonorder) return -1;
|
|
|
|
return 0;
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|