From 70eb0d6bc03d3041b2d3b83e87aa5377a0b786b6 Mon Sep 17 00:00:00 2001 From: Boy Date: Sun, 25 Dec 2022 12:01:39 +0100 Subject: [PATCH 1/8] wynntils merge --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 5d4dcf3..34e88bb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -86,7 +86,7 @@ compose.desktop { } } -val linuxAppDir = project.file("packaging/appimage/Mine in Abyss.AppDir") +val linuxAppDir = project.file("packaging/appimage/Wynntils.AppDir") val appImageTool = project.file("deps/appimagetool.AppImage") val composePackageDir = "$buildDir/compose/binaries/main/${ when { From 8657c96188db274ed7b7dda260bb1140f2c17147 Mon Sep 17 00:00:00 2001 From: Boy Date: Sun, 25 Dec 2022 17:17:42 +0100 Subject: [PATCH 2/8] basic textfield account details and ram slider --- gradle/wrapper/gradle-wrapper.properties | 2 +- .../com/mineinabyss/launchy/data/Config.kt | 2 + .../launchy/logic/FabricInstaller.kt | 63 +++++----- .../mineinabyss/launchy/logic/LaunchyState.kt | 19 ++- .../mineinabyss/launchy/ui/screens/Screens.kt | 16 ++- .../ui/screens/main/ImportSettingsDialog.kt | 6 +- .../launchy/ui/screens/main/MainScreen.kt | 7 +- .../ui/screens/main/buttons/AccountButton.kt | 18 +++ .../{SettingsButton.kt => ModsButton.kt} | 8 +- .../ui/screens/main/buttons/NewsButton.kt | 2 +- .../ui/screens/settings/AccountScreen.kt | 113 ++++++++++++++++++ .../{SettingsScreen.kt => ModsScreen.kt} | 2 +- .../ui/screens/settings/SettingGroup.kt | 68 +++++++++++ .../ui/screens/settings/SliderSwitch.kt | 53 ++++++++ 14 files changed, 330 insertions(+), 49 deletions(-) create mode 100644 src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/AccountButton.kt rename src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/{SettingsButton.kt => ModsButton.kt} (71%) create mode 100644 src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/AccountScreen.kt rename src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/{SettingsScreen.kt => ModsScreen.kt} (98%) create mode 100644 src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/SettingGroup.kt create mode 100644 src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/SliderSwitch.kt diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e750102..ae04661 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/kotlin/com/mineinabyss/launchy/data/Config.kt b/src/main/kotlin/com/mineinabyss/launchy/data/Config.kt index 607783c..e11b927 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/data/Config.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/data/Config.kt @@ -1,5 +1,6 @@ package com.mineinabyss.launchy.data +import com.mineinabyss.launchy.ui.screens.settings.ClientSettings import kotlinx.serialization.Serializable import kotlinx.serialization.encodeToString import java.io.* @@ -11,6 +12,7 @@ import kotlin.io.path.writeText @Serializable data class Config( val minecraftDir: String? = null, + val clientSettings: ClientSettings = ClientSettings(2), val fullEnabledGroups: Set = setOf(), val fullDisabledGroups: Set = setOf(), val toggledMods: Set = setOf(), diff --git a/src/main/kotlin/com/mineinabyss/launchy/logic/FabricInstaller.kt b/src/main/kotlin/com/mineinabyss/launchy/logic/FabricInstaller.kt index 8463e96..7400b88 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/logic/FabricInstaller.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/logic/FabricInstaller.kt @@ -8,7 +8,7 @@ package com.mineinabyss.launchy.logic import mjson.Json import mjson.Json.read -import net.fabricmc.installer.client.ProfileInstaller +import net.fabricmc.installer.client.ProfileInstaller.LauncherType import net.fabricmc.installer.util.Reference import net.fabricmc.installer.util.Utils import org.json.JSONObject @@ -36,13 +36,13 @@ object FabricInstaller { gameVersion: String, loaderName: String, loaderVersion: String, + launchyState: LaunchyState ): Boolean { val versionId = String.format("%s-%s-%s", loaderName, loaderVersion, gameVersion) - val launcherType: ProfileInstaller.LauncherType = (if (System.getProperty("os.name") - .contains("Windows") - ) getLauncherType(vanillaGameDir) else /* Return standalone if we aren't on Windows.*/ ProfileInstaller.LauncherType.WIN32) + val launcherType: LauncherType = (if ("Windows" in System.getProperty("os.name")) + getLauncherType(vanillaGameDir) else /* Return standalone if we aren't on Windows.*/ LauncherType.WIN32) installVersion(vanillaGameDir, gameVersion, loaderName, loaderVersion, launcherType) - installProfile(vanillaGameDir, instanceDir, profileName, versionId, launcherType) + installProfile(vanillaGameDir, instanceDir, profileName, versionId, launcherType, launchyState) return true } @@ -51,7 +51,7 @@ object FabricInstaller { gameVersion: String, loaderName: String, loaderVersion: String, - launcherType: ProfileInstaller.LauncherType + launcherType: LauncherType ) { println("Installing $gameVersion with fabric $loaderVersion to launcher $launcherType") val versionId = "$loaderName-$loaderVersion-$gameVersion" @@ -71,20 +71,16 @@ object FabricInstaller { Utils.writeToFile(profileJsonPath, profileJson.toString()) } - private fun installProfile( + fun installProfile( mcDir: Path, instanceDir: Path, profileName: String, versionId: String, - launcherType: ProfileInstaller.LauncherType + launcherType: LauncherType, + launchyState: LaunchyState ) { - val launcherProfiles: Path = mcDir.resolve(launcherType.profileJsonName) - if (!Files.exists(launcherProfiles)) { - println("Could not find launcher_profiles") - return - } + val jsonObject = getProfile(mcDir, launcherType) ?: return println("Creating profile") - val jsonObject = JSONObject(Utils.readString(launcherProfiles)) val profiles: JSONObject = jsonObject.getJSONObject("profiles") var foundProfileName: String? = profileName val it: Iterator = profiles.keys() @@ -101,17 +97,26 @@ object FabricInstaller { // If the profile already exists, use it instead of making a new one so that user's settings are kept (e.g icon) val profile: JSONObject = - if (profiles.has(foundProfileName)) profiles.getJSONObject(foundProfileName) else createProfile( - profileName, - instanceDir, - versionId, - ) + if (profiles.has(foundProfileName)) + profiles.getJSONObject(foundProfileName) + else createProfile(profileName, instanceDir, versionId) profile.put("name", profileName) profile.put("lastUsed", Utils.ISO_8601.format(Date())) // Update timestamp to bring to top of profile list profile.put("lastVersionId", versionId) + profile.put("javaArgs", "-Xmx${launchyState.clientSettings.ramAmount}G -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M") profiles.put(foundProfileName, profile) jsonObject.put("profiles", profiles) - Utils.writeToFile(launcherProfiles, jsonObject.toString()) + Utils.writeToFile(mcDir.resolve(launcherType.profileJsonName), jsonObject.toString()) + } + + fun getProfile(mcDir: Path, launcherType: LauncherType): JSONObject? { + val launcherProfiles: Path = mcDir.resolve(launcherType.profileJsonName) + if (!Files.exists(launcherProfiles)) { + println("Could not find launcher_profiles") + return null + } + + return JSONObject(Utils.readString(launcherProfiles)) } private fun createProfile(name: String, instanceDir: Path, versionId: String): JSONObject { @@ -157,7 +162,7 @@ object FabricInstaller { } } - private fun showLauncherTypeSelection(): ProfileInstaller.LauncherType? { + private fun showLauncherTypeSelection(): LauncherType? { val options = arrayOf( Utils.BUNDLE.getString("prompt.launcher.type.xbox"), Utils.BUNDLE.getString("prompt.launcher.type.win32") @@ -175,17 +180,17 @@ object FabricInstaller { return if (result == JOptionPane.CLOSED_OPTION) { null } else { - if (result == JOptionPane.YES_OPTION) ProfileInstaller.LauncherType.MICROSOFT_STORE else ProfileInstaller.LauncherType.WIN32 + if (result == JOptionPane.YES_OPTION) LauncherType.MICROSOFT_STORE else LauncherType.WIN32 } } - fun getLauncherType(vanillaGameDir: Path): ProfileInstaller.LauncherType { - var launcherType: ProfileInstaller.LauncherType? - val types: List = getInstalledLauncherTypes(vanillaGameDir) + fun getLauncherType(vanillaGameDir: Path): LauncherType { + var launcherType: LauncherType? + val types: List = getInstalledLauncherTypes(vanillaGameDir) if (types.size == 0) { // Default to WIN32, since nothing will happen anyway println("No launchers found, profile installation will not take place!") - launcherType = ProfileInstaller.LauncherType.WIN32 + launcherType = LauncherType.WIN32 } else if (types.size == 1) { println("Found only one launcher (" + types[0] + "), will proceed with that!") launcherType = types[0] @@ -194,14 +199,14 @@ object FabricInstaller { launcherType = showLauncherTypeSelection() if (launcherType == null) { System.out.println(Utils.BUNDLE.getString("prompt.ready.install")) - launcherType = ProfileInstaller.LauncherType.WIN32 + launcherType = LauncherType.WIN32 } } return launcherType } - fun getInstalledLauncherTypes(mcDir: Path): List { - return Arrays.stream(ProfileInstaller.LauncherType.values()).filter { launcherType -> + fun getInstalledLauncherTypes(mcDir: Path): List { + return Arrays.stream(LauncherType.values()).filter { launcherType -> Files.exists( mcDir.resolve( launcherType.profileJsonName diff --git a/src/main/kotlin/com/mineinabyss/launchy/logic/LaunchyState.kt b/src/main/kotlin/com/mineinabyss/launchy/logic/LaunchyState.kt index 5d44c17..0f059ec 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/logic/LaunchyState.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/logic/LaunchyState.kt @@ -112,6 +112,10 @@ class LaunchyState( "Mine in Abyss" ) } + val settingsUpToDate by derivedStateOf { + clientSettings == config.clientSettings + } + val updatesQueued by derivedStateOf { queuedUpdates.isNotEmpty() } val installsQueued by derivedStateOf { queuedInstalls.isNotEmpty() } val deletionsQueued by derivedStateOf { queuedDeletions.isNotEmpty() } @@ -126,6 +130,7 @@ class LaunchyState( ) var handledFirstLaunch by mutableStateOf(config.handledFirstLaunch) + var clientSettings by mutableStateOf(config.clientSettings) fun setModEnabled(mod: Mod, enabled: Boolean) { if (enabled) { @@ -175,6 +180,14 @@ class LaunchyState( } fun installFabric() { + installProfile() + installedFabricVersion = "Installing..." + installedFabricVersion = versions.fabricVersion + installedMinecraftVersion = "Installing..." + installedMinecraftVersion = versions.minecraftVersion + } + + fun installProfile() { installingProfile = true FabricInstaller.installToLauncher( Dirs.minecraft, @@ -183,12 +196,9 @@ class LaunchyState( versions.minecraftVersion, "fabric-loader", versions.fabricVersion, + this ) installingProfile = false - installedFabricVersion = "Installing..." - installedFabricVersion = versions.fabricVersion - installedMinecraftVersion = "Installing..." - installedMinecraftVersion = versions.minecraftVersion } suspend fun download(mod: Mod) { @@ -265,6 +275,7 @@ class LaunchyState( installedMinecraftVersion = installedMinecraftVersion, handledImportOptions = handledImportOptions, handledFirstLaunch = handledFirstLaunch, + clientSettings = clientSettings ).save() } diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/Screens.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/Screens.kt index 752b130..9c546e5 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/Screens.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/Screens.kt @@ -13,12 +13,14 @@ import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.dp import com.mineinabyss.launchy.ui.AppTopBar import com.mineinabyss.launchy.ui.screens.main.MainScreen -import com.mineinabyss.launchy.ui.screens.settings.SettingsScreen +import com.mineinabyss.launchy.ui.screens.settings.AccountScreen +import com.mineinabyss.launchy.ui.screens.settings.ModsScreen import com.mineinabyss.launchy.ui.state.TopBar sealed class Screen(val transparentTopBar: Boolean = false) { object Default : Screen(transparentTopBar = true) - object Settings : Screen() + object Mods : Screen() + object Account : Screen() } var screen: Screen by mutableStateOf(Screen.Default) @@ -31,8 +33,14 @@ fun Screens() { } TranslucentTopBar(screen) { - TransitionSlideUp(screen == Screen.Settings) { - SettingsScreen() + TransitionSlideUp(screen == Screen.Mods) { + ModsScreen() + } + } + + TranslucentTopBar(screen) { + TransitionSlideUp(screen == Screen.Account) { + AccountScreen() } } diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/ImportSettingsDialog.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/ImportSettingsDialog.kt index 4f0d7c5..03d9bc1 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/ImportSettingsDialog.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/ImportSettingsDialog.kt @@ -40,11 +40,11 @@ fun HandleImportSettings() { // TODO: Show error message e.printStackTrace() } - screen = Screen.Settings + screen = Screen.Mods state.handledImportOptions = true }, onDecline = { - screen = Screen.Settings + screen = Screen.Mods state.handledImportOptions = true } ) @@ -71,7 +71,7 @@ fun ImportSettingsDialog( modifier = Modifier.padding(24.dp) ) { Text( - text = "Import Settings", + text = "Import Mods", style = MaterialTheme.typography.headlineSmall ) Spacer(Modifier.height(16.dp)) diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/MainScreen.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/MainScreen.kt index a391248..4285c63 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/MainScreen.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/MainScreen.kt @@ -10,9 +10,10 @@ import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import com.mineinabyss.launchy.LocalLaunchyState +import com.mineinabyss.launchy.ui.screens.main.buttons.AccountButton import com.mineinabyss.launchy.ui.screens.main.buttons.InstallButton +import com.mineinabyss.launchy.ui.screens.main.buttons.ModsButton import com.mineinabyss.launchy.ui.screens.main.buttons.PlayButton -import com.mineinabyss.launchy.ui.screens.main.buttons.SettingsButton import com.mineinabyss.launchy.ui.state.windowScope val showComingSoonDialog = mutableStateOf(false) @@ -50,7 +51,9 @@ fun MainScreen() { Spacer(Modifier.width(10.dp)) // NewsButton(hasUpdates = true) // Spacer(Modifier.width(10.dp)) - SettingsButton() + ModsButton() + Spacer(Modifier.width(10.dp)) + AccountButton() } } diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/AccountButton.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/AccountButton.kt new file mode 100644 index 0000000..a221adf --- /dev/null +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/AccountButton.kt @@ -0,0 +1,18 @@ +package com.mineinabyss.launchy.ui.screens.main.buttons + +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.rounded.ManageAccounts +import androidx.compose.material3.Button +import androidx.compose.material3.Icon +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import com.mineinabyss.launchy.ui.screens.Screen +import com.mineinabyss.launchy.ui.screens.screen + +@Composable +fun AccountButton() { + Button(onClick = { screen = Screen.Account }) { + Icon(Icons.Rounded.ManageAccounts, contentDescription = "Account") + Text("Account") + } +} diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/SettingsButton.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/ModsButton.kt similarity index 71% rename from src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/SettingsButton.kt rename to src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/ModsButton.kt index 40c1ab8..fcb5459 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/SettingsButton.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/ModsButton.kt @@ -10,9 +10,9 @@ import com.mineinabyss.launchy.ui.screens.Screen import com.mineinabyss.launchy.ui.screens.screen @Composable -fun SettingsButton() { - Button(onClick = { screen = Screen.Settings }) { - Icon(Icons.Rounded.Settings, contentDescription = "Settings") - Text("Settings") +fun ModsButton() { + Button(onClick = { screen = Screen.Mods }) { + Icon(Icons.Rounded.Settings, contentDescription = "Mods") + Text("Mods") } } diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/NewsButton.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/NewsButton.kt index ad0fa87..46d2749 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/NewsButton.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/NewsButton.kt @@ -20,7 +20,7 @@ import androidx.compose.ui.unit.dp fun NewsButton(hasUpdates: Boolean) { Box { Button(onClick = {}) { - Icon(Icons.Rounded.Feed, contentDescription = "Settings") + Icon(Icons.Rounded.Feed, contentDescription = "Mods") Text("News") } if (hasUpdates) Surface( diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/AccountScreen.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/AccountScreen.kt new file mode 100644 index 0000000..1a4e0c7 --- /dev/null +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/AccountScreen.kt @@ -0,0 +1,113 @@ +package com.mineinabyss.launchy.ui.screens.settings + +import androidx.compose.desktop.ui.tooling.preview.Preview +import androidx.compose.foundation.VerticalScrollbar +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.rememberLazyListState +import androidx.compose.foundation.rememberScrollbarAdapter +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.foundation.text.KeyboardOptions +import androidx.compose.material.Icon +import androidx.compose.material.OutlinedTextField +import androidx.compose.material.Text +import androidx.compose.material.TextFieldDefaults +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.rounded.Password +import androidx.compose.material.icons.rounded.SupervisorAccount +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Surface +import androidx.compose.runtime.* +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.input.KeyboardType +import androidx.compose.ui.text.input.TextFieldValue +import androidx.compose.ui.unit.dp +import com.mineinabyss.launchy.LocalLaunchyState + +@Composable +@Preview +fun AccountScreen() { + val state = LocalLaunchyState + Scaffold( + bottomBar = { InfoBar() }, + ) { paddingValues -> + Column(horizontalAlignment = Alignment.CenterHorizontally) { + Surface( + shape = RoundedCornerShape(topStart = 10.dp, topEnd = 10.dp), + modifier = Modifier.padding(5.dp) + ) { + Box( + Modifier.padding(paddingValues).padding(start = 10.dp, top = 5.dp) + ) { + val lazyListState = rememberLazyListState() + LazyColumn(Modifier.fillMaxSize().padding(end = 12.dp), lazyListState) { + item("settings") { + TextField( + "Account Name", + "Enter Player Name", + icon = Icons.Rounded.SupervisorAccount + ) + TextField( + "Password", + "Enter Password", + KeyboardOptions(keyboardType = KeyboardType.Password), + Icons.Rounded.Password + ) + + Spacer(Modifier.height(10.dp)) + SettingGroup() + } + + } + VerticalScrollbar( + modifier = Modifier.fillMaxHeight().align(Alignment.CenterEnd), + adapter = rememberScrollbarAdapter(lazyListState) + ) + } + } + } + } +} + +@Composable +fun TextField( + label: String = "", + placeholder: String = "", + keyboardOptions: KeyboardOptions = KeyboardOptions.Default, + icon: ImageVector? = null, + singleLine: Boolean = true, + modifier: Modifier = Modifier, + textStyle: TextStyle = TextStyle.Default, + onValueChange: () -> Unit = {} +): TextFieldValue { + val errorColor = MaterialTheme.colorScheme.error + val primaryColor = MaterialTheme.colorScheme.onPrimaryContainer + var text by remember { mutableStateOf(TextFieldValue("")) } + OutlinedTextField( + value = text, + modifier = modifier, + textStyle = textStyle, + leadingIcon = { icon?.let { Icon(imageVector = it, "field") } }, + label = { Text(text = label) }, + singleLine = singleLine, + placeholder = { Text(text = placeholder) }, + keyboardOptions = keyboardOptions, + onValueChange = { newText -> + text = newText + }, + colors = TextFieldDefaults.outlinedTextFieldColors( + textColor = primaryColor, + cursorColor = errorColor, + unfocusedBorderColor = errorColor, + unfocusedLabelColor = errorColor, + focusedBorderColor = primaryColor, + focusedLabelColor = primaryColor, + placeholderColor = primaryColor + ) + ) + return text +} diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/SettingsScreen.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/ModsScreen.kt similarity index 98% rename from src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/SettingsScreen.kt rename to src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/ModsScreen.kt index c813296..32d1494 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/SettingsScreen.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/ModsScreen.kt @@ -18,7 +18,7 @@ import com.mineinabyss.launchy.LocalLaunchyState @Composable @Preview -fun SettingsScreen() { +fun ModsScreen() { val state = LocalLaunchyState Scaffold( bottomBar = { InfoBar() }, diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/SettingGroup.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/SettingGroup.kt new file mode 100644 index 0000000..536c35e --- /dev/null +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/SettingGroup.kt @@ -0,0 +1,68 @@ +package com.mineinabyss.launchy.ui.screens.settings + +import androidx.compose.animation.AnimatedVisibility +import androidx.compose.animation.core.animateFloatAsState +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.rounded.ArrowDropDown +import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Surface +import androidx.compose.material3.Text +import androidx.compose.runtime.* +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.rotate +import androidx.compose.ui.unit.dp +import com.mineinabyss.launchy.LocalLaunchyState +import kotlinx.serialization.Serializable +import kotlin.math.roundToInt + +@Composable +fun SettingGroup() { + var expanded by remember { mutableStateOf(false) } + val arrowRotationState by animateFloatAsState(targetValue = if (expanded) 180f else 0f) + val state = LocalLaunchyState + + Surface( + tonalElevation = 1.dp, + shape = RoundedCornerShape(20.dp), + modifier = Modifier.padding(2.dp).fillMaxWidth().clickable { expanded = !expanded }, + ) { + Column { + Row( + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.SpaceBetween, + modifier = Modifier.height(40.dp) + ) { + Spacer(Modifier.width(10.dp)) + Text( + "Settings", Modifier.weight(1f), + style = MaterialTheme.typography.bodyLarge, + ) + Spacer(Modifier.width(10.dp)) + Icon(Icons.Rounded.ArrowDropDown, "Show settings", Modifier.rotate(arrowRotationState)) + Spacer(Modifier.width(10.dp)) + } + AnimatedVisibility(expanded) { + Column { + Row( + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.SpaceBetween, + modifier = Modifier.height(40.dp) + ) { + Spacer(Modifier.width(10.dp)) + //TODO Slider for RAM Selection + val ram = SliderSwitch(label = "Dedicated RAM:").roundToInt() + state.clientSettings = ClientSettings(ram) + } + } + } + } + } +} + +@Serializable +data class ClientSettings(val ramAmount: Int) diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/SliderSwitch.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/SliderSwitch.kt new file mode 100644 index 0000000..483ecab --- /dev/null +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/SliderSwitch.kt @@ -0,0 +1,53 @@ +package com.mineinabyss.launchy.ui.screens.settings + +import androidx.compose.foundation.layout.* +import androidx.compose.material.* +import androidx.compose.material3.MaterialTheme +import androidx.compose.runtime.* +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.unit.dp +import kotlin.math.roundToLong + +@OptIn(ExperimentalMaterialApi::class) +@Composable +fun SliderSwitch( + label: String = "", + modifier: Modifier = Modifier, + valueRange: IntRange = 1..16, +): Float { + var sliderPosition by remember { mutableStateOf(2f) } + var sliderPos by remember { mutableStateOf(sliderPosition.toString()) } + + Text(label, color = MaterialTheme.colorScheme.error) + TextField( + label = sliderPosition.toString(), + textStyle = LocalTextStyle.current.copy(textAlign = TextAlign.Left), + modifier = modifier.width(100.dp), + onValueChange = { + println("$sliderPos $sliderPosition") + sliderPosition = sliderPos.toFloatOrNull() ?: sliderPosition + } + ) + // This is called too often, and should only be called when textfield triggers onValueChange but cant? not sure + //sliderPosition = sliderPos.toFloatOrNull() ?: sliderPosition + + Slider( + value = sliderPosition, + colors = SliderDefaults.colors( + thumbColor = MaterialTheme.colorScheme.error, Color.Transparent, + activeTrackColor = MaterialTheme.colorScheme.errorContainer, Color.Transparent + ), + onValueChangeFinished = { + sliderPos = sliderPosition.toString() + }, + valueRange = valueRange.first.toFloat()..valueRange.last.toFloat(), + steps = valueRange.last - valueRange.first, + onValueChange = { + sliderPosition = it.roundToLong().toFloat() + }, + modifier = modifier + ) + return sliderPosition +} From 99bdea4aa85b138ab282bb15215e55a5924618f2 Mon Sep 17 00:00:00 2001 From: Boy Date: Sun, 25 Dec 2022 19:04:34 +0100 Subject: [PATCH 3/8] lower default slider value --- .../com/mineinabyss/launchy/ui/screens/settings/SettingGroup.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/SettingGroup.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/SettingGroup.kt index 536c35e..8a53cb2 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/SettingGroup.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/SettingGroup.kt @@ -55,7 +55,7 @@ fun SettingGroup() { ) { Spacer(Modifier.width(10.dp)) //TODO Slider for RAM Selection - val ram = SliderSwitch(label = "Dedicated RAM:").roundToInt() + val ram = SliderSwitch(label = "Dedicated RAM:", valueRange = 1..6).roundToInt() state.clientSettings = ClientSettings(ram) } } From 5274012baa3ddf630c1cf295f9edc14a7a8916b1 Mon Sep 17 00:00:00 2001 From: Boy Date: Mon, 26 Dec 2022 13:39:47 +0100 Subject: [PATCH 4/8] login button --- .../main/buttons/LoginMicrosoftButton.kt | 32 +++++++++++++++++++ .../ui/screens/settings/AccountScreen.kt | 3 ++ 2 files changed, 35 insertions(+) create mode 100644 src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/LoginMicrosoftButton.kt diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/LoginMicrosoftButton.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/LoginMicrosoftButton.kt new file mode 100644 index 0000000..76d998a --- /dev/null +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/LoginMicrosoftButton.kt @@ -0,0 +1,32 @@ +package com.mineinabyss.launchy.ui.screens.main.buttons + +import androidx.compose.animation.AnimatedVisibility +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.rounded.Login +import androidx.compose.material3.* +import androidx.compose.runtime.Composable +import androidx.compose.runtime.rememberCoroutineScope +import com.mineinabyss.launchy.LocalLaunchyState + +@Composable +fun LoginMicrosoftButton(enabled: Boolean) { + val state = LocalLaunchyState + val coroutineScope = rememberCoroutineScope() + + Button( + enabled = enabled, + onClick = { /*TODO Login with Microsoft*/}, + colors = ButtonDefaults.buttonColors( + containerColor = MaterialTheme.colorScheme.primaryContainer, + contentColor = MaterialTheme.colorScheme.primary + ), + ) { + Icon(Icons.Rounded.Login, "Login with Microsoft") + AnimatedVisibility(!state.minecraftValid) { + Text("Login with Microsoft") + } + AnimatedVisibility(state.minecraftValid) { + Text("Login with Microsoft") + } + } +} diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/AccountScreen.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/AccountScreen.kt index 1a4e0c7..35ed621 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/AccountScreen.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/AccountScreen.kt @@ -27,6 +27,7 @@ import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.unit.dp import com.mineinabyss.launchy.LocalLaunchyState +import com.mineinabyss.launchy.ui.screens.main.buttons.LoginMicrosoftButton @Composable @Preview @@ -46,6 +47,8 @@ fun AccountScreen() { val lazyListState = rememberLazyListState() LazyColumn(Modifier.fillMaxSize().padding(end = 12.dp), lazyListState) { item("settings") { + + LoginMicrosoftButton(true) TextField( "Account Name", "Enter Player Name", From 7faa0ab0f89b2d103745eb8c72227b8492a46333 Mon Sep 17 00:00:00 2001 From: Boy Date: Mon, 26 Dec 2022 14:19:16 +0100 Subject: [PATCH 5/8] more settings --- .../com/mineinabyss/launchy/data/Config.kt | 4 +++- .../launchy/logic/FabricInstaller.kt | 22 ++++++++----------- .../ui/screens/settings/AccountScreen.kt | 8 ++----- .../ui/screens/settings/SettingGroup.kt | 18 ++++++++------- 4 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/main/kotlin/com/mineinabyss/launchy/data/Config.kt b/src/main/kotlin/com/mineinabyss/launchy/data/Config.kt index e11b927..ef1de0f 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/data/Config.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/data/Config.kt @@ -1,6 +1,8 @@ package com.mineinabyss.launchy.data import com.mineinabyss.launchy.ui.screens.settings.ClientSettings +import com.mineinabyss.launchy.ui.screens.settings.JavaSettings +import com.mineinabyss.launchy.ui.screens.settings.MinecraftSettings import kotlinx.serialization.Serializable import kotlinx.serialization.encodeToString import java.io.* @@ -12,7 +14,7 @@ import kotlin.io.path.writeText @Serializable data class Config( val minecraftDir: String? = null, - val clientSettings: ClientSettings = ClientSettings(2), + val clientSettings: ClientSettings = ClientSettings(MinecraftSettings(), JavaSettings()), val fullEnabledGroups: Set = setOf(), val fullDisabledGroups: Set = setOf(), val toggledMods: Set = setOf(), diff --git a/src/main/kotlin/com/mineinabyss/launchy/logic/FabricInstaller.kt b/src/main/kotlin/com/mineinabyss/launchy/logic/FabricInstaller.kt index 7400b88..722e75e 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/logic/FabricInstaller.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/logic/FabricInstaller.kt @@ -79,7 +79,13 @@ object FabricInstaller { launcherType: LauncherType, launchyState: LaunchyState ) { - val jsonObject = getProfile(mcDir, launcherType) ?: return + val launcherProfiles: Path = mcDir.resolve(launcherType.profileJsonName) + if (!Files.exists(launcherProfiles)) { + println("Could not find launcher_profiles") + return + } + + val jsonObject = JSONObject(Utils.readString(launcherProfiles)) println("Creating profile") val profiles: JSONObject = jsonObject.getJSONObject("profiles") var foundProfileName: String? = profileName @@ -94,7 +100,7 @@ object FabricInstaller { foundProfileName = key } } - + val javaSettings = launchyState.clientSettings.java // If the profile already exists, use it instead of making a new one so that user's settings are kept (e.g icon) val profile: JSONObject = if (profiles.has(foundProfileName)) @@ -103,22 +109,12 @@ object FabricInstaller { profile.put("name", profileName) profile.put("lastUsed", Utils.ISO_8601.format(Date())) // Update timestamp to bring to top of profile list profile.put("lastVersionId", versionId) - profile.put("javaArgs", "-Xmx${launchyState.clientSettings.ramAmount}G -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M") + profile.put("javaArgs", "-Xmx${javaSettings.maxRamAmount}G -Xms${javaSettings.minRamAmount}G -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M") profiles.put(foundProfileName, profile) jsonObject.put("profiles", profiles) Utils.writeToFile(mcDir.resolve(launcherType.profileJsonName), jsonObject.toString()) } - fun getProfile(mcDir: Path, launcherType: LauncherType): JSONObject? { - val launcherProfiles: Path = mcDir.resolve(launcherType.profileJsonName) - if (!Files.exists(launcherProfiles)) { - println("Could not find launcher_profiles") - return null - } - - return JSONObject(Utils.readString(launcherProfiles)) - } - private fun createProfile(name: String, instanceDir: Path, versionId: String): JSONObject { val jsonObject = JSONObject() jsonObject.put("name", name) diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/AccountScreen.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/AccountScreen.kt index 35ed621..457c76c 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/AccountScreen.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/AccountScreen.kt @@ -12,9 +12,6 @@ import androidx.compose.material.Icon import androidx.compose.material.OutlinedTextField import androidx.compose.material.Text import androidx.compose.material.TextFieldDefaults -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.rounded.Password -import androidx.compose.material.icons.rounded.SupervisorAccount import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Scaffold import androidx.compose.material3.Surface @@ -23,7 +20,6 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.text.TextStyle -import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.unit.dp import com.mineinabyss.launchy.LocalLaunchyState @@ -49,7 +45,7 @@ fun AccountScreen() { item("settings") { LoginMicrosoftButton(true) - TextField( + /*TextField( "Account Name", "Enter Player Name", icon = Icons.Rounded.SupervisorAccount @@ -59,7 +55,7 @@ fun AccountScreen() { "Enter Password", KeyboardOptions(keyboardType = KeyboardType.Password), Icons.Rounded.Password - ) + )*/ Spacer(Modifier.height(10.dp)) SettingGroup() diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/SettingGroup.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/SettingGroup.kt index 8a53cb2..00a975f 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/SettingGroup.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/SettingGroup.kt @@ -38,10 +38,7 @@ fun SettingGroup() { modifier = Modifier.height(40.dp) ) { Spacer(Modifier.width(10.dp)) - Text( - "Settings", Modifier.weight(1f), - style = MaterialTheme.typography.bodyLarge, - ) + Text("Settings", Modifier.weight(1f), style = MaterialTheme.typography.bodyLarge,) Spacer(Modifier.width(10.dp)) Icon(Icons.Rounded.ArrowDropDown, "Show settings", Modifier.rotate(arrowRotationState)) Spacer(Modifier.width(10.dp)) @@ -54,9 +51,10 @@ fun SettingGroup() { modifier = Modifier.height(40.dp) ) { Spacer(Modifier.width(10.dp)) - //TODO Slider for RAM Selection - val ram = SliderSwitch(label = "Dedicated RAM:", valueRange = 1..6).roundToInt() - state.clientSettings = ClientSettings(ram) + val minRam = SliderSwitch(label = "Minimum RAM", valueRange = 1..12).roundToInt() + val maxRam = SliderSwitch(label = "Maximum RAM:", valueRange = 1..12).roundToInt() + // Figure out way to handle this, probably storing via state or something + state.clientSettings = ClientSettings(state.clientSettings.minecraft, JavaSettings(minRam, maxRam)) } } } @@ -65,4 +63,8 @@ fun SettingGroup() { } @Serializable -data class ClientSettings(val ramAmount: Int) +data class ClientSettings(val minecraft: MinecraftSettings, val java: JavaSettings) +@Serializable +data class MinecraftSettings(val resWidth: Int = 1280, val resHeight: Int = 720, val fullscreenLaunch: Boolean = false) +@Serializable +data class JavaSettings(val minRamAmount: Int = 2, val maxRamAmount: Int = 2) From 355522757d020688cdffaa7de0f4b7eb7da2bc15 Mon Sep 17 00:00:00 2001 From: Boy Date: Mon, 26 Dec 2022 15:04:11 +0100 Subject: [PATCH 6/8] work on tabs --- .../com/mineinabyss/launchy/ui/TopBar.kt | 56 +++++++++++++++++-- .../mineinabyss/launchy/ui/screens/Screens.kt | 3 + .../ui/screens/settings/SettingsTab.kt | 26 +++++++++ 3 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/SettingsTab.kt diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/TopBar.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/TopBar.kt index 7d6c359..52e5e55 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/ui/TopBar.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/TopBar.kt @@ -6,19 +6,19 @@ import androidx.compose.animation.slideOut import androidx.compose.foundation.layout.* import androidx.compose.foundation.window.WindowDraggableArea import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.rounded.ArrowBack -import androidx.compose.material.icons.rounded.Close -import androidx.compose.material.icons.rounded.CropSquare -import androidx.compose.material.icons.rounded.Minimize +import androidx.compose.material.icons.rounded.* import androidx.compose.material3.* import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.RectangleShape import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.dp +import com.mineinabyss.launchy.ui.screens.Screen +import com.mineinabyss.launchy.ui.screens.screen import com.mineinabyss.launchy.ui.state.TopBarState @Composable @@ -33,6 +33,54 @@ fun WindowButton(icon: ImageVector, onClick: () -> Unit) { } } +@Composable +fun TabIconButton(label: String = "", icon: ImageVector, onClick: () -> Unit) { + Button(onClick, shape = RectangleShape, colors = ButtonDefaults.buttonColors(MaterialTheme.colorScheme.background, disabledContainerColor = MaterialTheme.colorScheme.onPrimaryContainer)) { + Icon(icon, "", tint = MaterialTheme.colorScheme.onPrimaryContainer) + Text(label, color = MaterialTheme.colorScheme.onPrimaryContainer) + } +} + +@Composable +fun TabIconBar( + state: TopBarState, + transparent: Boolean, + tabIconScreens: Set, + onTabIconClicked: (() -> Unit), +) = state.windowScope.WindowDraggableArea { + Box( + Modifier.fillMaxWidth().height(40.dp) + ) { + AnimatedVisibility( + !transparent, + enter = slideIn(initialOffset = { IntOffset(0, -120) }), + exit = slideOut(targetOffset = { IntOffset(0, -120) }) + ) { + Surface(tonalElevation = 1.dp, modifier = Modifier.fillMaxSize()) {} + } + Row( + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.SpaceAround, + ) { + Spacer(Modifier.width(5.dp)) + Row( + Modifier.weight(1f), + verticalAlignment = Alignment.CenterVertically, + ) { +// TabIconButton("Accounts", Icons.Rounded.ManageAccounts) { +// Screen.Account +// } + + TabIconButton("Mods", Icons.Rounded.Settings) { screen = Screen.Mods } + + } + Row { + + } + } + } +} + @Composable fun AppTopBar( state: TopBarState, diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/Screens.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/Screens.kt index 9c546e5..c1f73a9 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/Screens.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/Screens.kt @@ -15,12 +15,14 @@ import com.mineinabyss.launchy.ui.AppTopBar import com.mineinabyss.launchy.ui.screens.main.MainScreen import com.mineinabyss.launchy.ui.screens.settings.AccountScreen import com.mineinabyss.launchy.ui.screens.settings.ModsScreen +import com.mineinabyss.launchy.ui.screens.settings.Tabs import com.mineinabyss.launchy.ui.state.TopBar sealed class Screen(val transparentTopBar: Boolean = false) { object Default : Screen(transparentTopBar = true) object Mods : Screen() object Account : Screen() + object Settings : Screen() } var screen: Screen by mutableStateOf(Screen.Default) @@ -41,6 +43,7 @@ fun Screens() { TranslucentTopBar(screen) { TransitionSlideUp(screen == Screen.Account) { AccountScreen() + Tabs() } } diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/SettingsTab.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/SettingsTab.kt new file mode 100644 index 0000000..de77369 --- /dev/null +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/SettingsTab.kt @@ -0,0 +1,26 @@ +package com.mineinabyss.launchy.ui.screens.settings + +import androidx.compose.runtime.Composable +import com.mineinabyss.launchy.ui.TabIconBar +import com.mineinabyss.launchy.ui.screens.Screen +import com.mineinabyss.launchy.ui.screens.TransitionSlideUp +import com.mineinabyss.launchy.ui.screens.TranslucentTopBar +import com.mineinabyss.launchy.ui.screens.screen +import com.mineinabyss.launchy.ui.state.TopBar + +@Composable +fun Tabs() { + + TranslucentTopBar(screen) { + TransitionSlideUp(screen == Screen.Account) { + AccountScreen() + } + } + + TabIconBar( + TopBar, + screen.transparentTopBar, + tabIconScreens = setOf(Screen.Account), + onTabIconClicked = { screen = Screen.Default } + ) +} From 15b568dff575c52ab37cbc2d617eebcfc8cef14b Mon Sep 17 00:00:00 2001 From: Boy Date: Mon, 26 Dec 2022 18:45:25 +0100 Subject: [PATCH 7/8] switch to using tabs and 1 main setting button --- .../mineinabyss/launchy/data/Typealiases.kt | 3 ++ .../com/mineinabyss/launchy/ui/TopBar.kt | 18 ++++--- .../mineinabyss/launchy/ui/screens/Screens.kt | 24 ++++----- .../launchy/ui/screens/main/MainScreen.kt | 9 +--- .../ui/screens/main/buttons/AccountButton.kt | 18 ------- .../{ModsButton.kt => SettingsButton.kt} | 8 +-- .../ui/screens/settings/AccountScreen.kt | 25 ++-------- .../{SettingGroup.kt => JavaGroup.kt} | 4 +- .../launchy/ui/screens/settings/JavaScreen.kt | 49 +++++++++++++++++++ .../launchy/ui/screens/settings/ModsScreen.kt | 2 +- .../ui/screens/settings/SettingsTab.kt | 8 --- .../ui/screens/settings/TripleSwitch.kt | 3 +- 12 files changed, 90 insertions(+), 81 deletions(-) delete mode 100644 src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/AccountButton.kt rename src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/{ModsButton.kt => SettingsButton.kt} (68%) rename src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/{SettingGroup.kt => JavaGroup.kt} (95%) create mode 100644 src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/JavaScreen.kt diff --git a/src/main/kotlin/com/mineinabyss/launchy/data/Typealiases.kt b/src/main/kotlin/com/mineinabyss/launchy/data/Typealiases.kt index 5862780..9e74914 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/data/Typealiases.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/data/Typealiases.kt @@ -1,6 +1,9 @@ package com.mineinabyss.launchy.data +import androidx.compose.runtime.Composable + typealias ModName = String typealias GroupName = String typealias DownloadURL = String typealias ConfigURL = String +typealias ComposableFun = @Composable () -> Unit diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/TopBar.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/TopBar.kt index 52e5e55..f8c1fab 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/ui/TopBar.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/TopBar.kt @@ -6,7 +6,13 @@ import androidx.compose.animation.slideOut import androidx.compose.foundation.layout.* import androidx.compose.foundation.window.WindowDraggableArea import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.rounded.* +import androidx.compose.material.icons.outlined.ManageAccounts +import androidx.compose.material.icons.outlined.Settings +import androidx.compose.material.icons.outlined.SettingsApplications +import androidx.compose.material.icons.rounded.ArrowBack +import androidx.compose.material.icons.rounded.Close +import androidx.compose.material.icons.rounded.CropSquare +import androidx.compose.material.icons.rounded.Minimize import androidx.compose.material3.* import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment @@ -66,13 +72,11 @@ fun TabIconBar( Row( Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.Center ) { -// TabIconButton("Accounts", Icons.Rounded.ManageAccounts) { -// Screen.Account -// } - - TabIconButton("Mods", Icons.Rounded.Settings) { screen = Screen.Mods } - + TabIconButton("Accounts", Icons.Outlined.ManageAccounts) { screen = Screen.Account } + TabIconButton("Java", Icons.Outlined.SettingsApplications) { screen = Screen.Java } + TabIconButton("Mods", Icons.Outlined.Settings) { screen = Screen.Mods } } Row { diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/Screens.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/Screens.kt index c1f73a9..253f55e 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/Screens.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/Screens.kt @@ -11,15 +11,18 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.dp +import com.mineinabyss.launchy.data.ComposableFun import com.mineinabyss.launchy.ui.AppTopBar import com.mineinabyss.launchy.ui.screens.main.MainScreen import com.mineinabyss.launchy.ui.screens.settings.AccountScreen +import com.mineinabyss.launchy.ui.screens.settings.JavaScreen import com.mineinabyss.launchy.ui.screens.settings.ModsScreen import com.mineinabyss.launchy.ui.screens.settings.Tabs import com.mineinabyss.launchy.ui.state.TopBar sealed class Screen(val transparentTopBar: Boolean = false) { object Default : Screen(transparentTopBar = true) + object Java : Screen() object Mods : Screen() object Account : Screen() object Settings : Screen() @@ -35,14 +38,13 @@ fun Screens() { } TranslucentTopBar(screen) { - TransitionSlideUp(screen == Screen.Mods) { - ModsScreen() - } - } - - TranslucentTopBar(screen) { - TransitionSlideUp(screen == Screen.Account) { - AccountScreen() + TransitionSlideUp(screen != Screen.Default) { + when (screen) { + Screen.Account -> AccountScreen() + Screen.Java -> JavaScreen() + Screen.Mods -> ModsScreen() + else -> {} + } Tabs() } } @@ -56,7 +58,7 @@ fun Screens() { } @Composable -fun TranslucentTopBar(currentScreen: Screen, content: @Composable () -> Unit) { +fun TranslucentTopBar(currentScreen: Screen, content: ComposableFun) { Column { AnimatedVisibility(!currentScreen.transparentTopBar, enter = fadeIn(), exit = fadeOut()) { Spacer(Modifier.height(40.dp)) @@ -66,14 +68,14 @@ fun TranslucentTopBar(currentScreen: Screen, content: @Composable () -> Unit) { } @Composable -fun TransitionFade(enabled: Boolean, content: @Composable () -> Unit) { +fun TransitionFade(enabled: Boolean, content: ComposableFun) { AnimatedVisibility(enabled, enter = fadeIn(), exit = fadeOut()) { content() } } @Composable -fun TransitionSlideUp(enabled: Boolean, content: @Composable () -> Unit) { +fun TransitionSlideUp(enabled: Boolean, content: ComposableFun) { AnimatedVisibility( enabled, enter = fadeIn() + slideIn(initialOffset = { IntOffset(0, 100) }), diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/MainScreen.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/MainScreen.kt index 4285c63..c2f2e21 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/MainScreen.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/MainScreen.kt @@ -10,10 +10,9 @@ import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import com.mineinabyss.launchy.LocalLaunchyState -import com.mineinabyss.launchy.ui.screens.main.buttons.AccountButton import com.mineinabyss.launchy.ui.screens.main.buttons.InstallButton -import com.mineinabyss.launchy.ui.screens.main.buttons.ModsButton import com.mineinabyss.launchy.ui.screens.main.buttons.PlayButton +import com.mineinabyss.launchy.ui.screens.main.buttons.SettingsButton import com.mineinabyss.launchy.ui.state.windowScope val showComingSoonDialog = mutableStateOf(false) @@ -49,11 +48,7 @@ fun MainScreen() { UpdateInfoButton() } Spacer(Modifier.width(10.dp)) -// NewsButton(hasUpdates = true) -// Spacer(Modifier.width(10.dp)) - ModsButton() - Spacer(Modifier.width(10.dp)) - AccountButton() + SettingsButton(!state.isDownloading && state.operationsQueued && state.minecraftValid) } } diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/AccountButton.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/AccountButton.kt deleted file mode 100644 index a221adf..0000000 --- a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/AccountButton.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.mineinabyss.launchy.ui.screens.main.buttons - -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.rounded.ManageAccounts -import androidx.compose.material3.Button -import androidx.compose.material3.Icon -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import com.mineinabyss.launchy.ui.screens.Screen -import com.mineinabyss.launchy.ui.screens.screen - -@Composable -fun AccountButton() { - Button(onClick = { screen = Screen.Account }) { - Icon(Icons.Rounded.ManageAccounts, contentDescription = "Account") - Text("Account") - } -} diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/ModsButton.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/SettingsButton.kt similarity index 68% rename from src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/ModsButton.kt rename to src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/SettingsButton.kt index fcb5459..f920b61 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/ModsButton.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/SettingsButton.kt @@ -10,9 +10,9 @@ import com.mineinabyss.launchy.ui.screens.Screen import com.mineinabyss.launchy.ui.screens.screen @Composable -fun ModsButton() { - Button(onClick = { screen = Screen.Mods }) { - Icon(Icons.Rounded.Settings, contentDescription = "Mods") - Text("Mods") +fun SettingsButton(enabled: Boolean) { + Button(enabled = enabled, onClick = { screen = Screen.Settings }) { + Icon(Icons.Rounded.Settings, contentDescription = "Settings") + Text("Settings") } } diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/AccountScreen.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/AccountScreen.kt index 457c76c..2241f2a 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/AccountScreen.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/AccountScreen.kt @@ -22,43 +22,24 @@ import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.unit.dp -import com.mineinabyss.launchy.LocalLaunchyState import com.mineinabyss.launchy.ui.screens.main.buttons.LoginMicrosoftButton @Composable @Preview fun AccountScreen() { - val state = LocalLaunchyState - Scaffold( - bottomBar = { InfoBar() }, - ) { paddingValues -> + Scaffold { paddingValues -> Column(horizontalAlignment = Alignment.CenterHorizontally) { Surface( shape = RoundedCornerShape(topStart = 10.dp, topEnd = 10.dp), modifier = Modifier.padding(5.dp) ) { Box( - Modifier.padding(paddingValues).padding(start = 10.dp, top = 5.dp) + Modifier.padding(paddingValues).padding(start = 10.dp, top = 40.dp) ) { val lazyListState = rememberLazyListState() LazyColumn(Modifier.fillMaxSize().padding(end = 12.dp), lazyListState) { - item("settings") { - + item("account settings") { LoginMicrosoftButton(true) - /*TextField( - "Account Name", - "Enter Player Name", - icon = Icons.Rounded.SupervisorAccount - ) - TextField( - "Password", - "Enter Password", - KeyboardOptions(keyboardType = KeyboardType.Password), - Icons.Rounded.Password - )*/ - - Spacer(Modifier.height(10.dp)) - SettingGroup() } } diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/SettingGroup.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/JavaGroup.kt similarity index 95% rename from src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/SettingGroup.kt rename to src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/JavaGroup.kt index 00a975f..5a52c6e 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/SettingGroup.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/JavaGroup.kt @@ -21,7 +21,7 @@ import kotlinx.serialization.Serializable import kotlin.math.roundToInt @Composable -fun SettingGroup() { +fun JavaGroup() { var expanded by remember { mutableStateOf(false) } val arrowRotationState by animateFloatAsState(targetValue = if (expanded) 180f else 0f) val state = LocalLaunchyState @@ -40,7 +40,7 @@ fun SettingGroup() { Spacer(Modifier.width(10.dp)) Text("Settings", Modifier.weight(1f), style = MaterialTheme.typography.bodyLarge,) Spacer(Modifier.width(10.dp)) - Icon(Icons.Rounded.ArrowDropDown, "Show settings", Modifier.rotate(arrowRotationState)) + Icon(Icons.Rounded.ArrowDropDown, "Show Java Settings", Modifier.rotate(arrowRotationState)) Spacer(Modifier.width(10.dp)) } AnimatedVisibility(expanded) { diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/JavaScreen.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/JavaScreen.kt new file mode 100644 index 0000000..022fa8b --- /dev/null +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/JavaScreen.kt @@ -0,0 +1,49 @@ +package com.mineinabyss.launchy.ui.screens.settings + +import androidx.compose.desktop.ui.tooling.preview.Preview +import androidx.compose.foundation.VerticalScrollbar +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.rememberLazyListState +import androidx.compose.foundation.rememberScrollbarAdapter +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Surface +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import com.mineinabyss.launchy.LocalLaunchyState +import kotlin.math.roundToInt + +@Composable +@Preview +fun JavaScreen() { + val state = LocalLaunchyState + Scaffold { paddingValues -> + Column(horizontalAlignment = Alignment.CenterHorizontally) { + Surface( + shape = RoundedCornerShape(topStart = 10.dp, topEnd = 10.dp), + modifier = Modifier.padding(5.dp) + ) { + Box( + Modifier.padding(paddingValues).padding(start = 10.dp, top = 40.dp) + ) { + val lazyListState = rememberLazyListState() + LazyColumn(Modifier.fillMaxSize().padding(end = 12.dp), lazyListState) { + item("java settings") { + val minRam = SliderSwitch(label = "Minimum RAM", valueRange = 1..12).roundToInt() + val maxRam = SliderSwitch(label = "Maximum RAM:", valueRange = 1..12).roundToInt() + // Figure out way to handle this, probably storing via state or something + state.clientSettings = ClientSettings(state.clientSettings.minecraft, JavaSettings(minRam, maxRam)) + } + } + VerticalScrollbar( + modifier = Modifier.fillMaxHeight().align(Alignment.CenterEnd), + adapter = rememberScrollbarAdapter(lazyListState) + ) + } + } + } + } +} diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/ModsScreen.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/ModsScreen.kt index 32d1494..d1fbf04 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/ModsScreen.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/ModsScreen.kt @@ -30,7 +30,7 @@ fun ModsScreen() { ) { Box( Modifier.padding(paddingValues) - .padding(start = 10.dp, top = 5.dp) + .padding(start = 10.dp, top = 40.dp) ) { val lazyListState = rememberLazyListState() LazyColumn(Modifier.fillMaxSize().padding(end = 12.dp), lazyListState) { diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/SettingsTab.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/SettingsTab.kt index de77369..368b242 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/SettingsTab.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/SettingsTab.kt @@ -3,20 +3,12 @@ package com.mineinabyss.launchy.ui.screens.settings import androidx.compose.runtime.Composable import com.mineinabyss.launchy.ui.TabIconBar import com.mineinabyss.launchy.ui.screens.Screen -import com.mineinabyss.launchy.ui.screens.TransitionSlideUp -import com.mineinabyss.launchy.ui.screens.TranslucentTopBar import com.mineinabyss.launchy.ui.screens.screen import com.mineinabyss.launchy.ui.state.TopBar @Composable fun Tabs() { - TranslucentTopBar(screen) { - TransitionSlideUp(screen == Screen.Account) { - AccountScreen() - } - } - TabIconBar( TopBar, screen.transparentTopBar, diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/TripleSwitch.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/TripleSwitch.kt index 23e6f54..63b815d 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/TripleSwitch.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/TripleSwitch.kt @@ -17,6 +17,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp import com.mineinabyss.launchy.LocalLaunchyState +import com.mineinabyss.launchy.data.ComposableFun import com.mineinabyss.launchy.data.Group import com.mineinabyss.launchy.data.Mod import com.mineinabyss.launchy.util.Option @@ -101,7 +102,7 @@ fun TripleSwitchButton( onSwitch: (Option) -> Unit, enabled: Boolean = true, modifier: Modifier = Modifier, - content: @Composable () -> Unit, + content: ComposableFun, ) { Button( enabled = enabled, From cb9f517f0f15de2535b908571efe3324d90489ee Mon Sep 17 00:00:00 2001 From: Boy Date: Wed, 28 Dec 2022 16:40:40 +0100 Subject: [PATCH 8/8] more tweaks to sliders --- .../launchy/ui/screens/main/MainScreen.kt | 2 +- .../main/buttons/LoginMicrosoftButton.kt | 10 ++++++++- .../ui/screens/main/buttons/SettingsButton.kt | 4 ++-- .../launchy/ui/screens/settings/JavaGroup.kt | 2 +- .../ui/screens/settings/SliderSwitch.kt | 22 +++++++++++++++---- 5 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/MainScreen.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/MainScreen.kt index c2f2e21..2306214 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/MainScreen.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/MainScreen.kt @@ -48,7 +48,7 @@ fun MainScreen() { UpdateInfoButton() } Spacer(Modifier.width(10.dp)) - SettingsButton(!state.isDownloading && state.operationsQueued && state.minecraftValid) + SettingsButton() } } diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/LoginMicrosoftButton.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/LoginMicrosoftButton.kt index 76d998a..e74205d 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/LoginMicrosoftButton.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/LoginMicrosoftButton.kt @@ -15,7 +15,7 @@ fun LoginMicrosoftButton(enabled: Boolean) { Button( enabled = enabled, - onClick = { /*TODO Login with Microsoft*/}, + onClick = { startMicrosoftLoginProcess() }, colors = ButtonDefaults.buttonColors( containerColor = MaterialTheme.colorScheme.primaryContainer, contentColor = MaterialTheme.colorScheme.primary @@ -30,3 +30,11 @@ fun LoginMicrosoftButton(enabled: Boolean) { } } } + +private fun startMicrosoftLoginProcess() { + +} + +private fun microsoftOAuth2Flow() { + +} diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/SettingsButton.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/SettingsButton.kt index f920b61..40c1ab8 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/SettingsButton.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/main/buttons/SettingsButton.kt @@ -10,8 +10,8 @@ import com.mineinabyss.launchy.ui.screens.Screen import com.mineinabyss.launchy.ui.screens.screen @Composable -fun SettingsButton(enabled: Boolean) { - Button(enabled = enabled, onClick = { screen = Screen.Settings }) { +fun SettingsButton() { + Button(onClick = { screen = Screen.Settings }) { Icon(Icons.Rounded.Settings, contentDescription = "Settings") Text("Settings") } diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/JavaGroup.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/JavaGroup.kt index 5a52c6e..4715d30 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/JavaGroup.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/JavaGroup.kt @@ -52,7 +52,7 @@ fun JavaGroup() { ) { Spacer(Modifier.width(10.dp)) val minRam = SliderSwitch(label = "Minimum RAM", valueRange = 1..12).roundToInt() - val maxRam = SliderSwitch(label = "Maximum RAM:", valueRange = 1..12).roundToInt() + val maxRam = maxOf(minRam, SliderSwitch(label = "Maximum RAM:", valueRange = 1..12).roundToInt()) // Figure out way to handle this, probably storing via state or something state.clientSettings = ClientSettings(state.clientSettings.minecraft, JavaSettings(minRam, maxRam)) } diff --git a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/SliderSwitch.kt b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/SliderSwitch.kt index 483ecab..c596c92 100644 --- a/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/SliderSwitch.kt +++ b/src/main/kotlin/com/mineinabyss/launchy/ui/screens/settings/SliderSwitch.kt @@ -1,7 +1,10 @@ package com.mineinabyss.launchy.ui.screens.settings -import androidx.compose.foundation.layout.* -import androidx.compose.material.* +import androidx.compose.foundation.layout.width +import androidx.compose.material.LocalTextStyle +import androidx.compose.material.Slider +import androidx.compose.material.SliderDefaults +import androidx.compose.material.Text import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.* import androidx.compose.ui.Modifier @@ -10,12 +13,23 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import kotlin.math.roundToLong -@OptIn(ExperimentalMaterialApi::class) +@Composable +fun RamSlider( + label: String = "", + modifier: Modifier = Modifier, + valueRange: IntRange = 1..16, + minRam: Int? = null +) { + SliderSwitch(label, modifier, valueRange) + return +} + @Composable fun SliderSwitch( label: String = "", modifier: Modifier = Modifier, valueRange: IntRange = 1..16, + minRam: Float? = null ): Float { var sliderPosition by remember { mutableStateOf(2f) } var sliderPos by remember { mutableStateOf(sliderPosition.toString()) } @@ -27,7 +41,7 @@ fun SliderSwitch( modifier = modifier.width(100.dp), onValueChange = { println("$sliderPos $sliderPosition") - sliderPosition = sliderPos.toFloatOrNull() ?: sliderPosition + sliderPosition = minRam?.let { maxOf(it, (sliderPos.toFloatOrNull() ?: sliderPosition)) } ?: (sliderPos.toFloatOrNull() ?: sliderPosition) } ) // This is called too often, and should only be called when textfield triggers onValueChange but cant? not sure