From d7656f1f3b33bfa84b2221a31f2418671478294f Mon Sep 17 00:00:00 2001 From: codeimp Date: Wed, 14 May 2008 21:48:36 +0000 Subject: [PATCH] - added some new menus in the plugin - volatile mode may not be started from a volatile mode by shortcut key! - added ability to cancel an editing mode change - added mipmap levels setting to images (this fixes blurred fonts in low-quality display) --- Source/BuilderModes/BuilderModes.csproj | 10 + .../ClassicModes/DragGeometryMode.cs | 13 +- .../ClassicModes/DragLinedefsMode.cs | 2 +- .../ClassicModes/DragSectorsMode.cs | 2 +- .../ClassicModes/DragThingsMode.cs | 4 +- .../ClassicModes/DragVerticesMode.cs | 2 +- .../ClassicModes/DrawGeometryMode.cs | 4 +- .../BuilderModes/ClassicModes/LinedefsMode.cs | 2 +- .../BuilderModes/ClassicModes/SectorsMode.cs | 2 +- .../BuilderModes/ClassicModes/ThingsMode.cs | 2 +- .../BuilderModes/ClassicModes/VerticesMode.cs | 2 +- .../Interface/MenusForm.Designer.cs | 181 ++++++++++++++++++ Source/BuilderModes/Interface/MenusForm.cs | 119 ++++++++++++ Source/BuilderModes/Interface/MenusForm.resx | 123 ++++++++++++ Source/Data/ImageData.cs | 4 +- Source/Editing/EditModeInfo.cs | 28 ++- Source/General/MapManager.cs | 23 +++ Source/Interface/IMainForm.cs | 2 + Source/Interface/MainForm.cs | 13 ++ Source/Plugins/Plug.cs | 17 ++ Source/Plugins/Plugin.cs | 2 +- Source/Plugins/PluginManager.cs | 16 +- Source/Rendering/D3DDevice.cs | 1 + 23 files changed, 554 insertions(+), 20 deletions(-) create mode 100644 Source/BuilderModes/Interface/MenusForm.Designer.cs create mode 100644 Source/BuilderModes/Interface/MenusForm.cs create mode 100644 Source/BuilderModes/Interface/MenusForm.resx diff --git a/Source/BuilderModes/BuilderModes.csproj b/Source/BuilderModes/BuilderModes.csproj index 298a49bb..edaa2fa9 100644 --- a/Source/BuilderModes/BuilderModes.csproj +++ b/Source/BuilderModes/BuilderModes.csproj @@ -38,6 +38,12 @@ + + Form + + + MenusForm.cs + @@ -93,6 +99,10 @@ + + Designer + MenusForm.cs + diff --git a/Source/BuilderModes/ClassicModes/DragGeometryMode.cs b/Source/BuilderModes/ClassicModes/DragGeometryMode.cs index 8a5881a6..5a634ad5 100644 --- a/Source/BuilderModes/ClassicModes/DragGeometryMode.cs +++ b/Source/BuilderModes/ClassicModes/DragGeometryMode.cs @@ -34,7 +34,7 @@ using CodeImp.DoomBuilder.Editing; #endregion -namespace CodeImp.DoomBuilder.BuilderModes.Editing +namespace CodeImp.DoomBuilder.BuilderModes { public abstract class DragGeometryMode : ClassicMode { @@ -87,6 +87,8 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing // Just keep the base mode button checked public override string EditModeButtonName { get { return basemode.GetType().Name; } } + + internal EditMode BaseMode { get { return basemode; } } #endregion @@ -300,11 +302,12 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing public override void Disengage() { base.Disengage(); - Cursor.Current = Cursors.AppStarting; // When not cancelled if(!cancelled) { + Cursor.Current = Cursors.AppStarting; + // Move geometry back to original position MoveGeometryRelative(new Vector2D(0f, 0f), false, false); @@ -323,15 +326,13 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing // Update cached values General.Map.Map.Update(); - // Map is changed + // Done + Cursor.Current = Cursors.Default; General.Map.IsChanged = true; } // Hide highlight info General.Interface.HideInfo(); - - // Done - Cursor.Current = Cursors.Default; } // This checks if the view offset/zoom changed and updates the check diff --git a/Source/BuilderModes/ClassicModes/DragLinedefsMode.cs b/Source/BuilderModes/ClassicModes/DragLinedefsMode.cs index 558c22c6..28949bf9 100644 --- a/Source/BuilderModes/ClassicModes/DragLinedefsMode.cs +++ b/Source/BuilderModes/ClassicModes/DragLinedefsMode.cs @@ -34,7 +34,7 @@ using CodeImp.DoomBuilder.Editing; #endregion -namespace CodeImp.DoomBuilder.BuilderModes.Editing +namespace CodeImp.DoomBuilder.BuilderModes { // No action or button for this mode, it is automatic. // The EditMode attribute does not have to be specified unless the diff --git a/Source/BuilderModes/ClassicModes/DragSectorsMode.cs b/Source/BuilderModes/ClassicModes/DragSectorsMode.cs index 56ef905c..20c51919 100644 --- a/Source/BuilderModes/ClassicModes/DragSectorsMode.cs +++ b/Source/BuilderModes/ClassicModes/DragSectorsMode.cs @@ -34,7 +34,7 @@ using CodeImp.DoomBuilder.Editing; #endregion -namespace CodeImp.DoomBuilder.BuilderModes.Editing +namespace CodeImp.DoomBuilder.BuilderModes { // No action or button for this mode, it is automatic. // The EditMode attribute does not have to be specified unless the diff --git a/Source/BuilderModes/ClassicModes/DragThingsMode.cs b/Source/BuilderModes/ClassicModes/DragThingsMode.cs index ffecda67..0f37f07b 100644 --- a/Source/BuilderModes/ClassicModes/DragThingsMode.cs +++ b/Source/BuilderModes/ClassicModes/DragThingsMode.cs @@ -34,7 +34,7 @@ using CodeImp.DoomBuilder.Editing; #endregion -namespace CodeImp.DoomBuilder.BuilderModes.Editing +namespace CodeImp.DoomBuilder.BuilderModes { // No action or button for this mode, it is automatic. // The EditMode attribute does not have to be specified unless the @@ -86,6 +86,8 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing // Just keep the base mode button checked public override string EditModeButtonName { get { return basemode.GetType().Name; } } + + internal EditMode BaseMode { get { return basemode; } } #endregion diff --git a/Source/BuilderModes/ClassicModes/DragVerticesMode.cs b/Source/BuilderModes/ClassicModes/DragVerticesMode.cs index 2ff2b41e..3cf4351b 100644 --- a/Source/BuilderModes/ClassicModes/DragVerticesMode.cs +++ b/Source/BuilderModes/ClassicModes/DragVerticesMode.cs @@ -34,7 +34,7 @@ using CodeImp.DoomBuilder.Editing; #endregion -namespace CodeImp.DoomBuilder.BuilderModes.Editing +namespace CodeImp.DoomBuilder.BuilderModes { // No action or button for this mode, it is automatic. // The EditMode attribute does not have to be specified unless the diff --git a/Source/BuilderModes/ClassicModes/DrawGeometryMode.cs b/Source/BuilderModes/ClassicModes/DrawGeometryMode.cs index be8fb6b2..fb646796 100644 --- a/Source/BuilderModes/ClassicModes/DrawGeometryMode.cs +++ b/Source/BuilderModes/ClassicModes/DrawGeometryMode.cs @@ -35,7 +35,7 @@ using CodeImp.DoomBuilder.Controls; #endregion -namespace CodeImp.DoomBuilder.BuilderModes.Editing +namespace CodeImp.DoomBuilder.BuilderModes { [EditMode(SwitchAction = "drawlinesmode", Volatile = true)] @@ -82,6 +82,8 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing // Just keep the base mode button checked public override string EditModeButtonName { get { return basemode.GetType().Name; } } + internal EditMode BaseMode { get { return basemode; } } + #endregion #region ================== Constructor / Disposer diff --git a/Source/BuilderModes/ClassicModes/LinedefsMode.cs b/Source/BuilderModes/ClassicModes/LinedefsMode.cs index 306d8824..ac71a8c1 100644 --- a/Source/BuilderModes/ClassicModes/LinedefsMode.cs +++ b/Source/BuilderModes/ClassicModes/LinedefsMode.cs @@ -33,7 +33,7 @@ using CodeImp.DoomBuilder.Editing; #endregion -namespace CodeImp.DoomBuilder.BuilderModes.Editing +namespace CodeImp.DoomBuilder.BuilderModes { [EditMode(SwitchAction = "linedefsmode", // Action name used to switch to this mode ButtonDesc = "Linedefs Mode", // Description on the button in toolbar/menu diff --git a/Source/BuilderModes/ClassicModes/SectorsMode.cs b/Source/BuilderModes/ClassicModes/SectorsMode.cs index 5d314d12..68bbe911 100644 --- a/Source/BuilderModes/ClassicModes/SectorsMode.cs +++ b/Source/BuilderModes/ClassicModes/SectorsMode.cs @@ -34,7 +34,7 @@ using System.Drawing; #endregion -namespace CodeImp.DoomBuilder.BuilderModes.Editing +namespace CodeImp.DoomBuilder.BuilderModes { [EditMode(SwitchAction = "sectorsmode", // Action name used to switch to this mode ButtonDesc = "Sectors Mode", // Description on the button in toolbar/menu diff --git a/Source/BuilderModes/ClassicModes/ThingsMode.cs b/Source/BuilderModes/ClassicModes/ThingsMode.cs index 792bb3bd..ebc75702 100644 --- a/Source/BuilderModes/ClassicModes/ThingsMode.cs +++ b/Source/BuilderModes/ClassicModes/ThingsMode.cs @@ -33,7 +33,7 @@ using CodeImp.DoomBuilder.Editing; #endregion -namespace CodeImp.DoomBuilder.BuilderModes.Editing +namespace CodeImp.DoomBuilder.BuilderModes { [EditMode(SwitchAction = "thingsmode", // Action name used to switch to this mode ButtonDesc = "Things Mode", // Description on the button in toolbar/menu diff --git a/Source/BuilderModes/ClassicModes/VerticesMode.cs b/Source/BuilderModes/ClassicModes/VerticesMode.cs index 14bcd37b..5d98295b 100644 --- a/Source/BuilderModes/ClassicModes/VerticesMode.cs +++ b/Source/BuilderModes/ClassicModes/VerticesMode.cs @@ -33,7 +33,7 @@ using CodeImp.DoomBuilder.Editing; #endregion -namespace CodeImp.DoomBuilder.BuilderModes.Editing +namespace CodeImp.DoomBuilder.BuilderModes { [EditMode(SwitchAction = "verticesmode", // Action name used to switch to this mode ButtonDesc = "Vertices Mode", // Description on the button in toolbar/menu diff --git a/Source/BuilderModes/Interface/MenusForm.Designer.cs b/Source/BuilderModes/Interface/MenusForm.Designer.cs new file mode 100644 index 00000000..11ff2a1e --- /dev/null +++ b/Source/BuilderModes/Interface/MenusForm.Designer.cs @@ -0,0 +1,181 @@ +namespace CodeImp.DoomBuilder.BuilderModes +{ + partial class MenusForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if(disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.menustrip = new System.Windows.Forms.MenuStrip(); + this.linedefsmenu = new System.Windows.Forms.ToolStripMenuItem(); + this.sectorsmenu = new System.Windows.Forms.ToolStripMenuItem(); + this.thingsmenu = new System.Windows.Forms.ToolStripMenuItem(); + this.fliplinedefsitem = new System.Windows.Forms.ToolStripMenuItem(); + this.flipsidedefsitem = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator(); + this.curvelinedefsitem = new System.Windows.Forms.ToolStripMenuItem(); + this.joinsectorsitem = new System.Windows.Forms.ToolStripMenuItem(); + this.mergesectorsitem = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator(); + this.rotatethingscwitem = new System.Windows.Forms.ToolStripMenuItem(); + this.rotatethingsccwitem = new System.Windows.Forms.ToolStripMenuItem(); + this.menustrip.SuspendLayout(); + this.SuspendLayout(); + // + // menustrip + // + this.menustrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.linedefsmenu, + this.sectorsmenu, + this.thingsmenu}); + this.menustrip.Location = new System.Drawing.Point(0, 0); + this.menustrip.Name = "menustrip"; + this.menustrip.Size = new System.Drawing.Size(423, 24); + this.menustrip.TabIndex = 0; + this.menustrip.Text = "menustrip"; + // + // linedefsmenu + // + this.linedefsmenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.fliplinedefsitem, + this.flipsidedefsitem, + this.toolStripMenuItem1, + this.curvelinedefsitem}); + this.linedefsmenu.Name = "linedefsmenu"; + this.linedefsmenu.Size = new System.Drawing.Size(59, 20); + this.linedefsmenu.Text = "Linedefs"; + this.linedefsmenu.Visible = false; + // + // sectorsmenu + // + this.sectorsmenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.joinsectorsitem, + this.mergesectorsitem, + this.toolStripMenuItem2}); + this.sectorsmenu.Name = "sectorsmenu"; + this.sectorsmenu.Size = new System.Drawing.Size(55, 20); + this.sectorsmenu.Text = "Sectors"; + this.sectorsmenu.Visible = false; + // + // thingsmenu + // + this.thingsmenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.rotatethingscwitem, + this.rotatethingsccwitem}); + this.thingsmenu.Name = "thingsmenu"; + this.thingsmenu.Size = new System.Drawing.Size(50, 20); + this.thingsmenu.Text = "Things"; + this.thingsmenu.Visible = false; + // + // fliplinedefsitem + // + this.fliplinedefsitem.Name = "fliplinedefsitem"; + this.fliplinedefsitem.Size = new System.Drawing.Size(169, 22); + this.fliplinedefsitem.Text = "Flip Linedefs"; + // + // flipsidedefsitem + // + this.flipsidedefsitem.Name = "flipsidedefsitem"; + this.flipsidedefsitem.Size = new System.Drawing.Size(169, 22); + this.flipsidedefsitem.Text = "Flip Sidedefs"; + // + // toolStripMenuItem1 + // + this.toolStripMenuItem1.Name = "toolStripMenuItem1"; + this.toolStripMenuItem1.Size = new System.Drawing.Size(166, 6); + // + // curvelinedefsitem + // + this.curvelinedefsitem.Name = "curvelinedefsitem"; + this.curvelinedefsitem.Size = new System.Drawing.Size(169, 22); + this.curvelinedefsitem.Text = "Curve Linedefs..."; + // + // joinsectorsitem + // + this.joinsectorsitem.Name = "joinsectorsitem"; + this.joinsectorsitem.Size = new System.Drawing.Size(154, 22); + this.joinsectorsitem.Text = "Join Sectors"; + // + // mergesectorsitem + // + this.mergesectorsitem.Name = "mergesectorsitem"; + this.mergesectorsitem.Size = new System.Drawing.Size(154, 22); + this.mergesectorsitem.Text = "Merge Sectors"; + // + // toolStripMenuItem2 + // + this.toolStripMenuItem2.Name = "toolStripMenuItem2"; + this.toolStripMenuItem2.Size = new System.Drawing.Size(151, 6); + // + // rotatethingscwitem + // + this.rotatethingscwitem.Name = "rotatethingscwitem"; + this.rotatethingscwitem.Size = new System.Drawing.Size(204, 22); + this.rotatethingscwitem.Text = "Rotate Clockwise"; + // + // rotatethingsccwitem + // + this.rotatethingsccwitem.Name = "rotatethingsccwitem"; + this.rotatethingsccwitem.Size = new System.Drawing.Size(204, 22); + this.rotatethingsccwitem.Text = "Rotate Counterclockwise"; + // + // MenusForm + // + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; + this.ClientSize = new System.Drawing.Size(423, 248); + this.Controls.Add(this.menustrip); + this.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.MainMenuStrip = this.menustrip; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "MenusForm"; + this.ShowIcon = false; + this.ShowInTaskbar = false; + this.Text = "MenusForm"; + this.menustrip.ResumeLayout(false); + this.menustrip.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.MenuStrip menustrip; + private System.Windows.Forms.ToolStripMenuItem linedefsmenu; + private System.Windows.Forms.ToolStripMenuItem sectorsmenu; + private System.Windows.Forms.ToolStripMenuItem thingsmenu; + private System.Windows.Forms.ToolStripMenuItem fliplinedefsitem; + private System.Windows.Forms.ToolStripMenuItem flipsidedefsitem; + private System.Windows.Forms.ToolStripSeparator toolStripMenuItem1; + private System.Windows.Forms.ToolStripMenuItem curvelinedefsitem; + private System.Windows.Forms.ToolStripMenuItem joinsectorsitem; + private System.Windows.Forms.ToolStripMenuItem mergesectorsitem; + private System.Windows.Forms.ToolStripSeparator toolStripMenuItem2; + private System.Windows.Forms.ToolStripMenuItem rotatethingscwitem; + private System.Windows.Forms.ToolStripMenuItem rotatethingsccwitem; + } +} \ No newline at end of file diff --git a/Source/BuilderModes/Interface/MenusForm.cs b/Source/BuilderModes/Interface/MenusForm.cs new file mode 100644 index 00000000..69b99309 --- /dev/null +++ b/Source/BuilderModes/Interface/MenusForm.cs @@ -0,0 +1,119 @@ + +#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.Interface; +using CodeImp.DoomBuilder.IO; +using CodeImp.DoomBuilder.Map; +using CodeImp.DoomBuilder.Rendering; +using CodeImp.DoomBuilder.Geometry; +using System.Drawing; +using CodeImp.DoomBuilder.Editing; + +#endregion + +namespace CodeImp.DoomBuilder.BuilderModes +{ + public partial class MenusForm : Form + { + #region ================== Variables + + // Menus list + private ToolStripItem[] menus; + + #endregion + + #region ================== Properties + + public ToolStripMenuItem LinedefsMenu { get { return linedefsmenu; } } + public ToolStripMenuItem SectorsMenu { get { return sectorsmenu; } } + public ToolStripMenuItem ThingsMenu { get { return thingsmenu; } } + + #endregion + + #region ================== Constructor / Disposer + + // Constructor + public MenusForm() + { + // Initialize + InitializeComponent(); + + // List all menus + menus = new ToolStripItem[menustrip.Items.Count]; + for(int i = 0; i < menustrip.Items.Count; i++) menus[i] = menustrip.Items[i]; + } + + #endregion + + #region ================== Methods + + // This registers with the core + public void Register() + { + // Add the menus to the core + foreach(ToolStripMenuItem m in menus) + General.Interface.AddMenu(m); + } + + // This unregisters from the core + public void Unregister() + { + // Remove the menus from the core + foreach(ToolStripMenuItem m in menus) + General.Interface.RemoveMenu(m); + } + + // This hides all menus + public void HideAllMenus() + { + foreach(ToolStripMenuItem m in menus) m.Visible = false; + } + + // This hides all except one menu + public void HideAllMenusExcept(ToolStripMenuItem showthis) + { + HideAllMenus(); + showthis.Visible = true; + } + + // This shows the menu for the current editing mode + public void ShowEditingModeMenu(EditMode mode) + { + // When these modes are active, then test against the base mode they will return to + if(mode is DragGeometryMode) mode = (mode as DragGeometryMode).BaseMode; + if(mode is DragThingsMode) mode = (mode as DragThingsMode).BaseMode; + if(mode is DrawGeometryMode) mode = (mode as DrawGeometryMode).BaseMode; + + // Final decision + if(mode is LinedefsMode) HideAllMenusExcept(linedefsmenu); + else if(mode is SectorsMode) HideAllMenusExcept(sectorsmenu); + else if(mode is ThingsMode) HideAllMenusExcept(thingsmenu); + else HideAllMenus(); + } + + #endregion + } +} \ No newline at end of file diff --git a/Source/BuilderModes/Interface/MenusForm.resx b/Source/BuilderModes/Interface/MenusForm.resx new file mode 100644 index 00000000..909b457c --- /dev/null +++ b/Source/BuilderModes/Interface/MenusForm.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Source/Data/ImageData.cs b/Source/Data/ImageData.cs index 1e3550da..96e476fa 100644 --- a/Source/Data/ImageData.cs +++ b/Source/Data/ImageData.cs @@ -66,6 +66,7 @@ namespace CodeImp.DoomBuilder.Data private PixelColorBlock pixeldata; // Direct3D texture + private int mipmaplevels = 0; // 0 creates the full chain private Texture texture; // Disposing @@ -86,6 +87,7 @@ namespace CodeImp.DoomBuilder.Data internal bool Temporary { get { return temporary; } set { temporary = value; } } internal int LoadState { get { return loadstate; } set { loadstate = value; } } internal LinkedListNode LoadingTicket { get { return loadingticket; } set { loadingticket = value; } } + public int MipMapLevels { get { return mipmaplevels; } set { mipmaplevels = value; } } public int Width { get { return width; } } public int Height { get { return height; } } public float ScaledWidth { get { return scaledwidth; } } @@ -214,7 +216,7 @@ namespace CodeImp.DoomBuilder.Data memstream = new MemoryStream(); bitmap.Save(memstream, ImageFormat.Bmp); memstream.Seek(0, SeekOrigin.Begin); - texture = Texture.FromStream(General.Map.Graphics.Device, memstream, (int)memstream.Length, bitmap.Size.Width, bitmap.Size.Height, 0, + texture = Texture.FromStream(General.Map.Graphics.Device, memstream, (int)memstream.Length, bitmap.Size.Width, bitmap.Size.Height, mipmaplevels, Usage.None, Format.Unknown, Pool.Managed, Filter.Box, Filter.Box, 0); memstream.Dispose(); } diff --git a/Source/Editing/EditModeInfo.cs b/Source/Editing/EditModeInfo.cs index c721212f..481803ac 100644 --- a/Source/Editing/EditModeInfo.cs +++ b/Source/Editing/EditModeInfo.cs @@ -44,6 +44,7 @@ namespace CodeImp.DoomBuilder.Editing private Plugin plugin; private Type type; private bool configspecific; + private bool isvolatile; // Mode switching private BeginActionAttribute switchactionattr = null; @@ -65,7 +66,8 @@ namespace CodeImp.DoomBuilder.Editing public Image ButtonImage { get { return buttonimage; } } public string ButtonDesc { get { return buttondesc; } } public bool ConfigSpecific { get { return configspecific; } } - + public bool Volatile { get { return isvolatile; } } + #endregion #region ================== Constructor / Disposer @@ -77,12 +79,13 @@ namespace CodeImp.DoomBuilder.Editing this.plugin = plugin; this.type = type; this.configspecific = attr.ConfigSpecific; + this.isvolatile = attr.Volatile; // Make switch action info if((attr.SwitchAction != null) && (attr.SwitchAction.Length > 0)) { switchactionattr = new BeginActionAttribute(attr.SwitchAction); - switchactiondel = new ActionDelegate(SwitchToMode); + switchactiondel = new ActionDelegate(UserSwitchToMode); // Bind switch action General.Actions.BindBeginDelegate(plugin.Assembly, switchactiondel, switchactionattr); @@ -120,6 +123,27 @@ namespace CodeImp.DoomBuilder.Editing #region ================== Methods + // 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? + if((General.Map.Mode == null) || !General.Map.Mode.Attributes.Volatile || !this.isvolatile) + { + // Create instance + newmode = plugin.CreateObject(type); + + // Switch mode + General.Map.ChangeMode(newmode); + } + } + } + // This switches to the mode public void SwitchToMode() { diff --git a/Source/General/MapManager.cs b/Source/General/MapManager.cs index 1729252e..7445def9 100644 --- a/Source/General/MapManager.cs +++ b/Source/General/MapManager.cs @@ -79,6 +79,7 @@ namespace CodeImp.DoomBuilder private WAD tempwad; private GridSetup grid; private UndoManager undoredo; + private bool cancelmodechange; // Disposing private bool isdisposed = false; @@ -104,6 +105,7 @@ namespace CodeImp.DoomBuilder public GridSetup Grid { get { return grid; } } public UndoManager UndoRedo { get { return undoredo; } } public IMapSetIO FormatInterface { get { return io; } } + public bool CancelModeChange { get { return cancelmodechange; } set { cancelmodechange |= value; } } #endregion @@ -835,16 +837,34 @@ namespace CodeImp.DoomBuilder { EditMode oldmode = mode; newmode = nextmode; + cancelmodechange = false; // Log info if(newmode != null) General.WriteLogLine("Switching edit mode to " + newmode.GetType().Name + "..."); else General.WriteLogLine("Stopping edit mode..."); + + // Let the plugins know beforehand + General.Plugins.ModeChanges(oldmode, newmode); + // Change cancelled? + if(cancelmodechange) + { + General.WriteLogLine("Edit mode change cancelled."); + return; + } + // Disenagage old mode if(oldmode != null) oldmode.Disengage(); + // Change cancelled? + if(cancelmodechange) + { + General.WriteLogLine("Edit mode change cancelled."); + return; + } + // Apply new mode mode = newmode; @@ -942,6 +962,9 @@ namespace CodeImp.DoomBuilder // Re-link the background image grid.LinkBackground(); + // Inform all plugins that the resource are reloaded + General.Plugins.ReloadResources(); + // Reset status General.MainWindow.DisplayStatus(oldstatus); Cursor.Current = oldcursor; diff --git a/Source/Interface/IMainForm.cs b/Source/Interface/IMainForm.cs index e8518018..533aa165 100644 --- a/Source/Interface/IMainForm.cs +++ b/Source/Interface/IMainForm.cs @@ -68,5 +68,7 @@ namespace CodeImp.DoomBuilder.Interface void BreakExclusiveMouseInput(); void ResumeExclusiveMouseInput(); bool CheckActionActive(Assembly assembly, string actionname); + void AddMenu(ToolStripMenuItem menu); + void RemoveMenu(ToolStripMenuItem menu); } } diff --git a/Source/Interface/MainForm.cs b/Source/Interface/MainForm.cs index c60bfa1a..67a2d57e 100644 --- a/Source/Interface/MainForm.cs +++ b/Source/Interface/MainForm.cs @@ -933,6 +933,19 @@ namespace CodeImp.DoomBuilder.Interface #region ================== Menus + // This adds a menu to the menus bar + public void AddMenu(ToolStripMenuItem menu) + { + // Insert the menu before the Tools menu + menumain.Items.Insert(menumain.Items.IndexOf(menutools), menu); + } + + // This removes a menu to the menus bar + public void RemoveMenu(ToolStripMenuItem menu) + { + menumain.Items.Remove(menu); + } + // Public method to apply shortcut keys internal void ApplyShortcutKeys() { diff --git a/Source/Plugins/Plug.cs b/Source/Plugins/Plug.cs index 770cc487..23e4cb39 100644 --- a/Source/Plugins/Plug.cs +++ b/Source/Plugins/Plug.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Globalization; using System.Text; using System.IO; +using CodeImp.DoomBuilder.Editing; #endregion @@ -100,6 +101,22 @@ namespace CodeImp.DoomBuilder.Plugins { return plugin.GetResourceStream(resourcename); } + + /// + /// This is called by the Doom Builder core when the user chose to reload the resources. + /// + public virtual void ReloadResources() + { + } + + /// + /// This is called by the Doom Builder core when the editing mode changes. + /// + /// The previous editing mode + /// The new editing mode + public virtual void ModeChanges(EditMode oldmode, EditMode newmode) + { + } #endregion } diff --git a/Source/Plugins/Plugin.cs b/Source/Plugins/Plugin.cs index fd0f34de..6a590328 100644 --- a/Source/Plugins/Plugin.cs +++ b/Source/Plugins/Plugin.cs @@ -92,7 +92,7 @@ namespace CodeImp.DoomBuilder.Plugins { // How can we plug something in without a plug? General.WriteLogLine("ERROR: Could not load plugin '" + name + "', plugin is missing the plug!"); - throw new Exception(); + throw new InvalidProgramException(); } // Load actions diff --git a/Source/Plugins/PluginManager.cs b/Source/Plugins/PluginManager.cs index 674d0a29..46db7f12 100644 --- a/Source/Plugins/PluginManager.cs +++ b/Source/Plugins/PluginManager.cs @@ -80,7 +80,7 @@ namespace CodeImp.DoomBuilder.Plugins { p = new Plugin(fn); } - catch(Exception) + catch(InvalidProgramException) { General.WriteLogLine("WARNING: Plugin file '" + Path.GetFileName(fn) + "' was not loaded."); p = null; @@ -186,6 +186,20 @@ namespace CodeImp.DoomBuilder.Plugins // Nothing found return null; } + + // This calls ReloadResources on all plugins + public void ReloadResources() + { + foreach(Plugin p in plugins) + p.Plug.ReloadResources(); + } + + // This calls ModeChanges on all plugins + public void ModeChanges(EditMode oldmode, EditMode newmode) + { + foreach(Plugin p in plugins) + p.Plug.ModeChanges(oldmode, newmode); + } #endregion } diff --git a/Source/Rendering/D3DDevice.cs b/Source/Rendering/D3DDevice.cs index 11bff796..03ef3df3 100644 --- a/Source/Rendering/D3DDevice.cs +++ b/Source/Rendering/D3DDevice.cs @@ -266,6 +266,7 @@ namespace CodeImp.DoomBuilder.Rendering font = new TextFont(); fonttexture = new ResourceImage("Font.png"); fonttexture.LoadImage(); + fonttexture.MipMapLevels = 2; fonttexture.CreateTexture(); // Initialize settings