From 7491e14885efa206645ebee91eea43637845a6bd Mon Sep 17 00:00:00 2001 From: Deftu Date: Tue, 24 Nov 2026 15:10:58 +0200 Subject: [PATCH 1/5] feat: add Controlify controls for socials, the wardrobe, wheels, pings and voice --- build.gradle.kts | 1 + .../polyplus/client/PolyPlusClient.kt | 1 + .../polyplus/client/PolyPlusControllers.kt | 51 +++++++++++++++++++ .../polyplus/client/gui/WheelOverlay.kt | 18 +++++++ .../polyplus/client/ping/PingInput.kt | 16 ++++-- .../resources/assets/polyplus/lang/en_us.json | 11 +++- src/main/resources/fabric.mod.json | 3 ++ 7 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 src/main/kotlin/org/polyfrost/polyplus/client/PolyPlusControllers.kt diff --git a/build.gradle.kts b/build.gradle.kts index 02d4017ea..ca78b28f0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -589,6 +589,7 @@ tasks.withType().configureEach { if (isOrnithe) filter { line -> line.replace("\"fabric-api\": \"*\"", "\"osl-keybinds\": \"*\"") .replace("\"java\": \">=21\"", "\"java\": \">=25\"") + .replace("\"controlify\": \"*\"", "") } expand( mapOf( diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/PolyPlusClient.kt b/src/main/kotlin/org/polyfrost/polyplus/client/PolyPlusClient.kt index 6e76a7d2a..869e724ba 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/PolyPlusClient.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/PolyPlusClient.kt @@ -182,6 +182,7 @@ object PolyPlusClient { step("startup sounds") { StartupSounds.prepare() } step("cosmetics config preload") { PolyPlusCosmeticsConfig.preload() } step("pylon raw input") { PylonRawInput.initialize() } + step("controller actions") { PolyPlusControllers.initialize() } step("privacy enforcement") { PrivacyEnforcement.syncConfig() } step("legal documents") { if (PrivacyConsent.state() == PrivacyConsent.State.ACCEPTED && !PrivacyConsent.managedByLauncher) { diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/PolyPlusControllers.kt b/src/main/kotlin/org/polyfrost/polyplus/client/PolyPlusControllers.kt new file mode 100644 index 000000000..4d9522bf1 --- /dev/null +++ b/src/main/kotlin/org/polyfrost/polyplus/client/PolyPlusControllers.kt @@ -0,0 +1,51 @@ +package org.polyfrost.polyplus.client + +import org.polyfrost.compose.host.controller.ControllerAction +import org.polyfrost.compose.host.controller.Controllers +import org.polyfrost.oneconfig.api.event.v1.eventHandler +import org.polyfrost.oneconfig.api.event.v1.events.TickEvent +import org.polyfrost.polyplus.client.emotes.EmoteWheelKeybind +import org.polyfrost.polyplus.client.gui.PolyPlusOneConfigIntegration +import org.polyfrost.polyplus.client.party.PartyVoice +import org.polyfrost.polyplus.client.ping.PingInput +import org.polyfrost.polyplus.client.social.SocialOverlay + +object PolyPlusControllers { + private const val CATEGORY = "polyplus.controller.category" + + private class Held(val action: ControllerAction, val onChange: (Boolean) -> Unit) { + var down = false + + fun poll() { + val now = action.isPressed + if (now == down) return + down = now + onChange(now) + } + } + + private val held = ArrayList() + + fun initialize() { + tap("open_socials", "openSocials") { SocialOverlay.toggle() } + tap("open_wardrobe", "openWardrobe") { PolyPlusOneConfigIntegration.openCosmeticsFromKeybind() } + tap("toggle_mute", "toggleMute") { PartyVoice.onToggleMuteKey() } + tap("toggle_deafen", "toggleDeafen") { PartyVoice.onToggleDeafenKey() } + tap("join_leave_voice", "joinLeaveVoice") { PartyVoice.onJoinLeaveKey() } + hold("emote_wheel", "emoteWheel") { EmoteWheelKeybind.onKeybindState(it) } + hold("ping", "ping") { PingInput.onControllerState(it) } + hold("push_to_talk", "pushToTalk") { PartyVoice.onPushToTalk(it) } + eventHandler { for (entry in held) entry.poll() } + } + + private fun register(id: String, name: String, radial: Boolean): ControllerAction = + Controllers.register("polyplus:$id", "polyplus.controller.$name", category = CATEGORY, radial = radial) + + private fun tap(id: String, name: String, run: () -> Unit) { + register(id, name, radial = true).onPress { run() } + } + + private fun hold(id: String, name: String, onChange: (Boolean) -> Unit) { + held += Held(register(id, name, radial = false), onChange) + } +} diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/WheelOverlay.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/WheelOverlay.kt index d8ec9b745..144aea88b 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/WheelOverlay.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/WheelOverlay.kt @@ -22,6 +22,7 @@ import org.polyfrost.oneconfig.api.ui.v1.components.RadialMenuDefaults import org.polyfrost.oneconfig.api.ui.v1.components.RadialMenuInput import org.polyfrost.oneconfig.api.ui.v1.components.RadialMenuItem import org.polyfrost.oneconfig.api.ui.v1.components.RadialMenuState +import org.polyfrost.compose.host.controller.Controllers import org.polyfrost.compose.minecraft.hud.HudLayer import org.polyfrost.oneconfig.api.ui.v1.platform.OneConfigComposeOptions import org.polyfrost.polyplus.client.lobby.LobbyScene @@ -85,6 +86,8 @@ fun HudRadialMenu( object WheelOverlay { private const val SCROLL_NOTCH = 1.0 private const val PULL_GAIN = 1.9 + private const val STICK_DEAD = 0.35f + private const val STICK_REACH = 10_000f private var session: WheelSession? = null private var shown by mutableStateOf(null) @@ -93,6 +96,8 @@ object WheelOverlay { private var fadeEndsAt = 0L private var scrollAccum = 0.0 private var started = false + private var look: AutoCloseable? = null + private var stickUsed = false private val layer = HudLayer("radial_wheel", OneConfigComposeOptions) { Content() }.apply { acceptsInput = false } @@ -109,6 +114,8 @@ object WheelOverlay { lobbyHost = null session = next shown = next + stickUsed = false + if (Controllers.isActive) look = Controllers.captureLook() return true } @@ -216,6 +223,7 @@ object WheelOverlay { cancel() return } + if (look != null) steerWithStick(current) if (!current.held()) finish(true) } @@ -223,10 +231,20 @@ object WheelOverlay { if (session == null && lobbyShown != null && System.currentTimeMillis() >= fadeEndsAt) lobbyShown = null } + private fun steerWithStick(current: WheelSession) { + val stick = Controllers.rightStick + val deflected = stick.getDistance() >= STICK_DEAD + if (deflected) stickUsed = true + if (!stickUsed) return + if (deflected) current.state.aimAt(stick.x * STICK_REACH, stick.y * STICK_REACH) else current.state.aimAt(0f, 0f) + } + private fun finish(pick: Boolean) { val current = session ?: return session = null lobbyHost = null + look?.close() + look = null fadeEndsAt = System.currentTimeMillis() + if (Motion.reduced) 0L else RadialMenuDefaults.fadeMillis.toLong() if (!pick) { current.state.dismiss() diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/ping/PingInput.kt b/src/main/kotlin/org/polyfrost/polyplus/client/ping/PingInput.kt index 31ec5d053..ff6ad8161 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/ping/PingInput.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/ping/PingInput.kt @@ -3,6 +3,7 @@ package org.polyfrost.polyplus.client.ping import net.minecraft.client.Minecraft import net.minecraft.client.resources.sounds.SimpleSoundInstance import net.minecraft.sounds.SoundEvents +import org.polyfrost.compose.host.controller.Controllers import org.polyfrost.oneconfig.api.event.v1.eventHandler import org.polyfrost.oneconfig.api.event.v1.events.KeyInputEvent import org.polyfrost.oneconfig.api.event.v1.events.MouseInputEvent @@ -50,6 +51,7 @@ object PingInput { private const val HINT_TEXT = 0xFFFFFFFF.toInt() private const val MIN_ALPHA = 0.05f private const val MS_PER_SECOND = 1000L + private const val STICK_OPEN = 0.6f @Volatile private var held = false @@ -62,6 +64,7 @@ object PingInput { private var pickPress = false private var swallowPick = false + private var controllerHeld = false private val downKeys = HashSet() private val downMouse = HashSet() @@ -96,6 +99,12 @@ object PingInput { if (pressed) press() else release() } + fun onControllerState(pressed: Boolean) { + ensureStarted() + controllerHeld = pressed + if (pressed) press(fromController = true) else release() + } + private fun syncRaw() { val bind = PolyPlusConfig.pingKeybind var mods = KeyModifiers.NONE @@ -117,7 +126,7 @@ object PingInput { pickPress = false } - private fun press() { + private fun press(fromController: Boolean = false) { held = true pending = false pickPress = false @@ -127,7 +136,7 @@ object PingInput { pressedAt = System.currentTimeMillis() dragX = 0.0 dragY = 0.0 - if (!sharesPickInput(PolyPlusConfig.pingKeybind)) return + if (fromController || !sharesPickInput(PolyPlusConfig.pingKeybind)) return if (hoveredTarget() == null && crosshairInReach() && !usingItem()) pickPress = true else swallowPick = true } @@ -224,7 +233,8 @@ object PingInput { private fun tick() { if (!held) swallowPick = false - if (pending && held && System.currentTimeMillis() - pressedAt >= HOLD_MS) { + val flicked = controllerHeld && Controllers.rightStick.getDistance() >= STICK_OPEN + if (pending && held && (flicked || System.currentTimeMillis() - pressedAt >= HOLD_MS)) { pending = false pickPress = false if (canPing() && !WheelOverlay.isOpen) openWheel() diff --git a/src/main/resources/assets/polyplus/lang/en_us.json b/src/main/resources/assets/polyplus/lang/en_us.json index 8eee2987a..7384b5616 100644 --- a/src/main/resources/assets/polyplus/lang/en_us.json +++ b/src/main/resources/assets/polyplus/lang/en_us.json @@ -16,5 +16,14 @@ "polyplus.session.reconnecting": "Reconnecting...", "polyplus.session.refreshFailed": "Refresh failed - click to retry", "polyplus.page.wardrobe": "Wardrobe", - "polyplus.sodium.options.view_bobbing.tooltip": "If enabled, the player's view will sway and bob when moving around. Players who experience motion sickness while playing may benefit from disabling this." + "polyplus.sodium.options.view_bobbing.tooltip": "If enabled, the player's view will sway and bob when moving around. Players who experience motion sickness while playing may benefit from disabling this.", + "polyplus.controller.category": "PolyPlus", + "polyplus.controller.openSocials": "Open Socials", + "polyplus.controller.openWardrobe": "Open Wardrobe", + "polyplus.controller.emoteWheel": "Emote Wheel", + "polyplus.controller.ping": "Ping", + "polyplus.controller.pushToTalk": "Push to Talk", + "polyplus.controller.toggleMute": "Toggle Mute", + "polyplus.controller.toggleDeafen": "Toggle Deafen", + "polyplus.controller.joinLeaveVoice": "Join or Leave Voice" } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index b1d64a576..7e81f14aa 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -41,6 +41,9 @@ "oneconfigv1": ">=${oneconfig_version}", "polycompose": ">=${polycompose_version}" }, + "suggests": { + "controlify": "*" + }, "breaks": { "auto-reauth": "*", "wwaypoints": "<0.8.0" From 3c0ac27b0ab3fd41b1453d1f61c3f5d0e45a055f Mon Sep 17 00:00:00 2001 From: Deftu Date: Tue, 24 Nov 2026 15:10:58 +0200 Subject: [PATCH 2/5] feat: make the lobby, wardrobe, onboarding and pause screens usable with a controller --- .../polyplus/client/gui/AccountSwitcher.kt | 13 +++- .../polyplus/client/gui/ControllerFocus.kt | 13 ++++ .../client/gui/PolyPlusLobbyScreen.kt | 9 ++- .../client/gui/PolyPlusOnboardingScreen.kt | 5 +- .../client/gui/gamesocial/SocialWindow.kt | 3 +- .../client/gui/lobbyshell/LobbyChrome.kt | 3 +- .../gui/lobbyshell/LobbyCustomizeKit.kt | 11 ++- .../gui/lobbyshell/LobbyMultiplayerPage.kt | 4 +- .../client/gui/lobbyshell/LobbyMusicButton.kt | 3 + .../client/gui/lobbyshell/LobbyParty.kt | 25 +++++-- .../client/gui/lobbyshell/LobbyPartyPlay.kt | 12 ++- .../gui/lobbyshell/StartupAccessibility.kt | 2 + .../client/gui/lobbysocial/SocialParty.kt | 13 +++- .../gui/menuwardrobe/MenuWardrobePage.kt | 19 +++-- .../gui/menuwardrobe/MenuWardrobePanels.kt | 3 +- .../gui/menuwardrobe/MenuWardrobePicker.kt | 40 +++++++--- .../client/gui/pausescreen/PauseClassic.kt | 3 +- .../gui/pausescreen/PausePerformance.kt | 7 +- .../client/gui/pausescreen/PauseQuickDock.kt | 2 + .../client/gui/pausescreen/PauseStepBack.kt | 3 +- .../client/gui/preview/PlayerPreview.kt | 75 ++++++++++++------- .../client/gui/serveredit/ServerEditDialog.kt | 13 ++-- .../client/gui/wardrobe/AuraColorPicker.kt | 65 ++++++++++++++++ .../client/gui/wardrobe/WardrobeGrid.kt | 16 +++- .../gui/wardrobe/WardrobeWheelEditor.kt | 3 + .../client/gui/widgets/WidgetColumn.kt | 4 +- 26 files changed, 289 insertions(+), 80 deletions(-) create mode 100644 src/main/kotlin/org/polyfrost/polyplus/client/gui/ControllerFocus.kt diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/AccountSwitcher.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/AccountSwitcher.kt index e9a93a3b1..9b24c90b0 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/AccountSwitcher.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/AccountSwitcher.kt @@ -38,6 +38,9 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.onFocusChanged +import org.polyfrost.compose.host.controller.ControllerButton +import org.polyfrost.compose.host.controller.controllerAction import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.rotate import androidx.compose.ui.graphics.Color @@ -289,6 +292,8 @@ private fun AccountRow(state: AccountsPanelState, account: OneLauncherAccounts.A val theme = OneConfigTheme.current val hover = rememberHoverState() var confirmRemove by remember { mutableStateOf(false) } + var focused by remember { mutableStateOf(false) } + val revealed = hover.hovered || focused val busy = actions.refreshingId == account.id || state.pendingId == account.id val idle = actions.idle val shape = OneConfigTheme.shape(CustomizeKit.RowRadius) @@ -305,6 +310,10 @@ private fun AccountRow(state: AccountsPanelState, account: OneLauncherAccounts.A .fillMaxWidth() .height(CustomizeKit.RowHeight) .graphicsLayer { alpha = if (idle || busy) 1f else theme.disabledAlpha } + .onFocusChanged { focused = it.hasFocus } + .controllerAction(ControllerButton.X, "Remove", enabled = idle && !busy && !confirmRemove) { confirmRemove = true } + .controllerAction(ControllerButton.Y, "Refresh", enabled = idle && !busy && !confirmRemove && account.refreshable) { state.refresh(account) } + .then(if (account.active) Modifier.focusableOnController() else Modifier) .hoverable(hover.interactionSource) .selectableRow( false, @@ -349,10 +358,10 @@ private fun AccountRow(state: AccountsPanelState, account: OneLauncherAccounts.A else -> { if (account.expired && account.refreshable) { TextButton(text = "Sign in again", onClick = { state.refresh(account) }, size = ControlSize.Compact, enabled = idle) - } else if (hover.hovered && account.refreshable) { + } else if (revealed && account.refreshable) { RowIcon("refresh-cw-01", "Refresh ${account.username}", theme.textColorSecondary, idle) { state.refresh(account) } } - if (hover.hovered) { + if (revealed) { RowIcon("trash-01", "Remove ${account.username}", theme.textColorSecondary, idle) { confirmRemove = true } } else if (account.active) { LobbyIcon("check", OneConfigTheme.accent, 18.dp) diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/ControllerFocus.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/ControllerFocus.kt new file mode 100644 index 000000000..46c4cb26e --- /dev/null +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/ControllerFocus.kt @@ -0,0 +1,13 @@ +package org.polyfrost.polyplus.client.gui + +import androidx.compose.foundation.focusable +import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.focusProperties +import org.polyfrost.compose.host.controller.Controllers + +internal fun Modifier.controllerFocusOnly(): Modifier { + val active = Controllers.isActive + return focusProperties { canFocus = active } +} + +internal fun Modifier.focusableOnController(): Modifier = focusable(enabled = Controllers.isActive) diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/PolyPlusLobbyScreen.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/PolyPlusLobbyScreen.kt index a68620514..5dfe4cbe6 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/PolyPlusLobbyScreen.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/PolyPlusLobbyScreen.kt @@ -2,6 +2,7 @@ package org.polyfrost.polyplus.client.gui +import org.polyfrost.compose.host.controller.ControllerGuide import org.polyfrost.oneconfig.api.ui.v1.ExperimentalOneConfigUiApi import androidx.compose.runtime.Composable import com.mojang.blaze3d.platform.InputConstants @@ -12,6 +13,7 @@ import net.minecraft.client.gui.GuiGraphicsExtractor *///?} else { /*import net.minecraft.client.gui.screen.Screen *///?} +import org.polyfrost.compose.host.controller.Controllers import org.polyfrost.oneconfig.api.ui.v1.components.ProvidePopupSounds import org.polyfrost.oneconfig.api.ui.v1.platform.OneConfigComposeScreen import org.polyfrost.oneconfig.api.ui.v1.keybind.KeybindManager @@ -41,6 +43,8 @@ class PolyPlusLobbyScreen internal constructor(firstPage: LobbyPage) : OneConfig override val dimBackground: Boolean get() = false + override val controllerGuide: ControllerGuide get() = ControllerGuide.BottomCenter + override fun init() { lobby.open() super.init() @@ -80,7 +84,7 @@ class PolyPlusLobbyScreen internal constructor(firstPage: LobbyPage) : OneConfig return key !in wheelKeys } if (emoteWheelReady() && EmoteWheelKeybind.claimsKey(key, modifiers)) return true - if (key in navigationKeys) keyNavigated = true + if (key in navigationKeys || Controllers.isDispatching) keyNavigated = true LobbyAntics.key(key, lobby.calm()) if (lobby.setup && StartupAccessibility.handleKey(key, modifiers)) return true if (lobby.setup && OnboardingKeyCapture.capture(key)) return true @@ -96,7 +100,8 @@ class PolyPlusLobbyScreen internal constructor(firstPage: LobbyPage) : OneConfig *///?} } val enter = key == InputConstants.KEY_RETURN || key == InputConstants.KEY_NUMPADENTER - if (enter && (lobby.tour != null || !keyNavigated || !LobbyA11y.keyboardFocused()) && lobby.openSocial()) return true + val keyboardOnly = !Controllers.isDispatching && (!keyNavigated || !LobbyA11y.keyboardFocused()) + if (enter && (lobby.tour != null || keyboardOnly) && lobby.openSocial()) return true return super.handleKeyPressed(key, modifiers) } diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/PolyPlusOnboardingScreen.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/PolyPlusOnboardingScreen.kt index eaa795e31..2ef59cba7 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/PolyPlusOnboardingScreen.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/PolyPlusOnboardingScreen.kt @@ -80,6 +80,7 @@ import androidx.compose.ui.geometry.Offset import androidx.compose.ui.geometry.Rect import androidx.compose.ui.geometry.Size import org.polyfrost.compose.backend.drawPoly +import org.polyfrost.compose.host.controller.Controllers import org.polyfrost.compose.render.FilterQuality import org.polyfrost.compose.render.PolyBitmap import org.polyfrost.compose.render.PolyColor @@ -2479,7 +2480,7 @@ internal object OnboardingKeyCapture { fun capture(key: Int): Boolean { val capture = pending ?: return false capture( - if (key == InputConstants.KEY_ESCAPE) { + if (key == InputConstants.KEY_ESCAPE || Controllers.isDispatching) { null } else { //? if >= 26.3 || = 1.8.9 { @@ -2524,7 +2525,7 @@ internal object OnboardingKeys { when (key) { InputConstants.KEY_ESCAPE -> if (!BackStack.dispatch()) (back ?: return false)() InputConstants.KEY_RETURN, InputConstants.KEY_NUMPADENTER -> { - if (LobbyA11y.keyboardFocused()) return false + if (LobbyA11y.keyboardFocused() || Controllers.isDispatching) return false if (System.currentTimeMillis() - pageAt < PAGE_SETTLE_MS) return true val action = next when { diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/gamesocial/SocialWindow.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/gamesocial/SocialWindow.kt index 0a44dad08..1a31b567b 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/gamesocial/SocialWindow.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/gamesocial/SocialWindow.kt @@ -40,6 +40,7 @@ import androidx.compose.ui.unit.dp import kotlinx.coroutines.delay import net.minecraft.client.gui.screens.Screen import net.minecraft.client.multiplayer.ServerData +import org.polyfrost.compose.host.controller.Controllers import org.polyfrost.oneconfig.api.ui.v1.ExperimentalOneConfigUiApi import org.polyfrost.oneconfig.api.ui.v1.keybind.TextInputFocus import org.polyfrost.oneconfig.api.ui.v1.components.ControlSize @@ -225,7 +226,7 @@ internal class SocialWindowState(val screen: Screen, openWorld: Boolean) { fun enter(): Boolean { val covered = SocialEscape.popupOpen || SocialPageState.dialogOpen || TextInputFocus.isTyping - if (covered || SocialChatLink.active == null) return false + if (covered || Controllers.isDispatching || SocialChatLink.active == null) return false return runCatching { composer.requestFocus() }.isSuccess } } diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyChrome.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyChrome.kt index 4c22b71cd..c7a2c9dac 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyChrome.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyChrome.kt @@ -2,6 +2,7 @@ package org.polyfrost.polyplus.client.gui.lobbyshell +import org.polyfrost.compose.host.controller.focusWhenShown import org.polyfrost.oneconfig.api.ui.v1.components.rememberHoverState import org.polyfrost.polyplus.client.events.EventsRepository import org.polyfrost.polyplus.client.gui.KitDangerColor @@ -322,7 +323,7 @@ private fun BoxScope.LobbyChrome(lobby: LobbyShell, screen: Screen, feed: LobbyF } val claiming = EventsRepository.claiming LaunchedEffect(claiming) { EventsStage.settleCharge() } - Box(Modifier.fillMaxSize().offset { if (revealing) IntOffset(0, root.height * 2) else IntOffset.Zero }.a11yRegion(A11yRegion.Page)) { when (lobby.page) { + Box(Modifier.fillMaxSize().offset { if (revealing) IntOffset(0, root.height * 2) else IntOffset.Zero }.a11yRegion(A11yRegion.Page).focusWhenShown(lobby.page != LobbyPage.Home, lobby.page)) { when (lobby.page) { LobbyPage.Home -> { Box(Modifier.fillMaxSize().pointerHoverIcon(if (LobbyGift.hovered != null) PointerIcon.Hand else PointerIcon.Default).avatarTaps(lobby, notch)) SceneTags(lobby, feed, root, notch) diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyCustomizeKit.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyCustomizeKit.kt index dfb9e74be..c0c80ba90 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyCustomizeKit.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyCustomizeKit.kt @@ -34,6 +34,8 @@ import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.alpha +import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.graphics.graphicsLayer import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.layout.onGloballyPositioned @@ -43,6 +45,9 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.dp +import org.polyfrost.compose.host.controller.controllerFocusScope +import org.polyfrost.compose.host.controller.focusEntry +import org.polyfrost.compose.host.controller.focusWhenShown import org.polyfrost.oneconfig.api.ui.v1.ExperimentalOneConfigUiApi import org.polyfrost.oneconfig.api.ui.v1.a11y.A11yRole import org.polyfrost.oneconfig.api.ui.v1.a11y.Motion @@ -111,10 +116,11 @@ internal fun DockedPanel( if (open && root.width > 0f) LobbyFraming.panelInset = ((it.size.width + marginPx) / root.width).coerceIn(0f, MAX_INSET) } .panel(PANEL_RADIUS) + .controllerFocusScope(open) .pointerInput(Unit) { awaitPointerEventScope { while (true) awaitPointerEvent() } }, ) { PanelHeader(title, onClose, onBack) - Box(Modifier.weight(1f).fillMaxWidth(), content = content) + Box(Modifier.weight(1f).fillMaxWidth().focusWhenShown(open, title), content = content) } } } @@ -305,11 +311,13 @@ internal fun Segmented( val theme = OneConfigTheme.current val perRow = columns.coerceAtLeast(1) val itemShape = OneConfigTheme.shape(8.dp) + val selectedFocus = remember { FocusRequester() } Column( modifier .fillMaxWidth() .alpha(if (enabled) 1f else theme.disabledAlpha) .card(11.dp) + .focusEntry(selectedFocus, enabled && selected in options) .padding(3.dp), verticalArrangement = Arrangement.spacedBy(2.dp), ) { @@ -322,6 +330,7 @@ internal fun Segmented( Modifier .weight(1f) .height(CustomizeKit.SegmentHeight) + .then(if (on) Modifier.focusRequester(selectedFocus) else Modifier) .selectableRow(on, { if (!on) onSelect(option) }, text, itemShape, enabled, ItemSelectionStyle.Accent, A11yRole.RadioButton), contentAlignment = Alignment.Center, ) { diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyMultiplayerPage.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyMultiplayerPage.kt index 95846a947..e9d755e7e 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyMultiplayerPage.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyMultiplayerPage.kt @@ -86,7 +86,6 @@ import org.polyfrost.oneconfig.api.ui.v1.components.MenuHeading import org.polyfrost.oneconfig.api.ui.v1.components.MenuRadioGroup import org.polyfrost.oneconfig.api.ui.v1.components.AnchoredPopupButton import org.polyfrost.oneconfig.api.ui.v1.components.Placement -import androidx.compose.ui.focus.focusProperties import org.polyfrost.polyplus.client.featured.ServerFolders import org.polyfrost.oneconfig.api.ui.v1.components.ConfirmDialog import org.polyfrost.oneconfig.api.ui.v1.components.DialogButtons @@ -102,6 +101,7 @@ import org.polyfrost.polyplus.client.PolyPlusLobbyConfig import org.polyfrost.polyplus.client.PolyPlusMainMenuConfig import org.polyfrost.polyplus.client.featured.FeaturedServers import org.polyfrost.polyplus.client.gui.SocialDangerText +import org.polyfrost.polyplus.client.gui.controllerFocusOnly import org.polyfrost.polyplus.client.gui.ASSETS import org.polyfrost.polyplus.client.gui.RasterImage import org.polyfrost.polyplus.client.gui.SOCIAL_ASSETS @@ -244,7 +244,7 @@ private fun FolderNameDialog( AnchoredPopupButton( icon = "down", contentDescription = "Pick a folder", - modifier = Modifier.focusProperties { canFocus = false }, + modifier = Modifier.controllerFocusOnly(), placement = Placement.BelowEnd, ) { closeMenu -> MenuList(suggestions.map { folder -> MenuAction(folder, { name = folder }, checked = folder.equals(name.trim(), ignoreCase = true)) }, closeMenu) diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyMusicButton.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyMusicButton.kt index e81c830d3..9d5dff8d8 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyMusicButton.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyMusicButton.kt @@ -20,6 +20,8 @@ import androidx.compose.runtime.rememberUpdatedState import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import org.polyfrost.compose.host.controller.ControllerButton +import org.polyfrost.compose.host.controller.controllerAction import androidx.compose.ui.input.pointer.PointerEventType import androidx.compose.ui.input.pointer.isSecondaryPressed import androidx.compose.ui.input.pointer.pointerInput @@ -109,6 +111,7 @@ internal fun LobbyMusicButton(lobby: LobbyShell, first: Boolean, last: Boolean) Box( Modifier .hoverable(tileHover.interactionSource) + .controllerAction(ControllerButton.X, "Sound settings") { settings() } .pointerInput(Unit) { awaitPointerEventScope { while (true) { diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyParty.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyParty.kt index dbb9ada3e..380556f0f 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyParty.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyParty.kt @@ -334,6 +334,8 @@ private fun PartyPopupButton(icon: String, contentDescription: String, tint: Col ) } +private enum class FirstCard { Request, Hosted, Rejoin, LeaderMoved, Invite } + @Composable internal fun PartyInviteCards(host: SocialHost) { val invites by PartyRepository.incomingInvites.collectAsState() @@ -341,13 +343,26 @@ internal fun PartyInviteCards(host: SocialHost) { val rejoin = rejoinableWorld()?.takeUnless { hosted?.sessionId == it.sessionId } val requests = HostJoinRequests.pending if (invites.isEmpty() && LeaderFollow.card == null && rejoin == null && hosted == null && requests.isEmpty()) return + val shownRequests = requests.takeLast(MAX_INVITE_CARDS) + val shownInvites = invites.takeLast(MAX_INVITE_CARDS) + val first = when { + shownRequests.isNotEmpty() -> FirstCard.Request + hosted != null -> FirstCard.Hosted + rejoin != null -> FirstCard.Rejoin + LeaderFollow.card != null -> FirstCard.LeaderMoved + else -> FirstCard.Invite + } Popup(popupPositionProvider = rememberAbove(alignEnd = true), properties = PopupProperties(focusable = false)) { Column(verticalArrangement = Arrangement.spacedBy(8.dp)) { - requests.takeLast(MAX_INVITE_CARDS).forEach { request -> key(request.id) { HostJoinRequestCard(request) } } - hosted?.let { LeaderHostingCard(it) } - rejoin?.let { RejoinWorldCard(it) } - LeaderMovedCard(host) - invites.takeLast(MAX_INVITE_CARDS).forEach { invite -> key(invite.id) { PartyInviteCard(invite) } } + shownRequests.forEachIndexed { index, request -> + key(request.id) { HostJoinRequestCard(request, shortcut = first == FirstCard.Request && index == 0) } + } + hosted?.let { LeaderHostingCard(it, shortcut = first == FirstCard.Hosted) } + rejoin?.let { RejoinWorldCard(it, shortcut = first == FirstCard.Rejoin) } + LeaderMovedCard(host, shortcut = first == FirstCard.LeaderMoved) + shownInvites.forEachIndexed { index, invite -> + key(invite.id) { PartyInviteCard(invite, shortcut = first == FirstCard.Invite && index == 0) } + } } } } diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyPartyPlay.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyPartyPlay.kt index 12cf091e1..eff8aeb08 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyPartyPlay.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyPartyPlay.kt @@ -73,7 +73,7 @@ internal fun PlayTogetherHooks(host: SocialHost) { } @Composable -internal fun LeaderMovedCard(host: SocialHost) { +internal fun LeaderMovedCard(host: SocialHost, shortcut: Boolean = false) { val card = LeaderFollow.card ?: return val incompatible = card.check == ServerCheck.Result.INCOMPATIBLE LeaderJoinEffect(host) @@ -88,6 +88,7 @@ internal fun LeaderMovedCard(host: SocialHost) { captionFirst = true, acceptEnabled = !incompatible && !card.checking && !card.cleared, warning = if (incompatible) PartyCardText.needs(card.needs) else null, + shortcut = shortcut, ) } @@ -99,7 +100,7 @@ internal fun leaderHostedWorld(): LeaderFollow.Hosted? { } @Composable -internal fun LeaderHostingCard(hosted: LeaderFollow.Hosted) { +internal fun LeaderHostingCard(hosted: LeaderFollow.Hosted, shortcut: Boolean = false) { val names by PlayerNamesRepository.names.collectAsState() val name = names[hosted.leader] ?: hosted.name PartyCard( @@ -112,11 +113,12 @@ internal fun LeaderHostingCard(hosted: LeaderFollow.Hosted) { LeaderFollow::joinHosted, captionFirst = true, acceptEnabled = !hosted.busy, + shortcut = shortcut, ) } @Composable -internal fun HostJoinRequestCard(request: HostJoinRequests.Request) { +internal fun HostJoinRequestCard(request: HostJoinRequests.Request, shortcut: Boolean = false) { val names by PlayerNamesRepository.names.collectAsState() PartyCard( request.player, @@ -128,6 +130,7 @@ internal fun HostJoinRequestCard(request: HostJoinRequests.Request) { { HostJoinRequests.allow(request.id) }, acceptEnabled = !request.answering, dismissEnabled = !request.answering, + shortcut = shortcut, ) } @@ -139,7 +142,7 @@ internal fun rejoinableWorld(): SessionInvite? { } @Composable -internal fun RejoinWorldCard(invite: SessionInvite) { +internal fun RejoinWorldCard(invite: SessionInvite, shortcut: Boolean = false) { PartyCard( invite.sender, PartyCardText.world(PlayerNamesRepository.nameOr(invite.sender)), @@ -148,6 +151,7 @@ internal fun RejoinWorldCard(invite: SessionInvite) { P2PSessionManager::forgetRejoin, "Rejoin", P2PSessionManager::rejoin, + shortcut = shortcut, ) } diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/StartupAccessibility.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/StartupAccessibility.kt index 6019be067..3f97176d1 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/StartupAccessibility.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/StartupAccessibility.kt @@ -8,6 +8,7 @@ import androidx.compose.runtime.setValue import com.mojang.blaze3d.platform.InputConstants import net.minecraft.client.Minecraft import net.minecraft.client.resources.language.I18n +import org.polyfrost.compose.host.controller.Controllers import org.polyfrost.oneconfig.api.platform.v1.Platform import org.polyfrost.oneconfig.api.ui.v1.ExperimentalOneConfigUiApi import org.polyfrost.oneconfig.api.ui.v1.a11y.A11y @@ -160,6 +161,7 @@ internal object StartupAccessibility { fun handleKey(key: Int, modifiers: Int): Boolean { val exit = leave ?: return OnboardingKeys.handle(key) + if (Controllers.isDispatching && key != InputConstants.KEY_ESCAPE) return false when (key) { InputConstants.KEY_ESCAPE -> exit() InputConstants.KEY_TAB -> move(if (modifiers and SHIFT_MODIFIER != 0) -1 else 1) diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbysocial/SocialParty.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbysocial/SocialParty.kt index 9bef9623d..fc6b98abb 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbysocial/SocialParty.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbysocial/SocialParty.kt @@ -33,6 +33,8 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import org.polyfrost.compose.host.controller.ControllerButton +import org.polyfrost.compose.host.controller.controllerAction import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import androidx.compose.ui.window.PopupPositionProvider @@ -605,8 +607,14 @@ internal fun PartyCard( acceptEnabled: Boolean = true, dismissEnabled: Boolean = true, warning: String? = null, + shortcut: Boolean = false, ) { - Column(modifier.width(PartyCardWidth).popup().padding(12.dp), verticalArrangement = Arrangement.spacedBy(10.dp)) { + val frame = modifier + .controllerAction(ControllerButton.Y, acceptLabel, enabled = shortcut && acceptEnabled, requireFocus = false, onPress = onAccept) + .width(PartyCardWidth) + .popup() + .padding(12.dp) + Column(frame, verticalArrangement = Arrangement.spacedBy(10.dp)) { Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) { PlayerHead(seedOf(player), 34.dp, Modifier, shape = headShape(34.dp)) Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(2.dp)) { @@ -632,7 +640,7 @@ internal fun PartyCard( } @Composable -internal fun PartyInviteCard(invite: PartyInvite, modifier: Modifier = Modifier) { +internal fun PartyInviteCard(invite: PartyInvite, modifier: Modifier = Modifier, shortcut: Boolean = false) { val names by PlayerNamesRepository.names.collectAsState() PartyCard( invite.sender, @@ -643,6 +651,7 @@ internal fun PartyInviteCard(invite: PartyInvite, modifier: Modifier = Modifier) PartyCardText.JOIN_PARTY, { PartyRepository.accept(invite) }, modifier, + shortcut = shortcut, ) } diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/menuwardrobe/MenuWardrobePage.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/menuwardrobe/MenuWardrobePage.kt index 32aae3e4d..1ece06567 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/menuwardrobe/MenuWardrobePage.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/menuwardrobe/MenuWardrobePage.kt @@ -37,6 +37,8 @@ import androidx.compose.runtime.setValue import androidx.compose.runtime.snapshotFlow import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import org.polyfrost.compose.host.controller.controllerPan +import org.polyfrost.polyplus.client.gui.focusableOnController import androidx.compose.ui.geometry.Offset import androidx.compose.ui.geometry.Size import androidx.compose.ui.graphics.Brush @@ -94,6 +96,7 @@ private const val FACING_CAMERA = 180f private const val FRONT_YAW = FACING_CAMERA - 16f private const val BACK_YAW = -15f private const val DRAG_DEGREES = 0.5f +private const val PAN_DEGREES = 0.125f private const val STATUS_VISIBLE_MS = 4_000L private const val TRY_BAR_REACH_MS = 600L private const val FALLBACK_MODEL_SCALE = 0.36f @@ -411,13 +414,19 @@ private fun WardrobeContent(online: Boolean, onBack: () -> Unit, onMarketplace: .fillMaxSize() if (liveScene) { Box( - freeArea.pointerInput(rotation) { - detectDragGestures { change, drag -> - rotation.yaw -= drag.x * DRAG_DEGREES + freeArea + .pointerInput(rotation) { + detectDragGestures { change, drag -> + rotation.yaw -= drag.x * DRAG_DEGREES + rotation.userRotated = true + change.consume() + } + } + .controllerPan { delta -> + rotation.yaw -= delta.x * PAN_DEGREES rotation.userRotated = true - change.consume() } - }, + .focusableOnController(), ) } else { Canvas(freeArea) { diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/menuwardrobe/MenuWardrobePanels.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/menuwardrobe/MenuWardrobePanels.kt index 39467b7d9..6d8e7ba96 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/menuwardrobe/MenuWardrobePanels.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/menuwardrobe/MenuWardrobePanels.kt @@ -137,7 +137,8 @@ internal fun EquippedRail( current < 0 -> if (delta > 0) 0 else slots.lastIndex else -> (current + delta).coerceIn(0, slots.lastIndex) } - if (next != current) onSelect(slots[next].type) + if (next == current) return false + onSelect(slots[next].type) scope.launch { withFrameNanos {} withFrameNanos {} diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/menuwardrobe/MenuWardrobePicker.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/menuwardrobe/MenuWardrobePicker.kt index 605f75d31..2e660fcd7 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/menuwardrobe/MenuWardrobePicker.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/menuwardrobe/MenuWardrobePicker.kt @@ -39,6 +39,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester +import androidx.compose.ui.focus.onFocusChanged import androidx.compose.ui.input.key.Key import androidx.compose.ui.input.key.KeyEvent import androidx.compose.ui.input.key.KeyEventType @@ -51,6 +52,7 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch +import org.polyfrost.compose.host.controller.isFromController import org.polyfrost.oneconfig.api.ui.v1.ExperimentalOneConfigUiApi import org.polyfrost.oneconfig.api.ui.v1.components.Badge import org.polyfrost.oneconfig.api.ui.v1.components.Chip @@ -204,6 +206,7 @@ internal fun SlotPicker(model: PickerModel, modifier: Modifier = Modifier) { var query by remember(model.type) { mutableStateOf("") } var filter by remember(model.type) { mutableStateOf(PickerFilter.All) } var cursor by remember(model.type) { mutableStateOf(model.selected?.key) } + var gridFocused by remember { mutableStateOf(false) } val grid = remember(model.type) { LazyGridState() } val focus = remember { FocusRequester() } val scope = rememberCoroutineScope() @@ -213,21 +216,27 @@ internal fun SlotPicker(model: PickerModel, modifier: Modifier = Modifier) { LaunchedEffect(model.selected?.key) { model.selected?.key?.let { cursor = it } } LaunchedEffect(model.type) { runCatching { focus.requestFocus() } } - fun move(delta: Int) { + fun move(delta: Int): Boolean { val list = current.entries.filter { it.matches(filter, query) } - if (list.isEmpty()) return + if (list.isEmpty()) return false val from = list.indexOfFirst { it.key == (cursor ?: current.selected?.key ?: current.target?.key) } val next = if (from < 0) 0 else (from + delta).coerceIn(0, list.lastIndex) + if (next == from) return false val entry = list[next] cursor = entry.key if (!current.picksToWheel) current.onPick(entry) scope.revealItem(grid, next) + return true } fun confirm(): Boolean { val model = current + val entry = model.entries.firstOrNull { it.key == cursor } if (model.picksToWheel) { - val entry = model.entries.firstOrNull { it.key == cursor } ?: return false + model.onPick(entry ?: return false) + return true + } + if (entry != null && entry.key != model.selected?.key) { model.onPick(entry) return true } @@ -239,11 +248,12 @@ internal fun SlotPicker(model: PickerModel, modifier: Modifier = Modifier) { fun onKey(event: KeyEvent): Boolean { if (event.type != KeyEventType.KeyDown) return false + val arrows = !event.isFromController || gridFocused return when (event.key) { - Key.DirectionLeft -> { move(-1); true } - Key.DirectionRight -> { move(1); true } - Key.DirectionUp -> { move(-GRID_COLUMNS); true } - Key.DirectionDown -> { move(GRID_COLUMNS); true } + Key.DirectionLeft -> arrows && move(-1) + Key.DirectionRight -> arrows && move(1) + Key.DirectionUp -> arrows && move(-GRID_COLUMNS) + Key.DirectionDown -> arrows && move(GRID_COLUMNS) Key.Enter, Key.NumPadEnter -> confirm() else -> false } @@ -274,12 +284,13 @@ internal fun SlotPicker(model: PickerModel, modifier: Modifier = Modifier) { .padding(top = CustomizeKit.SectionGap) .focusRequester(focus) .onPreviewKeyEvent(::onKey) + .onFocusChanged { gridFocused = it.isFocused } .focusable(), ) { if (shown.isEmpty() && model.onMarketplace == null) { NoMatches(Modifier.fillMaxSize()) } else { - PickerGrid(model, shown, grid, cursor) { entry -> + PickerGrid(model, shown, grid, cursor, onTileFocus = { cursor = it.key }) { entry -> cursor = entry.key runCatching { focus.requestFocus() } } @@ -305,7 +316,14 @@ private fun CoroutineScope.revealItem(grid: LazyGridState, index: Int) { } @Composable -private fun PickerGrid(model: PickerModel, shown: List, grid: LazyGridState, cursor: String?, onTileClick: (PickerEntry) -> Unit) { +private fun PickerGrid( + model: PickerModel, + shown: List, + grid: LazyGridState, + cursor: String?, + onTileFocus: (PickerEntry) -> Unit, + onTileClick: (PickerEntry) -> Unit, +) { val current by rememberUpdatedState(model) var lastClickKey by remember { mutableStateOf(null) } var lastClickAt by remember { mutableLongStateOf(0L) } @@ -343,6 +361,7 @@ private fun PickerGrid(model: PickerModel, shown: List, grid: LazyG entry = entry, model = model, selected = entry.key == model.selected?.key || (model.picksToWheel && entry.key == cursor), + onFocus = { onTileFocus(entry) }, onClick = { click(entry) }, ) } @@ -352,7 +371,7 @@ private fun PickerGrid(model: PickerModel, shown: List, grid: LazyG } @Composable -private fun PickerTile(entry: PickerEntry, model: PickerModel, selected: Boolean, onClick: () -> Unit) { +private fun PickerTile(entry: PickerEntry, model: PickerModel, selected: Boolean, onFocus: () -> Unit, onClick: () -> Unit) { val hover = rememberHoverState() TryOnWhileHovered(entry, hover.hovered, model.onHover) val theme = OneConfigTheme.current @@ -362,6 +381,7 @@ private fun PickerTile(entry: PickerEntry, model: PickerModel, selected: Boolean .fillMaxWidth() .then(if (entry.equipped && !selected) Modifier.border(1.5.dp, OneConfigTheme.accent, shape) else Modifier) .hoverable(hover.interactionSource) + .onFocusChanged { if (it.isFocused) onFocus() } .selectableRow(selected, onClick, entry.name, shape, style = ItemSelectionStyle.Accent, interactionSource = hover.interactionSource) .padding(6.dp), horizontalAlignment = Alignment.CenterHorizontally, diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/pausescreen/PauseClassic.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/pausescreen/PauseClassic.kt index f7cd3abd9..dc06abde5 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/pausescreen/PauseClassic.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/pausescreen/PauseClassic.kt @@ -30,6 +30,7 @@ import androidx.compose.ui.layout.onGloballyPositioned import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp +import org.polyfrost.compose.host.controller.focusWhenShown import org.polyfrost.oneconfig.api.ui.v1.ExperimentalOneConfigUiApi import org.polyfrost.oneconfig.api.ui.v1.a11y.Motion import org.polyfrost.oneconfig.api.ui.v1.components.BadgeTone @@ -164,7 +165,7 @@ private fun ClassicGrid(screen: OneClientPauseScreen, layout: ClassicLayout) { Column(Modifier.fillMaxWidth().blockPointer(), verticalArrangement = Arrangement.spacedBy(CLASSIC_GAP)) { ClassicButton( capture.entry(PauseSlot.RESUME)?.label ?: "Back to Game", - Modifier.fillMaxWidth().onGloballyPositioned { screen.resumeBounds = it.boundsInRoot() }, + Modifier.fillMaxWidth().focusWhenShown(true).onGloballyPositioned { screen.resumeBounds = it.boundsInRoot() }, accent = true, onClick = screen::resume, ) diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/pausescreen/PausePerformance.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/pausescreen/PausePerformance.kt index 477578487..544891834 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/pausescreen/PausePerformance.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/pausescreen/PausePerformance.kt @@ -24,6 +24,8 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.onFocusChanged +import org.polyfrost.compose.host.controller.Controllers import androidx.compose.ui.geometry.Offset import androidx.compose.ui.geometry.Size import androidx.compose.ui.graphics.Color @@ -213,10 +215,11 @@ private fun PerfTool(closeHost: () -> Unit, trigger: @Composable (view: PerfView val interaction = hoverState.interactionSource val hovered = hoverState.hovered var menu by remember { mutableStateOf(false) } + var focused by remember { mutableStateOf(false) } val anchor = rememberWidgetAnchor() - Box(Modifier.fillMaxWidth().hoverable(interaction)) { + Box(Modifier.fillMaxWidth().hoverable(interaction).onFocusChanged { focused = it.hasFocus }) { trigger(current, { menu = !menu }, menu) - if (hovered && !menu) { + if ((hovered || focused && Controllers.isActive) && !menu) { Popup(popupPositionProvider = anchor, properties = PopupProperties(focusable = false, clippingEnabled = false)) { PerfPanel(current) } diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/pausescreen/PauseQuickDock.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/pausescreen/PauseQuickDock.kt index b2538aae0..7e71f1f37 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/pausescreen/PauseQuickDock.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/pausescreen/PauseQuickDock.kt @@ -2,6 +2,7 @@ package org.polyfrost.polyplus.client.gui.pausescreen +import org.polyfrost.compose.host.controller.focusWhenShown import org.polyfrost.oneconfig.api.ui.v1.a11y.Motion import org.polyfrost.oneconfig.api.ui.v1.a11y.notFocusable import org.polyfrost.polyplus.client.gui.SocialDangerText @@ -223,6 +224,7 @@ private fun DockResume(screen: OneClientPauseScreen, where: String, narrow: Bool .padding(horizontal = 4.dp) .width(if (narrow) 128.dp else 168.dp) .height(56.dp) + .focusWhenShown(true) .onGloballyPositioned { screen.resumeBounds = it.boundsInRoot() } .clip(shape) .background(OneConfigTheme.accent) diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/pausescreen/PauseStepBack.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/pausescreen/PauseStepBack.kt index c7f7d5a04..74f22f449 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/pausescreen/PauseStepBack.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/pausescreen/PauseStepBack.kt @@ -2,6 +2,7 @@ package org.polyfrost.polyplus.client.gui.pausescreen +import org.polyfrost.compose.host.controller.focusWhenShown import org.polyfrost.polyplus.client.gui.lobbyshell.headShape import org.polyfrost.polyplus.client.gui.lobbyshell.centerVerticallyExact import androidx.compose.foundation.layout.fillMaxHeight @@ -126,7 +127,7 @@ internal fun BoxScope.StepBackScreen(screen: OneClientPauseScreen, narrow: Boole Spacer(Modifier.height(6.dp)) PauseStateLine(state) Spacer(Modifier.height(if (narrow) 12.dp else 18.dp)) - PlayButton(Modifier.fillMaxWidth().onGloballyPositioned { screen.resumeBounds = it.boundsInRoot() }, screen.capture.entry(PauseSlot.RESUME)?.label ?: "Back to Game", null, screen::resume) + PlayButton(Modifier.fillMaxWidth().focusWhenShown(true).onGloballyPositioned { screen.resumeBounds = it.boundsInRoot() }, screen.capture.entry(PauseSlot.RESUME)?.label ?: "Back to Game", null, screen::resume) Spacer(Modifier.height(if (narrow) 8.dp else 12.dp)) StepBackRows(screen, if (narrow) TIGHT_ROW else CLASSIC_ROW) } diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/preview/PlayerPreview.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/preview/PlayerPreview.kt index 3275de448..7040fcaad 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/preview/PlayerPreview.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/preview/PlayerPreview.kt @@ -17,6 +17,7 @@ import androidx.compose.runtime.setValue import androidx.compose.runtime.withFrameNanos import androidx.compose.ui.Modifier import androidx.compose.ui.draw.drawBehind +import androidx.compose.ui.geometry.Offset import androidx.compose.ui.graphics.BlendMode import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color @@ -33,6 +34,8 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.withContext import kotlinx.coroutines.withTimeoutOrNull import org.polyfrost.compose.backend.drawPoly +import org.polyfrost.compose.host.controller.controllerPan +import org.polyfrost.polyplus.client.gui.focusableOnController import org.polyfrost.polyplus.client.cosmetics.MojangSkinService import org.polyfrost.polyplus.client.cosmetics.outfits.SkinLibrary @@ -114,29 +117,36 @@ private fun PlayerPreviewLive( val edgeFade = remember { edgeFadeBrush() } val bottomFade = remember(bottomFadeFraction) { bottomFadeBrush(bottomFadeFraction) } + fun turn(drag: Offset) { + if (rotation != null) { + rotation.yaw -= drag.x * DRAG_YAW_SENSITIVITY + rotation.pitch = (rotation.pitch + drag.y * DRAG_PITCH_SENSITIVITY) + .coerceIn(-MAX_PITCH, MAX_PITCH) + rotation.userRotated = true + entry.initialYaw = rotation.yaw + entry.dragPitch = rotation.pitch + } else { + entry.dragYaw -= drag.x * DRAG_YAW_SENSITIVITY + entry.dragPitch = (entry.dragPitch + drag.y * DRAG_PITCH_SENSITIVITY) + .coerceIn(-MAX_PITCH, MAX_PITCH) + } + } + val dragModifier: Modifier = if (allowDrag) { - Modifier.pointerInput(entry, rotation) { - detectDragGestures( - onDragStart = { entry.dragging = true }, - onDragEnd = { entry.dragging = false }, - onDragCancel = { entry.dragging = false }, - ) { change, drag -> - if (rotation != null) { - rotation.yaw -= drag.x * DRAG_YAW_SENSITIVITY - rotation.pitch = (rotation.pitch + drag.y * DRAG_PITCH_SENSITIVITY) - .coerceIn(-MAX_PITCH, MAX_PITCH) - rotation.userRotated = true - entry.initialYaw = rotation.yaw - entry.dragPitch = rotation.pitch - } else { - entry.dragYaw -= drag.x * DRAG_YAW_SENSITIVITY - entry.dragPitch = (entry.dragPitch + drag.y * DRAG_PITCH_SENSITIVITY) - .coerceIn(-MAX_PITCH, MAX_PITCH) + Modifier + .pointerInput(entry, rotation) { + detectDragGestures( + onDragStart = { entry.dragging = true }, + onDragEnd = { entry.dragging = false }, + onDragCancel = { entry.dragging = false }, + ) { change, drag -> + turn(drag) + change.consume() } - change.consume() } - } + .controllerPan { turn(it * PAN_SCALE) } + .focusableOnController() } else { Modifier } @@ -246,17 +256,23 @@ private fun PlayerPreviewBitmap( .onSizeChanged { sizePx = it } .then( if (allowDrag) { - Modifier.pointerInput(Unit) { - detectDragGestures( - onDragStart = { dragging = true }, - onDragEnd = { dragging = false }, - onDragCancel = { dragging = false }, - ) { change, drag -> - yaw -= drag.x * DRAG_YAW_SENSITIVITY - pitch = (pitch + drag.y * DRAG_PITCH_SENSITIVITY).coerceIn(-MAX_PITCH, MAX_PITCH) - change.consume() + Modifier + .pointerInput(Unit) { + detectDragGestures( + onDragStart = { dragging = true }, + onDragEnd = { dragging = false }, + onDragCancel = { dragging = false }, + ) { change, drag -> + yaw -= drag.x * DRAG_YAW_SENSITIVITY + pitch = (pitch + drag.y * DRAG_PITCH_SENSITIVITY).coerceIn(-MAX_PITCH, MAX_PITCH) + change.consume() + } } - } + .controllerPan { delta -> + yaw -= delta.x * PAN_SCALE * DRAG_YAW_SENSITIVITY + pitch = (pitch + delta.y * PAN_SCALE * DRAG_PITCH_SENSITIVITY).coerceIn(-MAX_PITCH, MAX_PITCH) + } + .focusableOnController() } else { Modifier }, @@ -276,5 +292,6 @@ private const val CAPTURE_POLL_INTERVAL_MS = 16L private const val AUTO_SPIN_DEG_PER_TICK = 0.6f private const val DRAG_YAW_SENSITIVITY = 0.5f +private const val PAN_SCALE = 0.25f private const val DRAG_PITCH_SENSITIVITY = 0.5f private const val MAX_PITCH = 45f diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/serveredit/ServerEditDialog.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/serveredit/ServerEditDialog.kt index e39c37596..84c43b5c9 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/serveredit/ServerEditDialog.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/serveredit/ServerEditDialog.kt @@ -20,7 +20,6 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester -import androidx.compose.ui.focus.focusProperties import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.graphics.Color import androidx.compose.ui.input.key.Key @@ -49,6 +48,7 @@ import net.minecraft.client.Minecraft import net.minecraft.client.multiplayer.ServerData import net.minecraft.client.multiplayer.resolver.ServerAddress import net.minecraft.client.resources.language.I18n +import org.polyfrost.compose.host.controller.isFromController import org.polyfrost.oneconfig.api.platform.v1.Platform import org.polyfrost.oneconfig.api.ui.v1.ExperimentalOneConfigUiApi import org.polyfrost.oneconfig.api.ui.v1.components.ControlStyle @@ -65,6 +65,7 @@ import org.polyfrost.oneconfig.api.ui.v1.components.TextButton import org.polyfrost.oneconfig.api.ui.v1.components.TextField import org.polyfrost.oneconfig.api.ui.v1.components.TooltipPlacement import org.polyfrost.polyplus.client.gui.SocialDangerText +import org.polyfrost.polyplus.client.gui.controllerFocusOnly import org.polyfrost.polyplus.client.gui.lobbyshell.LobbyIcons import org.polyfrost.polyplus.client.gui.SocialTextPrimary import org.polyfrost.polyplus.client.lobby.LobbySceneStore @@ -223,7 +224,7 @@ private class DialogBodyPolicy(private val minHeight: Dp) : MultiContentMeasureP } private fun dialogKey(event: KeyEvent, save: () -> Unit): Boolean { - if (event.type != KeyEventType.KeyDown) return false + if (event.type != KeyEventType.KeyDown || event.isFromController) return false return when (event.key) { Key.Enter, Key.NumPadEnter -> { save() @@ -244,7 +245,7 @@ private fun DialogHeader(title: String, onDismiss: () -> Unit) { icon = LobbyIcons.CLOSE, contentDescription = "Close", onClick = onDismiss, - modifier = Modifier.focusProperties { canFocus = false }, + modifier = Modifier.controllerFocusOnly(), tooltip = null, tooltipPlacement = TooltipPlacement.BelowStart, tint = SocialTextPrimary, @@ -314,7 +315,7 @@ private fun FolderField(form: ServerEditForm) { AnchoredPopupButton( icon = "down", contentDescription = "Pick a folder", - modifier = Modifier.focusProperties { canFocus = false }, + modifier = Modifier.controllerFocusOnly(), placement = Placement.BelowEnd, ) { close -> MenuList(form.folderNames.map { name -> MenuAction(name, { form.folder = name }, checked = name.equals(form.folder.trim(), ignoreCase = true)) }, close) @@ -333,7 +334,7 @@ private fun CaptureRow(form: ServerEditForm) { label = "Capture scenes here", checked = on, onCheckedChange = { form.captureDraft = it }, - modifier = Modifier.fillMaxWidth().focusProperties { canFocus = false }, + modifier = Modifier.fillMaxWidth().controllerFocusOnly(), description = when { blocked -> "Blocked by this server" on -> "Saves good spots while you play here" @@ -369,7 +370,7 @@ private fun RowScope.DialogFooter( onDismiss: () -> Unit, save: () -> Unit, ) { - val unfocusable = Modifier.focusProperties { canFocus = false } + val unfocusable = Modifier.controllerFocusOnly() if (canDelete) TextButton(text = "Delete", icon = LobbyIcons.TRASH, onClick = { form.confirmingDelete = true }, modifier = unfocusable, style = ControlStyle.Danger, size = ControlSize.Large, dangerColor = KitDangerColor) Spacer(Modifier.weight(1f)) TextButton(text = "Cancel", onClick = onDismiss, modifier = unfocusable.widthIn(min = ButtonWidth), style = ControlStyle.Secondary, size = ControlSize.Large) diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/wardrobe/AuraColorPicker.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/wardrobe/AuraColorPicker.kt index 8fe8f52fd..4245d7537 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/wardrobe/AuraColorPicker.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/wardrobe/AuraColorPicker.kt @@ -41,6 +41,11 @@ import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.SolidColor import androidx.compose.ui.graphics.graphicsLayer +import androidx.compose.ui.input.key.Key +import androidx.compose.ui.input.key.KeyEventType +import androidx.compose.ui.input.key.key +import androidx.compose.ui.input.key.onKeyEvent +import androidx.compose.ui.input.key.type import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.layout.onSizeChanged import androidx.compose.ui.text.TextStyle @@ -54,6 +59,8 @@ import androidx.compose.ui.window.PopupProperties import java.awt.Color as AwtColor import kotlin.math.ceil import kotlin.math.roundToInt +import org.polyfrost.compose.host.controller.ControllerAxes +import org.polyfrost.compose.host.controller.controllerArrows import org.polyfrost.oneconfig.api.ui.v1.ExperimentalOneConfigUiApi import org.polyfrost.oneconfig.api.ui.v1.components.EscapeCloses import org.polyfrost.oneconfig.api.ui.v1.components.Placement @@ -62,6 +69,7 @@ import org.polyfrost.oneconfig.api.ui.v1.components.oneConfigClickable import org.polyfrost.oneconfig.api.ui.v1.components.rememberAnchoredPosition import org.polyfrost.oneconfig.api.ui.v1.keybind.trackTextInputFocus import org.polyfrost.oneconfig.api.ui.v1.theme.OneConfigTheme +import org.polyfrost.polyplus.client.gui.focusableOnController import org.polyfrost.polyplus.client.gui.lobbyshell.sceneFrost @Composable @@ -188,6 +196,38 @@ private fun Color.toArgb(alpha: Float): Int = ((green.coerceIn(0f, 1f) * 255f).roundToInt() shl 8) or (blue.coerceIn(0f, 1f) * 255f).roundToInt() +private const val PAD_STEP = 0.05f +private const val HUE_STEP = 10f + +private fun Modifier.arrowAdjust( + state: AuraPickerState, + vertical: Boolean, + enabled: Boolean, + onDone: () -> Unit, + onStep: (dx: Float, dy: Float) -> Boolean, +): Modifier = if (!enabled) this else + onKeyEvent { event -> + val dx = when (event.key) { + Key.DirectionLeft -> -1f + Key.DirectionRight -> 1f + else -> 0f + } + val dy = when (event.key) { + Key.DirectionUp -> if (vertical) -1f else 0f + Key.DirectionDown -> if (vertical) 1f else 0f + else -> 0f + } + if (dx == 0f && dy == 0f) return@onKeyEvent false + when (event.type) { + KeyEventType.KeyDown -> onStep(dx, dy).also { if (it) state.adjusting = true } + KeyEventType.KeyUp -> state.adjusting.also { + if (it) onDone() + state.adjusting = false + } + else -> false + } + }.controllerArrows(if (vertical) ControllerAxes.Both else ControllerAxes.Horizontal).focusableOnController() + private class AuraPickerState(argb: Int) { var hue by mutableFloatStateOf(0f) var saturation by mutableFloatStateOf(0f) @@ -196,6 +236,8 @@ private class AuraPickerState(argb: Int) { var lastEmitted: Int? = null + var adjusting = false + init { applyFrom(argb) } @@ -326,6 +368,15 @@ private fun AuraCustomPopover( .graphicsLayer { this.alpha = controlAlpha } .clip(barShape) .onSizeChanged { paneSize = Size(it.width.toFloat(), it.height.toFloat()) } + .arrowAdjust(state, vertical = true, enabled, ::emitCommit) { dx, dy -> + val nextSaturation = (state.saturation + dx * PAD_STEP).coerceIn(0f, 1f) + val nextBrightness = (state.brightness - dy * PAD_STEP).coerceIn(0f, 1f) + val changed = nextSaturation != state.saturation || nextBrightness != state.brightness + state.saturation = nextSaturation + state.brightness = nextBrightness + if (changed) emitPreview() + changed + } .drawWithCache { val hueColor = hsbToColor(hue, 1f, 1f) val horizontal = Brush.horizontalGradient(listOf(Color.White, hueColor)) @@ -380,6 +431,13 @@ private fun AuraCustomPopover( ) onDrawBehind { drawRect(gradient) } } + .arrowAdjust(state, vertical = false, enabled, ::emitCommit) { dx, _ -> + val next = (state.hue + dx * HUE_STEP).coerceIn(0f, 360f) + val changed = next != state.hue + state.hue = next + if (changed) emitPreview() + changed + } .pointerInput(Unit) { awaitEachGesture { val down = awaitFirstDown() @@ -418,6 +476,13 @@ private fun AuraCustomPopover( modifier = Modifier.fillMaxWidth().height(14.dp) .graphicsLayer { this.alpha = controlAlpha } .clip(barShape) + .arrowAdjust(state, vertical = false, enabled, ::emitCommit) { dx, _ -> + val next = (state.alpha + dx * PAD_STEP).coerceIn(0f, 1f) + val changed = next != state.alpha + state.alpha = next + if (changed) emitPreview() + changed + } .pointerInput(Unit) { awaitEachGesture { val down = awaitFirstDown() diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/wardrobe/WardrobeGrid.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/wardrobe/WardrobeGrid.kt index aa9489d8d..a326c70ba 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/wardrobe/WardrobeGrid.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/wardrobe/WardrobeGrid.kt @@ -38,6 +38,10 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.drawBehind import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.focus.onFocusChanged +import org.polyfrost.compose.host.controller.ControllerButton +import org.polyfrost.compose.host.controller.Controllers +import org.polyfrost.compose.host.controller.controllerAction import androidx.compose.ui.geometry.Offset import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color @@ -482,6 +486,8 @@ private fun WardrobeCard( val hover = rememberHoverState() val hovered = hover.hovered var menuOpen by remember { mutableStateOf(false) } + var focused by remember { mutableStateOf(false) } + val padFocused = focused && Controllers.isActive val shape = OneConfigTheme.shape(12.dp) val highlight = theme.textColor.copy(alpha = theme.textColor.alpha * theme.hoverOverlayAlpha) Box( @@ -498,6 +504,12 @@ private fun WardrobeCard( ) } .then(if (equipped) Modifier.border(1.dp, OneConfigTheme.accent, shape) else Modifier) + .onFocusChanged { focused = it.hasFocus } + .controllerAction(ControllerButton.X, "More", enabled = menu.isNotEmpty()) { menuOpen = true } + .controllerAction(ControllerButton.Y, "Next style", enabled = enabled && variants.size > 1) { + val at = variants.indexOfFirst { it.id == selectedVariantId } + onPickVariant(variants[(at + 1).mod(variants.size)].id) + } .hoverable(hover.interactionSource) .cardSelection(selected && !equipped, shape, CardOutline) .controlInteraction(hover.interactionSource, shape, if (equipped) NoHoverFill else OutlineOnHover, enabled, focusRing = false, pointerIcon = null) @@ -520,7 +532,7 @@ private fun WardrobeCard( .themedSurface(SurfaceKind.Field, OneConfigTheme.shape(5.dp), glass = false), ) { thumbnail(Modifier.fillMaxSize()) - if (hovered && variants.size > 1) { + if ((hovered || padFocused) && variants.size > 1) { VariantSwatches( variants = variants, selectedVariantId = selectedVariantId, @@ -547,7 +559,7 @@ private fun WardrobeCard( entries = if (enabled) menu else menu.map { entry -> if (entry is MenuAction) MenuAction(entry.labelText, entry.onClick, enabled = false) else entry }, expanded = menuOpen, onExpandedChange = { menuOpen = it }, - modifier = Modifier.requiredSize(ControlSize.Compact.height).hiddenUntilHover(hovered || menuOpen), + modifier = Modifier.requiredSize(ControlSize.Compact.height).hiddenUntilHover(hovered || menuOpen || padFocused), sound = null, tooltip = null, menuSound = null, diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/wardrobe/WardrobeWheelEditor.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/wardrobe/WardrobeWheelEditor.kt index 36b9dc63a..a6c267192 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/wardrobe/WardrobeWheelEditor.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/wardrobe/WardrobeWheelEditor.kt @@ -16,6 +16,8 @@ import androidx.compose.foundation.layout.size import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import org.polyfrost.compose.host.controller.ControllerButton +import org.polyfrost.compose.host.controller.controllerAction import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp @@ -163,6 +165,7 @@ private fun WheelSlotCell( Box( modifier = modifier .themedSurface(SurfaceKind.Field, shape, glass = false) + .controllerAction(ControllerButton.X, "Clear slot", enabled = emoteId != null, onPress = onClear) .hoverable(hover.interactionSource) .selectableCard( selected, diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/widgets/WidgetColumn.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/widgets/WidgetColumn.kt index 0eddd9a99..1eb2384a2 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/widgets/WidgetColumn.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/widgets/WidgetColumn.kt @@ -57,6 +57,7 @@ import org.polyfrost.oneconfig.api.ui.v1.components.ToggleControl import org.polyfrost.oneconfig.api.ui.v1.components.ToggleRow import org.polyfrost.oneconfig.api.ui.v1.components.UiSound import org.polyfrost.oneconfig.api.ui.v1.components.contextMenu +import org.polyfrost.polyplus.client.gui.focusableOnController import org.polyfrost.oneconfig.api.ui.v1.components.playUiSound import org.polyfrost.oneconfig.api.ui.v1.components.withItemMoved import org.polyfrost.oneconfig.api.ui.v1.theme.OneConfigTheme @@ -347,7 +348,8 @@ fun WidgetColumn( .lift(list, widget.id, FRAME_RADIUS) .shellWidgetGuard(widget.id) .dragSource(list, widget.id) - .contextMenu(entries = { widgetMenu(surface, widget.id, list.shown.filter { it in byId }, scope) }), + .contextMenu(entries = { widgetMenu(surface, widget.id, list.shown.filter { it in byId }, scope) }) + .focusableOnController(), ) { ShellWidgetGuarded(widget.id) { widget.Content(scope) } } From 31fd99d4b1c5417ce1fa2e896c3997194f7c577e Mon Sep 17 00:00:00 2001 From: Deftu Date: Tue, 24 Nov 2026 15:10:59 +0200 Subject: [PATCH 3/5] build: move to OneConfig 1.10.0 and PolyCompose 3.1.0 --- stonecutter.properties.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stonecutter.properties.toml b/stonecutter.properties.toml index cc506892d..58dfbdead 100644 --- a/stonecutter.properties.toml +++ b/stonecutter.properties.toml @@ -5,8 +5,8 @@ mod.group = "org.polyfrost" deps.fabric_loader = "0.19.5" deps.fabric_language_kotlin = "1.14.1+kotlin.2.4.20" -deps.oneconfig = "1.9.1" -deps.polycompose = "3.0.9" +deps.oneconfig = "1.10.0" +deps.polycompose = "3.1.0" deps.kotlin = "2.4.20" deps.ktor = "3.5.2" deps.sentry = "7.22.6" From 802ec37413192fe8378cb3098ba881a30630da3a Mon Sep 17 00:00:00 2001 From: Deftu Date: Tue, 24 Nov 2026 15:10:59 +0200 Subject: [PATCH 4/5] docs: update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f94c717f8..b6565abf6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Onboarding asks whether the OneConfig keybind should open the Mods Menu or the HUD Editor first - Hotwire and LootBeams have icons in the mods list - A Share Performance Stats setting, on by default. It sends your in-game FPS, basic hardware info (CPU, GPU and RAM), video settings and installed mods to OneClient so performance problems get caught and fixed. If spark is installed, it also sends a one-minute profile while you're AFK. Nothing is sent unless you've allowed online services +- Controller support with Controlify. The lobby, onboarding, wardrobe, social windows and pause screens all work with a gamepad, and the emote and ping wheels follow the right stick +- Controlify controls for opening Socials and the Wardrobe, the emote wheel, pings and party voice. Opening Socials or the Wardrobe and the voice toggles can also go in Controlify's radial menu ### Changed - Cosmetics are now rendered in Rust by Polyfrost's plus-renderer, so they're slightly faster and look the same as on the website and in the launcher @@ -42,6 +44,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - The lobby play card reopens on the tab you last used - The Compact pause screen has a Mods button - The HUD Editor shows the OneClient logo in the middle +- Needs OneConfig 1.10.0 and PolyCompose 3.1.0 ### Fixed - Fixed the lobby UI staying hidden when using Iris shaders From a47a4edc870f788b94189277fe34f87ba545d099 Mon Sep 17 00:00:00 2001 From: Deftu Date: Tue, 24 Nov 2026 19:13:42 +0200 Subject: [PATCH 5/5] fix: tighten controller input across the lobby, wardrobe, wheels and party cards --- CHANGELOG.md | 3 +- .../polyplus/client/PolyPlusControllers.kt | 19 ++-- .../client/emotes/EmoteWheelKeybind.kt | 19 +++- .../polyplus/client/gui/AccountSwitcher.kt | 39 +++++++-- .../polyplus/client/gui/EmoteWheelScreen.kt | 2 + .../polyplus/client/gui/WheelOverlay.kt | 19 ++-- .../client/gui/lobbyshell/LobbyParty.kt | 86 +++++++++++++++---- .../client/gui/lobbyshell/LobbyPartyPlay.kt | 12 +-- .../client/gui/lobbyshell/LobbyTour.kt | 30 ++++++- .../client/gui/lobbysocial/SocialParty.kt | 8 +- .../gui/menuwardrobe/MenuWardrobePicker.kt | 57 ++++++++---- .../client/gui/preview/PlayerPreview.kt | 59 +++++++++++-- .../client/gui/wardrobe/AuraColorPicker.kt | 83 ++++++++++++------ .../client/gui/wardrobe/WardrobeActions.kt | 2 + .../polyplus/client/party/PartyVoice.kt | 7 +- .../polyplus/client/ping/PingInput.kt | 22 ++++- .../resources/assets/polyplus/lang/en_us.json | 1 + 17 files changed, 358 insertions(+), 110 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6565abf6..7c8ca368e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,7 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Onboarding asks whether the OneConfig keybind should open the Mods Menu or the HUD Editor first - Hotwire and LootBeams have icons in the mods list - A Share Performance Stats setting, on by default. It sends your in-game FPS, basic hardware info (CPU, GPU and RAM), video settings and installed mods to OneClient so performance problems get caught and fixed. If spark is installed, it also sends a one-minute profile while you're AFK. Nothing is sent unless you've allowed online services -- Controller support with Controlify. The lobby, onboarding, wardrobe, social windows and pause screens all work with a gamepad, and the emote and ping wheels follow the right stick +- Controller support with Controlify. The lobby, onboarding, wardrobe, social windows and pause screens all work with a gamepad, and the emote and ping wheels follow the right stick. B switches between your emote wheels while one is open. In the lobby, Y lets you answer party invites and join requests - Controlify controls for opening Socials and the Wardrobe, the emote wheel, pings and party voice. Opening Socials or the Wardrobe and the voice toggles can also go in Controlify's radial menu ### Changed @@ -39,7 +39,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - If the OneClient Menu fails to load, its button stays greyed out until you restart - Sentry crash reports no longer send your computer name - Updated to OneConfig 1.9.1 -- Needs PolyCompose 3.0.9 - Store cards show the live preview, like the Wardrobe does, instead of playing an animated clip when you hover over them - The lobby play card reopens on the tab you last used - The Compact pause screen has a Mods button diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/PolyPlusControllers.kt b/src/main/kotlin/org/polyfrost/polyplus/client/PolyPlusControllers.kt index 4d9522bf1..e86bcd7f5 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/PolyPlusControllers.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/PolyPlusControllers.kt @@ -1,11 +1,13 @@ package org.polyfrost.polyplus.client import org.polyfrost.compose.host.controller.ControllerAction +import org.polyfrost.compose.host.controller.ControllerButton import org.polyfrost.compose.host.controller.Controllers import org.polyfrost.oneconfig.api.event.v1.eventHandler import org.polyfrost.oneconfig.api.event.v1.events.TickEvent import org.polyfrost.polyplus.client.emotes.EmoteWheelKeybind import org.polyfrost.polyplus.client.gui.PolyPlusOneConfigIntegration +import org.polyfrost.polyplus.client.gui.WheelOverlay import org.polyfrost.polyplus.client.party.PartyVoice import org.polyfrost.polyplus.client.ping.PingInput import org.polyfrost.polyplus.client.social.SocialOverlay @@ -25,6 +27,7 @@ object PolyPlusControllers { } private val held = ArrayList() + private var emoteWheel: ControllerAction? = null fun initialize() { tap("open_socials", "openSocials") { SocialOverlay.toggle() } @@ -32,20 +35,22 @@ object PolyPlusControllers { tap("toggle_mute", "toggleMute") { PartyVoice.onToggleMuteKey() } tap("toggle_deafen", "toggleDeafen") { PartyVoice.onToggleDeafenKey() } tap("join_leave_voice", "joinLeaveVoice") { PartyVoice.onJoinLeaveKey() } - hold("emote_wheel", "emoteWheel") { EmoteWheelKeybind.onKeybindState(it) } + emoteWheel = hold("emote_wheel", "emoteWheel") { EmoteWheelKeybind.onControllerState(it) } + register("emote_wheel_next", "emoteWheelNext", radial = false, ControllerButton.B).onPress { WheelOverlay.page(1) } hold("ping", "ping") { PingInput.onControllerState(it) } - hold("push_to_talk", "pushToTalk") { PartyVoice.onPushToTalk(it) } + hold("push_to_talk", "pushToTalk") { PartyVoice.onControllerPushToTalk(it) } eventHandler { for (entry in held) entry.poll() } } - private fun register(id: String, name: String, radial: Boolean): ControllerAction = - Controllers.register("polyplus:$id", "polyplus.controller.$name", category = CATEGORY, radial = radial) + fun canBindEmoteWheel(): Boolean = emoteWheel?.isRebindable == true + + private fun register(id: String, name: String, radial: Boolean, button: ControllerButton = ControllerButton.NONE): ControllerAction = + Controllers.register("polyplus:$id", "polyplus.controller.$name", button, category = CATEGORY, radial = radial) private fun tap(id: String, name: String, run: () -> Unit) { register(id, name, radial = true).onPress { run() } } - private fun hold(id: String, name: String, onChange: (Boolean) -> Unit) { - held += Held(register(id, name, radial = false), onChange) - } + private fun hold(id: String, name: String, onChange: (Boolean) -> Unit): ControllerAction = + register(id, name, radial = false).also { held += Held(it, onChange) } } diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/emotes/EmoteWheelKeybind.kt b/src/main/kotlin/org/polyfrost/polyplus/client/emotes/EmoteWheelKeybind.kt index 377d07a3c..3a3198155 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/emotes/EmoteWheelKeybind.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/emotes/EmoteWheelKeybind.kt @@ -7,18 +7,22 @@ import org.polyfrost.oneconfig.api.ui.v1.ExperimentalOneConfigUiApi import org.polyfrost.oneconfig.api.ui.v1.keybind.KeybindManager import org.polyfrost.oneconfig.api.ui.v1.keybind.TextInputFocus import org.polyfrost.polyplus.client.PolyPlusConfig +import org.polyfrost.polyplus.client.PolyPlusControllers import org.polyfrost.polyplus.client.gui.EmoteWheelOverlay import org.polyfrost.polyplus.client.gui.WheelOverlay import org.polyfrost.polyplus.client.utils.ClientPlatform object EmoteWheelKeybind { @Volatile - private var held = false + private var keyHeld = false - fun isHeld(): Boolean = held + @Volatile + private var controllerHeld = false + + fun isHeld(): Boolean = keyHeld || controllerHeld fun onKeybindState(pressed: Boolean) { - held = pressed + keyHeld = pressed if (!pressed || WheelOverlay.isOpen) return if (Minecraft.getInstance().player != null && ClientPlatform.currentScreen() == null) { EmoteWheelOverlay.open() @@ -27,6 +31,13 @@ object EmoteWheelKeybind { EmoteWheelOverlay.openOverLobby() } + fun onControllerState(pressed: Boolean) { + controllerHeld = pressed + if (!pressed || WheelOverlay.isOpen) return + if (Minecraft.getInstance().player == null || ClientPlatform.currentScreen() != null) return + EmoteWheelOverlay.open() + } + fun isBound(): Boolean = PolyPlusConfig.emoteWheelKeybind.isBound fun claimsKey(key: Int, modifiers: Int): Boolean { @@ -42,6 +53,8 @@ object EmoteWheelKeybind { private const val MODIFIER_MASK = 0xF + fun canBindController(): Boolean = PolyPlusControllers.canBindEmoteWheel() + fun conflictingKeybindNames(): List { val wheel = PolyPlusConfig.emoteWheelKeybind if (!wheel.isBound) return emptyList() diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/AccountSwitcher.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/AccountSwitcher.kt index 9b24c90b0..d01127f75 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/AccountSwitcher.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/AccountSwitcher.kt @@ -38,8 +38,11 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.focus.onFocusChanged import org.polyfrost.compose.host.controller.ControllerButton +import org.polyfrost.compose.host.controller.Controllers import org.polyfrost.compose.host.controller.controllerAction import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.rotate @@ -292,6 +295,24 @@ private fun AccountRow(state: AccountsPanelState, account: OneLauncherAccounts.A val theme = OneConfigTheme.current val hover = rememberHoverState() var confirmRemove by remember { mutableStateOf(false) } + var confirmByController by remember { mutableStateOf(false) } + var refocusRow by remember { mutableIntStateOf(0) } + val rowFocus = remember { FocusRequester() } + val keepFocus = remember { FocusRequester() } + fun closeConfirm() { + confirmRemove = false + if (confirmByController) { + confirmByController = false + refocusRow++ + } + } + LaunchedEffect(confirmRemove, confirmByController) { + if (confirmRemove && confirmByController) runCatching { keepFocus.requestFocus() } + } + LaunchedEffect(refocusRow) { + if (refocusRow > 0) runCatching { rowFocus.requestFocus() } + } + if (confirmRemove && confirmByController) EscapeCloses { closeConfirm() } var focused by remember { mutableStateOf(false) } val revealed = hover.hovered || focused val busy = actions.refreshingId == account.id || state.pendingId == account.id @@ -311,7 +332,11 @@ private fun AccountRow(state: AccountsPanelState, account: OneLauncherAccounts.A .height(CustomizeKit.RowHeight) .graphicsLayer { alpha = if (idle || busy) 1f else theme.disabledAlpha } .onFocusChanged { focused = it.hasFocus } - .controllerAction(ControllerButton.X, "Remove", enabled = idle && !busy && !confirmRemove) { confirmRemove = true } + .focusRequester(rowFocus) + .controllerAction(ControllerButton.X, "Remove", enabled = idle && !busy && !confirmRemove) { + confirmByController = true + confirmRemove = true + } .controllerAction(ControllerButton.Y, "Refresh", enabled = idle && !busy && !confirmRemove && account.refreshable) { state.refresh(account) } .then(if (account.active) Modifier.focusableOnController() else Modifier) .hoverable(hover.interactionSource) @@ -350,10 +375,10 @@ private fun AccountRow(state: AccountsPanelState, account: OneLauncherAccounts.A busy -> Spinner(OneConfigTheme.accent) confirmRemove -> { RowIcon("check", "Remove ${account.username}", SocialDangerText, idle) { - confirmRemove = false + closeConfirm() state.remove(account) } - RowIcon("x-close", "Keep ${account.username}", theme.textColorSecondary, true) { confirmRemove = false } + RowIcon("x-close", "Keep ${account.username}", theme.textColorSecondary, true, Modifier.focusRequester(keepFocus)) { closeConfirm() } } else -> { if (account.expired && account.refreshable) { @@ -362,7 +387,10 @@ private fun AccountRow(state: AccountsPanelState, account: OneLauncherAccounts.A RowIcon("refresh-cw-01", "Refresh ${account.username}", theme.textColorSecondary, idle) { state.refresh(account) } } if (revealed) { - RowIcon("trash-01", "Remove ${account.username}", theme.textColorSecondary, idle) { confirmRemove = true } + RowIcon("trash-01", "Remove ${account.username}", theme.textColorSecondary, idle) { + if (Controllers.isDispatching) confirmByController = true + confirmRemove = true + } } else if (account.active) { LobbyIcon("check", OneConfigTheme.accent, 18.dp) } @@ -615,11 +643,12 @@ private fun Spinner(color: Color, size: Dp = 16.dp) { } @Composable -private fun RowIcon(icon: String, label: String, tint: Color, enabled: Boolean, onClick: () -> Unit) { +private fun RowIcon(icon: String, label: String, tint: Color, enabled: Boolean, modifier: Modifier = Modifier, onClick: () -> Unit) { IconButton( icon = "$ASSETS$icon.svg", contentDescription = label, onClick = onClick, + modifier = modifier, enabled = enabled, tooltip = null, tint = tint, diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/EmoteWheelScreen.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/EmoteWheelScreen.kt index 8c2ab3ec1..c18519ac7 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/EmoteWheelScreen.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/EmoteWheelScreen.kt @@ -11,6 +11,7 @@ import androidx.compose.runtime.setValue import androidx.compose.runtime.withFrameNanos import kotlinx.coroutines.launch import org.apache.logging.log4j.LogManager +import org.polyfrost.compose.host.controller.Controllers import org.polyfrost.oneconfig.api.event.v1.eventHandler import org.polyfrost.oneconfig.api.event.v1.events.WorldEvent import org.polyfrost.oneconfig.api.ui.v1.ExperimentalOneConfigUiApi @@ -258,6 +259,7 @@ private fun EmoteWheelContent(session: WheelSession, lobby: Boolean) { val subtitle = when { empty -> null wheelCount > 1 && lobbyDuo -> "Wheel ${wheelIndex + 1} of $wheelCount · $LOBBY_DUO_NOTE" + wheelCount > 1 && Controllers.isActive -> "Wheel ${wheelIndex + 1} of $wheelCount" wheelCount > 1 -> "Wheel ${wheelIndex + 1} of $wheelCount · Scroll for more" lobbyDuo -> LOBBY_DUO_NOTE else -> null diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/WheelOverlay.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/WheelOverlay.kt index 144aea88b..67b999203 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/WheelOverlay.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/WheelOverlay.kt @@ -115,7 +115,7 @@ object WheelOverlay { session = next shown = next stickUsed = false - if (Controllers.isActive) look = Controllers.captureLook() + look = Controllers.captureGameplay() return true } @@ -138,6 +138,10 @@ object WheelOverlay { if (session === target) finish(pick) } + fun page(step: Int) { + session?.onScroll?.invoke(step) + } + @JvmStatic fun consumeLook(dx: Double, dy: Double): Boolean { val current = session ?: return PingInput.consumePendingLook(dx, dy) @@ -223,7 +227,7 @@ object WheelOverlay { cancel() return } - if (look != null) steerWithStick(current) + if (Controllers.isActive) steerWithStick(current) else stickUsed = false if (!current.held()) finish(true) } @@ -233,10 +237,13 @@ object WheelOverlay { private fun steerWithStick(current: WheelSession) { val stick = Controllers.rightStick - val deflected = stick.getDistance() >= STICK_DEAD - if (deflected) stickUsed = true - if (!stickUsed) return - if (deflected) current.state.aimAt(stick.x * STICK_REACH, stick.y * STICK_REACH) else current.state.aimAt(0f, 0f) + if (stick.getDistance() >= STICK_DEAD) { + stickUsed = true + current.state.aimAt(stick.x * STICK_REACH, stick.y * STICK_REACH) + } else if (stickUsed) { + stickUsed = false + current.state.aimAt(0f, 0f) + } } private fun finish(pick: Boolean) { diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyParty.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyParty.kt index 380556f0f..602400f8c 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyParty.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyParty.kt @@ -17,18 +17,37 @@ import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.IntrinsicSize import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.offset import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.widthIn import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.key +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip +import androidx.compose.ui.focus.onFocusChanged +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.platform.LocalFocusManager +import androidx.compose.ui.unit.IntOffset +import androidx.compose.ui.unit.IntRect +import androidx.compose.ui.unit.IntSize +import androidx.compose.ui.unit.LayoutDirection +import androidx.compose.ui.window.PopupPositionProvider +import org.polyfrost.oneconfig.api.ui.v1.components.ScrollContainer +import org.polyfrost.compose.host.controller.ControllerButton +import org.polyfrost.compose.host.controller.Controllers +import org.polyfrost.compose.host.controller.controllerAction +import org.polyfrost.compose.host.controller.focusWhenShown +import org.polyfrost.oneconfig.api.ui.v1.components.EscapeCloses import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.Dp @@ -56,6 +75,7 @@ import org.polyfrost.polyplus.client.gui.SocialTextPrimary import org.polyfrost.polyplus.client.gui.ThemedIcon import org.polyfrost.polyplus.client.gui.lobbysocial.InvitePicker import org.polyfrost.polyplus.client.gui.lobbysocial.MemberPopoverContent +import org.polyfrost.polyplus.client.gui.lobbysocial.PartyCardText import org.polyfrost.polyplus.client.gui.lobbysocial.PartyCell import org.polyfrost.polyplus.client.gui.lobbysocial.PartyIcons import org.polyfrost.polyplus.client.gui.lobbysocial.PartyInviteCard @@ -83,6 +103,8 @@ private val TagInviteSize = 22.dp private val SeatHeight = 60.dp private val PartyPopupGap = 14.dp private const val MAX_INVITE_CARDS = 3 +private val CardStackMargin = 24.dp +private val CardStackMinHeight = 96.dp private const val LEAVE_VOICE = SOCIAL_ASSETS + "log-out-04.svg" private const val WARNING = "alert-circle" @@ -334,8 +356,6 @@ private fun PartyPopupButton(icon: String, contentDescription: String, tint: Col ) } -private enum class FirstCard { Request, Hosted, Rejoin, LeaderMoved, Invite } - @Composable internal fun PartyInviteCards(host: SocialHost) { val invites by PartyRepository.incomingInvites.collectAsState() @@ -345,24 +365,52 @@ internal fun PartyInviteCards(host: SocialHost) { if (invites.isEmpty() && LeaderFollow.card == null && rejoin == null && hosted == null && requests.isEmpty()) return val shownRequests = requests.takeLast(MAX_INVITE_CARDS) val shownInvites = invites.takeLast(MAX_INVITE_CARDS) - val first = when { - shownRequests.isNotEmpty() -> FirstCard.Request - hosted != null -> FirstCard.Hosted - rejoin != null -> FirstCard.Rejoin - LeaderFollow.card != null -> FirstCard.LeaderMoved - else -> FirstCard.Invite - } - Popup(popupPositionProvider = rememberAbove(alignEnd = true), properties = PopupProperties(focusable = false)) { - Column(verticalArrangement = Arrangement.spacedBy(8.dp)) { - shownRequests.forEachIndexed { index, request -> - key(request.id) { HostJoinRequestCard(request, shortcut = first == FirstCard.Request && index == 0) } - } - hosted?.let { LeaderHostingCard(it, shortcut = first == FirstCard.Hosted) } - rejoin?.let { RejoinWorldCard(it, shortcut = first == FirstCard.Rejoin) } - LeaderMovedCard(host, shortcut = first == FirstCard.LeaderMoved) - shownInvites.forEachIndexed { index, invite -> - key(invite.id) { PartyInviteCard(invite, shortcut = first == FirstCard.Invite && index == 0) } + var responding by remember { mutableStateOf(false) } + var inside by remember { mutableStateOf(false) } + val controller = Controllers.isActive + LaunchedEffect(controller) { if (!controller) responding = false } + if (responding) EscapeCloses { responding = false } + var space by remember { mutableStateOf(null) } + val above = rememberAbove(alignEnd = true) + val position = remember(above) { SpaceTrackingPosition(above) { space = it } } + val density = LocalDensity.current + val maxHeight = space?.let { with(density) { (it.toDp() - CardStackMargin).coerceAtLeast(CardStackMinHeight) } } + Popup( + popupPositionProvider = position, + onDismissRequest = { responding = false }, + properties = PopupProperties(focusable = responding), + ) { + val focus = LocalFocusManager.current + LaunchedEffect(responding) { if (!responding) focus.clearFocus(force = true) } + ScrollContainer( + modifier = if (maxHeight != null) Modifier.heightIn(max = maxHeight) else Modifier, + scrollbar = false, + fadingEdges = true, + ) { + Column( + Modifier + .controllerAction(ControllerButton.Y, PartyCardText.RESPOND, enabled = !responding, requireFocus = false) { responding = true } + .onFocusChanged { inside = it.hasFocus } + .focusWhenShown(responding && !inside), + verticalArrangement = Arrangement.spacedBy(8.dp), + ) { + shownRequests.forEach { request -> + key(request.id) { HostJoinRequestCard(request) } + } + hosted?.let { LeaderHostingCard(it) } + rejoin?.let { RejoinWorldCard(it) } + LeaderMovedCard(host) + shownInvites.forEach { invite -> + key(invite.id) { PartyInviteCard(invite) } + } } } } } + +private class SpaceTrackingPosition(private val base: PopupPositionProvider, private val onSpace: (Int) -> Unit) : PopupPositionProvider { + override fun calculatePosition(anchorBounds: IntRect, windowSize: IntSize, layoutDirection: LayoutDirection, popupContentSize: IntSize): IntOffset { + onSpace(maxOf(anchorBounds.top, windowSize.height - anchorBounds.bottom)) + return base.calculatePosition(anchorBounds, windowSize, layoutDirection, popupContentSize) + } +} diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyPartyPlay.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyPartyPlay.kt index eff8aeb08..12cf091e1 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyPartyPlay.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyPartyPlay.kt @@ -73,7 +73,7 @@ internal fun PlayTogetherHooks(host: SocialHost) { } @Composable -internal fun LeaderMovedCard(host: SocialHost, shortcut: Boolean = false) { +internal fun LeaderMovedCard(host: SocialHost) { val card = LeaderFollow.card ?: return val incompatible = card.check == ServerCheck.Result.INCOMPATIBLE LeaderJoinEffect(host) @@ -88,7 +88,6 @@ internal fun LeaderMovedCard(host: SocialHost, shortcut: Boolean = false) { captionFirst = true, acceptEnabled = !incompatible && !card.checking && !card.cleared, warning = if (incompatible) PartyCardText.needs(card.needs) else null, - shortcut = shortcut, ) } @@ -100,7 +99,7 @@ internal fun leaderHostedWorld(): LeaderFollow.Hosted? { } @Composable -internal fun LeaderHostingCard(hosted: LeaderFollow.Hosted, shortcut: Boolean = false) { +internal fun LeaderHostingCard(hosted: LeaderFollow.Hosted) { val names by PlayerNamesRepository.names.collectAsState() val name = names[hosted.leader] ?: hosted.name PartyCard( @@ -113,12 +112,11 @@ internal fun LeaderHostingCard(hosted: LeaderFollow.Hosted, shortcut: Boolean = LeaderFollow::joinHosted, captionFirst = true, acceptEnabled = !hosted.busy, - shortcut = shortcut, ) } @Composable -internal fun HostJoinRequestCard(request: HostJoinRequests.Request, shortcut: Boolean = false) { +internal fun HostJoinRequestCard(request: HostJoinRequests.Request) { val names by PlayerNamesRepository.names.collectAsState() PartyCard( request.player, @@ -130,7 +128,6 @@ internal fun HostJoinRequestCard(request: HostJoinRequests.Request, shortcut: Bo { HostJoinRequests.allow(request.id) }, acceptEnabled = !request.answering, dismissEnabled = !request.answering, - shortcut = shortcut, ) } @@ -142,7 +139,7 @@ internal fun rejoinableWorld(): SessionInvite? { } @Composable -internal fun RejoinWorldCard(invite: SessionInvite, shortcut: Boolean = false) { +internal fun RejoinWorldCard(invite: SessionInvite) { PartyCard( invite.sender, PartyCardText.world(PlayerNamesRepository.nameOr(invite.sender)), @@ -151,7 +148,6 @@ internal fun RejoinWorldCard(invite: SessionInvite, shortcut: Boolean = false) { P2PSessionManager::forgetRejoin, "Rejoin", P2PSessionManager::rejoin, - shortcut = shortcut, ) } diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyTour.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyTour.kt index 1e833d814..f27d87f12 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyTour.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbyshell/LobbyTour.kt @@ -28,9 +28,18 @@ import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.key import androidx.compose.runtime.mutableIntStateOf +import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue +import androidx.compose.runtime.withFrameNanos import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.focus.focusRequester +import androidx.compose.ui.focus.onFocusChanged +import org.polyfrost.compose.host.controller.Controllers +import org.polyfrost.compose.host.controller.controllerFocusScope +import org.polyfrost.compose.host.controller.hidesFocusRing +import androidx.compose.foundation.focusable import androidx.compose.ui.geometry.Rect import androidx.compose.ui.geometry.Size import androidx.compose.ui.graphics.graphicsLayer @@ -112,10 +121,20 @@ internal fun TourLayer(tour: LobbyTour, anchors: Map, onEnd: ( EscapeCloses(onEnd) val theme = OneConfigTheme.current val appear = remember { Animatable(0f) } + var started by remember { mutableStateOf(false) } LaunchedEffect(Unit) { delay(START_DELAY_MILLIS) + started = true appear.animateTo(1f, Motion.finiteSpec(tween(APPEAR_MILLIS))) } + val controller = Controllers.isActive + val blockFocus = remember { FocusRequester() } + LaunchedEffect(started, controller) { + if (started || !controller) return@LaunchedEffect + withFrameNanos { } + runCatching { blockFocus.requestFocus() } + } + Box(Modifier.fillMaxSize().controllerFocusScope().hidesFocusRing().focusRequester(blockFocus).focusable(enabled = controller)) val density = LocalDensity.current val pad = with(density) { HolePad.toPx() } val gap = with(density) { CardGap.toPx() } @@ -128,10 +147,19 @@ internal fun TourLayer(tour: LobbyTour, anchors: Map, onEnd: ( key(tour.index) { val shown = remember { Animatable(0f) } LaunchedEffect(Unit) { shown.animateTo(1f, Motion.finiteSpec(tween(APPEAR_MILLIS))) } + val nextFocus = remember { FocusRequester() } + var cardFocused by remember { mutableStateOf(false) } + LaunchedEffect(started, controller, cardFocused) { + if (!started || !controller || cardFocused) return@LaunchedEffect + withFrameNanos { } + runCatching { nextFocus.requestFocus() } + } Announce("${tour.title()}. ${tour.text()}") Column( Modifier .placed { size -> cardOffset(anchor, hole, size, root, gap, margin) } + .onFocusChanged { cardFocused = it.hasFocus } + .controllerFocusScope() .a11yRegion(A11yRegion.Tour) .width(CardWidth) .graphicsLayer { alpha = shown.value } @@ -147,7 +175,7 @@ internal fun TourLayer(tour: LobbyTour, anchors: Map, onEnd: ( Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(8.dp)) { TextButton(text = "Skip tour", onClick = onEnd, size = ControlSize.Large) Spacer(Modifier.weight(1f)) - TextButton(text = if (tour.last) "Done" else "Next", onClick = { if (!tour.next()) onEnd() }, size = ControlSize.Large, style = ControlStyle.Primary) + TextButton(text = if (tour.last) "Done" else "Next", onClick = { if (!tour.next()) onEnd() }, modifier = Modifier.focusRequester(nextFocus), size = ControlSize.Large, style = ControlStyle.Primary) } } } diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbysocial/SocialParty.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbysocial/SocialParty.kt index fc6b98abb..3b54d4f75 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbysocial/SocialParty.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/lobbysocial/SocialParty.kt @@ -33,8 +33,6 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import org.polyfrost.compose.host.controller.ControllerButton -import org.polyfrost.compose.host.controller.controllerAction import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import androidx.compose.ui.window.PopupPositionProvider @@ -585,6 +583,7 @@ internal object PartyCardText { const val ALLOW = "Allow" const val DENY = "Deny" const val WANTS_TO_JOIN = "Wants to join your world" + const val RESPOND = "Respond" fun needs(version: String?): String = version?.let { "Needs Minecraft $it" } ?: "Needs another Minecraft version" @@ -607,10 +606,8 @@ internal fun PartyCard( acceptEnabled: Boolean = true, dismissEnabled: Boolean = true, warning: String? = null, - shortcut: Boolean = false, ) { val frame = modifier - .controllerAction(ControllerButton.Y, acceptLabel, enabled = shortcut && acceptEnabled, requireFocus = false, onPress = onAccept) .width(PartyCardWidth) .popup() .padding(12.dp) @@ -640,7 +637,7 @@ internal fun PartyCard( } @Composable -internal fun PartyInviteCard(invite: PartyInvite, modifier: Modifier = Modifier, shortcut: Boolean = false) { +internal fun PartyInviteCard(invite: PartyInvite, modifier: Modifier = Modifier) { val names by PlayerNamesRepository.names.collectAsState() PartyCard( invite.sender, @@ -651,7 +648,6 @@ internal fun PartyInviteCard(invite: PartyInvite, modifier: Modifier = Modifier, PartyCardText.JOIN_PARTY, { PartyRepository.accept(invite) }, modifier, - shortcut = shortcut, ) } diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/menuwardrobe/MenuWardrobePicker.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/menuwardrobe/MenuWardrobePicker.kt index 2e660fcd7..dadb3abc4 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/menuwardrobe/MenuWardrobePicker.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/menuwardrobe/MenuWardrobePicker.kt @@ -52,6 +52,7 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch +import org.polyfrost.compose.host.controller.controllerArrows import org.polyfrost.compose.host.controller.isFromController import org.polyfrost.oneconfig.api.ui.v1.ExperimentalOneConfigUiApi import org.polyfrost.oneconfig.api.ui.v1.components.Badge @@ -97,6 +98,7 @@ import org.polyfrost.polyplus.client.network.http.responses.CosmeticType private const val GRID_COLUMNS = 3 private const val DOUBLE_CLICK_MS = 400L +private const val GET_MORE_KEY = "get-more" private val TileGap = 8.dp private val TileRadius = 12.dp internal val OutlineOnHover = ControlIndication(hoverAlpha = 0f, hoverBorder = true) @@ -216,21 +218,36 @@ internal fun SlotPicker(model: PickerModel, modifier: Modifier = Modifier) { LaunchedEffect(model.selected?.key) { model.selected?.key?.let { cursor = it } } LaunchedEffect(model.type) { runCatching { focus.requestFocus() } } - fun move(delta: Int): Boolean { + fun move(delta: Int, controller: Boolean): Boolean { val list = current.entries.filter { it.matches(filter, query) } - if (list.isEmpty()) return false - val from = list.indexOfFirst { it.key == (cursor ?: current.selected?.key ?: current.target?.key) } - val next = if (from < 0) 0 else (from + delta).coerceIn(0, list.lastIndex) + val getMore = controller && current.onMarketplace != null + val last = if (getMore) list.size else list.lastIndex + if (last < 0) return false + val key = cursor ?: current.selected?.key ?: current.target?.key + val from = if (getMore && key == GET_MORE_KEY) list.size else list.indexOfFirst { it.key == key } + val raw = from + delta + val leaves = raw < 0 || (raw > last && from / GRID_COLUMNS == last / GRID_COLUMNS) + if (controller && from >= 0 && leaves) return false + val next = if (from < 0) 0 else raw.coerceIn(0, last) if (next == from) return false + scope.revealItem(grid, next) + if (next == list.size) { + cursor = GET_MORE_KEY + return true + } val entry = list[next] cursor = entry.key if (!current.picksToWheel) current.onPick(entry) - scope.revealItem(grid, next) return true } fun confirm(): Boolean { val model = current + if (cursor == GET_MORE_KEY) { + val open = model.onMarketplace ?: return false + open() + return true + } val entry = model.entries.firstOrNull { it.key == cursor } if (model.picksToWheel) { model.onPick(entry ?: return false) @@ -248,13 +265,14 @@ internal fun SlotPicker(model: PickerModel, modifier: Modifier = Modifier) { fun onKey(event: KeyEvent): Boolean { if (event.type != KeyEventType.KeyDown) return false - val arrows = !event.isFromController || gridFocused + val controller = event.isFromController + val arrows = !controller || gridFocused return when (event.key) { - Key.DirectionLeft -> arrows && move(-1) - Key.DirectionRight -> arrows && move(1) - Key.DirectionUp -> arrows && move(-GRID_COLUMNS) - Key.DirectionDown -> arrows && move(GRID_COLUMNS) - Key.Enter, Key.NumPadEnter -> confirm() + Key.DirectionLeft -> arrows && move(-1, controller) + Key.DirectionRight -> arrows && move(1, controller) + Key.DirectionUp -> arrows && move(-GRID_COLUMNS, controller) + Key.DirectionDown -> arrows && move(GRID_COLUMNS, controller) + Key.Enter, Key.NumPadEnter -> gridFocused && confirm() else -> false } } @@ -285,12 +303,13 @@ internal fun SlotPicker(model: PickerModel, modifier: Modifier = Modifier) { .focusRequester(focus) .onPreviewKeyEvent(::onKey) .onFocusChanged { gridFocused = it.isFocused } + .controllerArrows() .focusable(), ) { if (shown.isEmpty() && model.onMarketplace == null) { NoMatches(Modifier.fillMaxSize()) } else { - PickerGrid(model, shown, grid, cursor, onTileFocus = { cursor = it.key }) { entry -> + PickerGrid(model, shown, grid, cursor, gridFocused, onTileFocus = { cursor = it.key }) { entry -> cursor = entry.key runCatching { focus.requestFocus() } } @@ -321,6 +340,7 @@ private fun PickerGrid( shown: List, grid: LazyGridState, cursor: String?, + gridFocused: Boolean, onTileFocus: (PickerEntry) -> Unit, onTileClick: (PickerEntry) -> Unit, ) { @@ -365,7 +385,9 @@ private fun PickerGrid( onClick = { click(entry) }, ) } - model.onMarketplace?.let { open -> item(key = "get-more") { GetMoreTile(open) } } + model.onMarketplace?.let { open -> + item(key = GET_MORE_KEY) { GetMoreTile(gridFocused && cursor == GET_MORE_KEY, open) } + } } } } @@ -420,16 +442,19 @@ private fun EquippedCheck(modifier: Modifier) { } @Composable -private fun GetMoreTile(onClick: () -> Unit) { +private fun GetMoreTile(highlighted: Boolean, onClick: () -> Unit) { val theme = OneConfigTheme.current - val color = theme.textColorSecondary + val color = if (highlighted) OneConfigTheme.accent else theme.textColorSecondary val shape = OneConfigTheme.shape(TileRadius) Column( Modifier .fillMaxWidth() .aspectRatio(0.8f) .clip(shape) - .border(1.dp, theme.textColorSecondary.copy(alpha = 0.25f), shape) + .then( + if (highlighted) Modifier.border(1.5.dp, OneConfigTheme.accent, shape) + else Modifier.border(1.dp, theme.textColorSecondary.copy(alpha = 0.25f), shape), + ) .oneConfigClickable("Get more in the Marketplace", onClick, shape = shape, recipe = OutlineOnHover) .padding(6.dp), horizontalAlignment = Alignment.CenterHorizontally, diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/preview/PlayerPreview.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/preview/PlayerPreview.kt index 7040fcaad..6a08feff1 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/preview/PlayerPreview.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/preview/PlayerPreview.kt @@ -13,6 +13,8 @@ import androidx.compose.runtime.mutableFloatStateOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.produceState import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.runtime.rememberUpdatedState import androidx.compose.runtime.setValue import androidx.compose.runtime.withFrameNanos import androidx.compose.ui.Modifier @@ -29,8 +31,11 @@ import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.layout.onGloballyPositioned import androidx.compose.ui.layout.onSizeChanged import androidx.compose.ui.unit.IntSize +import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Job import kotlinx.coroutines.delay +import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import kotlinx.coroutines.withTimeoutOrNull import org.polyfrost.compose.backend.drawPoly @@ -132,20 +137,25 @@ private fun PlayerPreviewLive( } } + val hold = rememberDragHold { entry.dragging = it } + val dragModifier: Modifier = if (allowDrag) { Modifier .pointerInput(entry, rotation) { detectDragGestures( - onDragStart = { entry.dragging = true }, - onDragEnd = { entry.dragging = false }, - onDragCancel = { entry.dragging = false }, + onDragStart = { hold.mouse(true) }, + onDragEnd = { hold.mouse(false) }, + onDragCancel = { hold.mouse(false) }, ) { change, drag -> turn(drag) change.consume() } } - .controllerPan { turn(it * PAN_SCALE) } + .controllerPan { + hold.pan() + turn(it * PAN_SCALE) + } .focusableOnController() } else { Modifier @@ -210,6 +220,7 @@ private fun PlayerPreviewBitmap( var pitch by remember(previewKey) { mutableFloatStateOf(0f) } var dragging by remember { mutableStateOf(false) } var sizePx by remember { mutableStateOf(IntSize.Zero) } + val hold = rememberDragHold { dragging = it } DisposableEffect(previewKey) { PlayerPreviewRenderer.retain(previewKey) @@ -259,9 +270,9 @@ private fun PlayerPreviewBitmap( Modifier .pointerInput(Unit) { detectDragGestures( - onDragStart = { dragging = true }, - onDragEnd = { dragging = false }, - onDragCancel = { dragging = false }, + onDragStart = { hold.mouse(true) }, + onDragEnd = { hold.mouse(false) }, + onDragCancel = { hold.mouse(false) }, ) { change, drag -> yaw -= drag.x * DRAG_YAW_SENSITIVITY pitch = (pitch + drag.y * DRAG_PITCH_SENSITIVITY).coerceIn(-MAX_PITCH, MAX_PITCH) @@ -269,6 +280,7 @@ private fun PlayerPreviewBitmap( } } .controllerPan { delta -> + hold.pan() yaw -= delta.x * PAN_SCALE * DRAG_YAW_SENSITIVITY pitch = (pitch + delta.y * PAN_SCALE * DRAG_PITCH_SENSITIVITY).coerceIn(-MAX_PITCH, MAX_PITCH) } @@ -285,6 +297,39 @@ private fun PlayerPreviewBitmap( } } +private class DragHold(private val scope: CoroutineScope, private val apply: (Boolean) -> Unit) { + private var mouse = false + private var panning = false + private var release: Job? = null + + fun mouse(down: Boolean) { + mouse = down + sync() + } + + fun pan() { + panning = true + sync() + release?.cancel() + release = scope.launch { + delay(PAN_RELEASE_MS) + panning = false + sync() + } + } + + private fun sync() = apply(mouse || panning) +} + +@Composable +private fun rememberDragHold(onHold: (Boolean) -> Unit): DragHold { + val scope = rememberCoroutineScope() + val hold by rememberUpdatedState(onHold) + return remember(scope) { DragHold(scope) { hold(it) } } +} + +private const val PAN_RELEASE_MS = 300L + private const val CAPTURE_RENDERS = 3 private const val CAPTURE_RETRY_DELAY_MS = 250L private const val CAPTURE_TIMEOUT_MS = 1_000L diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/wardrobe/AuraColorPicker.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/wardrobe/AuraColorPicker.kt index 4245d7537..811387d34 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/wardrobe/AuraColorPicker.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/wardrobe/AuraColorPicker.kt @@ -31,6 +31,7 @@ import androidx.compose.runtime.rememberUpdatedState import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.composed import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.drawBehind import androidx.compose.ui.draw.drawWithCache @@ -39,6 +40,7 @@ import androidx.compose.ui.geometry.Offset import androidx.compose.ui.geometry.Size import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.Shape import androidx.compose.ui.graphics.SolidColor import androidx.compose.ui.graphics.graphicsLayer import androidx.compose.ui.input.key.Key @@ -60,8 +62,10 @@ import java.awt.Color as AwtColor import kotlin.math.ceil import kotlin.math.roundToInt import org.polyfrost.compose.host.controller.ControllerAxes +import org.polyfrost.compose.host.controller.Controllers import org.polyfrost.compose.host.controller.controllerArrows import org.polyfrost.oneconfig.api.ui.v1.ExperimentalOneConfigUiApi +import org.polyfrost.oneconfig.api.ui.v1.a11y.focusRing import org.polyfrost.oneconfig.api.ui.v1.components.EscapeCloses import org.polyfrost.oneconfig.api.ui.v1.components.Placement import org.polyfrost.oneconfig.api.ui.v1.components.Text @@ -200,33 +204,62 @@ private const val PAD_STEP = 0.05f private const val HUE_STEP = 10f private fun Modifier.arrowAdjust( - state: AuraPickerState, vertical: Boolean, enabled: Boolean, + shape: Shape, onDone: () -> Unit, onStep: (dx: Float, dy: Float) -> Boolean, -): Modifier = if (!enabled) this else - onKeyEvent { event -> - val dx = when (event.key) { - Key.DirectionLeft -> -1f - Key.DirectionRight -> 1f - else -> 0f - } - val dy = when (event.key) { - Key.DirectionUp -> if (vertical) -1f else 0f - Key.DirectionDown -> if (vertical) 1f else 0f - else -> 0f - } - if (dx == 0f && dy == 0f) return@onKeyEvent false - when (event.type) { - KeyEventType.KeyDown -> onStep(dx, dy).also { if (it) state.adjusting = true } - KeyEventType.KeyUp -> state.adjusting.also { - if (it) onDone() - state.adjusting = false +): Modifier = if (!enabled) this else composed { + var editing by remember { mutableStateOf(false) } + var dirty by remember { mutableStateOf(false) } + val done by rememberUpdatedState(onDone) + val step by rememberUpdatedState(onStep) + + fun stopEditing() { + editing = false + if (!dirty) return + dirty = false + done() + } + + DisposableEffect(Unit) { onDispose { if (dirty) done() } } + + onFocusChanged { if (!it.isFocused && editing) stopEditing() } + .then(if (editing) Modifier.controllerArrows(if (vertical) ControllerAxes.Both else ControllerAxes.Horizontal) else Modifier) + .onKeyEvent { event -> + when (event.key) { + Key.Enter, Key.NumPadEnter -> { + if (event.type == KeyEventType.KeyUp) { + if (editing) stopEditing() else editing = true + } + true + } + Key.Escape -> { + if (!editing) return@onKeyEvent false + if (event.type == KeyEventType.KeyDown) stopEditing() + true + } + else -> { + if (!editing || event.type != KeyEventType.KeyDown) return@onKeyEvent false + val dx = when (event.key) { + Key.DirectionLeft -> -1f + Key.DirectionRight -> 1f + else -> 0f + } + val dy = when (event.key) { + Key.DirectionUp -> if (vertical) -1f else 0f + Key.DirectionDown -> if (vertical) 1f else 0f + else -> 0f + } + if (dx == 0f && dy == 0f) return@onKeyEvent false + if (step(dx, dy)) dirty = true + true + } } - else -> false } - }.controllerArrows(if (vertical) ControllerAxes.Both else ControllerAxes.Horizontal).focusableOnController() + .focusRing(shape, editing && Controllers.isActive) + .focusableOnController() +} private class AuraPickerState(argb: Int) { var hue by mutableFloatStateOf(0f) @@ -236,8 +269,6 @@ private class AuraPickerState(argb: Int) { var lastEmitted: Int? = null - var adjusting = false - init { applyFrom(argb) } @@ -368,7 +399,7 @@ private fun AuraCustomPopover( .graphicsLayer { this.alpha = controlAlpha } .clip(barShape) .onSizeChanged { paneSize = Size(it.width.toFloat(), it.height.toFloat()) } - .arrowAdjust(state, vertical = true, enabled, ::emitCommit) { dx, dy -> + .arrowAdjust(vertical = true, enabled, barShape, ::emitCommit) { dx, dy -> val nextSaturation = (state.saturation + dx * PAD_STEP).coerceIn(0f, 1f) val nextBrightness = (state.brightness - dy * PAD_STEP).coerceIn(0f, 1f) val changed = nextSaturation != state.saturation || nextBrightness != state.brightness @@ -431,7 +462,7 @@ private fun AuraCustomPopover( ) onDrawBehind { drawRect(gradient) } } - .arrowAdjust(state, vertical = false, enabled, ::emitCommit) { dx, _ -> + .arrowAdjust(vertical = false, enabled, barShape, ::emitCommit) { dx, _ -> val next = (state.hue + dx * HUE_STEP).coerceIn(0f, 360f) val changed = next != state.hue state.hue = next @@ -476,7 +507,7 @@ private fun AuraCustomPopover( modifier = Modifier.fillMaxWidth().height(14.dp) .graphicsLayer { this.alpha = controlAlpha } .clip(barShape) - .arrowAdjust(state, vertical = false, enabled, ::emitCommit) { dx, _ -> + .arrowAdjust(vertical = false, enabled, barShape, ::emitCommit) { dx, _ -> val next = (state.alpha + dx * PAD_STEP).coerceIn(0f, 1f) val changed = next != state.alpha state.alpha = next diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/gui/wardrobe/WardrobeActions.kt b/src/main/kotlin/org/polyfrost/polyplus/client/gui/wardrobe/WardrobeActions.kt index bdb3b0e0e..1dcfa3acc 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/gui/wardrobe/WardrobeActions.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/gui/wardrobe/WardrobeActions.kt @@ -218,6 +218,8 @@ internal fun addEmoteToWheel(item: CosmeticUiItem, targetSlot: Int?, onStatus: ( } internal fun emoteKeybindWarning(): String? = when { + !EmoteWheelKeybind.isBound() && EmoteWheelKeybind.canBindController() -> + "The emote wheel has no keyboard keybind. Unless it's bound in Controlify, it can't be opened in game." !EmoteWheelKeybind.isBound() -> "The emote wheel has no keybind yet, so it can't be opened in game." else -> EmoteWheelKeybind.conflictingKeybindNames().takeIf { it.isNotEmpty() } ?.let { "The emote wheel keybind is also used by ${it.joinToString()}." } diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/party/PartyVoice.kt b/src/main/kotlin/org/polyfrost/polyplus/client/party/PartyVoice.kt index 39b7edf48..6664595be 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/party/PartyVoice.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/party/PartyVoice.kt @@ -59,6 +59,7 @@ object PartyVoice { @Volatile private var micBlocked = false @Volatile private var pttHeld = false @Volatile private var ptmHeld = false + @Volatile private var controllerPttHeld = false @Volatile private var rtcFailedAt = 0L @Volatile private var rtcSessionFailed = false @Volatile private var linuxRtcChecked = false @@ -230,6 +231,10 @@ object PartyVoice { ptmHeld = state } + fun onControllerPushToTalk(state: Boolean) { + controllerPttHeld = state + } + fun onSettingsChanged(restartAudio: Boolean = false) { if (EchoReference.enabled != PolyPlusConfig.voiceEchoCancellation) { EchoReference.setEnabled(PolyPlusConfig.voiceEchoCancellation) @@ -436,7 +441,7 @@ object PartyVoice { if (voiced) lastLoud = now val recent = now - lastLoud < VAD_HANGOVER_MS val gate = when (PartyVoiceSettings.inputMode()) { - VoiceInputMode.PUSH_TO_TALK -> pttHeld + VoiceInputMode.PUSH_TO_TALK -> pttHeld || controllerPttHeld VoiceInputMode.PUSH_TO_MUTE -> recent && !ptmHeld VoiceInputMode.VOICE_ACTIVITY -> recent } diff --git a/src/main/kotlin/org/polyfrost/polyplus/client/ping/PingInput.kt b/src/main/kotlin/org/polyfrost/polyplus/client/ping/PingInput.kt index ff6ad8161..280fac96d 100644 --- a/src/main/kotlin/org/polyfrost/polyplus/client/ping/PingInput.kt +++ b/src/main/kotlin/org/polyfrost/polyplus/client/ping/PingInput.kt @@ -52,6 +52,7 @@ object PingInput { private const val MIN_ALPHA = 0.05f private const val MS_PER_SECOND = 1000L private const val STICK_OPEN = 0.6f + private const val STICK_NEUTRAL = 0.3f @Volatile private var held = false @@ -65,6 +66,8 @@ object PingInput { private var pickPress = false private var swallowPick = false private var controllerHeld = false + private var stickArmed = false + private var keyHeld = false private val downKeys = HashSet() private val downMouse = HashSet() @@ -96,15 +99,24 @@ object PingInput { fun onKeybindState(pressed: Boolean) { ensureStarted() if (rawSeen) return - if (pressed) press() else release() + keyboard(pressed) } fun onControllerState(pressed: Boolean) { ensureStarted() + if (pressed == controllerHeld) return controllerHeld = pressed + if (pressed) stickArmed = Controllers.rightStick.getDistance() < STICK_OPEN + if (keyHeld) return if (pressed) press(fromController = true) else release() } + private fun keyboard(pressed: Boolean) { + keyHeld = pressed + if (controllerHeld) return + if (pressed) press() else release() + } + private fun syncRaw() { val bind = PolyPlusConfig.pingKeybind var mods = KeyModifiers.NONE @@ -113,7 +125,7 @@ object PingInput { if (active == rawActive) return rawActive = active rawSeen = true - if (active) press() else release() + keyboard(active) } private fun resetRaw() { @@ -121,6 +133,8 @@ object PingInput { downMouse.clear() if (!rawActive) return rawActive = false + keyHeld = false + if (controllerHeld) return held = false pending = false pickPress = false @@ -233,7 +247,9 @@ object PingInput { private fun tick() { if (!held) swallowPick = false - val flicked = controllerHeld && Controllers.rightStick.getDistance() >= STICK_OPEN + val stick = Controllers.rightStick.getDistance() + if (controllerHeld && !stickArmed && stick < STICK_NEUTRAL) stickArmed = true + val flicked = controllerHeld && stickArmed && stick >= STICK_OPEN if (pending && held && (flicked || System.currentTimeMillis() - pressedAt >= HOLD_MS)) { pending = false pickPress = false diff --git a/src/main/resources/assets/polyplus/lang/en_us.json b/src/main/resources/assets/polyplus/lang/en_us.json index 7384b5616..f74b49c80 100644 --- a/src/main/resources/assets/polyplus/lang/en_us.json +++ b/src/main/resources/assets/polyplus/lang/en_us.json @@ -21,6 +21,7 @@ "polyplus.controller.openSocials": "Open Socials", "polyplus.controller.openWardrobe": "Open Wardrobe", "polyplus.controller.emoteWheel": "Emote Wheel", + "polyplus.controller.emoteWheelNext": "Next Emote Wheel", "polyplus.controller.ping": "Ping", "polyplus.controller.pushToTalk": "Push to Talk", "polyplus.controller.toggleMute": "Toggle Mute",