Add better key modifier behavior for GUI contexts (#3307)
This commit is contained in:
parent
7bbd3954f5
commit
bea5d44273
2 changed files with 53 additions and 6 deletions
|
@ -53,11 +53,11 @@
|
|||
public boolean func_151470_d()
|
||||
{
|
||||
- return this.field_74513_e;
|
||||
+ return this.field_74513_e && getKeyConflictContext().isActive() && getKeyModifier().isActive();
|
||||
+ return this.field_74513_e && getKeyConflictContext().isActive() && getKeyModifier().isActive(getKeyConflictContext());
|
||||
}
|
||||
|
||||
public String func_151466_e()
|
||||
@@ -158,4 +158,130 @@
|
||||
@@ -158,4 +158,135 @@
|
||||
|
||||
return i;
|
||||
}
|
||||
|
@ -101,7 +101,7 @@
|
|||
+ */
|
||||
+ public boolean isActiveAndMatches(int keyCode)
|
||||
+ {
|
||||
+ return keyCode != 0 && keyCode == this.func_151463_i() && getKeyConflictContext().isActive() && getKeyModifier().isActive();
|
||||
+ return keyCode != 0 && keyCode == this.func_151463_i() && getKeyConflictContext().isActive() && getKeyModifier().isActive(getKeyConflictContext());
|
||||
+ }
|
||||
+
|
||||
+ public void setKeyConflictContext(net.minecraftforge.client.settings.IKeyConflictContext keyConflictContext)
|
||||
|
@ -159,9 +159,14 @@
|
|||
+ {
|
||||
+ return true;
|
||||
+ }
|
||||
+ else if (keyModifier == otherKeyModifier || keyModifier == net.minecraftforge.client.settings.KeyModifier.NONE || otherKeyModifier == net.minecraftforge.client.settings.KeyModifier.NONE)
|
||||
+ else if (func_151463_i() == other.func_151463_i())
|
||||
+ {
|
||||
+ return func_151463_i() == other.func_151463_i();
|
||||
+ return keyModifier == otherKeyModifier ||
|
||||
+ // IN_GAME key contexts have a conflict when at least one modifier is NONE.
|
||||
+ // For example: If you hold shift to crouch, you can still press E to open your inventory. This means that a Shift+E hotkey is in conflict with E.
|
||||
+ // GUI and other key contexts do not have this limitation.
|
||||
+ (getKeyConflictContext().conflicts(net.minecraftforge.client.settings.KeyConflictContext.IN_GAME) &&
|
||||
+ (keyModifier == net.minecraftforge.client.settings.KeyModifier.NONE || otherKeyModifier == net.minecraftforge.client.settings.KeyModifier.NONE));
|
||||
+ }
|
||||
+ }
|
||||
+ return false;
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
package net.minecraftforge.client.settings;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
|
@ -46,6 +48,12 @@ public enum KeyModifier {
|
|||
return GuiScreen.isCtrlKeyDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive(@Nullable IKeyConflictContext conflictContext)
|
||||
{
|
||||
return GuiScreen.isCtrlKeyDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalizedComboName(int keyCode)
|
||||
{
|
||||
|
@ -67,6 +75,12 @@ public enum KeyModifier {
|
|||
return GuiScreen.isShiftKeyDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive(@Nullable IKeyConflictContext conflictContext)
|
||||
{
|
||||
return GuiScreen.isShiftKeyDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalizedComboName(int keyCode)
|
||||
{
|
||||
|
@ -87,6 +101,12 @@ public enum KeyModifier {
|
|||
return GuiScreen.isAltKeyDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive(@Nullable IKeyConflictContext conflictContext)
|
||||
{
|
||||
return GuiScreen.isAltKeyDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalizedComboName(int keyCode)
|
||||
{
|
||||
|
@ -107,6 +127,22 @@ public enum KeyModifier {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive(@Nullable IKeyConflictContext conflictContext)
|
||||
{
|
||||
if (conflictContext != null && !conflictContext.conflicts(KeyConflictContext.IN_GAME))
|
||||
{
|
||||
for (KeyModifier keyModifier : MODIFIER_VALUES)
|
||||
{
|
||||
if (keyModifier.isActive(conflictContext))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalizedComboName(int keyCode)
|
||||
{
|
||||
|
@ -120,7 +156,7 @@ public enum KeyModifier {
|
|||
{
|
||||
for (KeyModifier keyModifier : MODIFIER_VALUES)
|
||||
{
|
||||
if (keyModifier.isActive())
|
||||
if (keyModifier.isActive(null))
|
||||
{
|
||||
return keyModifier;
|
||||
}
|
||||
|
@ -158,7 +194,13 @@ public enum KeyModifier {
|
|||
|
||||
public abstract boolean matches(int keyCode);
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #isActive(IKeyConflictContext)}
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract boolean isActive();
|
||||
|
||||
public abstract boolean isActive(@Nullable IKeyConflictContext conflictContext);
|
||||
|
||||
public abstract String getLocalizedComboName(int keyCode);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue