diff --git a/src/android/app/src/main/java/io/github/lime3ds/android/fragments/EmulationFragment.kt b/src/android/app/src/main/java/io/github/lime3ds/android/fragments/EmulationFragment.kt
index 7c5408167..c99d918bb 100644
--- a/src/android/app/src/main/java/io/github/lime3ds/android/fragments/EmulationFragment.kt
+++ b/src/android/app/src/main/java/io/github/lime3ds/android/fragments/EmulationFragment.kt
@@ -624,6 +624,11 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram
true
}
+ R.id.menu_emulation_adjust_opacity -> {
+ showAdjustOpacityDialog()
+ true
+ }
+
R.id.menu_emulation_joystick_rel_center -> {
EmulationMenuSettings.joystickRelCenter =
!EmulationMenuSettings.joystickRelCenter
@@ -800,6 +805,37 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram
.show()
}
+ private fun showAdjustOpacityDialog() {
+ val sliderBinding = DialogSliderBinding.inflate(layoutInflater)
+
+ sliderBinding.apply {
+ slider.valueTo = 100f
+ slider.value = preferences.getInt("controlOpacity", 100).toFloat()
+ slider.addOnChangeListener(
+ Slider.OnChangeListener { slider: Slider, progress: Float, _: Boolean ->
+ textValue.text = (progress.toInt()).toString()
+ setControlOpacity(slider.value.toInt())
+ })
+ textValue.text = (sliderBinding.slider.value.toInt()).toString()
+ textUnits.text = "%"
+ }
+ val previousProgress = sliderBinding.slider.value.toInt()
+
+ MaterialAlertDialogBuilder(requireContext())
+ .setTitle(R.string.emulation_control_opacity)
+ .setView(sliderBinding.root)
+ .setNegativeButton(android.R.string.cancel) { _: DialogInterface?, _: Int ->
+ setControlOpacity(previousProgress)
+ }
+ .setPositiveButton(android.R.string.ok) { _: DialogInterface?, _: Int ->
+ setControlOpacity(sliderBinding.slider.value.toInt())
+ }
+ .setNeutralButton(R.string.slider_default) { _: DialogInterface?, _: Int ->
+ setControlOpacity(100)
+ }
+ .show()
+ }
+
private fun setControlScale(scale: Int) {
preferences.edit()
.putInt("controlScale", scale)
@@ -807,6 +843,13 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram
binding.surfaceInputOverlay.refreshControls()
}
+ private fun setControlOpacity(opacity: Int) {
+ preferences.edit()
+ .putInt("controlOpacity", opacity)
+ .apply()
+ binding.surfaceInputOverlay.refreshControls()
+ }
+
private fun showResetOverlayDialog() {
MaterialAlertDialogBuilder(requireContext())
.setTitle(getString(R.string.emulation_touch_overlay_reset))
@@ -820,6 +863,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram
private fun resetInputOverlay() {
preferences.edit()
.putInt("controlScale", 50)
+ .putInt("controlOpacity", 100)
.apply()
val editor = preferences.edit()
diff --git a/src/android/app/src/main/java/io/github/lime3ds/android/overlay/InputOverlay.kt b/src/android/app/src/main/java/io/github/lime3ds/android/overlay/InputOverlay.kt
index 54da5c7d3..afcadf5f2 100644
--- a/src/android/app/src/main/java/io/github/lime3ds/android/overlay/InputOverlay.kt
+++ b/src/android/app/src/main/java/io/github/lime3ds/android/overlay/InputOverlay.kt
@@ -939,11 +939,13 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex
scale *= (preferences.getInt("controlScale", 50) + 50).toFloat()
scale /= 100f
+ val opacity: Int = preferences.getInt("controlOpacity", 100) * 255 / 100
+
// Initialize the InputOverlayDrawableButton.
val defaultStateBitmap = getBitmap(context, defaultResId, scale)
val pressedStateBitmap = getBitmap(context, pressedResId, scale)
val overlayDrawable =
- InputOverlayDrawableButton(res, defaultStateBitmap, pressedStateBitmap, buttonId)
+ InputOverlayDrawableButton(res, defaultStateBitmap, pressedStateBitmap, buttonId, opacity)
// The X and Y coordinates of the InputOverlayDrawableButton on the InputOverlay.
// These were set in the input overlay configuration menu.
@@ -995,6 +997,8 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex
scale *= (preferences.getInt("controlScale", 50) + 50).toFloat()
scale /= 100f
+ val opacity: Int = preferences.getInt("controlOpacity", 100) * 255 / 100
+
// Initialize the InputOverlayDrawableDpad.
val defaultStateBitmap = getBitmap(context, defaultResId, scale)
val pressedOneDirectionStateBitmap = getBitmap(context, pressedOneDirectionResId, scale)
@@ -1007,7 +1011,8 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex
buttonUp,
buttonDown,
buttonLeft,
- buttonRight
+ buttonRight,
+ opacity
)
// The X and Y coordinates of the InputOverlayDrawableDpad on the InputOverlay.
@@ -1052,6 +1057,8 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex
scale *= (preferences.getInt("controlScale", 50) + 50).toFloat()
scale /= 100f
+ val opacity: Int = preferences.getInt("controlOpacity", 100) * 255 / 100
+
// Initialize the InputOverlayDrawableJoystick.
val bitmapOuter = getBitmap(context, resOuter, scale)
val bitmapInnerDefault = getBitmap(context, defaultResInner, scale)
@@ -1088,7 +1095,8 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex
bitmapInnerPressed,
outerRect,
innerRect,
- joystick
+ joystick,
+ opacity
)
// Need to set the image's position
diff --git a/src/android/app/src/main/java/io/github/lime3ds/android/overlay/InputOverlayDrawableButton.kt b/src/android/app/src/main/java/io/github/lime3ds/android/overlay/InputOverlayDrawableButton.kt
index 49b7ce023..ffa3bd47f 100644
--- a/src/android/app/src/main/java/io/github/lime3ds/android/overlay/InputOverlayDrawableButton.kt
+++ b/src/android/app/src/main/java/io/github/lime3ds/android/overlay/InputOverlayDrawableButton.kt
@@ -26,7 +26,8 @@ class InputOverlayDrawableButton(
res: Resources,
defaultStateBitmap: Bitmap,
pressedStateBitmap: Bitmap,
- val id: Int
+ val id: Int,
+ val opacity: Int
) {
var trackId: Int
private var previousTouchX = 0
@@ -35,6 +36,7 @@ class InputOverlayDrawableButton(
private var controlPositionY = 0
val width: Int
val height: Int
+ private val opacityId: Int
private val defaultStateBitmap: BitmapDrawable
private val pressedStateBitmap: BitmapDrawable
private var pressedState = false
@@ -42,6 +44,7 @@ class InputOverlayDrawableButton(
init {
this.defaultStateBitmap = BitmapDrawable(res, defaultStateBitmap)
this.pressedStateBitmap = BitmapDrawable(res, pressedStateBitmap)
+ this.opacityId = this.opacity
trackId = -1
width = this.defaultStateBitmap.intrinsicWidth
height = this.defaultStateBitmap.intrinsicHeight
@@ -114,7 +117,11 @@ class InputOverlayDrawableButton(
controlPositionY = y
}
- fun draw(canvas: Canvas) = currentStateBitmapDrawable.draw(canvas)
+ fun draw(canvas: Canvas) {
+ val bitmapDrawable: BitmapDrawable = currentStateBitmapDrawable
+ bitmapDrawable.alpha = opacityId
+ bitmapDrawable.draw(canvas)
+ }
private val currentStateBitmapDrawable: BitmapDrawable
get() = if (pressedState) pressedStateBitmap else defaultStateBitmap
diff --git a/src/android/app/src/main/java/io/github/lime3ds/android/overlay/InputOverlayDrawableDpad.kt b/src/android/app/src/main/java/io/github/lime3ds/android/overlay/InputOverlayDrawableDpad.kt
index e28fdafd5..a288cc4b8 100644
--- a/src/android/app/src/main/java/io/github/lime3ds/android/overlay/InputOverlayDrawableDpad.kt
+++ b/src/android/app/src/main/java/io/github/lime3ds/android/overlay/InputOverlayDrawableDpad.kt
@@ -25,6 +25,7 @@ import io.github.lime3ds.android.NativeLibrary
* @param downId Identifier for the down button.
* @param leftId Identifier for the left button.
* @param rightId Identifier for the right button.
+ * @param opacity 0-255 alpha value
*/
class InputOverlayDrawableDpad(
res: Resources,
@@ -34,7 +35,8 @@ class InputOverlayDrawableDpad(
val upId: Int,
val downId: Int,
val leftId: Int,
- val rightId: Int
+ val rightId: Int,
+ val opacity: Int
) {
var trackId: Int
private var previousTouchX = 0
@@ -43,6 +45,7 @@ class InputOverlayDrawableDpad(
private var controlPositionY = 0
val width: Int
val height: Int
+ private val opacityId: Int
private val defaultStateBitmap: BitmapDrawable
private val pressedOneDirectionStateBitmap: BitmapDrawable
private val pressedTwoDirectionsStateBitmap: BitmapDrawable
@@ -55,6 +58,7 @@ class InputOverlayDrawableDpad(
this.defaultStateBitmap = BitmapDrawable(res, defaultStateBitmap)
this.pressedOneDirectionStateBitmap = BitmapDrawable(res, pressedOneDirectionStateBitmap)
this.pressedTwoDirectionsStateBitmap = BitmapDrawable(res, pressedTwoDirectionsStateBitmap)
+ this.opacityId = this.opacity
width = this.defaultStateBitmap.intrinsicWidth
height = this.defaultStateBitmap.intrinsicHeight
trackId = -1
@@ -137,6 +141,7 @@ class InputOverlayDrawableDpad(
// Pressed up
if (upButtonState && !leftButtonState && !rightButtonState) {
+ pressedOneDirectionStateBitmap.alpha = opacityId
pressedOneDirectionStateBitmap.draw(canvas)
return
}
@@ -145,6 +150,7 @@ class InputOverlayDrawableDpad(
if (downButtonState && !leftButtonState && !rightButtonState) {
canvas.save()
canvas.rotate(180f, px.toFloat(), py.toFloat())
+ pressedOneDirectionStateBitmap.alpha = opacityId
pressedOneDirectionStateBitmap.draw(canvas)
canvas.restore()
return
@@ -154,6 +160,7 @@ class InputOverlayDrawableDpad(
if (leftButtonState && !upButtonState && !downButtonState) {
canvas.save()
canvas.rotate(270f, px.toFloat(), py.toFloat())
+ pressedOneDirectionStateBitmap.alpha = opacityId
pressedOneDirectionStateBitmap.draw(canvas)
canvas.restore()
return
@@ -163,6 +170,7 @@ class InputOverlayDrawableDpad(
if (rightButtonState && !upButtonState && !downButtonState) {
canvas.save()
canvas.rotate(90f, px.toFloat(), py.toFloat())
+ pressedOneDirectionStateBitmap.alpha = opacityId
pressedOneDirectionStateBitmap.draw(canvas)
canvas.restore()
return
@@ -170,6 +178,7 @@ class InputOverlayDrawableDpad(
// Pressed up left
if (upButtonState && leftButtonState && !rightButtonState) {
+ pressedTwoDirectionsStateBitmap.alpha = opacityId
pressedTwoDirectionsStateBitmap.draw(canvas)
return
}
@@ -178,6 +187,7 @@ class InputOverlayDrawableDpad(
if (upButtonState && !leftButtonState && rightButtonState) {
canvas.save()
canvas.rotate(90f, px.toFloat(), py.toFloat())
+ pressedTwoDirectionsStateBitmap.alpha = opacityId
pressedTwoDirectionsStateBitmap.draw(canvas)
canvas.restore()
return
@@ -187,6 +197,7 @@ class InputOverlayDrawableDpad(
if (downButtonState && leftButtonState && !rightButtonState) {
canvas.save()
canvas.rotate(270f, px.toFloat(), py.toFloat())
+ pressedTwoDirectionsStateBitmap.alpha = opacityId
pressedTwoDirectionsStateBitmap.draw(canvas)
canvas.restore()
return
@@ -196,12 +207,14 @@ class InputOverlayDrawableDpad(
if (downButtonState && !leftButtonState && rightButtonState) {
canvas.save()
canvas.rotate(180f, px.toFloat(), py.toFloat())
+ pressedTwoDirectionsStateBitmap.alpha = opacityId
pressedTwoDirectionsStateBitmap.draw(canvas)
canvas.restore()
return
}
// Not pressed
+ defaultStateBitmap.alpha = opacityId
defaultStateBitmap.draw(canvas)
}
diff --git a/src/android/app/src/main/java/io/github/lime3ds/android/overlay/InputOverlayDrawableJoystick.kt b/src/android/app/src/main/java/io/github/lime3ds/android/overlay/InputOverlayDrawableJoystick.kt
index f3fcff6f1..a19647091 100644
--- a/src/android/app/src/main/java/io/github/lime3ds/android/overlay/InputOverlayDrawableJoystick.kt
+++ b/src/android/app/src/main/java/io/github/lime3ds/android/overlay/InputOverlayDrawableJoystick.kt
@@ -29,6 +29,7 @@ import kotlin.math.sqrt
* @param rectOuter [Rect] which represents the outer joystick bounds.
* @param rectInner [Rect] which represents the inner joystick bounds.
* @param joystickId Identifier for which joystick this is.
+ * @param opacity 0-255 alpha value
*/
class InputOverlayDrawableJoystick(
res: Resources,
@@ -37,7 +38,8 @@ class InputOverlayDrawableJoystick(
bitmapInnerPressed: Bitmap,
rectOuter: Rect,
rectInner: Rect,
- val joystickId: Int
+ val joystickId: Int,
+ val opacity: Int
) {
var trackId = -1
var xAxis = 0f
@@ -50,6 +52,7 @@ class InputOverlayDrawableJoystick(
private var previousTouchY = 0
val width: Int
val height: Int
+ private val opacityId: Int
private var virtBounds: Rect
private var origBounds: Rect
private val outerBitmap: BitmapDrawable
@@ -72,6 +75,7 @@ class InputOverlayDrawableJoystick(
width = bitmapOuter.width
height = bitmapOuter.height
bounds = rectOuter
+ opacityId = opacity
defaultStateInnerBitmap.bounds = rectInner
pressedStateInnerBitmap.bounds = rectInner
virtBounds = bounds
@@ -79,10 +83,14 @@ class InputOverlayDrawableJoystick(
boundsBoxBitmap.alpha = 0
boundsBoxBitmap.bounds = virtBounds
setInnerBounds()
+ defaultStateInnerBitmap.alpha = opacity
+ pressedStateInnerBitmap.alpha = opacity
+ outerBitmap.alpha = opacity
}
fun draw(canvas: Canvas?) {
outerBitmap.draw(canvas!!)
+ currentStateBitmapDrawable.alpha = opacityId
currentStateBitmapDrawable.draw(canvas)
boundsBoxBitmap.draw(canvas)
}
@@ -103,7 +111,7 @@ class InputOverlayDrawableJoystick(
}
pressedState = true
outerBitmap.alpha = 0
- boundsBoxBitmap.alpha = 255
+ boundsBoxBitmap.alpha = opacityId
if (EmulationMenuSettings.joystickRelCenter) {
virtBounds.offset(
xPosition - virtBounds.centerX(),
@@ -123,7 +131,7 @@ class InputOverlayDrawableJoystick(
yAxis = 0.0f
angle = 0.0f
radius = 0.0f
- outerBitmap.alpha = 255
+ outerBitmap.alpha = opacityId
boundsBoxBitmap.alpha = 0
virtBounds = Rect(origBounds.left, origBounds.top, origBounds.right, origBounds.bottom)
bounds = Rect(origBounds.left, origBounds.top, origBounds.right, origBounds.bottom)
diff --git a/src/android/app/src/main/res/menu/menu_overlay_options.xml b/src/android/app/src/main/res/menu/menu_overlay_options.xml
index 605c15213..14e9a788a 100644
--- a/src/android/app/src/main/res/menu/menu_overlay_options.xml
+++ b/src/android/app/src/main/res/menu/menu_overlay_options.xml
@@ -28,6 +28,10 @@
android:id="@+id/menu_emulation_adjust_scale"
android:title="@string/emulation_control_scale" />
+
+
-
Hecho
Activar Controles
Ajustar Escala
+ Ajustar Opacidad
Posición central relativa del stick
Deslizamiento de la Cruceta
Abrir Configuración
diff --git a/src/android/app/src/main/res/values/strings.xml b/src/android/app/src/main/res/values/strings.xml
index fe1832ce7..098fec0b0 100644
--- a/src/android/app/src/main/res/values/strings.xml
+++ b/src/android/app/src/main/res/values/strings.xml
@@ -331,6 +331,7 @@
Done
Toggle Controls
Adjust Scale
+ Adjust Opacity
Relative Stick Center
D-Pad Sliding
Open Settings