示例#1
0
        private void ImportCharacter(string fileName)
        {
            try
            {
                Character character;

                if (fileName.ToLower().EndsWith(NEW_CHARACTER_FILE_EXTENSION))
                {
                    character = ImportExport.ImportCharacterNew(fileName, _agsEditor.CurrentGame);
                }
                else
                {
                    character = ImportExport.ImportCharacter272(fileName, _agsEditor.CurrentGame);
                }

                character.ID = _agsEditor.CurrentGame.RootCharacterFolder.GetAllItemsCount();
                AddSingleItem(character);
                // Pretend that character has just changed into the new room
                OnCharacterRoomChanged?.Invoke(this, new CharacterRoomChangedEventArgs(character, -1));
            }
            catch (ApplicationException ex)
            {
                _guiController.ShowMessage("An error occurred importing the character file. The error was: " + Environment.NewLine + Environment.NewLine + ex.Message, MessageBoxIcon.Warning);
            }
            RePopulateTreeView();
        }
示例#2
0
 protected override void ItemCommandClick(string controlID)
 {
     if (controlID == COMMAND_NEW_ITEM)
     {
         Character newItem = new Character();
         newItem.ID           = _agsEditor.CurrentGame.RootCharacterFolder.GetAllItemsCount();
         newItem.ScriptName   = _agsEditor.GetFirstAvailableScriptName("cChar");
         newItem.RealName     = "New character";
         newItem.StartingRoom = -1;
         string newNodeID = AddSingleItem(newItem);
         _guiController.ProjectTree.SelectNode(this, newNodeID);
         ShowOrAddPane(newItem);
     }
     else if (controlID == COMMAND_IMPORT)
     {
         string fileName = _guiController.ShowOpenFileDialog("Select character to import...", CHARACTER_IMPORT_FILE_FILTER);
         if (fileName != null)
         {
             ImportCharacter(fileName);
         }
     }
     else if (controlID == COMMAND_EXPORT)
     {
         string fileName = _guiController.ShowSaveFileDialog("Export character as...", CHARACTER_EXPORT_FILE_FILTER);
         if (fileName != null)
         {
             ExportCharacter(_itemRightClicked, fileName);
         }
     }
     else if (controlID == COMMAND_FIND_ALL_USAGES)
     {
         FindAllUsages findAllUsages = new FindAllUsages(null, null, null, _agsEditor);
         findAllUsages.Find(null, _itemRightClicked.ScriptName);
     }
     else if (controlID == COMMAND_DELETE_ITEM)
     {
         if (MessageBox.Show("Are you sure you want to delete this character? Doing so could break any scripts that refer to characters by number.", "Confirm delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             Character c = _itemRightClicked;
             // For a lack of better solution at the moment, pretend that character leaves current room before being deleted
             int oldRoom = c.StartingRoom;
             c.StartingRoom = -1;
             OnCharacterRoomChanged?.Invoke(this, new CharacterRoomChangedEventArgs(c, oldRoom));
             DeleteSingleItem(_itemRightClicked);
         }
     }
     else if ((!controlID.StartsWith(NODE_ID_PREFIX_FOLDER)) &&
              (controlID != TOP_LEVEL_COMMAND_ID))
     {
         Character chosenItem = _items[controlID];
         ShowOrAddPane(chosenItem);
     }
 }