Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
Swordfish90 committed Apr 22, 2022
2 parents e19d53c + aecee54 commit c8aae1c
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import com.swordfish.lemuroid.lib.controller.TouchControllerSettingsManager
import com.swordfish.lemuroid.lib.util.subscribeBy
import com.swordfish.libretrodroid.GLRetroView
import com.swordfish.radialgamepad.library.RadialGamePad
import com.swordfish.radialgamepad.library.config.RadialGamePadTheme
import com.swordfish.radialgamepad.library.event.Event
import com.swordfish.radialgamepad.library.event.GestureType
import com.swordfish.radialgamepad.library.haptics.HapticConfig
Expand All @@ -78,6 +79,10 @@ import kotlin.math.roundToInt
class GameActivity : BaseGameActivity() {
@Inject lateinit var sharedPreferences: Lazy<SharedPreferences>

private lateinit var horizontalDivider: View
private lateinit var leftVerticalDivider: View
private lateinit var rightVerticalDivider: View

private var serviceController: GameService.GameServiceController? = null

private lateinit var tiltSensor: TiltSensor
Expand Down Expand Up @@ -108,6 +113,10 @@ class GameActivity : BaseGameActivity() {

tiltSensor = TiltSensor(applicationContext)

horizontalDivider = findViewById(R.id.horizontaldividier)
leftVerticalDivider = findViewById(R.id.leftverticaldivider)
rightVerticalDivider = findViewById(R.id.rightverticaldivider)

initializeInsetsObservable()

startGameService()
Expand Down Expand Up @@ -206,6 +215,8 @@ class GameActivity : BaseGameActivity() {

val theme = LemuroidTouchOverlayThemes.getGamePadTheme(leftGamePadContainer)

updateDividers(orientation, theme, controllerConfig)

val leftConfig = LemuroidTouchConfigs.getRadialGamePadConfig(
touchControllerConfig.leftConfig,
hapticConfig,
Expand Down Expand Up @@ -235,6 +246,26 @@ class GameActivity : BaseGameActivity() {
this.touchControllerConfig = controllerConfig
}

private fun updateDividers(
orientation: Int,
theme: RadialGamePadTheme,
controllerConfig: ControllerConfig
) {
val displayHorizontalDivider = orientation == Configuration.ORIENTATION_PORTRAIT

val displayVerticalDivider = orientation != Configuration.ORIENTATION_PORTRAIT &&
!controllerConfig.allowTouchOverlay

updateDivider(horizontalDivider, displayHorizontalDivider, theme)
updateDivider(leftVerticalDivider, displayVerticalDivider, theme)
updateDivider(rightVerticalDivider, displayVerticalDivider, theme)
}

private fun updateDivider(divider: View, visible: Boolean, theme: RadialGamePadTheme) {
divider.setVisibleOrGone(visible)
divider.setBackgroundColor(theme.backgroundStrokeColor)
}

private fun setupDefaultActions(virtualPadEvents: Observable<Event>) {
virtualControllerDisposables.add(
virtualPadEvents
Expand Down Expand Up @@ -578,7 +609,7 @@ class GameActivity : BaseGameActivity() {
constraintSet.connect(
R.id.gamecontainer,
ConstraintSet.BOTTOM,
R.id.leftgamepad,
R.id.horizontaldividier,
ConstraintSet.TOP
)

Expand Down Expand Up @@ -635,14 +666,14 @@ class GameActivity : BaseGameActivity() {
constraintSet.connect(
R.id.gamecontainer,
ConstraintSet.LEFT,
R.id.leftgamepad,
R.id.leftverticaldivider,
ConstraintSet.RIGHT
)

constraintSet.connect(
R.id.gamecontainer,
ConstraintSet.RIGHT,
R.id.rightgamepad,
R.id.rightverticaldivider,
ConstraintSet.LEFT
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.swordfish.lemuroid.app.mobile.feature.game

import android.content.Context
import android.graphics.drawable.Drawable
import android.graphics.drawable.GradientDrawable
import android.view.View
import android.view.ViewConfiguration
import android.widget.ImageView
import com.google.android.material.progressindicator.CircularProgressIndicator
import com.swordfish.lemuroid.R
import com.swordfish.lemuroid.common.graphics.GraphicsUtils
import com.swordfish.lemuroid.common.view.animateProgress
import com.swordfish.lemuroid.common.view.animateVisibleOrGone
import com.swordfish.lemuroid.common.view.setVisibleOrGone
Expand All @@ -15,6 +17,7 @@ import io.reactivex.Maybe
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import java.util.concurrent.TimeUnit
import kotlin.math.roundToInt

object VirtualLongPressHandler {

Expand All @@ -26,14 +29,25 @@ object VirtualLongPressHandler {
val palette = LemuroidTouchOverlayThemes.getGamePadTheme(longPressView(gameActivity))
longPressIconView(gameActivity).setColorFilter(palette.textColor)
longPressProgressBar(gameActivity).setIndicatorColor(palette.textColor)
longPressView(gameActivity).background = buildCircleDrawable(palette.backgroundColor)
longPressForegroundView(gameActivity).background = buildCircleDrawable(palette.normalColor)
longPressView(gameActivity).background = buildCircleDrawable(
gameActivity,
palette.backgroundColor,
palette.backgroundStrokeColor,
palette.strokeWidthDp
)
longPressForegroundView(gameActivity).background = buildCircleDrawable(
gameActivity,
palette.normalColor,
palette.normalStrokeColor,
palette.strokeWidthDp
)
}

private fun buildCircleDrawable(color: Int): Drawable {
private fun buildCircleDrawable(context: Context, fillColor: Int, strokeColor: Int, strokeSize: Float): Drawable {
return GradientDrawable().apply {
shape = GradientDrawable.OVAL
setColor(color)
setColor(fillColor)
setStroke(GraphicsUtils.convertDpToPixel(strokeSize, context).roundToInt(), strokeColor)
}
}

Expand Down
36 changes: 33 additions & 3 deletions lemuroid-app/src/main/res/layout/activity_game.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/maincontainer"
Expand Down Expand Up @@ -94,10 +95,39 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/progress" />

<View
android:id="@+id/horizontaldividier"
android:layout_width="0dp"
android:layout_height="@dimen/touch_control_stroke_size"
android:visibility="gone"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toTopOf="@id/leftgamepad"/>

<View
android:id="@+id/leftverticaldivider"
android:orientation="vertical"
android:layout_width="@dimen/touch_control_stroke_size"
android:layout_height="0dp"
android:visibility="gone"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@id/leftgamepad"/>

<View
android:id="@+id/rightverticaldivider"
android:orientation="vertical"
android:layout_width="@dimen/touch_control_stroke_size"
android:layout_height="0dp"
android:visibility="gone"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toLeftOf="@id/rightgamepad"/>

<include layout="@layout/layout_game_long_press"
android:id="@+id/settings_loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="@dimen/loading_circle_outer"
android:layout_height="@dimen/loading_circle_outer"
app:layout_constraintBottom_toBottomOf="@id/gamecontainer"
app:layout_constraintEnd_toEndOf="@id/gamecontainer"
app:layout_constraintStart_toStartOf="@id/gamecontainer"
Expand Down
16 changes: 8 additions & 8 deletions lemuroid-app/src/main/res/layout/layout_game_long_press.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="@dimen/loading_circle_outer"
android:layout_height="@dimen/loading_circle_outer"
android:layout_gravity="center_vertical"
android:visibility="gone">

<View
android:id="@+id/long_press_foreground"
android:layout_margin="@dimen/loading_circle_progress_thickness"
android:layout_gravity="center"
android:layout_width="@dimen/loading_circle_size"
android:layout_height="@dimen/loading_circle_size"/>
android:layout_margin="10dp"
android:layout_width="@dimen/loading_circle_inner"
android:layout_height="@dimen/loading_circle_inner"/>

<com.google.android.material.progressindicator.CircularProgressIndicator
android:id="@+id/settings_loading_progress"
app:indicatorSize="@dimen/loading_circle_size"
app:indicatorSize="@dimen/loading_circle_progress"
app:trackThickness="@dimen/loading_circle_progress_thickness"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -25,8 +25,8 @@

<ImageView
android:id="@+id/settings_loading_icon"
android:layout_width="@dimen/loading_circle_icon_size"
android:layout_height="@dimen/loading_circle_icon_size"
android:layout_width="@dimen/loading_circle_icon"
android:layout_height="@dimen/loading_circle_icon"
android:layout_gravity="center"/>

</FrameLayout>
8 changes: 6 additions & 2 deletions lemuroid-app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
<string name="system_card_image_ratio">4:3</string>
<string name="game_card_image_ratio">1:1</string>

<dimen name="loading_circle_size">58dp</dimen>
<dimen name="loading_circle_icon_size">32dp</dimen>
<string name="touch_control_stroke_size">2dp</string>

<dimen name="loading_circle_outer">80dp</dimen>
<dimen name="loading_circle_inner">68dp</dimen>
<dimen name="loading_circle_progress">56dp</dimen>
<dimen name="loading_circle_icon">32dp</dimen>
<dimen name="loading_circle_progress_thickness">6dp</dimen>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,18 @@ object LemuroidTouchConfigs {
private val PRIMARY_DIAL_CROSS = PrimaryDialConfig.Cross(
CrossConfig(
id = MOTION_SOURCE_DPAD,
shape = CrossConfig.Shape.STANDARD,
shape = CrossConfig.Shape.CIRCLE,
supportsGestures = setOf(GestureType.TRIPLE_TAP, GestureType.FIRST_TOUCH),
rightDrawableForegroundId = R.drawable.direction_foreground
rightDrawableForegroundId = R.drawable.direction_alt_foreground
),
)

private val PRIMARY_DIAL_CROSS_MERGED = PrimaryDialConfig.Cross(
CrossConfig(
id = MOTION_SOURCE_DPAD_AND_LEFT_STICK,
shape = CrossConfig.Shape.STANDARD,
supportsGestures = setOf(GestureType.TRIPLE_TAP, GestureType.FIRST_TOUCH)
shape = CrossConfig.Shape.CIRCLE,
supportsGestures = setOf(GestureType.TRIPLE_TAP, GestureType.FIRST_TOUCH),
rightDrawableForegroundId = R.drawable.direction_alt_foreground
)
)

Expand Down Expand Up @@ -1200,7 +1201,8 @@ object LemuroidTouchConfigs {
id = KeyEvent.KEYCODE_BUTTON_THUMBL,
iconId = R.drawable.button_keyboard,
contentDescription = "Keyboard"
)
),
rotationProcessor = rotationInvert(),
),
SecondaryDialConfig.Stick(
9,
Expand Down Expand Up @@ -1455,11 +1457,7 @@ object LemuroidTouchConfigs {
scale = 1f,
distance = 0f,
buttonConfig = BUTTON_CONFIG_MENU,
rotationProcessor = object : SecondaryDialConfig.RotationProcessor() {
override fun getRotation(rotation: Float): Float {
return -rotation
}
},
rotationProcessor = rotationInvert(),
theme = theme
)
}
Expand All @@ -1471,4 +1469,10 @@ object LemuroidTouchConfigs {
}
}
}

private fun rotationInvert() = object : SecondaryDialConfig.RotationProcessor() {
override fun getRotation(rotation: Float): Float {
return -rotation
}
}
}
Original file line number Diff line number Diff line change
@@ -1,39 +1,48 @@
package com.swordfish.touchinput.radial

import android.graphics.Color
import android.view.View
import androidx.core.graphics.ColorUtils
import com.google.android.material.color.MaterialColors
import com.swordfish.lemuroid.common.graphics.GraphicsUtils
import com.swordfish.radialgamepad.library.config.RadialGamePadTheme
import com.google.android.material.R
import com.swordfish.touchinput.controller.R
import com.google.android.material.R as MaterialR

object LemuroidTouchOverlayThemes {

private const val LIGHTNESS = 0.5f
private const val TEXT_LIGHTNESS = 1f
private const val ALPHA_FOREGROUND = 0.75f
private const val ALPHA_MIDDLE = 0.5f
private const val ALPHA_BACKGROUND = 0.25f
private const val ALPHA_FILL_LIGHT = 0.2f
private const val ALPHA_FILL_STRONG = 0.2f
private const val ALPHA_FILL_SIMULATED = 0.4f
private const val ALPHA_FILL_PRESSED = 0.6f

private const val ALPHA_STROKE = 0.9f
private const val ALPHA_STROKE_LIGHT = 0.15f * ALPHA_STROKE
private const val ALPHA_STROKE_STRONG = 0.5f * ALPHA_STROKE
private const val ALPHA_STROKE_TEXT = 0.8f * ALPHA_STROKE

private const val BACKGROUND_COLOR = Color.BLACK

fun getGamePadTheme(view: View): RadialGamePadTheme {
return buildTheme(view)
}

private fun buildTheme(view: View): RadialGamePadTheme {
val colorOnSurface = MaterialColors.getColor(view, R.attr.colorOnSurface)
val colorSurface = MaterialColors.getColor(view, R.attr.colorSurface)
val colorPrimary = MaterialColors.getColor(view, R.attr.colorPrimary)
val colorSecondary = MaterialColors.getColor(view, R.attr.colorSecondary)

val mainColor = ColorUtils.blendARGB(colorSurface, colorOnSurface, LIGHTNESS)
val mainTextColor = ColorUtils.blendARGB(colorSurface, colorOnSurface, TEXT_LIGHTNESS)
val strokeSize = GraphicsUtils.getRawDpSize(view.context, R.dimen.touch_control_stroke_size)
val colorOnSurface = MaterialColors.getColor(view, MaterialR.attr.colorOnSurface)
val colorPrimary = MaterialColors.getColor(view, MaterialR.attr.colorPrimary)
val colorSecondary = MaterialColors.getColor(view, MaterialR.attr.colorSecondary)

return RadialGamePadTheme(
normalColor = withAlpha(mainColor, ALPHA_MIDDLE),
backgroundColor = withAlpha(mainColor, ALPHA_BACKGROUND),
pressedColor = withAlpha(colorPrimary, ALPHA_FOREGROUND),
textColor = withAlpha(mainTextColor, ALPHA_FOREGROUND),
simulatedColor = withAlpha(colorSecondary, ALPHA_MIDDLE),
lightColor = withAlpha(mainColor, ALPHA_BACKGROUND),
normalColor = withAlpha(BACKGROUND_COLOR, ALPHA_FILL_STRONG),
normalStrokeColor = withAlpha(colorOnSurface, ALPHA_STROKE_STRONG),
backgroundColor = withAlpha(BACKGROUND_COLOR, ALPHA_FILL_LIGHT),
backgroundStrokeColor = withAlpha(colorOnSurface, ALPHA_STROKE_LIGHT),
pressedColor = withAlpha(colorPrimary, ALPHA_FILL_PRESSED),
textColor = withAlpha(colorOnSurface, ALPHA_STROKE_TEXT),
simulatedColor = withAlpha(colorSecondary, ALPHA_FILL_SIMULATED),
lightColor = withAlpha(BACKGROUND_COLOR, ALPHA_FILL_STRONG),
lightStrokeColor = withAlpha(colorOnSurface, ALPHA_STROKE_LIGHT),
strokeWidthDp = strokeSize
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.swordfish.lemuroid.common.graphics
import android.content.Context
import android.graphics.Color
import android.util.DisplayMetrics
import android.util.TypedValue

object GraphicsUtils {

Expand All @@ -25,4 +26,10 @@ object GraphicsUtils {
fun convertPixelsToDp(px: Float, context: Context): Float {
return px / (context.resources.displayMetrics.densityDpi.toFloat() / DisplayMetrics.DENSITY_DEFAULT)
}

fun getRawDpSize(context: Context, resource: Int): Float {
val value = TypedValue()
context.resources.getValue(resource, value, true)
return TypedValue.complexToFloat(value.data)
}
}

0 comments on commit c8aae1c

Please sign in to comment.