This commit is contained in:
ADAS2024 2026-05-31 09:54:57 +03:00 committed by GitHub
commit 7868094a47
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 226 additions and 21 deletions

View file

@ -238,6 +238,7 @@ if (ANDROID)
"android_hide_images"
"screen_orientation"
"performance_overlay_position"
"combo_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

@ -13,6 +13,7 @@ import org.citra.citra_emu.NativeLibrary
import org.citra.citra_emu.R
import org.citra.citra_emu.utils.EmulationLifecycleUtil
import org.citra.citra_emu.utils.TurboHelper
import org.citra.citra_emu.utils.ComboHelper
import org.citra.citra_emu.display.ScreenAdjustmentUtil
import org.citra.citra_emu.features.settings.model.view.InputBindingSetting
import org.citra.citra_emu.features.settings.model.Settings
@ -81,6 +82,7 @@ class HotkeyUtility(
// this is a hotkey button
if (hotkeyButtons.contains(button)) {
currentlyPressedButtons.remove(button)
handleHotkeyRelease(button)
if (!currentlyPressedButtons.any { hotkeyButtons.contains(it) }) {
// all hotkeys are no longer pressed
hotkeyIsPressed = false
@ -106,6 +108,14 @@ class HotkeyUtility(
return handled
}
fun handleHotkeyRelease(bindedButton: Int): Boolean {
// Log.debug("Handling hotkey button release: " + bindedButton)
if (bindedButton == Hotkey.COMBO_BUTTON.button) {
ComboHelper.comboActivate(NativeLibrary.ButtonState.RELEASED)
}
return true
}
fun handleHotkey(bindedButton: Int): Boolean {
when (bindedButton) {
Hotkey.SWAP_SCREEN.button -> screenAdjustmentUtil.swapScreen()
@ -121,7 +131,6 @@ class HotkeyUtility(
Toast.LENGTH_SHORT
).show()
}
Hotkey.QUICKLOAD.button -> {
val wasLoaded = NativeLibrary.loadStateIfAvailable(NativeLibrary.QUICKSAVE_SLOT)
val stringRes = if (wasLoaded) {
@ -135,6 +144,9 @@ class HotkeyUtility(
Toast.LENGTH_SHORT
).show()
}
Hotkey.COMBO_BUTTON.button -> {
ComboHelper.comboActivate(NativeLibrary.ButtonState.PRESSED)
}
else -> {}
}

View file

@ -141,4 +141,5 @@ object SettingKeys {
external fun android_hide_images(): String
external fun screen_orientation(): String
external fun performance_overlay_position(): String
external fun combo_buttons(): String
}

View file

@ -4,6 +4,8 @@
package org.citra.citra_emu.features.settings.model
import org.citra.citra_emu.CitraApplication
import org.citra.citra_emu.R
import org.citra.citra_emu.features.settings.SettingKeys
enum class IntListSetting(
@ -13,8 +15,11 @@ enum class IntListSetting(
val canBeEmpty: Boolean = true
) : AbstractListSetting<Int> {
LAYOUTS_TO_CYCLE(SettingKeys.layouts_to_cycle(), Settings.SECTION_LAYOUT, listOf(0, 1, 2, 3, 4, 5), canBeEmpty = false);
LAYOUTS_TO_CYCLE(SettingKeys.layouts_to_cycle(), Settings.SECTION_LAYOUT, listOf(0, 1, 2, 3, 4, 5), canBeEmpty = false),
COMBO_BUTTONS(SettingKeys.combo_buttons(), Settings.SECTION_CONTROLS,
CitraApplication.appContext.resources.getIntArray(R.array.comboOptionValues).toCollection(ArrayList()),
canBeEmpty = true);
private var backingList: List<Int> = defaultValue
private var lastValidList : List<Int> = defaultValue

View file

@ -130,6 +130,7 @@ class Settings {
const val KEY_BUTTON_R = "button_r"
const val KEY_BUTTON_ZL = "button_zl"
const val KEY_BUTTON_ZR = "button_zr"
const val KEY_BUTTON_COMBO = "button_combo"
const val KEY_CIRCLEPAD_AXIS_VERTICAL = "circlepad_axis_vertical"
const val KEY_CIRCLEPAD_AXIS_HORIZONTAL = "circlepad_axis_horizontal"
const val KEY_CSTICK_AXIS_VERTICAL = "cstick_axis_vertical"
@ -144,6 +145,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,
@ -211,7 +213,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,
@ -221,7 +224,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
@ -250,4 +254,4 @@ class Settings {
)
}
}
}
}

View file

@ -137,6 +137,7 @@ class InputBindingSetting(
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

@ -44,6 +44,7 @@ import org.citra.citra_emu.features.settings.model.FloatSetting
import org.citra.citra_emu.features.settings.model.IntListSetting
import org.citra.citra_emu.features.settings.model.ScaledFloatSetting
import org.citra.citra_emu.features.settings.model.AbstractShortSetting
import org.citra.citra_emu.features.settings.model.Settings
import org.citra.citra_emu.features.settings.model.view.DateTimeSetting
import org.citra.citra_emu.features.settings.model.view.InputBindingSetting
import org.citra.citra_emu.features.settings.model.view.SettingsItem
@ -571,15 +572,20 @@ class SettingsAdapter(
//onclick for multichoice
override fun onClick(dialog: DialogInterface?, which: Int, isChecked: Boolean) {
val mcsetting = clickedItem as? MultiChoiceSetting
mcsetting?.let {
val value = getValueForMultiChoiceSelection(it, which)
if (it.selectedValues.contains(value) != isChecked) {
val setting = it.setSelectedValue((if (isChecked) it.selectedValues + value else it.selectedValues - value).sorted())
fragmentView?.putSetting(setting)
fragmentView?.onSettingChanged()
when (clickedItem) {
is MultiChoiceSetting -> {
val mcsetting = clickedItem as? MultiChoiceSetting
mcsetting?.let {
val value = getValueForMultiChoiceSelection(it, which)
if (it.selectedValues.contains(value) != isChecked) {
val setting =
it.setSelectedValue((if (isChecked) it.selectedValues + value else it.selectedValues - value).sorted())
fragmentView?.putSetting(setting)
fragmentView?.onSettingChanged()
}
fragmentView.loadSettingsList()
}
}
fragmentView.loadSettingsList()
}
}

View file

@ -14,7 +14,6 @@ import android.os.Build
import android.text.TextUtils
import androidx.preference.PreferenceManager
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.serialization.builtins.IntArraySerializer
import org.citra.citra_emu.CitraApplication
import org.citra.citra_emu.R
import org.citra.citra_emu.display.ScreenLayout
@ -787,6 +786,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(
@ -798,6 +798,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)
@ -838,6 +839,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
val button = getInputObject(key)
add(InputBindingSetting(button, Settings.hotkeyTitles[i]))
}
add(HeaderSetting(R.string.miscellaneous))
add(
SwitchSetting(
@ -848,6 +850,18 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
BooleanSetting.USE_ARTIC_BASE_CONTROLLER.defaultValue
)
)
add(
MultiChoiceSetting(
IntListSetting.COMBO_BUTTONS,
R.string.combo_key_options,
R.string.combo_key_description,
R.array.comboOptions,
R.array.comboOptionValues,
IntListSetting.COMBO_BUTTONS.key,
IntListSetting.COMBO_BUTTONS.defaultValue
)
)
}
}

View file

@ -258,7 +258,7 @@ object SettingsFile {
val intListSetting = IntListSetting.from(key)
if (intListSetting != null) {
intListSetting.list = value.split(", ").map { it.toInt() }
intListSetting.list = value.split(", ").mapNotNull { it.toIntOrNull() }
}
return null

View file

@ -67,9 +67,9 @@ import org.citra.citra_emu.databinding.FragmentEmulationBinding
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.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.Settings
import org.citra.citra_emu.features.settings.model.SettingsViewModel
import org.citra.citra_emu.features.settings.ui.SettingsActivity
import org.citra.citra_emu.features.settings.utils.SettingsFile
@ -78,7 +78,6 @@ import org.citra.citra_emu.utils.BuildUtil
import org.citra.citra_emu.utils.DirectoryInitialization
import org.citra.citra_emu.utils.DirectoryInitialization.DirectoryInitializationState
import org.citra.citra_emu.utils.EmulationMenuSettings
import org.citra.citra_emu.utils.FileUtil
import org.citra.citra_emu.utils.GameHelper
import org.citra.citra_emu.utils.GameIconUtils
import org.citra.citra_emu.utils.EmulationLifecycleUtil
@ -834,6 +833,11 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram
true
}
R.id.menu_emulation_adjust_scale_button_combo -> {
showAdjustScaleDialog("controlScale-" + Hotkey.COMBO_BUTTON.button)
true
}
R.id.menu_emulation_adjust_opacity -> {
showAdjustOpacityDialog()
true
@ -1051,13 +1055,13 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram
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)
}

View file

@ -24,8 +24,10 @@ import androidx.preference.PreferenceManager
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.EmulationMenuSettings
import org.citra.citra_emu.utils.TurboHelper
import org.citra.citra_emu.utils.ComboHelper
import java.lang.NullPointerException
import kotlin.math.min
@ -175,6 +177,9 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex
else if (button.id == NativeLibrary.ButtonType.BUTTON_TURBO && button.status == NativeLibrary.ButtonState.PRESSED) {
TurboHelper.toggleTurbo(true)
}
else if (button.id == Hotkey.COMBO_BUTTON.button && button.status == NativeLibrary.ButtonState.PRESSED) {
ComboHelper.comboActivate(NativeLibrary.ButtonState.PRESSED)
}
NativeLibrary.onGamePadEvent(
NativeLibrary.TouchScreenDevice,
@ -568,6 +573,18 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex
)
)
}
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() {
@ -781,6 +798,14 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex
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()
}
@ -932,6 +957,14 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex
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,22 @@
// 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_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.TouchScreenDevice, nativeButton, buttonStatus)
}
}
}
}

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

@ -181,8 +181,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">445</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 Key</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,10 @@
<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_key_enable">Enable Combo Button</string>
<string name="combo_key_options">Combo Key Settings</string>
<string name="combo_key_description">Enable and Change Combo Button Bindings.</string>
<string name="combo_key_submenu_description">Changes whether or not Combo Button can be displayed and used in game.</string>
<!-- System files strings -->
<string name="setup_system_files">System Files</string>