public override void PropertyChanged(string propertyName, object oldValue) { Character itemBeingEdited = ((CharacterEditor)_guiController.ActivePane.Control).ItemToEdit; if (propertyName == Character.PROPERTY_NAME_SCRIPTNAME) { bool nameInUse = _agsEditor.CurrentGame.IsScriptNameAlreadyUsed(itemBeingEdited.ScriptName, itemBeingEdited); if (itemBeingEdited.ScriptName.StartsWith("c") && itemBeingEdited.ScriptName.Length > 1) { nameInUse |= _agsEditor.CurrentGame.IsScriptNameAlreadyUsed(itemBeingEdited.ScriptName.Substring(1).ToUpper(), itemBeingEdited); } if (nameInUse) { _guiController.ShowMessage("This script name is already used by another item.", MessageBoxIcon.Warning); itemBeingEdited.ScriptName = (string)oldValue; } else { OnItemIDChanged(itemBeingEdited); OnCharacterIDChanged?.Invoke(this, new CharacterIDChangedEventArgs(itemBeingEdited, itemBeingEdited.ID)); } } else if (propertyName == Character.PROPERTY_NAME_STARTINGROOM) { if (OnCharacterRoomChanged != null) { int oldRoom = (int)oldValue; OnCharacterRoomChanged(this, new CharacterRoomChangedEventArgs(itemBeingEdited, oldRoom)); } } }
private void DeleteCharacter(Character character) { int removingID = character.ID; foreach (Character item in _agsEditor.CurrentGame.RootCharacterFolder.AllItemsFlat) { if (item.ID > removingID) { item.ID--; OnCharacterIDChanged?.Invoke(this, new CharacterIDChangedEventArgs(item, item.ID + 1)); } } ContentDocument document; if (_documents.TryGetValue(character, out document)) { _guiController.RemovePaneIfExists(document); _documents.Remove(character); } }
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 == COMMAND_CHANGE_ID) { int oldNumber = _itemRightClicked.ID; int newNumber = Factory.GUIController.ShowChangeObjectIDDialog("Character", oldNumber, 0, _items.Count - 1); if (newNumber < 0) { return; } foreach (var obj in _items) { if (obj.Value.ID == newNumber) { obj.Value.ID = oldNumber; break; } } _itemRightClicked.ID = newNumber; GetFlatList().Swap(oldNumber, newNumber); OnItemIDChanged(_itemRightClicked); OnCharacterIDChanged?.Invoke(this, new CharacterIDChangedEventArgs(_itemRightClicked, oldNumber)); } else if ((!controlID.StartsWith(NODE_ID_PREFIX_FOLDER)) && (controlID != TOP_LEVEL_COMMAND_ID)) { Character chosenItem = _items[controlID]; ShowOrAddPane(chosenItem); } }