public void Remove(IGameDocument doc) { if (doc == null) { return; } if (!m_documents.Contains(doc)) { return; } foreach (IReference <IGameDocument> gameDocRef in doc.GameDocumentReferences) { Remove(gameDocRef.Target); } m_documents.Remove(doc); doc.DirtyChanged -= OnDocumentDirtyChanged; doc.UriChanged -= OnDocumentUriChanged; doc.EditableResourceOwnerDirtyChanged -= OnResourceDirtyChanged; UpdateAnyDocDirty(); UpdateAnyResourceDirty(); DocumentRemoved(this, new ItemRemovedEventArgs <IGameDocument>(0, doc)); }
private void OnDocumentUriChanged(object sender, UriChangedEventArgs e) { UpdateAnyResourceDirty(); IGameDocument doc = (IGameDocument)sender; DocumentUriChanged(this, new ItemChangedEventArgs <IGameDocument>(doc)); }
private void m_gameDocumentRegistry_DocumentRemoved(object sender, ItemRemovedEventArgs <IGameDocument> e) { IGameDocument document = e.Item; document.DirtyChanged -= m_document_DirtyChanged; document.UriChanged -= m_document_UriChanged; IGame game = document.Cast <IGame>(); if (document == m_designView.Context.Cast <IGameDocument>()) {// master document. IGrid grid = document.As <IGame>().Grid; GridRenderer gridRender = grid.Cast <GridRenderer>(); gridRender.DeleteVertexBuffer(); m_designView.Context = null; GameEngine.DestroyObject(game.Cast <NativeObjectAdapter>()); GameEngine.Clear(); } else {// sub document. DomNode masterNode = m_gameDocumentRegistry.MasterDocument.As <DomNode>(); DomNode rooFolderNode = game.RootGameObjectFolder.Cast <DomNode>(); NativeGameWorldAdapter gworld = masterNode.Cast <NativeGameWorldAdapter>(); gworld.Remove(masterNode, rooFolderNode, masterNode.Type.GetChildInfo("gameObjectFolder")); } }
private void UpdateControlInfo(IGameDocument document) { string name; string description; if (document != null) { string filePath = document.Uri.LocalPath; string fileName = Path.GetFileNameWithoutExtension(filePath); if (AnyDocDirty) { fileName += "*"; } name = fileName; description = filePath; } else { name = "DesignView"; description = "Design View"; } m_controlInfo.Name = name; m_controlInfo.Description = description; }
private void m_gameDocumentRegistry_DocumentAdded(object sender, ItemInsertedEventArgs <IGameDocument> e) { IGameDocument document = e.Item; IGame game = document.Cast <IGame>(); if (document == m_gameDocumentRegistry.MasterDocument) { NativeObjectAdapter gameLevel = document.Cast <NativeObjectAdapter>(); GameEngine.CreateObject(gameLevel); GameEngine.SetGameLevel(gameLevel); gameLevel.UpdateNativeOjbect(); //create vertex buffer for grid. IGrid grid = document.As <IGame>().Grid; GridRenderer gridRender = grid.Cast <GridRenderer>(); gridRender.CreateVertices(); m_designView.Context = document.Cast <IGameContext>(); } DomNode masterNode = m_gameDocumentRegistry.MasterDocument.As <DomNode>(); DomNode rooFolderNode = game.RootGameObjectFolder.Cast <DomNode>(); NativeGameWorldAdapter gworld = masterNode.Cast <NativeGameWorldAdapter>(); gworld.Insert(masterNode, rooFolderNode, masterNode.Type.GetChildInfo("gameObjectFolder"), -1); }
public void Clear() { for (int i = m_documents.Count - 1; i >= 0; i--) { IGameDocument doc = m_documents[i]; m_documents.RemoveAt(i); DocumentRemoved(this, new ItemRemovedEventArgs <IGameDocument>(i, doc)); } }
public void Add(IGameDocument doc) { if (doc == null) throw new ArgumentNullException("doc"); if(!m_documents.Contains(doc)) { m_documents.Add(doc); DocumentAdded(this, new ItemInsertedEventArgs<IGameDocument>(m_documents.Count - 1, doc)); } }
public void Add(IGameDocument doc) { if (doc == null) { throw new ArgumentNullException("doc"); } if (!m_documents.Contains(doc)) { m_documents.Add(doc); DocumentAdded(this, new ItemInsertedEventArgs <IGameDocument>(m_documents.Count - 1, doc)); } }
public void Remove(IGameDocument doc) { if (doc == null) return; if (!m_documents.Contains(doc)) return; foreach (IReference<IGameDocument> gameDocRef in doc.GameDocumentReferences) { Remove(gameDocRef.Target); } m_documents.Remove(doc); DocumentRemoved(this, new ItemRemovedEventArgs<IGameDocument>(0, doc)); }
public void Add(IGameDocument doc) { if (doc == null) { throw new ArgumentNullException("doc"); } if (!m_documents.Contains(doc)) { m_documents.Add(doc); doc.DirtyChanged += OnDocumentDirtyChanged; doc.UriChanged += OnDocumentUriChanged; doc.EditableResourceOwnerDirtyChanged += OnResourceDirtyChanged; UpdateAnyDocDirty(); UpdateAnyResourceDirty(); DocumentAdded(this, new ItemInsertedEventArgs <IGameDocument>(m_documents.Count - 1, doc)); } }
private void m_gameDocumentRegistry_DocumentAdded(object sender, ItemInsertedEventArgs <IGameDocument> e) { IGameDocument document = e.Item; if (document == m_gameDocumentRegistry.MasterDocument) { IGame game = document.As <IGame>(); if (game != null && game.Grid != null) { game.Grid.Cast <GridRenderer>().CreateVertices(); } var context = document.As <IGameContext>(); if (context != null) { m_designView.Context = context; } } }
public void Remove(IGameDocument doc) { if (doc == null) { return; } if (!m_documents.Contains(doc)) { return; } foreach (IReference <IGameDocument> gameDocRef in doc.GameDocumentReferences) { Remove(gameDocRef.Target); } m_documents.Remove(doc); DocumentRemoved(this, new ItemRemovedEventArgs <IGameDocument>(0, doc)); }
public void Remove(IGameDocument doc) { if (doc == null) { return; } if (!m_documents.Contains(doc)) { return; } var docRefs = doc.GameDocumentReferences; if (docRefs != null) { foreach (IReference <IGameDocument> gameDocRef in docRefs) { Remove(gameDocRef.Target); } } { var gameDoc = doc as DomDocument; if (gameDoc != null) { LevelEditorXLE.Patches.Unresolve(gameDoc); } } m_documents.Remove(doc); doc.DirtyChanged -= OnDocumentDirtyChanged; doc.UriChanged -= OnDocumentUriChanged; doc.EditableResourceOwnerDirtyChanged -= OnResourceDirtyChanged; UpdateAnyDocDirty(); UpdateAnyResourceDirty(); DocumentRemoved(this, new ItemRemovedEventArgs <IGameDocument>(0, doc)); }
private void Resolve() { if (m_target != null) { return; } Uri ur = GetAttribute <Uri>(Schema.gameObjectReferenceType.refAttribute); // find game document Uri docUri = new Uri(ur.GetLeftPart(UriPartial.Path)); var gameDocRegistry = Globals.MEFContainer.GetExportedValue <GameDocumentRegistry>(); IGameDocument gamedoc = gameDocRegistry.FindDocument(docUri); if (gamedoc == null) { return; } string nodeId = ur.Fragment.TrimStart('#'); DomNode target = gamedoc.Cast <IdToDomNode>().FindById(nodeId); SetTarget(target); }
private void m_gameDocumentRegistry_DocumentRemoved(object sender, ItemRemovedEventArgs <IGameDocument> e) { IGameDocument document = e.Item; IGame game = e.Item.As <IGame>(); if (game != null && game.Grid != null) { game.Grid.Cast <GridRenderer>().DeleteVertexBuffer(); } var context = document.As <IGameContext>(); if (context == m_designView.Context) { m_designView.Context = null; } var nativeAdapter = document.As <NativeDocumentAdapter>(); if (nativeAdapter != null) { nativeAdapter.OnDocumentRemoved(); } }
public IDocument Open(Uri uri) { IGameDocument activeDoc = m_documentRegistry.GetActiveDocument <IGameDocument>(); if (activeDoc != null) { if (!m_documentService.Close(activeDoc)) { return(null); } } List <IResource> resources = new List <IResource>(m_resourceService.Resources); foreach (var res in resources) { m_resourceService.Unload(res.Uri); } GameDocument document = GameDocument.OpenOrCreate(uri, m_schemaLoader); m_contextRegistry.ActiveContext = document.As <GameContext>(); return(document); }
private void UpdateControlInfo(IGameDocument document) { string name; string description; if (document != null) { string filePath = document.Uri.LocalPath; string fileName = Path.GetFileNameWithoutExtension(filePath); if (AnyDocDirty) fileName += "*"; name = fileName; description = filePath; } else { name = "DesignView"; description = "Design View"; } m_controlInfo.Name = name; m_controlInfo.Description = description; }
public bool Contains(IGameDocument doc) { return m_documents.Contains(doc); }
public bool Contains(IGameDocument doc) { return(m_documents.Contains(doc)); }
void ICommandClient.DoCommand(object commandTag) { var target = TreeControlAdapter.LastHit; // If the command isn't one of our immediate commands, it // might belong to one of our sub providers. // Try to cast the targetted node to a command client and // execute from there if (!(commandTag is Command)) { var targetClient = target.As <ICommandClient>(); if (targetClient != null) { targetClient.DoCommand(commandTag); } return; } IDocument gameDocument = null; string filePath = null; IGame game = target.As <IGame>(); if (game == null) { GameReference gameRef = target.As <GameReference>(); if (gameRef != null) { game = gameRef.Target; } } if (game != null) { gameDocument = game.As <IDocument>(); } switch ((Command)commandTag) { case Command.CreateNewSubGame: if (gameDocument != null) { filePath = Util.GetFilePath(m_fileFilter, System.IO.Path.GetDirectoryName(gameDocument.Uri.LocalPath), true); if (!string.IsNullOrEmpty(filePath)) { try { if (!m_gameEditor.Info.IsCompatiblePath(filePath)) { throw new Exception("Incompatible file type " + filePath); } Uri ur = new Uri(filePath); if (m_gameDocumentRegistry.FindDocument(ur) != null) { throw new Exception(filePath + " is already open"); } GameDocument subGame = GameDocument.OpenOrCreate(ur, m_schemaLoader); subGame.Dirty = true; GameReference gameRef = GameReference.CreateNew(subGame); // try all implementation of IHierarchical until one works var parent = game.AsAll <IHierarchical>(); foreach (var p in parent) { if (p.AddChild(gameRef)) { break; } } // because we performing this operation outside of TransactionContext // we must set Document Dirty flag. gameDocument.Dirty = true; } catch (Exception ex) { MessageBox.Show(m_mainWindow.DialogOwner, ex.Message); } } } break; case Command.AddSubGame: if (gameDocument != null) { filePath = Util.GetFilePath(m_fileFilter, System.IO.Path.GetDirectoryName(gameDocument.Uri.LocalPath), false); if (!string.IsNullOrEmpty(filePath)) { try { if (!m_gameEditor.Info.IsCompatiblePath(filePath)) { throw new Exception("Incompatible file type " + filePath); } Uri ur = new Uri(filePath); if (m_gameDocumentRegistry.FindDocument(ur) != null) { throw new Exception(filePath + " is already open"); } GameReference gameRef = GameReference.CreateNew(ur); gameRef.Resolve(); // try all implementation of IHierarchical until one works var parent = game.AsAll <IHierarchical>(); foreach (var p in parent) { if (p.AddChild(gameRef)) { break; } } // because we performing this operation outside of TransactionContext // we must set Document Dirty flag. gameDocument.Dirty = true; RefreshLayerContext(); } catch (Exception ex) { MessageBox.Show(m_mainWindow.DialogOwner, ex.Message); } } } break; case Command.Exclude: { GameReference gameRef = target.As <GameReference>(); if (gameRef == null) { break; } gameDocument = gameRef.DomNode.Parent.Cast <IDocument>(); IGameDocument subDoc = gameRef.Target.Cast <IGameDocument>(); bool exclue = true; bool save = false; if (subDoc.Dirty) { string msg = "Save changes\r\n" + subDoc.Uri.LocalPath; DialogResult dlgResult = MessageBox.Show(m_mainWindow.DialogOwner, msg, m_mainWindow.Text , MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); save = dlgResult == DialogResult.Yes; exclue = dlgResult != DialogResult.Cancel; } if (save) { subDoc.Save(subDoc.Uri, m_schemaLoader); } if (exclue) { gameRef.DomNode.RemoveFromParent(); // because we performing this operation outside of TransactionContext // we must set Document Dirty flag. gameDocument.Dirty = true; UpdateGameObjectReferences(); RefreshLayerContext(); } } break; case Command.Resolve: { bool madeChange = false; GameReference gameRef = target.As <GameReference>(); if (gameRef != null) { gameRef.Resolve(); madeChange = true; } else { var resolveable = target.As <IResolveable>(); if (resolveable != null && !resolveable.IsResolved()) { resolveable.Resolve(); madeChange = true; } } if (madeChange) { TreeControlAdapter.Refresh(target); RefreshLayerContext(); } } break; case Command.Unresolve: { try { GameReference gameRef = target.As <GameReference>(); if (gameRef != null) { IGameDocument subDoc = gameRef.Target.Cast <IGameDocument>(); bool unresolve = true; bool save = false; if (subDoc.Dirty) { string msg = "Save changes\r\n" + subDoc.Uri.LocalPath; DialogResult dlgResult = MessageBox.Show(m_mainWindow.DialogOwner, msg, m_mainWindow.Text , MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); save = dlgResult == DialogResult.Yes; unresolve = dlgResult != DialogResult.Cancel; } //cando = gameRef != null && gameRef.Target != null; if (save) { subDoc.Save(subDoc.Uri, m_schemaLoader); } if (unresolve) { gameRef.Unresolve(); UpdateGameObjectReferences(); RefreshLayerContext(); } TreeControlAdapter.Refresh(gameRef); } else { var resolveable = target.As <IResolveable>(); if (resolveable != null && resolveable.IsResolved()) { resolveable.Unresolve(); RefreshLayerContext(); TreeControlAdapter.Refresh(target); } } } catch (Exception ex) { MessageBox.Show(m_mainWindow.DialogOwner, ex.Message); } } break; case Command.CreateNewResolveable: { try { var resolveable = target.As <IResolveable>(); if (resolveable != null && !resolveable.IsResolved() && resolveable.CanCreateNew()) { resolveable.CreateAndResolve(); RefreshLayerContext(); TreeControlAdapter.Refresh(target); } } catch (Exception ex) { MessageBox.Show(m_mainWindow.DialogOwner, ex.Message); } } break; case Command.SaveSubDoc: { try { var resolveable = target.As <IResolveable>(); if (resolveable != null && resolveable.CanSave()) { resolveable.Save(m_schemaLoader); } } catch (Exception ex) { MessageBox.Show(m_mainWindow.DialogOwner, ex.Message); } } break; default: throw new ArgumentOutOfRangeException("commandTag"); } m_designView.InvalidateViews(); Refresh(); }
bool IReference <IGameDocument> .CanReference(IGameDocument item) { return(false); }