Skip to content

Commit

Permalink
Side chat (giga chad)
Browse files Browse the repository at this point in the history
  • Loading branch information
SirObby committed Aug 30, 2022
1 parent 596f42f commit 4c49824
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ public static Screen build_screen() {
.setSaveConsumer(newValue -> IslandChamp.sidechat_x = newValue) // Recommended: Called when user save the config
.build()); // Builds the option entry for cloth config

general.addEntry(entryBuilder.startIntSlider(Text.translatable("option.sidechatw.int"), IslandChamp.sidechat_w, 1, 1920)
.setDefaultValue(90) // Recommended: Used when user click "Reset"
.setTooltip(Text.translatable("tooltip.sidechatw.int")) // Optional: Shown when the user hover over this option
.setSaveConsumer(newValue -> IslandChamp.sidechat_w = newValue) // Recommended: Called when user save the config
.build()); // Builds the option entry for cloth config

Screen screen = builder.build();

//MinecraftClient.getInstance().setScreen(screen);
Expand All @@ -69,7 +75,7 @@ public static void saveConfigs() throws IOException {

//String c = Files.readString(p);

JsonObject object = new Gson().fromJson(String.format("{ \"debugging_enabled\": %s, \"sidechat\": %s, \"sidechat_x\": %d }", IslandChamp.debugging_enabled, IslandChamp.sidechat_enabled, IslandChamp.sidechat_x), JsonObject.class);
JsonObject object = new Gson().fromJson(String.format("{ \"debugging_enabled\": %s, \"sidechat\": %s, \"sidechat_x\": %d, \"sidechat_w\": %d }", IslandChamp.debugging_enabled, IslandChamp.sidechat_enabled, IslandChamp.sidechat_x, IslandChamp.sidechat_w), JsonObject.class);

Files.writeString(p, object.toString());

Expand All @@ -78,7 +84,7 @@ public static void saveConfigs() throws IOException {
public static void defaultConfigs() throws IOException {
Path p = FabricLoader.getInstance().getConfigDir().resolve("islandchamp.json");

JsonObject object = new Gson().fromJson(String.format("{ \"debugging_enabled\": %s \"sidechat\": %s, \"sidechat_x\": %d }", false, true, 310 ), JsonObject.class);
JsonObject object = new Gson().fromJson(String.format("{ \"debugging_enabled\": %s \"sidechat\": %s, \"sidechat_x\": %d, \"sidechat_w\": %d }", false, true, 310, 90 ), JsonObject.class);

Files.writeString(p, object.toString());
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/net/sirobby/mods/islandchamp/IslandChamp.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class IslandChamp implements ModInitializer {
public static boolean sidechat_enabled = true; // Automatic enable.

public static int sidechat_x = 310; // test?
public static int sidechat_w = 90;

@Override
public void onInitialize() {
Expand All @@ -49,7 +50,9 @@ public void onInitialize() {
ClothConfig.saveConfigs();
} else {
debugging_enabled = jsonObject.get("debugging_enabled").getAsBoolean();
sidechat_enabled = jsonObject.get("sidechat").getAsBoolean();
sidechat_x = jsonObject.get("sidechat_x").getAsInt();
sidechat_w = jsonObject.get("sidechat_w").getAsInt();
}

} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,28 @@ public void onChatMessage(Text message, MessageSignatureData signature, int tick
if(IslandChamp.debugging_enabled) {
System.out.println(message.toString());

System.out.println(message.getSiblings().get(0).toString());
System.out.println(message.getSiblings().get(1).toString());
System.out.println(message.getSiblings().get(2).toString());
System.out.println(message.getSiblings().get(0).getString());
System.out.println(message.getSiblings().get(1).getString());
//System.out.println(message.getSiblings().get(2).getString());
}

System.out.println(IslandChamp.sidechat_enabled);
System.out.println(IslandChamp.debugging_enabled);

if(IslandChamp.sidechat_enabled) {
int i = MathHelper.floor((double) this.getWidth() / this.getChatScale());
if (indicator != null && indicator.icon() != null) {
i -= indicator.icon().width + 4 + 2;
}
List<OrderedText> list = ChatMessages.breakRenderedChatMessageLines(message, i, this.client.textRenderer);
if(/*Objects.equals(message.getStyle().getColor(), TextColor.fromRgb(0xFF7EFF)) && */Objects.equals(message.getSiblings().get(0).getString(), "[PM To] ") || Objects.equals(message.getSiblings().get(0).getString(), "[PM From] ")) {
if(/*Objects.equals(message.getStyle().getColor(), TextColor.fromRgb(0xFF7EFF)) && */message.getSiblings().get(0).getString().startsWith("[PM To] ") || message.getSiblings().get(0).getString().startsWith("[PM From] ")) {
boolean bl = this.isChatFocused();

ChatHudLine.Visible vis = new ChatHudLine.Visible(0, message.asOrderedText(), indicator, bl);
//ChatHudLine.Visible vis = new ChatHudLine.Visible(0, message.asOrderedText(), indicator, bl);

visibleMessagesIguess.add(vis);
//visibleMessagesIguess.add(vis);
System.out.println("Sending the message to the side.");
visibleMessagesIguess.add(0, new ChatHudLine.Visible(this.client.inGameHud.getTicks(), message.asOrderedText(), indicator, true));
ci.cancel();
}
}
Expand Down Expand Up @@ -104,12 +109,14 @@ private static double getMessageOpacityMultiplier(int age) {

@Inject(method={"render"}, at = @At("HEAD"), cancellable = true)
public void render(MatrixStack matrices, int currentTick, CallbackInfo ci) {
renderChat(matrices, currentTick, IslandChamp.sidechat_x, 90, 90);
renderChat(matrices, currentTick, IslandChamp.sidechat_x, IslandChamp.sidechat_w, 90);
}

@Shadow
public abstract void scroll(int scroll);

@Shadow @Final private List<ChatHudLine> messages;

@Inject(method={"clear"}, at = @At("HEAD"))
public void clear(boolean clearHistory, CallbackInfo ci) {
this.client.getMessageHandler().processAll();
Expand Down Expand Up @@ -147,6 +154,7 @@ private void renderChat(MatrixStack matrices, int currentTick,
float f = (float)this.getChatScale();

int k = MathHelper.ceil((float)this.getWidth() / f);
k = MathHelper.ceil(displayX / f);
matrices.push();
matrices.translate(displayX, 8.0, 0.0);
matrices.scale(f, f, 1.0f);
Expand Down

0 comments on commit 4c49824

Please sign in to comment.