Ejemplo n.º 1
0
    protected override void Update()
    {
        base.Update();
        if (this.card == null)
        {
            return;
        }
        VoosActor user = voosEngine.FindOneActorUsing(this.card.GetUri());

        // Only allow changing the category if no one is using this card.
        categoryDropdown.gameObject.SetActive(user == null);
    }
Ejemplo n.º 2
0
    public void Populate(ICardModel unassignedCard)
    {
        if (unassignedCard == null || !unassignedCard.IsValid())
        {
            return;
        }

        cardContainer = null;
        card.Populate(unassignedCard, true);
        if (unassignedCard.IsBuiltin())
        {
            codeText.SetText("Duplicate and edit JavaScript");
            trashButton.gameObject.SetActive(false);
            previewButton.gameObject.SetActive(true);
        }
        else
        {
            codeText.SetText("Edit JavaScript");
            previewButton.gameObject.SetActive(false);

            string    behaviorUri  = unassignedCard.GetUnassignedBehaviorItem().behaviorUri;
            VoosActor user         = voosEngine.FindOneActorUsing(behaviorUri);
            string    fromActorLib = actorLib.FindOneActorUsingBehavior(behaviorUri);

            if (user != null)
            {
                trashText.SetText($"Cannot delete - used by actor '{user.GetDisplayName()}'");
                trashButton.interactable = false;
            }
            else if (fromActorLib != null)
            {
                trashText.SetText($"Cannot delete - used by creation library actor '{fromActorLib}'");
                trashButton.interactable = false;
            }
            else
            {
                trashText.SetText($"Remove card");
                trashButton.interactable = true;
            }
            trashButton.gameObject.SetActive(true);
        }
        noPropertiesObject.SetActive(!card.HasAnyProps());
        UpdateAddToSlotButton();
    }
Ejemplo n.º 3
0
    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();
    }