From 697069e27ba166da3ea533842f96a7cdac58f2c9 Mon Sep 17 00:00:00 2001 From: MaxED <j.maxed@gmail.com> Date: Mon, 8 Sep 2014 13:09:14 +0000 Subject: [PATCH] Texture Browser Form: some minor logic fixes (no texture groups were selected when initial texture was empty and no texture group was stored in the program configuration). Texture Browser Form: don't save current texture group when the form was canceled. Keyboard Shortcut Reference export: generated html will now be saved to program configuration folder if working folder is write-protected. Internal: added SupportedMapFormats property to EditModeAttribute. A mode with this property specified will be available only in specified map formats. Interface: Ceiling Align Mode and Floor Align Mode are now enabled by default. Interface: Ceiling Align Mode and Floor Align Mode are now only available in UDMF map format. Interface: Visplane Explorer Mode is now available only in Doom map format. --- Source/Core/Editing/EditModeAttribute.cs | 8 +++++- Source/Core/Editing/EditingManager.cs | 10 +++++--- Source/Core/Windows/ConfigForm.cs | 25 ++++++++++++++++++- Source/Core/Windows/MainForm.cs | 15 ++++++++--- Source/Core/Windows/TextureBrowserForm.cs | 21 ++++++++-------- .../ClassicModes/CeilingAlignMode.cs | 2 ++ .../ClassicModes/FloorAlignMode.cs | 2 ++ .../VisplaneExplorer/VisplaneExplorerMode.cs | 8 +----- 8 files changed, 64 insertions(+), 27 deletions(-) diff --git a/Source/Core/Editing/EditModeAttribute.cs b/Source/Core/Editing/EditModeAttribute.cs index 86d805b6f..f80e226b8 100644 --- a/Source/Core/Editing/EditModeAttribute.cs +++ b/Source/Core/Editing/EditModeAttribute.cs @@ -42,6 +42,7 @@ namespace CodeImp.DoomBuilder.Editing private bool allowcopypaste = true; private bool usebydefault; private bool safestartmode; + private string[] supportedmapformats; //mxd #endregion @@ -108,7 +109,12 @@ namespace CodeImp.DoomBuilder.Editing /// opening a map. The user can then select this as starting mode in the configuration. /// </summary> public bool SafeStartMode { get { return safestartmode; } set { safestartmode = value; } } - + + /// <summary> + /// List of map formats this mode can work with. Null means all map formats are supported (mxd) + /// </summary> + public string[] SupportedMapFormats { get { return supportedmapformats; } set { supportedmapformats = value; } } + #endregion #region ================== Constructor / Disposer diff --git a/Source/Core/Editing/EditingManager.cs b/Source/Core/Editing/EditingManager.cs index 85d8317a9..bd1b7df68 100644 --- a/Source/Core/Editing/EditingManager.cs +++ b/Source/Core/Editing/EditingManager.cs @@ -247,10 +247,12 @@ namespace CodeImp.DoomBuilder.Editing { foreach(EditModeInfo emi in allmodes) { - // 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 ) + // Include the mode if it supports current map format (mxd) + // Also include the mode when it is listed and enabled or when it's not optional + if( (emi.Attributes.SupportedMapFormats == null || Array.IndexOf(emi.Attributes.SupportedMapFormats, General.Map.Config.FormatInterface) != -1) && + ((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); diff --git a/Source/Core/Windows/ConfigForm.cs b/Source/Core/Windows/ConfigForm.cs index 8f9d5644d..e8e2cf560 100644 --- a/Source/Core/Windows/ConfigForm.cs +++ b/Source/Core/Windows/ConfigForm.cs @@ -90,6 +90,7 @@ namespace CodeImp.DoomBuilder.Windows lvi = listmodes.Items.Add(emi.Attributes.DisplayName); lvi.Tag = emi; lvi.SubItems.Add(emi.Plugin.Plug.Name); + lvi.UseItemStyleForSubItems = true; //mxd } } @@ -194,8 +195,27 @@ namespace CodeImp.DoomBuilder.Windows foreach(ListViewItem lvi in listmodes.Items) { EditModeInfo emi = (lvi.Tag as EditModeInfo); - lvi.Checked = (configinfo.EditModes.ContainsKey(emi.Type.FullName) && configinfo.EditModes[emi.Type.FullName]); + + //mxd. Disable item if the mode does not support current map format + if (emi.Attributes.SupportedMapFormats != null && + Array.IndexOf(emi.Attributes.SupportedMapFormats, gameconfig.FormatInterface) == -1) + { + lvi.Text = emi.Attributes.DisplayName + " (map format not supported)"; + lvi.ForeColor = SystemColors.GrayText; + lvi.BackColor = SystemColors.InactiveBorder; + lvi.Checked = false; + } + else + { + lvi.Text = emi.Attributes.DisplayName; + lvi.ForeColor = SystemColors.WindowText; + lvi.BackColor = SystemColors.Window; + lvi.Checked = (configinfo.EditModes.ContainsKey(emi.Type.FullName) && configinfo.EditModes[emi.Type.FullName]); + } } + + // Update listmodes columns width (mxd) + listmodes.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); // Fill start modes RefillStartModes(); @@ -559,6 +579,9 @@ namespace CodeImp.DoomBuilder.Windows // Leave when no configuration selected if(configinfo == null) return; + + // mxd. Not the best way to detect a disabled item, but we will go with that... + if(e.Item.ForeColor == SystemColors.GrayText) e.Item.Checked = false; // Apply changes EditModeInfo emi = (e.Item.Tag as EditModeInfo); diff --git a/Source/Core/Windows/MainForm.cs b/Source/Core/Windows/MainForm.cs index 275443534..75ced6f71 100644 --- a/Source/Core/Windows/MainForm.cs +++ b/Source/Core/Windows/MainForm.cs @@ -2758,12 +2758,21 @@ namespace CodeImp.DoomBuilder.Windows html.AppendLine("</table></div></body></html>"); //write - using(StreamWriter writer = File.CreateText(fileName)) { - writer.Write(html.ToString()); + string path; + try { + path = Path.Combine(General.AppPath, fileName); + using(StreamWriter writer = File.CreateText(path)) { + writer.Write(html.ToString()); + } + } catch (Exception) { + //Configurtions path SHOULD be accessible and not read-only, right? + path = Path.Combine(General.SettingsPath, fileName); + using(StreamWriter writer = File.CreateText(path)) { + writer.Write(html.ToString()); + } } //open file - string path = Path.Combine(General.AppPath, fileName); DisplayStatus(StatusType.Info, "Shortcut reference saved to '" + path + "'"); System.Diagnostics.Process.Start(path); } diff --git a/Source/Core/Windows/TextureBrowserForm.cs b/Source/Core/Windows/TextureBrowserForm.cs index cea409f88..b2460bebd 100644 --- a/Source/Core/Windows/TextureBrowserForm.cs +++ b/Source/Core/Windows/TextureBrowserForm.cs @@ -92,8 +92,10 @@ namespace CodeImp.DoomBuilder.Windows item.ImageIndex = 2 + ts.Location.type; item.SelectedImageIndex = item.ImageIndex; - if (ts.Location.type != DataLocation.RESOURCE_WAD) + if (ts.Location.type != DataLocation.RESOURCE_WAD) { createNodes(item); + item.Expand(); + } } //mxd. Add All textures set @@ -124,11 +126,10 @@ namespace CodeImp.DoomBuilder.Windows } //mxd. If the selected texture was not found in the last-selected set, try finding it in the other sets - if (selectedset == null) { + if (selectedset == null && selecttexture != "-") { foreach (TreeNode n in tvTextureSets.Nodes) { selectedset = findTextureByLongName(n, longname); - if (selectedset != null) - break; + if (selectedset != null) break; } } @@ -136,13 +137,11 @@ namespace CodeImp.DoomBuilder.Windows if (selectedset == null && match != null) selectedset = match; - if(tvTextureSets.Nodes.Count > 0) - tvTextureSets.Nodes[0].Expand();//mxd - tvTextureSets.EndUpdate();//mxd + //mxd. Select found node or "All" node, if none were found + if (tvTextureSets.Nodes.Count > 0) + tvTextureSets.SelectedNode = (selectedset ?? tvTextureSets.Nodes[tvTextureSets.Nodes.Count - 1]); - if (selectedset != null) {//mxd - tvTextureSets.SelectedNode = selectedset; - } + tvTextureSets.EndUpdate();//mxd // Keep last position and size lastposition = this.Location; @@ -375,7 +374,7 @@ namespace CodeImp.DoomBuilder.Windows General.Settings.WriteSetting("browserwindow.windowstate", windowstate); //mxd. Save last selected texture set - if(tvTextureSets.SelectedNode != null) + if(this.DialogResult == DialogResult.OK && tvTextureSets.SelectedNode != null) General.Settings.WriteSetting("browserwindow.textureset", tvTextureSets.SelectedNode.Name); // Clean up diff --git a/Source/Plugins/BuilderModes/ClassicModes/CeilingAlignMode.cs b/Source/Plugins/BuilderModes/ClassicModes/CeilingAlignMode.cs index 0e8a7f59f..b5badc69b 100644 --- a/Source/Plugins/BuilderModes/ClassicModes/CeilingAlignMode.cs +++ b/Source/Plugins/BuilderModes/ClassicModes/CeilingAlignMode.cs @@ -30,6 +30,8 @@ namespace CodeImp.DoomBuilder.BuilderModes ButtonImage = "CeilingAlign.png", ButtonOrder = int.MinValue + 311, ButtonGroup = "000_editing", + UseByDefault = true, //mxd + SupportedMapFormats = new[] { "UniversalMapSetIO" }, //mxd Volatile = true)] public class CeilingAlignMode : FlatAlignMode diff --git a/Source/Plugins/BuilderModes/ClassicModes/FloorAlignMode.cs b/Source/Plugins/BuilderModes/ClassicModes/FloorAlignMode.cs index 8886d0c9b..885bef4c5 100644 --- a/Source/Plugins/BuilderModes/ClassicModes/FloorAlignMode.cs +++ b/Source/Plugins/BuilderModes/ClassicModes/FloorAlignMode.cs @@ -30,6 +30,8 @@ namespace CodeImp.DoomBuilder.BuilderModes ButtonImage = "FloorAlign.png", ButtonOrder = int.MinValue + 310, ButtonGroup = "000_editing", + UseByDefault = true, //mxd + SupportedMapFormats = new[] { "UniversalMapSetIO" }, //mxd Volatile = true)] public class FloorAlignMode : FlatAlignMode diff --git a/Source/Plugins/VisplaneExplorer/VisplaneExplorerMode.cs b/Source/Plugins/VisplaneExplorer/VisplaneExplorerMode.cs index ebea6f422..6d993e115 100644 --- a/Source/Plugins/VisplaneExplorer/VisplaneExplorerMode.cs +++ b/Source/Plugins/VisplaneExplorer/VisplaneExplorerMode.cs @@ -25,6 +25,7 @@ namespace CodeImp.DoomBuilder.Plugins.VisplaneExplorer ButtonGroup = "002_tools", Volatile = true, UseByDefault = true, + SupportedMapFormats = new[] { "DoomMapSetIO" }, //mxd AllowCopyPaste = false)] public class VisplaneExplorerMode : ClassicMode { @@ -248,13 +249,6 @@ namespace CodeImp.DoomBuilder.Plugins.VisplaneExplorer // Mode starts public override void OnEngage() { - //mxd. I think it only applies to maps in Doom format - if (General.Map.Config.FormatInterface != "DoomMapSetIO") { - General.Interface.DisplayStatus(StatusType.Warning, "Visplane Explorer requires map in Doom format!"); - OnCancel(); //return to previous mode - return; - } - Cursor.Current = Cursors.WaitCursor; base.OnEngage(); General.Interface.DisplayStatus(StatusType.Busy, "Setting up test environment..."); -- GitLab