cg改了一些东西

This commit is contained in:
草莓 2024-12-06 17:05:15 +08:00
parent 93fade2337
commit e59bdda35a

View File

@ -8663,7 +8663,8 @@ core.plugin.animate = {
CGUI.style.transform = "translate(-50%,-50%)" CGUI.style.transform = "translate(-50%,-50%)"
const ctx = CGUI.getContext("2d"); const ctx = CGUI.getContext("2d");
main.dom.CGUI = CGUI; main.dom.CGUI = CGUI;
if (core.getLocalStorage("page", null) == null) core.setLocalStorage("page", 0); let page = 0; //初始页面
let show = false; //展示状态
CGUI.onclick = function (e) { CGUI.onclick = function (e) {
try { try {
e.preventDefault(); e.preventDefault();
@ -8776,7 +8777,7 @@ core.plugin.animate = {
["none", "none", 'none'], ["none", "none", 'none'],
["none", "none", "none"] ["none", "none", "none"]
] ]
]; ]
} }
//更新 //更新
@ -8800,38 +8801,77 @@ core.plugin.animate = {
} }
onclick(px, py) { //点击 onclick(px, py) { //点击
if (show) {
show = !show
core.clearMap(ctx);
this.drawUI();
return
}
console.log([px, py]); console.log([px, py]);
const makeBox = ([x, y], [w, h]) => {
if (px >= 33 && px <= 177 && py >= 33 && py <= 177) { //离开按钮是一致的,其余的记区分横竖屏 return [
[x, y],
[x + w, y + h]
];
}
const inRect = ([x, y], [
[sx, sy],
[dx, dy]
]) => {
return sx <= x && x <= dx && sy <= y && y <= dy;
};
const pos = [px, py];
const backbox = makeBox([33, 33], [144, 144])
if (inRect(pos, backbox)) { //离开按钮是一致的,其余的记区分横竖屏
CGUI.style.display = "none" CGUI.style.display = "none"
core.clearMap(ctx) core.clearMap(ctx)
core.restart(); core.restart();
return
} }
if (core.domStyle.isVertical) { if (core.domStyle.isVertical) {
//竖屏 //竖屏
if (px >= 33 && px <= 177 && py >= 384 && py <= 520) { const pageupbox = makeBox([33, 384], [144, 136])
const pagedownbox = makeBox([33, 1080], [144, 190])
const imagebox0 = makeBox([200, 300], [480, 320])
if (inRect(pos, pageupbox)) {
//2代表当前最大页数-1 //2代表当前最大页数-1
core.setLocalStorage("page", Math.min(2, core.getLocalStorage("page", 0) + 1)); if (page < 2) {
console.log(core.getLocalStorage("page")); page++;
} else if (px >= 33 && px <= 177 && py >= 1080 && py <= 1270) { core.clearMap(ctx);
core.setLocalStorage("page", Math.max(0, core.getLocalStorage("page", 2) - 1)); this.drawUI();
console.log(core.getLocalStorage("page"));
} }
} else if (inRect(pos, pagedownbox)) {
if (page > 0) {
page--;
core.clearMap(ctx);
this.drawUI();
}
} else if (inRect(pos, imagebox0)) {
const img = core.material.images.images[this.UIMx[page][0][0]]
ctx.save(); //保存设置
ctx.translate(1248, 0) //重新定位右上角为基准
ctx.rotate(Math.PI / 2) //旋转90度
ctx.drawImage(img, 0, 0, 2028, 1248)
ctx.restore(); //重置画布设置
show = !show;
} else { } else {
if (px >= 33 && px <= 177 && py >= 342 && py <= 471) { const pageupbox = makeBox([33, 342], [144, 129])
//2代表当前最大页数-1 const pagedownbox = makeBox([33, 837], [144, 138])
core.setLocalStorage("page", Math.min(2, core.getLocalStorage("page", 0) + 1)); if (inRect(pos, pageupbox)) {
console.log(core.getLocalStorage("page")); if (page < 2) {
} else if (px >= 33 && px <= 177 && py >= 837 && py <= 975) { page++;
core.setLocalStorage("page", Math.max(0, core.getLocalStorage("page", 2) - 1)); core.clearMap(ctx);
console.log(core.getLocalStorage("page")); this.drawUI();
} }
for (let i = 0; i < 2; i++) { } else if (inRect(pos, pagedownbox)) {
for (let j = 0; j < 3; j++) { if (page > 0) {
//这里是绘图脚本,然而我并不会写,交给草莓了 page++;
//drawImage(ctx, this.UIMx[core.getLocalStorage("page")][i * 3 - 3 + j], 480, 320, 300 + j * 500, 300 + i * 450); core.clearMap(ctx);
this.drawUI();
} }
} }
}
} }
} }
drawUI() { drawUI() {
@ -8856,11 +8896,12 @@ core.plugin.animate = {
core.fillText(ctx, '向上翻页', 100, 450, '#FFFFFF', core.ui._buildFont(24, true)); core.fillText(ctx, '向上翻页', 100, 450, '#FFFFFF', core.ui._buildFont(24, true));
core.fillText(ctx, '向下翻页', 100, 1150, '#FFFFFF', core.ui._buildFont(24, true)); core.fillText(ctx, '向下翻页', 100, 1150, '#FFFFFF', core.ui._buildFont(24, true));
// 添加3*2个4:3的画框 // 添加3*2个4:3的画框,及图片
for (let i = 0; i < 3; i++) { for (let i = 0; i < 3; i++) {
for (let j = 0; j < 2; j++) { for (let j = 0; j < 2; j++) {
core.fillRect(ctx, 200 + j * 500, 300 + i * 450, 480, 320, '#FFFFFF'); const img = core.material.images.images[this.UIMx[page][j][i]]
core.strokeRect(ctx, 200 + j * 500, 300 + i * 450, 480, 320, "#444444", 2); core.strokeRect(ctx, 200 + j * 500, 300 + i * 450, 480, 320, "#444444", 5);
if (img) ctx.drawImage(img, 200 + j * 500 + 15, 300 + i * 450 + 15, 480 - 30, 320 - 30)
} }
} }