mirror of
https://github.com/TeamMidnightDust/MidnightControls.git
synced 2025-12-13 15:25:08 +01:00
More GUI rework! Controller controls tab works now.
This commit is contained in:
16
build.gradle
16
build.gradle
@@ -48,10 +48,12 @@ repositories {
|
||||
name = 'CottonMC'
|
||||
url = 'http://server.bbkr.space:8081/artifactory/libs-snapshot'
|
||||
}
|
||||
repositories {
|
||||
maven { url = "https://jitpack.io" }
|
||||
maven {
|
||||
name = 'Terraformers'
|
||||
url = 'https://maven.terraformersmc.com/releases'
|
||||
}
|
||||
maven { url "https://maven.shedaniel.me/" }
|
||||
maven { url = "https://jitpack.io" }
|
||||
}
|
||||
|
||||
configurations {
|
||||
@@ -68,13 +70,17 @@ dependencies {
|
||||
// Fabric API. This is technically optional, but you probably want it anyway.
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||
|
||||
modImplementation "io.github.prospector:modmenu:${project.modmenu_version}"
|
||||
modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}"
|
||||
modImplementation "com.github.lambdaurora:spruceui:${project.spruceui_version}"
|
||||
include "com.github.lambdaurora:spruceui:${project.spruceui_version}"
|
||||
|
||||
// Compatibility mods
|
||||
modImplementation "com.github.joaoh1:okzoomer:e13183c59b"
|
||||
modImplementation "me.shedaniel:RoughlyEnoughItems:5.10.184"
|
||||
modImplementation("com.github.joaoh1:okzoomer:e13183c59b") {
|
||||
exclude group: 'me.shedaniel.cloth'
|
||||
exclude group: 'io.github.prospector'
|
||||
}
|
||||
|
||||
modImplementation("me.shedaniel:RoughlyEnoughItems:5.10.184")
|
||||
|
||||
shadow "com.electronwill.night-config:core:3.6.3"
|
||||
shadow "com.electronwill.night-config:toml:3.6.3"
|
||||
|
||||
@@ -15,5 +15,5 @@ archives_base_name = lambdacontrols
|
||||
# Dependencies
|
||||
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
|
||||
fabric_version=0.32.0+1.16
|
||||
spruceui_version=2.0.4-1.16
|
||||
modmenu_version=1.14.6+build.31
|
||||
spruceui_version=2.1.1-1.16
|
||||
modmenu_version=1.16.8
|
||||
|
||||
@@ -18,6 +18,7 @@ import me.lambdaurora.spruceui.Position;
|
||||
import me.lambdaurora.spruceui.SpruceTexts;
|
||||
import me.lambdaurora.spruceui.option.*;
|
||||
import me.lambdaurora.spruceui.screen.SpruceScreen;
|
||||
import me.lambdaurora.spruceui.widget.AbstractSpruceWidget;
|
||||
import me.lambdaurora.spruceui.widget.SpruceLabelWidget;
|
||||
import me.lambdaurora.spruceui.widget.container.SpruceContainerWidget;
|
||||
import me.lambdaurora.spruceui.widget.container.SpruceOptionListWidget;
|
||||
@@ -30,6 +31,7 @@ import net.minecraft.client.resource.language.I18n;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.MutableText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.Util;
|
||||
@@ -39,6 +41,7 @@ import org.lwjgl.glfw.GLFW;
|
||||
* Represents the LambdaControls settings screen.
|
||||
*/
|
||||
public class LambdaControlsSettingsScreen extends SpruceScreen {
|
||||
private static final Text SDL2_GAMEPAD_TOOL = new LiteralText("SDL2 Gamepad Tool").formatted(Formatting.GREEN);
|
||||
public static final String GAMEPAD_TOOL_URL = "https://generalarcade.com/gamepadtool/";
|
||||
final LambdaControlsClient mod;
|
||||
private final Screen parent;
|
||||
@@ -71,7 +74,6 @@ public class LambdaControlsSettingsScreen extends SpruceScreen {
|
||||
private final MutableText controllerMappingsUrlText = new LiteralText("(")
|
||||
.append(new LiteralText(GAMEPAD_TOOL_URL).formatted(Formatting.GOLD))
|
||||
.append("),");
|
||||
private SpruceLabelWidget gamepadToolUrlLabel;
|
||||
|
||||
public LambdaControlsSettingsScreen(Screen parent, boolean hideControls) {
|
||||
super(new TranslatableText("lambdacontrols.title.settings"));
|
||||
@@ -273,11 +275,6 @@ public class LambdaControlsSettingsScreen extends SpruceScreen {
|
||||
|
||||
this.buildTabs();
|
||||
|
||||
this.gamepadToolUrlLabel = new SpruceLabelWidget(Position.of(this.width / 2, this.height - 29 - (5 + this.textRenderer.fontHeight) * 2), this.controllerMappingsUrlText, this.width,
|
||||
label -> Util.getOperatingSystem().open(GAMEPAD_TOOL_URL), true);
|
||||
this.gamepadToolUrlLabel.setTooltip(new TranslatableText("chat.link.open"));
|
||||
this.addChild(this.gamepadToolUrlLabel);
|
||||
|
||||
this.addChild(this.resetOption.createWidget(Position.of(this.width / 2 - 155, this.height - 29), 150));
|
||||
this.addButton(new ButtonWidget(this.width / 2 - 155 + 160, this.height - 29, 150, 20, SpruceTexts.GUI_DONE,
|
||||
btn -> this.client.openScreen(this.parent)));
|
||||
@@ -286,7 +283,7 @@ public class LambdaControlsSettingsScreen extends SpruceScreen {
|
||||
public void buildTabs() {
|
||||
SpruceTabbedWidget tabs = new SpruceTabbedWidget(Position.of(0, 24), this.width, this.height - 32 - 24,
|
||||
null,
|
||||
Math.max(100, this.width / 8), 0);
|
||||
Math.max(110, this.width / 8), 0);
|
||||
this.addChild(tabs);
|
||||
|
||||
tabs.addSeparatorEntry(new TranslatableText("lambdacontrols.menu.separator.general"));
|
||||
@@ -337,11 +334,38 @@ public class LambdaControlsSettingsScreen extends SpruceScreen {
|
||||
return new ControllerControlsWidget(Position.origin(), width, height);
|
||||
}
|
||||
|
||||
public SpruceOptionListWidget buildControllerTab(int width, int height) {
|
||||
SpruceOptionListWidget list = new SpruceOptionListWidget(Position.origin(), width, height);
|
||||
public AbstractSpruceWidget buildControllerTab(int width, int height) {
|
||||
SpruceContainerWidget root = new SpruceContainerWidget(Position.origin(), width, height);
|
||||
|
||||
SpruceLabelWidget aboutMappings1 = new SpruceLabelWidget(Position.of(width / 2, 2),
|
||||
new TranslatableText("lambdacontrols.controller.mappings.1", SDL2_GAMEPAD_TOOL),
|
||||
width, true);
|
||||
|
||||
SpruceLabelWidget gamepadToolUrlLabel = new SpruceLabelWidget(Position.of(width / 2, aboutMappings1.getHeight() + 4),
|
||||
this.controllerMappingsUrlText, width,
|
||||
label -> Util.getOperatingSystem().open(GAMEPAD_TOOL_URL), true);
|
||||
gamepadToolUrlLabel.setTooltip(new TranslatableText("chat.link.open"));
|
||||
|
||||
SpruceLabelWidget aboutMappings3 = new SpruceLabelWidget(Position.of(width / 2,
|
||||
aboutMappings1.getHeight() + gamepadToolUrlLabel.getHeight() + 6),
|
||||
new TranslatableText("lambdacontrols.controller.mappings.3", Formatting.GREEN.toString(), Formatting.RESET.toString()),
|
||||
width, true);
|
||||
|
||||
int listHeight = height - 8 - aboutMappings1.getHeight() - aboutMappings3.getHeight() - gamepadToolUrlLabel.getHeight();
|
||||
SpruceContainerWidget labels = new SpruceContainerWidget(Position.of(0,
|
||||
listHeight),
|
||||
width, height - listHeight);
|
||||
labels.addChild(aboutMappings1);
|
||||
labels.addChild(gamepadToolUrlLabel);
|
||||
labels.addChild(aboutMappings3);
|
||||
|
||||
SpruceOptionListWidget list = new SpruceOptionListWidget(Position.origin(), width, listHeight);
|
||||
list.addSingleOptionEntry(this.controllerOption);
|
||||
list.addSingleOptionEntry(this.secondControllerOption);
|
||||
return list;
|
||||
|
||||
root.addChild(list);
|
||||
root.addChild(labels);
|
||||
return root;
|
||||
}
|
||||
|
||||
public SpruceContainerWidget buildMappingsStringEditorTab(int width, int height) {
|
||||
@@ -351,7 +375,7 @@ public class LambdaControlsSettingsScreen extends SpruceScreen {
|
||||
@Override
|
||||
public void renderTitle(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||
drawCenteredString(matrices, this.textRenderer, I18n.translate("lambdacontrols.menu.title"), this.width / 2, 8, 16777215);
|
||||
drawCenteredString(matrices, this.textRenderer, I18n.translate("lambdacontrols.controller.mappings.1", Formatting.GREEN.toString(), Formatting.RESET.toString()), this.width / 2, this.height - 29 - (5 + this.textRenderer.fontHeight) * 3, 10526880);
|
||||
drawCenteredString(matrices, this.textRenderer, I18n.translate("lambdacontrols.controller.mappings.3", Formatting.GREEN.toString(), Formatting.RESET.toString()), this.width / 2, this.height - 29 - (5 + this.textRenderer.fontHeight), 10526880);
|
||||
// drawCenteredString(matrices, this.textRenderer, I18n.translate("lambdacontrols.controller.mappings.1", Formatting.GREEN.toString(), Formatting.RESET.toString()), this.width / 2, this.height - 29 - (5 + this.textRenderer.fontHeight) * 3, 10526880);
|
||||
// drawCenteredString(matrices, this.textRenderer, I18n.translate("lambdacontrols.controller.mappings.3", Formatting.GREEN.toString(), Formatting.RESET.toString()), this.width / 2, this.height - 29 - (5 + this.textRenderer.fontHeight), 10526880);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ public class MappingsStringInputWidget extends SpruceContainerWidget {
|
||||
}
|
||||
|
||||
int textFieldWidth = (int) (this.width * (5.0 / 6.0));
|
||||
this.textArea = new SpruceTextAreaWidget(Position.of(this, this.width / 2 - textFieldWidth / 2, 0), this.client.textRenderer, textFieldWidth, this.height - 50, new LiteralText(mappings));
|
||||
this.textArea = new SpruceTextAreaWidget(Position.of(this, this.width / 2 - textFieldWidth / 2, 0), textFieldWidth, this.height - 50, new LiteralText(mappings));
|
||||
this.textArea.setText(mappings);
|
||||
// Display as many lines as possible
|
||||
this.textArea.setDisplayedLines(this.textArea.getInnerHeight() / this.client.textRenderer.fontHeight);
|
||||
|
||||
@@ -47,7 +47,7 @@ public class ControllerControlsWidget extends SpruceContainerWidget {
|
||||
this.addChild(new SpruceButtonWidget(Position.of(this, this.width / 2 - 155, 18), 310, 20,
|
||||
new TranslatableText("lambdacontrols.menu.keyboard_controls"),
|
||||
btn -> this.client.openScreen(new ControlsOptionsScreen(null, this.client.options))));
|
||||
this.bindingsListWidget = new ControlsListWidget(Position.of(this, 0, 43), this.width, this.height - 43 - 43, this);
|
||||
this.bindingsListWidget = new ControlsListWidget(Position.of(this, 0, 43), this.width, this.height - 43 - 35, this);
|
||||
this.addChild(this.bindingsListWidget);
|
||||
this.addChild(this.resetButton = new SpruceButtonWidget(Position.of(this, this.width / 2 - 155, this.height - 29), 150, 20,
|
||||
SpruceTexts.CONTROLS_RESET_ALL,
|
||||
@@ -56,7 +56,8 @@ public class ControllerControlsWidget extends SpruceContainerWidget {
|
||||
|
||||
@Override
|
||||
public void renderWidget(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||
drawCenteredText(matrices, this.client.textRenderer, new TranslatableText("lambdacontrols.menu.title.controller_controls"), this.width / 2, 8, 16777215);
|
||||
drawCenteredText(matrices, this.client.textRenderer, new TranslatableText("lambdacontrols.menu.title.controller_controls"),
|
||||
this.getX() + this.width / 2, this.getY() + 4, 16777215);
|
||||
this.resetButton.setActive(InputManager.streamBindings().anyMatch(Predicates.not(ButtonBinding::isDefault)));
|
||||
super.renderWidget(matrices, mouseX, mouseY, delta);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import me.lambdaurora.spruceui.widget.SpruceButtonWidget;
|
||||
import me.lambdaurora.spruceui.widget.SpruceSeparatorWidget;
|
||||
import me.lambdaurora.spruceui.widget.SpruceWidget;
|
||||
import me.lambdaurora.spruceui.widget.container.SpruceEntryListWidget;
|
||||
import me.lambdaurora.spruceui.widget.container.SpruceParentWidget;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
@@ -73,7 +74,7 @@ public class ControlsListWidget extends SpruceEntryListWidget<ControlsListWidget
|
||||
return this.getWidth() / 2 - baseWidth / 2 + 72 - this.maxTextLength;
|
||||
}
|
||||
|
||||
public class ButtonBindingEntry extends Entry {
|
||||
public class ButtonBindingEntry extends Entry implements SpruceParentWidget<SpruceWidget> {
|
||||
private final List<SpruceWidget> children = new ArrayList<>();
|
||||
private @Nullable SpruceWidget focused;
|
||||
private final ButtonBinding binding;
|
||||
@@ -86,7 +87,7 @@ public class ControlsListWidget extends SpruceEntryListWidget<ControlsListWidget
|
||||
super(parent);
|
||||
this.binding = binding;
|
||||
this.bindingName = I18n.translate(this.binding.getTranslationKey());
|
||||
this.editButton = new ControllerButtonWidget(Position.of(this, this.getWidth() - 55 - 110, 0), 110, this.binding, btn -> {
|
||||
this.editButton = new ControllerButtonWidget(Position.of(this, parent.getWidth() / 2 - 8, 0), 110, this.binding, btn -> {
|
||||
gui.focusedBinding = binding;
|
||||
LambdaControlsClient.get().input.beginControlsInput(gui);
|
||||
}) {
|
||||
@@ -95,14 +96,18 @@ public class ControlsListWidget extends SpruceEntryListWidget<ControlsListWidget
|
||||
}
|
||||
};
|
||||
this.children.add(editButton);
|
||||
this.resetButton = new SpruceButtonWidget(Position.of(this, this.getWidth() - 50, 0), 50, 20, new TranslatableText("controls.reset"),
|
||||
this.resetButton = new SpruceButtonWidget(Position.of(this,
|
||||
this.editButton.getPosition().getRelativeX() + this.editButton.getWidth() + 2, 0),
|
||||
44, 20, new TranslatableText("controls.reset"),
|
||||
btn -> LambdaControlsClient.get().config.setButtonBinding(binding, binding.getDefaultButton())) {
|
||||
protected Optional<Text> getNarrationMessage() {
|
||||
return Optional.of(new TranslatableText("narrator.controls.reset", bindingName));
|
||||
}
|
||||
};
|
||||
this.children.add(this.resetButton);
|
||||
this.unbindButton = new SpruceButtonWidget(Position.of(this, this.getWidth() - 50, 0), 50, 20, SpruceTexts.GUI_UNBIND,
|
||||
this.unbindButton = new SpruceButtonWidget(Position.of(this,
|
||||
this.editButton.getPosition().getRelativeX() + this.editButton.getWidth() + 2, 0),
|
||||
this.resetButton.getWidth(), this.resetButton.getHeight(), SpruceTexts.GUI_UNBIND,
|
||||
btn -> {
|
||||
LambdaControlsClient.get().config.setButtonBinding(binding, UNBOUND);
|
||||
gui.focusedBinding = null;
|
||||
@@ -113,16 +118,22 @@ public class ControlsListWidget extends SpruceEntryListWidget<ControlsListWidget
|
||||
}
|
||||
};
|
||||
this.children.add(this.unbindButton);
|
||||
|
||||
this.position.setRelativeX(4);
|
||||
this.width -= 10;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SpruceWidget> children() {
|
||||
return this.children;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable SpruceWidget getFocused() {
|
||||
return this.focused;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFocused(@Nullable SpruceWidget focused) {
|
||||
if (this.focused == focused)
|
||||
return;
|
||||
@@ -136,21 +147,6 @@ public class ControlsListWidget extends SpruceEntryListWidget<ControlsListWidget
|
||||
return this.children.stream().mapToInt(SpruceWidget::getHeight).reduce(Integer::max).orElse(0) + 4;
|
||||
}
|
||||
|
||||
public Optional<SpruceWidget> hoveredElement(double mouseX, double mouseY) {
|
||||
Iterator<SpruceWidget> it = this.children().iterator();
|
||||
|
||||
SpruceWidget element;
|
||||
do {
|
||||
if (!it.hasNext()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
element = it.next();
|
||||
} while (!element.isMouseOver(mouseX, mouseY));
|
||||
|
||||
return Optional.of(element);
|
||||
}
|
||||
|
||||
/* Input */
|
||||
|
||||
@Override
|
||||
@@ -362,7 +358,6 @@ public class ControlsListWidget extends SpruceEntryListWidget<ControlsListWidget
|
||||
|
||||
protected Entry(ControlsListWidget parent) {
|
||||
this.parent = parent;
|
||||
this.position.setRelativeX(this.parent.getRowLeft());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -63,8 +63,8 @@
|
||||
"lambdacontrols.button.unknown": "Unknown (%d)",
|
||||
"lambdacontrols.controller.connected": "Controller %d connected.",
|
||||
"lambdacontrols.controller.disconnected": "Controller %d disconnected.",
|
||||
"lambdacontrols.controller.mappings.1": "To configure the controller mappings, please use %sSDL2 Gamepad Tool%s",
|
||||
"lambdacontrols.controller.mappings.3": "and put the mapping in `%s.minecraft/config/gamecontrollerdb.txt%s`.",
|
||||
"lambdacontrols.controller.mappings.1": "To configure the controller mappings, please use %s",
|
||||
"lambdacontrols.controller.mappings.3": "and paste the mapping in the mappings file editor.",
|
||||
"lambdacontrols.controller.mappings.error": "Error while loading mappings.",
|
||||
"lambdacontrols.controller.mappings.error.write": "Error while writing mappings to file.",
|
||||
"lambdacontrols.controller.mappings.updated": "Updated mappings!",
|
||||
|
||||
Reference in New Issue
Block a user