Пример #1
0
    private VisualElement CreateItemSelectionButton(BaseItem baseItem)
    {
        VisualElement visualElement = new VisualElement();
        Button        button        = new Button();

        button.style.height = 50;
        button.style.width  = 50;
        button.text         = string.Empty;

        Sprite icon = baseItem.icon;

        button.style.backgroundImage = new StyleBackground(icon?icon.texture:null);
        button.style.alignSelf       = new StyleEnum <Align>(Align.Center);
        Label label = new Label {
            text = baseItem.name
        };

        label.style.alignSelf = new StyleEnum <Align>(Align.Center);

        visualElement.Add(button);
        visualElement.Add(label);
        button.clicked += () => SelectItem(baseItem);

        Manipulator manipulator = new ContextualMenuManipulator(
            contextualMenuPopulateEvent =>
            AddContextMenuOptions(
                contextualMenuPopulateEvent,
                new []
        {
            new Tuple <string, Action>("ChangeID", () => ChangeItemName(baseItem)),
            new Tuple <string, Action>("Delete", () => DestroyItem(baseItem))
        }
                ))
        {
            target = button
        };

        button.AddManipulator(manipulator);
        return(visualElement);
    }
Пример #2
0
    private VisualElement CreateProductSelectionButton(BaseProduct baseProduct, Action <BaseProduct> OnProductSelected, Tuple <string, Action>[] contextualMenuOptions)
    {
        VisualElement visualElement = new VisualElement();
        Button        button        = new Button();

        button.style.height    = 50;
        button.style.width     = 50;
        button.text            = string.Empty;
        button.style.alignSelf = new StyleEnum <Align>(Align.Center);
        Sprite icon = baseProduct.Icon;

        button.style.backgroundImage = new StyleBackground(icon?icon.texture:null);
        Label label = new Label {
            text = RemoveUntilFirstPoint(baseProduct.name)
        };

        label.style.alignSelf  = new StyleEnum <Align>(Align.Center);
        button.style.alignSelf = new StyleEnum <Align>(Align.Center);

        visualElement.Add(button);
        visualElement.Add(label);
        button.clicked += () => OnProductSelected.Invoke(baseProduct);

        if (contextualMenuOptions == null)
        {
            return(visualElement);
        }


        Manipulator manipulator = new ContextualMenuManipulator(contextualMenuPopulateEvent => AddContextMenuOptions(contextualMenuPopulateEvent.menu, contextualMenuOptions))
        {
            target = button
        };

        button.AddManipulator(manipulator);

        return(visualElement);
    }
Пример #3
0
    private void RenderCatalogsPanel()
    {
        VisualElement body = rootVisualElement.Q <VisualElement>("body");

        body.Clear();
        catalogsVisualTree.CloneTree(body);

        ListView listView = body.Q <ListView>("CatalogsList");

        List <BaseCatalog> catalogs = new List <BaseCatalog>(MarketManager.catalogs);

        catalogs.Sort(NameComparer);
        for (int i = 0; i < catalogs.Count; i++)
        {
            Button button = new Button {
                text = catalogs[i].name
            };
            int index = i;
            button.clicked += () => OnCatalogSelected(catalogs[index]);

            button.AddManipulator(
                new ContextualMenuManipulator(
                    x =>
                    AddContextMenuOptions(
                        x.menu,
                        new []
            {
                new Tuple <string, Action>("ChangeID", () => ChangeCatalogName(catalogs[index])),
                new Tuple <string, Action>("Delete", () => DestroyCatalog(catalogs[index])),
            })));
            listView.Add(button);
        }

        Button newCatalogButton = new Button {
            text = "+"
        };

        newCatalogButton.clicked        += CreateNewCatalogRequest;
        newCatalogButton.style.width     = 25;
        newCatalogButton.style.height    = 25;
        newCatalogButton.style.alignSelf = new StyleEnum <Align>(Align.Center);
        listView.Add(newCatalogButton);

        ListView catalogContent = body.Q <ListView>("LeftContent");

        catalogContent.style.flexGrow = 1;
        catalogContent.contentContainer.style.flexDirection = new StyleEnum <FlexDirection>(FlexDirection.Row);
        catalogContent.contentContainer.style.flexWrap      = new StyleEnum <Wrap>(Wrap.Wrap);

        Label label = body.Q <Label>("CurrentCatalogLabel");

        if (_selectedCatalog != null)
        {
            label.text = _selectedCatalog.name;
            List <BaseProduct> baseProducts = new List <BaseProduct>(_selectedCatalog.Products);
            baseProducts.Sort(NameComparer);
            for (int i = 0; i < baseProducts.Count; i++)
            {
                int           localIndex    = i;
                VisualElement prodSelection = CreateProductSelectionButton(
                    baseProducts[i],
                    baseProduct => RemoveFrom(baseProduct, _selectedCatalog),
                    new []
                {
                    new Tuple <string, Action>("Preview", () => PreviewProduct(baseProducts[localIndex])),
                    new Tuple <string, Action>("Edit", () => GoToProductEdit(baseProducts[localIndex])),
                    new Tuple <string, Action>("Delete", () => DestroyProduct(baseProducts[localIndex]))
                });
                catalogContent.Add(prodSelection);
            }
        }
        else
        {
            label.text = "-";
        }

        #region SelectionList

        GetProductNamesAndTypes(out List <Type> types, out List <string> names);
        ListView typeSelectionList = body.Q <ListView>("TypesList");

        Button allButton = new Button {
            text = "Select All"
        };
        allButton.style.width = 70;
        allButton.clicked    += () => OnAllCategorySelected(selectedProductCategories, names);

        FillListWithToggle(names, "Product", selectedProductCategories, typeSelectionList, OnProductTypeSelected);
        typeSelectionList.contentContainer.Insert(0, allButton);
        typeSelectionList.Insert(0, allButton);

        #endregion

        #region Preview
        if (_selectedPreviewProduct != null)
        {
            VisualElement selectionRender = body.Q <VisualElement>("Right");

            selectionRender.style.paddingLeft   = 5;
            selectionRender.style.paddingRight  = 5;
            selectionRender.style.paddingTop    = 5;
            selectionRender.style.paddingBottom = 5;

            Button closeButton = new Button()
            {
                text = "X"
            };
            closeButton.clicked += () =>
            {
                _selectedPreviewProduct = null;
                Render();
            };
            closeButton.style.width  = 20;
            closeButton.style.height = 20;

            scriptableObjectEdit_View.CloneTree(selectionRender);
            Image          icon     = new Image();
            IMGUIContainer soRender = selectionRender.Q <IMGUIContainer>("Render");
            icon.style.alignSelf       = new StyleEnum <Align>(Align.Center);
            icon.style.height          = 100;
            icon.style.width           = 100;
            icon.style.backgroundColor = new Color(.25f, .25f, .25f);
            icon.style.marginTop       = 10;
            icon.style.marginBottom    = 10;

            selectionRender.Insert(0, icon);
            selectionRender.Insert(0, closeButton);

            if (_selectedPreviewProduct != null)
            {
                Editor editor = Editor.CreateEditor(_selectedPreviewProduct);
                soRender.onGUIHandler = () => editor.OnInspectorGUI();
                if (_selectedPreviewProduct.Icon != null)
                {
                    icon.image = _selectedPreviewProduct.Icon.texture;
                }
            }

            VisualElement buttons = body.Q <VisualElement>("Buttons");
            if (buttons != null)
            {
                buttons.style.opacity = 0;
                buttons.SetEnabled(false);
            }
            soRender.SetEnabled(false);
        }
        #endregion

        #region Add Selection
        VisualElement lowerContent = body.Q <VisualElement>("LowerContent");
        lowerContent.contentContainer.style.flexDirection = new StyleEnum <FlexDirection>(FlexDirection.Row);
        lowerContent.contentContainer.style.flexWrap      = new StyleEnum <Wrap>(Wrap.Wrap);

        HashSet <BaseProduct> products = new HashSet <BaseProduct>();
        Dictionary <string, List <BaseProduct> > productsByClass = MarketManager.GetProductsByClass();

        if (_selectedCatalog == null)
        {
            return;
        }

        foreach (KeyValuePair <string, List <BaseProduct> > keyValuePair in productsByClass)
        {
            if (!selectedProductCategories.Contains(keyValuePair.Key))
            {
                continue;
            }
            for (int i = 0; i < keyValuePair.Value.Count; i++)
            {
                if (!_selectedCatalog.Products.Contains(keyValuePair.Value[i]))
                {
                    products.Add(keyValuePair.Value[i]);
                }
            }
        }

        foreach (BaseProduct itemProduct in products)
        {
            lowerContent.Add(
                CreateProductSelectionButton(
                    itemProduct,
                    baseProduct => AddTo(itemProduct, _selectedCatalog),
                    new []
            {
                new Tuple <string, Action>("Preview", () => PreviewProduct(itemProduct)),
                new Tuple <string, Action>("Edit", () => GoToProductEdit(itemProduct)),
                new Tuple <string, Action>("Delete", () => DestroyProduct(itemProduct))
            }));
        }

        #endregion
    }