mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-11-23 08:39:16 +01:00
Add extension to retrieve input manager from context
This commit is contained in:
parent
f5d5caf939
commit
a261ff8413
@ -8,7 +8,7 @@ package emu.skyline.adapter.controller
|
|||||||
import emu.skyline.adapter.GenericListItem
|
import emu.skyline.adapter.GenericListItem
|
||||||
import emu.skyline.adapter.GenericViewHolder
|
import emu.skyline.adapter.GenericViewHolder
|
||||||
import emu.skyline.databinding.ControllerItemBinding
|
import emu.skyline.databinding.ControllerItemBinding
|
||||||
import emu.skyline.di.InputManagerProviderEntryPoint
|
import emu.skyline.di.getInputManager
|
||||||
import emu.skyline.input.ButtonGuestEvent
|
import emu.skyline.input.ButtonGuestEvent
|
||||||
import emu.skyline.input.ButtonId
|
import emu.skyline.input.ButtonId
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ class ControllerButtonViewItem(private val controllerId : Int, val button : Butt
|
|||||||
override fun bind(holder : GenericViewHolder<ControllerItemBinding>, position : Int) {
|
override fun bind(holder : GenericViewHolder<ControllerItemBinding>, position : Int) {
|
||||||
content = button.long?.let { holder.itemView.context.getString(it) } ?: button.toString()
|
content = button.long?.let { holder.itemView.context.getString(it) } ?: button.toString()
|
||||||
val guestEvent = ButtonGuestEvent(controllerId, button)
|
val guestEvent = ButtonGuestEvent(controllerId, button)
|
||||||
subContent = InputManagerProviderEntryPoint.getInputManager(holder.binding.root.context).eventMap.filter { it.value is ButtonGuestEvent && it.value == guestEvent }.keys.firstOrNull()?.toString() ?: ""
|
subContent = holder.binding.root.context.getInputManager().eventMap.filter { it.value is ButtonGuestEvent && it.value == guestEvent }.keys.firstOrNull()?.toString() ?: ""
|
||||||
|
|
||||||
super.bind(holder, position)
|
super.bind(holder, position)
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import emu.skyline.R
|
|||||||
import emu.skyline.adapter.GenericListItem
|
import emu.skyline.adapter.GenericListItem
|
||||||
import emu.skyline.adapter.GenericViewHolder
|
import emu.skyline.adapter.GenericViewHolder
|
||||||
import emu.skyline.databinding.ControllerItemBinding
|
import emu.skyline.databinding.ControllerItemBinding
|
||||||
import emu.skyline.di.InputManagerProviderEntryPoint
|
import emu.skyline.di.getInputManager
|
||||||
import emu.skyline.input.GeneralType
|
import emu.skyline.input.GeneralType
|
||||||
import emu.skyline.input.JoyConLeftController
|
import emu.skyline.input.JoyConLeftController
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ import emu.skyline.input.JoyConLeftController
|
|||||||
class ControllerGeneralViewItem(private val controllerId : Int, val type : GeneralType, private val onClick : (item : ControllerGeneralViewItem, position : Int) -> Unit) : ControllerViewItem() {
|
class ControllerGeneralViewItem(private val controllerId : Int, val type : GeneralType, private val onClick : (item : ControllerGeneralViewItem, position : Int) -> Unit) : ControllerViewItem() {
|
||||||
override fun bind(holder : GenericViewHolder<ControllerItemBinding>, position : Int) {
|
override fun bind(holder : GenericViewHolder<ControllerItemBinding>, position : Int) {
|
||||||
val context = holder.itemView.context
|
val context = holder.itemView.context
|
||||||
val controller = InputManagerProviderEntryPoint.getInputManager(context).controllers[controllerId]!!
|
val controller = context.getInputManager().controllers[controllerId]!!
|
||||||
|
|
||||||
content = context.getString(type.stringRes)
|
content = context.getString(type.stringRes)
|
||||||
subContent = when (type) {
|
subContent = when (type) {
|
||||||
|
@ -9,7 +9,7 @@ import emu.skyline.R
|
|||||||
import emu.skyline.adapter.GenericListItem
|
import emu.skyline.adapter.GenericListItem
|
||||||
import emu.skyline.adapter.GenericViewHolder
|
import emu.skyline.adapter.GenericViewHolder
|
||||||
import emu.skyline.databinding.ControllerItemBinding
|
import emu.skyline.databinding.ControllerItemBinding
|
||||||
import emu.skyline.di.InputManagerProviderEntryPoint
|
import emu.skyline.di.getInputManager
|
||||||
import emu.skyline.input.AxisGuestEvent
|
import emu.skyline.input.AxisGuestEvent
|
||||||
import emu.skyline.input.ButtonGuestEvent
|
import emu.skyline.input.ButtonGuestEvent
|
||||||
import emu.skyline.input.StickId
|
import emu.skyline.input.StickId
|
||||||
@ -20,7 +20,7 @@ import emu.skyline.input.StickId
|
|||||||
class ControllerStickViewItem(private val controllerId : Int, val stick : StickId, private val onClick : (item : ControllerStickViewItem, position : Int) -> Unit) : ControllerViewItem(stick.toString()) {
|
class ControllerStickViewItem(private val controllerId : Int, val stick : StickId, private val onClick : (item : ControllerStickViewItem, position : Int) -> Unit) : ControllerViewItem(stick.toString()) {
|
||||||
override fun bind(holder : GenericViewHolder<ControllerItemBinding>, position : Int) {
|
override fun bind(holder : GenericViewHolder<ControllerItemBinding>, position : Int) {
|
||||||
val context = holder.itemView.context
|
val context = holder.itemView.context
|
||||||
val inputManager = InputManagerProviderEntryPoint.getInputManager(context)
|
val inputManager = context.getInputManager()
|
||||||
|
|
||||||
val buttonGuestEvent = ButtonGuestEvent(controllerId, stick.button)
|
val buttonGuestEvent = ButtonGuestEvent(controllerId, stick.button)
|
||||||
val button = inputManager.eventMap.filter { it.value is ButtonGuestEvent && it.value == buttonGuestEvent }.keys.firstOrNull()?.toString() ?: context.getString(R.string.none)
|
val button = inputManager.eventMap.filter { it.value is ButtonGuestEvent && it.value == buttonGuestEvent }.keys.firstOrNull()?.toString() ?: context.getString(R.string.none)
|
||||||
|
@ -11,8 +11,6 @@ import emu.skyline.input.InputManager
|
|||||||
@InstallIn(SingletonComponent::class)
|
@InstallIn(SingletonComponent::class)
|
||||||
interface InputManagerProviderEntryPoint {
|
interface InputManagerProviderEntryPoint {
|
||||||
fun inputManager() : InputManager
|
fun inputManager() : InputManager
|
||||||
|
|
||||||
companion object {
|
|
||||||
fun getInputManager(context : Context) = EntryPointAccessors.fromApplication(context, InputManagerProviderEntryPoint::class.java).inputManager()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Context.getInputManager() = EntryPointAccessors.fromApplication(this, InputManagerProviderEntryPoint::class.java).inputManager()
|
||||||
|
@ -12,7 +12,7 @@ import android.util.AttributeSet
|
|||||||
import androidx.preference.Preference
|
import androidx.preference.Preference
|
||||||
import androidx.preference.Preference.SummaryProvider
|
import androidx.preference.Preference.SummaryProvider
|
||||||
import emu.skyline.R
|
import emu.skyline.R
|
||||||
import emu.skyline.di.InputManagerProviderEntryPoint
|
import emu.skyline.di.getInputManager
|
||||||
import emu.skyline.input.ControllerActivity
|
import emu.skyline.input.ControllerActivity
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -26,7 +26,7 @@ class ControllerPreference @JvmOverloads constructor(context : Context, attrs :
|
|||||||
|
|
||||||
override var requestCode = 0
|
override var requestCode = 0
|
||||||
|
|
||||||
private val inputManager = InputManagerProviderEntryPoint.getInputManager(context)
|
private val inputManager = context.getInputManager()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
for (i in 0 until attrs!!.attributeCount) {
|
for (i in 0 until attrs!!.attributeCount) {
|
||||||
|
Loading…
Reference in New Issue
Block a user