lyb-pixi-js 1.12.33 → 1.12.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Components/Base/LibPixiArc.d.ts +16 -0
- package/Components/Base/LibPixiArc.js +14 -0
- package/Components/Base/LibPixiBitText.d.ts +20 -0
- package/Components/Base/LibPixiBitText.js +26 -0
- package/Components/Base/LibPixiCircular.d.ts +7 -0
- package/Components/Base/LibPixiCircular.js +12 -0
- package/Components/Base/LibPixiContainer.d.ts +22 -0
- package/Components/Base/LibPixiContainer.js +51 -0
- package/Components/Base/LibPixiHtmlText.d.ts +31 -0
- package/Components/Base/LibPixiHtmlText.js +30 -0
- package/Components/Base/LibPixiOval.d.ts +5 -0
- package/Components/Base/LibPixiOval.js +10 -0
- package/Components/Base/LibPixiParticleMove.d.ts +101 -0
- package/Components/Base/LibPixiParticleMove.js +136 -0
- package/Components/Base/LibPixiPolygon.d.ts +7 -0
- package/Components/Base/LibPixiPolygon.js +15 -0
- package/Components/Base/LibPixiRectBgColor.d.ts +41 -0
- package/Components/Base/LibPixiRectBgColor.js +95 -0
- package/Components/Base/LibPixiRectangle.d.ts +7 -0
- package/Components/Base/LibPixiRectangle.js +15 -0
- package/Components/Base/LibPixiRound.d.ts +5 -0
- package/Components/Base/LibPixiRound.js +9 -0
- package/Components/Base/LibPixiRoundedRect.d.ts +5 -0
- package/Components/Base/LibPixiRoundedRect.js +10 -0
- package/Components/Base/LibPixiSpine.d.ts +58 -0
- package/Components/Base/LibPixiSpine.js +128 -0
- package/Components/Base/LibPixiText.d.ts +37 -0
- package/Components/Base/LibPixiText.js +35 -0
- package/Components/Custom/LibPixiAreaClick.d.ts +6 -0
- package/Components/Custom/LibPixiAreaClick.js +16 -0
- package/Components/Custom/LibPixiArrangeLinearV2.d.ts +25 -0
- package/Components/Custom/LibPixiArrangeLinearV2.js +80 -0
- package/Components/Custom/LibPixiButtonHover.d.ts +40 -0
- package/Components/Custom/LibPixiButtonHover.js +53 -0
- package/Components/Custom/LibPixiCapsule.d.ts +5 -0
- package/Components/Custom/LibPixiCapsule.js +10 -0
- package/Components/Custom/LibPixiCloseBtn.d.ts +14 -0
- package/Components/Custom/LibPixiCloseBtn.js +36 -0
- package/Components/Custom/LibPixiDragLocate.d.ts +36 -0
- package/Components/Custom/LibPixiDragLocate.js +230 -0
- package/Components/Custom/LibPixiDrawer.d.ts +16 -0
- package/Components/Custom/LibPixiDrawer.js +59 -0
- package/Components/Custom/LibPixiGridLayoutV2.d.ts +27 -0
- package/Components/Custom/LibPixiGridLayoutV2.js +37 -0
- package/Components/Custom/LibPixiInput.d.ts +77 -0
- package/Components/Custom/LibPixiInput.js +198 -0
- package/Components/Custom/LibPixiLabelValue.d.ts +30 -0
- package/Components/Custom/LibPixiLabelValue.js +26 -0
- package/Components/Custom/LibPixiPerforMon.d.ts +47 -0
- package/Components/Custom/LibPixiPerforMon.js +166 -0
- package/Components/Custom/LibPixiProgress.d.ts +33 -0
- package/Components/Custom/LibPixiProgress.js +47 -0
- package/Components/Custom/LibPixiPuzzleBg.d.ts +7 -0
- package/Components/Custom/LibPixiPuzzleBg.js +46 -0
- package/Components/Custom/LibPixiScrollContainerX.d.ts +71 -0
- package/Components/Custom/LibPixiScrollContainerX.js +198 -0
- package/Components/Custom/LibPixiScrollContainerY.d.ts +109 -0
- package/Components/Custom/LibPixiScrollContainerY.js +340 -0
- package/Components/Custom/LibPixiScrollNum.d.ts +67 -0
- package/Components/Custom/LibPixiScrollNum.js +184 -0
- package/Components/Custom/LibPixiSlide.d.ts +94 -0
- package/Components/Custom/LibPixiSlide.js +285 -0
- package/Components/Custom/LibPixiSlider.d.ts +82 -0
- package/Components/Custom/LibPixiSlider.js +165 -0
- package/Components/Custom/LibPixiTable.d.ts +64 -0
- package/Components/Custom/LibPixiTable.js +76 -0
- package/Components/Custom/LibPixiTextGroupWrap.d.ts +20 -0
- package/Components/Custom/LibPixiTextGroupWrap.js +50 -0
- package/Components/Custom/LibPixiTriangle.d.ts +5 -0
- package/Components/Custom/LibPixiTriangle.js +12 -0
- package/Components/Custom/LibPixiTurntable.d.ts +6 -0
- package/Components/Custom/LibPixiTurntable.js +14 -0
- package/Utils/LibContainerCenter.d.ts +3 -0
- package/Utils/LibContainerCenter.js +10 -0
- package/Utils/LibControlledDelayedCall.d.ts +5 -0
- package/Utils/LibControlledDelayedCall.js +20 -0
- package/Utils/LibPixiArrangeLinear.d.ts +16 -0
- package/Utils/LibPixiArrangeLinear.js +62 -0
- package/Utils/LibPixiAudio.d.ts +53 -0
- package/Utils/LibPixiAudio.js +168 -0
- package/Utils/LibPixiCreateNineGrid.d.ts +15 -0
- package/Utils/LibPixiCreateNineGrid.js +19 -0
- package/Utils/LibPixiDialogManager/index.d.ts +25 -0
- package/Utils/LibPixiDialogManager/index.js +43 -0
- package/Utils/LibPixiDialogManager/ui/LibPixiBaseContainer.d.ts +11 -0
- package/Utils/LibPixiDialogManager/ui/LibPixiBaseContainer.js +31 -0
- package/Utils/LibPixiDialogManager/ui/LibPixiDialog.d.ts +38 -0
- package/Utils/LibPixiDialogManager/ui/LibPixiDialog.js +133 -0
- package/Utils/LibPixiDigitalIncreasingAnimation.d.ts +18 -0
- package/Utils/LibPixiDigitalIncreasingAnimation.js +26 -0
- package/Utils/LibPixiDownScaleAnimation.d.ts +7 -0
- package/Utils/LibPixiDownScaleAnimation.js +33 -0
- package/Utils/LibPixiEmitContainerEvent.d.ts +7 -0
- package/Utils/LibPixiEmitContainerEvent.js +13 -0
- package/Utils/LibPixiEvent.d.ts +19 -0
- package/Utils/LibPixiEvent.js +68 -0
- package/Utils/LibPixiFilter.d.ts +9 -0
- package/Utils/LibPixiFilter.js +34 -0
- package/Utils/LibPixiGlobalUpdater.d.ts +15 -0
- package/Utils/LibPixiGlobalUpdater.js +21 -0
- package/Utils/LibPixiGridLayout.d.ts +10 -0
- package/Utils/LibPixiGridLayout.js +27 -0
- package/Utils/LibPixiHVCenter.d.ts +7 -0
- package/Utils/LibPixiHVCenter.js +14 -0
- package/Utils/LibPixiHVGap.d.ts +8 -0
- package/Utils/LibPixiHVGap.js +26 -0
- package/Utils/LibPixiIntervalTrigger.d.ts +7 -0
- package/Utils/LibPixiIntervalTrigger.js +35 -0
- package/Utils/LibPixiOutsideClick.d.ts +8 -0
- package/Utils/LibPixiOutsideClick.js +22 -0
- package/Utils/LibPixiOverflowHidden.d.ts +6 -0
- package/Utils/LibPixiOverflowHidden.js +14 -0
- package/Utils/LibPixiPolygonDrawTool.d.ts +44 -0
- package/Utils/LibPixiPolygonDrawTool.js +114 -0
- package/Utils/LibPixiPromiseTickerTimeout.d.ts +6 -0
- package/Utils/LibPixiPromiseTickerTimeout.js +22 -0
- package/Utils/LibPixiScaleContainer.d.ts +8 -0
- package/Utils/LibPixiScaleContainer.js +14 -0
- package/Utils/LibPixiShadow.d.ts +17 -0
- package/Utils/LibPixiShadow.js +18 -0
- package/Utils/LibPixiSlideInput.d.ts +55 -0
- package/Utils/LibPixiSlideInput.js +61 -0
- package/Utils/LibPixiTicker.d.ts +14 -0
- package/Utils/LibPixiTicker.js +49 -0
- package/Utils/LibPixiTickerTimeout.d.ts +6 -0
- package/Utils/LibPixiTickerTimeout.js +22 -0
- package/package.json +1 -2
- package/index.js +0 -5
- package/lyb-pixi.js +0 -58890
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/** @description 表格绘制并填入数字 */
|
|
2
|
+
import { Container, Graphics, Text } from "pixi.js";
|
|
3
|
+
import { libPixiScaleContainer } from '../../Utils/LibPixiScaleContainer';
|
|
4
|
+
/** @description 绘制表格并填充数字
|
|
5
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiTable-数字表格
|
|
6
|
+
*/
|
|
7
|
+
export class LibPixiTable extends Container {
|
|
8
|
+
constructor(params) {
|
|
9
|
+
super();
|
|
10
|
+
const { data, cellWidth = 130, cellHeight = 100, fontColor = "#fff", firstColumnFontColor = "#fff", fontSize = 30, lineWidth = 2, lineColor = "#5b5b5b", outsideBorder = true, fontBold = true, } = params;
|
|
11
|
+
this._data = data;
|
|
12
|
+
this._rows = data.length;
|
|
13
|
+
this._cols = data[0].length;
|
|
14
|
+
this._cellWidth = cellWidth;
|
|
15
|
+
this._cellHeight = cellHeight;
|
|
16
|
+
this._fontColor = fontColor;
|
|
17
|
+
this._fontSize = fontSize;
|
|
18
|
+
this._lineWidth = lineWidth;
|
|
19
|
+
this._lineColor = lineColor;
|
|
20
|
+
this._outsideBorder = outsideBorder;
|
|
21
|
+
this._fontBold = fontBold;
|
|
22
|
+
this._firstColumnFontColor = firstColumnFontColor;
|
|
23
|
+
this._drawTable();
|
|
24
|
+
this.fillNumbers();
|
|
25
|
+
}
|
|
26
|
+
/** @description 绘制表格 */
|
|
27
|
+
_drawTable() {
|
|
28
|
+
const tableWidth = this._cellWidth * this._cols;
|
|
29
|
+
const tableHeight = this._cellHeight * this._rows;
|
|
30
|
+
const graphics = new Graphics();
|
|
31
|
+
graphics.lineStyle(this._lineWidth, this._lineColor);
|
|
32
|
+
// 绘制表格外框
|
|
33
|
+
if (this._outsideBorder) {
|
|
34
|
+
graphics.drawRect(0, 0, tableWidth, tableHeight);
|
|
35
|
+
}
|
|
36
|
+
// 绘制横线
|
|
37
|
+
for (let i = 1; i < this._rows; i++) {
|
|
38
|
+
graphics.moveTo(0, i * this._cellHeight);
|
|
39
|
+
graphics.lineTo(tableWidth, i * this._cellHeight);
|
|
40
|
+
}
|
|
41
|
+
// 绘制竖线
|
|
42
|
+
for (let j = 1; j < this._cols; j++) {
|
|
43
|
+
graphics.moveTo(j * this._cellWidth, 0);
|
|
44
|
+
graphics.lineTo(j * this._cellWidth, tableHeight);
|
|
45
|
+
}
|
|
46
|
+
this.addChild(graphics);
|
|
47
|
+
}
|
|
48
|
+
/** @description 填充数字 */
|
|
49
|
+
fillNumbers() {
|
|
50
|
+
for (let row = 0; row < this._rows; row++) {
|
|
51
|
+
for (let col = 0; col < this._cols; col++) {
|
|
52
|
+
const number = this._data[row][col];
|
|
53
|
+
this._createNumberText(number, col, row);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** @description 创建数字文本
|
|
58
|
+
* @param number 数字
|
|
59
|
+
* @param col 列索引
|
|
60
|
+
* @param row 行索引
|
|
61
|
+
*/
|
|
62
|
+
_createNumberText(number, col, row) {
|
|
63
|
+
const text = new Text(number.toString(), {
|
|
64
|
+
_fontSize: this._fontSize,
|
|
65
|
+
fill: col === 0 ? this._firstColumnFontColor : this._fontColor,
|
|
66
|
+
fontWeight: this._fontBold ? "bold" : "normal",
|
|
67
|
+
});
|
|
68
|
+
// 计算文本的居中位置
|
|
69
|
+
const x = col * this._cellWidth + this._cellWidth / 2;
|
|
70
|
+
const y = row * this._cellHeight + this._cellHeight / 2;
|
|
71
|
+
this.addChild(text);
|
|
72
|
+
text.anchor.set(0.5);
|
|
73
|
+
text.position.set(x, y);
|
|
74
|
+
libPixiScaleContainer(text, this._cellWidth * 0.9);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Container, type ITextStyle } from "pixi.js";
|
|
2
|
+
interface TextItem {
|
|
3
|
+
text: string;
|
|
4
|
+
style?: Partial<ITextStyle>;
|
|
5
|
+
}
|
|
6
|
+
interface TextGroupOptions {
|
|
7
|
+
items: TextItem[];
|
|
8
|
+
defaultStyle?: Partial<ITextStyle>;
|
|
9
|
+
wordWrapWidth?: number;
|
|
10
|
+
paddingX?: number;
|
|
11
|
+
paddingY?: number;
|
|
12
|
+
align?: "left" | "center" | "right";
|
|
13
|
+
anchorX?: number;
|
|
14
|
+
anchorY?: number;
|
|
15
|
+
}
|
|
16
|
+
/** @description 文本组换行 */
|
|
17
|
+
export declare class LibPixiTextGroupWrap extends Container {
|
|
18
|
+
constructor({ items, defaultStyle, wordWrapWidth, paddingX, paddingY, align, anchorX, anchorY, }: TextGroupOptions);
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Container, Text } from "pixi.js";
|
|
2
|
+
/** @description 文本组换行 */
|
|
3
|
+
export class LibPixiTextGroupWrap extends Container {
|
|
4
|
+
constructor({ items, defaultStyle = {}, wordWrapWidth, paddingX = 0, paddingY = 0, align = "left", anchorX = 0, anchorY = 0, }) {
|
|
5
|
+
super();
|
|
6
|
+
if (!items.length)
|
|
7
|
+
return;
|
|
8
|
+
const lineGroups = [];
|
|
9
|
+
let currentLine = [];
|
|
10
|
+
let x = 0;
|
|
11
|
+
// 分行
|
|
12
|
+
for (const { text, style = {} } of items) {
|
|
13
|
+
const instance = new Text(text, Object.assign(Object.assign({}, defaultStyle), style));
|
|
14
|
+
const w = instance.width;
|
|
15
|
+
if (wordWrapWidth && x + w > wordWrapWidth && x > 0) {
|
|
16
|
+
lineGroups.push(currentLine);
|
|
17
|
+
currentLine = [];
|
|
18
|
+
x = 0;
|
|
19
|
+
}
|
|
20
|
+
currentLine.push(instance);
|
|
21
|
+
x += w + paddingX;
|
|
22
|
+
}
|
|
23
|
+
if (currentLine.length)
|
|
24
|
+
lineGroups.push(currentLine);
|
|
25
|
+
// 布局每行
|
|
26
|
+
let y = 0;
|
|
27
|
+
for (const line of lineGroups) {
|
|
28
|
+
const totalWidth = line.reduce((sum, i) => sum + i.width + paddingX, -paddingX);
|
|
29
|
+
let offsetX = 0;
|
|
30
|
+
if (align === "center" && wordWrapWidth)
|
|
31
|
+
offsetX = (wordWrapWidth - totalWidth) / 2;
|
|
32
|
+
else if (align === "right" && wordWrapWidth)
|
|
33
|
+
offsetX = wordWrapWidth - totalWidth;
|
|
34
|
+
let currentX = offsetX;
|
|
35
|
+
let maxHeight = 0;
|
|
36
|
+
for (const item of line) {
|
|
37
|
+
item.x = currentX;
|
|
38
|
+
item.y = y;
|
|
39
|
+
this.addChild(item);
|
|
40
|
+
currentX += item.width + paddingX;
|
|
41
|
+
if (item.height > maxHeight)
|
|
42
|
+
maxHeight = item.height;
|
|
43
|
+
}
|
|
44
|
+
y += maxHeight + paddingY;
|
|
45
|
+
}
|
|
46
|
+
// 根据 anchor 调整整体偏移
|
|
47
|
+
const bounds = this.getLocalBounds();
|
|
48
|
+
this.pivot.set(bounds.x + bounds.width * anchorX, bounds.y + bounds.height * anchorY);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Graphics } from "pixi.js";
|
|
2
|
+
/** @description 三角形 */
|
|
3
|
+
export class LibPixiTriangle extends Graphics {
|
|
4
|
+
constructor(dots, color) {
|
|
5
|
+
super();
|
|
6
|
+
this.beginFill(color);
|
|
7
|
+
this.moveTo(0, 0);
|
|
8
|
+
this.lineTo(dots[0][0], dots[0][1]);
|
|
9
|
+
this.lineTo(dots[1][0], dots[1][1]);
|
|
10
|
+
this.endFill();
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { libJsConvertAngle } from "lyb-js/Math/LibJsConvertAngle.js";
|
|
2
|
+
/** @description 转盘布局
|
|
3
|
+
* @param num 份数
|
|
4
|
+
* @param distance 中心距离
|
|
5
|
+
* @param layoutCallback 定位计算回调
|
|
6
|
+
*/
|
|
7
|
+
export const LibPixiTurntable = (num, distance, layoutCallback) => {
|
|
8
|
+
for (let i = 0; i < num; i++) {
|
|
9
|
+
const rotation = libJsConvertAngle((360 / num) * i, "rad");
|
|
10
|
+
const cos = Math.cos(rotation + libJsConvertAngle(-90, "rad"));
|
|
11
|
+
const sin = Math.sin(rotation + libJsConvertAngle(-90, "rad"));
|
|
12
|
+
layoutCallback(cos * distance, sin * distance, rotation, i);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** @description 当前容器在父容器居中 */
|
|
2
|
+
export const libContainerCenter = (parent, item, centerType = "xy") => {
|
|
3
|
+
const xy = centerType === "xy";
|
|
4
|
+
if (centerType === "x" || xy) {
|
|
5
|
+
item.x = parent.width / 2 - item.width / 2;
|
|
6
|
+
}
|
|
7
|
+
if (centerType === "y" || xy) {
|
|
8
|
+
item.y = parent.height / 2 - item.height / 2;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { libPixiTickerTimeout } from "./LibPixiTickerTimeout";
|
|
2
|
+
/** @description 可控延迟调用函数 */
|
|
3
|
+
export const libControlledDelayedCall = (time) => {
|
|
4
|
+
let _resolve;
|
|
5
|
+
let timer;
|
|
6
|
+
const start = new Promise((resolve) => {
|
|
7
|
+
_resolve = resolve;
|
|
8
|
+
timer = libPixiTickerTimeout(() => {
|
|
9
|
+
resolve();
|
|
10
|
+
}, time);
|
|
11
|
+
});
|
|
12
|
+
const stop = () => {
|
|
13
|
+
timer();
|
|
14
|
+
_resolve();
|
|
15
|
+
};
|
|
16
|
+
return {
|
|
17
|
+
start,
|
|
18
|
+
stop,
|
|
19
|
+
};
|
|
20
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Container } from "pixi.js";
|
|
2
|
+
/**
|
|
3
|
+
* @description 线性排列 PIXI.Container 元素(支持横向/纵向排列,多列布局、固定或自定义间隔)
|
|
4
|
+
* @param items 需要排列的容器数组
|
|
5
|
+
* @param gap 间隔,可为固定值或数组(数组长度必须等于 items.length - 1)
|
|
6
|
+
* @param direction 排列方向:"x" 横向排列,"y" 纵向排列
|
|
7
|
+
* @param cols 每行(或每列)最多的元素个数,默认为 Infinity(单行/单列)
|
|
8
|
+
* @example
|
|
9
|
+
* // 横向排列
|
|
10
|
+
* LibPixiArrangeLinear([sprite1, sprite2, sprite3], 10, "x");
|
|
11
|
+
* // 纵向排列
|
|
12
|
+
* LibPixiArrangeLinear([sprite1, sprite2, sprite3], 20, "y");
|
|
13
|
+
* // 两列布局
|
|
14
|
+
* LibPixiArrangeLinear([sprite1, sprite2, sprite3, sprite4], 10, "x", 2);
|
|
15
|
+
*/
|
|
16
|
+
export declare const LibPixiArrangeLinear: (items: Container[], gap: number | number[], direction?: "x" | "y", cols?: number) => void;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description 线性排列 PIXI.Container 元素(支持横向/纵向排列,多列布局、固定或自定义间隔)
|
|
3
|
+
* @param items 需要排列的容器数组
|
|
4
|
+
* @param gap 间隔,可为固定值或数组(数组长度必须等于 items.length - 1)
|
|
5
|
+
* @param direction 排列方向:"x" 横向排列,"y" 纵向排列
|
|
6
|
+
* @param cols 每行(或每列)最多的元素个数,默认为 Infinity(单行/单列)
|
|
7
|
+
* @example
|
|
8
|
+
* // 横向排列
|
|
9
|
+
* LibPixiArrangeLinear([sprite1, sprite2, sprite3], 10, "x");
|
|
10
|
+
* // 纵向排列
|
|
11
|
+
* LibPixiArrangeLinear([sprite1, sprite2, sprite3], 20, "y");
|
|
12
|
+
* // 两列布局
|
|
13
|
+
* LibPixiArrangeLinear([sprite1, sprite2, sprite3, sprite4], 10, "x", 2);
|
|
14
|
+
*/
|
|
15
|
+
export const LibPixiArrangeLinear = (items, gap, direction = "x", cols = Infinity) => {
|
|
16
|
+
// 验证 gap 数组长度是否正确
|
|
17
|
+
if (Array.isArray(gap)) {
|
|
18
|
+
if (gap.length !== items.length - 1) {
|
|
19
|
+
console.error(new Error("间隔的数组长度只能等于元素数组长度-1"));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
let lastRowMax = 0; // 当前行(或列)的最大高度(或宽度),用于多行/多列换行时计算偏移
|
|
24
|
+
let rowOffset = 0; // 累计偏移量,控制换行后的整体偏移位置
|
|
25
|
+
items.forEach((item, index) => {
|
|
26
|
+
var _a, _b;
|
|
27
|
+
const row = Math.floor(index / cols); // 当前行号
|
|
28
|
+
const col = index % cols; // 当前列号
|
|
29
|
+
if (direction === "x") {
|
|
30
|
+
//间隔
|
|
31
|
+
const gapValue = Array.isArray(gap) ? (_a = gap[index - 1]) !== null && _a !== void 0 ? _a : 0 : gap;
|
|
32
|
+
//在每行第一列重置列偏移量
|
|
33
|
+
if (col === 0 && row > 0) {
|
|
34
|
+
rowOffset += lastRowMax + gapValue;
|
|
35
|
+
lastRowMax = 0;
|
|
36
|
+
}
|
|
37
|
+
// 横向位置 = 前一个元素的右侧 + 间隔;首列则从 0 开始
|
|
38
|
+
item.x =
|
|
39
|
+
col === 0 ? 0 : items[index - 1].x + items[index - 1].width + gapValue;
|
|
40
|
+
// 纵向位置 = 当前累计的行偏移
|
|
41
|
+
rowOffset && (item.y = rowOffset);
|
|
42
|
+
// 更新当前行的最大高度
|
|
43
|
+
lastRowMax = Math.max(lastRowMax, item.height);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
//间隔
|
|
47
|
+
const gapValue = Array.isArray(gap) ? (_b = gap[index - 1]) !== null && _b !== void 0 ? _b : 0 : gap;
|
|
48
|
+
//在每列第一行重置行偏移
|
|
49
|
+
if (col === 0 && row > 0) {
|
|
50
|
+
rowOffset += lastRowMax + gapValue;
|
|
51
|
+
lastRowMax = 0;
|
|
52
|
+
}
|
|
53
|
+
// 纵向位置 = 首列则从 0 开始,其余从前一个元素的y坐标 + 高度 + 间隔;
|
|
54
|
+
item.y =
|
|
55
|
+
col === 0 ? 0 : items[index - 1].y + items[index - 1].height + gapValue;
|
|
56
|
+
// 横向位置 = 当前累计的列偏移
|
|
57
|
+
rowOffset && (item.x = rowOffset);
|
|
58
|
+
// 更新当前列的最大宽度
|
|
59
|
+
lastRowMax = Math.max(lastRowMax, item.width);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import "@pixi/sound";
|
|
2
|
+
export declare class LibPixiAudio {
|
|
3
|
+
/** 是否启用音效 */
|
|
4
|
+
effectEnabled: boolean;
|
|
5
|
+
/** 是否启用音乐 */
|
|
6
|
+
musicEnabled: boolean;
|
|
7
|
+
/** 音乐是否处于暂停状态 */
|
|
8
|
+
private _isMusicPaused;
|
|
9
|
+
/** 是否已切换后台 */
|
|
10
|
+
private _isBackground;
|
|
11
|
+
/** 当前音乐播放器 */
|
|
12
|
+
private _musicPlayer?;
|
|
13
|
+
/** 当前正在播放的音效列表 */
|
|
14
|
+
private _playingList;
|
|
15
|
+
constructor();
|
|
16
|
+
/** @description 播放音效
|
|
17
|
+
* @param key 音效资源Key,内部会使用Assets.get(key)获取音频资源
|
|
18
|
+
* @param end 倒数几秒位置播放,单位秒
|
|
19
|
+
*/
|
|
20
|
+
playEffect(key: string, end?: number): Promise<void>;
|
|
21
|
+
/** @description 播放音乐
|
|
22
|
+
* @param key 音效资源Key,内部会使用Assets.get(key)获取音频资源
|
|
23
|
+
*/
|
|
24
|
+
playMusic(key: string): Promise<void>;
|
|
25
|
+
/** @description 暂停音乐 */
|
|
26
|
+
pauseMusic(): void;
|
|
27
|
+
/** @description 继续播放音乐 */
|
|
28
|
+
resumeMusic(): void;
|
|
29
|
+
/** @description 停止播放指定音效
|
|
30
|
+
* @param key 音效资源Key,内部会使用Assets.get(key)获取音频资源进行停止
|
|
31
|
+
*/
|
|
32
|
+
stopEffect(key: string): void;
|
|
33
|
+
/** @description 设置启用音效
|
|
34
|
+
* @param enabled 启用状态,false为禁用
|
|
35
|
+
*/
|
|
36
|
+
setEffectEnabled(enabled: boolean): void;
|
|
37
|
+
/** @description 设置启用音乐
|
|
38
|
+
* @param enabled 启用状态,false为禁用
|
|
39
|
+
*/
|
|
40
|
+
setMusicEnabled(enabled: boolean): void;
|
|
41
|
+
/** @description 设置音效和音乐播放状态
|
|
42
|
+
* @param status 播放状态,false为暂停
|
|
43
|
+
*/
|
|
44
|
+
private _setPlayStatus;
|
|
45
|
+
/** @description 设置静音音乐
|
|
46
|
+
* @param disabled 静音状态,true为静音
|
|
47
|
+
*/
|
|
48
|
+
private _setMusicMute;
|
|
49
|
+
/** @description 设置静音音效
|
|
50
|
+
* @param disabled 静音状态,true为静音
|
|
51
|
+
*/
|
|
52
|
+
private _setEffectMute;
|
|
53
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { Assets } from "pixi.js";
|
|
11
|
+
import { Howl } from "howler";
|
|
12
|
+
import "@pixi/sound";
|
|
13
|
+
import gsap from "gsap";
|
|
14
|
+
export class LibPixiAudio {
|
|
15
|
+
constructor() {
|
|
16
|
+
/** 是否启用音效 */
|
|
17
|
+
this.effectEnabled = true;
|
|
18
|
+
/** 是否启用音乐 */
|
|
19
|
+
this.musicEnabled = true;
|
|
20
|
+
/** 音乐是否处于暂停状态 */
|
|
21
|
+
this._isMusicPaused = false;
|
|
22
|
+
/** 是否已切换后台 */
|
|
23
|
+
this._isBackground = false;
|
|
24
|
+
/** 当前正在播放的音效列表 */
|
|
25
|
+
this._playingList = [];
|
|
26
|
+
/** @description 设置音效和音乐播放状态
|
|
27
|
+
* @param status 播放状态,false为暂停
|
|
28
|
+
*/
|
|
29
|
+
this._setPlayStatus = (status) => {
|
|
30
|
+
var _a, _b;
|
|
31
|
+
if (status) {
|
|
32
|
+
!this._isMusicPaused && ((_a = this._musicPlayer) === null || _a === void 0 ? void 0 : _a.play());
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
(_b = this._musicPlayer) === null || _b === void 0 ? void 0 : _b.pause();
|
|
36
|
+
}
|
|
37
|
+
this._playingList.forEach((item) => {
|
|
38
|
+
if (status) {
|
|
39
|
+
item.audio.play();
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
item.audio.pause();
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
document.addEventListener("visibilitychange", () => {
|
|
47
|
+
this._isBackground = document.hidden;
|
|
48
|
+
this._setPlayStatus(!document.hidden);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/** @description 播放音效
|
|
52
|
+
* @param key 音效资源Key,内部会使用Assets.get(key)获取音频资源
|
|
53
|
+
* @param end 倒数几秒位置播放,单位秒
|
|
54
|
+
*/
|
|
55
|
+
playEffect(key, end) {
|
|
56
|
+
return new Promise((resolve) => {
|
|
57
|
+
const id = Math.random();
|
|
58
|
+
const url = Assets.get(key).url;
|
|
59
|
+
const sound = new Howl({
|
|
60
|
+
src: url,
|
|
61
|
+
mute: this._isBackground || !this.effectEnabled,
|
|
62
|
+
});
|
|
63
|
+
sound.play();
|
|
64
|
+
sound.on("end", () => {
|
|
65
|
+
this._playingList = this._playingList.filter((item) => item.id !== id);
|
|
66
|
+
resolve();
|
|
67
|
+
});
|
|
68
|
+
//倒数几秒位置播放
|
|
69
|
+
if (end) {
|
|
70
|
+
const duration = sound.duration();
|
|
71
|
+
const start = duration - end;
|
|
72
|
+
sound.seek(start);
|
|
73
|
+
}
|
|
74
|
+
this._playingList.push({
|
|
75
|
+
id,
|
|
76
|
+
audio: sound,
|
|
77
|
+
url,
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
/** @description 播放音乐
|
|
82
|
+
* @param key 音效资源Key,内部会使用Assets.get(key)获取音频资源
|
|
83
|
+
*/
|
|
84
|
+
playMusic(key) {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
const url = Assets.get(key).url;
|
|
87
|
+
//如果有音乐正在播放,则停止
|
|
88
|
+
if (this._musicPlayer) {
|
|
89
|
+
gsap.killTweensOf(this._musicPlayer);
|
|
90
|
+
yield gsap.to(this._musicPlayer, {
|
|
91
|
+
volume: 0,
|
|
92
|
+
duration: 1,
|
|
93
|
+
ease: "linear",
|
|
94
|
+
});
|
|
95
|
+
this._musicPlayer.stop();
|
|
96
|
+
}
|
|
97
|
+
this._musicPlayer = new Howl({
|
|
98
|
+
src: url,
|
|
99
|
+
loop: true,
|
|
100
|
+
volume: 0,
|
|
101
|
+
mute: this._isBackground || !this.musicEnabled,
|
|
102
|
+
});
|
|
103
|
+
this._musicPlayer.play();
|
|
104
|
+
this._isMusicPaused = false;
|
|
105
|
+
gsap.killTweensOf(this._musicPlayer);
|
|
106
|
+
gsap.to(this._musicPlayer, {
|
|
107
|
+
volume: 1,
|
|
108
|
+
duration: 1,
|
|
109
|
+
ease: "linear",
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/** @description 暂停音乐 */
|
|
114
|
+
pauseMusic() {
|
|
115
|
+
var _a;
|
|
116
|
+
this._isMusicPaused = true;
|
|
117
|
+
(_a = this._musicPlayer) === null || _a === void 0 ? void 0 : _a.pause();
|
|
118
|
+
}
|
|
119
|
+
/** @description 继续播放音乐 */
|
|
120
|
+
resumeMusic() {
|
|
121
|
+
var _a, _b;
|
|
122
|
+
this._isMusicPaused = false;
|
|
123
|
+
if ((_a = this._musicPlayer) === null || _a === void 0 ? void 0 : _a.playing())
|
|
124
|
+
return;
|
|
125
|
+
(_b = this._musicPlayer) === null || _b === void 0 ? void 0 : _b.play();
|
|
126
|
+
}
|
|
127
|
+
/** @description 停止播放指定音效
|
|
128
|
+
* @param key 音效资源Key,内部会使用Assets.get(key)获取音频资源进行停止
|
|
129
|
+
*/
|
|
130
|
+
stopEffect(key) {
|
|
131
|
+
const url = Assets.get(key).url;
|
|
132
|
+
this._playingList.forEach((item) => {
|
|
133
|
+
if (item.url === url) {
|
|
134
|
+
item.audio.stop();
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
this._playingList = this._playingList.filter((item) => item.url !== url);
|
|
138
|
+
}
|
|
139
|
+
/** @description 设置启用音效
|
|
140
|
+
* @param enabled 启用状态,false为禁用
|
|
141
|
+
*/
|
|
142
|
+
setEffectEnabled(enabled) {
|
|
143
|
+
this.effectEnabled = enabled;
|
|
144
|
+
this._setEffectMute(!enabled);
|
|
145
|
+
}
|
|
146
|
+
/** @description 设置启用音乐
|
|
147
|
+
* @param enabled 启用状态,false为禁用
|
|
148
|
+
*/
|
|
149
|
+
setMusicEnabled(enabled) {
|
|
150
|
+
this.musicEnabled = enabled;
|
|
151
|
+
this._setMusicMute(!enabled);
|
|
152
|
+
}
|
|
153
|
+
/** @description 设置静音音乐
|
|
154
|
+
* @param disabled 静音状态,true为静音
|
|
155
|
+
*/
|
|
156
|
+
_setMusicMute(disabled) {
|
|
157
|
+
var _a;
|
|
158
|
+
(_a = this._musicPlayer) === null || _a === void 0 ? void 0 : _a.mute(disabled || !this.musicEnabled);
|
|
159
|
+
}
|
|
160
|
+
/** @description 设置静音音效
|
|
161
|
+
* @param disabled 静音状态,true为静音
|
|
162
|
+
*/
|
|
163
|
+
_setEffectMute(disabled) {
|
|
164
|
+
this._playingList.forEach((item) => {
|
|
165
|
+
item.audio.mute(disabled || !this.effectEnabled);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { NineSlicePlane, type Texture } from "pixi.js";
|
|
2
|
+
export interface LibPixiCreateNineGridParams {
|
|
3
|
+
/** 九宫格图片 */
|
|
4
|
+
texture: Texture;
|
|
5
|
+
/** 四个角的宽度 */
|
|
6
|
+
dotWidth: number | [number, number, number, number];
|
|
7
|
+
/** 宽度 */
|
|
8
|
+
width: number;
|
|
9
|
+
/** 高度 */
|
|
10
|
+
height: number;
|
|
11
|
+
}
|
|
12
|
+
/** @description 九宫格图
|
|
13
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiCreateNineGrid-九宫格图
|
|
14
|
+
*/
|
|
15
|
+
export declare const libPixiCreateNineGrid: (params: LibPixiCreateNineGridParams) => NineSlicePlane;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { NineSlicePlane } from "pixi.js";
|
|
2
|
+
/** @description 九宫格图
|
|
3
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiCreateNineGrid-九宫格图
|
|
4
|
+
*/
|
|
5
|
+
export const libPixiCreateNineGrid = (params) => {
|
|
6
|
+
const { texture, dotWidth, width, height } = params;
|
|
7
|
+
let slice_width = [];
|
|
8
|
+
// 四个角的宽度
|
|
9
|
+
if (Array.isArray(dotWidth)) {
|
|
10
|
+
slice_width = dotWidth;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
slice_width = [dotWidth, dotWidth, dotWidth, dotWidth];
|
|
14
|
+
}
|
|
15
|
+
const nineSlicePlane = new NineSlicePlane(texture, slice_width[0], slice_width[1], slice_width[2], slice_width[3]);
|
|
16
|
+
nineSlicePlane.width = width;
|
|
17
|
+
nineSlicePlane.height = height;
|
|
18
|
+
return nineSlicePlane;
|
|
19
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Container } from "pixi.js";
|
|
2
|
+
import type { LibPixiBaseContainer } from "./ui/LibPixiBaseContainer";
|
|
3
|
+
export { LibPixiBaseContainer } from "./ui/LibPixiBaseContainer";
|
|
4
|
+
export { LibPixiDialog } from "./ui/LibPixiDialog";
|
|
5
|
+
interface IViewCtor {
|
|
6
|
+
new (...args: any[]): LibPixiBaseContainer;
|
|
7
|
+
}
|
|
8
|
+
/** @description 弹窗管理器 */
|
|
9
|
+
export declare class LibPixiDialogManager {
|
|
10
|
+
/** 视图表 */
|
|
11
|
+
private views;
|
|
12
|
+
/** open时显示的元素的父容器 */
|
|
13
|
+
private _openContainer;
|
|
14
|
+
constructor(parent: Container);
|
|
15
|
+
/**
|
|
16
|
+
* 打开界面
|
|
17
|
+
* @param View 实例类型或构造方法
|
|
18
|
+
* @param args 实例参数
|
|
19
|
+
*/
|
|
20
|
+
open<T extends IViewCtor>(View: T, id: string, ...args: ConstructorParameters<T>): InstanceType<T>;
|
|
21
|
+
/** @description 关闭页面,会调用页面的 onBeforeUnmount 事件,里面会做关闭动画,动画结束后会自动销毁
|
|
22
|
+
* @param id 页面名称
|
|
23
|
+
*/
|
|
24
|
+
close(id: string): Promise<void>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export { LibPixiBaseContainer } from "./ui/LibPixiBaseContainer";
|
|
11
|
+
export { LibPixiDialog } from "./ui/LibPixiDialog";
|
|
12
|
+
/** @description 弹窗管理器 */
|
|
13
|
+
export class LibPixiDialogManager {
|
|
14
|
+
constructor(parent) {
|
|
15
|
+
/** 视图表 */
|
|
16
|
+
this.views = {};
|
|
17
|
+
this._openContainer = parent;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 打开界面
|
|
21
|
+
* @param View 实例类型或构造方法
|
|
22
|
+
* @param args 实例参数
|
|
23
|
+
*/
|
|
24
|
+
open(View, id, ...args) {
|
|
25
|
+
const view = new View(...args);
|
|
26
|
+
this._openContainer.addChild(view);
|
|
27
|
+
this.views[id] = view;
|
|
28
|
+
return view;
|
|
29
|
+
}
|
|
30
|
+
/** @description 关闭页面,会调用页面的 onBeforeUnmount 事件,里面会做关闭动画,动画结束后会自动销毁
|
|
31
|
+
* @param id 页面名称
|
|
32
|
+
*/
|
|
33
|
+
close(id) {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
var _a;
|
|
36
|
+
const view = this.views[id];
|
|
37
|
+
if (view) {
|
|
38
|
+
yield ((_a = view.destroy) === null || _a === void 0 ? void 0 : _a.call(view));
|
|
39
|
+
delete this.views[id];
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Container } from "pixi.js";
|
|
2
|
+
/** @description */
|
|
3
|
+
export declare class LibPixiBaseContainer extends Container {
|
|
4
|
+
/** 销毁之前 */
|
|
5
|
+
protected _onBeforeDestroy?: () => void | Promise<void>;
|
|
6
|
+
/** 已销毁 */
|
|
7
|
+
protected _onDestroyed?: () => void;
|
|
8
|
+
constructor();
|
|
9
|
+
/** @description 销毁 */
|
|
10
|
+
destroy(): Promise<void>;
|
|
11
|
+
}
|