Example #1
0
        private void btnDuplicate_Click(object sender, EventArgs e)
        {
            if ((lbxAreas.Items.Count > 0) && (lbxAreas.SelectedIndex >= 0))
            {
                //if file exists, rename the file
                string filePath = prntForm._mainDirectory + "\\modules\\" + prntForm.mod.moduleName + "\\areas";
                string filename = prntForm.mod.moduleAreasList[prntForm._selectedLbxAreaIndex];
                if (File.Exists(filePath + "\\" + filename + ".lvl"))
                {
                    try
                    {
                        //rename file
                        File.Copy(filePath + "\\" + filename + ".lvl", filePath + "\\" + filename + "-Copy.lvl");
                        try
                        {
                            //load area
                            Area newArea = new Area();
                            newArea = newArea.loadAreaFile(filePath + "\\" + filename + "-Copy.lvl");
                            if (newArea == null)
                            {
                                MessageBox.Show("returned a null area");
                            }
                            //change area file name in area file object properties
                            newArea.Filename = filename + "-Copy";
                            newArea.saveAreaFile(filePath + "\\" + filename + "-Copy.lvl");

                            prntForm.mod.moduleAreasList.Add(newArea.Filename);
                            refreshListBoxAreas();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("failed to open file: " + ex.ToString());
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString()); // Write error
                    }
                }
                else
                {
                    MessageBox.Show("File: " + filename + ".lvl does not exist in the areas folder");
                }
                refreshListBoxAreas();
            }
        }
Example #2
0
 private void btnRename_Click(object sender, EventArgs e)
 {
     if ((lbxAreas.Items.Count > 0) && (lbxAreas.SelectedIndex >= 0))
     {
         RenameDialog newName = new RenameDialog();
         DialogResult result = newName.ShowDialog();
         if (result == System.Windows.Forms.DialogResult.OK)
         {
             try
             {
                 #region New Area
                 if (prntForm.mod.moduleAreasList[prntForm._selectedLbxAreaIndex] == "new area")
                 {
                     //if file exists, rename the file
                     string filePath = prntForm._mainDirectory + "\\modules\\" + prntForm.mod.moduleName + "\\areas";
                     if (File.Exists(filePath + "\\" + prntForm.mod.moduleAreasList[prntForm._selectedLbxAreaIndex] + ".lvl"))
                     {
                         try
                         {
                             //rename file
                             File.Move(filePath + "\\" + prntForm.mod.moduleAreasList[prntForm._selectedLbxAreaIndex] + ".lvl", filePath + "\\" + newName.RenameText + ".lvl"); // Try to move
                             try
                             {
                                 //load area
                                 Area newArea = new Area();
                                 newArea = newArea.loadAreaFile(filePath + "\\" + newName.RenameText + ".lvl");
                                 if (newArea == null)
                                 {
                                     MessageBox.Show("returned a null area");
                                 }
                                 //change area file name in area file object properties
                                 newArea.Filename = newName.RenameText;
                                 newArea.saveAreaFile(filePath + "\\" + newName.RenameText + ".lvl");
                                 prntForm.mod.moduleAreasList[prntForm._selectedLbxAreaIndex] = newName.RenameText;
                             }
                             catch (Exception ex)
                             {
                                 MessageBox.Show("failed to open file: " + ex.ToString());
                             }
                         }
                         catch (Exception ex)
                         {
                             MessageBox.Show(ex.ToString()); // Write error
                         }
                     }
                     else
                     {
                         prntForm.mod.moduleAreasList[prntForm._selectedLbxAreaIndex] = newName.RenameText;
                     }
                     refreshListBoxAreas();
                 }
                 #endregion
                 #region Existing Area
                 else
                 {
                     DialogResult sure = MessageBox.Show("Are you sure you wish to change the area name and the area file name? (make sure to update any references to this area name such as transitions and scripts)", "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);
                     if (sure == System.Windows.Forms.DialogResult.Yes)
                     {
                         //if file exists, rename the file
                         string filePath = prntForm._mainDirectory + "\\modules\\" + prntForm.mod.moduleName + "\\areas";
                         if (File.Exists(filePath + "\\" + prntForm.mod.moduleAreasList[prntForm._selectedLbxAreaIndex] + ".lvl"))
                         {
                             try
                             {
                                 //rename file
                                 File.Move(filePath + "\\" + prntForm.mod.moduleAreasList[prntForm._selectedLbxAreaIndex] + ".lvl", filePath + "\\" + newName.RenameText + ".lvl"); // Try to move
                                 try
                                 {
                                     //load area
                                     Area newArea = new Area();
                                     newArea = newArea.loadAreaFile(filePath + "\\" + newName.RenameText + ".lvl");
                                     if (newArea == null)
                                     {
                                         MessageBox.Show("returned a null area");
                                     }
                                     //change area file name in area file object properties
                                     newArea.Filename = newName.RenameText;
                                     newArea.saveAreaFile(filePath + "\\" + newName.RenameText + ".lvl");
                                     prntForm.mod.moduleAreasList[prntForm._selectedLbxAreaIndex] = newName.RenameText;
                                 }
                                 catch (Exception ex)
                                 {
                                     MessageBox.Show("failed to open file: " + ex.ToString());
                                 }
                             }
                             catch (Exception ex)
                             {
                                 MessageBox.Show(ex.ToString()); // Write error
                             }
                         }
                         else
                         {
                             prntForm.mod.moduleAreasList[prntForm._selectedLbxAreaIndex] = newName.RenameText;
                         }
                         refreshListBoxAreas();
                     }
                 }
                 #endregion
             }
             catch { }
         }
     }
 }
Example #3
0
 public void loadAreas(string path)
 {
     Area newArea = new Area();
     foreach (string areaName in moduleAreasList)
     {
         try
         {
             newArea = newArea.loadAreaFile(path + areaName + ".level");
             if (newArea == null)
             {
                 MessageBox.Show("returned a null area filling areaList");
             }
             moduleAreasObjects.Add(newArea);
             //MessageBox.Show("open file success");
         }
         catch (Exception ex)
         {
             MessageBox.Show("failed to open all files: " + ex.ToString() + ex.Message);
         }
     }
 }