211 lines
9.4 KiB
TypeScript
211 lines
9.4 KiB
TypeScript
import { Color, Graphics, Layers, Sprite, UITransform } from 'cc';
|
|
import type { Node } from 'cc';
|
|
import type { DialogComposer } from './OrchardDialogs';
|
|
|
|
type Point = readonly [number, number];
|
|
type RGB = readonly [number, number, number];
|
|
type Curve = readonly [number, number, number, number, number, number];
|
|
|
|
const LIGHT_CENTRE: Point = [535, 1090];
|
|
const GOLD: RGB = [255, 210, 125];
|
|
const PINK: RGB = [255, 135, 199];
|
|
|
|
/** 参考图坐标统一转为画布中心坐标。 / Convert reference pixels to canvas coordinates. */
|
|
function absoluteVertices(graphics: Graphics, points: readonly Point[]): void {
|
|
graphics.moveTo(points[0][0] - 540, 960 - points[0][1]);
|
|
for (let index = 1; index < points.length; index++) {
|
|
graphics.lineTo(points[index][0] - 540, 960 - points[index][1]);
|
|
}
|
|
graphics.close();
|
|
}
|
|
|
|
function decorationGraphics(ui: DialogComposer, name: string, parent: Node): Graphics {
|
|
const node = ui.group(name, parent);
|
|
node.layer = Layers.Enum.UI_2D;
|
|
node.getComponent(UITransform)!.setContentSize(1080, 1920);
|
|
const graphics = node.getComponent(Graphics) ?? node.addComponent(Graphics);
|
|
graphics.clear();
|
|
return graphics;
|
|
}
|
|
|
|
function polarPoint(radius: number, angle: number): Point {
|
|
return [
|
|
LIGHT_CENTRE[0] + Math.cos(angle) * radius,
|
|
LIGHT_CENTRE[1] + Math.sin(angle) * radius,
|
|
];
|
|
}
|
|
|
|
/** 独立扇形径向、横向渐淡,不填充整圆。 / Feather individual rays, never a solid disc. */
|
|
function authorRays(ui: DialogComposer, parent: Node): void {
|
|
const graphics = decorationGraphics(ui, 'BonusAwardRaysDecor', parent);
|
|
const rays: readonly (readonly [number, number, number, number])[] = [
|
|
[-176, 5, 610, 27], [-158, 9, 650, 30], [-140, 5, 620, 38],
|
|
[-123, 10, 650, 32], [-105, 5, 650, 43], [-88, 9, 650, 35],
|
|
[-70, 5, 650, 42], [-53, 10, 650, 31], [-34, 5, 630, 37],
|
|
[-17, 8, 650, 29], [2, 5, 610, 31], [20, 9, 625, 25],
|
|
[39, 5, 590, 34], [57, 8, 650, 26], [76, 4, 620, 32],
|
|
[95, 9, 650, 24], [114, 5, 620, 33], [132, 8, 650, 26],
|
|
[151, 5, 610, 35], [165, 4, 630, 25],
|
|
];
|
|
const feather: readonly (readonly [number, number, number])[] = [
|
|
[-1, -0.55, 0.2], [-0.55, 0.55, 1], [0.55, 1, 0.2],
|
|
];
|
|
const bands = 12;
|
|
for (let rayIndex = 0; rayIndex < rays.length; rayIndex++) {
|
|
const [degrees, halfWidth, length, opacity] = rays[rayIndex];
|
|
const angle = degrees * Math.PI / 180;
|
|
const spread = halfWidth * Math.PI / 180;
|
|
const tint = rayIndex % 3 === 0 ? PINK : GOLD;
|
|
for (let band = 0; band < bands; band++) {
|
|
const inner = length * band / bands;
|
|
const outer = length * (band + 1) / bands;
|
|
const fade = Math.pow(1 - (band + 0.5) / bands, 1.6);
|
|
for (const [left, right, strength] of feather) {
|
|
const alpha = Math.round(opacity * fade * strength);
|
|
if (alpha === 0) continue;
|
|
graphics.fillColor = new Color(tint[0], tint[1], tint[2], alpha);
|
|
const a = polarPoint(inner, angle + spread * left);
|
|
const b = polarPoint(outer, angle + spread * left);
|
|
const c = polarPoint(outer, angle + spread * right);
|
|
const d = polarPoint(inner, angle + spread * right);
|
|
absoluteVertices(graphics, [a, b, c]);
|
|
if (band > 0) absoluteVertices(graphics, [a, c, d]);
|
|
graphics.fill();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
const RIBBON_START: Point = [-27, -70];
|
|
const RIBBON_CURVES: readonly Curve[] = [
|
|
[-65, -62, -53, -20, -12, -27],
|
|
[32, -37, 50, -12, 21, 4],
|
|
[-12, 24, -33, 5, -22, -9],
|
|
[-7, -28, 21, -7, 8, 22],
|
|
[-4, 48, -15, 54, 11, 75],
|
|
];
|
|
|
|
/** 多层描边表现卷曲彩带的暗边、曲面和高光。 / Layer strokes for ribbon depth and sheen. */
|
|
function authorRibbon(
|
|
ui: DialogComposer, parent: Node, name: string, centre: Point,
|
|
degrees: number, scale: number, violet: boolean,
|
|
): void {
|
|
const graphics = decorationGraphics(ui, name, parent);
|
|
graphics.lineCap = Graphics.LineCap.ROUND;
|
|
graphics.lineJoin = Graphics.LineJoin.ROUND;
|
|
const angle = degrees * Math.PI / 180;
|
|
const cosine = Math.cos(angle);
|
|
const sine = Math.sin(angle);
|
|
const transform = (x: number, y: number, offset: Point): Point => [
|
|
centre[0] + (x * cosine - y * sine + offset[0]) * scale - 540,
|
|
960 - centre[1] - (x * sine + y * cosine + offset[1]) * scale,
|
|
];
|
|
const strokes: readonly { width: number; tint: RGB; alpha: number; offset: Point }[] = [
|
|
{ width: 18, tint: [72, 12, 102], alpha: 125, offset: [2, 3] },
|
|
{ width: 14, tint: violet ? [127, 40, 199] : [211, 44, 151], alpha: 245, offset: [0, 0] },
|
|
{ width: 8, tint: violet ? [197, 105, 247] : [250, 113, 205], alpha: 245, offset: [-1, -1] },
|
|
{ width: 2.5, tint: [255, 222, 252], alpha: 220, offset: [-3, -2] },
|
|
];
|
|
for (const stroke of strokes) {
|
|
graphics.lineWidth = stroke.width * scale;
|
|
graphics.strokeColor = new Color(stroke.tint[0], stroke.tint[1], stroke.tint[2], stroke.alpha);
|
|
const start = transform(RIBBON_START[0], RIBBON_START[1], stroke.offset);
|
|
graphics.moveTo(start[0], start[1]);
|
|
for (const curve of RIBBON_CURVES) {
|
|
const first = transform(curve[0], curve[1], stroke.offset);
|
|
const second = transform(curve[2], curve[3], stroke.offset);
|
|
const end = transform(curve[4], curve[5], stroke.offset);
|
|
graphics.bezierCurveTo(first[0], first[1], second[0], second[1], end[0], end[1]);
|
|
}
|
|
graphics.stroke();
|
|
}
|
|
}
|
|
|
|
function starPoints(x: number, y: number, radius: number): readonly Point[] {
|
|
const waist = radius * 0.14;
|
|
return [
|
|
[x, y - radius], [x + waist, y - waist],
|
|
[x + radius * 0.76, y], [x + waist, y + waist],
|
|
[x, y + radius], [x - waist, y + waist],
|
|
[x - radius * 0.76, y], [x - waist, y - waist],
|
|
];
|
|
}
|
|
|
|
/** 扩散也使用四角路径,保持星芒轻透。 / Use four-point silhouettes for translucent bloom. */
|
|
function authorStar(ui: DialogComposer, parent: Node, name: string, x: number, y: number, radius: number): void {
|
|
const graphics = decorationGraphics(ui, name, parent);
|
|
const layers = [
|
|
{ scale: 2.3, tint: GOLD, alpha: 13 },
|
|
{ scale: 1.65, tint: GOLD, alpha: 31 },
|
|
{ scale: 1.15, tint: GOLD, alpha: 115 },
|
|
{ scale: 1, tint: [255, 244, 204] as const, alpha: 240 },
|
|
{ scale: 0.56, tint: [255, 255, 255] as const, alpha: 255 },
|
|
];
|
|
for (const layer of layers) {
|
|
graphics.fillColor = new Color(layer.tint[0], layer.tint[1], layer.tint[2], layer.alpha);
|
|
absoluteVertices(graphics, starPoints(x, y, radius * layer.scale));
|
|
graphics.fill();
|
|
}
|
|
}
|
|
|
|
/** 原图含叶片,按原始画幅等比适配。 / Preserve the source fruit and leaves without stretching. */
|
|
function authorFruit(
|
|
ui: DialogComposer, parent: Node, name: string, key: string,
|
|
x: number, y: number, width: number, height: number,
|
|
): void {
|
|
const node = ui.image(name, key, x, y, width, height, parent);
|
|
node.layer = Layers.Enum.UI_2D;
|
|
const frame = node.getComponent(Sprite)!.spriteFrame!;
|
|
const original = frame.originalSize;
|
|
const scale = Math.min(width / original.width, height / original.height);
|
|
node.getComponent(UITransform)!.setContentSize(original.width * scale, original.height * scale);
|
|
}
|
|
|
|
/** 只构建庆祝底饰;标题、次数、徽标与按钮由调用方创建。 / Author decorations behind caller-owned content. */
|
|
export function authorCelebration(ui: DialogComposer, parent: Node): void {
|
|
const decor = ui.group('BonusAwardCelebrationDecor', parent);
|
|
decor.layer = Layers.Enum.UI_2D;
|
|
decor.getComponent(UITransform)!.setContentSize(1080, 1920);
|
|
decor.setSiblingIndex(0);
|
|
|
|
authorRays(ui, decor);
|
|
authorRibbon(ui, decor, 'BonusAwardRibbonUpperLeftDecor', [230, 365], -23, 1.08, false);
|
|
authorRibbon(ui, decor, 'BonusAwardRibbonUpperRightDecor', [865, 410], 19, 0.95, true);
|
|
authorRibbon(ui, decor, 'BonusAwardRibbonMiddleLeftDecor', [70, 1020], 12, 0.87, true);
|
|
authorRibbon(ui, decor, 'BonusAwardRibbonMiddleRightDecor', [992, 1125], -13, 0.95, false);
|
|
authorRibbon(ui, decor, 'BonusAwardRibbonLowerLeftDecor', [90, 1350], -18, 0.86, false);
|
|
authorRibbon(ui, decor, 'BonusAwardRibbonLowerRightDecor', [980, 1420], 25, 0.82, true);
|
|
|
|
authorFruit(ui, decor, 'BonusAwardLeftStrawberryDecor', 'crimson-berry', 203, 1170, 240, 265);
|
|
authorFruit(ui, decor, 'BonusAwardLeftBlueberriesDecor', 'indigo-bunch', 285, 1240, 160, 164);
|
|
authorFruit(ui, decor, 'BonusAwardRightStrawberryDecor', 'crimson-berry', 860, 1223, 185, 204);
|
|
authorFruit(ui, decor, 'BonusAwardRightBlueberriesDecor', 'indigo-bunch', 755, 1228, 177, 182);
|
|
|
|
authorStar(ui, decor, 'BonusAwardStarUpperLeftDecor', 216, 475, 26);
|
|
authorStar(ui, decor, 'BonusAwardStarTopDecor', 780, 365, 23);
|
|
authorStar(ui, decor, 'BonusAwardStarUpperRightDecor', 980, 647, 30);
|
|
authorStar(ui, decor, 'BonusAwardStarMiddleLeftDecor', 224, 1030, 26);
|
|
authorStar(ui, decor, 'BonusAwardStarRightDecor', 970, 1280, 25);
|
|
authorStar(ui, decor, 'BonusAwardStarLowerLeftDecor', 117, 1515, 16);
|
|
authorStar(ui, decor, 'BonusAwardStarLowerRightDecor', 945, 1540, 18);
|
|
}
|
|
|
|
/** 只使用现有装饰节点重绘,禁止因加载场景而重新创建节点。 / Redraw on existing decoration nodes without rebuilding UI at runtime. */
|
|
export function drawCelebrationGraphics(parent: Node): void {
|
|
const existing = parent.getChildByName('BonusAwardCelebrationDecor');
|
|
if (!existing) return;
|
|
const ui = {
|
|
group: (name: string, owner: Node = parent): Node => {
|
|
const node = owner.getChildByName(name);
|
|
if (!node) throw new Error(`Missing celebration drawing node: ${name}`);
|
|
return node;
|
|
},
|
|
image: (name: string, _key: string, _x: number, _y: number, _w: number, _h: number, owner: Node = parent): Node => {
|
|
const node = owner.getChildByName(name);
|
|
if (!node) throw new Error(`Missing celebration image node: ${name}`);
|
|
return node;
|
|
},
|
|
} as DialogComposer;
|
|
authorCelebration(ui, parent);
|
|
}
|