예제 #1
0
        internal void ComposeHoverTextElement()
        {
            ElementBounds bounds = new ElementBounds().WithFixedPadding(7).WithParent(ElementBounds.Empty);

            string text = currentValue + unit;

            if (OnSliderTooltip != null)
            {
                text = OnSliderTooltip(currentValue);
            }

            textElem = new GuiElementStaticText(api, text, EnumTextOrientation.Center, bounds, CairoFont.WhiteMediumText().WithFontSize((float)GuiStyle.SubNormalFontSize));
            textElem.Font.UnscaledFontsize = GuiStyle.SmallishFontSize;
            textElem.AutoBoxSize();
            textElem.Bounds.CalcWorldBounds();

            ImageSurface surface = new ImageSurface(Format.Argb32, (int)bounds.OuterWidth, (int)bounds.OuterHeight);
            Context      ctx     = genContext(surface);

            ctx.SetSourceRGBA(1, 1, 1, 0);
            ctx.Paint();
            ctx.SetSourceRGBA(GuiStyle.DialogStrongBgColor);
            RoundRectangle(ctx, 0, 0, bounds.OuterWidth, bounds.OuterHeight, GuiStyle.ElementBGRadius);
            ctx.FillPreserve();
            double[] color = GuiStyle.DialogStrongBgColor;
            ctx.SetSourceRGBA(color[0] / 2, color[1] / 2, color[2] / 2, color[3]);
            ctx.Stroke();

            textElem.ComposeElements(ctx, surface);

            generateTexture(surface, ref hoverTextTexture);
            ctx.Dispose();
            surface.Dispose();
        }
예제 #2
0
 /// <summary>
 /// Adds a static text component to the GUI that automatically resizes as necessary.
 /// </summary>
 /// <param name="text">The text of the text component.</param>
 /// <param name="font">The font of the text.</param>
 /// <param name="orientation">The orientation of the text.</param>
 /// <param name="bounds">The bounds of the text container.</param>
 /// <param name="key">The name of the component.</param>
 public static GuiComposer AddStaticTextAutoBoxSize(this GuiComposer composer, string text, CairoFont font, EnumTextOrientation orientation, ElementBounds bounds, string key = null)
 {
     if (!composer.composed)
     {
         GuiElementStaticText elem = new GuiElementStaticText(composer.Api, text, orientation, bounds, font);
         composer.AddStaticElement(elem, key);
         elem.AutoBoxSize();
     }
     return(composer);
 }
예제 #3
0
        /// <summary>
        /// Creates a button with text.
        /// </summary>
        /// <param name="capi">The Client API</param>
        /// <param name="text">The text of the button.</param>
        /// <param name="font">The font of the text.</param>
        /// <param name="hoverFont">The font of the text when the player is hovering over the button.</param>
        /// <param name="onClick">The event fired when the button is clicked.</param>
        /// <param name="bounds">The bounds of the button.</param>
        /// <param name="style">The style of the button.</param>
        public GuiElementTextButton(ICoreClientAPI capi, string text, CairoFont font, CairoFont hoverFont, ActionConsumable onClick, ElementBounds bounds, EnumButtonStyle style = EnumButtonStyle.Normal) : base(capi, bounds)
        {
            hoverTexture     = new LoadedTexture(capi);
            disabledTexture  = new LoadedTexture(capi);
            this.buttonStyle = style;

            normalText = new GuiElementStaticText(capi, text, EnumTextOrientation.Center, bounds, font);
            normalText.AutoBoxSize(true);

            pressedText = new GuiElementStaticText(capi, text, EnumTextOrientation.Center, bounds.CopyOnlySize(), hoverFont);
            bounds      = normalText.Bounds;

            this.onClick = onClick;
        }
예제 #4
0
        public override void ComposeElements(Context ctx, ImageSurface surface)
        {
            Bounds.CalcWorldBounds();

            if (drawBackground)
            {
                ctx.SetSourceRGBA(1, 1, 1, 0.6);
                ElementRoundRectangle(ctx, Bounds);
                ctx.Fill();
                EmbossRoundRectangleElement(ctx, Bounds, true);
            }

            double absSlotSize = scaled(unscaledSlotSize);

            ElementBounds textBounds = ElementBounds
                                       .Fixed(0, unscaledSlotSize - GuiStyle.SmallFontSize - 2, unscaledSlotSize - 5, unscaledSlotSize - 5)
                                       .WithEmptyParent();

            CairoFont font = CairoFont.WhiteSmallText();

            font.FontWeight = FontWeight.Bold;
            textComposer    = new GuiElementStaticText(api, "", EnumTextOrientation.Right, textBounds, font);
        }
예제 #5
0
        internal void ComposeHoverTextElement()
        {
            ElementBounds bounds = new ElementBounds().WithFixedPadding(7).WithParent(ElementBounds.Empty);

            textElem = new GuiElementStaticText(api, currentValue + unit, EnumTextOrientation.Center, bounds, CairoFont.WhiteMediumText());
            textElem.Font.UnscaledFontsize = GuiStyle.SmallishFontSize;
            textElem.AutoBoxSize();
            textElem.Bounds.CalcWorldBounds();

            ImageSurface surface = new ImageSurface(Format.Argb32, (int)bounds.OuterWidth, (int)bounds.OuterHeight);
            Context      ctx     = genContext(surface);

            ctx.SetSourceRGBA(1, 1, 1, 0);
            ctx.Paint();
            ctx.SetSourceRGBA(0, 0, 0, 0.3);
            RoundRectangle(ctx, 0, 0, bounds.OuterWidth, bounds.OuterHeight, GuiStyle.ElementBGRadius);
            ctx.Fill();

            textElem.ComposeElements(ctx, surface);

            generateTexture(surface, ref hoverTextTextureId);
            ctx.Dispose();
            surface.Dispose();
        }
예제 #6
0
        void ComposeInteractiveElements()
        {
            slotBounds           = new ElementBounds[availableSlots.Count];
            scissorBounds        = new ElementBounds[availableSlots.Count];
            slotQuantityTextures = new LoadedTexture[availableSlots.Count];
            for (int k = 0; k < slotQuantityTextures.Length; k++)
            {
                slotQuantityTextures[k] = new LoadedTexture(this.api);
            }

            this.rows = (int)Math.Ceiling(1f * availableSlots.Count / cols);

            Bounds.CalcWorldBounds();

            double unscaledSlotWidth  = GuiElementPassiveItemSlot.unscaledSlotSize;
            double unscaledSlotHeight = GuiElementPassiveItemSlot.unscaledSlotSize;

            // Slot sizes
            double absSlotPadding = scaled(unscaledSlotPadding);
            double absSlotWidth   = scaled(GuiElementPassiveItemSlot.unscaledSlotSize);
            double absSlotHeight  = scaled(GuiElementPassiveItemSlot.unscaledSlotSize);

            ElementBounds textBounds = ElementBounds
                                       .Fixed(0, GuiElementPassiveItemSlot.unscaledSlotSize - GuiStyle.SmallishFontSize - 2, GuiElementPassiveItemSlot.unscaledSlotSize - 5, GuiElementPassiveItemSlot.unscaledSlotSize - 5)
                                       .WithEmptyParent();

            CairoFont font = CairoFont.WhiteSmallText().WithFontSize((float)GuiStyle.SmallishFontSize);

            font.FontWeight  = FontWeight.Bold;
            font.Color       = new double[] { 1, 1, 1, 1 };
            font.StrokeColor = new double[] { 0, 0, 0, 1 };
            font.StrokeWidth = RuntimeEnv.GUIScale;

            textComposer = new GuiElementStaticText(api, "", EnumTextOrientation.Right, textBounds, font);


            // 1. draw generic slot
            ImageSurface slotSurface = new ImageSurface(Format.Argb32, (int)absSlotWidth, (int)absSlotWidth);
            Context      slotCtx     = genContext(slotSurface);

            slotCtx.SetSourceRGBA(GuiStyle.DialogSlotBackColor);
            RoundRectangle(slotCtx, 0, 0, absSlotWidth, absSlotHeight, GuiStyle.ElementBGRadius);
            slotCtx.Fill();

            slotCtx.SetSourceRGBA(GuiStyle.DialogSlotFrontColor);
            RoundRectangle(slotCtx, 0, 0, absSlotWidth, absSlotHeight, GuiStyle.ElementBGRadius);
            slotCtx.LineWidth = scaled(4.5);
            slotCtx.Stroke();
            slotSurface.Blur(scaled(4), true);
            slotSurface.Blur(scaled(4), true);

            RoundRectangle(slotCtx, 0, 0, absSlotWidth, absSlotHeight, 1);
            slotCtx.LineWidth = scaled(4.5);
            slotCtx.SetSourceRGBA(0, 0, 0, 0.8);
            slotCtx.Stroke();



            generateTexture(slotSurface, ref slotTexture, true);

            slotCtx.Dispose();
            slotSurface.Dispose();

            // 2. draw slots with backgrounds
            foreach (var val in availableSlots)
            {
                ItemSlot slot = val.Value;
                string   key  = slot.BackgroundIcon + "-" + slot.HexBackgroundColor;

                if ((slot.BackgroundIcon == null && slot.HexBackgroundColor == null) || slotTextureIdsByBgIconAndColor.ContainsKey(key))
                {
                    continue;
                }


                slotSurface = new ImageSurface(Format.Argb32, (int)absSlotWidth, (int)absSlotWidth);
                slotCtx     = genContext(slotSurface);

                if (slot.HexBackgroundColor != null)
                {
                    double[] bgcolor = ColorUtil.Hex2Doubles(slot.HexBackgroundColor);

                    slotCtx.SetSourceRGBA(bgcolor);
                    RoundRectangle(slotCtx, 0, 0, absSlotWidth, absSlotHeight, GuiStyle.ElementBGRadius);
                    slotCtx.Fill();

                    slotCtx.SetSourceRGBA(bgcolor[0] * 0.25, bgcolor[1] * 0.25, bgcolor[2] * 0.25, 1);
                    RoundRectangle(slotCtx, 0, 0, absSlotWidth, absSlotHeight, GuiStyle.ElementBGRadius);
                    slotCtx.LineWidth = scaled(4.5);
                    slotCtx.Stroke();
                    slotSurface.Blur(scaled(4), true);
                    slotSurface.Blur(scaled(4), true);

                    slotCtx.SetSourceRGBA(0, 0, 0, 0.8);
                    RoundRectangle(slotCtx, 0, 0, absSlotWidth, absSlotHeight, 1);
                    slotCtx.LineWidth = scaled(4.5);
                    slotCtx.Stroke();
                }
                else
                {
                    slotCtx.SetSourceRGBA(GuiStyle.DialogSlotBackColor);
                    RoundRectangle(slotCtx, 0, 0, absSlotWidth, absSlotHeight, GuiStyle.ElementBGRadius);
                    slotCtx.Fill();

                    slotCtx.SetSourceRGBA(GuiStyle.DialogSlotFrontColor);
                    RoundRectangle(slotCtx, 0, 0, absSlotWidth, absSlotHeight, GuiStyle.ElementBGRadius);
                    slotCtx.LineWidth = scaled(4.5);
                    slotCtx.Stroke();
                    slotSurface.Blur(scaled(4), true);
                    slotSurface.Blur(scaled(4), true);

                    RoundRectangle(slotCtx, 0, 0, absSlotWidth, absSlotHeight, 1);
                    slotCtx.LineWidth = scaled(4.5);
                    slotCtx.SetSourceRGBA(0, 0, 0, 0.8);
                    slotCtx.Stroke();
                }


                if (slot.BackgroundIcon != null)
                {
                    DrawIconHandler?.Invoke(
                        slotCtx, slot.BackgroundIcon, 2 * (int)absSlotPadding, 2 * (int)absSlotPadding,
                        (int)(absSlotWidth - 4 * absSlotPadding), (int)(absSlotHeight - 4 * absSlotPadding),
                        new double[] { 0, 0, 0, 0.2 }
                        );
                }

                int texId = 0;
                generateTexture(slotSurface, ref texId, true);

                slotCtx.Dispose();
                slotSurface.Dispose();

                slotTextureIdsByBgIconAndColor[key] = texId;
            }

            // 3. Crossed out overlay
            int csize = (int)absSlotWidth - 4;

            slotSurface = new ImageSurface(Format.Argb32, (int)csize, (int)csize);
            slotCtx     = genContext(slotSurface);

            slotCtx.SetSourceRGBA(0, 0, 0, 0.8);
            api.Gui.Icons.DrawCross(slotCtx, 4, 4, 7, csize - 18, true);
            slotCtx.SetSourceRGBA(1, 0.2, 0.2, 0.8);
            slotCtx.LineWidth = 2;
            slotCtx.Stroke();
            generateTexture(slotSurface, ref crossedOutTexture);
            slotCtx.Dispose();
            slotSurface.Dispose();


            // 4. Slot highlight overlay
            slotSurface = new ImageSurface(Format.Argb32, (int)absSlotWidth + 4, (int)absSlotWidth + 4);
            slotCtx     = genContext(slotSurface);

            slotCtx.SetSourceRGBA(GuiStyle.ActiveSlotColor);
            RoundRectangle(slotCtx, 0, 0, absSlotWidth + 4, absSlotHeight + 4, GuiStyle.ElementBGRadius);
            slotCtx.LineWidth = scaled(9);
            slotCtx.StrokePreserve();
            slotSurface.Blur(scaled(6), true);
            slotCtx.StrokePreserve();
            slotSurface.Blur(scaled(6), true);

            slotCtx.LineWidth = scaled(3);
            slotCtx.Stroke();

            slotCtx.LineWidth = scaled(1);
            slotCtx.SetSourceRGBA(GuiStyle.ActiveSlotColor);
            slotCtx.Stroke();

            generateTexture(slotSurface, ref highlightSlotTexture);



            slotCtx.Dispose();
            slotSurface.Dispose();

            int slotIndex = 0;

            foreach (var val in availableSlots)
            {
                int col = slotIndex % cols;
                int row = slotIndex / cols;

                double x = col * (unscaledSlotWidth + unscaledSlotPadding);
                double y = row * (unscaledSlotHeight + unscaledSlotPadding);

                ItemSlot slot = inventory[val.Key];

                slotBounds[slotIndex] = ElementBounds.Fixed(x, y, unscaledSlotWidth, unscaledSlotHeight).WithParent(Bounds);
                slotBounds[slotIndex].CalcWorldBounds();

                scissorBounds[slotIndex] = ElementBounds.Fixed(x + 2, y + 2, unscaledSlotWidth - 4, unscaledSlotHeight - 4).WithParent(Bounds);
                scissorBounds[slotIndex].CalcWorldBounds();

                ComposeSlotOverlays(slot, val.Key, slotIndex);

                slotIndex++;
            }
        }