diff options
| author | Roman / Nea <roman.graef@gmail.com> | 2022-05-06 16:13:36 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-06 16:13:36 +0200 |
| commit | 1ca41f88d7729d9279df71cd186ff86f22e7d515 (patch) | |
| tree | 1809b7d4719c9e91d441be6fcffded012d03f3d1 /src/main/java/io/github/moulberry/notenoughupdates/miscgui | |
| parent | ead065aa1303acc3f6834bcfceb77242702b5622 (diff) | |
| download | notenoughupdates-1ca41f88d7729d9279df71cd186ff86f22e7d515.tar.gz notenoughupdates-1ca41f88d7729d9279df71cd186ff86f22e7d515.tar.bz2 notenoughupdates-1ca41f88d7729d9279df71cd186ff86f22e7d515.zip | |
Item Shop Recipes (#118)
* first draft of item shop PR
* add teleporter navigation because i can
* fix teleporter navigation because apparently i cant
* navigation gui basics
* :pushpin: and removed some unused shit and added myself to devtest command
* track / untrack + ery texture
Co-Authored-By: RayDeeUx <51521765+RayDeeUx@users.noreply.github.com>
* consoom the event
* fix crash in ItemShopRecipe.java + fetch repository
* i am so sorry jani
* on second thought, this entire thing was a bit untested
* more recipe stuff
* make navigation actually good
* make pins dissapear if you not a waypoint
* npc parsing
* save file
* different file saving
* remove message
* Warping... (to deez nuts)
* move shit around
Co-authored-by: jani270 <jani270@gmx.de>
Co-authored-by: RayDeeUx <51521765+RayDeeUx@users.noreply.github.com>
Co-authored-by: Lulonaut <lulonaut@tutanota.de>
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/miscgui')
| -rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java | 44 | ||||
| -rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiNavigation.java | 154 |
2 files changed, 188 insertions, 10 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java index be9ce6c7..129e25e7 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java @@ -8,6 +8,7 @@ import io.github.moulberry.notenoughupdates.recipes.RecipeType; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; @@ -22,8 +23,11 @@ import org.lwjgl.opengl.GL11; import java.awt.*; import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; import java.util.List; -import java.util.*; +import java.util.Map; public class GuiItemRecipe extends GuiScreen { public static final ResourceLocation resourcePacksTexture = new ResourceLocation("textures/gui/resource_packs.png"); @@ -68,6 +72,13 @@ public class GuiItemRecipe extends GuiScreen { } } + @Override + public void initGui() { + this.guiLeft = (width - this.xSize) / 2; + this.guiTop = (height - this.ySize) / 2; + changeRecipe(0, 0); + } + public NeuRecipe getCurrentRecipe() { List<NeuRecipe> currentRecipes = getCurrentRecipeList(); currentIndex = MathHelper.clamp_int(currentIndex, 0, currentRecipes.size() - 1); @@ -84,8 +95,8 @@ public class GuiItemRecipe extends GuiScreen { } public boolean isWithinRect(int x, int y, int topLeftX, int topLeftY, int width, int height) { - return topLeftX <= x && x <= topLeftX + width - && topLeftY <= y && y <= topLeftY + height; + return topLeftX <= x && x < topLeftX + width + && topLeftY <= y && y < topLeftY + height; } private ImmutableList<RecipeSlot> getAllRenderedSlots() { @@ -99,9 +110,6 @@ public class GuiItemRecipe extends GuiScreen { drawDefaultBackground(); FontRenderer fontRendererObj = Minecraft.getMinecraft().fontRendererObj; - this.guiLeft = (width - this.xSize) / 2; - this.guiTop = (height - this.ySize) / 2; - GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); NeuRecipe currentRecipe = getCurrentRecipe(); @@ -131,7 +139,7 @@ public class GuiItemRecipe extends GuiScreen { ); currentRecipe.drawExtraInfo(this, mouseX, mouseY); - + super.drawScreen(mouseX, mouseY, partialTicks); for (RecipeSlot slot : slots) { if (isWithinRect(mouseX, mouseY, slot.getX(this), slot.getY(this), SLOT_SIZE, SLOT_SIZE)) { if (slot.getItemStack() == null) continue; @@ -292,6 +300,18 @@ public class GuiItemRecipe extends GuiScreen { } } + public void changeRecipe(int tabIndex, int recipeIndex) { + buttonList.removeAll(getCurrentRecipe().getExtraButtons(this)); + currentTab = tabIndex; + currentIndex = recipeIndex; + buttonList.addAll(getCurrentRecipe().getExtraButtons(this)); + } + + @Override + protected void actionPerformed(GuiButton p_actionPerformed_1_) throws IOException { + getCurrentRecipe().actionPerformed(p_actionPerformed_1_); + } + @Override protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { super.mouseClicked(mouseX, mouseY, mouseButton); @@ -310,7 +330,7 @@ public class GuiItemRecipe extends GuiScreen { BUTTON_HEIGHT ) && currentIndex > 0) { - currentIndex = currentIndex - 1; + changeRecipe(currentTab, currentIndex - 1); Utils.playPressSound(); return; } @@ -324,7 +344,7 @@ public class GuiItemRecipe extends GuiScreen { BUTTON_HEIGHT ) && currentIndex < getCurrentRecipeList().size()) { - currentIndex = currentIndex + 1; + changeRecipe(currentTab, currentIndex + 1); Utils.playPressSound(); return; } @@ -338,7 +358,7 @@ public class GuiItemRecipe extends GuiScreen { TAB_SIZE_X, TAB_SIZE_Y )) { - currentTab = i; + changeRecipe(i, currentIndex); Utils.playPressSound(); return; } @@ -349,10 +369,14 @@ public class GuiItemRecipe extends GuiScreen { ItemStack itemStack = slot.getItemStack(); if (mouseButton == 0) { manager.displayGuiItemRecipe(manager.getInternalNameForItem(itemStack)); + return; } else if (mouseButton == 1) { manager.displayGuiItemUsages(manager.getInternalNameForItem(itemStack)); + return; } } } + + currentRecipe.mouseClicked(this, mouseX, mouseY, mouseButton); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiNavigation.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiNavigation.java new file mode 100644 index 00000000..d34988f6 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiNavigation.java @@ -0,0 +1,154 @@ +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; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.util.ResourceLocation; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + +public class GuiNavigation extends GuiScreen { + + public static ResourceLocation BACKGROUND = new ResourceLocation( + "notenoughupdates", + "textures/gui/navigation.png" + ); + + public static final int PIN_POSITION_U = 182; + public static final int PIN_POSITION_V = 3; + public static final int TICK_POSITION_U = 182; + public static final int TICK_POSITION_V = 34; + public static final int ICON_SIZE = 26; + + public static final int SEARCH_BAR_X = 14; + public static final int SEARCH_BAR_Y = 11; + public static final int SEARCH_BAR_WIDTH = 151; + public static final int SEARCH_BAR_HEIGHT = 24; + + public static final int LIST_START_X = 14; + public static final int LIST_START_Y = 43; + public static final int LIST_OFFSET_Y = 28; + public static final int TEXT_OFFSET_X = 28; + public static final int LIST_COUNT = 6; + + List<String> searchResults = new ArrayList<>(); + + public int xSize = 176; + public int ySize = 222; + public int guiLeft, guiTop; + + public GuiElementTextField textField = new GuiElementTextField("", SEARCH_BAR_WIDTH, SEARCH_BAR_HEIGHT, 0); + + @Override + public void initGui() { + super.initGui(); + NotEnoughUpdates.INSTANCE.config.hidden.hasOpenedWaypointMenu = true; + guiLeft = (width - xSize) / 2; + guiTop = (height - ySize) / 2; + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + drawDefaultBackground(); + Minecraft.getMinecraft().getTextureManager().bindTexture(BACKGROUND); + this.drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize); + textField.render(guiLeft + SEARCH_BAR_X, guiTop + SEARCH_BAR_Y); + + refreshResults(); + for (int i = 0; i < LIST_COUNT; i++) { + if (i < searchResults.size()) { + Minecraft.getMinecraft().getTextureManager().bindTexture(BACKGROUND); + String name = searchResults.get(i); + JsonObject json = NotEnoughUpdates.INSTANCE.navigation.getWaypoints().get(name); + boolean selected = name.equals(NotEnoughUpdates.INSTANCE.navigation.getInternalname()); + int baseX = guiLeft + LIST_START_X; + int baseY = guiTop + LIST_START_Y + LIST_OFFSET_Y * i; + + GlStateManager.color(1F, 1F, 1F); + drawTexturedModalRect( + baseX, + baseY, + selected ? TICK_POSITION_U : PIN_POSITION_U, selected ? TICK_POSITION_V : PIN_POSITION_V, + ICON_SIZE, ICON_SIZE + ); + Utils.drawStringF( + json.get("displayname").getAsString(), + Minecraft.getMinecraft().fontRendererObj, + baseX + TEXT_OFFSET_X, + baseY + LIST_OFFSET_Y / 2F - Minecraft.getMinecraft().fontRendererObj.FONT_HEIGHT / 2F, + false, + 0x000000 + ); + } + } + } + + private void refreshResults() { + String text = textField.getText().toLowerCase(); + List<String> results = NotEnoughUpdates.INSTANCE.navigation + .getWaypoints() + .values() + .stream() + .filter(it -> + it.get("internalname").getAsString().toLowerCase().contains(text) + || it.get("displayname").getAsString().toLowerCase().contains(text)) + .map(it -> it.get("internalname").getAsString()) + .sorted(Comparator.comparing(String::length) + .thenComparing(String.CASE_INSENSITIVE_ORDER)) + .collect(Collectors.toList()); + + String internalname = NotEnoughUpdates.INSTANCE.navigation.getInternalname(); + if (internalname != null) { + results.remove(internalname); + results.add(0, internalname); + } + searchResults = results; + } + + @Override + protected void keyTyped(char p_keyTyped_1_, int p_keyTyped_2_) throws IOException { + super.keyTyped(p_keyTyped_1_, p_keyTyped_2_); + textField.keyTyped(p_keyTyped_1_, p_keyTyped_2_); + } + + @Override + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { + super.mouseClicked(mouseX, mouseY, mouseButton); + if (Utils.isWithinRect( + mouseX, + mouseY, + guiLeft + SEARCH_BAR_X, + guiTop + SEARCH_BAR_Y, + SEARCH_BAR_WIDTH, + SEARCH_BAR_HEIGHT + )) { + textField.mouseClicked(mouseX, mouseY, mouseButton); + } 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)) { + String thing = searchResults.get(i); + boolean selected = thing.equals(NotEnoughUpdates.INSTANCE.navigation.getInternalname()); + if (selected) { + NotEnoughUpdates.INSTANCE.navigation.untrackWaypoint(); + } else { + NotEnoughUpdates.INSTANCE.navigation.trackWaypoint(thing); + } + Utils.playPressSound(); + } + } + } + } +} |
