1
0
mirror of https://github.com/chylex/Better-Controls.git synced 2024-11-25 19:42:45 +01:00

Compare commits

...

3 Commits

Author SHA1 Message Date
76af39fb18
Release 1.2.4 for Minecraft 1.19.3+ 2022-12-12 21:00:33 +01:00
38fb2a1f1e
Fix positioning of buttons in Controls screen 2022-12-12 20:48:15 +01:00
e748c21efe
Fix compilation with Minecraft 1.19.3
Closes #26
2022-12-12 19:26:46 +01:00
6 changed files with 41 additions and 24 deletions

View File

@ -3,21 +3,21 @@ modId=bettercontrols
modName=Better Controls
modDescription=Adds many powerful key bindings and options to control your movement.\\n\\nThe features complement vanilla mechanics without giving unfair advantages, so server use should be fine.
modAuthor=chylex
modVersion=1.2.3b
modVersion=1.2.4
modLicense=MPL-2.0
modSourcesURL=https://github.com/chylex/Better-Controls
modIssuesURL=https://github.com/chylex/Better-Controls/issues
# Dependencies
minecraftVersion=22w42a
#forgeVersion=41.1.0
fabricVersion=0.14.10
minecraftVersion=1.19.3
forgeVersion=44.0.11
fabricVersion=0.14.11
loomVersion=0.12
mixinVersion=0.8.5
# Constraints
minimumMinecraftVersion=1.19
minimumForgeVersion=41.0.94
minimumMinecraftVersion=1.19.3
minimumForgeVersion=44.0.0
minimumFabricVersion=0.7.4
# Gradle

View File

@ -242,7 +242,7 @@ public class BetterControlsScreen extends OptionsSubScreen {
elements.add(new TextWidget(0, y, ROW_WIDTH, ROW_HEIGHT, text("Miscellaneous"), CENTER));
y = generateMiscellaneousOptions(y + ROW_HEIGHT, elements) + TITLE_MARGIN_TOP;
addRenderableWidget(new Button(width / 2 - 99, height - 29, 200, 20, CommonComponents.GUI_DONE, btn -> minecraft.setScreen(lastScreen)));
addRenderableWidget(Button.builder(CommonComponents.GUI_DONE, btn -> minecraft.setScreen(lastScreen)).pos(width / 2 - 99, height - 29).size(200, 20).build());
addWidget(optionsWidget = new OptionListWidget(21, height - 32, width, height, elements, y - TITLE_MARGIN_TOP + BOTTOM_PADDING));
}

View File

@ -4,7 +4,7 @@ import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.client.gui.components.ContainerObjectSelectionList;
import net.minecraft.client.gui.components.Widget;
import net.minecraft.client.gui.components.Renderable;
import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.narration.NarratableEntry;
import org.jetbrains.annotations.NotNull;
@ -35,14 +35,14 @@ public final class OptionListWidget extends ContainerObjectSelectionList<Entry>
return new Offset(widget.getX(), widget.getY());
}
else if (element instanceof final AbstractWidget widget) {
return new Offset(widget.x, widget.y);
return new Offset(widget.getX(), widget.getY());
}
else {
return new Offset(0, 0);
}
}
public interface OptionWidget extends GuiEventListener, Widget {
public interface OptionWidget extends GuiEventListener, Renderable {
int getX();
int getY();
void setX(int x);
@ -82,13 +82,15 @@ public final class OptionListWidget extends ContainerObjectSelectionList<Entry>
this.offsets = elements.stream().collect(Collectors.toMap(Function.identity(), OptionListWidget::getElementOffset));
}
@NotNull
@Override
public @NotNull List<? extends GuiEventListener> children() {
public List<? extends GuiEventListener> children() {
return Collections.unmodifiableList(elements);
}
@NotNull
@Override
public @NotNull List<? extends NarratableEntry> narratables() {
public List<? extends NarratableEntry> narratables() {
return Collections.unmodifiableList(narratables);
}
@ -98,16 +100,16 @@ public final class OptionListWidget extends ContainerObjectSelectionList<Entry>
final Offset offset = offsets.get(element);
if (element instanceof final AbstractWidget widget) {
widget.x = x + offset.x;
widget.y = y + offset.y;
widget.setX(x + offset.x);
widget.setY(y + offset.y);
}
else if (element instanceof final OptionWidget widget) {
widget.setX(x + offset.x);
widget.setY(y + offset.y);
}
if (element instanceof final Widget widget) {
widget.render(matrices, mouseX, mouseY, tickDelta);
if (element instanceof final Renderable renderable) {
renderable.render(matrices, mouseX, mouseY, tickDelta);
}
}
}

View File

@ -44,8 +44,9 @@ public final class DiscreteValueSliderWidget<T> extends AbstractSliderButton {
}
}
@NotNull
@Override
protected @NotNull MutableComponent createNarrationMessage() {
protected MutableComponent createNarrationMessage() {
return Component.translatable("gui.narrate.slider", narration.plainCopy().append(" ").append(getMessage()));
}
}

View File

@ -22,7 +22,7 @@ public final class KeyBindingWidget extends Button {
private boolean isEditing;
public KeyBindingWidget(final int x, final int y, final int width, final int height, final Component bindingName, final KeyMapping binding, final Consumer<KeyBindingWidget> onEditingStarted) {
super(x, y, width, height, Component.empty(), btn -> {});
super(x, y, width, height, Component.empty(), btn -> {}, DEFAULT_NARRATION);
this.binding = binding;
this.bindingName = bindingName;
this.onEditingStarted = onEditingStarted;
@ -38,8 +38,9 @@ public final class KeyBindingWidget extends Button {
button.active = !binding.isUnbound();
}
@NotNull
@Override
protected @NotNull MutableComponent createNarrationMessage() {
protected MutableComponent createNarrationMessage() {
return binding.isUnbound() ? Component.translatable("narrator.controls.unbound", bindingName) : Component.translatable("narrator.controls.bound", bindingName, super.createNarrationMessage());
}

View File

@ -9,7 +9,9 @@ import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.screens.OptionsSubScreen;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.controls.ControlsScreen;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
@ -29,25 +31,31 @@ public abstract class HookControlsScreen extends OptionsSubScreen {
int leftBottomY = 0;
int rightBottomY = 0;
AbstractWidget doneButton = null;
for (final GuiEventListener child : children()) {
if (!(child instanceof AbstractWidget widget)) {
continue;
}
final int bottomY = widget.y + widget.getHeight();
if (widget instanceof Button button && button.getMessage() == CommonComponents.GUI_DONE) {
doneButton = widget;
continue;
}
if (widget.x + widget.getWidth() < center) {
final int bottomY = widget.getY() + widget.getHeight();
if (widget.getX() + widget.getWidth() < center) {
leftBottomY = Math.max(leftBottomY, bottomY);
}
if (widget.x >= center) {
if (widget.getX() >= center) {
rightBottomY = Math.max(rightBottomY, bottomY);
}
}
final int x, y;
if (leftBottomY < rightBottomY) {
if (leftBottomY <= rightBottomY) {
x = center - 155;
y = leftBottomY + 4;
}
@ -56,6 +64,11 @@ public abstract class HookControlsScreen extends OptionsSubScreen {
y = rightBottomY + 4;
}
addRenderableWidget(new Button(x, y, 150, 20, BetterControlsScreen.TITLE.plainCopy().append("..."), btn -> Minecraft.getInstance().setScreen(new BetterControlsScreen(screen))));
final MutableComponent buttonTitle = BetterControlsScreen.TITLE.plainCopy().append("...");
addRenderableWidget(Button.builder(buttonTitle, btn -> Minecraft.getInstance().setScreen(new BetterControlsScreen(screen))).pos(x, y).size(150, 20).build());
if (doneButton != null) {
doneButton.setY(y + 24);
}
}
}