Skip to content

Commit

Permalink
3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Dituon committed Jul 12, 2022
1 parent 3257668 commit 53c6abf
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 20 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down
91 changes: 84 additions & 7 deletions editor/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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(`<div class="element text" id="t${this.id}"><div class="typeText">Text ${this.id}</div>` +
'<div class="check" title="">color<input type="color" class="color"></div>' +
'<div class="check">size<input type="number" class="typein" value="8"></div>' +
'<div class="check">size<input type="number" class="typein size" value="8"></div>' +
'<select class="textAlign"><option value="LEFT">左对齐</option><option value="RIGHT">右对齐</option><option value="CENTER">居中</option></select>' +
'<select class="textWrap"><option value="NONE">不换行</option><option value="BREAK">自动换行</option><option value="ZOOM">自动缩放</option></select>' +
'<div class="check setWidth" style="display: none">maxWidth<input type="number" class="typein width" value="0"></div>' +
'<div class="check deleteText">delete</div></div>')
}

$('#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() {
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/xmmt/dituon/plugin/Petpet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "你";
Expand All @@ -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;
}
}

Expand All @@ -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
Expand All @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/xmmt/dituon/plugin/PluginPetService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/xmmt/dituon/share/BaseGifMaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ public InputStream makeAvatarGIF(String path, ArrayList<AvatarModel> 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);
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/xmmt/dituon/share/TextModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 53c6abf

Please sign in to comment.