public GuiDialogItemLootRandomizer(ItemStack[] stacks, float[] chances, ICoreClientAPI capi) : base("Item Loot Randomizer", capi)
        {
            double pad = GuiElementItemSlotGrid.unscaledSlotPadding;

            ElementBounds slotBounds = ElementStdBounds.SlotGrid(EnumDialogArea.None, pad, 45 + pad, 10, 1).FixedGrow(2 * pad, 2 * pad);

            ElementBounds chanceInputBounds = ElementBounds.Fixed(3, 0, 48, 30).FixedUnder(slotBounds, -4);

            ElementBounds leftButton       = ElementBounds.Fixed(EnumDialogArea.LeftFixed, 0, 0, 0, 0).WithFixedPadding(10, 1);
            ElementBounds chanceTextBounds = ElementBounds.Fixed(EnumDialogArea.CenterFixed, 0, 0, 150, 30).WithFixedPadding(10, 1);
            ElementBounds rightButton      = ElementBounds.Fixed(EnumDialogArea.RightFixed, 0, 0, 0, 0).WithFixedPadding(10, 1);

            ElementBounds bgBounds = ElementBounds.Fill.WithFixedPadding(ElementGeometrics.ElementToDialogPadding);

            bgBounds.BothSizing = ElementSizing.FitToChildren;

            inv = new InventoryGeneric(10, "lootrandomizer-1", capi, null);
            for (int i = 0; i < 10; i++)
            {
                inv.GetSlot(i).Itemstack = stacks[i];
            }

            ElementBounds dialogBounds = ElementStdBounds
                                         .AutosizedMainDialog.WithAlignment(EnumDialogArea.CenterMiddle)
                                         .WithFixedAlignmentOffset(ElementGeometrics.DialogToScreenPadding, 0);

            float  totalChance = chances.Sum();
            string text        = "Total chance: " + (int)totalChance + "%";

            SingleComposer = capi.Gui
                             .CreateCompo("itemlootrandomizer", dialogBounds, false)
                             .AddDialogBG(bgBounds, true)
                             .AddDialogTitleBar("Item Loot Randomizer", OnTitleBarClose)
                             .BeginChildElements(bgBounds)
                             .AddItemSlotGrid(inv, SendInvPacket, 10, slotBounds, "slots")
                             .AddNumberInput(chanceInputBounds = chanceInputBounds.FlatCopy(), (t) => OnTextChanced(0), CairoFont.WhiteDetailText(), "chance1")
                             .AddNumberInput(chanceInputBounds = chanceInputBounds.RightCopy(3), (t) => OnTextChanced(1), CairoFont.WhiteDetailText(), "chance2")
                             .AddNumberInput(chanceInputBounds = chanceInputBounds.RightCopy(3), (t) => OnTextChanced(2), CairoFont.WhiteDetailText(), "chance3")
                             .AddNumberInput(chanceInputBounds = chanceInputBounds.RightCopy(3), (t) => OnTextChanced(3), CairoFont.WhiteDetailText(), "chance4")
                             .AddNumberInput(chanceInputBounds = chanceInputBounds.RightCopy(3), (t) => OnTextChanced(4), CairoFont.WhiteDetailText(), "chance5")
                             .AddNumberInput(chanceInputBounds = chanceInputBounds.RightCopy(3), (t) => OnTextChanced(5), CairoFont.WhiteDetailText(), "chance6")
                             .AddNumberInput(chanceInputBounds = chanceInputBounds.RightCopy(3), (t) => OnTextChanced(6), CairoFont.WhiteDetailText(), "chance7")
                             .AddNumberInput(chanceInputBounds = chanceInputBounds.RightCopy(3), (t) => OnTextChanced(7), CairoFont.WhiteDetailText(), "chance8")
                             .AddNumberInput(chanceInputBounds = chanceInputBounds.RightCopy(3), (t) => OnTextChanced(8), CairoFont.WhiteDetailText(), "chance9")
                             .AddNumberInput(chanceInputBounds = chanceInputBounds.RightCopy(3), (t) => OnTextChanced(9), CairoFont.WhiteDetailText(), "chance10")

                             .AddButton("Close", OnCloseClicked, leftButton.FixedUnder(chanceInputBounds, 25))
                             .AddDynamicText(text, CairoFont.WhiteDetailText(), EnumTextOrientation.Left, chanceTextBounds.FixedUnder(chanceInputBounds, 25), 1, "totalchance")
                             .AddButton("Save", OnSaveClicked, rightButton.FixedUnder(chanceInputBounds, 25))


                             .EndChildElements()
                             .Compose()
            ;

            for (int i = 0; i < 10; i++)
            {
                GuiElementNumberInput inp = SingleComposer.GetNumberInput("chance" + (i + 1));
                inp.SetValue("" + chances[i]);
            }



            SingleComposer.GetSlotGrid("slots").CanClickSlot = OnCanClickSlot;
        }
        private void onPriceChanged(string text)
        {
            int   cost    = Composers["tradercreateauction"].GetNumberInput("price").GetText().ToInt(1);
            float gearcut = cost * auctionSys.SalesCutRate + auctionSys.debtClient;

            Composers["tradercreateauction"].GetRichtext("cutText").SetNewText(Lang.Get("Trader cut on sale (10%): {0}" + " " + gearIcon, (int)gearcut), CairoFont.WhiteSmallText());
        }
        public void Init()
        {
            var slotBounds = ElementBounds.Fixed(0, 30, 50, 50);

            ElementBounds bgBounds = ElementBounds.Fill.WithFixedPadding(GuiStyle.ElementToDialogPadding);

            bgBounds.BothSizing = ElementSizing.FitToChildren;
            dialogBounds        = ElementStdBounds
                                  .AutosizedMainDialog.WithAlignment(EnumDialogArea.CenterMiddle)
                                  .WithFixedAlignmentOffset(-GuiStyle.DialogToScreenPadding, 0);

            bgBounds.verticalSizing   = ElementSizing.FitToChildren;
            bgBounds.horizontalSizing = ElementSizing.Fixed;
            bgBounds.fixedWidth       = 300;

            ElementBounds leftButton  = ElementBounds.Fixed(EnumDialogArea.LeftFixed, 0, 0, 0, 0).WithFixedPadding(10, 1);
            ElementBounds rightButton = ElementBounds.Fixed(EnumDialogArea.RightFixed, 0, 0, 0, 0).WithFixedPadding(10, 1);

            ElementBounds priceLabelBounds    = ElementBounds.Fixed(0, 0, 250, 25).FixedUnder(slotBounds, 20);
            ElementBounds priceBounds         = ElementBounds.Fixed(0, 0, 100, 30).FixedUnder(priceLabelBounds, 0);
            ElementBounds durationLabelBounds = ElementBounds.Fixed(0, 0, 250, 25).FixedUnder(priceBounds, 20);
            ElementBounds dropDownBounds      = ElementBounds.Fixed(0, 0, 150, 25).FixedUnder(durationLabelBounds, 0);

            ElementBounds costLabelBounds = ElementBounds.Fixed(0, 0, 300, 25).FixedUnder(dropDownBounds, 20);
            ElementBounds cutLabelBounds  = ElementBounds.Fixed(0, 0, 300, 25).FixedUnder(costLabelBounds, 0);

            int[]    weeks  = new int[] { 1, 2, 3, 4, 5 };
            string[] codes  = new string[5];
            string[] values = new string[5];
            for (int i = 0; i < weeks.Length; i++)
            {
                weeks[i] *= auctionSys.DurationWeeksMul;
                codes[i]  = "" + weeks[i];
                values[i] = weeks[i] == 1 ? Lang.Get("{0} week", weeks[i]) : Lang.Get("{0} weeks", weeks[i]);
            }

            Composers["tradercreateauction"] = capi.Gui
                                               .CreateCompo("tradercreateauction-" + owningEntity.EntityId, dialogBounds)
                                               .AddShadedDialogBG(bgBounds, true)
                                               .AddDialogTitleBar(Lang.Get("Create Auction"), OnCreateAuctionClose)
                                               .BeginChildElements(bgBounds)
                                               .AddItemSlotGrid(auctionSlotInv, (p) => {
                capi.Network.SendPacketClient(p);
            }, 1, null, slotBounds, "traderSellingSlots")

                                               .AddStaticText(Lang.Get("Price in rusty gears"), CairoFont.WhiteSmallText(), priceLabelBounds)
                                               .AddNumberInput(priceBounds, onPriceChanged, CairoFont.WhiteSmallText(), "price")

                                               .AddStaticText(Lang.Get("Duration"), CairoFont.WhiteSmallText(), durationLabelBounds)
                                               .AddDropDown(codes, values, 0, onDurationChanged, dropDownBounds, CairoFont.WhiteSmallText(), "duration")

                                               .AddRichtext(Lang.Get("Deposit: {0}", 1) + " " + gearIcon, CairoFont.WhiteSmallText(), costLabelBounds, "depositText")
                                               .AddRichtext(Lang.Get("Trader cut on sale (10%): {0}" + " " + gearIcon, 1), CairoFont.WhiteSmallText(), cutLabelBounds, "cutText")

                                               .AddSmallButton(Lang.Get("Cancel"), OnCancelAuctionClose, leftButton.FixedUnder(cutLabelBounds, 20).WithFixedPadding(8, 5))
                                               .AddSmallButton(Lang.Get("Create Auction"), OnCreateAuctionConfirm, rightButton.FixedUnder(cutLabelBounds, 20).WithFixedPadding(8, 5), EnumButtonStyle.Normal, EnumTextOrientation.Left, "buysellButton")
                                               .EndChildElements()
                                               .Compose()
            ;

            Composers["tradercreateauction"].GetNumberInput("price").SetValue(lastPrice);
        }
        private void Compose()
        {
            ClearComposers();

            ElementBounds creatureTextBounds = ElementBounds.Fixed(0, 30, 300, 25);

            ElementBounds dropDownBounds = ElementBounds.Fixed(0, 0, 300, 28).FixedUnder(creatureTextBounds, 0);


            ElementBounds areaTextBounds = ElementBounds.Fixed(0, 30, 300, 25).FixedUnder(dropDownBounds, 0);

            ElementBounds closeButtonBounds = ElementBounds
                                              .FixedSize(0, 0)
                                              .WithAlignment(EnumDialogArea.LeftFixed)
                                              .WithFixedPadding(20, 4)
            ;

            ElementBounds saveButtonBounds = ElementBounds
                                             .FixedSize(0, 0)
                                             .WithAlignment(EnumDialogArea.RightFixed)
                                             .WithFixedPadding(20, 4)
            ;


            // 2. Around all that is 10 pixel padding
            ElementBounds bgBounds = ElementBounds.Fill.WithFixedPadding(ElementGeometrics.ElementToDialogPadding);

            bgBounds.BothSizing = ElementSizing.FitToChildren;
            bgBounds.WithChildren(dropDownBounds, creatureTextBounds, closeButtonBounds, saveButtonBounds);

            // 3. Finally Dialog
            ElementBounds dialogBounds = ElementStdBounds.AutosizedMainDialog.WithAlignment(EnumDialogArea.CenterMiddle);

            List <string> entityCodes = new List <string>();
            List <string> entityNames = new List <string>();

            entityCodes.Add("");
            entityNames.Add("-");

            foreach (EntityProperties type in capi.World.EntityTypes)
            {
                entityCodes.Add(type.Code.ToString());
                entityNames.Add(Lang.Get("item-creature-" + type.Code.Path));
            }


            ElementBounds tmpBoundsDim1;
            ElementBounds tmpBoundsDim2;
            ElementBounds tmpBoundsDim3;

            SingleComposer = capi.Gui
                             .CreateCompo("spawnwerconfig", dialogBounds, false)
                             .AddDialogBG(bgBounds, true)
                             .AddDialogTitleBar(DialogTitle, OnTitleBarClose)
                             .AddStaticText("Entity to spawn", CairoFont.WhiteDetailText(), creatureTextBounds)
                             .AddDropDown(entityCodes.ToArray(), entityNames.ToArray(), 0, didSelectEntity, dropDownBounds, "entityCode")

                             .AddStaticText("Spawn area dimensions", CairoFont.WhiteDetailText(), tmpBoundsDim1 = dropDownBounds.BelowCopy(0, 10))
                             .AddStaticText("X1", CairoFont.WhiteDetailText(), tmpBoundsDim1 = tmpBoundsDim1.BelowCopy(0, 7).WithFixedSize(20, 29))
                             .AddNumberInput(tmpBoundsDim1 = tmpBoundsDim1.RightCopy(5, -7).WithFixedSize(60, 29), OnDimensionsChanged, CairoFont.WhiteDetailText(), "x1")
                             .AddStaticText("Y1", CairoFont.WhiteDetailText(), tmpBoundsDim1 = tmpBoundsDim1.RightCopy(10, 7).WithFixedSize(20, 29))
                             .AddNumberInput(tmpBoundsDim1 = tmpBoundsDim1.RightCopy(5, -7).WithFixedSize(60, 29), OnDimensionsChanged, CairoFont.WhiteDetailText(), "y1")
                             .AddStaticText("Z1", CairoFont.WhiteDetailText(), tmpBoundsDim1 = tmpBoundsDim1.RightCopy(10, 7).WithFixedSize(20, 29))
                             .AddNumberInput(tmpBoundsDim1 = tmpBoundsDim1.RightCopy(5, -7).WithFixedSize(60, 29), OnDimensionsChanged, CairoFont.WhiteDetailText(), "z1")

                             .AddStaticText("X2", CairoFont.WhiteDetailText(), tmpBoundsDim2 = dropDownBounds.FlatCopy().WithFixedSize(20, 29).FixedUnder(tmpBoundsDim1, -40))
                             .AddNumberInput(tmpBoundsDim2 = tmpBoundsDim2.RightCopy(5, -7).WithFixedSize(60, 29), OnDimensionsChanged, CairoFont.WhiteDetailText(), "x2")
                             .AddStaticText("Y2", CairoFont.WhiteDetailText(), tmpBoundsDim2 = tmpBoundsDim2.RightCopy(10, 7).WithFixedSize(20, 29))
                             .AddNumberInput(tmpBoundsDim2 = tmpBoundsDim2.RightCopy(5, -7).WithFixedSize(60, 29), OnDimensionsChanged, CairoFont.WhiteDetailText(), "y2")
                             .AddStaticText("Z2", CairoFont.WhiteDetailText(), tmpBoundsDim2 = tmpBoundsDim2.RightCopy(10, 7).WithFixedSize(20, 29))
                             .AddNumberInput(tmpBoundsDim2 = tmpBoundsDim2.RightCopy(5, -7).WithFixedSize(60, 29), OnDimensionsChanged, CairoFont.WhiteDetailText(), "z2")

                             .AddStaticText("Interval (ingame hours)", CairoFont.WhiteDetailText(), tmpBoundsDim3 = dropDownBounds.FlatCopy().WithFixedSize(300, 30).FixedUnder(tmpBoundsDim2, -40))
                             .AddNumberInput(tmpBoundsDim3 = tmpBoundsDim3.BelowCopy(0, -10).WithFixedSize(100, 29), OnIntervalChanged, CairoFont.WhiteDetailText(), "interval")

                             .AddStaticText("Max concurrent entities to spawn", CairoFont.WhiteDetailText(), tmpBoundsDim3 = tmpBoundsDim3.BelowCopy(0, 10).WithFixedSize(300, 30))
                             .AddNumberInput(tmpBoundsDim3 = tmpBoundsDim3.BelowCopy(0, -10).WithFixedSize(100, 29), OnMaxChanged, CairoFont.WhiteDetailText(), "maxentities")


                             .AddSmallButton("Close", OnButtonClose, closeButtonBounds.FixedUnder(tmpBoundsDim3, 20))
                             .AddSmallButton("Save", OnButtonSave, saveButtonBounds.FixedUnder(tmpBoundsDim3, 20))
                             .Compose()
            ;

            UpdateFromServer(this.spawnerData);
        }
Exemple #5
0
        public void initOverviewGui()
        {
            ElementBounds searchFieldBounds = ElementBounds.Fixed(GuiStyle.ElementToDialogPadding - 2, 45, 300, 30);
            ElementBounds stackListBounds   = ElementBounds.Fixed(0, 0, 500, listHeight).FixedUnder(searchFieldBounds, 5);

            ElementBounds clipBounds  = stackListBounds.ForkBoundingParent();
            ElementBounds insetBounds = stackListBounds.FlatCopy().FixedGrow(6).WithFixedOffset(-3, -3);

            ElementBounds scrollbarBounds = insetBounds.CopyOffsetedSibling(3 + stackListBounds.fixedWidth + 7).WithFixedWidth(20);

            ElementBounds closeButtonBounds = ElementBounds
                                              .FixedSize(0, 0)
                                              .FixedUnder(clipBounds, 2 * 5 + 8)
                                              .WithAlignment(EnumDialogArea.RightFixed)
                                              .WithFixedPadding(20, 4)
                                              .WithFixedAlignmentOffset(2, 0)
            ;

            // 2. Around all that is 10 pixel padding
            ElementBounds bgBounds = ElementBounds.Fill.WithFixedPadding(GuiStyle.ElementToDialogPadding);

            bgBounds.BothSizing = ElementSizing.FitToChildren;
            bgBounds.WithChildren(insetBounds, stackListBounds, scrollbarBounds, closeButtonBounds);

            // 3. Finally Dialog
            ElementBounds dialogBounds = ElementStdBounds.AutosizedMainDialog.WithAlignment(EnumDialogArea.None).WithAlignment(EnumDialogArea.CenterFixed).WithFixedPosition(0, 70);

            ElementBounds tabBounds = ElementBounds.Fixed(-200, 35, 200, 545);

            int           curTab;
            ElementBounds backButtonBounds = ElementBounds
                                             .FixedSize(0, 0)
                                             .FixedUnder(clipBounds, 2 * 5 + 5)
                                             .WithAlignment(EnumDialogArea.LeftFixed)
                                             .WithFixedPadding(20, 4)
                                             .WithFixedAlignmentOffset(-6, 3)
            ;

            overviewGui = capi.Gui
                          .CreateCompo("handbook-overview", dialogBounds)
                          .AddShadedDialogBG(bgBounds, true)
                          .AddDialogTitleBar(Lang.Get("Survival Handbook"), OnTitleBarClose)
                          .AddVerticalTabs(genTabs(out curTab), tabBounds, OnTabClicked, "verticalTabs")
                          .AddTextInput(searchFieldBounds, FilterItemsBySearchText, CairoFont.WhiteSmallishText(), "searchField")
                          .BeginChildElements(bgBounds)
                          .BeginClip(clipBounds)
                          .AddInset(insetBounds, 3)
                          .AddHandbookStackList(stackListBounds, onLeftClickListElement, shownHandbookPages, "stacklist")
                          .EndClip()
                          .AddVerticalScrollbar(OnNewScrollbarvalueOverviewPage, scrollbarBounds, "scrollbar")
                          .AddSmallButton(Lang.Get("general-back"), OnButtonBack, backButtonBounds, EnumButtonStyle.Normal, EnumTextOrientation.Center, "backButton")
                          .AddSmallButton(Lang.Get("Close Handbook"), OnButtonClose, closeButtonBounds)
                          .EndChildElements()
                          .Compose()
            ;

            overviewGui.GetScrollbar("scrollbar").SetHeights(
                (float)listHeight, (float)overviewGui.GetHandbookStackList("stacklist").insideBounds.fixedHeight
                );

            overviewGui.GetTextInput("searchField").SetPlaceHolderText("Search...");

            overviewGui.GetVerticalTab("verticalTabs").SetValue(curTab);
        }
Exemple #6
0
        protected void SetupDialog()
        {
            _isSetup = true;

            var dialogBounds = ElementStdBounds.AutosizedMainDialog.WithAlignment(EnumDialogArea.RightBottom)
                               .WithFixedAlignmentOffset(-GuiStyle.DialogToScreenPadding, -GuiStyle.DialogToScreenPadding);

            const int    switchSize    = 20;
            const int    switchPadding = 10;
            const double sliderWidth   = 200.0;
            var          font          = CairoFont.WhiteSmallText();

            var switchBounds = ElementBounds.Fixed(250, GuiStyle.TitleBarHeight, switchSize, switchSize);
            var textBounds   = ElementBounds.Fixed(0, GuiStyle.TitleBarHeight + 1.0, 240.0, switchSize);

            var applyButtonBounds = ElementBounds.Fixed(255.0, GuiStyle.TitleBarHeight, 110.0, switchSize);

            var bgBounds = ElementBounds.Fill.WithFixedPadding(GuiStyle.ElementToDialogPadding);

            bgBounds.BothSizing = ElementSizing.FitToChildren;

            var composer = capi.Gui.CreateCompo(DialogKey, dialogBounds)
                           .AddShadedDialogBG(bgBounds)
                           .AddDialogTitleBar(DialogTitle, OnTitleBarCloseClicked)
                           .BeginChildElements(bgBounds);

            foreach (var option in ConfigOptions)
            {
                composer.AddStaticText(option.Text, font, textBounds);
                if (option.Tooltip != null)
                {
                    composer.AddHoverText(option.Tooltip, font, 260, textBounds);
                }

                if (option.SliderKey != null)
                {
                    composer.AddSlider(option.SlideAction, switchBounds.FlatCopy().WithFixedWidth(sliderWidth),
                                       option.SliderKey);
                }
                else if (option.SwitchKey != null)
                {
                    composer.AddSwitch(option.ToggleAction, switchBounds, option.SwitchKey, switchSize);
                }

                if (option.ApplyAction != null)
                {
                    composer.AddSmallButton(option.ApplyText, option.ApplyAction, applyButtonBounds);
                }

                textBounds        = textBounds.BelowCopy(fixedDeltaY: switchPadding);
                switchBounds      = switchBounds.BelowCopy(fixedDeltaY: switchPadding);
                applyButtonBounds = applyButtonBounds.BelowCopy(fixedDeltaY: switchPadding);
            }

            SingleComposer = composer.EndChildElements().Compose();

            foreach (var option in ConfigOptions.Where(option => option.SliderKey != null && !option.InstantSlider))
            {
                SingleComposer.GetSlider(option.SliderKey).TriggerOnlyOnMouseUp();
            }
        }
Exemple #7
0
        public void SetupDialog(BEEAssembler bea)
        {
            ElementBounds dialogBounds = ElementStdBounds.AutosizedMainDialog.WithAlignment(EnumDialogArea.CenterMiddle);

            // Just a simple 300x100 pixel box with 40 pixels top spacing for the title bar
            ElementBounds textBounds = ElementBounds.Fixed(0, 40, 600, 600);

            // Background boundaries. Again, just make it fit it's child elements, then add the text as a child element
            ElementBounds bgBounds = ElementBounds.Fill.WithFixedPadding(GuiStyle.ElementToDialogPadding);

            bgBounds.BothSizing = ElementSizing.FitToChildren;
            bgBounds.WithChildren(textBounds);
            string guicomponame = bea.Pos.ToString() + "Assembler";
            string statustext   = "";
            string alertred     = "<font color=\"#ffbbaa\">";//<font <color=\"#ffdddd\">>";

            if (!bea.IsPowered)
            {
                statustext += alertred;
            }
            else if (bea.DeviceState == BEEBaseDevice.enDeviceState.MATERIALHOLD)
            {
                statustext += alertred;
            }
            else if (bea.DeviceState == BEEBaseDevice.enDeviceState.RUNNING)
            {
                statustext += "<font color=\"#aaff55\">";
            }
            else
            {
                statustext += "<font>";
            }
            statustext += "<strong>STATUS: " + bea.Status + "</strong></font><br><br>";
            statustext += "Making <strong>" + bea.FG.ToUpper() + "</strong><br><br>";
            statustext += "Requires <strong>" + bea.RM + "</strong>";
            if (bea.Materials.Length > 0 && bea.DeviceState == BEEBaseDevice.enDeviceState.MATERIALHOLD)
            {
                statustext += " of material ";
                statustext += "<font><strong>";

                for (int c = 0; c < bea.Materials.Length; c++)
                {
                    if (c == bea.Materials.Length - 1)
                    {
                        statustext += ", or ";
                    }
                    else if (c != 0)
                    {
                        statustext += ", ";
                    }

                    statustext += bea.Materials[c];
                }
                statustext += ".</font></strong>";
            }
            SingleComposer = capi.Gui.CreateCompo(guicomponame, dialogBounds)
                             .AddShadedDialogBG(bgBounds)
                             .AddDialogTitleBar("Metal Press Status", OnTitleBarCloseClicked)
                             .AddRichtext(statustext, CairoFont.WhiteDetailText(), textBounds)

                             .Compose()
            ;
        }
Exemple #8
0
        void initOverviewGui()
        {
            ElementBounds searchFieldBounds = ElementBounds.Fixed(GuiStyle.ElementToDialogPadding - 2, 45, 300, 30);
            ElementBounds stackListBounds   = ElementBounds.Fixed(0, 0, 400, listHeight).FixedUnder(searchFieldBounds, 5);

            ElementBounds clipBounds  = stackListBounds.ForkBoundingParent();
            ElementBounds insetBounds = stackListBounds.FlatCopy().FixedGrow(6).WithFixedOffset(-3, -3);

            ElementBounds scrollbarBounds = insetBounds.CopyOffsetedSibling(3 + stackListBounds.fixedWidth + 7).WithFixedWidth(20);

            ElementBounds closeButtonBounds = ElementBounds
                                              .FixedSize(0, 0)
                                              .FixedUnder(clipBounds, 2 * 5 + 8)
                                              .WithAlignment(EnumDialogArea.RightFixed)
                                              .WithFixedPadding(20, 4)
                                              .WithFixedAlignmentOffset(2, 0)
            ;

            // 2. Around all that is 10 pixel padding
            ElementBounds bgBounds = ElementBounds.Fill.WithFixedPadding(GuiStyle.ElementToDialogPadding);

            bgBounds.BothSizing = ElementSizing.FitToChildren;
            bgBounds.WithChildren(insetBounds, stackListBounds, scrollbarBounds, closeButtonBounds);

            // 3. Finally Dialog
            ElementBounds dialogBounds = ElementStdBounds.AutosizedMainDialog.WithAlignment(EnumDialogArea.CenterMiddle);

            ElementBounds tabBounds = ElementBounds.Fixed(-130, 35, 130, 545);

            GuiTab[] tabs = new GuiTab[2];
            tabs[0] = new GuiTab()
            {
                DataInt = 0,
                Name    = Lang.Get("Blocks and Items"),
            };
            tabs[1] = new GuiTab()
            {
                DataInt = 1,
                Name    = Lang.Get("Crafting mechanics")
            };

            overviewGui = capi.Gui
                          .CreateCompo("handbook-overview", dialogBounds)
                          .AddShadedDialogBG(bgBounds, true)
                          .AddDialogTitleBar(Lang.Get("Survival Handbook"), OnTitleBarClose)
                          //.AddVerticalTabs(tabs, tabBounds, OnTabClicked, "verticalTabs")
                          .AddTextInput(searchFieldBounds, FilterItemsBySearchText, CairoFont.WhiteSmallishText(), "searchField")
                          .BeginChildElements(bgBounds)
                          .BeginClip(clipBounds)
                          .AddInset(insetBounds, 3)
                          .AddHandbookStackList(stackListBounds, onLeftClickListElement, listElements, "stacklist")
                          .EndClip()
                          .AddVerticalScrollbar(OnNewScrollbarvalueOverviewPage, scrollbarBounds, "scrollbar")
                          .AddSmallButton(Lang.Get("Close Handbook"), OnButtonClose, closeButtonBounds)
                          .EndChildElements()
                          .Compose()
            ;

            overviewGui.GetScrollbar("scrollbar").SetHeights(
                (float)listHeight, (float)overviewGui.GetHandbookStackList("stacklist").insideBounds.fixedHeight
                );
        }
Exemple #9
0
        public override void OnOwnPlayerDataReceived()
        {
            base.OnOwnPlayerDataReceived();

            //ElementBounds dialogBounds = ElementBounds.Fixed(EnumDialogArea.LeftMiddle, 30, 0, 465, 500);
            //ElementBounds bgBounds = ElementBounds.Fixed(EnumDialogArea.LeftMiddle, 0, -150, 465, 200);
            ElementBounds radialRoot   = ElementBounds.Fixed(EnumDialogArea.LeftMiddle, 0, 0, 25, 25);
            ElementBounds dialogBounds = radialRoot.CopyOffsetedSibling(0, 0, 200, 100);
            ElementBounds bgBounds     = dialogBounds.CopyOffsetedSibling();

            radialRoot = radialRoot.WithFixedOffset(165, 15);

            SingleComposer = capi.Gui.CreateCompo("claim", dialogBounds)
                             .AddDialogTitleBar("Claims", () => TryClose(), CairoFont.WhiteSmallText())
                             .AddDialogBG(bgBounds)
                             .AddTextToggleButtons(new string[] { "New", "Start", "End", "Add", "Cancel", "Save", "U", "D", "N", "S", "E", "W" }, CairoFont.ButtonText().WithFontSize(10),
                                                   i =>
            {
                int m = op ? -1 : 1;
                switch (i)
                {
                case 0:
                    capi.SendChatMessage("/land claim new");
                    break;

                case 1:
                    capi.SendChatMessage("/land claim start");
                    break;

                case 2:
                    capi.SendChatMessage("/land claim end");
                    break;

                case 3:
                    capi.SendChatMessage("/land claim add");
                    break;

                case 4:
                    capi.SendChatMessage("/land claim cancel");
                    break;

                case 5:
                    capi.SendChatMessage("/land claim save " + capi.World.Claims.All.Count);
                    break;

                case 6:
                    capi.SendChatMessage("/land claim gu " + m);
                    break;

                case 7:
                    capi.SendChatMessage("/land claim gd " + m);
                    break;

                case 8:
                    capi.SendChatMessage("/land claim gn " + m);
                    break;

                case 9:
                    capi.SendChatMessage("/land claim gs " + m);
                    break;

                case 10:
                    capi.SendChatMessage("/land claim ge " + m);
                    break;

                case 11:
                    capi.SendChatMessage("/land claim gw " + m);
                    break;

                default:
                    break;
                }
                capi.Event.RegisterCallback(dt => SingleComposer.GetToggleButton("buttons-" + i).On = false, 50);
            },
                                                   new ElementBounds[]
            {
                radialRoot.CopyOffsetedSibling(-150, -25, 25),
                radialRoot.CopyOffsetedSibling(-150, 0, 25),
                radialRoot.CopyOffsetedSibling(-150, 25, 25),
                radialRoot.CopyOffsetedSibling(-100, 0, 25),
                radialRoot.CopyOffsetedSibling(-100, -25, 25),
                radialRoot.CopyOffsetedSibling(-100, 25, 25),
                radialRoot.CopyOffsetedSibling(-50, -25),
                radialRoot.CopyOffsetedSibling(-50, 25),
                radialRoot.CopyOffsetedSibling(0, -25),
                radialRoot.CopyOffsetedSibling(0, 25),
                radialRoot.CopyOffsetedSibling(25, 0),
                radialRoot.CopyOffsetedSibling(-25, 0),
                radialRoot,
            }, "buttons")
                             .AddToggleButton("OP", CairoFont.ButtonText().WithFontSize(10),
                                              b =>
            {
                op = b;
            }, radialRoot)
                             .Compose();
        }
Exemple #10
0
        private void SetupDialog(int numSlots, int numInstalledUpgrades)
        {
            // title bar
            var bgBounds     = ElementStdBounds.DialogBackground();
            var dialogBounds = ElementStdBounds.AutosizedMainDialog.WithChild(bgBounds);

            int    searchCaretPos;
            string searchText;
            bool   searchHasFocus;

            if (SingleComposer == null)
            {
                SingleComposer = capi.Gui.CreateCompo("chardis", dialogBounds);
                searchCaretPos = 0;
                searchText     = "";
                searchHasFocus = true;
            }
            else
            {
                var oldSearch = SingleComposer.GetTextInput(SearchBoxKey);
                searchCaretPos = oldSearch?.CaretPosInLine ?? 0;
                searchText     = oldSearch?.GetText() ?? "";
                searchHasFocus = oldSearch?.HasFocus ?? true;
                SingleComposer.Clear(dialogBounds);
            }

            var numVisibleSlots = GetFilteredSlotCount();
            var rows            = (int)Math.Ceiling(numVisibleSlots / (double)GridColumns);

            SingleComposer
            .AddShadedDialogBG(bgBounds)
            .AddDialogTitleBar(Lang.Get("chardis:title"), () => TryClose())
            .BeginChildElements(bgBounds);
            var titleBarBounds = ElementStdBounds.TitleBar();

            bgBounds.WithChild(titleBarBounds);

            // search text box
            var searchBounds = ElementBounds.FixedSize(200, 30).FixedUnder(titleBarBounds).WithFixedOffset(-InsetSize, 0);

            bgBounds.WithChild(searchBounds);
            SingleComposer.AddInteractiveElement(new TextBox(capi, searchBounds, FilterItems, CairoFont.WhiteSmallishText()), SearchBoxKey);

            var searchBox = SingleComposer.GetTextInput(SearchBoxKey);

            searchBox.SetPlaceHolderText(Lang.Get("chardis:search-placeholder"));
            searchBox.LoadValue(searchText);
            searchBox.SetCaretPos(searchCaretPos);
            if (searchHasFocus)
            {
                SingleComposer.FocusElement(SingleComposer.GetTextInput(SearchBoxKey).TabIndex);
            }

            if (_upgradeSlot != null)
            {
                var countBounds = ElementBounds.FixedSize(32, 32).FixedUnder(titleBarBounds, 10).WithAlignment(EnumDialogArea.RightFixed);
                bgBounds.WithChild(countBounds);
                SingleComposer.AddInteractiveElement(new UpgradeSlot(capi, countBounds, _upgradeSlot));
            }

            // stacklist
            var stacklistBounds =
                ElementBounds.FixedSize(410, StackListHeight).FixedUnder(searchBounds, Padding);

            bgBounds.WithChild(stacklistBounds);
            var clipBounds      = stacklistBounds.ForkBoundingParent();
            var insetBounds     = stacklistBounds.FlatCopy().FixedGrow(6).WithFixedOffset(-3, -3);
            var scrollbarBounds =
                insetBounds.CopyOffsetedSibling(3 + stacklistBounds.fixedWidth + 7).WithFixedWidth(20);

            var pad        = GuiElementItemSlotGridBase.unscaledSlotPadding;
            var inv        = _chardisBlockEntity.Inventory;
            var slotBounds = ElementStdBounds.SlotGrid(EnumDialogArea.None, pad, 40 + pad, GridColumns, 1).FixedGrow(2 * pad, 0);

            SingleComposer
            .BeginClip(clipBounds)
            .AddInset(insetBounds, InsetSize)
            .AddItemSlotGrid(
                inv,
                DoSendPacket,
                GridColumns,
                slotBounds,
                StackListKey
                )
            .EndClip()
            ;

            var stacklist = SingleComposer.GetSlotGrid(StackListKey);

            SingleComposer.AddVerticalScrollbar(value =>
            {
                if (SingleComposer.GetSlotGrid(StackListKey).Bounds.fixedHeight > StackListHeight)
                {
                    stacklist.Bounds.fixedY = InsetSize - value;
                }
                else
                {
                    stacklist.Bounds.fixedY = 0;
                }
                stacklist.Bounds.CalcWorldBounds();
            }, scrollbarBounds, ScrollBarKey)
            ;

            stacklist.Bounds.fixedHeight = rows * (GuiElementPassiveItemSlot.unscaledSlotSize +
                                                   GuiElementItemSlotGridBase.unscaledSlotPadding);
            stacklist.Bounds.CalcWorldBounds();
            var scrollbar = SingleComposer.GetScrollbar(ScrollBarKey);

            scrollbar.SetHeights(
                StackListHeight,
                Math.Max(StackListHeight, (float)stacklist.Bounds.fixedHeight)
                );
            scrollbar.OnMouseWheel(capi, new MouseWheelEventArgs {
                deltaPrecise = 999999
            });                                // scroll to top hax

            SingleComposer.EndChildElements(); // bgBounds
            SingleComposer.Compose();
        }
Exemple #11
0
        public GuiDialogLogViewer(string text, ICoreClientAPI capi) : base("Log Viewer", capi)
        {
            ElementBounds topTextBounds = ElementBounds.Fixed(GuiStyle.ElementToDialogPadding, 40, 900, 30);

            ElementBounds logtextBounds = ElementBounds.Fixed(0, 0, 900, 300).FixedUnder(topTextBounds, 5);

            // Clipping bounds for textarea
            ElementBounds clippingBounds = logtextBounds.ForkBoundingParent();

            ElementBounds insetBounds = logtextBounds.FlatCopy().FixedGrow(6).WithFixedOffset(-3, -3);

            ElementBounds scrollbarBounds = insetBounds.CopyOffsetedSibling(logtextBounds.fixedWidth + 7).WithFixedWidth(20);

            ElementBounds closeButtonBounds = ElementBounds
                                              .FixedSize(0, 0)
                                              .FixedUnder(clippingBounds, 2 * 5)
                                              .WithAlignment(EnumDialogArea.RightFixed)
                                              .WithFixedPadding(20, 4)
            ;


            // 2. Around all that is 10 pixel padding
            ElementBounds bgBounds = ElementBounds.Fill.WithFixedPadding(GuiStyle.ElementToDialogPadding);

            bgBounds.BothSizing = ElementSizing.FitToChildren;
            bgBounds.WithChildren(insetBounds, clippingBounds, scrollbarBounds, closeButtonBounds);

            // 3. Finally Dialog
            ElementBounds dialogBounds = ElementStdBounds.AutosizedMainDialog.WithAlignment(EnumDialogArea.CenterMiddle);


            SingleComposer = capi.Gui
                             .CreateCompo("dialogviewer", dialogBounds)
                             .AddShadedDialogBG(bgBounds, true)
                             .AddDialogTitleBar(DialogTitle, OnTitleBarClose)
                             .AddStaticText("The following warnings and errors were reported during startup:", CairoFont.WhiteDetailText(), topTextBounds)
                             .BeginChildElements(bgBounds)
                             .BeginClip(clippingBounds)
                             .AddInset(insetBounds, 3)
                             .AddDynamicText("", CairoFont.WhiteDetailText(), EnumTextOrientation.Left, logtextBounds, "text")
                             .EndClip()
                             .AddVerticalScrollbar(OnNewScrollbarvalue, scrollbarBounds, "scrollbar")
                             .AddSmallButton("Close", OnButtonClose, closeButtonBounds)
                             .EndChildElements()
                             .Compose()
            ;

            GuiElementDynamicText logtextElem = SingleComposer.GetDynamicText("text");

            logtextElem.AutoHeight();
            logtextElem.SetNewText(text);

            SingleComposer.GetScrollbar("scrollbar").SetHeights(
                (float)300, (float)logtextBounds.fixedHeight
                );
        }
        void changeClass(int dir)
        {
            currentClassIndex = GameMath.Mod(currentClassIndex + dir, modSys.characterClasses.Count);

            CharacterClass chclass = modSys.characterClasses[currentClassIndex];

            Composers["createcharacter"].GetDynamicText("className").SetNewText(Lang.Get("characterclass-" + chclass.Code));

            StringBuilder fulldesc   = new StringBuilder();
            StringBuilder attributes = new StringBuilder();

            fulldesc.AppendLine(Lang.Get("characterdesc-" + chclass.Code));
            fulldesc.AppendLine();
            fulldesc.AppendLine(Lang.Get("traits-title"));

            var chartraits = chclass.Traits.Select(code => modSys.TraitsByCode[code]).OrderBy(trait => (int)trait.Type);

            foreach (var trait in chartraits)
            {
                attributes.Clear();
                foreach (var val in trait.Attributes)
                {
                    if (attributes.Length > 0)
                    {
                        attributes.Append(", ");
                    }
                    attributes.Append(Lang.Get(string.Format(GlobalConstants.DefaultCultureInfo, "charattribute-{0}-{1}", val.Key, val.Value)));
                }

                if (attributes.Length > 0)
                {
                    fulldesc.AppendLine(Lang.Get("traitwithattributes", Lang.Get("trait-" + trait.Code), attributes));
                }
                else
                {
                    string desc = Lang.GetIfExists("traitdesc-" + trait.Code);
                    if (desc != null)
                    {
                        fulldesc.AppendLine(Lang.Get("traitwithattributes", Lang.Get("trait-" + trait.Code), desc));
                    }
                    else
                    {
                        fulldesc.AppendLine(Lang.Get("trait-" + trait.Code));
                    }
                }
            }

            if (chclass.Traits.Length == 0)
            {
                fulldesc.AppendLine("No positive or negative traits");
            }

            Composers["createcharacter"].GetRichtext("characterDesc").SetNewText(fulldesc.ToString(), CairoFont.WhiteDetailText());

            modSys.setCharacterClass(capi.World.Player.Entity, chclass.Code, true);

            var essr = capi.World.Player.Entity.Properties.Client.Renderer as EntitySkinnableShapeRenderer;

            essr.TesselateShape();
        }
        protected void ComposeGuis()
        {
            double pad      = GuiElementItemSlotGridBase.unscaledSlotPadding;
            double slotsize = GuiElementPassiveItemSlot.unscaledSlotSize;

            characterInv = capi.World.Player.InventoryManager.GetOwnInventory(GlobalConstants.characterInvClassName);

            ElementBounds tabBounds = ElementBounds.Fixed(0, -25, 450, 25);

            double ypos = 20 + pad;



            ElementBounds bgBounds = ElementBounds.FixedSize(717, dlgHeight).WithFixedPadding(GuiStyle.ElementToDialogPadding);

            ElementBounds dialogBounds = ElementBounds.FixedSize(757, dlgHeight + 40).WithAlignment(EnumDialogArea.CenterMiddle)
                                         .WithFixedAlignmentOffset(GuiStyle.DialogToScreenPadding, 0);


            GuiTab[] tabs = new GuiTab[] {
                new GuiTab()
                {
                    Name = "Skin & Voice", DataInt = 0
                },
                new GuiTab()
                {
                    Name = "Class", DataInt = 1
                },
                //  new GuiTab() { Name = "Outfit", DataInt = 2 }
            };

            Composers["createcharacter"] =
                capi.Gui
                .CreateCompo("createcharacter", dialogBounds)
                .AddShadedDialogBG(bgBounds, true)
                .AddDialogTitleBar(curTab == 0 ? Lang.Get("Customize Skin") : (curTab == 1 ? Lang.Get("Select character class") : Lang.Get("Select your outfit")), OnTitleBarClose)
                .AddHorizontalTabs(tabs, tabBounds, onTabClicked, CairoFont.WhiteSmallText().WithWeight(Cairo.FontWeight.Bold), CairoFont.WhiteSmallText().WithWeight(Cairo.FontWeight.Bold), "tabs")
                .BeginChildElements(bgBounds)
            ;

            capi.World.Player.Entity.hideClothing = false;

            if (curTab == 0)
            {
                var skinMod = capi.World.Player.Entity.GetBehavior <EntityBehaviorExtraSkinnable>();

                capi.World.Player.Entity.hideClothing = charNaked;
                var essr = capi.World.Player.Entity.Properties.Client.Renderer as EntitySkinnableShapeRenderer;
                essr.TesselateShape();

                CairoFont smallfont     = CairoFont.WhiteSmallText();
                var       textExt       = smallfont.GetTextExtents(Lang.Get("Show dressed"));
                int       colorIconSize = 22;

                ElementBounds leftColBounds = ElementBounds.Fixed(0, ypos, 204, dlgHeight - 59).FixedGrow(2 * pad, 2 * pad);

                insetSlotBounds = ElementBounds.Fixed(0, ypos + 2, 265, leftColBounds.fixedHeight - 2 * pad + 10).FixedRightOf(leftColBounds, 10);
                ElementBounds rightColBounds     = ElementBounds.Fixed(0, ypos, 54, dlgHeight - 59).FixedGrow(2 * pad, 2 * pad).FixedRightOf(insetSlotBounds, 10);
                ElementBounds toggleButtonBounds = ElementBounds.Fixed(
                    (int)insetSlotBounds.fixedX + insetSlotBounds.fixedWidth / 2 - textExt.Width / RuntimeEnv.GUIScale / 2 - 12,
                    0,
                    textExt.Width / RuntimeEnv.GUIScale + 1,
                    textExt.Height / RuntimeEnv.GUIScale
                    )
                                                   .FixedUnder(insetSlotBounds, 4).WithAlignment(EnumDialogArea.LeftFixed).WithFixedPadding(12, 6)
                ;

                ElementBounds bounds     = null;
                ElementBounds prevbounds = null;

                double leftX = 0;

                foreach (var skinpart in skinMod.AvailableSkinParts)
                {
                    bounds = ElementBounds.Fixed(leftX, (prevbounds == null || prevbounds.fixedY == 0) ? -10 : prevbounds.fixedY + 8, colorIconSize, colorIconSize);

                    string code = skinpart.Code;

                    AppliedSkinnablePartVariant appliedVar = skinMod.AppliedSkinParts.FirstOrDefault(sp => sp.PartCode == code);


                    if (skinpart.Type == EnumSkinnableType.Texture && !skinpart.UseDropDown)
                    {
                        int   selectedIndex = 0;
                        int[] colors        = new int[skinpart.Variants.Length];

                        for (int i = 0; i < skinpart.Variants.Length; i++)
                        {
                            colors[i] = skinpart.Variants[i].Color;

                            if (appliedVar?.Code == skinpart.Variants[i].Code)
                            {
                                selectedIndex = i;
                            }
                        }

                        Composers["createcharacter"].AddRichtext(Lang.Get("skinpart-" + code), CairoFont.WhiteSmallText(), bounds     = bounds.BelowCopy(0, 10).WithFixedSize(210, 22));
                        Composers["createcharacter"].AddColorListPicker(colors, (index) => onToggleSkinPartColor(code, index), bounds = bounds.BelowCopy(0, 0).WithFixedSize(colorIconSize, colorIconSize), 180, "picker-" + code);

                        for (int i = 0; i < colors.Length; i++)
                        {
                            var picker = Composers["createcharacter"].GetColorListPicker("picker-" + code + "-" + i);
                            picker.ShowToolTip = true;
                            picker.TooltipText = Lang.Get("color-" + skinpart.Variants[i].Code);

                            //Console.WriteLine("\"" + Lang.Get("color-" + skinpart.Variants[i].Code) + "\": \""+ skinpart.Variants[i].Code + "\"");
                        }

                        Composers["createcharacter"].ColorListPickerSetValue("picker-" + code, selectedIndex);
                    }
                    else
                    {
                        int selectedIndex = 0;

                        string[] names  = new string[skinpart.Variants.Length];
                        string[] values = new string[skinpart.Variants.Length];

                        for (int i = 0; i < skinpart.Variants.Length; i++)
                        {
                            names[i]  = Lang.Get("skinpart-" + code + "-" + skinpart.Variants[i].Code);
                            values[i] = skinpart.Variants[i].Code;

                            //Console.WriteLine("\"" + names[i] + "\": \"" + skinpart.Variants[i].Code + "\",");

                            if (appliedVar?.Code == values[i])
                            {
                                selectedIndex = i;
                            }
                        }


                        Composers["createcharacter"].AddRichtext(Lang.Get("skinpart-" + code), CairoFont.WhiteSmallText(), bounds = bounds.BelowCopy(0, 10).WithFixedSize(210, 22));

                        string tooltip = Lang.GetIfExists("skinpartdesc-" + code);
                        if (tooltip != null)
                        {
                            Composers["createcharacter"].AddHoverText(tooltip, CairoFont.WhiteSmallText(), 300, bounds = bounds.FlatCopy());
                        }

                        Composers["createcharacter"].AddDropDown(values, names, selectedIndex, (variantcode, selected) => onToggleSkinPartColor(code, variantcode), bounds = bounds.BelowCopy(0, 0).WithFixedSize(200, 25), "dropdown-" + code);
                    }

                    prevbounds = bounds.FlatCopy();

                    if (skinpart.Colbreak)
                    {
                        leftX             = insetSlotBounds.fixedX + insetSlotBounds.fixedWidth + 22;
                        prevbounds.fixedY = 0;
                    }
                }



                Composers["createcharacter"]
                .AddInset(insetSlotBounds, 2)
                .AddToggleButton(Lang.Get("Show dressed"), smallfont, OnToggleDressOnOff, toggleButtonBounds, "showdressedtoggle")
                .AddSmallButton(Lang.Get("Randomize"), OnRandomizeSkin, ElementBounds.Fixed(0, dlgHeight - 30).WithAlignment(EnumDialogArea.LeftFixed).WithFixedPadding(12, 6), EnumButtonStyle.Normal, EnumTextOrientation.Center)
                .AddSmallButton(Lang.Get("Confirm Skin"), OnNext, ElementBounds.Fixed(0, dlgHeight - 30).WithAlignment(EnumDialogArea.RightFixed).WithFixedPadding(12, 6), EnumButtonStyle.Normal, EnumTextOrientation.Center)
                ;

                Composers["createcharacter"].GetToggleButton("showdressedtoggle").SetValue(!charNaked);
            }

            if (curTab == 1)
            {
                var essr = capi.World.Player.Entity.Properties.Client.Renderer as EntitySkinnableShapeRenderer;
                essr.TesselateShape();

                ypos -= 10;

                ElementBounds leftColBounds = ElementBounds.Fixed(0, ypos, 0, dlgHeight - 47).FixedGrow(2 * pad, 2 * pad);
                insetSlotBounds = ElementBounds.Fixed(0, ypos + 25, 190, leftColBounds.fixedHeight - 2 * pad + 10).FixedRightOf(leftColBounds, 10);

                //ElementBounds leftSlotBounds = ElementStdBounds.SlotGrid(EnumDialogArea.None, 0, ypos, 0, rows).FixedGrow(2 * pad, 2 * pad);
                //insetSlotBounds = ElementBounds.Fixed(0, ypos + 25, 190, leftSlotBounds.fixedHeight - 2 * pad + 8 + 25).FixedRightOf(leftSlotBounds, 10);

                ElementBounds rightSlotBounds = ElementStdBounds.SlotGrid(EnumDialogArea.None, 0, ypos, 1, rows).FixedGrow(2 * pad, 2 * pad).FixedRightOf(insetSlotBounds, 10);

                ElementBounds prevButtonBounds = ElementBounds.Fixed(0, ypos + 25, 35, slotsize - 4).WithFixedPadding(2).FixedRightOf(insetSlotBounds, 20);
                ElementBounds centerTextBounds = ElementBounds.Fixed(0, ypos + 25, 200, slotsize - 4 - 8).FixedRightOf(prevButtonBounds, 20);

                ElementBounds charclasssInset = centerTextBounds.ForkBoundingParent(4, 4, 4, 4);

                ElementBounds nextButtonBounds = ElementBounds.Fixed(0, ypos + 25, 35, slotsize - 4).WithFixedPadding(2).FixedRightOf(charclasssInset, 20);

                CairoFont font = CairoFont.WhiteMediumText();
                centerTextBounds.fixedY += (centerTextBounds.fixedHeight - font.GetFontExtents().Height / RuntimeEnv.GUIScale) / 2;

                ElementBounds charTextBounds = ElementBounds.Fixed(0, 0, 480, 100).FixedUnder(prevButtonBounds, 20).FixedRightOf(insetSlotBounds, 20);

                Composers["createcharacter"]
                .AddInset(insetSlotBounds, 2)

                .AddIconButton("left", (on) => changeClass(-1), prevButtonBounds.FlatCopy())
                .AddInset(charclasssInset, 2)
                .AddDynamicText("Commoner", font.Clone().WithOrientation(EnumTextOrientation.Center), centerTextBounds, "className")
                .AddIconButton("right", (on) => changeClass(1), nextButtonBounds.FlatCopy())

                .AddRichtext("", CairoFont.WhiteDetailText(), charTextBounds, "characterDesc")
                .AddSmallButton(Lang.Get("Confirm Class"), OnConfirm, ElementBounds.Fixed(0, dlgHeight - 30).WithAlignment(EnumDialogArea.RightFixed).WithFixedPadding(12, 6), EnumButtonStyle.Normal, EnumTextOrientation.Center)
                ;

                changeClass(0);
            }

            /*if (curTab == 2) {
             *
             *  ElementBounds leftPrevButtonBounds = ElementBounds.Fixed(0, ypos + 52, 19, slotsize - 4).WithFixedPadding(2);
             *  ElementBounds leftNextButtonBounds = ElementBounds.Fixed(0, ypos + 52, 19, slotsize - 4).WithFixedPadding(2).FixedRightOf(leftPrevButtonBounds, 6);
             *
             *  ElementBounds leftSlotBounds = ElementStdBounds.SlotGrid(EnumDialogArea.None, 0, ypos, 1, rows).FixedGrow(2 * pad, 2 * pad).FixedRightOf(leftNextButtonBounds, 8);
             *  insetSlotBounds = ElementBounds.Fixed(0, ypos + 25, 220, leftSlotBounds.fixedHeight - 2 * pad - 4 + 25).FixedRightOf(leftSlotBounds, 10);
             *  ElementBounds rightSlotBounds = ElementStdBounds.SlotGrid(EnumDialogArea.None, 0, ypos, 1, rows).FixedGrow(2 * pad, 2 * pad).FixedRightOf(insetSlotBounds, 10);
             *
             *  ElementBounds rightPrevButtonBounds = ElementBounds.Fixed(20, ypos + 1, 19, slotsize - 4).WithFixedPadding(2).FixedRightOf(rightSlotBounds, 6);
             *  ElementBounds rightNextButtonBounds = ElementBounds.Fixed(20, ypos + 1, 19, slotsize - 4).WithFixedPadding(2).FixedRightOf(rightPrevButtonBounds, 6);
             *
             *
             *
             *  Composers["createcharacter"]
             *      .AddItemSlotGrid(characterInv, SendInvPacket, 1, new int[] { 0, 1, 2, 11, 3, 4 }, leftSlotBounds, "leftSlots")
             *
             *          // Shoulder
             *          .AddIconButton("left", (on) => OnPrevious(1), leftPrevButtonBounds.FlatCopy())
             *          .AddIconButton("right", (on) => OnNext(1), leftNextButtonBounds.FlatCopy())
             *
             *          // Upper body
             *          .AddIconButton("left", (on) => OnPrevious(2), leftPrevButtonBounds = leftPrevButtonBounds.BelowCopy(0, 3))
             *          .AddIconButton("right", (on) => OnNext(2), leftNextButtonBounds = leftNextButtonBounds.BelowCopy(0, 3))
             *
             *          // Trousers
             *          .AddIconButton("left", (on) => OnPrevious(3), leftPrevButtonBounds = leftPrevButtonBounds.BelowCopy(0, 3).BelowCopy(0, 3))
             *          .AddIconButton("right", (on) => OnNext(3), leftNextButtonBounds = leftNextButtonBounds.BelowCopy(0, 3).BelowCopy(0, 3))
             *
             *          // Shoes
             *          .AddIconButton("left", (on) => OnPrevious(4), leftPrevButtonBounds = leftPrevButtonBounds.BelowCopy(0, 3))
             *          .AddIconButton("right", (on) => OnNext(4), leftNextButtonBounds = leftNextButtonBounds.BelowCopy(0, 3))
             *
             *          // Gloves (on the right)
             *          //  .AddIconButton("left", (on) => OnPrevious(5), rightPrevButtonBounds = rightPrevButtonBounds.BelowCopy(0, 3).BelowCopy(0, 3).BelowCopy(0, 3).BelowCopy(0, 3))
             *          // .AddIconButton("right", (on) => OnNext(5), rightNextButtonBounds = rightNextButtonBounds.BelowCopy(0, 3).BelowCopy(0, 3).BelowCopy(0, 3).BelowCopy(0, 3))
             *
             *          .AddInset(insetSlotBounds, 2)
             *          //.AddItemSlotGrid(characterInv, SendInvPacket, 1, new int[] { 6, 7, 8, 10, 5, 9 }, rightSlotBounds, "rightSlots")
             *
             *          .AddSmallButton(Lang.Get("Randomize"), OnRandomizeClothes, ElementBounds.Fixed(0, 0).FixedUnder(rightSlotBounds, 20).WithAlignment(EnumDialogArea.LeftFixed).WithFixedPadding(10, 4), EnumButtonStyle.Normal, EnumTextOrientation.Center)
             *          .AddSmallButton(Lang.Get("Confirm Selection"), OnConfirm, ElementBounds.Fixed(0, 0).FixedUnder(rightSlotBounds, 20).WithAlignment(EnumDialogArea.RightFixed).WithFixedPadding(10, 4), EnumButtonStyle.Normal, EnumTextOrientation.Center)
             *
             *      .EndChildElements()
             *  ;
             * }*/


            var tabElem = Composers["createcharacter"].GetHorizontalTabs("tabs");

            tabElem.unscaledTabSpacing = 20;
            tabElem.unscaledTabPadding = 10;
            tabElem.activeElement      = curTab;

            Composers["createcharacter"].Compose();


            /*if (curTab == 2)
             * {
             *  Composers["createcharacter"].GetSlotGrid("leftSlots").CanClickSlot = (slotid) => { return false; };
             *  //Composers["createcharacter"].GetSlotGrid("rightSlots").CanClickSlot = (slotid) => { return false; };
             * }*/
        }
        void SetupDialog()
        {
            ItemSlot hoveredSlot = capi.World.Player.InventoryManager.CurrentHoveredSlot;

            if (hoveredSlot != null && hoveredSlot.Inventory?.InventoryID != Inventory?.InventoryID)
            {
                hoveredSlot = null;
            }

            string newOutputText           = Attributes.GetString("outputText", "");
            bool   newHaveCookingContainer = Attributes.GetInt("haveCookingContainer") > 0;

            GuiElementDynamicText outputTextElem;

            if (haveCookingContainer == newHaveCookingContainer && SingleComposer != null)
            {
                outputTextElem = SingleComposer.GetDynamicText("outputText");
                outputTextElem.SetNewText(newOutputText, true);
                SingleComposer.GetCustomDraw("symbolDrawer").Redraw();

                haveCookingContainer = newHaveCookingContainer;
                currentOutputText    = newOutputText;

                outputTextElem.Bounds.fixedOffsetY = 0;

                if (outputTextElem.QuantityTextLines > 2)
                {
                    outputTextElem.Bounds.fixedOffsetY = -outputTextElem.Font.GetFontExtents().Height / RuntimeEnv.GUIScale * 0.65;
                }

                outputTextElem.Bounds.CalcWorldBounds();

                return;
            }


            haveCookingContainer = newHaveCookingContainer;
            currentOutputText    = newOutputText;

            int qCookingSlots = Attributes.GetInt("quantityCookingSlots");

            ElementBounds stoveBounds = ElementBounds.Fixed(0, 0, 210, 250);

            cookingSlotsSlotBounds              = ElementStdBounds.SlotGrid(EnumDialogArea.None, 0, 30 + 45, 4, qCookingSlots / 4);
            cookingSlotsSlotBounds.fixedHeight += 10;

            double top = cookingSlotsSlotBounds.fixedHeight + cookingSlotsSlotBounds.fixedY;

            ElementBounds inputSlotBounds  = ElementStdBounds.SlotGrid(EnumDialogArea.None, 0, top, 1, 1);
            ElementBounds fuelSlotBounds   = ElementStdBounds.SlotGrid(EnumDialogArea.None, 0, 110 + top, 1, 1);
            ElementBounds outputSlotBounds = ElementStdBounds.SlotGrid(EnumDialogArea.None, 153, top, 1, 1);

            // 2. Around all that is 10 pixel padding
            ElementBounds bgBounds = ElementBounds.Fill.WithFixedPadding(GuiStyle.ElementToDialogPadding);

            bgBounds.BothSizing = ElementSizing.FitToChildren;
            bgBounds.WithChildren(stoveBounds);

            // 3. Finally Dialog
            ElementBounds dialogBounds = ElementStdBounds.AutosizedMainDialog
                                         .WithFixedAlignmentOffset(IsRight(screenPos) ? -GuiStyle.DialogToScreenPadding : GuiStyle.DialogToScreenPadding, 0)
                                         .WithAlignment(IsRight(screenPos) ? EnumDialogArea.RightMiddle : EnumDialogArea.LeftMiddle)
            ;


            if (!capi.Settings.Bool["immersiveMouseMode"])
            {
                dialogBounds.fixedOffsetY += (stoveBounds.fixedHeight + 65 + (haveCookingContainer ? 25 : 0)) * YOffsetMul(screenPos);
            }


            int[] cookingSlotIds = new int[qCookingSlots];
            for (int i = 0; i < qCookingSlots; i++)
            {
                cookingSlotIds[i] = 3 + i;
            }

            SingleComposer = capi.Gui
                             .CreateCompo("blockentitystove" + BlockEntityPosition, dialogBounds)
                             .AddShadedDialogBG(bgBounds)
                             .AddDialogTitleBar(DialogTitle, OnTitleBarClose)
                             .BeginChildElements(bgBounds)
                             .AddDynamicCustomDraw(stoveBounds, OnBgDraw, "symbolDrawer")
                             .AddDynamicText("", CairoFont.WhiteDetailText(), ElementBounds.Fixed(0, 30, 210, 45), "outputText")
                             .AddIf(haveCookingContainer)
                             .AddItemSlotGrid(Inventory, SendInvPacket, 4, cookingSlotIds, cookingSlotsSlotBounds, "ingredientSlots")
                             .EndIf()
                             .AddItemSlotGrid(Inventory, SendInvPacket, 1, new int[] { 0 }, fuelSlotBounds, "fuelslot")
                             .AddDynamicText("", CairoFont.WhiteDetailText(), fuelSlotBounds.RightCopy(17, 16).WithFixedSize(60, 30), "fueltemp")
                             .AddItemSlotGrid(Inventory, SendInvPacket, 1, new int[] { 1 }, inputSlotBounds, "oreslot")
                             .AddDynamicText("", CairoFont.WhiteDetailText(), inputSlotBounds.RightCopy(23, 16).WithFixedSize(60, 30), "oretemp")

                             .AddItemSlotGrid(Inventory, SendInvPacket, 1, new int[] { 2 }, outputSlotBounds, "outputslot")
                             .EndChildElements()
                             .Compose();

            lastRedrawMs = capi.ElapsedMilliseconds;

            if (hoveredSlot != null)
            {
                SingleComposer.OnMouseMove(new MouseEvent(capi.Input.MouseX, capi.Input.MouseY));
            }

            outputTextElem = SingleComposer.GetDynamicText("outputText");
            outputTextElem.SetNewText(currentOutputText, true);
            outputTextElem.Bounds.fixedOffsetY = 0;

            if (outputTextElem.QuantityTextLines > 2)
            {
                outputTextElem.Bounds.fixedOffsetY = -outputTextElem.Font.GetFontExtents().Height / RuntimeEnv.GUIScale * 0.65;
            }
            outputTextElem.Bounds.CalcWorldBounds();
        }
Exemple #15
0
        public static RichTextComponentBase[] Richtextify(ICoreClientAPI capi, string vtmlCode, CairoFont baseFont, Action <LinkTextComponent> didClickLink = null)
        {
            List <RichTextComponentBase> elems = new List <RichTextComponentBase>();

            Stack <CairoFont> fontStack = new Stack <CairoFont>();

            fontStack.Push(baseFont);

            VtmlToken[] tokens = VtmlParser.Tokenize(capi.Logger, vtmlCode);
            Richtextify(capi, tokens, ref elems, fontStack, didClickLink);

            return(elems.ToArray());
        }
        private void SetupDialog()
        {
            var availableTeleports = TPNetManager.GetAvailableTeleports(capi.World.Player);

            ElementBounds[] buttons = new ElementBounds[availableTeleports?.Count() > 0 ? availableTeleports.Count() : 1];

            buttons[0] = ElementBounds.Fixed(0, 0, 300, 40);
            for (int i = 1; i < buttons.Length; i++)
            {
                buttons[i] = buttons[i - 1].BelowCopy(0, 1);
            }


            ElementBounds listBounds = ElementBounds.Fixed(0, 0, 302, 400).WithFixedPadding(1);

            listBounds.BothSizing = ElementSizing.Fixed;

            ElementBounds clipBounds  = listBounds.ForkBoundingParent();
            ElementBounds insetBounds = listBounds.FlatCopy().FixedGrow(6).WithFixedOffset(-3, -3);

            ElementBounds scrollbarBounds = ElementStdBounds.VerticalScrollbar(insetBounds);


            ElementBounds bgBounds = ElementBounds.Fill.WithFixedPadding(GuiStyle.ElementToDialogPadding).WithFixedOffset(0, GuiStyle.TitleBarHeight);

            bgBounds.BothSizing = ElementSizing.FitToChildren;
            bgBounds.WithChildren(insetBounds, scrollbarBounds);


            ElementBounds dialogBounds = ElementStdBounds.AutosizedMainDialog;


            SingleComposer = capi.Gui
                             .CreateCompo("teleport-dialog", dialogBounds)
                             .AddDialogTitleBar(DialogTitle, CloseIconPressed)
                             .AddDialogBG(bgBounds, false)
                             .BeginChildElements(bgBounds)
            ;

            if (availableTeleports == null || availableTeleports.Count() == 0)
            {
                SingleComposer
                .AddStaticText(
                    Lang.Get("No available teleports"),
                    CairoFont.WhiteSmallText(),
                    buttons[0])
                .EndChildElements()
                .Compose()
                ;
                return;
            }

            SingleComposer
            .BeginClip(clipBounds)
            .AddInset(insetBounds, 3)
            .AddContainer(listBounds, "stacklist")
            .EndClip()
            .AddHoverText("", CairoFont.WhiteDetailText(), 300, listBounds.FlatCopy(), "hovertext")
            .AddVerticalScrollbar(OnNewScrollbarValue, scrollbarBounds, "scrollbar")
            .EndChildElements()
            ;

            var hoverTextElem = SingleComposer.GetHoverText("hovertext");

            hoverTextElem.SetAutoWidth(true);

            var stacklist = SingleComposer.GetContainer("stacklist");

            for (int i = 0; i < buttons.Length; i++)
            {
                var tp = availableTeleports.ElementAt(i);
                if (tp.Value.Name == null)
                {
                    tp.Value.Name = "null";
                }

                bool playerLowStability = capi.World.Player?.Entity?.GetBehavior <EntityBehaviorTemporalStabilityAffected>()?.OwnStability < 0.2;
                bool nowStormActive     = capi.ModLoader.GetModSystem <SystemTemporalStability>().StormData.nowStormActive;

                var font = CairoFont.WhiteSmallText();

                stacklist.Add(new GuiElementTextButtonExt(capi,
                                                          (nowStormActive || playerLowStability) ? tp.Value.Name.Shuffle() : tp.Value.Name,
                                                          tp.Key,
                                                          tp.Value.Available ? font : font.WithColor(ColorUtil.Hex2Doubles("#c91a1a")),
                                                          CairoFont.WhiteSmallText(),
                                                          () => OnClickItem(tp.Key),
                                                          buttons[i],
                                                          EnumButtonStyle.Normal
                                                          ));

                if (tp.Key == blockEntityPos)
                {
                    (stacklist.Elements.Last() as GuiElementTextButtonExt).Enabled = false;
                }
            }

            SingleComposer.GetScrollbar("scrollbar").SetHeights(
                (float)Math.Min(listBounds.fixedHeight, (buttons.Last().fixedHeight + buttons.Last().fixedY)),
                (float)(buttons.Last().fixedHeight + buttons.Last().fixedY)
                );
            //SingleComposer.GetScrollbar("scrollbar").ScrollToBottom();
            //SingleComposer.GetScrollbar("scrollbar").CurrentYPosition = 0;
            SingleComposer.Compose();
        }
Exemple #17
0
        static void Richtextify(ICoreClientAPI capi, VtmlToken token, ref List <RichTextComponentBase> elems, Stack <CairoFont> fontStack, Action <LinkTextComponent> didClickLink)
        {
            if (token is VtmlTagToken)
            {
                VtmlTagToken tagToken = token as VtmlTagToken;

                switch (tagToken.Name)
                {
                case "br":
                    elems.Add(new RichTextComponent(capi, "\r\n", fontStack.Peek()));
                    break;

                case "i":
                    CairoFont font = fontStack.Peek().Clone();
                    font.Slant = FontSlant.Italic;
                    fontStack.Push(font);
                    foreach (var val in tagToken.ChildElements)
                    {
                        Richtextify(capi, val, ref elems, fontStack, didClickLink);
                    }
                    fontStack.Pop();
                    break;

                case "a":
                    LinkTextComponent cmp = new LinkTextComponent(capi, tagToken.ContentText, fontStack.Peek(), didClickLink);
                    tagToken.Attributes.TryGetValue("href", out cmp.Href);

                    elems.Add(cmp);
                    break;

                case "icon":
                    string iconName;
                    tagToken.Attributes.TryGetValue("name", out iconName);
                    IconComponent iconcmp = new IconComponent(capi, iconName, fontStack.Peek());
                    elems.Add(iconcmp);
                    break;

                case "itemstack":
                    string    code;
                    string    type;
                    float     size      = (float)fontStack.Peek().GetFontExtents().Height;
                    EnumFloat floatType = EnumFloat.Inline;
                    string    floattypestr;
                    if (tagToken.Attributes.TryGetValue("floattype", out floattypestr))
                    {
                        if (!Enum.TryParse(floattypestr, out floatType))
                        {
                            floatType = EnumFloat.Inline;
                        }
                    }

                    tagToken.Attributes.TryGetValue("code", out code);
                    if (!tagToken.Attributes.TryGetValue("type", out type))
                    {
                        type = "block";
                    }

                    ItemStack stack;
                    if (type == "item")
                    {
                        stack = new ItemStack(capi.World.GetItem(new AssetLocation(code)));
                    }
                    else
                    {
                        stack = new ItemStack(capi.World.GetBlock(new AssetLocation(code)));
                    }

                    float sizemul = 1f;
                    if (tagToken.Attributes.TryGetValue("rsize", out var sizemulstr))
                    {
                        sizemul = sizemulstr.ToFloat();
                    }

                    SlideshowItemstackTextComponent stckcmp = new SlideshowItemstackTextComponent(capi, new ItemStack[] { stack }, size / RuntimeEnv.GUIScale, floatType);
                    stckcmp.renderSize   *= sizemul;
                    stckcmp.VerticalAlign = EnumVerticalAlign.Middle;

                    if (tagToken.Attributes.TryGetValue("offx", out var offxstr))
                    {
                        stckcmp.offX = GuiElement.scaled(offxstr.ToFloat(0));
                    }
                    if (tagToken.Attributes.TryGetValue("offy", out var offystr))
                    {
                        stckcmp.offY = GuiElement.scaled(offystr.ToFloat(0));
                    }

                    elems.Add(stckcmp);
                    break;

                case "font":
                    fontStack.Push(getFont(tagToken, fontStack));
                    foreach (var val in tagToken.ChildElements)
                    {
                        Richtextify(capi, val, ref elems, fontStack, didClickLink);
                    }
                    fontStack.Pop();
                    break;

                case "clear":
                    elems.Add(new ClearFloatTextComponent(capi));
                    break;

                case "strong":
                    fontStack.Push(fontStack.Peek().Clone().WithWeight(Cairo.FontWeight.Bold));
                    foreach (var val in tagToken.ChildElements)
                    {
                        Richtextify(capi, val, ref elems, fontStack, didClickLink);
                    }
                    fontStack.Pop();
                    break;
                }


                if (tagToken.Name != null && TagConverters.ContainsKey(tagToken.Name))
                {
                    RichTextComponentBase elem = TagConverters[tagToken.Name](capi, tagToken, fontStack, didClickLink);
                    if (elem != null)
                    {
                        elems.Add(elem);
                    }
                }
            }
            else
            {
                VtmlTextToken textToken = token as VtmlTextToken;
                elems.Add(new RichTextComponent(capi, textToken.Text, fontStack.Peek()));
            }
        }
Exemple #18
0
        void ComposeDialog()
        {
            double elemToDlgPad = ElementGeometrics.ElementToDialogPadding;

            ElementBounds button = ElementBounds.Fixed(15, 40, 290, 30).WithFixedPadding(10, 2);

            ElementBounds dialogBounds =
                ElementBounds.Fixed(EnumDialogArea.LeftMiddle, 30, 0, 250, 500)
                .ForkBoundingParent(elemToDlgPad, elemToDlgPad, elemToDlgPad, elemToDlgPad)
            ;

            ClearComposers();

            DialogComposers["loreList"] =
                capi.Gui
                .CreateCompo("loreList", dialogBounds, false)
                .AddDialogBG(ElementBounds.Fill)
                .AddDialogTitleBar("Journal Inventory", CloseIconPressed)
            ;

            for (int i = 0; i < journalitems.Count; i++)
            {
                int page = i;
                DialogComposers["loreList"].AddButton(journalitems[i].Title, () => { return(onClickItem(page)); }, button, CairoFont.WhiteSmallText(), EnumButtonStyle.None, EnumTextOrientation.Left, "button-" + i);

                DialogComposers["loreList"].GetButton("button-" + i).PlaySound = false;

                button = button.BelowCopy();
            }


            DialogComposers["loreList"]
            .Compose()
            ;
        }
Exemple #19
0
        public EyesOverlayRenderer(ICoreClientAPI capi, IShaderProgram eyeShaderProg)
        {
            this.capi          = capi;
            this.eyeShaderProg = eyeShaderProg;

            MeshData quadMesh = QuadMeshUtil.GetCustomQuadModelData(-1, -1, -20000 + 151 + 1, 2, 2);

            quadMesh.Rgba = null;

            quadRef = capi.Render.UploadMesh(quadMesh);

            string hotkey = capi.Input.HotKeys["sneak"].CurrentMapping.ToString();

            exitHelpTexture = capi.Gui.TextTexture.GenTextTexture(Lang.Get("bed-exithint", hotkey), CairoFont.WhiteSmallishText());
        }
Exemple #20
0
        private bool onClickItem(int i)
        {
            currentLoreItemIndex = i;
            page = 0;

            CairoFont      font     = CairoFont.WhiteDetailText().WithFontSize(17);
            TextSizeProber prober   = new TextSizeProber();
            StringBuilder  fulltext = new StringBuilder();

            for (int p = 0; p < journalitems[currentLoreItemIndex].Pieces.Length; p++)
            {
                if (p > 0)
                {
                    fulltext.AppendLine();
                }
                fulltext.Append(journalitems[currentLoreItemIndex].Pieces[p]);
            }

            pages = Paginate(fulltext, font, GuiElement.scaled(629), GuiElement.scaled(450), 1.15);


            double elemToDlgPad = ElementGeometrics.ElementToDialogPadding;

            ElementBounds textBounds   = ElementBounds.Fixed(0, 0, 630, 450);
            ElementBounds dialogBounds = textBounds.ForkBoundingParent(elemToDlgPad, elemToDlgPad + 20, elemToDlgPad, elemToDlgPad + 30).WithAlignment(EnumDialogArea.LeftMiddle);

            dialogBounds.fixedX = 350;


            DialogComposers["loreItem"] =
                capi.Gui
                .CreateCompo("loreItem", dialogBounds, false)
                .AddDialogBG(ElementBounds.Fill, true)
                .AddDialogTitleBar(journalitems[i].Title, CloseIconPressedLoreItem)
                .AddDynamicText(pages[0], font, EnumTextOrientation.Left, textBounds, 1.15f, "page")
                .AddDynamicText("1 / " + pages.Length, CairoFont.WhiteSmallishText(), EnumTextOrientation.Center, ElementBounds.Fixed(250, 500, 100, 30), 1, "currentpage")
                .AddButton("Previous Page", OnPrevPage, ElementBounds.Fixed(17, 500, 100, 23).WithFixedPadding(10, 4), CairoFont.WhiteSmallishText())
                .AddButton("Next Page", OnNextPage, ElementBounds.Fixed(520, 500, 100, 23).WithFixedPadding(10, 4), CairoFont.WhiteSmallishText())
                .Compose()
            ;

            return(true);
        }
Exemple #21
0
        private GuiComposer ComposeDialog(EnumDialogType dlgType)
        {
            GuiComposer compo;

            ElementBounds mapBounds = ElementBounds.Fixed(0, 28, mapWidth, mapHeight);
            ElementBounds layerList = mapBounds.RightCopy().WithFixedSize(1, 350);

            ElementBounds bgBounds = ElementBounds.Fill.WithFixedPadding(3);

            bgBounds.BothSizing = ElementSizing.FitToChildren;
            bgBounds.WithChildren(mapBounds, layerList);

            ElementBounds dialogBounds =
                ElementStdBounds.AutosizedMainDialog
                .WithAlignment(EnumDialogArea.CenterMiddle)
                .WithFixedAlignmentOffset(-GuiStyle.DialogToScreenPadding, 0);

            if (dlgType == EnumDialogType.HUD)
            {
                mapBounds = ElementBounds.Fixed(0, 0, 250, 250);

                bgBounds            = ElementBounds.Fill.WithFixedPadding(2);
                bgBounds.BothSizing = ElementSizing.FitToChildren;
                bgBounds.WithChildren(mapBounds);

                dialogBounds =
                    ElementStdBounds.AutosizedMainDialog
                    .WithAlignment(EnumDialogArea.RightTop)
                    .WithFixedAlignmentOffset(-GuiStyle.DialogToScreenPadding, GuiStyle.DialogToScreenPadding);

                compo = hudDialog;
            }
            else
            {
                compo = fullDialog;
            }

            Cuboidd beforeBounds = null;

            if (compo != null)
            {
                beforeBounds = (compo.GetElement("mapElem") as GuiElementMap)?.CurrentBlockViewBounds;
                compo.Dispose();
            }

            compo = capi.Gui
                    .CreateCompo("worldmap" + dlgType, dialogBounds)
                    .AddShadedDialogBG(bgBounds, false)
                    .AddIf(dlgType == EnumDialogType.Dialog)
                    .AddDialogTitleBar("World Map", OnTitleBarClose)
                    .AddInset(mapBounds, 2)
                    .EndIf()
                    .BeginChildElements(bgBounds)
                    .AddHoverText("", CairoFont.WhiteDetailText(), 350, mapBounds.FlatCopy(), "hoverText")
                    .AddInteractiveElement(new GuiElementMap(capi.ModLoader.GetModSystem <WorldMapManager>().MapLayers, capi, mapBounds, dlgType == EnumDialogType.HUD), "mapElem")
                    .EndChildElements()
                    .Compose()
            ;

            compo.OnRecomposed += SingleComposer_OnRecomposed;

            GuiElementMap mapElem = compo.GetElement("mapElem") as GuiElementMap;

            if (beforeBounds != null)
            {
                mapElem.chunkViewBoundsBefore = beforeBounds.ToCuboidi().Div(capi.World.BlockAccessor.ChunkSize);
            }
            mapElem.viewChanged = viewChanged;
            mapElem.ZoomAdd(1, 0.5f, 0.5f);



            var hoverTextElem = compo.GetHoverText("hoverText");

            hoverTextElem.SetAutoWidth(true);

            if (listenerId == 0)
            {
                listenerId = capi.Event.RegisterGameTickListener(
                    (dt) =>
                {
                    if (!IsOpened())
                    {
                        return;
                    }

                    GuiElementMap singlec = SingleComposer.GetElement("mapElem") as GuiElementMap;
                    singlec?.EnsureMapFullyLoaded();

                    if (requireRecompose)
                    {
                        var dlgtype = dialogType;
                        capi.ModLoader.GetModSystem <WorldMapManager>().ToggleMap(dlgtype);
                        capi.ModLoader.GetModSystem <WorldMapManager>().ToggleMap(dlgtype);
                        requireRecompose = false;
                    }
                }
                    , 100);
            }

            capi.World.FrameProfiler.Mark("composeworldmap");
            return(compo);
        }
        protected virtual void ComposeGuis()
        {
            double pad      = GuiElementItemSlotGrid.unscaledSlotPadding;
            double slotsize = GuiElementPassiveItemSlot.unscaledSlotSize;

            ElementBounds leftPrevButtonBounds = ElementBounds.Fixed(75, 120 + pad + 52, 19, 19).WithFixedPadding(2);
            ElementBounds leftNextButtonBounds = ElementBounds.Fixed(75, 120 + pad + 52, 19, 19).WithFixedPadding(2).FixedRightOf(leftPrevButtonBounds, 6);
            ElementBounds textBounds           = ElementBounds.Fixed(0, 120 + pad + 52, 19, 19).WithFixedPadding(2);

            ElementBounds humanButtonBounds = ElementBounds.Fixed(0, pad + 52, 19, 19).WithFixedPadding(2);
            ElementBounds dwarfButtonBounds = ElementBounds.Fixed(0, pad + 52, 19, 19).WithFixedPadding(2).FixedRightOf(humanButtonBounds, 40);

            ElementBounds maleButtonBounds   = ElementBounds.Fixed(0, 57 + pad + 52, 19, 19).WithFixedPadding(2);
            ElementBounds femaleButtonBounds = ElementBounds.Fixed(0, 57 + pad + 52, 19, 19).WithFixedPadding(2).FixedRightOf(maleButtonBounds, 30);

            ElementBounds titleTextBounds = ElementBounds.Fixed(0, pad + 20, 19, 19).WithFixedPadding(2);

            characterInv = capi.World.Player.InventoryManager.GetOwnInventory(GlobalConstants.characterInvClassName);
            ElementBounds leftSlotBounds = ElementStdBounds.SlotGrid(EnumDialogArea.None, pad, 20 + pad, 1, 6).FixedGrow(2 * pad, 2 * pad);

            insetSlotBounds = ElementBounds.Fixed(pad + 65 + 65, pad + 20 + 2, 300 - 60, leftSlotBounds.fixedHeight - 2 * pad - 4);

            ElementBounds bgBounds = ElementBounds.Fill.WithFixedPadding(GuiStyle.ElementToDialogPadding);

            bgBounds.BothSizing = ElementSizing.FitToChildren;


            ElementBounds dialogBounds = ElementStdBounds
                                         .AutosizedMainDialog.WithAlignment(EnumDialogArea.None)
                                         .WithFixedAlignmentOffset(GuiStyle.DialogToScreenPadding, 0);


            ClearComposers();
            SingleComposer = capi.Gui
                             .CreateCompo("playercharacter", dialogBounds)
                             .AddDialogBG(bgBounds, true)
                             //.AddDialogTitleBar(capi.World.Player.PlayerName, OnTitleBarClose)
                             .BeginChildElements(bgBounds)

                             // Race
                             .AddStaticTextAutoBoxSize("Race:", CairoFont.WhiteSmallishText(), EnumTextOrientation.Right, titleTextBounds.FlatCopy())
                             .AddSmallButton("Human", () => ButtonClickRace("human"), humanButtonBounds.FlatCopy())
                             .AddSmallButton("Dwarf", () => ButtonClickRace("dwarf"), dwarfButtonBounds.FlatCopy())

                             // Sex
                             .AddStaticTextAutoBoxSize("Sex:", CairoFont.WhiteSmallishText(), EnumTextOrientation.Right, titleTextBounds = titleTextBounds.BelowCopy(0, 35))
                             .AddSmallButton("Male", () => ButtonClickSex("male"), maleButtonBounds.FlatCopy())
                             .AddSmallButton("Female", () => ButtonClickSex("female"), femaleButtonBounds.FlatCopy())

                             .AddStaticTextAutoBoxSize("Appearance:", CairoFont.WhiteSmallishText(), EnumTextOrientation.Right, titleTextBounds = titleTextBounds.BelowCopy(0, 35))

                             // Skin Color
                             .AddIconButton("left", (on) => OnPrevious("skincolor"), leftPrevButtonBounds.FlatCopy())
                             .AddIconButton("right", (on) => OnNext("skincolor"), leftNextButtonBounds.FlatCopy())
                             .AddStaticTextAutoBoxSize("Skin color:", CairoFont.WhiteDetailText(), EnumTextOrientation.Right, textBounds.FlatCopy())

                             // Eye Color
                             .AddIconButton("left", (on) => OnPrevious("eyecolor"), leftPrevButtonBounds = leftPrevButtonBounds.BelowCopy(0, 5))
                             .AddIconButton("right", (on) => OnNext("eyecolor"), leftNextButtonBounds    = leftNextButtonBounds.BelowCopy(0, 5))
                             .AddStaticTextAutoBoxSize("Eye color:", CairoFont.WhiteDetailText(), EnumTextOrientation.Right, textBounds = textBounds.BelowCopy(0, 5))

                             // Hair Color
                             .AddIconButton("left", (on) => OnPrevious("haircolor"), leftPrevButtonBounds = leftPrevButtonBounds.BelowCopy(0, 5))
                             .AddIconButton("right", (on) => OnNext("haircolor"), leftNextButtonBounds    = leftNextButtonBounds.BelowCopy(0, 5))
                             .AddStaticTextAutoBoxSize("Hair color:", CairoFont.WhiteDetailText(), EnumTextOrientation.Right, textBounds = textBounds.BelowCopy(0, 7))

                             // Hair Type
                             .AddIconButton("left", (on) => OnPrevious("hairtype"), leftPrevButtonBounds = leftPrevButtonBounds.BelowCopy(0, 5))
                             .AddIconButton("right", (on) => OnNext("hairtype"), leftNextButtonBounds    = leftNextButtonBounds.BelowCopy(0, 5))
                             .AddStaticTextAutoBoxSize("Hair type:", CairoFont.WhiteDetailText(), EnumTextOrientation.Right, textBounds = textBounds.BelowCopy(0, 7))

                             // Facial Hair
                             .AddIconButton("left", (on) => OnPrevious("facialhair"), leftPrevButtonBounds = leftPrevButtonBounds.BelowCopy(0, 5))
                             .AddIconButton("right", (on) => OnNext("facialhair"), leftNextButtonBounds    = leftNextButtonBounds.BelowCopy(0, 5))
                             .AddStaticTextAutoBoxSize("Facial hair:", CairoFont.WhiteDetailText(), EnumTextOrientation.Right, textBounds = textBounds.BelowCopy(0, 7))

                             .AddSmallButton("Confirm", () => TryClose(), textBounds = textBounds.BelowCopy(0, 7))

                             //.AddItemSlotGrid(characterInv, SendInvPacket, 1, new int[] { 0, 1, 2, 11, 3, 4 }, leftSlotBounds, "leftSlots")
                             .AddInset(insetSlotBounds, 2)
                             //.AddItemSlotGrid(characterInv, SendInvPacket, 1, new int[] { 6, 7, 8, 10, 5, 9 }, rightSlotBounds, "rightSlots")
                             .EndChildElements()
                             .Compose()
            ;
        }
        public override void OnOwnPlayerDataReceived()
        {
            base.OnOwnPlayerDataReceived();
            config = capi.ModLoader.GetModSystem <ConfigLoader>().Config;

            ElementBounds dialogBounds = ElementBounds.Fixed(EnumDialogArea.LeftMiddle, 30, 0, 465, 500);
            ElementBounds bgBounds     = ElementBounds.Fixed(EnumDialogArea.LeftMiddle, 0, -200, 465, 100);

            string[]      colors;
            List <string> c = new List <string>()
            {
                "Random"
            };

            string[] names = Enum.GetNames(typeof(KnownColor));

            for (int i = 28; i < 166; i++)
            {
                c.Add(names[i]);
            }
            colors = c.ToArray();
            config.SetColorIndex = config.SetColorIndex < 0 ? 0 : config.SetColorIndex;

            color = colors[config.SetColorIndex];
            UpdateDropDown(colors, color);

            SingleComposer = capi.Gui.CreateCompo("waypointfrontend", dialogBounds)
                             .AddDialogTitleBar("Waypoint Utils", VClose, CairoFont.WhiteSmallText())
                             .AddDialogBG(bgBounds)
                             .AddTextInput(ElementBounds.Fixed(EnumDialogArea.LeftMiddle, 86.5, -200, 370, 20), OnTextChanged, null, "textinput")
                             .AddDropDown(colors, colors, config.SetColorIndex, (newval, on) =>
            {
                UpdateDropDown(colors, newval);
                capi.TriggerChatMessage(".wpcfg save");
                capi.Event.RegisterCallback(dt => capi.ModLoader.GetModSystem <WaypointUtilSystem>().Update(), 100);
            },
                                          ElementBounds.Fixed(EnumDialogArea.LeftMiddle, 250, -170, 125, 10), "dropdown")
                             .AddTextToggleButtons(new string[] { "Create WP", "Purge Death Waypoints", "Toggle Floaty Waypoints", "Toggle Block Waypoints", "Toggle This Color" }, CairoFont.ButtonText().WithFontSize(10), i =>
            {
                capi.Event.RegisterCallback(j =>
                {
                    SingleComposer.Dispose();
                    OnOwnPlayerDataReceived();
                    SingleComposer.Compose();
                    capi.TriggerChatMessage(".wpcfg save");
                }, 100);
                switch (i)
                {
                case 0:
                    CreateWaypoint();
                    break;

                case 1:
                    capi.TriggerChatMessage(".wpcfg pdw");
                    break;

                case 2:
                    capi.TriggerChatMessage(".wpcfg open");
                    break;

                case 3:
                    capi.TriggerChatMessage(".wpcfg perblockwaypoints");
                    break;

                case 4:
                    if (config.DisabledColors.Contains(intColor))
                    {
                        config.DisabledColors.Remove(intColor);
                    }
                    else
                    {
                        config.DisabledColors.Add(intColor);
                    }
                    break;

                default:
                    break;
                }
                capi.Event.RegisterCallback(dt => capi.ModLoader.GetModSystem <WaypointUtilSystem>().Update(), 100);
            }, new ElementBounds[] {
                ElementBounds.Fixed(EnumDialogArea.LeftMiddle, 5, -200, 80, 25),
                ElementBounds.Fixed(EnumDialogArea.LeftMiddle, 5, -170, 80, 35),
                ElementBounds.Fixed(EnumDialogArea.LeftMiddle, 85, -170, 80, 35),
                ElementBounds.Fixed(EnumDialogArea.LeftMiddle, 165, -170, 80, 35),
                ElementBounds.Fixed(EnumDialogArea.LeftMiddle, 380, -170, 80, 35),
            });
        }
Exemple #24
0
        private void ComposeDialog()
        {
            ElementBounds leftColumn  = ElementBounds.Fixed(0, 28, 120, 25);
            ElementBounds rightColumn = leftColumn.RightCopy();

            ElementBounds buttonRow = ElementBounds.Fixed(0, 28, 360, 25);

            ElementBounds bgBounds = ElementBounds.Fill.WithFixedPadding(GuiStyle.ElementToDialogPadding);

            bgBounds.BothSizing = ElementSizing.FitToChildren;
            bgBounds.WithChildren(leftColumn, rightColumn);

            ElementBounds dialogBounds =
                ElementStdBounds.AutosizedMainDialog
                .WithAlignment(EnumDialogArea.CenterMiddle)
                .WithFixedAlignmentOffset(-GuiStyle.DialogToScreenPadding, 0);


            if (SingleComposer != null)
            {
                SingleComposer.Dispose();
            }

            string[] names = new string[] { "circle", "bee", "cave", "home", "ladder", "pick", "rocks", "ruins", "spiral", "star1", "star2", "trader", "vessel" };
            int      index = names.IndexOf(waypoint.Icon);

            if (index < 0)
            {
                index = 0;
            }

            SingleComposer = capi.Gui
                             .CreateCompo("worldmap-modwp", dialogBounds)
                             .AddShadedDialogBG(bgBounds, false)
                             .AddDialogTitleBar(Lang.Get("Modify waypoint"), () => TryClose())
                             .BeginChildElements(bgBounds)
                             .AddStaticText(Lang.Get("Name"), CairoFont.WhiteSmallText(), leftColumn = leftColumn.FlatCopy())
                             .AddTextInput(rightColumn = rightColumn.FlatCopy().WithFixedWidth(200), onNameChanged, CairoFont.TextInput(), "nameInput")

                             .AddRichtext(Lang.Get("waypoint-color"), CairoFont.WhiteSmallText(), leftColumn = leftColumn.BelowCopy(0, 5))
                             .AddTextInput(rightColumn = rightColumn.BelowCopy(0, 5).WithFixedWidth(150), onColorChanged, CairoFont.TextInput(), "colorInput")
                             .AddDynamicCustomDraw(rightColumn.FlatCopy().WithFixedWidth(30).WithFixedOffset(160, 0), onDrawColorRect, "colorRect")

                             .AddStaticText(Lang.Get("Icon"), CairoFont.WhiteSmallText(), leftColumn = leftColumn.BelowCopy(0, 9))
                             .AddDropDown(
                names,
                new string[] { "<icon name=\"wpCircle\">", "<icon name=\"wpBee\">", "<icon name=\"wpCave\">", "<icon name=\"wpHome\">", "<icon name=\"wpLadder\">", "<icon name=\"wpPick\">", "<icon name=\"wpRocks\">", "<icon name=\"wpRuins\">", "<icon name=\"wpSpiral\">", "<icon name=\"wpStar1\">", "<icon name=\"wpStar2\">", "<icon name=\"wpTrader\">", "<icon name=\"wpVessel\">" },
                index,
                onIconSelectionChanged,
                rightColumn = rightColumn.BelowCopy(0, 5).WithFixedWidth(60),
                CairoFont.WhiteSmallishText(),
                "iconInput"
                )

                             .AddStaticText(Lang.Get("Pinned"), CairoFont.WhiteSmallText(), leftColumn = leftColumn.BelowCopy(0, 9))
                             .AddSwitch(onPinnedToggled, rightColumn = rightColumn.BelowCopy(0, 5).WithFixedWidth(200), "pinnedSwitch")

                             .AddSmallButton(Lang.Get("Cancel"), onCancel, buttonRow.FlatCopy().FixedUnder(leftColumn, 0).WithFixedWidth(100), EnumButtonStyle.Normal)
                             .AddSmallButton(Lang.Get("Delete"), onDelete, buttonRow.FlatCopy().FixedUnder(leftColumn, 0).WithFixedWidth(100).WithAlignment(EnumDialogArea.CenterFixed), EnumButtonStyle.Normal)
                             .AddSmallButton(Lang.Get("Save"), onSave, buttonRow.FlatCopy().FixedUnder(leftColumn, 0).WithFixedWidth(100).WithAlignment(EnumDialogArea.RightFixed), EnumButtonStyle.Normal, key: "saveButton")
                             .EndChildElements()
                             .Compose()
            ;

            var col = System.Drawing.Color.FromArgb(255, ColorUtil.ColorR(waypoint.Color), ColorUtil.ColorG(waypoint.Color), ColorUtil.ColorB(waypoint.Color));


            if (colorLookup[waypoint.Color].Count() > 0)
            {
                SingleComposer.GetTextInput("colorInput").SetValue(colorLookup[waypoint.Color].First().ToKnownColor().ToString().ToLowerInvariant());
            }
            else
            {
                SingleComposer.GetTextInput("colorInput").SetValue(ColorUtil.Int2Hex(waypoint.Color));
            }

            SingleComposer.GetTextInput("nameInput").SetValue(waypoint.Title);
            SingleComposer.GetSwitch("pinnedSwitch").SetValue(waypoint.Pinned);
        }
Exemple #25
0
        internal void ComposeWindow()
        {
            ClearComposers();

            var         rows  = new[] { 0f, 1f, 1.5f, 2.5f, 3.0f };
            const float width = 500f;

            var guiComposer = Api.AsClientMain().GetField <GuiComposerManager>("GuiComposers")
                              .Create("wpex-settings", ElementStdBounds.AutosizedMainDialog)
                              .AddShadedDialogBG(ElementStdBounds.DialogBackground()
                                                 .WithFixedPadding(GuiStyle.ElementToDialogPadding, GuiStyle.ElementToDialogPadding), false)
                              .BeginChildElements();

            // Title.
            guiComposer.AddStaticText(LangEx.UI("SettingsWindow.Headers.Wpex"),
                                      CairoFont.WhiteSmallishText().WithFontSize(25f),
                                      EnumTextOrientation.Center,
                                      ElementStdBounds.MenuButton(rows[0])
                                      .WithFixedWidth(width));

            // Auto Translocator.
            guiComposer.AddStaticText(LangEx.UI("SettingsWindow.Labels.AutoTranslocator"), CairoFont.WhiteSmallishText(),
                                      ElementStdBounds.MenuButton(rows[1], EnumDialogArea.LeftTop).WithFixedWidth(330))
            .AddHoverText(LangEx.UI("SettingsWindow.Tooltips.AutoTranslocator"), CairoFont.WhiteSmallText(), 250,
                          ElementStdBounds.MenuButton(rows[1], EnumDialogArea.LeftTop).WithFixedWidth(250))
            .AddSwitch(AutoTranslocatorChanged,
                       ElementStdBounds.MenuButton(rows[1], EnumDialogArea.LeftTop).WithFixedOffset(350.0, 0), "AutoTranslocatorWaypoints");

            // Auto Trader
            guiComposer.AddStaticText(LangEx.UI("SettingsWindow.Labels.AutoTrader"), CairoFont.WhiteSmallishText(),
                                      ElementStdBounds.MenuButton(rows[2], EnumDialogArea.LeftTop).WithFixedWidth(330))
            .AddHoverText(LangEx.UI("SettingsWindow.Tooltips.AutoTrader"), CairoFont.WhiteSmallText(), 250,
                          ElementStdBounds.MenuButton(rows[2], EnumDialogArea.LeftTop).WithFixedWidth(250))
            .AddSwitch(AutoTraderChanged,
                       ElementStdBounds.MenuButton(rows[2], EnumDialogArea.LeftTop).WithFixedOffset(350.0, 0), "AutoTraderWaypoints");

            // Donate Button.
            guiComposer.AddButton(LangEx.UI("SettingsWindow.Labels.Donate"), OnDonateButton,
                                  ElementStdBounds.MenuButton(rows[3]).WithFixedWidth(width));

            // Back Button.
            guiComposer.AddButton(Lang.Get("pause-back2game"), OnBackToGame,
                                  ElementStdBounds.MenuButton(rows[4]).WithFixedWidth(width));

            guiComposer.GetSwitch("AutoTranslocatorWaypoints").On = Mod.Settings.AutoTranslocatorWaypoints;
            guiComposer.GetSwitch("AutoTraderWaypoints").On       = Mod.Settings.AutoTraderWaypoints;

            SingleComposer = guiComposer.EndChildElements().Compose();
        }
Exemple #26
0
 public GuiElementTextButtonExt(ICoreClientAPI capi, string text, BlockPos teleportPos, CairoFont font, CairoFont hoverFont, ActionConsumable onClick, ElementBounds bounds, EnumButtonStyle style = EnumButtonStyle.Normal) : base(capi, text, font, hoverFont, onClick, bounds, style)
 {
     this.TeleportPos = teleportPos;
 }
        private void onDurationChanged(string code, bool selected)
        {
            int cost = code.ToInt(1) / auctionSys.DurationWeeksMul;

            Composers["tradercreateauction"].GetRichtext("depositText").SetNewText(Lang.Get("Deposit: {0}x", cost) + " " + gearIcon, CairoFont.WhiteSmallText());
        }
Exemple #28
0
        static CairoFont getFont(VtmlTagToken tag, Stack <CairoFont> fontStack)
        {
            double size                = 0;
            double lineHeight          = 1;
            string fontName            = "";
            EnumTextOrientation orient = EnumTextOrientation.Left;

            double[]   color  = ColorUtil.WhiteArgbDouble;
            FontWeight weight = FontWeight.Normal;

            CairoFont prevFont = fontStack.Pop();

            if (!tag.Attributes.ContainsKey("size") || !double.TryParse(tag.Attributes["size"], NumberStyles.Any, GlobalConstants.DefaultCultureInfo, out size))
            {
                size = prevFont.UnscaledFontsize;
            }

            if (!tag.Attributes.ContainsKey("family"))
            {
                fontName = prevFont.Fontname;
            }
            else
            {
                fontName = tag.Attributes["family"];
            }

            if (!tag.Attributes.ContainsKey("color") || !parseHexColor(tag.Attributes["color"], out color))
            {
                color = prevFont.Color;
            }

            double opacity;

            if (tag.Attributes.ContainsKey("opacity") && double.TryParse(tag.Attributes["opacity"], NumberStyles.Any, GlobalConstants.DefaultCultureInfo, out opacity))
            {
                color     = (double[])color.Clone();
                color[3] *= opacity;
            }

            if (tag.Attributes.ContainsKey("weight"))
            {
                weight = tag.Attributes["weight"] == "bold" ? FontWeight.Bold : FontWeight.Normal;
            }
            else
            {
                weight = prevFont.FontWeight;
            }

            if (!tag.Attributes.ContainsKey("lineheight") || !double.TryParse(tag.Attributes["lineheight"], NumberStyles.Any, GlobalConstants.DefaultCultureInfo, out lineHeight))
            {
                lineHeight = prevFont.LineHeightMultiplier;
            }

            if (tag.Attributes.ContainsKey("align"))
            {
                switch (tag.Attributes["align"])
                {
                case "left":
                    orient = EnumTextOrientation.Left;
                    break;

                case "right":
                    orient = EnumTextOrientation.Right;
                    break;

                case "center":
                    orient = EnumTextOrientation.Center;
                    break;

                case "justify":
                    orient = EnumTextOrientation.Justify;
                    break;
                }
            }
            else
            {
                orient = prevFont.Orientation;
            }

            fontStack.Push(prevFont);

            return(new CairoFont(size, fontName, color).WithWeight(weight).WithLineHeightMultiplier(lineHeight).WithOrientation(orient));
        }
        public void Compose()
        {
            var tabs = new GuiTab[] { new GuiTab()
                                      {
                                          Name = Lang.Get("Local goods"), DataInt = 0
                                      }, new GuiTab()
                                      {
                                          Name = Lang.Get("Auction house"), DataInt = 1
                                      }, new GuiTab()
                                      {
                                          Name = Lang.Get("Your Auctions"), DataInt = 2
                                      } };
            var tabBounds = ElementBounds.Fixed(0, -24, 500, 25);
            var tabFont   = CairoFont.WhiteDetailText();

            if (!auctionHouseEnabled)
            {
                tabs = new GuiTab[] { new GuiTab()
                                      {
                                          Name = Lang.Get("Local goods"), DataInt = 0
                                      } };
            }


            ElementBounds bgBounds = ElementBounds.Fill.WithFixedPadding(GuiStyle.ElementToDialogPadding);

            bgBounds.BothSizing = ElementSizing.FitToChildren;
            ElementBounds dialogBounds = ElementStdBounds
                                         .AutosizedMainDialog.WithAlignment(EnumDialogArea.RightMiddle)
                                         .WithFixedAlignmentOffset(-GuiStyle.DialogToScreenPadding, 0);


            ElementBounds leftButton  = ElementBounds.Fixed(EnumDialogArea.LeftFixed, 0, 0, 0, 0).WithFixedPadding(8, 5);
            ElementBounds rightButton = ElementBounds.Fixed(EnumDialogArea.RightFixed, 0, 0, 0, 0).WithFixedPadding(8, 5);


            string traderName = owningEntity.GetBehavior <EntityBehaviorNameTag>().DisplayName;
            string dlgTitle   = Lang.Get("tradingwindow-" + owningEntity.Code.Path, traderName);

            if (curTab > 0)
            {
                dlgTitle = Lang.Get("tradertabtitle-" + curTab);
            }

            SingleComposer =
                capi.Gui
                .CreateCompo("traderdialog-" + owningEntity.EntityId, dialogBounds)
                .AddShadedDialogBG(bgBounds, true)
                .AddDialogTitleBar(dlgTitle, OnTitleBarClose)
                .AddHorizontalTabs(tabs, tabBounds, OnTabClicked, tabFont, tabFont.Clone().WithColor(GuiStyle.ActiveButtonTextColor), "tabs")
                .BeginChildElements(bgBounds)
            ;

            SingleComposer.GetHorizontalTabs("tabs").activeElement = curTab;

            if (curTab == 0)
            {
                double pad = GuiElementItemSlotGrid.unscaledSlotPadding;

                ElementBounds leftTopSlotBounds  = ElementStdBounds.SlotGrid(EnumDialogArea.None, pad, 70 + pad, cols, rows).FixedGrow(2 * pad, 2 * pad);
                ElementBounds rightTopSlotBounds = ElementStdBounds.SlotGrid(EnumDialogArea.None, pad + leftTopSlotBounds.fixedWidth + 20, 70 + pad, cols, rows).FixedGrow(2 * pad, 2 * pad);

                ElementBounds rightBotSlotBounds = ElementStdBounds
                                                   .SlotGrid(EnumDialogArea.None, pad + leftTopSlotBounds.fixedWidth + 20, 15 + pad, cols, 1)
                                                   .FixedGrow(2 * pad, 2 * pad)
                                                   .FixedUnder(rightTopSlotBounds, 5)
                ;

                ElementBounds leftBotSlotBounds = ElementStdBounds
                                                  .SlotGrid(EnumDialogArea.None, pad, 15 + pad, cols, 1)
                                                  .FixedGrow(2 * pad, 2 * pad)
                                                  .FixedUnder(leftTopSlotBounds, 5)
                ;

                ElementBounds costTextBounds  = ElementBounds.Fixed(pad, 85 + 2 * pad + leftTopSlotBounds.fixedHeight + leftBotSlotBounds.fixedHeight, 200, 25);
                ElementBounds offerTextBounds = ElementBounds.Fixed(leftTopSlotBounds.fixedWidth + pad + 20, 85 + 2 * pad + leftTopSlotBounds.fixedHeight + leftBotSlotBounds.fixedHeight, 200, 25);

                ElementBounds traderMoneyBounds = offerTextBounds.FlatCopy().WithFixedOffset(0, offerTextBounds.fixedHeight);
                ElementBounds playerMoneyBounds = costTextBounds.FlatCopy().WithFixedOffset(0, costTextBounds.fixedHeight);


                double daysLeft       = (owningEntity as EntityTrader).NextRefreshTotalDays();
                string daysLeftString = daysLeft < 1 ? Lang.Get("Delievery of new goods in less than 1 day") : Lang.Get("Delievery of new goods in {0} days", (int)daysLeft);

                CairoFont deliveryTextFont = CairoFont.WhiteDetailText();
                deliveryTextFont.Color[3] *= 0.7;

                SingleComposer
                .AddStaticText(daysLeftString, deliveryTextFont, ElementBounds.Fixed(pad, 20 + pad, 500, 25))

                .AddStaticText(Lang.Get("You can Buy"), CairoFont.WhiteDetailText(), ElementBounds.Fixed(pad, 50 + pad, 200, 25))
                .AddStaticText(Lang.Get("You can Sell"), CairoFont.WhiteDetailText(), ElementBounds.Fixed(leftTopSlotBounds.fixedWidth + pad + 20, 50 + pad, 200, 25))

                .AddItemSlotGrid(traderInventory, DoSendPacket, cols, (new int[rows * cols]).Fill(i => i), leftTopSlotBounds, "traderSellingSlots")
                .AddItemSlotGrid(traderInventory, DoSendPacket, cols, (new int[cols]).Fill(i => rows * cols + i), leftBotSlotBounds, "playerBuyingSlots")

                .AddItemSlotGrid(traderInventory, DoSendPacket, cols, (new int[rows * cols]).Fill(i => rows * cols + cols + i), rightTopSlotBounds, "traderBuyingSlots")
                .AddItemSlotGrid(traderInventory, DoSendPacket, cols, (new int[cols]).Fill(i => rows * cols + cols + rows * cols + i), rightBotSlotBounds, "playerSellingSlots")

                .AddStaticText(Lang.Get("trader-yourselection"), CairoFont.WhiteDetailText(), ElementBounds.Fixed(pad, 70 + 2 * pad + leftTopSlotBounds.fixedHeight, 150, 25))
                .AddStaticText(Lang.Get("trader-youroffer"), CairoFont.WhiteDetailText(), ElementBounds.Fixed(leftTopSlotBounds.fixedWidth + pad + 20, 70 + 2 * pad + leftTopSlotBounds.fixedHeight, 150, 25))

                // Cost
                .AddDynamicText("", CairoFont.WhiteDetailText(), costTextBounds, "costText")
                // Player money
                .AddDynamicText("", CairoFont.WhiteDetailText(), playerMoneyBounds, "playerMoneyText")
                // Offer
                .AddDynamicText("", CairoFont.WhiteDetailText(), offerTextBounds, "gainText")
                // Trader money
                .AddDynamicText("", CairoFont.WhiteDetailText(), traderMoneyBounds, "traderMoneyText")

                .AddSmallButton(Lang.Get("Goodbye!"), OnByeClicked, leftButton.FixedUnder(playerMoneyBounds, 20))
                .AddSmallButton(Lang.Get("Buy / Sell"), OnBuySellClicked, rightButton.FixedUnder(traderMoneyBounds, 20), EnumButtonStyle.Normal, EnumTextOrientation.Left, "buysellButton")

                .EndChildElements()
                .Compose()
                ;

                SingleComposer.GetButton("buysellButton").Enabled = false;
                CalcAndUpdateAssetsDisplay();
                return;
            }

            double        listHeight      = 377;
            ElementBounds stackListBounds = ElementBounds.Fixed(0, 25, 700, listHeight); //.FixedUnder(searchFieldBounds, 5);

            clipBounds = stackListBounds.ForkBoundingParent();
            ElementBounds insetBounds = stackListBounds.FlatCopy().FixedGrow(3).WithFixedOffset(0, 0);

            ElementBounds scrollbarBounds = insetBounds.CopyOffsetedSibling(3 + stackListBounds.fixedWidth + 7).WithFixedWidth(20);

            if (curTab == 1)
            {
                auctions = auctionSys.activeAuctions;

                SingleComposer
                .BeginClip(clipBounds)
                .AddInset(insetBounds, 3)
                .AddCellList(stackListBounds, createCell, auctionSys.activeAuctions, "stacklist")
                .EndClip()
                .AddVerticalScrollbar(OnNewScrollbarValue, scrollbarBounds, "scrollbar")

                .AddSmallButton(Lang.Get("Goodbye!"), OnByeClicked, leftButton.FixedUnder(clipBounds, 20))
                .AddSmallButton(Lang.Get("Buy"), OnBuyAuctionClicked, rightButton.FixedUnder(clipBounds, 20), EnumButtonStyle.Normal, EnumTextOrientation.Left, "buyauction")
                ;
            }

            if (curTab == 2)
            {
                auctions = auctionSys.ownAuctions;

                ElementBounds button    = ElementBounds.Fixed(EnumDialogArea.RightFixed, 0, 0, 0, 0).WithFixedPadding(8, 5);
                string        placeStr  = Lang.Get("Place Auction");
                string        cancelStr = Lang.Get("Cancel Auction");

                double placelen  = CairoFont.ButtonText().GetTextExtents(placeStr).Width / RuntimeEnv.GUIScale;
                double cancellen = CairoFont.ButtonText().GetTextExtents(cancelStr).Width / RuntimeEnv.GUIScale;

                SingleComposer
                .BeginClip(clipBounds)
                .AddInset(insetBounds, 3)
                .AddCellList(stackListBounds, createCell, auctionSys.ownAuctions, "stacklist")
                .EndClip()
                .AddVerticalScrollbar(OnNewScrollbarValue, scrollbarBounds, "scrollbar")

                .AddSmallButton(Lang.Get("Goodbye!"), OnByeClicked, leftButton.FixedUnder(clipBounds, 20))
                .AddSmallButton(Lang.Get("Place Auction"), OnCreateAuction, rightButton.FixedUnder(clipBounds, 20), EnumButtonStyle.Normal, EnumTextOrientation.Left, "placeAuction")
                .AddSmallButton(cancelStr, OnCancelAuction, button.FlatCopy().FixedUnder(clipBounds, 20).WithFixedAlignmentOffset(-placelen, 0), EnumButtonStyle.Normal, EnumTextOrientation.Center, "cancelAuction")
                .AddSmallButton(Lang.Get("Collect Funds"), OnCollectFunds, button.FlatCopy().FixedUnder(clipBounds, 20).WithFixedAlignmentOffset(-placelen, 0), EnumButtonStyle.Normal, EnumTextOrientation.Center, "collectFunds")
                .AddSmallButton(Lang.Get("Retrieve Items"), OnRetrieveItems, button.FixedUnder(clipBounds, 20).WithFixedAlignmentOffset(-placelen, 0), EnumButtonStyle.Normal, EnumTextOrientation.Center, "retrieveItems")
                ;
            }

            if (curTab == 1 || curTab == 2)
            {
                selectedElem = null;
                listElem     = SingleComposer.GetCellList <Auction>("stacklist");
                listElem.BeforeCalcBounds();
                listElem.UnscaledCellVerPadding = 0;
                listElem.unscaledCellSpacing    = 5;
                SingleComposer.EndChildElements().Compose();

                updateScrollbarBounds();


                didClickAuctionElem(-1);
            }
        }
        private void SetupDialog()
        {
            // title bar
            ElementBounds bgBounds     = ElementStdBounds.DialogBackground();
            ElementBounds dialogBounds = ElementStdBounds.AutosizedMainDialog.WithChild(bgBounds);

            SingleComposer = capi.Gui.CreateCompo("tailoring", dialogBounds)
                             .AddShadedDialogBG(bgBounds)
                             .AddDialogTitleBar("Tailoring", () => TryClose())
                             .BeginChildElements(bgBounds);
            ElementBounds titleBarBounds = ElementStdBounds.TitleBar();

            bgBounds.WithChild(titleBarBounds);

            // search text box
            ElementBounds searchBounds = ElementBounds.FixedSize(200, 30).FixedUnder(titleBarBounds);

            bgBounds.WithChild(searchBounds);
            SingleComposer.AddTextInput(searchBounds, (string newText) => {
                filterSearch = newText;
                FilterItems();
            }, CairoFont.WhiteSmallishText(), "search");
            SingleComposer.GetTextInput("search").SetPlaceHolderText("Search...");
            // SingleComposer.FocusElement(SingleComposer.GetTextInput("search").TabIndex);

            // prep for category dropdown
            string[]      characterDressTypeNames         = EnumCharacterDressType.GetNames(typeof(EnumCharacterDressType));
            List <string> filteredCharacterDressTypeNames = new List <string>();

            foreach (var characterDressTypeName in characterDressTypeNames)
            {
                if (categoryCount.ContainsKey(characterDressTypeName.ToLowerInvariant()))
                {
                    filteredCharacterDressTypeNames.Add(characterDressTypeName);
                }
            }
            string[] values = new string[filteredCharacterDressTypeNames.Count + 1];
            values[0] = "";
            filteredCharacterDressTypeNames.CopyTo(0, values, 1, filteredCharacterDressTypeNames.Count);
            string[] names = new string[filteredCharacterDressTypeNames.Count + 1];
            names[0] = "(Show all)";
            filteredCharacterDressTypeNames.CopyTo(0, names, 1, filteredCharacterDressTypeNames.Count);

            // category dropdown
            ElementBounds categoryDropdownBounds = ElementBounds.FixedSize(150, 30).FixedUnder(titleBarBounds).FixedRightOf(searchBounds, PADDING);

            bgBounds.WithChild(categoryDropdownBounds);
            SingleComposer.AddDropDown(values, names, 0, (value, selected) => {
                filterCategory = value;
                FilterItems();
            }, categoryDropdownBounds, "category");

            // stacklist
            ElementBounds stacklistBounds = ElementBounds.FixedSize(400, STACKLIST_HEIGHT).FixedUnder(searchBounds, PADDING);

            bgBounds.WithChild(stacklistBounds);
            ElementBounds clipBounds      = stacklistBounds.ForkBoundingParent();
            ElementBounds insetBounds     = stacklistBounds.FlatCopy().FixedGrow(6).WithFixedOffset(-3, -3);
            ElementBounds scrollbarBounds = insetBounds.CopyOffsetedSibling(3 + stacklistBounds.fixedWidth + 7).WithFixedWidth(20);

            SingleComposer
            .BeginClip(clipBounds)
            .AddInset(insetBounds, 3)
            .AddInteractiveElement(new GuiElementHandbookListWithTooltips(capi, stacklistBounds, (int index) => {
                OnSelectProduct((shownStacklistItems[index] as GuiHandbookItemStackPage).Stack);
            }, shownStacklistItems), "stacklist")
            .EndClip()
            .AddVerticalScrollbar((float value) => {
                GuiElementHandbookList stacklist = SingleComposer.GetHandbookStackList("stacklist");
                stacklist.insideBounds.fixedY    = 3 - value;
                stacklist.insideBounds.CalcWorldBounds();
            }, scrollbarBounds, "scrollbar")
            ;
            UpdateStacklistScrollbar();

            // costLabel
            ElementBounds costLabelBounds = ElementBounds.FixedSize(300, 80).FixedUnder(clipBounds, PADDING);

            bgBounds.WithChild(costLabelBounds);
            SingleComposer.AddDynamicText("", CairoFont.WhiteSmallText(), EnumTextOrientation.Left, costLabelBounds, "costLabel");

            // craftButton
            ElementBounds craftButtonBounds = ElementBounds
                                              .FixedSize(0, 0)
                                              .FixedUnder(clipBounds, PADDING)
                                              .WithAlignment(EnumDialogArea.RightFixed)
                                              .WithFixedPadding(20, 4)
                                              .WithFixedAlignmentOffset(-11, 1)
            ;

            bgBounds.WithChild(craftButtonBounds);
            SingleComposer.AddSmallButton("Craft", () => {
                OnCraftButtonClicked();
                return(true);
            }, craftButtonBounds, EnumButtonStyle.Normal, EnumTextOrientation.Center, "craftButton");
            var craftButton = SingleComposer.GetButton("craftButton");

            craftButton.Enabled = false;

            SingleComposer.EndChildElements(); // bgBounds
            SingleComposer.Compose();
        }