Esempio n. 1
0
        /// <summary>
        /// Creates a new title bar.
        /// </summary>
        /// <param name="capi">The Client API.</param>
        /// <param name="text">The text on the title bar.</param>
        /// <param name="composer">The GuiComposer for the title bar.</param>
        /// <param name="OnClose">The event fired when the title bar is closed.</param>
        /// <param name="font">The font of the title bar.</param>
        /// <param name="bounds">The bounds of the title bar.</param>
        public GuiElementDialogTitleBar(ICoreClientAPI capi, string text, GuiComposer composer, Action OnClose = null, CairoFont font = null, ElementBounds bounds = null) : base(capi, text, font, bounds)
        {
            closeIconHoverTexture = new LoadedTexture(capi);
            menuIconHoverTexture  = new LoadedTexture(capi);

            if (bounds == null)
            {
                this.Bounds = ElementStdBounds.TitleBar();
            }
            if (font == null)
            {
                this.Font = CairoFont.WhiteSmallText();
            }
            this.OnClose = OnClose;

            ElementBounds dropDownBounds = ElementBounds.Fixed(0, 0, 100, 25);

            this.Bounds.WithChild(dropDownBounds);

            listMenu = new GuiElementListMenu(capi, new string[] { "auto", "manual" }, new string[] { Lang.Get("Fixed"), Lang.Get("Movable") }, 0, onSelectionChanged, dropDownBounds, CairoFont.WhiteSmallText(), false)
            {
                HoveredIndex = 0
            };

            baseComposer = composer;
        }
Esempio n. 2
0
        /// <summary>
        /// Composes the dialogue with specifications dictated by JSON.
        /// </summary>
        public void ComposeDialog()
        {
            double factor = settings.SizeMultiplier;

            ElementBounds dlgBounds = ElementStdBounds.AutosizedMainDialog
                                      .WithAlignment(settings.Alignment)
                                      .WithFixedPadding(10)
                                      .WithScale(factor)
                                      .WithFixedPosition(settings.PosX, settings.PosY)
            ;

            GuiComposer composer =
                capi.Gui
                .CreateCompo("cmdDlg" + settings.Code, dlgBounds)
                .AddDialogBG(ElementStdBounds.DialogBackground().WithScale(factor).WithFixedPadding(settings.Padding), false)
                .BeginChildElements()
            ;

            double y       = 0;
            int    elemKey = 1;

            for (int i = 0; i < settings.Rows.Length; i++)
            {
                DialogRow row = settings.Rows[i];

                y += row.TopPadding;

                double maxheight = 0;
                double x         = 0;
                for (int j = 0; j < row.Elements.Length; j++)
                {
                    DialogElement elem = row.Elements[j];
                    maxheight = Math.Max(elem.Height, maxheight);

                    x += elem.PaddingLeft;

                    ComposeElement(composer, settings, elem, elemKey, x, y);

                    elemKey++;

                    x += elem.Width + 20;
                }

                y += maxheight + row.BottomPadding;
            }


            Composers["cmdDlg" + settings.Code] = composer.EndChildElements().Compose();
        }
        public GuiDialogBlockEntityInventory(string dialogTitle, InventoryBase inventory, BlockPos blockEntityPos, int cols, ICoreClientAPI capi)
            : base(dialogTitle, inventory, blockEntityPos, capi)
        {
            if (IsDuplicate)
            {
                return;
            }
            this.cols = cols;


            double elemToDlgPad = GuiStyle.ElementToDialogPadding;
            double pad          = GuiElementItemSlotGrid.unscaledSlotPadding;
            int    rows         = (int)Math.Ceiling(inventory.Count / (float)cols);
            int    visibleRows  = Math.Min(rows, 7);

            // 1. The bounds of the slot grid itself. It is offseted by slot padding. It determines the size of the dialog, so we build the dialog from the bottom up
            ElementBounds slotGridBounds = ElementStdBounds.SlotGrid(EnumDialogArea.None, pad, pad, cols, visibleRows);

            // 1a.) Determine the full size of scrollable area, required to calculate scrollbar handle size
            ElementBounds fullGridBounds = ElementStdBounds.SlotGrid(EnumDialogArea.None, 0, 0, cols, rows);

            // 2. Around that is the 3 wide inset stroke
            ElementBounds insetBounds = slotGridBounds.ForkBoundingParent(6, 6, 6, 6);

            screenPos = GetFreePos("smallblockgui");

            if (visibleRows < rows)
            {
                // 2a. The scrollable bounds is also the clipping bounds. Needs it's parent to be set.
                ElementBounds clippingBounds = slotGridBounds.CopyOffsetedSibling();
                clippingBounds.fixedHeight -= 3; // Why?

                // 3. Around all that is the dialog centered to screen middle, with some extra spacing right for the scrollbar
                ElementBounds dialogBounds = insetBounds
                                             .ForkBoundingParent(elemToDlgPad, elemToDlgPad + 30, elemToDlgPad + 20, elemToDlgPad)
                                             .WithFixedAlignmentOffset(IsRight(screenPos) ? -GuiStyle.DialogToScreenPadding : GuiStyle.DialogToScreenPadding, 0)
                                             .WithAlignment(IsRight(screenPos) ? EnumDialogArea.RightMiddle :EnumDialogArea.LeftMiddle)
                ;

                if (!capi.Settings.Bool["immersiveMouseMode"])
                {
                    dialogBounds.fixedOffsetY += (dialogBounds.fixedHeight + 10) * YOffsetMul(screenPos);
                }

                // 4. Right of the slot grid is the scrollbar
                ElementBounds scrollbarBounds = ElementStdBounds.VerticalScrollbar(insetBounds).WithParent(dialogBounds);

                SingleComposer = capi.Gui
                                 .CreateCompo("blockentityinventory" + blockEntityPos, dialogBounds)
                                 .AddShadedDialogBG(ElementBounds.Fill)
                                 .AddDialogTitleBar(dialogTitle, CloseIconPressed)
                                 .AddInset(insetBounds)
                                 .AddVerticalScrollbar(OnNewScrollbarvalue, scrollbarBounds, "scrollbar")
                                 .BeginClip(clippingBounds)
                                 .AddItemSlotGrid(inventory, DoSendPacket, cols, fullGridBounds, "slotgrid")
                                 .EndClip()
                                 .Compose();

                SingleComposer.GetScrollbar("scrollbar").SetHeights(
                    (float)(slotGridBounds.fixedHeight),
                    (float)(fullGridBounds.fixedHeight + pad)
                    );
            }
            else
            {
                // 3. Around all that is the dialog centered to screen middle, with some extra spacing right for the scrollbar
                ElementBounds dialogBounds = insetBounds
                                             .ForkBoundingParent(elemToDlgPad, elemToDlgPad + 20, elemToDlgPad, elemToDlgPad)
                                             .WithFixedAlignmentOffset(IsRight(screenPos) ? -GuiStyle.DialogToScreenPadding : GuiStyle.DialogToScreenPadding, 0)
                                             .WithAlignment(IsRight(screenPos) ? EnumDialogArea.RightMiddle : EnumDialogArea.LeftMiddle)
                ;

                if (!capi.Settings.Bool["immersiveMouseMode"])
                {
                    dialogBounds.fixedOffsetY += (dialogBounds.fixedHeight + 10) * YOffsetMul(screenPos);
                }

                SingleComposer = capi.Gui
                                 .CreateCompo("blockentityinventory" + blockEntityPos, dialogBounds)
                                 .AddShadedDialogBG(ElementBounds.Fill)
                                 .AddDialogTitleBar(dialogTitle, CloseIconPressed)
                                 .AddInset(insetBounds)
                                 .AddItemSlotGrid(inventory, DoSendPacket, cols, slotGridBounds, "slotgrid")
                                 .Compose();
            }

            SingleComposer.UnfocusOwnElements();
        }