Skip to content

Commit

Permalink
WIP: Improve Instrument and MusicVenueTool overlays.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aeronica committed Mar 16, 2024
1 parent 742bf65 commit ea3250d
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 28 deletions.
3 changes: 3 additions & 0 deletions src/generated/resources/assets/mxtune/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
"enum.mxtune.group.mode.pin": "Pin",
"enum.mxtune.group.mode.pin.help01": "Players must know the pin to join your group.",
"enum.mxtune.group.mode.pin.help02": "Click to toggle access mode.",
"enum.mxtune.item.overlay.position.center": "Center",
"enum.mxtune.item.overlay.position.left": "Left",
"enum.mxtune.item.overlay.position.right": "Right",
"enum.mxtune.tool_state.type.done": "Done",
"enum.mxtune.tool_state.type.end": "End",
"enum.mxtune.tool_state.type.remove": "Remove",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ private void addEnums()
addEnum("group.mode.open", "Open");
addEnum("group.mode.open.help01", "Anyone can join your group.");
addEnum("group.mode.open.help02", "Click to toggle access mode.");

addEnum("item.overlay.position.left", "Left");
addEnum("item.overlay.position.center", "Center");
addEnum("item.overlay.position.right", "Right");
}

private void addErrors()
Expand Down
47 changes: 32 additions & 15 deletions src/main/java/aeronicamc/mods/mxtune/gui/OverlayManagerScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import aeronicamc.mods.mxtune.config.MXTuneConfig;
import aeronicamc.mods.mxtune.gui.widget.MXButton;
import aeronicamc.mods.mxtune.gui.widget.MXSlideButton;
import aeronicamc.mods.mxtune.gui.widget.MXSlider;
import aeronicamc.mods.mxtune.items.MusicVenueToolItem;
import aeronicamc.mods.mxtune.render.*;
import aeronicamc.mods.mxtune.util.IInstrument;
Expand All @@ -17,15 +17,17 @@ public class OverlayManagerScreen extends MXScreen implements IItemOverlayPositi

private final OverlayInstance<?>[] visible = { null, null };
private Screen parent = null;
IOverlayItem.Position xPosVenueTool;
private IOverlayItem.Position xPosVenueTool;
private int yPosVenueTool;
private double lastYPosVenueTool = -1D;
IOverlayItem.Position xPosInstrument;
private int yPosInstrument = -1;
private IOverlayItem.Position xPosInstrument;
private int yPosInstrument;
private double lastYPosInstrument = -1D;

MXSlideButton instYPosSlider;
MXSlideButton toolYPosSlider;
private final MXButton instXPosButton = new MXButton(p->nextInstXPos());
private final MXSlider instYPosSlider = new MXSlider((p, v)-> applyInstYPos(v));
private final MXButton toolXPosButton = new MXButton(p->nextToolXPos());
private final MXSlider toolYPosSlider = new MXSlider((p, v)-> applyToolYPos(v));

public OverlayManagerScreen(@Nullable Screen parent) {
super(StringTextComponent.EMPTY);
Expand All @@ -42,16 +44,20 @@ protected void init() {
MXButton doneButton = new MXButton(((width/2) - 25), height-24, 50, 20,
new TranslationTextComponent("gui.done"), done -> onClose());
addButton(doneButton);
instYPosSlider = new MXSlideButton((p, v)->applyInstPos(v));
instYPosSlider.setLayout(doneButton.getLeft() - 150 - 4, height-24, 150, 20);
instYPosSlider.setValueD(yPosInstrument /100D);
instYPosSlider.setMessage(new StringTextComponent("Instrument VPos"));
addButton(instYPosSlider);
toolYPosSlider = new MXSlideButton((p, v)->applyToolPos(v));
instXPosButton.setLayout(instYPosSlider.getLeft() - 54, height-24, 50, 20);
instXPosButton.setMessage(new TranslationTextComponent(xPosInstrument.getPositionKey()));
addButton(instXPosButton);
toolYPosSlider.setLayout( doneButton.getRight() + 4, height-24, 150, 20);
toolYPosSlider.setValueD(yPosVenueTool /100D);
toolYPosSlider.setMessage(new StringTextComponent("Venue Tool VPos"));
addButton(toolYPosSlider);
toolXPosButton.setLayout(toolYPosSlider.getRight() + 4, height-24, 50, 20);
toolXPosButton.setMessage(new TranslationTextComponent(xPosVenueTool.getPositionKey()));
addButton(toolXPosButton);
}

@Override
Expand All @@ -75,19 +81,28 @@ else if (overlayItem.getItemStack().getItem() instanceof MusicVenueToolItem)
return 0F;
}

private void applyInstPos(double value) {
private void nextInstXPos() {
xPosInstrument = IOverlayItem.Position.nextPosition(xPosInstrument);
instXPosButton.setMessage(new TranslationTextComponent(xPosInstrument.getPositionKey()));
}

private void applyInstYPos(double value) {
if ((100 * value) != lastYPosInstrument) {
yPosInstrument = ((int) (100 * value));
lastYPosInstrument = yPosInstrument;
instYPosSlider.setValueD(yPosInstrument /100D);
instYPosSlider.setMessage(new StringTextComponent("Instrument VPos"));
}
}
private void applyToolPos(double value) {
}

private void nextToolXPos() {
xPosVenueTool = IOverlayItem.Position.nextPosition(xPosVenueTool);
toolXPosButton.setMessage(new TranslationTextComponent(xPosVenueTool.getPositionKey()));
}

private void applyToolYPos(double value) {
if ((100 * value) != lastYPosVenueTool) {
yPosVenueTool = ((int) (100 * value));
lastYPosVenueTool = yPosVenueTool;
toolYPosSlider.setValueD(yPosVenueTool /100D);
toolYPosSlider.setMessage(new StringTextComponent("Venue Tool VPos"));
}
}
Expand All @@ -100,7 +115,9 @@ public boolean isPauseScreen()

@Override
public void onClose() {
MXTuneConfig.CLIENT.instrumentOverlayXPosition.set(xPosInstrument);
MXTuneConfig.CLIENT.instrumentOverlayYPercent.set(yPosInstrument);
MXTuneConfig.CLIENT.venueToolOverlayXPosition.set(xPosVenueTool);
MXTuneConfig.CLIENT.venueToolOverlayYPercent.set(yPosVenueTool);
if (parent != null)
getMinecraft().setScreen(parent);
Expand Down Expand Up @@ -131,9 +148,9 @@ public boolean mouseScrolled(double pMouseX, double pMouseY, double pDelta) {
@Nullable
private OverlayInstance<?> getOverLayInstance(int idx) {
if (0 == idx)
return new OverlayInstance<>(this, new OverlayInst());
return new OverlayInstance<>(this, new InstrumentOverlay());
else if (1 == idx)
return new OverlayInstance<>(this, new OverlayVenueTool());
return new OverlayInstance<>(this, new VenueToolOverlay());
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
import java.util.ArrayList;
import java.util.List;

public class MXSlideButton extends AbstractSlider implements ILayout, IHooverText {
public class MXSlider extends AbstractSlider implements ILayout, IHooverText {
protected int padding = 0;
private final List<ITextComponent> hooverTexts = new ArrayList<>();
private boolean hooverTextsOverride;
private IPressable onApply;
private ITextComponent sliderText;

public MXSlideButton(IPressable onApply) {
public MXSlider(IPressable onApply) {
super(0,0,0,50, StringTextComponent.EMPTY, 0F);
this.onApply = onApply;
sliderText = StringTextComponent.EMPTY;
}

public MXSlideButton(int pX, int pY, int pWidth, int pHeight, ITextComponent pMessage, double pValue) {
public MXSlider(int pX, int pY, int pWidth, int pHeight, ITextComponent pMessage, double pValue) {
super(pX, pY, pWidth, pHeight, pMessage, pValue);
}

Expand Down Expand Up @@ -121,6 +121,6 @@ public void setPadding(int padding) {
}

public interface IPressable {
void onPress(MXSlideButton onPress, double value);
void onPress(MXSlider onPress, double value);
}
}
17 changes: 16 additions & 1 deletion src/main/java/aeronicamc/mods/mxtune/render/IOverlayItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,25 @@ public void playSound(SoundHandler pHandler) {
}

enum Position {
LEFT, CENTER, RIGHT;
LEFT("enum.mxtune.item.overlay.position.left"), CENTER("enum.mxtune.item.overlay.position.center"), RIGHT("enum.mxtune.item.overlay.position.right");

private final String positionKey;

Position(String positionKey) {
this.positionKey = positionKey;
}

public String getPositionKey() {
return positionKey;
}

private static final Position[] values = values();
public static Position getPosition(int ordinal) {
return ordinal >= 0 && ordinal < values.length ? values[ordinal] : LEFT;
}
public static Position nextPosition(Position pos) {
int cycle = (pos.ordinal() + 1) % values.length;
return getPosition(cycle);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import static aeronicamc.mods.mxtune.render.RenderHelper.*;

public class OverlayInst implements IOverlayItem {
public class InstrumentOverlay implements IOverlayItem {
private final ItemStack itemStack;
private long lastChanged;
private boolean changed;
Expand All @@ -20,7 +20,7 @@ public class OverlayInst implements IOverlayItem {
private final int lastSlot;
private final boolean managePosition;

public OverlayInst(ItemStack itemStack) {
public InstrumentOverlay(ItemStack itemStack) {
this.lastSlot = RenderHelper.getSelectedSlot();
this.itemStack = itemStack;
ItemStack sheetMusic = SheetMusicHelper.getIMusicFromIInstrument(itemStack);
Expand All @@ -30,7 +30,7 @@ public OverlayInst(ItemStack itemStack) {
this.managePosition = false;
}

public OverlayInst() {
public InstrumentOverlay() {
this.lastSlot = -1;
this.itemStack = new ItemStack(ModItems.MULTI_INST.get(), 1);
ItemStack sheetMusic = SheetMusicHelper.getIMusicFromIInstrument(itemStack);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public void render(MatrixStack pPoseStack) {
public OverlayInstance<?> getOverLayInstance() {
ItemStack stack = getPlayer().inventory.getSelected();
if (stack.getItem() instanceof IInstrument)
return new OverlayInstance<>(this, new OverlayInst(stack));
return new OverlayInstance<>(this, new InstrumentOverlay(stack));
else if (stack.getItem() instanceof MusicVenueToolItem)
return new OverlayInstance<>(this, new OverlayVenueTool(stack));
return new OverlayInstance<>(this, new VenueToolOverlay(stack));
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@

import static aeronicamc.mods.mxtune.render.RenderHelper.*;

public class OverlayVenueTool implements IOverlayItem {
public class VenueToolOverlay implements IOverlayItem {
private final ItemStack itemStack;
private long lastChanged;
private boolean changed;
private int totalWidth;
private final int lastSlot;
private final boolean managedPosition;

public OverlayVenueTool(ItemStack itemStack) {
public VenueToolOverlay(ItemStack itemStack) {
this.lastSlot = RenderHelper.getSelectedSlot();
this.itemStack = itemStack;
this.totalWidth = this.baseWidth();
this.managedPosition = false;
}

public OverlayVenueTool() {
public VenueToolOverlay() {
this.lastSlot = -1;
this.itemStack = new ItemStack(ModItems.MUSIC_VENUE_TOOL.get(), 1);
this.totalWidth = this.baseWidth();
Expand Down

0 comments on commit ea3250d

Please sign in to comment.