Skip to content

Commit

Permalink
allow scrolling in gui
Browse files Browse the repository at this point in the history
  • Loading branch information
ImToggle committed Jul 25, 2024
1 parent f0211a8 commit f7f8da1
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.polyfrost.chatting.mixin;

import cc.polyfrost.oneconfig.utils.Notifications;
import org.polyfrost.chatting.config.ChattingConfig;
import org.spongepowered.asm.mixin.Dynamic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Pseudo
@Mixin(targets = {"at.hannibal2.skyhanni.features.chat.ChatPeek"})
public class ChatPeekMixin_SkyHanni {

@Unique
private static long chatting$lastNotify = System.currentTimeMillis();

@Dynamic("SkyHanni")
@Inject(method = "peek", at = @At("HEAD"), cancellable = true, remap = false)
private static void cancel(CallbackInfoReturnable<Boolean> cir) {
if (!ChattingConfig.INSTANCE.getChatPeek() && cir.getReturnValue()) {
if (System.currentTimeMillis() - chatting$lastNotify >= 1000) {
Notifications.INSTANCE.send("Chatting", "SkyHanni's chat peek has been replaced by Chatting. You can configure this via OneConfig, by clicking the right shift key on your keyboard, or by typing /chatting in your chat.");
chatting$lastNotify = System.currentTimeMillis();
}
}
cir.setReturnValue(false);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.polyfrost.chatting.mixin;

import net.minecraft.client.gui.inventory.GuiContainerCreative;
import org.polyfrost.chatting.Chatting;
import org.polyfrost.chatting.config.ChattingConfig;
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;

@Mixin(GuiContainerCreative.class)
public class GuiContainerCreativeMixin {

@Inject(method = "handleMouseInput", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Mouse;getEventDWheel()I"), cancellable = true)
private void cancelScrolling(CallbackInfo ci) {
if (Chatting.INSTANCE.getPeeking() && ChattingConfig.INSTANCE.getPeekScrolling()) {
ci.cancel();
}
}
}
35 changes: 17 additions & 18 deletions src/main/kotlin/org/polyfrost/chatting/Chatting.kt
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,23 @@ object Chatting {

@SubscribeEvent
fun onTickEvent(event: TickEvent.ClientTickEvent) {
if (event.phase == TickEvent.Phase.START && mc.theWorld != null && mc.thePlayer != null && (mc.currentScreen == null || mc.currentScreen is GuiChat)) {
if (doTheThing) {
screenshotChat()
doTheThing = false
if (event.phase == TickEvent.Phase.START && mc.theWorld != null && mc.thePlayer != null) {
if ((mc.currentScreen == null || mc.currentScreen is GuiChat)) {
if (doTheThing) {
screenshotChat()
doTheThing = false
}
}

val key = ChattingConfig.chatPeekBind
if (key.isActive != lastPressed && ChattingConfig.chatPeek) {
lastPressed = key.isActive
if (key.isActive) {
peeking = !peeking
} else if (!ChattingConfig.peekMode) {
peeking = false
}
if (!peeking) mc.ingameGUI.chatGUI.resetScroll()
}

if (mc.currentScreen is GuiChat) peeking = false
Expand All @@ -191,20 +204,6 @@ object Chatting {
}
}

@SubscribeEvent
fun peek(e: KeyInputEvent) {
val key = ChattingConfig.chatPeekBind
if (key.isActive != lastPressed && ChattingConfig.chatPeek) {
lastPressed = key.isActive
if (key.isActive) {
peeking = !peeking
} else if (!ChattingConfig.peekMode) {
peeking = false
}
if (!peeking) mc.ingameGUI.chatGUI.resetScroll()
}
}

fun getChatHeight(opened: Boolean): Int {
return if (opened) ChattingConfig.chatWindow.focusedHeight else ChattingConfig.chatWindow.unfocusedHeight
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/mixins.chatting.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"EntityRendererMixin",
"GameSettingsMixin",
"GuiChatMixin",
"GuiContainerCreativeMixin",
"GuiIngameForgeAccessor",
"GuiIngameForgeMixin",
"GuiNewChatAccessor",
Expand All @@ -28,6 +29,7 @@
"InventoryPlayerMixin"
],
"mixins": [
"ChatPeekMixin_SkyHanni",
"ChatStyleMixin",
"EssentialKeybindingRegistryMixin"
]
Expand Down

0 comments on commit f7f8da1

Please sign in to comment.