Commit aa82314c by Jonathan Thomas

- Added arrows to chat bubble (to indicate when next/prev pages are avaialble) - owlmaddie art

- Added new keyboard icon - owlmaddie art, as a chat bubble at the end of a chat message
- Removed ChatStatus.END, and replaced the logic with isEndOfMessage() function
parent f80faf0a
Pipeline #11988 passed with stage
in 29 seconds
......@@ -38,7 +38,6 @@ import java.util.stream.Collectors;
public class BubbleRenderer {
public static final Logger LOGGER = LoggerFactory.getLogger("mobgpt");
protected static TextureLoader textures = new TextureLoader();
public static int DISPLAY_NUM_LINES = 3;
public static int DISPLAY_PADDING = 2;
public static int animationFrame = 0;
public static long lastTick = 0;
......@@ -185,14 +184,6 @@ public class BubbleRenderer {
}
}
private static void drawEndOfMessageText(Matrix4f matrix, VertexConsumerProvider immediate,
int fullBright, float yOffset) {
TextRenderer fontRenderer = MinecraftClient.getInstance().textRenderer;
String lineText = "<end of message>";
fontRenderer.draw(lineText, -fontRenderer.getWidth(lineText) / 2f, yOffset + 10F, 0xffffff,
false, matrix, immediate, TextLayerType.NORMAL, 0, fullBright);
}
private static void drawEntityName(MobEntity entity, Matrix4f matrix, VertexConsumerProvider immediate,
int fullBright, float yOffset) {
if (entity.getCustomName() != null) {
......@@ -251,7 +242,7 @@ public class BubbleRenderer {
// Set the range of lines to display
int starting_line = chatData.currentLineNumber;
int ending_line = Math.min(chatData.currentLineNumber + DISPLAY_NUM_LINES, lines.size());
int ending_line = Math.min(chatData.currentLineNumber + ChatDataManager.DISPLAY_NUM_LINES, lines.size());
// Push a new matrix onto the stack.
matrices.push();
......@@ -340,7 +331,7 @@ public class BubbleRenderer {
// Calculate size of text scaled to world
float scaledTextHeight = linesDisplayed * (fontRenderer.fontHeight + lineSpacing);
float minTextHeight = (DISPLAY_NUM_LINES * (fontRenderer.fontHeight + lineSpacing)) + (DISPLAY_PADDING * 2);
float minTextHeight = (ChatDataManager.DISPLAY_NUM_LINES * (fontRenderer.fontHeight + lineSpacing)) + (DISPLAY_PADDING * 2);
scaledTextHeight = Math.max(scaledTextHeight, minTextHeight);
// Update Bubble Data for Click Handling using UUID (account for scaling)
......@@ -384,13 +375,18 @@ public class BubbleRenderer {
// Draw Friendship status
drawFriendshipStatus(matrices, 51, 18, 31, 21, chatData.friendship);
// Draw 'arrows' & 'keyboard' buttons
if (chatData.currentLineNumber > 0) {
drawIcon("arrow-left", matrices, -63, scaledTextHeight + 29, 16, 16);
}
if (!chatData.isEndOfMessage()) {
drawIcon("arrow-right", matrices, 47, scaledTextHeight + 29, 16, 16);
} else {
drawIcon("keyboard", matrices, 47, scaledTextHeight + 28, 16, 16);
}
// Render each line of the text
drawMessageText(matrix, lines, starting_line, ending_line, immediate, lineSpacing, fullBright, 40.0F + DISPLAY_PADDING);
if (starting_line > 0 && starting_line == ending_line) {
// Add <End Of Message> text
drawEndOfMessageText(matrix, immediate, fullBright, 40.0F + DISPLAY_PADDING);
}
}
// Pop the matrix to return to the original state.
......
......@@ -148,8 +148,8 @@ public class ClickHandler {
Vec3d[] corners = getBillboardCorners(bubbleData.position, camera.getPos(), bubbleData.height, bubbleData.width, bubbleData.yaw, bubbleData.pitch);
// DEBUG CODE
drawCorners(player.getWorld(), corners);
drawRay(startRay, lookVec, player.getWorld());
//drawCorners(player.getWorld(), corners);
//drawRay(startRay, lookVec, player.getWorld());
// Cast ray and determine intersection with chat bubble
Optional<Vec3d> hitResult = rayIntersectsPolygon(startRay, lookVec, corners);
......@@ -181,14 +181,21 @@ public class ClickHandler {
if (chatData.status == ChatDataManager.ChatStatus.NONE) {
// Start conversation
ModPackets.sendGenerateGreeting(closestEntity);
} else if (chatData.status == ChatDataManager.ChatStatus.DISPLAY) {
// Update lines read
ModPackets.sendUpdateLineNumber(closestEntity, chatData.currentLineNumber + BubbleRenderer.DISPLAY_NUM_LINES);
} else if (chatData.status == ChatDataManager.ChatStatus.END) {
// End of chat (open player chat screen)
ModPackets.sendStartChat(closestEntity);
client.setScreen(new ChatScreen(closestEntity));
if (hitRegion.equals("RIGHT") && !chatData.isEndOfMessage()) {
// Update lines read > next lines
ModPackets.sendUpdateLineNumber(closestEntity, chatData.currentLineNumber + ChatDataManager.DISPLAY_NUM_LINES);
} else if (hitRegion.equals("LEFT") && chatData.currentLineNumber > 0) {
// Update lines read < previous lines
ModPackets.sendUpdateLineNumber(closestEntity, chatData.currentLineNumber - ChatDataManager.DISPLAY_NUM_LINES);
} else if (hitRegion.equals("RIGHT") && chatData.isEndOfMessage()) {
// End of chat (open player chat screen)
ModPackets.sendStartChat(closestEntity);
client.setScreen(new ChatScreen(closestEntity));
}
}
}
}
}
......
......@@ -43,6 +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_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");
......@@ -70,8 +71,7 @@ public class ModInit implements ModInitializer {
EntityBehaviorManager.addGoal(entity, talkGoal, GoalPriority.TALK_PLAYER);
ChatDataManager.EntityChatData chatData = ChatDataManager.getServerInstance().getOrCreateChatData(entity.getUuidAsString());
if (chatData.status == ChatDataManager.ChatStatus.NONE ||
chatData.status == ChatDataManager.ChatStatus.END) {
if (chatData.status == ChatDataManager.ChatStatus.NONE) {
// Only generate a new greeting if not already doing so
String player_biome = player.getWorld().getBiome(player.getBlockPos()).getKey().get().getValue().getPath();
......@@ -107,11 +107,8 @@ public class ModInit implements ModInitializer {
EntityBehaviorManager.addGoal(entity, talkGoal, GoalPriority.TALK_PLAYER);
ChatDataManager.EntityChatData chatData = ChatDataManager.getServerInstance().getOrCreateChatData(entity.getUuidAsString());
if (chatData.status == ChatDataManager.ChatStatus.DISPLAY) {
// Only set line number if status allows
LOGGER.info("Increment read lines to " + lineNumber + " for: " + entity.getType().toString());
chatData.setLineNumber(lineNumber);
}
LOGGER.info("Update read lines to " + lineNumber + " for: " + entity.getType().toString());
chatData.setLineNumber(lineNumber);
}
});
});
......@@ -145,11 +142,9 @@ public class ModInit implements ModInitializer {
EntityBehaviorManager.addGoal(entity, talkGoal, GoalPriority.TALK_PLAYER);
ChatDataManager.EntityChatData chatData = ChatDataManager.getServerInstance().getOrCreateChatData(entity.getUuidAsString());
if (chatData.status == ChatDataManager.ChatStatus.END) {
// Add new message
LOGGER.info("Add new message (" + message + ") to Entity: " + entity.getType().toString());
chatData.generateMessage(player, "system-chat", message);
}
// Add new message
LOGGER.info("Add new message (" + message + ") to Entity: " + entity.getType().toString());
chatData.generateMessage(player, "system-chat", message);
}
});
});
......
......@@ -39,7 +39,8 @@ public class ChatDataManager {
private static final ChatDataManager SERVER_INSTANCE = new ChatDataManager(true);
private static final ChatDataManager CLIENT_INSTANCE = new ChatDataManager(false);
public static final Logger LOGGER = LoggerFactory.getLogger("mobgpt");
public static int MAX_CHAR_PER_LINE = 22;
public static int MAX_CHAR_PER_LINE = 20;
public static int DISPLAY_NUM_LINES = 3;
public QuestJson quest = null;
private static final Gson GSON = new Gson();
......@@ -47,7 +48,7 @@ public class ChatDataManager {
NONE, // No chat status yet
PENDING, // Chat is pending (e.g., awaiting response or processing)
DISPLAY, // Chat is currently being displayed
END // Chat has ended or been dismissed
HIDDEN, // Chat is currently hidden
}
public enum ChatSender {
......@@ -104,9 +105,7 @@ public class ChatDataManager {
public EntityChatDataLight toLightVersion() {
EntityChatDataLight light = new EntityChatDataLight();
light.entityId = this.entityId;
if (light.status != ChatStatus.END) {
light.currentMessage = this.currentMessage;
}
light.currentMessage = this.currentMessage;
light.currentLineNumber = this.currentLineNumber;
light.status = this.status;
light.sender = this.sender;
......@@ -320,13 +319,16 @@ public class ChatDataManager {
return LineWrapper.wrapLines(this.currentMessage, MAX_CHAR_PER_LINE);
}
// Update starting line number of displayed text
public boolean isEndOfMessage() {
int totalLines = this.getWrappedLines().size();
// Check if the current line number plus DISPLAY_NUM_LINES covers or exceeds the total number of lines
return currentLineNumber + DISPLAY_NUM_LINES >= totalLines;
}
public void setLineNumber(Integer lineNumber) {
// Update displayed starting line # (between 0 and # of lines)
currentLineNumber = Math.min(Math.max(lineNumber, 0), this.getWrappedLines().size());
if (currentLineNumber >= this.getWrappedLines().size()) {
status = ChatStatus.END;
}
int totalLines = this.getWrappedLines().size();
// Ensure the lineNumber is within the valid range
currentLineNumber = Math.min(Math.max(lineNumber, 0), totalLines);
// Broadcast to all players
ModInit.BroadcastPacketMessage(this);
......
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