From 75f32ed2e5c4afe58d9f710391641e2dc3cbfc5c Mon Sep 17 00:00:00 2001 From: Ismael Date: Fri, 5 May 2023 08:50:58 +0200 Subject: [PATCH] added ExportCustomSettingsPreference --- .../ExportCustomSettingsPreference.kt | 78 +++++++++++++++++++ app/src/main/res/values/strings.xml | 2 + .../main/res/xml/custom_game_preferences.xml | 4 + 3 files changed, 84 insertions(+) create mode 100644 app/src/main/java/emu/skyline/preference/ExportCustomSettingsPreference.kt diff --git a/app/src/main/java/emu/skyline/preference/ExportCustomSettingsPreference.kt b/app/src/main/java/emu/skyline/preference/ExportCustomSettingsPreference.kt new file mode 100644 index 00000000..7c3cae5f --- /dev/null +++ b/app/src/main/java/emu/skyline/preference/ExportCustomSettingsPreference.kt @@ -0,0 +1,78 @@ +/* + * SPDX-License-Identifier: MPL-2.0 + * Copyright © 2023 Skyline Team and Contributors (https://github.com/skyline-emu/) + */ + +package emu.skyline.preference + +import android.content.Context +import android.util.AttributeSet +import androidx.preference.Preference +import com.google.android.material.dialog.MaterialAlertDialogBuilder +import android.content.ClipData +import android.content.ClipboardManager +import emu.skyline.settings.EmulationSettings + +/** + * Copies global emulation settings into the current shared preferences, showing a dialog to confirm the action + * This preference recreates the activity to update the UI after modifying shared preferences + */ +class ExportCustomSettingsPreference @JvmOverloads constructor(context : Context, attrs : AttributeSet? = null, defStyleAttr : Int = androidx.preference.R.attr.preferenceStyle) : Preference(context, attrs, defStyleAttr) { + + init { + setOnPreferenceClickListener { + var emulationSettings = EmulationSettings.forPrefName(preferenceManager.sharedPreferencesName) + + if (!emulationSettings.useCustomSettings) { + emulationSettings = EmulationSettings.global + } + + val systemIsDocked = emulationSettings.isDocked; + + val gpuDriver = emulationSettings.gpuDriver; + val gpuTripleBuffering = emulationSettings.forceTripleBuffering; + val gpuExecSlotCount = emulationSettings.executorSlotCountScale + val gpuExecFlushThreshold = emulationSettings.executorFlushThreshold; + val gpuDMI = emulationSettings.useDirectMemoryImport; + val gpuFreeGuestTextureMemory = emulationSettings.freeGuestTextureMemory; + val gpuDisableShaderCache = emulationSettings.disableShaderCache; + val gpuForceMaxGpuClocks = emulationSettings.forceMaxGpuClocks + + val hackFastGpuReadback = emulationSettings.enableFastGpuReadbackHack; + val hackFastReadbackWrite = emulationSettings.enableFastReadbackWrites; + val hackDisableSubgroupShuffle = emulationSettings.disableSubgroupShuffle; + + val settingsAsText = String.format( + """ + SYSTEM + - Docked: $systemIsDocked + + GPU + - Driver: $gpuDriver (executors: $gpuExecSlotCount slots, threshold of $gpuExecFlushThreshold) + - Triple buffering: $gpuTripleBuffering, DMI: $gpuDMI + - Max clocks: $gpuForceMaxGpuClocks, free guest texture memory: $gpuFreeGuestTextureMemory + - Disable shader cache: $gpuDisableShaderCache + + HACKS + - Fast GPU readback: $hackFastGpuReadback, fast readback writes $hackFastReadbackWrite + - Disable GPU subgroup shuffle: $hackDisableSubgroupShuffle + """.trimIndent() + ) + + MaterialAlertDialogBuilder(context) + .setTitle(title) + .setMessage(settingsAsText) + .setPositiveButton(android.R.string.copy) { _, _ -> + // Copy the current settings as text to the system clipboard + val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager + val clip = ClipData.newPlainText("label", settingsAsText) + clipboard.setPrimaryClip(clip) + + } + .setNegativeButton(android.R.string.ok, null) + .show() + + true + } + } +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e5ec230a..21ff02cb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -64,6 +64,8 @@ Enable Custom Settings Custom settings are enabled for this game Custom settings are disabled for this game + Export custom settings to text + Copy a text with your current settings to share online Reset Custom Settings Reset custom settings to the default values Are you sure you want to reset all settings to the default values? Current settings will be lost diff --git a/app/src/main/res/xml/custom_game_preferences.xml b/app/src/main/res/xml/custom_game_preferences.xml index 3250b2e3..fca26c18 100644 --- a/app/src/main/res/xml/custom_game_preferences.xml +++ b/app/src/main/res/xml/custom_game_preferences.xml @@ -9,6 +9,10 @@ android:summaryOn="@string/use_custom_settings_desc_on" app:key="use_custom_settings" app:title="@string/use_custom_settings" /> +