2007-10-20 12:34:27 +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 CodeImp.DoomBuilder.IO;
|
2007-10-21 18:06:10 +00:00
|
|
|
using CodeImp.DoomBuilder.Data;
|
|
|
|
using System.IO;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Windows.Forms;
|
2007-10-21 22:41:46 +00:00
|
|
|
using CodeImp.DoomBuilder.Rendering;
|
2007-10-20 12:34:27 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2007-10-21 18:06:10 +00:00
|
|
|
namespace CodeImp.DoomBuilder.Config
|
2007-10-20 12:34:27 +00:00
|
|
|
{
|
2008-01-02 21:49:43 +00:00
|
|
|
public class ThingCategory
|
2007-10-20 12:34:27 +00:00
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
2007-10-21 22:41:46 +00:00
|
|
|
// Things
|
|
|
|
private List<ThingTypeInfo> things;
|
|
|
|
|
|
|
|
// Category properties
|
|
|
|
private string name;
|
|
|
|
private string title;
|
|
|
|
private bool sorted;
|
|
|
|
|
|
|
|
// Thing properties for inheritance
|
|
|
|
private string sprite;
|
|
|
|
private int color;
|
|
|
|
private int arrow;
|
2009-02-16 10:06:58 +00:00
|
|
|
private float radius;
|
2007-10-21 22:41:46 +00:00
|
|
|
private float height;
|
|
|
|
private int hangs;
|
|
|
|
private int blocking;
|
|
|
|
private int errorcheck;
|
2008-11-17 16:14:45 +00:00
|
|
|
private bool fixedsize;
|
2007-10-21 22:41:46 +00:00
|
|
|
|
|
|
|
// Disposing
|
|
|
|
private bool isdisposed = false;
|
|
|
|
|
2007-10-20 12:34:27 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
2007-10-21 22:41:46 +00:00
|
|
|
public string Name { get { return name; } }
|
|
|
|
public string Title { get { return title; } }
|
|
|
|
public string Sprite { get { return sprite; } }
|
|
|
|
public bool Sorted { get { return sorted; } }
|
|
|
|
public int Color { get { return color; } }
|
|
|
|
public int Arrow { get { return arrow; } }
|
2009-02-16 10:06:58 +00:00
|
|
|
public float Radius { get { return radius; } }
|
2007-10-21 22:41:46 +00:00
|
|
|
public float Height { get { return height; } }
|
|
|
|
public int Hangs { get { return hangs; } }
|
|
|
|
public int Blocking { get { return blocking; } }
|
|
|
|
public int ErrorCheck { get { return errorcheck; } }
|
2008-11-17 16:14:45 +00:00
|
|
|
public bool FixedSize { get { return fixedsize; } }
|
2007-10-21 22:41:46 +00:00
|
|
|
public bool IsDisposed { get { return isdisposed; } }
|
|
|
|
public List<ThingTypeInfo> Things { get { return things; } }
|
|
|
|
|
2007-10-20 12:34:27 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
2009-01-22 15:10:41 +00:00
|
|
|
|
|
|
|
// Constructor
|
|
|
|
internal ThingCategory(string name, string title)
|
|
|
|
{
|
|
|
|
// Initialize
|
|
|
|
this.name = name;
|
|
|
|
this.title = title;
|
|
|
|
this.things = new List<ThingTypeInfo>();
|
|
|
|
|
|
|
|
// Set default properties
|
|
|
|
this.sprite = "";
|
|
|
|
this.sorted = true;
|
|
|
|
this.color = 18;
|
|
|
|
this.arrow = 1;
|
2009-02-16 10:06:58 +00:00
|
|
|
this.radius = 10;
|
2009-01-22 15:10:41 +00:00
|
|
|
this.height = 20;
|
|
|
|
this.hangs = 0;
|
|
|
|
this.blocking = 0;
|
|
|
|
this.errorcheck = 1;
|
|
|
|
this.fixedsize = false;
|
|
|
|
|
|
|
|
// We have no destructor
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
|
2007-10-20 12:34:27 +00:00
|
|
|
// Constructor
|
2008-01-02 21:49:43 +00:00
|
|
|
internal ThingCategory(Configuration cfg, string name)
|
2007-10-20 12:34:27 +00:00
|
|
|
{
|
2007-10-21 22:41:46 +00:00
|
|
|
IDictionary dic;
|
|
|
|
int index;
|
|
|
|
|
2007-10-20 12:34:27 +00:00
|
|
|
// Initialize
|
2007-10-21 22:41:46 +00:00
|
|
|
this.name = name;
|
|
|
|
this.things = new List<ThingTypeInfo>();
|
|
|
|
|
|
|
|
// Read properties
|
|
|
|
this.title = cfg.ReadSetting("thingtypes." + name + ".title", "<category>");
|
|
|
|
this.sprite = cfg.ReadSetting("thingtypes." + name + ".sprite", "");
|
|
|
|
this.sorted = (cfg.ReadSetting("thingtypes." + name + ".sort", 0) != 0);
|
|
|
|
this.color = cfg.ReadSetting("thingtypes." + name + ".color", 0);
|
|
|
|
this.arrow = cfg.ReadSetting("thingtypes." + name + ".arrow", 0);
|
2009-02-16 10:06:58 +00:00
|
|
|
this.radius = cfg.ReadSetting("thingtypes." + name + ".width", 10);
|
2009-01-04 00:01:59 +00:00
|
|
|
this.height = cfg.ReadSetting("thingtypes." + name + ".height", 20);
|
2007-10-21 22:41:46 +00:00
|
|
|
this.hangs = cfg.ReadSetting("thingtypes." + name + ".hangs", 0);
|
|
|
|
this.blocking = cfg.ReadSetting("thingtypes." + name + ".blocking", 0);
|
2008-10-23 22:01:07 +00:00
|
|
|
this.errorcheck = cfg.ReadSetting("thingtypes." + name + ".error", 1);
|
2008-11-17 16:14:45 +00:00
|
|
|
this.fixedsize = cfg.ReadSetting("thingtypes." + name + ".fixedsize", false);
|
2007-10-21 22:41:46 +00:00
|
|
|
|
|
|
|
// Safety
|
2009-02-16 10:06:58 +00:00
|
|
|
if(this.radius < 8f) this.radius = 8f;
|
2007-10-21 22:41:46 +00:00
|
|
|
|
|
|
|
// Go for all items in category
|
|
|
|
dic = cfg.ReadSetting("thingtypes." + name, new Hashtable());
|
|
|
|
foreach(DictionaryEntry de in dic)
|
|
|
|
{
|
|
|
|
// Check if the item key is numeric
|
|
|
|
if(int.TryParse(de.Key.ToString(), NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, CultureInfo.InvariantCulture, out index))
|
|
|
|
{
|
|
|
|
// Check if the item value is a structure
|
|
|
|
if(de.Value is IDictionary)
|
|
|
|
{
|
|
|
|
// Create this thing
|
|
|
|
things.Add(new ThingTypeInfo(this, index, cfg));
|
|
|
|
}
|
|
|
|
// Check if the item value is a string
|
|
|
|
else if(de.Value is string)
|
|
|
|
{
|
|
|
|
// Interpret this as the title
|
|
|
|
things.Add(new ThingTypeInfo(this, index, de.Value.ToString()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-10-21 18:06:10 +00:00
|
|
|
|
2007-10-20 12:34:27 +00:00
|
|
|
// We have no destructor
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
|
2007-10-21 22:41:46 +00:00
|
|
|
// Disposer
|
2008-01-02 21:49:43 +00:00
|
|
|
internal void Dispose()
|
2007-10-21 22:41:46 +00:00
|
|
|
{
|
|
|
|
// Not already disposed?
|
|
|
|
if(!isdisposed)
|
|
|
|
{
|
|
|
|
// Clean up
|
|
|
|
things = null;
|
|
|
|
|
|
|
|
// Done
|
|
|
|
isdisposed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-20 12:34:27 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
2009-01-22 22:22:02 +00:00
|
|
|
// This sorts the category, if preferred
|
|
|
|
internal void SortIfNeeded()
|
|
|
|
{
|
|
|
|
if(sorted) things.Sort();
|
|
|
|
}
|
|
|
|
|
2007-10-21 22:41:46 +00:00
|
|
|
// This adds a thing to the category
|
2008-01-02 21:49:43 +00:00
|
|
|
internal void AddThing(ThingTypeInfo t)
|
2007-10-21 22:41:46 +00:00
|
|
|
{
|
|
|
|
// Add
|
|
|
|
things.Add(t);
|
|
|
|
}
|
2008-05-26 20:06:15 +00:00
|
|
|
|
|
|
|
// String representation
|
|
|
|
public override string ToString()
|
|
|
|
{
|
|
|
|
return title;
|
|
|
|
}
|
2007-10-21 22:41:46 +00:00
|
|
|
|
2007-10-20 12:34:27 +00:00
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|
2007-10-21 22:41:46 +00:00
|
|
|
|