Selaa lähdekoodia

Code cleanup, made key category show where the mouse is

Jared 7 vuotta sitten
vanhempi
sitoutus
dc05b4453a

+ 21 - 27
src/main/java/us/getfluxed/controlsearch/client/gui/GuiNewControls.java

@@ -141,26 +141,32 @@ public class GuiNewControls extends GuiControls {
         return none;
     }
     
+    public void sort(LinkedList<GuiListExtended.IGuiListEntry> list, EnumSortingType type) {
+        if(sortingType != EnumSortingType.DEFAULT)
+            list.sort((o1, o2) -> {
+                if(o1 instanceof GuiNewKeyBindingList.KeyEntry && o2 instanceof GuiNewKeyBindingList.KeyEntry) {
+                    GuiNewKeyBindingList.KeyEntry ent1 = (GuiNewKeyBindingList.KeyEntry) o1;
+                    GuiNewKeyBindingList.KeyEntry ent2 = (GuiNewKeyBindingList.KeyEntry) o2;
+                    if(type == EnumSortingType.AZ) {
+                        return translate(ent1.getKeybinding().getKeyDescription()).compareTo(I18n.format(ent2.getKeybinding().getKeyDescription()));
+                    } else if(type == EnumSortingType.ZA) {
+                        return translate(ent2.getKeybinding().getKeyDescription()).compareTo(I18n.format(ent1.getKeybinding().getKeyDescription()));
+                    }
+                    
+                }
+                return -1;
+            });
+    }
+    
+    
     public LinkedList<GuiListExtended.IGuiListEntry> sortKeys(LinkedList<GuiListExtended.IGuiListEntry> list, EnumSortingType type) {
         if(type == EnumSortingType.DEFAULT) {
             return list;
         }
         LinkedList<GuiListExtended.IGuiListEntry> sorted = new LinkedList<>();
         sorted.addAll(list);
+        sort(list, type);
         
-        sorted.sort((o1, o2) -> {
-            if(o1 instanceof GuiNewKeyBindingList.KeyEntry && o2 instanceof GuiNewKeyBindingList.KeyEntry) {
-                GuiNewKeyBindingList.KeyEntry ent1 = (GuiNewKeyBindingList.KeyEntry) o1;
-                GuiNewKeyBindingList.KeyEntry ent2 = (GuiNewKeyBindingList.KeyEntry) o2;
-                if(type == EnumSortingType.AZ) {
-                    return translate(ent1.getKeybinding().getKeyDescription()).compareTo(I18n.format(ent2.getKeybinding().getKeyDescription()));
-                } else if(type == EnumSortingType.ZA) {
-                    return translate(ent2.getKeybinding().getKeyDescription()).compareTo(I18n.format(ent1.getKeybinding().getKeyDescription()));
-                }
-                
-            }
-            return -1;
-        });
         return sorted;
     }
     
@@ -237,20 +243,8 @@ public class GuiNewControls extends GuiControls {
                     sorted.add(entry);
                 }
             }
-            if(sortingType != EnumSortingType.DEFAULT)
-                sorted.sort((o1, o2) -> {
-                    if(o1 instanceof GuiNewKeyBindingList.KeyEntry && o2 instanceof GuiNewKeyBindingList.KeyEntry) {
-                        GuiNewKeyBindingList.KeyEntry ent1 = (GuiNewKeyBindingList.KeyEntry) o1;
-                        GuiNewKeyBindingList.KeyEntry ent2 = (GuiNewKeyBindingList.KeyEntry) o2;
-                        if(sortingType == EnumSortingType.AZ) {
-                            return translate(ent1.getKeybinding().getKeyDescription()).compareTo(I18n.format(ent2.getKeybinding().getKeyDescription()));
-                        } else if(sortingType == EnumSortingType.ZA) {
-                            return translate(ent2.getKeybinding().getKeyDescription()).compareTo(I18n.format(ent1.getKeybinding().getKeyDescription()));
-                        }
-                        
-                    }
-                    return -1;
-                });
+            
+            sort(list, sortingType);
             
             ((GuiNewKeyBindingList) keyBindingList).setListEntries(sorted);
             

+ 12 - 10
src/main/java/us/getfluxed/controlsearch/client/gui/GuiNewKeyBindingList.java

@@ -49,7 +49,7 @@ public class GuiNewKeyBindingList extends GuiKeyBindingList {
                 //                this.listEntries[i++] = new GuiNewKeyBindingList.CategoryEntry(s1);
             }
             
-            int j = mcIn.fontRendererObj.getStringWidth(I18n.format(keybinding.getKeyDescription(), new Object[0]));
+            int j = mcIn.fontRendererObj.getStringWidth(I18n.format(keybinding.getKeyDescription()));
             
             if(j > this.maxListLabelWidth) {
                 this.maxListLabelWidth = j;
@@ -135,9 +135,9 @@ public class GuiNewKeyBindingList extends GuiKeyBindingList {
         
         private KeyEntry(KeyBinding name) {
             this.keybinding = name;
-            this.keyDesc = I18n.format(name.getKeyDescription(), new Object[0]);
-            this.btnChangeKeyBinding = new GuiButton(0, 0, 0, 95, 20, I18n.format(name.getKeyDescription(), new Object[0]));
-            this.btnReset = new GuiButton(0, 0, 0, 50, 20, I18n.format("controls.reset", new Object[0]));
+            this.keyDesc = I18n.format(name.getKeyDescription());
+            this.btnChangeKeyBinding = new GuiButton(0, 0, 0, 95, 20, I18n.format(name.getKeyDescription()));
+            this.btnReset = new GuiButton(0, 0, 0, 50, 20, I18n.format("controls.reset"));
         }
         
         @Override
@@ -148,12 +148,8 @@ public class GuiNewKeyBindingList extends GuiKeyBindingList {
         public void func_192634_a(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected, float p_192634_9_) {
             boolean flag = GuiNewKeyBindingList.this.controlsScreen.buttonId == this.keybinding;
             GuiNewKeyBindingList.this.mc.fontRendererObj.drawString(this.keyDesc, x + 90 - GuiNewKeyBindingList.this.maxListLabelWidth, y + slotHeight / 2 - GuiNewKeyBindingList.this.mc.fontRendererObj.FONT_HEIGHT / 2, 16777215);
-            GuiNewKeyBindingList.this.mc.fontRendererObj.drawString(String.format("(%s)", I18n.format(keybinding.getKeyCategory())), x - 45 - GuiNewKeyBindingList.this.maxListLabelWidth, y + slotHeight / 2 - GuiNewKeyBindingList.this.mc.fontRendererObj.FONT_HEIGHT / 2, 16777215);
-            if(keybinding.isSetToDefaultValue()) {
-                btnReset.visible = false;
-            } else {
-                btnReset.visible = true;
-            }
+//            GuiNewKeyBindingList.this.mc.fontRendererObj.drawString(String.format("(%s)", I18n.format(keybinding.getKeyCategory())), x - 45 - GuiNewKeyBindingList.this.maxListLabelWidth, y + slotHeight / 2 - GuiNewKeyBindingList.this.mc.fontRendererObj.FONT_HEIGHT / 2, 16777215);
+            btnReset.visible = !keybinding.isSetToDefaultValue();
             this.btnReset.xPosition = x + 210;
             this.btnReset.yPosition = y;
             this.btnReset.enabled = !this.keybinding.isSetToDefaultValue();
@@ -179,6 +175,12 @@ public class GuiNewKeyBindingList extends GuiKeyBindingList {
             } else if(flag1) {
                 this.btnChangeKeyBinding.displayString = (keyCodeModifierConflict ? TextFormatting.GOLD : TextFormatting.RED) + this.btnChangeKeyBinding.displayString;
             }
+//            if(mouseX >= x + 90 - GuiNewKeyBindingList.this.maxListLabelWidth && mouseX <= x + listWidth) {
+                if(mouseY >= y && mouseY <= y + slotHeight) {
+//                    Gui.drawRect(mouseX + 8, mouseY - 2, mouseX + mc.fontRendererObj.getStringWidth(I18n.format(keybinding.getKeyCategory())), mouseY + mc.fontRendererObj.FONT_HEIGHT, 0xFF000000);
+                    mc.fontRendererObj.drawString(I18n.format(keybinding.getKeyCategory()), mouseX + 10, mouseY, 0xFFFFFF);
+                }
+//            }
             
             this.btnChangeKeyBinding.func_191745_a(GuiNewKeyBindingList.this.mc, mouseX, mouseY, p_192634_9_);
         }