diff options
author | nea <romangraef@gmail.com> | 2022-04-28 02:21:50 +0200 |
---|---|---|
committer | nea <romangraef@gmail.com> | 2022-04-28 02:21:50 +0200 |
commit | 18f8c51dba37368d0a8810bfeabe9f3f499a36dc (patch) | |
tree | dea43cfaa0eb2212d05416efc876b2ca11d7c8d2 | |
parent | c5e88e1f689bd259da654e57481beb6c7753e3bd (diff) | |
download | NotEnoughUpdates-18f8c51dba37368d0a8810bfeabe9f3f499a36dc.tar.gz NotEnoughUpdates-18f8c51dba37368d0a8810bfeabe9f3f499a36dc.tar.bz2 NotEnoughUpdates-18f8c51dba37368d0a8810bfeabe9f3f499a36dc.zip |
track / untrack + ery texture
Co-Authored-By: RayDeeUx <51521765+RayDeeUx@users.noreply.github.com>
7 files changed, 80 insertions, 25 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java index b11379a6..e3a60066 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java @@ -79,6 +79,7 @@ public class NEUManager { public final APIManager auctionManager; private final TreeMap<String, JsonObject> itemMap = new TreeMap<>(); + private boolean hasBeenLoadedBefore = false; private final TreeMap<String, HashMap<String, List<Integer>>> titleWordMap = new TreeMap<>(); private final TreeMap<String, HashMap<String, List<Integer>>> loreWordMap = new TreeMap<>(); @@ -1523,7 +1524,8 @@ public class NEUManager { } } - new RepositoryReloadEvent(repoLocation).post(); + new RepositoryReloadEvent(repoLocation, !hasBeenLoadedBefore).post(); + hasBeenLoadedBefore = true; }); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java index 8d0955bb..0cd55c30 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java @@ -166,7 +166,7 @@ public class NEUOverlay extends Gui { private final NEUManager manager; - private final String mobRegex = ".*?((_MONSTER)|(_ANIMAL)|(_MINIBOSS)|(_BOSS)|(_SC))$"; + private final String mobRegex = ".*?((_MONSTER)|(_NPC)|(_ANIMAL)|(_MINIBOSS)|(_BOSS)|(_SC))$"; private final String petRegex = ".*?;[0-5]$"; private final ResourceLocation[] sortIcons = new ResourceLocation[]{ diff --git a/src/main/java/io/github/moulberry/notenoughupdates/events/RepositoryReloadEvent.java b/src/main/java/io/github/moulberry/notenoughupdates/events/RepositoryReloadEvent.java index cc0f8c0c..b0ffc3e7 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/events/RepositoryReloadEvent.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/events/RepositoryReloadEvent.java @@ -4,9 +4,15 @@ import java.io.File; public class RepositoryReloadEvent extends NEUEvent { private final File baseFile; + private boolean isFirstLoad; - public RepositoryReloadEvent(File baseFile) { + public RepositoryReloadEvent(File baseFile, boolean isFirstLoad) { this.baseFile = baseFile; + this.isFirstLoad = isFirstLoad; + } + + public boolean isFirstLoad() { + return isFirstLoad; } public File getRepositoryRoot() { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/Navigation.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/Navigation.java index 93c2692b..4703fd0e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/Navigation.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/Navigation.java @@ -17,16 +17,23 @@ import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; public class Navigation { private List<Teleporter> teleporters = new ArrayList<>(); private Map<String, String> areaNames = new HashMap<>(); + private Map<String, JsonObject> waypoints = new HashMap<>(); + + public Map<String, JsonObject> getWaypoints() { + return waypoints; + } public static class Teleporter { public final double x, y, z; @@ -52,16 +59,21 @@ public class Navigation { private BlockPos position = null; private String island = null; private String displayName = null; + private String internalname = null; private Teleporter nextTeleporter = null; + private boolean isValidWaypoint(JsonObject object) { + return object.has("x") + && object.has("y") + && object.has("z") + && object.has("island") + && object.has("displayname") + && object.has("internalname"); + } + public void trackWaypoint(JsonObject trackNow) { - if (trackNow != null && ( - !trackNow.has("x") - || !trackNow.has("y") - || !trackNow.has("z") - || !trackNow.has("island") - || !trackNow.has("displayname"))) { + if (trackNow != null && !isValidWaypoint(trackNow)) { showError("Could not track waypoint. This is likely due to an outdated or broken repository."); return; } @@ -88,6 +100,10 @@ public class Navigation { } } this.teleporters = teleporters; + this.waypoints = NotEnoughUpdates.INSTANCE.manager + .getItemInformation().values().stream() + .filter(this::isValidWaypoint) + .collect(Collectors.toMap(it -> it.get("internalname").getAsString(), it -> it)); this.areaNames = JsonUtils.transformJsonObjectToMap(obj.getAsJsonObject("area_names"), JsonElement::getAsString); } @@ -119,18 +135,25 @@ public class Navigation { return position; } + public String getInternalname() { + return internalname; + } + private void updateData() { if (currentlyTrackedWaypoint == null) { position = null; island = null; displayName = null; nextTeleporter = null; + internalname = null; + return; } position = new BlockPos( currentlyTrackedWaypoint.get("x").getAsDouble(), currentlyTrackedWaypoint.get("y").getAsDouble(), currentlyTrackedWaypoint.get("z").getAsDouble() ); + internalname = currentlyTrackedWaypoint.get("internalname").getAsString(); island = currentlyTrackedWaypoint.get("island").getAsString(); displayName = currentlyTrackedWaypoint.get("displayname").getAsString(); recalculateNextTeleporter(SBInfo.getInstance().mode); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiNavigation.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiNavigation.java index cd71ec1a..c0ff5b93 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiNavigation.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiNavigation.java @@ -1,5 +1,7 @@ package io.github.moulberry.notenoughupdates.miscgui; +import com.google.gson.JsonObject; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.GuiElementTextField; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; @@ -9,7 +11,6 @@ import net.minecraft.util.ResourceLocation; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; @@ -38,12 +39,7 @@ public class GuiNavigation extends GuiScreen { public static final int TEXT_OFFSET_X = 28; public static final int LIST_COUNT = 6; - List<String> mockNpcs = Arrays.asList( - "hoho", - "§aOphelia (NPC)", - "§lN" - ); - List<String> result = new ArrayList<>(); + List<JsonObject> searchResults = new ArrayList<>(); public int xSize = 176; public int ySize = 222; @@ -67,10 +63,11 @@ public class GuiNavigation extends GuiScreen { refreshResults(); for (int i = 0; i < LIST_COUNT; i++) { - if (i < result.size()) { + if (i < searchResults.size()) { Minecraft.getMinecraft().getTextureManager().bindTexture(BACKGROUND); - String text = result.get(i); - boolean selected = text.equals("hoho"); + JsonObject thing = searchResults.get(i); + boolean selected = + thing.get("internalname").getAsString().equals(NotEnoughUpdates.INSTANCE.navigation.getInternalname()); int baseX = guiLeft + LIST_START_X; int baseY = guiTop + LIST_START_Y + LIST_OFFSET_Y * i; @@ -82,7 +79,7 @@ public class GuiNavigation extends GuiScreen { ICON_SIZE, ICON_SIZE ); Utils.drawStringF( - text, + thing.get("displayname").getAsString(), Minecraft.getMinecraft().fontRendererObj, baseX + TEXT_OFFSET_X, baseY + LIST_OFFSET_Y / 2F - Minecraft.getMinecraft().fontRendererObj.FONT_HEIGHT / 2F, @@ -95,10 +92,20 @@ public class GuiNavigation extends GuiScreen { private void refreshResults() { String text = textField.getText().toLowerCase(); - result = mockNpcs + searchResults = NotEnoughUpdates.INSTANCE.navigation + .getWaypoints() + .values() .stream() - .filter(it -> it.toLowerCase().contains(text.toLowerCase())) - .sorted(Comparator.comparing(String::length).thenComparing(String.CASE_INSENSITIVE_ORDER)) + .filter(it -> + it.get("internalname").getAsString().toLowerCase().contains(text) + || it.get("displayname").getAsString().toLowerCase().contains(text)) + .sorted(Comparator + .comparing( + it -> it.get("internalname").getAsString(), + Comparator.comparing(String::length) + .thenComparing(String.CASE_INSENSITIVE_ORDER) + ) + ) .collect(Collectors.toList()); } @@ -123,5 +130,22 @@ public class GuiNavigation extends GuiScreen { } else { textField.setFocus(false); } + for (int i = 0; i < LIST_COUNT; i++) { + if (i < searchResults.size()) { + int baseX = guiLeft + LIST_START_X; + int baseY = guiTop + LIST_START_Y + LIST_OFFSET_Y * i; + if (Utils.isWithinRect(mouseX, mouseY, baseX, baseY, ICON_SIZE, ICON_SIZE)) { + JsonObject thing = searchResults.get(i); + boolean selected = + thing.get("internalname").getAsString().equals(NotEnoughUpdates.INSTANCE.navigation.getInternalname()); + if (selected) { + NotEnoughUpdates.INSTANCE.navigation.untrackWaypoint(); + } else { + NotEnoughUpdates.INSTANCE.navigation.trackWaypoint(thing); + } + Utils.playPressSound(); + } + } + } } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java index 5fac9208..25e4ac82 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java @@ -1819,8 +1819,8 @@ public class Utils { } public static boolean isWithinRect(int x, int y, int left, int top, int width, int height) { - return left <= x && x <= left + width && - top <= y && y <= top + height; + return left <= x && x < left + width && + top <= y && y < top + height; } public static int getNumberOfStars(ItemStack stack) { diff --git a/src/main/resources/assets/notenoughupdates/textures/gui/navigation.png b/src/main/resources/assets/notenoughupdates/textures/gui/navigation.png Binary files differindex 0f0c162c..b8eb26e4 100644 --- a/src/main/resources/assets/notenoughupdates/textures/gui/navigation.png +++ b/src/main/resources/assets/notenoughupdates/textures/gui/navigation.png |