From a2d6eb085cd199f63e97ad1632d4b47e5d94f6aa Mon Sep 17 00:00:00 2001 From: syeyoung Date: Mon, 27 Feb 2023 20:04:21 +0900 Subject: - Search in config Signed-off-by: syeyoung --- .../guiconfig/configv3/MainConfigWidget.java | 34 +++++++++++- .../configv3/SearchPageCategoryWidget.java | 46 +++++++++++++++++ .../guiconfig/configv3/SearchPageWidget.java | 60 ++++++++++++++++++++++ .../mod/guiv2/elements/Navigator.java | 11 +++- .../dungeonsguide/gui/config/normalconfig.gui | 29 ++++------- .../gui/config/search/fromcategory.gui | 29 +++++++++++ .../dungeonsguide/gui/config/search/searchpage.gui | 31 +++++++++++ 7 files changed, 219 insertions(+), 21 deletions(-) create mode 100644 mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/configv3/SearchPageCategoryWidget.java create mode 100644 mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/configv3/SearchPageWidget.java create mode 100644 mod/src/main/resources/assets/dungeonsguide/gui/config/search/fromcategory.gui create mode 100644 mod/src/main/resources/assets/dungeonsguide/gui/config/search/searchpage.gui diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/configv3/MainConfigWidget.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/configv3/MainConfigWidget.java index 1dc6b5b9..2246c10d 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/configv3/MainConfigWidget.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/configv3/MainConfigWidget.java @@ -23,9 +23,13 @@ import kr.syeyoung.dungeonsguide.mod.config.guiconfig.location2.HUDLocationConfi import kr.syeyoung.dungeonsguide.mod.features.AbstractFeature; import kr.syeyoung.dungeonsguide.mod.features.FeatureRegistry; import kr.syeyoung.dungeonsguide.mod.guiv2.BindableAttribute; +import kr.syeyoung.dungeonsguide.mod.guiv2.DomElement; import kr.syeyoung.dungeonsguide.mod.guiv2.Widget; import kr.syeyoung.dungeonsguide.mod.guiv2.elements.Navigator; import kr.syeyoung.dungeonsguide.mod.guiv2.elements.Text; +import kr.syeyoung.dungeonsguide.mod.guiv2.renderer.Renderer; +import kr.syeyoung.dungeonsguide.mod.guiv2.renderer.RenderingContext; +import kr.syeyoung.dungeonsguide.mod.guiv2.renderer.SingleChildRenderer; import kr.syeyoung.dungeonsguide.mod.guiv2.xml.AnnotatedImportOnlyWidget; import kr.syeyoung.dungeonsguide.mod.guiv2.xml.annotations.Bind; import kr.syeyoung.dungeonsguide.mod.guiv2.xml.annotations.On; @@ -38,7 +42,7 @@ import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; -public class MainConfigWidget extends AnnotatedImportOnlyWidget { +public class MainConfigWidget extends AnnotatedImportOnlyWidget implements Renderer { @Bind(variableName = "menu") public final BindableAttribute menu = new BindableAttribute<>(WidgetList.class); @Bind(variableName = "relocate") @@ -49,13 +53,21 @@ public class MainConfigWidget extends AnnotatedImportOnlyWidget { @Bind(variableName = "sidebar") public final BindableAttribute sidebar = new BindableAttribute<>(String.class, "hide"); + @Bind(variableName = "search") + public final BindableAttribute search = new BindableAttribute<>(String.class, ""); @Bind(variableName = "mainpage") public final BindableAttribute mainPage = new BindableAttribute<>(Widget.class, new MainPageWidget()); + + private long doSearch = Long.MAX_VALUE; public MainConfigWidget() { super(new ResourceLocation("dungeonsguide:gui/config/normalconfig.gui")); menu.setValue(buildMenu()); relocate.setValue(new GUIOpenItem("GUI Config", () -> new HUDLocationConfig(null))); + + search.addOnUpdate((old, neu) -> { + doSearch = System.currentTimeMillis() + 500; + }); } public List buildMenu() { @@ -80,4 +92,24 @@ public class MainConfigWidget extends AnnotatedImportOnlyWidget { else this.sidebar.setValue("show"); } + + @Override + public void doRender(int absMouseX, int absMouseY, double relMouseX, double relMouseY, float partialTicks, RenderingContext context, DomElement buildContext) { + if (doSearch < System.currentTimeMillis()) { + doSearch = Long.MAX_VALUE; + + Navigator navigator = Navigator.getNavigator(getDomElement()); + if (search.getValue().isEmpty()) { + if (navigator.getCurrent() instanceof SearchPageWidget) + navigator.goBack(); + } else { + if (navigator.getCurrent() instanceof SearchPageWidget) + navigator.setPageWithoutPush(new SearchPageWidget(search.getValue())); + else + navigator.openPage(new SearchPageWidget(search.getValue())); + } + } + + SingleChildRenderer.INSTANCE.doRender(absMouseX,absMouseY,relMouseX,relMouseY,partialTicks,context,buildContext); + } } diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/configv3/SearchPageCategoryWidget.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/configv3/SearchPageCategoryWidget.java new file mode 100644 index 00000000..b666b3f6 --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/configv3/SearchPageCategoryWidget.java @@ -0,0 +1,46 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2023 cyoung06 (syeyoung) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package kr.syeyoung.dungeonsguide.mod.config.guiconfig.configv3; + +import kr.syeyoung.dungeonsguide.mod.features.AbstractFeature; +import kr.syeyoung.dungeonsguide.mod.features.FeatureRegistry; +import kr.syeyoung.dungeonsguide.mod.features.IFeature; +import kr.syeyoung.dungeonsguide.mod.guiv2.BindableAttribute; +import kr.syeyoung.dungeonsguide.mod.guiv2.Widget; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.AnnotatedImportOnlyWidget; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.annotations.Bind; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.data.WidgetList; +import net.minecraft.util.ResourceLocation; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +public class SearchPageCategoryWidget extends AnnotatedImportOnlyWidget { + @Bind(variableName = "items") + public final BindableAttribute items = new BindableAttribute<>(WidgetList.class); + @Bind(variableName = "category") + public final BindableAttribute category = new BindableAttribute<>(String.class); + public SearchPageCategoryWidget(String category, List featureList) { + super(new ResourceLocation("dungeonsguide:gui/config/search/fromcategory.gui")); + items.setValue(featureList.stream().map(FeatureItem::new).collect(Collectors.toList())); + this.category.setValue(category.replace(".", " > ")); + } + +} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/configv3/SearchPageWidget.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/configv3/SearchPageWidget.java new file mode 100644 index 00000000..917c8121 --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/configv3/SearchPageWidget.java @@ -0,0 +1,60 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2023 cyoung06 (syeyoung) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package kr.syeyoung.dungeonsguide.mod.config.guiconfig.configv3; + +import kr.syeyoung.dungeonsguide.mod.features.AbstractFeature; +import kr.syeyoung.dungeonsguide.mod.features.FeatureRegistry; +import kr.syeyoung.dungeonsguide.mod.guiv2.BindableAttribute; +import kr.syeyoung.dungeonsguide.mod.guiv2.Widget; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.AnnotatedImportOnlyWidget; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.annotations.Bind; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.data.WidgetList; +import net.minecraft.util.ResourceLocation; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class SearchPageWidget extends AnnotatedImportOnlyWidget { + @Bind(variableName = "items") + public final BindableAttribute items = new BindableAttribute<>(WidgetList.class); + @Bind(variableName = "resultShow") + public final BindableAttribute resultShow = new BindableAttribute<>(String.class, "hide"); + public SearchPageWidget(String word) { + super(new ResourceLocation("dungeonsguide:gui/config/search/searchpage.gui")); + + Map> categoryMap = new HashMap<>(); + for (AbstractFeature abstractFeature : FeatureRegistry.getFeatureList()) { + if (abstractFeature.getName().toLowerCase().contains(word.toLowerCase()) || abstractFeature.getDescription().toLowerCase().contains(word.toLowerCase())) { + if (!categoryMap.containsKey(abstractFeature.getCategory())) + categoryMap.put(abstractFeature.getCategory(), new ArrayList<>()); + categoryMap.get(abstractFeature.getCategory()).add(abstractFeature); + } + } + + resultShow.setValue(categoryMap.isEmpty() ? "hide" : "show"); + + List widgets = new ArrayList<>(); + for (Map.Entry> stringListEntry : categoryMap.entrySet()) { + widgets.add(new SearchPageCategoryWidget(stringListEntry.getKey(), stringListEntry.getValue())); + } + this.items.setValue(widgets); + } +} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Navigator.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Navigator.java index 5126b7cb..718b1844 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Navigator.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Navigator.java @@ -24,6 +24,7 @@ import kr.syeyoung.dungeonsguide.mod.guiv2.Widget; import kr.syeyoung.dungeonsguide.mod.guiv2.xml.AnnotatedExportOnlyWidget; import kr.syeyoung.dungeonsguide.mod.guiv2.xml.annotations.Bind; import kr.syeyoung.dungeonsguide.mod.guiv2.xml.annotations.Export; +import lombok.Getter; import java.util.Collections; import java.util.List; @@ -35,7 +36,8 @@ public class Navigator extends AnnotatedExportOnlyWidget { @Export(attributeName = "_") public final BindableAttribute child = new BindableAttribute<>(Widget.class); - public Widget current; + @Getter + private Widget current; public Navigator() { child.addOnUpdate((old, a) -> { @@ -44,12 +46,19 @@ public class Navigator extends AnnotatedExportOnlyWidget { } public void openPage(Widget widget) { + if (widget.equals(current)) return; widgets.push(current); getDomElement().removeElement(getDomElement().getChildren().get(0)); getDomElement().addElement(widget.createDomElement(getDomElement())); current = widget; } + public void setPageWithoutPush(Widget widget) { + getDomElement().removeElement(getDomElement().getChildren().get(0)); + getDomElement().addElement(widget.createDomElement(getDomElement())); + current = widget; + } + public void goBack() { getDomElement().removeElement(getDomElement().getChildren().get(0)); Widget page; diff --git a/mod/src/main/resources/assets/dungeonsguide/gui/config/normalconfig.gui b/mod/src/main/resources/assets/dungeonsguide/gui/config/normalconfig.gui index 410b3423..3acb0660 100644 --- a/mod/src/main/resources/assets/dungeonsguide/gui/config/normalconfig.gui +++ b/mod/src/main/resources/assets/dungeonsguide/gui/config/normalconfig.gui @@ -49,25 +49,16 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + diff --git a/mod/src/main/resources/assets/dungeonsguide/gui/config/search/fromcategory.gui b/mod/src/main/resources/assets/dungeonsguide/gui/config/search/fromcategory.gui new file mode 100644 index 00000000..d8bc1817 --- /dev/null +++ b/mod/src/main/resources/assets/dungeonsguide/gui/config/search/fromcategory.gui @@ -0,0 +1,29 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/mod/src/main/resources/assets/dungeonsguide/gui/config/search/searchpage.gui b/mod/src/main/resources/assets/dungeonsguide/gui/config/search/searchpage.gui new file mode 100644 index 00000000..e21bc8e1 --- /dev/null +++ b/mod/src/main/resources/assets/dungeonsguide/gui/config/search/searchpage.gui @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + \ No newline at end of file -- cgit