예제 #1
0
    public void Setup(IAssignedPanel model, CardManager cardManager, PanelManager panelManager, DynamicPopup popups)
    {
        this.model        = model;
        this.cardManager  = cardManager;
        this.panelManager = panelManager;
        this.popups       = popups;

        cardPanelUI.headerIcon.sprite = model.GetIcon();
        initialTitle = model.GetTitle();
        cardPanelUI.SetHeaderText(model.GetTitle());
        cardPanelUI.closeButton.onClick.AddListener(DeletePanel);

        cardPanelUI.headerTextInput.onEndEdit.AddListener(OnEditTitle);

        foreach (var slot in model.GetDecks())
        {
            GameObject newSlotObj = Instantiate(cardSlotPrefab, cardPanelUI.deckParent);
            CardDeck   newslot    = newSlotObj.GetComponentInChildren <CardDeck>();
            newslot.Setup(slot);
            newslot.SetColor(model.GetColor());
            string propName = slot.GetPropertyName();
            if (propName != null)
            {
                cardSlotForProperty[propName] = newSlotObj;
            }
        }

        cardPanelUI.headerBackground.color = model.GetColor();

        GameObject propsObject = Instantiate(propertyFieldsPrefab, cardPanelUI.fieldsParent);

        propsObject.transform.SetAsFirstSibling();
        propsLayoutElement = cardPanelUI.fieldsParent.GetComponent <UnityEngine.UI.LayoutElement>();
        cardPropertiesUX   = propsObject.GetComponent <BehaviorUX.CardPropertiesUX>();

        cardPropertiesUX.Setup(model.GetBehavior()?.GetProperties());
        cardPropertiesUX.onValueChanged += (type) =>
        {
            UpdateSlotsVisibility();
        };
        cardPropertiesUX.gameObject.SetActive(cardPropertiesUX.HasAnyProps());

        parentRect = transform.parent.GetComponent <RectTransform>();

        // I don't like this.
        if (GetModel().GetId() == BehaviorCards.GetMiscPanelId())
        {
            cardPanelUI.closeButton.gameObject.SetActive(false);
        }

        UpdateSlotsVisibility();
    }