From 9a6d3ea84c6c3e62b571cf46ad6833c0b4cf7f8e Mon Sep 17 00:00:00 2001
From: MaxED
Date: Thu, 14 Jul 2016 12:42:16 +0000
Subject: [PATCH] Added, DECORATE: added "//$ArgNRenderStyle" special comment.
It allows to specify a rendering shape to display the value of given
argument. Supported values are "circle" and "rectangle". Added, DECORATE:
added "//$ArgNRenderColor" special comment. It allows to specify a color used
by the rendering shape. Updated documentation.
---
Help/gc_argumentsettings.html | 14 ++-
Help/gc_decoratekeys.html | 41 ++++++---
Source/Core/Config/ArgumentInfo.cs | 92 ++++++++++++++++++-
Source/Core/Config/ThingTypeInfo.cs | 4 +-
Source/Core/GZBuilder/Data/LinksCollector.cs | 65 ++++++++++++-
.../BuilderModes/ClassicModes/ThingsMode.cs | 21 +----
6 files changed, 203 insertions(+), 34 deletions(-)
diff --git a/Help/gc_argumentsettings.html b/Help/gc_argumentsettings.html
index 5d3a63e6..6c2400af 100644
--- a/Help/gc_argumentsettings.html
+++ b/Help/gc_argumentsettings.html
@@ -91,7 +91,19 @@ arg0
Enums can be also set in DECORATE.
- flags (structure or string) - GZDB only
+
renderstyle (string) - GZDB only
+ Allows to specify a rendering shape to display the value of this argument. Supported values are:
+
+ - "Rectangle". The argument value is used as rectangle size.
+ - "Circle". The argument value is used as circle radius.
+
+ Rendering shapes can be toggled using "Toggle Event Lines" action/menu button.
+ Currently rendering shapes are supported only for Thing arguments.
Currently rendering shapes are shown only in Classic modes.
+ rendercolor (integer) - GZDB only
+ Allows to specify a color used by rendering shape. Supported values are hex color (like "FF0000"), HTML-formatted hex color (like "#F00" or "#FF0000") or color name (like "Red").
+ By default rendering shapes will use Event line editor color.
+ This property must be used in conjunction with the "renderstyle" property.
+flags (structure or string) - GZDB only
Provides a list of predefined bit flag values to display for this argument. Used only when argument type is 26.
The value can be either a name of a predefined enum or an explicit definition.
Example:
diff --git a/Help/gc_decoratekeys.html b/Help/gc_decoratekeys.html
index b10d4961..9d614025 100644
--- a/Help/gc_decoratekeys.html
+++ b/Help/gc_decoratekeys.html
@@ -48,21 +48,39 @@
Allows to override default argument names for this actor.
//$ArgNDefault <integer> - GZDB only.
- Allows to set the default value for this argument. This property can only be used in conjunction with "//$ArgN" property.
+ Allows to set the default value for this argument. This property must be used in conjunction with the "//$ArgN" property.
//$ArgNTooltip <text> - GZDB only.
- Allows to specify a tooltip text displayed for this argument. Newline character ("\n") can be used to format the text. This property can only be used in conjunction with "//$ArgN" property.
+ Allows to specify a tooltip text displayed for this argument. Newline character ("\n") can be used to format the text. This property must be used in conjunction with the "//$ArgN" property.
Argument tooltips can be also set for things and linedefs in a Game Configuration.
//$ArgNType <integer> - GZDB only.
- Allows to specify an argument type for this argument. This property can only be used in conjunction with "//$ArgN" property.
+ Allows to specify an argument type for this argument. This property must be used in conjunction with the "//$ArgN" property.
- //$ArgNEnum <string or structure> - GZDB only.
- Allows to specify an enum for this argument. This can be either a name of an enum defined in the Game Configuration, or an explicit enum definition. This property can only be used in conjunction with "//$ArgN" property.
-
- //$Color <color index> - GZDB only.
- Allows to override category color for this actor. Possible values are:
-
+
+ //$ArgNRenderStyle <string> - GZDB only.
+ Allows to specify a rendering shape to display the value of this argument. Supported values are:
+
+ - "Rectangle". The argument value is used as rectangle size.
+ - "Circle". The argument value is used as circle radius.
+
+ Rendering shapes can be toggled using "Toggle Event Lines" action/menu button.
+ Currently rendering shapes are shown only in Classic modes.
+ This property must be used in conjunction with the "//$ArgN" property.
+
+ //$ArgNRenderColor <integer> - GZDB only.
+ Allows to specify a color used by rendering shape. Supported values are hex color (like "FF0000"), HTML-formatted hex color (like "#F00" or "#FF0000") or color name (like "Red").
+ By default rendering shapes will use Event line editor color.
+ This property must be used in conjunction with "//$ArgN" and "//$ArgNRenderStyle" properties.
+
+
+
+ //$ArgNEnum <string or structure> - GZDB only.
+ Allows to specify an enum for this argument. This can be either a name of an enum defined in the Game Configuration, or an explicit enum definition. This property must be used in conjunction with the "//$ArgN" property.
+
+ //$Color <color index> - GZDB only.
+ Allows to override category color for this actor. Possible values are:
+
- 0 - █ Dark Gray;
- 1 - █ Blue;
- 2 - █ Green;
@@ -117,6 +135,8 @@ Actor ChexShield : ResistanceRune replaces ResistanceRune 5104
//$Arg3 "Radius"
//$Arg3Type 23
//$Arg3Default 32
+ //$Arg3RenderStyle "Circle"
+ //$Arg3RenderColor #ff00ff
//$Arg4 "Height"
//$Arg4Type 24
@@ -142,7 +162,7 @@ actor SuperGiantImpBall : DoomImpBall
Damage 30
}
-
+
Category definitions (GZDB only):
Thing categories can be defined in DECORATE using #region / #endregion blocks. Region name is used as thing category title. "//$Category" actor block definition overrides these. Additional information can be conveyed with keys in the form of special comments inserted within #region / #endregion block (these keys replicate Game Configuration thing category properties with a slightly different syntax):
@@ -163,7 +183,6 @@ Thing categories can be defined in DECORATE using #region / //$Error (integer) [0 .. 2]
Sets the stuck things error checking mode to use on this thing.
Possible values are:
-
- 0 - Don't check this thing.
- 1 - Check if the thing is outside of map geometry.
diff --git a/Source/Core/Config/ArgumentInfo.cs b/Source/Core/Config/ArgumentInfo.cs
index 7bd23d51..0291b0ee 100644
--- a/Source/Core/Config/ArgumentInfo.cs
+++ b/Source/Core/Config/ArgumentInfo.cs
@@ -21,7 +21,9 @@ using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using CodeImp.DoomBuilder.IO;
+using CodeImp.DoomBuilder.Rendering;
using CodeImp.DoomBuilder.Types;
+using CodeImp.DoomBuilder.ZDoom;
#endregion
@@ -31,6 +33,19 @@ namespace CodeImp.DoomBuilder.Config
{
#region ================== Constants
+ private const int HELPER_SHAPE_ALPHA = 192; //mxd
+
+ #endregion
+
+ #region ================== Enums (mxd)
+
+ public enum ArgumentRenderStyle
+ {
+ NONE,
+ CIRCLE,
+ RECTANGLE,
+ }
+
#endregion
#region ================== Variables
@@ -43,6 +58,8 @@ namespace CodeImp.DoomBuilder.Config
private EnumList flagslist; //mxd
private readonly object defaultvalue; //mxd
private readonly HashSet targetclasses; //mxd
+ private readonly ArgumentRenderStyle renderstyle; //mxd
+ private readonly PixelColor rendercolor; //mxd
#endregion
@@ -56,6 +73,8 @@ namespace CodeImp.DoomBuilder.Config
public EnumList Enum { get { return enumlist; } internal set { enumlist = value; } }
public EnumList Flags { get { return flagslist; } internal set { flagslist = value; } } //mxd
public object DefaultValue { get { return defaultvalue; } } //mxd
+ public ArgumentRenderStyle RenderStyle { get { return renderstyle; } } //mxd
+ public PixelColor RenderColor { get { return rendercolor; } } //mxd
#endregion
@@ -72,6 +91,44 @@ namespace CodeImp.DoomBuilder.Config
this.type = cfg.ReadSetting(argspath + ".arg" + istr + ".type", 0);
this.defaultvalue = cfg.ReadSetting(argspath + ".arg" + istr + ".default", 0); //mxd
+ //mxd. Get rendering hint settings
+ string renderstyle = cfg.ReadSetting(argspath + ".arg" + istr + ".renderstyle", string.Empty);
+ switch(renderstyle.ToLowerInvariant())
+ {
+ case "circle":
+ this.renderstyle = ArgumentRenderStyle.CIRCLE;
+ break;
+ case "rectangle":
+ this.renderstyle = ArgumentRenderStyle.RECTANGLE;
+ break;
+ 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 + "\"!");
+ break;
+ }
+
+ if(this.renderstyle != ArgumentRenderStyle.NONE)
+ {
+ string rendercolor = cfg.ReadSetting(argspath + ".arg" + istr + ".rendercolor", string.Empty);
+ if(!string.IsNullOrEmpty(rendercolor))
+ {
+ if(!ZDTextParser.GetColorFromString(rendercolor, ref this.rendercolor))
+ {
+ General.ErrorLogger.Add(ErrorType.Error, "\"" + argspath + ".arg" + istr + "\": action argument \"" + this.title + "\": unable to get rendercolor from value \"" + rendercolor + "\"!");
+ this.rendercolor = General.Colors.InfoLine.WithAlpha(HELPER_SHAPE_ALPHA);
+ }
+ else
+ {
+ this.rendercolor.a = HELPER_SHAPE_ALPHA;
+ }
+ }
+ else
+ {
+ this.rendercolor = General.Colors.InfoLine.WithAlpha(HELPER_SHAPE_ALPHA);
+ }
+ }
+
//mxd. Check for TargetClass?
this.targetclasses = new HashSet(StringComparer.InvariantCultureIgnoreCase);
if(this.type == (int)UniversalType.ThingTag)
@@ -138,7 +195,8 @@ namespace CodeImp.DoomBuilder.Config
}
//mxd. Constructor for an argument info defined in DECORATE
- internal ArgumentInfo(string actorname, string argtitle, string tooltip, int type, int defaultvalue, string enumstr, IDictionary enums)
+ internal ArgumentInfo(string actorname, string argtitle, string tooltip, string renderstyle, string rendercolor,
+ int type, int defaultvalue, string enumstr, IDictionary enums)
{
this.used = true;
this.title = argtitle;
@@ -146,6 +204,38 @@ namespace CodeImp.DoomBuilder.Config
this.defaultvalue = defaultvalue;
this.flagslist = new EnumList(); //mxd
+ // Get rendering hint settings
+ switch(renderstyle.ToLowerInvariant())
+ {
+ case "circle": this.renderstyle = ArgumentRenderStyle.CIRCLE; break;
+ case "rectangle": this.renderstyle = ArgumentRenderStyle.RECTANGLE; break;
+ default:
+ this.renderstyle = ArgumentRenderStyle.NONE;
+ if(!string.IsNullOrEmpty(renderstyle))
+ General.ErrorLogger.Add(ErrorType.Error, actorname + ": action argument \"" + argtitle + "\" has unknown renderstyle \"" + renderstyle + "\"!");
+ break;
+ }
+
+ if(this.renderstyle != ArgumentRenderStyle.NONE)
+ {
+ if(!string.IsNullOrEmpty(rendercolor))
+ {
+ if(!ZDTextParser.GetColorFromString(rendercolor, ref this.rendercolor))
+ {
+ General.ErrorLogger.Add(ErrorType.Error, actorname + ": action argument \"" + argtitle + "\": unable to get rendercolor from value \"" + rendercolor + "\"!");
+ this.rendercolor = General.Colors.InfoLine.WithAlpha(HELPER_SHAPE_ALPHA);
+ }
+ else
+ {
+ this.rendercolor.a = HELPER_SHAPE_ALPHA;
+ }
+ }
+ else
+ {
+ this.rendercolor = General.Colors.InfoLine.WithAlpha(HELPER_SHAPE_ALPHA);
+ }
+ }
+
// Get argument type
if(System.Enum.IsDefined(typeof(UniversalType), type))
{
diff --git a/Source/Core/Config/ThingTypeInfo.cs b/Source/Core/Config/ThingTypeInfo.cs
index d9ab5a39..781d21fa 100644
--- a/Source/Core/Config/ThingTypeInfo.cs
+++ b/Source/Core/Config/ThingTypeInfo.cs
@@ -443,7 +443,9 @@ namespace CodeImp.DoomBuilder.Config
int argtype = actor.GetPropertyValueInt("$arg" + i + "type", 0);
int defaultvalue = actor.GetPropertyValueInt("$arg" + i + "default", 0);
string argenum = ZDTextParser.StripQuotes(actor.GetPropertyAllValues("$arg" + i + "enum"));
- args[i] = new ArgumentInfo(title, argtitle, argtooltip, argtype, defaultvalue, argenum, General.Map.Config.Enums);
+ string argrenderstyle = ZDTextParser.StripQuotes(actor.GetPropertyAllValues("$arg" + i + "renderstyle"));
+ string argrendercolor = ZDTextParser.StripQuotes(actor.GetPropertyAllValues("$arg" + i + "rendercolor"));
+ args[i] = new ArgumentInfo(title, argtitle, argtooltip, argrenderstyle, argrendercolor, argtype, defaultvalue, argenum, General.Map.Config.Enums);
}
//mxd. Some SLADE compatibility
diff --git a/Source/Core/GZBuilder/Data/LinksCollector.cs b/Source/Core/GZBuilder/Data/LinksCollector.cs
index 10bca10f..91c150d9 100644
--- a/Source/Core/GZBuilder/Data/LinksCollector.cs
+++ b/Source/Core/GZBuilder/Data/LinksCollector.cs
@@ -1,7 +1,9 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
using CodeImp.DoomBuilder.Config;
using CodeImp.DoomBuilder.Map;
using CodeImp.DoomBuilder.Geometry;
+using CodeImp.DoomBuilder.Rendering;
using CodeImp.DoomBuilder.VisualModes;
namespace CodeImp.DoomBuilder.GZBuilder.Data
@@ -71,6 +73,39 @@ namespace CodeImp.DoomBuilder.GZBuilder.Data
}
}
+ public static IEnumerable MakeCircleLines(Vector2D pos, PixelColor color, float radius, int numsides)
+ {
+ List result = new List(numsides);
+ Vector2D start = new Vector2D(pos.x, pos.y + radius);
+ float anglestep = Angle2D.PI2 / numsides;
+
+ for(int i = 1; i < numsides + 1; i++)
+ {
+ Vector2D end = pos + new Vector2D((float)Math.Sin(anglestep * i) * radius, (float)Math.Cos(anglestep * i) * radius);
+ result.Add(new Line3D(start, end, color, false));
+ start = end;
+ }
+
+ return result;
+ }
+
+ public static IEnumerable MakeRectangleLines(Vector2D pos, PixelColor color, float size)
+ {
+ float halfsize = size / 2;
+ Vector2D tl = new Vector2D(pos.x - halfsize, pos.y - halfsize);
+ Vector2D tr = new Vector2D(pos.x + halfsize, pos.y - halfsize);
+ Vector2D bl = new Vector2D(pos.x - halfsize, pos.y + halfsize);
+ Vector2D br = new Vector2D(pos.x + halfsize, pos.y + halfsize);
+
+ return new List
+ {
+ new Line3D(tl, tr, color, false),
+ new Line3D(tr, br, color, false),
+ new Line3D(bl, br, color, false),
+ new Line3D(bl, tl, color, false),
+ };
+ }
+
public static List GetThingLinks(IEnumerable things) { return GetThingLinks(things, null); }
public static List GetThingLinks(IEnumerable things, VisualBlockMap blockmap)
{
@@ -367,6 +402,34 @@ namespace CodeImp.DoomBuilder.GZBuilder.Data
}
}
+ // Process arg helpers
+ const int numsides = 24;
+ foreach(Thing t in General.Map.ThingsFilter.VisibleThings)
+ {
+ if(t.Action != 0) continue;
+ ThingTypeInfo tti = General.Map.Data.GetThingInfoEx(t.Type);
+ if(tti == null) continue;
+
+ for(int i = 0; i < t.Args.Length; i++)
+ {
+ if(t.Args[i] != 0 && tti.Args[i].RenderStyle != ArgumentInfo.ArgumentRenderStyle.NONE)
+ {
+ switch(tti.Args[i].RenderStyle)
+ {
+ case ArgumentInfo.ArgumentRenderStyle.CIRCLE:
+ lines.AddRange(MakeCircleLines(t.Position, tti.Args[i].RenderColor, t.Args[i], numsides));
+ break;
+
+ case ArgumentInfo.ArgumentRenderStyle.RECTANGLE:
+ lines.AddRange(MakeRectangleLines(t.Position, tti.Args[i].RenderColor, t.Args[i]));
+ break;
+
+ default: throw new NotImplementedException("Unknown ArgumentRenderStyle");
+ }
+ }
+ }
+ }
+
return lines;
}
diff --git a/Source/Plugins/BuilderModes/ClassicModes/ThingsMode.cs b/Source/Plugins/BuilderModes/ClassicModes/ThingsMode.cs
index 2934f6b7..0a6b326d 100644
--- a/Source/Plugins/BuilderModes/ClassicModes/ThingsMode.cs
+++ b/Source/Plugins/BuilderModes/ClassicModes/ThingsMode.cs
@@ -1115,31 +1115,14 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Add lines if visible
const int numsides = 24;
- if(primaryradius > 0) circles.AddRange(MakeCircleLines(t.Position, color, primaryradius, numsides));
- if(secondaryradius > 0) circles.AddRange(MakeCircleLines(t.Position, color, secondaryradius, numsides));
+ if(primaryradius > 0) circles.AddRange(LinksCollector.MakeCircleLines(t.Position, color, primaryradius, numsides));
+ if(secondaryradius > 0) circles.AddRange(LinksCollector.MakeCircleLines(t.Position, color, secondaryradius, numsides));
}
// Done
return circles;
}
- //mxd
- private static IEnumerable MakeCircleLines(Vector2D pos, PixelColor color, float radius, int numsides)
- {
- List result = new List(numsides);
- Vector2D start = new Vector2D(pos.x, pos.y + radius);
- float anglestep = Angle2D.PI2 / numsides;
-
- for(int i = 1; i < numsides + 1; i++)
- {
- Vector2D end = pos + new Vector2D((float)Math.Sin(anglestep * i) * radius, (float)Math.Cos(anglestep * i) * radius);
- result.Add(new Line3D(start, end, color, false));
- start = end;
- }
-
- return result;
- }
-
#endregion
#region ================== Actions