Skip to content

Commit

Permalink
update talk message
Browse files Browse the repository at this point in the history
  • Loading branch information
nicol authored and nicol committed Sep 24, 2023
1 parent 2b3487d commit 87cf45b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 15 deletions.
19 changes: 17 additions & 2 deletions src/main/java/org/magic/api/beans/messages/TalkMessage.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package org.magic.api.beans.messages;

import java.awt.Color;
import java.io.IOException;
import java.util.regex.Pattern;

import org.magic.api.beans.MagicCard;
import org.magic.api.beans.abstracts.AbstractMessage;
import org.magic.api.interfaces.MTGCardsProvider;
import org.magic.services.tools.MTG;

public class TalkMessage extends AbstractMessage{

private static final long serialVersionUID = 1L;
private static final String REGEX = "\\{(.*?)\\}";

private MagicCard mc;

public String toChatString() {
return getAuthor().getName() + " : " + getMessage();
Expand All @@ -23,11 +27,22 @@ public TalkMessage(String message, Color color) {
var m = Pattern.compile(REGEX).matcher(message);
if(m.find())
{
logger.info("founnd card");
var cardName = m.group(1);
try {
var ret = MTG.getEnabledPlugin(MTGCardsProvider.class).searchCardByName(cardName, null, true);
if(!ret.isEmpty())
mc=ret.get(0);

} catch (IOException e) {
logger.error(e);
}
}

}

public MagicCard getMagicCard() {
return mc;
}



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.magic.api.beans.abstracts.AbstractMessage;
import org.magic.api.beans.abstracts.AbstractMessage.MSG_TYPE;
import org.magic.api.beans.messages.SearchMessage;
import org.magic.api.beans.messages.TalkMessage;
import org.magic.api.interfaces.MTGProduct;
import org.magic.services.MTGControler;
import org.magic.services.network.URLTools;
import org.magic.services.tools.ImageTools;
Expand All @@ -32,13 +34,13 @@ public class JsonMessagePanel extends JPanel {
private static final long serialVersionUID = 1L;
private JLabel lblTime;
private JTextArea textArea;

int iconSize=25;


public JsonMessagePanel(AbstractMessage value) {
setBorder(new LineBorder(value.getColor(),2,true));

int iconSize=25;


GridBagLayout gridBagLayout = new GridBagLayout();
gridBagLayout.columnWidths = new int[]{10, 0, 0, 0};
Expand All @@ -59,21 +61,22 @@ public JsonMessagePanel(AbstractMessage value) {
if(value.getTypeMessage()==MSG_TYPE.SEARCH)
{
var item = ((SearchMessage)value).getItem();
BufferedImage bi;
try {
bi = URLTools.extractAsImage(item.getUrl());
bi=ImageTools.scaleResize(bi, iconSize*2);
var lab = new JLabel(new ImageIcon(bi));

separator.add(lab);

separator.add(read(item));
} catch (IOException e) {
//do nothing
}




}

if(value.getTypeMessage()==MSG_TYPE.TALK)
{
var item = ((TalkMessage)value).getMagicCard();
if(item!=null)
try {
separator.add(read(item));
} catch (IOException e) {
//do nothing
}
}


Expand Down Expand Up @@ -120,5 +123,14 @@ public JsonMessagePanel(AbstractMessage value) {
gbclblTime.gridy = 2;
add(lblTime, gbclblTime);
}



private JLabel read(MTGProduct item) throws IOException {
var bi = URLTools.extractAsImage(item.getUrl());
bi=ImageTools.scaleResize(bi, iconSize*2);
return new JLabel(new ImageIcon(bi));

}

}

0 comments on commit 87cf45b

Please sign in to comment.