diff --git a/build.gradle b/build.gradle
index 2aa443cc..5d298f42 100644
--- a/build.gradle
+++ b/build.gradle
@@ -11,7 +11,7 @@ apply plugin: "java"
group = 'xmmt.dituon'
-version = '3.6-M1'
+version = '3.6'
repositories {
maven { url 'https://maven.aliyun.com/repository/public' }
diff --git a/editor/text.js b/editor/text.js
index 333e17c6..24859748 100644
--- a/editor/text.js
+++ b/editor/text.js
@@ -13,7 +13,7 @@ function Text(text) {
this.text.on('moving', () => {
textMoving()
})
- this.text.on('scaling', e => {
+ this.text.on('scaling', e => {
if (e.transform.target.scaleX === e.transform.target.scaleY) {
let size = e.transform.target.scaleX * 200
that.text.set('fontSize', size)
@@ -22,14 +22,74 @@ function Text(text) {
}
textMoving()
})
+ this.text.on('changing', () => {
+ textMoving()
+ })
this.pos = [0, 0]
function textMoving() {
- that.pos = [Math.round(that.text.left), Math.round(that.text.top)]
+ let x = Math.round(that.text.left)
+ switch (that.align) {
+ case 'RIGHT':
+ x += Math.round(that.text.getScaledWidth())
+ break
+ case 'CENTER':
+ x += Math.round(that.text.getScaledWidth() / 2)
+ break
+ }
+
+ that.pos[0] = x
+ that.pos[1] = Math.round(that.text.top)
$('#avatar_pos').text('坐标: [' + that.pos + ']')
}
+ this.align = 'LEFT'
+ this.changeAlign = value => {
+ that.align = value
+ switch (value) {
+ case 'LEFT':
+ that.text.textAlign = 'left'
+ break
+ case 'RIGHT':
+ that.text.textAlign = 'right'
+ break
+ case 'CENTER':
+ that.text.textAlign = 'right'
+ break
+ }
+ textMoving()
+ }
+
+ this.wrap = 'NONE'
+ this.changeWrap = value => {
+ console.log(value)
+ that.wrap = value
+ switch (value) {
+ case 'NONE':
+ $(`#t${that.id} .check.setWidth`).slideUp()
+ that.setMaxWidth(0)
+ break
+ default:
+ console.log(0)
+ $(`#t${that.id} .check.setWidth`).slideDown()
+ that.setMaxWidth(Math.round(that.text.getScaledWidth()))
+ break
+ }
+ }
+
+ this.maxWidth = 0
+ this.setMaxWidth = width => {
+ that.maxWidth = width
+ if (width === 0) {
+ that.pos.length = 2
+ } else {
+ $(`#t${that.id} .check.setWidth .typein.width`).val(width)
+ that.pos[2] = width
+ }
+ textMoving()
+ }
+
this.isDelete = false
this.delete = () => {
canvas.remove(this.text)
@@ -39,35 +99,52 @@ function Text(text) {
}
this.build = () => {
+ let extra = (that.align === 'LEFT' ? '' : `,\n "align": "${that.align}"`) +
+ (that.wrap === 'NONE' ? '' : `,\n "wrap": "${that.wrap}"`)
return `{
"text": "${that.text.get('text')}",
"pos": [${that.pos}],
"color": "${that.text.get('fill')}",
- "size": ${Math.round(that.text.get('fontSize') / 16)}
+ "size": ${Math.round(that.text.get('fontSize') / 16)}${extra}
}`
}
this.id = textList.length
$('#elementBar').append(`
Text ${this.id}
` +
'
color
' +
- '
size
' +
+ '
size
' +
+ '
' +
+ '
' +
+ '
maxWidth
' +
'
delete
')
}
-$('#elementBar').on('change', '.text .color', function () {
+$('#elementBar').on('change', '.text .color', function () {
textList[this.parentNode.parentNode.id.slice(1)].text.set('fill', this.value)
canvas.renderAll()
})
- .on('change', '.text .typein', function () {
+ .on('change', '.text .check .typein.size', function () {
textList[this.parentNode.parentNode.id.slice(1)].text.set('fontSize', this.value * 16)
canvas.renderAll()
})
- .on('click', '.text .deleteText', function () {
+ .on('click', '.text .deleteText', function () {
textList[this.parentNode.id.slice(1)].delete()
})
+ .on('change', '.text select.textAlign', function () {
+ textList[this.parentNode.id.slice(1)].changeAlign(this.value)
+ })
+
+ .on('change', '.text select.textWrap', function () {
+ textList[this.parentNode.id.slice(1)].changeWrap(this.value)
+ })
+
+ .on('change', '.text .check .typein.width', function () {
+ textList[this.parentNode.parentNode.id.slice(1)].setMaxWidth(this.value)
+ })
+
let textList = [];
function addText() {
diff --git a/src/main/java/xmmt/dituon/plugin/Petpet.java b/src/main/java/xmmt/dituon/plugin/Petpet.java
index a505f2ee..918dd96a 100644
--- a/src/main/java/xmmt/dituon/plugin/Petpet.java
+++ b/src/main/java/xmmt/dituon/plugin/Petpet.java
@@ -97,6 +97,7 @@ private void onGroupMessage(GroupMessageEvent e) {
e.getGroup().sendMessage("Petpet KeyList: \n" + pluginPetService.getKeyAliasListString());
return;
}
+ boolean lock = false;
String fromName = "我";
String toName = "你";
@@ -119,12 +120,14 @@ private void onGroupMessage(GroupMessageEvent e) {
toUrl = to.getAvatarUrl();
groupName = e.getGroup().getName();
+ lock = true;
continue;
}
if (singleMessage instanceof Image) {
fromUrl = e.getSender().getAvatarUrl();
toUrl = Image.queryUrl((Image) singleMessage);
groupName = e.getGroup().getName();
+ lock = true;
}
}
@@ -138,9 +141,7 @@ private void onGroupMessage(GroupMessageEvent e) {
new Random().nextInt(pluginPetService.randomableList.size())));
}
- if (!strList.get(0).startsWith(pluginPetService.keyCommandHead)) {
- return;
- }
+ if (!strList.get(0).startsWith(pluginPetService.keyCommandHead)) return;
strList.set(0, strList.get(0).substring(pluginPetService.keyCommandHead.length()));
if (!pluginPetService.getDataMap().containsKey(strList.get(0))) { //没有指定key
@@ -151,7 +152,7 @@ private void onGroupMessage(GroupMessageEvent e) {
}
}
- if (pluginPetService.fuzzy && strList.size() > 1) {
+ if (pluginPetService.fuzzy && strList.size() > 1 && !lock) {
for (Member m : e.getGroup().getMembers()) {
if (m.getNameCard().contains(strList.get(1)) || m.getNick().contains(strList.get(1))) {
toName = getNameOrNick(m);
diff --git a/src/main/java/xmmt/dituon/plugin/PluginPetService.java b/src/main/java/xmmt/dituon/plugin/PluginPetService.java
index 3c0526b5..b0b70fd2 100644
--- a/src/main/java/xmmt/dituon/plugin/PluginPetService.java
+++ b/src/main/java/xmmt/dituon/plugin/PluginPetService.java
@@ -94,9 +94,7 @@ public void sendImage(Group group, Member from, Member to, boolean random) {
return;
}
int r = new Random().nextInt(99) + 1; //不能为0
- if (r >= probability) {
- return;
- }
+ if (r >= probability) return;
sendImage(group, from, to);
}
diff --git a/src/main/java/xmmt/dituon/share/BaseGifMaker.java b/src/main/java/xmmt/dituon/share/BaseGifMaker.java
index fb2b1d5a..c3e6f2f3 100644
--- a/src/main/java/xmmt/dituon/share/BaseGifMaker.java
+++ b/src/main/java/xmmt/dituon/share/BaseGifMaker.java
@@ -19,9 +19,7 @@ public InputStream makeAvatarGIF(String path, ArrayList avatarList,
if(!imageNumMap.containsKey(path)){
short imageNum = 0;
for (File file : Objects.requireNonNull(new File(path).listFiles())) {
- if (file.getName().endsWith(".png")) {
- imageNum++;
- }
+ if (file.getName().endsWith(".png")) imageNum++;
}
imageNumMap.put(path, imageNum);
}
diff --git a/src/main/java/xmmt/dituon/share/TextModel.java b/src/main/java/xmmt/dituon/share/TextModel.java
index 79a2b7ec..cdb365ed 100644
--- a/src/main/java/xmmt/dituon/share/TextModel.java
+++ b/src/main/java/xmmt/dituon/share/TextModel.java
@@ -16,6 +16,7 @@ public class TextModel {
protected Font font;
protected TextAlign align;
protected TextWrap wrap;
+ private int width;
public TextModel(TextData textData, TextExtraData extraInfo) {
text = extraInfo != null ? buildText(textData.getText(), extraInfo)
@@ -63,7 +64,7 @@ private Color setColor(JsonElement jsonElement) {
short[] rgba = {25, 25, 25, 255};
try { //rgb or rgba
JsonArray jsonArray = (JsonArray) jsonElement;
- if (jsonArray.getSize() == 3 && jsonArray.getSize() == 4) {
+ if (jsonArray.getSize() == 3 || jsonArray.getSize() == 4) {
rgba[0] = Short.parseShort(jsonArray.get(0).toString());
rgba[1] = Short.parseShort(jsonArray.get(1).toString());
rgba[2] = Short.parseShort(jsonArray.get(2).toString());
@@ -124,7 +125,8 @@ public Font getFont() {
}
public int getWidth() {
+ if (width != 0) return width;
Graphics2D g2d = new BufferedImage(1, 1, Image.SCALE_DEFAULT).createGraphics();
- return g2d.getFontMetrics(font).stringWidth(text);
+ return width = g2d.getFontMetrics(font).stringWidth(text);
}
}