From f62fb84e13e4766dde09b3eb00f3a2e3b016bc01 Mon Sep 17 00:00:00 2001 From: Scionwest_cp Date: Fri, 6 Nov 2009 18:10:52 -0800 Subject: [PATCH] MUDEngine: * Realm.cs - Description Property added. * Room.cs - Inherits from Zone.cs * Zone.cs - Inherits from Realm.cs * Zone.cs - Removed Name Property. * Deleted old MUDEngine/XmlSerialization.cs as it has been replaced with MUDEngine/FileSystem/XmlSerialization.cs Project Manager: * frmMain.cs - collection of Zones and Rooms are created during selectedIndexChanges from comRealms, lstRooms and lstZones. * frmMain.cs - PropertyGrid is now populated within the frmMain_Load instead of within the forms constructor. * frmMain.cs - lstZones now populates the lstRooms list box with rooms when its selected index is changed. --- MUDEngine/Environment/Realm.cs | 9 +++++ MUDEngine/Environment/Room.cs | 2 +- MUDEngine/Environment/Zone.cs | 6 +-- MUDEngine/XmlSerialization.cs | 42 -------------------- Project Manager/frmMain.Designer.cs | 45 +++++++++++----------- Project Manager/frmMain.cs | 60 +++++++++++++++++++++++++---- 6 files changed, 87 insertions(+), 77 deletions(-) delete mode 100644 MUDEngine/XmlSerialization.cs diff --git a/MUDEngine/Environment/Realm.cs b/MUDEngine/Environment/Realm.cs index 9ed00ad..1bd652f 100644 --- a/MUDEngine/Environment/Realm.cs +++ b/MUDEngine/Environment/Realm.cs @@ -18,5 +18,14 @@ namespace MUDEngine.Environment get; set; } + + /// + /// Description of the Realm. + /// + public string Description + { + get; + set; + } } } diff --git a/MUDEngine/Environment/Room.cs b/MUDEngine/Environment/Room.cs index 976f433..0f0e0b4 100644 --- a/MUDEngine/Environment/Room.cs +++ b/MUDEngine/Environment/Room.cs @@ -9,7 +9,7 @@ namespace MUDEngine.Environment /// Rooms are traversable by players during gameplay. They are connected via Door objects, that allow players /// to move from one room to another. /// - public class Room + public class Room : Zone { } } diff --git a/MUDEngine/Environment/Zone.cs b/MUDEngine/Environment/Zone.cs index 59d25d3..82f6ed7 100644 --- a/MUDEngine/Environment/Zone.cs +++ b/MUDEngine/Environment/Zone.cs @@ -8,11 +8,7 @@ namespace MUDEngine.Environment /// /// Zones contain an unlimited number of Rooms. /// - public class Zone + public class Zone : Realm { - /// - /// The name of the Zone. - /// - public string Name { get; set; } } } diff --git a/MUDEngine/XmlSerialization.cs b/MUDEngine/XmlSerialization.cs deleted file mode 100644 index 54c840b..0000000 --- a/MUDEngine/XmlSerialization.cs +++ /dev/null @@ -1,42 +0,0 @@ -#region ====== Using Statements ====== -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Reflection; -using System.Xml; -using System.Xml.Serialization; -using System.IO; -#endregion - -namespace MUDEngine -{ - public class XmlSerialization - { - public static void Save(string Filename, object o) - { - Stream stream = File.Create(Filename); - - XmlSerializer serializer = new XmlSerializer(o.GetType()); - serializer.Serialize(stream, o); - stream.Close(); - } - - - /// - /// Loads an item via Xml Deserialization - /// - /// The Xml document to deserialize. - /// - public static object Load(string Filename, object o) - { - Stream stream = File.OpenRead(Filename); - - object obj = new object(); - XmlSerializer serializer = new XmlSerializer(o.GetType()); - obj = (object)serializer.Deserialize(stream); - - stream.Close(); - return obj; - } - } -} diff --git a/Project Manager/frmMain.Designer.cs b/Project Manager/frmMain.Designer.cs index 420e6b8..ec322f2 100644 --- a/Project Manager/frmMain.Designer.cs +++ b/Project Manager/frmMain.Designer.cs @@ -32,11 +32,11 @@ this.propertyGrid1 = new System.Windows.Forms.PropertyGrid(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.groupBox4 = new System.Windows.Forms.GroupBox(); + this.lstRooms = new System.Windows.Forms.CheckedListBox(); this.groupBox3 = new System.Windows.Forms.GroupBox(); + this.lstZones = new System.Windows.Forms.CheckedListBox(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.comRealms = new System.Windows.Forms.ComboBox(); - this.lstZones = new System.Windows.Forms.CheckedListBox(); - this.lstRooms = new System.Windows.Forms.CheckedListBox(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); this.splitContainer1.SuspendLayout(); @@ -93,6 +93,16 @@ this.groupBox4.TabStop = false; this.groupBox4.Text = "Available Rooms"; // + // lstRooms + // + this.lstRooms.Dock = System.Windows.Forms.DockStyle.Fill; + this.lstRooms.FormattingEnabled = true; + this.lstRooms.Location = new System.Drawing.Point(3, 16); + this.lstRooms.Name = "lstRooms"; + this.lstRooms.Size = new System.Drawing.Size(143, 154); + this.lstRooms.TabIndex = 1; + this.lstRooms.ThreeDCheckBoxes = true; + // // groupBox3 // this.groupBox3.Controls.Add(this.lstZones); @@ -103,6 +113,17 @@ this.groupBox3.TabStop = false; this.groupBox3.Text = "Available Zones"; // + // lstZones + // + this.lstZones.Dock = System.Windows.Forms.DockStyle.Fill; + this.lstZones.FormattingEnabled = true; + this.lstZones.Location = new System.Drawing.Point(3, 16); + this.lstZones.Name = "lstZones"; + this.lstZones.Size = new System.Drawing.Size(143, 109); + this.lstZones.TabIndex = 0; + this.lstZones.ThreeDCheckBoxes = true; + this.lstZones.SelectedIndexChanged += new System.EventHandler(this.lstZones_SelectedIndexChanged); + // // groupBox2 // this.groupBox2.Controls.Add(this.comRealms); @@ -125,26 +146,6 @@ this.comRealms.TabIndex = 0; this.comRealms.SelectedIndexChanged += new System.EventHandler(this.comRealms_SelectedIndexChanged); // - // lstZones - // - this.lstZones.Dock = System.Windows.Forms.DockStyle.Fill; - this.lstZones.FormattingEnabled = true; - this.lstZones.Location = new System.Drawing.Point(3, 16); - this.lstZones.Name = "lstZones"; - this.lstZones.Size = new System.Drawing.Size(143, 109); - this.lstZones.TabIndex = 0; - this.lstZones.ThreeDCheckBoxes = true; - // - // lstRooms - // - this.lstRooms.Dock = System.Windows.Forms.DockStyle.Fill; - this.lstRooms.FormattingEnabled = true; - this.lstRooms.Location = new System.Drawing.Point(3, 16); - this.lstRooms.Name = "lstRooms"; - this.lstRooms.Size = new System.Drawing.Size(143, 154); - this.lstRooms.TabIndex = 1; - this.lstRooms.ThreeDCheckBoxes = true; - // // frmMain // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); diff --git a/Project Manager/frmMain.cs b/Project Manager/frmMain.cs index 533909c..469d95f 100644 --- a/Project Manager/frmMain.cs +++ b/Project Manager/frmMain.cs @@ -11,20 +11,24 @@ namespace Project_Manager { public partial class frmMain : Form { + List zones; + List rooms; + public frmMain() { InitializeComponent(); - - propertyGrid1.SelectedObject = Program.project; } private void frmMain_Load(object sender, EventArgs e) { //Get all of the realms currently created. - string[] realms = System.IO.Directory.GetFiles(Application.StartupPath + @"\Data\Realms"); + string[] files = System.IO.Directory.GetFiles(Application.StartupPath + @"\Data\Realms"); + + //Aquire the project settings and show them. + propertyGrid1.SelectedObject = Program.project; //Add each realm found into the combo box of available realms. - foreach (string realm in realms) + foreach (string realm in files) { //Instance a new realm MUDEngine.Environment.Realm newRealm = new MUDEngine.Environment.Realm(); @@ -44,7 +48,7 @@ namespace Project_Manager { comRealms.SelectedIndex = 0; } - } + }//End frmMain_Load private void comRealms_SelectedIndexChanged(object sender, EventArgs e) { @@ -54,16 +58,17 @@ namespace Project_Manager if (comRealms.Items.Count == 0) return; - string[] zones = System.IO.Directory.GetFiles(Application.StartupPath + @"\Data\Zones"); + string[] files = System.IO.Directory.GetFiles(Application.StartupPath + @"\Data\Zones"); //Add each zone found into the list box. - foreach (string zone in zones) + foreach (string zone in files) { MUDEngine.Environment.Zone newZone = new MUDEngine.Environment.Zone(); //De-serialize the current zone. newZone = (MUDEngine.Environment.Zone)MUDEngine.FileSystem.FileSystem.Load(zone, newZone); //Add it to the available zones list box lstZones.Items.Add(newZone.Name); + zones.Add(newZone); } //Check if we have an existing realm that's set as our startup. @@ -82,6 +87,47 @@ namespace Project_Manager } } } + }//End comRealms + + private void lstZones_SelectedIndexChanged(object sender, EventArgs e) + { + string realm = comRealms.SelectedItem.ToString(); + string zone = lstZones.SelectedItem.ToString(); + + lstRooms.Items.Clear(); + + //Check if we have any realms first. + if (comRealms.Items.Count == 0) + return; + + string[] files = System.IO.Directory.GetFiles(Application.StartupPath + @"\Data\Rooms"); + + //Add each room found into the list box. + foreach (string room in files) + { + MUDEngine.Environment.Room newRoom = new MUDEngine.Environment.Room(); + //De-serialize the current Room. + newRoom = (MUDEngine.Environment.Room)MUDEngine.FileSystem.FileSystem.Load(room, newRoom); + //Add it to the available rooms list box + lstRooms.Items.Add(newRoom.Name); + rooms.Add(newRoom); + } + + //Now select the initial room if its listed. + string selectedRealm = comRealms.SelectedItem.ToString(); + string selectedZone = lstZones.SelectedItem.ToString(); + string initialRealm = Program.project.InitialLocation.Realm.Name; + string initialZone = Program.project.InitialLocation.Zone.Name; + + //The realm and zone that matches the initial are selected, so lets select the initial room next. + if ((initialRealm == selectedRealm) && (initialZone == selectedZone)) + { + foreach (MUDEngine.Environment.Room room in rooms) + { + if (lstRooms.Items.Contains(room.Name)) + lstRooms.SelectedIndex = lstRooms.Items.IndexOf(room.Name); + } + } } } }