From 42e6fef109cde4e48729ee9a7614321a5ffc7c44 Mon Sep 17 00:00:00 2001 From: Scionwest_cp Date: Mon, 18 Jan 2010 20:46:43 -0800 Subject: [PATCH] Major Changes: - Rooms are now saved within the selected Zone. - Fixed Project Explorer not displaying project directory structure on Designer startup. Engine: - Re-wrote Zone.GetRoom() to use the more efficient LINQ query. - Zone.RefreshRoomList now saves itself after re-building the Room collection - UIRoomControl now has a public Rooms collection for use by the UIRoomEditor - UIRoomEditor now returns the modified UIRoomControl.Rooms collection to the Designers properties pane instead of an empty collection. Designer: - Project Explorer now displays project directory structure on load. This was broken during Designers Constructor re-write. - Added additional comments to increase readability of source. --- Mud Designer/..svnbridge/.svnbridge | 3 ++ Mud Designer/Designer.Designer.cs | 42 ++++++++++++++++++- Mud Designer/Designer.cs | 15 ++++++- .../MudEngine/GameObjects/Environment/Room.cs | 2 +- .../MudEngine/GameObjects/Environment/Zone.cs | 30 ++++++++++--- .../MudEngine/UITypeEditors/UIRoomControl.cs | 3 ++ .../MudEngine/UITypeEditors/UIRoomEditor.cs | 2 +- 7 files changed, 86 insertions(+), 11 deletions(-) create mode 100644 Mud Designer/..svnbridge/.svnbridge diff --git a/Mud Designer/..svnbridge/.svnbridge b/Mud Designer/..svnbridge/.svnbridge new file mode 100644 index 0000000..bdf168c --- /dev/null +++ b/Mud Designer/..svnbridge/.svnbridge @@ -0,0 +1,3 @@ +svn:ignorebin +obj + \ No newline at end of file diff --git a/Mud Designer/Designer.Designer.cs b/Mud Designer/Designer.Designer.cs index 0b2e4ea..b0836db 100644 --- a/Mud Designer/Designer.Designer.cs +++ b/Mud Designer/Designer.Designer.cs @@ -86,6 +86,10 @@ this.propertyObject = new System.Windows.Forms.PropertyGrid(); this.lblObjectProperties = new System.Windows.Forms.Label(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); + this.addObjectToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.environmentToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.mnuNewRealmShortcut = new System.Windows.Forms.ToolStripMenuItem(); + this.mnuNewZoneShortcut = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip1.SuspendLayout(); this.containerMain.Panel2.SuspendLayout(); this.containerMain.SuspendLayout(); @@ -444,11 +448,12 @@ // contextMenuStrip1 // this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.addObjectToolStripMenuItem, this.mnuEditObject, this.toolStripMenuItem1, this.mnuDeleteSelectedObject}); this.contextMenuStrip1.Name = "contextMenuStrip1"; - this.contextMenuStrip1.Size = new System.Drawing.Size(153, 76); + this.contextMenuStrip1.Size = new System.Drawing.Size(153, 98); // // mnuEditObject // @@ -555,6 +560,37 @@ this.toolTip1.ShowAlways = true; this.toolTip1.ToolTipTitle = "Mud Designer Help"; // + // addObjectToolStripMenuItem + // + this.addObjectToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.environmentToolStripMenuItem}); + this.addObjectToolStripMenuItem.Name = "addObjectToolStripMenuItem"; + this.addObjectToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.addObjectToolStripMenuItem.Text = "Add Object"; + // + // environmentToolStripMenuItem + // + this.environmentToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.mnuNewRealmShortcut, + this.mnuNewZoneShortcut}); + this.environmentToolStripMenuItem.Name = "environmentToolStripMenuItem"; + this.environmentToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.environmentToolStripMenuItem.Text = "Environment"; + // + // mnuNewRealmShortcut + // + this.mnuNewRealmShortcut.Name = "mnuNewRealmShortcut"; + this.mnuNewRealmShortcut.Size = new System.Drawing.Size(152, 22); + this.mnuNewRealmShortcut.Text = "New Realm"; + this.mnuNewRealmShortcut.Click += new System.EventHandler(this.mnuNewRealm_Click); + // + // mnuNewZoneShortcut + // + this.mnuNewZoneShortcut.Name = "mnuNewZoneShortcut"; + this.mnuNewZoneShortcut.Size = new System.Drawing.Size(152, 22); + this.mnuNewZoneShortcut.Text = "New Zone"; + this.mnuNewZoneShortcut.Click += new System.EventHandler(this.mnuNewZone_Click); + // // Designer // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -641,6 +677,10 @@ private System.Windows.Forms.ToolStripSeparator toolStripMenuItem2; private System.Windows.Forms.PropertyGrid propertyObject; private System.Windows.Forms.ToolStripMenuItem mnuNewRoom; + private System.Windows.Forms.ToolStripMenuItem addObjectToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem environmentToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem mnuNewRealmShortcut; + private System.Windows.Forms.ToolStripMenuItem mnuNewZoneShortcut; diff --git a/Mud Designer/Designer.cs b/Mud Designer/Designer.cs index 6ed158b..4f4f2fc 100644 --- a/Mud Designer/Designer.cs +++ b/Mud Designer/Designer.cs @@ -63,6 +63,8 @@ namespace MudDesigner //ensure the path exists ValidatePath(projectPath); + + RefreshProjectExplorer(); } /// @@ -136,16 +138,20 @@ namespace MudDesigner //for root objects switch (objType) { + //A non-editable object was found case ObjectType.Nothing: return; + //Project Information file case ObjectType.Project: _Project = (ProjectInformation)_Project.Load(FileManager.GetDataPath(SaveDataTypes.Root)); break; + //Currency File case ObjectType.Currency: Currency currency = new Currency(); objectFilename = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Currencies), selectedNode.Text); propertyObject.SelectedObject = (Currency)currency.Load(objectFilename); break; + //Realm File selected case ObjectType.Realm: objectName = Path.GetFileNameWithoutExtension(selectedNode.Parent.Text); objectPath = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Realms), objectName); @@ -153,6 +159,7 @@ namespace MudDesigner _GameObject = new Realm(); propertyObject.SelectedObject = _GameObject.Load(objectFilename); break; + //Zone File located under Project/Zones case ObjectType.ZoneRoot: objectName = Path.GetFileNameWithoutExtension(selectedNode.Parent.Text); objectPath = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Zones), objectName); @@ -160,6 +167,7 @@ namespace MudDesigner _GameObject = new Zone(); propertyObject.SelectedObject = _GameObject.Load(objectFilename); break; + //Zone File located under Project/Realms/Zones case ObjectType.ZoneWithinRealm: TreeNode grandparent = selectedNode.Parent.Parent; objectName = Path.GetFileNameWithoutExtension(selectedNode.Parent.Text); @@ -179,8 +187,6 @@ namespace MudDesigner { if (!Directory.Exists(path)) Directory.CreateDirectory(path); - - string projectPath = Path.Combine(Application.StartupPath, "Project"); } /// @@ -189,15 +195,20 @@ namespace MudDesigner /// private bool CheckSavedState() { + //No need to continue if the save flag is already set if (IsSaved) return true; + //Inform the user DialogResult result = MessageBox.Show(lblObjectProperties.Text + " has not been saved! Do you wish to save it?", "Mud Designer", MessageBoxButtons.YesNoCancel); + //Don't save it. Return true so that it can be overwrote if (result == DialogResult.No) return true; + //User hit cancel, it's not saved so return false. else if (result == DialogResult.Cancel) return false; + //User hit Yes, so save the object else SaveSelected(); diff --git a/Mud Designer/MudEngine/GameObjects/Environment/Room.cs b/Mud Designer/MudEngine/GameObjects/Environment/Room.cs index ec4920a..ca03f22 100644 --- a/Mud Designer/MudEngine/GameObjects/Environment/Room.cs +++ b/Mud Designer/MudEngine/GameObjects/Environment/Room.cs @@ -1,9 +1,9 @@ using System; +using System.Collections; using System.ComponentModel; using System.Collections.Generic; using System.Linq; using System.Text; -using System.ComponentModel; using System.Xml.Serialization; namespace MudDesigner.MudEngine.GameObjects.Environment diff --git a/Mud Designer/MudEngine/GameObjects/Environment/Zone.cs b/Mud Designer/MudEngine/GameObjects/Environment/Zone.cs index 765724f..4a56994 100644 --- a/Mud Designer/MudEngine/GameObjects/Environment/Zone.cs +++ b/Mud Designer/MudEngine/GameObjects/Environment/Zone.cs @@ -64,17 +64,29 @@ namespace MudDesigner.MudEngine.GameObjects.Environment //throw new NotSupportedException("Parameterless constructors of Type " + this.GetType().FullName + " is not supported."); } + /// + /// + /// + /// + /// public Room GetRoom(string RoomName) { - foreach (Room r in Rooms) - { - if (r.Name == RoomName) - return r; - } + var filterQuery = + from room in Rooms + where room.Name == RoomName + select room; + + foreach (var room in filterQuery) + return room; return null; } + /// + /// Clears out the Zones room collection and re-builds it. + /// This is a time consuming process if there are a large amount of + /// of rooms, use sparingly. + /// public void RefreshRoomList() { Rooms = new List(); @@ -88,13 +100,19 @@ namespace MudDesigner.MudEngine.GameObjects.Environment //Zone exists, so it's already been saved. string[] rooms = Directory.GetFiles(zonePath, "*.room"); - + + //Clear the existing collection of Rooms + this.Rooms.Clear(); + //Build a new one based off of the files foreach (string file in rooms) { Room r = new Room(); r = (Room)FileManager.Load(file, r); this.Rooms.Add(r); } + + //Save the re-built Room collection + this.Save(Path.Combine(zonePath, this.Filename)); } } } diff --git a/Mud Designer/MudEngine/UITypeEditors/UIRoomControl.cs b/Mud Designer/MudEngine/UITypeEditors/UIRoomControl.cs index 7b50839..5ef8391 100644 --- a/Mud Designer/MudEngine/UITypeEditors/UIRoomControl.cs +++ b/Mud Designer/MudEngine/UITypeEditors/UIRoomControl.cs @@ -19,12 +19,14 @@ namespace MudDesigner.MudEngine.UITypeEditors bool IsSaved; Room _Room; string savePath = ""; + public List Rooms { get; set; } public UIRoomControl(Zone zone) { InitializeComponent(); IsSaved = true; _Room = new Room(); + Rooms = new List(); string projectPath = Path.Combine(Application.StartupPath, "Project"); string zonesPath = Path.Combine(projectPath, "Zones"); @@ -81,6 +83,7 @@ namespace MudDesigner.MudEngine.UITypeEditors if (!lstRooms.Items.Contains(_Room.Filename)) lstRooms.Items.Add(_Room.Filename); + Rooms.Add(_Room); IsSaved = true; } diff --git a/Mud Designer/MudEngine/UITypeEditors/UIRoomEditor.cs b/Mud Designer/MudEngine/UITypeEditors/UIRoomEditor.cs index 73ac084..76beb26 100644 --- a/Mud Designer/MudEngine/UITypeEditors/UIRoomEditor.cs +++ b/Mud Designer/MudEngine/UITypeEditors/UIRoomEditor.cs @@ -21,7 +21,7 @@ namespace MudDesigner.MudEngine.UITypeEditors ctl.ShowDialog(); - return new List(); + return ctl.Rooms; } public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)