aboutsummaryrefslogtreecommitdiff
path: root/mod/src/main/java/kr/syeyoung
diff options
context:
space:
mode:
authorsyeyoung <cyoung06@naver.com>2023-02-27 20:04:21 +0900
committersyeyoung <cyoung06@naver.com>2023-02-27 20:04:33 +0900
commita2d6eb085cd199f63e97ad1632d4b47e5d94f6aa (patch)
tree59c840ef54b9adc34313eb477c289d37316ea2fa /mod/src/main/java/kr/syeyoung
parent8a891463f2c593d71f02d6f585976cd75d3d98e1 (diff)
downloadSkyblock-Dungeons-Guide-a2d6eb085cd199f63e97ad1632d4b47e5d94f6aa.tar.gz
Skyblock-Dungeons-Guide-a2d6eb085cd199f63e97ad1632d4b47e5d94f6aa.tar.bz2
Skyblock-Dungeons-Guide-a2d6eb085cd199f63e97ad1632d4b47e5d94f6aa.zip
- Search in config
Signed-off-by: syeyoung <cyoung06@naver.com>
Diffstat (limited to 'mod/src/main/java/kr/syeyoung')
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/configv3/MainConfigWidget.java34
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/configv3/SearchPageCategoryWidget.java46
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/configv3/SearchPageWidget.java60
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Navigator.java11
4 files changed, 149 insertions, 2 deletions
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<String> sidebar = new BindableAttribute<>(String.class, "hide");
+ @Bind(variableName = "search")
+ public final BindableAttribute<String> search = new BindableAttribute<>(String.class, "");
@Bind(variableName = "mainpage")
public final BindableAttribute<Widget> 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<Widget> 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 <https://www.gnu.org/licenses/>.
+ */
+
+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<String> category = new BindableAttribute<>(String.class);
+ public SearchPageCategoryWidget(String category, List<AbstractFeature> 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 <https://www.gnu.org/licenses/>.
+ */
+
+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<String> resultShow = new BindableAttribute<>(String.class, "hide");
+ public SearchPageWidget(String word) {
+ super(new ResourceLocation("dungeonsguide:gui/config/search/searchpage.gui"));
+
+ Map<String, List<AbstractFeature>> 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<Widget> widgets = new ArrayList<>();
+ for (Map.Entry<String, List<AbstractFeature>> 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<Widget> 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;