Skip to content

Commit

Permalink
Cleanup, add very important info to mod menu screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
PseudoDistant committed Dec 28, 2023
1 parent 78b4a12 commit dbac282
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 145 deletions.
163 changes: 18 additions & 145 deletions src/main/java/io/github/minifabric/minifabric_api/impl/ModsDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,10 @@
import java.util.Objects;

public class ModsDisplay extends SelectControlMenu {
//private static final String[] defaultOptions = new String[]{"Highscore", "Load game", "Save game", "Start new game", "Resume game", "Respawn"};
private static String[] defaultOptions;
public static final int titleColor = Color.get(0, 8, 131, 551);

private final Collection<ModContainer> modsList = FabricLoader.getInstance().getAllMods();
private static String modName = "";

public static String getModName() { return modName; }

private static ArrayList<String> modNames;
private static final ArrayList<String> modVersions = new ArrayList<>();
private static ArrayList<String> modDescriptions;
private static ArrayList<String> modVersions;

public ModsDisplay(SelectControlMenu parent) {
super(parent);
Expand All @@ -38,6 +31,8 @@ public ModsDisplay(SelectControlMenu parent) {
private static ArrayList<String> getModNames() {
Collection<ModContainer> modsList = FabricLoader.getInstance().getAllMods();
ArrayList<String> modNames = new ArrayList<>();
ArrayList<String> modVersions = new ArrayList<>();
ArrayList<String> modDescs = new ArrayList<>();

if(ModsDisplay.modNames != null) {
modNames.addAll(ModsDisplay.modNames);
Expand All @@ -49,7 +44,7 @@ private static ArrayList<String> getModNames() {
return new ArrayList<>();
}

modVersions.clear();


// Iterate between every mod loaded by Fabric.
for (ModContainer container : modsList) {
Expand All @@ -58,44 +53,37 @@ private static ArrayList<String> getModNames() {
if (!container.getMetadata().getId().equals("java")) {
modNames.add(name);
modVersions.add(container.getMetadata().getVersion().toString());
modDescs.add(container.getMetadata().getDescription() == null ? "" : container.getMetadata().getDescription());
}
}
}

if(ModsDisplay.modNames == null)
if(ModsDisplay.modNames == null || ModsDisplay.modDescriptions == null || ModsDisplay.modVersions == null) {
ModsDisplay.modNames = new ArrayList<>();
else
ModsDisplay.modDescriptions = new ArrayList<>();
ModsDisplay.modVersions = new ArrayList<>();
} else {
ModsDisplay.modNames.clear();
ModsDisplay.modDescriptions.clear();
ModsDisplay.modVersions.clear();
}

ModsDisplay.modNames.addAll(modNames);
ModsDisplay.modVersions.addAll(modVersions);
ModsDisplay.modDescriptions.addAll(modDescs);

return modNames;
}

public void init(GameControl gameControl, InputHandler input) {
defaultOptions = getModNames().toArray(new String[0]);
super.init(gameControl, input);
int[] new_selectable = new int[defaultOptions.length];

int amount;
for(amount = 0; amount < defaultOptions.length; ++amount) {
new_selectable[amount] = 1;
}

amount = defaultOptions.length;

this.setOptions(Arrays.copyOf(defaultOptions, amount));
this.setOptions(Arrays.copyOf(getModNames().toArray(new String[0]), modNames.size()));
this.selected = this.options.length - 1;
}

public void optionSelected(int selected) {
String description = modsList.stream()
.filter(mod -> Objects.equals(mod.getMetadata().getName(), defaultOptions[selected]))
.findFirst().get().getMetadata().getDescription() == null ?
"" : modsList.stream()
.filter(mod -> Objects.equals(mod.getMetadata().getName(), defaultOptions[selected]))
.findFirst().get().getMetadata().getDescription();
this.gameControl.setMenu(new SingleModDisplay(this, defaultOptions[selected], description, modVersions.get(selected)));
this.gameControl.setMenu(new SingleModDisplay(this, modNames.get(selected), modDescriptions.get(selected), modVersions.get(selected)));

}

Expand All @@ -111,120 +99,5 @@ public void render(Screen screen) {
screen.renderSprite(xo, yo * SpriteSheet.spriteSize, 13, 28, titleColor, 0, 4 * SpriteSheet.spriteSize, SpriteSheet.spriteSize);
this.menuTop = yo + h + 1;
super.render(screen, false);
Font.draw(GameControl.VERSION, screen, screen.w - GameControl.VERSION.length() * SpriteSheet.spriteSize, screen.h - SpriteSheet.spriteSize, infoCol);
}
}
/*
private final Collection<ModContainer> modsList = FabricLoader.getInstance().getAllMods();
private static String modName = "";
public static String getModName() { return modName; }
private static ArrayList<String> modNames = null;
private static final ArrayList<String> modVersions = new ArrayList<>();
ControlMenu parent;
private static ArrayList<String> getModNames() {
Collection<ModContainer> modsList = FabricLoader.getInstance().getAllMods();
ArrayList<String> modNames = new ArrayList<>();
if(ModsDisplay.modNames != null) {
modNames.addAll(ModsDisplay.modNames);
return modNames;
}
if(modsList.isEmpty()) {
System.err.println("ERROR: No mods are detected by Fabric Loader somehow...");
return new ArrayList<>();
}
modVersions.clear();
// Iterate between every mod loaded by Fabric.
for (ModContainer container : modsList) {
if (container != null) {
String name = container.getMetadata().getName();
if (!container.getMetadata().getId().equals("java")) {
modNames.add(name);
modVersions.add(container.getMetadata().getVersion().toString());
}
}
}
if(ModsDisplay.modNames == null)
ModsDisplay.modNames = new ArrayList<>();
else
ModsDisplay.modNames.clear();
ModsDisplay.modNames.addAll(modNames);
return modNames;
}
public ModsDisplay(ControlMenu parent) {
super(parent);
this.parent = parent;
}
@Override
public void init(GameControl gameControl, InputHandler input) {
super.init(gameControl, input);
modName = "";
ArrayList<String> modNames = getModNames();
int[] entries = new int[modNames.size()];
for(int i = 0; i < entries.length; i++) {
entries[i] = 1;
String name = modNames.get(i);
final String version = modVersions.get(i);
String description = modsList.stream()
.filter(mod -> Objects.equals(mod.getMetadata().getName(), name))
.findFirst().get().getMetadata().getDescription() == null ?
"" : modsList.stream()
.filter(mod -> Objects.equals(mod.getMetadata().getName(), name))
.findFirst().get().getMetadata().getDescription();
entries[i] = new SelectEntry(modNames.get(i), () -> {
Game.setDisplay(new BookDisplay(description, false));
}, false) {};
}
menus = new Menu[] {
new Menu.Builder(false, 0, RelPos.CENTER, entries)
.setDisplayLength(5)
.setScrollPolicies(1, true)
.createMenu()
};
}
@Override
public void render(Screen screen) {
super.render(screen);
int sel = ((MenuDuck)menus[0]).minifabric_modmenu$selectionGetter();
if(sel >= 0 && sel < modVersions.size()) {
String name = modNames.get(sel);
String version = modVersions.get(sel);
int col = Color.WHITE;
Font.drawCentered(Localization.getLocalized("Name:") + " " + name, screen, Font.textHeight() * 2, col);
Font.drawCentered(Localization.getLocalized("Mod version:") + " " + version, screen, Font.textHeight() * 7/2, col);
}
Font.drawCentered(Game.input.getMapping("select") + Localization.getLocalized(" to confirm"), screen, Screen.h - 60, Color.GRAY);
Font.drawCentered(Game.input.getMapping("exit") + Localization.getLocalized(" to return"), screen, Screen.h - 40, Color.GRAY);
String title = Localization.getLocalized("Fabric Mod Menu");
int color = Color.WHITE;
int y = Screen.h - Font.textHeight();
Font.drawCentered(title, screen, 0, color);
}
}
*/
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package io.github.minifabric.minifabric_api.mixin;

import com.mojang.ld22.gfx.Color;
import com.mojang.ld22.gfx.Font;
import com.mojang.ld22.gfx.Screen;
import com.mojang.ld22.gfx.SpriteSheet;
import com.mojang.ld22.screen.controlmenu.ControlMenu;
import com.mojang.ld22.screen.controlmenu.SelectControlMenu;
import com.mojang.ld22.screen.controlmenu.TitleMenu;
import io.github.minifabric.minifabric_api.impl.ModsDisplay;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import static com.mojang.ld22.screen.controlmenu.SelectControlMenu.infoCol;

@Mixin(SelectControlMenu.class)
public class SelectControlMenuMixin extends ControlMenu {
@Shadow protected int selected;
Expand All @@ -22,4 +29,13 @@ public void removeClose(SelectControlMenu instance, int i) {
this.gameControl.setMenu(this.parent);
}
}

@Redirect(method = "render(Lcom/mojang/ld22/gfx/Screen;Z)V", at = @At(value = "INVOKE", target = "Lcom/mojang/ld22/gfx/Font;draw(Ljava/lang/String;Lcom/mojang/ld22/gfx/Screen;III)V", ordinal = 2))
private void addCredits(String msg, Screen screen, int x, int y, int col) {
if ((SelectControlMenu)(Object)this instanceof ModsDisplay) {
Font.draw("ModMenu by PseudoDistant!", screen, 0, screen.h - SpriteSheet.spriteSize, Color.get(0, 50, 50, 50));
} else {
Font.draw("(§/°/[/], X and C)", screen, 0, screen.h - SpriteSheet.spriteSize, infoCol);
}
}
}

0 comments on commit dbac282

Please sign in to comment.