// Deletes the particle effect with that ID. public void DeleteParticleEffect(string particleEffectId) { Sojo sojo = sojoSystem.GetSojoById(particleEffectId); if (sojo == null) { return; } ClaimableUndoUtil.ClaimableUndoItem undoItem = new ClaimableUndoUtil.ClaimableUndoItem(); undoItem.resourceId = PFX_CLAIM_PREFIX + particleEffectId; undoItem.resourceName = sojo.name; undoItem.label = $"Deleting particle effect {sojo.name}"; undoItem.cannotDoReason = () => { return(null); }; undoItem.cannotUndoReason = () => { return(null); }; undoItem.doIt = () => { sojoSystem.DeleteSojo(particleEffectId); }; undoItem.undo = () => { sojoSystem.PutSojo(sojo); }; ClaimableUndoUtil.PushUndoForResource(undoStack, claimKeeper, undoItem); }
// Saves a particle effect. If the ID corresponds to an existing particle effect, that effect will // be overwritten; if not, a new particle effect will be created. public void PutParticleEffect(ParticleEffect particleEffect) { ParticleEffect prevEffect = GetParticleEffect(particleEffect.id); ClaimableUndoUtil.ClaimableUndoItem undoItem = new ClaimableUndoUtil.ClaimableUndoItem(); undoItem.resourceId = undoItem.resourceId = ParticleEffectSystem.PFX_CLAIM_PREFIX + particleEffect.id; undoItem.resourceName = particleEffect.name; if (prevEffect != null) { undoItem.label = $"Change particle effect {prevEffect.name}"; } else { undoItem.label = $"Add particle effect {particleEffect.name}"; } undoItem.doIt = () => { sojoSystem.PutSojo(new Sojo(particleEffect.id, particleEffect.name, SojoType.ParticleEffect, JsonUtility.ToJson(particleEffect.content))); }; undoItem.undo = () => { if (prevEffect != null) { sojoSystem.PutSojo(new Sojo(prevEffect.id, prevEffect.name, SojoType.ParticleEffect, JsonUtility.ToJson(prevEffect.content))); } else { sojoSystem.DeleteSojo(particleEffect.id); } }; undoItem.cannotDoReason = () => { return(null); }; ClaimableUndoUtil.PushUndoForResource(undoStack, claimKeeper, undoItem); }
public void Setup() { Util.FindIfNotSet(this, ref behaviorSystem); Util.FindIfNotSet(this, ref claimKeeper); Util.FindIfNotSet(this, ref undoStack); Util.FindIfNotSet(this, ref voosEngine); Util.FindIfNotSet(this, ref popups); newCardUI.newCardButton.onClick.AddListener(() => { string category = newCardCategoryOptions[newCardUI.newCardCategoryDropdown.value].text; AddNewCard(category); }); cardLibraryUI.closeButton.onClick.AddListener(Close); cardLibraryUI.inputField.onValueChanged.AddListener(OnInputFieldChanged); cardLibraryUI.clearSearchButton.onClick.AddListener(ClearSearch); cardLibraryUI.categoryDropdown.onValueChanged.AddListener((v) => { MatchNewCardCategoryToFilter(); UpdateCards(); }); cardDetail = Instantiate(cardDetailPrefab); cardDetail.Setup(parentRect); cardDetail.onCodeCard += (model, _, container) => { if (!model.IsValid()) { return; } if (model.IsBuiltin()) { // Not embedded, need to copy first string newBehaviorUri = model.MakeCopy().GetUri(); onCodeRequest?.Invoke(newBehaviorUri); } else { onCodeRequest?.Invoke(model.GetUri()); } }; cardDetail.onPreviewCard += (model) => { onCodeRequest?.Invoke(model.GetUri()); }; cardDetail.onTrashCard += (model, _) => { if (!model.IsValid()) { return; } ClaimableUndoUtil.ClaimableUndoItem undoItem = new ClaimableUndoUtil.ClaimableUndoItem(); Behaviors.Behavior behavior = model.GetUnassignedBehaviorItem().GetBehavior(); string uri = model.GetUri(); string id = model.GetId(); undoItem.resourceId = UnassignedBehavior.GetClaimResourceId(id); undoItem.resourceName = model.GetTitle(); undoItem.label = $"Delete {model.GetTitle()}"; undoItem.doIt = () => { behaviorSystem.DeleteBehavior(id); }; undoItem.undo = () => { behaviorSystem.PutBehavior(id, behavior); }; undoItem.cannotDoReason = () => { if (voosEngine.FindOneActorUsing(uri) != null) { return("One or more actors are using this card."); } return(null); }; ClaimableUndoUtil.PushUndoForResource(undoStack, claimKeeper, undoItem); }; behaviorSystem.onBehaviorPut += OnBehaviorPut; behaviorSystem.onBehaviorDelete += OnBehaviorDelete; #if USE_STEAMWORKS uploadDialog = Instantiate(uploadDialogPrefab); uploadDialog.Setup(); workshopMenu = Instantiate(workshopMenuPrefab); workshopMenu.Setup(); #endif cardPackPicker = Instantiate(cardPackPickerPrefab); cardLibraryUI.selectionDoneButton.onClick.AddListener(() => { Debug.Assert(selection != null); selection.selectionFinishedCallback(selection.selectedCards); EndSelection(); }); cardLibraryUI.selectionCancelButton.onClick.AddListener(() => { EndSelection(); }); #if USE_STEAMWORKS cardLibraryUI.exportDropdown.SetOptions(new List <string>() { EXPORT_TO_DISK, EXPORT_TO_WORKSHOP, UPDATE_WORKSHOP_PACK }); #else // cardLibraryUI.exportDropdown.SetOptions(new List<string>() { // EXPORT_TO_DISK // }); cardLibraryUI.exportButton.onClick.AddListener(() => StartSelection(OnFinishSelectionForLocal)); #endif cardLibraryUI.exportDropdown.onOptionClicked += (value) => { if (value == EXPORT_TO_DISK) { StartSelection(OnFinishSelectionForLocal); } #if USE_STEAMWORKS else if (value == UPDATE_WORKSHOP_PACK) { cardPackPicker.Open((res) => { if (res.IsEmpty()) { return; } StartSelection((list) => OnFinishSelectionForWorkshop(list, res), res); }); } else { StartSelection(OnFinishSelectionForWorkshop, Util.Maybe <ulong> .CreateEmpty()); } #endif }; #if USE_STEAMWORKS cardLibraryUI.importDropdown.SetOptions(new List <string>() { IMPORT_FROM_DISK, IMPORT_FROM_WORKSHOP }); #else cardLibraryUI.importButton.onClick.AddListener(ImportLocal); // cardLibraryUI.importDropdown.SetOptions(new List<string>() { // IMPORT_FROM_DISK // }); #endif cardLibraryUI.importDropdown.onOptionClicked += (value) => { if (value == IMPORT_FROM_DISK) { ImportLocal(); } else { workshopMenu.Open(); } }; PopulateCards(); }