帮助随机背景

This commit is contained in:
yeyang
2022-10-09 13:50:57 +08:00
parent d6ba11d256
commit 1d446df40e
6 changed files with 27 additions and 100 deletions

View File

@@ -5,7 +5,7 @@ import { segment } from "oicq";
import puppeteer from '../../../lib/puppeteer/puppeteer.js'
import cfg from '../../../lib/config/config.js'
import { Cfg, Common, Data, Version, Plugin_Name, Plugin_Path } from '../components/index.js'
import Theme from './help/theme.js'
// import Theme from './help/theme.js'
export class yenai_help extends plugin {
constructor() {
@@ -65,12 +65,26 @@ async function help(e) {
helpGroup.push(group)
})
let themeData = await Theme.getThemeData(diyCfg.helpCfg || {}, sysCfg.helpCfg || {})
let bg = await rodom()
let colCount = 3;
return await Common.render('help/index', {
helpCfg: helpConfig,
helpGroup,
...themeData,
element: 'default'
}, { e, scale: 2.0 })
bg,
colCount,
// element: 'default'
}, {
e,
scale: 2.0
})
}
const rodom = async function () {
var image = fs.readdirSync(`./plugins/yenai-plugin/resources/help/imgs/`);
var list_img = [];
for (let val of image) {
list_img.push(val)
}
var imgs = list_img.length == 1 ? list_img[0] : list_img[lodash.random(0, list_img.length - 1)];
return imgs;
}

View File

@@ -1,67 +0,0 @@
import lodash from 'lodash'
import fs from 'fs'
import { Data , Plugin_Name} from '../../components/index.js'
let Theme = {
async getThemeCfg (theme, exclude) {
let dirPath = `./plugins/${Plugin_Name}/resources/help/theme/`
let ret = []
let names = []
let dirs = fs.readdirSync(dirPath)
lodash.forEach(dirs, (dir) => {
if (fs.existsSync(`${dirPath}${dir}/main.png`)) {
names.push(dir)
}
})
if (lodash.isArray(theme)) {
ret = lodash.intersection(theme, names)
} else if (theme === 'all') {
ret = names
}
if (exclude && lodash.isArray(exclude)) {
ret = lodash.difference(ret, exclude)
}
if (ret.length === 0) {
ret = ['default']
}
let name = lodash.sample(ret)
let resPath = '{{_res_path}}/help/theme/'
return {
main: `${resPath}${name}/main.png`,
bg: fs.existsSync(`${dirPath}${name}/bg.jpg`) ? `${resPath}${name}/bg.jpg` : `${resPath}default/bg.jpg`,
style: (await Data.importModule(`resources/help/theme/${name}/config.js`)).style || {}
}
},
async getThemeData (diyStyle, sysStyle) {
let helpConfig = lodash.extend({}, sysStyle, diyStyle)
let colCount = Math.min(5, Math.max(parseInt(helpConfig?.colCount) || 3, 2))
let colWidth = Math.min(500, Math.max(100, parseInt(helpConfig?.colWidth) || 265))
let width = Math.min(2500, Math.max(800, colCount * colWidth + 30))
let theme = await Theme.getThemeCfg(helpConfig.theme, diyStyle.themeExclude || sysStyle.themeExclude)
let themeStyle = theme.style || {}
let ret = [`
body{background-image:url(${theme.bg});width:${width}px;}
.container{background-image:url(${theme.main});width:${width}px;}
.help-table .td,.help-table .th{width:${100 / colCount}%}
`]
let css = function (sel, css, key, def, fn) {
let val = Data.def(themeStyle[key], diyStyle[key], sysStyle[key], def)
if (fn) {
val = fn(val)
}
ret.push(`${sel}{${css}:${val}}`)
}
css('.help-title,.help-group', 'color', 'fontColor', '#ceb78b')
css('.help-title,.help-group', 'text-shadow', 'fontShadow', 'none')
css('.help-desc', 'color', 'descColor', '#eee')
css('.cont-box', 'background', 'contBgColor', 'rgba(43, 52, 61, 0.8)')
css('.cont-box', 'backdrop-filter', 'contBgBlur', 3, (n) => diyStyle.bgBlur === false ? 'none' : `blur(${n}px)`)
css('.help-group', 'background', 'headerBgColor', 'rgba(34, 41, 51, .4)')
css('.help-table .tr:nth-child(odd)', 'background', 'rowBgColor1', 'rgba(34, 41, 51, .2)')
css('.help-table .tr:nth-child(even)', 'background', 'rowBgColor2', 'rgba(34, 41, 51, .4)')
return {
style: `<style>${ret.join('\n')}</style>`,
colCount
}
}
}
export default Theme

Binary file not shown.

After

Width:  |  Height:  |  Size: 663 KiB

View File

@@ -1,7 +1,7 @@
body {
transform: scale(1);
width: 830px;
/* background: url("../common/theme/bg-01.jpg"); */
background: url("../common/theme/bg-01.jpg");
}
.container {

View File

@@ -2,8 +2,12 @@
{{block 'css'}}
<link rel="stylesheet" type="text/css" href="{{_res_path}}/help/index.css" />
<!-- <% style = style.replace(/{{_res_path}}/g, _res_path) %> -->
<!-- {{@style}} -->
<style>
.container {
background: url("{{_res_path}}/help/imgs/{{bg}}") right center !important;
background-size: cover !important;
}
</style>
{{/block}}
{{block 'main'}}

View File

@@ -1,24 +0,0 @@
export const style = {
// 主文字颜色
fontColor: '#ceb78b',
// 主文字阴影: 横向距离 垂直距离 阴影大小 阴影颜色
// fontShadow: '0px 0px 1px rgba( 219,212,246, .9)',
fontShadow: 'none',
// 描述文字颜色
descColor: '#eee',
/* 面板整体底色,会叠加在标题栏及帮助行之下,方便整体帮助有一个基础底色
* 若无需此项可将rgba最后一位置为0即为完全透明
* 注意若综合透明度较低,或颜色与主文字颜色过近或太透明可能导致阅读困难 */
// contBgColor: 'rgba( 255, 255, 255, .5)',
// 面板底图毛玻璃效果数字越大越模糊0-10 ,可为小数
// contBgBlur: 0,
// 板块标题栏底色
// headerBgColor: 'rgba( 255, 255, 255, .4)',
// 帮助奇数行底色
// rowBgColor1: 'rgba( 255, 255, 255, .2)',
// 帮助偶数行底色
// rowBgColor2: 'rgba( 255, 255, 255, .35)'
}