Skip to content

Commit

Permalink
Make sure sound is not cleared midway (fix possible crash)
Browse files Browse the repository at this point in the history
Fixed non-muffled sounds non being removed from the muffled screen
Fixed muffled and play sound button tooltips being just bad
Other small gui fixes
  • Loading branch information
LeoBeliik committed Oct 28, 2023
1 parent b504ec0 commit d1207c3
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 29 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Made logo square and added the issues page for better compat with ModMenu.

Fixed null crashes.
Make sure sound is not cleared midway (fix possible crash)
Fixed non-muffled sounds non being removed from the muffled screen
Fixed muffled and play sound button tooltips being just bad
Other small gui fixes
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ protected void init() {
minYButton = getY() + 46;
maxYButton = getY() + 164;

//allows to hold a key to keep printing it. in this case I want it to easy erase text
//minecraft.keyboardHandler.setSendRepeatsToGui(true);

addButtons();
addSideButtons();
addAnchorButtons();
Expand Down Expand Up @@ -498,7 +495,9 @@ private void renderSideScreen(GuiGraphics stack) {
}

private void renderButtonTooltip(GuiGraphics stack, Component message, AbstractWidget button) {
int centeredMessageX = button.getX() - (font.width(message) / 2);
//to render CSL button tooltip more centered
int CSLShift = button.equals(btnCSL) ? 25 : 0;
int centeredMessageX = button.getX() - ((font.width(message) - CSLShift) / 2);
int centeredMessageY = button.equals(btnPrevSounds) || button.equals(btnNextSounds) ? button.getY() - 1 : button.getY() + button.getHeight() + 16;
stack.renderTooltip(font, message, centeredMessageX, centeredMessageY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,13 @@ public void renderWidget(@NotNull GuiGraphics stack, int mouseX, int mouseY, flo
this.drawMessage(stack);
}

private void renderButtonTooltip(GuiGraphics stack, AbstractButton btn, Component text) {
int lengthierText = font.width(text);
int x1 = btn.getX() + (btn.getHeight() / 2) - (font.width(text) / 2);
int x2 = x1 + lengthierText + 2;
int y1 = btn.getY() - font.lineHeight - 2;
int y2 = btn.getY() - 1;
private void renderButtonTooltip(GuiGraphics stack, AbstractButton button, Component message) {
int centeredMessageX = button.getX() - (font.width(message) / 2);
int centeredMessageY = button.getY() - 1;

stack.fill(x1 - 3, y1 - 5, x2, y2 + 1, darkBG);
stack.drawString(font, text, x1, y1 - 2, whiteText);
stack.pose().pushPose();
stack.renderTooltip(font, message, centeredMessageX, centeredMessageY);
stack.pose().popPose();
}

private void drawMessage(GuiGraphics stack) {
Expand Down Expand Up @@ -127,6 +125,7 @@ private void setBtnToggleSound(ResourceLocation sound) {
if (isMuffling) {
if (screen.removeSoundMuffled(sound)) {
setFGColor(this, "white");
this.visible = false;
}
} else {
setSliderValue(CommonConfig.get().defaultMuteVolume().get());
Expand Down Expand Up @@ -172,13 +171,15 @@ protected void onDrag(double mouseX, double mouseY, double dragX, double dragY)

@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
this.btnToggleSound.mouseClicked(mouseX, mouseY, button);
this.btnPlaySound.mouseClicked(mouseX, mouseY, button);

if (isHovered && isMuffling) {
changeSliderValue((float) mouseX);
showSlider = true;
setFocused(true);
if (this.visible) {
this.btnToggleSound.mouseClicked(mouseX, mouseY, button);
this.btnPlaySound.mouseClicked(mouseX, mouseY, button);

if (isHovered && isMuffling) {
changeSliderValue((float) mouseX);
showSlider = true;
setFocused(true);
}
}
return super.mouseClicked(mouseX, mouseY, button);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,23 @@ private void esm_captureTickableSoundVolume(SoundInstance sound, CallbackInfo ci
@ModifyArg(index = 0, at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Mth;clamp(FFF)F"),
method = "calculateVolume(FLnet/minecraft/sounds/SoundSource;)F")
private float esm_setVolume(float volume) {
SoundInstance tempSound = esmSound;
//don't care about forbidden sounds or from the psb
if (esmSound != null && !esm_isForbidden(esmSound) && !PlaySoundButton.isFromPSB()) {
if (tempSound != null && !esm_isForbidden(tempSound) && !PlaySoundButton.isFromPSB()) {

//add sound to recent sounds list
recentSoundsList.add(esmSound.getLocation());
recentSoundsList.add(tempSound.getLocation());

if (MufflerScreen.isMuffling()) {
if (muffledSounds.containsKey(esmSound.getLocation())) {
return (float) (esmSound.getVolume() * muffledSounds.get(esmSound.getLocation()));
if (muffledSounds.containsKey(tempSound.getLocation())) {
return (float) (tempSound.getVolume() * muffledSounds.get(tempSound.getLocation()));
}

//don't continue if the anchors are disabled
if (CommonConfig.get() == null || !CommonConfig.get().disableAnchors().get()) {
Anchor anchor = Anchor.getAnchor(esmSound);
Anchor anchor = Anchor.getAnchor(tempSound);
if (anchor != null) {
return (float) (esmSound.getVolume() * anchor.getMuffledSounds().get(esmSound.getLocation()));
return (float) (tempSound.getVolume() * anchor.getMuffledSounds().get(tempSound.getLocation()));
}
}
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Project
modversion = 39
modversion = 40
group=com.leobeliik.extremesoundmuffler

# Common
Expand Down

0 comments on commit d1207c3

Please sign in to comment.