Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package app.gamenative.ui.screen.xserver

import com.winlator.inputcontrols.ControlElement
import com.winlator.inputcontrols.ControlsProfile
import com.winlator.widget.InputControlsView

internal fun copyInputControlsProfileElements(
sourceProfile: ControlsProfile,
targetProfile: ControlsProfile,
view: InputControlsView
) {
sourceProfile.loadElements(view)
targetProfile.elements.toList().forEach(targetProfile::removeElement)
sourceProfile.elements.forEach { targetProfile.addElement(it.copyForView(view)) }
view.invalidate()
}

private fun ControlElement.copyForView(view: InputControlsView) = ControlElement(view).also { newElement ->
newElement.setType(type)
newElement.setShape(shape)
newElement.setX(x.toInt())
newElement.setY(y.toInt())
newElement.setScale(scale)
newElement.setText(text)
newElement.setIconId(iconId.toInt())
newElement.setToggleSwitch(isToggleSwitch)
newElement.copyButtonAppearanceFrom(this)

if (type == ControlElement.Type.RANGE_BUTTON) {
newElement.setRange(range)
newElement.setOrientation(orientation)
newElement.setBindingCount(bindingCount)
newElement.isScrollLocked = isScrollLocked
}

for (i in 0 until bindingCount) {
newElement.setBindingAt(i, getBindingAt(i))
}

if (type == ControlElement.Type.SHOOTER_MODE) {
newElement.shooterMovementType = shooterMovementType
newElement.shooterLookType = shooterLookType
newElement.shooterLookSensitivity = shooterLookSensitivity
newElement.shooterJoystickSize = shooterJoystickSize
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2493,46 +2493,7 @@ fun XServerScreen(
// Wait for view to be laid out before loading elements
PluviaApp.inputControlsView?.let { icView ->
icView.post {
// Load Profile 0 elements (with valid dimensions)
profile.loadElements(icView)

// Clear current profile elements and copy from Profile 0
val elementsToRemove = currentProfile.elements.toList()
elementsToRemove.forEach { currentProfile.removeElement(it) }

profile.elements.forEach { element ->
val newElement = com.winlator.inputcontrols.ControlElement(icView)
newElement.setType(element.type)
newElement.setShape(element.shape)
newElement.setX(element.x.toInt())
newElement.setY(element.y.toInt())
newElement.setScale(element.scale)
newElement.setText(element.text)
newElement.setIconId(element.iconId.toInt())
newElement.setToggleSwitch(element.isToggleSwitch)
// Copy range button properties — must set binding count
// BEFORE copying bindings, because setBindingCount resets
// the bindings array to NONE.
if (element.type == com.winlator.inputcontrols.ControlElement.Type.RANGE_BUTTON) {
newElement.setRange(element.range)
newElement.setOrientation(element.orientation)
newElement.setBindingCount(element.bindingCount)
newElement.isScrollLocked = element.isScrollLocked
}
for (i in 0 until element.bindingCount) {
newElement.setBindingAt(i, element.getBindingAt(i))
}
// Copy shooter mode properties
if (element.type == com.winlator.inputcontrols.ControlElement.Type.SHOOTER_MODE) {
newElement.shooterMovementType = element.shooterMovementType
newElement.shooterLookType = element.shooterLookType
newElement.shooterLookSensitivity = element.shooterLookSensitivity
newElement.shooterJoystickSize = element.shooterJoystickSize
}
currentProfile.addElement(newElement)
}

icView.invalidate()
copyInputControlsProfileElements(profile, currentProfile, icView)
SnackbarManager.show(context.getString(R.string.toast_controls_reset))
}
}
Expand Down
Loading
Loading