|
@@ -1,5 +1,6 @@
|
|
package com.blamejared.controlling.client;
|
|
package com.blamejared.controlling.client;
|
|
|
|
|
|
|
|
+import com.blamejared.controlling.ControllingConstants;
|
|
import com.blamejared.controlling.api.DisplayMode;
|
|
import com.blamejared.controlling.api.DisplayMode;
|
|
import com.blamejared.controlling.api.SearchType;
|
|
import com.blamejared.controlling.api.SearchType;
|
|
import com.blamejared.controlling.api.SortOrder;
|
|
import com.blamejared.controlling.api.SortOrder;
|
|
@@ -7,6 +8,7 @@ import com.blamejared.controlling.mixin.AccessKeyBindsScreen;
|
|
import com.blamejared.controlling.mixin.AccessKeyMapping;
|
|
import com.blamejared.controlling.mixin.AccessKeyMapping;
|
|
import com.blamejared.controlling.mixin.AccessScreen;
|
|
import com.blamejared.controlling.mixin.AccessScreen;
|
|
import com.blamejared.controlling.platform.Services;
|
|
import com.blamejared.controlling.platform.Services;
|
|
|
|
+import com.google.common.base.Suppliers;
|
|
import com.mojang.blaze3d.platform.InputConstants;
|
|
import com.mojang.blaze3d.platform.InputConstants;
|
|
import com.mojang.blaze3d.vertex.PoseStack;
|
|
import com.mojang.blaze3d.vertex.PoseStack;
|
|
import net.minecraft.Util;
|
|
import net.minecraft.Util;
|
|
@@ -27,9 +29,11 @@ import java.util.LinkedHashSet;
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
import java.util.Set;
|
|
import java.util.Set;
|
|
import java.util.function.Predicate;
|
|
import java.util.function.Predicate;
|
|
|
|
+import java.util.function.Supplier;
|
|
|
|
|
|
public class NewKeyBindsScreen extends KeyBindsScreen {
|
|
public class NewKeyBindsScreen extends KeyBindsScreen {
|
|
|
|
|
|
|
|
+
|
|
private Button buttonReset;
|
|
private Button buttonReset;
|
|
private final Options options;
|
|
private final Options options;
|
|
|
|
|
|
@@ -44,11 +48,11 @@ public class NewKeyBindsScreen extends KeyBindsScreen {
|
|
private Button buttonConflicting;
|
|
private Button buttonConflicting;
|
|
private FancyCheckbox buttonKey;
|
|
private FancyCheckbox buttonKey;
|
|
private FancyCheckbox buttonCat;
|
|
private FancyCheckbox buttonCat;
|
|
- private boolean confirmingReset = false;
|
|
|
|
- private boolean showFree = false;
|
|
|
|
|
|
+ private boolean confirmingReset;
|
|
|
|
+ private boolean showFree;
|
|
|
|
|
|
private KeyBindsList customKeyList;
|
|
private KeyBindsList customKeyList;
|
|
- private FreeKeysList freeKeyList;
|
|
|
|
|
|
+ private Supplier<FreeKeysList> freeKeyList;
|
|
|
|
|
|
public NewKeyBindsScreen(Screen screen, Options settings) {
|
|
public NewKeyBindsScreen(Screen screen, Options settings) {
|
|
|
|
|
|
@@ -63,22 +67,22 @@ public class NewKeyBindsScreen extends KeyBindsScreen {
|
|
protected void init() {
|
|
protected void init() {
|
|
|
|
|
|
this.customKeyList = new NewKeyBindsList(this, this.minecraft);
|
|
this.customKeyList = new NewKeyBindsList(this, this.minecraft);
|
|
- this.freeKeyList = new FreeKeysList(this, this.minecraft);
|
|
|
|
- this.setKeyBindsList(this.customKeyList);
|
|
|
|
|
|
+ this.freeKeyList = Suppliers.memoize(() -> new FreeKeysList(this, this.minecraft));
|
|
|
|
+ this.setKeyBindsList(showFree ? this.freeKeyList.get() : this.customKeyList);
|
|
this.addWidget(getKeyBindsList());
|
|
this.addWidget(getKeyBindsList());
|
|
this.setFocused(getKeyBindsList());
|
|
this.setFocused(getKeyBindsList());
|
|
- this.addRenderableWidget(Button.builder(Component.translatable("gui.done"), (btn) -> Objects.requireNonNull(this.minecraft)
|
|
|
|
|
|
+ this.addRenderableWidget(Button.builder(ControllingConstants.COMPONENT_GUI_DONE, (btn) -> Objects.requireNonNull(this.minecraft)
|
|
.setScreen(this.lastScreen)).bounds(this.width / 2 - 155 + 160, this.height - 29, 150, 20).build());
|
|
.setScreen(this.lastScreen)).bounds(this.width / 2 - 155 + 160, this.height - 29, 150, 20).build());
|
|
|
|
|
|
- this.buttonReset = this.addRenderableWidget(Button.builder(Component.translatable("controls.resetAll"), btn -> {
|
|
|
|
|
|
+ this.buttonReset = this.addRenderableWidget(Button.builder(confirmingReset ? ControllingConstants.COMPONENT_OPTIONS_CONFIRM_RESET : ControllingConstants.COMPONENT_CONTROLS_RESET_ALL, btn -> {
|
|
|
|
|
|
if(!confirmingReset) {
|
|
if(!confirmingReset) {
|
|
confirmingReset = true;
|
|
confirmingReset = true;
|
|
- btn.setMessage(Component.translatable("options.confirmReset"));
|
|
|
|
|
|
+ btn.setMessage(ControllingConstants.COMPONENT_OPTIONS_CONFIRM_RESET);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
confirmingReset = false;
|
|
confirmingReset = false;
|
|
- btn.setMessage(Component.translatable("controls.resetAll"));
|
|
|
|
|
|
+ btn.setMessage(ControllingConstants.COMPONENT_CONTROLS_RESET_ALL);
|
|
for(KeyMapping keybinding : Objects.requireNonNull(minecraft).options.keyMappings) {
|
|
for(KeyMapping keybinding : Objects.requireNonNull(minecraft).options.keyMappings) {
|
|
Services.PLATFORM.setToDefault(minecraft.options, keybinding);
|
|
Services.PLATFORM.setToDefault(minecraft.options, keybinding);
|
|
KeyMapping.resetMapping();
|
|
KeyMapping.resetMapping();
|
|
@@ -86,49 +90,49 @@ public class NewKeyBindsScreen extends KeyBindsScreen {
|
|
|
|
|
|
KeyMapping.releaseAll();
|
|
KeyMapping.releaseAll();
|
|
}).bounds(this.width / 2 - 155, this.height - 29, 74, 20).build());
|
|
}).bounds(this.width / 2 - 155, this.height - 29, 74, 20).build());
|
|
- this.buttonNone = this.addRenderableWidget(Button.builder(Component.translatable("options.showNone"), (btn) -> {
|
|
|
|
|
|
+ this.buttonNone = this.addRenderableWidget(Button.builder(ControllingConstants.COMPONENT_OPTIONS_SHOW_NONE, (btn) -> {
|
|
if(displayMode == DisplayMode.NONE) {
|
|
if(displayMode == DisplayMode.NONE) {
|
|
- buttonNone.setMessage(Component.translatable("options.showNone"));
|
|
|
|
|
|
+ buttonNone.setMessage(ControllingConstants.COMPONENT_OPTIONS_SHOW_NONE);
|
|
displayMode = DisplayMode.ALL;
|
|
displayMode = DisplayMode.ALL;
|
|
} else {
|
|
} else {
|
|
displayMode = DisplayMode.NONE;
|
|
displayMode = DisplayMode.NONE;
|
|
- buttonNone.setMessage(Component.translatable("options.showAll"));
|
|
|
|
- buttonConflicting.setMessage(Component.translatable("options.showConflicts"));
|
|
|
|
|
|
+ buttonNone.setMessage(ControllingConstants.COMPONENT_OPTIONS_SHOW_ALL);
|
|
|
|
+ buttonConflicting.setMessage(ControllingConstants.COMPONENT_OPTIONS_SHOW_CONFLICTS);
|
|
}
|
|
}
|
|
filterKeys();
|
|
filterKeys();
|
|
}).bounds(this.width / 2 - 155 + 160 + 76, this.height - 29 - 24, 150 / 2, 20).build());
|
|
}).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) -> {
|
|
|
|
|
|
+ this.buttonConflicting = this.addRenderableWidget(Button.builder(ControllingConstants.COMPONENT_OPTIONS_SHOW_CONFLICTS, (btn) -> {
|
|
if(displayMode == DisplayMode.CONFLICTING) {
|
|
if(displayMode == DisplayMode.CONFLICTING) {
|
|
- buttonConflicting.setMessage(Component.translatable("options.showConflicts"));
|
|
|
|
|
|
+ buttonConflicting.setMessage(ControllingConstants.COMPONENT_OPTIONS_SHOW_CONFLICTS);
|
|
displayMode = DisplayMode.ALL;
|
|
displayMode = DisplayMode.ALL;
|
|
} else {
|
|
} else {
|
|
displayMode = DisplayMode.CONFLICTING;
|
|
displayMode = DisplayMode.CONFLICTING;
|
|
- buttonConflicting.setMessage(Component.translatable("options.showAll"));
|
|
|
|
- buttonNone.setMessage(Component.translatable("options.showNone"));
|
|
|
|
|
|
+ buttonConflicting.setMessage(ControllingConstants.COMPONENT_OPTIONS_SHOW_ALL);
|
|
|
|
+ buttonNone.setMessage(ControllingConstants.COMPONENT_OPTIONS_SHOW_NONE);
|
|
}
|
|
}
|
|
filterKeys();
|
|
filterKeys();
|
|
}).bounds(this.width / 2 - 155 + 160, this.height - 29 - 24, 150 / 2, 20).build());
|
|
}).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());
|
|
search = new EditBox(font, this.width / 2 - 154, this.height - 29 - 23, 148, 18, Component.empty());
|
|
addWidget(search);
|
|
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 -> {
|
|
|
|
|
|
+ this.buttonKey = this.addRenderableWidget(new FancyCheckbox(this.width / 2 - (155 / 2), this.height - 29 - 37, 11, 11, ControllingConstants.COMPONENT_OPTIONS_KEY, false, btn -> {
|
|
buttonCat.selected(false);
|
|
buttonCat.selected(false);
|
|
searchType = btn.selected() ? SearchType.KEY : SearchType.NAME;
|
|
searchType = btn.selected() ? SearchType.KEY : SearchType.NAME;
|
|
filterKeys();
|
|
filterKeys();
|
|
}));
|
|
}));
|
|
- this.buttonCat = this.addRenderableWidget(new FancyCheckbox(this.width / 2 - (155 / 2), this.height - 29 - 50, 11, 11, Component.translatable("options.category"), false, btn -> {
|
|
|
|
|
|
+ this.buttonCat = this.addRenderableWidget(new FancyCheckbox(this.width / 2 - (155 / 2), this.height - 29 - 50, 11, 11, ControllingConstants.COMPONENT_OPTIONS_CATEGORY, false, btn -> {
|
|
buttonKey.selected(false);
|
|
buttonKey.selected(false);
|
|
searchType = btn.selected() ? SearchType.CATEGORY : SearchType.NAME;
|
|
searchType = btn.selected() ? SearchType.CATEGORY : SearchType.NAME;
|
|
filterKeys();
|
|
filterKeys();
|
|
}));
|
|
}));
|
|
sortOrder = SortOrder.NONE;
|
|
sortOrder = SortOrder.NONE;
|
|
- Button buttonSort = this.addRenderableWidget(Button.builder(Component.translatable("options.sort")
|
|
|
|
|
|
+ Button buttonSort = this.addRenderableWidget(Button.builder(ControllingConstants.COMPONENT_OPTIONS_SORT.copy()
|
|
.append(": " + sortOrder.getName()), (btn) -> {
|
|
.append(": " + sortOrder.getName()), (btn) -> {
|
|
sortOrder = sortOrder.cycle();
|
|
sortOrder = sortOrder.cycle();
|
|
- btn.setMessage(Component.translatable("options.sort").append(": " + sortOrder.getName()));
|
|
|
|
|
|
+ btn.setMessage(ControllingConstants.COMPONENT_OPTIONS_SORT.copy().append(": " + sortOrder.getName()));
|
|
filterKeys();
|
|
filterKeys();
|
|
}).bounds(this.width / 2 - 155 + 160 + 76, this.height - 29 - 24 - 24, 150 / 2, 20).build());
|
|
}).bounds(this.width / 2 - 155 + 160 + 76, this.height - 29 - 24 - 24, 150 / 2, 20).build());
|
|
|
|
|
|
- this.addRenderableWidget(Button.builder(Component.translatable("options.toggleFree"), (btn) -> {
|
|
|
|
|
|
+ this.addRenderableWidget(Button.builder(ControllingConstants.COMPONENT_OPTIONS_TOGGLE_FREE, (btn) -> {
|
|
this.removeWidget(getKeyBindsList());
|
|
this.removeWidget(getKeyBindsList());
|
|
if(showFree) {
|
|
if(showFree) {
|
|
buttonSort.active = true;
|
|
buttonSort.active = true;
|
|
@@ -139,14 +143,14 @@ public class NewKeyBindsScreen extends KeyBindsScreen {
|
|
buttonReset.active = true;
|
|
buttonReset.active = true;
|
|
setKeyBindsList(customKeyList);
|
|
setKeyBindsList(customKeyList);
|
|
} else {
|
|
} else {
|
|
- freeKeyList.recalculate();
|
|
|
|
|
|
+ freeKeyList.get().recalculate();
|
|
buttonSort.active = false;
|
|
buttonSort.active = false;
|
|
buttonCat.active = false;
|
|
buttonCat.active = false;
|
|
buttonKey.active = false;
|
|
buttonKey.active = false;
|
|
buttonNone.active = false;
|
|
buttonNone.active = false;
|
|
buttonConflicting.active = false;
|
|
buttonConflicting.active = false;
|
|
buttonReset.active = false;
|
|
buttonReset.active = false;
|
|
- setKeyBindsList(freeKeyList);
|
|
|
|
|
|
+ setKeyBindsList(freeKeyList.get());
|
|
}
|
|
}
|
|
this.addWidget(getKeyBindsList());
|
|
this.addWidget(getKeyBindsList());
|
|
this.setFocused(getKeyBindsList());
|
|
this.setFocused(getKeyBindsList());
|
|
@@ -283,12 +287,10 @@ public class NewKeyBindsScreen extends KeyBindsScreen {
|
|
this.buttonReset.active = flag;
|
|
this.buttonReset.active = flag;
|
|
if(!flag) {
|
|
if(!flag) {
|
|
confirmingReset = false;
|
|
confirmingReset = false;
|
|
- buttonReset.setMessage(Component.translatable("controls.resetAll"));
|
|
|
|
|
|
+ buttonReset.setMessage(ControllingConstants.COMPONENT_CONTROLS_RESET_ALL);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
- 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);
|
|
|
|
|
|
+ font.draw(stack, ControllingConstants.COMPONENT_OPTIONS_SEARCH, this.width / 2f - (155 / 2f) - (font.width(ControllingConstants.COMPONENT_OPTIONS_SEARCH.getString())) - 5, this.height - 29 - 42, 16777215);
|
|
|
|
|
|
for(Renderable renderable : getScreenAccess().controlling$getRenderables()) {
|
|
for(Renderable renderable : getScreenAccess().controlling$getRenderables()) {
|
|
renderable.render(stack, mouseX, mouseY, partialTicks);
|
|
renderable.render(stack, mouseX, mouseY, partialTicks);
|