修复缩略图

This commit is contained in:
unanmed 2022-12-30 18:26:30 +08:00
parent ce8aa43412
commit 045400ecd6
3 changed files with 39 additions and 178 deletions

View File

@ -640,8 +640,8 @@ maps.prototype.resizeMap = function (floorId) {
core.canvas[cn].canvas.style.height =
height * core.domStyle.scale + 'px';
core.canvas[cn].translate(
core.bigmap.v2 ? 32 : 0,
core.bigmap.v2 ? 32 : 0
core.bigmap.v2 ? 32 * devicePixelRatio : 0,
core.bigmap.v2 ? 32 * devicePixelRatio : 0
);
if (main.mode === 'editor' && editor.isMobile) {
core.canvas[cn].canvas.style.width =
@ -2751,31 +2751,43 @@ maps.prototype._drawThumbnail_drawToTarget = function (floorId, options) {
hh = core._HALF_HEIGHT_,
W = core._WIDTH_,
H = core._HEIGHT_;
var ratio = core.domStyle.isVertical
? core.domStyle.ratio
: core.domStyle.scale;
if (main.mode == 'editor') {
pw = ph = core.__PIXELS__;
hw = hh = core.__HALF_SIZE__;
W = H = core.__SIZE__;
}
if (options.v2) {
core.drawImage(
ctx,
tempCanvas.canvas,
0,
0,
pw * ratio,
ph * ratio,
x,
y,
w,
h
);
if (options.noHD) {
core.drawImage(
ctx,
tempCanvas.canvas,
0,
0,
pw,
ph,
x,
y,
w,
h
);
} else {
const scale = devicePixelRatio * core.domStyle.scale;
core.drawImage(
ctx,
tempCanvas.canvas,
0,
0,
pw * scale,
ph * scale,
x,
y,
w,
h
);
}
} else {
var offsetX = core.clamp(centerX - hw, 0, width - W),
offsetY = core.clamp(centerY - hh, 0, height - H),
c = options.noHD ? 1 : core.domStyle.scale;
offsetY = core.clamp(centerY - hh, 0, height - H);
if (options.noHD) {
core.drawImage(
ctx,
@ -2794,10 +2806,10 @@ maps.prototype._drawThumbnail_drawToTarget = function (floorId, options) {
core.drawImage(
ctx,
tempCanvas.canvas,
offsetX * 32 * ratio,
offsetY * 32 * ratio,
pw * ratio,
ph * ratio,
offsetX * 32,
offsetY * 32,
pw,
ph,
x,
y,
w,

View File

@ -193,7 +193,10 @@ ui.prototype.fillBoldText = function (
this.setFontForMaxWidth(ctx, text, maxWidth);
}
ctx.strokeStyle = strokeStyle;
ctx.lineWidth = 1 * core.domStyle.scale * devicePixelRatio;
ctx.lineWidth =
1 *
(core.domStyle.isVertical ? core.domStyle.ratio : core.domStyle.scale) *
devicePixelRatio;
ctx.fillStyle = style;
ctx.strokeText(text, x, y);
ctx.fillText(text, x, y);

View File

@ -3424,160 +3424,6 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = {
});
document.body.addEventListener('keyup', keyboard);
}
maps.prototype._drawThumbnail_drawToTarget = function (
floorId,
options
) {
const ctx = core.getContextByName(options.ctx);
if (ctx == null) return;
const x = options.x || 0,
y = options.y || 0,
size = options.size || 1;
// size的含义改为(0,1]范围的系数以适配长方形默认为1楼传为3/4SL界面为0.3
let w = Math.ceil(size * core._PX_),
h = Math.ceil(size * core._PY_);
// 特判是否为编辑器编辑器中长宽均采用core.js的遗留正方形像素边长以保证下面的绘制正常
if (main.mode == 'editor') w = h = size * core.__PIXELS__;
const width = core.floors[floorId].width,
height = core.floors[floorId].height;
let centerX = options.centerX,
centerY = options.centerY;
if (centerX == null) centerX = Math.floor(width / 2);
if (centerY == null) centerY = Math.floor(height / 2);
const tempCanvas = core.bigmap.tempCanvas;
if (options.all) {
const tempWidth = tempCanvas.canvas.width,
tempHeight = tempCanvas.canvas.height;
// 绘制全景图
if (tempWidth <= tempHeight) {
const realHeight = h,
realWidth = (realHeight * tempWidth) / tempHeight;
const side = (w - realWidth) / 2;
if (options.fromMap) {
return core.drawImage(
ctx,
tempCanvas.canvas,
0,
0,
tempWidth,
tempHeight,
x,
y,
realWidth,
realHeight
);
}
core.fillRect(ctx, x, y, side, realHeight, '#000000');
core.fillRect(ctx, x + w - side, y, side, realHeight);
core.drawImage(
ctx,
tempCanvas.canvas,
0,
0,
tempWidth,
tempHeight,
x + side,
y,
realWidth,
realHeight
);
} else {
const realWidth = w,
realHeight = (realWidth * tempHeight) / tempWidth;
const side = (h - realHeight) / 2;
if (options.fromMap) {
return core.drawImage(
ctx,
tempCanvas.canvas,
0,
0,
tempWidth,
tempHeight,
x,
y,
realWidth,
realHeight
);
}
core.fillRect(ctx, x, y, realWidth, side, '#000000');
core.fillRect(ctx, x, y + h - side, realWidth, side);
core.drawImage(
ctx,
tempCanvas.canvas,
0,
0,
tempWidth,
tempHeight,
x,
y + side,
realWidth,
realHeight
);
}
} else {
// 只绘制可见窗口
let pw = core._PX_,
ph = core._PY_,
hw = core._HALF_WIDTH_,
hh = core._HALF_HEIGHT_,
W = core._WIDTH_,
H = core._HEIGHT_;
const ratio = core.domStyle.isVertical
? core.domStyle.ratio
: core.domStyle.scale;
if (main.mode == 'editor') {
pw = ph = core.__PIXELS__;
hw = hh = core.__HALF_SIZE__;
W = H = core.__SIZE__;
}
if (options.v2) {
core.drawImage(
ctx,
tempCanvas.canvas,
0,
0,
pw * ratio,
ph * ratio,
x,
y,
w,
h
);
} else {
const offsetX = core.clamp(centerX - hw, 0, width - W),
offsetY = core.clamp(centerY - hh, 0, height - H);
if (options.noHD) {
core.drawImage(
ctx,
tempCanvas.canvas,
offsetX * 32,
offsetY * 32,
pw,
ph,
x,
y,
w,
h
);
return;
}
core.drawImage(
ctx,
tempCanvas.canvas,
offsetX * 32 * ratio,
offsetY * 32 * ratio,
pw * ratio,
ph * ratio,
x,
y,
w,
h
);
}
}
};
},
towerBoss: function () {
// 智慧boss