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.treeExplorer = new System.Windows.Forms.TreeView();
|
||||
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.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator();
|
||||
this.mnuDeleteSelectedObject = new System.Windows.Forms.ToolStripMenuItem();
|
||||
|
@ -86,10 +90,6 @@
|
|||
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();
|
||||
|
@ -453,24 +453,55 @@
|
|||
this.toolStripMenuItem1,
|
||||
this.mnuDeleteSelectedObject});
|
||||
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
|
||||
//
|
||||
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.Click += new System.EventHandler(this.mnuEditObject_Click);
|
||||
//
|
||||
// toolStripMenuItem1
|
||||
//
|
||||
this.toolStripMenuItem1.Name = "toolStripMenuItem1";
|
||||
this.toolStripMenuItem1.Size = new System.Drawing.Size(149, 6);
|
||||
this.toolStripMenuItem1.Size = new System.Drawing.Size(142, 6);
|
||||
//
|
||||
// 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.Click += new System.EventHandler(this.mnuDeleteSelectedObject_Click);
|
||||
//
|
||||
|
@ -513,7 +544,7 @@
|
|||
//
|
||||
this.txtSearch.Name = "txtSearch";
|
||||
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
|
||||
//
|
||||
|
@ -560,37 +591,6 @@
|
|||
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);
|
||||
|
|
|
@ -141,6 +141,69 @@ namespace MudDesigner
|
|||
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>
|
||||
/// Searchs to find what Type the selected TreeNode is, and loads
|
||||
/// that objects into the propertygrid.
|
||||
|
@ -233,7 +296,7 @@ namespace MudDesigner
|
|||
return false;
|
||||
//User hit Yes, so save the object
|
||||
else
|
||||
SaveSelected();
|
||||
SaveObject();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -306,48 +369,21 @@ namespace MudDesigner
|
|||
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 it is a BaseObject (Aquire it's BaseObject.Filename)
|
||||
var obj = (BaseObject)propertyObject.SelectedObject;
|
||||
if (txtSearch.Text == "")
|
||||
return;
|
||||
|
||||
//Filepaths
|
||||
string objectPath = "";
|
||||
string filename = "";
|
||||
|
||||
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);
|
||||
}
|
||||
TreeNode node = FindNode(txtSearch.Text, treeExplorer.Nodes[0]);
|
||||
if (node == null)
|
||||
MessageBox.Show("No results found!", "Mud Designer");
|
||||
else
|
||||
{
|
||||
objectPath = FileManager.GetDataPath(z.Realm, z.Name);
|
||||
filename = Path.Combine(objectPath, z.Filename);
|
||||
}
|
||||
obj.Save(filename);
|
||||
break;
|
||||
}
|
||||
treeExplorer.SelectedNode = node;
|
||||
|
||||
RefreshProjectExplorer();
|
||||
//TODO: Fix objects not loading during search.
|
||||
LoadObject(node);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -417,25 +453,6 @@ namespace MudDesigner
|
|||
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)
|
||||
{
|
||||
//Check if we are trying to delete the root node
|
||||
|
@ -461,6 +478,8 @@ namespace MudDesigner
|
|||
{
|
||||
Realm r = new Realm();
|
||||
string filename = "";
|
||||
//If the user selected the file, then we need to get the realm
|
||||
//filename differently
|
||||
if (IsFile)
|
||||
{
|
||||
string realmName = selectedNode.Parent.Parent.Parent.Text;
|
||||
|
@ -473,9 +492,13 @@ namespace MudDesigner
|
|||
filename = Path.Combine(realmName, realmName + ".realm");
|
||||
filename = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Realms), filename);
|
||||
}
|
||||
//Finalize the filename of the realm
|
||||
filename = Path.Combine(Application.StartupPath, filename);
|
||||
|
||||
//Load the realm that this Zone belongs to
|
||||
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)
|
||||
r.Zones.Remove(selectedNode.Parent.Text);
|
||||
else
|
||||
|
@ -483,6 +506,8 @@ namespace MudDesigner
|
|||
}
|
||||
|
||||
//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)
|
||||
Directory.Delete(selectedNode.Parent.FullPath, true);
|
||||
else
|
||||
|
@ -506,7 +531,7 @@ namespace MudDesigner
|
|||
if (obj.Name == "New " + obj.GetType().Name)
|
||||
return;
|
||||
}
|
||||
SaveSelected();
|
||||
SaveObject();
|
||||
IsSaved = true;
|
||||
RefreshProjectExplorer();
|
||||
}
|
||||
|
@ -524,6 +549,10 @@ namespace MudDesigner
|
|||
|
||||
private void treeExplorer_DoubleClick(object sender, EventArgs e)
|
||||
{
|
||||
if (treeExplorer.SelectedNode.Text == "Project")
|
||||
return;
|
||||
if (Path.GetExtension(treeExplorer.SelectedNode.Text) == "")
|
||||
return;
|
||||
if (CheckSavedState())
|
||||
LoadObject(treeExplorer.SelectedNode);
|
||||
}
|
||||
|
@ -543,5 +572,11 @@ namespace MudDesigner
|
|||
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);
|
||||
FileManager.Save(filename, this);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return this.Name;
|
||||
|
|
|
@ -29,28 +29,16 @@ namespace MudDesigner.MudEngine.GameObjects.Environment
|
|||
/// </summary>
|
||||
/// <param name="zoneName"></param>
|
||||
/// <returns></returns>
|
||||
public Zone GetZone(string zoneName)
|
||||
public Zone GetZone(string filename)
|
||||
{
|
||||
string zoneFilename = "";
|
||||
//correct the zonename if needed
|
||||
if (!zoneName.EndsWith(".zone"))
|
||||
zoneFilename = zoneName + ".zone";
|
||||
else
|
||||
{
|
||||
zoneName = Path.GetFileNameWithoutExtension(zoneName);
|
||||
zoneFilename = zoneName;
|
||||
}
|
||||
var filterQuery =
|
||||
from zone in Zones
|
||||
where zone == filename
|
||||
select zone;
|
||||
|
||||
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();
|
||||
z = (Zone)FileManager.Load(zoneFilename, z);
|
||||
return z;
|
||||
}
|
||||
foreach (var zone in filterQuery)
|
||||
return (Zone)z.Load(zone); ;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -69,11 +69,29 @@ namespace MudDesigner.MudEngine.GameObjects.Environment
|
|||
/// </summary>
|
||||
/// <param name="RoomName"></param>
|
||||
/// <returns></returns>
|
||||
public Room GetRoom(string RoomName)
|
||||
public Room GetRoomByName(string name)
|
||||
{
|
||||
var filterQuery =
|
||||
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;
|
||||
|
||||
foreach (var room in filterQuery)
|
||||
|
|
|
@ -20,13 +20,12 @@ namespace MudDesigner.MudEngine.UITypeEditors
|
|||
private Realm _Realm;
|
||||
private string realmPath = "";
|
||||
string projectPath = "";
|
||||
private List<string> zones;
|
||||
|
||||
public List<string> Zones
|
||||
{
|
||||
get
|
||||
{
|
||||
return zones;
|
||||
return _Realm.Zones;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,44 +34,47 @@ namespace MudDesigner.MudEngine.UITypeEditors
|
|||
{
|
||||
InitializeComponent();
|
||||
|
||||
//Store the supplied Realm loaded by the user
|
||||
_Realm = realm;
|
||||
zones = new List<string>();
|
||||
|
||||
projectPath = Path.Combine(Application.StartupPath, "Project");
|
||||
realmPath = Path.Combine(projectPath, "Realms");
|
||||
realmPath = Path.Combine(realmPath, _Realm.Name);
|
||||
//Setup our paths
|
||||
projectPath = FileManager.GetDataPath(SaveDataTypes.Root);
|
||||
realmPath = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Realms), _Realm.Name);
|
||||
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();
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (string zone in _Realm.Zones)
|
||||
{
|
||||
zones.Add(zone);
|
||||
}
|
||||
//If the Zones directory has not been created yet within the Realm, we need to create it.
|
||||
if (!Directory.Exists(realmZones))
|
||||
Directory.CreateDirectory(realmZones);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
lstRealmMembers.Items.Add(zone);
|
||||
}
|
||||
|
||||
//Create the Root Zone directory if it does not exist
|
||||
string zonePath = FileManager.GetDataPath(SaveDataTypes.Zones);
|
||||
if (!Directory.Exists(zonePath))
|
||||
Directory.CreateDirectory(zonePath);
|
||||
|
||||
string[] zones = Directory.GetFiles(zonePath, "*.zone", SearchOption.AllDirectories);
|
||||
|
||||
foreach (string zone in zones)
|
||||
//Add all of the existing Un-owned Zones into the Available Zones listbox
|
||||
foreach (string zone in Directory.GetFiles(zonePath, "*.zone", SearchOption.AllDirectories))
|
||||
{
|
||||
Zone z = new Zone();
|
||||
z = (Zone)FileManager.Load(zone, z);
|
||||
lstAvailableZones.Items.Add(z.Filename);
|
||||
//place the filename into the Available Zones.
|
||||
lstAvailableZones.Items.Add(Path.GetFileName(zone));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,78 +86,67 @@ namespace MudDesigner.MudEngine.UITypeEditors
|
|||
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();
|
||||
//Set the paths
|
||||
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 = (Zone)zone.Load(originalFilename);
|
||||
zone.Realm = _Realm.Name;
|
||||
FileManager.Save(file, zone);
|
||||
}
|
||||
else
|
||||
zone = null;
|
||||
}
|
||||
//Save the Zone changes into the new Realm path.
|
||||
//We are done with modifying the Zone so we are free to delete it
|
||||
//after we are done moving all of its Rooms.
|
||||
zone.Save(newFilename);
|
||||
|
||||
//check if we have a zone
|
||||
if (zone == null)
|
||||
{
|
||||
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);
|
||||
//Check if the original Zone contained Rooms.
|
||||
string[] rooms = Directory.GetFiles(originalZoneRooms, "*.room");
|
||||
|
||||
//If we find Rooms, we need to copy them.
|
||||
if (rooms.Length != 0)
|
||||
{
|
||||
string newPath = newFile.Substring(0, newFile.Length - Path.GetFileName(newFile).Length);
|
||||
string newRooms = Path.Combine(newPath, "Rooms");
|
||||
if (!Directory.Exists(newRooms))
|
||||
Directory.CreateDirectory(newRooms);
|
||||
|
||||
//Loop through the collection, copying each Room file into the
|
||||
//new Rooms directory within the Realms Room path
|
||||
foreach (string room in rooms)
|
||||
{
|
||||
newFile = Path.Combine(newRooms, Path.GetFileName(room));
|
||||
File.Copy(room, newFile);
|
||||
File.Delete(room);
|
||||
//Get the current filename and it's new Path
|
||||
string roomFile = Path.GetFileName(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);
|
||||
lstAvailableZones.Items.Remove(lstAvailableZones.SelectedItem);
|
||||
|
||||
//All of our Rooms are copied, Zone has been updated.
|
||||
//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)
|
||||
{
|
||||
Designer form = (Designer)Program.CurrentEditor;
|
||||
form.SaveSelected();
|
||||
Program.Designer.SaveObject();
|
||||
}
|
||||
|
||||
private void btnRemove_Click(object sender, EventArgs e)
|
||||
|
|
|
@ -14,11 +14,16 @@ namespace MudDesigner.MudEngine.UITypeEditors
|
|||
{
|
||||
Realm obj = (Realm)context.Instance;
|
||||
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);
|
||||
if (ctl.IsDisposed)
|
||||
//return the previous zones collection, incase the control error'd out
|
||||
//we aren't overriding and loosing content.
|
||||
return obj.Zones;
|
||||
return zones;
|
||||
|
||||
ctl.ShowDialog();
|
||||
|
||||
|
|
|
@ -33,11 +33,11 @@ namespace MudDesigner.MudEngine.UITypeEditors
|
|||
return null;
|
||||
}
|
||||
|
||||
if (Program.CurrentEditor is Designer)
|
||||
if (Program.Designer is Designer)
|
||||
{
|
||||
UIScriptControl control = new UIScriptControl(baseObj);
|
||||
control.Dock = DockStyle.Fill;
|
||||
Designer frm = (Designer)Program.CurrentEditor;
|
||||
Designer frm = (Designer)Program.Designer;
|
||||
//frm.ControlContainer.Panel1.Controls.Clear();
|
||||
//frm.ControlContainer.Panel1.Controls.Add(control);
|
||||
string script = "";
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace MudDesigner
|
|||
{
|
||||
static class Program
|
||||
{
|
||||
public static Form CurrentEditor { get; set; }
|
||||
public static Designer Designer{ get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
|
@ -29,8 +29,8 @@ namespace MudDesigner
|
|||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
|
||||
//Run the toolkit
|
||||
CurrentEditor = new Designer();
|
||||
Application.Run(CurrentEditor);
|
||||
Designer = new Designer();
|
||||
Application.Run(Designer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue