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 18, 2024
1 parent 5041f53 commit 5bff505
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,20 @@ public OverlayManagerScreen(@Nullable Screen parent) {
@Override
protected void init() {
super.init();
setBlitOffset(900);
getMinecraft().keyboardHandler.setSendRepeatsToGui(true);
MXButton doneButton = new MXButton(((width/2) - 25), height-24, 50, 20,
new TranslationTextComponent("gui.done"), done -> onClose());
addButton(doneButton);
instYPosSlider.setLayout(doneButton.getLeft() - 150 - 4, height-24, 150, 20);
instYPosSlider.setValueD(yPosInstrument /100D);
instYPosSlider.forceValue(yPosInstrument /100D);
instYPosSlider.setMessage(new StringTextComponent("Instrument VPos"));
addButton(instYPosSlider);
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.forceValue(yPosVenueTool /100D);
toolYPosSlider.setMessage(new StringTextComponent("Venue Tool VPos"));
addButton(toolYPosSlider);
toolXPosButton.setLayout(toolYPosSlider.getRight() + 4, height-24, 50, 20);
Expand Down Expand Up @@ -119,6 +121,7 @@ public void onClose() {
MXTuneConfig.CLIENT.instrumentOverlayYPercent.set(yPosInstrument);
MXTuneConfig.CLIENT.venueToolOverlayXPosition.set(xPosVenueTool);
MXTuneConfig.CLIENT.venueToolOverlayYPercent.set(yPosVenueTool);
getMinecraft().keyboardHandler.setSendRepeatsToGui(false);
if (parent != null)
getMinecraft().setScreen(parent);
else
Expand All @@ -140,11 +143,6 @@ public boolean mouseDragged(double pMouseX, double pMouseY, int pButton, double
return super.mouseDragged(pMouseX, pMouseY, pButton, pDragX, pDragY);
}

@Override
public boolean mouseScrolled(double pMouseX, double pMouseY, double pDelta) {
return super.mouseScrolled(pMouseX, pMouseY, pDelta);
}

@Nullable
private OverlayInstance<?> getOverLayInstance(int idx) {
if (0 == idx)
Expand Down
34 changes: 24 additions & 10 deletions src/main/java/aeronicamc/mods/mxtune/gui/widget/MXSlider.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package aeronicamc.mods.mxtune.gui.widget;

import net.minecraft.client.gui.widget.AbstractSlider;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;

Expand All @@ -11,12 +12,12 @@ 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 IPressable onPress;
private ITextComponent sliderText;

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

Expand All @@ -37,17 +38,13 @@ protected void updateMessage() {
super.setMessage((new StringTextComponent(sliderText.getString()).append(": ").append(itextcomponent)));
}

public double getValueD() {
return this.value;
}

public void setValueD(double value) {
this.value = value;
public void forceValue(double pValue) {
this.value = MathHelper.clamp(pValue, 0.0D, 1.0D);
}

@Override
protected void applyValue() {
this.onApply.onPress(this, this.value);
this.onPress.onPress(this, this.value);
}

@Override
Expand All @@ -61,6 +58,23 @@ public boolean isMouseOverWidget(double mouseX, double mouseY) {
return this.visible && mouseX >= this.x && mouseY >= this.y && mouseX < (this.x + this.width) && mouseY < (this.y + this.height);
}

@Override
public boolean mouseScrolled(double pMouseX, double pMouseY, double pDelta) {
if (this.isMouseOverWidget(pMouseX, pMouseY) && this.active) {
this.setValue(this.value + (pDelta / 100));
}
return super.mouseScrolled(pMouseX, pMouseY, pDelta);
}

private void setValue(double pValue) {
double d0 = this.value;
this.value = MathHelper.clamp(pValue, 0.0D, 1.0D);
if (d0 != this.value) {
this.applyValue();
}
this.updateMessage();
}

@Override
public List<ITextComponent> getHooverTexts() {
return this.hooverTexts;
Expand Down

0 comments on commit 5bff505

Please sign in to comment.