Skip to content

Commit

Permalink
update: draw style
Browse files Browse the repository at this point in the history
  • Loading branch information
Colter23 committed Jun 25, 2022
1 parent 9c3baa1 commit cef3589
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 101 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ v3还有很多问题没解决(但还是摸了好长时间才摸出来 后面写

如果你再使用v3版中有什么问题可统一前往 [V3问题/建议反馈](https://github.com/Colter23/bilibili-dynamic-mirai-plugin/issues/66) 进行反馈

建了个QQ群,有问题可即时反馈 [734922374](https://jq.qq.com/?_wv=1027&k=NuSQdKTQ)

## 数据迁移
v2与v3的数据结构不一样
但不用担心 当你第一次运行v3版插件会自动进行数据迁移
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = "top.colter"
version = "3.0.0-M2"
version = "3.0.0-M3"

repositories {
mavenLocal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ object BiliBiliDynamic : KotlinPlugin(
JvmPluginDescription(
id = "top.colter.bilibili-dynamic-mirai-plugin",
name = "BiliBili Dynamic",
version = "3.0.0-M2",
version = "3.0.0-M3",
) {
author("Colter")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ suspend fun DynamicItem.drawDynamic(themeColor: Int, isForward: Boolean = false)
}

val footerTemplate = BiliConfig.templateConfig.footer.dynamicFooter
val footerParagraph = if (footerTemplate.isNotBlank()){
val footerParagraph = if (footerTemplate.isNotBlank() && !isForward){
val footer = footerTemplate
.replace("{name}", modules.moduleAuthor.name)
.replace("{uid}", modules.moduleAuthor.mid.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ suspend fun ModuleDynamic.Major.makeGeneral(isForward: Boolean = false): Image?
}

"MAJOR_TYPE_PGC" -> {
drawInfoText("暂时无法绘制类型为 [$type] 的动态类型")
pgc!!.drawSmall()
}

"MAJOR_TYPE_COMMON" -> {
Expand Down Expand Up @@ -192,7 +192,9 @@ suspend fun ModuleDynamic.Major.Archive.drawGeneral(): Image {
ParagraphBuilder(paragraphStyle, FontUtils.fonts).addText(desc.replace("\n", " ")).build()
.layout(paragraphWidth)

val videoCoverHeight = cardContentRect.width * 0.625f // 封面比例 16:10
val coverImg = getOrDownloadImage(cover, CacheType.IMAGES)

val videoCoverHeight = cardContentRect.width * coverImg.height / coverImg.width
val videoCardHeight = videoCoverHeight + titleParagraph.height + descParagraph.height + quality.cardPadding

val videoCardRect = RRect.makeComplexXYWH(
Expand All @@ -215,7 +217,6 @@ suspend fun ModuleDynamic.Major.Archive.drawGeneral(): Image {
drawRectShadowAntiAlias(videoCardRect.inflate(1f), theme.smallCardShadow)

// 封面
val coverImg = getOrDownloadImage(cover, CacheType.IMAGES)
val coverRRect = RRect.makeComplexXYWH(
videoCardRect.left,
videoCardRect.top,
Expand Down Expand Up @@ -310,6 +311,10 @@ suspend fun ModuleDynamic.Major.Archive.drawSmall(): Image {
return drawSmallCard(title, desc, cover, badge.text, "av$aid | $bvid", durationText)
}

suspend fun ModuleDynamic.Major.Pgc.drawSmall(): Image {
return drawSmallCard(title, "播放: ${stat.play} 弹幕: ${stat.danmaku}", cover, badge.text, "ep$epid", null)
}

suspend fun drawSmallCard(
title: String,
desc: String,
Expand Down Expand Up @@ -386,7 +391,8 @@ suspend fun drawSmallCard(
).inflate(-1f) as RRect
drawImageRRect(coverImg, coverRRect)

val y = videoCardRect.top + (videoCardRect.height - titleParagraph.height - descParagraph.height) / 2
val space = (videoCardRect.height - titleParagraph.height - descParagraph.height) / 3
val y = videoCardRect.top + space
titleParagraph.paint(
this,
quality.cardPadding * 1.5f + coverWidth,
Expand All @@ -396,7 +402,7 @@ suspend fun drawSmallCard(
descParagraph.paint(
this,
quality.cardPadding * 1.5f + coverWidth,
y + titleParagraph.height
y + titleParagraph.height + space
)

if (duration != null) {
Expand Down Expand Up @@ -680,16 +686,21 @@ suspend fun ModuleDynamic.Major.Music.drawGeneral(): Image {
).inflate(-1f) as RRect
drawImageRRect(coverImg, coverRRect)

val space = (musicCardHeight - titleParagraph.height - descParagraph.height) / 3
val y = musicCardRect.top + space

titleParagraph.paint(
this,
musicCardHeight + quality.cardMargin * 2,
(quality.badgeHeight + quality.cardMargin * 2).toFloat()
y
//(quality.badgeHeight + quality.cardMargin * 2).toFloat()
)

descParagraph.paint(
this,
musicCardHeight + quality.cardMargin * 2,
quality.badgeHeight + quality.cardMargin * 2 + titleParagraph.height
y + space + titleParagraph.height
//quality.badgeHeight + quality.cardMargin * 2 + titleParagraph.height
)

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,31 +438,31 @@ suspend fun ModuleAuthor.drawForward(time: String): Image {
suspend fun ModuleAuthor.drawGeneral(time: String, link: String, themeColor: Int): Image {
return Surface.makeRasterN32Premul(
quality.imageWidth - quality.cardMargin * 2,
(quality.faceSize + quality.cardPadding * 2f).toInt()
quality.pendantSize.toInt()
).apply surface@{
canvas.apply {
drawAvatar(face, pendant?.image, officialVerify?.type, quality.faceSize, quality.verifyIconSize)

val textLineName = TextLine.make(name, font.makeWithSize(quality.nameFontSize))
val textLineTime = TextLine.make(time, font.makeWithSize(quality.subTitleFontSize))

val x = quality.faceSize + quality.cardPadding * 3f
var y =
((quality.faceSize - (quality.nameFontSize + textLineTime.height)) / 2) + quality.nameFontSize + (quality.cardPadding * 1.2f)
val x = quality.faceSize + quality.cardPadding * 3.2f
val space = (quality.pendantSize - quality.nameFontSize - quality.subTitleFontSize) / 3
var y = quality.nameFontSize + space * 1.25f

drawTextLine(textLineName, x, y, Paint().apply { color = theme.nameColor })

y += textLineTime.height
y += quality.subTitleFontSize + space * 0.5f
drawTextLine(textLineTime, x, y, Paint().apply { color = theme.subTitleColor })

drawOrnament(decorate, link, themeColor)
drawOrnament(BiliConfig.imageConfig.cardOrnament, decorate, link, themeColor, null)
}
}.makeImageSnapshot()
}

suspend fun Canvas.drawOrnament(decorate: ModuleAuthor.Decorate?, link: String, qrCodeColor: Int) {
suspend fun Canvas.drawOrnament(cardOrnament: String, decorate: ModuleAuthor.Decorate?, link: String?, qrCodeColor: Int?, label: String?) {

when (BiliConfig.imageConfig.cardOrnament) {
when (cardOrnament) {
"FanCard" -> {
if (decorate != null) {
val fanImg = getOrDownloadImage(decorate.cardUrl, CacheType.USER)
Expand Down Expand Up @@ -505,7 +505,7 @@ suspend fun Canvas.drawOrnament(decorate: ModuleAuthor.Decorate?, link: String,
}

"QrCode" -> {
val qrCodeImg = qrCode(link, quality.ornamentHeight.toInt(), qrCodeColor)
val qrCodeImg = qrCode(link!!, quality.ornamentHeight.toInt(), qrCodeColor!!)
val y = ((quality.faceSize - quality.ornamentHeight) / 2) + quality.cardPadding
val tarFRect = Rect.makeXYWH(
cardContentRect.right - quality.ornamentHeight - 20f,
Expand All @@ -523,5 +523,21 @@ suspend fun Canvas.drawOrnament(decorate: ModuleAuthor.Decorate?, link: String,
true
)
}

"Label" -> {
val labelTextLine = TextLine.make(label, font.makeWithSize(quality.subTitleFontSize))
val y = ((quality.faceSize - quality.ornamentHeight) / 2) + quality.cardPadding
drawLabelCard(
labelTextLine,
cardContentRect.right - labelTextLine.width - quality.badgePadding * 4,
y,
Paint().apply {
color = theme.subLeftBadge.fontColor
},
Paint().apply {
color = theme.subLeftBadge.bgColor
}
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,18 @@ suspend fun LiveInfo.drawAvatar(): Image {

val textLineTitle = TextLine.make(title, font.makeWithSize(quality.nameFontSize))
val textLineTime =
TextLine.make("$uname ${liveTime.formatTime}", font.makeWithSize(quality.subTitleFontSize))
TextLine.make("$uname ${liveTime.formatTime}", font.makeWithSize(quality.subTitleFontSize))

var x = quality.faceSize + quality.cardPadding * 3f
var y =
((quality.faceSize - (quality.nameFontSize + textLineTime.height)) / 2) + quality.nameFontSize + (quality.cardPadding * 1.2f)
val x = quality.faceSize + quality.cardPadding * 3f
val space = (quality.pendantSize - quality.nameFontSize - quality.subTitleFontSize) / 3
var y = quality.nameFontSize + space * 1.25f

drawTextLine(textLineTitle, x, y, Paint().apply { color = theme.titleColor })

y += textLineTime.height
y += quality.subTitleFontSize + space * 0.5f
drawTextLine(textLineTime, x, y, Paint().apply { color = theme.subTitleColor })

//drawOrnament(decorate, link)
//drawOrnament(if (BiliConfig.imageConfig.cardOrnament=="QrCode") "QrCode" else "Label", null, link, "")
}
}.makeImageSnapshot()
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ object DynamicCheckTasker : BiliTasker() {
}
}

override suspend fun main() = withTimeout(180000) {
override suspend fun main() = withTimeout(180001) {
logger.debug("Check Dynamic...")
val dynamicList = client.getNewDynamic()
if (dynamicList != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ object DynamicMessageTasker : BiliTasker() {

private val dynamic by BiliData::dynamic

override suspend fun main() = withTimeout(180000) {
override suspend fun main() {
val dynamicDetail = dynamicChannel.receive()
val dynamicItem = dynamicDetail.item
logger.debug(dynamicItem.idStr)
messageChannel.send(dynamicItem.buildMessage(dynamicDetail.contact))
withTimeout(180002) {
val dynamicItem = dynamicDetail.item
logger.debug(dynamicItem.idStr)
messageChannel.send(dynamicItem.buildMessage(dynamicDetail.contact))
}
}

suspend fun DynamicItem.buildMessage(contact: String? = null): DynamicMessage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ object LiveCheckTasker : BiliTasker() {

private var lastLive: Long = Instant.now().epochSecond

override suspend fun main() = withTimeout(180000) {
override suspend fun main() = withTimeout(180003) {
logger.debug("Check Live...")
val liveList = client.getLive()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ object LiveMessageTasker : BiliTasker() {
private val liveChannel by BiliBiliDynamic::liveChannel
private val messageChannel by BiliBiliDynamic::messageChannel

override suspend fun main() = withTimeout(180000) {
override suspend fun main() {
val liveDetail = liveChannel.receive()
val liveInfo = liveDetail.item
logger.debug("直播: ${liveInfo.uname}@${liveInfo.uid}@${liveInfo.title}")
messageChannel.send(liveInfo.buildMessage(liveDetail.contact))
withTimeout(180004) {
val liveInfo = liveDetail.item
logger.debug("直播: ${liveInfo.uname}@${liveInfo.uid}@${liveInfo.title}")
messageChannel.send(liveInfo.buildMessage(liveDetail.contact))
}
}

suspend fun LiveInfo.buildMessage(contact: String? = null): LiveMessage {
Expand Down
Loading

0 comments on commit cef3589

Please sign in to comment.