private void ComposeDialog() { int height = 200; int tableWidth = 150; int textAreaWidth = 200; int headerHeight = 20; int labelWidth = 60; var spacer = ElementStdBounds .TitleBar(); var tableBounds = Fixed(0, 0, tableWidth, height); var labelBounds = Fixed(0, 0, labelWidth, headerHeight); var nameInputBounds = Fixed(labelWidth, 0, textAreaWidth - labelWidth, headerHeight); var headerBounds = Fixed(0, 0, textAreaWidth, headerHeight) .WithChildren(labelBounds, nameInputBounds); var textAreaBounds = Fixed(0, 0, textAreaWidth, height) .FixedUnder(headerBounds, HalfPadding); var textContainerBounds = Fill .WithSizing(ElementSizing.FitToChildren) .FixedRightOf(tableBounds, HalfPadding) .WithChildren(textAreaBounds, headerBounds); var bodyBounds = Fill .WithSizing(ElementSizing.FitToChildren) .FixedUnder(spacer) .WithChildren(textContainerBounds, tableBounds); var bgBounds = Fill .WithFixedPadding(ElementToDialogPadding) .WithChildren(bodyBounds) .WithSizing(ElementSizing.FitToChildren); var dialogBounds = ElementStdBounds .AutosizedMainDialog .WithAlignment(EnumDialogArea.CenterMiddle); SingleComposer = capi.Gui.CreateCompo("aliaseditor", dialogBounds) .AddShadedDialogBG(bgBounds) .AddDialogTitleBar("Alias Editor", () => TryClose()) .AddStaticText("Alias:", CairoFont.WhiteSmallishText(), labelBounds) .AddTextInput(nameInputBounds, OnAliasNameChanged, CairoFont.TextInput(), "aliastextinput") .AddTextArea(textAreaBounds, OnAliasTextChanged, CairoFont.TextInput(), "aliastextarea") .AddCellList(tableBounds, (cell, elBounds) => new GuiElementCell(capi, cell, elBounds) { ShowModifyIcons = false }, OnMouseDownOnCell, OnMouseDownOnCell, cellList, "aliascellarea") .Compose(); textArea = SingleComposer.GetTextArea("aliastextarea"); textArea.Enabled = false; textInput = SingleComposer.GetTextInput("aliastextinput"); }
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(); }
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(); }