예제 #1
0
        public KsmGuiToggleListElement(KsmGuiToggleList <T> parent, T toggleId, string text) : base(parent)
        {
            ToggleComponent            = TopObject.AddComponent <Toggle>();
            ToggleComponent.transition = Selectable.Transition.None;
            ToggleComponent.navigation = new Navigation()
            {
                mode = Navigation.Mode.None
            };
            ToggleComponent.isOn             = false;
            ToggleComponent.toggleTransition = Toggle.ToggleTransition.Fade;
            ToggleComponent.group            = parent.ToggleGroupComponent;

            this.parent = parent;
            parent.ChildToggles.Add(this);
            ToggleId = toggleId;
            ToggleComponent.onValueChanged.AddListener(NotifyParent);

            Image image = TopObject.AddComponent <Image>();

            image.color = KsmGuiStyle.boxColor;

            SetLayoutElement(false, false, -1, -1, -1, 14);

            KsmGuiVerticalLayout highlightImage = new KsmGuiVerticalLayout(this);
            Image bgImage = highlightImage.TopObject.AddComponent <Image>();

            bgImage.color           = KsmGuiStyle.selectedBoxColor;
            bgImage.raycastTarget   = false;
            ToggleComponent.graphic = bgImage;

            TextObject = new KsmGuiText(highlightImage, text);
            TextObject.SetLayoutElement(true);
        }
예제 #2
0
        public KsmGuiTextBox(KsmGuiBase parent, string text, string tooltipText = null, TextAlignmentOptions alignement = TextAlignmentOptions.TopLeft) : base(parent)
        {
            SetLayoutElement(true, true);
            TextObject = new KsmGuiText(this, text, null, alignement);

            if (tooltipText != null)
            {
                SetTooltipText(text);
            }
        }
예제 #3
0
        public KsmGuiButton
        (
            KsmGuiBase parent,
            string buttonText,
            UnityAction onClick,
            string tooltipText    = null,
            int width             = -1,
            int height            = 18,
            Texture2D iconTexture = null,
            int iconWidth         = 16,
            int iconHeight        = 16
        ) : base(parent, 2, 3, 3, 0, 0, TextAnchor.MiddleCenter)
        {
            // buttons are 18 px high and expand horizontaly in their container by default, but a fixed width can be defined in the ctor
            // in any case, SetLayoutElement can be called after to customise the button size.
            if (width <= 0)
            {
                SetLayoutElement(true, false, -1, height);
            }
            else
            {
                SetLayoutElement(false, false, width, height);
            }

            ImageComponent            = TopObject.AddComponent <Image>();
            ImageComponent.sprite     = Textures.KsmGuiSpriteBtnNormal;
            ImageComponent.type       = Image.Type.Sliced;
            ImageComponent.fillCenter = true;

            ButtonComponent             = TopObject.AddComponent <Button>();
            ButtonComponent.transition  = Selectable.Transition.SpriteSwap;
            ButtonComponent.spriteState = KsmGuiStyle.buttonSpriteSwap;
            ButtonComponent.navigation  = new Navigation()
            {
                mode = Navigation.Mode.None
            };                                                                                         // fix the transitions getting stuck

            SetButtonOnClick(onClick);

            SetIconTexture(iconTexture, iconWidth, iconHeight);

            TextObject = new KsmGuiText(this, buttonText, null, TextAlignmentOptions.Center);
            TextObject.SetLayoutElement(true);
            TextObject.TopTransform.SetParentFixScale(TopTransform);

            if (tooltipText != null)
            {
                SetTooltipText(tooltipText);
            }
        }
예제 #4
0
        public KsmGuiHeader(KsmGuiBase parent, string title, Color backgroundColor = default, int textPreferredWidth = -1)
            : base(parent, 2, 0, 0, 0, 0, TextAnchor.UpperLeft)
        {
            // default : black background
            Image image = TopObject.AddComponent <Image>();

            if (backgroundColor == default)
            {
                image.color = Color.black;
            }
            else
            {
                image.color = backgroundColor;
            }


            TextObject = new KsmGuiText(this, title, null, TextAlignmentOptions.Center);
            TextObject.TextComponent.fontStyle = FontStyles.UpperCase;
            TextObject.SetLayoutElement(true, false, textPreferredWidth, -1, -1, 16);
        }
예제 #5
0
        public KsmGuiToggle(KsmGuiBase parent, string toggleText, bool initialOnState, UnityAction <bool> onClick, string tooltipText = null, int width = -1, int height = 18)
            : base(parent, 5)
        {
            onClickAction = onClick;

            if (width <= 0)
            {
                SetLayoutElement(true, false, -1, height);
            }
            else
            {
                SetLayoutElement(false, false, width, height);
            }

            ToggleComponent             = TopObject.AddComponent <Toggle>();
            ToggleComponent.transition  = Selectable.Transition.SpriteSwap;
            ToggleComponent.spriteState = KsmGuiStyle.buttonSpriteSwap;
            ToggleComponent.navigation  = new Navigation()
            {
                mode = Navigation.Mode.None
            };                                                                                         // fix the transitions getting stuck
            ToggleComponent.toggleTransition = Toggle.ToggleTransition.Fade;
            ToggleComponent.isOn             = initialOnState;
            ToggleComponent.onValueChanged.AddListener(onClickAction);

            GameObject    background          = new GameObject("Background");
            RectTransform backgroundTransform = background.AddComponent <RectTransform>();
            LayoutElement backgroundLayout    = background.AddComponent <LayoutElement>();

            backgroundLayout.preferredHeight = 18f;             // the toggle is always 18x18
            backgroundLayout.preferredWidth  = 18f;
            backgroundTransform.SetParentFixScale(TopTransform);
            background.AddComponent <CanvasRenderer>();
            Image backgroundImage = background.AddComponent <Image>();

            backgroundImage.sprite        = Textures.KsmGuiSpriteBtnNormal;
            backgroundImage.type          = Image.Type.Sliced;
            backgroundImage.fillCenter    = true;
            ToggleComponent.targetGraphic = backgroundImage;

            GameObject    checkmark          = new GameObject("Checkmark");
            RectTransform checkmarkTransform = checkmark.AddComponent <RectTransform>();

            checkmarkTransform.SetAnchorsAndPosition(TextAnchor.MiddleCenter, TextAnchor.MiddleCenter, 0, 0);
            checkmarkTransform.SetSizeDelta(10, 10);             // a checkbox is always 10x10, centered in the toggle
            checkmarkTransform.SetParentFixScale(backgroundTransform);
            checkmark.AddComponent <CanvasRenderer>();
            RawImage checkmarkImage = checkmark.AddComponent <RawImage>();

            checkmarkImage.texture  = Textures.KsmGuiTexCheckmark;
            ToggleComponent.graphic = checkmarkImage;

            TextObject = new KsmGuiText(this, toggleText, null, TextAlignmentOptions.Left, false, TextOverflowModes.Ellipsis);
            if (width <= 0)
            {
                SetLayoutElement(true, false, -1, height);
            }
            else
            {
                SetLayoutElement(false, false, width - 18 - 5, height);
            }
            TextObject.TopTransform.SetParentFixScale(TopTransform);

            if (tooltipText != null)
            {
                SetTooltipText(tooltipText);
            }
        }