email: move composer→ui/composer, imap/smtp→network/*, EmailModels→data, Email*→platform (git mv)
- Commit
d6b383c750c034c0e3d20a3f96a388e8921dc517- Author
- vayun-mathur <[email protected]>
- When
- 2026-08-15 19:03 UTC (3 months ago)
- Parents
0698194
Diff
email/src/main/java/com/vayunmathur/email/data/EmailModels.kt
diff --git a/email/src/main/java/com/vayunmathur/email/EmailModels.kt b/email/src/main/java/com/vayunmathur/email/data/EmailModels.ktsimilarity index 100%rename from email/src/main/java/com/vayunmathur/email/EmailModels.ktrename to email/src/main/java/com/vayunmathur/email/data/EmailModels.kt
email/src/main/java/com/vayunmathur/email/network/imap/ImapAuthException.kt
diff --git a/email/src/main/java/com/vayunmathur/email/imap/ImapAuthException.kt b/email/src/main/java/com/vayunmathur/email/network/imap/ImapAuthException.ktsimilarity index 100%rename from email/src/main/java/com/vayunmathur/email/imap/ImapAuthException.ktrename to email/src/main/java/com/vayunmathur/email/network/imap/ImapAuthException.kt
email/src/main/java/com/vayunmathur/email/network/imap/ImapClient.kt
diff --git a/email/src/main/java/com/vayunmathur/email/imap/ImapClient.kt b/email/src/main/java/com/vayunmathur/email/network/imap/ImapClient.ktsimilarity index 100%rename from email/src/main/java/com/vayunmathur/email/imap/ImapClient.ktrename to email/src/main/java/com/vayunmathur/email/network/imap/ImapClient.kt
email/src/main/java/com/vayunmathur/email/network/imap/ImapParser.kt
diff --git a/email/src/main/java/com/vayunmathur/email/imap/ImapParser.kt b/email/src/main/java/com/vayunmathur/email/network/imap/ImapParser.ktsimilarity index 100%rename from email/src/main/java/com/vayunmathur/email/imap/ImapParser.ktrename to email/src/main/java/com/vayunmathur/email/network/imap/ImapParser.kt
email/src/main/java/com/vayunmathur/email/network/imap/MimeParser.kt
diff --git a/email/src/main/java/com/vayunmathur/email/imap/MimeParser.kt b/email/src/main/java/com/vayunmathur/email/network/imap/MimeParser.ktsimilarity index 100%rename from email/src/main/java/com/vayunmathur/email/imap/MimeParser.ktrename to email/src/main/java/com/vayunmathur/email/network/imap/MimeParser.kt
email/src/main/java/com/vayunmathur/email/network/imap/RawImapConnection.kt
diff --git a/email/src/main/java/com/vayunmathur/email/imap/RawImapConnection.kt b/email/src/main/java/com/vayunmathur/email/network/imap/RawImapConnection.ktsimilarity index 100%rename from email/src/main/java/com/vayunmathur/email/imap/RawImapConnection.ktrename to email/src/main/java/com/vayunmathur/email/network/imap/RawImapConnection.kt
email/src/main/java/com/vayunmathur/email/network/imap/TrustAll.kt
diff --git a/email/src/main/java/com/vayunmathur/email/imap/TrustAll.kt b/email/src/main/java/com/vayunmathur/email/network/imap/TrustAll.ktsimilarity index 100%rename from email/src/main/java/com/vayunmathur/email/imap/TrustAll.ktrename to email/src/main/java/com/vayunmathur/email/network/imap/TrustAll.kt
email/src/main/java/com/vayunmathur/email/network/smtp/MimeBuilder.kt
diff --git a/email/src/main/java/com/vayunmathur/email/smtp/MimeBuilder.kt b/email/src/main/java/com/vayunmathur/email/network/smtp/MimeBuilder.ktsimilarity index 100%rename from email/src/main/java/com/vayunmathur/email/smtp/MimeBuilder.ktrename to email/src/main/java/com/vayunmathur/email/network/smtp/MimeBuilder.kt
email/src/main/java/com/vayunmathur/email/network/smtp/RawSmtpConnection.kt
diff --git a/email/src/main/java/com/vayunmathur/email/smtp/RawSmtpConnection.kt b/email/src/main/java/com/vayunmathur/email/network/smtp/RawSmtpConnection.ktsimilarity index 100%rename from email/src/main/java/com/vayunmathur/email/smtp/RawSmtpConnection.ktrename to email/src/main/java/com/vayunmathur/email/network/smtp/RawSmtpConnection.kt
email/src/main/java/com/vayunmathur/email/network/smtp/SmtpClient.kt
diff --git a/email/src/main/java/com/vayunmathur/email/smtp/SmtpClient.kt b/email/src/main/java/com/vayunmathur/email/network/smtp/SmtpClient.ktsimilarity index 100%rename from email/src/main/java/com/vayunmathur/email/smtp/SmtpClient.ktrename to email/src/main/java/com/vayunmathur/email/network/smtp/SmtpClient.kt
email/src/main/java/com/vayunmathur/email/platform/EmailClientFlag.kt
diff --git a/email/src/main/java/com/vayunmathur/email/EmailClientFlag.kt b/email/src/main/java/com/vayunmathur/email/platform/EmailClientFlag.ktsimilarity index 100%rename from email/src/main/java/com/vayunmathur/email/EmailClientFlag.ktrename to email/src/main/java/com/vayunmathur/email/platform/EmailClientFlag.kt
email/src/main/java/com/vayunmathur/email/platform/EmailManager.kt
diff --git a/email/src/main/java/com/vayunmathur/email/EmailManager.kt b/email/src/main/java/com/vayunmathur/email/platform/EmailManager.ktsimilarity index 100%rename from email/src/main/java/com/vayunmathur/email/EmailManager.ktrename to email/src/main/java/com/vayunmathur/email/platform/EmailManager.kt
email/src/main/java/com/vayunmathur/email/platform/EmailViewModel.kt
diff --git a/email/src/main/java/com/vayunmathur/email/EmailViewModel.kt b/email/src/main/java/com/vayunmathur/email/platform/EmailViewModel.ktsimilarity index 100%rename from email/src/main/java/com/vayunmathur/email/EmailViewModel.ktrename to email/src/main/java/com/vayunmathur/email/platform/EmailViewModel.kt
email/src/main/java/com/vayunmathur/email/ui/composer/CidImageSpan.kt
diff --git a/email/src/main/java/com/vayunmathur/email/composer/CidImageSpan.kt b/email/src/main/java/com/vayunmathur/email/ui/composer/CidImageSpan.ktsimilarity index 100%rename from email/src/main/java/com/vayunmathur/email/composer/CidImageSpan.ktrename to email/src/main/java/com/vayunmathur/email/ui/composer/CidImageSpan.kt
email/src/main/java/com/vayunmathur/email/ui/composer/EmailHtmlEditor.kt
diff --git a/email/src/main/java/com/vayunmathur/email/composer/EmailHtmlEditor.kt b/email/src/main/java/com/vayunmathur/email/ui/composer/EmailHtmlEditor.ktsimilarity index 100%rename from email/src/main/java/com/vayunmathur/email/composer/EmailHtmlEditor.ktrename to email/src/main/java/com/vayunmathur/email/ui/composer/EmailHtmlEditor.kt
email/src/main/java/com/vayunmathur/email/ui/composer/EmailHtmlEditorController.kt
diff --git a/email/src/main/java/com/vayunmathur/email/composer/EmailHtmlEditorController.kt b/email/src/main/java/com/vayunmathur/email/ui/composer/EmailHtmlEditorController.ktsimilarity index 100%rename from email/src/main/java/com/vayunmathur/email/composer/EmailHtmlEditorController.ktrename to email/src/main/java/com/vayunmathur/email/ui/composer/EmailHtmlEditorController.kt
email/src/main/java/com/vayunmathur/email/ui/composer/EmailHtmlSerializer.kt
diff --git a/email/src/main/java/com/vayunmathur/email/composer/EmailHtmlSerializer.kt b/email/src/main/java/com/vayunmathur/email/ui/composer/EmailHtmlSerializer.ktsimilarity index 100%rename from email/src/main/java/com/vayunmathur/email/composer/EmailHtmlSerializer.ktrename to email/src/main/java/com/vayunmathur/email/ui/composer/EmailHtmlSerializer.kt
email/src/main/java/com/vayunmathur/email/ui/composer/EmailHtmlTagHandler.kt
diff --git a/email/src/main/java/com/vayunmathur/email/composer/EmailHtmlTagHandler.kt b/email/src/main/java/com/vayunmathur/email/ui/composer/EmailHtmlTagHandler.ktsimilarity index 100%rename from email/src/main/java/com/vayunmathur/email/composer/EmailHtmlTagHandler.ktrename to email/src/main/java/com/vayunmathur/email/ui/composer/EmailHtmlTagHandler.kt
email/src/main/java/com/vayunmathur/email/ui/composer/InlineImage.kt
diff --git a/email/src/main/java/com/vayunmathur/email/composer/InlineImage.kt b/email/src/main/java/com/vayunmathur/email/ui/composer/InlineImage.ktsimilarity index 100%rename from email/src/main/java/com/vayunmathur/email/composer/InlineImage.ktrename to email/src/main/java/com/vayunmathur/email/ui/composer/InlineImage.kt
files/src/main/AndroidManifest.xml
diff --git a/files/src/main/AndroidManifest.xml b/files/src/main/AndroidManifest.xmlindex 038cd7c8f3..4b4113ad31 100644--- a/files/src/main/AndroidManifest.xml+++ b/files/src/main/AndroidManifest.xml@@ -16,7 +16,7 @@ tools:ignore="ProtectedPermissions" /> <application- android:name=".FilesApp"+ android:name=".FilesApplication" android:allowBackup="true" android:dataExtractionRules="@xml/data_extraction_rules" android:icon="@mipmap/ic_launcher"
files/src/main/java/com/vayunmathur/files/FilesApplication.kt
diff --git a/files/src/main/java/com/vayunmathur/files/FilesApp.kt b/files/src/main/java/com/vayunmathur/files/FilesApplication.ktsimilarity index 95%rename from files/src/main/java/com/vayunmathur/files/FilesApp.ktrename to files/src/main/java/com/vayunmathur/files/FilesApplication.ktindex ea11e231ad..6ae47240fc 100644--- a/files/src/main/java/com/vayunmathur/files/FilesApp.kt+++ b/files/src/main/java/com/vayunmathur/files/FilesApplication.kt@@ -17,7 +17,7 @@ import com.vayunmathur.files.data.saf.DocumentPickerActivity * * The call is idempotent, so running it on every process start is cheap. */-class FilesApp : Application() {+class FilesApplication : Application() { override fun onCreate() { super.onCreate() syncDocumentPickerAvailability()
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/MainActivity.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/MainActivity.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/MainActivity.ktindex 21651a5a52..6f72595320 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/MainActivity.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/MainActivity.kt@@ -15,4 +15,4 @@ class MainActivity : ComponentActivity() { enableEdgeToEdge() setContent { DynamicTheme { Navigation(viewModel) } } }-}+}\ No newline at end of file
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/Navigation.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/Navigation.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/Navigation.ktnew file mode 100644index 0000000000..e967f63884--- /dev/null+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/Navigation.kt@@ -0,0 +1,37 @@+package com.vayunmathur.games.wordmaker++import androidx.compose.runtime.Composable+import com.vayunmathur.games.wordmaker.data.LevelDataStore+import com.vayunmathur.games.wordmaker.platform.AppBackupAgent+import com.vayunmathur.games.wordmaker.platform.WordMakerAchievementsManager+import com.vayunmathur.games.wordmaker.platform.WordMakerViewModel+import com.vayunmathur.games.wordmaker.ui.CompetitiveLobbyPage+import com.vayunmathur.games.wordmaker.ui.SettingsPage+import com.vayunmathur.games.wordmaker.ui.WordMakerGameLoader+import com.vayunmathur.library.ui.GameCenterScreen+import com.vayunmathur.library.util.MainNavigation+import com.vayunmathur.library.util.openSettingsIfRequested+import com.vayunmathur.library.util.rememberNavBackStack+import com.vayunmathur.library.util.AchievementsManager+import com.vayunmathur.library.util.GameHubSessionHook++@Composable+fun Navigation(viewModel: WordMakerViewModel) {+ val b=rememberNavBackStack<Route>(Route.Game)+ b.openSettingsIfRequested(Route.Settings)+ GameHubSessionHook("wordmaker","Wordmaker")+ MainNavigation(b){+ entry<Route.Game>{ WordMakerGameLoader(b,viewModel) }+ entry<Route.GameCenter>{+ val g=rememberAchievementsManager(viewModel.levelDataStore)+ if(g!=null) GameCenterScreen(backupAgent=AppBackupAgent(), manager=g, onBack={b.pop()})+ }+ entry<Route.Settings>{ SettingsPage(viewModel=viewModel,onBack={b.pop()}) }+ }+}+@Composable+fun rememberAchievementsManager(levelDataStore: LevelDataStore): AchievementsManager? {+ val c=androidx.compose.ui.platform.LocalContext.current+ val s=androidx.compose.runtime.produceState<AchievementsManager?>(null,c,levelDataStore){ value=kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.IO){ val j=c.assets.open("achievements.json").bufferedReader().use{it.readText()}; WordMakerAchievementsManager(c,j,levelDataStore)} }+ return s.value+}\ No newline at end of file
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/Route.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/Route.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/Route.ktnew file mode 100644index 0000000000..ee005d175c--- /dev/null+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/Route.kt@@ -0,0 +1,14 @@+package com.vayunmathur.games.wordmaker++import com.vayunmathur.library.util.NavKey+import kotlinx.serialization.Serializable++@Serializable+sealed interface Route : NavKey {+ @Serializable+ data object Game : Route+ @Serializable+ data object GameCenter : Route+ @Serializable+ data object Settings : Route+}\ No newline at end of file
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/domain/CompetitiveLevelGenerator.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/util/CompetitiveLevelGenerator.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/domain/CompetitiveLevelGenerator.ktsimilarity index 99%rename from games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/util/CompetitiveLevelGenerator.ktrename to games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/domain/CompetitiveLevelGenerator.ktindex eb483aad6d..b8a2fb313f 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/util/CompetitiveLevelGenerator.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/domain/CompetitiveLevelGenerator.kt@@ -1,4 +1,4 @@-package com.vayunmathur.games.wordmaker.util+package com.vayunmathur.games.wordmaker.domain import android.content.Context import com.vayunmathur.games.wordmaker.data.CrosswordData
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/domain/Dictionary.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/util/Dictionary.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/domain/Dictionary.ktsimilarity index 98%rename from games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/util/Dictionary.ktrename to games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/domain/Dictionary.ktindex f844c83dfc..7f99321d44 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/util/Dictionary.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/domain/Dictionary.kt@@ -1,4 +1,4 @@-package com.vayunmathur.games.wordmaker.util+package com.vayunmathur.games.wordmaker.domain import android.content.Context import java.nio.ByteBuffer import org.brotli.dec.BrotliInputStream
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/AppBackupAgent.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/util/AppBackupAgent.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/AppBackupAgent.ktsimilarity index 78%rename from games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/util/AppBackupAgent.ktrename to games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/AppBackupAgent.ktindex ac526cbce5..4f54d43c15 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/util/AppBackupAgent.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/AppBackupAgent.kt@@ -1,4 +1,4 @@-package com.vayunmathur.games.wordmaker.util+package com.vayunmathur.games.wordmaker.platform import com.vayunmathur.library.util.BaseBackupAgent
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerAchievementsManager.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/util/WordMakerAchievementsManager.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerAchievementsManager.ktsimilarity index 96%rename from games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/util/WordMakerAchievementsManager.ktrename to games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerAchievementsManager.ktindex 0b68584cab..2fcfb980e2 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/util/WordMakerAchievementsManager.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerAchievementsManager.kt@@ -1,4 +1,4 @@-package com.vayunmathur.games.wordmaker.util+package com.vayunmathur.games.wordmaker.platform import android.content.Context import com.vayunmathur.games.wordmaker.data.LevelDataStore
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerUiContract.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/util/WordMakerUiContract.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerUiContract.ktsimilarity index 98%rename from games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/util/WordMakerUiContract.ktrename to games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerUiContract.ktindex 8368f16420..3dc5c2e100 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/util/WordMakerUiContract.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerUiContract.kt@@ -1,4 +1,4 @@-package com.vayunmathur.games.wordmaker.util+package com.vayunmathur.games.wordmaker.platform import com.vayunmathur.games.wordmaker.data.CrosswordData import com.vayunmathur.games.wordmaker.data.Difficulty
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerViewModel.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/util/WordMakerViewModel.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerViewModel.ktsimilarity index 98%rename from games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/util/WordMakerViewModel.ktrename to games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerViewModel.ktindex 3061f72930..1ff530b888 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/util/WordMakerViewModel.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerViewModel.kt@@ -1,4 +1,4 @@-package com.vayunmathur.games.wordmaker.util+package com.vayunmathur.games.wordmaker.platform import android.app.Application import android.content.Context@@ -8,7 +8,7 @@ import com.vayunmathur.games.wordmaker.R import com.vayunmathur.games.wordmaker.data.CrosswordData import com.vayunmathur.games.wordmaker.data.Difficulty import com.vayunmathur.games.wordmaker.data.GameMode-import com.vayunmathur.games.wordmaker.data.LevelDataStore+import com.vayunmathur.games.wordmaker.data.LevelDataStore`nimport com.vayunmathur.games.wordmaker.domain.CompetitiveLevelGenerator`nimport com.vayunmathur.games.wordmaker.domain.Dictionary import com.vayunmathur.library.util.DailyChallengeStore import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.Flow
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/ChooserLetter.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/ChooserLetter.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/ChooserLetter.ktnew file mode 100644index 0000000000..1aaa4f265f--- /dev/null+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/ChooserLetter.kt@@ -0,0 +1,2 @@+package com.vayunmathur.games.wordmaker.ui+data class ChooserLetter(val id:Int,val char:Char)
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/CompetitiveLobbyScreen.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/CompetitiveLobbyScreen.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/CompetitiveLobbyScreen.ktnew file mode 100644index 0000000000..239a907151--- /dev/null+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/CompetitiveLobbyScreen.kt@@ -0,0 +1,116 @@+package com.vayunmathur.games.wordmaker.ui++import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Spacer+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.height+import androidx.compose.foundation.layout.padding+import androidx.compose.material3.Button+import androidx.compose.material3.MaterialTheme+import androidx.compose.material3.Scaffold+import androidx.compose.material3.Text+import androidx.compose.runtime.Composable+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.getValue+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.text.font.FontWeight+import androidx.compose.ui.unit.dp+import androidx.compose.ui.unit.sp+import com.vayunmathur.games.wordmaker.R+import com.vayunmathur.games.wordmaker.platform.CompetitiveLobbyActions+import com.vayunmathur.games.wordmaker.platform.CompetitiveLobbyUiState+import com.vayunmathur.games.wordmaker.platform.WordMakerViewModel+import com.vayunmathur.games.wordmaker.ui.components.DifficultyDropdown+import com.vayunmathur.games.wordmaker.ui.components.WordMakerTopBar+import com.vayunmathur.library.ui.ExperimentalMaterial3Api++fun CompetitiveLobbyPage(+ viewModel: WordMakerViewModel,+ onOpenGameCenter: () -> Unit,+ onOpenSettings: () -> Unit+) {+ val gameMode by viewModel.gameMode.collectAsState()+ val difficulty by viewModel.difficulty.collectAsState()+ val score by viewModel.competitiveScore.collectAsState()+ val result by viewModel.competitiveResult.collectAsState()++ CompetitiveLobbyScreen(+ state = CompetitiveLobbyUiState(+ gameMode = gameMode,+ difficulty = difficulty,+ score = score,+ result = result+ ),+ actions = viewModel,+ onOpenGameCenter = onOpenGameCenter,+ onOpenSettings = onOpenSettings+ )+}+++fun CompetitiveLobbyScreen(+ state: CompetitiveLobbyUiState,+ actions: CompetitiveLobbyActions,+ onOpenGameCenter: () -> Unit,+ onOpenSettings: () -> Unit+) {+ val difficulty = state.difficulty+ val result = state.result++ Scaffold(+ topBar = {+ WordMakerTopBar(+ gameMode = state.gameMode,+ onModeSelected = { actions.setGameMode(it) },+ onOpenGameCenter = onOpenGameCenter,+ onOpenSettings = onOpenSettings+ )+ }+ ) { innerPadding ->+ Column(+ modifier = Modifier+ .padding(innerPadding)+ .fillMaxSize()+ .padding(24.dp),+ horizontalAlignment = Alignment.CenterHorizontally,+ verticalArrangement = Arrangement.Center+ ) {+ Text(+ stringResource(R.string.competitive_score, state.score),+ fontWeight = FontWeight.Bold,+ fontSize = 20.sp+ )++ result?.let {+ Spacer(Modifier.height(24.dp))+ Text(+ text = if (it.won) {+ stringResource(R.string.competitive_solved, it.delta)+ } else {+ stringResource(R.string.competitive_timed_out, it.delta)+ },+ color = if (it.won) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.error,+ fontWeight = FontWeight.Bold,+ fontSize = 22.sp+ )+ }++ Spacer(Modifier.height(32.dp))+ Text(stringResource(R.string.competitive_difficulty), fontWeight = FontWeight.Bold)+ DifficultyDropdown(selected = difficulty, onSelected = { actions.setDifficulty(it) })+ Text(stringResource(R.string.competitive_time_limit, difficulty.timeLimitSeconds))++ Spacer(Modifier.height(32.dp))+ Button(onClick = { actions.loadNextCompetitiveLevel() }) {+ Text(+ stringResource(+ if (result == null) R.string.competitive_start else R.string.next_level+ )+ )+ }+ }+ }+}
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGamePage.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGamePage.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGamePage.ktnew file mode 100644index 0000000000..b0e4413afb--- /dev/null+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGamePage.kt@@ -0,0 +1,101 @@+package com.vayunmathur.games.wordmaker.ui++import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.getValue+import androidx.compose.runtime.remember+import com.vayunmathur.games.wordmaker.data.CrosswordData+import com.vayunmathur.games.wordmaker.platform.WordGameActions+import com.vayunmathur.games.wordmaker.platform.WordGameUiState+import com.vayunmathur.games.wordmaker.platform.WordMakerViewModel+import com.vayunmathur.library.util.AchievementsManager++fun WordGamePage(+ crosswordData: CrosswordData,+ currentLevel: Int,+ viewModel: WordMakerViewModel,+ achievementsManager: AchievementsManager,+ onOpenGameCenter: () -> Unit,+ onOpenSettings: () -> Unit+) {+ val foundWords by viewModel.foundWords.collectAsState()+ val bonusWords by viewModel.bonusWords.collectAsState()+ val tapToSpell by viewModel.tapToSpell.collectAsState()+ val revealedHints by viewModel.revealedHints.collectAsState()+ val hintCooldownEnd by viewModel.hintCooldownEnd.collectAsState()+ val gameMode by viewModel.gameMode.collectAsState()+ val competitiveScore by viewModel.competitiveScore.collectAsState()+ val competitiveLevelNumber by viewModel.competitiveLevelNumber.collectAsState()+ val competitiveDeadline by viewModel.competitiveDeadline.collectAsState()+ val dailyDay by viewModel.dailyDay.collectAsState()+ val dailyStreak by viewModel.dailyStreak.collectAsState()+ val dailyBestStreak by viewModel.dailyBestStreak.collectAsState()++ val isCompetitive = gameMode == GameMode.COMPETITIVE+ val isDaily = gameMode == GameMode.DAILY+ val isWon = crosswordData.winsWith(foundWords)++ LaunchedEffect(isWon) {+ if (!isWon) return@LaunchedEffect+ if (isCompetitive) {+ viewModel.onCompetitiveWin()+ return@LaunchedEffect+ }+ if (isDaily) {+ viewModel.onDailyWin()+ achievementsManager.onAchievementUnlocked("first_daily")+ return@LaunchedEffect+ }+ if (currentLevel == 1) achievementsManager.onAchievementUnlocked("level_1_done")+ if (currentLevel == 861) achievementsManager.onAchievementUnlocked("manual_levels_done")++ achievementsManager.onProgressUpdated("manual_levels_done", currentLevel)+ achievementsManager.onProgressUpdated("level_50", currentLevel)+ achievementsManager.onProgressUpdated("level_100", currentLevel)+ achievementsManager.onProgressUpdated("level_500", currentLevel)+ }++ LaunchedEffect(dailyBestStreak) {+ if (dailyBestStreak <= 0L) return@LaunchedEffect+ achievementsManager.onProgressUpdated("daily_streak_7", dailyBestStreak.toInt())+ achievementsManager.onProgressUpdated("daily_streak_30", dailyBestStreak.toInt())+ }++ // The achievements manager belongs to the activity, not the ViewModel, so the two+ // achievement-reporting callbacks are stitched on here rather than pushed into the screen.+ val actions = remember(viewModel, achievementsManager) {+ object : WordGameActions by viewModel {+ override fun onSolutionWordFound(word: String) {+ if (word.length >= 7) achievementsManager.onAchievementUnlocked("long_word")+ }++ override suspend fun addBonusWord(word: String): Int {+ val newTotal = viewModel.addBonusWord(word)+ achievementsManager.onProgressUpdated("bonus_hunter", newTotal)+ return newTotal+ }+ }+ }++ WordGameScreen(+ state = WordGameUiState(+ crosswordData = crosswordData,+ currentLevel = currentLevel,+ foundWords = foundWords,+ bonusWords = bonusWords,+ tapToSpell = tapToSpell,+ revealedHints = revealedHints,+ hintCooldownEnd = hintCooldownEnd,+ gameMode = gameMode,+ competitiveScore = competitiveScore,+ competitiveLevelNumber = competitiveLevelNumber,+ competitiveDeadline = competitiveDeadline,+ dailyDay = dailyDay,+ dailyStreak = dailyStreak+ ),+ actions = actions,+ onOpenGameCenter = onOpenGameCenter,+ onOpenSettings = onOpenSettings+ )+}\ No newline at end of file
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameScreen.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameScreen.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameScreen.ktnew file mode 100644index 0000000000..4fc62f0521--- /dev/null+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameScreen.kt@@ -0,0 +1,439 @@+package com.vayunmathur.games.wordmaker.ui++import androidx.compose.animation.core.Animatable+import androidx.compose.animation.core.AnimationVector1D+import androidx.compose.animation.core.tween+import androidx.compose.foundation.clickable+import androidx.compose.foundation.gestures.rememberTransformableState+import androidx.compose.foundation.gestures.transformable+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.Spacer+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.height+import androidx.compose.foundation.layout.offset+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.rememberScrollState+import androidx.compose.foundation.verticalScroll+import androidx.compose.foundation.shape.CircleShape+import androidx.compose.foundation.shape.RoundedCornerShape+import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableFloatStateOf+import androidx.compose.runtime.mutableLongStateOf+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.rememberCoroutineScope+import androidx.compose.runtime.setValue+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.geometry.Offset+import androidx.compose.ui.geometry.lerp+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.graphics.RectangleShape+import androidx.compose.ui.graphics.graphicsLayer+import androidx.compose.ui.layout.onGloballyPositioned+import androidx.compose.ui.platform.LocalDensity+import androidx.compose.ui.res.painterResource+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.text.font.FontWeight+import androidx.compose.ui.unit.IntOffset+import androidx.compose.ui.unit.dp+import androidx.compose.ui.unit.sp+import com.vayunmathur.games.wordmaker.R+import com.vayunmathur.games.wordmaker.data.CrosswordData+import com.vayunmathur.games.wordmaker.data.GameMode+import com.vayunmathur.games.wordmaker.platform.WordGameActions+import com.vayunmathur.games.wordmaker.platform.WordGameUiState+import com.vayunmathur.games.wordmaker.ui.components.AnimatedLetter+import com.vayunmathur.games.wordmaker.ui.components.SurfaceText+import com.vayunmathur.games.wordmaker.ui.components.WordToAnimate+import com.vayunmathur.library.ui.AlertDialog+import com.vayunmathur.library.ui.Button+import com.vayunmathur.library.ui.CircularProgressIndicator+import com.vayunmathur.library.ui.ExperimentalMaterial3Api+import com.vayunmathur.library.ui.FilledIconButton+import com.vayunmathur.library.ui.Icon+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Scaffold+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.util.AchievementsManager+import com.vayunmathur.games.wordmaker.ui.components.CompetitiveStatusBar+import com.vayunmathur.games.wordmaker.ui.components.CrosswordBoard+import com.vayunmathur.games.wordmaker.ui.components.DailyStatusBar+import com.vayunmathur.games.wordmaker.ui.components.LetterChooser+import com.vayunmathur.games.wordmaker.ui.dialogs.BonusWordsDialog+import com.vayunmathur.games.wordmaker.ui.dialogs.DefinitionDialog+import kotlinx.coroutines.delay+import kotlinx.coroutines.joinAll+import kotlinx.coroutines.launch++fun WordGameScreen(+ state: WordGameUiState,+ actions: WordGameActions,+ onOpenGameCenter: () -> Unit,+ onOpenSettings: () -> Unit+) {+ val crosswordData = state.crosswordData+ val currentLevel = state.currentLevel+ val foundWords = state.foundWords+ val bonusWords = state.bonusWords+ val tapToSpell = state.tapToSpell+ val revealedHints = state.revealedHints+ val hintCooldownEnd = state.hintCooldownEnd+ val gameMode = state.gameMode+ val competitiveScore = state.competitiveScore+ val competitiveLevelNumber = state.competitiveLevelNumber+ val competitiveDeadline = state.competitiveDeadline+ val isCompetitive = gameMode == GameMode.COMPETITIVE+ val isDaily = gameMode == GameMode.DAILY+ val levelKey = when (gameMode) {+ GameMode.COMPETITIVE -> "c$competitiveLevelNumber"+ GameMode.DAILY -> "d${state.dailyDay}"+ GameMode.CASUAL -> "n$currentLevel"+ }+ var showBonusWordsDialog by remember(levelKey) { mutableStateOf(false) }+ var showHintDialog by remember(levelKey) { mutableStateOf(false) }+ var remainingCooldown by remember { mutableLongStateOf(0L) }+ var remainingTime by remember(levelKey) { mutableLongStateOf(0L) }+ var timedOut by remember(levelKey) { mutableStateOf(false) }+ val density = LocalDensity.current+ var rootOffset by remember { mutableStateOf(Offset.Zero) }+ var wordWithDefinition by remember { mutableStateOf<Pair<String, List<String>>?>(null) }++ // Animation state+ val coroutineScope = rememberCoroutineScope()+ var animatedWord by remember(levelKey) { mutableStateOf<String?>(null) }+ val animationProgress = remember(levelKey) { Animatable(0f) }+ var wordBoxOffset by remember(levelKey) { mutableStateOf(Offset.Zero) }+ var bonusButtonOffset by remember(levelKey) { mutableStateOf(Offset.Zero) }+ var crosswordCellPositions by remember(levelKey) {+ mutableStateOf<Map<Pair<Int, Int>, Offset>>(+ emptyMap()+ )+ }+ var letterChooserPositions by remember(levelKey) {+ mutableStateOf<Map<Int, Offset>>(+ emptyMap()+ )+ }+ var wordToAnimate by remember(levelKey) { mutableStateOf<WordToAnimate?>(null) }+ var animatedLetters by remember(levelKey) { mutableStateOf<List<AnimatedLetter>>(emptyList()) }++ // Animatables for shaking (we'll animate them directly when submission fails)+ val wordShakeAnim = remember { Animatable(0f) }+ val bonusShakeAnim = remember { Animatable(0f) }++ var scale by remember { mutableFloatStateOf(1f) }+ var shuffledLetters by remember(crosswordData) {+ mutableStateOf(crosswordData.lettersInChooser.mapIndexed { index, char ->+ ChooserLetter(index, char)+ })+ }+++ LaunchedEffect(wordToAnimate) {+ wordToAnimate?.let { animationInfo ->+ val word = animationInfo.word+ val letterPositions = crosswordData.letterPositions[word]?.firstOrNull()+ if (letterPositions != null) {+ val letters = word.mapIndexed { index, char ->+ val id = animationInfo.letterIds[index]+ val start = (letterChooserPositions[id] ?: Offset.Zero) - rootOffset+ val end =+ (crosswordCellPositions[letterPositions[index]] ?: Offset.Zero) - rootOffset++ val offsetCorrection = with(density) { 15.dp.toPx() }+ val correctedStart = start.plus(Offset(offsetCorrection, offsetCorrection))++ AnimatedLetter(char, correctedStart, end, Animatable(0f))+ }+ animatedLetters = letters++ // Animate+ val jobs = letters.map {+ launch {+ it.progress.animateTo(1f, animationSpec = tween(durationMillis = 800))+ }+ }+ jobs.joinAll()++ // After animation+ actions.addFoundWord(word)+ wordToAnimate = null+ animatedLetters = emptyList()+ }+ }+ }++ val isWon = crosswordData.winsWith(foundWords)++ LaunchedEffect(competitiveDeadline, isCompetitive, isWon, levelKey) {+ if (!isCompetitive || isWon || competitiveDeadline <= 0L) {+ if (competitiveDeadline <= 0L && !isWon) remainingTime = 0L+ return@LaunchedEffect+ }+ while (true) {+ remainingTime = (competitiveDeadline - System.currentTimeMillis()).coerceAtLeast(0)+ if (remainingTime <= 0L) break+ delay(200)+ }+ if (!isWon) {+ timedOut = true+ actions.onCompetitiveTimeout()+ }+ }++ LaunchedEffect(hintCooldownEnd) {+ while (true) {+ remainingCooldown = (hintCooldownEnd - System.currentTimeMillis()).coerceAtLeast(0)+ if (remainingCooldown <= 0) break+ delay(100)+ }+ }++ Scaffold(+ Modifier.fillMaxSize(),+ topBar = {+ WordMakerTopBar(+ gameMode = gameMode,+ onModeSelected = { actions.setGameMode(it) },+ onOpenGameCenter = onOpenGameCenter,+ onOpenSettings = onOpenSettings,+ levelNumber = currentLevel+ )+ }+ ) { innerPadding ->+ Box(+ modifier = Modifier+ .padding(innerPadding).padding(bottom = 32.dp)+ .fillMaxSize()+ .onGloballyPositioned {+ rootOffset = it.localToRoot(Offset.Zero)+ }+ ) {+ // Puzzle board fills entire area so it can be dragged under the letter wheel.+ // It is drawn first (behind), so the wheel and buttons appear on top.+ Box(+ modifier = Modifier.fillMaxSize(),+ contentAlignment = Alignment.Center+ ) {+ CrosswordBoard(+ foundWords = foundWords,+ revealedHints = revealedHints,+ crosswordData = crosswordData,+ wordToAnimate = wordToAnimate?.word,+ onCellPositioned = { position, offset ->+ if (crosswordCellPositions[position] != offset) {+ crosswordCellPositions =+ crosswordCellPositions + (position to offset)+ }+ },+ onCellClicked = { row, col ->+ val word = crosswordData.getWordAt(row, col, foundWords)+ if (word != null && word in foundWords) {+ val definition = actions.getDefinition(word)+ if (definition.isNotEmpty()) {+ wordWithDefinition = Pair(word, definition)+ }+ }+ }, {+ scale = it+ }+ )+ }+ Column(+ modifier = Modifier.fillMaxSize(),+ horizontalAlignment = Alignment.CenterHorizontally+ ) {+ if (isCompetitive) {+ CompetitiveStatusBar(+ score = competitiveScore,+ remainingTimeMs = remainingTime+ )+ } else if (isDaily) {+ DailyStatusBar(streak = state.dailyStreak)+ }+ Spacer(modifier = Modifier.weight(1f))+ Box(+ modifier = Modifier.height(320.dp),+ contentAlignment = Alignment.Center+ ) {+ if (isWon && isDaily) {+ Text(+ stringResource(R.string.daily_come_back_tomorrow),+ fontWeight = FontWeight.Bold+ )+ } else if (isWon && !isCompetitive) {+ Button(onClick = { actions.saveLevel(currentLevel + 1) }) {+ Text(stringResource(R.string.next_level))+ }+ } else if (isCompetitive && (isWon || timedOut)) {+ // Level finished ΓÇö the between-levels lobby (WordMakerGameLoader) takes over.+ } else {+ LetterChooser(+ letters = shuffledLetters,+ tapToSpell = tapToSpell,+ onShuffle = {+ var nextLetters = shuffledLetters.shuffled()+ while (nextLetters == shuffledLetters && shuffledLetters.size > 1) {+ nextLetters = shuffledLetters.shuffled()+ }+ shuffledLetters = nextLetters+ },+ onWordSubmitted = { word, ids ->+ suspend fun shakeAnim(anim: Animatable<Float, AnimationVector1D>, duration: Int = 40) {+ for (o in listOf(-16f, 12f, -8f, 6f, -3f, 0f)) {+ anim.animateTo(with(density) { o.dp.toPx() }, tween(duration))+ }+ }++ val isSolution = word in crosswordData.solutionWords+ val isBonus = !isSolution && word.length >= 3 && actions.isInDictionary(word)++ when {+ isSolution && word !in foundWords -> {+ wordToAnimate = WordToAnimate(word, ids)+ actions.onSolutionWordFound(word)+ }+ isBonus && word !in bonusWords -> {+ coroutineScope.launch {+ animatedWord = word+ animationProgress.snapTo(0f)+ animationProgress.animateTo(1f, tween(800))+ actions.addBonusWord(word)+ animatedWord = null+ }+ }+ isBonus && word in bonusWords -> {+ val j = launch { shakeAnim(bonusShakeAnim, 60) }+ shakeAnim(wordShakeAnim)+ j.join()+ }+ else -> shakeAnim(wordShakeAnim)+ }+ },+ onWordBoxPositioned = { wordBoxOffset = it },+ onLetterPositioned = { id, offset ->+ if (letterChooserPositions[id] != offset) {+ letterChooserPositions =+ letterChooserPositions + (id to offset)+ }+ },+ wordShakeTranslation = wordShakeAnim.value+ )+ }+ }+ }++ FilledIconButton(+ onClick = { showBonusWordsDialog = true },+ modifier = Modifier+ .align(Alignment.BottomStart)+ .padding(16.dp)+ .padding(bottom = 32.dp)+ .onGloballyPositioned { bonusButtonOffset = it.localToRoot(Offset.Zero) }+ .graphicsLayer {+ translationX = bonusShakeAnim.value+ },+ enabled = bonusWords.isNotEmpty()+ ) {+ Icon(painterResource(R.drawable.outline_book_2_24), null)+ }++ if (!isWon && !isCompetitive) {+ val hintEnabled = remainingCooldown <= 0L+ Box(+ modifier = Modifier+ .align(Alignment.BottomEnd)+ .padding(16.dp)+ ) {+ FilledIconButton(+ onClick = { showHintDialog = true },+ enabled = hintEnabled+ ) {+ Icon(+ painterResource(android.R.drawable.ic_menu_help),+ contentDescription = stringResource(R.string.cd_hint),+ modifier = Modifier.graphicsLayer { alpha = if (hintEnabled) 1f else 0.5f }+ )+ }+ if (!hintEnabled) {+ CircularProgressIndicator(+ progress = { 1f - (remainingCooldown / 30_000f) },+ modifier = Modifier.size(48.dp).align(Alignment.Center),+ strokeWidth = 3.dp+ )+ }+ }+ }++ if (showHintDialog) {+ AlertDialog(+ onDismissRequest = { showHintDialog = false },+ title = { Text(stringResource(R.string.hint_confirmation)) },+ confirmButton = {+ Button(onClick = {+ actions.revealHint(crosswordData, foundWords, revealedHints)+ showHintDialog = false+ }) {+ Text(stringResource(R.string.yes))+ }+ },+ dismissButton = {+ Button(onClick = { showHintDialog = false }) {+ Text(stringResource(R.string.no))+ }+ }+ )+ }++ if (showBonusWordsDialog) {+ BonusWordsDialog(bonusWords = bonusWords, getDefinition = actions::getDefinition) {+ showBonusWordsDialog = false+ }+ }++ wordWithDefinition?.let { (word, definition) ->+ DefinitionDialog(word, definition) {+ wordWithDefinition = null+ }+ }++ animatedWord?.let { word ->+ val progress = animationProgress.value+ val currentOffset = lerp(wordBoxOffset, bonusButtonOffset, progress)+ val alpha = 1f - progress+ val scale = 1f - (progress * 0.5f)++ Text(+ text = word,+ fontWeight = FontWeight.Bold,+ fontSize = 32.sp,+ modifier = Modifier+ .offset { IntOffset(currentOffset.x.toInt(), currentOffset.y.toInt()) }+ .graphicsLayer(+ scaleX = scale,+ scaleY = scale,+ alpha = alpha+ )+ )+ }+ val (size, fontSize) = Pair(35.dp * scale, 18.sp * scale)+ animatedLetters.forEach { letter ->+ val progress = letter.progress.value+ val offset = lerp(letter.startOffset, letter.endOffset, progress)++ SurfaceText(Modifier.offset { IntOffset(offset.x.toInt(), offset.y.toInt()) },+ RoundedCornerShape(4.dp * scale),+ MaterialTheme.colorScheme.primary, letter.char.toString(),+ Modifier, FontWeight.Bold, fontSize, size,+ textColor = MaterialTheme.colorScheme.onPrimary)+ }+ }+ }+}
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordMakerGameLoader.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordMakerGameLoader.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordMakerGameLoader.ktnew file mode 100644index 0000000000..fbfba40186--- /dev/null+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordMakerGameLoader.kt@@ -0,0 +1,78 @@+package com.vayunmathur.games.wordmaker.ui++import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.material3.CircularProgressIndicator+import androidx.compose.material3.MaterialTheme+import androidx.compose.material3.Text+import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.getValue+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import com.vayunmathur.games.wordmaker.R+import com.vayunmathur.games.wordmaker.Route+import com.vayunmathur.games.wordmaker.data.GameMode+import com.vayunmathur.games.wordmaker.platform.WordMakerViewModel+import com.vayunmathur.games.wordmaker.rememberAchievementsManager+import com.vayunmathur.library.ui.AchievementNotification+import com.vayunmathur.library.util.NavBackStack++fun WordMakerGameLoader(backStack: NavBackStack<Route>, viewModel: WordMakerViewModel) {+ val currentLevel by viewModel.currentLevel.collectAsState()+ val crosswordData by viewModel.crosswordData.collectAsState()+ val error by viewModel.error.collectAsState()+ val gameMode by viewModel.gameMode.collectAsState()+ val competitiveActive by viewModel.competitiveActive.collectAsState()++ val achievementsManager = rememberAchievementsManager(viewModel.levelDataStore)+ if (achievementsManager == null) {+ Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {+ CircularProgressIndicator()+ }+ return+ }+ val newAchievement by achievementsManager.newAchievement.collectAsState()++ LaunchedEffect(Unit) {+ achievementsManager.checkExistingAchievements()+ }++ Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {+ when {+ gameMode == GameMode.COMPETITIVE && !competitiveActive -> {+ CompetitiveLobbyPage(+ viewModel = viewModel,+ onOpenGameCenter = { backStack.add(Route.GameCenter) },+ onOpenSettings = { backStack.add(Route.Settings) }+ )+ }++ error != null -> {+ Text(text = error!!, color = MaterialTheme.colorScheme.error)+ }++ crosswordData != null -> {+ WordGamePage(+ crosswordData = crosswordData!!,+ currentLevel = currentLevel,+ viewModel = viewModel,+ achievementsManager = achievementsManager,+ onOpenGameCenter = { backStack.add(Route.GameCenter) },+ onOpenSettings = { backStack.add(Route.Settings) }+ )+ }++ else -> {+ CircularProgressIndicator()+ }+ }++ newAchievement?.let {+ AchievementNotification(it) {+ achievementsManager.dismissNotification()+ }+ }+ }+}\ No newline at end of file
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/CrosswordBoard.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/CrosswordBoard.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/CrosswordBoard.ktnew file mode 100644index 0000000000..ecc9cf67c8--- /dev/null+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/CrosswordBoard.kt@@ -0,0 +1,140 @@+package com.vayunmathur.games.wordmaker.ui.components++import androidx.compose.foundation.clickable+import androidx.compose.foundation.gestures.rememberTransformableState+import androidx.compose.foundation.gestures.transformable+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.BoxWithConstraints+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.layout.wrapContentSize+import androidx.compose.foundation.shape.RoundedCornerShape+import androidx.compose.material3.MaterialTheme+import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableFloatStateOf+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.geometry.Offset+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.graphics.RectangleShape+import androidx.compose.ui.graphics.graphicsLayer+import androidx.compose.ui.layout.onGloballyPositioned+import androidx.compose.ui.text.font.FontWeight+import androidx.compose.ui.unit.dp+import androidx.compose.ui.unit.sp+import com.vayunmathur.games.wordmaker.data.CrosswordData++fun CrosswordBoard(+ foundWords: Set<String>,+ revealedHints: Set<Pair<Int, Int>>,+ crosswordData: CrosswordData,+ wordToAnimate: String?,+ onCellPositioned: (position: Pair<Int, Int>, offset: Offset) -> Unit,+ onCellClicked: (row: Int, col: Int) -> Unit,+ scaleUpdated: (Float) -> Unit+) {+ val allCharPositions = mutableMapOf<Pair<Int, Int>, Char>()+ crosswordData.letterPositions.forEach { (word, occurrences) ->+ for (positions in occurrences) {+ val isFound = word in foundWords && word != wordToAnimate+ word.forEachIndexed { index, char ->+ val pos = positions[index]+ if (isFound || (pos in revealedHints && pos !in allCharPositions)) {+ allCharPositions[pos] = char+ }+ }+ }+ }+ val (size, fontSize) = Pair(35.dp, 18.sp)++ BoxWithConstraints(+ modifier = Modifier+ .fillMaxSize()+ .clip(RectangleShape)+ ) {+ val numRows = crosswordData.gridStructure.size+ val numCols = if (numRows > 0) crosswordData.gridStructure[0].length else 0++ val boardWidth = 37.dp * numCols+ val boardHeight = 37.dp * numRows++ val initialScale = remember(crosswordData, maxWidth, maxHeight) {+ val scaleX = if (boardWidth.value > 0) maxWidth / boardWidth else 1f+ val scaleY = if (boardHeight.value > 0) maxHeight / boardHeight else 1f+ minOf(scaleX, scaleY, 1f)+ }++ var scale by remember(crosswordData) { mutableFloatStateOf(initialScale) }+ var offset by remember(crosswordData) { mutableStateOf(Offset.Zero) }+ var boxCenter by remember { mutableStateOf(Offset.Zero) }++ // Ensure parent knows the current scale, especially the initial one+ LaunchedEffect(scale) {+ scaleUpdated(scale)+ }++ val state = rememberTransformableState { centroid, zoomChange, offsetChange, _ ->+ scale *= zoomChange+ // Keep the board point under the gesture centroid fixed while zooming.+ // The graphicsLayer lives on the centered child (default centre+ // transformOrigin), so pivot relative to the container centre, then+ // apply the two-finger drag.+ val d = centroid - boxCenter+ offset = d - (d - offset) * zoomChange + offsetChange+ scaleUpdated(scale)+ }++ Box(+ modifier = Modifier+ .fillMaxSize()+ .onGloballyPositioned { boxCenter = Offset(it.size.width / 2f, it.size.height / 2f) }+ .transformable(state = state)+ ) {+ Column(+ modifier = Modifier.align(Alignment.Center)+ .wrapContentSize(align = Alignment.TopStart, unbounded = true)+ .graphicsLayer(+ scaleX = scale,+ scaleY = scale,+ translationX = offset.x,+ translationY = offset.y+ ) // 3. Apply transformations+ ) {+ crosswordData.gridStructure.forEachIndexed { y, rowString ->+ Row {+ rowString.forEachIndexed { x, char ->+ if (char != '.') {+ val letter = allCharPositions[Pair(y, x)]+ SurfaceText(+ Modifier.padding(1.dp)+ .onGloballyPositioned {+ onCellPositioned(Pair(y, x), it.localToRoot(Offset.Zero))+ }.clickable(enabled = letter != null) {+ onCellClicked(y, x)+ },+ RoundedCornerShape(4.dp),+ if (letter != null) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.surfaceVariant,+ letter?.toString() ?: " ",+ Modifier,+ FontWeight.Bold, fontSize, size,+ textColor = if (letter != null) MaterialTheme.colorScheme.onPrimary else Color.Unspecified+ )+ } else {+ Box(Modifier.padding(1.dp).size(size))+ }+ }+ }+ }+ }+ }+ }+}\ No newline at end of file
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/LetterChooser.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/LetterChooser.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/LetterChooser.ktnew file mode 100644index 0000000000..68616bef90--- /dev/null+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/LetterChooser.kt@@ -0,0 +1,243 @@+package com.vayunmathur.games.wordmaker.ui.components++import androidx.compose.animation.core.animateDpAsState+import androidx.compose.foundation.Canvas+import androidx.compose.foundation.clickable+import androidx.compose.foundation.gestures.detectDragGestures+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.Spacer+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.height+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.shape.CircleShape+import androidx.compose.foundation.shape.RoundedCornerShape+import androidx.compose.material3.MaterialTheme+import androidx.compose.material3.Surface+import androidx.compose.material3.Text+import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+import androidx.compose.runtime.key+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.rememberCoroutineScope+import androidx.compose.runtime.setValue+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.geometry.Offset+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.graphics.StrokeCap+import androidx.compose.ui.graphics.graphicsLayer+import androidx.compose.ui.input.pointer.pointerInput+import androidx.compose.ui.layout.onGloballyPositioned+import androidx.compose.ui.platform.LocalDensity+import androidx.compose.ui.res.painterResource+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.text.font.FontWeight+import androidx.compose.ui.unit.IntOffset+import androidx.compose.ui.unit.dp+import androidx.compose.ui.unit.sp+import com.vayunmathur.games.wordmaker.R+import com.vayunmathur.games.wordmaker.ui.ChooserLetter+import kotlinx.coroutines.CoroutineScope+import kotlinx.coroutines.launch+import kotlin.math.atan2+import kotlin.math.cos+import kotlin.math.roundToInt+import kotlin.math.sin++fun LetterChooser(+ letters: List<ChooserLetter>,+ tapToSpell: Boolean,+ onShuffle: () -> Unit,+ onWordSubmitted: suspend CoroutineScope.(String, List<Int>) -> Unit,+ onWordBoxPositioned: (Offset) -> Unit,+ onLetterPositioned: (id: Int, offset: Offset) -> Unit,+ wordShakeTranslation: Float+) {+ val coroutineScope = rememberCoroutineScope()++ var selectedLettersIndices by remember(letters) { mutableStateOf(listOf<Int>()) }+ val formedWord = selectedLettersIndices.map { letters[it].char }.joinToString("")+ var dragStartOffset by remember(letters) { mutableStateOf(Offset.Zero) }+ var currentDragPosition by remember(letters) { mutableStateOf<Offset?>(null) }++ val density = LocalDensity.current+ val letterCircleRadius = with(density) { 35.dp.toPx() }+ val boxSizePx = with(density) { 250.dp.toPx() }+ val boxCenter = Offset(boxSizePx / 2, boxSizePx / 2)++ val angleStep = 2 * Math.PI / letters.size.toDouble()+ val radius = 85.dp+ val radiusPx = with(density) { radius.toPx() }+ val letterCenters = remember(letters, boxCenter, radiusPx) {+ List(letters.size) { index ->+ val angle = angleStep * index - (Math.PI / 2)+ boxCenter + Offset(cos(angle).toFloat() * radiusPx, sin(angle).toFloat() * radiusPx)+ }+ }++ fun getLetterAtArc(position: Offset): Int {+ val relative = position - boxCenter++ val angle = atan2(relative.y, relative.x)+ var normalizedAngle = angle + Math.PI / 2+ while (normalizedAngle < 0) normalizedAngle += 2 * Math.PI+ while (normalizedAngle >= 2 * Math.PI) normalizedAngle -= 2 * Math.PI++ return (normalizedAngle / angleStep).roundToInt() % letters.size+ }++ fun getLetterAtCircle(position: Offset): Int? {+ for (i in letterCenters.indices) {+ val center = letterCenters[i]+ if (distance(position, center) <= letterCircleRadius) {+ return i+ }+ }+ return null+ }++ Column(horizontalAlignment = Alignment.CenterHorizontally) {+ SurfaceText(+ Modifier+ .padding(bottom = 20.dp)+ .graphicsLayer(+ alpha = if (selectedLettersIndices.isNotEmpty()) 1f else 0f,+ translationX = wordShakeTranslation+ ),+ RoundedCornerShape(8.dp), MaterialTheme.colorScheme.primaryContainer,+ formedWord.ifEmpty { " " },+ Modifier+ .padding(horizontal = 16.dp, vertical = 12.dp)+ .onGloballyPositioned { onWordBoxPositioned(it.localToRoot(Offset.Zero)) },+ FontWeight.Bold,+ 32.sp,+ null+ )++ Row(verticalAlignment = Alignment.Top) {+ Column(+ modifier = Modifier.width(72.dp),+ horizontalAlignment = Alignment.CenterHorizontally+ ) {+ if (tapToSpell && selectedLettersIndices.isNotEmpty()) {+ FilledIconButton(onClick = {+ selectedLettersIndices = selectedLettersIndices.dropLast(1)+ }) {+ Icon(painterResource(R.drawable.backspace_24px), contentDescription = stringResource(R.string.cd_backspace))+ }+ Spacer(modifier = Modifier.height(8.dp))+ FilledIconButton(onClick = {+ if (selectedLettersIndices.isNotEmpty()) {+ val word = selectedLettersIndices.map { letters[it].char }.joinToString("")+ val ids = selectedLettersIndices.map { letters[it].id }+ coroutineScope.launch {+ onWordSubmitted(word, ids)+ selectedLettersIndices = emptyList()+ }+ }+ }) {+ Icon(painterResource(R.drawable.keyboard_return_24px), contentDescription = stringResource(R.string.cd_submit))+ }+ }+ }+ Box(+ modifier = Modifier+ .size(250.dp)+ .onGloballyPositioned {+ dragStartOffset = it.localToRoot(Offset.Zero)+ }+ .pointerInput(letters) {+ detectDragGestures(+ onDragStart = { startOffset ->+ currentDragPosition = startOffset+ selectedLettersIndices = listOf(getLetterAtArc(startOffset))+ },+ onDrag = { change, _ ->+ currentDragPosition = change.position+ getLetterAtCircle(change.position)?.let { idx ->+ if (idx !in selectedLettersIndices) {+ selectedLettersIndices = selectedLettersIndices + idx+ } else if (selectedLettersIndices.size > 1 && idx == selectedLettersIndices[selectedLettersIndices.size - 2]) {+ selectedLettersIndices = selectedLettersIndices.dropLast(1)+ }+ }+ },+ onDragEnd = {+ coroutineScope.launch {+ if (selectedLettersIndices.isNotEmpty()) {+ onWordSubmitted(+ selectedLettersIndices.map { letters[it].char }.joinToString(""),+ selectedLettersIndices.map { letters[it].id }+ )+ }+ selectedLettersIndices = emptyList()+ currentDragPosition = null+ }+ }+ )+ },+ contentAlignment = Alignment.Center+ ) {+ val primaryColor = MaterialTheme.colorScheme.primary+ Canvas(modifier = Modifier.fillMaxSize()) {+ selectedLettersIndices.zipWithNext { a, b ->+ drawLine(primaryColor, letterCenters[a], letterCenters[b], 10f, cap = StrokeCap.Round)+ }+ val lastLetter = selectedLettersIndices.lastOrNull()+ if (lastLetter != null && currentDragPosition != null) {+ drawLine(primaryColor, letterCenters[lastLetter], currentDragPosition!!, 10f, cap = StrokeCap.Round)+ }+ }+ Surface(+ Modifier.fillMaxSize(0.9f),+ CircleShape,+ MaterialTheme.colorScheme.secondaryContainer.copy(alpha = 0.5f)+ ) {}++ letters.forEachIndexed { index, chooserLetter ->+ key(chooserLetter.id) {+ val angle = angleStep * index - (Math.PI / 2)+ val targetX = (cos(angle) * radius.value).dp+ val targetY = (sin(angle) * radius.value).dp++ val x by animateDpAsState(targetX, label = "x")+ val y by animateDpAsState(targetY, label = "y")++ SurfaceText(Modifier+ .align(Alignment.Center)+ .offset { IntOffset(x.roundToPx(), y.roundToPx()) }+ .onGloballyPositioned { coordinates ->+ onLetterPositioned(chooserLetter.id, coordinates.localToRoot(Offset.Zero))+ }+ .then(if (tapToSpell) Modifier.clickable {+ if (selectedLettersIndices.lastOrNull() == index) {+ selectedLettersIndices = selectedLettersIndices.dropLast(1)+ } else if (index !in selectedLettersIndices) {+ selectedLettersIndices = selectedLettersIndices + index+ }+ } else Modifier),+ CircleShape,+ if (index in selectedLettersIndices) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.secondary,+ chooserLetter.char.toString(),+ Modifier.padding(1.dp),+ FontWeight.Bold,+ 42.sp,+ 70.dp+ )+ }+ }+ }+ FilledIconButton(onClick = onShuffle) {+ Icon(painterResource(R.drawable.ic_shuffle), contentDescription = stringResource(R.string.cd_shuffle))+ }+ }+ }+}++private fun distance(a: Offset, b: Offset): Float = (a - b).getDistance()\ No newline at end of file
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/WordComponents.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/WordComponents.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/WordComponents.ktnew file mode 100644index 0000000000..37ab6be8c6--- /dev/null+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/WordComponents.kt@@ -0,0 +1,41 @@+package com.vayunmathur.games.wordmaker.ui.components++import androidx.compose.animation.core.Animatable+import androidx.compose.animation.core.AnimationVector1D+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.shape.RoundedCornerShape+import androidx.compose.material3.MaterialTheme+import androidx.compose.material3.Surface+import androidx.compose.material3.Text+import androidx.compose.runtime.Composable+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.geometry.Offset+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.graphics.Shape+import androidx.compose.ui.text.font.FontWeight+import androidx.compose.ui.unit.Dp+import androidx.compose.ui.unit.TextUnit+import androidx.compose.ui.unit.dp+import androidx.compose.ui.unit.sp++data class AnimatedLetter(+ val char: Char,+ val startOffset: Offset,+ val endOffset: Offset,+ val progress: Animatable<Float, AnimationVector1D>+)++data class WordToAnimate(val word: String, val letterIds: List<Int>)+++fun SurfaceText(modifier: Modifier, surfaceShape: Shape, surfaceColor: Color, text: String, textModifier: Modifier, fontWeight: FontWeight? = null, fontSize: TextUnit = TextUnit.Unspecified, surfaceSize: Dp?, textColor: Color = Color.Unspecified) {+ val modifier2 = if(surfaceSize != null) modifier.size(surfaceSize) else modifier+ Surface(modifier2, surfaceShape, surfaceColor) {+ Box(if(surfaceSize == null) Modifier else Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {+ Text(text, textModifier, color = textColor, fontWeight = fontWeight, fontSize = fontSize)+ }+ }+}\ No newline at end of file
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/WordMakerTopBar.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/WordMakerTopBar.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/WordMakerTopBar.ktnew file mode 100644index 0000000000..11efdbd1f9--- /dev/null+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/WordMakerTopBar.kt@@ -0,0 +1,166 @@+package com.vayunmathur.games.wordmaker.ui.components++import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.Spacer+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.material3.MaterialTheme+import androidx.compose.material3.Text+import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+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.res.painterResource+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.text.font.FontWeight+import androidx.compose.ui.unit.dp+import androidx.compose.ui.unit.sp+import com.vayunmathur.games.wordmaker.R+import com.vayunmathur.games.wordmaker.data.Difficulty+import com.vayunmathur.games.wordmaker.data.GameMode+import com.vayunmathur.library.ui.CenterAlignedTopAppBar+import com.vayunmathur.library.ui.DropdownMenu+import com.vayunmathur.library.ui.DropdownMenuItem+import com.vayunmathur.library.ui.ExperimentalMaterial3Api+import com.vayunmathur.library.ui.Icon+import com.vayunmathur.library.ui.IconButton+import com.vayunmathur.library.ui.IconSettings+import com.vayunmathur.library.ui.TextButton++fun GameModeDropdown(selected: GameMode, onSelected: (GameMode) -> Unit) {+ var expanded by remember { mutableStateOf(false) }+ Box {+ TextButton(onClick = { expanded = true }) {+ Text(stringResource(gameModeLabel(selected)), fontWeight = FontWeight.Bold)+ Text(" Γû╛", fontWeight = FontWeight.Bold)+ }+ DropdownMenu(expanded = expanded, onDismissRequest = { expanded = false }) {+ GameMode.entries.forEach { mode ->+ DropdownMenuItem(+ text = { Text(stringResource(gameModeLabel(mode))) },+ onClick = {+ expanded = false+ onSelected(mode)+ }+ )+ }+ }+ }+}++private fun gameModeLabel(mode: GameMode) = when (mode) {+ GameMode.CASUAL -> R.string.mode_casual+ GameMode.COMPETITIVE -> R.string.mode_competitive+ GameMode.DAILY -> R.string.mode_daily+}+++private fun gameModeLabel(mode: GameMode) = when (mode) {+ GameMode.CASUAL -> R.string.mode_casual+ GameMode.COMPETITIVE -> R.string.mode_competitive+ GameMode.DAILY -> R.string.mode_daily+}++@Composable+fun DailyStatusBar(streak: Long) {+ Row(+ modifier = Modifier+ .fillMaxWidth()+ .padding(horizontal = 16.dp, vertical = 4.dp),+ verticalAlignment = Alignment.CenterVertically+ ) {+ Text(stringResource(R.string.daily_challenge), fontWeight = FontWeight.Bold)+ Spacer(Modifier.weight(1f))+ Text(stringResource(R.string.daily_streak, streak.toInt()))+ }+}+++fun DifficultyDropdown(selected: Difficulty, onSelected: (Difficulty) -> Unit) {+ var expanded by remember { mutableStateOf(false) }+ fun label(d: Difficulty) = when (d) {+ Difficulty.EASY -> R.string.difficulty_easy+ Difficulty.MEDIUM -> R.string.difficulty_medium+ Difficulty.HARD -> R.string.difficulty_hard+ }+ Box {+ TextButton(onClick = { expanded = true }) {+ Text(stringResource(label(selected)))+ Text(" Γû╛")+ }+ DropdownMenu(expanded = expanded, onDismissRequest = { expanded = false }) {+ Difficulty.values().forEach { d ->+ DropdownMenuItem(+ text = { Text(stringResource(label(d))) },+ onClick = {+ expanded = false+ onSelected(d)+ }+ )+ }+ }+ }+}++@OptIn(ExperimentalMaterial3Api::class)+@Composable++fun WordMakerTopBar(+ gameMode: GameMode,+ onModeSelected: (GameMode) -> Unit,+ onOpenGameCenter: () -> Unit,+ onOpenSettings: () -> Unit,+ levelNumber: Int? = null+) {+ CenterAlignedTopAppBar(+ title = {+ if (gameMode == GameMode.CASUAL && levelNumber != null) {+ Text(+ text = stringResource(R.string.level_number, levelNumber),+ fontWeight = FontWeight.Bold+ )+ }+ },+ navigationIcon = {+ GameModeDropdown(selected = gameMode, onSelected = onModeSelected)+ },+ actions = {+ IconButton(onClick = onOpenGameCenter) {+ Icon(painterResource(id = android.R.drawable.btn_star_big_on), "Achievements")+ }+ IconButton(onClick = onOpenSettings) {+ IconSettings()+ }+ }+ )+}+++fun CompetitiveStatusBar(+ score: Int,+ remainingTimeMs: Long+) {+ val totalSeconds = (remainingTimeMs / 1000L).toInt()+ val minutes = totalSeconds / 60+ val seconds = totalSeconds % 60+ val timeColor = if (totalSeconds <= 10) MaterialTheme.colorScheme.error else MaterialTheme.colorScheme.onSurface+ Row(+ modifier = Modifier+ .fillMaxWidth()+ .padding(horizontal = 16.dp, vertical = 4.dp),+ verticalAlignment = Alignment.CenterVertically+ ) {+ Text(stringResource(R.string.competitive_score, score))+ Spacer(Modifier.weight(1f))+ Text(+ text = "%d:%02d".format(minutes, seconds),+ fontWeight = FontWeight.Bold,+ fontSize = 20.sp,+ color = timeColor+ )+ }+}
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/dialogs/WordDialogs.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/dialogs/WordDialogs.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/dialogs/WordDialogs.ktnew file mode 100644index 0000000000..d269049285--- /dev/null+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/dialogs/WordDialogs.kt@@ -0,0 +1,79 @@+package com.vayunmathur.games.wordmaker.ui.dialogs++import androidx.compose.foundation.clickable+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.lazy.LazyColumn+import androidx.compose.foundation.lazy.items+import androidx.compose.foundation.rememberScrollState+import androidx.compose.foundation.verticalScroll+import androidx.compose.material3.Text+import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.compose.ui.Modifier+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.unit.dp+import com.vayunmathur.games.wordmaker.R+import com.vayunmathur.library.ui.AlertDialog+import com.vayunmathur.library.ui.Button+import com.vayunmathur.library.ui.R as UiR++fun DefinitionDialog(word: String, definition: List<String>, onDismiss: () -> Unit) {+ AlertDialog(+ onDismissRequest = onDismiss,+ title = { Text(text = word.replaceFirstChar { it.uppercase() }) },+ text = {+ Column(modifier = Modifier.verticalScroll(rememberScrollState())) {+ Text(text = definition.joinToString("\n\n"))+ }+ },+ confirmButton = {+ Button(onClick = onDismiss) {+ Text(stringResource(UiR.string.close))+ }+ }+ )+}+++fun BonusWordsDialog(+ bonusWords: Set<String>,+ getDefinition: (String) -> List<String>,+ onDismiss: () -> Unit+) {+ var definitionDialog by remember { mutableStateOf<Pair<String, List<String>>?>(null) }+ AlertDialog(+ onDismissRequest = onDismiss,+ title = { Text(text = stringResource(R.string.bonus_words)) },+ text = {+ LazyColumn(modifier = Modifier.fillMaxWidth()) {+ items(bonusWords.toList().sorted()) { word ->+ Text(+ text = word,+ modifier = Modifier+ .padding(vertical = 4.dp)+ .fillMaxWidth()+ .clickable {+ definitionDialog = Pair(word, getDefinition(word))+ })+ }+ }+ },+ confirmButton = {+ Button(+ onClick = onDismiss+ ) {+ Text(stringResource(UiR.string.close))+ }+ }+ )+ definitionDialog?.let { (w, d) ->+ DefinitionDialog(word = w, definition = d) {+ definitionDialog = null+ }+ }+}