diff options
Diffstat (limited to 'src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java')
| -rw-r--r-- | src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java | 57 |
1 files changed, 32 insertions, 25 deletions
diff --git a/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java index 9d04b9168..7b70cfb93 100644 --- a/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java @@ -9,26 +9,23 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.mojang.blaze3d.platform.GlStateManager; import com.zeitheron.hammercore.client.utils.Scissors; +import me.shedaniel.cloth.api.ClientUtils; import me.shedaniel.rei.api.*; import me.shedaniel.rei.client.ScreenHelper; import me.shedaniel.rei.gui.renderables.RecipeRenderer; import me.shedaniel.rei.gui.widget.*; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.audio.PositionedSoundInstance; import net.minecraft.client.gui.Element; import net.minecraft.client.gui.Screen; import net.minecraft.client.render.GuiLighting; import net.minecraft.client.resource.language.I18n; +import net.minecraft.client.sound.PositionedSoundInstance; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.sound.SoundEvents; -import net.minecraft.text.StringTextComponent; -import net.minecraft.text.TranslatableTextComponent; import net.minecraft.util.math.MathHelper; -import org.lwjgl.BufferUtils; -import org.lwjgl.glfw.GLFW; -import org.lwjgl.opengl.GL11; import java.awt.*; -import java.nio.IntBuffer; import java.util.List; import java.util.Map; import java.util.Optional; @@ -51,7 +48,7 @@ public class VillagerRecipeViewingScreen extends Screen { private int tabsPage; public VillagerRecipeViewingScreen(Map<RecipeCategory, List<RecipeDisplay>> map) { - super(new StringTextComponent("")); + super(new TextComponent("")); this.widgets = Lists.newArrayList(); this.categoryMap = Maps.newLinkedHashMap(); this.selectedCategoryIndex = 0; @@ -140,7 +137,7 @@ public class VillagerRecipeViewingScreen extends Screen { } } ButtonWidget w, w2; - this.widgets.add(w = new ButtonWidget(bounds.x + 2, bounds.y - 16, 10, 10, new TranslatableTextComponent("text.rei.left_arrow")) { + this.widgets.add(w = new ButtonWidget(bounds.x + 2, bounds.y - 16, 10, 10, new TranslatableComponent("text.rei.left_arrow")) { @Override public void onPressed() { tabsPage--; @@ -149,7 +146,7 @@ public class VillagerRecipeViewingScreen extends Screen { VillagerRecipeViewingScreen.this.init(); } }); - this.widgets.add(w2 = new ButtonWidget(bounds.x + bounds.width - 12, bounds.y - 16, 10, 10, new TranslatableTextComponent("text.rei.right_arrow")) { + this.widgets.add(w2 = new ButtonWidget(bounds.x + bounds.width - 12, bounds.y - 16, 10, 10, new TranslatableComponent("text.rei.right_arrow")) { @Override public void onPressed() { tabsPage++; @@ -206,6 +203,23 @@ public class VillagerRecipeViewingScreen extends Screen { scroll = MathHelper.clamp(scroll, 0, height - scrollListBounds.height + 2); return true; } + for(Element listener : children()) + if (listener.mouseScrolled(double_1, double_2, double_3)) + return true; + if (bounds.contains(ClientUtils.getMouseLocation())) { + if (double_3 < 0 && categoryMap.get(categories.get(selectedCategoryIndex)).size() > 1) { + selectedRecipeIndex++; + if (selectedRecipeIndex >= categoryMap.get(categories.get(selectedCategoryIndex)).size()) + selectedRecipeIndex = 0; + init(); + } else if (categoryMap.get(categories.get(selectedCategoryIndex)).size() > 1) { + selectedRecipeIndex--; + if (selectedRecipeIndex < 0) + selectedRecipeIndex = categoryMap.get(categories.get(selectedCategoryIndex)).size() - 1; + init(); + return true; + } + } return super.mouseScrolled(double_1, double_2, double_3); } @@ -219,7 +233,7 @@ public class VillagerRecipeViewingScreen extends Screen { }); GuiLighting.disable(); ScreenHelper.getLastOverlay().render(mouseX, mouseY, delta); - GL11.glPushMatrix(); + GlStateManager.pushMatrix(); Scissors.begin(); Scissors.scissor(0, scrollListBounds.y + 1, width, scrollListBounds.height - 2); for(int i = 0; i < buttonWidgets.size(); i++) { @@ -239,17 +253,10 @@ public class VillagerRecipeViewingScreen extends Screen { } } Scissors.end(); - GL11.glPopMatrix(); + GlStateManager.popMatrix(); ScreenHelper.getLastOverlay().lateRender(mouseX, mouseY, delta); } - private int getTitleBarHeight() { - IntBuffer useless = BufferUtils.createIntBuffer(3), top = BufferUtils.createIntBuffer(1); - GLFW.glfwGetWindowFrameSize(minecraft.window.getHandle(), useless, top, useless, useless); - System.out.println(top.get(0)); - return top.get(0) / 3 * 2; - } - private int getReal(int i) { return (int) (i / ((double) minecraft.window.getScaledWidth() / (double) minecraft.window.getWidth())); } @@ -269,18 +276,18 @@ public class VillagerRecipeViewingScreen extends Screen { } if (ClientHelper.getInstance().getNextPageKeyBinding().matchesKey(int_1, int_2)) { if (categoryMap.get(categories.get(selectedCategoryIndex)).size() > 1) { - selectedCategoryIndex++; - if (selectedCategoryIndex >= categoryMap.get(categories.get(selectedCategoryIndex)).size()) - selectedCategoryIndex = 0; + selectedRecipeIndex ++; + if (selectedRecipeIndex >= categoryMap.get(categories.get(selectedCategoryIndex)).size()) + selectedRecipeIndex = 0; init(); return true; } return false; } else if (ClientHelper.getInstance().getPreviousPageKeyBinding().matchesKey(int_1, int_2)) { if (categoryMap.get(categories.get(selectedCategoryIndex)).size() > 1) { - selectedCategoryIndex--; - if (selectedCategoryIndex < 0) - selectedCategoryIndex = categoryMap.get(categories.get(selectedCategoryIndex)).size() - 1; + selectedRecipeIndex--; + if (selectedRecipeIndex < 0) + selectedRecipeIndex = categoryMap.get(categories.get(selectedCategoryIndex)).size() - 1; init(); return true; } |
