[Android] Add Combo Button (#1244)

* Base starting commit for Feature Impl

* Base commit 2 (off of closed PR, impl details of the actual button will likely be different.)

* Added Combo Button Bool setting to use for later implementation.

* Added Combo Button Submenu and associated strings. Need to implement button displaying for user to interact with.

* Added layout file for combo settings for potential impl

* Removed combo settings as it wasn't liked. Starting Multi Choice impl

* Added Multi Choice Impl. Need to Refactor OnClick for MultiChoice and debug Impl when adding combo button.

* Change List<> in Multi Files to be MutableSet<> to allow adds while prevent potential duplicates. Finished primary multi choice backend impl.

* used correct lisencing procedure for multi files

* Added code in arrays.xml to display the buttons.
This code has the buttons display but clicking on them crashes the app. Will debug further.
Also replaced setSelectedValues with add and remove SelectedValue for clarity purposes.

* Deleted Int Combo Value array in arrays.xml as it was not needed. Able to Click multiple buttons at once but unchecking them causes app to crash. (within the MultiChoice OnClick for SettingsAdapter.kt)

Also debating whether to remove the normal MultiChoice addition as it wasn't added.

* Attempt to deal with merge conflicts

* Moved OnSettingChange after I add or remove selected vals to fix crashing issue.

* Displayed combo button in both landscape and portrait

* WIP on Button Impl, made combo button setting run time editable

* Changed the combo_key string into button_combo, added functionality (impl could be better), added combo key as an input bindable setting within the buttons tab

* Moved Combo Settings into just controls instead of having its own submenu

* Made ComboHelper code more readable and added the key setting to be toggleable in game

* Edited Layout integers of combo button. Made Combo Button display properly in normal portrait mode.

* Code Cleanup and Start of Reimplementation based off #1430

* Progress commit for better impl, need to have the pop up menu show up to select buttons

* Code cleanup and bug fix to properly map values.

* Deleted Multi String Setting, added basic error handling, added comment explaining hardcoded size

* Changed Combo Button to be a HotKey, changed impl to be default multi choice, and removed StringMultiChoice details

* Remove Commented Code

* Changed ComboHelper.kt to use Native Button ints, removed rest of initial implementation traces

* Commented out debug logging, added back missing TODO statement regarding magic numbers

* Cleanup

* Changed Combo Key to Combo Button in kotlin code (will need to test)

* Trying to integrate combo button as a SettingsKey setting. Running into issues with malformed/missing key

* latest changes (added setting to default ini). Still debugging file issue

* added possible fix to touchscreen latency issue, will need to test

* Reverted MultiChoice code to original, removed unused strings and variables and ensured consistent naming, fixed latency issues with button,

* reverted int list setting change as its no longer needed.

* `combo_buttons` --> `combo_button_buttons`

* default_ini.h: Adjust ini comment for combo_button_buttons

* Fix "Reset Overlay" not affecting combo button

* Better center default position of combo button in portrait layout

* `combo_button_options` --> `combo_button_settings`

Better reflects string content

* Last-minute minor string nitpicks

---------

Co-authored-by: OpenSauce <opensauce04@gmail.com>
This commit is contained in:
ADAS2024 2026-07-04 10:11:06 -04:00 committed by GitHub
parent 8c4e8b77b2
commit 209173fa0c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 217 additions and 7 deletions

View File

@ -241,6 +241,7 @@ if (ANDROID)
"screen_orientation"
"performance_overlay_position"
"enable_secondary_display"
"combo_button_buttons"
)
string(REPLACE "_" "_1" KEY_JNI_ESCAPED ${KEY})
set(SETTING_KEY_LIST "${SETTING_KEY_LIST}\n\"${KEY}\",")

View File

@ -12,5 +12,6 @@ enum class Hotkey(val button: Int) {
QUICKSAVE(10005),
QUICKLOAD(10006),
TURBO_LIMIT(10007),
ENABLE(10008)
ENABLE(10008),
COMBO_BUTTON(10009)
}

View File

@ -14,6 +14,7 @@ import org.citra.citra_emu.R
import org.citra.citra_emu.display.ScreenAdjustmentUtil
import org.citra.citra_emu.features.settings.model.Settings
import org.citra.citra_emu.features.settings.model.view.InputBindingSetting
import org.citra.citra_emu.utils.ComboHelper
import org.citra.citra_emu.utils.EmulationLifecycleUtil
import org.citra.citra_emu.utils.TurboHelper
@ -71,12 +72,17 @@ class HotkeyUtility(
var handled = false
val buttonSet = InputBindingSetting.getButtonSet(keyEvent)
val thisKeyIsEnableButton = buttonSet.contains(Hotkey.ENABLE.button)
val thisKeyIsComboButton = buttonSet.contains(Hotkey.COMBO_BUTTON.button)
val thisKeyIsHotkey =
!thisKeyIsEnableButton && Hotkey.entries.any { buttonSet.contains(it.button) }
if (thisKeyIsEnableButton) {
handled = true
hotkeyIsEnabled = false
}
if (thisKeyIsComboButton) {
ComboHelper.comboActivate(NativeLibrary.ButtonState.RELEASED)
handled = true
}
for (button in buttonSet) {
// this is a hotkey button
@ -142,6 +148,10 @@ class HotkeyUtility(
).show()
}
Hotkey.COMBO_BUTTON.button -> {
ComboHelper.comboActivate(NativeLibrary.ButtonState.PRESSED)
}
else -> {}
}
hotkeyIsPressed = true

View File

@ -143,4 +143,5 @@ object SettingKeys {
external fun screen_orientation(): String
external fun performance_overlay_position(): String
external fun enable_secondary_display(): String
external fun combo_button_buttons(): String
}

View File

@ -18,6 +18,16 @@ enum class IntListSetting(
Settings.SECTION_LAYOUT,
listOf(0, 1, 2, 3, 4, 5),
canBeEmpty = false
),
/**
* Combo Buttons will be given options on MultiChoice setting initialization. This just makes selections empty by default.
*/
COMBO_BUTTON_BUTTONS(
SettingKeys.combo_button_buttons(),
Settings.SECTION_CONTROLS,
listOf(),
canBeEmpty = true
);
private var backingList: List<Int> = defaultValue

View File

@ -142,6 +142,7 @@ class Settings {
const val HOTKEY_QUICKSAVE = "hotkey_quickload"
const val HOTKEY_QUICKLOAD = "hotkey_quickpause"
const val HOTKEY_TURBO_LIMIT = "hotkey_turbo_limit"
const val HOTKEY_BUTTON_COMBO = "hotkey_button_combo"
val buttonKeys = listOf(
KEY_BUTTON_A,
@ -209,7 +210,8 @@ class Settings {
HOTKEY_PAUSE_OR_RESUME,
HOTKEY_QUICKSAVE,
HOTKEY_QUICKLOAD,
HOTKEY_TURBO_LIMIT
HOTKEY_TURBO_LIMIT,
HOTKEY_BUTTON_COMBO
)
val hotkeyTitles = listOf(
R.string.controller_hotkey_enable_button,
@ -219,7 +221,8 @@ class Settings {
R.string.emulation_toggle_pause,
R.string.emulation_quicksave,
R.string.emulation_quickload,
R.string.turbo_limit_hotkey
R.string.turbo_limit_hotkey,
R.string.button_combo
)
// TODO: Move these in with the other setting keys in GenerateSettingKeys.cmake

View File

@ -127,6 +127,7 @@ class InputBindingSetting(val abstractSetting: AbstractSetting, titleId: Int) :
Settings.HOTKEY_QUICKSAVE -> Hotkey.QUICKSAVE.button
Settings.HOTKEY_QUICKLOAD -> Hotkey.QUICKLOAD.button
Settings.HOTKEY_TURBO_LIMIT -> Hotkey.TURBO_LIMIT.button
Settings.HOTKEY_BUTTON_COMBO -> Hotkey.COMBO_BUTTON.button
else -> -1
}

View File

@ -799,6 +799,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
private fun addControlsSettings(sl: ArrayList<SettingsItem>) {
settingsActivity.setToolbarTitle(settingsActivity.getString(R.string.preferences_controls))
sl.apply {
add(
RunnableSetting(
@ -810,6 +811,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
onLongClick = { settingsAdapter.onLongClickAutoMap() }
)
)
add(HeaderSetting(R.string.generic_buttons))
Settings.buttonKeys.forEachIndexed { i: Int, key: String ->
val button = getInputObject(key)
@ -860,6 +862,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
val button = getInputObject(key)
add(InputBindingSetting(button, Settings.hotkeyTitles[i]))
}
add(HeaderSetting(R.string.miscellaneous))
add(
SwitchSetting(
@ -870,6 +873,18 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
BooleanSetting.USE_ARTIC_BASE_CONTROLLER.defaultValue
)
)
add(
MultiChoiceSetting(
IntListSetting.COMBO_BUTTON_BUTTONS,
R.string.combo_button_settings,
R.string.combo_button_settings_description,
R.array.comboOptions,
R.array.comboOptionValues,
IntListSetting.COMBO_BUTTON_BUTTONS.key,
IntListSetting.COMBO_BUTTON_BUTTONS.defaultValue
)
)
}
}

View File

@ -69,6 +69,7 @@ import org.citra.citra_emu.display.PortraitScreenLayout
import org.citra.citra_emu.display.ScreenAdjustmentUtil
import org.citra.citra_emu.display.ScreenLayout
import org.citra.citra_emu.display.SecondaryDisplayLayout
import org.citra.citra_emu.features.hotkeys.Hotkey
import org.citra.citra_emu.features.settings.model.BooleanSetting
import org.citra.citra_emu.features.settings.model.IntSetting
import org.citra.citra_emu.features.settings.model.SettingsViewModel
@ -862,6 +863,11 @@ class EmulationFragment :
true
}
R.id.menu_emulation_adjust_scale_button_combo -> {
showAdjustScaleDialog("controlScale-" + Hotkey.COMBO_BUTTON.button)
true
}
R.id.menu_emulation_adjust_opacity -> {
showAdjustOpacityDialog()
true
@ -1241,13 +1247,13 @@ class EmulationFragment :
private fun showToggleControlsDialog() {
val editor = preferences.edit()
val enabledButtons = BooleanArray(16)
val enabledButtons = BooleanArray(17)
enabledButtons.forEachIndexed { i: Int, _: Boolean ->
// Buttons that are disabled by default
var defaultValue = true
when (i) {
// TODO: Remove these magic numbers
6, 7, 12, 13, 14, 15 -> defaultValue = false
6, 7, 12, 13, 14, 15, 16 -> defaultValue = false
}
enabledButtons[i] = preferences.getBoolean("buttonToggle$i", defaultValue)
}
@ -1415,6 +1421,7 @@ class EmulationFragment :
resetScale("controlScale-" + NativeLibrary.ButtonType.STICK_C)
resetScale("controlScale-" + NativeLibrary.ButtonType.BUTTON_HOME)
resetScale("controlScale-" + NativeLibrary.ButtonType.BUTTON_SWAP)
resetScale("controlScale-" + Hotkey.COMBO_BUTTON.button)
binding.surfaceInputOverlay.refreshControls()
}
@ -1442,10 +1449,11 @@ class EmulationFragment :
.apply()
val editor = preferences.edit()
for (i in 0 until 16) {
// TODO: This code sucks balls. We need to do this differently. -OS
for (i in 0 until 17) {
var defaultValue = true
when (i) {
6, 7, 12, 13, 14, 15 -> defaultValue = false
6, 7, 12, 13, 14, 15, 16 -> defaultValue = false
}
editor.putBoolean("buttonToggle$i", defaultValue)
}

View File

@ -26,6 +26,8 @@ import kotlin.math.min
import org.citra.citra_emu.CitraApplication
import org.citra.citra_emu.NativeLibrary
import org.citra.citra_emu.R
import org.citra.citra_emu.features.hotkeys.Hotkey
import org.citra.citra_emu.utils.ComboHelper
import org.citra.citra_emu.utils.EmulationMenuSettings
import org.citra.citra_emu.utils.TurboHelper
@ -184,6 +186,8 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) :
button.status == NativeLibrary.ButtonState.PRESSED
) {
TurboHelper.toggleTurbo(true)
} else if (button.id == Hotkey.COMBO_BUTTON.button) {
ComboHelper.comboActivate(button.status)
}
NativeLibrary.onGamePadEvent(
@ -593,6 +597,18 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) :
)
)
}
if (preferences.getBoolean("buttonToggle16", false)) {
overlayButtons.add(
initializeOverlayButton(
context,
R.drawable.button_combo,
R.drawable.button_combo_pressed,
Hotkey.COMBO_BUTTON.button,
orientation
)
)
}
}
fun refreshControls() {
@ -806,6 +822,14 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) :
NativeLibrary.ButtonType.BUTTON_TURBO.toString() + "-Y",
resources.getInteger(R.integer.N3DS_BUTTON_TURBO_Y).toFloat() / 1000 * maxY
)
.putFloat(
Hotkey.COMBO_BUTTON.button.toString() + "-X",
resources.getInteger(R.integer.N3DS_BUTTON_COMBO_X).toFloat() / 1000 * maxX
)
.putFloat(
Hotkey.COMBO_BUTTON.button.toString() + "-Y",
resources.getInteger(R.integer.N3DS_BUTTON_COMBO_Y).toFloat() / 1000 * maxY
)
.apply()
}
@ -957,6 +981,14 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) :
NativeLibrary.ButtonType.BUTTON_TURBO.toString() + portrait + "-Y",
resources.getInteger(R.integer.N3DS_BUTTON_TURBO_PORTRAIT_Y).toFloat() / 1000 * maxY
)
.putFloat(
Hotkey.COMBO_BUTTON.button.toString() + portrait + "-X",
resources.getInteger(R.integer.N3DS_BUTTON_COMBO_PORTRAIT_X).toFloat() / 1000 * maxX
)
.putFloat(
Hotkey.COMBO_BUTTON.button.toString() + portrait + "-Y",
resources.getInteger(R.integer.N3DS_BUTTON_COMBO_PORTRAIT_Y).toFloat() / 1000 * maxY
)
.apply()
}

View File

@ -0,0 +1,26 @@
// Copyright Citra Emulator Project / Azahar Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
package org.citra.citra_emu.utils
import org.citra.citra_emu.NativeLibrary
import org.citra.citra_emu.features.settings.model.IntListSetting
object ComboHelper {
fun comboActivate(buttonStatus: Int) {
val comboArray = IntListSetting.COMBO_BUTTON_BUTTONS.list
for (nativeButton in comboArray) {
if (nativeButton == -1) {
// We don't want to parse any bad inputs here so we continue loop
continue
} else {
NativeLibrary.onGamePadEvent(
NativeLibrary.TOUCHSCREEN_DEVICE,
nativeButton,
buttonStatus
)
}
}
}
}

View File

@ -80,6 +80,9 @@ static const char* android_config_default_file_content = (BOOST_HANA_STRING(R"(
# Use Artic Controller when connected to Artic Base Server. (Default 0)
)") DECLARE_KEY(use_artic_base_controller) BOOST_HANA_STRING(R"(
# List of buttons which will be triggered by the combo button. (Default [] or empty)
)") DECLARE_KEY(combo_button_buttons) BOOST_HANA_STRING(R"(
[Core]
# Whether to use the Just-In-Time (JIT) compiler for CPU emulation
# 0: Interpreter (slow), 1 (default): JIT (fast)

View File

@ -0,0 +1,32 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="100dp"
android:height="100dp"
android:viewportWidth="99.27"
android:viewportHeight="99.27">
<!-- Outer circle -->
<path
android:fillAlpha="0.5"
android:fillColor="#eaeaea"
android:pathData="M49.64,49.64m-49.64,0a49.64,49.64 0,1 1,99.28 0a49.64,49.64 0,1 1,-99.28 0"
android:strokeAlpha="0.5" />
<!-- Centered blocky "C" icon -->
<path
android:fillAlpha="0.75"
android:fillColor="#FF000000"
android:pathData="M42,30
H62
V40
H47
V60
H62
V70
H42
V60
H37
V40
H42
Z"
android:strokeAlpha="0.75" />
</vector>

View File

@ -0,0 +1,28 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="100dp"
android:height="100dp"
android:viewportWidth="99.27"
android:viewportHeight="99.27">
<path
android:fillAlpha="0.5"
android:fillColor="#151515"
android:pathData="M49.64,49.64m-49.64,0a49.64,49.64 0,1 1,99.28 0a49.64,49.64 0,1 1,-99.28 0"
android:strokeAlpha="0.5" />
<path
android:fillAlpha="0.75"
android:fillColor="#fff"
android:pathData="M42,30
H62
V40
H47
V60
H62
V70
H42
V60
H37
V40
H42
Z"
android:strokeAlpha="0.75" />
</vector>

View File

@ -79,6 +79,9 @@
<item
android:id="@+id/menu_emulation_adjust_scale_button_swap"
android:title="@string/button_swap" />
<item
android:id="@+id/menu_emulation_adjust_scale_button_combo"
android:title="@string/button_combo" />
</menu>
</item>

View File

@ -188,8 +188,37 @@
<item>@string/button_home</item>
<item>@string/button_swap</item>
<item>@string/button_turbo</item>
<item>@string/button_combo</item>
</string-array>
<string-array name="comboOptions">
<item>@string/button_a</item>
<item>@string/button_b</item>
<item>@string/button_x</item>
<item>@string/button_y</item>
<item>@string/button_l</item>
<item>@string/button_r</item>
<item>@string/button_zl</item>
<item>@string/button_zr</item>
<item>@string/button_start</item>
<item>@string/button_select</item>
</string-array>
<!-- Ints refer to button values in NativeLibrary -->
<integer-array name="comboOptionValues">
<item>700</item>
<item>701</item>
<item>702</item>
<item>703</item>
<item>773</item>
<item>774</item>
<item>707</item>
<item>708</item>
<item>704</item>
<item>705</item>
</integer-array>
<string-array name="cameraImageSourceNames">
<item>@string/blank</item>
<item>@string/still_image</item>

View File

@ -35,6 +35,8 @@
<integer name="N3DS_BUTTON_SWAP_Y">850</integer>
<integer name="N3DS_BUTTON_TURBO_X">630</integer>
<integer name="N3DS_BUTTON_TURBO_Y">850</integer>
<integer name="N3DS_BUTTON_COMBO_X">740</integer>
<integer name="N3DS_BUTTON_COMBO_Y">480</integer>
<!-- Default N3DS portrait layout -->
<integer name="N3DS_BUTTON_A_PORTRAIT_X">810</integer>
@ -69,5 +71,7 @@
<integer name="N3DS_BUTTON_SWAP_PORTRAIT_Y">675</integer>
<integer name="N3DS_BUTTON_TURBO_PORTRAIT_X">453</integer>
<integer name="N3DS_BUTTON_TURBO_PORTRAIT_Y">720</integer>
<integer name="N3DS_BUTTON_COMBO_PORTRAIT_X">450</integer>
<integer name="N3DS_BUTTON_COMBO_PORTRAIT_Y">925</integer>
</resources>

View File

@ -156,6 +156,7 @@
<string name="button_home">HOME</string>
<string name="button_swap">Swap Screens</string>
<string name="button_turbo">Turbo</string>
<string name="button_combo">Combo Button</string>
<string name="button_x" translatable="false">X</string>
<string name="button_y" translatable="false">Y</string>
<string name="button_l" translatable="false">L</string>
@ -167,6 +168,8 @@
<string name="turbo_limit_hotkey">Turbo Speed</string>
<string name="turbo_enabled_toast">Turbo Speed Enabled</string>
<string name="turbo_disabled_toast">Turbo Speed Disabled</string>
<string name="combo_button_settings">Configure Combo Button</string>
<string name="combo_button_settings_description">Select which buttons are triggered by the Combo Button.</string>
<!-- System files strings -->
<string name="setup_system_files">System Files</string>