private void OnNewScrollbarvalueOverviewPage(float value) { GuiElementHandbookList stacklist = overviewGui.GetHandbookStackList("stacklist"); stacklist.insideBounds.fixedY = 3 - value; stacklist.insideBounds.CalcWorldBounds(); }
private void FilterItems() { shownStacklistItems.Clear(); foreach (GuiHandbookItemStackPage stacklistItem in allStacklistItems) { if (filterCategory != "") { var stacklistItemClothesCategory = stacklistItem.Stack.ItemAttributes?["clothescategory"].AsString() ?? ""; if (stacklistItemClothesCategory != filterCategory.ToLowerInvariant()) { // capi.Logger.Debug($"filtering by cat: {stacklistItemClothesCategory} != {filterCategory}"); continue; } } if (filterSearch != "") { var itemName = stacklistItem.Stack.GetName(); if (!itemName.ToLowerInvariant().Contains(filterSearch.ToLowerInvariant())) { continue; } } shownStacklistItems.Add(stacklistItem); } GuiElementHandbookList stacklist = SingleComposer.GetHandbookStackList("stacklist"); stacklist.CalcTotalHeight(); UpdateStacklistScrollbar(); }
public void FilterItems() { string text = currentSearchText?.ToLowerInvariant(); List <WeightedHandbookPage> foundPages = new List <WeightedHandbookPage>(); shownHandbookPages.Clear(); for (int i = 0; i < allHandbookPages.Count; i++) { GuiHandbookPage page = allHandbookPages[i]; if (currentCatgoryCode != null && page.CategoryCode != currentCatgoryCode) { continue; } float weight = 1; if (text != null && text.Length != 0) { weight = page.TextMatchWeight(text); if (weight <= 0) { continue; } } foundPages.Add(new WeightedHandbookPage() { Page = page, Weight = weight }); } foreach (var val in foundPages.OrderByDescending(wpage => wpage.Weight)) { shownHandbookPages.Add(val.Page); } GuiElementHandbookList stacklist = overviewGui.GetHandbookStackList("stacklist"); stacklist.CalcTotalHeight(); overviewGui.GetScrollbar("scrollbar").SetHeights( (float)listHeight, (float)stacklist.insideBounds.fixedHeight ); }
public void FilterItemsBySearchText(string text) { currentSearchText = text; text = text.ToLowerInvariant(); for (int i = 0; i < listElements.Count; i++) { listElements[i].Visible = text.Length == 0 || listElements[i].MatchesText(text); } GuiElementHandbookList stacklist = overviewGui.GetHandbookStackList("stacklist"); stacklist.CalcTotalHeight(); overviewGui.GetScrollbar("scrollbar").SetHeights( (float)listHeight, (float)stacklist.insideBounds.fixedHeight ); }
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(); }