mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2025-01-18 14:31:50 +00:00
Added: string/float user variables, //$UserDefaultValue <value> for specifying default user variable value
This commit is contained in:
parent
74e31b658b
commit
04dc210db5
7 changed files with 84 additions and 16 deletions
|
@ -256,14 +256,20 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
}
|
||||
|
||||
//mxd
|
||||
public void SetUserVars(Dictionary<string, UniversalType> vars, UniFields fromfields, bool first)
|
||||
public void SetUserVars(Dictionary<string, UniversalType> vars, Dictionary<string, object> defaults, UniFields fromfields, bool first)
|
||||
{
|
||||
foreach(KeyValuePair<string, UniversalType> group in vars)
|
||||
{
|
||||
// Go for all rows
|
||||
bool foundrow = false;
|
||||
// Go for all rows
|
||||
bool foundrow = false;
|
||||
TypeHandler vartype = General.Types.GetFieldHandler((int)group.Value, 0);
|
||||
object value = fromfields.ContainsKey(group.Key) ? fromfields[group.Key].Value : vartype.GetDefaultValue();
|
||||
|
||||
object defaultvalue;
|
||||
if (defaults.ContainsKey(group.Key))
|
||||
defaultvalue = defaults[group.Key];
|
||||
else defaultvalue = vartype.GetDefaultValue();
|
||||
|
||||
object value = fromfields.ContainsKey(group.Key) ? fromfields[group.Key].Value : defaultvalue;
|
||||
|
||||
foreach(DataGridViewRow row in fieldslist.Rows)
|
||||
{
|
||||
|
@ -298,8 +304,8 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
// Row not found?
|
||||
if(!foundrow)
|
||||
{
|
||||
// Make new row
|
||||
object defaultvalue = vartype.GetDefaultValue();
|
||||
// Make new row
|
||||
// [ZZ] 24.07.08: add support for custom defaults for user vars. ZScript only for now.
|
||||
FieldsEditorRow frow = new FieldsEditorRow(fieldslist, group.Key, (int)group.Value, defaultvalue, true);
|
||||
if(!value.Equals(defaultvalue)) frow.Define(value);
|
||||
fieldslist.Rows.Insert(fieldslist.Rows.Count - 1, frow);
|
||||
|
|
|
@ -130,7 +130,7 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
// Not defined
|
||||
this.DefaultCellStyle.ForeColor = SystemColors.GrayText;
|
||||
isdefined = false;
|
||||
fieldtype.ApplyDefaultValue();
|
||||
//fieldtype.ApplyDefaultValue(); // [ZZ] don't do this. this is only done for int, and not a very good place to do it...
|
||||
|
||||
// Setup property cell
|
||||
this.Cells[0].Value = name;
|
||||
|
|
|
@ -30,6 +30,6 @@ using CodeImp.DoomBuilder;
|
|||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
[assembly: AssemblyVersion("2.3.0.3035")]
|
||||
[assembly: AssemblyVersion("2.3.0.3036")]
|
||||
[assembly: NeutralResourcesLanguageAttribute("en")]
|
||||
[assembly: AssemblyHash("a196457")]
|
||||
[assembly: AssemblyHash("74e31b6")]
|
||||
|
|
|
@ -206,7 +206,7 @@ namespace CodeImp.DoomBuilder.Windows
|
|||
//mxd. User vars. Should be done before adding regular fields
|
||||
ThingTypeInfo fti = General.Map.Data.GetThingInfoEx(ft.Type);
|
||||
if(fti != null && fti.Actor != null && fti.Actor.UserVars.Count > 0)
|
||||
fieldslist.SetUserVars(fti.Actor.UserVars, ft.Fields, true);
|
||||
fieldslist.SetUserVars(fti.Actor.UserVars, fti.Actor.UserVarDefaults, ft.Fields, true);
|
||||
thinginfo = fti; //mxd
|
||||
|
||||
// Custom fields
|
||||
|
@ -289,7 +289,7 @@ namespace CodeImp.DoomBuilder.Windows
|
|||
//mxd. User vars. Should be done before adding regular fields
|
||||
ThingTypeInfo ti = General.Map.Data.GetThingInfoEx(t.Type);
|
||||
if(ti != null && ti.Actor != null && ti.Actor.UserVars.Count > 0)
|
||||
fieldslist.SetUserVars(ti.Actor.UserVars, t.Fields, false);
|
||||
fieldslist.SetUserVars(ti.Actor.UserVars, ti.Actor.UserVarDefaults, t.Fields, false);
|
||||
|
||||
//mxd. Custom fields
|
||||
fieldslist.SetValues(t.Fields, false);
|
||||
|
|
|
@ -54,6 +54,7 @@ namespace CodeImp.DoomBuilder.ZDoom
|
|||
// Properties
|
||||
internal Dictionary<string, List<string>> props;
|
||||
internal Dictionary<string, UniversalType> uservars; //mxd
|
||||
internal Dictionary<string, object> uservar_defaults; // [ZZ] should correspond to UniversalType
|
||||
|
||||
//mxd. Categories
|
||||
internal DecorateCategoryInfo catinfo;
|
||||
|
@ -76,6 +77,7 @@ namespace CodeImp.DoomBuilder.ZDoom
|
|||
public ActorStructure BaseClass { get { return baseclass; } }
|
||||
internal int DoomEdNum { get { return doomednum; } set { doomednum = value; } }
|
||||
public Dictionary<string, UniversalType> UserVars { get { return uservars; } } //mxd
|
||||
public Dictionary<string, object> UserVarDefaults { get { return uservar_defaults; } } // [ZZ]
|
||||
internal DecorateCategoryInfo CategoryInfo { get { return catinfo; } } //mxd
|
||||
|
||||
#endregion
|
||||
|
@ -90,6 +92,7 @@ namespace CodeImp.DoomBuilder.ZDoom
|
|||
props = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
|
||||
states = new Dictionary<string, StateStructure>(StringComparer.OrdinalIgnoreCase);
|
||||
uservars = new Dictionary<string, UniversalType>(StringComparer.OrdinalIgnoreCase);//mxd
|
||||
uservar_defaults = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);// [ZZ]
|
||||
|
||||
// Always define a game property, but default to 0 values
|
||||
props["game"] = new List<string>();
|
||||
|
|
|
@ -17,6 +17,8 @@ namespace CodeImp.DoomBuilder.ZDoom
|
|||
|
||||
internal static bool ParseGZDBComment(Dictionary<string, List<string>> props, string text)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(text))
|
||||
return false;
|
||||
text = text.Trim();
|
||||
// check if it's a GZDB comment
|
||||
if (text[0] != '$')
|
||||
|
@ -415,6 +417,9 @@ namespace CodeImp.DoomBuilder.ZDoom
|
|||
return;
|
||||
}
|
||||
|
||||
// this dict holds temporary user settings per field (function, etc)
|
||||
Dictionary<string, List<string>> var_props = new Dictionary<string, List<string>>();
|
||||
|
||||
// in the class definition, we can have the following:
|
||||
// - Defaults block
|
||||
// - States block
|
||||
|
@ -425,7 +430,18 @@ namespace CodeImp.DoomBuilder.ZDoom
|
|||
// we are skipping everything, except Defaults and States.
|
||||
while (true)
|
||||
{
|
||||
tokenizer.SkipWhitespace();
|
||||
var_props.Clear();
|
||||
while (true)
|
||||
{
|
||||
ZScriptToken tt = tokenizer.ExpectToken(ZScriptTokenType.Whitespace, ZScriptTokenType.BlockComment, ZScriptTokenType.LineComment, ZScriptTokenType.Newline);
|
||||
if (tt == null || !tt.IsValid)
|
||||
break;
|
||||
|
||||
if (tt.Type == ZScriptTokenType.LineComment)
|
||||
ParseGZDBComment(var_props, tt.Value);
|
||||
}
|
||||
|
||||
//tokenizer.SkipWhitespace();
|
||||
long ocpos = stream.Position;
|
||||
ZScriptToken token = tokenizer.ExpectToken(ZScriptTokenType.Identifier, ZScriptTokenType.CloseCurly);
|
||||
if (token == null || !token.IsValid)
|
||||
|
@ -749,12 +765,13 @@ namespace CodeImp.DoomBuilder.ZDoom
|
|||
// - bool
|
||||
string type = types[0];
|
||||
UniversalType utype;
|
||||
object udefault = null;
|
||||
switch (type)
|
||||
{
|
||||
case "int":
|
||||
utype = UniversalType.Integer;
|
||||
break;
|
||||
/*case "float":
|
||||
case "float":
|
||||
case "double":
|
||||
utype = UniversalType.Float;
|
||||
break;
|
||||
|
@ -764,12 +781,52 @@ namespace CodeImp.DoomBuilder.ZDoom
|
|||
case "string":
|
||||
utype = UniversalType.String;
|
||||
break;
|
||||
// todo test if class names and colors will work*/
|
||||
// [ZZ] currently only integer variable works.
|
||||
// todo test if class names and colors will work
|
||||
default:
|
||||
continue; // go read next field
|
||||
}
|
||||
|
||||
if (var_props.ContainsKey("$userdefaultvalue"))
|
||||
{
|
||||
string sp = var_props["$userdefaultvalue"][0];
|
||||
switch (utype)
|
||||
{
|
||||
case UniversalType.String:
|
||||
if (sp[0] == '"' && sp[sp.Length - 1] == '"')
|
||||
sp = sp.Substring(1, sp.Length - 2);
|
||||
udefault = sp;
|
||||
break;
|
||||
case UniversalType.Float:
|
||||
float d;
|
||||
if (!float.TryParse(sp, out d))
|
||||
{
|
||||
parser.LogWarning("Incorrect float default from string \"" + sp + "\"");
|
||||
break;
|
||||
}
|
||||
udefault = d;
|
||||
break;
|
||||
case UniversalType.Integer:
|
||||
int i;
|
||||
if (!int.TryParse(sp, out i))
|
||||
{
|
||||
if (type == "bool")
|
||||
{
|
||||
sp = sp.ToLowerInvariant();
|
||||
if (sp == "true")
|
||||
udefault = true;
|
||||
else if (sp == "false")
|
||||
udefault = false;
|
||||
else parser.LogWarning("Incorrect boolean default from string \"" + sp + "\"");
|
||||
break;
|
||||
}
|
||||
parser.LogWarning("Incorrect integer default from string \"" + sp + "\"");
|
||||
break;
|
||||
}
|
||||
udefault = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < names.Count; i++)
|
||||
{
|
||||
string name = names[i];
|
||||
|
@ -779,6 +836,8 @@ namespace CodeImp.DoomBuilder.ZDoom
|
|||
continue; // we don't process non-user_ fields (because ZScript won't pick them up anyway)
|
||||
// parent class is not guaranteed to be loaded already, so handle collisions later
|
||||
uservars.Add(name, utype);
|
||||
if (udefault != null)
|
||||
uservar_defaults.Add(name, udefault);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,5 +29,5 @@ using System.Resources;
|
|||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
[assembly: AssemblyVersion("2.3.0.3035")]
|
||||
[assembly: AssemblyVersion("2.3.0.3036")]
|
||||
[assembly: NeutralResourcesLanguageAttribute("en")]
|
||||
|
|
Loading…
Reference in a new issue