diff --git a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/App.kt b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/App.kt index aada2bd..e3f0e95 100644 --- a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/App.kt +++ b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/App.kt @@ -34,11 +34,13 @@ import com.pixelized.desktop.lwa.navigation.screen.destination.CharacterSheetDes import com.pixelized.desktop.lwa.navigation.screen.destination.CharacterSheetEditDestination import com.pixelized.desktop.lwa.navigation.window.WindowController import com.pixelized.desktop.lwa.navigation.window.WindowsNavHost -import com.pixelized.desktop.lwa.navigation.window.destination.CharacterSheetCreateWindow +import com.pixelized.desktop.lwa.navigation.window.destination.CharacterSheetEditWindow import com.pixelized.desktop.lwa.navigation.window.destination.CharacterSheetWindow +import com.pixelized.desktop.lwa.navigation.window.destination.RollHistoryWindow import com.pixelized.desktop.lwa.repository.network.NetworkRepository import com.pixelized.desktop.lwa.repository.network.NetworkRepository.Status import com.pixelized.desktop.lwa.screen.characterSheet.CharacterSheetMainNavHost +import com.pixelized.desktop.lwa.screen.rollhistory.RollHistoryPage import com.pixelized.desktop.lwa.theme.LwaTheme import kotlinx.coroutines.launch import lwacharactersheet.composeapp.generated.resources.Res @@ -141,11 +143,13 @@ private fun WindowsHandler( ), ) - is CharacterSheetCreateWindow -> CharacterSheetMainNavHost( + is CharacterSheetEditWindow -> CharacterSheetMainNavHost( startDestination = CharacterSheetEditDestination.navigationRoute( id = window.sheetId, ), ) + + is RollHistoryWindow -> RollHistoryPage() } } ) diff --git a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/navigation/screen/MainNavHost.kt b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/navigation/screen/MainNavHost.kt index 90a8c28..a0f2ec7 100644 --- a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/navigation/screen/MainNavHost.kt +++ b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/navigation/screen/MainNavHost.kt @@ -9,7 +9,6 @@ import androidx.navigation.compose.rememberNavController import com.pixelized.desktop.lwa.navigation.screen.destination.MainDestination import com.pixelized.desktop.lwa.navigation.screen.destination.composableMainPage import com.pixelized.desktop.lwa.navigation.screen.destination.composableNetworkPage -import com.pixelized.desktop.lwa.navigation.screen.destination.composableRollHistory val LocalScreenController = compositionLocalOf { error("MainNavHost controller is not yet ready") @@ -29,7 +28,6 @@ fun MainNavHost( ) { composableMainPage() composableNetworkPage() - composableRollHistory() } } } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/navigation/screen/destination/RollHistoryDestination.kt b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/navigation/screen/destination/RollHistoryDestination.kt deleted file mode 100644 index d7d795b..0000000 --- a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/navigation/screen/destination/RollHistoryDestination.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.pixelized.desktop.lwa.navigation.screen.destination - -import androidx.navigation.NavGraphBuilder -import androidx.navigation.NavHostController -import androidx.navigation.compose.composable -import com.pixelized.desktop.lwa.screen.rollhistory.RollHistoryPage - -object RollHistoryDestination { - private const val ROUTE = "roll_history" - - fun baseRoute() = ROUTE - fun navigationRoute() = ROUTE -} - -fun NavGraphBuilder.composableRollHistory() { - composable( - route = RollHistoryDestination.baseRoute() - ) { - RollHistoryPage() - } -} - -fun NavHostController.navigateToRollHistory() { - val route = RollHistoryDestination.navigationRoute() - navigate(route = route) -} \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/navigation/window/destination/CharacterSheetCreateWindow.kt b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/navigation/window/destination/CharacterSheetEditWindow.kt similarity index 51% rename from composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/navigation/window/destination/CharacterSheetCreateWindow.kt rename to composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/navigation/window/destination/CharacterSheetEditWindow.kt index 4c0fe67..9edafd6 100644 --- a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/navigation/window/destination/CharacterSheetCreateWindow.kt +++ b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/navigation/window/destination/CharacterSheetEditWindow.kt @@ -3,9 +3,10 @@ package com.pixelized.desktop.lwa.navigation.window.destination import androidx.compose.runtime.Stable import androidx.compose.ui.unit.DpSize import androidx.compose.ui.unit.dp +import com.pixelized.desktop.lwa.navigation.window.WindowController @Stable -class CharacterSheetCreateWindow( +class CharacterSheetEditWindow( title: String, val sheetId: String?, ) : Window( @@ -15,4 +16,16 @@ class CharacterSheetCreateWindow( companion object { val size = DpSize(600.dp, 900.dp) } +} + +fun WindowController.navigateToCharacterSheetEdit( + title: String, + characterId: String?, +) { + showWindow( + window = CharacterSheetEditWindow( + title = title, + sheetId = characterId, + ) + ) } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/navigation/window/destination/CharacterSheetWindow.kt b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/navigation/window/destination/CharacterSheetWindow.kt index e841a92..7cc4e17 100644 --- a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/navigation/window/destination/CharacterSheetWindow.kt +++ b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/navigation/window/destination/CharacterSheetWindow.kt @@ -3,13 +3,14 @@ package com.pixelized.desktop.lwa.navigation.window.destination import androidx.compose.runtime.Stable import androidx.compose.ui.unit.DpSize import androidx.compose.ui.unit.dp +import com.pixelized.desktop.lwa.navigation.window.WindowController @Stable class CharacterSheetWindow( + title: String, val characterId: String, - characterName: String, ) : Window( - title = characterName, + title = title, size = size, ) { companion object { @@ -20,3 +21,14 @@ class CharacterSheetWindow( } } +fun WindowController.navigateToCharacterSheet( + title: String, + characterId: String, +) { + showWindow( + window = CharacterSheetWindow( + title = title, + characterId = characterId, + ) + ) +} \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/navigation/window/destination/RollHistoryWindow.kt b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/navigation/window/destination/RollHistoryWindow.kt new file mode 100644 index 0000000..ea9e41d --- /dev/null +++ b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/navigation/window/destination/RollHistoryWindow.kt @@ -0,0 +1,21 @@ +package com.pixelized.desktop.lwa.navigation.window.destination + +import androidx.compose.ui.unit.DpSize +import androidx.compose.ui.unit.dp +import com.pixelized.desktop.lwa.navigation.window.WindowController + +class RollHistoryWindow: Window( + title = "", + size = size, +) { + companion object { + val size = DpSize( + width = 400.dp + 64.dp, + height = 900.dp, + ) + } +} + +fun WindowController.navigateToRollHistory() { + showWindow(window = RollHistoryWindow()) +} \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/screen/characterSheet/detail/CharacterSheetPage.kt b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/screen/characterSheet/detail/CharacterSheetPage.kt index 42badb3..9519b2e 100644 --- a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/screen/characterSheet/detail/CharacterSheetPage.kt +++ b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/screen/characterSheet/detail/CharacterSheetPage.kt @@ -61,7 +61,7 @@ import com.pixelized.desktop.lwa.composable.tooltip.TooltipLayout import com.pixelized.desktop.lwa.composable.tooltip.TooltipUio import com.pixelized.desktop.lwa.navigation.screen.LocalScreenController import com.pixelized.desktop.lwa.navigation.window.LocalWindow -import com.pixelized.desktop.lwa.navigation.window.destination.CharacterSheetCreateWindow +import com.pixelized.desktop.lwa.navigation.window.destination.navigateToCharacterSheetEdit import com.pixelized.desktop.lwa.screen.characterSheet.detail.dialog.CharacterSheetDeleteConfirmationDialog import com.pixelized.desktop.lwa.screen.characterSheet.detail.dialog.CharacterSheetStatDialog import com.pixelized.desktop.lwa.screen.characterSheet.detail.dialog.DiminishedStatDialog @@ -148,11 +148,9 @@ fun CharacterSheetPage( } }, onEdit = { - windowController.showWindow( - window = CharacterSheetCreateWindow( - title = runBlocking { getString(Res.string.character_sheet_edit__edit__title) }, - sheetId = sheet.id, - ), + windowController.navigateToCharacterSheetEdit( + title = runBlocking { getString(Res.string.character_sheet_edit__edit__title) }, + characterId = sheet.id, ) }, onDelete = { diff --git a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/screen/main/MainPage.kt b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/screen/main/MainPage.kt index c472bc3..210d9e6 100644 --- a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/screen/main/MainPage.kt +++ b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/screen/main/MainPage.kt @@ -26,9 +26,9 @@ import androidx.compose.ui.unit.dp import com.pixelized.desktop.lwa.LocalWindowController import com.pixelized.desktop.lwa.navigation.screen.LocalScreenController import com.pixelized.desktop.lwa.navigation.screen.destination.navigateToNetwork -import com.pixelized.desktop.lwa.navigation.screen.destination.navigateToRollHistory -import com.pixelized.desktop.lwa.navigation.window.destination.CharacterSheetCreateWindow -import com.pixelized.desktop.lwa.navigation.window.destination.CharacterSheetWindow +import com.pixelized.desktop.lwa.navigation.window.destination.navigateToCharacterSheet +import com.pixelized.desktop.lwa.navigation.window.destination.navigateToCharacterSheetEdit +import com.pixelized.desktop.lwa.navigation.window.destination.navigateToRollHistory import kotlinx.coroutines.runBlocking import lwacharactersheet.composeapp.generated.resources.Res import lwacharactersheet.composeapp.generated.resources.character_sheet_edit__create__title @@ -70,24 +70,21 @@ fun MainPage( ) { MainPageContent( characters = viewModel.characters, + enableRollHistory = viewModel.enableRollHistory, onCharacter = { - window.showWindow( - window = CharacterSheetWindow( - characterId = it.id, - characterName = it.name, - ) + window.navigateToCharacterSheet( + characterId = it.id, + title = it.name, ) }, onCreateCharacter = { - window.showWindow( - window = CharacterSheetCreateWindow( - title = runBlocking { getString(Res.string.character_sheet_edit__create__title) }, - sheetId = null, - ) + window.navigateToCharacterSheetEdit( + title = runBlocking { getString(Res.string.character_sheet_edit__create__title) }, + characterId = null, ) }, onRollHistory = { - screen.navigateToRollHistory() + window.navigateToRollHistory() }, onOpenSaveDirectory = { viewModel.openSaveDirectory() @@ -104,6 +101,7 @@ fun MainPage( fun MainPageContent( modifier: Modifier = Modifier, characters: State>, + enableRollHistory: State, onCharacter: (CharacterUio) -> Unit, onCreateCharacter: () -> Unit, onRollHistory: () -> Unit, @@ -173,6 +171,7 @@ fun MainPageContent( } TextButton( + enabled = enableRollHistory.value, onClick = onRollHistory, ) { Row( diff --git a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/screen/main/MainPageViewModel.kt b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/screen/main/MainPageViewModel.kt index 8e1c3f7..d88cb67 100644 --- a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/screen/main/MainPageViewModel.kt +++ b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/screen/main/MainPageViewModel.kt @@ -1,31 +1,36 @@ package com.pixelized.desktop.lwa.screen.main import androidx.compose.runtime.Composable -import androidx.compose.runtime.Stable import androidx.compose.runtime.State import androidx.lifecycle.ViewModel import com.lordcodes.turtle.shellRun import com.pixelized.desktop.lwa.repository.OperatingSystem import com.pixelized.desktop.lwa.repository.characterSheet.CharacterSheetRepository +import com.pixelized.desktop.lwa.repository.network.NetworkRepository import com.pixelized.desktop.lwa.repository.storePath import com.pixelized.desktop.lwa.utils.extention.collectAsState class MainPageViewModel( - private val repository: CharacterSheetRepository + repository: CharacterSheetRepository, + networkRepository: NetworkRepository, ) : ViewModel() { + + private val charactersFlow = repository.characterSheetFlow() val characters: State> @Composable - @Stable - get() = repository - .characterSheetFlow() - .collectAsState { sheets -> - sheets.map { sheet -> - CharacterUio( - id = sheet.id, - name = sheet.name, - ) - } + get() = charactersFlow.collectAsState { sheets -> + sheets.map { sheet -> + CharacterUio( + id = sheet.id, + name = sheet.name, + ) } + } + + private val networkStatus = networkRepository.status + val enableRollHistory: State + @Composable + get() = networkStatus.collectAsState { it == NetworkRepository.Status.CONNECTED } fun openSaveDirectory( os: OperatingSystem = OperatingSystem.current diff --git a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/screen/rollhistory/RollHistoryItem.kt b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/screen/rollhistory/RollHistoryItem.kt index 6057e5e..0c822b8 100644 --- a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/screen/rollhistory/RollHistoryItem.kt +++ b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/screen/rollhistory/RollHistoryItem.kt @@ -48,11 +48,15 @@ fun RollHistoryItem( modifier = Modifier.alignByBaseline(), style = MaterialTheme.typography.body1, fontWeight = FontWeight.Bold, + overflow = TextOverflow.Ellipsis, + maxLines = 1, text = roll.from, ) Text( modifier = Modifier.alignByBaseline(), style = MaterialTheme.typography.caption, + overflow = TextOverflow.Ellipsis, + maxLines = 1, text = stringResource(Res.string.roll_history__item__throw), ) Text( @@ -69,14 +73,20 @@ fun RollHistoryItem( roll.rollDifficulty?.let { Text( style = MaterialTheme.typography.caption, + overflow = TextOverflow.Ellipsis, + maxLines = 1, text = stringResource(Res.string.roll_history__item__difficulty), ) Text( style = MaterialTheme.typography.caption, + overflow = TextOverflow.Ellipsis, + maxLines = 1, text = it, ) Text( style = MaterialTheme.typography.caption, + overflow = TextOverflow.Ellipsis, + maxLines = 1, text = "-", ) } @@ -84,6 +94,8 @@ fun RollHistoryItem( Text( style = MaterialTheme.typography.caption, fontWeight = FontWeight.Bold, + overflow = TextOverflow.Ellipsis, + maxLines = 1, text = it, ) } @@ -96,6 +108,8 @@ fun RollHistoryItem( modifier = Modifier.alignByBaseline(), style = MaterialTheme.typography.h5, fontWeight = FontWeight.Bold, + overflow = TextOverflow.Ellipsis, + maxLines = 1, text = "${roll.rollValue}", ) roll.rollSuccessLimit?.let { @@ -103,6 +117,8 @@ fun RollHistoryItem( modifier = Modifier.alignByBaseline(), style = MaterialTheme.typography.caption, fontWeight = FontWeight.Light, + overflow = TextOverflow.Ellipsis, + maxLines = 1, text = "/ $it", ) } diff --git a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/screen/rollhistory/RollHistoryPage.kt b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/screen/rollhistory/RollHistoryPage.kt index 9bbe8fe..9e375bf 100644 --- a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/screen/rollhistory/RollHistoryPage.kt +++ b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/screen/rollhistory/RollHistoryPage.kt @@ -7,43 +7,31 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.rememberLazyListState -import androidx.compose.material.Icon -import androidx.compose.material.IconButton import androidx.compose.material.Scaffold import androidx.compose.material.Surface import androidx.compose.material.Text import androidx.compose.material.TopAppBar -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.automirrored.filled.ArrowBack import androidx.compose.runtime.Composable import androidx.compose.runtime.State import androidx.compose.ui.Modifier import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp -import com.pixelized.desktop.lwa.navigation.screen.LocalScreenController import lwacharactersheet.composeapp.generated.resources.Res import lwacharactersheet.composeapp.generated.resources.roll_history__title import org.jetbrains.compose.resources.stringResource import org.koin.compose.viewmodel.koinViewModel -import org.koin.core.annotation.KoinExperimentalAPI -@OptIn(KoinExperimentalAPI::class) @Composable fun RollHistoryPage( viewModel: RollHistoryViewModel = koinViewModel(), ) { - val screen = LocalScreenController.current - Surface( modifier = Modifier.fillMaxSize(), ) { RollHistoryContent( modifier = Modifier.fillMaxSize(), rolls = viewModel.rolls, - onBack = { - screen.popBackStack() - }, ) } } @@ -52,7 +40,6 @@ fun RollHistoryPage( private fun RollHistoryContent( modifier: Modifier = Modifier, rolls: State>, - onBack: () -> Unit, ) { Scaffold( modifier = modifier, @@ -65,16 +52,6 @@ private fun RollHistoryContent( text = stringResource(Res.string.roll_history__title), ) }, - navigationIcon = { - IconButton( - onClick = onBack, - ) { - Icon( - imageVector = Icons.AutoMirrored.Filled.ArrowBack, - contentDescription = null, - ) - } - } ) }, content = {