mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 20:28:00 +00:00
Support triangles for chat
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -17712,6 +17712,7 @@ forge-gui/src/main/java/forge/model/FModel.java svneol=native#text/plain
|
|||||||
forge-gui/src/main/java/forge/model/MetaSet.java -text
|
forge-gui/src/main/java/forge/model/MetaSet.java -text
|
||||||
forge-gui/src/main/java/forge/model/UnOpenedMeta.java -text
|
forge-gui/src/main/java/forge/model/UnOpenedMeta.java -text
|
||||||
forge-gui/src/main/java/forge/model/package-info.java svneol=native#text/plain
|
forge-gui/src/main/java/forge/model/package-info.java svneol=native#text/plain
|
||||||
|
forge-gui/src/main/java/forge/net/ChatMessage.java -text
|
||||||
forge-gui/src/main/java/forge/net/GameProtocolHandler.java -text
|
forge-gui/src/main/java/forge/net/GameProtocolHandler.java -text
|
||||||
forge-gui/src/main/java/forge/net/GameProtocolSender.java -text
|
forge-gui/src/main/java/forge/net/GameProtocolSender.java -text
|
||||||
forge-gui/src/main/java/forge/net/IOnlineChatInterface.java -text
|
forge-gui/src/main/java/forge/net/IOnlineChatInterface.java -text
|
||||||
|
|||||||
@@ -115,10 +115,10 @@ public class OnlineChatScreen extends FScreen implements IOnlineChatInterface {
|
|||||||
private static final FSkinColor MESSAGE_COLOR = FSkinColor.get(Colors.CLR_TEXT);
|
private static final FSkinColor MESSAGE_COLOR = FSkinColor.get(Colors.CLR_TEXT);
|
||||||
private static final FSkinColor SOURCE_COLOR = MESSAGE_COLOR.alphaColor(0.75f);
|
private static final FSkinColor SOURCE_COLOR = MESSAGE_COLOR.alphaColor(0.75f);
|
||||||
private static final FSkinColor TIMESTAMP_COLOR = MESSAGE_COLOR.alphaColor(0.5f);
|
private static final FSkinColor TIMESTAMP_COLOR = MESSAGE_COLOR.alphaColor(0.5f);
|
||||||
private static final FSkinColor BORDER_COLOR = FSkinColor.get(Colors.CLR_BORDERS);
|
private static final FSkinColor BORDER_COLOR = FSkinColor.get(Colors.CLR_BORDERS).alphaColor(0.5f);
|
||||||
private static final float BORDER_THICKNESS = Utils.scale(1);
|
private static final float BORDER_THICKNESS = Utils.scale(1.5f);
|
||||||
private static final float TEXT_INSET = Utils.scale(5);
|
private static final float TEXT_INSET = Utils.scale(5);
|
||||||
private static final float TRIANGLE_WIDTH = Utils.scale(5);
|
private static final float TRIANGLE_WIDTH = Utils.scale(8);
|
||||||
|
|
||||||
private final ChatMessage message;
|
private final ChatMessage message;
|
||||||
private final boolean isLocal;
|
private final boolean isLocal;
|
||||||
@@ -137,9 +137,9 @@ public class OnlineChatScreen extends FScreen implements IOnlineChatInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public float getPreferredHeight(float width) {
|
public float getPreferredHeight(float width) {
|
||||||
float height = FONT.getCapHeight() + 4 * TEXT_INSET + TRIANGLE_WIDTH;
|
float height = FONT.getCapHeight() + 4 * TEXT_INSET + 2 * BORDER_THICKNESS;
|
||||||
if (header != null) {
|
if (header != null) {
|
||||||
height += FONT.getLineHeight() + TEXT_INSET;
|
height += FONT.getLineHeight();
|
||||||
}
|
}
|
||||||
height += textRenderer.getWrappedBounds(message.getMessage(), FONT, width - 2 * TEXT_INSET).height;
|
height += textRenderer.getWrappedBounds(message.getMessage(), FONT, width - 2 * TEXT_INSET).height;
|
||||||
return height;
|
return height;
|
||||||
@@ -153,10 +153,32 @@ public class OnlineChatScreen extends FScreen implements IOnlineChatInterface {
|
|||||||
float h = getHeight() - TEXT_INSET;
|
float h = getHeight() - TEXT_INSET;
|
||||||
FSkinColor color = isLocal ? LOCAL_COLOR : REMOTE_COLOR;
|
FSkinColor color = isLocal ? LOCAL_COLOR : REMOTE_COLOR;
|
||||||
HAlignment horzAlignment = isLocal ? HAlignment.RIGHT : HAlignment.LEFT;
|
HAlignment horzAlignment = isLocal ? HAlignment.RIGHT : HAlignment.LEFT;
|
||||||
|
float timestampHeight = FONT.getCapHeight();
|
||||||
|
|
||||||
|
//draw bubble fill
|
||||||
g.fillRect(color, x, y, w, h);
|
g.fillRect(color, x, y, w, h);
|
||||||
g.drawRect(BORDER_THICKNESS, BORDER_COLOR, x, y, w, h);
|
g.drawRect(BORDER_THICKNESS, BORDER_COLOR, x, y, w, h);
|
||||||
|
|
||||||
|
//draw triangle to make this look like chat bubble
|
||||||
|
float x1, x2;
|
||||||
|
if (isLocal) {
|
||||||
|
x1 = w - 1;
|
||||||
|
x2 = w + TRIANGLE_WIDTH;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
x1 = TRIANGLE_WIDTH + 1;
|
||||||
|
x2 = 0;
|
||||||
|
}
|
||||||
|
float x3 = x1;
|
||||||
|
float y1 = y + timestampHeight + TEXT_INSET;
|
||||||
|
float y3 = y1 + TRIANGLE_WIDTH * 1.25f;
|
||||||
|
float y2 = (y1 + y3) / 2;
|
||||||
|
|
||||||
|
g.fillTriangle(color, x1, y1, x2, y2, x3, y3);
|
||||||
|
g.drawLine(BORDER_THICKNESS, BORDER_COLOR, x1, y1, x2, y2);
|
||||||
|
g.drawLine(BORDER_THICKNESS, BORDER_COLOR, x2, y2, x3, y3);
|
||||||
|
|
||||||
|
//draw text
|
||||||
x += TEXT_INSET;
|
x += TEXT_INSET;
|
||||||
y += TEXT_INSET;
|
y += TEXT_INSET;
|
||||||
w -= 2 * TEXT_INSET;
|
w -= 2 * TEXT_INSET;
|
||||||
@@ -164,10 +186,9 @@ public class OnlineChatScreen extends FScreen implements IOnlineChatInterface {
|
|||||||
if (!isLocal && message.getSource() != null) {
|
if (!isLocal && message.getSource() != null) {
|
||||||
float sourceHeight = FONT.getLineHeight();
|
float sourceHeight = FONT.getLineHeight();
|
||||||
g.drawText(message.getSource() + ":", FONT, SOURCE_COLOR, x, y, w, sourceHeight, false, horzAlignment, true);
|
g.drawText(message.getSource() + ":", FONT, SOURCE_COLOR, x, y, w, sourceHeight, false, horzAlignment, true);
|
||||||
y += sourceHeight + TEXT_INSET;
|
y += sourceHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
float timestampHeight = FONT.getCapHeight();
|
|
||||||
g.drawText(message.getTimestamp(), FONT, TIMESTAMP_COLOR, x, h - timestampHeight, w, timestampHeight, false, horzAlignment, true);
|
g.drawText(message.getTimestamp(), FONT, TIMESTAMP_COLOR, x, h - timestampHeight, w, timestampHeight, false, horzAlignment, true);
|
||||||
|
|
||||||
h -= y + timestampHeight + TEXT_INSET;
|
h -= y + timestampHeight + TEXT_INSET;
|
||||||
|
|||||||
44
forge-gui/src/main/java/forge/net/ChatMessage.java
Normal file
44
forge-gui/src/main/java/forge/net/ChatMessage.java
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package forge.net;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import forge.model.FModel;
|
||||||
|
import forge.properties.ForgePreferences;
|
||||||
|
import forge.properties.ForgePreferences.FPref;
|
||||||
|
|
||||||
|
public class ChatMessage {
|
||||||
|
private static final ForgePreferences prefs = FModel.getPreferences();
|
||||||
|
private static final SimpleDateFormat inFormat = new SimpleDateFormat("HH:mm:ss");
|
||||||
|
|
||||||
|
private final String source, message, timestamp;
|
||||||
|
|
||||||
|
public ChatMessage(String source0, String message0) {
|
||||||
|
source = source0;
|
||||||
|
message = message0;
|
||||||
|
timestamp = inFormat.format(new Date());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLocal() {
|
||||||
|
return source == null || source.equals(prefs.getPref(FPref.PLAYER_NAME));
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSource() {
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTimestamp() {
|
||||||
|
return timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFormattedMessage() {
|
||||||
|
if (source == null) {
|
||||||
|
return String.format("%n[%s] %s", timestamp, message);
|
||||||
|
}
|
||||||
|
return String.format("%n[%s] %s: %s", timestamp, source, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user