public override void OnBeforeRenderFrame3D(float deltaTime) { base.OnBeforeRenderFrame3D(deltaTime); if (notifyPlayerMoneyTextSeconds > 0) { notifyPlayerMoneyTextSeconds -= deltaTime; if (notifyPlayerMoneyTextSeconds <= 0) { SingleComposer.GetDynamicText("playerMoneyText").Bounds.absFixedX = prevPlrAbsFixedX; SingleComposer.GetDynamicText("playerMoneyText").Bounds.absFixedY = prevPlrAbsFixedY; } else { SingleComposer.GetDynamicText("playerMoneyText").Bounds.absFixedX = prevPlrAbsFixedX + notifyPlayerMoneyTextSeconds * (capi.World.Rand.NextDouble() * 4 - 2); SingleComposer.GetDynamicText("playerMoneyText").Bounds.absFixedY = prevPlrAbsFixedY + notifyPlayerMoneyTextSeconds * (capi.World.Rand.NextDouble() * 4 - 2); } } if (notifyTraderMoneyTextSeconds > 0) { notifyTraderMoneyTextSeconds -= deltaTime; if (notifyTraderMoneyTextSeconds <= 0) { SingleComposer.GetDynamicText("traderMoneyText").Bounds.absFixedX = prevPlrAbsFixedX; SingleComposer.GetDynamicText("traderMoneyText").Bounds.absFixedY = prevPlrAbsFixedY; } else { SingleComposer.GetDynamicText("traderMoneyText").Bounds.absFixedX = prevTdrAbsFixedX + notifyTraderMoneyTextSeconds * (capi.World.Rand.NextDouble() * 4 - 2); SingleComposer.GetDynamicText("traderMoneyText").Bounds.absFixedY = prevTdrAbsFixedY + notifyTraderMoneyTextSeconds * (capi.World.Rand.NextDouble() * 4 - 2); } } }
public override void OnMouseUp(MouseEvent args) { if (!SingleComposer.Bounds.PointInside(args.X, args.Y)) { base.OnMouseUp(args); return; } var mpc = SingleComposer.GetElement("mapElem") as GuiElementMap; foreach (MapLayer ml in mpc.mapLayers) { ml.OnMouseUpClient(args, mpc); if (args.Handled) { return; } } if (args.Button == EnumMouseButton.Right) { Vec3d wpPos = new Vec3d(); loadWorldPos(args.X, args.Y, ref wpPos); if (addWpDlg != null) { addWpDlg.TryClose(); addWpDlg.Dispose(); } addWpDlg = new GuiDialogAddWayPoint(capi); addWpDlg.WorldPos = wpPos; addWpDlg.TryOpen(); } base.OnMouseUp(args); }
public GuiDialogItemStackRandomizer(float totalChance, ICoreClientAPI capi) : base("Item Stack Randomizer", capi) { double pad = GuiElementItemSlotGrid.unscaledSlotPadding; ElementBounds chanceInputBounds = ElementBounds.Fixed(0, 70, 60, 30); 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 bgBounds = ElementBounds.Fill.WithFixedPadding(GuiStyle.ElementToDialogPadding); bgBounds.BothSizing = ElementSizing.FitToChildren; ElementBounds dialogBounds = ElementStdBounds .AutosizedMainDialog.WithAlignment(EnumDialogArea.CenterMiddle) .WithFixedAlignmentOffset(GuiStyle.DialogToScreenPadding, 0); SingleComposer = capi.Gui .CreateCompo("itemstackrandomizer", dialogBounds) .AddShadedDialogBG(bgBounds, true) .AddDialogTitleBar("Item Stack Randomizer", OnTitleBarClose) .BeginChildElements(bgBounds) .AddStaticText("Chance for any loot to appear:", CairoFont.WhiteDetailText(), ElementBounds.Fixed(0, 30, 250, 30)) .AddNumberInput(chanceInputBounds = chanceInputBounds.FlatCopy(), null, CairoFont.WhiteDetailText(), "chance") .AddButton("Close", OnCloseClicked, leftButton.FixedUnder(chanceInputBounds, 25)) .AddButton("Save", OnSaveClicked, rightButton.FixedUnder(chanceInputBounds, 25)) .EndChildElements() .Compose() ; SingleComposer.GetNumberInput("chance").SetValue("" + (totalChance * 100)); }
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), }); }
public override void OnGuiClosed() { SingleComposer.Dispose(); }
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(); }
private void onNameChanged(string t1) { bool hasValidColor = (SingleComposer.GetTextInput("colorInput").Font.Color != GuiStyle.ErrorTextColor); SingleComposer.GetButton("saveButton").Enabled = (t1.Trim() != "") && hasValidColor; }
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); } }
public override void OnGuiOpened() { base.OnGuiOpened(); SingleComposer.FocusElement(SingleComposer.GetTextArea("text").TabIndex); }
public override void OnGuiClosed() { base.OnGuiClosed(); capi.Network.SendPacketClient(inventory.Close(capi.World.Player)); SingleComposer.GetSlotGrid("slot").OnGuiClosed(capi); }
public void TranslateWorldPosToViewPos(Vec3d worldPos, ref Vec2f viewPos) { var mpc = SingleComposer.GetElement("mapElem") as GuiElementMap; mpc.TranslateWorldPosToViewPos(worldPos, ref viewPos); }
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(); } }
public void UpdateContents() { SingleComposer.GetCustomDraw("liquidBar").Redraw(); }
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(); }
private void OnCountChanged(string t1) { float count = SingleComposer.GetNumberInput("spawncount").GetValue(); spawnerData.RemoveAfterSpawnCount = (int)count; }
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(); }
public void SetupDialog() { ItemSlot hoveredSlot = capi.World.Player.InventoryManager.CurrentHoveredSlot; if (hoveredSlot != null && hoveredSlot.Inventory == Inventory) { capi.Input.TriggerOnMouseLeaveSlot(hoveredSlot); } else { hoveredSlot = null; } ElementBounds quernBounds = ElementBounds.Fixed(0, 0, 400, 400); // 2. Around all that is 10 pixel padding ElementBounds bgBounds = ElementBounds.Fill.WithFixedPadding(GuiStyle.ElementToDialogPadding); bgBounds.BothSizing = ElementSizing.FitToChildren; bgBounds.WithChildren(quernBounds); // 3. Finally Dialog ElementBounds dialogBounds = ElementStdBounds.AutosizedMainDialog.WithAlignment(EnumDialogArea.CenterMiddle) .WithFixedAlignmentOffset(-GuiStyle.DialogToScreenPadding, 0); ClearComposers(); SingleComposer = capi.Gui .CreateCompo("BlockEntityTinkerTable" + BlockEntityPosition, dialogBounds) .AddShadedDialogBG(bgBounds) .AddDialogTitleBar(DialogTitle, OnTitleBarClose) .BeginChildElements(bgBounds) .AddItemSlotGrid(Inventory, SendInvPacket, 1, new int[] { 0 }, ElementStdBounds.SlotGrid(EnumDialogArea.CenterMiddle, 0, 0, 1, 1), "targetSlot") ; IModularItem item = Inventory[0].Itemstack?.Item as IModularItem; SlotDefinition[] slotdefs = item?.TinkerProps?.AvailableSlots; if (item != null && slotdefs != null) { var slots = item.GetSlots(Inventory[0].Itemstack); for (int i = 0; i < slotdefs.Length && i < Inventory.Count - 1; ++i) { var slotdef = slotdefs[i]; ItemStack stack = slots[slotdef.SlotName]; int invslot = i + 1; if (stack == null) { stack = Inventory[invslot].Itemstack; } Inventory[invslot].Itemstack = stack; SingleComposer = SingleComposer.AddItemSlotGrid(Inventory, SendInvPacket, 1, new int[] { invslot }, ElementStdBounds.SlotGrid(EnumDialogArea.CenterMiddle, slotdef.OffsetX, slotdef.OffsetY, 1, 1), "partSlot" + invslot.ToString()); } } else if (Inventory[0].Itemstack?.Item == null && Inventory.Count >= 4) { SingleComposer = SingleComposer .AddItemSlotGrid(Inventory, SendInvPacket, 1, new int[] { 1 }, ElementStdBounds.SlotGrid(EnumDialogArea.CenterMiddle, 0, -90.0, 1, 1), "partSlot1"); SingleComposer = SingleComposer .AddItemSlotGrid(Inventory, SendInvPacket, 1, new int[] { 3 }, ElementStdBounds.SlotGrid(EnumDialogArea.CenterMiddle, 0, 90.0, 1, 1), "partSlot2"); } SingleComposer = SingleComposer.Compose(); if (hoveredSlot != null) { SingleComposer.OnMouseMove(new MouseEvent(capi.Input.MouseX, capi.Input.MouseY)); } }
public GuiDialogSignPost(string DialogTitle, BlockPos blockEntityPos, string[] textByCardinalDirection, ICoreClientAPI capi, CairoFont signPostFont) : base(DialogTitle, capi) { this.signPostFont = signPostFont; this.blockEntityPos = blockEntityPos; ElementBounds line = ElementBounds.Fixed(0, 0, 150, 20); ElementBounds input = ElementBounds.Fixed(0, 15, 150, 25); // 2. Around all that is 10 pixel padding ElementBounds bgBounds = ElementBounds.Fill.WithFixedPadding(GuiStyle.ElementToDialogPadding); bgBounds.BothSizing = ElementSizing.FitToChildren; // 3. Finally Dialog ElementBounds dialogBounds = ElementStdBounds.AutosizedMainDialog.WithAlignment(EnumDialogArea.LeftTop) .WithFixedAlignmentOffset(60 + GuiStyle.DialogToScreenPadding, GuiStyle.DialogToScreenPadding); float inputLineY = 27; float textLineY = 32; float width = 250; SingleComposer = capi.Gui .CreateCompo("blockentitytexteditordialog", dialogBounds) .AddShadedDialogBG(bgBounds) .AddDialogTitleBar(DialogTitle, OnTitleBarClose) .BeginChildElements(bgBounds) .AddStaticText("North", CairoFont.WhiteDetailText(), line = line.BelowCopy(0, 0).WithFixedWidth(width)) .AddTextInput(input = input.BelowCopy(0, 0).WithFixedWidth(width), OnTextChangedDlg, CairoFont.WhiteSmallText(), "text0") .AddStaticText("Northeast", CairoFont.WhiteDetailText(), line = line.BelowCopy(0, textLineY).WithFixedWidth(width)) .AddTextInput(input = input.BelowCopy(0, inputLineY).WithFixedWidth(width), OnTextChangedDlg, CairoFont.WhiteSmallText(), "text1") .AddStaticText("East", CairoFont.WhiteDetailText(), line = line.BelowCopy(0, textLineY).WithFixedWidth(width)) .AddTextInput(input = input.BelowCopy(0, inputLineY).WithFixedWidth(width), OnTextChangedDlg, CairoFont.WhiteSmallText(), "text2") .AddStaticText("Southeast", CairoFont.WhiteDetailText(), line = line.BelowCopy(0, textLineY).WithFixedWidth(width)) .AddTextInput(input = input.BelowCopy(0, inputLineY).WithFixedWidth(width), OnTextChangedDlg, CairoFont.WhiteSmallText(), "text3") .AddStaticText("South", CairoFont.WhiteDetailText(), line = line.BelowCopy(0, textLineY).WithFixedWidth(width)) .AddTextInput(input = input.BelowCopy(0, inputLineY).WithFixedWidth(width), OnTextChangedDlg, CairoFont.WhiteSmallText(), "text4") .AddStaticText("Southwest", CairoFont.WhiteDetailText(), line = line.BelowCopy(0, textLineY).WithFixedWidth(width)) .AddTextInput(input = input.BelowCopy(0, inputLineY).WithFixedWidth(width), OnTextChangedDlg, CairoFont.WhiteSmallText(), "text5") .AddStaticText("West", CairoFont.WhiteDetailText(), line = line.BelowCopy(0, textLineY).WithFixedWidth(width)) .AddTextInput(input = input.BelowCopy(0, inputLineY).WithFixedWidth(width), OnTextChangedDlg, CairoFont.WhiteSmallText(), "text6") .AddStaticText("Northwest", CairoFont.WhiteDetailText(), line = line.BelowCopy(0, textLineY).WithFixedWidth(width)) .AddTextInput(input = input.BelowCopy(0, inputLineY).WithFixedWidth(width), OnTextChangedDlg, CairoFont.WhiteSmallText(), "text7") .AddSmallButton(Lang.Get("Cancel"), OnButtonCancel, input = input.BelowCopy(0, 20).WithFixedSize(100, 20).WithAlignment(EnumDialogArea.LeftFixed).WithFixedPadding(10, 2), EnumButtonStyle.Normal, EnumTextOrientation.Center) .AddSmallButton(Lang.Get("Save"), OnButtonSave, input = input.FlatCopy().WithFixedSize(100, 20).WithAlignment(EnumDialogArea.RightFixed).WithFixedPadding(10, 2), EnumButtonStyle.Normal, EnumTextOrientation.Center) .EndChildElements() .Compose() ; for (int i = 0; i < 8; i++) { GuiElementTextInput texinput = SingleComposer.GetTextInput("text" + i); texinput.SetValue(textByCardinalDirection[i]); } }
private void OnNewScrollbarValue(float value) { listElem = SingleComposer.GetCellList <Auction>("stacklist"); listElem.Bounds.fixedY = 0 - value; listElem.Bounds.CalcWorldBounds(); }
private void ComposeDialog() { ElementBounds mapBounds = ElementBounds.Fixed(0, 28, 1200, 800); 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 (dialogType == 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); } Vec3d centerPos = capi.World.Player.Entity.Pos.XYZ; if (SingleComposer != null) { SingleComposer.Dispose(); } SingleComposer = capi.Gui .CreateCompo("worldmap", dialogBounds) .AddShadedDialogBG(bgBounds, false) .AddIf(dialogType == EnumDialogType.Dialog) .AddDialogTitleBar("World Map", OnTitleBarClose) .AddInset(mapBounds, 2) .EndIf() .BeginChildElements(bgBounds) .AddHoverText("", CairoFont.WhiteDetailText(), 350, mapBounds.FlatCopy(), "hoverText") .AddInteractiveElement(new GuiElementMap(mapComponents, centerPos, capi, mapBounds), "mapElem") .EndChildElements() .Compose() ; SingleComposer.OnRecomposed += SingleComposer_OnRecomposed; mapElem = SingleComposer.GetElement("mapElem") as GuiElementMap; mapElem.viewChanged = viewChanged; mapElem.ZoomAdd(1, 0.5f, 0.5f); hoverTextElem = SingleComposer.GetHoverText("hoverText"); hoverTextElem.SetAutoWidth(true); if (listenerId != 0) { capi.Event.UnregisterGameTickListener(listenerId); } listenerId = capi.Event.RegisterGameTickListener( (dt) => { mapElem.EnsureMapFullyLoaded(); if (requireRecompose) { TryClose(); TryOpen(); requireRecompose = false; } } , 100); }
void SetupDialog() { ItemSlot hoveredSlot = capi.World.Player.InventoryManager.CurrentHoveredSlot; if (hoveredSlot != null && hoveredSlot.Inventory?.InventoryID != Inventory?.InventoryID) { //capi.Input.TriggerOnMouseLeaveSlot(hoveredSlot); - wtf is this for? 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(), EnumTextOrientation.Left, 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(), EnumTextOrientation.Left, fuelSlotBounds.RightCopy(17, 16).WithFixedSize(60, 30), "fueltemp") .AddItemSlotGrid(Inventory, SendInvPacket, 1, new int[] { 1 }, inputSlotBounds, "oreslot") .AddDynamicText("", CairoFont.WhiteDetailText(), EnumTextOrientation.Left, 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(); }
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; }
public override void OnOwnPlayerDataReceived() { base.OnOwnPlayerDataReceived(); 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(); }
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); }
public void UpdateContents() { SingleComposer.GetCustomDraw("liquidBar").Redraw(); SingleComposer.GetDynamicText("contentText").SetNewText(getContentsText()); }
private void OnMaxChanged(string t1) { float max = SingleComposer.GetNumberInput("maxentities").GetValue(); spawnerData.MaxCount = (int)max; }
private void OnTextChanged(string value) { GuiElementDynamicText logtextElem = SingleComposer.GetDynamicText("text"); SingleComposer.GetScrollbar("scrollbar").SetNewTotalHeight((float)logtextElem.Bounds.fixedHeight); }
private void OnIntervalChanged(string t1) { float interval = SingleComposer.GetNumberInput("interval").GetValue(); spawnerData.InGameHourInterval = interval; }
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("Modify waypoint", () => TryClose()) .BeginChildElements(bgBounds) .AddRichtext("Color (<a href=\"https://www.99colors.net/dot-net-colors\">List</a>)", CairoFont.WhiteSmallText(), leftColumn = leftColumn.FlatCopy()) .AddTextInput(rightColumn = rightColumn.FlatCopy().WithFixedWidth(150), onColorChanged, CairoFont.TextInput(), "colorInput") .AddDynamicCustomDraw(rightColumn.FlatCopy().WithFixedWidth(30).WithFixedOffset(160, 0), onDrawColorRect, "colorRect") .AddStaticText("Name", CairoFont.WhiteSmallText(), leftColumn = leftColumn.BelowCopy(0, 5)) .AddTextInput(rightColumn = rightColumn.BelowCopy(0, 5).WithFixedWidth(200), onNameChanged, CairoFont.TextInput(), "nameInput") .AddStaticText("Icon", CairoFont.WhiteSmallText(), leftColumn = leftColumn.BelowCopy(0, 5)) .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" ) .AddSmallButton("Cancel", onCancel, buttonRow.FlatCopy().FixedUnder(leftColumn, 0).WithFixedWidth(100), EnumButtonStyle.Normal) .AddSmallButton("Delete", onDelete, buttonRow.FlatCopy().FixedUnder(leftColumn, 0).WithFixedWidth(100).WithAlignment(EnumDialogArea.CenterFixed), EnumButtonStyle.Normal) .AddSmallButton("Save", onSave, buttonRow.FlatCopy().FixedUnder(leftColumn, 0).WithFixedWidth(100).WithAlignment(EnumDialogArea.RightFixed), EnumButtonStyle.Normal, key: "saveButton") .EndChildElements() .Compose() ; var col = System.Drawing.Color.FromArgb(0, ColorUtil.ColorR(waypoint.Color), ColorUtil.ColorG(waypoint.Color), ColorUtil.ColorB(waypoint.Color)); if (col.IsKnownColor) { SingleComposer.GetTextInput("colorInput").SetValue(col.ToKnownColor().ToString().ToLowerInvariant()); } else { SingleComposer.GetTextInput("colorInput").SetValue(ColorUtil.Int2Hex(waypoint.Color)); } SingleComposer.GetTextInput("nameInput").SetValue(waypoint.Title); }
public override void OnGuiOpened() { OnOwnPlayerDataReceived(); SingleComposer.Compose(); }