|
| 1 | +/* |
| 2 | + * Zalith Launcher 2 |
| 3 | + * Copyright (C) 2025 MovTery <movtery228@qq.com> and contributors |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 | + * See the GNU General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License |
| 16 | + * along with this program. If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. |
| 17 | + */ |
| 18 | + |
| 19 | +package com.movtery.zalithlauncher.ui.screens.game.elements |
| 20 | + |
| 21 | +import androidx.compose.foundation.clickable |
| 22 | +import androidx.compose.foundation.layout.Arrangement |
| 23 | +import androidx.compose.foundation.layout.BoxWithConstraints |
| 24 | +import androidx.compose.foundation.layout.Column |
| 25 | +import androidx.compose.foundation.layout.Row |
| 26 | +import androidx.compose.foundation.layout.fillMaxHeight |
| 27 | +import androidx.compose.foundation.layout.fillMaxWidth |
| 28 | +import androidx.compose.foundation.layout.heightIn |
| 29 | +import androidx.compose.foundation.layout.padding |
| 30 | +import androidx.compose.foundation.layout.wrapContentHeight |
| 31 | +import androidx.compose.foundation.rememberScrollState |
| 32 | +import androidx.compose.foundation.verticalScroll |
| 33 | +import androidx.compose.material3.FilledTonalButton |
| 34 | +import androidx.compose.material3.MaterialTheme |
| 35 | +import androidx.compose.material3.RadioButton |
| 36 | +import androidx.compose.material3.Surface |
| 37 | +import androidx.compose.material3.Text |
| 38 | +import androidx.compose.runtime.Composable |
| 39 | +import androidx.compose.runtime.getValue |
| 40 | +import androidx.compose.runtime.mutableStateOf |
| 41 | +import androidx.compose.runtime.remember |
| 42 | +import androidx.compose.runtime.setValue |
| 43 | +import androidx.compose.ui.Alignment |
| 44 | +import androidx.compose.ui.Modifier |
| 45 | +import androidx.compose.ui.draw.clip |
| 46 | +import androidx.compose.ui.focus.focusProperties |
| 47 | +import androidx.compose.ui.res.stringResource |
| 48 | +import androidx.compose.ui.unit.dp |
| 49 | +import androidx.compose.ui.window.Dialog |
| 50 | +import androidx.compose.ui.window.DialogProperties |
| 51 | +import com.movtery.zalithlauncher.R |
| 52 | +import com.movtery.zalithlauncher.setting.AllSettings |
| 53 | +import com.movtery.zalithlauncher.setting.enums.GamepadInputMode |
| 54 | +import com.movtery.zalithlauncher.ui.components.rememberDialogMaxHeight |
| 55 | +import com.movtery.zalithlauncher.ui.theme.cardColor |
| 56 | +import com.movtery.zalithlauncher.ui.theme.onCardColor |
| 57 | + |
| 58 | +/** |
| 59 | + * 手柄输入模式选择对话框 |
| 60 | + */ |
| 61 | +@Composable |
| 62 | +fun GamepadModePromptDialog( |
| 63 | + visible: Boolean, |
| 64 | + onConfirm: (GamepadInputMode) -> Unit |
| 65 | +) { |
| 66 | + if (!visible) return |
| 67 | + var selected by remember { |
| 68 | + mutableStateOf(AllSettings.gamepadInputMode.state) |
| 69 | + } |
| 70 | + |
| 71 | + Dialog( |
| 72 | + onDismissRequest = {}, |
| 73 | + properties = DialogProperties( |
| 74 | + dismissOnBackPress = false, |
| 75 | + dismissOnClickOutside = false, |
| 76 | + usePlatformDefaultWidth = false |
| 77 | + ) |
| 78 | + ) { |
| 79 | + BoxWithConstraints( |
| 80 | + modifier = Modifier |
| 81 | + .fillMaxWidth(0.65f) |
| 82 | + .heightIn(max = rememberDialogMaxHeight()) |
| 83 | + .fillMaxHeight(), |
| 84 | + contentAlignment = Alignment.Center |
| 85 | + ) { |
| 86 | + Surface( |
| 87 | + modifier = Modifier |
| 88 | + .padding(all = 6.dp) |
| 89 | + .heightIn(max = (maxHeight - 12.dp).coerceAtMost(rememberDialogMaxHeight())) |
| 90 | + .wrapContentHeight(), |
| 91 | + shape = MaterialTheme.shapes.extraLarge, |
| 92 | + color = cardColor(false), |
| 93 | + contentColor = onCardColor(), |
| 94 | + shadowElevation = 6.dp |
| 95 | + ) { |
| 96 | + Column( |
| 97 | + modifier = Modifier.padding(all = 24.dp), |
| 98 | + verticalArrangement = Arrangement.spacedBy(12.dp) |
| 99 | + ) { |
| 100 | + Text( |
| 101 | + text = stringResource(R.string.settings_gamepad_input_mode_title), |
| 102 | + style = MaterialTheme.typography.headlineSmall |
| 103 | + ) |
| 104 | + |
| 105 | + // 内容区域 |
| 106 | + Column( |
| 107 | + modifier = Modifier |
| 108 | + .weight(1f, fill = false) |
| 109 | + .verticalScroll(rememberScrollState()), |
| 110 | + verticalArrangement = Arrangement.spacedBy(12.dp) |
| 111 | + ) { |
| 112 | + Text( |
| 113 | + text = stringResource(R.string.gamepad_mode_prompt_description), |
| 114 | + style = MaterialTheme.typography.bodyMedium, |
| 115 | + color = MaterialTheme.colorScheme.onSurfaceVariant |
| 116 | + ) |
| 117 | + |
| 118 | + GamepadInputMode.entries.forEach { mode -> |
| 119 | + Row( |
| 120 | + modifier = Modifier |
| 121 | + .fillMaxWidth() |
| 122 | + .clip(MaterialTheme.shapes.medium) |
| 123 | + .clickable { selected = mode }, |
| 124 | + verticalAlignment = Alignment.CenterVertically |
| 125 | + ) { |
| 126 | + RadioButton( |
| 127 | + selected = selected == mode, |
| 128 | + onClick = { selected = mode } |
| 129 | + ) |
| 130 | + Column( |
| 131 | + modifier = Modifier.padding(start = 4.dp) |
| 132 | + ) { |
| 133 | + Text( |
| 134 | + text = stringResource(mode.titleRes), |
| 135 | + style = MaterialTheme.typography.bodyMedium |
| 136 | + ) |
| 137 | + Text( |
| 138 | + text = stringResource(mode.summaryRes), |
| 139 | + style = MaterialTheme.typography.bodySmall, |
| 140 | + color = MaterialTheme.colorScheme.onSurfaceVariant |
| 141 | + ) |
| 142 | + } |
| 143 | + } |
| 144 | + } |
| 145 | + |
| 146 | + Text( |
| 147 | + text = stringResource(R.string.gamepad_mode_prompt_hint), |
| 148 | + style = MaterialTheme.typography.bodySmall, |
| 149 | + color = MaterialTheme.colorScheme.onSurfaceVariant |
| 150 | + ) |
| 151 | + } |
| 152 | + |
| 153 | + Row( |
| 154 | + modifier = Modifier.fillMaxWidth(), |
| 155 | + horizontalArrangement = Arrangement.End |
| 156 | + ) { |
| 157 | + FilledTonalButton( |
| 158 | + //确认按钮不参与焦点导航,手柄输入也已在更上游被吞掉,避免误触 |
| 159 | + modifier = Modifier.focusProperties { canFocus = false }, |
| 160 | + onClick = { onConfirm(selected) } |
| 161 | + ) { |
| 162 | + Text(stringResource(R.string.generic_confirm)) |
| 163 | + } |
| 164 | + } |
| 165 | + } |
| 166 | + } |
| 167 | + } |
| 168 | + } |
| 169 | +} |
0 commit comments