Skip to content

Commit

Permalink
v1.7.9 - Fix crash when the screen re-initializes with an empty list [C…
Browse files Browse the repository at this point in the history
…loses #63]
  • Loading branch information
Prospector committed Aug 18, 2019
1 parent 5ba39c5 commit 5a577d3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
org.gradle.jvmargs=-Xmx1G

mod_version=1.7.8
mod_version=1.7.9
maven_group=io.github.prospector
archive_name=modmenu

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected int getScrollbarPosition() {

@Override
public void render(int mouseX, int mouseY, float delta) {
ModListEntry selectedEntry = parent.getModList().getSelected();
ModListEntry selectedEntry = parent.getSelectedEntry();
if (selectedEntry != lastSelected) {
lastSelected = selectedEntry;
clearEntries();
Expand Down
25 changes: 13 additions & 12 deletions src/main/java/io/github/prospector/modmenu/gui/ModListScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,12 @@ protected void init() {
searchBoxX = paneWidth / 2 - searchBoxWidth / 2 - 22 / 2;
this.searchBox = new TextFieldWidget(this.font, searchBoxX, 22, searchBoxWidth, 20, this.searchBox, I18n.translate("selectWorld.search"));
this.searchBox.setChangedListener((string_1) -> this.modList.filter(() -> string_1, false));

this.modList = new ModListWidget(this.minecraft, paneWidth, this.height, paneY + 19, this.height - 36, 36, () -> this.searchBox.getText(), this.modList, this);
this.modList.setLeftPos(0);
this.descriptionListWidget = new DescriptionListWidget(this.minecraft, paneWidth, this.height, paneY + 60, this.height - 36, font.fontHeight + 1, this);
this.descriptionListWidget.setLeftPos(rightPaneX);
ButtonWidget configureButton = new ModMenuTexturedButtonWidget(width - 24, paneY, 20, 20, 0, 0, CONFIGURE_BUTTON_LOCATION, 32, 64, button -> {
final String modid = Objects.requireNonNull(modList.getSelected()).getMetadata().getId();
final String modid = Objects.requireNonNull(selected).getMetadata().getId();
final Screen screen = ModMenu.getConfigScreen(modid, this);
if (screen != null) {
minecraft.openScreen(screen);
Expand All @@ -102,8 +101,8 @@ protected void init() {
I18n.translate("modmenu.configure")) {
@Override
public void render(int mouseX, int mouseY, float delta) {
if (modList.getSelected() != null) {
String modid = modList.getSelected().getMetadata().getId();
if (selected != null) {
String modid = selected.getMetadata().getId();
active = ModMenu.hasFactory(modid) || ModMenu.hasLegacyConfigScreenTask(modid);
} else {
active = false;
Expand All @@ -122,7 +121,7 @@ public void renderButton(int int_1, int int_2, float float_1) {
int cappedButtonWidth = urlButtonWidths > 200 ? 200 : urlButtonWidths;
ButtonWidget websiteButton = new ButtonWidget(rightPaneX + (urlButtonWidths / 2) - (cappedButtonWidth / 2), paneY + 36, urlButtonWidths > 200 ? 200 : urlButtonWidths, 20,
I18n.translate("modmenu.website"), button -> {
final ModMetadata metadata = Objects.requireNonNull(modList.getSelected()).getMetadata();
final ModMetadata metadata = Objects.requireNonNull(selected).getMetadata();
this.minecraft.openScreen(new ConfirmChatLinkScreen((bool) -> {
if (bool) {
SystemUtil.getOperatingSystem().open(metadata.getContact().get("homepage").get());
Expand All @@ -132,14 +131,14 @@ public void renderButton(int int_1, int int_2, float float_1) {
}) {
@Override
public void render(int var1, int var2, float var3) {
visible = modList.getSelected() != null;
active = visible && modList.getSelected().getMetadata().getContact().get("homepage").isPresent();
visible = selected != null;
active = visible && selected.getMetadata().getContact().get("homepage").isPresent();
super.render(var1, var2, var3);
}
};
ButtonWidget issuesButton = new ButtonWidget(rightPaneX + urlButtonWidths + 4 + (urlButtonWidths / 2) - (cappedButtonWidth / 2), paneY + 36, urlButtonWidths > 200 ? 200 : urlButtonWidths, 20,
I18n.translate("modmenu.issues"), button -> {
final ModMetadata metadata = Objects.requireNonNull(modList.getSelected()).getMetadata();
final ModMetadata metadata = Objects.requireNonNull(selected).getMetadata();
this.minecraft.openScreen(new ConfirmChatLinkScreen((bool) -> {
if (bool) {
SystemUtil.getOperatingSystem().open(metadata.getContact().get("issues").get());
Expand All @@ -149,8 +148,8 @@ public void render(int var1, int var2, float var3) {
}) {
@Override
public void render(int var1, int var2, float var3) {
visible = modList.getSelected() != null;
active = visible && modList.getSelected().getMetadata().getContact().get("issues").isPresent();
visible = selected != null;
active = visible && selected.getMetadata().getContact().get("issues").isPresent();
super.render(var1, var2, var3);
}
};
Expand Down Expand Up @@ -231,7 +230,7 @@ public boolean charTyped(char char_1, int int_1) {
public void render(int mouseX, int mouseY, float delta) {
ModListScreen.overlayBackground(paneWidth, 0, rightPaneX, height, 64, 64, 64, 255, 255);
this.tooltip = null;
ModListEntry selectedEntry = modList.getSelected();
ModListEntry selectedEntry = selected;
if (selectedEntry != null) {
this.descriptionListWidget.render(mouseX, mouseY, delta);
}
Expand Down Expand Up @@ -316,7 +315,9 @@ public ModListEntry getSelectedEntry() {
}

public void updateSelectedEntry(ModListEntry entry) {
this.selected = entry;
if (entry != null) {
this.selected = entry;
}
}

public double getScrollPercent() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public void filter(Supplier<String> searchTerm, boolean refresh, boolean search)
}
}
} else {
if (getSelected() == null && getEntry(0) != null) {
if (getSelected() == null && !children().isEmpty() && getEntry(0) != null) {
setSelected(getEntry(0));
}
}
Expand Down

0 comments on commit 5a577d3

Please sign in to comment.