mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2025-01-31 04:40:55 +00:00
Things: fixed an issue where inserting a new thing would not immediately apply ZScript user variables
This commit is contained in:
parent
5dc8d1eda0
commit
d46dc1413b
6 changed files with 79 additions and 4 deletions
|
@ -749,6 +749,21 @@ namespace CodeImp.DoomBuilder.Config
|
|||
t.Args[2] = (int)tti.Args[2].DefaultValue;
|
||||
t.Args[3] = (int)tti.Args[3].DefaultValue;
|
||||
t.Args[4] = (int)tti.Args[4].DefaultValue;
|
||||
|
||||
// Add user vars
|
||||
if (tti.Actor != null)
|
||||
{
|
||||
Dictionary<string, UniversalType> uservars = tti.Actor.GetAllUserVars();
|
||||
Dictionary<string, object> uservardefaults = tti.Actor.GetAllUserVarDefaults();
|
||||
|
||||
t.BeforeFieldsChange();
|
||||
|
||||
foreach (string fname in uservars.Keys)
|
||||
{
|
||||
if (uservardefaults.ContainsKey(fname))
|
||||
t.Fields[fname] = new UniValue(uservars[fname], uservardefaults[fname]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -779,6 +794,21 @@ namespace CodeImp.DoomBuilder.Config
|
|||
t.Args[2] = (int)tti.Args[2].DefaultValue;
|
||||
t.Args[3] = (int)tti.Args[3].DefaultValue;
|
||||
t.Args[4] = (int)tti.Args[4].DefaultValue;
|
||||
|
||||
// Add user vars
|
||||
if (tti.Actor != null)
|
||||
{
|
||||
Dictionary<string, UniversalType> uservars = tti.Actor.GetAllUserVars();
|
||||
Dictionary<string, object> uservardefaults = tti.Actor.GetAllUserVarDefaults();
|
||||
|
||||
t.BeforeFieldsChange();
|
||||
|
||||
foreach (string fname in uservars.Keys)
|
||||
{
|
||||
if (uservardefaults.ContainsKey(fname))
|
||||
t.Fields[fname] = new UniValue(uservars[fname], uservardefaults[fname]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -161,6 +161,13 @@ namespace CodeImp.DoomBuilder.Config
|
|||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
internal UniversalFieldInfo(string name, int type, object defaultvalue)
|
||||
{
|
||||
this.name = name.ToLowerInvariant();
|
||||
this.type = type;
|
||||
this.defaultvalue = defaultvalue;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Methods
|
||||
|
|
|
@ -1005,6 +1005,29 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
if (index >= 0)
|
||||
fieldslist.Rows.RemoveAt(index);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes all user vars that have their default values.
|
||||
/// </summary>
|
||||
public void RemoveUserVarsWithDefaultValue()
|
||||
{
|
||||
List<int> removeindices = new List<int>();
|
||||
|
||||
// Go through all rows and find the ones to remove. We can't remove them immediately since that would
|
||||
// change the collection while the loop is going through it.
|
||||
foreach (DataGridViewRow dgvr in fieldslist.Rows)
|
||||
{
|
||||
if(dgvr is FieldsEditorRow frow)
|
||||
{
|
||||
if (frow.RowType == FieldsEditorRowType.USERVAR && frow.Info != null && frow.TypeHandler.GetValue().Equals(frow.Info.Default))
|
||||
removeindices.Add(dgvr.Index);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove rows. Do it from behind since otherwise the indices would not match
|
||||
for (int i = removeindices.Count - 1; i >= 0; i--)
|
||||
fieldslist.Rows.RemoveAt(removeindices[i]);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
|
|
@ -132,6 +132,9 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
isdefined = false;
|
||||
//fieldtype.ApplyDefaultValue(); // [ZZ] don't do this. this is only done for int, and not a very good place to do it...
|
||||
|
||||
// We need to remember the default value of the user var
|
||||
fieldinfo = new UniversalFieldInfo(name, type, value);
|
||||
|
||||
// Setup property cell
|
||||
this.Cells[0].Value = name;
|
||||
this.Cells[0].ReadOnly = true;
|
||||
|
|
|
@ -815,6 +815,21 @@ namespace CodeImp.DoomBuilder.Windows
|
|||
t.UpdateConfiguration();
|
||||
}
|
||||
|
||||
// Remove user vars (that have their default value) that do not belong to any selected thing
|
||||
fieldslist.RemoveUserVarsWithDefaultValue();
|
||||
|
||||
// Set the user vars for the new thing
|
||||
Thing ft = things.First();
|
||||
ThingTypeInfo fti = General.Map.Data.GetThingInfoEx(ft.Type);
|
||||
if (fti != null && fti.Actor != null)
|
||||
{
|
||||
Dictionary<string, UniversalType> uservars = fti.Actor.GetAllUserVars();
|
||||
Dictionary<string, object> uservardefaults = fti.Actor.GetAllUserVarDefaults();
|
||||
|
||||
if (uservars.Count > 0)
|
||||
fieldslist.SetUserVars(uservars, uservardefaults, ft.Fields, true);
|
||||
}
|
||||
|
||||
UpdateFlagNames(); //mxd
|
||||
|
||||
General.Map.IsChanged = true;
|
||||
|
|
|
@ -1103,10 +1103,7 @@ namespace CodeImp.DoomBuilder.UDBScript.Wrapper
|
|||
if(t == null)
|
||||
throw BuilderPlug.Me.ScriptRunner.CreateRuntimeException("Failed to create new thing.");
|
||||
|
||||
General.Settings.ApplyCleanThingSettings(t);
|
||||
|
||||
if (type > 0)
|
||||
t.Type = type;
|
||||
General.Settings.ApplyCleanThingSettings(t, type);
|
||||
|
||||
if(v is Vector2D)
|
||||
t.Move((Vector2D)v);
|
||||
|
|
Loading…
Reference in a new issue