Handle mouse clicks in radial menu
This commit is contained in:
parent
fa647a4b5c
commit
accfe1ebc5
@ -180,6 +180,7 @@ public final class OverdriveThatMatters {
|
||||
}
|
||||
|
||||
EVENT_BUS.addListener(EventPriority.NORMAL, AndroidMenuKeyMapping.INSTANCE::onRenderGuiEvent);
|
||||
EVENT_BUS.addListener(EventPriority.NORMAL, AndroidMenuKeyMapping.INSTANCE::onMouseClick);
|
||||
|
||||
event.enqueueWork(GlobalEventHandlerKt::recordClientThread);
|
||||
|
||||
|
@ -5,6 +5,7 @@ import com.mojang.blaze3d.systems.RenderSystem
|
||||
import it.unimi.dsi.fastutil.objects.Object2FloatArrayMap
|
||||
import it.unimi.dsi.fastutil.objects.Object2FloatFunction
|
||||
import net.minecraft.client.KeyMapping
|
||||
import net.minecraftforge.client.event.InputEvent
|
||||
import net.minecraftforge.client.event.RegisterKeyMappingsEvent
|
||||
import net.minecraftforge.client.event.RenderGuiEvent
|
||||
import net.minecraftforge.client.settings.KeyConflictContext
|
||||
@ -41,6 +42,10 @@ object AndroidMenuKeyMapping : KeyMapping("key.otm.android_menu", KeyConflictCon
|
||||
private var lastSelectedDegree: Double? = null
|
||||
private val lastSelectProgress = Object2FloatArrayMap<AndroidFeature>()
|
||||
|
||||
private var holdIt: AndroidSwitchableFeature? = null
|
||||
|
||||
private var clickOnce = false
|
||||
|
||||
override fun setDown(isDown: Boolean) {
|
||||
val old = this.isDown
|
||||
super.setDown(isDown)
|
||||
@ -60,6 +65,7 @@ object AndroidMenuKeyMapping : KeyMapping("key.otm.android_menu", KeyConflictCon
|
||||
if (minecraft.screen == null) {
|
||||
minecraft.mouseHandler.grabMouse()
|
||||
|
||||
if (!clickOnce) {
|
||||
val selectedFeature = selectedFeature
|
||||
|
||||
if (selectedFeature != null) {
|
||||
@ -67,11 +73,35 @@ object AndroidMenuKeyMapping : KeyMapping("key.otm.android_menu", KeyConflictCon
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
selectedFeature = null
|
||||
lastSelectedFeature = null
|
||||
lastSelectedDegree = null
|
||||
lastSelectProgress.clear()
|
||||
clickOnce = false
|
||||
holdIt = null
|
||||
}
|
||||
}
|
||||
|
||||
fun onMouseClick(event: InputEvent.MouseButton.Pre) {
|
||||
if (grabbedInput) {
|
||||
clickOnce = true
|
||||
event.isCanceled = true
|
||||
|
||||
if (event.button == InputConstants.MOUSE_BUTTON_LEFT && event.action == 1) {
|
||||
if (selectedFeature != null) {
|
||||
playGuiClickSound()
|
||||
holdIt = selectedFeature
|
||||
}
|
||||
} else if (event.button == InputConstants.MOUSE_BUTTON_LEFT && event.action == 0) {
|
||||
holdIt = null
|
||||
val selectedFeature = selectedFeature
|
||||
|
||||
if (selectedFeature != null) {
|
||||
MatteryPlayerNetworkChannel.sendToServer(SwitchAndroidFeaturePacket(selectedFeature.type, !selectedFeature.isActive))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -114,7 +144,7 @@ object AndroidMenuKeyMapping : KeyMapping("key.otm.android_menu", KeyConflictCon
|
||||
|
||||
val length = (mouseX * mouseX + mouseY * mouseY).pow(0.5)
|
||||
|
||||
if ((length / minecraft.window.guiScale) in (size * 0.3f) .. size) {
|
||||
if ((length / minecraft.window.guiScale) in (size * 0.3f) .. size || holdIt != null) {
|
||||
var deg = acos(mouseX / length)
|
||||
|
||||
// opengl
|
||||
@ -127,7 +157,7 @@ object AndroidMenuKeyMapping : KeyMapping("key.otm.android_menu", KeyConflictCon
|
||||
deg += PI * 2
|
||||
}
|
||||
|
||||
val index = (deg / degreePerSlice).toInt()
|
||||
val index = if (holdIt != null) features.indexOf(holdIt) else (deg / degreePerSlice).toInt()
|
||||
selectedFeature = features[index]
|
||||
lastSelectedFeature = features[index]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user