]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/blobdiff - src/main/java/com/irtimaled/bbor/client/gui/WorldSaveRow.java
Fully support keyboard nav in gui
[BoundingBoxOutlineReloaded.git] / src / main / java / com / irtimaled / bbor / client / gui / WorldSaveRow.java
index 5dde418443244ec29f0d0deccbb9a0a2cb1969b9..f0268e454def8a68851853e31d00aa1f4e6cf5bf 100644 (file)
@@ -21,6 +21,7 @@ import java.io.InputStream;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.function.Consumer;
 
 public class WorldSaveRow extends ControlListEntry implements Comparable<WorldSaveRow> {
     private static final Logger LOGGER = LogManager.getLogger();
@@ -30,15 +31,17 @@ public class WorldSaveRow extends ControlListEntry implements Comparable<WorldSa
     private final Minecraft client;
     private final WorldSummary worldSummary;
     private final SaveFormat saveLoader;
+    private final Consumer<ControlListEntry> setSelectedEntry;
     private final ResourceLocation iconLocation;
     private final DynamicTexture icon;
 
     private File iconFile;
     private long lastClickTime;
 
-    WorldSaveRow(WorldSummary worldSummary, SaveFormat saveLoader) {
+    WorldSaveRow(WorldSummary worldSummary, SaveFormat saveLoader, Consumer<ControlListEntry> setSelectedEntry) {
         this.worldSummary = worldSummary;
         this.saveLoader = saveLoader;
+        this.setSelectedEntry = setSelectedEntry;
         this.client = Minecraft.getInstance();
         this.iconLocation = new ResourceLocation("worlds/" + Hashing.sha1().hashUnencodedChars(worldSummary.getFileName()) + "/icon");
         this.iconFile = saveLoader.getFile(worldSummary.getFileName(), "icon.png");
@@ -49,24 +52,29 @@ public class WorldSaveRow extends ControlListEntry implements Comparable<WorldSa
         this.icon = this.loadIcon();
     }
 
+    @Override
+    public boolean isMouseOver(double mouseX, double mouseY) {
+        return mouseX > this.getX() &&
+                mouseX < this.getX() + ControlList.CONTROLS_WIDTH &&
+                mouseY > this.getY() &&
+                mouseY < this.getY() + this.getControlHeight();
+    }
+
     @Override
     public boolean mouseClicked(double mouseX, double mouseY, int button) {
-        this.list.setSelectedIndex(this.index);
+        if (!isMouseOver(mouseX, mouseY)) return false;
+
+        this.setSelectedEntry.accept(this);
         if (Util.milliTime() - this.lastClickTime < 250L) {
-            loadWorld();
-            return true;
+            done();
         } else {
             this.lastClickTime = Util.milliTime();
-            return false;
         }
+        return true;
     }
 
     @Override
-    public boolean mouseReleased(double mouseX, double mouseY, int button) {
-        return false;
-    }
-
-    void loadWorld() {
+    public void done() {
         String fileName = this.worldSummary.getFileName();
         WorldInfo worldInfo = saveLoader.getWorldInfo(fileName);
         long seed = worldInfo.getSeed();
@@ -105,14 +113,9 @@ public class WorldSaveRow extends ControlListEntry implements Comparable<WorldSa
         GL11.glDisable(GL11.GL_BLEND);
     }
 
-    @Override
-    public int getControlWidth() {
-        return 310;
-    }
-
     @Override
     public void filter(String lowerValue) {
-        setVisible(lowerValue == "" ||
+        super.setVisible(lowerValue.isEmpty() ||
                 this.worldSummary.getDisplayName().toLowerCase().contains(lowerValue) ||
                 this.worldSummary.getFileName().toLowerCase().contains(lowerValue));
     }