Skip to content

Commit

Permalink
[fixes]
Browse files Browse the repository at this point in the history
+ Exception when adding a linked ref when there aren't any existing linked refs to an object reference (fixes issue #6)
+ Potentially sending synced object changed events twice for object references when they change cells
+ Exception when importing an object reference depending on another form import
+ Some windows using FormClosing event instead of FormClosed for cleanup
+ BatchImport becoming unresponsive while performing imports (applying imports is now threaded)

[changes]
+ Generalized how windows (Windows Forms) are handled and accessed

[adds]
+ Debug string (Name) to ImportTarget for logging issues to a specific target
+ Initial code to handle rendering workshop build volumes/sandboxes/border markers/etc
  • Loading branch information
ForsakenShell committed Dec 19, 2019
1 parent 40c2aa5 commit 597da97
Show file tree
Hide file tree
Showing 45 changed files with 726 additions and 490 deletions.
2 changes: 1 addition & 1 deletion AnnexTheCommonwealth/BorderEnabler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public void BuildSegmentsFromSubDivisionEdgeFlags( float approximateNodeLength,
{
DebugLog.OpenIndentLevel( new [] { this.GetType().ToString(), "BuildSegmentsFromSubDivisionEdgeFlags()", this.GetEditorID( Engine.Plugin.TargetHandle.WorkingOrLastFullRequired ), "approximateNodeLength = " + approximateNodeLength, "slopeAllowance = " + slopeAllowance, "updateMapUIData = " + updateMapUIData, this.ToString() } );

var m = GodObject.Windows.GetMainWindow();
var m = GodObject.Windows.GetWindow<GUIBuilder.Windows.Main>();
m.PushStatusMessage();
m.StartSyncTimer();
var tStart = m.SyncTimerElapsed();
Expand Down
2 changes: 1 addition & 1 deletion AnnexTheCommonwealth/SubDivision.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ public void BuildSegmentsFromEdgeFlags( float approximateNodeLength, float slope
{
DebugLog.OpenIndentLevel( new [] { this.GetType().ToString(), "BuildSegmentsFromEdgeFlags()", this.GetEditorID( Engine.Plugin.TargetHandle.WorkingOrLastFullRequired ) } );

var m = GodObject.Windows.GetMainWindow();
var m = GodObject.Windows.GetWindow<GUIBuilder.Windows.Main>();
m.PushStatusMessage();
m.StartSyncTimer();
var tStart = m.SyncTimerElapsed();
Expand Down
8 changes: 4 additions & 4 deletions Engine/Plugin/Collection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ IXHandle CreateNewChildForm()
}

// Add the form to the container
var resObject = AddFromRecord( wf, resHandle );
var resObject = AddFromRecord( pForm, resHandle );
if( resObject == null )
{
DebugLog.WriteError( this.GetType().ToString(), "CreateNewChildForm()", string.Format( "Unable to add new child \"{0}\" Form to parent \"{1}\" Form in {4} :: 0x{2} - \"{3}\"", _Association.Signature, pForm.Signature, pForm.GetFormID( Engine.Plugin.TargetHandle.Master ).ToString( "X8" ), pForm.GetEditorID( Engine.Plugin.TargetHandle.LastValid ), wf.Filename ) );
Expand Down Expand Up @@ -866,7 +866,7 @@ public List<TSync> ToList<TSync>( int loadOrderFilter = -1, bool tr

protected bool LoadFromEx( Interface.IXHandle source, ElementHandle handle )
{
var m = GodObject.Windows.GetMainWindow();
var m = GodObject.Windows.GetWindow<GUIBuilder.Windows.Main>();
m.PushItemOfItems();
m.StartSyncTimer();
var tStart = m.SyncTimerElapsed();
Expand Down Expand Up @@ -984,7 +984,7 @@ public bool LoadAllForms()

//DebugLog.OpenIndentLevel( new [] { "LoadAllForms()", string.Format( "ParentForm :: {0}", ( ParentForm == null ? "plugins" : ParentForm.ToString() ) ) } );

var m = GodObject.Windows.GetMainWindow();
var m = GodObject.Windows.GetWindow<GUIBuilder.Windows.Main>();
m.PushStatusMessage();
m.SetCurrentStatusMessage( string.Format( "Plugin.LoadingSigFormsFromAncestor".Translate(), _Association.Signature, ( ParentForm == null ? "Plugin.PluginFiles".Translate() : ParentForm.ExtraInfoFor() ) ) );
m.StartSyncTimer();
Expand Down Expand Up @@ -1045,7 +1045,7 @@ public bool PostLoad()
if( !_FullLoadComplete ) return false;
if( _FullPostLoadComplete ) return true;

var m = GodObject.Windows.GetMainWindow();
var m = GodObject.Windows.GetWindow<GUIBuilder.Windows.Main>();
m.PushStatusMessage();
m.PushItemOfItems();
m.SetCurrentStatusMessage( string.Format( "Plugin.PostLoadReferenceOfSig".Translate(), _Association.Signature ) );
Expand Down
2 changes: 1 addition & 1 deletion Engine/Plugin/Collections/Cells.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected override void Dispose( bool disposing )
public Plugin.Forms.Cell GetByGrid( Vector2i coords )
{
//DebugLog.OpenIndentLevel( new [] { this.GetType().ToString(), "GetByGrid()", "coords = " + coords.ToString(), "Worldspace = " + Worldspace.ToStringNullSafe() } );
var m = GodObject.Windows.GetMainWindow();
var m = GodObject.Windows.GetWindow<GUIBuilder.Windows.Main>();
//m.PushStatusMessage();
//m.StartSyncTimer();
//var tStart = m.SyncTimerElapsed();
Expand Down
5 changes: 4 additions & 1 deletion Engine/Plugin/Form.cs
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,9 @@ public ICollection CollectionFor( ClassAssociation association )
public virtual string ExtraInfo { get { return Signature; } }

bool _SupressObjectDataChangedEvent = false;

public bool ObjectDataChangedEventsSupressed { get { return _SupressObjectDataChangedEvent; } }

public void SupressObjectDataChangedEvents() { _SupressObjectDataChangedEvent = true; }

public void ResumeObjectDataChangedEvents( bool sendevent )
Expand Down Expand Up @@ -819,7 +822,7 @@ public List<Form> References
{
get
{
var m = GodObject.Windows.GetMainWindow();
var m = GodObject.Windows.GetWindow<GUIBuilder.Windows.Main>();
m.PushStatusMessage();
m.PushItemOfItems();
m.SetCurrentStatusMessage( string.Format( "Plugin.LoadingReferencesOf".Translate(), GetFormID( Engine.Plugin.TargetHandle.Master ).ToString( "X8" ), GetEditorID( Engine.Plugin.TargetHandle.WorkingOrLastFullRequired ) ) );
Expand Down
2 changes: 2 additions & 0 deletions Engine/Plugin/Forms/Fields/ObjectReference/LinkedRefs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ public bool Add( TargetHandle target, uint refID, uint keywo
int AddEx( uint refID, uint keywordFormID )
{
// New element in form
if( _LinkedReferences == null )
_LinkedReferences = new List<ElementHandle>();
var index = _LinkedReferences.Count;
var lrh = Form.WorkingFileHandle.AddArrayItem<ElementHandle>( XPath, "", "" );
if( !lrh.IsValid() )
Expand Down
3 changes: 3 additions & 0 deletions Engine/Plugin/Forms/ObjectReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ bool UpdateContainerCellHandle( Cell cell )

public void CheckForBackgroundCellChange( bool sendObjectDataChangedEvent )
{
if( ObjectDataChangedEventsSupressed )
return;

DebugLog.OpenIndentLevel( new [] { this.GetType().ToString(), "CheckForBackgroundCellChange()", this.ToStringNullSafe() } );

// Changing position and some record flags will trigger XeLib to update the cell container,
Expand Down
4 changes: 3 additions & 1 deletion Engine/Plugin/Interface/ISyncedGUIObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public interface ISyncedGUIObject
string ExtraInfo { get; }

event EventHandler ObjectDataChanged;


bool ObjectDataChangedEventsSupressed { get; }

void SupressObjectDataChangedEvents();
void ResumeObjectDataChangedEvents( bool sendevent );
void SendObjectDataChangedEvent( object sender );
Expand Down
3 changes: 3 additions & 0 deletions Engine/Plugin/PapyrusScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,9 @@ public virtual bool ObjectChecked( bool checkedValue )
public event EventHandler ObjectDataChanged;

bool _SupressObjectDataChangedEvent = false;

public bool ObjectDataChangedEventsSupressed { get { return _SupressObjectDataChangedEvent; } }

public void SupressObjectDataChangedEvents()
{
_SupressObjectDataChangedEvent = true;
Expand Down
1 change: 1 addition & 0 deletions GUIBuilder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
<Compile Include="Extensions\GenRenderTransform.cs" />
<Compile Include="Extensions\GenStream.cs" />
<Compile Include="Extensions\GenString.cs" />
<Compile Include="GUIBuilder\Windows\IEnableControlForm.cs" />
<Compile Include="GUIBuilder\Windows\PluginSelector.cs">
<SubType>Form</SubType>
</Compile>
Expand Down
6 changes: 3 additions & 3 deletions GUIBuilder/BorderBatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static bool ImportNIFs( string guiBuilderImportFile, bool enableControlsO

var result = false;

var m = GodObject.Windows.GetMainWindow();
var m = GodObject.Windows.GetWindow<GUIBuilder.Windows.Main>();
m.PushStatusMessage();
var tStart = m.SyncTimerElapsed();

Expand Down Expand Up @@ -131,7 +131,7 @@ public static bool ImportNIFs( string guiBuilderImportFile, bool enableControlsO

//DebugLog.Write( "GUIBuilder.BorderBatch.CreateNIFs() :: Start (Workshop)" );

var m = GodObject.Windows.GetMainWindow();
var m = GodObject.Windows.GetWindow<GUIBuilder.Windows.Main>();
m.PushStatusMessage();
m.StartSyncTimer();
var tStart = m.SyncTimerElapsed();
Expand Down Expand Up @@ -191,7 +191,7 @@ public static bool ImportNIFs( string guiBuilderImportFile, bool enableControlsO

//DebugLog.Write( "\nGUIBuilder.BorderBatch.CreateNIFs() :: Start (Sub-Division)" );

var m = GodObject.Windows.GetMainWindow();
var m = GodObject.Windows.GetWindow<GUIBuilder.Windows.Main>();
m.PushStatusMessage();
m.StartSyncTimer();
var tStart = m.SyncTimerElapsed();
Expand Down
6 changes: 3 additions & 3 deletions GUIBuilder/FormImport/FormTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public Engine.Plugin.Form Form
set { Value = value; }
}

public FormTarget( ImportBase parent, Type formType, uint formID, string editorID ) : base( parent, formType, formID, editorID ) {}
public FormTarget( ImportBase parent, Type formType, Engine.Plugin.Form form ) : base( parent, formType, form ) {}
public FormTarget( ImportBase parent, Type formType ) : base( parent, formType ) {}
public FormTarget( string name, ImportBase parent, Type formType, uint formID, string editorID ) : base( name, parent, formType, formID, editorID ) {}
public FormTarget( string name, ImportBase parent, Type formType, Engine.Plugin.Form form ) : base( name, parent, formType, form ) {}
public FormTarget( string name, ImportBase parent, Type formType ) : base( name, parent, formType ) {}
//public FormTarget( ImportBase parent ) : base( parent ) {}

protected override void ResolveValue()
Expand Down
50 changes: 35 additions & 15 deletions GUIBuilder/FormImport/ImportBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ protected ImportBase( string signature, uint recordFlags,
_RecordFlags = recordFlags;
_FailOnApplyIfUnresolved = failOnApplyIfUnresolved;
_Target = classType == typeof( Engine.Plugin.Forms.ObjectReference )
? new ObjectReferenceTarget( this, targetForm, null, null )
: new FormTarget( this, classType, targetForm );
? new ObjectReferenceTarget( "Target Ref", this, targetForm, null, null )
: new FormTarget( "Target Form", this, classType, targetForm );
resolved = _Target.Resolve( failOnApplyIfUnresolved );
if( ( failOnApplyIfUnresolved )&( !resolved ) )
throw new Exception( string.Format(
Expand Down Expand Up @@ -130,7 +130,7 @@ protected ImportBase( string signature, uint recordFlags,
_Signature = signature;
_RecordFlags = recordFlags;
_FailOnApplyIfUnresolved = failOnApplyIfUnresolved;
_Target = new ScriptTarget( this, classType, targetScript );
_Target = new ScriptTarget( "Target Ref Script", this, classType, targetScript );
resolved = _Target.Resolve( failOnApplyIfUnresolved );
if( ( failOnApplyIfUnresolved )&( !resolved ) )
throw new Exception( string.Format(
Expand Down Expand Up @@ -176,8 +176,8 @@ protected ImportBase( string signature, uint recordFlags,
_RecordFlags = recordFlags;
_FailOnApplyIfUnresolved = failOnApplyIfUnresolved;
_Target = classType == typeof( Engine.Plugin.Forms.ObjectReference )
? new ObjectReferenceTarget( this, targetForm, worldspace, cell )
: new FormTarget( this, classType, targetForm );
? new ObjectReferenceTarget( "Target Ref", this, targetForm, worldspace, cell )
: new FormTarget( "Target Form", this, classType, targetForm );
resolved = _Target.Resolve( failOnApplyIfUnresolved );
if( ( failOnApplyIfUnresolved )&( !resolved ) )
throw new Exception( string.Format(
Expand Down Expand Up @@ -212,8 +212,8 @@ protected ImportBase( string signature, uint recordFlags,
_RecordFlags = recordFlags;
_FailOnApplyIfUnresolved = failOnApplyIfUnresolved;
_Target = classType == typeof( Engine.Plugin.Forms.ObjectReference )
? new ObjectReferenceTarget( this )
: new FormTarget( this, classType );
? new ObjectReferenceTarget( "Target Ref", this )
: new FormTarget( "Target Form", this, classType );
//_Target = new FormTarget( this, classType );
resolved = ParseImport( importData );
if( ( failOnApplyIfUnresolved )&( !resolved ) )
Expand Down Expand Up @@ -648,6 +648,8 @@ public string ExtraInfo
public event EventHandler ObjectDataChanged;
bool _SupressEvents = false;

public bool ObjectDataChangedEventsSupressed { get { return _SupressEvents; } }

public void SupressObjectDataChangedEvents()
{
_SupressEvents = true;
Expand Down Expand Up @@ -741,6 +743,7 @@ public bool Apply( GUIBuilder.Windows.BatchImport importWind
AddErrorMessage( ErrorTypes.Import, "Import in error state, cannot Apply()" );
goto localAbort;
}
/*
if(
( _FailOnApplyIfUnresolved )&
( !Resolve( _FailOnApplyIfUnresolved ) )
Expand All @@ -749,6 +752,15 @@ public bool Apply( GUIBuilder.Windows.BatchImport importWind
AddErrorMessage( ErrorTypes.Import, "Resolve() errors, cannot Apply()" );
goto localAbort;
}
*/
// Target may not resolve if this is a new form
_Target.Resolve( false );
// All reference forms must resolve, however
if( !ResolveReferenceForms( true ) )
{
AddErrorMessage( ErrorTypes.Import, "Resolve() errors, cannot Apply()" );
goto localAbort;
}

if( TargetForm == null )
{
Expand Down Expand Up @@ -787,16 +799,17 @@ public bool Apply( GUIBuilder.Windows.BatchImport importWind
{
AddErrorMessage( ErrorTypes.Import, "An unexpected exception has occured applying import!", e );
}

ResumeObjectDataChangedEvents( true );

if( result )
{
var refr = TargetForm as Engine.Plugin.Forms.ObjectReference;
if( refr != null ) refr.CheckForBackgroundCellChange( false );
if( refr != null ) refr.CheckForBackgroundCellChange( true );
}
else
DebugLog.WriteError( this.GetType().ToString(), "Apply()", "Unable to apply import to the target form!" );

ResumeObjectDataChangedEvents( true );

localAbort:
DebugLog.CloseIndentLevel( "result", result.ToString() );
return result;
Expand Down Expand Up @@ -871,15 +884,23 @@ public override string ToString()
return string.Format( "[Signature = \"{0}\" :: Target = {1}]", Signature, DisplayIDInfo() );
}

/// <summary>
/// Open the import dialog and wait for it to exit.
/// DO NOT CALL THIS FROM THE MAIN UI THREAD!
/// </summary>
/// <param name="importForms">Forms to import</param>
/// <param name="enableControlsOnClose">Enable all forms when the dialog closes</param>
/// <param name="allImportsMatchTarget">All import targets match import data on close</param>
/// <returns></returns>
public static bool ShowImportDialog( List<ImportBase> importForms, bool enableControlsOnClose, ref bool allImportsMatchTarget )
{
if( importForms.NullOrEmpty() ) return false;

DebugLog.OpenIndentLevel( new [] { "GUIBuilder.FormImport.ImportBase", "ShowImportDialog()" } );
if( System.Threading.Thread.CurrentThread.ManagedThreadId == 1 )
throw new Exception( "Cannot show BatchImportWindow from main thread!" );

#region Import window
var bbiw = new GUIBuilder.Windows.BatchImport();

var bbiw = GodObject.Windows.GetWindow<GUIBuilder.Windows.BatchImport>();
bbiw.EnableControlsOnClose = enableControlsOnClose;
bbiw.ImportForms = importForms;
bbiw.ShowDialog();
Expand All @@ -888,7 +909,6 @@ public static bool ShowImportDialog( List<ImportBase> importForms,

#endregion

DebugLog.CloseIndentLevel();
return true;
}

Expand Down
16 changes: 8 additions & 8 deletions GUIBuilder/FormImport/ImportBorderEnablerReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,22 @@ public ImportBorderEnablerReference( AnnexTheCommonweal
if( !Target.IsResolved )
Target.EditorID = newEditorID;
NewEditorID = newEditorID;
ftWorldspace = new FormTarget( this, typeof( Engine.Plugin.Forms.Worldspace ), worldspace );
ftCell = new FormTarget( this, typeof( Engine.Plugin.Forms.Cell ), cell );
ftWorldspace = new FormTarget( "Worldspace", this, typeof( Engine.Plugin.Forms.Worldspace ), worldspace );
ftCell = new FormTarget( "Cell", this, typeof( Engine.Plugin.Forms.Cell ), cell );
Position = new Vector3f( position );
stSubDivision = new ScriptTarget( this, typeof( AnnexTheCommonwealth.SubDivision ), subdivision );
stNeighbour = new ScriptTarget( this, typeof( AnnexTheCommonwealth.SubDivision ), neighbour );
stSubDivision = new ScriptTarget( "SubDivision", this, typeof( AnnexTheCommonwealth.SubDivision ), subdivision );
stNeighbour = new ScriptTarget( "Neighbour", this, typeof( AnnexTheCommonwealth.SubDivision ), neighbour );

DumpImport();
}

public ImportBorderEnablerReference( string[] importData )
: base( IMPORT_SIGNATURE, TARGET_RECORD_FLAGS, false, typeof( AnnexTheCommonwealth.BorderEnabler ), importData )
{
ftWorldspace = new FormTarget( this, typeof( Engine.Plugin.Forms.Worldspace ) );
ftCell = new FormTarget( this, typeof( Engine.Plugin.Forms.Cell ) );
stSubDivision = new ScriptTarget( this, typeof( AnnexTheCommonwealth.SubDivision ) );
stNeighbour = new ScriptTarget( this, typeof( AnnexTheCommonwealth.SubDivision ) );
ftWorldspace = new FormTarget( "Worldspace", this, typeof( Engine.Plugin.Forms.Worldspace ) );
ftCell = new FormTarget( "Cell", this, typeof( Engine.Plugin.Forms.Cell ) );
stSubDivision = new ScriptTarget( "SubDivision", this, typeof( AnnexTheCommonwealth.SubDivision ) );
stNeighbour = new ScriptTarget( "Neighbour", this, typeof( AnnexTheCommonwealth.SubDivision ) );
DumpImport();
}

Expand Down
Loading

0 comments on commit 597da97

Please sign in to comment.