Commit fd5da028 by Jonathan Thomas

- Added new top bar minimize UI click

- HIDDEN chat bubbles will become visible again when clicked again
- Added new setStatus packet to update chat status between DISPLAY and HIDDEN
parent aa82314c
Pipeline #11989 passed with stage
in 20 seconds
package com.owlmaddie.network;
import com.owlmaddie.ModInit;
import com.owlmaddie.chat.ChatDataManager;
import io.netty.buffer.Unpooled;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.minecraft.entity.Entity;
......@@ -37,6 +38,15 @@ public class ModPackets {
ClientPlayNetworking.send(ModInit.PACKET_C2S_START_CHAT, buf);
}
public static void setChatStatus(Entity entity, ChatDataManager.ChatStatus new_status) {
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
buf.writeString(entity.getUuidAsString());
buf.writeString(new_status.toString());
// Send C2S packet
ClientPlayNetworking.send(ModInit.PACKET_C2S_SET_STATUS, buf);
}
public static void sendChat(Entity entity, String message) {
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
buf.writeString(entity.getUuidAsString());
......
......@@ -365,7 +365,7 @@ public class BubbleRenderer {
animationFrame = 0;
}
} else if (chatData.sender == ChatDataManager.ChatSender.ASSISTANT) {
} else if (chatData.sender == ChatDataManager.ChatSender.ASSISTANT && chatData.status != ChatDataManager.ChatStatus.HIDDEN) {
// Draw text background (no smaller than 50F tall)
drawTextBubbleBackground(matrices, -64, 0, 128, scaledTextHeight, chatData.friendship);
......@@ -387,6 +387,10 @@ public class BubbleRenderer {
// Render each line of the text
drawMessageText(matrix, lines, starting_line, ending_line, immediate, lineSpacing, fullBright, 40.0F + DISPLAY_PADDING);
} else if (chatData.sender == ChatDataManager.ChatSender.ASSISTANT && chatData.status == ChatDataManager.ChatStatus.HIDDEN) {
// Draw 'resume chat' button
drawIcon("button-chat", matrices, -16, textHeaderHeight, 32, 17);
}
// Pop the matrix to return to the original state.
......
......@@ -193,7 +193,13 @@ public class ClickHandler {
// End of chat (open player chat screen)
ModPackets.sendStartChat(closestEntity);
client.setScreen(new ChatScreen(closestEntity));
} else if (hitRegion.equals("TOP")) {
// Hide chat
ModPackets.setChatStatus(closestEntity, ChatDataManager.ChatStatus.HIDDEN);
}
} else if (chatData.status == ChatDataManager.ChatStatus.HIDDEN) {
// Show chat
ModPackets.setChatStatus(closestEntity, ChatDataManager.ChatStatus.DISPLAY);
}
}
......
......@@ -43,7 +43,7 @@ public class ModInit implements ModInitializer {
private static ChatDataSaverScheduler scheduler = null;
public static final Identifier PACKET_C2S_GREETING = new Identifier("mobgpt", "packet_c2s_greeting");
public static final Identifier PACKET_C2S_READ_NEXT = new Identifier("mobgpt", "packet_c2s_read_next");
public static final Identifier PACKET_C2S_READ_PREV = new Identifier("mobgpt", "packet_c2s_read_prev");
public static final Identifier PACKET_C2S_SET_STATUS = new Identifier("mobgpt", "packet_c2s_set_status");
public static final Identifier PACKET_C2S_START_CHAT = new Identifier("mobgpt", "packet_c2s_start_chat");
public static final Identifier PACKET_C2S_SEND_CHAT = new Identifier("mobgpt", "packet_c2s_send_chat");
public static final Identifier PACKET_S2C_MESSAGE = new Identifier("mobgpt", "packet_s2c_message");
......@@ -113,6 +113,26 @@ public class ModInit implements ModInitializer {
});
});
// Handle packet for setting status of chat bubbles
ServerPlayNetworking.registerGlobalReceiver(PACKET_C2S_SET_STATUS, (server, player, handler, buf, responseSender) -> {
UUID entityId = UUID.fromString(buf.readString());
String status_name = buf.readString(32767);
// Ensure that the task is synced with the server thread
server.execute(() -> {
MobEntity entity = ServerEntityFinder.getEntityByUUID(player.getServerWorld(), entityId);
if (entity != null) {
// Set talk to player goal (prevent entity from walking off)
TalkPlayerGoal talkGoal = new TalkPlayerGoal(player, entity, 3.5F);
EntityBehaviorManager.addGoal(entity, talkGoal, GoalPriority.TALK_PLAYER);
ChatDataManager.EntityChatData chatData = ChatDataManager.getServerInstance().getOrCreateChatData(entity.getUuidAsString());
LOGGER.info("Hiding chat bubble for: " + entity.getType().toString());
chatData.setStatus(ChatDataManager.ChatStatus.valueOf(status_name));
}
});
});
// Handle packet for Start Chat
ServerPlayNetworking.registerGlobalReceiver(PACKET_C2S_START_CHAT, (server, player, handler, buf, responseSender) -> {
UUID entityId = UUID.fromString(buf.readString());
......
......@@ -333,6 +333,13 @@ public class ChatDataManager {
// Broadcast to all players
ModInit.BroadcastPacketMessage(this);
}
public void setStatus(ChatStatus new_status) {
status = new_status;
// Broadcast to all players
ModInit.BroadcastPacketMessage(this);
}
}
public void clearData() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment