Skip to content

Commit dd24382

Browse files
committed
v1.5.1 - Code cleanup and fix some alignment issues
1 parent 95badbf commit dd24382

10 files changed

+177
-94
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ A picture's worth 2 words
2525
}
2626
```
2727
- Features
28-
- Mods can provide a Supplier<Screen> to provide a custom config screen to open with the config button. Implement the `getConfigScreen` method in your API implementation.
28+
- Mods can provide a Screen factory to provide a custom config screen to open with the config button. Implement the `getConfigScreenFactory` method in your API implementation.

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ targetCompatibility = 1.8
2828

2929
group = "io.github.prospector.modmenu"
3030
archivesBaseName = "ModMenu"
31-
version = "1.5.0"
31+
version = "1.5.1"
3232

3333
def ENV = System.getenv()
3434
if (ENV.BUILD_NUMBER) {

src/main/java/io/github/prospector/modmenu/gui/DescriptionListWidget.java

+12-8
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
public class DescriptionListWidget extends EntryListWidget<DescriptionListWidget.DescriptionItem> {
88

9+
private final ModListScreen parent;
10+
private final TextRenderer textRenderer;
911
private ModListEntry lastSelected = null;
10-
private ModListScreen parent;
11-
private TextRenderer textRenderer;
1212

1313
public DescriptionListWidget(MinecraftClient client, int width, int height, int top, int bottom, int entryHeight, ModListScreen parent) {
1414
super(client, width, height, top, bottom, entryHeight);
@@ -32,16 +32,20 @@ protected int getScrollbarPosition() {
3232
}
3333

3434
@Override
35-
public void render(int int_1, int int_2, float float_1) {
36-
if (parent.getModList().getSelected() != lastSelected) {
37-
lastSelected = parent.getModList().getSelected();
35+
public void render(int mouseX, int mouseY, float delta) {
36+
ModListEntry selectedEntry = parent.getModList().getSelected();
37+
if (selectedEntry != lastSelected) {
38+
lastSelected = selectedEntry;
3839
clearEntries();
3940
setScrollAmount(-Double.MAX_VALUE);
40-
if (lastSelected != null && lastSelected.metadata.getDescription() != null && !lastSelected.metadata.getDescription().isEmpty())
41-
for (String line : textRenderer.wrapStringToWidthAsList(lastSelected.metadata.getDescription().replaceAll("\n", "\n\n"), getRowWidth()))
41+
String description = lastSelected.getMetadata().getDescription();
42+
if (lastSelected != null && description != null && !description.isEmpty()) {
43+
for (String line : textRenderer.wrapStringToWidthAsList(description.replaceAll("\n", "\n\n"), getRowWidth())) {
4244
children().add(new DescriptionItem(line));
45+
}
46+
}
4347
}
44-
super.render(int_1, int_2, float_1);
48+
super.render(mouseX, mouseY, delta);
4549
}
4650

4751
protected class DescriptionItem extends EntryListWidget.Entry<DescriptionItem> {

src/main/java/io/github/prospector/modmenu/gui/ModListEntry.java

+25-12
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,40 @@
1919
import java.io.InputStream;
2020
import java.nio.file.Files;
2121
import java.nio.file.NoSuchFileException;
22+
import java.util.Objects;
2223

2324
public class ModListEntry extends AlwaysSelectedEntryListWidget.Entry<ModListEntry> implements AutoCloseable {
25+
public static final Identifier UNKNOWN_ICON = new Identifier("textures/misc/unknown_pack.png");
2426
private static final Logger LOGGER = LogManager.getLogger();
2527
private final MinecraftClient client;
26-
public ModContainer container;
27-
public ModMetadata metadata;
28-
public ModListWidget list;
29-
public final Identifier iconLocation;
30-
public final NativeImageBackedTexture icon;
31-
public static final Identifier unknownIcon = new Identifier("textures/misc/unknown_pack.png");
28+
private final ModContainer container;
29+
private final ModMetadata metadata;
30+
private final ModListWidget list;
31+
private final Identifier iconLocation;
32+
private final NativeImageBackedTexture icon;
3233

3334
public ModListEntry(ModContainer container, ModListWidget list) {
3435
this.container = container;
3536
this.list = list;
3637
this.metadata = container.getMetadata();
3738
this.client = MinecraftClient.getInstance();
3839
this.iconLocation = new Identifier("modmenu", metadata.getId() + "_icon");
39-
this.icon = this.getIcon();
40+
this.icon = this.createIcon();
4041
}
4142

4243
@Override
4344
public void render(int index, int y, int x, int rowWidth, int rowHeight, int mouseX, int mouseY, boolean isSelected, float delta) {
4445
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
45-
this.client.getTextureManager().bindTexture(this.icon != null ? this.iconLocation : unknownIcon);
46+
this.client.getTextureManager().bindTexture(this.icon != null ? this.iconLocation : UNKNOWN_ICON);
4647
GlStateManager.enableBlend();
4748
DrawableHelper.blit(x, y, 0.0F, 0.0F, 32, 32, 32, 32);
4849
GlStateManager.disableBlend();
4950
this.client.textRenderer.draw(metadata.getName(), (float) (x + 32 + 3), (float) (y + 1), 0xFFFFFF);
50-
new BadgeRenderer(x + 32 + 3 + this.client.textRenderer.getStringWidth(metadata.getName()) + 2, y, rowWidth, metadata, list.parent).draw(mouseX, mouseY);
51-
RenderUtils.drawWrappedString(metadata.getDescription(), (x + 32 + 3 + 4), (y + client.textRenderer.fontHeight + 2), rowWidth - 32 - 3 - 25 - 4, 2, 0x808080);
51+
new BadgeRenderer(x + 32 + 3 + this.client.textRenderer.getStringWidth(metadata.getName()) + 2, y, rowWidth, metadata, list.getParent()).draw(mouseX, mouseY);
52+
RenderUtils.drawWrappedString(metadata.getDescription(), (x + 32 + 3 + 4), (y + client.textRenderer.fontHeight + 2), rowWidth - 32 - 3, 2, 0x808080);
5253
}
5354

54-
private NativeImageBackedTexture getIcon() {
55+
private NativeImageBackedTexture createIcon() {
5556
try {
5657
InputStream inputStream;
5758
try {
@@ -66,7 +67,7 @@ private NativeImageBackedTexture getIcon() {
6667
Throwable var3 = null;
6768
NativeImageBackedTexture var6;
6869
try {
69-
NativeImage image = NativeImage.fromInputStream(inputStream);
70+
NativeImage image = NativeImage.fromInputStream(Objects.requireNonNull(inputStream));
7071
Validate.validState(image.getHeight() == image.getWidth(), "Must be square icon");
7172
NativeImageBackedTexture var5 = new NativeImageBackedTexture(image);
7273
this.client.getTextureManager().registerTexture(this.iconLocation, var5);
@@ -102,10 +103,22 @@ public boolean mouseClicked(double v, double v1, int i) {
102103
return true;
103104
}
104105

106+
@Override
105107
public void close() {
106108
if (this.icon != null) {
107109
this.icon.close();
108110
}
111+
}
112+
113+
public ModMetadata getMetadata() {
114+
return metadata;
115+
}
116+
117+
public Identifier getIconLocation() {
118+
return iconLocation;
119+
}
109120

121+
public NativeImageBackedTexture getIcon() {
122+
return icon;
110123
}
111124
}

src/main/java/io/github/prospector/modmenu/gui/ModListScreen.java

+46-29
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,26 @@
2828
import java.io.File;
2929
import java.util.ArrayList;
3030
import java.util.List;
31+
import java.util.Objects;
3132

3233
public class ModListScreen extends Screen {
34+
private static final Identifier CONFIGURE_BUTTON_LOCATION = new Identifier("modmenu", "textures/gui/configure_button.png");
3335
private static final Logger LOGGER = LogManager.getLogger();
34-
public static final Identifier CONFIGURE_BUTTON_LOCATION = new Identifier("modmenu", "textures/gui/configure_button.png");
35-
protected String textTitle;
36-
protected TextFieldWidget searchBox;
37-
protected DescriptionListWidget descriptionListWidget;
38-
protected Screen parent;
39-
protected ModListWidget modList;
40-
protected String tooltip;
41-
protected ModListEntry selected;
42-
protected BadgeRenderer badgeRenderer;
43-
protected double scrollPercent = 0;
44-
int leftPaneX;
45-
boolean init = false;
46-
int leftPaneRight;
47-
int paneY;
48-
int paneWidth;
49-
int rightPaneX;
36+
private final String textTitle;
37+
private TextFieldWidget searchBox;
38+
private DescriptionListWidget descriptionListWidget;
39+
private Screen parent;
40+
private ModListWidget modList;
41+
private String tooltip;
42+
private ModListEntry selected;
43+
private BadgeRenderer badgeRenderer;
44+
private double scrollPercent = 0;
45+
private int leftPaneX;
46+
private boolean init = false;
47+
private int leftPaneRight;
48+
private int paneY;
49+
private int paneWidth;
50+
private int rightPaneX;
5051

5152
public ModListScreen(Screen previousGui) {
5253
super(ModMenu.noFabric ? new StringTextComponent("Mods") : new TranslatableTextComponent("modmenu.title"));
@@ -70,7 +71,7 @@ public void tick() {
7071

7172
@Override
7273
protected void init() {
73-
this.minecraft.keyboard.enableRepeatEvents(true);
74+
Objects.requireNonNull(this.minecraft).keyboard.enableRepeatEvents(true);
7475
leftPaneX = 4;
7576
leftPaneRight = width / 2 - 4;
7677
paneY = 48;
@@ -86,7 +87,8 @@ protected void init() {
8687
this.descriptionListWidget = new DescriptionListWidget(this.minecraft, paneWidth, this.height, paneY + 60, this.height - 36, font.fontHeight + 1, this);
8788
this.descriptionListWidget.setLeftPos(rightPaneX);
8889
final ModListEntry selectedEntry = modList.getSelected();
89-
final String modid = selectedEntry.metadata.getId();
90+
final ModMetadata metadata = Objects.requireNonNull(selectedEntry).getMetadata();
91+
final String modid = metadata.getId();
9092
ButtonWidget configureButton = new TexturedButtonWidget(width - 24, paneY, 20, 20, 0, 0, CONFIGURE_BUTTON_LOCATION, 32, 64, button -> {
9193
final Screen screen = ModMenu.getConfigScreen(modid, this);
9294
if (screen != null) {
@@ -108,27 +110,27 @@ public void render(int mouseX, int mouseY, float delta) {
108110
ButtonWidget websiteButton = new ButtonWidget(rightPaneX + (urlButtonWidths / 2) - (cappedButtonWidth / 2), paneY + 36, urlButtonWidths > 200 ? 200 : urlButtonWidths, 20,
109111
ModMenu.noFabric ? "Website" : I18n.translate("modmenu.website"), button -> this.minecraft.openScreen(new ConfirmChatLinkScreen((bool) -> {
110112
if (bool) {
111-
SystemUtil.getOperatingSystem().open(selectedEntry.metadata.getContact().get("homepage").get());
113+
SystemUtil.getOperatingSystem().open(metadata.getContact().get("homepage").get());
112114
}
113115
this.minecraft.openScreen(this);
114-
}, selectedEntry.metadata.getContact().get("homepage").get(), true))) {
116+
}, metadata.getContact().get("homepage").get(), true))) {
115117
@Override
116118
public void render(int var1, int var2, float var3) {
117-
active = selectedEntry.metadata.getContact().get("homepage").isPresent();
119+
active = metadata.getContact().get("homepage").isPresent();
118120
visible = true;
119121
super.render(var1, var2, var3);
120122
}
121123
};
122124
ButtonWidget issuesButton = new ButtonWidget(rightPaneX + urlButtonWidths + 4 + (urlButtonWidths / 2) - (cappedButtonWidth / 2), paneY + 36, urlButtonWidths > 200 ? 200 : urlButtonWidths, 20,
123125
ModMenu.noFabric ? "Issues" : I18n.translate("modmenu.issues"), button -> this.minecraft.openScreen(new ConfirmChatLinkScreen((bool) -> {
124126
if (bool) {
125-
SystemUtil.getOperatingSystem().open(selectedEntry.metadata.getContact().get("issues").get());
127+
SystemUtil.getOperatingSystem().open(metadata.getContact().get("issues").get());
126128
}
127129
this.minecraft.openScreen(this);
128-
}, selectedEntry.metadata.getContact().get("issues").get(), true))) {
130+
}, metadata.getContact().get("issues").get(), true))) {
129131
@Override
130132
public void render(int var1, int var2, float var3) {
131-
active = selectedEntry.metadata.getContact().get("issues").isPresent();
133+
active = metadata.getContact().get("issues").isPresent();
132134
visible = true;
133135
super.render(var1, var2, var3);
134136
}
@@ -177,10 +179,10 @@ public void render(int mouseX, int mouseY, float delta) {
177179
this.drawCenteredString(this.font, this.textTitle, this.modList.getWidth() / 2, 8, 16777215);
178180
super.render(mouseX, mouseY, delta);
179181

180-
ModMetadata metadata = modList.getSelected().metadata;
182+
ModMetadata metadata = modList.getSelected().getMetadata();
181183
int x = rightPaneX;
182184
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
183-
this.minecraft.getTextureManager().bindTexture(selected.icon != null ? selected.iconLocation : ModListEntry.unknownIcon);
185+
Objects.requireNonNull(this.minecraft).getTextureManager().bindTexture(selected.getIcon() != null ? selected.getIconLocation() : ModListEntry.UNKNOWN_ICON);
184186
GlStateManager.enableBlend();
185187
blit(x, paneY, 0.0F, 0.0F, 32, 32, 32, 32);
186188
GlStateManager.disableBlend();
@@ -190,7 +192,7 @@ public void render(int mouseX, int mouseY, float delta) {
190192
if (mouseX > x + imageOffset && mouseY > paneY + 1 && mouseY < paneY + 1 + font.fontHeight && mouseX < x + imageOffset + font.getStringWidth(metadata.getName())) {
191193
setTooltip(I18n.translate("modmenu.modIdToolTip", metadata.getId()));
192194
}
193-
if (init || badgeRenderer == null || badgeRenderer.metadata != metadata) {
195+
if (init || badgeRenderer == null || badgeRenderer.getMetadata() != metadata) {
194196
badgeRenderer = new BadgeRenderer(x + imageOffset + this.minecraft.textRenderer.getStringWidth(metadata.getName()) + 2, paneY, width - 28, metadata, this);
195197
init = false;
196198
}
@@ -216,9 +218,8 @@ public void render(int mouseX, int mouseY, float delta) {
216218
protected void overlayBackground(int x1, int y1, int x2, int y2, int red, int green, int blue, int startAlpha, int endAlpha) {
217219
Tessellator tessellator = Tessellator.getInstance();
218220
BufferBuilder buffer = tessellator.getBufferBuilder();
219-
minecraft.getTextureManager().bindTexture(DrawableHelper.BACKGROUND_LOCATION);
221+
Objects.requireNonNull(minecraft).getTextureManager().bindTexture(DrawableHelper.BACKGROUND_LOCATION);
220222
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
221-
float f = 32.0F;
222223
buffer.begin(7, VertexFormats.POSITION_UV_COLOR);
223224
buffer.vertex(x1, y2, 0.0D).texture(x1 / 32.0D, y2 / 32.0D).color(red, green, blue, endAlpha).next();
224225
buffer.vertex(x2, y2, 0.0D).texture(x2 / 32.0D, y2 / 32.0D).color(red, green, blue, endAlpha).next();
@@ -230,4 +231,20 @@ protected void overlayBackground(int x1, int y1, int x2, int y2, int red, int gr
230231
public void setTooltip(String tooltip) {
231232
this.tooltip = tooltip;
232233
}
234+
235+
public ModListEntry getSelectedEntry() {
236+
return selected;
237+
}
238+
239+
public void updateSelectedEntry(ModListEntry entry) {
240+
this.selected = entry;
241+
}
242+
243+
public double getScrollPercent() {
244+
return scrollPercent;
245+
}
246+
247+
public void updateScrollPercent(double scrollPercent) {
248+
this.scrollPercent = scrollPercent;
249+
}
233250
}

0 commit comments

Comments
 (0)