public void SetButton(Vector2 localPos, RadialMenu menuController, RightClickMenuItem menuItem, bool topLevel)
    {
        this.menuItem           = menuItem;
        transform.localPosition = localPos;
        menuControl             = menuController;
        isTopLevel    = topLevel;
        circle.color  = menuItem.BackgroundColor;
        defaultColour = menuItem.BackgroundColor;
        action        = menuItem.Action;

        icon.sprite = menuItem.IconSprite;
        icon.color  = menuItem.IconColor;
        palette     = menuItem.palette;
        if (palette != null)
        {
            icon.material.SetInt(IsPaletted, 1);
            icon.material.SetColorArray(ColorPalette, menuItem.palette.ToArray());
        }
        else
        {
            icon.material.SetInt(IsPaletted, 0);
        }

        if (menuItem.BackgroundSprite != null)
        {
            circle.sprite = menuItem.BackgroundSprite;
        }

        if (!topLevel)
        {
            title.text = menuItem.Label;
        }
    }
Exemple #2
0
    //creates the top-level menu item for this object. If object has a RightClickAppearance, uses that to
    //define the appeareance. Otherwise sticks to defaults. Doesn't populate the sub menus though.
    private RightClickMenuItem CreateObjectMenu(GameObject forObject, List <RightClickMenuItem> subMenus)
    {
        RightClickAppearance rightClickAppearance = forObject.GetComponent <RightClickAppearance>();

        if (rightClickAppearance != null)
        {
            //use right click menu to determine appearance
            return(rightClickAppearance.AsMenu(subMenus));
        }

        //use defaults
        var            label       = forObject.name.Replace("(clone)", "");
        SpriteRenderer firstSprite = forObject.GetComponentInChildren <SpriteRenderer>();
        Sprite         sprite      = null;

        if (firstSprite != null)
        {
            sprite = firstSprite.sprite;
        }
        else
        {
            Logger.LogWarningFormat("Could not determine sprite to use for right click menu" +
                                    " for object {0}. Please manually configure a sprite in a RightClickAppearance component" +
                                    " on this object.", Category.UI, forObject.name);
        }

        return(RightClickMenuItem.CreateObjectMenuItem(Color.gray, sprite, null, label, subMenus));
    }
Exemple #3
0
        private RightClickMenuItem CreateObjectMenu(GameObject forObject)
        {
            var label = forObject.ExpensiveName();

            // check if is a paletted item
            ItemAttributesV2 item    = forObject.GetComponent <ItemAttributesV2>();
            List <Color>     palette = null;

            if (item != null)
            {
                if (item.ItemSprites.IsPaletted)
                {
                    palette = item.ItemSprites.Palette;
                }
            }

            // See if this object has an AirLockAnimator then try to get the sprite from that, otherwise try to get the sprite from the first renderer we find
            var airLockAnimator = forObject.GetComponentInChildren <AirLockAnimator>();
            var spriteRenderer  = airLockAnimator != null ? airLockAnimator.doorbase : forObject.GetComponentInChildren <SpriteRenderer>();

            Sprite sprite = null;

            if (spriteRenderer != null)
            {
                sprite = spriteRenderer.sprite;
            }
            else
            {
                Logger.LogWarningFormat("Could not determine sprite to use for right click menu" +
                                        " for object {0}. Please manually configure a sprite in a RightClickAppearance component" +
                                        " on this object.", Category.UserInput, forObject.name);
            }

            return(RightClickMenuItem.CreateObjectMenuItem(forObject, ButtonColor, sprite, null, label, spriteRenderer.color, palette));
        }
    /// <summary>
    /// Create a RightClickMenuItem for the object based on the current configuration in this RightClickAppearance.
    /// </summary>
    /// <param name="subMenus">sub menu items to show underneath this object's menu</param>
    public RightClickMenuItem AsMenu(List <RightClickMenuItem> subMenus)
    {
        var    label  = nameOverride != null && nameOverride.Trim().Length != 0 ? nameOverride : gameObject.name.Replace("(clone)", "");
        Sprite sprite = null;

        if (iconOverride == null)
        {
            SpriteRenderer firstSprite = GetComponentInChildren <SpriteRenderer>();
            if (firstSprite != null)
            {
                sprite = firstSprite.sprite;
            }
            else
            {
                Logger.LogWarningFormat("Could not determine sprite to use for right click menu" +
                                        " for object {0}. Please specify a sprite in the RightClickMenu component" +
                                        " for this object.", Category.UI, gameObject.name);
            }
        }
        else
        {
            sprite = iconOverride;
        }

        return(RightClickMenuItem.CreateObjectMenuItem(backgroundColor, sprite, backgroundSprite, label, subMenus));
    }
    /// <summary>
    /// Create a menu item based on this element.
    /// </summary>
    /// <returns></returns>
    public RightClickMenuItem AsMenu()
    {
        var label    = nameOverride ?? option.label;
        var color    = bgColorOverride ?? option.backgroundColor;
        var sprite   = spriteOverride ? spriteOverride : option.icon;
        var bgSprite = bgSpriteOverride ? bgSpriteOverride : option.backgroundSprite;

        return(RightClickMenuItem.CreateSubMenuItem(color, sprite, bgSprite, label, action, keepMenuOpen: keepMenuOpen));
    }
        void NextMenu(MenuItem item)
        {
            for (int i = 0; i < transform.childCount; i++)
            {
                //TODO: Change to put object
                if (transform.GetChild(i).name != "Label")
                {
                    Destroy(transform.GetChild(i).gameObject);
                }
            }

            if (item.father != null)
            {
                CachePool.I().GetObject("Prefabs/Context/BackButton", (obj) =>
                {
                    obj.transform.SetParent(transform, false);
                    RightClickMenuItem rcItem = obj.GetComponent <RightClickMenuItem>();
                    MenuItem next             = item;
                    rcItem.AddAction(() => {
                        Label.text = Label.text.Substring(0, Label.text.Length - new StringBuilder("/").Append(item.name).ToString().Length);
                        NextMenu(next.father);
                    });
                });
            }

            for (int i = 0; i < item.SubItems.Count; i++)
            {
                CachePool.I().GetObject("Prefabs/Context/ContextButton", (obj) =>
                {
                    obj.transform.SetParent(transform, false);
                    RightClickMenuItem rcItem = obj.GetComponent <RightClickMenuItem>();
                    rcItem.SetLabel(Item.SubItems[i].name);
                    MenuItem nextItem = Item.SubItems[i];
                    MenuItem cur      = item;
                    rcItem.AddAction(() => {
                        nextItem.father = cur;
                        Label.text     += new StringBuilder("/").Append(nextItem.name).ToString();
                        NextMenu(nextItem);
                    });
                });
            }

            foreach (var key in item.ActualItem.Keys)
            {
                CachePool.I().GetObject("Prefabs/Context/ActualButton", (obj) =>
                {
                    obj.transform.SetParent(transform, false);
                    RightClickMenuItem rcItem = obj.GetComponent <RightClickMenuItem>();
                    rcItem.SetLabel(key);
                    rcItem.AddAction(item.ActualItem[key]);
                });
            }
        }
Exemple #7
0
        private void SetupIcon(RightClickMenuItem itemInfo)
        {
            icon.SetActive(true);
            altLabel.SetActive(false);
            icon.color  = itemInfo.IconColor;
            icon.sprite = itemInfo.IconSprite;
            var palette = itemInfo.palette;

            if (palette != null)
            {
                icon.material.SetInt(IsPaletted, 1);
                icon.material.SetInt(PaletteSize, palette.Count);
                icon.material.SetColorArray(ColorPalette, palette.ToArray());
            }
            else
            {
                icon.material.SetInt(IsPaletted, 0);
            }
        }
Exemple #8
0
    //creates the top-level menu item for this object. If object has a RightClickAppearance, uses that to
    //define the appearance. Otherwise sticks to defaults. Doesn't populate the sub menus though.
    private RightClickMenuItem CreateObjectMenu(GameObject forObject, List <RightClickMenuItem> subMenus)
    {
        RightClickAppearance rightClickAppearance = forObject.GetComponent <RightClickAppearance>();

        if (rightClickAppearance != null)
        {
            //use right click menu to determine appearance
            return(rightClickAppearance.AsMenu(subMenus));
        }
        // else use defaults:

        var label = forObject.ExpensiveName();

        // check if is a paletted item
        ItemAttributesV2 item    = forObject.GetComponent <ItemAttributesV2>();
        List <Color>     palette = null;

        if (item != null)
        {
            if (item.ItemSprites.IsPaletted)
            {
                palette = item.ItemSprites.Palette;
            }
        }

        // try get sprite
        SpriteRenderer firstRenderer = forObject.GetComponentInChildren <SpriteRenderer>();
        Sprite         sprite        = null;

        if (firstRenderer != null)
        {
            sprite = firstRenderer.sprite;
        }
        else
        {
            Logger.LogWarningFormat("Could not determine sprite to use for right click menu" +
                                    " for object {0}. Please manually configure a sprite in a RightClickAppearance component" +
                                    " on this object.", Category.UI, forObject.name);
        }

        return(RightClickMenuItem.CreateObjectMenuItem(Color.gray, sprite, null, label, subMenus, firstRenderer.color, palette));
    }
Exemple #9
0
    public void SetButton(Vector2 localPos, RadialMenu menuController, RightClickMenuItem menuItem, bool topLevel)
    {
        this.menuItem           = menuItem;
        transform.localPosition = localPos;
        menuControl             = menuController;
        isTopLevel    = topLevel;
        circle.color  = menuItem.BackgroundColor;
        defaultColour = menuItem.BackgroundColor;
        action        = menuItem.Action;

        icon.sprite = menuItem.IconSprite;
        if (menuItem.BackgroundSprite != null)
        {
            circle.sprite = menuItem.BackgroundSprite;
        }

        if (!topLevel)
        {
            title.text = menuItem.Label;
        }
    }
Exemple #10
0
    /// <summary>
    /// Creates a RightClickMenuItem whose appearance is based on the properties specified in this attribute,
    /// wired to the specified action (which should be the method it is attributed on)
    /// </summary>
    /// <param name="attributedMethod">method this was attributed to</param>
    /// <param name="attributedMethod">component instance whose method should be invoked when this option is clicked.</param>
    public RightClickMenuItem AsMenu(MethodInfo attributedMethod, Component forComponent)
    {
        var labelToUse = label ?? attributedMethod.Name;

        var colorToUse = RightClickManager.ButtonColor;

        if (ColorUtility.TryParseHtmlString(bgColorHex, out var color))
        {
            colorToUse = color;
        }
        else
        {
            Logger.LogWarningFormat("Unable to parse hex color string {0} in RightClickMethod. Please ensure this is a" +
                                    " valid hex color string like #223344. Defaulting to gray.", Category.UI, bgColorHex);
        }

        var sprite = Resources.Load <Sprite>(spritePath);

        if (sprite == null)
        {
            Logger.LogWarningFormat("Unable to load sprite at path {0} in RightClickMethod. Please ensure this is a" +
                                    " valid path to a sprite. Defaulting to question mark.", Category.UI, spritePath);
            sprite = Resources.Load <Sprite>("UI/RightClickButtonIcon/question_mark.png");
        }

        Sprite bgSprite = null;

        if (bgSpritePath != null)
        {
            bgSprite = Resources.Load <Sprite>(bgSpritePath);
            if (bgSprite == null)
            {
                Logger.LogWarningFormat(
                    "Unable to load bgSprite at path {0} in RightClickMethod. Please ensure this is a" +
                    " valid path to a sprite. Defaulting to question no background.", Category.UI, bgSpritePath);
            }
        }

        return(RightClickMenuItem.CreateSubMenuItem(colorToUse, sprite, bgSprite, labelToUse, (Action)Delegate.CreateDelegate(typeof(Action), forComponent, attributedMethod)));
    }
Exemple #11
0
        public void ChangeItem(RightClickMenuItem itemInfo)
        {
            Mask.raycastTarget = true;
            Mask.color         = itemInfo.BackgroundColor;
            // Due to the way Unity handles selectables and transitions, we will handle the transitions ourselves instead.
            var colorBlock = colors;

            colorBlock.highlightedColor = CalculateHighlight(itemInfo.BackgroundColor);
            colorBlock.selectedColor    = colorBlock.highlightedColor;
            colorBlock.disabledColor    = Color.clear;
            colors = colorBlock;
            // Temporary solution for items/actions that currently do not have an icon set up or have the default question mark icon.
            if (itemInfo.IconSprite == null || itemInfo.IconSprite.name == "question_mark")
            {
                icon.SetActive(false);
                altLabel.SetActive(true);
                altLabel.SetText(itemInfo.Label);
            }
            else
            {
                SetupIcon(itemInfo);
            }
        }
Exemple #12
0
    /// <summary>
    /// Create a Right click Menu item whose appearance is based on the settings in this RightClickOption.
    /// </summary>
    /// <param name="action">action to invoke when clicked</param>
    public RightClickMenuItem AsMenu(Action action)
    {
        var menu = RightClickMenuItem.CreateSubMenuItem(backgroundColor, icon, backgroundSprite, label, action);

        return(menu);
    }