Designer:
- Re-wrote the Object Delete code. Reduced the code by 52% and increased readability. - Added additional search criteria to GetNodeType() - Removed the Application from running within a Try/Catch as it made debugging difficult.
This commit is contained in:
parent
a98e2bc069
commit
af4dc2ad7a
2 changed files with 49 additions and 86 deletions
|
@ -82,6 +82,20 @@ namespace MudDesigner
|
||||||
//The provided nodes parent node is aquired so we can
|
//The provided nodes parent node is aquired so we can
|
||||||
//find if we can get it's current type.
|
//find if we can get it's current type.
|
||||||
TreeNode parentNode = node.Parent;
|
TreeNode parentNode = node.Parent;
|
||||||
|
|
||||||
|
//Root searching.
|
||||||
|
switch (node.Text)
|
||||||
|
{
|
||||||
|
case "Currencies":
|
||||||
|
return ObjectType.Currency;
|
||||||
|
case "Realms":
|
||||||
|
return ObjectType.Realm;
|
||||||
|
case "Zones":
|
||||||
|
if (parentNode.Text == "Realms")
|
||||||
|
return ObjectType.ZoneWithinRealm;
|
||||||
|
else
|
||||||
|
return ObjectType.ZoneRoot;
|
||||||
|
}
|
||||||
|
|
||||||
//switch is only for ProjectInfo, Currency, un-owned Zones & Rooms
|
//switch is only for ProjectInfo, Currency, un-owned Zones & Rooms
|
||||||
switch (parentNode.Text)
|
switch (parentNode.Text)
|
||||||
|
@ -92,6 +106,13 @@ namespace MudDesigner
|
||||||
break;
|
break;
|
||||||
case "Currencies":
|
case "Currencies":
|
||||||
return ObjectType.Currency;
|
return ObjectType.Currency;
|
||||||
|
case "Realms":
|
||||||
|
return ObjectType.Realm;
|
||||||
|
case "Zones":
|
||||||
|
if ((parentNode.Parent.Parent != null) && (parentNode.Parent.Parent.Text == "Realms"))
|
||||||
|
return ObjectType.ZoneWithinRealm;
|
||||||
|
else
|
||||||
|
return ObjectType.ZoneRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Basic Root items where not found, do a deeper search now.
|
//Basic Root items where not found, do a deeper search now.
|
||||||
|
@ -425,99 +446,48 @@ namespace MudDesigner
|
||||||
}
|
}
|
||||||
|
|
||||||
DialogResult result;
|
DialogResult result;
|
||||||
ObjectType objectType = new ObjectType();
|
|
||||||
|
|
||||||
//Check if we are deleting a realm or zone, if so inform the user that
|
|
||||||
//all zones/rooms within the object will be deleted as well.
|
|
||||||
string fullPath = treeExplorer.SelectedNode.FullPath;
|
|
||||||
TreeNode selectedNode = treeExplorer.SelectedNode;
|
TreeNode selectedNode = treeExplorer.SelectedNode;
|
||||||
|
bool IsFile = true;
|
||||||
|
|
||||||
if (fullPath.Contains("Realms") || fullPath.Contains("Zones"))
|
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);
|
||||||
{
|
|
||||||
//ask if we want to delete this
|
|
||||||
result = MessageBox.Show("Are you sure you want to delete"
|
|
||||||
+ treeExplorer.SelectedNode.Text + "?\nAll Rooms or Zones within this item will be deleted!", "Mud Designer", MessageBoxButtons.YesNo);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
//ask if we want to delete this
|
|
||||||
result = MessageBox.Show("Are you sure you want to delete"
|
|
||||||
+ treeExplorer.SelectedNode.Text + "?", "Mud Designer", MessageBoxButtons.YesNo);
|
|
||||||
|
|
||||||
//User hit no, cancel
|
//User hit no, cancel
|
||||||
if (result == DialogResult.No)
|
if (result == DialogResult.No)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//Find out what we are deleting
|
//Check if the object is a Zone owned by a Realm.
|
||||||
if (Path.GetExtension(fullPath) == "")
|
//If so, remove the zone from the realms zone collection
|
||||||
|
if (GetNodeType(selectedNode) == ObjectType.ZoneWithinRealm)
|
||||||
{
|
{
|
||||||
if (selectedNode.Text == "Zones")
|
Realm r = new Realm();
|
||||||
objectType = ObjectType.Zone;
|
string filename = "";
|
||||||
else if (selectedNode.Text == "Rooms")
|
if (IsFile)
|
||||||
objectType = ObjectType.Room;
|
|
||||||
}
|
|
||||||
else if (Path.GetExtension(fullPath) == ".Room")
|
|
||||||
{
|
|
||||||
objectType = ObjectType.Room;
|
|
||||||
}
|
|
||||||
else if (Path.GetExtension(fullPath) == "Zone")
|
|
||||||
{
|
|
||||||
objectType = ObjectType.Zone;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (objectType == ObjectType.Zone)
|
|
||||||
{
|
|
||||||
Zone z = new Zone();
|
|
||||||
string filename = Path.Combine(Application.StartupPath, treeExplorer.SelectedNode.FullPath);
|
|
||||||
if (Path.GetExtension(treeExplorer.SelectedNode.FullPath) == "")
|
|
||||||
{
|
{
|
||||||
string[] zone = Directory.GetFiles(filename, "*.zone");
|
string realmName = selectedNode.Parent.Parent.Parent.Text;
|
||||||
if (zone.Length != 0)
|
filename = Path.Combine(realmName, realmName + ".realm");
|
||||||
{
|
filename = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Realms), filename);
|
||||||
filename = zone[0];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Directory.Delete(treeExplorer.SelectedNode.FullPath, true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
z = (Zone)FileManager.Load(filename, z);
|
else
|
||||||
if (z.Realm != "")
|
{
|
||||||
{
|
string realmName = selectedNode.Parent.Parent.Text;
|
||||||
string projectPath = Path.Combine(Application.StartupPath, "Project");
|
filename = Path.Combine(realmName, realmName + ".realm");
|
||||||
string[] files = Directory.GetFiles(Path.Combine(projectPath, "Realms"), "*.realm", SearchOption.AllDirectories);
|
filename = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Realms), filename);
|
||||||
|
}
|
||||||
|
filename = Path.Combine(Application.StartupPath, filename);
|
||||||
|
|
||||||
foreach (string file in files)
|
r = (Realm)r.Load(filename);
|
||||||
{
|
if (IsFile)
|
||||||
Realm r = new Realm();
|
r.Zones.Remove(selectedNode.Parent.Text);
|
||||||
r = (Realm)FileManager.Load(file, r);
|
else
|
||||||
if (r.Name == z.Realm)
|
r.Zones.Remove(selectedNode.Text);
|
||||||
{
|
|
||||||
r.Zones.Remove(z.Filename);
|
|
||||||
FileManager.Save(file, r);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}//end if(object is zone)
|
|
||||||
else if (objectType == ObjectType.Room)
|
|
||||||
{
|
|
||||||
//TODO Delete rooms from owning zone
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Its a directory to delete if we have no extension assigned to it
|
//Delete the object.
|
||||||
if (Path.GetExtension(treeExplorer.SelectedNode.FullPath) == "")
|
if (IsFile)
|
||||||
{
|
Directory.Delete(selectedNode.Parent.FullPath, true);
|
||||||
Directory.Delete(Path.Combine(Application.StartupPath, treeExplorer.SelectedNode.FullPath), true);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
Directory.Delete(selectedNode.FullPath, true);
|
||||||
string filename = Path.GetFileName(treeExplorer.SelectedNode.FullPath);
|
|
||||||
fullPath = treeExplorer.SelectedNode.FullPath;
|
|
||||||
string deletePath = fullPath.Substring(0, fullPath.Length - filename.Length);
|
|
||||||
File.Delete(Path.Combine(Application.StartupPath, treeExplorer.SelectedNode.FullPath));
|
|
||||||
Directory.Delete(Path.Combine(Application.StartupPath, deletePath), true);
|
|
||||||
}
|
|
||||||
//Just incase we have the zone or the realm selected that the zone belonged too.
|
//Just incase we have the zone or the realm selected that the zone belonged too.
|
||||||
//users can re-save the current realm and if it contained the zone we just deleted
|
//users can re-save the current realm and if it contained the zone we just deleted
|
||||||
//the zone will be still be saved as part of the realm.
|
//the zone will be still be saved as part of the realm.
|
||||||
|
|
|
@ -29,15 +29,8 @@ namespace MudDesigner
|
||||||
Application.SetCompatibleTextRenderingDefault(false);
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
|
|
||||||
//Run the toolkit
|
//Run the toolkit
|
||||||
try
|
|
||||||
{
|
|
||||||
CurrentEditor = new Designer();
|
CurrentEditor = new Designer();
|
||||||
Application.Run(CurrentEditor);
|
Application.Run(CurrentEditor);
|
||||||
}
|
|
||||||
catch (Exception msg)
|
|
||||||
{
|
|
||||||
MessageBox.Show("Critical error!\n\n" + msg + "\n\nMud Designer shut down occured.", "Mud Designer", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue