started work on texture sets

This commit is contained in:
codeimp 2008-09-30 15:09:37 +00:00
parent 0ae660c8a9
commit edee6a40c2
6 changed files with 489 additions and 1 deletions

View file

@ -46,8 +46,10 @@
-->
<ItemGroup>
<Compile Include="Config\ArgumentInfo.cs" />
<Compile Include="Config\DefinedTextureSet.cs" />
<Compile Include="Config\EnumItem.cs" />
<Compile Include="Config\EnumList.cs" />
<Compile Include="Config\OthersTextureSet.cs" />
<Compile Include="Config\SectorEffectInfo.cs" />
<Compile Include="Config\GeneralizedBit.cs" />
<Compile Include="Config\GeneralizedOption.cs" />
@ -60,6 +62,7 @@
<Compile Include="Config\ProgramConfiguration.cs" />
<Compile Include="Config\SkillInfo.cs" />
<Compile Include="Config\TagType.cs" />
<Compile Include="Config\TextureSet.cs" />
<Compile Include="Config\ThingCategory.cs" />
<Compile Include="Config\ThingTypeInfo.cs" />
<Compile Include="Config\UniversalFieldInfo.cs" />

View file

@ -0,0 +1,159 @@
#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 CodeImp.DoomBuilder.IO;
using CodeImp.DoomBuilder.Data;
using System.IO;
using System.Diagnostics;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.Collections.Specialized;
#endregion
namespace CodeImp.DoomBuilder.Config
{
internal class DefinedTextureSet : TextureSet
{
#region ================== Variables
// Never stored, only used at run-time
private Regex regex;
#endregion
#region ================== Constructor / Destructor
// Texture set from configuration
public DefinedTextureSet(Configuration cfg, string path)
{
// Read the name
name = cfg.ReadSetting(path + ".name", "Unnamed Set");
// Read the filters
IDictionary dic = cfg.ReadSetting(path, new Hashtable());
filters = new List<string>(dic.Count);
foreach(DictionaryEntry de in dic)
{
// If not the name of this texture set, add value as filter
if(de.Key.ToString() != "name") filters.Add(de.Value.ToString());
}
}
// New texture set constructor
public DefinedTextureSet(string name)
{
this.name = name;
this.filters = new List<string>();
}
#endregion
#region ================== Methods
// This writes the texture set to configuration
internal override void WriteToConfig(Configuration cfg, string path)
{
IDictionary dic;
// Fill structure
dic = new ListDictionary();
// Add name
dic.Add("name", name);
for(int i = 0; i < filters.Count; i++)
{
// Add filters
dic.Add(i.ToString(), filters[i]);
}
// Write to config
cfg.WriteSetting(path, dic);
}
// This resets the matches and recreates the regex
internal override void Reset()
{
base.Reset();
// Make the regex string that handles all filters
StringBuilder regexstr = new StringBuilder("");
foreach(string s in filters)
{
// Replace the * with the regex code
string ss = s.Replace("*", ".*?");
// Escape other regex characters, except the ?
ss = ss.Replace("+", "\\+");
ss = ss.Replace("\\", "\\\\");
ss = ss.Replace("|", "\\|");
ss = ss.Replace("{", "\\{");
ss = ss.Replace("[", "\\[");
ss = ss.Replace("(", "\\(");
ss = ss.Replace(")", "\\)");
ss = ss.Replace("^", "\\^");
ss = ss.Replace("$", "\\$");
ss = ss.Replace(".", "\\.");
ss = ss.Replace("#", "\\#");
ss = ss.Replace(" ", "\\ ");
// When a filter has already added, insert a conditional OR operator
if(regexstr.Length > 0) regexstr.Append("|");
// Open group without backreferencing
regexstr.Append("(?:");
// Add the filter
regexstr.Append(ss);
// Close group
regexstr.Append(")");
}
// Make the regex
regex = new Regex(regexstr.ToString(), RegexOptions.Compiled |
RegexOptions.CultureInvariant |
RegexOptions.IgnoreCase);
}
// This matches a name against the regex and adds a texture to
// the list if it matches. Returns true when matched and added.
internal virtual bool Add(ImageData image)
{
// Check against regex
if(regex.IsMatch(image.Name))
{
// Matches! Add it.
return base.Add(image);
}
else
{
// Doesn't match
return false;
}
}
#endregion
}
}

View file

@ -0,0 +1,63 @@
#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 CodeImp.DoomBuilder.IO;
using CodeImp.DoomBuilder.Data;
using System.IO;
using System.Diagnostics;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.Collections.Specialized;
#endregion
namespace CodeImp.DoomBuilder.Config
{
internal class OthersTextureSet : TextureSet
{
#region ================== Constants
public const string NAME = "Other";
#endregion
#region ================== Constructor / Destructor
// New texture set constructor
public OthersTextureSet()
{
this.name = NAME;
}
#endregion
#region ================== Methods
// This does absolutely nothing
internal override void WriteToConfig(Configuration cfg, string path)
{
}
#endregion
}
}

108
Source/Config/TextureSet.cs Normal file
View file

@ -0,0 +1,108 @@
#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 CodeImp.DoomBuilder.IO;
using CodeImp.DoomBuilder.Data;
using System.IO;
using System.Diagnostics;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.Collections.Specialized;
#endregion
namespace CodeImp.DoomBuilder.Config
{
internal abstract class TextureSet
{
#region ================== Variables
protected string name;
protected List<string> filters;
// Never stored, only used at run-time
protected Dictionary<long, ImageData> matches;
#endregion
#region ================== Properties
public string Name { get { return name; } set { name = value; } }
internal List<string> Filters { get { return filters; } }
#endregion
#region ================== Constructor / Destructor
public TextureSet()
{
this.name = "Unnamed Set";
this.filters = new List<string>();
}
#endregion
#region ================== Methods
// This writes the texture set to configuration
internal abstract void WriteToConfig(Configuration cfg, string path);
// This resets the matches and recreates the regex
internal virtual void Reset()
{
// Clear matches
matches = new Dictionary<long, ImageData>();
}
// This adds a texture to this set
internal virtual bool Add(ImageData image)
{
// Can we add it?
if(!matches.ContainsKey(image.LongName))
{
// Add it
matches.Add(image.LongName, image);
return true;
}
else
{
// Can't add it
return false;
}
}
// This tests if a texture is in this texturset
public virtual bool Exists(long longname)
{
return matches.ContainsKey(longname);
}
// This returns the name
public override string ToString()
{
return name;
}
#endregion
}
}

View file

@ -37,6 +37,7 @@ namespace CodeImp.DoomBuilder.Windows
System.Windows.Forms.Label label9;
System.Windows.Forms.Label label1;
System.Windows.Forms.Label label8;
System.Windows.Forms.Label label4;
this.labelparameters = new System.Windows.Forms.Label();
this.cancel = new System.Windows.Forms.Button();
this.apply = new System.Windows.Forms.Button();
@ -58,6 +59,14 @@ namespace CodeImp.DoomBuilder.Windows
this.listconfigs = new System.Windows.Forms.ListView();
this.columnname = new System.Windows.Forms.ColumnHeader();
this.testprogramdialog = new System.Windows.Forms.OpenFileDialog();
this.tabtextures = new System.Windows.Forms.TabPage();
this.listtextures = new System.Windows.Forms.ListBox();
this.addtextureset = new System.Windows.Forms.Button();
this.removetextureset = new System.Windows.Forms.Button();
this.copytexturesets = new System.Windows.Forms.Button();
this.pastetexturesets = new System.Windows.Forms.Button();
this.edittextureset = new System.Windows.Forms.Button();
this.restoretexturesets = new System.Windows.Forms.Button();
label5 = new System.Windows.Forms.Label();
label6 = new System.Windows.Forms.Label();
label3 = new System.Windows.Forms.Label();
@ -66,10 +75,12 @@ namespace CodeImp.DoomBuilder.Windows
label9 = new System.Windows.Forms.Label();
label1 = new System.Windows.Forms.Label();
label8 = new System.Windows.Forms.Label();
label4 = new System.Windows.Forms.Label();
this.tabs.SuspendLayout();
this.tabresources.SuspendLayout();
this.tabnodebuilder.SuspendLayout();
this.tabtesting.SuspendLayout();
this.tabtextures.SuspendLayout();
this.SuspendLayout();
//
// label5
@ -193,9 +204,10 @@ namespace CodeImp.DoomBuilder.Windows
this.tabs.Controls.Add(this.tabresources);
this.tabs.Controls.Add(this.tabnodebuilder);
this.tabs.Controls.Add(this.tabtesting);
this.tabs.Controls.Add(this.tabtextures);
this.tabs.Enabled = false;
this.tabs.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.tabs.ItemSize = new System.Drawing.Size(110, 19);
this.tabs.ItemSize = new System.Drawing.Size(100, 19);
this.tabs.Location = new System.Drawing.Point(256, 12);
this.tabs.Name = "tabs";
this.tabs.SelectedIndex = 0;
@ -417,6 +429,107 @@ namespace CodeImp.DoomBuilder.Windows
this.testprogramdialog.Filter = "Executable Files (*.exe)|*.exe|Batch Files (*.bat)|*.bat";
this.testprogramdialog.Title = "Browse Test Program";
//
// tabtextures
//
this.tabtextures.Controls.Add(this.restoretexturesets);
this.tabtextures.Controls.Add(this.edittextureset);
this.tabtextures.Controls.Add(this.pastetexturesets);
this.tabtextures.Controls.Add(this.copytexturesets);
this.tabtextures.Controls.Add(this.removetextureset);
this.tabtextures.Controls.Add(this.addtextureset);
this.tabtextures.Controls.Add(this.listtextures);
this.tabtextures.Controls.Add(label4);
this.tabtextures.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.tabtextures.Location = new System.Drawing.Point(4, 23);
this.tabtextures.Name = "tabtextures";
this.tabtextures.Size = new System.Drawing.Size(415, 318);
this.tabtextures.TabIndex = 3;
this.tabtextures.Text = "Textures";
this.tabtextures.UseVisualStyleBackColor = true;
//
// label4
//
label4.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
label4.AutoEllipsis = true;
label4.Location = new System.Drawing.Point(12, 15);
label4.Name = "label4";
label4.Size = new System.Drawing.Size(394, 75);
label4.TabIndex = 24;
label4.Text = resources.GetString("label4.Text");
//
// listtextures
//
this.listtextures.ColumnWidth = 120;
this.listtextures.IntegralHeight = false;
this.listtextures.ItemHeight = 14;
this.listtextures.Location = new System.Drawing.Point(15, 93);
this.listtextures.MultiColumn = true;
this.listtextures.Name = "listtextures";
this.listtextures.ScrollAlwaysVisible = true;
this.listtextures.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended;
this.listtextures.Size = new System.Drawing.Size(382, 138);
this.listtextures.Sorted = true;
this.listtextures.TabIndex = 25;
//
// addtextureset
//
this.addtextureset.Location = new System.Drawing.Point(15, 237);
this.addtextureset.Name = "addtextureset";
this.addtextureset.Size = new System.Drawing.Size(67, 24);
this.addtextureset.TabIndex = 26;
this.addtextureset.Text = "Add...";
this.addtextureset.UseVisualStyleBackColor = true;
//
// removetextureset
//
this.removetextureset.Enabled = false;
this.removetextureset.Location = new System.Drawing.Point(161, 237);
this.removetextureset.Name = "removetextureset";
this.removetextureset.Size = new System.Drawing.Size(68, 24);
this.removetextureset.TabIndex = 27;
this.removetextureset.Text = "Remove";
this.removetextureset.UseVisualStyleBackColor = true;
//
// copytexturesets
//
this.copytexturesets.Enabled = false;
this.copytexturesets.Location = new System.Drawing.Point(275, 237);
this.copytexturesets.Name = "copytexturesets";
this.copytexturesets.Size = new System.Drawing.Size(58, 24);
this.copytexturesets.TabIndex = 28;
this.copytexturesets.Text = "Copy";
this.copytexturesets.UseVisualStyleBackColor = true;
//
// pastetexturesets
//
this.pastetexturesets.Enabled = false;
this.pastetexturesets.Location = new System.Drawing.Point(339, 237);
this.pastetexturesets.Name = "pastetexturesets";
this.pastetexturesets.Size = new System.Drawing.Size(58, 24);
this.pastetexturesets.TabIndex = 29;
this.pastetexturesets.Text = "Paste";
this.pastetexturesets.UseVisualStyleBackColor = true;
//
// edittextureset
//
this.edittextureset.Enabled = false;
this.edittextureset.Location = new System.Drawing.Point(88, 237);
this.edittextureset.Name = "edittextureset";
this.edittextureset.Size = new System.Drawing.Size(67, 24);
this.edittextureset.TabIndex = 30;
this.edittextureset.Text = "Edit...";
this.edittextureset.UseVisualStyleBackColor = true;
//
// restoretexturesets
//
this.restoretexturesets.Location = new System.Drawing.Point(15, 275);
this.restoretexturesets.Name = "restoretexturesets";
this.restoretexturesets.Size = new System.Drawing.Size(140, 24);
this.restoretexturesets.TabIndex = 31;
this.restoretexturesets.Text = "Add Default Categories";
this.restoretexturesets.UseVisualStyleBackColor = true;
//
// ConfigForm
//
this.AcceptButton = this.apply;
@ -444,6 +557,7 @@ namespace CodeImp.DoomBuilder.Windows
this.tabnodebuilder.PerformLayout();
this.tabtesting.ResumeLayout(false);
this.tabtesting.PerformLayout();
this.tabtextures.ResumeLayout(false);
this.ResumeLayout(false);
}
@ -471,5 +585,13 @@ namespace CodeImp.DoomBuilder.Windows
private System.Windows.Forms.CheckBox customparameters;
private CodeImp.DoomBuilder.Controls.ActionSelectorControl skill;
private System.Windows.Forms.Label labelparameters;
private System.Windows.Forms.TabPage tabtextures;
private System.Windows.Forms.Button addtextureset;
private System.Windows.Forms.ListBox listtextures;
private System.Windows.Forms.Button restoretexturesets;
private System.Windows.Forms.Button edittextureset;
private System.Windows.Forms.Button pastetexturesets;
private System.Windows.Forms.Button copytexturesets;
private System.Windows.Forms.Button removetextureset;
}
}

View file

@ -222,6 +222,39 @@
<metadata name="testapplication.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="tabtextures.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="restoretexturesets.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="edittextureset.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="pastetexturesets.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="copytexturesets.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="removetextureset.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="addtextureset.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="listtextures.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="label4.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="label4.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<data name="label4.Text" xml:space="preserve">
<value>Texture Sets are a way to group textures and flats into categories, so that you can easily find a texture for the specific style or purpose you need by selecting one of the categories. Textures that are not in any category are automatically shown in the "Others" category.</value>
</data>
<metadata name="listconfigs.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>