Skip to content

Commit

Permalink
Fix mods button not showing up in game menu on server with Server Links
Browse files Browse the repository at this point in the history
Closes #745

- Fixed mods button not showing up on servers with Server Links
- Changed functionality of Game Mode display option "Replace Bugs" to "Replace", which now replaces both Give Feedback and Report Bugs, these are now both found in Mod Menu under the Minecraft entry. "Below Bugs" is now "Insert"
  • Loading branch information
Prospector committed Jun 18, 2024
1 parent 73829e6 commit fc50c22
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 86 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/terraformersmc/modmenu/ModMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public static Text createModsButtonText(boolean title) {
gameMenuStyle == ModMenuConfig.GameMenuButtonStyle.ICON;
var isShort = title ?
titleStyle == ModMenuConfig.TitleMenuButtonStyle.SHRINK :
gameMenuStyle == ModMenuConfig.GameMenuButtonStyle.REPLACE_BUGS;
gameMenuStyle == ModMenuConfig.GameMenuButtonStyle.REPLACE;
MutableText modsText = ModMenuScreenTexts.TITLE.copy();
if (ModMenuConfig.MOD_COUNT_LOCATION.getValue().isOnModsButton() && !isIcon) {
String count = ModMenu.getDisplayedModCount();
Expand Down
22 changes: 10 additions & 12 deletions src/main/java/com/terraformersmc/modmenu/config/ModMenuConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.terraformersmc.modmenu.config;

import com.google.gson.annotations.SerializedName;
import com.terraformersmc.modmenu.api.UpdateChannel;
import com.terraformersmc.modmenu.config.option.BooleanConfigOption;
import com.terraformersmc.modmenu.config.option.EnumConfigOption;
Expand All @@ -20,17 +21,14 @@ public class ModMenuConfig {
public static final BooleanConfigOption COUNT_LIBRARIES = new BooleanConfigOption("count_libraries", true);
public static final BooleanConfigOption COMPACT_LIST = new BooleanConfigOption("compact_list", false);
public static final BooleanConfigOption COUNT_CHILDREN = new BooleanConfigOption("count_children", true);
public static final EnumConfigOption<TitleMenuButtonStyle> MODS_BUTTON_STYLE = new EnumConfigOption<>(
"mods_button_style",
public static final EnumConfigOption<TitleMenuButtonStyle> MODS_BUTTON_STYLE = new EnumConfigOption<>("mods_button_style",
TitleMenuButtonStyle.CLASSIC
);
public static final EnumConfigOption<GameMenuButtonStyle> GAME_MENU_BUTTON_STYLE = new EnumConfigOption<>(
"game_menu_button_style",
GameMenuButtonStyle.REPLACE_BUGS
public static final EnumConfigOption<GameMenuButtonStyle> GAME_MENU_BUTTON_STYLE = new EnumConfigOption<>("game_menu_button_style",
GameMenuButtonStyle.REPLACE
);
public static final BooleanConfigOption COUNT_HIDDEN_MODS = new BooleanConfigOption("count_hidden_mods", true);
public static final EnumConfigOption<ModCountLocation> MOD_COUNT_LOCATION = new EnumConfigOption<>(
"mod_count_location",
public static final EnumConfigOption<ModCountLocation> MOD_COUNT_LOCATION = new EnumConfigOption<>("mod_count_location",
ModCountLocation.TITLE_SCREEN
);
public static final BooleanConfigOption HIDE_MOD_LINKS = new BooleanConfigOption("hide_mod_links", false);
Expand Down Expand Up @@ -70,16 +68,16 @@ public class ModMenuConfig {
new HashSet<>()
);
@FileOnlyConfig
public static final StringSetConfigOption DISABLE_UPDATE_CHECKER = new StringSetConfigOption(
"disable_update_checker",
public static final StringSetConfigOption DISABLE_UPDATE_CHECKER = new StringSetConfigOption("disable_update_checker",
new HashSet<>()
);

public static SimpleOption<?>[] asOptions() {
ArrayList<SimpleOption<?>> options = new ArrayList<>();
for (Field field : ModMenuConfig.class.getDeclaredFields()) {
if (Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers()) && OptionConvertable.class.isAssignableFrom(
field.getType()) && !field.isAnnotationPresent(FileOnlyConfig.class)) {
if (Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers()) &&
OptionConvertable.class.isAssignableFrom(field.getType()) &&
!field.isAnnotationPresent(FileOnlyConfig.class)) {
try {
options.add(((OptionConvertable) field.get(null)).asOption());
} catch (IllegalAccessException e) {
Expand Down Expand Up @@ -131,6 +129,6 @@ public enum TitleMenuButtonStyle {
}

public enum GameMenuButtonStyle {
REPLACE_BUGS, BELOW_BUGS, ICON
@SerializedName(value = "replace", alternate = { "replace_bugs" }) REPLACE, @SerializedName(value = "insert", alternate = { "below_bugs" }) INSERT, ICON
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
import java.util.List;

public class ModMenuEventHandler {
public static final Identifier FABRIC_ICON_BUTTON_LOCATION = Identifier.of(ModMenu.MOD_ID,
"textures/gui/mods_button.png"
);
public static final Identifier MODS_BUTTON_TEXTURE = Identifier.of(ModMenu.MOD_ID, "textures/gui/mods_button.png");
private static KeyBinding MENU_KEY_BIND;

public static void register() {
Expand Down Expand Up @@ -67,7 +65,8 @@ private static void afterTitleScreenInit(Screen screen) {
}
}
if (buttonHasText(button, "menu.online")) {
if (ModMenuConfig.MODS_BUTTON_STYLE.getValue() == ModMenuConfig.TitleMenuButtonStyle.REPLACE_REALMS) {
if (ModMenuConfig.MODS_BUTTON_STYLE.getValue() ==
ModMenuConfig.TitleMenuButtonStyle.REPLACE_REALMS) {
buttons.set(i, new ModMenuButtonWidget(button.getX(),
button.getY(),
button.getWidth(),
Expand All @@ -76,7 +75,8 @@ private static void afterTitleScreenInit(Screen screen) {
screen
));
} else {
if (ModMenuConfig.MODS_BUTTON_STYLE.getValue() == ModMenuConfig.TitleMenuButtonStyle.SHRINK) {
if (ModMenuConfig.MODS_BUTTON_STYLE.getValue() ==
ModMenuConfig.TitleMenuButtonStyle.SHRINK) {
button.setWidth(98);
}
modsButtonIndex = i + 1;
Expand Down Expand Up @@ -115,7 +115,7 @@ private static void afterTitleScreenInit(Screen screen) {
0,
0,
20,
FABRIC_ICON_BUTTON_LOCATION,
MODS_BUTTON_TEXTURE,
32,
64,
button -> MinecraftClient.getInstance().setScreen(new ModsScreen(screen)),
Expand All @@ -137,17 +137,18 @@ public static boolean buttonHasText(Widget widget, String translationKey) {
if (widget instanceof ButtonWidget button) {
Text text = button.getMessage();
TextContent textContent = text.getContent();
return textContent instanceof TranslatableTextContent && ((TranslatableTextContent) textContent).getKey()
.equals(translationKey);
return textContent instanceof TranslatableTextContent &&
((TranslatableTextContent) textContent).getKey().equals(translationKey);
}
return false;
}

public static void shiftButtons(Widget widget, boolean shiftUp, int spacing) {
if (shiftUp) {
widget.setY(widget.getY() - spacing / 2);
} else if (!(widget instanceof ClickableWidget button && button.getMessage()
.equals(Text.translatable("title.credits")))) {
} else if (!(widget instanceof ClickableWidget button &&
button.getMessage().equals(Text.translatable("title.credits"))
)) {
widget.setY(widget.getY() + spacing / 2);
}
}
Expand Down
94 changes: 57 additions & 37 deletions src/main/java/com/terraformersmc/modmenu/gui/ModsScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.terraformersmc.modmenu.util.mod.Mod;
import com.terraformersmc.modmenu.util.mod.ModBadgeRenderer;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.SharedConstants;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ConfirmLinkScreen;
import net.minecraft.client.gui.screen.ConfirmScreen;
Expand All @@ -28,10 +29,7 @@
import net.minecraft.screen.ScreenTexts;
import net.minecraft.text.StringVisitable;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import net.minecraft.util.Language;
import net.minecraft.util.Util;
import net.minecraft.util.*;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -83,6 +81,9 @@ public class ModsScreen extends Screen {
public final Map<String, Boolean> modHasConfigScreen = new HashMap<>();
public final Map<String, Throwable> modScreenErrors = new HashMap<>();

private static final Text SEND_FEEDBACK_TEXT = Text.translatable("menu.sendFeedback");
private static final Text REPORT_BUGS_TEXT = Text.translatable("menu.reportBugs");

public ModsScreen(Screen previousScreen) {
super(ModMenuScreenTexts.TITLE);
this.previousScreen = previousScreen;
Expand All @@ -108,7 +109,9 @@ protected void init() {
Screen configScreen = ModMenu.getConfigScreen(id, this);
modHasConfigScreen.put(id, configScreen != null);
} catch (java.lang.NoClassDefFoundError e) {
LOGGER.warn("The '" + id + "' mod config screen is not available because " + e.getLocalizedMessage() + " is missing.");
LOGGER.warn(
"The '" + id + "' mod config screen is not available because " + e.getLocalizedMessage() +
" is missing.");
modScreenErrors.put(id, e);
modHasConfigScreen.put(id, false);
} catch (Throwable e) {
Expand Down Expand Up @@ -166,8 +169,7 @@ protected void init() {
this.updateFiltersX();

if (!ModMenuConfig.CONFIG_MODE.getValue()) {
this.filtersButton = LegacyTexturedButtonWidget.legacyTexturedBuilder(
ModMenuScreenTexts.TOGGLE_FILTER_OPTIONS,
this.filtersButton = LegacyTexturedButtonWidget.legacyTexturedBuilder(ModMenuScreenTexts.TOGGLE_FILTER_OPTIONS,
button -> {
this.setFilterOptionsShown(!this.filterOptionsShown);
}
Expand Down Expand Up @@ -221,12 +223,15 @@ protected void init() {

this.websiteButton = ButtonWidget.builder(ModMenuScreenTexts.WEBSITE, button -> {
final Mod mod = Objects.requireNonNull(selected).getMod();
this.client.setScreen(new ConfirmLinkScreen(confirmed -> {
if (confirmed) {
Util.getOperatingSystem().open(mod.getWebsite());
}
this.client.setScreen(this);
}, mod.getWebsite(), false));
boolean isMinecraft = selected.getMod().getId().equals("minecraft");

if (isMinecraft) {
var url = SharedConstants.getGameVersion().isStable() ? Urls.JAVA_FEEDBACK : Urls.SNAPSHOT_FEEDBACK;
ConfirmLinkScreen.open(this, url, true);
} else {
var url = mod.getWebsite();
ConfirmLinkScreen.open(this, url, false);
}
})
.position(this.rightPaneX + (urlButtonWidths / 2) - (cappedButtonWidth / 2), RIGHT_PANE_Y + 36)
.size(Math.min(urlButtonWidths, 200), 20)
Expand All @@ -235,12 +240,14 @@ protected void init() {
// Issues button
this.issuesButton = ButtonWidget.builder(ModMenuScreenTexts.ISSUES, button -> {
final Mod mod = Objects.requireNonNull(selected).getMod();
this.client.setScreen(new ConfirmLinkScreen(confirmed -> {
if (confirmed) {
Util.getOperatingSystem().open(mod.getIssueTracker());
}
this.client.setScreen(this);
}, mod.getIssueTracker(), false));
boolean isMinecraft = selected.getMod().getId().equals("minecraft");

if (isMinecraft) {
ConfirmLinkScreen.open(this, Urls.SNAPSHOT_BUGS, true);
} else {
var url = mod.getIssueTracker();
ConfirmLinkScreen.open(this, url, false);
}
})
.position(this.rightPaneX + urlButtonWidths + 4 + (urlButtonWidths / 2) - (cappedButtonWidth / 2),
RIGHT_PANE_Y + 36
Expand Down Expand Up @@ -300,10 +307,8 @@ protected void init() {

@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
return super.keyPressed(keyCode, scanCode, modifiers) || this.searchBox.keyPressed(keyCode,
scanCode,
modifiers
);
return super.keyPressed(keyCode, scanCode, modifiers) ||
this.searchBox.keyPressed(keyCode, scanCode, modifiers);
}

@Override
Expand Down Expand Up @@ -340,7 +345,8 @@ public void render(DrawContext DrawContext, int mouseX, int mouseY, float delta)
Text fullModCount = this.computeModCountText(true);
if (!ModMenuConfig.CONFIG_MODE.getValue() && this.updateFiltersX()) {
if (this.filterOptionsShown) {
if (!ModMenuConfig.SHOW_LIBRARIES.getValue() || textRenderer.getWidth(fullModCount) <= this.filtersX - 5) {
if (!ModMenuConfig.SHOW_LIBRARIES.getValue() ||
textRenderer.getWidth(fullModCount) <= this.filtersX - 5) {
DrawContext.drawText(textRenderer,
fullModCount.asOrderedText(),
this.searchBoxX,
Expand All @@ -365,7 +371,8 @@ public void render(DrawContext DrawContext, int mouseX, int mouseY, float delta)
);
}
} else {
if (!ModMenuConfig.SHOW_LIBRARIES.getValue() || textRenderer.getWidth(fullModCount) <= modList.getWidth() - 5) {
if (!ModMenuConfig.SHOW_LIBRARIES.getValue() ||
textRenderer.getWidth(fullModCount) <= modList.getWidth() - 5) {
DrawContext.drawText(textRenderer,
fullModCount.asOrderedText(),
this.searchBoxX,
Expand Down Expand Up @@ -409,8 +416,7 @@ public void render(DrawContext DrawContext, int mouseX, int mouseY, float delta)
int maxNameWidth = this.width - (x + imageOffset);
if (textRenderer.getWidth(name) > maxNameWidth) {
StringVisitable ellipsis = StringVisitable.plain("...");
trimmedName = StringVisitable.concat(textRenderer.trimToWidth(
name,
trimmedName = StringVisitable.concat(textRenderer.trimToWidth(name,
maxNameWidth - textRenderer.getWidth(ellipsis)
), ellipsis);
}
Expand All @@ -421,12 +427,14 @@ public void render(DrawContext DrawContext, int mouseX, int mouseY, float delta)
0xFFFFFF,
true
);
if (mouseX > x + imageOffset && mouseY > RIGHT_PANE_Y + 1 && mouseY < RIGHT_PANE_Y + 1 + textRenderer.fontHeight && mouseX < x + imageOffset + textRenderer.getWidth(
trimmedName)) {
if (mouseX > x + imageOffset && mouseY > RIGHT_PANE_Y + 1 &&
mouseY < RIGHT_PANE_Y + 1 + textRenderer.fontHeight &&
mouseX < x + imageOffset + textRenderer.getWidth(trimmedName)) {
this.setTooltip(ModMenuScreenTexts.modIdTooltip(mod.getId()));
}
if (this.init || modBadgeRenderer == null || modBadgeRenderer.getMod() != mod) {
modBadgeRenderer = new ModBadgeRenderer(x + imageOffset + this.client.textRenderer.getWidth(trimmedName) + 2,
modBadgeRenderer = new ModBadgeRenderer(
x + imageOffset + this.client.textRenderer.getWidth(trimmedName) + 2,
RIGHT_PANE_Y,
width - 28,
selectedEntry.mod,
Expand Down Expand Up @@ -528,13 +536,13 @@ public ModListEntry getSelectedEntry() {
public void updateSelectedEntry(ModListEntry entry) {
if (entry != null) {
this.selected = entry;
String modId = selected.getMod().getId();

if (this.configureButton != null) {
String modId = selected.getMod().getId();

this.configureButton.active = modHasConfigScreen.get(modId);
this.configureButton.visible = selected != null && modHasConfigScreen.get(modId) || modScreenErrors.containsKey(
modId);
this.configureButton.visible =
selected != null && modHasConfigScreen.get(modId) || modScreenErrors.containsKey(modId);

if (modScreenErrors.containsKey(modId)) {
Throwable e = modScreenErrors.get(modId);
Expand All @@ -544,11 +552,21 @@ public void updateSelectedEntry(ModListEntry entry) {
}
}

var isMinecraft = modId.equals("minecraft");

if (isMinecraft) {
this.websiteButton.setMessage(SEND_FEEDBACK_TEXT);
this.issuesButton.setMessage(REPORT_BUGS_TEXT);
} else {
this.websiteButton.setMessage(ModMenuScreenTexts.WEBSITE);
this.issuesButton.setMessage(ModMenuScreenTexts.ISSUES);
}

this.websiteButton.visible = true;
this.websiteButton.active = selected.getMod().getWebsite() != null;
this.websiteButton.active = isMinecraft || selected.getMod().getWebsite() != null;

this.issuesButton.visible = true;
this.issuesButton.active = selected.getMod().getIssueTracker() != null;
this.issuesButton.active = isMinecraft || selected.getMod().getIssueTracker() != null;
}
}

Expand All @@ -565,8 +583,10 @@ public String getSearchInput() {
}

private boolean updateFiltersX() {
if ((this.filtersWidth + textRenderer.getWidth(this.computeModCountText(true)) + 20) >= this.searchRowWidth && ((this.filtersWidth + textRenderer.getWidth(
computeModCountText(false)) + 20) >= this.searchRowWidth || (this.filtersWidth + textRenderer.getWidth(this.computeLibraryCountText()) + 20) >= this.searchRowWidth)) {
if ((this.filtersWidth + textRenderer.getWidth(this.computeModCountText(true)) + 20) >= this.searchRowWidth &&
((this.filtersWidth + textRenderer.getWidth(computeModCountText(false)) + 20) >= this.searchRowWidth ||
(this.filtersWidth + textRenderer.getWidth(this.computeLibraryCountText()) + 20) >= this.searchRowWidth
)) {
this.filtersX = this.paneWidth / 2 - this.filtersWidth / 2;
return !filterOptionsShown;
} else {
Expand Down
Loading

0 comments on commit fc50c22

Please sign in to comment.