mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 16:27:47 +00:00
Rework KeyModifiers system to properly allow keybinds to be triggered when multiple modifiers are pressed.
Fix setting keybinds whel using keyboard inputs to select the menu. Closes #9793
This commit is contained in:
6 files changed
+67
-40
No files matched your search
@@ -90,12 +90,12 @@
|
||||
}
|
||||
|
||||
public String m_90865_() {
|
||||
@@ -184,4 +_,84 @@
|
||||
@@ -183,5 +_,88 @@
|
||||
|
||||
public void m_7249_(boolean p_90846_) {
|
||||
this.f_90817_ = p_90846_;
|
||||
}
|
||||
+ }
|
||||
+
|
||||
+ /****************** Forge Start *****************************/
|
||||
+ private net.minecraftforge.client.settings.KeyModifier keyModifierDefault = net.minecraftforge.client.settings.KeyModifier.NONE;
|
||||
+ private net.minecraftforge.client.settings.KeyModifier keyModifier = net.minecraftforge.client.settings.KeyModifier.NONE;
|
||||
+ private net.minecraftforge.client.settings.IKeyConflictContext keyConflictContext = net.minecraftforge.client.settings.KeyConflictContext.UNIVERSAL;
|
||||
@@ -165,13 +165,17 @@
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void setKeyModifierAndCode(net.minecraftforge.client.settings.KeyModifier keyModifier, InputConstants.Key keyCode) {
|
||||
+ this.f_90816_ = keyCode;
|
||||
+ if (keyModifier.matches(keyCode))
|
||||
+ keyModifier = net.minecraftforge.client.settings.KeyModifier.NONE;
|
||||
+ public void setKeyModifierAndCode(@org.jetbrains.annotations.Nullable net.minecraftforge.client.settings.KeyModifier keyModifier, InputConstants.Key keyCode) {
|
||||
+ f_90810_.remove(this);
|
||||
+
|
||||
+ if (keyModifier == null)
|
||||
+ keyModifier = net.minecraftforge.client.settings.KeyModifier.getModifier(this.f_90816_);
|
||||
+ if (keyModifier == null || keyCode == InputConstants.f_84822_ || net.minecraftforge.client.settings.KeyModifier.isKeyCodeModifier(keyCode))
|
||||
+ keyModifier = net.minecraftforge.client.settings.KeyModifier.NONE;
|
||||
+
|
||||
+ this.f_90816_ = keyCode;
|
||||
+ this.keyModifier = keyModifier;
|
||||
+
|
||||
+ f_90810_.put(keyCode, this);
|
||||
+ }
|
||||
+ /****************** Forge End *****************************/
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,6 @@
|
||||
--- a/net/minecraft/client/KeyboardHandler.java
|
||||
+++ b/net/minecraft/client/KeyboardHandler.java
|
||||
@@ -329,7 +_,9 @@
|
||||
}
|
||||
}
|
||||
|
||||
- if (p_90897_ == 1 && (!(this.f_90867_.f_91080_ instanceof KeyBindsScreen) || ((KeyBindsScreen)screen).f_193976_ <= Util.m_137550_() - 20L)) {
|
||||
+
|
||||
+ if ((!(this.f_90867_.f_91080_ instanceof KeyBindsScreen) || ((KeyBindsScreen)screen).f_193976_ <= Util.m_137550_() - 20L)) {
|
||||
+ if (p_90897_ == 1) {
|
||||
if (this.f_90867_.f_91066_.f_92105_.m_90832_(p_90895_, p_90896_)) {
|
||||
this.f_90867_.m_91268_().m_85438_();
|
||||
this.f_90867_.f_91066_.m_231829_().m_231514_(this.f_90867_.m_91268_().m_85440_());
|
||||
@@ -347,6 +_,8 @@
|
||||
});
|
||||
return;
|
||||
}
|
||||
+ } else if (p_90897_ == 0 /*GLFW_RELEASE*/ && this.f_90867_.f_91080_ instanceof KeyBindsScreen)
|
||||
+ ((KeyBindsScreen)this.f_90867_.f_91080_).f_193975_ = null; //Forge: Unset pure modifiers.
|
||||
}
|
||||
|
||||
if (this.f_90867_.m_240477_().m_93316_()) {
|
||||
@@ -369,11 +_,15 @@
|
||||
@@ -329,6 +_,7 @@
|
||||
Screen.m_96579_(() -> {
|
||||
if (p_90897_ != 1 && p_90897_ != 2) {
|
||||
if (p_90897_ == 0) {
|
||||
|
||||
@@ -9,9 +9,11 @@
|
||||
}
|
||||
|
||||
public int m_5759_() {
|
||||
@@ -129,10 +_,11 @@
|
||||
@@ -128,11 +_,13 @@
|
||||
this.f_193911_ = p_193917_;
|
||||
this.f_193912_ = Button.m_253074_(p_193917_, (p_269618_) -> {
|
||||
KeyBindsList.this.f_193858_.f_193975_ = p_193916_;
|
||||
+ p_193916_.setKeyModifierAndCode(null, com.mojang.blaze3d.platform.InputConstants.f_84822_);
|
||||
KeyBindsList.this.m_269130_();
|
||||
- }).m_252987_(0, 0, 75, 20).m_252778_((p_253311_) -> {
|
||||
+ }).m_252987_(0, 0, 75 + 20 /* Forge: Add space */, 20).m_252778_((p_253311_) -> {
|
||||
|
||||
+23
-3
@@ -13,14 +13,34 @@
|
||||
public boolean m_7933_(int p_193987_, int p_193988_, int p_193989_) {
|
||||
if (this.f_193975_ != null) {
|
||||
if (p_193987_ == 256) {
|
||||
+ this.f_193975_.setKeyModifierAndCode(net.minecraftforge.client.settings.KeyModifier.getActiveModifier(), InputConstants.f_84822_);
|
||||
+ this.f_193975_.setKeyModifierAndCode(null, InputConstants.f_84822_);
|
||||
this.f_96282_.m_92159_(this.f_193975_, InputConstants.f_84822_);
|
||||
} else {
|
||||
+ this.f_193975_.setKeyModifierAndCode(net.minecraftforge.client.settings.KeyModifier.getActiveModifier(), InputConstants.m_84827_(p_193987_, p_193988_));
|
||||
+ this.f_193975_.setKeyModifierAndCode(null, InputConstants.m_84827_(p_193987_, p_193988_));
|
||||
this.f_96282_.m_92159_(this.f_193975_, InputConstants.m_84827_(p_193987_, p_193988_));
|
||||
}
|
||||
|
||||
+ if(!net.minecraftforge.client.settings.KeyModifier.isKeyCodeModifier(this.f_193975_.getKey()))
|
||||
+ if (p_193987_ == 256 || !net.minecraftforge.client.settings.KeyModifier.isKeyCodeModifier(this.f_193975_.getKey()))
|
||||
this.f_193975_ = null;
|
||||
this.f_193976_ = Util.m_137550_();
|
||||
this.f_193977_.m_269130_();
|
||||
@@ -67,6 +_,19 @@
|
||||
} else {
|
||||
return super.m_7933_(p_193987_, p_193988_, p_193989_);
|
||||
}
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean m_7920_(int keyCode, int scanCode, int modifiers) {
|
||||
+ // Forge: We wait for a second key above if the first press is a modifier
|
||||
+ // but if they release the modifier then set it explicitly.
|
||||
+ var key = InputConstants.m_84827_(keyCode, scanCode);
|
||||
+ if (this.f_193975_ != null && this.f_193975_.getKey() == key) {
|
||||
+ this.f_193975_ = null;
|
||||
+ this.f_193976_ = Util.m_137550_();
|
||||
+ this.f_193977_.m_269130_();
|
||||
+ }
|
||||
+ return super.m_7920_(keyCode, scanCode, modifiers);
|
||||
}
|
||||
|
||||
public void m_88315_(GuiGraphics p_282556_, int p_193992_, int p_193993_, float p_193994_) {
|
||||
@@ -58,15 +58,17 @@ public class KeyMappingLookup {
|
||||
*/
|
||||
public List<KeyMapping> getAll(InputConstants.Key keyCode) {
|
||||
var ret = new ArrayList<KeyMapping>();
|
||||
var modifier = KeyModifier.getActiveModifier();
|
||||
if (!modifier.matches(keyCode)) {
|
||||
for (var modifier : KeyModifier.getValues(false)) {
|
||||
if (!modifier.isActive(null) || modifier.matches(keyCode))
|
||||
continue;
|
||||
|
||||
for (var binding : get(modifier, keyCode)) {
|
||||
if (binding.isActiveAndMatches(keyCode))
|
||||
ret.add(binding);
|
||||
}
|
||||
}
|
||||
|
||||
if (!ret.isEmpty() || modifier == KeyModifier.NONE)
|
||||
if (!ret.isEmpty())
|
||||
return ret;
|
||||
|
||||
for (var binding : get(KeyModifier.NONE, keyCode)) {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
package net.minecraftforge.client.settings;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -78,7 +79,7 @@ public enum KeyModifier {
|
||||
@Override
|
||||
public boolean isActive(@Nullable IKeyConflictContext conflictContext) {
|
||||
if (conflictContext != null && !conflictContext.conflicts(KeyConflictContext.IN_GAME)) {
|
||||
for (KeyModifier keyModifier : MODIFIER_VALUES) {
|
||||
for (KeyModifier keyModifier : VALUES) {
|
||||
if (keyModifier.isActive(conflictContext))
|
||||
return false;
|
||||
}
|
||||
@@ -92,18 +93,36 @@ public enum KeyModifier {
|
||||
}
|
||||
};
|
||||
|
||||
@Deprecated(forRemoval = true, since = "1.20.2")
|
||||
public static final KeyModifier[] MODIFIER_VALUES = {SHIFT, CONTROL, ALT};
|
||||
|
||||
@Deprecated(forRemoval = true, since = "1.20.2")
|
||||
public static KeyModifier getActiveModifier() {
|
||||
for (KeyModifier keyModifier : MODIFIER_VALUES) {
|
||||
for (var keyModifier : VALUES) {
|
||||
if (keyModifier.isActive(null))
|
||||
return keyModifier;
|
||||
}
|
||||
return NONE;
|
||||
}
|
||||
|
||||
private static final KeyModifier[] VALUES = {SHIFT, CONTROL, ALT};
|
||||
private static final List<KeyModifier> VALUES_LIST = List.of(SHIFT, CONTROL, ALT);
|
||||
private static final List<KeyModifier> ALL = List.of(SHIFT, CONTROL, ALT, NONE);
|
||||
public static final List<KeyModifier> getValues(boolean includeNone) {
|
||||
return includeNone ? ALL : VALUES_LIST;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static KeyModifier getModifier(InputConstants.Key key) {
|
||||
for (var modifier : VALUES) {
|
||||
if (modifier.matches(key))
|
||||
return modifier;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isKeyCodeModifier(InputConstants.Key key) {
|
||||
for (KeyModifier keyModifier : MODIFIER_VALUES) {
|
||||
for (KeyModifier keyModifier : VALUES) {
|
||||
if (keyModifier.matches(key))
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user