Jared 2 лет назад
Родитель
Сommit
02dea1b30a

+ 3 - 5
Common/src/main/java/com/blamejared/controlling/api/SortOrder.java

@@ -9,11 +9,9 @@ import java.util.List;
 public enum SortOrder {
     NONE(entries -> {
     }),
-    AZ(entries -> entries.sort(Comparator.comparing(o -> ((NewKeyBindsList.KeyEntry) o).getKeyDesc()))),
-    ZA(entries -> {
-        entries.sort((o1, o2) -> ((NewKeyBindsList.KeyEntry) o2).getKeyDesc()
-                .compareTo(((NewKeyBindsList.KeyEntry) o1).getKeyDesc()));
-    });
+    AZ(entries -> entries.sort(Comparator.comparing(o -> ((NewKeyBindsList.KeyEntry) o).getKeyDesc().getString()))),
+    ZA(entries -> entries.sort(Comparator.comparing(o -> ((NewKeyBindsList.KeyEntry) o).getKeyDesc().getString())
+            .reversed()));
     
     private final ISort sorter;
     

+ 11 - 9
Common/src/main/java/com/blamejared/controlling/client/FancyCheckbox.java

@@ -1,5 +1,6 @@
 package com.blamejared.controlling.client;
 
+import com.google.common.collect.Comparators;
 import com.mojang.blaze3d.platform.GlStateManager;
 import com.mojang.blaze3d.systems.RenderSystem;
 import com.mojang.blaze3d.vertex.PoseStack;
@@ -11,6 +12,8 @@ import net.minecraft.network.chat.Component;
 import net.minecraft.resources.ResourceLocation;
 import net.minecraft.util.Mth;
 
+import java.util.Comparator;
+
 public class FancyCheckbox extends AbstractButton {
     
     private static final ResourceLocation TEXTURE = new ResourceLocation("textures/gui/checkbox.png");
@@ -43,21 +46,20 @@ public class FancyCheckbox extends AbstractButton {
         return this.selected;
     }
     
-    public void updateNarration(NarrationElementOutput elementOutput) {
-        
-        elementOutput.add(NarratedElementType.TITLE, this.createNarrationMessage());
+    @Override
+    protected void updateWidgetNarration(NarrationElementOutput narrationElementOutput) {
+        narrationElementOutput.add(NarratedElementType.TITLE, this.createNarrationMessage());
         if(this.active) {
             if(this.isFocused()) {
-                elementOutput.add(NarratedElementType.USAGE, Component.translatable("narration.checkbox.usage.focused"));
+                narrationElementOutput.add(NarratedElementType.USAGE, Component.translatable("narration.checkbox.usage.focused"));
             } else {
-                elementOutput.add(NarratedElementType.USAGE, Component.translatable("narration.checkbox.usage.hovered"));
+                narrationElementOutput.add(NarratedElementType.USAGE, Component.translatable("narration.checkbox.usage.hovered"));
             }
         }
-        
     }
     
     public void renderButton(PoseStack stack, int mouseX, int mouseY, float partialTicks) {
-        
+    
         Minecraft mc = Minecraft.getInstance();
         RenderSystem.setShaderTexture(0, TEXTURE);
         RenderSystem.enableDepthTest();
@@ -65,9 +67,9 @@ public class FancyCheckbox extends AbstractButton {
         RenderSystem.enableBlend();
         RenderSystem.defaultBlendFunc();
         RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
-        blit(stack, this.x, this.y, this.isHoveredOrFocused() ? 11 : 0.0F, this.selected ? 11 : 0.0F, 11, this.height, (int) (64f * (11f / 20f)), (int) (64f * (11f / 20f)));
+        blit(stack, this.getX(), this.getY(), this.isHoveredOrFocused() ? 11 : 0.0F, this.selected ? 11 : 0.0F, 11, this.height, (int) (64f * (11f / 20f)), (int) (64f * (11f / 20f)));
         this.renderBg(stack, mc, mouseX, mouseY);
-        drawString(stack, mc.font, this.getMessage(), this.x + 11 + 2, this.y + (this.height - 8) / 2, TEXT_COLOR | Mth.ceil(this.alpha * 255.0F) << 24);
+        drawString(stack, mc.font, this.getMessage(), this.getX() + 11 + 2, this.getY() + (this.height - 8) / 2, TEXT_COLOR | Mth.ceil(this.alpha * 255.0F) << 24);
         
     }
     

+ 1 - 1
Common/src/main/java/com/blamejared/controlling/client/FreeKeysList.java

@@ -32,7 +32,7 @@ public class FreeKeysList extends CustomList {
         super(controls, mcIn);
         this.width = controls.width + 45;
         this.height = controls.height;
-        this.y0 = 43;
+        this.y0 = 20;
         this.y1 = controls.height - 80;
         this.x1 = controls.width + 45;
         this.controlsScreen = controls;

+ 27 - 40
Common/src/main/java/com/blamejared/controlling/client/NewKeyBindsList.java

@@ -18,17 +18,10 @@ import net.minecraft.client.gui.screens.controls.KeyBindsList;
 import net.minecraft.client.gui.screens.controls.KeyBindsScreen;
 import net.minecraft.client.resources.language.I18n;
 import net.minecraft.network.chat.Component;
-import net.minecraft.network.chat.MutableComponent;
-import net.minecraft.network.chat.contents.TranslatableContents;
 import net.minecraft.util.Mth;
 import org.apache.commons.lang3.ArrayUtils;
 
-import java.awt.*;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Objects;
-import java.util.Optional;
+import java.util.*;
 import java.util.function.UnaryOperator;
 
 public class NewKeyBindsList extends CustomList {
@@ -61,13 +54,14 @@ public class NewKeyBindsList extends CustomList {
                     addEntry(new NewKeyBindsList.CategoryEntry(category));
                 }
             }
-            
-            int width = mcIn.font.width(I18n.get(keybinding.getName()));
+    
+            Component component = Component.translatable(keybinding.getName());
+            int width = mcIn.font.width(component);
             if(width > this.maxListLabelWidth) {
                 this.maxListLabelWidth = width;
             }
             if(!category.endsWith(".hidden")) {
-                addEntry(new NewKeyBindsList.KeyEntry(keybinding));
+                addEntry(new NewKeyBindsList.KeyEntry(keybinding, component));
             }
         }
         
@@ -79,7 +73,8 @@ public class NewKeyBindsList extends CustomList {
         Entry entry = this.getEntryAtPos(mouseY);
         if(entry instanceof KeyEntry keyEntry) {
             
-            controlsScreen.renderTooltip(matrixStack, Component.translatable(keyEntry.getKeybinding().getCategory()), mouseX, mouseY);
+            controlsScreen.renderTooltip(matrixStack, Component.translatable(keyEntry.getKeybinding()
+                    .getCategory()), mouseX, mouseY);
         }
     }
     
@@ -160,35 +155,27 @@ public class NewKeyBindsList extends CustomList {
         /**
          * The localized key description for this KeyEntry
          */
-        private final String keyDesc;
+        private final Component keyDesc;
         private final Button btnChangeKeyBinding;
         private final Button btnResetKeyBinding;
         
         
-        private KeyEntry(final KeyMapping name) {
+        private KeyEntry(final KeyMapping name, final Component keyDesc) {
             
             this.keybinding = name;
-            this.keyDesc = I18n.get(name.getName());
-            this.btnChangeKeyBinding = new Button(0, 0, 75 + 20, 20, Component.literal(this.keyDesc), (btn) -> NewKeyBindsList.this.controlsScreen.selectedKey = name) {
-                
-                @Override
-                protected MutableComponent createNarrationMessage() {
-                    
-                    return name.isUnbound() ? Component.translatable("narrator.controls.unbound", NewKeyBindsList.KeyEntry.this.keyDesc) : Component.translatable("narrator.controls.bound", NewKeyBindsList.KeyEntry.this.keyDesc, super.createNarrationMessage());
-                }
-                
-            };
-            this.btnResetKeyBinding = new Button(0, 0, 50, 20, Component.translatable("controls.reset"), (btn) -> {
-                Services.PLATFORM.setToDefault(minecraft.options, name);
-                KeyMapping.resetMapping();
-            }) {
-                
-                @Override
-                protected MutableComponent createNarrationMessage() {
-                    
-                    return Component.translatable("narrator.controls.reset", NewKeyBindsList.KeyEntry.this.keyDesc);
-                }
-            };
+            this.keyDesc = keyDesc;
+            this.btnChangeKeyBinding = Button.builder(this.keyDesc, (btn) -> NewKeyBindsList.this.controlsScreen.selectedKey = name)
+                    .bounds(0, 0, 75, 20)
+                    .createNarration(supp -> name.isUnbound() ? Component.translatable("narrator.controls.unbound", keyDesc) : Component.translatable("narrator.controls.bound", keyDesc, supp.get()))
+                    .build();
+            
+            this.btnResetKeyBinding = Button.builder(Component.translatable("controls.reset"), btn -> {
+                        Services.PLATFORM.setToDefault(minecraft.options, name);
+                        KeyMapping.resetMapping();
+                    }).bounds(0, 0, 50, 20)
+                    .createNarration(supp -> Component.translatable("narrator.controls.reset", keyDesc))
+                    .build();
+            
         }
         
         @Override
@@ -198,14 +185,14 @@ public class NewKeyBindsList extends CustomList {
             boolean flag = NewKeyBindsList.this.controlsScreen.selectedKey == this.keybinding;
             int length = Math.max(0, x + 90 - NewKeyBindsList.this.maxListLabelWidth);
             NewKeyBindsList.this.mc.font.draw(stack, this.keyDesc, (float) (length), (float) (y + rowWidth / 2 - 9 / 2), 16777215);
-            this.btnResetKeyBinding.x = x + 190 + 20;
-            this.btnResetKeyBinding.y = y;
+            this.btnResetKeyBinding.setX(x + 190 + 20);
+            this.btnResetKeyBinding.setY(y);
             this.btnResetKeyBinding.active = !this.keybinding.isDefault();
             this.btnResetKeyBinding.render(stack, mouseX, mouseY, partialTicks);
             
             
-            this.btnChangeKeyBinding.x = x + 105;
-            this.btnChangeKeyBinding.y = y;
+            this.btnChangeKeyBinding.setX(x + 105);
+            this.btnChangeKeyBinding.setY(y);
             this.btnChangeKeyBinding.setMessage(this.keybinding.getTranslatedKeyMessage());
             
             boolean flag1 = false;
@@ -279,7 +266,7 @@ public class NewKeyBindsList extends CustomList {
             return keybinding;
         }
         
-        public String getKeyDesc() {
+        public Component getKeyDesc() {
             
             return keyDesc;
         }

+ 20 - 17
Common/src/main/java/com/blamejared/controlling/client/NewKeyBindsScreen.java

@@ -15,7 +15,7 @@ import net.minecraft.client.Minecraft;
 import net.minecraft.client.Options;
 import net.minecraft.client.gui.components.Button;
 import net.minecraft.client.gui.components.EditBox;
-import net.minecraft.client.gui.components.Widget;
+import net.minecraft.client.gui.components.Renderable;
 import net.minecraft.client.gui.components.events.GuiEventListener;
 import net.minecraft.client.gui.screens.Screen;
 import net.minecraft.client.gui.screens.controls.KeyBindsList;
@@ -23,7 +23,6 @@ import net.minecraft.client.gui.screens.controls.KeyBindsScreen;
 import net.minecraft.network.chat.Component;
 import org.lwjgl.glfw.GLFW;
 
-import java.awt.*;
 import java.util.LinkedHashSet;
 import java.util.Objects;
 import java.util.Set;
@@ -68,10 +67,10 @@ public class NewKeyBindsScreen extends KeyBindsScreen {
         this.setKeyBindsList(this.customKeyList);
         this.addWidget(getKeyBindsList());
         this.setFocused(getKeyBindsList());
-        this.addRenderableWidget(new Button(this.width / 2 - 155 + 160, this.height - 29, 150, 20, Component.translatable("gui.done"), (btn) -> Objects.requireNonNull(this.minecraft)
-                .setScreen(this.lastScreen)));
+        this.addRenderableWidget(Button.builder(Component.translatable("gui.done"), (btn) -> Objects.requireNonNull(this.minecraft)
+                .setScreen(this.lastScreen)).bounds(this.width / 2 - 155 + 160, this.height - 29, 150, 20).build());
         
-        this.buttonReset = this.addRenderableWidget(new Button(this.width / 2 - 155, this.height - 29, 74, 20, Component.translatable("controls.resetAll"), (btn) -> {
+        this.buttonReset = this.addRenderableWidget(Button.builder(Component.translatable("controls.resetAll"), btn -> {
             
             if(!confirmingReset) {
                 confirmingReset = true;
@@ -86,8 +85,8 @@ public class NewKeyBindsScreen extends KeyBindsScreen {
             }
             
             KeyMapping.releaseAll();
-        }));
-        this.buttonNone = this.addRenderableWidget(new Button(this.width / 2 - 155 + 160 + 76, this.height - 29 - 24, 150 / 2, 20, Component.translatable("options.showNone"), (btn) -> {
+        }).bounds(this.width / 2 - 155, this.height - 29, 74, 20).build());
+        this.buttonNone = this.addRenderableWidget(Button.builder(Component.translatable("options.showNone"), (btn) -> {
             if(displayMode == DisplayMode.NONE) {
                 buttonNone.setMessage(Component.translatable("options.showNone"));
                 displayMode = DisplayMode.ALL;
@@ -97,8 +96,8 @@ public class NewKeyBindsScreen extends KeyBindsScreen {
                 buttonConflicting.setMessage(Component.translatable("options.showConflicts"));
             }
             filterKeys();
-        }));
-        this.buttonConflicting = this.addRenderableWidget(new Button(this.width / 2 - 155 + 160, this.height - 29 - 24, 150 / 2, 20, Component.translatable("options.showConflicts"), (btn) -> {
+        }).bounds(this.width / 2 - 155 + 160 + 76, this.height - 29 - 24, 150 / 2, 20).build());
+        this.buttonConflicting = this.addRenderableWidget(Button.builder(Component.translatable("options.showConflicts"), (btn) -> {
             if(displayMode == DisplayMode.CONFLICTING) {
                 buttonConflicting.setMessage(Component.translatable("options.showConflicts"));
                 displayMode = DisplayMode.ALL;
@@ -108,7 +107,7 @@ public class NewKeyBindsScreen extends KeyBindsScreen {
                 buttonNone.setMessage(Component.translatable("options.showNone"));
             }
             filterKeys();
-        }));
+        }).bounds(this.width / 2 - 155 + 160, this.height - 29 - 24, 150 / 2, 20).build());
         search = new EditBox(font, this.width / 2 - 154, this.height - 29 - 23, 148, 18, Component.empty());
         addWidget(search);
         this.buttonKey = this.addRenderableWidget(new FancyCheckbox(this.width / 2 - (155 / 2), this.height - 29 - 37, 11, 11, Component.translatable("options.key"), false, btn -> {
@@ -122,13 +121,14 @@ public class NewKeyBindsScreen extends KeyBindsScreen {
             filterKeys();
         }));
         sortOrder = SortOrder.NONE;
-        Button buttonSort = this.addRenderableWidget(new Button(this.width / 2 - 155 + 160 + 76, this.height - 29 - 24 - 24, 150 / 2, 20, Component.translatable("options.sort").append(": " + sortOrder.getName()), (btn) -> {
+        Button buttonSort = this.addRenderableWidget(Button.builder(Component.translatable("options.sort")
+                .append(": " + sortOrder.getName()), (btn) -> {
             sortOrder = sortOrder.cycle();
             btn.setMessage(Component.translatable("options.sort").append(": " + sortOrder.getName()));
             filterKeys();
-        }));
+        }).bounds(this.width / 2 - 155 + 160 + 76, this.height - 29 - 24 - 24, 150 / 2, 20).build());
         
-        this.addRenderableWidget(new Button(this.width / 2 - 155 + 76, this.height - 29, 74, 20, Component.translatable("options.toggleFree"), (btn) -> {
+        this.addRenderableWidget(Button.builder(Component.translatable("options.toggleFree"), (btn) -> {
             this.removeWidget(getKeyBindsList());
             if(showFree) {
                 buttonSort.active = true;
@@ -151,7 +151,7 @@ public class NewKeyBindsScreen extends KeyBindsScreen {
             this.addWidget(getKeyBindsList());
             this.setFocused(getKeyBindsList());
             showFree = !showFree;
-        }));
+        }).bounds(this.width / 2 - 155 + 76, this.height - 29, 74, 20).build());
         
         lastSearch = "";
         displayMode = DisplayMode.ALL;
@@ -186,7 +186,10 @@ public class NewKeyBindsScreen extends KeyBindsScreen {
             getKeyBindsList().setScrollAmount(0);
             Predicate<NewKeyBindsList.KeyEntry> filters = switch(searchType) {
                 case NAME -> displayMode.getPredicate()
-                        .and(keyEntry -> keyEntry.getKeyDesc().toLowerCase().contains(lastSearch.toLowerCase()));
+                        .and(keyEntry -> keyEntry.getKeyDesc()
+                                .getString()
+                                .toLowerCase()
+                                .contains(lastSearch.toLowerCase()));
                 case CATEGORY -> displayMode.getPredicate()
                         .and(keyEntry -> Component.translatable(keyEntry.getKeybinding().getCategory()).getString()
                                 .toLowerCase()
@@ -287,8 +290,8 @@ public class NewKeyBindsScreen extends KeyBindsScreen {
         Component text = Component.translatable("options.search");
         font.draw(stack, text, this.width / 2f - (155 / 2f) - (font.width(text.getString())) - 5, this.height - 29 - 42, 16777215);
         
-        for(Widget widget : getScreenAccess().controlling$getRenderables()) {
-            widget.render(stack, mouseX, mouseY, partialTicks);
+        for(Renderable renderable : getScreenAccess().controlling$getRenderables()) {
+            renderable.render(stack, mouseX, mouseY, partialTicks);
         }
     }
     

+ 2 - 2
Common/src/main/java/com/blamejared/controlling/mixin/AccessScreen.java

@@ -1,6 +1,6 @@
 package com.blamejared.controlling.mixin;
 
-import net.minecraft.client.gui.components.Widget;
+import net.minecraft.client.gui.components.Renderable;
 import net.minecraft.client.gui.screens.Screen;
 import org.spongepowered.asm.mixin.Mixin;
 import org.spongepowered.asm.mixin.gen.Accessor;
@@ -11,6 +11,6 @@ import java.util.List;
 public interface AccessScreen {
     
     @Accessor("renderables")
-    List<Widget> controlling$getRenderables();
+    List<Renderable> controlling$getRenderables();
     
 }

+ 1 - 1
Fabric/build.gradle.kts

@@ -4,7 +4,7 @@ import net.darkhax.curseforgegradle.Constants as CFG_Constants
 
 plugins {
     `maven-publish`
-    id("fabric-loom") version "0.12-SNAPSHOT"
+    id("fabric-loom") version "1.0-SNAPSHOT"
     id("com.blamejared.modtemplate")
     id("net.darkhax.curseforgegradle") version ("1.0.8")
 }

+ 4 - 4
gradle.properties

@@ -3,12 +3,12 @@ modVersion=10.0
 group=com.blamejared.controlling
 modJavaVersion=17
 # Common
-minecraftVersion=1.19.2
+minecraftVersion=1.19.3
 # Forge
-forgeVersion=43.1.2
+forgeVersion=44.0.4
 # Fabric
-fabricVersion=0.60.0+1.19.2
-fabricLoaderVersion=0.14.9
+fabricVersion=0.68.1+1.19.3
+fabricLoaderVersion=0.14.11
 # Mod options
 modName=Controlling
 modAuthor=Jared