public void Open(string openCardUri = null, VoosEngine.BehaviorLogItem?error = null) { gameObject.SetActive(true); resourceClaimer.Unclaim(); isNewCard = false; this.error = null; // Which card are we editing ? if (openCardUri != null && behaviorSystem.IsBehaviorUriValid(openCardUri)) { cardUri = openCardUri; this.error = error; } else if (cardUri == null || !behaviorSystem.IsBehaviorUriValid(cardUri)) { UnassignedBehavior newBehavior = behaviorSystem.CreateNewBehavior( CodeTemplates.MISC, BehaviorCards.GetMiscMetadataJson()); cardUri = newBehavior.GetBehaviorUri(); isNewCard = true; } resourceClaimer.Claim(UnassignedBehavior.GetClaimResourceId(cardUri), OnClaimStatusChanged); }
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(); }