Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,20 @@ public void render(int mouseX, int mouseY, float delta) {
lastSelected = selectedEntry;
clearEntries();
setScrollAmount(-Double.MAX_VALUE);
String description = lastSelected.getMetadata().getDescription();
String id = lastSelected.getMetadata().getId();
Collection<Person> authors = lastSelected.getMetadata().getAuthors();
Collection<Person> contributors = lastSelected.getMetadata().getContributors();
Collection<String> licenses = lastSelected.getMetadata().getLicense();
if (description.isEmpty() && HardcodedUtil.getHardcodedDescriptions().containsKey(id)) {
description = HardcodedUtil.getHardcodedDescription(id);
String id = selectedEntry.getMetadata().getId();
String descKey = "modmenu.descriptionTranslation." + id;
String translatedDesc = i18n.translateKey(descKey);

String description;
if (!translatedDesc.equals(descKey)) {
description = translatedDesc;
} else {
description = selectedEntry.getMetadata().getDescription();
}

Collection<Person> authors = selectedEntry.getMetadata().getAuthors();
Collection<Person> contributors = selectedEntry.getMetadata().getContributors();
Collection<String> licenses = selectedEntry.getMetadata().getLicense();
if (lastSelected != null && description != null && !description.isEmpty()) {
for (String line : RenderUtils.INSTANCE.wrapStringToWidthAsList(textRenderer, description.replaceAll("\n", "\n\n"), getRowWidth())) {
children().add(new DescriptionEntry(line));
Expand Down
39 changes: 18 additions & 21 deletions src/main/java/io/github/prospector/modmenu/gui/EntryListWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public abstract class EntryListWidget<E extends EntryListWidget.Entry<E>> extend
protected boolean renderSelection = true;
protected boolean renderHeader;
protected int headerHeight;
private boolean scrolling;
protected boolean scrolling;
private E selected;

private E focused;
Expand Down Expand Up @@ -168,7 +168,6 @@ protected void renderDecorations(int i, int j) {
}

public void render(int i, int j, float f) {
oldY = j;
this.renderBackground();
int k = this.getScrollbarPosition();
int l = k + 6;
Expand Down Expand Up @@ -321,25 +320,25 @@ protected int getScrollbarPosition() {
return this.width / 2 + 124;
}

@Override
@Override
public void mouseClicked(int d, int e, int i) {
this.updateScrollingState(d, e, i);
if (this.isMouseOver(d, e)) {
E entry = this.getEntryAtPosition(d, e);
if (entry != null) {
if (entry.list.getFocused() != null) {
if (!entry.list.getFocused().equals(entry)) {
this.focused = entry;
this.selected = entry;
this.dragging = true;
super.mouseClicked(d, e, i);
}
} else {
this.focused = entry;
this.selected = entry;
this.dragging = true;
super.mouseClicked(d, e, i);
}
if (entry.list.getFocused() != null) {
if (!entry.list.getFocused().equals(entry)) {
this.focused = entry;
this.selected = entry;
this.dragging = true;
super.mouseClicked(d, e, i);
}
} else {
this.focused = entry;
this.selected = entry;
this.dragging = true;
super.mouseClicked(d, e, i);
}
} else if (i == 0) {
this.clickedHeader((int)(d - (double)(this.left + this.width / 2 - this.getRowWidth() / 2)), (int)(e - (double)this.top) + (int)this.getScrollAmount() - 4);
}
Expand All @@ -353,14 +352,12 @@ public boolean mouseReleased(double d, double e, int i) {
return false;
}

double oldY = -1;
public boolean mouseDragged(double mouseX, double mouseY, int mouseButton, double mouseDX, double mouseDY) {
if (mouseButton == 0 && isMouseOver(mouseX, mouseY)) {
setScrollAmount(getScrollAmount() - mouseY + oldY);
if (this.scrolling) {
setScrollAmount(getScrollAmount() - mouseDY);
return true;
} else {
return false;
}
return false;
}

public boolean mouseScrolled(double d, double e, double f) {
Expand Down
23 changes: 17 additions & 6 deletions src/main/java/io/github/prospector/modmenu/gui/ModListEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.minecraft.client.render.renderer.Shaders;
import net.minecraft.client.render.renderer.State;
import net.minecraft.client.render.tessellator.TessellatorGeneral;
import net.minecraft.core.lang.I18n;
import org.lwjgl.opengl.GL11;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -52,9 +53,15 @@ public void render(int index, int y, int x, int rowWidth, int rowHeight, int mou
GLRenderer.setColor4f(1, 1, 1, 1); // We LOVE random color calls
this.bindIconTexture();
internalRender(y, x);
String name = metadata.getName();
if (name.equals("Minecraft")){ // BAD CODE
name = "Better than Adventure";
String id = metadata.getId();
String translationKey = "modmenu.nameTranslation." + id;
String translatedName = I18n.getInstance().translateKey(translationKey);
String name;
if (!translatedName.equals(translationKey)) {
name = translatedName;
} else {
name = metadata.getName();
name = HardcodedUtil.formatFabricModuleName(name);
}
name = HardcodedUtil.formatFabricModuleName(name);
String trimmedName = name;
Expand All @@ -63,9 +70,13 @@ public void render(int index, int y, int x, int rowWidth, int rowHeight, int mou
trimmedName = ModListScreen.getString(fontRenderer, name, trimmedName, maxNameWidth);
this.drawStringNoShadow(font, trimmedName, x + 32 + 3, y + 1, 0xFFFFFF);
new BadgeRenderer(client, x + 32 + 3 + font.stringWidth(name) + 2, y, x + rowWidth, container, list.getParent()).draw(mouseX, mouseY);
String description = metadata.getDescription();
if (description.isEmpty() && HardcodedUtil.getHardcodedDescriptions().containsKey(metadata.getId())) {
description = HardcodedUtil.getHardcodedDescription(metadata.getId());
String descKey = "modmenu.descriptionTranslation." + id;
String translatedDesc = I18n.getInstance().translateKey(descKey);
String description;
if (!translatedDesc.equals(descKey)) {
description = translatedDesc;
} else {
description = metadata.getDescription();
}
RenderUtils.INSTANCE.drawWrappedString(this, description, (x + 32 + 3 + 4), (y + 9 + 2), rowWidth - 32 - 7, 2, 0x808080);

Expand Down
98 changes: 56 additions & 42 deletions src/main/java/io/github/prospector/modmenu/gui/ModListScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import net.minecraft.client.render.renderer.Shaders;
import net.minecraft.client.render.renderer.State;
import net.minecraft.client.render.tessellator.TessellatorGeneral;
import net.minecraft.client.util.helper.UrlHelper;
import net.minecraft.core.Global;
import net.minecraft.core.lang.I18n;
import org.lwjgl.Sys;
Expand Down Expand Up @@ -186,8 +187,8 @@ public void drawButton(Minecraft mc, int mouseX, int mouseY) {
this.buttons.add(configureButton);
this.buttons.add(websiteButton);
this.buttons.add(issuesButton);
this.buttons.add(ButtonUtil.createButton(MODS_FOLDER_BUTTON_ID, this.width / 2 - 154, this.height - 28, 150, 20, "Open Mods Folder"));
this.buttons.add(ButtonUtil.createButton(DONE_BUTTON_ID, this.width / 2 + 4, this.height - 28, 150, 20, "Done"));
this.buttons.add(ButtonUtil.createButton(MODS_FOLDER_BUTTON_ID, this.width / 2 - 154, this.height - 28, 150, 20, I18n.getInstance().translateKey("modmenu.modsFolder")));
this.buttons.add(ButtonUtil.createButton(DONE_BUTTON_ID, this.width / 2 + 4, this.height - 28, 150, 20, I18n.getInstance().translateKey("modmenu.done")));
this.searchBox.setFocused(true);

init = true;
Expand All @@ -207,13 +208,11 @@ protected void buttonClicked(ButtonElement button) {
break;
}
case WEBSITE_BUTTON_ID: {
final ModMetadata metadata = Objects.requireNonNull(selected).getMetadata();
metadata.getContact().get("homepage").ifPresent(Sys::openURL);
Objects.requireNonNull(selected).getMetadata().getContact().get("homepage").ifPresent(UrlHelper::openURL);
break;
}
case ISSUES_BUTTON_ID: {
final ModMetadata metadata = Objects.requireNonNull(selected).getMetadata();
metadata.getContact().get("issues").ifPresent(Sys::openURL);
Objects.requireNonNull(selected).getMetadata().getContact().get("issues").ifPresent(UrlHelper::openURL);
break;
}
case TOGGLE_FILTER_OPTIONS_BUTTON_ID: {
Expand Down Expand Up @@ -253,9 +252,9 @@ public ModListWidget getModList() {
@Override
public void keyPressed(char char_1, int int_1, int mouseX, int mouseY) {
this.searchBox.textboxKeyTyped(char_1, int_1);
if (int_1 == 1) {
this.mc.displayScreen(this.parent);
}
if (int_1 == 1) {
this.mc.displayScreen(this.parent);
}
modList.keyPressed(int_1, 0, 0);
descriptionListWidget.keyPressed(int_1, 0, 0);
}
Expand All @@ -275,12 +274,23 @@ public void mouseReleased(int mouseX, int mouseY, int mouseButton) {
descriptionListWidget.mouseReleased(mouseX, mouseY, mouseButton);
}
}

@Override
public void render(int mouseX, int mouseY, float delta) {
I18n i18n = I18n.getInstance();
int mouseDX = Mouse.getEventDX() * this.width / this.mc.resolution.getScaledWidthScreenCoords(); // field_6326_c
int mouseDY = this.height - Mouse.getEventDY() * this.height / this.mc.resolution.getScaledHeightScreenCoords() - 1; // field_6325_d

int dWheel = Mouse.getDWheel();
if (dWheel != 0) {
double scrollDelta = dWheel > 0 ? 1.0 : -1.0;
if (this.modList != null && this.modList.isMouseOver(mouseX, mouseY)) {
this.modList.mouseScrolled(mouseX, mouseY, scrollDelta);
} else if (this.descriptionListWidget != null && this.descriptionListWidget.isMouseOver(mouseX, mouseY)) {
this.descriptionListWidget.mouseScrolled(mouseX, mouseY, scrollDelta);
}
}

int mouseDX = Mouse.getDX() * this.width / this.mc.resolution.getScaledWidthScreenCoords(); // field_6326_c
int mouseDY = Mouse.getDY() * this.height / this.mc.resolution.getScaledHeightScreenCoords(); // field_6325_d
for (int button = 0; button < Mouse.getButtonCount(); button++) {
if (Mouse.isButtonDown(button)) {
modList.mouseDragged(mouseX, mouseY, button, mouseDX, mouseDY);
Expand Down Expand Up @@ -318,18 +328,25 @@ public void render(int mouseX, int mouseY, float delta) {
GLRenderer.setColor4f(1, 1, 1, 1);

this.selected.bindIconTexture();
ModListEntry.internalRender(paneY, x);
int lineSpacing = 9 + 1;
ModListEntry.internalRender(paneY, x);
int lineSpacing = 9 + 1;
int imageOffset = 36;
String name = metadata.getName();
if (name.equals("Minecraft")){ // BAD CODE
name = "Better than Adventure";
String id = metadata.getId();
String translationKey = "modmenu.nameTranslation." + id;
String translatedName = i18n.translateKey(translationKey);
String name;
if (!translatedName.equals(translationKey)) {
name = translatedName;
} else {
name = metadata.getName();
name = HardcodedUtil.formatFabricModuleName(name);
}
name = HardcodedUtil.formatFabricModuleName(name);

String trimmedName = name;
int maxNameWidth = this.width - (x + imageOffset);
trimmedName = getString(font, name, trimmedName, maxNameWidth);
this.drawStringNoShadow(font, trimmedName, x + imageOffset, paneY + 1, 0xFFFFFF);
trimmedName = getString(font, name, trimmedName, maxNameWidth);
this.drawStringNoShadow(font, trimmedName, x + imageOffset, paneY + 1, 0xFFFFFF);
if (mouseX > x + imageOffset && mouseY > paneY + 1 && mouseY < paneY + 1 + 9 && mouseX < x + imageOffset + fontRenderer.stringWidth(trimmedName)) {
setTooltip(i18n.translateKeyAndFormat("modmenu.modIdToolTip", metadata.getId()));
}
Expand All @@ -338,21 +355,18 @@ public void render(int mouseX, int mouseY, float delta) {
init = false;
}
badgeRenderer.draw(mouseX, mouseY);
String versionString;
if (metadata.getName().equals("Minecraft")){ // BAD CODE
versionString = Global.VERSION;
} else {
versionString = metadata.getVersion().getFriendlyString();
}
String versionString = metadata.getId().equals("minecraft")
? Global.VERSION
: metadata.getVersion().getFriendlyString();
this.drawStringNoShadow(font, "v" + versionString, x + imageOffset, paneY + 2 + lineSpacing, 0x808080);
String authors;
List<String> names = new ArrayList<>();

metadata.getAuthors().stream()
.filter(Objects::nonNull)
.map(Person::getName)
.filter(Objects::nonNull)
.forEach(names::add);
.filter(Objects::nonNull)
.map(Person::getName)
.filter(Objects::nonNull)
.forEach(names::add);

if (!names.isEmpty()) {
if (names.size() > 1) {
Expand All @@ -372,19 +386,19 @@ public void render(int mouseX, int mouseY, float delta) {
GLRenderer.popFrame();
}

static String getString(FontRenderer fontRenderer, String name, String trimmedName, int maxNameWidth) {
if (fontRenderer.stringWidth(name) > maxNameWidth) {
int maxWidth = maxNameWidth - fontRenderer.stringWidth("...");
trimmedName = "";
while (fontRenderer.stringWidth(trimmedName) < maxWidth && trimmedName.length() < name.length()) {
trimmedName += name.charAt(trimmedName.length());
}
trimmedName = trimmedName.isEmpty() ? "..." : trimmedName.substring(0, trimmedName.length() - 1) + "...";
}
return trimmedName;
}

public void overlayBackground(int x1, int y1, int x2, int y2, int red, int green, int blue, int startAlpha, int endAlpha) {
static String getString(FontRenderer fontRenderer, String name, String trimmedName, int maxNameWidth) {
if (fontRenderer.stringWidth(name) > maxNameWidth) {
int maxWidth = maxNameWidth - fontRenderer.stringWidth("...");
trimmedName = "";
while (fontRenderer.stringWidth(trimmedName) < maxWidth && trimmedName.length() < name.length()) {
trimmedName += name.charAt(trimmedName.length());
}
trimmedName = trimmedName.isEmpty() ? "..." : trimmedName.substring(0, trimmedName.length() - 1) + "...";
}
return trimmedName;
}

public void overlayBackground(int x1, int y1, int x2, int y2, int red, int green, int blue, int startAlpha, int endAlpha) {

GLRenderer.pushFrame();
GLRenderer.setShader(Shaders.INTERFACE);
Expand Down
35 changes: 22 additions & 13 deletions src/main/java/io/github/prospector/modmenu/gui/ModListWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,25 +239,34 @@ public void mouseClicked(int double_1, int double_2, int int_1) {
if (this.isMouseOver(double_1, double_2)) {
ModListEntry entry = this.getEntryAtPos(double_1, double_2);
if (entry != null) {
if (entry.list.getFocused() != null) {
if (!entry.list.getFocused().equals(entry)) {
this.setFocused(entry);
this.setSelected(entry);
this.setDragging(true);
super.mouseClicked(double_1, double_2, int_1);
}
} else {
this.setFocused(entry);
this.setSelected(entry);
this.setDragging(true);
super.mouseClicked(double_1, double_2, int_1);
}
if (entry.list.getFocused() != null) {
if (!entry.list.getFocused().equals(entry)) {
this.setFocused(entry);
this.setSelected(entry);
this.setDragging(true);
super.mouseClicked(double_1, double_2, int_1);
}
} else {
this.setFocused(entry);
this.setSelected(entry);
this.setDragging(true);
super.mouseClicked(double_1, double_2, int_1);
}
} else if (int_1 == 0) {
this.clickedHeader((int) (double_1 - (double) (this.left + this.width / 2 - this.getRowWidth() / 2)), (int) (double_2 - (double) this.top) + (int) this.getScrollAmount() - 4);
}
}
}

@Override
public boolean mouseScrolled(double mouseX, double mouseY, double scrollDelta) {
if (this.isMouseOver(mouseX, mouseY)) {
setScrollAmount(getScrollAmount() - scrollDelta * 20.0);
return true;
}
return false;
}

public final ModListEntry getEntryAtPos(double x, double y) {
int int_5 = MathHelper.floor(y - (double) this.top) - this.headerHeight + (int) this.getScrollAmount() - 4; // convertToBlockCoord
int index = int_5 / this.itemHeight;
Expand Down
13 changes: 0 additions & 13 deletions src/main/java/io/github/prospector/modmenu/util/HardcodedUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
public final class HardcodedUtil {
private static final Pattern FABRIC_PATTERN = Pattern.compile("^fabric-.*(-v\\d+)$");
private static final Set<String> FABRIC_MODS = new HashSet<>();
private static final HashMap<String, String> HARDCODED_DESCRIPTIONS = new HashMap<>();

public static void initializeHardcodings() {
HARDCODED_DESCRIPTIONS.put("minecraft", new Random().nextInt(1000) == 0 ? "The based game." : "The base game.");
}

public static void hardcodeModuleMetadata(ModContainer mod, ModMetadata metadata, String id) {
Matcher matcher = FABRIC_PATTERN.matcher(id);
Expand Down Expand Up @@ -69,15 +64,7 @@ private static String capitalize(String str) {
return sb.toString();
}

public static String getHardcodedDescription(String id) {
return HARDCODED_DESCRIPTIONS.getOrDefault(id, "");
}

public static Set<String> getFabricMods() {
return FABRIC_MODS;
}

public static HashMap<String, String> getHardcodedDescriptions() {
return HARDCODED_DESCRIPTIONS;
}
}
Loading