| 1 | package net.minecraft.client.gui;
|
| 2 |
|
| 3 | import java.util.Arrays;
|
| 4 | import net.minecraft.client.Minecraft;
|
| 5 | import net.minecraft.client.resources.I18n;
|
| 6 | import net.minecraft.client.settings.GameSettings;
|
| 7 | import net.minecraft.client.settings.KeyBinding;
|
| 8 | import net.minecraft.util.EnumChatFormatting;
|
| 9 | import org.apache.commons.lang3.ArrayUtils;
|
| 10 |
|
| 11 | public class GuiKeyBindingList extends GuiListExtended
|
| 12 | {
|
| 13 | private final GuiControls field_148191_k;
|
| 14 | private final Minecraft mc;
|
| 15 | private final GuiListExtended.IGuiListEntry[] listEntries;
|
| 16 | private int maxListLabelWidth = 0;
|
| 17 |
|
| 18 | public GuiKeyBindingList(GuiControls controls, Minecraft mcIn)
|
| 19 | {
|
| 20 | super(mcIn, controls.width, controls.height, 63, controls.height - 32, 20);
|
| 21 | this.field_148191_k = controls;
|
| 22 | this.mc = mcIn;
|
| 23 | KeyBinding[] akeybinding = (KeyBinding[])ArrayUtils.clone(mcIn.gameSettings.keyBindings);
|
| 24 | this.listEntries = new GuiListExtended.IGuiListEntry[akeybinding.length + KeyBinding.getKeybinds().size()];
|
| 25 | Arrays.sort((Object[])akeybinding);
|
| 26 | int i = 0;
|
| 27 | String s = null;
|
| 28 |
|
| 29 | for (KeyBinding keybinding : akeybinding)
|
| 30 | {
|
| 31 | String s1 = keybinding.getKeyCategory();
|
| 32 |
|
| 33 | if (!s1.equals(s))
|
| 34 | {
|
| 35 | s = s1;
|
| 36 | this.listEntries[i++] = new GuiKeyBindingList.CategoryEntry(s1);
|
| 37 | }
|
| 38 |
|
| 39 | int j = mcIn.fontRendererObj.getStringWidth(I18n.format(keybinding.getKeyDescription(), new Object[0]));
|
| 40 |
|
| 41 | if (j > this.maxListLabelWidth)
|
| 42 | {
|
| 43 | this.maxListLabelWidth = j;
|
| 44 | }
|
| 45 |
|
| 46 | this.listEntries[i++] = new GuiKeyBindingList.KeyEntry(keybinding);
|
| 47 | }
|
| 48 | }
|
| 49 |
|
| 50 | protected int getSize()
|
| 51 | {
|
| 52 | return this.listEntries.length;
|
| 53 | }
|
| 54 |
|
| 55 | /**
|
| 56 | * Gets the IGuiListEntry object for the given index
|
| 57 | */
|
| 58 | public GuiListExtended.IGuiListEntry getListEntry(int index)
|
| 59 | {
|
| 60 | return this.listEntries[index];
|
| 61 | }
|
| 62 |
|
| 63 | protected int getScrollBarX()
|
| 64 | {
|
| 65 | return super.getScrollBarX() + 15;
|
| 66 | }
|
| 67 |
|
| 68 | /**
|
| 69 | * Gets the width of the list
|
| 70 | */
|
| 71 | public int getListWidth()
|
| 72 | {
|
| 73 | return super.getListWidth() + 32;
|
| 74 | }
|
| 75 |
|
| 76 | public class CategoryEntry implements GuiListExtended.IGuiListEntry
|
| 77 | {
|
| 78 | private final String labelText;
|
| 79 | private final int labelWidth;
|
| 80 |
|
| 81 | public CategoryEntry(String p_i45028_2_)
|
| 82 | {
|
| 83 | this.labelText = I18n.format(p_i45028_2_, new Object[0]);
|
| 84 | this.labelWidth = GuiKeyBindingList.this.mc.fontRendererObj.getStringWidth(this.labelText);
|
| 85 | }
|
| 86 |
|
| 87 | public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected)
|
| 88 | {
|
| 89 | GuiKeyBindingList.this.mc.fontRendererObj.drawString(this.labelText, GuiKeyBindingList.this.mc.currentScreen.width / 2 - this.labelWidth / 2, y + slotHeight - GuiKeyBindingList.this.mc.fontRendererObj.FONT_HEIGHT - 1, 16777215);
|
| 90 | }
|
| 91 |
|
| 92 | public boolean mousePressed(int slotIndex, int p_148278_2_, int p_148278_3_, int p_148278_4_, int p_148278_5_, int p_148278_6_)
|
| 93 | {
|
| 94 | return false;
|
| 95 | }
|
| 96 |
|
| 97 | public void mouseReleased(int slotIndex, int x, int y, int mouseEvent, int relativeX, int relativeY)
|
| 98 | {
|
| 99 | }
|
| 100 |
|
| 101 | public void setSelected(int p_178011_1_, int p_178011_2_, int p_178011_3_)
|
| 102 | {
|
| 103 | }
|
| 104 | }
|
| 105 |
|
| 106 | public class KeyEntry implements GuiListExtended.IGuiListEntry
|
| 107 | {
|
| 108 | private final KeyBinding keybinding;
|
| 109 | private final String keyDesc;
|
| 110 | private final GuiButton btnChangeKeyBinding;
|
| 111 | private final GuiButton btnReset;
|
| 112 |
|
| 113 | private KeyEntry(KeyBinding p_i45029_2_)
|
| 114 | {
|
| 115 | this.keybinding = p_i45029_2_;
|
| 116 | this.keyDesc = I18n.format(p_i45029_2_.getKeyDescription(), new Object[0]);
|
| 117 | this.btnChangeKeyBinding = new GuiButton(0, 0, 0, 75, 20, I18n.format(p_i45029_2_.getKeyDescription(), new Object[0]));
|
| 118 | this.btnReset = new GuiButton(0, 0, 0, 50, 20, I18n.format("controls.reset", new Object[0]));
|
| 119 | }
|
| 120 |
|
| 121 | public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected)
|
| 122 | {
|
| 123 | boolean flag = GuiKeyBindingList.this.field_148191_k.buttonId == this.keybinding;
|
| 124 | GuiKeyBindingList.this.mc.fontRendererObj.drawString(this.keyDesc, x + 90 - GuiKeyBindingList.this.maxListLabelWidth, y + slotHeight / 2 - GuiKeyBindingList.this.mc.fontRendererObj.FONT_HEIGHT / 2, 16777215);
|
| 125 | this.btnReset.xPosition = x + 190;
|
| 126 | this.btnReset.yPosition = y;
|
| 127 | this.btnReset.enabled = this.keybinding.getKeyCode() != this.keybinding.getKeyCodeDefault();
|
| 128 | this.btnReset.drawButton(GuiKeyBindingList.this.mc, mouseX, mouseY);
|
| 129 | this.btnChangeKeyBinding.xPosition = x + 105;
|
| 130 | this.btnChangeKeyBinding.yPosition = y;
|
| 131 | this.btnChangeKeyBinding.displayString = GameSettings.getKeyDisplayString(this.keybinding.getKeyCode());
|
| 132 | boolean flag1 = false;
|
| 133 |
|
| 134 | if (this.keybinding.getKeyCode() != 0)
|
| 135 | {
|
| 136 | for (KeyBinding keybinding : GuiKeyBindingList.this.mc.gameSettings.keyBindings)
|
| 137 | {
|
| 138 | if (keybinding != this.keybinding && keybinding.getKeyCode() == this.keybinding.getKeyCode())
|
| 139 | {
|
| 140 | flag1 = true;
|
| 141 | break;
|
| 142 | }
|
| 143 | }
|
| 144 | }
|
| 145 |
|
| 146 | if (flag)
|
| 147 | {
|
| 148 | this.btnChangeKeyBinding.displayString = EnumChatFormatting.WHITE + "> " + EnumChatFormatting.YELLOW + this.btnChangeKeyBinding.displayString + EnumChatFormatting.WHITE + " <";
|
| 149 | }
|
| 150 | else if (flag1)
|
| 151 | {
|
| 152 | this.btnChangeKeyBinding.displayString = EnumChatFormatting.RED + this.btnChangeKeyBinding.displayString;
|
| 153 | }
|
| 154 |
|
| 155 | this.btnChangeKeyBinding.drawButton(GuiKeyBindingList.this.mc, mouseX, mouseY);
|
| 156 | }
|
| 157 |
|
| 158 | public boolean mousePressed(int slotIndex, int p_148278_2_, int p_148278_3_, int p_148278_4_, int p_148278_5_, int p_148278_6_)
|
| 159 | {
|
| 160 | if (this.btnChangeKeyBinding.mousePressed(GuiKeyBindingList.this.mc, p_148278_2_, p_148278_3_))
|
| 161 | {
|
| 162 | GuiKeyBindingList.this.field_148191_k.buttonId = this.keybinding;
|
| 163 | return true;
|
| 164 | }
|
| 165 | else if (this.btnReset.mousePressed(GuiKeyBindingList.this.mc, p_148278_2_, p_148278_3_))
|
| 166 | {
|
| 167 | GuiKeyBindingList.this.mc.gameSettings.setOptionKeyBinding(this.keybinding, this.keybinding.getKeyCodeDefault());
|
| 168 | KeyBinding.resetKeyBindingArrayAndHash();
|
| 169 | return true;
|
| 170 | }
|
| 171 | else
|
| 172 | {
|
| 173 | return false;
|
| 174 | }
|
| 175 | }
|
| 176 |
|
| 177 | public void mouseReleased(int slotIndex, int x, int y, int mouseEvent, int relativeX, int relativeY)
|
| 178 | {
|
| 179 | this.btnChangeKeyBinding.mouseReleased(x, y);
|
| 180 | this.btnReset.mouseReleased(x, y);
|
| 181 | }
|
| 182 |
|
| 183 | public void setSelected(int p_178011_1_, int p_178011_2_, int p_178011_3_)
|
| 184 | {
|
| 185 | }
|
| 186 | }
|
| 187 | }
|
| 188 |
|