Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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)
}
}
}
Expand All @@ -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)
}
}
}
Expand Down Expand Up @@ -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"
Expand All @@ -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) } }
Expand Down Expand Up @@ -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()
Expand All @@ -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,
Expand All @@ -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) }
Expand All @@ -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<MenuAction>, icon: @Composable () -> Unit) {
TooltipBox(name, Modifier, TooltipPlacement.AboveCenter, Dp.Unspecified) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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")
Expand Down