mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2024-12-28 10:41:52 +01:00
Android overlay: possibility to adjust the scale of individual buttons (#69)
* Can adjust the scale of each button individually 4x --------- Co-authored-by: João Vitor Polverari <69534455+Polarzincomfrio@users.noreply.github.com>
This commit is contained in:
parent
63c15b1467
commit
2733189c0d
@ -619,8 +619,88 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_emulation_adjust_scale_reset_all -> {
|
||||
resetAllScales()
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_emulation_adjust_scale -> {
|
||||
showAdjustScaleDialog()
|
||||
showAdjustScaleDialog("controlScale")
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_emulation_adjust_scale_button_a -> {
|
||||
showAdjustScaleDialog("controlScale-" + NativeLibrary.ButtonType.BUTTON_A)
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_emulation_adjust_scale_button_b -> {
|
||||
showAdjustScaleDialog("controlScale-" + NativeLibrary.ButtonType.BUTTON_B)
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_emulation_adjust_scale_button_x -> {
|
||||
showAdjustScaleDialog("controlScale-" + NativeLibrary.ButtonType.BUTTON_X)
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_emulation_adjust_scale_button_y -> {
|
||||
showAdjustScaleDialog("controlScale-" + NativeLibrary.ButtonType.BUTTON_Y)
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_emulation_adjust_scale_button_l -> {
|
||||
showAdjustScaleDialog("controlScale-" + NativeLibrary.ButtonType.TRIGGER_L)
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_emulation_adjust_scale_button_r -> {
|
||||
showAdjustScaleDialog("controlScale-" + NativeLibrary.ButtonType.TRIGGER_R)
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_emulation_adjust_scale_button_zl -> {
|
||||
showAdjustScaleDialog("controlScale-" + NativeLibrary.ButtonType.BUTTON_ZL)
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_emulation_adjust_scale_button_zr -> {
|
||||
showAdjustScaleDialog("controlScale-" + NativeLibrary.ButtonType.BUTTON_ZR)
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_emulation_adjust_scale_button_start -> {
|
||||
showAdjustScaleDialog("controlScale-" + NativeLibrary.ButtonType.BUTTON_START)
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_emulation_adjust_scale_button_select -> {
|
||||
showAdjustScaleDialog("controlScale-" + NativeLibrary.ButtonType.BUTTON_SELECT)
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_emulation_adjust_scale_controller_dpad -> {
|
||||
showAdjustScaleDialog("controlScale-" + NativeLibrary.ButtonType.DPAD)
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_emulation_adjust_scale_controller_circlepad -> {
|
||||
showAdjustScaleDialog("controlScale-" + NativeLibrary.ButtonType.STICK_LEFT)
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_emulation_adjust_scale_controller_c -> {
|
||||
showAdjustScaleDialog("controlScale-" + NativeLibrary.ButtonType.STICK_C)
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_emulation_adjust_scale_button_home -> {
|
||||
showAdjustScaleDialog("controlScale-" + NativeLibrary.ButtonType.BUTTON_HOME)
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_emulation_adjust_scale_button_swap -> {
|
||||
showAdjustScaleDialog("controlScale-" + NativeLibrary.ButtonType.BUTTON_SWAP)
|
||||
true
|
||||
}
|
||||
|
||||
@ -774,16 +854,16 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun showAdjustScaleDialog() {
|
||||
private fun showAdjustScaleDialog(target: String) {
|
||||
val sliderBinding = DialogSliderBinding.inflate(layoutInflater)
|
||||
|
||||
sliderBinding.apply {
|
||||
slider.valueTo = 150f
|
||||
slider.value = preferences.getInt("controlScale", 50).toFloat()
|
||||
slider.value = preferences.getInt(target, 50).toFloat()
|
||||
slider.addOnChangeListener(
|
||||
Slider.OnChangeListener { slider: Slider, progress: Float, _: Boolean ->
|
||||
textValue.text = (progress.toInt() + 50).toString()
|
||||
setControlScale(slider.value.toInt())
|
||||
setControlScale(slider.value.toInt(), target)
|
||||
})
|
||||
textValue.text = (sliderBinding.slider.value.toInt() + 50).toString()
|
||||
textUnits.text = "%"
|
||||
@ -794,13 +874,13 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram
|
||||
.setTitle(R.string.emulation_control_scale)
|
||||
.setView(sliderBinding.root)
|
||||
.setNegativeButton(android.R.string.cancel) { _: DialogInterface?, _: Int ->
|
||||
setControlScale(previousProgress)
|
||||
setControlScale(previousProgress, target)
|
||||
}
|
||||
.setPositiveButton(android.R.string.ok) { _: DialogInterface?, _: Int ->
|
||||
setControlScale(sliderBinding.slider.value.toInt())
|
||||
setControlScale(sliderBinding.slider.value.toInt(), target)
|
||||
}
|
||||
.setNeutralButton(R.string.slider_default) { _: DialogInterface?, _: Int ->
|
||||
setControlScale(50)
|
||||
setControlScale(50, target)
|
||||
}
|
||||
.show()
|
||||
}
|
||||
@ -836,13 +916,40 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun setControlScale(scale: Int) {
|
||||
private fun setControlScale(scale: Int, target: String) {
|
||||
preferences.edit()
|
||||
.putInt("controlScale", scale)
|
||||
.putInt(target, scale)
|
||||
.apply()
|
||||
binding.surfaceInputOverlay.refreshControls()
|
||||
}
|
||||
|
||||
private fun resetScale(target: String) {
|
||||
preferences.edit().putInt(
|
||||
target,
|
||||
50
|
||||
).apply()
|
||||
}
|
||||
|
||||
private fun resetAllScales() {
|
||||
resetScale("controlScale")
|
||||
resetScale("controlScale-" + NativeLibrary.ButtonType.BUTTON_A)
|
||||
resetScale("controlScale-" + NativeLibrary.ButtonType.BUTTON_B)
|
||||
resetScale("controlScale-" + NativeLibrary.ButtonType.BUTTON_X)
|
||||
resetScale("controlScale-" + NativeLibrary.ButtonType.BUTTON_Y)
|
||||
resetScale("controlScale-" + NativeLibrary.ButtonType.TRIGGER_L)
|
||||
resetScale("controlScale-" + NativeLibrary.ButtonType.TRIGGER_R)
|
||||
resetScale("controlScale-" + NativeLibrary.ButtonType.BUTTON_ZL)
|
||||
resetScale("controlScale-" + NativeLibrary.ButtonType.BUTTON_ZR)
|
||||
resetScale("controlScale-" + NativeLibrary.ButtonType.BUTTON_START)
|
||||
resetScale("controlScale-" + NativeLibrary.ButtonType.BUTTON_SELECT)
|
||||
resetScale("controlScale-" + NativeLibrary.ButtonType.DPAD)
|
||||
resetScale("controlScale-" + NativeLibrary.ButtonType.STICK_LEFT)
|
||||
resetScale("controlScale-" + NativeLibrary.ButtonType.STICK_C)
|
||||
resetScale("controlScale-" + NativeLibrary.ButtonType.BUTTON_HOME)
|
||||
resetScale("controlScale-" + NativeLibrary.ButtonType.BUTTON_SWAP)
|
||||
binding.surfaceInputOverlay.refreshControls()
|
||||
}
|
||||
|
||||
private fun setControlOpacity(opacity: Int) {
|
||||
preferences.edit()
|
||||
.putInt("controlOpacity", opacity)
|
||||
@ -861,8 +968,8 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram
|
||||
}
|
||||
|
||||
private fun resetInputOverlay() {
|
||||
resetAllScales()
|
||||
preferences.edit()
|
||||
.putInt("controlScale", 50)
|
||||
.putInt("controlOpacity", 50)
|
||||
.apply()
|
||||
|
||||
|
@ -939,6 +939,10 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex
|
||||
scale *= (preferences.getInt("controlScale", 50) + 50).toFloat()
|
||||
scale /= 100f
|
||||
|
||||
|
||||
scale *= (preferences.getInt("controlScale-$buttonId", 50) + 50).toFloat()
|
||||
scale /= 100f
|
||||
|
||||
val opacity: Int = preferences.getInt("controlOpacity", 50) * 255 / 100
|
||||
|
||||
// Initialize the InputOverlayDrawableButton.
|
||||
@ -997,6 +1001,13 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex
|
||||
scale *= (preferences.getInt("controlScale", 50) + 50).toFloat()
|
||||
scale /= 100f
|
||||
|
||||
scale *= (preferences.getInt(
|
||||
"controlScale-" + NativeLibrary.ButtonType.DPAD,
|
||||
50
|
||||
) + 50).toFloat()
|
||||
|
||||
scale /= 100f
|
||||
|
||||
val opacity: Int = preferences.getInt("controlOpacity", 50) * 255 / 100
|
||||
|
||||
// Initialize the InputOverlayDrawableDpad.
|
||||
@ -1057,6 +1068,9 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex
|
||||
scale *= (preferences.getInt("controlScale", 50) + 50).toFloat()
|
||||
scale /= 100f
|
||||
|
||||
scale *= (preferences.getInt("controlScale-$joystick", 50) + 50).toFloat()
|
||||
scale /= 100f
|
||||
|
||||
val opacity: Int = preferences.getInt("controlOpacity", 50) * 255 / 100
|
||||
|
||||
// Initialize the InputOverlayDrawableJoystick.
|
||||
|
@ -25,8 +25,62 @@
|
||||
android:title="@string/emulation_toggle_controls" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_emulation_adjust_scale"
|
||||
android:title="@string/emulation_control_scale" />
|
||||
android:id="@+id/menu_emulation_adjust_scales"
|
||||
android:title="@string/emulation_control_scale">
|
||||
<menu>
|
||||
<item
|
||||
android:id="@+id/menu_emulation_adjust_scale_reset_all"
|
||||
android:title="@string/emulation_control_scale_reset_all" />
|
||||
<item
|
||||
android:id="@+id/menu_emulation_adjust_scale"
|
||||
android:title="@string/emulation_control_scale_global" />
|
||||
<item
|
||||
android:id="@+id/menu_emulation_adjust_scale_button_a"
|
||||
android:title="@string/button_a" />
|
||||
<item
|
||||
android:id="@+id/menu_emulation_adjust_scale_button_b"
|
||||
android:title="@string/button_b" />
|
||||
<item
|
||||
android:id="@+id/menu_emulation_adjust_scale_button_x"
|
||||
android:title="@string/button_x" />
|
||||
<item
|
||||
android:id="@+id/menu_emulation_adjust_scale_button_y"
|
||||
android:title="@string/button_y" />
|
||||
<item
|
||||
android:id="@+id/menu_emulation_adjust_scale_button_l"
|
||||
android:title="@string/button_l" />
|
||||
<item
|
||||
android:id="@+id/menu_emulation_adjust_scale_button_r"
|
||||
android:title="@string/button_r" />
|
||||
<item
|
||||
android:id="@+id/menu_emulation_adjust_scale_button_zl"
|
||||
android:title="@string/button_zl" />
|
||||
<item
|
||||
android:id="@+id/menu_emulation_adjust_scale_button_zr"
|
||||
android:title="@string/button_zr" />
|
||||
<item
|
||||
android:id="@+id/menu_emulation_adjust_scale_button_start"
|
||||
android:title="@string/button_start" />
|
||||
<item
|
||||
android:id="@+id/menu_emulation_adjust_scale_button_select"
|
||||
android:title="@string/button_select" />
|
||||
<item
|
||||
android:id="@+id/menu_emulation_adjust_scale_controller_dpad"
|
||||
android:title="@string/controller_dpad" />
|
||||
<item
|
||||
android:id="@+id/menu_emulation_adjust_scale_controller_circlepad"
|
||||
android:title="@string/controller_circlepad" />
|
||||
<item
|
||||
android:id="@+id/menu_emulation_adjust_scale_controller_c"
|
||||
android:title="@string/controller_c" />
|
||||
<item
|
||||
android:id="@+id/menu_emulation_adjust_scale_button_home"
|
||||
android:title="@string/button_home" />
|
||||
<item
|
||||
android:id="@+id/menu_emulation_adjust_scale_button_swap"
|
||||
android:title="@string/button_swap" />
|
||||
</menu>
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_emulation_adjust_opacity"
|
||||
|
@ -331,6 +331,8 @@
|
||||
<string name="emulation_done">Done</string>
|
||||
<string name="emulation_toggle_controls">Toggle Controls</string>
|
||||
<string name="emulation_control_scale">Adjust Scale</string>
|
||||
<string name="emulation_control_scale_global">Global Scale</string>
|
||||
<string name="emulation_control_scale_reset_all">Reset All</string>
|
||||
<string name="emulation_control_opacity">Adjust Opacity</string>
|
||||
<string name="emulation_control_joystick_rel_center">Relative Stick Center</string>
|
||||
<string name="emulation_control_dpad_slide_enable">D-Pad Sliding</string>
|
||||
|
Loading…
Reference in New Issue
Block a user