forked from Clones/Controlify
✏️ Radial menu: move editing of actions into the config screen as it's more intuitive
This commit is contained in:
@ -308,6 +308,20 @@ public class ControllerConfigScreenFactory {
|
|||||||
.name(Component.translatable("controlify.gui.group.controls"));
|
.name(Component.translatable("controlify.gui.group.controls"));
|
||||||
|
|
||||||
List<OptionBindPair> optionBinds = new ArrayList<>();
|
List<OptionBindPair> optionBinds = new ArrayList<>();
|
||||||
|
|
||||||
|
ButtonOption editRadialButton = ButtonOption.createBuilder()
|
||||||
|
.name(Component.translatable("controlify.gui.radial_menu"))
|
||||||
|
.description(OptionDescription.of(Component.translatable("controlify.gui.radial_menu.tooltip")))
|
||||||
|
.action((screen, opt) -> Minecraft.getInstance().setScreen(new RadialMenuScreen(controller, true, screen)))
|
||||||
|
.text(Component.translatable("controlify.gui.radial_menu.btn_text"))
|
||||||
|
.build();
|
||||||
|
Option<?> radialBind = controller.bindings().RADIAL_MENU.startYACLOption()
|
||||||
|
.listener((opt, val) -> updateConflictingBinds(optionBinds))
|
||||||
|
.build();
|
||||||
|
optionBinds.add(new OptionBindPair(radialBind, controller.bindings().RADIAL_MENU));
|
||||||
|
category.option(editRadialButton);
|
||||||
|
category.option(radialBind);
|
||||||
|
|
||||||
groupBindings(controller.bindings().registry().values()).forEach((categoryName, bindGroup) -> {
|
groupBindings(controller.bindings().registry().values()).forEach((categoryName, bindGroup) -> {
|
||||||
var controlsGroup = OptionGroup.createBuilder()
|
var controlsGroup = OptionGroup.createBuilder()
|
||||||
.name(categoryName);
|
.name(categoryName);
|
||||||
|
@ -27,6 +27,7 @@ import net.minecraft.client.gui.navigation.FocusNavigationEvent;
|
|||||||
import net.minecraft.client.gui.navigation.ScreenRectangle;
|
import net.minecraft.client.gui.navigation.ScreenRectangle;
|
||||||
import net.minecraft.client.gui.screens.Screen;
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
|
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
|
||||||
|
import net.minecraft.network.chat.CommonComponents;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.sounds.SoundEvents;
|
import net.minecraft.sounds.SoundEvents;
|
||||||
@ -42,21 +43,23 @@ public class RadialMenuScreen extends Screen implements ScreenControllerEventLis
|
|||||||
public static final ResourceLocation EMPTY_ACTION = new ResourceLocation("controlify", "empty_action");
|
public static final ResourceLocation EMPTY_ACTION = new ResourceLocation("controlify", "empty_action");
|
||||||
|
|
||||||
private final Controller<?, ?> controller;
|
private final Controller<?, ?> controller;
|
||||||
|
private final boolean editMode;
|
||||||
public RadialMenuScreen(Controller<?, ?> controller) {
|
private final Screen parent;
|
||||||
super(Component.empty());
|
|
||||||
this.controller = controller;
|
|
||||||
}
|
|
||||||
|
|
||||||
private final RadialButton[] buttons = new RadialButton[8];
|
private final RadialButton[] buttons = new RadialButton[8];
|
||||||
private int selectedButton = -1;
|
private int selectedButton = -1;
|
||||||
private int idleTicks;
|
private int idleTicks;
|
||||||
private boolean editMode;
|
|
||||||
private boolean isEditing;
|
private boolean isEditing;
|
||||||
|
|
||||||
private PositionedComponent<GuideActionRenderer<Object>> editModeGuide;
|
|
||||||
private ActionSelectList actionSelectList;
|
private ActionSelectList actionSelectList;
|
||||||
|
|
||||||
|
public RadialMenuScreen(Controller<?, ?> controller, boolean editMode, Screen parent) {
|
||||||
|
super(Component.empty());
|
||||||
|
this.controller = controller;
|
||||||
|
this.editMode = editMode;
|
||||||
|
this.parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void init() {
|
||||||
int centerX = this.width / 2;
|
int centerX = this.width / 2;
|
||||||
@ -79,47 +82,36 @@ public class RadialMenuScreen extends Screen implements ScreenControllerEventLis
|
|||||||
}
|
}
|
||||||
Animator.INSTANCE.play(animation);
|
Animator.INSTANCE.play(animation);
|
||||||
|
|
||||||
editModeGuide = addRenderableWidget(new PositionedComponent<>(
|
if (editMode) {
|
||||||
new GuideActionRenderer<>(
|
var exitGuide = addRenderableWidget(new PositionedComponent<>(
|
||||||
new GuideAction<>(
|
new GuideActionRenderer<>(
|
||||||
controller.bindings().GUI_ABSTRACT_ACTION_2,
|
new GuideAction<>(
|
||||||
obj -> Optional.of(Component.literal(!editMode ? "Edit Mode" : "Done Editing"))
|
controller.bindings().GUI_BACK,
|
||||||
),
|
obj -> Optional.of(CommonComponents.GUI_DONE)
|
||||||
false,
|
),
|
||||||
true
|
false,
|
||||||
),
|
true
|
||||||
AnchorPoint.BOTTOM_CENTER,
|
),
|
||||||
0, -10,
|
AnchorPoint.BOTTOM_CENTER,
|
||||||
AnchorPoint.BOTTOM_CENTER
|
0, -10,
|
||||||
));
|
AnchorPoint.BOTTOM_CENTER
|
||||||
|
));
|
||||||
|
|
||||||
editModeGuide.getComponent().updateName(null);
|
exitGuide.getComponent().updateName(null);
|
||||||
editModeGuide.updatePosition(width, height);
|
exitGuide.updatePosition(width, height);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onControllerInput(Controller<?, ?> controller) {
|
public void onControllerInput(Controller<?, ?> controller) {
|
||||||
if (this.controller != controller) return;
|
if (this.controller != controller) return;
|
||||||
|
|
||||||
if (!controller.bindings().RADIAL_MENU.held()) {
|
if (!editMode && !controller.bindings().RADIAL_MENU.held()) {
|
||||||
if (!isEditing && !editMode) {
|
if (selectedButton != -1 && buttons[selectedButton].invoke()) {
|
||||||
if (selectedButton != -1 && buttons[selectedButton].invoke()) {
|
playClickSound();
|
||||||
playClickSound();
|
|
||||||
}
|
|
||||||
|
|
||||||
onClose();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (controller.bindings().GUI_ABSTRACT_ACTION_2.justPressed()) {
|
onClose();
|
||||||
editMode = !editMode;
|
|
||||||
editModeGuide.getComponent().updateName(null);
|
|
||||||
editModeGuide.updatePosition(width, height);
|
|
||||||
playClickSound();
|
|
||||||
|
|
||||||
if (!editMode) {
|
|
||||||
finishEditing();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isEditing && controller.state() instanceof GamepadState state) {
|
if (!isEditing && controller.state() instanceof GamepadState state) {
|
||||||
@ -158,6 +150,18 @@ public class RadialMenuScreen extends Screen implements ScreenControllerEventLis
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
|
||||||
|
if (minecraft.level == null)
|
||||||
|
renderDirtBackground(graphics);
|
||||||
|
|
||||||
|
super.render(graphics, mouseX, mouseY, delta);
|
||||||
|
|
||||||
|
if (!editMode) {
|
||||||
|
graphics.drawCenteredString(font, Component.translatable("controlify.radial_menu.configure_hint"), width / 2, height - 10 - font.lineHeight, -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void playClickSound() {
|
private void playClickSound() {
|
||||||
minecraft.getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1f));
|
minecraft.getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1f));
|
||||||
}
|
}
|
||||||
@ -171,7 +175,7 @@ public class RadialMenuScreen extends Screen implements ScreenControllerEventLis
|
|||||||
@Override
|
@Override
|
||||||
public void onClose() {
|
public void onClose() {
|
||||||
Controlify.instance().config().saveIfDirty();
|
Controlify.instance().config().saveIfDirty();
|
||||||
super.onClose();
|
minecraft.setScreen(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class RadialButton implements Renderable, GuiEventListener, NarratableEntry, ComponentProcessor {
|
public class RadialButton implements Renderable, GuiEventListener, NarratableEntry, ComponentProcessor {
|
||||||
@ -180,24 +184,15 @@ public class RadialMenuScreen extends Screen implements ScreenControllerEventLis
|
|||||||
private int x, y;
|
private int x, y;
|
||||||
private float translateX, translateY;
|
private float translateX, translateY;
|
||||||
private boolean focused;
|
private boolean focused;
|
||||||
private final ControllerBinding binding;
|
private ControllerBinding binding;
|
||||||
private final MultiLineLabel name;
|
private MultiLineLabel name;
|
||||||
private final RadialIcons.Icon icon;
|
private RadialIcons.Icon icon;
|
||||||
|
|
||||||
private RadialButton(int index, int x, int y) {
|
private RadialButton(int index, float x, float y) {
|
||||||
this.x = x;
|
this.setX(x);
|
||||||
this.y = y;
|
this.setY(y);
|
||||||
|
|
||||||
ResourceLocation binding = controller.config().radialActions[index];
|
this.setAction(controller.config().radialActions[index]);
|
||||||
if (!EMPTY_ACTION.equals(binding)) {
|
|
||||||
this.binding = controller.bindings().get(binding);
|
|
||||||
this.icon = RadialIcons.getIcons().get(this.binding.radialIcon().orElseThrow());
|
|
||||||
this.name = MultiLineLabel.create(font, this.binding.name(), 76);
|
|
||||||
} else {
|
|
||||||
this.binding = null;
|
|
||||||
this.name = MultiLineLabel.EMPTY;
|
|
||||||
this.icon = RadialIcons.getIcons().get(RadialIcons.EMPTY);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -226,6 +221,18 @@ public class RadialMenuScreen extends Screen implements ScreenControllerEventLis
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setAction(ResourceLocation binding) {
|
||||||
|
if (!EMPTY_ACTION.equals(binding)) {
|
||||||
|
this.binding = controller.bindings().get(binding);
|
||||||
|
this.icon = RadialIcons.getIcons().get(this.binding.radialIcon().orElseThrow());
|
||||||
|
this.name = MultiLineLabel.create(font, this.binding.name(), 76);
|
||||||
|
} else {
|
||||||
|
this.binding = null;
|
||||||
|
this.name = MultiLineLabel.EMPTY;
|
||||||
|
this.icon = RadialIcons.getIcons().get(RadialIcons.EMPTY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int getX() {
|
public int getX() {
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
@ -452,6 +459,8 @@ public class RadialMenuScreen extends Screen implements ScreenControllerEventLis
|
|||||||
controller.config().radialActions[radialIndex] = binding;
|
controller.config().radialActions[radialIndex] = binding;
|
||||||
Controlify.instance().config().setDirty();
|
Controlify.instance().config().setDirty();
|
||||||
|
|
||||||
|
buttons[radialIndex].setAction(binding);
|
||||||
|
|
||||||
playClickSound();
|
playClickSound();
|
||||||
finishEditing();
|
finishEditing();
|
||||||
return true;
|
return true;
|
||||||
|
@ -109,7 +109,7 @@ public class InGameInputHandler {
|
|||||||
shouldShowPlayerList = controller.bindings().SHOW_PLAYER_LIST.held();
|
shouldShowPlayerList = controller.bindings().SHOW_PLAYER_LIST.held();
|
||||||
|
|
||||||
if (controller.bindings().RADIAL_MENU.justPressed()) {
|
if (controller.bindings().RADIAL_MENU.justPressed()) {
|
||||||
minecraft.setScreen(new RadialMenuScreen(controller));
|
minecraft.setScreen(new RadialMenuScreen(controller, false, null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,8 +109,9 @@
|
|||||||
"controlify.gui.test_vibration": "Test Vibration",
|
"controlify.gui.test_vibration": "Test Vibration",
|
||||||
"controlify.gui.test_vibration.tooltip": "Test the vibration of your controller.",
|
"controlify.gui.test_vibration.tooltip": "Test the vibration of your controller.",
|
||||||
|
|
||||||
"controlify.gui.group.radial_menu": "Radial Menu",
|
"controlify.gui.radial_menu": "Radial Menu",
|
||||||
"controlify.gui.radial_menu_action": "Action #%s",
|
"controlify.gui.radial_menu.tooltip": "Open up the radial menu to configure what each button does.",
|
||||||
|
"controlify.gui.radial_menu.btn_text": "CONFIGURE",
|
||||||
"controlify.gui.group.controls": "Controls",
|
"controlify.gui.group.controls": "Controls",
|
||||||
"controlify.gui.group.controls.tooltip": "Adjust the controller controls.",
|
"controlify.gui.group.controls.tooltip": "Adjust the controller controls.",
|
||||||
"controlify.gui.bind_input_awaiting": "Press any button",
|
"controlify.gui.bind_input_awaiting": "Press any button",
|
||||||
@ -282,6 +283,8 @@
|
|||||||
"controlify.calibration.later": "Maybe Later",
|
"controlify.calibration.later": "Maybe Later",
|
||||||
"controlify.calibration.later.tooltip": "You must calibrate to use the controller. Pressing this will deactivate the controller and you will have to use it again to calibrate.",
|
"controlify.calibration.later.tooltip": "You must calibrate to use the controller. Pressing this will deactivate the controller and you will have to use it again to calibrate.",
|
||||||
|
|
||||||
|
"controlify.radial_menu.configure_hint": "Configure actions in the controller settings.",
|
||||||
|
|
||||||
"controlify.beta.title": "Controlify Beta Notice",
|
"controlify.beta.title": "Controlify Beta Notice",
|
||||||
"controlify.beta.message": "You are currently using Controlify Beta.\n\nThis mod is a work in progress and will contain many bugs. Please, if you spot a bug in this mod or have a suggestion to make it even better, please create an issue on the %s!\n\nYou can always find the link to the issue tracker in Controlify's settings menu.",
|
"controlify.beta.message": "You are currently using Controlify Beta.\n\nThis mod is a work in progress and will contain many bugs. Please, if you spot a bug in this mod or have a suggestion to make it even better, please create an issue on the %s!\n\nYou can always find the link to the issue tracker in Controlify's settings menu.",
|
||||||
"controlify.beta.message.link": "issue tracker",
|
"controlify.beta.message.link": "issue tracker",
|
||||||
|
Reference in New Issue
Block a user