Designer:
- Renamed SaveSelected() to SaveObject() - Added additional commenting - Re-formatted the document - Moved the search code out from the text box and into its own method SearchForObject() - Changed search method for the text box from txtSearch_Enter to txtSearch_KeyDown - Re-write of object save code finished. Engine: - Realm.GetZone() re-wrote to use LINQ. - Zone.GetRoom() renamed to Zone.GetRoomByName() for searching for a Room by name - Zone.GetRoomByFilename() added for searching by filename for a Room. - Re-wrote Adding Zones into Realms via the UIRealmControl. Uses 54% less source, and better readability. - UIRealmEditor now stores a proper backup of Zones incase of UIRealmControl instancing failure.
This commit is contained in:
parent
af4dc2ad7a
commit
0395acb0f9
9 changed files with 256 additions and 218 deletions
80
Mud Designer/Designer.Designer.cs
generated
80
Mud Designer/Designer.Designer.cs
generated
|
@ -74,6 +74,10 @@
|
||||||
this.containerSidebar = new System.Windows.Forms.SplitContainer();
|
this.containerSidebar = new System.Windows.Forms.SplitContainer();
|
||||||
this.treeExplorer = new System.Windows.Forms.TreeView();
|
this.treeExplorer = new System.Windows.Forms.TreeView();
|
||||||
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
|
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(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.mnuEditObject = new System.Windows.Forms.ToolStripMenuItem();
|
this.mnuEditObject = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator();
|
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator();
|
||||||
this.mnuDeleteSelectedObject = new System.Windows.Forms.ToolStripMenuItem();
|
this.mnuDeleteSelectedObject = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
@ -86,10 +90,6 @@
|
||||||
this.propertyObject = new System.Windows.Forms.PropertyGrid();
|
this.propertyObject = new System.Windows.Forms.PropertyGrid();
|
||||||
this.lblObjectProperties = new System.Windows.Forms.Label();
|
this.lblObjectProperties = new System.Windows.Forms.Label();
|
||||||
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
|
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.menuStrip1.SuspendLayout();
|
||||||
this.containerMain.Panel2.SuspendLayout();
|
this.containerMain.Panel2.SuspendLayout();
|
||||||
this.containerMain.SuspendLayout();
|
this.containerMain.SuspendLayout();
|
||||||
|
@ -453,24 +453,55 @@
|
||||||
this.toolStripMenuItem1,
|
this.toolStripMenuItem1,
|
||||||
this.mnuDeleteSelectedObject});
|
this.mnuDeleteSelectedObject});
|
||||||
this.contextMenuStrip1.Name = "contextMenuStrip1";
|
this.contextMenuStrip1.Name = "contextMenuStrip1";
|
||||||
this.contextMenuStrip1.Size = new System.Drawing.Size(153, 98);
|
this.contextMenuStrip1.Size = new System.Drawing.Size(146, 76);
|
||||||
|
//
|
||||||
|
// addObjectToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.addObjectToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
|
this.environmentToolStripMenuItem});
|
||||||
|
this.addObjectToolStripMenuItem.Name = "addObjectToolStripMenuItem";
|
||||||
|
this.addObjectToolStripMenuItem.Size = new System.Drawing.Size(145, 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(142, 22);
|
||||||
|
this.environmentToolStripMenuItem.Text = "Environment";
|
||||||
|
//
|
||||||
|
// mnuNewRealmShortcut
|
||||||
|
//
|
||||||
|
this.mnuNewRealmShortcut.Name = "mnuNewRealmShortcut";
|
||||||
|
this.mnuNewRealmShortcut.Size = new System.Drawing.Size(134, 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(134, 22);
|
||||||
|
this.mnuNewZoneShortcut.Text = "New Zone";
|
||||||
|
this.mnuNewZoneShortcut.Click += new System.EventHandler(this.mnuNewZone_Click);
|
||||||
//
|
//
|
||||||
// mnuEditObject
|
// mnuEditObject
|
||||||
//
|
//
|
||||||
this.mnuEditObject.Name = "mnuEditObject";
|
this.mnuEditObject.Name = "mnuEditObject";
|
||||||
this.mnuEditObject.Size = new System.Drawing.Size(152, 22);
|
this.mnuEditObject.Size = new System.Drawing.Size(145, 22);
|
||||||
this.mnuEditObject.Text = "Edit Object";
|
this.mnuEditObject.Text = "Edit Object";
|
||||||
this.mnuEditObject.Click += new System.EventHandler(this.mnuEditObject_Click);
|
this.mnuEditObject.Click += new System.EventHandler(this.mnuEditObject_Click);
|
||||||
//
|
//
|
||||||
// toolStripMenuItem1
|
// toolStripMenuItem1
|
||||||
//
|
//
|
||||||
this.toolStripMenuItem1.Name = "toolStripMenuItem1";
|
this.toolStripMenuItem1.Name = "toolStripMenuItem1";
|
||||||
this.toolStripMenuItem1.Size = new System.Drawing.Size(149, 6);
|
this.toolStripMenuItem1.Size = new System.Drawing.Size(142, 6);
|
||||||
//
|
//
|
||||||
// mnuDeleteSelectedObject
|
// mnuDeleteSelectedObject
|
||||||
//
|
//
|
||||||
this.mnuDeleteSelectedObject.Name = "mnuDeleteSelectedObject";
|
this.mnuDeleteSelectedObject.Name = "mnuDeleteSelectedObject";
|
||||||
this.mnuDeleteSelectedObject.Size = new System.Drawing.Size(152, 22);
|
this.mnuDeleteSelectedObject.Size = new System.Drawing.Size(145, 22);
|
||||||
this.mnuDeleteSelectedObject.Text = "Delete Object";
|
this.mnuDeleteSelectedObject.Text = "Delete Object";
|
||||||
this.mnuDeleteSelectedObject.Click += new System.EventHandler(this.mnuDeleteSelectedObject_Click);
|
this.mnuDeleteSelectedObject.Click += new System.EventHandler(this.mnuDeleteSelectedObject_Click);
|
||||||
//
|
//
|
||||||
|
@ -513,7 +544,7 @@
|
||||||
//
|
//
|
||||||
this.txtSearch.Name = "txtSearch";
|
this.txtSearch.Name = "txtSearch";
|
||||||
this.txtSearch.Size = new System.Drawing.Size(100, 25);
|
this.txtSearch.Size = new System.Drawing.Size(100, 25);
|
||||||
this.txtSearch.Enter += new System.EventHandler(this.txtSearch_Enter);
|
this.txtSearch.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtSearch_KeyDown);
|
||||||
//
|
//
|
||||||
// label1
|
// label1
|
||||||
//
|
//
|
||||||
|
@ -560,37 +591,6 @@
|
||||||
this.toolTip1.ShowAlways = true;
|
this.toolTip1.ShowAlways = true;
|
||||||
this.toolTip1.ToolTipTitle = "Mud Designer Help";
|
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
|
// Designer
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
|
|
|
@ -141,6 +141,69 @@ namespace MudDesigner
|
||||||
return ObjectType.Nothing;
|
return ObjectType.Nothing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SaveObject()
|
||||||
|
{
|
||||||
|
//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;
|
||||||
|
|
||||||
|
//Filepaths
|
||||||
|
string objectPath = "";
|
||||||
|
string filename = "";
|
||||||
|
|
||||||
|
//Scan through the available Types that can be saved
|
||||||
|
switch (obj.GetType().Name)
|
||||||
|
{
|
||||||
|
//ProjectInformation
|
||||||
|
case "ProjectInformation":
|
||||||
|
filename = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Root), "Game.xml");
|
||||||
|
_Project.Save(filename);
|
||||||
|
break;
|
||||||
|
//Currency
|
||||||
|
case "Currency":
|
||||||
|
filename = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Currencies), obj.Filename);
|
||||||
|
obj.Save(filename);
|
||||||
|
break;
|
||||||
|
//Realm
|
||||||
|
case "Realm":
|
||||||
|
objectPath= Path.Combine(FileManager.GetDataPath(SaveDataTypes.Realms), obj.Name);
|
||||||
|
filename = Path.Combine(objectPath, obj.Filename);
|
||||||
|
obj.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;
|
||||||
|
//No realm assigned to it, so it's in the Root Zones directory.
|
||||||
|
//Base our save path off of that
|
||||||
|
if (String.IsNullOrEmpty(z.Realm))
|
||||||
|
{
|
||||||
|
objectPath = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Zones), z.Name);
|
||||||
|
filename = Path.Combine(objectPath, z.Filename);
|
||||||
|
}
|
||||||
|
//Realm assigned to it, so save the zone within that Realm
|
||||||
|
else
|
||||||
|
{
|
||||||
|
objectPath = FileManager.GetDataPath(z.Realm, z.Name);
|
||||||
|
filename = Path.Combine(objectPath, z.Filename);
|
||||||
|
}
|
||||||
|
//Save the Zone
|
||||||
|
obj.Save(filename);
|
||||||
|
|
||||||
|
//Check if the Rooms Directory exists.
|
||||||
|
string roomsPath = Path.Combine(objectPath, "Rooms");
|
||||||
|
if (!Directory.Exists(roomsPath))
|
||||||
|
Directory.CreateDirectory(roomsPath);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case "Room":
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
RefreshProjectExplorer();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Searchs to find what Type the selected TreeNode is, and loads
|
/// Searchs to find what Type the selected TreeNode is, and loads
|
||||||
/// that objects into the propertygrid.
|
/// that objects into the propertygrid.
|
||||||
|
@ -233,7 +296,7 @@ namespace MudDesigner
|
||||||
return false;
|
return false;
|
||||||
//User hit Yes, so save the object
|
//User hit Yes, so save the object
|
||||||
else
|
else
|
||||||
SaveSelected();
|
SaveObject();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -306,48 +369,21 @@ namespace MudDesigner
|
||||||
PopulateTree(FileManager.GetDataPath(SaveDataTypes.Root), node);
|
PopulateTree(FileManager.GetDataPath(SaveDataTypes.Root), node);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveSelected()
|
public void FindObject(string obj)
|
||||||
{
|
{
|
||||||
//We can use to get a copy of the currently selected object
|
if (txtSearch.Text == "")
|
||||||
//if it is a BaseObject (Aquire it's BaseObject.Filename)
|
return;
|
||||||
var obj = (BaseObject)propertyObject.SelectedObject;
|
|
||||||
|
|
||||||
//Filepaths
|
TreeNode node = FindNode(txtSearch.Text, treeExplorer.Nodes[0]);
|
||||||
string objectPath = "";
|
if (node == null)
|
||||||
string filename = "";
|
MessageBox.Show("No results found!", "Mud Designer");
|
||||||
|
|
||||||
switch (obj.GetType().Name)
|
|
||||||
{
|
|
||||||
case "ProjectInformation":
|
|
||||||
filename = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Root), "Game.xml");
|
|
||||||
_Project.Save(filename);
|
|
||||||
break;
|
|
||||||
case "Currency":
|
|
||||||
filename = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Currencies), obj.Filename);
|
|
||||||
obj.Save(filename);
|
|
||||||
break;
|
|
||||||
case "Realm":
|
|
||||||
filename = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Realms), obj.Filename);
|
|
||||||
obj.Save(filename);
|
|
||||||
break;
|
|
||||||
case "Zone":
|
|
||||||
Zone z = new Zone();
|
|
||||||
z = (Zone)obj;
|
|
||||||
if (String.IsNullOrEmpty(z.Realm))
|
|
||||||
{
|
|
||||||
objectPath = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Zones), z.Name);
|
|
||||||
filename = Path.Combine(objectPath, z.Filename);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
objectPath = FileManager.GetDataPath(z.Realm, z.Name);
|
treeExplorer.SelectedNode = node;
|
||||||
filename = Path.Combine(objectPath, z.Filename);
|
|
||||||
}
|
|
||||||
obj.Save(filename);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
RefreshProjectExplorer();
|
//TODO: Fix objects not loading during search.
|
||||||
|
LoadObject(node);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -417,25 +453,6 @@ namespace MudDesigner
|
||||||
propertyObject.SelectedObject = new Zone();
|
propertyObject.SelectedObject = new Zone();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Searchs the Project Explorer for a file or directory matching the supplied name
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void txtSearch_Enter(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (txtSearch.Text == "")
|
|
||||||
return;
|
|
||||||
|
|
||||||
TreeNode node = FindNode(txtSearch.Text, treeExplorer.Nodes[0]);
|
|
||||||
if (node == null)
|
|
||||||
MessageBox.Show("No results found!", "Mud Designer");
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//TODO select the node
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void mnuDeleteSelectedObject_Click(object sender, EventArgs e)
|
private void mnuDeleteSelectedObject_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
//Check if we are trying to delete the root node
|
//Check if we are trying to delete the root node
|
||||||
|
@ -461,6 +478,8 @@ namespace MudDesigner
|
||||||
{
|
{
|
||||||
Realm r = new Realm();
|
Realm r = new Realm();
|
||||||
string filename = "";
|
string filename = "";
|
||||||
|
//If the user selected the file, then we need to get the realm
|
||||||
|
//filename differently
|
||||||
if (IsFile)
|
if (IsFile)
|
||||||
{
|
{
|
||||||
string realmName = selectedNode.Parent.Parent.Parent.Text;
|
string realmName = selectedNode.Parent.Parent.Parent.Text;
|
||||||
|
@ -473,9 +492,13 @@ namespace MudDesigner
|
||||||
filename = Path.Combine(realmName, realmName + ".realm");
|
filename = Path.Combine(realmName, realmName + ".realm");
|
||||||
filename = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Realms), filename);
|
filename = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Realms), filename);
|
||||||
}
|
}
|
||||||
|
//Finalize the filename of the realm
|
||||||
filename = Path.Combine(Application.StartupPath, filename);
|
filename = Path.Combine(Application.StartupPath, filename);
|
||||||
|
|
||||||
|
//Load the realm that this Zone belongs to
|
||||||
r = (Realm)r.Load(filename);
|
r = (Realm)r.Load(filename);
|
||||||
|
//Zone collection does not contain filenames, so we need
|
||||||
|
//to check so we can use the directory name for removal
|
||||||
if (IsFile)
|
if (IsFile)
|
||||||
r.Zones.Remove(selectedNode.Parent.Text);
|
r.Zones.Remove(selectedNode.Parent.Text);
|
||||||
else
|
else
|
||||||
|
@ -483,6 +506,8 @@ namespace MudDesigner
|
||||||
}
|
}
|
||||||
|
|
||||||
//Delete the object.
|
//Delete the object.
|
||||||
|
//Check if it's a file, if so then delete the parent directory so that
|
||||||
|
//we dont have a left over empty folder
|
||||||
if (IsFile)
|
if (IsFile)
|
||||||
Directory.Delete(selectedNode.Parent.FullPath, true);
|
Directory.Delete(selectedNode.Parent.FullPath, true);
|
||||||
else
|
else
|
||||||
|
@ -506,7 +531,7 @@ namespace MudDesigner
|
||||||
if (obj.Name == "New " + obj.GetType().Name)
|
if (obj.Name == "New " + obj.GetType().Name)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SaveSelected();
|
SaveObject();
|
||||||
IsSaved = true;
|
IsSaved = true;
|
||||||
RefreshProjectExplorer();
|
RefreshProjectExplorer();
|
||||||
}
|
}
|
||||||
|
@ -524,6 +549,10 @@ namespace MudDesigner
|
||||||
|
|
||||||
private void treeExplorer_DoubleClick(object sender, EventArgs e)
|
private void treeExplorer_DoubleClick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
if (treeExplorer.SelectedNode.Text == "Project")
|
||||||
|
return;
|
||||||
|
if (Path.GetExtension(treeExplorer.SelectedNode.Text) == "")
|
||||||
|
return;
|
||||||
if (CheckSavedState())
|
if (CheckSavedState())
|
||||||
LoadObject(treeExplorer.SelectedNode);
|
LoadObject(treeExplorer.SelectedNode);
|
||||||
}
|
}
|
||||||
|
@ -543,5 +572,11 @@ namespace MudDesigner
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void txtSearch_KeyDown(object sender, KeyEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.KeyCode == Keys.Enter)
|
||||||
|
FindObject(txtSearch.Text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,6 +185,7 @@ namespace MudDesigner.MudEngine.GameObjects
|
||||||
Directory.CreateDirectory(directory);
|
Directory.CreateDirectory(directory);
|
||||||
FileManager.Save(filename, this);
|
FileManager.Save(filename, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return this.Name;
|
return this.Name;
|
||||||
|
|
|
@ -29,28 +29,16 @@ namespace MudDesigner.MudEngine.GameObjects.Environment
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="zoneName"></param>
|
/// <param name="zoneName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Zone GetZone(string zoneName)
|
public Zone GetZone(string filename)
|
||||||
{
|
{
|
||||||
string zoneFilename = "";
|
var filterQuery =
|
||||||
//correct the zonename if needed
|
from zone in Zones
|
||||||
if (!zoneName.EndsWith(".zone"))
|
where zone == filename
|
||||||
zoneFilename = zoneName + ".zone";
|
select zone;
|
||||||
else
|
|
||||||
{
|
|
||||||
zoneName = Path.GetFileNameWithoutExtension(zoneName);
|
|
||||||
zoneFilename = zoneName;
|
|
||||||
}
|
|
||||||
|
|
||||||
string zonePath = FileManager.GetDataPath(this.Name, zoneFilename);
|
|
||||||
zonePath = Path.Combine(zonePath, zoneName);
|
|
||||||
zoneFilename = Path.Combine(zonePath, zoneFilename);
|
|
||||||
|
|
||||||
if (File.Exists(zoneFilename))
|
|
||||||
{
|
|
||||||
Zone z = new Zone();
|
Zone z = new Zone();
|
||||||
z = (Zone)FileManager.Load(zoneFilename, z);
|
foreach (var zone in filterQuery)
|
||||||
return z;
|
return (Zone)z.Load(zone); ;
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,11 +69,29 @@ namespace MudDesigner.MudEngine.GameObjects.Environment
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="RoomName"></param>
|
/// <param name="RoomName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Room GetRoom(string RoomName)
|
public Room GetRoomByName(string name)
|
||||||
{
|
{
|
||||||
var filterQuery =
|
var filterQuery =
|
||||||
from room in Rooms
|
from room in Rooms
|
||||||
where room.Name == RoomName
|
where room.Name == name
|
||||||
|
select room;
|
||||||
|
|
||||||
|
foreach (var room in filterQuery)
|
||||||
|
return room;
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="RoomName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Room GetRoomByFilename(string filename)
|
||||||
|
{
|
||||||
|
var filterQuery =
|
||||||
|
from room in Rooms
|
||||||
|
where room.Filename == filename
|
||||||
select room;
|
select room;
|
||||||
|
|
||||||
foreach (var room in filterQuery)
|
foreach (var room in filterQuery)
|
||||||
|
|
|
@ -20,13 +20,12 @@ namespace MudDesigner.MudEngine.UITypeEditors
|
||||||
private Realm _Realm;
|
private Realm _Realm;
|
||||||
private string realmPath = "";
|
private string realmPath = "";
|
||||||
string projectPath = "";
|
string projectPath = "";
|
||||||
private List<string> zones;
|
|
||||||
|
|
||||||
public List<string> Zones
|
public List<string> Zones
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return zones;
|
return _Realm.Zones;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,44 +34,47 @@ namespace MudDesigner.MudEngine.UITypeEditors
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
//Store the supplied Realm loaded by the user
|
||||||
_Realm = realm;
|
_Realm = realm;
|
||||||
zones = new List<string>();
|
|
||||||
|
|
||||||
projectPath = Path.Combine(Application.StartupPath, "Project");
|
//Setup our paths
|
||||||
realmPath = Path.Combine(projectPath, "Realms");
|
projectPath = FileManager.GetDataPath(SaveDataTypes.Root);
|
||||||
realmPath = Path.Combine(realmPath, _Realm.Name);
|
realmPath = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Realms), _Realm.Name);
|
||||||
string realmZones = Path.Combine(realmPath, "Zones");
|
string realmZones = Path.Combine(realmPath, "Zones");
|
||||||
|
|
||||||
if (!Directory.Exists(realmZones))
|
//Check if the Realm path exist, if not then the Realm has not been saved and
|
||||||
|
//we cannot go any further.
|
||||||
|
if (!Directory.Exists(realmPath))
|
||||||
{
|
{
|
||||||
MessageBox.Show("You must save the Realm prior to adding Zones to it.", "Mud Designer");
|
MessageBox.Show("You must save the Realm prior to adding Zones to it. The Realm will Auto-Save after the default name has been changed.", "Mud Designer");
|
||||||
this.Close();
|
this.Close();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (string zone in _Realm.Zones)
|
//If the Zones directory has not been created yet within the Realm, we need to create it.
|
||||||
{
|
if (!Directory.Exists(realmZones))
|
||||||
zones.Add(zone);
|
Directory.CreateDirectory(realmZones);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UIRealmControl_Load(object sender, EventArgs e)
|
private void UIRealmControl_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
string zonePath = Path.Combine(projectPath, "Zones");
|
//Place all of the Realms existing Zones into the Realm Members
|
||||||
|
//list box.
|
||||||
foreach (string zone in _Realm.Zones)
|
foreach (string zone in _Realm.Zones)
|
||||||
{
|
{
|
||||||
lstRealmMembers.Items.Add(zone);
|
lstRealmMembers.Items.Add(zone);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Create the Root Zone directory if it does not exist
|
||||||
|
string zonePath = FileManager.GetDataPath(SaveDataTypes.Zones);
|
||||||
if (!Directory.Exists(zonePath))
|
if (!Directory.Exists(zonePath))
|
||||||
Directory.CreateDirectory(zonePath);
|
Directory.CreateDirectory(zonePath);
|
||||||
|
|
||||||
string[] zones = Directory.GetFiles(zonePath, "*.zone", SearchOption.AllDirectories);
|
//Add all of the existing Un-owned Zones into the Available Zones listbox
|
||||||
|
foreach (string zone in Directory.GetFiles(zonePath, "*.zone", SearchOption.AllDirectories))
|
||||||
foreach (string zone in zones)
|
|
||||||
{
|
{
|
||||||
Zone z = new Zone();
|
//place the filename into the Available Zones.
|
||||||
z = (Zone)FileManager.Load(zone, z);
|
lstAvailableZones.Items.Add(Path.GetFileName(zone));
|
||||||
lstAvailableZones.Items.Add(z.Filename);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,78 +86,67 @@ namespace MudDesigner.MudEngine.UITypeEditors
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Store the name of the current Zone being added to the World.
|
||||||
|
string zoneName = Path.GetFileNameWithoutExtension(lstAvailableZones.SelectedItem.ToString());
|
||||||
|
|
||||||
|
//Store the original Folder & Filename locations of the Zone we are moving
|
||||||
|
string originalZonePath = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Zones), zoneName);
|
||||||
|
string originalFilename = Path.Combine(originalZonePath, lstAvailableZones.SelectedItem.ToString());
|
||||||
|
string originalZoneRooms = Path.Combine(originalZonePath, "Rooms");
|
||||||
|
|
||||||
|
//Create our new paths
|
||||||
|
string newZonePath = FileManager.GetDataPath(_Realm.Name, zoneName);
|
||||||
|
string newFilename = Path.Combine(newZonePath, lstAvailableZones.SelectedItem.ToString());
|
||||||
|
string newZoneRooms = Path.Combine(newZonePath, "Rooms");
|
||||||
|
|
||||||
|
//Create the new Zone directory within it's new Realm.
|
||||||
|
//Checking and Creating the Rooms directory will force the
|
||||||
|
//Zone directory to be created at the same time.
|
||||||
|
if (!Directory.Exists(newZoneRooms))
|
||||||
|
Directory.CreateDirectory(newZoneRooms);
|
||||||
|
|
||||||
|
//Load the original Zone and assign it to the new Realm.
|
||||||
Zone zone = new Zone();
|
Zone zone = new Zone();
|
||||||
//Set the paths
|
zone = (Zone)zone.Load(originalFilename);
|
||||||
string zoneRoot = Path.Combine(projectPath, "Zones");
|
|
||||||
string realmZones = Path.Combine(realmPath, "Zones");
|
|
||||||
string[] files = Directory.GetFiles(zoneRoot, "*.zone", SearchOption.AllDirectories);
|
|
||||||
string originalFile = "";
|
|
||||||
if (files.Length == 0)
|
|
||||||
zone = null;
|
|
||||||
|
|
||||||
foreach (string file in files)
|
|
||||||
{
|
|
||||||
if (Path.GetFileName(file) == lstAvailableZones.SelectedItem.ToString())
|
|
||||||
{
|
|
||||||
zone = new Zone();
|
|
||||||
zone = (Zone)zone.Load(file);
|
|
||||||
originalFile = file;
|
|
||||||
zone.Realm = _Realm.Name;
|
zone.Realm = _Realm.Name;
|
||||||
FileManager.Save(file, zone);
|
//Save the Zone changes into the new Realm path.
|
||||||
}
|
//We are done with modifying the Zone so we are free to delete it
|
||||||
else
|
//after we are done moving all of its Rooms.
|
||||||
zone = null;
|
zone.Save(newFilename);
|
||||||
}
|
|
||||||
|
|
||||||
//check if we have a zone
|
//Check if the original Zone contained Rooms.
|
||||||
if (zone == null)
|
string[] rooms = Directory.GetFiles(originalZoneRooms, "*.room");
|
||||||
{
|
|
||||||
MessageBox.Show("Unable to locate the zone specified!", "Mud Designer");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//get the new path for the zone within the realm directory
|
|
||||||
string zonePath = Path.Combine(realmZones, zone.Name);
|
|
||||||
if (!Directory.Exists(zonePath))
|
|
||||||
Directory.CreateDirectory(zonePath);
|
|
||||||
|
|
||||||
|
|
||||||
zones.Add(lstAvailableZones.SelectedItem.ToString());
|
|
||||||
lstRealmMembers.Items.Add(lstAvailableZones.SelectedItem);
|
|
||||||
|
|
||||||
//copy the file
|
|
||||||
string newFile = Path.Combine(zonePath, lstAvailableZones.SelectedItem.ToString());
|
|
||||||
File.Copy(originalFile, newFile, true);
|
|
||||||
//copy all of its rooms if they exist
|
|
||||||
string originalPath = originalFile.Substring(0, originalFile.Length - Path.GetFileName(originalFile).Length);
|
|
||||||
string roomPath = Path.Combine(originalPath, "Rooms");
|
|
||||||
if (!Directory.Exists(roomPath))
|
|
||||||
Directory.CreateDirectory(roomPath);
|
|
||||||
|
|
||||||
string[] rooms = Directory.GetFiles(roomPath);
|
|
||||||
|
|
||||||
|
//If we find Rooms, we need to copy them.
|
||||||
if (rooms.Length != 0)
|
if (rooms.Length != 0)
|
||||||
{
|
{
|
||||||
string newPath = newFile.Substring(0, newFile.Length - Path.GetFileName(newFile).Length);
|
//Loop through the collection, copying each Room file into the
|
||||||
string newRooms = Path.Combine(newPath, "Rooms");
|
//new Rooms directory within the Realms Room path
|
||||||
if (!Directory.Exists(newRooms))
|
|
||||||
Directory.CreateDirectory(newRooms);
|
|
||||||
|
|
||||||
foreach (string room in rooms)
|
foreach (string room in rooms)
|
||||||
{
|
{
|
||||||
newFile = Path.Combine(newRooms, Path.GetFileName(room));
|
//Get the current filename and it's new Path
|
||||||
File.Copy(room, newFile);
|
string roomFile = Path.GetFileName(room);
|
||||||
File.Delete(room);
|
string roomPath = newZoneRooms;
|
||||||
|
//Copy the current file into the new path.
|
||||||
|
File.Copy(room, Path.Combine(roomPath, roomFile), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File.Delete(originalFile);
|
|
||||||
Directory.Delete(Path.Combine(zoneRoot, zone.Name), true);
|
//All of our Rooms are copied, Zone has been updated.
|
||||||
lstAvailableZones.Items.Remove(lstAvailableZones.SelectedItem);
|
//Update the Realm to give it the Zone, then add it to the
|
||||||
|
//List box, then remove it from the Available listbox
|
||||||
|
_Realm.Zones.Add(zone.Filename);
|
||||||
|
lstRealmMembers.Items.Add(zone.Filename);
|
||||||
|
lstAvailableZones.Items.Remove(zone.Filename);
|
||||||
|
|
||||||
|
//Done with what we needed to do, let's delete the original Zone
|
||||||
|
//and all of its files.
|
||||||
|
Directory.Delete(originalZonePath, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UIRealmControl_FormClosing(object sender, FormClosingEventArgs e)
|
private void UIRealmControl_FormClosing(object sender, FormClosingEventArgs e)
|
||||||
{
|
{
|
||||||
Designer form = (Designer)Program.CurrentEditor;
|
Program.Designer.SaveObject();
|
||||||
form.SaveSelected();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btnRemove_Click(object sender, EventArgs e)
|
private void btnRemove_Click(object sender, EventArgs e)
|
||||||
|
|
|
@ -14,11 +14,16 @@ namespace MudDesigner.MudEngine.UITypeEditors
|
||||||
{
|
{
|
||||||
Realm obj = (Realm)context.Instance;
|
Realm obj = (Realm)context.Instance;
|
||||||
List<string> zones = new List<string>();
|
List<string> zones = new List<string>();
|
||||||
|
|
||||||
|
//Save a copy of the original
|
||||||
|
foreach (string zone in obj.Zones)
|
||||||
|
zones.Add(zone);
|
||||||
|
|
||||||
UIRealmControl ctl = new UIRealmControl(obj);
|
UIRealmControl ctl = new UIRealmControl(obj);
|
||||||
if (ctl.IsDisposed)
|
if (ctl.IsDisposed)
|
||||||
//return the previous zones collection, incase the control error'd out
|
//return the previous zones collection, incase the control error'd out
|
||||||
//we aren't overriding and loosing content.
|
//we aren't overriding and loosing content.
|
||||||
return obj.Zones;
|
return zones;
|
||||||
|
|
||||||
ctl.ShowDialog();
|
ctl.ShowDialog();
|
||||||
|
|
||||||
|
|
|
@ -33,11 +33,11 @@ namespace MudDesigner.MudEngine.UITypeEditors
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Program.CurrentEditor is Designer)
|
if (Program.Designer is Designer)
|
||||||
{
|
{
|
||||||
UIScriptControl control = new UIScriptControl(baseObj);
|
UIScriptControl control = new UIScriptControl(baseObj);
|
||||||
control.Dock = DockStyle.Fill;
|
control.Dock = DockStyle.Fill;
|
||||||
Designer frm = (Designer)Program.CurrentEditor;
|
Designer frm = (Designer)Program.Designer;
|
||||||
//frm.ControlContainer.Panel1.Controls.Clear();
|
//frm.ControlContainer.Panel1.Controls.Clear();
|
||||||
//frm.ControlContainer.Panel1.Controls.Add(control);
|
//frm.ControlContainer.Panel1.Controls.Add(control);
|
||||||
string script = "";
|
string script = "";
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace MudDesigner
|
||||||
{
|
{
|
||||||
static class Program
|
static class Program
|
||||||
{
|
{
|
||||||
public static Form CurrentEditor { get; set; }
|
public static Designer Designer{ get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The main entry point for the application.
|
/// The main entry point for the application.
|
||||||
|
@ -29,8 +29,8 @@ namespace MudDesigner
|
||||||
Application.SetCompatibleTextRenderingDefault(false);
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
|
|
||||||
//Run the toolkit
|
//Run the toolkit
|
||||||
CurrentEditor = new Designer();
|
Designer = new Designer();
|
||||||
Application.Run(CurrentEditor);
|
Application.Run(Designer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue