diff --git a/app/build.gradle b/app/build.gradle index 9d7ff3fa67749e913f86cf411b8eed9ecf7fd990..5363e27ec5e2f2b0d1714ecdc839b6a35cbeb4a7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -52,7 +52,7 @@ android { } composeOptions { kotlinCompilerExtensionVersion compose_version - kotlinCompilerVersion '1.4.32' + kotlinCompilerVersion '1.5.10' } } @@ -73,5 +73,4 @@ dependencies { implementation 'androidx.activity:activity-compose:1.3.0-alpha08' implementation "androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha05" implementation "androidx.constraintlayout:constraintlayout-compose:1.0.0-alpha07" - implementation "androidx.navigation:navigation-compose:1.0.0-alpha02" } \ No newline at end of file diff --git a/app/src/main/java/github/leavesc/compose_tetris/MainActivity.kt b/app/src/main/java/github/leavesc/compose_tetris/MainActivity.kt index 7d8a5aaf143d0e7a3ff7144d728bc0a7614ebdf1..059d360931fbaabb8dab0fe53f8e92c4cf5f237a 100644 --- a/app/src/main/java/github/leavesc/compose_tetris/MainActivity.kt +++ b/app/src/main/java/github/leavesc/compose_tetris/MainActivity.kt @@ -3,25 +3,10 @@ package github.leavesc.compose_tetris import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent -import androidx.compose.material.Surface -import androidx.compose.runtime.Composable -import androidx.compose.runtime.DisposableEffect -import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue -import androidx.compose.ui.platform.LocalLifecycleOwner -import androidx.compose.ui.tooling.preview.Preview -import androidx.lifecycle.DefaultLifecycleObserver -import androidx.lifecycle.LifecycleOwner -import androidx.lifecycle.viewmodel.compose.viewModel -import github.leavesc.compose_tetris.logic.Action -import github.leavesc.compose_tetris.logic.TetrisViewModel -import github.leavesc.compose_tetris.logic.combinedPlayListener -import github.leavesc.compose_tetris.logic.previewTetrisState -import github.leavesc.compose_tetris.ui.TetrisBody -import github.leavesc.compose_tetris.ui.TetrisButton -import github.leavesc.compose_tetris.ui.TetrisScreen -import github.leavesc.compose_tetris.ui.theme.ComposeTetrisTheme -import github.leavesc.compose_tetris.utils.StatusBarUtil +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue /** * @Author: leavesC @@ -29,14 +14,53 @@ import github.leavesc.compose_tetris.utils.StatusBarUtil * @Desc: * @Github:https://github.com/leavesC */ + +// 屏幕间传递信息的变量类 +class ScreenToScreenInfo { + // 初始为游戏页面 + var currentScreen by mutableStateOf(0) + + // 难度选择 + var difficulty by mutableStateOf("Normal") + // 选择夜间模式还是普通配色 + var tetrisTheme by mutableStateOf(0) + // 音乐选择 + var bgm by mutableStateOf(0) + // 用户名 + var username by mutableStateOf("") + // 历史记录最高分 + var highestScore by mutableStateOf(65535) /* TODO: 等待有一个后端计分的变量 */ +} + +var infoStorage = ScreenToScreenInfo() + class MainActivity : ComponentActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContent { + when(infoStorage.currentScreen) { + 0 -> { + TetrisGameScreen() + } + 1 -> { + SettingsScreen() + } + } + } + } +} + + +/* +class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - StatusBarUtil.transparentStatusBar(this) + // StatusBarUtil.transparentStatusBar(this) setContent { val tetrisViewModel = viewModel() val lifecycle = LocalLifecycleOwner.current.lifecycle + DisposableEffect(key1 = Unit) { val observer = object : DefaultLifecycleObserver { override fun onResume(owner: LifecycleOwner) { @@ -52,45 +76,46 @@ class MainActivity : ComponentActivity() { lifecycle.removeObserver(observer) } } + ComposeTetrisTheme { Surface { val tetrisState by tetrisViewModel.tetrisStateLD.collectAsState() - TetrisBody(tetrisScreen = { - TetrisScreen(tetrisState = tetrisState) - }, tetrisButton = { - TetrisButton( - playListener = combinedPlayListener( - onStart = { - tetrisViewModel.dispatch(Action.Start) - }, - onPause = { - tetrisViewModel.dispatch(Action.Pause) - }, - onReset = { - tetrisViewModel.dispatch(Action.Reset) - }, - onTransformation = { - tetrisViewModel.dispatch(Action.Transformation(it)) - }, - onSound = { - tetrisViewModel.dispatch(Action.Sound) - }, + TetrisBody( + tetrisScreen = { + TetrisScreen(tetrisState = tetrisState) + }, + tetrisButton = { + TetrisButton( + playListener = combinedPlayListener( + onStart = { + tetrisViewModel.dispatch(Action.Start) + }, + onPause = { + tetrisViewModel.dispatch(Action.Pause) + }, + onReset = { + tetrisViewModel.dispatch(Action.Reset) + }, + onTransformation = { + tetrisViewModel.dispatch(Action.Transformation(it)) + }, + onSound = { + tetrisViewModel.dispatch(Action.Sound) + }, + onSettings = { + + } + ) ) - ) - }) + } + ) } } tetrisViewModel.dispatch(action = Action.Welcome) } } } + */ + + -@Composable -@Preview(widthDp = 420, heightDp = 760) -fun DefaultPreview() { - TetrisBody(tetrisScreen = { - TetrisScreen(tetrisState = previewTetrisState) - }, tetrisButton = { - TetrisButton() - }) -} \ No newline at end of file diff --git a/app/src/main/java/github/leavesc/compose_tetris/TetrisApplication.kt b/app/src/main/java/github/leavesc/compose_tetris/TetrisApplication.kt index e48f14ad25a651507c40cb8b261276f402d044be..249d6b8d0c8a0f721e3725bd092de11a5cdb4444 100644 --- a/app/src/main/java/github/leavesc/compose_tetris/TetrisApplication.kt +++ b/app/src/main/java/github/leavesc/compose_tetris/TetrisApplication.kt @@ -10,10 +10,8 @@ import github.leavesc.compose_tetris.utils.SoundUtil * @Github:https://github.com/leavesC */ class TetrisApplication : Application() { - override fun onCreate() { super.onCreate() SoundUtil.init(this) } - } \ No newline at end of file diff --git a/app/src/main/java/github/leavesc/compose_tetris/TetrisGameScreen.kt b/app/src/main/java/github/leavesc/compose_tetris/TetrisGameScreen.kt new file mode 100644 index 0000000000000000000000000000000000000000..67110ce8889266fbfb1062abb6e02a7830de6107 --- /dev/null +++ b/app/src/main/java/github/leavesc/compose_tetris/TetrisGameScreen.kt @@ -0,0 +1,90 @@ +package github.leavesc.compose_tetris + +import androidx.compose.foundation.layout.padding +import androidx.compose.material.Scaffold +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect +import androidx.compose.runtime.collectAsState +import androidx.compose.runtime.getValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalLifecycleOwner +import androidx.compose.ui.tooling.preview.Preview +import androidx.lifecycle.DefaultLifecycleObserver +import androidx.lifecycle.LifecycleOwner +import androidx.lifecycle.viewmodel.compose.viewModel +import github.leavesc.compose_tetris.logic.Action +import github.leavesc.compose_tetris.logic.TetrisViewModel +import github.leavesc.compose_tetris.logic.combinedPlayListener +import github.leavesc.compose_tetris.logic.previewTetrisState +import github.leavesc.compose_tetris.ui.TetrisBody +import github.leavesc.compose_tetris.ui.TetrisButton +import github.leavesc.compose_tetris.ui.TetrisScreen + +@Composable +fun TetrisGameScreen() { + val tetrisViewModel = viewModel() + val lifecycle = LocalLifecycleOwner.current.lifecycle + val tetrisState by tetrisViewModel.tetrisStateLD.collectAsState() + + DisposableEffect(key1 = Unit) { + val observer = object : DefaultLifecycleObserver { + override fun onResume(owner: LifecycleOwner) { + tetrisViewModel.dispatch(Action.Resume) + } + + override fun onPause(owner: LifecycleOwner) { + tetrisViewModel.dispatch(Action.Background) + } + } + lifecycle.addObserver(observer) + onDispose { + lifecycle.removeObserver(observer) + } + } + + TetrisBody( + tetrisScreen = { + TetrisScreen(tetrisState = tetrisState) + }, + tetrisButton = { + TetrisButton( + playListener = combinedPlayListener( + onStart = { + tetrisViewModel.dispatch(Action.Start) + }, + onPause = { + tetrisViewModel.dispatch(Action.Pause) + }, + onReset = { + tetrisViewModel.dispatch(Action.Reset) + }, + onTransformation = { + tetrisViewModel.dispatch(Action.Transformation(it)) + }, + onSound = { + tetrisViewModel.dispatch(Action.Sound) + }, + onSettings = { + /* TODO: 链接到设置页面 */ + tetrisViewModel.dispatch(Action.Settings) + } + ) + ) + } + ) + tetrisViewModel.dispatch(action = Action.Welcome) +} + +@Composable +@Preview(widthDp = 420, heightDp = 760) +fun GameScreenPreview() { + TetrisBody( + tetrisScreen = { + TetrisScreen(tetrisState = previewTetrisState) + }, + tetrisButton = { + TetrisButton() + } + ) +} \ No newline at end of file diff --git a/app/src/main/java/github/leavesc/compose_tetris/TetrisSetting.kt b/app/src/main/java/github/leavesc/compose_tetris/TetrisSettingScreen.kt similarity index 82% rename from app/src/main/java/github/leavesc/compose_tetris/TetrisSetting.kt rename to app/src/main/java/github/leavesc/compose_tetris/TetrisSettingScreen.kt index e468fedddc1e9e3fbdc8327b2be54ec22f39c8d1..4f5c3a75c36a32e38389f55d1c43122ed6152ac3 100644 --- a/app/src/main/java/github/leavesc/compose_tetris/TetrisSetting.kt +++ b/app/src/main/java/github/leavesc/compose_tetris/TetrisSettingScreen.kt @@ -18,16 +18,11 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.constraintlayout.compose.ConstraintLayout import github.leavesc.compose_tetris.ui.theme.BodyBackground import androidx.compose.ui.unit.* -import github.leavesc.compose_tetris.ui.brushYellow +import github.leavesc.compose_tetris.ui.theme.RectangularButton +import github.leavesc.compose_tetris.ui.theme.brushYellow -@Preview(widthDp = 360, heightDp = 700) @Composable -fun PreviewTetrisSetting() { - SettingsBody() -} - -@Composable -fun SettingsBody() { +fun SettingsScreen() { Column( modifier = Modifier .fillMaxSize() @@ -41,7 +36,7 @@ fun SettingsBody() { text = "Game Settings", fontSize = 36.sp, fontWeight = FontWeight.Bold, - modifier = Modifier.padding(bottom = 5.dp) + modifier = Modifier.padding(top = smallerMargin, bottom = smallerMargin) ) ConstraintLayout( modifier = Modifier @@ -58,10 +53,10 @@ fun SettingsBody() { Text( text = "Switch difficulty", style = MaterialTheme.typography.body1.merge(), - modifier = Modifier.padding(5.dp) + modifier = Modifier.padding(smallerMargin) ) - // 难度选择框 + // 难度选择框 TODO: 还没完成难度选择功能 val difficultyOptions = listOf("Easy", "Normal", "Hard") val (selectedOption, onOptionSelected) = mutableStateOf(difficultyOptions[1]) @@ -158,12 +153,13 @@ fun SettingsBody() { modifier = Modifier .wrapContentWidth(align = Alignment.CenterHorizontally) ) { - var username by remember { mutableStateOf("") } - var highestScore = 65535 /* TODO: 等待有一个计分的变量 */ + val (playerName, historyScore, - rules) = createRefs() + rules, + backButton) = createRefs() + Row(modifier = Modifier.constrainAs(playerName) { start.linkTo(parent.start) top.linkTo(parent.top) @@ -174,8 +170,8 @@ fun SettingsBody() { modifier = Modifier.padding(smallerMargin) ) TextField( - value = username, - onValueChange = {username = it}, + value = infoStorage.username, + onValueChange = {infoStorage.username = it}, label = { Text("What's your name? ") }, maxLines = 1, modifier = Modifier @@ -194,7 +190,7 @@ fun SettingsBody() { ) Text( - text = "$highestScore", + text = "${infoStorage.highestScore}", fontSize = 24.sp, fontWeight = FontWeight.Bold, modifier = Modifier.padding(horizontal = biggerMargin) @@ -202,56 +198,57 @@ fun SettingsBody() { } Row(modifier = Modifier - .fillMaxSize() .constrainAs(rules) { start.linkTo(historyScore.start) top.linkTo(historyScore.bottom, margin = biggerMargin) }) { - Text( - text = "How to play", - style = MaterialTheme.typography.body1.merge(), - modifier = Modifier.padding(smallerMargin) - ) + Column( + modifier = Modifier.fillMaxHeight() + ) { + Text( + text = "How to play", + style = MaterialTheme.typography.body1.merge(), + modifier = Modifier.padding(smallerMargin) + ) + } Text( text = "Press \"Rotate\" to rotate the block\n" + "Press \"◀\" and \"▶\" to move the block horizontally\n" + "Press \"▼\" to speed up the block fall\n" + "Press \"✔\" directly to drop the current block\n", fontSize = 14.sp, - modifier = Modifier.padding(smallerMargin) + modifier = Modifier + .padding(smallerMargin) .fillMaxSize() ) } - + Row(modifier = Modifier + .fillMaxSize() + .constrainAs(backButton) { + start.linkTo(rules.start) + top.linkTo(rules.bottom) + bottom.linkTo(parent.bottom, margin = smallerMargin) + }) { + RectangularButton( + icon = "Back", + modifier = Modifier.padding( + top = 4 * biggerMargin, + bottom = 0.dp, + start = 0.dp + ) + ) { + /* TODO: 这里需要设置返回游戏页面的动作 */ + infoStorage.currentScreen = 0 + } + } } } } +@Preview @Composable -fun RectangularButton( - icon: String, - modifier: Modifier, - fontSize: TextUnit = 16.sp, - onPress: () -> Unit -) { - Box( - modifier = modifier - .clip(shape = RoundedCornerShape(7.dp)) - .background( - brush = brushYellow - ) - .padding(7.dp) - .clickable { - onPress() - }, - contentAlignment = Alignment.Center - ) { - Text( - text = icon, - fontSize = fontSize, - color = Color.Black.copy(0.9f) - ) - } -} \ No newline at end of file +fun PreviewTetrisSetting() { + SettingsScreen() +} diff --git a/app/src/main/java/github/leavesc/compose_tetris/logic/TetrisState.kt b/app/src/main/java/github/leavesc/compose_tetris/logic/TetrisState.kt index 7fdffbc5c3ee7f9c51107032a2f640fc5bdb95fb..24fd99b8b0b8628c9291fba4f60f4c1709ff4955 100644 --- a/app/src/main/java/github/leavesc/compose_tetris/logic/TetrisState.kt +++ b/app/src/main/java/github/leavesc/compose_tetris/logic/TetrisState.kt @@ -236,6 +236,7 @@ sealed class Action { object Pause : Action() object Reset : Action() object Sound : Action() + object Settings : Action() object Background : Action() object Resume : Action() data class Transformation(val transformationType: TransformationType) : Action() @@ -250,6 +251,7 @@ data class PlayListener constructor( val onPause: () -> Unit, val onReset: () -> Unit, val onSound: () -> Unit, + val onSettings: () -> Unit, val onTransformation: (TransformationType) -> Unit ) @@ -258,12 +260,14 @@ fun combinedPlayListener( onPause: () -> Unit = {}, onReset: () -> Unit = {}, onSound: () -> Unit = {}, + onSettings: () -> Unit = {}, onTransformation: (TransformationType) -> Unit = {} ) = PlayListener( onStart = onStart, onPause = onPause, onReset = onReset, onSound = onSound, + onSettings = onSettings, onTransformation = onTransformation ) diff --git a/app/src/main/java/github/leavesc/compose_tetris/logic/TetrisViewModel.kt b/app/src/main/java/github/leavesc/compose_tetris/logic/TetrisViewModel.kt index 6bd79102b71741e19e5eb1aefbd37cf4cdc60651..1469aafe9a2fa14aa458c033e8d61445bd1f0701 100644 --- a/app/src/main/java/github/leavesc/compose_tetris/logic/TetrisViewModel.kt +++ b/app/src/main/java/github/leavesc/compose_tetris/logic/TetrisViewModel.kt @@ -2,6 +2,7 @@ package github.leavesc.compose_tetris.logic import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import github.leavesc.compose_tetris.infoStorage import github.leavesc.compose_tetris.utils.SoundType import github.leavesc.compose_tetris.utils.SoundUtil import kotlinx.coroutines.Job @@ -19,11 +20,8 @@ import kotlinx.coroutines.launch class TetrisViewModel : ViewModel() { companion object { - private const val DOWN_SPEED = 500L - private const val CLEAR_SCREEN_SPEED = 30L - } private val _tetrisStateLD: MutableStateFlow = MutableStateFlow(TetrisState()) @@ -64,6 +62,10 @@ class TetrisViewModel : ViewModel() { Action.Sound -> { dispatchState(tetrisState.copy(soundEnable = !tetrisState.soundEnable)) } + Action.Settings -> { + /* TODO: 等待绑定设置页面 */ + infoStorage.currentScreen = 1 + } is Action.Transformation -> { if (!tetrisState.isRunning) { return @@ -226,6 +228,9 @@ class TetrisViewModel : ViewModel() { } Action.Sound -> { playSound(SoundType.Transformation) + } + Action.Settings -> { + } is Action.Transformation -> { when (action.transformationType) { diff --git a/app/src/main/java/github/leavesc/compose_tetris/ui/TetrisBody.kt b/app/src/main/java/github/leavesc/compose_tetris/ui/TetrisBody.kt index c27fdc2f25ed77754a8965fc325a46befd2b0114..7e45f73d9cc2127056219e4f753b9f9b61400f1b 100644 --- a/app/src/main/java/github/leavesc/compose_tetris/ui/TetrisBody.kt +++ b/app/src/main/java/github/leavesc/compose_tetris/ui/TetrisBody.kt @@ -24,16 +24,14 @@ import github.leavesc.compose_tetris.ui.theme.BodyBackground @Preview(widthDp = 360, heightDp = 700) @Composable fun PreviewTetrisBody() { - TetrisBody(tetrisScreen = { - }, tetrisButton = { - Box( - modifier = Modifier + TetrisBody( + tetrisScreen = {}, + tetrisButton = { + Box(modifier = Modifier .fillMaxWidth() - .fillMaxHeight(0.4f) - ) { - + .fillMaxHeight(0.4f)) {} } - }) + ) } @Composable diff --git a/app/src/main/java/github/leavesc/compose_tetris/ui/TetrisButton.kt b/app/src/main/java/github/leavesc/compose_tetris/ui/TetrisButton.kt index 627b7b0bb64ea2875cf74cc53298471eb8c9361b..bb1e28054ed4b937e3d4a610062b7aa007610733 100644 --- a/app/src/main/java/github/leavesc/compose_tetris/ui/TetrisButton.kt +++ b/app/src/main/java/github/leavesc/compose_tetris/ui/TetrisButton.kt @@ -44,8 +44,11 @@ fun TetrisButton( .wrapContentHeight(), horizontalArrangement = Arrangement.Center ) { - val controlPadding = 20.dp - ControlButton(hint = "Start", modifier = Modifier.padding(end = controlPadding)) { + val controlPadding = 13.dp + ControlButton( + hint = "Start", + modifier = Modifier.padding(end = controlPadding) + ) { playListener.onStart() } ControlButton( @@ -60,9 +63,18 @@ fun TetrisButton( ) { playListener.onReset() } - ControlButton(hint = "Sound", modifier = Modifier.padding(start = controlPadding)) { + ControlButton( + hint = "Sound", + modifier = Modifier.padding(start = controlPadding) + ) { playListener.onSound() } + ControlButton( + hint = "Settings", + modifier = Modifier.padding(start = controlPadding) + ) { + playListener.onSettings() + } } ConstraintLayout( modifier = Modifier @@ -81,7 +93,7 @@ fun TetrisButton( end: 右 top: 上 bottom: 下 - margin: 内边距 + margin: 应用之前定义的内边距 innerMargin = 24.dp */ start.linkTo(anchor = leftBtn.start) end.linkTo(anchor = rightBtn.end) @@ -126,86 +138,6 @@ fun TetrisButton( }) { playListener.onTransformation(FastDown) } - } } - -} - -val brushYellow = Brush.linearGradient( - colors = listOf( - PlayButtonColor, - PlayButtonColor2, - PlayButtonColor3 - ) -) - -val brushBlue = Brush.linearGradient( - colors = listOf( - PlayButtonColorNight, - PlayButtonColorNight2, - PlayButtonColorNight3 - ) -) - -@Composable -fun ControlButton( - modifier: Modifier, - hint: String, - fontSize: TextUnit = 18.sp, - btnSize: Dp = 46.dp, - onPress: () -> Unit = {}, -) { - Column( - modifier = modifier, - horizontalAlignment = Alignment.CenterHorizontally - ) { - Text( - modifier = Modifier.padding(2.dp), - text = hint, - fontSize = fontSize, - color = Color.Black.copy(0.8f), - maxLines = 1 - ) - Box( - modifier = Modifier - .size(width = btnSize, height = btnSize) - .shadow(elevation = 60.dp, shape = PlayButtonShape) - .clip(shape = PlayButtonShape) - .background( - brush = brushYellow - ) - .clickable { - onPress() - } - ) - } -} - -@Composable -fun PlayButton( - size: Dp = 70.dp, icon: String, - modifier: Modifier, - fontSize: TextUnit = 22.sp, - onPress: () -> Unit -) { - Box( - modifier = modifier - .size(width = size, height = size) - .shadow(elevation = 60.dp, shape = PlayButtonShape) - .clip(shape = PlayButtonShape) - .background( - brush = brushYellow - ) - .clickable { - onPress() - }, - contentAlignment = Alignment.Center - ) { - Text( - text = icon, - fontSize = fontSize, - color = Color.Black.copy(0.8f) - ) - } } \ No newline at end of file diff --git a/app/src/main/java/github/leavesc/compose_tetris/ui/TetrisIcon.kt b/app/src/main/java/github/leavesc/compose_tetris/ui/TetrisIcon.kt index a15cd7d5aec2b6302db9f4480f9a2f47c6d9d644..11cd75501ff302bf56a758d68c04bab8bab74312 100644 --- a/app/src/main/java/github/leavesc/compose_tetris/ui/TetrisIcon.kt +++ b/app/src/main/java/github/leavesc/compose_tetris/ui/TetrisIcon.kt @@ -18,6 +18,7 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import github.leavesc.compose_tetris.ui.theme.BodyBackground import github.leavesc.compose_tetris.ui.theme.BrickAlpha +import github.leavesc.compose_tetris.ui.theme.ControlButton import github.leavesc.compose_tetris.ui.theme.ScreenBackground /** diff --git a/app/src/main/java/github/leavesc/compose_tetris/ui/theme/Button.kt b/app/src/main/java/github/leavesc/compose_tetris/ui/theme/Button.kt new file mode 100644 index 0000000000000000000000000000000000000000..acee2da4548211f263c3d64330b137a98d3710fc --- /dev/null +++ b/app/src/main/java/github/leavesc/compose_tetris/ui/theme/Button.kt @@ -0,0 +1,109 @@ +package github.leavesc.compose_tetris.ui.theme + +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.draw.shadow +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.TextUnit +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp + +@Composable +fun ControlButton( + modifier: Modifier, + hint: String, + fontSize: TextUnit = 18.sp, + btnSize: Dp = 46.dp, + onPress: () -> Unit = {}, +) { + Column( + modifier = modifier, + horizontalAlignment = Alignment.CenterHorizontally + ) { + Text( + modifier = Modifier.padding(2.dp), + text = hint, + fontSize = fontSize, + color = Color.Black.copy(0.8f), + maxLines = 1 + ) + Box( + modifier = Modifier + .size(width = btnSize, height = btnSize) + .shadow(elevation = 60.dp, shape = PlayButtonShape) + .clip(shape = PlayButtonShape) + .background( + brush = brushYellow + ) + .clickable { + onPress() + } + ) + } +} + +@Composable +fun PlayButton( + size: Dp = 70.dp, icon: String, + modifier: Modifier, + fontSize: TextUnit = 22.sp, + onPress: () -> Unit +) { + Box( + modifier = modifier + .size(width = size, height = size) + .shadow(elevation = 60.dp, shape = PlayButtonShape) + .clip(shape = PlayButtonShape) + .background( + brush = brushYellow + ) + .clickable { + onPress() + }, + contentAlignment = Alignment.Center + ) { + Text( + text = icon, + fontSize = fontSize, + color = Color.Black.copy(0.8f) + ) + } +} + +@Composable +fun RectangularButton( + icon: String, + modifier: Modifier, + fontSize: TextUnit = 16.sp, + onPress: () -> Unit +) { + Box( + modifier = modifier + .clip(shape = RoundedCornerShape(7.dp)) + .background( + brush = brushYellow + ) + .padding(7.dp) + .clickable { + onPress() + }, + contentAlignment = Alignment.Center + ) { + Text( + text = icon, + fontSize = fontSize, + color = Color.Black.copy(0.9f) + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/github/leavesc/compose_tetris/ui/theme/Color.kt b/app/src/main/java/github/leavesc/compose_tetris/ui/theme/Color.kt index ab4253d1e5d934a1633e27c9a36143c586da9ebe..95af717e23b8c197a0ec186b9e0295928b7753c5 100644 --- a/app/src/main/java/github/leavesc/compose_tetris/ui/theme/Color.kt +++ b/app/src/main/java/github/leavesc/compose_tetris/ui/theme/Color.kt @@ -1,5 +1,6 @@ package github.leavesc.compose_tetris.ui.theme +import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color val Purple200 = Color(0xFFBB86FC) @@ -20,4 +21,20 @@ val PlayButtonColorNight = Color(0xF24784FF) val PlayButtonColorNight2 = Color(0xF2245AC7) val PlayButtonColorNight3 = Color(0xF2123E97) val BrickAlpha = Color.Black.copy(alpha = 0.2f) -val BrickFill = Color.Black.copy(alpha = 0.9f) \ No newline at end of file +val BrickFill = Color.Black.copy(alpha = 0.9f) + +val brushYellow = Brush.linearGradient( + colors = listOf( + PlayButtonColor, + PlayButtonColor2, + PlayButtonColor3 + ) +) + +val brushBlue = Brush.linearGradient( + colors = listOf( + PlayButtonColorNight, + PlayButtonColorNight2, + PlayButtonColorNight3 + ) +) \ No newline at end of file diff --git a/daemon/7.0/registry.bin b/daemon/7.0/registry.bin index 820dcb1e975f69e28cc4b95dc4b2f496b1525ca0..f7efac7ffd4c082fc823d1537789ba393de05e20 100644 Binary files a/daemon/7.0/registry.bin and b/daemon/7.0/registry.bin differ diff --git a/daemon/7.0/registry.bin.lock b/daemon/7.0/registry.bin.lock index cf2814023d4b21f3d3f7369452de298f6aa8c864..9bd45cbfa2000bf7fab4a631bcbd94110e0f6d7b 100644 Binary files a/daemon/7.0/registry.bin.lock and b/daemon/7.0/registry.bin.lock differ diff --git a/kotlin-profile/2021-08-01-21-17-40-129.profile b/kotlin-profile/2021-08-01-21-17-40-129.profile deleted file mode 100644 index 70e963eef37159613c6578ace35671ba0f28b5bc..0000000000000000000000000000000000000000 --- a/kotlin-profile/2021-08-01-21-17-40-129.profile +++ /dev/null @@ -1,27 +0,0 @@ -BUILD_FINISH_TIME=1627823891357 -CONFIGURATION_API_COUNT=1 -CONFIGURATION_IMPLEMENTATION_COUNT=1 -CPU_NUMBER_OF_CORES=12 -GRADLE_BUILD_DURATION=31659 -GRADLE_BUILD_NUMBER_IN_CURRENT_DAEMON=14 -GRADLE_DAEMON_HEAP_SIZE=2291312926 -GRADLE_EXECUTION_DURATION=31228 -GRADLE_NUMBER_OF_TASKS=288 -GRADLE_NUMBER_OF_UNCONFIGURED_TASKS=227 -NUMBER_OF_SUBPROJECTS=2 -STATISTICS_COLLECT_METRICS_OVERHEAD=4 -STATISTICS_VISIT_ALL_PROJECTS_OVERHEAD=1 -BUILD_FAILED=false -EXECUTED_FROM_IDEA=true -JVM_COMPILER_IR_MODE=true -KOTLIN_KTS_USED=false -KOTLIN_OFFICIAL_CODESTYLE=true -KOTLIN_PROGRESSIVE_MODE=false -GRADLE_VERSION=7.0.0 -JVM_DEFAULTS=disable -KOTLIN_COMPILER_VERSION=1.5.10 -KOTLIN_STDLIB_VERSION=1.5.10 -OS_TYPE=Windows 10 -PROJECT_PATH=D:\CyberAngel\gitee\android_tetris -USE_OLD_BACKEND=false -BUILD FINISHED