-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #439 from WaitingIdly/improved-toast-control
Improve Toast Control capability
- Loading branch information
Showing
7 changed files
with
215 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/mod/acgaming/universaltweaks/tweaks/misc/toastcontrol/UTClearToastKeybind.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package mod.acgaming.universaltweaks.tweaks.misc.toastcontrol; | ||
|
||
import mod.acgaming.universaltweaks.config.UTConfigTweaks; | ||
import mod.acgaming.universaltweaks.util.UTKeybindings; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraftforge.client.settings.KeyConflictContext; | ||
import net.minecraftforge.client.settings.KeyModifier; | ||
import net.minecraftforge.fml.relauncher.Side; | ||
import net.minecraftforge.fml.relauncher.SideOnly; | ||
import org.lwjgl.input.Keyboard; | ||
|
||
@SideOnly(Side.CLIENT) | ||
public class UTClearToastKeybind extends UTKeybindings.Key | ||
{ | ||
public UTClearToastKeybind() | ||
{ | ||
super("clear_toasts", KeyConflictContext.IN_GAME, KeyModifier.CONTROL, Keyboard.KEY_0); | ||
} | ||
|
||
public static void createKeybind() | ||
{ | ||
if (UTConfigTweaks.MISC.TOAST_CONTROL.utToastControlToggle && UTConfigTweaks.MISC.TOAST_CONTROL.utClearToastKeybind) UTKeybindings.addKey(new UTClearToastKeybind()); | ||
} | ||
|
||
@SideOnly(Side.CLIENT) | ||
@Override | ||
public void handleKeybind() | ||
{ | ||
Minecraft.getMinecraft().getToastGui().clear(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...ain/java/mod/acgaming/universaltweaks/tweaks/misc/toastcontrol/mixin/UTGuiToastMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package mod.acgaming.universaltweaks.tweaks.misc.toastcontrol.mixin; | ||
|
||
import mod.acgaming.universaltweaks.UniversalTweaks; | ||
import mod.acgaming.universaltweaks.config.UTConfigTweaks; | ||
import net.minecraft.client.gui.toasts.GuiToast; | ||
import net.minecraft.client.gui.toasts.IToast; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import java.util.Arrays; | ||
|
||
@Mixin(value = GuiToast.class) | ||
public abstract class UTGuiToastMixin | ||
{ | ||
@Inject(method = "add", at = @At(value = "HEAD"), cancellable = true) | ||
private void utFilterToasts(IToast toastIn, CallbackInfo ci) | ||
{ | ||
if (UTConfigTweaks.MISC.TOAST_CONTROL.utToastNameLogging) UniversalTweaks.LOGGER.info("UTGuiToastMixin ::: Displaying Toast: " + toastIn.getClass().getName()); | ||
boolean isWhitelist = UTConfigTweaks.MISC.TOAST_CONTROL.utToastControlClassListMode == UTConfigTweaks.EnumLists.WHITELIST; | ||
if (Arrays.asList(UTConfigTweaks.MISC.TOAST_CONTROL.utToastControlClassList).contains(toastIn.getClass().getName()) != isWhitelist) ci.cancel(); | ||
} | ||
} |
127 changes: 127 additions & 0 deletions
127
src/main/java/mod/acgaming/universaltweaks/util/UTKeybindings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package mod.acgaming.universaltweaks.util; | ||
|
||
import mod.acgaming.universaltweaks.UniversalTweaks; | ||
import mod.acgaming.universaltweaks.tweaks.misc.toastcontrol.UTClearToastKeybind; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.settings.KeyBinding; | ||
import net.minecraftforge.client.settings.IKeyConflictContext; | ||
import net.minecraftforge.client.settings.KeyConflictContext; | ||
import net.minecraftforge.client.settings.KeyModifier; | ||
import net.minecraftforge.fml.client.registry.ClientRegistry; | ||
import net.minecraftforge.fml.common.Mod; | ||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; | ||
import net.minecraftforge.fml.common.gameevent.InputEvent; | ||
import net.minecraftforge.fml.relauncher.Side; | ||
import net.minecraftforge.fml.relauncher.SideOnly; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Mod.EventBusSubscriber(modid = UniversalTweaks.MODID, value = Side.CLIENT) | ||
@SideOnly(Side.CLIENT) | ||
public class UTKeybindings extends KeyBinding | ||
{ | ||
private static final List<Key> keys = new ArrayList<>(); | ||
|
||
protected UTKeybindings(UTKeybindings.Key key) | ||
{ | ||
super(key.getDescription(), key.getKeyConflictContext(), key.getKeyModifier(), key.getKeyCode(), UniversalTweaks.NAME); | ||
ClientRegistry.registerKeyBinding(this); | ||
} | ||
|
||
public static void addKey(UTKeybindings.Key key) | ||
{ | ||
keys.add(key); | ||
} | ||
|
||
public static void initialize() | ||
{ | ||
UTClearToastKeybind.createKeybind(); | ||
|
||
for (Key key : keys) | ||
{ | ||
key.getKey(); | ||
} | ||
} | ||
|
||
@SubscribeEvent | ||
public static void onKeyInput(InputEvent event) | ||
{ | ||
if (!Minecraft.getMinecraft().inGameHasFocus) return; | ||
|
||
for (Key key : keys) | ||
{ | ||
if (key.getKey().isPressed()) key.handleKeybind(); | ||
} | ||
} | ||
|
||
public static abstract class Key | ||
{ | ||
private final String name; | ||
private final IKeyConflictContext keyConflictContext; | ||
private final KeyModifier keyModifier; | ||
private final int keyCode; | ||
|
||
@SideOnly(Side.CLIENT) | ||
private KeyBinding key; | ||
|
||
public Key(String name, int keyCode) | ||
{ | ||
this(name, KeyConflictContext.UNIVERSAL, keyCode); | ||
} | ||
|
||
public Key(String name, IKeyConflictContext keyConflictContext, int keyCode) | ||
{ | ||
this(name, keyConflictContext, KeyModifier.NONE, keyCode); | ||
} | ||
|
||
public Key(String name, IKeyConflictContext keyConflictContext, KeyModifier keyModifier, int keyCode) | ||
{ | ||
this.name = name; | ||
this.keyConflictContext = keyConflictContext; | ||
this.keyModifier = keyModifier; | ||
this.keyCode = keyCode; | ||
} | ||
|
||
@SideOnly(Side.CLIENT) | ||
public abstract void handleKeybind(); | ||
|
||
public String getName() | ||
{ | ||
return name; | ||
} | ||
|
||
public IKeyConflictContext getKeyConflictContext() | ||
{ | ||
return keyConflictContext; | ||
} | ||
|
||
public KeyModifier getKeyModifier() | ||
{ | ||
return keyModifier; | ||
} | ||
|
||
public int getKeyCode() | ||
{ | ||
return keyCode; | ||
} | ||
|
||
@SideOnly(Side.CLIENT) | ||
public KeyBinding getKey() | ||
{ | ||
if (key == null) key = new UTKeybindings(this); | ||
return key; | ||
} | ||
|
||
@SideOnly(Side.CLIENT) | ||
public void setKey(KeyBinding key) | ||
{ | ||
this.key = key; | ||
} | ||
|
||
public String getDescription() | ||
{ | ||
return String.format("keybind.%s.%s", UniversalTweaks.MODID, name); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters