diff --git a/src/main/java/xyz/nucleoid/extras/error/ExtrasErrorReporter.java b/src/main/java/xyz/nucleoid/extras/error/ExtrasErrorReporter.java index f0ed55f..9f7597a 100644 --- a/src/main/java/xyz/nucleoid/extras/error/ExtrasErrorReporter.java +++ b/src/main/java/xyz/nucleoid/extras/error/ExtrasErrorReporter.java @@ -11,6 +11,7 @@ import xyz.nucleoid.plasmid.api.game.GameLifecycle; import xyz.nucleoid.plasmid.api.game.GameSpace; import xyz.nucleoid.plasmid.api.game.config.GameConfig; +import xyz.nucleoid.plasmid.api.game.config.GameConfigs; import java.io.IOException; import java.io.PrintWriter; @@ -52,7 +53,7 @@ public void onClosed(GameSpace gameSpace, List players, Game } private static String sourceName(RegistryEntry> game) { - var name = game.value().name().getString(); + var name = GameConfig.name(game).getString(); return name + " (" + GameConfig.sourceName(game) + ")"; } diff --git a/src/main/java/xyz/nucleoid/extras/game_portal/SimpleStyledMenuPortalBackend.java b/src/main/java/xyz/nucleoid/extras/game_portal/SimpleStyledMenuPortalBackend.java index cb2f2f2..2f4a651 100644 --- a/src/main/java/xyz/nucleoid/extras/game_portal/SimpleStyledMenuPortalBackend.java +++ b/src/main/java/xyz/nucleoid/extras/game_portal/SimpleStyledMenuPortalBackend.java @@ -2,6 +2,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.text.Text; +import xyz.nucleoid.plasmid.api.game.config.GameConfig; import xyz.nucleoid.plasmid.impl.portal.game.ConcurrentGamePortalBackend; import xyz.nucleoid.plasmid.impl.portal.menu.*; @@ -23,14 +24,14 @@ protected List getEntries() { this.entries = new ArrayList<>(this.configEntries.size()); for (var configEntry : configEntries) { var game = new ConcurrentGamePortalBackend(configEntry.game()); - var gameConfig = configEntry.game().value(); + var gameConfig = configEntry.game(); if (gameConfig != null) { this.entries.add(new GameMenuEntry( game, - configEntry.name().orElse(gameConfig.name()), - configEntry.description().orElse(gameConfig.description()), - configEntry.icon().orElse(gameConfig.icon()) + configEntry.name().orElse(GameConfig.name(gameConfig)), + configEntry.description().orElse(gameConfig.value().description()), + configEntry.icon().orElse(gameConfig.value().icon()) )); } else if (ExtrasGamePortals.SHOW_INVALID) { this.entries.add(new InvalidMenuEntry(game.getName())); diff --git a/src/main/java/xyz/nucleoid/extras/game_portal/StyledMenuPortalBackend.java b/src/main/java/xyz/nucleoid/extras/game_portal/StyledMenuPortalBackend.java index 618ca1a..53b5487 100644 --- a/src/main/java/xyz/nucleoid/extras/game_portal/StyledMenuPortalBackend.java +++ b/src/main/java/xyz/nucleoid/extras/game_portal/StyledMenuPortalBackend.java @@ -18,6 +18,8 @@ import xyz.nucleoid.extras.util.CommonGuiElements; import xyz.nucleoid.extras.util.PagedGui; import xyz.nucleoid.plasmid.api.game.GameSpace; +import xyz.nucleoid.plasmid.api.game.GameSpaceState; +import xyz.nucleoid.plasmid.api.game.config.GameConfig; import xyz.nucleoid.plasmid.api.game.player.GamePlayerJoiner; import xyz.nucleoid.plasmid.api.game.player.JoinIntent; import xyz.nucleoid.plasmid.impl.portal.GamePortalBackend; @@ -180,7 +182,7 @@ private void fillOpen(ServerPlayerEntity player, SimpleGui gui, MutableInt page) if (games.size() > pIndex) { var portal = games.get(pIndex); var m = portal.getMetadata().sourceConfig().value(); - gui.setSlot(index, createIconFor(m.icon(), m.name(), m.description(), portal.getPlayers().size(), (p) -> { + gui.setSlot(index, createIconFor(m.icon(), GameConfig.name(portal.getMetadata().sourceConfig()), m.description(), portal.getState(), (p) -> { PagedGui.playClickSound(player); tryJoinGame(p, portal, JoinIntent.PLAY); })); @@ -259,7 +261,7 @@ protected void fillInterface(ServerPlayerEntity player, SimpleGui gui, MutableIn } } - protected GuiElementBuilder createIconFor(ItemStack icon, Text name, List description, int playerCount, Consumer click) { + protected GuiElementBuilder createIconFor(ItemStack icon, Text name, List description, GameSpaceState state, Consumer click) { var element = GuiElementBuilder.from(icon) .setItemName(name) .hideDefaultTooltip(); @@ -274,15 +276,36 @@ protected GuiElementBuilder createIconFor(ItemStack icon, Text name, List element.addLoreLine(text); } - if (playerCount > -1) { + int playerCount = state.players(); + int maxPlayerCount = state.maxPlayers(); + int spectatorCount = state.spectators(); + boolean allowSpace = true; + var stateText = state.state().display(); + if (stateText != null) { element.addLoreLine(ScreenTexts.EMPTY); - element.addLoreLine(Text.empty() - .append(Text.literal("» ").formatted(Formatting.DARK_GRAY)) - .append(Text.translatable("text.plasmid.ui.game_join.players", - Text.literal(playerCount + "").formatted(Formatting.YELLOW)).formatted(Formatting.GOLD)) - ); + element.addLoreLine(Text.literal(" ").append(stateText).formatted(Formatting.WHITE)); + allowSpace = false; + } + + if (playerCount > -1) { + if (allowSpace) { + element.addLoreLine(ScreenTexts.EMPTY); + allowSpace = false; + } + + element.addLoreLine(Text.empty().append(Text.literal("» ").formatted(Formatting.DARK_GRAY)).append(Text.translatable("text.plasmid.ui.game_join.players", new Object[]{Text.literal("" + playerCount + (maxPlayerCount > 0 ? " / " + maxPlayerCount : "")).formatted(Formatting.YELLOW)}).formatted(Formatting.GOLD))); } + if (spectatorCount > 0) { + if (allowSpace) { + element.addLoreLine(ScreenTexts.EMPTY); + allowSpace = false; + } + + element.addLoreLine(Text.empty().append(Text.literal("» ").formatted(Formatting.DARK_GRAY)).append(Text.translatable("text.plasmid.ui.game_join.spectators", new Object[]{Text.literal("" + spectatorCount).formatted(Formatting.YELLOW)}).formatted(Formatting.GOLD))); + } + + element.setCallback((a, b, c, gui) -> { click.accept(gui.getPlayer()); }); diff --git a/src/main/java/xyz/nucleoid/extras/integrations/game/GameStatusIntegration.java b/src/main/java/xyz/nucleoid/extras/integrations/game/GameStatusIntegration.java index b444870..7ea576f 100644 --- a/src/main/java/xyz/nucleoid/extras/integrations/game/GameStatusIntegration.java +++ b/src/main/java/xyz/nucleoid/extras/integrations/game/GameStatusIntegration.java @@ -83,7 +83,7 @@ void clear() { } void addGame(RegistryEntry> game, int playerCount) { - this.games.add(new GameEntry(game.value().name().getString(), game.value().type().id(), playerCount)); + this.games.add(new GameEntry(GameConfig.name(game).getString(), game.value().type().id(), playerCount)); } JsonObject serialize() { diff --git a/src/main/java/xyz/nucleoid/extras/placeholder/GameTextContent.java b/src/main/java/xyz/nucleoid/extras/placeholder/GameTextContent.java index 3892cf5..9045628 100644 --- a/src/main/java/xyz/nucleoid/extras/placeholder/GameTextContent.java +++ b/src/main/java/xyz/nucleoid/extras/placeholder/GameTextContent.java @@ -7,6 +7,7 @@ import xyz.nucleoid.plasmid.api.game.GameSpace; import xyz.nucleoid.plasmid.api.game.GameSpaceManager; import org.jetbrains.annotations.Nullable; +import xyz.nucleoid.plasmid.api.game.config.GameConfig; import java.util.stream.Stream; @@ -32,7 +33,7 @@ public Text toVanilla(@Nullable ServerPlayerEntity player, Text text) { .withColor( TextColor.fromRgb(gameSpace == null ? 0x800080 : (int) (gameSpace.getMetadata().id().getLeastSignificantBits() & 0xFFFFFF))) .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, - gameSpace == null ? Text.literal("Lobby") : gameSpace.getMetadata().sourceConfig().value().name()))) + gameSpace == null ? Text.literal("Lobby") : GameConfig.name(gameSpace.getMetadata().sourceConfig())))) ).append(ScreenTexts.SPACE); out.getSiblings().addAll(text.getSiblings()); diff --git a/src/main/java/xyz/nucleoid/extras/sidebar/NucleoidSidebar.java b/src/main/java/xyz/nucleoid/extras/sidebar/NucleoidSidebar.java index 48045fa..c8d9c4c 100644 --- a/src/main/java/xyz/nucleoid/extras/sidebar/NucleoidSidebar.java +++ b/src/main/java/xyz/nucleoid/extras/sidebar/NucleoidSidebar.java @@ -12,6 +12,7 @@ import net.minecraft.world.World; import xyz.nucleoid.extras.NucleoidExtrasConfig; import xyz.nucleoid.plasmid.api.game.GameSpaceManager; +import xyz.nucleoid.plasmid.api.game.config.GameConfig; import xyz.nucleoid.plasmid.impl.game.manager.ManagedGameSpace; import java.util.ArrayList; @@ -150,7 +151,7 @@ private void writeGamesToSidebar(LineBuilder builder, Collection { - var name = game.getMetadata().sourceConfig().value().shortName(); + var name = GameConfig.shortName(game.getMetadata().sourceConfig()); int players = game.getPlayers().size(); var playersText = Text.translatable("nucleoid.sidebar.game.player." + (players < 2 ? "1" : "more"), players).setStyle(GAME_COUNT_STYLE);