2008-01-02 21:49:43 +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;
|
2008-05-29 11:34:01 +00:00
|
|
|
using CodeImp.DoomBuilder.Actions;
|
2008-01-02 21:49:43 +00:00
|
|
|
using CodeImp.DoomBuilder.Plugins;
|
|
|
|
using System.Drawing;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Editing
|
|
|
|
{
|
|
|
|
internal class EditModeInfo : IComparable<EditModeInfo>
|
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
// Mode type
|
|
|
|
private Plugin plugin;
|
|
|
|
private Type type;
|
2008-11-27 10:33:09 +00:00
|
|
|
private EditModeAttribute attribs;
|
2008-01-02 21:49:43 +00:00
|
|
|
|
|
|
|
// Mode switching
|
2008-04-27 12:07:26 +00:00
|
|
|
private BeginActionAttribute switchactionattr = null;
|
2008-01-02 21:49:43 +00:00
|
|
|
private ActionDelegate switchactiondel = null;
|
|
|
|
|
|
|
|
// Mode button
|
|
|
|
private Stream buttonimagestream = null;
|
|
|
|
private Image buttonimage = null;
|
|
|
|
private string buttondesc = null;
|
|
|
|
private int buttonorder = int.MaxValue;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
public Plugin Plugin { get { return plugin; } }
|
|
|
|
public Type Type { get { return type; } }
|
2008-11-27 19:25:13 +00:00
|
|
|
public bool IsOptional { get { return ((switchactionattr != null) || (buttonimage != null)) && attribs.Optional; } }
|
2008-04-27 12:07:26 +00:00
|
|
|
public BeginActionAttribute SwitchAction { get { return switchactionattr; } }
|
2008-01-02 21:49:43 +00:00
|
|
|
public Image ButtonImage { get { return buttonimage; } }
|
|
|
|
public string ButtonDesc { get { return buttondesc; } }
|
2008-11-27 10:33:09 +00:00
|
|
|
public EditModeAttribute Attributes { get { return attribs; } }
|
2008-05-14 21:48:36 +00:00
|
|
|
|
2008-01-02 21:49:43 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
public EditModeInfo(Plugin plugin, Type type, EditModeAttribute attr)
|
|
|
|
{
|
|
|
|
// Initialize
|
|
|
|
this.plugin = plugin;
|
|
|
|
this.type = type;
|
2008-11-27 10:33:09 +00:00
|
|
|
this.attribs = attr;
|
2008-01-02 21:49:43 +00:00
|
|
|
|
2008-11-27 19:25:13 +00:00
|
|
|
// Make switch action info
|
|
|
|
if((attribs.SwitchAction != null) && (attribs.SwitchAction.Length > 0))
|
|
|
|
switchactionattr = new BeginActionAttribute(attribs.SwitchAction);
|
|
|
|
|
2008-01-02 21:49:43 +00:00
|
|
|
// Make button info
|
2008-11-27 19:25:13 +00:00
|
|
|
if(attr.ButtonImage != null)
|
2008-01-02 21:49:43 +00:00
|
|
|
{
|
2008-05-13 22:28:30 +00:00
|
|
|
buttonimagestream = plugin.GetResourceStream(attr.ButtonImage);
|
2008-01-02 21:49:43 +00:00
|
|
|
if(buttonimagestream != null)
|
|
|
|
{
|
|
|
|
buttonimage = Image.FromStream(buttonimagestream);
|
2008-11-27 19:25:13 +00:00
|
|
|
buttondesc = attr.DisplayName;
|
2008-01-02 21:49:43 +00:00
|
|
|
buttonorder = attr.ButtonOrder;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We have no destructor
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disposer
|
|
|
|
public void Dispose()
|
|
|
|
{
|
2008-11-27 13:42:18 +00:00
|
|
|
// Dispose
|
|
|
|
UnbindSwitchAction();
|
2008-01-02 21:49:43 +00:00
|
|
|
buttonimage.Dispose();
|
|
|
|
buttonimagestream.Dispose();
|
|
|
|
|
|
|
|
// Clean up
|
|
|
|
plugin = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
2008-11-27 13:42:18 +00:00
|
|
|
|
|
|
|
// This binds the action to switch to this editing mode
|
|
|
|
public void BindSwitchAction()
|
|
|
|
{
|
2008-11-27 19:25:13 +00:00
|
|
|
if((switchactiondel == null) && (switchactionattr != null))
|
2008-11-27 13:42:18 +00:00
|
|
|
{
|
|
|
|
switchactiondel = new ActionDelegate(UserSwitchToMode);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-14 21:48:36 +00:00
|
|
|
// This switches to the mode by user command
|
|
|
|
// (when user presses shortcut key)
|
|
|
|
public void UserSwitchToMode()
|
|
|
|
{
|
|
|
|
EditMode newmode;
|
|
|
|
|
|
|
|
// Only when a map is opened
|
|
|
|
if(General.Map != null)
|
|
|
|
{
|
|
|
|
// Not switching from volatile mode to volatile mode?
|
2008-11-27 11:59:17 +00:00
|
|
|
if((General.Editing.Mode == null) || !General.Editing.Mode.Attributes.Volatile || !this.attribs.Volatile)
|
2008-05-14 21:48:36 +00:00
|
|
|
{
|
|
|
|
// Create instance
|
|
|
|
newmode = plugin.CreateObject<EditMode>(type);
|
|
|
|
|
|
|
|
// Switch mode
|
2008-11-27 11:59:17 +00:00
|
|
|
General.Editing.ChangeMode(newmode);
|
2008-05-14 21:48:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-02 21:49:43 +00:00
|
|
|
// This switches to the mode
|
|
|
|
public void SwitchToMode()
|
|
|
|
{
|
|
|
|
EditMode newmode;
|
|
|
|
|
|
|
|
// Only when a map is opened
|
|
|
|
if(General.Map != null)
|
|
|
|
{
|
|
|
|
// Create instance
|
|
|
|
newmode = plugin.CreateObject<EditMode>(type);
|
|
|
|
|
|
|
|
// Switch mode
|
2008-11-27 11:59:17 +00:00
|
|
|
General.Editing.ChangeMode(newmode);
|
2008-01-02 21:49:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This switches to the mode with arguments
|
|
|
|
public void SwitchToMode(object[] args)
|
|
|
|
{
|
|
|
|
EditMode newmode;
|
|
|
|
|
|
|
|
// Only when a map is opened
|
|
|
|
if(General.Map != null)
|
|
|
|
{
|
|
|
|
// Create instance
|
|
|
|
newmode = plugin.CreateObjectA<EditMode>(type, args);
|
|
|
|
|
|
|
|
// Switch mode
|
2008-11-27 11:59:17 +00:00
|
|
|
if(!General.Editing.ChangeMode(newmode))
|
2008-10-08 15:15:45 +00:00
|
|
|
{
|
|
|
|
// When cancelled, dispose mode
|
|
|
|
newmode.Dispose();
|
|
|
|
}
|
2008-01-02 21:49:43 +00:00
|
|
|
}
|
|
|
|
}
|
2008-10-08 15:15:45 +00:00
|
|
|
|
2008-01-02 21:49:43 +00:00
|
|
|
// String representation
|
|
|
|
public override string ToString()
|
|
|
|
{
|
|
|
|
return type.Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compare by button order
|
|
|
|
public int CompareTo(EditModeInfo other)
|
|
|
|
{
|
|
|
|
if(this.buttonorder > other.buttonorder) return 1;
|
|
|
|
else if(this.buttonorder < other.buttonorder) return -1;
|
|
|
|
else return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|