mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2025-03-14 01:32:25 +01:00
More code cleanup
This commit is contained in:
parent
2656290107
commit
d72284f49a
@ -22,10 +22,9 @@ class ControllerQuickConfigDialog(
|
|||||||
titles: ArrayList<List<Int>>,
|
titles: ArrayList<List<Int>>,
|
||||||
private var preferences: SharedPreferences
|
private var preferences: SharedPreferences
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private var index = 0
|
private var index = 0
|
||||||
val inflater = LayoutInflater.from(context)
|
val inflater = LayoutInflater.from(context)
|
||||||
val automappingBinding = DialogControllerQuickConfigBinding.inflate(inflater)
|
val quickConfigBinding = DialogControllerQuickConfigBinding.inflate(inflater)
|
||||||
var dialog: AlertDialog? = null
|
var dialog: AlertDialog? = null
|
||||||
|
|
||||||
var allButtons = arrayListOf<String>()
|
var allButtons = arrayListOf<String>()
|
||||||
@ -42,14 +41,13 @@ class ControllerQuickConfigDialog(
|
|||||||
allTitles.add(title)
|
allTitles.add(title)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun show() {
|
fun show() {
|
||||||
val builder: AlertDialog.Builder = AlertDialog.Builder(context)
|
val builder: AlertDialog.Builder = AlertDialog.Builder(context)
|
||||||
builder
|
builder
|
||||||
.setView(automappingBinding.root)
|
.setView(quickConfigBinding.root)
|
||||||
.setTitle("Automapper")
|
.setTitle("Quick Configure")
|
||||||
.setPositiveButton("Next") {_,_ -> }
|
.setPositiveButton("Next") {_,_ -> }
|
||||||
.setNegativeButton("Close") { dialog, which ->
|
.setNegativeButton("Close") { dialog, which ->
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
@ -59,7 +57,7 @@ class ControllerQuickConfigDialog(
|
|||||||
dialog?.show()
|
dialog?.show()
|
||||||
|
|
||||||
dialog?.setOnKeyListener { _, _, event -> onKeyEvent(event) }
|
dialog?.setOnKeyListener { _, _, event -> onKeyEvent(event) }
|
||||||
automappingBinding.root.setOnGenericMotionListener { _, event -> onMotionEvent(event) }
|
quickConfigBinding.root.setOnGenericMotionListener { _, event -> onMotionEvent(event) }
|
||||||
|
|
||||||
// Prepare the first element
|
// Prepare the first element
|
||||||
prepareUIforIndex(index)
|
prepareUIforIndex(index)
|
||||||
@ -69,7 +67,6 @@ class ControllerQuickConfigDialog(
|
|||||||
// Skip to next:
|
// Skip to next:
|
||||||
prepareUIforIndex(index++)
|
prepareUIforIndex(index++)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun prepareUIforIndex(i: Int) {
|
private fun prepareUIforIndex(i: Int) {
|
||||||
@ -78,9 +75,9 @@ class ControllerQuickConfigDialog(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if(index>0) {
|
if (index>0) {
|
||||||
automappingBinding.lastMappingIcon.visibility = View.VISIBLE
|
quickConfigBinding.lastMappingIcon.visibility = View.VISIBLE
|
||||||
automappingBinding.lastMappingDescription.visibility = View.VISIBLE
|
quickConfigBinding.lastMappingDescription.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
|
|
||||||
val currentButton = allButtons[i]
|
val currentButton = allButtons[i]
|
||||||
@ -89,28 +86,25 @@ class ControllerQuickConfigDialog(
|
|||||||
val button = InputBindingSetting.getInputObject(currentButton, preferences)
|
val button = InputBindingSetting.getInputObject(currentButton, preferences)
|
||||||
|
|
||||||
var lastTitle = setting?.value ?: ""
|
var lastTitle = setting?.value ?: ""
|
||||||
if(lastTitle.isBlank()) {
|
if (lastTitle.isBlank()) {
|
||||||
lastTitle = context.getString(R.string.controller_quick_config_unassigned)
|
lastTitle = context.getString(R.string.controller_quick_config_unassigned)
|
||||||
}
|
}
|
||||||
automappingBinding.lastMappingDescription.text = lastTitle
|
quickConfigBinding.lastMappingDescription.text = lastTitle
|
||||||
automappingBinding.lastMappingIcon.setImageDrawable(automappingBinding.currentMappingIcon.drawable)
|
quickConfigBinding.lastMappingIcon.setImageDrawable(quickConfigBinding.currentMappingIcon.drawable)
|
||||||
|
|
||||||
setting = InputBindingSetting(button, currentTitleInt)
|
setting = InputBindingSetting(button, currentTitleInt)
|
||||||
|
quickConfigBinding.currentMappingTitle.text = calculateTitle()
|
||||||
automappingBinding.currentMappingTitle.text = calculateTitle()
|
quickConfigBinding.currentMappingDescription.text = setting?.value
|
||||||
automappingBinding.currentMappingDescription.text = setting?.value
|
quickConfigBinding.currentMappingIcon.setImageDrawable(getIcon())
|
||||||
automappingBinding.currentMappingIcon.setImageDrawable(getIcon())
|
|
||||||
|
|
||||||
|
|
||||||
if (allButtons.size-1 < index) {
|
if (allButtons.size-1 < index) {
|
||||||
dialog?.getButton(AlertDialog.BUTTON_POSITIVE)?.text =
|
dialog?.getButton(AlertDialog.BUTTON_POSITIVE)?.text =
|
||||||
context.getString(R.string.controller_quick_config_finish)
|
context.getString(R.string.controller_quick_config_finish)
|
||||||
dialog?.getButton(AlertDialog.BUTTON_NEGATIVE)?.visibility = View.GONE
|
dialog?.getButton(AlertDialog.BUTTON_NEGATIVE)?.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun calculateTitle(): String {
|
private fun calculateTitle(): String {
|
||||||
|
|
||||||
val inputTypeId = when {
|
val inputTypeId = when {
|
||||||
setting!!.isCirclePad() -> R.string.controller_circlepad
|
setting!!.isCirclePad() -> R.string.controller_circlepad
|
||||||
setting!!.isCStick() -> R.string.controller_c
|
setting!!.isCStick() -> R.string.controller_c
|
||||||
@ -135,7 +129,7 @@ class ControllerQuickConfigDialog(
|
|||||||
setting!!.isDPad() -> R.drawable.dpad
|
setting!!.isDPad() -> R.drawable.dpad
|
||||||
else -> {
|
else -> {
|
||||||
val resourceTitle = context.resources.getResourceEntryName(setting!!.nameId)
|
val resourceTitle = context.resources.getResourceEntryName(setting!!.nameId)
|
||||||
if(resourceTitle.startsWith("direction")) {
|
if (resourceTitle.startsWith("direction")) {
|
||||||
R.drawable.dpad
|
R.drawable.dpad
|
||||||
} else {
|
} else {
|
||||||
context.resources.getIdentifier(resourceTitle, "drawable", context.packageName)
|
context.resources.getIdentifier(resourceTitle, "drawable", context.packageName)
|
||||||
@ -154,26 +148,24 @@ class ControllerQuickConfigDialog(
|
|||||||
private fun onKeyEvent(event: KeyEvent): Boolean {
|
private fun onKeyEvent(event: KeyEvent): Boolean {
|
||||||
return when (event.action) {
|
return when (event.action) {
|
||||||
KeyEvent.ACTION_UP -> {
|
KeyEvent.ACTION_UP -> {
|
||||||
if(System.currentTimeMillis()-debounceTimestamp < 500) {
|
if (System.currentTimeMillis()-debounceTimestamp < 500) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
debounceTimestamp = System.currentTimeMillis()
|
debounceTimestamp = System.currentTimeMillis()
|
||||||
|
|
||||||
index++
|
index++
|
||||||
setting?.onKeyInput(event)
|
setting?.onKeyInput(event)
|
||||||
prepareUIforIndex(index)
|
prepareUIforIndex(index)
|
||||||
// Even if we ignore the key, we still consume it. Thus return true regardless.
|
// Even if we ignore the key, we still consume it. Thus return true regardless.
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onMotionEvent(event: MotionEvent): Boolean {
|
private fun onMotionEvent(event: MotionEvent): Boolean {
|
||||||
if (event.source and InputDevice.SOURCE_CLASS_JOYSTICK == 0) return false
|
if ((event.source and InputDevice.SOURCE_CLASS_JOYSTICK == 0) ||
|
||||||
if (event.action != MotionEvent.ACTION_MOVE) return false
|
event.action != MotionEvent.ACTION_MOVE) return false
|
||||||
|
|
||||||
val input = event.device
|
val input = event.device
|
||||||
val motionRanges = input.motionRanges
|
val motionRanges = input.motionRanges
|
||||||
@ -224,7 +216,6 @@ class ControllerQuickConfigDialog(
|
|||||||
}
|
}
|
||||||
previousValues[i] = origValue
|
previousValues[i] = origValue
|
||||||
}
|
}
|
||||||
|
|
||||||
// If only one axis moved, that's the winner.
|
// If only one axis moved, that's the winner.
|
||||||
if (numMovedAxis == 1) {
|
if (numMovedAxis == 1) {
|
||||||
waitingForEvent = false
|
waitingForEvent = false
|
||||||
@ -233,5 +224,4 @@ class ControllerQuickConfigDialog(
|
|||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user