Implement string argument info

This commit is contained in:
MascaraSnake 2022-12-30 18:37:26 +01:00
parent fbd2beff41
commit fea4ac17db
8 changed files with 112 additions and 51 deletions

View file

@ -94,20 +94,21 @@ namespace CodeImp.DoomBuilder.Config
#region ================== Constructor / Disposer
// Constructor for argument info from configuration
internal ArgumentInfo(Configuration cfg, string argspath, int argindex, IDictionary<string, EnumList> enums)
internal ArgumentInfo(Configuration cfg, string argspath, int argindex, bool isstringarg, IDictionary<string, EnumList> enums)
{
// Read
string istr = argindex.ToString(CultureInfo.InvariantCulture);
this.used = cfg.SettingExists(argspath + ".arg" + istr);
this.title = cfg.ReadSetting(argspath + ".arg" + istr + ".title", "Argument " + (argindex + 1));
this.tooltip = cfg.ReadSetting(argspath + ".arg" + istr + ".tooltip", string.Empty); //mxd
this.type = cfg.ReadSetting(argspath + ".arg" + istr + ".type", 0);
this.str = cfg.ReadSetting(argspath + ".arg" + istr + ".str", false);
this.titlestr = cfg.ReadSetting(argspath + ".arg" + istr + ".titlestr", this.title);
this.defaultvalue = cfg.ReadSetting(argspath + ".arg" + istr + ".default", 0);
string argtype = isstringarg ? ".stringarg" : ".arg";
string argpath = argspath + argtype + argindex.ToString(CultureInfo.InvariantCulture);
this.used = cfg.SettingExists(argpath);
this.title = cfg.ReadSetting(argpath + ".title", (isstringarg ? "String argument " : "Argument ") + (argindex + 1));
this.tooltip = cfg.ReadSetting(argpath + ".tooltip", string.Empty); //mxd
this.type = cfg.ReadSetting(argpath + ".type", 0);
this.str = cfg.ReadSetting(argpath + ".str", false);
this.titlestr = cfg.ReadSetting(argpath + ".titlestr", this.title);
this.defaultvalue = cfg.ReadSetting(argpath + ".default", 0);
//mxd. Get rendering hint settings
string renderstyle = cfg.ReadSetting(argspath + ".arg" + istr + ".renderstyle", string.Empty);
string renderstyle = cfg.ReadSetting(argpath + ".renderstyle", string.Empty);
switch(renderstyle.ToLowerInvariant())
{
case "circle":
@ -119,45 +120,45 @@ namespace CodeImp.DoomBuilder.Config
default:
this.renderstyle = ArgumentRenderStyle.NONE;
if(!string.IsNullOrEmpty(renderstyle))
General.ErrorLogger.Add(ErrorType.Error, "\"" + argspath + ".arg" + istr + "\": action argument \"" + this.title + "\" has unknown renderstyle \"" + renderstyle + "\"!");
General.ErrorLogger.Add(ErrorType.Error, "\"" + argpath + "\": action argument \"" + this.title + "\" has unknown renderstyle \"" + renderstyle + "\"!");
break;
}
if(this.renderstyle != ArgumentRenderStyle.NONE)
{
// Get rendercolor
string rendercolor = cfg.ReadSetting(argspath + ".arg" + istr + ".rendercolor", string.Empty);
string rendercolor = cfg.ReadSetting(argpath + ".rendercolor", string.Empty);
this.rendercolor = General.Colors.InfoLine;
if(!string.IsNullOrEmpty(rendercolor) && !ZDTextParser.GetColorFromString(rendercolor, out this.rendercolor))
General.ErrorLogger.Add(ErrorType.Error, "\"" + argspath + ".arg" + istr + "\": action argument \"" + this.title + "\": unable to get rendercolor from value \"" + rendercolor + "\"!");
General.ErrorLogger.Add(ErrorType.Error, "\"" + argpath + "\": action argument \"" + this.title + "\": unable to get rendercolor from value \"" + rendercolor + "\"!");
this.rendercolor.a = HELPER_SHAPE_ALPHA;
// Get minrange settings
string minrange = cfg.ReadSetting(argspath + ".arg" + istr + ".minrange", string.Empty);
string minrange = cfg.ReadSetting(argpath + ".minrange", string.Empty);
if(int.TryParse(minrange, NumberStyles.Integer, CultureInfo.InvariantCulture, out this.minrange) && this.minrange > 0f)
{
// Get minrangecolor
string minrangecolor = cfg.ReadSetting(argspath + ".arg" + istr + ".minrangecolor", string.Empty);
string minrangecolor = cfg.ReadSetting(argpath + ".minrangecolor", string.Empty);
this.minrangecolor = General.Colors.Indication;
if(!string.IsNullOrEmpty(minrangecolor) && !ZDTextParser.GetColorFromString(minrangecolor, out this.minrangecolor))
General.ErrorLogger.Add(ErrorType.Error, "\"" + argspath + ".arg" + istr + "\": action argument \"" + this.title + "\": unable to get minrangecolor from value \"" + minrangecolor + "\"!");
General.ErrorLogger.Add(ErrorType.Error, "\"" + argpath + "\": action argument \"" + this.title + "\": unable to get minrangecolor from value \"" + minrangecolor + "\"!");
this.minrangecolor.a = RANGE_SHAPE_ALPHA;
}
// Get maxrange settings
string maxrange = cfg.ReadSetting(argspath + ".arg" + istr + ".maxrange", string.Empty);
string maxrange = cfg.ReadSetting(argpath + ".maxrange", string.Empty);
if(int.TryParse(maxrange, NumberStyles.Integer, CultureInfo.InvariantCulture, out this.maxrange) && this.maxrange > 0f)
{
// Get minrangecolor
string maxrangecolor = cfg.ReadSetting(argspath + ".arg" + istr + ".maxrangecolor", string.Empty);
string maxrangecolor = cfg.ReadSetting(argpath + ".maxrangecolor", string.Empty);
this.maxrangecolor = General.Colors.Indication;
if(!string.IsNullOrEmpty(maxrangecolor) && !ZDTextParser.GetColorFromString(maxrangecolor, out this.maxrangecolor))
General.ErrorLogger.Add(ErrorType.Error, "\"" + argspath + ".arg" + istr + "\": action argument \"" + this.title + "\": unable to get maxrangecolor from value \"" + maxrangecolor + "\"!");
General.ErrorLogger.Add(ErrorType.Error, "\"" + argpath + "\": action argument \"" + this.title + "\": unable to get maxrangecolor from value \"" + maxrangecolor + "\"!");
this.maxrangecolor.a = RANGE_SHAPE_ALPHA;
}
@ -180,7 +181,7 @@ namespace CodeImp.DoomBuilder.Config
this.targetclasses = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
if(this.type == (int)UniversalType.ThingTag)
{
string s = cfg.ReadSetting(argspath + ".arg" + istr + ".targetclasses", string.Empty);
string s = cfg.ReadSetting(argpath + ".targetclasses", string.Empty);
if(!string.IsNullOrEmpty(s))
{
foreach(string tclass in s.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries))
@ -189,7 +190,7 @@ namespace CodeImp.DoomBuilder.Config
}
// Determine enum type
IDictionary argdic = cfg.ReadSetting(argspath + ".arg" + istr, new Hashtable());
IDictionary argdic = cfg.ReadSetting(argpath, new Hashtable());
if(argdic.Contains("enum"))
{
// Enum fully specified?
@ -208,7 +209,7 @@ namespace CodeImp.DoomBuilder.Config
}
else
{
General.ErrorLogger.Add(ErrorType.Warning, "\"" + argspath + ".arg" + istr + "\" references unknown enumeration \"" + argdic["enum"] + "\".");
General.ErrorLogger.Add(ErrorType.Warning, "\"" + argpath + "\" references unknown enumeration \"" + argdic["enum"] + "\".");
}
}
}
@ -232,7 +233,7 @@ namespace CodeImp.DoomBuilder.Config
}
else
{
General.ErrorLogger.Add(ErrorType.Warning, "\"" + argspath + ".arg" + istr + "\" references unknown flags enumeration \"" + argdic["flags"] + "\".");
General.ErrorLogger.Add(ErrorType.Warning, "\"" + argpath + "\" references unknown flags enumeration \"" + argdic["flags"] + "\".");
}
}
}
@ -397,10 +398,10 @@ namespace CodeImp.DoomBuilder.Config
}
// Constructor for unknown argument info
internal ArgumentInfo(int argindex)
internal ArgumentInfo(int argindex, bool isstringarg)
{
this.used = false;
this.title = "Argument " + (argindex + 1);
this.title = (isstringarg ? "String argument " : "Argument ") + (argindex + 1);
this.type = 0;
this.enumlist = new EnumList();
this.flagslist = new EnumList(); //mxd

View file

@ -58,6 +58,7 @@ namespace CodeImp.DoomBuilder.Config
private readonly string title;
private readonly string id; //mxd. wiki-compatible name
private readonly ArgumentInfo[] args;
private readonly ArgumentInfo[] stringargs;
private readonly bool isgeneralized;
private readonly bool isknown;
private readonly bool requiresactivation; //mxd
@ -80,6 +81,7 @@ namespace CodeImp.DoomBuilder.Config
public bool IsNull { get { return (index == 0); } }
public bool RequiresActivation { get { return requiresactivation; } } //mxd
public ArgumentInfo[] Args { get { return args; } }
public ArgumentInfo[] StringArgs { get { return stringargs; } }
public bool LineToLineTag { get { return linetolinetag; } }
public bool LineToLineSameAction { get { return linetolinesameaction; } }
public ErrorCheckerExemptions ErrorCheckerExemptions { get { return errorcheckerexemptions; } }
@ -97,6 +99,7 @@ namespace CodeImp.DoomBuilder.Config
this.index = index;
this.category = categoryname;
this.args = new ArgumentInfo[Linedef.NUM_ARGS];
this.stringargs = new ArgumentInfo[Linedef.NUM_STRING_ARGS];
this.isgeneralized = false;
this.isknown = true;
this.errorcheckerexemptions = new ErrorCheckerExemptions();
@ -123,8 +126,10 @@ namespace CodeImp.DoomBuilder.Config
// Read the args
for (int i = 0; i < this.args.Length; i++)
this.args[i] = new ArgumentInfo(cfg, actionsetting, i, enums);
this.args[i] = new ArgumentInfo(cfg, actionsetting, i, false, enums);
for (int i = 0; i < this.stringargs.Length; i++)
this.stringargs[i] = new ArgumentInfo(cfg, actionsetting, i, true, enums);
// We have no destructor
GC.SuppressFinalize(this);
}
@ -138,8 +143,11 @@ namespace CodeImp.DoomBuilder.Config
this.requiresactivation = true; //mxd. Unused, set for consistency sake.
this.title = title;
this.args = new ArgumentInfo[Linedef.NUM_ARGS];
for(int i = 0; i < this.args.Length; i++)
this.args[i] = new ArgumentInfo(i);
this.stringargs = new ArgumentInfo[Linedef.NUM_STRING_ARGS];
for (int i = 0; i < this.args.Length; i++)
this.args[i] = new ArgumentInfo(i, false);
for (int i = 0; i < this.stringargs.Length; i++)
this.stringargs[i] = new ArgumentInfo(i, true);
}
#endregion

View file

@ -81,6 +81,7 @@ namespace CodeImp.DoomBuilder.Config
private readonly bool fixedrotation; //mxd
private readonly ThingCategory category;
private readonly ArgumentInfo[] args;
private readonly ArgumentInfo[] stringargs;
private readonly bool isknown;
private readonly bool absolutez;
private bool xybillboard; //mxd
@ -131,6 +132,7 @@ namespace CodeImp.DoomBuilder.Config
public bool FixedRotation { get { return fixedrotation; } } //mxd
public ThingCategory Category { get { return category; } }
public ArgumentInfo[] Args { get { return args; } }
public ArgumentInfo[] StringArgs { get { return stringargs; } }
public bool IsKnown { get { return isknown; } }
public bool IsNull { get { return (index == 0); } }
public bool IsObsolete { get { return obsolete; } } //mxd
@ -189,7 +191,8 @@ namespace CodeImp.DoomBuilder.Config
this.fixedsize = false;
this.fixedrotation = false; //mxd
this.spriteframe = new[] { new SpriteFrameInfo { Sprite = sprite, SpriteLongName = Lump.MakeLongName(sprite, true) } }; //mxd
this.args = new ArgumentInfo[Linedef.NUM_ARGS];
this.args = new ArgumentInfo[Thing.NUM_ARGS];
this.stringargs = new ArgumentInfo[Thing.NUM_STRING_ARGS];
this.isknown = false;
this.absolutez = false;
this.xybillboard = false;
@ -210,7 +213,8 @@ namespace CodeImp.DoomBuilder.Config
// Initialize
this.index = index;
this.category = cat;
this.args = new ArgumentInfo[Linedef.NUM_ARGS];
this.args = new ArgumentInfo[Thing.NUM_ARGS];
this.stringargs = new ArgumentInfo[Thing.NUM_STRING_ARGS];
this.isknown = true;
this.actor = null;
this.bright = false; //mxd
@ -262,10 +266,12 @@ namespace CodeImp.DoomBuilder.Config
// Read the args
for(int i = 0; i < this.args.Length; i++)
this.args[i] = new ArgumentInfo(cfg, "thingtypes." + cat.Name + "." + key, i, enums);
this.args[i] = new ArgumentInfo(cfg, "thingtypes." + cat.Name + "." + key, i, false, enums);
for (int i = 0; i < this.stringargs.Length; i++)
this.stringargs[i] = new ArgumentInfo(cfg, "thingtypes." + cat.Name + "." + key, i, true, enums);
// Safety
if(this.radius < 4f || this.fixedsize) this.radius = THING_FIXED_SIZE;
if (this.radius < 4f || this.fixedsize) this.radius = THING_FIXED_SIZE;
if(this.hangs && this.absolutez) this.hangs = false; //mxd
//mxd. Create sprite frame
@ -293,9 +299,11 @@ namespace CodeImp.DoomBuilder.Config
this.isknown = true;
this.bright = false; //mxd
this.distancechecksq = double.MaxValue;
this.args = new ArgumentInfo[Linedef.NUM_ARGS];
for(int i = 0; i < this.args.Length; i++) this.args[i] = new ArgumentInfo(i);
this.args = new ArgumentInfo[Thing.NUM_ARGS];
this.stringargs = new ArgumentInfo[Thing.NUM_STRING_ARGS];
for (int i = 0; i < this.args.Length; i++) this.args[i] = new ArgumentInfo(i, false);
for (int i = 0; i < this.stringargs.Length; i++) this.stringargs[i] = new ArgumentInfo(i, true);
// Read properties
this.sprite = cat.Sprite;
this.color = cat.Color;
@ -340,9 +348,11 @@ namespace CodeImp.DoomBuilder.Config
this.isknown = true;
this.bright = false; //mxd
this.distancechecksq = double.MaxValue;
this.args = new ArgumentInfo[Linedef.NUM_ARGS];
for(int i = 0; i < this.args.Length; i++) this.args[i] = new ArgumentInfo(i);
this.args = new ArgumentInfo[Thing.NUM_ARGS];
this.stringargs = new ArgumentInfo[Thing.NUM_STRING_ARGS];
for (int i = 0; i < this.args.Length; i++) this.args[i] = new ArgumentInfo(i, false);
for (int i = 0; i < this.stringargs.Length; i++) this.stringargs[i] = new ArgumentInfo(i, true);
// Read properties
this.sprite = cat.Sprite;
this.color = cat.Color;
@ -389,8 +399,10 @@ namespace CodeImp.DoomBuilder.Config
this.isknown = true;
this.bright = false; //mxd
this.distancechecksq = double.MaxValue;
this.args = new ArgumentInfo[Linedef.NUM_ARGS];
for(int i = 0; i < this.args.Length; i++) this.args[i] = new ArgumentInfo(i);
this.args = new ArgumentInfo[Thing.NUM_ARGS];
this.stringargs = new ArgumentInfo[Thing.NUM_STRING_ARGS];
for (int i = 0; i < this.args.Length; i++) this.args[i] = new ArgumentInfo(i, false);
for (int i = 0; i < this.stringargs.Length; i++) this.stringargs[i] = new ArgumentInfo(i, true);
// Read properties
this.sprite = cat.Sprite;
@ -437,9 +449,12 @@ namespace CodeImp.DoomBuilder.Config
this.actor = other.actor;
this.classname = other.classname; //mxd
this.isknown = true;
this.args = new ArgumentInfo[Linedef.NUM_ARGS];
for(int i = 0; i < this.args.Length; i++)
this.args = new ArgumentInfo[Thing.NUM_ARGS];
this.stringargs = new ArgumentInfo[Thing.NUM_STRING_ARGS];
for (int i = 0; i < this.args.Length; i++)
this.args[i] = other.args[i];
for (int i = 0; i < this.stringargs.Length; i++)
this.stringargs[i] = other.stringargs[i];
// Copy properties
this.sprite = other.sprite;

View file

@ -31,10 +31,11 @@ namespace CodeImp.DoomBuilder.Controls
private int action;
private ArgumentInfo[] arginfo;
private ArgumentInfo[] stringarginfo;
private Label[] labels;
private ArgumentBox[] args;
private Label[] stringlabels;
private System.Windows.Forms.TextBox[] stringargs;
private TextBox[] stringargs;
#endregion
@ -129,15 +130,17 @@ namespace CodeImp.DoomBuilder.Controls
// Update arguments
int showaction = 0;
ArgumentInfo[] oldarginfo = (arginfo != null ? (ArgumentInfo[])arginfo.Clone() : null); //mxd
ArgumentInfo[] oldstringarginfo = (stringarginfo != null ? (ArgumentInfo[])stringarginfo.Clone() : null);
// Only when action type is known
if (General.Map.Config.LinedefActions.ContainsKey(action)) showaction = action;
// Update argument infos
arginfo = General.Map.Config.LinedefActions[showaction].Args;
stringarginfo = General.Map.Config.LinedefActions[showaction].StringArgs;
//mxd. Don't update action args when old and new argument infos match
if (arginfo != null && oldarginfo != null && ArgumentInfosMatch(arginfo, oldarginfo)) return;
if (arginfo != null && oldarginfo != null && stringarginfo != null && oldstringarginfo != null && ArgumentInfosMatch(arginfo, oldarginfo) && ArgumentInfosMatch(stringarginfo, oldstringarginfo)) return;
// Change the argument descriptions
this.BeginUpdate();
@ -145,6 +148,9 @@ namespace CodeImp.DoomBuilder.Controls
for (int i = 0; i < args.Length; i++)
UpdateArgument(args[i], labels[i], arginfo[i]);
for (int i = 0; i < stringargs.Length; i++)
UpdateStringArgument(stringargs[i], stringlabels[i], stringarginfo[i]);
if (!setuponly)
{
// Apply action's default arguments
@ -158,6 +164,9 @@ namespace CodeImp.DoomBuilder.Controls
for (int i = 0; i < args.Length; i++)
args[i].SetValue(0);
}
for (int i = 0; i < stringargs.Length; i++)
stringargs[i].Text = string.Empty;
}
// Store current action
@ -170,12 +179,22 @@ namespace CodeImp.DoomBuilder.Controls
{
// Update arguments
ArgumentInfo[] oldarginfo = (arginfo != null ? (ArgumentInfo[])arginfo.Clone() : null); //mxd
ArgumentInfo[] oldstringarginfo = (stringarginfo != null ? (ArgumentInfo[])stringarginfo.Clone() : null);
// Update argument infos
arginfo = info.Args;
if (info != null)
{
arginfo = info.Args;
stringarginfo = info.StringArgs;
}
else
{
arginfo = General.Map.Config.LinedefActions[0].Args;
stringarginfo = General.Map.Config.LinedefActions[0].Args;
}
//mxd. Don't update args when old and new argument infos match
if (arginfo != null && oldarginfo != null && ArgumentInfosMatch(arginfo, oldarginfo)) return;
if (arginfo != null && oldarginfo != null && stringarginfo != null && oldstringarginfo != null && ArgumentInfosMatch(arginfo, oldarginfo) && ArgumentInfosMatch(stringarginfo, oldstringarginfo)) return;
// Change the argument descriptions
this.BeginUpdate();
@ -183,6 +202,9 @@ namespace CodeImp.DoomBuilder.Controls
for (int i = 0; i < args.Length; i++)
UpdateArgument(args[i], labels[i], arginfo[i]);
for (int i = 0; i < stringargs.Length; i++)
UpdateStringArgument(stringargs[i], stringlabels[i], stringarginfo[i]);
// Apply thing's default arguments
if (info != null)
{
@ -195,6 +217,9 @@ namespace CodeImp.DoomBuilder.Controls
args[i].SetValue(0);
}
for (int i = 0; i < stringargs.Length; i++)
stringargs[i].Text = string.Empty;
this.EndUpdate();
}
@ -213,6 +238,16 @@ namespace CodeImp.DoomBuilder.Controls
// Update tooltip
UpdateToolTip(label, info);
}
private void UpdateStringArgument(TextBox arg, Label label, ArgumentInfo info)
{
// Update labels
label.Text = info.Title + ":";
label.Enabled = info.Used;
arg.ForeColor = (label.Enabled ? SystemColors.WindowText : SystemColors.GrayText);
// Update tooltip
UpdateToolTip(label, info);
}
private void UpdateToolTip(Label label, ArgumentInfo info)
{

View file

@ -350,7 +350,7 @@ namespace CodeImp.DoomBuilder.IO
map.SetCapacity(0, 0, 0, 0, map.Things.Count + count);
for(int i = 0; i < count; i++)
{
int[] args = new int[Linedef.NUM_ARGS];
int[] args = new int[Thing.NUM_ARGS];
int tag = reader.ReadInt32();
double x = reader.ReadDouble();
double y = reader.ReadDouble();

View file

@ -180,7 +180,7 @@ namespace CodeImp.DoomBuilder.IO
{
// Read fields
UniversalCollection c = collections[i];
int[] args = new int[Linedef.NUM_ARGS];
int[] args = new int[Thing.NUM_ARGS];
string where = "thing " + i;
double x = GetCollectionEntry(c, "x", true, 0.0, where);
double y = GetCollectionEntry(c, "y", true, 0.0, where);

View file

@ -34,7 +34,8 @@ namespace CodeImp.DoomBuilder.Map
public const double SIDE_POINT_DISTANCE = 0.01;
public const int NUM_ARGS = 10;
public const int NUM_STRING_ARGS = 2;
#endregion
#region ================== Variables

View file

@ -37,6 +37,7 @@ namespace CodeImp.DoomBuilder.Map
#region ================== Constants
public const int NUM_ARGS = 10;
public const int NUM_STRING_ARGS = 2;
public static readonly HashSet<ThingRenderMode> AlignableRenderModes = new HashSet<ThingRenderMode>
{
ThingRenderMode.FLATSPRITE, ThingRenderMode.WALLSPRITE, ThingRenderMode.MODEL