-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add toggle button to show/hide child mods, and a search widget (#…
…21) * chore: Refactor package structure * refactor: Extract TitledScreen * refactor: Extract ModSettingsOption to top-level class * refactor: Rename ModSettingsOption to ModConfigInfo * feat: Filter list of mod based on search string and if child mods are included * chore: Fix incorrect whitespace * refactor: Cleanups and preparing for mod options * feat: Add icon button widgets * feat: Add toggle button to show or hide child mods, and a search widget to filter visible mods * chore: Update changelog
- Loading branch information
Showing
20 changed files
with
372 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package se.icus.mag.modsettings.gui; | ||
|
||
import net.minecraft.client.gui.screen.Screen; | ||
|
||
public record ModConfigInfo(String modId, String modName, Screen configScreen) { | ||
} |
74 changes: 0 additions & 74 deletions
74
src/main/java/se/icus/mag/modsettings/gui/ModSettingsScreen.java
This file was deleted.
Oops, something went wrong.
92 changes: 92 additions & 0 deletions
92
src/main/java/se/icus/mag/modsettings/gui/screen/ModSettingsScreen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package se.icus.mag.modsettings.gui.screen; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
import net.minecraft.client.gui.screen.Screen; | ||
import net.minecraft.client.gui.tooltip.Tooltip; | ||
import net.minecraft.screen.ScreenTexts; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Identifier; | ||
import se.icus.mag.modsettings.Main; | ||
import se.icus.mag.modsettings.ModRegistry; | ||
import se.icus.mag.modsettings.gui.ModConfigInfo; | ||
import se.icus.mag.modsettings.gui.widget.Button; | ||
import se.icus.mag.modsettings.gui.widget.IconToggleButtonWidget; | ||
import se.icus.mag.modsettings.gui.widget.ModListWidget; | ||
import se.icus.mag.modsettings.gui.widget.SearchWidget; | ||
|
||
public class ModSettingsScreen extends TitledScreen { | ||
private static final int FULL_BUTTON_WIDTH = 200; | ||
private static final int BUTTON_HEIGHT = 20; | ||
|
||
private boolean initIsProcessing; | ||
private ModListWidget list; | ||
private SearchWidget searchWidget; | ||
|
||
public ModSettingsScreen(Screen previous) { | ||
super(Text.translatable("modsettings.screen.title"), previous); | ||
} | ||
|
||
@Override | ||
protected void init() { | ||
// Protect against mods like Content Creator Integration that triggers | ||
// a recursive call of Screen.init() while creating the settings screen... | ||
if (initIsProcessing) return; | ||
initIsProcessing = true; | ||
|
||
// Add the toggle show indirect mods button | ||
IconToggleButtonWidget showIndirectButton = new IconToggleButtonWidget(10, 6, | ||
BUTTON_HEIGHT, BUTTON_HEIGHT, 15, 15, | ||
List.of(new Identifier("modsettings", "expand"), | ||
new Identifier("modsettings", "collapse")), | ||
List.of(Tooltip.of(Text.translatable("modsettings.indirect.show")), | ||
Tooltip.of(Text.translatable("modsettings.indirect.hide"))), | ||
Main.OPTIONS.showIndirect ? 1 : 0, selection -> { | ||
Main.OPTIONS.showIndirect = (selection == 1); | ||
updateModButtons(); | ||
}); | ||
this.addDrawableChild(showIndirectButton); | ||
|
||
// Add the search widget | ||
searchWidget = new SearchWidget(40, 6, 100, | ||
Main.OPTIONS.filterText, this.textRenderer, text -> { | ||
Main.OPTIONS.filterText = text; | ||
updateModButtons(); | ||
}, () -> this.setFocused(searchWidget)); | ||
|
||
this.addDrawableChild(searchWidget); | ||
this.setInitialFocus(searchWidget); | ||
|
||
// Add the actual mod list buttons | ||
// Put the list between 32 pixels from top and bottom | ||
this.list = new ModListWidget(this.client, this.width, this.height - 64, 32, 25); | ||
|
||
this.addDrawableChild(this.list); | ||
|
||
// Add the Done button | ||
this.addDrawableChild(new Button(this.width / 2 - FULL_BUTTON_WIDTH / 2, this.height - 27, FULL_BUTTON_WIDTH, BUTTON_HEIGHT, ScreenTexts.DONE, button -> this.client.setScreen(this.previous))); | ||
|
||
updateModButtons(); | ||
initIsProcessing = false; | ||
} | ||
|
||
private void updateModButtons() { | ||
List<String> visibleModIds = ModRegistry.getInstance().getVisibleModIds(Main.OPTIONS.showIndirect, Main.OPTIONS.filterText); | ||
this.list.setModButtons(getModConfigInfo(visibleModIds)); | ||
} | ||
|
||
private List<ModConfigInfo> getModConfigInfo(List<String> modIds) { | ||
List<ModConfigInfo> options = new LinkedList<>(); | ||
for (String modId : modIds) { | ||
try { | ||
Screen configScreen = ModRegistry.getInstance().getConfigScreen(modId, this); | ||
if (configScreen != null) { | ||
options.add(new ModConfigInfo(modId, ModRegistry.getInstance().getModName(modId), configScreen)); | ||
} | ||
} catch (Throwable e) { | ||
Main.LOGGER.error("Error creating Settings screen from mod " + modId, e); | ||
} | ||
} | ||
return options; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/se/icus/mag/modsettings/gui/screen/TitledScreen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package se.icus.mag.modsettings.gui.screen; | ||
|
||
import net.minecraft.client.gui.DrawContext; | ||
import net.minecraft.client.gui.screen.Screen; | ||
import net.minecraft.text.Text; | ||
|
||
public class TitledScreen extends Screen { | ||
private static final int TITLE_COLOR = 0xffffff; | ||
protected final Screen previous; | ||
|
||
public TitledScreen(Text title, Screen previous) { | ||
super(title); | ||
this.previous = previous; | ||
} | ||
|
||
@Override | ||
public void render(DrawContext context, int mouseX, int mouseY, float delta) { | ||
super.render(context, mouseX, mouseY, delta); | ||
context.drawCenteredTextWithShadow(this.textRenderer, this.title, this.width / 2, 5, TITLE_COLOR); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
this.client.setScreen(this.previous); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...a/se/icus/mag/modsettings/gui/Button.java → ...us/mag/modsettings/gui/widget/Button.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/se/icus/mag/modsettings/gui/widget/IconButtonWidget.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package se.icus.mag.modsettings.gui.widget; | ||
|
||
import net.minecraft.client.font.TextRenderer; | ||
import net.minecraft.client.gui.DrawContext; | ||
import net.minecraft.client.gui.widget.ButtonWidget; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Identifier; | ||
|
||
public class IconButtonWidget extends ButtonWidget { | ||
private final int textureWidth; | ||
private final int textureHeight; | ||
protected Identifier texture; | ||
|
||
public IconButtonWidget(int x, int y, int width, int height,int textureWidth, int textureHeight, | ||
Identifier texture, ButtonWidget.PressAction onPress) { | ||
this(x, y, width, height, textureWidth, textureHeight, onPress); | ||
this.texture = texture; | ||
} | ||
|
||
protected IconButtonWidget(int x, int y, int width, int height,int textureWidth, int textureHeight, | ||
ButtonWidget.PressAction onPress) { | ||
super(x, y, width, height, Text.empty(), onPress, DEFAULT_NARRATION_SUPPLIER); | ||
this.textureWidth = textureWidth; | ||
this.textureHeight = textureHeight; | ||
} | ||
|
||
@Override | ||
public void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) { | ||
super.renderWidget(context, mouseX, mouseY, delta); | ||
int x = this.getX() + this.getWidth() / 2 - this.textureWidth / 2; | ||
int y = this.getY() + this.getHeight() / 2 - this.textureHeight / 2; | ||
context.drawGuiTexture(this.texture, x, y, this.textureWidth, this.textureHeight); | ||
} | ||
|
||
@Override | ||
public void drawMessage(DrawContext context, TextRenderer textRenderer, int color) { | ||
} | ||
} |
Oops, something went wrong.