|
@@ -2,41 +2,40 @@ package com.blamejared.controlling.client.gui;
|
|
|
|
|
|
import net.minecraft.client.GameSettings;
|
|
|
import net.minecraft.client.gui.*;
|
|
|
+import net.minecraft.client.gui.screen.*;
|
|
|
+import net.minecraft.client.gui.widget.*;
|
|
|
+import net.minecraft.client.gui.widget.button.*;
|
|
|
import net.minecraft.client.resources.I18n;
|
|
|
-import net.minecraft.client.settings.KeyBinding;
|
|
|
+import net.minecraft.client.settings.*;
|
|
|
import net.minecraft.client.util.InputMappings;
|
|
|
import net.minecraft.util.Util;
|
|
|
import net.minecraftforge.api.distmarker.*;
|
|
|
-import net.minecraftforge.fml.client.config.GuiCheckBox;
|
|
|
|
|
|
-import java.util.Iterator;
|
|
|
import java.util.function.Predicate;
|
|
|
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
|
-public class GuiNewControls extends GuiControls {
|
|
|
-
|
|
|
- private static final GameSettings.Options[] OPTIONS_ARR = new GameSettings.Options[]{GameSettings.Options.INVERT_MOUSE, GameSettings.Options.SENSITIVITY, GameSettings.Options.TOUCHSCREEN, GameSettings.Options.AUTO_JUMP};
|
|
|
+public class GuiNewControls extends ControlsScreen {
|
|
|
|
|
|
private GuiNewKeyBindingList keyBindingList;
|
|
|
- private GuiButton buttonReset;
|
|
|
- private final GuiScreen parentScreen;
|
|
|
+ private Button buttonReset;
|
|
|
+ private final Screen parentScreen;
|
|
|
private final GameSettings options;
|
|
|
|
|
|
private String lastSearch;
|
|
|
- private GuiTextField search;
|
|
|
+ private TextFieldWidget search;
|
|
|
|
|
|
private DisplayMode displayMode;
|
|
|
private SearchType searchType;
|
|
|
private SortOrder sortOrder;
|
|
|
|
|
|
- private GuiButton buttonNone;
|
|
|
- private GuiButton buttonConflicting;
|
|
|
+ private Button buttonNone;
|
|
|
+ private Button buttonConflicting;
|
|
|
private GuiCheckBox buttonKey;
|
|
|
private GuiCheckBox buttonCat;
|
|
|
|
|
|
- private GuiButton buttonSort;
|
|
|
+ private Button buttonSort;
|
|
|
|
|
|
- public GuiNewControls(GuiScreen screen, GameSettings settings) {
|
|
|
+ public GuiNewControls(Screen screen, GameSettings settings) {
|
|
|
super(screen, settings);
|
|
|
this.parentScreen = screen;
|
|
|
this.options = settings;
|
|
@@ -46,60 +45,50 @@ public class GuiNewControls extends GuiControls {
|
|
|
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
|
|
|
* window resizes, the buttonList is cleared beforehand.
|
|
|
*/
|
|
|
- protected void initGui() {
|
|
|
- this.keyBindingList = new GuiNewKeyBindingList(this, this.mc);
|
|
|
+ protected void init() {
|
|
|
+
|
|
|
+ this.addButton(new Button(this.width / 2 - 155, 18, 150, 20, I18n.format("options.mouse_settings"), (p_213126_1_) -> {
|
|
|
+ this.minecraft.displayGuiScreen(new MouseSettingsScreen(this));
|
|
|
+ }));
|
|
|
+ this.addButton(AbstractOption.field_216719_z.func_216586_a(this.minecraft.gameSettings, this.width / 2 - 155 + 160, 18, 150));
|
|
|
+
|
|
|
+ this.keyBindingList = new GuiNewKeyBindingList(this, this.minecraft);
|
|
|
this.children.add(this.keyBindingList);
|
|
|
this.setFocused(this.keyBindingList);
|
|
|
- this.addButton(new GuiButton(200, this.width / 2 - 155 + 160, this.height - 29, 150, 20, I18n.format("gui.done")) {
|
|
|
- /**
|
|
|
- * Called when the left mouse button is pressed over this button. This method is specific to GuiButton.
|
|
|
- */
|
|
|
- public void onClick(double mouseX, double mouseY) {
|
|
|
- GuiNewControls.this.mc.displayGuiScreen(GuiNewControls.this.parentScreen);
|
|
|
- }
|
|
|
- });
|
|
|
- this.buttonReset = this.addButton(new GuiButton(201, this.width / 2 - 155, this.height - 29, 150, 20, I18n.format("controls.resetAll")) {
|
|
|
- /**
|
|
|
- * Called when the left mouse button is pressed over this button. This method is specific to GuiButton.
|
|
|
- */
|
|
|
- public void onClick(double mouseX, double mouseY) {
|
|
|
- for(KeyBinding keybinding : GuiNewControls.this.mc.gameSettings.keyBindings) {
|
|
|
- keybinding.setToDefault();
|
|
|
- }
|
|
|
-
|
|
|
- KeyBinding.resetKeyBindingArrayAndHash();
|
|
|
+ this.addButton(new Button(this.width / 2 - 155 + 160, this.height - 29, 150, 20, I18n.format("gui.done"), (p_213126_1_) -> GuiNewControls.this.minecraft.displayGuiScreen(GuiNewControls.this.parentScreen)));
|
|
|
+
|
|
|
+ this.buttonReset = this.addButton(new Button(this.width / 2 - 155, this.height - 29, 150, 20, I18n.format("controls.resetAll"), (p_213126_1_) -> {
|
|
|
+
|
|
|
+ for(KeyBinding keybinding : GuiNewControls.this.minecraft.gameSettings.keyBindings) {
|
|
|
+ keybinding.setToDefault();
|
|
|
}
|
|
|
- });
|
|
|
- this.buttonNone = this.addButton(new GuiButton(2907, this.width / 2 - 155 + 160 + 76, this.height - 29 - 24, 150 / 2, 20, "Show Unbound"/*I18n.translate("options.showNone")*/) {
|
|
|
- @Override
|
|
|
- public void onClick(double mouseX, double mouseY) {
|
|
|
- if(displayMode == DisplayMode.NONE) {
|
|
|
- buttonNone.displayString = I18n.format("options.showNone");
|
|
|
- displayMode = DisplayMode.ALL;
|
|
|
- } else {
|
|
|
- displayMode = DisplayMode.NONE;
|
|
|
- buttonNone.displayString = I18n.format("options.showAll");
|
|
|
- buttonConflicting.displayString = I18n.format("options.showConflicts");
|
|
|
- }
|
|
|
- filterKeys();
|
|
|
+
|
|
|
+ KeyBinding.resetKeyBindingArrayAndHash();
|
|
|
+ }));
|
|
|
+ this.buttonNone = this.addButton(new Button(this.width / 2 - 155 + 160 + 76, this.height - 29 - 24, 150 / 2, 20, I18n.format("options.showNone"), (p_213126_1_) -> {
|
|
|
+ if(displayMode == DisplayMode.NONE) {
|
|
|
+ buttonNone.setMessage(I18n.format("options.showNone"));
|
|
|
+ displayMode = DisplayMode.ALL;
|
|
|
+ } else {
|
|
|
+ displayMode = DisplayMode.NONE;
|
|
|
+ buttonNone.setMessage(I18n.format("options.showAll"));
|
|
|
+ buttonConflicting.setMessage(I18n.format("options.showConflicts"));
|
|
|
}
|
|
|
- });
|
|
|
- this.buttonConflicting = this.addButton(new GuiButton(2906, this.width / 2 - 155 + 160, this.height - 29 - 24, 150 / 2, 20, "Show Conflicts"/*I18n.translate("options.showConflicts")*/) {
|
|
|
- @Override
|
|
|
- public void onClick(double mouseX, double mouseY) {
|
|
|
- if(displayMode == DisplayMode.CONFLICTING) {
|
|
|
- buttonConflicting.displayString = I18n.format("options.showConflicts");
|
|
|
- displayMode = DisplayMode.ALL;
|
|
|
- } else {
|
|
|
- displayMode = DisplayMode.CONFLICTING;
|
|
|
- buttonConflicting.displayString = "Show All";
|
|
|
- buttonNone.displayString = I18n.format("options.showNone");
|
|
|
- }
|
|
|
- filterKeys();
|
|
|
+ filterKeys();
|
|
|
+ }));
|
|
|
+ this.buttonConflicting = this.addButton(new Button(this.width / 2 - 155 + 160, this.height - 29 - 24, 150 / 2, 20, I18n.format("options.showConflicts"), (p_213126_1_) -> {
|
|
|
+ if(displayMode == DisplayMode.CONFLICTING) {
|
|
|
+ buttonConflicting.setMessage(I18n.format("options.showConflicts"));
|
|
|
+ displayMode = DisplayMode.ALL;
|
|
|
+ } else {
|
|
|
+ displayMode = DisplayMode.CONFLICTING;
|
|
|
+ buttonConflicting.setMessage("Show All");
|
|
|
+ buttonNone.setMessage(I18n.format("options.showNone"));
|
|
|
}
|
|
|
- });
|
|
|
- search = new GuiTextField(0, fontRenderer, this.width / 2 - 154, this.height - 29 - 23, 148, 18);
|
|
|
- this.buttonKey = this.addButton(new GuiCheckBox(2908, this.width / 2 - (155 / 2) + 20, this.height - 29 - 37, I18n.format("options.key"), false) {
|
|
|
+ filterKeys();
|
|
|
+ }));
|
|
|
+ search = new TextFieldWidget(font, this.width / 2 - 154, this.height - 29 - 23, 148, 18, "");
|
|
|
+ this.buttonKey = this.addButton(new GuiCheckBox(this.width / 2 - (155 / 2) + 20, this.height - 29 - 37, I18n.format("options.key"), false) {
|
|
|
@Override
|
|
|
public void onClick(double mouseX, double mouseY) {
|
|
|
super.onClick(mouseX, mouseY);
|
|
@@ -108,7 +97,7 @@ public class GuiNewControls extends GuiControls {
|
|
|
filterKeys();
|
|
|
}
|
|
|
});
|
|
|
- this.buttonCat = this.addButton(new GuiCheckBox(2909, this.width / 2 - (155 / 2) + 20, this.height - 29 - 50, I18n.format("options.category"), false) {
|
|
|
+ this.buttonCat = this.addButton(new GuiCheckBox(this.width / 2 - (155 / 2) + 20, this.height - 29 - 50, I18n.format("options.category"), false) {
|
|
|
@Override
|
|
|
public void onClick(double mouseX, double mouseY) {
|
|
|
super.onClick(mouseX, mouseY);
|
|
@@ -118,34 +107,11 @@ public class GuiNewControls extends GuiControls {
|
|
|
}
|
|
|
});
|
|
|
sortOrder = SortOrder.NONE;
|
|
|
- this.buttonSort = this.addButton(new GuiButton(2910, this.width / 2 - 155 + 160 + 76, this.height - 29 - 24 - 24, 150 / 2, 20, I18n.format("options.sort") + ": " + sortOrder.getName()) {
|
|
|
- @Override
|
|
|
- public void onClick(double mouseX, double mouseY) {
|
|
|
- super.onClick(mouseX, mouseY);
|
|
|
- sortOrder = sortOrder.cycle();
|
|
|
- this.displayString = I18n.format("options.sort") + ": " + sortOrder.getName();
|
|
|
- filterKeys();
|
|
|
- }
|
|
|
- });
|
|
|
- this.screenTitle = I18n.format("controls.title");
|
|
|
- int i = 0;
|
|
|
-
|
|
|
- for(GameSettings.Options gamesettings$options : GuiNewControls.OPTIONS_ARR) {
|
|
|
- if(gamesettings$options.isFloat()) {
|
|
|
- this.addButton(new GuiOptionSlider(gamesettings$options.getOrdinal(), this.width / 2 - 155 + i % 2 * 160, 18 + 24 * (i >> 1), gamesettings$options));
|
|
|
- } else {
|
|
|
- this.addButton(new GuiOptionButton(gamesettings$options.getOrdinal(), this.width / 2 - 155 + i % 2 * 160, 18 + 24 * (i >> 1), gamesettings$options, this.options.getKeyBinding(gamesettings$options)) {
|
|
|
- public void onClick(double mouseX, double mouseY) {
|
|
|
- GuiNewControls.this.options.setOptionValue(this.getOption(), 1);
|
|
|
- this.displayString = GuiNewControls.this.options.getKeyBinding(GameSettings.Options.byOrdinal(this.id));
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- ++i;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
+ this.buttonSort = this.addButton(new Button(this.width / 2 - 155 + 160 + 76, this.height - 29 - 24 - 24, 150 / 2, 20, I18n.format("options.sort") + ": " + sortOrder.getName(), (p_213126_1_) -> {
|
|
|
+ sortOrder = sortOrder.cycle();
|
|
|
+ p_213126_1_.setMessage(I18n.format("options.sort") + ": " + sortOrder.getName());
|
|
|
+ filterKeys();
|
|
|
+ }));
|
|
|
lastSearch = "";
|
|
|
displayMode = DisplayMode.ALL;
|
|
|
searchType = SearchType.NAME;
|
|
@@ -166,9 +132,9 @@ public class GuiNewControls extends GuiControls {
|
|
|
|
|
|
public void filterKeys() {
|
|
|
lastSearch = search.getText();
|
|
|
- keyBindingList.getChildren().clear();
|
|
|
+ keyBindingList.children().clear();
|
|
|
if(lastSearch.isEmpty() && displayMode == DisplayMode.ALL && sortOrder == SortOrder.NONE) {
|
|
|
- keyBindingList.getChildren().addAll(keyBindingList.getAllEntries());
|
|
|
+ keyBindingList.children().addAll(keyBindingList.getAllEntries());
|
|
|
return;
|
|
|
}
|
|
|
Predicate<GuiNewKeyBindingList.KeyEntry> filters = displayMode.getPredicate();
|
|
@@ -182,7 +148,7 @@ public class GuiNewControls extends GuiControls {
|
|
|
filters = filters.and(keyEntry -> keyEntry.getKeybinding().getKeyCategory().toLowerCase().contains(lastSearch.toLowerCase()));
|
|
|
break;
|
|
|
case KEY:
|
|
|
- filters = filters.and(keyEntry -> keyEntry.getKeybinding().getKey().getName().toLowerCase().contains(lastSearch.toLowerCase()));
|
|
|
+ filters = filters.and(keyEntry -> keyEntry.getKeybinding().getKey().getTranslationKey().toLowerCase().contains(lastSearch.toLowerCase()));
|
|
|
break;
|
|
|
}
|
|
|
|
|
@@ -190,11 +156,11 @@ public class GuiNewControls extends GuiControls {
|
|
|
if(entry instanceof GuiNewKeyBindingList.KeyEntry) {
|
|
|
GuiNewKeyBindingList.KeyEntry keyEntry = (GuiNewKeyBindingList.KeyEntry) entry;
|
|
|
if(filters.test(keyEntry)) {
|
|
|
- keyBindingList.getChildren().add(entry);
|
|
|
+ keyBindingList.children().add(entry);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- sortOrder.sort(keyBindingList.getChildren());
|
|
|
+ sortOrder.sort(keyBindingList.children());
|
|
|
|
|
|
|
|
|
}
|
|
@@ -203,29 +169,25 @@ public class GuiNewControls extends GuiControls {
|
|
|
* Draws the screen and all the components in it.
|
|
|
*/
|
|
|
public void render(int mouseX, int mouseY, float partialTicks) {
|
|
|
- this.drawDefaultBackground();
|
|
|
- this.keyBindingList.drawScreen(mouseX, mouseY, partialTicks);
|
|
|
- this.drawCenteredString(this.fontRenderer, this.screenTitle, this.width / 2, 8, 16777215);
|
|
|
+ this.renderBackground();
|
|
|
+ this.keyBindingList.render(mouseX, mouseY, partialTicks);
|
|
|
+ this.drawCenteredString(this.font, this.title.getFormattedText(), this.width / 2, 8, 16777215);
|
|
|
boolean flag = false;
|
|
|
|
|
|
for(KeyBinding keybinding : this.options.keyBindings) {
|
|
|
- if(!keybinding.func_197985_l()) {
|
|
|
+ if(!keybinding.isDefault()) {
|
|
|
flag = true;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- search.drawTextField(mouseX, mouseY, partialTicks);
|
|
|
- this.buttonReset.enabled = flag;
|
|
|
+ search.render(mouseX, mouseY, partialTicks);
|
|
|
+ this.buttonReset.active = flag;
|
|
|
for(int i = 0; i < this.buttons.size(); ++i) {
|
|
|
this.buttons.get(i).render(mouseX, mouseY, partialTicks);
|
|
|
}
|
|
|
|
|
|
- for(int j = 0; j < this.labels.size(); ++j) {
|
|
|
- this.labels.get(j).render(mouseX, mouseY, partialTicks);
|
|
|
-
|
|
|
- }
|
|
|
String text = I18n.format("options.search");
|
|
|
- fontRenderer.drawString(text, this.width / 2 - (155 / 2) - (fontRenderer.getStringWidth(text) / 2), this.height - 29 - 39, 16777215);
|
|
|
+ font.drawString(text, this.width / 2 - (155 / 2) - (font.getStringWidth(text) / 2), this.height - 29 - 39, 16777215);
|
|
|
}
|
|
|
|
|
|
public boolean mouseClicked(double mx, double my, int mb) {
|
|
@@ -251,27 +213,21 @@ public class GuiNewControls extends GuiControls {
|
|
|
|
|
|
if(!valid) {
|
|
|
|
|
|
- Iterator childIter = this.getChildren().iterator();
|
|
|
-
|
|
|
- IGuiEventListener listener;
|
|
|
- boolean clicked;
|
|
|
- do
|
|
|
- {
|
|
|
- if(!childIter.hasNext()) {
|
|
|
- return false;
|
|
|
+ for(IGuiEventListener iguieventlistener : this.children()) {
|
|
|
+ if(iguieventlistener.mouseClicked(mx, my, mb)) {
|
|
|
+ this.setFocused(iguieventlistener);
|
|
|
+ if(mb == 0) {
|
|
|
+ this.setDragging(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
}
|
|
|
-
|
|
|
- listener = (IGuiEventListener) childIter.next();
|
|
|
- clicked = listener.mouseClicked(mx, my, mb);
|
|
|
- } while(!clicked);
|
|
|
-
|
|
|
- this.focusOn(listener);
|
|
|
- if(mb == 0) {
|
|
|
- this.setDragging(true);
|
|
|
}
|
|
|
|
|
|
valid = true;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
return valid;
|
|
|
}
|
|
|
|