diff --git a/Mud Designer/Designer.cs b/Mud Designer/Designer.cs index 7b9ecf4..83dc124 100644 --- a/Mud Designer/Designer.cs +++ b/Mud Designer/Designer.cs @@ -41,6 +41,7 @@ namespace MudDesigner BaseObject _GameObject; //Check for if the loaded object is saved yet or not. bool IsSaved; + IWidget _Widget; /// /// Initializes the Designers Temporary objects, Project Information and varifies project paths. @@ -53,6 +54,7 @@ namespace MudDesigner //for use during our runtime _GameObject = new BaseObject(); _Project = new ProjectInformation(); + _Widget = new RealmWidget(); IsSaved = true; //Get out saved project file @@ -66,6 +68,9 @@ namespace MudDesigner //Display the Project directory structure in the Project Explorer RefreshProjectExplorer(); + + //Install out Realm Widget + this.containerMain.Panel1.Controls.Add(_Widget.Initialize()); } /// @@ -145,14 +150,15 @@ namespace MudDesigner { //We can use to get a copy of the currently selected object //if it is a BaseObject (Aquire it's BaseObject.Filename) - var obj = (BaseObject)propertyObject.SelectedObject; + if (propertyObject.SelectedObject.GetType().BaseType.Name == "BaseObject") + _GameObject = (BaseObject)propertyObject.SelectedObject; //Filepaths string objectPath = ""; string filename = ""; //Scan through the available Types that can be saved - switch (obj.GetType().Name) + switch (propertyObject.SelectedObject.GetType().Name) { //ProjectInformation case "ProjectInformation": @@ -161,20 +167,20 @@ namespace MudDesigner break; //Currency case "Currency": - filename = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Currencies), obj.Filename); - obj.Save(filename); + filename = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Currencies), _GameObject.Filename); + _GameObject.Save(filename); break; //Realm case "Realm": - objectPath= Path.Combine(FileManager.GetDataPath(SaveDataTypes.Realms), obj.Name); - filename = Path.Combine(objectPath, obj.Filename); - obj.Save(filename); + objectPath = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Realms), _GameObject.Name); + filename = Path.Combine(objectPath, _GameObject.Filename); + _GameObject.Save(filename); break; //Zone case "Zone": //Get the current Zone being edited. We need to check if it has a Realm Zone z = new Zone(); - z = (Zone)obj; + z = (Zone)_GameObject; //No realm assigned to it, so it's in the Root Zones directory. //Base our save path off of that if (z.Realm == "No Realm Associated.") @@ -189,7 +195,7 @@ namespace MudDesigner filename = Path.Combine(objectPath, z.Filename); } //Save the Zone - obj.Save(filename); + _GameObject.Save(filename); //Check if the Rooms Directory exists. string roomsPath = Path.Combine(objectPath, "Rooms"); @@ -466,6 +472,9 @@ namespace MudDesigner TreeNode selectedNode = treeExplorer.SelectedNode; bool IsFile = true; + if (Path.GetExtension(selectedNode.Text) == "") + IsFile = false; + result = MessageBox.Show("Are you sure you want to delete this object?\n\nAll objects contained within it will be deleted too!", "Mud Designer", MessageBoxButtons.YesNo); //User hit no, cancel @@ -534,6 +543,8 @@ namespace MudDesigner SaveObject(); IsSaved = true; RefreshProjectExplorer(); + if (_Widget != null) + _Widget.Refresh(); } private void mnuAbout_Click(object sender, EventArgs e) diff --git a/Mud Designer/MudEngine/UITypeEditors/UIRoomControl.cs b/Mud Designer/MudEngine/UITypeEditors/UIRoomControl.cs index 093b346..76a6765 100644 --- a/Mud Designer/MudEngine/UITypeEditors/UIRoomControl.cs +++ b/Mud Designer/MudEngine/UITypeEditors/UIRoomControl.cs @@ -35,7 +35,7 @@ namespace MudDesigner.MudEngine.UITypeEditors string realmsPath = Path.Combine(projectPath, "Realms"); savePath = ""; - if (zone.Realm == "No Realm Associated") + if (zone.Realm == "No Realm Associated.") { //Project/Zones/ZoneName savePath = Path.Combine(zonesPath, zone.Name); diff --git a/Mud Designer/UIWidgets/IWidget.cs b/Mud Designer/UIWidgets/IWidget.cs index b3bb420..8775128 100644 --- a/Mud Designer/UIWidgets/IWidget.cs +++ b/Mud Designer/UIWidgets/IWidget.cs @@ -2,11 +2,13 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Windows.Forms; namespace MudDesigner.UIWidgets { public interface IWidget { - void InstallControl(string path); + Control Initialize(); + void Refresh(); } } diff --git a/Mud Designer/UIWidgets/RealmWidget.Designer.cs b/Mud Designer/UIWidgets/RealmWidget.Designer.cs index 439b2ac..85700b8 100644 --- a/Mud Designer/UIWidgets/RealmWidget.Designer.cs +++ b/Mud Designer/UIWidgets/RealmWidget.Designer.cs @@ -1,6 +1,6 @@ namespace MudDesigner.UIWidgets { - partial class RealmExplorer + partial class RealmWidget { /// /// Required designer variable. diff --git a/Mud Designer/UIWidgets/RealmWidget.cs b/Mud Designer/UIWidgets/RealmWidget.cs index d8fa33a..ae8ad3f 100644 --- a/Mud Designer/UIWidgets/RealmWidget.cs +++ b/Mud Designer/UIWidgets/RealmWidget.cs @@ -11,26 +11,47 @@ using System.IO; using MudDesigner.MudEngine.FileSystem; using MudDesigner.MudEngine.GameObjects; using MudDesigner.MudEngine.GameObjects.Environment; + namespace MudDesigner.UIWidgets { - public partial class RealmExplorer : UserControl + public partial class RealmWidget : UserControl, IWidget { - public RealmExplorer() + public RealmWidget() { InitializeComponent(); this.Dock = DockStyle.Fill; } - public Control InstallControl(string projectPath) + public Control Initialize() { - string[] files = Directory.GetFiles(Path.Combine(projectPath, "Realms"), "*.realm", SearchOption.AllDirectories); + string[] files = new string[]{}; + + if (Directory.Exists(FileManager.GetDataPath(SaveDataTypes.Realms))) + files = Directory.GetFiles(FileManager.GetDataPath(SaveDataTypes.Realms), "*.realm", SearchOption.AllDirectories); //TODO: Add if (files.length==0) statement and set a 'No Realms' label in container + if (files.Length == 0) + { + Button button = new Button(); + button.FlatStyle = FlatStyle.Flat; + button.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(48, 48, 48); + button.FlatAppearance.MouseDownBackColor = System.Drawing.Color.FromArgb(48, 48, 48); + button.Font = new Font(new FontFamily(System.Drawing.Text.GenericFontFamilies.Serif), 12f, FontStyle.Bold); + button.BackColor = System.Drawing.Color.FromArgb(48, 48, 48); + button.ForeColor = System.Drawing.Color.LightGray; + button.Size = new System.Drawing.Size(160, 128); + button.Name = "btnNoRealms"; + button.Text = "No Existing Realms."; + button.Dock = DockStyle.Fill; + this.Controls.Clear(); + this.Controls.Add(button); + } + foreach (string realmFile in files) { Realm realm = new Realm(); - realm = (Realm)FileManager.Load(realmFile, realm); + realm = (Realm)realm.Load(realmFile); Button button = new Button(); button.FlatStyle = FlatStyle.Flat; @@ -51,5 +72,61 @@ namespace MudDesigner.UIWidgets { } + + public override void Refresh() + { + this.Controls.Clear(); + + FlowLayoutPanel flowContainer = new FlowLayoutPanel(); + flowContainer.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + flowContainer.Dock = System.Windows.Forms.DockStyle.Fill; + flowContainer.Location = new System.Drawing.Point(0, 0); + flowContainer.Name = "flowContainer"; + flowContainer.Padding = new System.Windows.Forms.Padding(10); + flowContainer.Size = new System.Drawing.Size(537, 502); + flowContainer.TabIndex = 0; + + string[] files = new string[] { }; + + if (Directory.Exists(FileManager.GetDataPath(SaveDataTypes.Realms))) + files = Directory.GetFiles(FileManager.GetDataPath(SaveDataTypes.Realms), "*.realm", SearchOption.AllDirectories); + + //TODO: Add if (files.length==0) statement and set a 'No Realms' label in container + + if (files.Length == 0) + { + Button button = new Button(); + button.FlatStyle = FlatStyle.Flat; + button.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(48, 48, 48); + button.FlatAppearance.MouseDownBackColor = System.Drawing.Color.FromArgb(48, 48, 48); + button.Font = new Font(new FontFamily(System.Drawing.Text.GenericFontFamilies.Serif), 12f, FontStyle.Bold); + button.BackColor = System.Drawing.Color.FromArgb(48, 48, 48); + button.ForeColor = System.Drawing.Color.LightGray; + button.Size = new System.Drawing.Size(160, 128); + button.Name = "btnNoRealms"; + button.Text = "No Existing Realms."; + button.Dock = DockStyle.Fill; + this.Controls.Clear(); + this.Controls.Add(button); + } + + foreach (string realmFile in files) + { + Realm realm = new Realm(); + realm = (Realm)realm.Load(realmFile); + + Button button = new Button(); + button.FlatStyle = FlatStyle.Flat; + button.Font = new Font(new FontFamily(System.Drawing.Text.GenericFontFamilies.Serif), 12f, FontStyle.Bold); + button.BackColor = System.Drawing.Color.FromArgb(48, 48, 48); + button.ForeColor = System.Drawing.Color.LightGray; + button.Size = new System.Drawing.Size(160, 128); + button.Name = "btn" + realm.Name; + button.Text = realm.Name; + button.Click += new EventHandler(button_Click); + flowContainer.Controls.Add(button); + } + base.Refresh(); + } } }