diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyPlayUnit.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyPlayUnit.kt index 754f8015..a9d9e874 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyPlayUnit.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyPlayUnit.kt @@ -142,6 +142,7 @@ internal fun PlayUnit(lobby: LobbyShell, modifier: Modifier) { PlaySource.Multiplayer -> lobby.activeServer() PlaySource.Replays -> lobby.activeReplay() } + val flows = remember { SingleplayerFlows() } if (source == PlaySource.Replays) LaunchedEffect(Unit) { ReplayLibrary.reload() } LaunchedEffect(Unit) { LobbyRealms.refresh() } Box((if (quick) modifier.height(LobbyLayout.UnitHeight) else modifier).panel()) { @@ -157,7 +158,7 @@ internal fun PlayUnit(lobby: LobbyShell, modifier: Modifier) { is ServerData -> ServerHero(lobby, shown) is LobbyWorld -> WorldHero(shown) is ReplayEntry -> ReplayHero(shown) - else -> EmptyHero(lobby, source) + else -> EmptyHero(lobby, source, flows) } } } @@ -166,7 +167,7 @@ internal fun PlayUnit(lobby: LobbyShell, modifier: Modifier) { PinnedServersStrip(lobby, Modifier.padding(start = PanelGutter, end = PanelGutter, top = 8.dp)) Spacer(Modifier.height(PanelGutter)) Box(Modifier.fillMaxWidth().height(1.dp).background(SocialBorderColor)) - Footer(lobby, source, quick) + Footer(lobby, source, quick, target != null, flows) } } } @@ -406,7 +407,7 @@ private fun ReplayHero(entry: ReplayEntry) { } @Composable -private fun EmptyHero(lobby: LobbyShell, source: PlaySource) { +private fun EmptyHero(lobby: LobbyShell, source: PlaySource, flows: SingleplayerFlows) { val singleplayer = source == PlaySource.Singleplayer val title = when { source == PlaySource.Replays -> if (!ReplayLibrary.loaded) "Loading replays..." else if (ReplayLibrary.failed && ReplayLibrary.entries.isEmpty()) "Couldn't load replays" else "No replays yet" @@ -425,7 +426,6 @@ private fun EmptyHero(lobby: LobbyShell, source: PlaySource) { PlaySource.Singleplayer -> "minecraft-block" PlaySource.Multiplayer -> "globe-01" } - val flows = remember { SingleplayerFlows() } val action: (@Composable () -> Unit)? = when { source == PlaySource.Multiplayer -> { { TextButton(text = "Add server", icon = LobbyIcons.PLUS, onClick = lobby::addServer, style = ControlStyle.Secondary) } } singleplayer && lobby.worlds.loaded -> { { TextButton(text = "Create world", icon = LobbyIcons.PLUS, onClick = flows::create, style = ControlStyle.Secondary) } } @@ -551,7 +551,7 @@ private fun HostingStrip(lobby: LobbyShell) { } @Composable -private fun Footer(lobby: LobbyShell, source: PlaySource, quick: Boolean) { +private fun Footer(lobby: LobbyShell, source: PlaySource, quick: Boolean, hasTarget: Boolean, flows: SingleplayerFlows) { val page = source.page val servers = lobby.servers val worlds = if (quick && source == PlaySource.Singleplayer) lobby.quickWorlds() else emptyList() @@ -563,6 +563,12 @@ private fun Footer(lobby: LobbyShell, source: PlaySource, quick: Boolean) { PlaySource.Replays -> ReplayLibrary.entries.size } val count = "$saved saved" + val add = when { + !hasTarget || lobby.page == page -> null + source == PlaySource.Multiplayer -> AddAction("Add server", lobby::addServer) + source == PlaySource.Singleplayer && lobby.worlds.loaded -> AddAction("Create world", flows::create) + else -> null + } Row( Modifier.fillMaxWidth().height(FooterHeight).padding(horizontal = PanelGutter), verticalAlignment = Alignment.CenterVertically, @@ -585,6 +591,7 @@ private fun Footer(lobby: LobbyShell, source: PlaySource, quick: Boolean) { } Spacer(Modifier.weight(1f)) } + add?.let { NavIconButton(LobbyIcons.PLUS, it.label, it.onClick, tooltipPlacement = TooltipPlacement.AboveCenter, frameSize = TileSize) } when { lobby.page == page -> if (listed) Text(count, color = OneConfigTheme.current.mutedText, style = OneConfigTheme.current.typography.small, maxLines = 1, overflow = TextOverflow.Ellipsis, softWrap = false) listed -> AllButton("All", "$saved") { lobby.show(page) } @@ -595,6 +602,8 @@ private fun Footer(lobby: LobbyShell, source: PlaySource, quick: Boolean) { } } +private class AddAction(val label: String, val onClick: () -> Unit) + @Composable private fun RecentTile(name: String, selected: Boolean, onClick: () -> Unit, menu: () -> List, icon: @Composable () -> Unit) { TooltipBox(name, Modifier, TooltipPlacement.AboveCenter, Dp.Unspecified) { diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyShell.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyShell.kt index e33f7f8b..39798e3b 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyShell.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyShell.kt @@ -68,6 +68,11 @@ internal enum class LobbyPage(val frosted: Boolean) { val hidden: Boolean get() = when (this) { Wardrobe -> PolyPlusMainMenuConfig.hideMainMenuCosmetics + else -> unavailable + } + + val unavailable: Boolean + get() = when (this) { Social -> PolyPlusMainMenuConfig.hideMainMenuSocial Replays -> !ReplayLibrary.enabled Events -> EventsRepository.running().isEmpty() @@ -184,7 +189,7 @@ internal class LobbyShell(private val screen: Screen, firstPage: LobbyPage) : So fun skipIntro(): Boolean = (!setup || LobbyScene.overlayAlpha <= 0f) && !LobbyWardrobe.open && LobbyScene.skipIntro() fun show(target: LobbyPage) { - val shown = if (target.hidden) LobbyPage.Home else target + val shown = if (target.unavailable) LobbyPage.Home else target if (shown != page) { AnimationActivity.hold(0.6) A11y.announce(shown.spokenName + " page")