Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/670/dpadjoystick #677

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class SettingsManager(private val context: Context, sharedPreferences: Lazy<Shar

suspend fun enableDeviceRumble() = booleanPreference(R.string.pref_key_enable_device_rumble, false)

suspend fun joinStickDpad() = booleanPreference(R.string.pref_key_join_stick_dpad, false)

suspend fun cacheSizeBytes() =
stringPreference(
R.string.pref_key_max_cache_size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ private fun InputSettings(navController: NavController) {
},
items = stringListResource(R.array.pref_key_haptic_feedback_mode_display_names),
)
LemuroidSettingsSwitch(
state = booleanPreferenceState(R.string.pref_key_join_stick_dpad, false),
title = { Text(text = stringResource(id = R.string.settings_title_join_stick_dpad)) },
subtitle = { Text(text = stringResource(id = R.string.settings_summary_join_stick_dpad)) },
)
LemuroidSettingsMenuLink(
title = { Text(text = stringResource(id = R.string.settings_title_gamepad_settings)) },
subtitle = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import com.swordfish.lemuroid.lib.game.GameLoaderException
import com.swordfish.lemuroid.lib.library.ExposedSetting
import com.swordfish.lemuroid.lib.library.GameSystem
import com.swordfish.lemuroid.lib.library.SystemCoreConfig
import com.swordfish.lemuroid.lib.library.SystemID
import com.swordfish.lemuroid.lib.library.db.entity.Game
import com.swordfish.lemuroid.lib.saves.IncompatibleStateException
import com.swordfish.lemuroid.lib.saves.SaveState
Expand Down Expand Up @@ -154,6 +155,8 @@ abstract class BaseGameActivity : ImmersiveActivity() {
private val loadingMessageStateFlow = MutableStateFlow("")
private val controllerConfigsState = MutableStateFlow<Map<Int, ControllerConfig>>(mapOf())

private var joinStickAndDPADifSupported = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_game)
Expand All @@ -172,6 +175,7 @@ abstract class BaseGameActivity : ImmersiveActivity() {
system = GameSystem.findById(game.systemId)

lifecycleScope.launch {
joinStickAndDPADifSupported = settingsManager.joinStickDpad()
loadGame()
}

Expand Down Expand Up @@ -655,7 +659,22 @@ abstract class BaseGameActivity : ImmersiveActivity() {
if (port < 0) return
when (event.source) {
InputDevice.SOURCE_JOYSTICK -> {
if (controllerConfigsState.value[port]?.mergeDPADAndLeftStickEvents == true) {
var allowJoypad = controllerConfigsState.value[port]?.mergeDPADAndLeftStickEvents ?: false

if(joinStickAndDPADifSupported) {
allowJoypad = when(system.id) {
SystemID.NES -> true
SystemID.SNES -> true
SystemID.GENESIS -> true
SystemID.GB -> true
SystemID.GBC -> true
SystemID.GBA -> true
SystemID.NDS -> true
else -> allowJoypad
}
}

if (allowJoypad) {
sendMergedMotionEvents(event, port)
} else {
sendSeparateMotionEvents(event, port)
Expand Down
1 change: 1 addition & 0 deletions lemuroid-app/src/main/res/values/keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<string name="pref_key_low_latency_audio" translatable="false">low_latency_audio</string>
<string name="pref_key_enable_rumble" translatable="false">enable_rumble</string>
<string name="pref_key_enable_device_rumble" translatable="false">enable_device_rumble</string>
<string name="pref_key_join_stick_dpad" translatable="false">pref_key_join_stick_dpad</string>
<string name="pref_key_max_cache_size" translatable="false">max_cache_size_bytes</string>
<string name="pref_key_allow_direct_game_load" translatable="false">allow_direct_game_load</string>

Expand Down
3 changes: 3 additions & 0 deletions lemuroid-app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@
<string name="settings_save_sync_include_states">Sync states</string>
<string name="settings_save_sync_include_states_description">More convenient, but heavier and less reliable. Choose which cores/systems you want to sync</string>

<string name="settings_title_join_stick_dpad">D-Pad Emulation</string>
<string name="settings_summary_join_stick_dpad">Use joystick as D-Pad for systems that do not use a joystick.</string>

<string name="game_context_menu_add_to_favorites">Add to favorites</string>
<string name="game_context_menu_remove_from_favorites">Remove from favorites</string>
<string name="game_context_menu_resume">Resume</string>
Expand Down