public static bool AddGuiItemToGroup(this List <GuiItem> guiItems, string name)
        {
            int itemsCount = guiItems.Count;

            GuiItem lastItem1 = guiItems[itemsCount - 1];
            GuiItem lastItem2 = guiItems[itemsCount - 2];

            Rect lastRect1 = lastItem1.Rect;
            Rect lastRect2 = lastItem2.Rect;

            Rect nextRect = new Rect(lastRect1.x, lastRect1.y + (lastRect1.y - lastRect2.y), lastRect1.width, lastRect1.height);

            guiItems.Add(new GuiItem()
            {
                Name           = name,
                Tooltip        = null,
                Type           = lastItem1.Type,
                Enabled        = true,
                Rect           = nextRect,
                ItemColor      = lastItem1.ItemColor,
                State          = GuiItemState.NORMAL,
                FontStyle      = lastItem1.FontStyle,
                TextAnchor     = lastItem1.TextAnchor,
                OnChangedEvent = null
            });

            return(true);
        }
        public static bool RemoveGuiItemFromGroup(this List <GuiItem> guiItems, int index)
        {
            int itemsCount = guiItems.Count;

            if (index >= itemsCount)
            {
                return(false);
            }

            if (itemsCount < 2 || index == itemsCount - 1)
            {
                guiItems.RemoveAt(index);
                return(true);
            }

            GuiItem firstItem  = guiItems[0];
            GuiItem secondItem = guiItems[1];

            float distanceY = secondItem.Rect.y - firstItem.Rect.y;

            float x      = guiItems[index].Rect.x;
            float y      = guiItems[index].Rect.y;
            float width  = guiItems[index].Rect.width;
            float height = guiItems[index].Rect.height;

            guiItems.RemoveAt(index);

            int i = index;
            int j = 0;

            do
            {
                guiItems[i].Rect = new Rect(x, y + (j * distanceY), width, height);
                i++;
                j++;
            }while (i < guiItems.Count);

            return(true);
        }
 public static void SetStateInverse(this GuiItem guiItem)
 {
     guiItem.State = InvertState(guiItem.State);
 }
Ejemplo n.º 4
0
        public static GUIStyle GetGuiItemStyle(GuiItem guiItem)
        {
            if (!isInitStyles)
            {
                isInitStyles = SetGUIStyles();
            }

            switch (guiItem.Type)
            {
            case GuiItemType.NORMALBUTTON:
                NormalButton.fontStyle = guiItem.FontStyle;
                NormalButton.alignment = guiItem.TextAnchor;

                if (guiItem.State == GuiItemState.PRESSED)
                {
                    NormalButton.normal.textColor = GetGuiColor(guiItem.ItemColor.Active);
                    NormalButton.hover.textColor  = GetGuiColor(guiItem.ItemColor.Active);
                    NormalButton.active.textColor = GetGuiColor(guiItem.ItemColor.Active);
                }
                else
                {
                    NormalButton.normal.textColor = GetGuiColor(guiItem.ItemColor.Normal);
                    NormalButton.hover.textColor  = GetGuiColor(guiItem.ItemColor.Normal);
                    NormalButton.active.textColor = GetGuiColor(guiItem.ItemColor.Active);
                }
                return(NormalButton);

            case GuiItemType.TOGGLEBUTTON:
                ToggleButton.fontStyle = guiItem.FontStyle;
                ToggleButton.alignment = guiItem.TextAnchor;

                if (guiItem.State == GuiItemState.PRESSED)
                {
                    ToggleButton.normal.textColor = GetGuiColor(guiItem.ItemColor.Active);
                    ToggleButton.hover.textColor  = GetGuiColor(guiItem.ItemColor.Active);
                    ToggleButton.active.textColor = GetGuiColor(guiItem.ItemColor.Active);
                }
                else
                {
                    ToggleButton.normal.textColor = GetGuiColor(guiItem.ItemColor.Normal);
                    ToggleButton.hover.textColor  = GetGuiColor(guiItem.ItemColor.Normal);
                    ToggleButton.active.textColor = GetGuiColor(guiItem.ItemColor.Normal);
                }
                return(ToggleButton);

            case GuiItemType.TAB:
                Tab.fontStyle = guiItem.FontStyle;
                Tab.alignment = guiItem.TextAnchor;

                if (guiItem.State == GuiItemState.PRESSED)
                {
                    Tab.normal.textColor = GetGuiColor(guiItem.ItemColor.Active);
                    Tab.hover.textColor  = GetGuiColor(guiItem.ItemColor.Active);
                    Tab.active.textColor = GetGuiColor(guiItem.ItemColor.Active);
                }
                else
                {
                    Tab.normal.textColor = GetGuiColor(guiItem.ItemColor.Normal);
                    Tab.hover.textColor  = GetGuiColor(guiItem.ItemColor.Hover);
                    Tab.active.textColor = GetGuiColor(guiItem.ItemColor.Active);
                }
                return(Tab);

            case GuiItemType.TEXTFIELD:
                Textfield.fontStyle        = guiItem.FontStyle;
                Textfield.alignment        = guiItem.TextAnchor;
                Textfield.normal.textColor = GetGuiColor(guiItem.ItemColor.Normal);
                Textfield.hover.textColor  = GetGuiColor(guiItem.ItemColor.Hover);
                return(Textfield);

            case GuiItemType.LABEL:
                Label.fontStyle        = guiItem.FontStyle;
                Label.alignment        = guiItem.TextAnchor;
                Label.normal.textColor = GetGuiColor(guiItem.ItemColor.Normal);
                Label.hover.textColor  = GetGuiColor(guiItem.ItemColor.Normal);
                return(Label);
            }

            throw new Exception("Unknown error!");
        }