Skip to content

Commit

Permalink
so many features
Browse files Browse the repository at this point in the history
  • Loading branch information
ImToggle committed Jan 29, 2024
1 parent 6161f12 commit 526161e
Show file tree
Hide file tree
Showing 13 changed files with 202 additions and 63 deletions.
44 changes: 19 additions & 25 deletions src/main/java/org/polyfrost/chatting/mixin/GuiChatMixin.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.polyfrost.chatting.mixin;

import cc.polyfrost.oneconfig.libs.universal.UDesktop;
import cc.polyfrost.oneconfig.libs.universal.UKeyboard;
import cc.polyfrost.oneconfig.libs.universal.*;
import com.google.common.collect.Lists;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.*;
Expand All @@ -11,20 +10,11 @@
import org.lwjgl.input.Mouse;
import org.polyfrost.chatting.chat.*;
import org.polyfrost.chatting.config.ChattingConfig;
import org.polyfrost.chatting.gui.components.CleanButton;
import org.polyfrost.chatting.gui.components.ClearButton;
import org.polyfrost.chatting.gui.components.ScreenshotButton;
import org.polyfrost.chatting.gui.components.SearchButton;
import org.polyfrost.chatting.hook.ChatLineHook;
import org.polyfrost.chatting.hook.GuiChatHook;
import org.polyfrost.chatting.hook.GuiNewChatHook;
import org.polyfrost.chatting.gui.components.*;
import org.polyfrost.chatting.hook.*;
import org.polyfrost.chatting.utils.ModCompatHooks;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
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.ModifyArg;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.awt.*;
Expand Down Expand Up @@ -69,7 +59,7 @@ public abstract class GuiChatMixin extends GuiScreen implements GuiChatHook {
@Inject(method = "initGui", at = @At("TAIL"))
private void init(CallbackInfo ci) {
chatting$initButtons();
if (ChattingConfig.INSTANCE.getInputFieldDraft()) {
if (ChattingConfig.INSTANCE.getChatInput().getInputFieldDraft()) {
String command = (ChatHooks.INSTANCE.getCommandDraft().startsWith("/") ? "" : "/") + ChatHooks.INSTANCE.getCommandDraft();
inputField.setText(inputField.getText().equals("/") ? command : ChatHooks.INSTANCE.getDraft());
}
Expand Down Expand Up @@ -114,16 +104,20 @@ private void onDrawScreen(int mouseX, int mouseY, float partialTicks, CallbackIn
}
}

@ModifyArg(method = "drawScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiChat;drawRect(IIIII)V"), index = 2)
private int modifyRight(int right) {
@Redirect(method = "drawScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiChat;drawRect(IIIII)V"))
private void drawBG(int left, int top, int right, int bottom, int color) {
ChattingConfig config = ChattingConfig.INSTANCE;
ChatHooks.INSTANCE.setInputBoxRight(config.getCompactInputBox() ? Math.max((int) config.getChatWindow().getWidth() + 2, ChatHooks.INSTANCE.getInputRight() + (inputField.getText().length() < ModCompatHooks.getChatInputLimit() ? 8 : 2)) : right);
return ChatHooks.INSTANCE.getInputBoxRight();
ChatHooks.INSTANCE.setInputBoxRight(config.getChatInput().getCompactInputBox() ? Math.max((int) config.getChatWindow().getWidth() + 2, ChatHooks.INSTANCE.getInputRight() + (inputField.getText().length() < ModCompatHooks.getChatInputLimit() ? 8 : 2)) : right);
config.getChatInput().drawBG(left, bottom, ChatHooks.INSTANCE.getInputBoxRight() - left, top - bottom);
}

@ModifyArg(method = "drawScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiChat;drawRect(IIIII)V"), index = 4)
private int modifyInputBoxColor(int color) {
return ChattingConfig.INSTANCE.getInputBoxBackgroundColor().getRGB();
@Redirect(method = "drawScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiTextField;drawTextBox()V"))
private void scale(GuiTextField instance) {
ChatInputBox inputBox = ChattingConfig.INSTANCE.getChatInput();
GlStateManager.pushMatrix();
GlStateManager.scale(inputBox.getScale(), inputBox.getScale(), 1f);
instance.drawTextBox();
GlStateManager.popMatrix();
}

@Inject(method = "mouseClicked", at = @At("HEAD"))
Expand Down Expand Up @@ -163,14 +157,14 @@ private String modifySentMessage(String original) {

@Inject(method = "keyTyped", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiChat;sendChatMessage(Ljava/lang/String;)V"))
private void clearDraft(CallbackInfo ci) {
if (ChattingConfig.INSTANCE.getInputFieldDraft()) {
if (ChattingConfig.INSTANCE.getChatInput().getInputFieldDraft()) {
inputField.setText(inputField.getText().startsWith("/") ? "/" : "");
}
}

@Inject(method = "onGuiClosed", at = @At("HEAD"))
private void saveDraft(CallbackInfo ci) {
if (ChattingConfig.INSTANCE.getInputFieldDraft()) {
if (ChattingConfig.INSTANCE.getChatInput().getInputFieldDraft()) {
if (inputField.getText().startsWith("/")) {
ChatHooks.INSTANCE.setCommandDraft(inputField.getText());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ private void cancelTranslate(Args args) {

@Inject(method = "renderChat", at = @At(value = "HEAD"), cancellable = true, remap = false)
private void cancelChat(int width, int height, CallbackInfo ci) {
if (!ChattingConfig.INSTANCE.getChatWindow().isEnabled()) ci.cancel();
if (!ChattingConfig.INSTANCE.getChatWindow().canShow()) ci.cancel();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook {
private int scrollPos;
@Shadow
public abstract int getChatWidth();

@Unique
private static final ResourceLocation COPY = new ResourceLocation("chatting:copy.png");
@Unique
Expand Down Expand Up @@ -173,7 +172,7 @@ private void startScissor(int updateCounter, CallbackInfo ci) {
int mcScale = new ScaledResolution(mc).getScaleFactor();
GL11.glEnable(GL11.GL_SCISSOR_TEST);
int height = (int) hud.getAnimationHeight();
GL11.glScissor((int) hud.position.getX() * mcScale, mc.displayHeight - (int) (hud.position.getBottomY() + 1) * mcScale, (int) (hud.position.getWidth() + (getChatOpen() ? 20 : 0) * hud.getScale()) * mcScale, (height + 1) * mcScale);
GL11.glScissor((int) hud.position.getX() * mcScale, mc.displayHeight - (int) (hud.position.getBottomY() + 1) * mcScale, (int) hud.getAnimationWidth() * mcScale, (height + 1) * mcScale);
}

@Inject(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;popMatrix()V"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,29 @@

import net.minecraft.client.gui.GuiTextField;
import org.polyfrost.chatting.chat.ChatHooks;
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.ModifyVariable;

@Mixin(GuiTextField.class)
public abstract class GuiTextFieldMixin {

@ModifyVariable(method = "drawTextBox", at = @At(value = "STORE"), ordinal = 6)
@ModifyVariable(method = "drawTextBox", at = @At(value = "STORE"), ordinal = 3)
private int setX(int value) {
ChattingConfig config = ChattingConfig.INSTANCE;
if (ChatHooks.INSTANCE.checkField(this)) return (int) (value / config.getChatWindow().getScale());
return value;
}

@ModifyVariable(method = "drawTextBox", at = @At(value = "STORE"), ordinal = 4)
private int setY(int value) {
ChattingConfig config = ChattingConfig.INSTANCE;
if (ChatHooks.INSTANCE.checkField(this)) return (int) config.getChatInput().getBgTop();
return value;
}

@ModifyVariable(method = "drawTextBox", at = @At(value = "STORE"), ordinal = 5)
private int getRight(int right) {
if (ChatHooks.INSTANCE.checkField(this)) ChatHooks.INSTANCE.setInputRight(right);
return right;
Expand Down
63 changes: 63 additions & 0 deletions src/main/java/org/polyfrost/chatting/mixin/HudUtilsMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.polyfrost.chatting.mixin;

import cc.polyfrost.oneconfig.config.Config;
import cc.polyfrost.oneconfig.config.elements.BasicOption;
import cc.polyfrost.oneconfig.hud.HUDUtils;
import cc.polyfrost.oneconfig.hud.Hud;
import org.polyfrost.chatting.chat.ChatHooks;
import org.polyfrost.chatting.config.ChattingConfig;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Supplier;

@Mixin(HUDUtils.class)
public class HudUtilsMixin {

@Unique
private static boolean isChatWindow, isInputBox;

@Redirect(method = "addHudOptions", at = @At(value = "INVOKE", target = "Lcc/polyfrost/oneconfig/hud/Hud;setConfig(Lcc/polyfrost/oneconfig/config/Config;)V"), remap = false)
private static void detect(Hud instance, Config config) {
isChatWindow = instance.equals(ChattingConfig.INSTANCE.getChatWindow());
isInputBox = instance.equals(ChattingConfig.INSTANCE.getChatInput());
instance.setConfig(config);
}

@Redirect(method = "addHudOptions", at = @At(value = "INVOKE", target = "Ljava/util/ArrayList;add(Ljava/lang/Object;)Z"), remap = false)
private static boolean paddingY(ArrayList instance, Object e) {
BasicOption option = (BasicOption) e;
if (isChatWindow || isInputBox) {
ArrayList<BasicOption> removeQueue = new ArrayList<>();
for (Object object : instance) {
BasicOption basicOption = (BasicOption) object;
List<String> shows = Arrays.asList("Show in F3 (Debug)", "Show in GUIs", "Enabled", "Position Alignment");
if (basicOption.name.equals("Show in Chat") || (isInputBox && shows.contains(basicOption.name))) {
removeQueue.add(basicOption);
}
if (basicOption.name.equals("Input Field Draft")) {
basicOption.addListener(ChatHooks.INSTANCE::resetDraft);
}
}
instance.removeAll(removeQueue);
}
List<String> paddings = Arrays.asList("X-Padding", "Y-Padding");
if (isInputBox && paddings.contains(option.name)) return false;
return instance.add(option);
}

@Redirect(method = "addHudOptions", at = @At(value = "INVOKE", target = "Lcc/polyfrost/oneconfig/config/elements/BasicOption;addDependency(Ljava/lang/String;Ljava/util/function/Supplier;)V", ordinal = 5), remap = false)
private static void no(BasicOption instance, String optionName, Supplier<Boolean> supplier) {
if (isInputBox) return;
instance.addDependency(optionName, supplier);
}

@Redirect(method = "addHudOptions", at = @At(value = "INVOKE", target = "Lcc/polyfrost/oneconfig/config/elements/BasicOption;addDependency(Ljava/lang/String;Ljava/util/function/Supplier;)V", ordinal = 6), remap = false)
private static void no1(BasicOption instance, String optionName, Supplier<Boolean> supplier) {
if (isInputBox) return;
instance.addDependency(optionName, supplier);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.entity.player.InventoryPlayer;
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;
Expand All @@ -11,7 +12,7 @@
public class InventoryPlayerMixin {
@Inject(method = "changeCurrentItem", at = @At("HEAD"), cancellable = true)
private void cancelHotbarScrolling(int direction, CallbackInfo ci) {
if (Chatting.INSTANCE.getPeaking()) {
if (Chatting.INSTANCE.getPeaking() && ChattingConfig.INSTANCE.getPeakScrolling()) {
ci.cancel();
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/kotlin/org/polyfrost/chatting/Chatting.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ object Chatting {
var deltaTime = 17L
private var lastPressed = false;
var peaking = false
get() = ChattingConfig.chatPeak && field

private val fileFormatter: SimpleDateFormat = SimpleDateFormat("yyyy-MM-dd_HH.mm.ss'.png'")

Expand Down Expand Up @@ -177,7 +178,7 @@ object Chatting {

if (mc.currentScreen is GuiChat) peaking = false

if (peaking) {
if (peaking && ChattingConfig.peakScrolling) {
var i = Mouse.getDWheel().coerceIn(-1..1)

if (i != 0) {
Expand All @@ -196,14 +197,14 @@ object Chatting {
@SubscribeEvent
fun peak(e: KeyInputEvent) {
val key = ChattingConfig.chatPeakBind
if (key.isActive != lastPressed) {
if (key.isActive != lastPressed && ChattingConfig.chatPeak) {
lastPressed = key.isActive
if (key.isActive) {
peaking = !peaking
if (!peaking) mc.ingameGUI.chatGUI.resetScroll()
} else if (!ChattingConfig.peakMode) {
peaking = false
}
if (!peaking) mc.ingameGUI.chatGUI.resetScroll()
}
}

Expand Down
63 changes: 63 additions & 0 deletions src/main/kotlin/org/polyfrost/chatting/chat/ChatInputBox.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.polyfrost.chatting.chat

import cc.polyfrost.oneconfig.config.annotations.Exclude
import cc.polyfrost.oneconfig.config.annotations.Switch
import cc.polyfrost.oneconfig.hud.BasicHud
import cc.polyfrost.oneconfig.libs.universal.UMatrixStack
import cc.polyfrost.oneconfig.utils.dsl.nanoVG
import net.minecraft.client.renderer.GlStateManager
import org.polyfrost.chatting.utils.ModCompatHooks

class ChatInputBox: BasicHud(true, -100f, -100f) {

init {
paddingX = 0f
paddingY = 0f
}

@Switch(
name = "Compact Input Box", category = "Input Box",
description = "Make the chat input box the same width as the chat box."
)
var compactInputBox = false

@Switch(
name = "Input Field Draft", category = "Input Box",
description = "Drafts the text you wrote in the input field after closing the chat and back it up when opening the chat again."
)
var inputFieldDraft = false

@Exclude
var bgTop = 0f

fun drawBG(x: Float, y: Float, width: Float, height: Float) {
bgTop = y / scale + height + 2
if (!ModCompatHooks.shouldDrawInputBox) return
GlStateManager.enableAlpha()
GlStateManager.enableBlend()
nanoVG(true) {
drawBackground(x, y, width * scale, height * scale, scale)
}
GlStateManager.disableBlend()
GlStateManager.disableAlpha()
}

override fun isEnabled(): Boolean {
return true
}

override fun draw(matrices: UMatrixStack?, x: Float, y: Float, scale: Float, example: Boolean) {
}

override fun shouldShow(): Boolean {
return false
}

override fun getWidth(scale: Float, example: Boolean): Float {
return 0f
}

override fun getHeight(scale: Float, example: Boolean): Float {
return 0f
}
}
6 changes: 4 additions & 2 deletions src/main/kotlin/org/polyfrost/chatting/chat/ChatWindow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import cc.polyfrost.oneconfig.hud.BasicHud
import cc.polyfrost.oneconfig.internal.hud.HudCore
import cc.polyfrost.oneconfig.libs.universal.UGraphics.GL
import cc.polyfrost.oneconfig.libs.universal.UMatrixStack
import cc.polyfrost.oneconfig.platform.Platform
import cc.polyfrost.oneconfig.utils.dsl.*
import club.sk1er.patcher.config.PatcherConfig
import net.minecraft.client.gui.*
Expand Down Expand Up @@ -92,8 +93,9 @@ class ChatWindow : BasicHud(true, 2f, 1080 - 27f - 45f) {
GlStateManager.disableAlpha()
}

fun getAlphaBG(): Int {
return bgColor.alpha
fun canShow(): Boolean {
showInChat = true
return isEnabled && (shouldShow() || Platform.getGuiPlatform().isInChat)
}

fun getPaddingX(): Float {
Expand Down
Loading

0 comments on commit 526161e

Please sign in to comment.