more on selectable editing modes

This commit is contained in:
codeimp 2008-11-27 19:25:13 +00:00
parent 6e67dba0d4
commit e135c279eb
22 changed files with 165 additions and 87 deletions

View file

@ -99,7 +99,7 @@
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="Testing\TriangulatorMode.cs" />
<Compile Include="Testing\TriangulatorMode.cs" />
<Compile Include="ClassicModes\DragThingsMode.cs" />
<Compile Include="General\LineLengthLabel.cs" />
<Compile Include="VisualModes\BaseVisualMode.cs" />
@ -110,7 +110,7 @@
<Compile Include="VisualModes\VisualFloor.cs" />
<Compile Include="VisualModes\VisualLower.cs" />
<Compile Include="VisualModes\VisualMiddle.cs" />
<None Include="Testing\WAuthorMode.cs" />
<Compile Include="Testing\WAuthorMode.cs" />
<Compile Include="Testing\WAuthorTools.cs">
<SubType>Form</SubType>
</Compile>

View file

@ -40,10 +40,10 @@ namespace CodeImp.DoomBuilder.BuilderModes
{
[EditMode(DisplayName = "Brightness Mode",
SwitchAction = "brightnessmode",
ButtonDesc = "Brightness Mode",
ButtonImage = "BrightnessMode.png",
ButtonOrder = int.MinValue + 201,
AllowCopyPaste = false)]
AllowCopyPaste = false,
UseByDefault = true)]
public sealed class BrightnessMode : BaseClassicMode
{

View file

@ -37,9 +37,11 @@ using CodeImp.DoomBuilder.Actions;
namespace CodeImp.DoomBuilder.BuilderModes
{
[EditMode(DisplayName = "Drawing",
[EditMode(DisplayName = "Drawing Mode",
SwitchAction = "drawlinesmode",
Volatile = true)]
Volatile = true,
UseByDefault = true,
Optional = false)]
public class DrawGeometryMode : BaseClassicMode
{

View file

@ -39,9 +39,11 @@ using System.Drawing;
namespace CodeImp.DoomBuilder.BuilderModes
{
[EditMode(DisplayName = "Edit Selection",
[EditMode(DisplayName = "Edit Selection Mode",
SwitchAction = "editselectionmode", // Action name used to switch to this mode
Volatile = true)]
Volatile = true,
UseByDefault = true,
Optional = false)]
public class EditSelectionMode : BaseClassicMode
{

View file

@ -36,9 +36,10 @@ using CodeImp.DoomBuilder.Editing;
namespace CodeImp.DoomBuilder.BuilderModes
{
[EditMode(DisplayName = "Map Analysis",
[EditMode(DisplayName = "Map Analysis Mode",
SwitchAction = "errorcheckmode",
Volatile = true)]
Volatile = true,
UseByDefault = true)]
public sealed class ErrorCheckMode : BaseClassicMode
{

View file

@ -36,9 +36,10 @@ using CodeImp.DoomBuilder.Editing;
namespace CodeImp.DoomBuilder.BuilderModes
{
[EditMode(DisplayName = "Find & Replace",
[EditMode(DisplayName = "Find & Replace Mode",
SwitchAction = "findmode",
Volatile = true)]
Volatile = true,
UseByDefault = true)]
public sealed class FindReplaceMode : BaseClassicMode
{

View file

@ -38,11 +38,11 @@ using CodeImp.DoomBuilder.Config;
namespace CodeImp.DoomBuilder.BuilderModes
{
[EditMode(DisplayName = "Linedefs",
[EditMode(DisplayName = "Linedefs Mode",
SwitchAction = "linedefsmode", // Action name used to switch to this mode
ButtonDesc = "Linedefs Mode", // Description on the button in toolbar/menu
ButtonImage = "LinesMode.png", // Image resource name for the button
ButtonOrder = int.MinValue + 100)] // Position of the button (lower is more to the left)
ButtonOrder = int.MinValue + 100, // Position of the button (lower is more to the left)
UseByDefault = true)]
public class LinedefsMode : BaseClassicMode
{

View file

@ -37,11 +37,11 @@ using CodeImp.DoomBuilder.Actions;
namespace CodeImp.DoomBuilder.BuilderModes
{
[EditMode(DisplayName = "Make Sectors",
[EditMode(DisplayName = "Make Sectors Mode",
SwitchAction = "makesectormode",
ButtonDesc = "Make Sectors Mode", // Description on the button in toolbar/menu
ButtonImage = "NewSector2.png", // Image resource name for the button
ButtonOrder = int.MinValue + 202)] // Position of the button (lower is more to the left)
ButtonOrder = int.MinValue + 202, // Position of the button (lower is more to the left)
UseByDefault = true)]
public class MakeSectorMode : BaseClassicMode
{

View file

@ -39,11 +39,11 @@ using CodeImp.DoomBuilder.BuilderModes.Interface;
namespace CodeImp.DoomBuilder.BuilderModes
{
[EditMode(DisplayName = "Sectors",
[EditMode(DisplayName = "Sectors Mode",
SwitchAction = "sectorsmode", // Action name used to switch to this mode
ButtonDesc = "Sectors Mode", // Description on the button in toolbar/menu
ButtonImage = "SectorsMode.png", // Image resource name for the button
ButtonOrder = int.MinValue + 200)] // Position of the button (lower is more to the left)
ButtonOrder = int.MinValue + 200, // Position of the button (lower is more to the left)
UseByDefault = true)]
public class SectorsMode : BaseClassicMode
{

View file

@ -38,11 +38,11 @@ using CodeImp.DoomBuilder.Types;
namespace CodeImp.DoomBuilder.BuilderModes
{
[EditMode(DisplayName = "Things",
[EditMode(DisplayName = "Things Mode",
SwitchAction = "thingsmode", // Action name used to switch to this mode
ButtonDesc = "Things Mode", // Description on the button in toolbar/menu
ButtonImage = "ThingsMode.png", // Image resource name for the button
ButtonOrder = int.MinValue + 300)] // Position of the button (lower is more to the left)
ButtonOrder = int.MinValue + 300, // Position of the button (lower is more to the left)
UseByDefault = true)]
public class ThingsMode : BaseClassicMode
{

View file

@ -36,11 +36,11 @@ using CodeImp.DoomBuilder.Actions;
namespace CodeImp.DoomBuilder.BuilderModes
{
[EditMode(DisplayName = "Vertices",
[EditMode(DisplayName = "Vertices Mode",
SwitchAction = "verticesmode", // Action name used to switch to this mode
ButtonDesc = "Vertices Mode", // Description on the button in toolbar/menu
ButtonImage = "VerticesMode.png", // Image resource name for the button
ButtonOrder = int.MinValue + 0)] // Position of the button (lower is more to the left)
ButtonOrder = int.MinValue + 0, // Position of the button (lower is more to the left)
UseByDefault = true)]
public class VerticesMode : BaseClassicMode
{

View file

@ -39,8 +39,8 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
{
#if DEBUG
[EditMode(SwitchAction = "triangulatormode", // Action name used to switch to this mode
ButtonDesc = "Triangulator Mode", // Description on the button in toolbar/menu
[EditMode(DisplayName = "Triangulator Mode",
SwitchAction = "triangulatormode", // Action name used to switch to this mode
ButtonImage = "TriangulatorMode.png", // Image resource name for the button
ButtonOrder = int.MaxValue)] // Position of the button (lower is more to the left)

View file

@ -36,8 +36,10 @@ using CodeImp.DoomBuilder.Actions;
namespace CodeImp.DoomBuilder.BuilderModes.Editing
{
[EditMode(SwitchAction = "wauthormode",
ButtonDesc = "WadAuthor Mode",
#if DEBUG
[EditMode(DisplayName = "WadAuthor Mode",
SwitchAction = "wauthormode",
ButtonImage = "WAuthor.png",
ButtonOrder = int.MinValue + 4)]
@ -385,4 +387,6 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
#endregion
}
#endif
}

View file

@ -39,9 +39,9 @@ namespace CodeImp.DoomBuilder.BuilderModes
{
[EditMode(DisplayName = "Visual Mode",
SwitchAction = "visualmode", // Action name used to switch to this mode
ButtonDesc = "Visual Mode", // Description on the button in toolbar/menu
ButtonImage = "VisualMode.png", // Image resource name for the button
ButtonOrder = 0)] // Position of the button (lower is more to the left)
ButtonOrder = 0, // Position of the button (lower is more to the left)
UseByDefault = true)]
public class BaseVisualMode : VisualMode
{

View file

@ -25,6 +25,7 @@ using CodeImp.DoomBuilder.IO;
using CodeImp.DoomBuilder.Data;
using System.IO;
using CodeImp.DoomBuilder.Editing;
using System.Collections.Specialized;
#endregion
@ -32,6 +33,13 @@ namespace CodeImp.DoomBuilder.Config
{
internal class ConfigurationInfo : IComparable<ConfigurationInfo>
{
#region ================== Constants
private const string MODE_DISABLED_KEY = "disabled";
private const string MODE_ENABLED_KEY = "enabled";
#endregion
#region ================== Variables
private string name;
@ -47,7 +55,7 @@ namespace CodeImp.DoomBuilder.Config
private int testskill;
private List<ThingsFilter> thingsfilters;
private List<DefinedTextureSet> texturesets;
private List<string> editmodes;
private Dictionary<string, bool> editmodes;
#endregion
@ -65,7 +73,7 @@ namespace CodeImp.DoomBuilder.Config
public bool CustomParameters { get { return customparameters; } set { customparameters = value; } }
internal ICollection<ThingsFilter> ThingsFilters { get { return thingsfilters; } }
public List<DefinedTextureSet> TextureSets { get { return texturesets; } }
internal List<string> EditModes { get { return editmodes; } }
internal Dictionary<string, bool> EditModes { get { return editmodes; } }
#endregion
@ -108,11 +116,14 @@ namespace CodeImp.DoomBuilder.Config
}
// Make list of edit modes
this.editmodes = new List<string>();
this.editmodes = new Dictionary<string, bool>();
IDictionary modes = General.Settings.ReadSetting("configurations." + settingskey + ".editmodes", new Hashtable());
foreach(DictionaryEntry de in modes)
{
editmodes.Add(de.Value.ToString());
if(de.Key.ToString().StartsWith(MODE_ENABLED_KEY))
editmodes.Add(de.Value.ToString(), true);
else if(de.Key.ToString().StartsWith(MODE_DISABLED_KEY))
editmodes.Add(de.Value.ToString(), false);
}
}
@ -159,10 +170,18 @@ namespace CodeImp.DoomBuilder.Config
}
// Write filters to configuration
for(int i = 0; i < editmodes.Count; i++)
ListDictionary modeslist = new ListDictionary();
int index = 0;
foreach(KeyValuePair<string, bool> em in editmodes)
{
General.Settings.WriteSetting("configurations." + settingskey + ".editmodes.mode" + i.ToString(CultureInfo.InvariantCulture), editmodes[i]);
if(em.Value)
modeslist.Add(MODE_ENABLED_KEY + index.ToString(CultureInfo.InvariantCulture), em.Key);
else
modeslist.Add(MODE_DISABLED_KEY + index.ToString(CultureInfo.InvariantCulture), em.Key);
index++;
}
General.Settings.WriteSetting("configurations." + settingskey + ".editmodes", modeslist);
}
// String representation
@ -188,7 +207,7 @@ namespace CodeImp.DoomBuilder.Config
ci.testskill = this.testskill;
ci.texturesets = new List<DefinedTextureSet>();
foreach(DefinedTextureSet s in this.texturesets) ci.texturesets.Add(s.Copy());
ci.editmodes = new List<string>(this.editmodes);
ci.editmodes = new Dictionary<string, bool>(this.editmodes);
return ci;
}
@ -208,20 +227,36 @@ namespace CodeImp.DoomBuilder.Config
this.testskill = ci.testskill;
this.texturesets = new List<DefinedTextureSet>();
foreach(DefinedTextureSet s in ci.texturesets) this.texturesets.Add(s.Copy());
this.editmodes = new List<string>(ci.editmodes);
this.editmodes = new Dictionary<string, bool>(ci.editmodes);
}
// This applies the defaults
public void ApplyDefaults()
public void ApplyDefaults(GameConfiguration gameconfig)
{
// No texture sets?
if(texturesets.Count == 0)
// We can only apply texture set defaults when the game configuration is specified
if(gameconfig != null)
{
// Copy the default texture sets from the game configuration
foreach(DefinedTextureSet s in General.Map.Config.TextureSets)
// No texture sets?
if(texturesets.Count == 0)
{
// Add a copy to our list
texturesets.Add(s.Copy());
// Copy the default texture sets from the game configuration
foreach(DefinedTextureSet s in gameconfig.TextureSets)
{
// Add a copy to our list
texturesets.Add(s.Copy());
}
}
}
// Go for all available editing modes
foreach(EditModeInfo info in General.Editing.ModesInfo)
{
// Is this a mode thats is optional?
if(info.IsOptional)
{
// Add if not listed yet
if(!editmodes.ContainsKey(info.Type.FullName))
editmodes.Add(info.Type.FullName, info.Attributes.UseByDefault);
}
}
}

View file

@ -39,12 +39,12 @@ namespace CodeImp.DoomBuilder.Editing
// Properties
private string switchaction = null;
private string buttonimage = null;
private string buttondesc = null;
private int buttonorder = 0;
private bool optional = false;
private bool optional = true;
private bool isvolatile = false;
private string displayname = "<unnamed mode>";
private bool allowcopypaste = true;
private bool usebydefault = false;
#endregion
@ -63,11 +63,6 @@ namespace CodeImp.DoomBuilder.Editing
/// </summary>
public string ButtonImage { get { return buttonimage; } set { buttonimage = value; } }
/// <summary>
/// Toolbar button and menu item description of this mode.
/// </summary>
public string ButtonDesc { get { return buttondesc; } set { buttondesc = value; } }
/// <summary>
/// Sorting number for the order of buttons on the toolbar. Buttons with
/// lower values will be more to the left than buttons with higher values.
@ -80,6 +75,13 @@ namespace CodeImp.DoomBuilder.Editing
/// </summary>
public bool Optional { get { return optional; } set { optional = value; } }
/// <summary>
/// Set this to true to select this editing mode for use in all game configurations
/// by default. This only applies the first time and can still be changed by the user.
/// THIS OPTION MAY BE INTRUSIVE TO THE USER, USE WITH GREAT CARE!
/// </summary>
public bool UseByDefault { get { return usebydefault; } set { usebydefault = value; } }
/// <summary>
/// When set to true, this mode is cancelled when core actions like
/// undo and save are performed. The editing mode should then return to
@ -88,8 +90,8 @@ namespace CodeImp.DoomBuilder.Editing
public bool Volatile { get { return isvolatile; } set { isvolatile = value; } }
/// <summary>
/// Name to display on the button information bar when no specific element
/// information is displayed.
/// Name to display in the game configuration editing modes list and on the
/// information bar when the mode is currently active.
/// </summary>
public string DisplayName { get { return displayname; } set { displayname = value; } }

View file

@ -61,6 +61,7 @@ namespace CodeImp.DoomBuilder.Editing
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; } }
@ -78,14 +79,18 @@ namespace CodeImp.DoomBuilder.Editing
this.type = type;
this.attribs = attr;
// Make switch action info
if((attribs.SwitchAction != null) && (attribs.SwitchAction.Length > 0))
switchactionattr = new BeginActionAttribute(attribs.SwitchAction);
// Make button info
if((attr.ButtonImage != null) && (attr.ButtonDesc != null))
if(attr.ButtonImage != null)
{
buttonimagestream = plugin.GetResourceStream(attr.ButtonImage);
if(buttonimagestream != null)
{
buttonimage = Image.FromStream(buttonimagestream);
buttondesc = attr.ButtonDesc;
buttondesc = attr.DisplayName;
buttonorder = attr.ButtonOrder;
}
}
@ -113,13 +118,9 @@ namespace CodeImp.DoomBuilder.Editing
// This binds the action to switch to this editing mode
public void BindSwitchAction()
{
// Make switch action info
if((switchactiondel == null) && (attribs.SwitchAction != null) && (attribs.SwitchAction.Length > 0))
if((switchactiondel == null) && (switchactionattr != null))
{
switchactionattr = new BeginActionAttribute(attribs.SwitchAction);
switchactiondel = new ActionDelegate(UserSwitchToMode);
// Bind switch action
General.Actions.BindBeginDelegate(plugin.Assembly, switchactiondel, switchactionattr);
}
}

View file

@ -153,7 +153,10 @@ namespace CodeImp.DoomBuilder.Editing
{
foreach(EditModeInfo emi in allmodes)
{
if(General.Map.ConfigSettings.EditModes.Contains(emi.Type.FullName))
// Include the mode when it is listed and enabled
// Also include the mode when it is not optional
if( (General.Map.ConfigSettings.EditModes.ContainsKey(emi.Type.FullName) &&
General.Map.ConfigSettings.EditModes[emi.Type.FullName]) || !emi.IsOptional )
{
// Add the mode to be used and bind switch action
usedmodes.Add(emi);
@ -188,11 +191,34 @@ namespace CodeImp.DoomBuilder.Editing
{
EditMode oldmode = mode;
// Log info
if(newmode != null)
General.WriteLogLine("Switching edit mode to " + newmode.GetType().Name + "...");
if(nextmode != null)
{
// Verify that this mode is usable
bool allowuse = false;
foreach(EditModeInfo emi in usedmodes)
{
if(emi.Type.FullName == nextmode.GetType().FullName)
{
allowuse = true;
break;
}
}
if(!allowuse)
{
General.Interface.MessageBeep(MessageBeepType.Error);
General.WriteLogLine("Attempt to switch to an invalid edit mode " + nextmode.GetType().Name + "!");
return false;
}
else
{
General.WriteLogLine("Switching edit mode to " + nextmode.GetType().Name + "...");
}
}
else
{
General.WriteLogLine("Stopping edit mode...");
}
// Remember previous mode
newmode = nextmode;

View file

@ -599,14 +599,19 @@ namespace CodeImp.DoomBuilder
plugins = new PluginManager();
plugins.LoadAllPlugins();
// Load game configurations
General.WriteLogLine("Loading game configurations...");
LoadAllGameConfigurations();
// Create editing modes
General.WriteLogLine("Creating editing modes manager...");
editing = new EditingManager();
// Now that all settings have been combined (core & plugins) apply the defaults
General.WriteLogLine("Applying configuration settings...");
actions.ApplyDefaultShortcutKeys();
mainwindow.ApplyShortcutKeys();
// Load game configurations
General.WriteLogLine("Loading game configurations...");
LoadAllGameConfigurations();
foreach(ConfigurationInfo info in configs) info.ApplyDefaults(null);
// Load compiler configurations
General.WriteLogLine("Loading compiler configurations...");
@ -632,10 +637,6 @@ namespace CodeImp.DoomBuilder
General.WriteLogLine("Creating types manager...");
types = new TypesManager();
// Create editing modes
General.WriteLogLine("Creating editing modes manager...");
editing = new EditingManager();
// Do auto map loading when window is delayed
if(delaymainwindow)
mainwindow.PerformAutoMapLoading();

View file

@ -234,7 +234,7 @@ namespace CodeImp.DoomBuilder
General.WriteLogLine("Loading game configuration...");
configinfo = General.GetConfigurationInfo(options.ConfigFile);
config = new GameConfiguration(General.LoadGameConfiguration(options.ConfigFile));
configinfo.ApplyDefaults();
configinfo.ApplyDefaults(config);
General.Editing.UpdateCurrentEditModes();
// Create map data
@ -306,7 +306,7 @@ namespace CodeImp.DoomBuilder
General.WriteLogLine("Loading game configuration...");
configinfo = General.GetConfigurationInfo(options.ConfigFile);
config = new GameConfiguration(General.LoadGameConfiguration(options.ConfigFile));
configinfo.ApplyDefaults();
configinfo.ApplyDefaults(config);
General.Editing.UpdateCurrentEditModes();
// Create map data
@ -1314,7 +1314,7 @@ namespace CodeImp.DoomBuilder
General.WriteLogLine("Loading game configuration...");
configinfo = General.GetConfigurationInfo(options.ConfigFile);
config = new GameConfiguration(General.LoadGameConfiguration(options.ConfigFile));
configinfo.ApplyDefaults();
configinfo.ApplyDefaults(config);
General.Editing.UpdateCurrentEditModes();
// Setup new map format IO

View file

@ -566,11 +566,11 @@ namespace CodeImp.DoomBuilder.Windows
this.colmodeplugin});
this.listmodes.FullRowSelect = true;
this.listmodes.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.listmodes.Location = new System.Drawing.Point(15, 76);
this.listmodes.Location = new System.Drawing.Point(15, 70);
this.listmodes.MultiSelect = false;
this.listmodes.Name = "listmodes";
this.listmodes.ShowGroups = false;
this.listmodes.Size = new System.Drawing.Size(442, 226);
this.listmodes.Size = new System.Drawing.Size(442, 233);
this.listmodes.Sorting = System.Windows.Forms.SortOrder.Ascending;
this.listmodes.TabIndex = 26;
this.listmodes.UseCompatibleStateImageBehavior = false;

View file

@ -78,7 +78,7 @@ namespace CodeImp.DoomBuilder.Windows
foreach(EditModeInfo emi in General.Editing.ModesInfo)
{
// Is this mode selectable by the user?
if(emi.ButtonImage != null)
if(emi.IsOptional)
{
lvi = listmodes.Items.Add(emi.Attributes.DisplayName);
lvi.Tag = emi;
@ -110,6 +110,9 @@ namespace CodeImp.DoomBuilder.Windows
// Load the game configuration
gameconfig = new GameConfiguration(General.LoadGameConfiguration(configinfo.Filename));
// Set defaults
configinfo.ApplyDefaults(gameconfig);
// Fill resources list
configdata.EditResourceLocationList(configinfo.Resources);
@ -172,7 +175,7 @@ namespace CodeImp.DoomBuilder.Windows
foreach(ListViewItem lvi in listmodes.Items)
{
EditModeInfo emi = (lvi.Tag as EditModeInfo);
lvi.Checked = configinfo.EditModes.Contains(emi.Type.FullName);
lvi.Checked = (configinfo.EditModes.ContainsKey(emi.Type.FullName) && configinfo.EditModes[emi.Type.FullName]);
}
}
}
@ -486,16 +489,16 @@ namespace CodeImp.DoomBuilder.Windows
// Apply changes
EditModeInfo emi = (e.Item.Tag as EditModeInfo);
bool currentstate = configinfo.EditModes.Contains(emi.Type.FullName);
bool currentstate = (configinfo.EditModes.ContainsKey(emi.Type.FullName) && configinfo.EditModes[emi.Type.FullName]);
if(e.Item.Checked && !currentstate)
{
// Add
configinfo.EditModes.Add(emi.Type.FullName);
configinfo.EditModes[emi.Type.FullName] = true;
}
else if(!e.Item.Checked && currentstate)
{
// Remove
configinfo.EditModes.Remove(emi.Type.FullName);
configinfo.EditModes[emi.Type.FullName] = false;
}
}
}