lyb-pixi-js 1.1.11 → 1.1.13
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/LibPixiBitText.d.ts +20 -0
- package/Components/Base/LibPixiBitText.js +26 -0
- package/Components/Base/LibPixiContainer.d.ts +22 -0
- package/Components/Base/LibPixiContainer.js +51 -0
- package/Components/Base/LibPixiParticleMove.d.ts +39 -0
- package/Components/Base/LibPixiParticleMove.js +100 -0
- package/Components/Base/LibPixiRectBgColor.d.ts +45 -0
- package/Components/Base/LibPixiRectBgColor.js +98 -0
- package/Components/Base/LibPixiSpine.d.ts +57 -0
- package/Components/Base/LibPixiSpine.js +122 -0
- package/Components/Base/LibPixiText.d.ts +37 -0
- package/Components/Base/LibPixiText.js +32 -0
- package/Components/Custom/LibPixiButtonHover.d.ts +32 -0
- package/Components/Custom/LibPixiButtonHover.js +44 -0
- package/Components/Custom/LibPixiCloseBtn.d.ts +14 -0
- package/Components/Custom/LibPixiCloseBtn.js +35 -0
- package/Components/Custom/LibPixiDrawer.d.ts +16 -0
- package/Components/Custom/LibPixiDrawer.js +59 -0
- package/Components/Custom/LibPixiPerforMon.d.ts +31 -0
- package/Components/Custom/LibPixiPerforMon.js +107 -0
- package/Components/Custom/LibPixiProgress.d.ts +29 -0
- package/Components/Custom/LibPixiProgress.js +36 -0
- package/Components/Custom/LibPixiScrollContainer.d.ts +57 -0
- package/Components/Custom/LibPixiScrollContainer.js +166 -0
- package/Components/Custom/LibPixiScrollNum.d.ts +62 -0
- package/Components/Custom/LibPixiScrollNum.js +146 -0
- package/Components/Custom/LibPixiSlider.d.ts +45 -0
- package/Components/Custom/LibPixiSlider.js +111 -0
- package/Components/Custom/LibPixiSubAddMinMax.d.ts +49 -0
- package/Components/Custom/LibPixiSubAddMinMax.js +76 -0
- package/Components/Custom/LibPixiTable.d.ts +52 -0
- package/Components/Custom/LibPixiTable.js +70 -0
- package/Utils/LibPixiAudio.d.ts +55 -0
- package/Utils/LibPixiAudio.js +172 -0
- package/Utils/LibPixiCreateNineGrid.d.ts +15 -0
- package/Utils/LibPixiCreateNineGrid.js +19 -0
- package/Utils/LibPixiEvent.d.ts +9 -0
- package/Utils/LibPixiEvent.js +22 -0
- package/Utils/LibPixiEventControlled.d.ts +8 -0
- package/Utils/LibPixiEventControlled.js +21 -0
- package/Utils/LibPixiFilter.d.ts +9 -0
- package/Utils/LibPixiFilter.js +30 -0
- package/Utils/LibPixiIntervalTrigger.d.ts +6 -0
- package/Utils/LibPixiIntervalTrigger.js +33 -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/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/LibPixiTickerTimeout.d.ts +6 -0
- package/Utils/LibPixiTickerTimeout.js +28 -0
- package/index.d.ts +1 -0
- package/index.js +2 -0
- package/libPixiJs.d.ts +163 -0
- package/libPixiJs.js +174 -0
- package/lyb-pixi.js +1263 -0
- package/package.json +1 -1
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { Graphics } from "pixi.js";
|
|
2
|
+
import gsap from "gsap";
|
|
3
|
+
import { LibPixiContainer } from '../Base/LibPixiContainer';
|
|
4
|
+
/** @description 通过鼠标或手指拖动数字列选择数字
|
|
5
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiScrollNum-数字滑动
|
|
6
|
+
*/
|
|
7
|
+
export class LibPixiScrollNum extends LibPixiContainer {
|
|
8
|
+
constructor(params) {
|
|
9
|
+
const { width, height, content, slideCallback, scrollCallback, pageNum, pageHeight, } = params;
|
|
10
|
+
super(width, height);
|
|
11
|
+
/** 当前幻灯片索引 */
|
|
12
|
+
this._currentIndex = 0;
|
|
13
|
+
/** 滚动区域高度 */
|
|
14
|
+
this._scrollHeight = 0;
|
|
15
|
+
/** 滑动区域高度 */
|
|
16
|
+
this._slideHeight = 0;
|
|
17
|
+
/** 记录拖动开始时的Y坐标 */
|
|
18
|
+
this._startY = 0;
|
|
19
|
+
/** 偏移量 */
|
|
20
|
+
this._offsetY = 0;
|
|
21
|
+
/** 最大索引 */
|
|
22
|
+
this._pageNum = 0;
|
|
23
|
+
/** 记录开始时间 */
|
|
24
|
+
this._startTime = new Date().getTime();
|
|
25
|
+
/** 是否正在拖动 */
|
|
26
|
+
this._isDragging = false;
|
|
27
|
+
//设置遮罩
|
|
28
|
+
const mask = new Graphics();
|
|
29
|
+
mask.beginFill(0xffffff);
|
|
30
|
+
mask.drawRect(0, 0, this.width, this.height);
|
|
31
|
+
mask.endFill();
|
|
32
|
+
this.addChild(mask);
|
|
33
|
+
this.mask = mask;
|
|
34
|
+
this._scrollHeight = height;
|
|
35
|
+
this._slideHeight = pageHeight;
|
|
36
|
+
this._slideArea = content;
|
|
37
|
+
this._slideCallback = slideCallback;
|
|
38
|
+
this._scrollCallback = scrollCallback;
|
|
39
|
+
this._pageNum = pageNum - 1;
|
|
40
|
+
this.addChild(this._slideArea);
|
|
41
|
+
this._slideArea.x = width / 2;
|
|
42
|
+
this._slideArea.y = this._scrollHeight / 2;
|
|
43
|
+
// 监听拖动事件
|
|
44
|
+
this.eventMode = "static";
|
|
45
|
+
this.cursor = "pointer";
|
|
46
|
+
this.on("pointerdown", this._onDragStart);
|
|
47
|
+
window.addEventListener("pointermove", this._onDragMove.bind(this));
|
|
48
|
+
window.addEventListener("pointerup", this._onDragEnd.bind(this));
|
|
49
|
+
}
|
|
50
|
+
/** @description 更新坐标
|
|
51
|
+
* @param y Y坐标
|
|
52
|
+
* @param index 页数索引
|
|
53
|
+
*/
|
|
54
|
+
updatePosition(y, index) {
|
|
55
|
+
this._slideArea.y = y;
|
|
56
|
+
this._currentIndex = index;
|
|
57
|
+
}
|
|
58
|
+
/** @description 滑动到指定索引
|
|
59
|
+
* @param index 页数索引
|
|
60
|
+
* @param animate 是否需要过渡动画
|
|
61
|
+
*/
|
|
62
|
+
slideTo(index, animate = true) {
|
|
63
|
+
var _a;
|
|
64
|
+
if (index < 0) {
|
|
65
|
+
// 回弹到第一张
|
|
66
|
+
gsap.to(this._slideArea, {
|
|
67
|
+
y: this._scrollHeight / 2,
|
|
68
|
+
duration: 0.25,
|
|
69
|
+
onUpdate: () => {
|
|
70
|
+
var _a;
|
|
71
|
+
(_a = this._scrollCallback) === null || _a === void 0 ? void 0 : _a.call(this, this._slideArea.y, this._currentIndex);
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
this._currentIndex = 0;
|
|
75
|
+
}
|
|
76
|
+
else if (index > this._pageNum) {
|
|
77
|
+
// 回弹到最后一张
|
|
78
|
+
gsap.to(this._slideArea, {
|
|
79
|
+
y: -this._pageNum * this._slideHeight + this._scrollHeight / 2,
|
|
80
|
+
duration: 0.5,
|
|
81
|
+
onUpdate: () => {
|
|
82
|
+
var _a;
|
|
83
|
+
(_a = this._scrollCallback) === null || _a === void 0 ? void 0 : _a.call(this, this._slideArea.y, this._currentIndex);
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
this._currentIndex = this._pageNum;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
// 正常滑动
|
|
90
|
+
this._currentIndex = index;
|
|
91
|
+
gsap.to(this._slideArea, {
|
|
92
|
+
y: -this._currentIndex * this._slideHeight + this._scrollHeight / 2,
|
|
93
|
+
duration: animate ? 0.25 : 0.01,
|
|
94
|
+
onUpdate: () => {
|
|
95
|
+
var _a;
|
|
96
|
+
(_a = this._scrollCallback) === null || _a === void 0 ? void 0 : _a.call(this, this._slideArea.y, this._currentIndex);
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
(_a = this._slideCallback) === null || _a === void 0 ? void 0 : _a.call(this, this._currentIndex);
|
|
101
|
+
}
|
|
102
|
+
/** @description 开始拖动 */
|
|
103
|
+
_onDragStart(event) {
|
|
104
|
+
this._isDragging = true;
|
|
105
|
+
this._startY = event.data.global.y;
|
|
106
|
+
this._offsetY = this._slideArea.y;
|
|
107
|
+
gsap.killTweensOf(this._slideArea);
|
|
108
|
+
this._startTime = new Date().getTime();
|
|
109
|
+
}
|
|
110
|
+
/** @description 拖动中 */
|
|
111
|
+
_onDragMove(event) {
|
|
112
|
+
var _a;
|
|
113
|
+
if (!this._isDragging)
|
|
114
|
+
return;
|
|
115
|
+
const moveY = event.pageY - this._startY;
|
|
116
|
+
this._slideArea.y = this._offsetY + moveY;
|
|
117
|
+
(_a = this._scrollCallback) === null || _a === void 0 ? void 0 : _a.call(this, this._slideArea.y, this._currentIndex);
|
|
118
|
+
}
|
|
119
|
+
/** @description 结束拖动 */
|
|
120
|
+
_onDragEnd(event) {
|
|
121
|
+
if (!this._isDragging)
|
|
122
|
+
return;
|
|
123
|
+
this._isDragging = false;
|
|
124
|
+
const endTime = new Date().getTime() - this._startTime;
|
|
125
|
+
const slide = this._startY - event.pageY; // 计算滑动的距离
|
|
126
|
+
const slideSpeed = Math.abs(slide) / endTime; // 计算滑动速度
|
|
127
|
+
const speedThreshold = 0.275;
|
|
128
|
+
// 计算滑动的页面变化数,根据滑动距离来调整页码
|
|
129
|
+
const slideThreshold = this._slideHeight / 2;
|
|
130
|
+
// 计算实际的翻页增量,使用 `slide / this._slideHeight` 来计算滑动的页数
|
|
131
|
+
const pageChange = Math.round(slide / this._slideHeight);
|
|
132
|
+
// 如果滑动速度足够快,且滑动的距离大于阈值,强制翻页
|
|
133
|
+
if (Math.abs(slide) > slideThreshold || slideSpeed > speedThreshold) {
|
|
134
|
+
this._currentIndex += pageChange; // 这里会根据滑动的方向来增加或减少当前页码
|
|
135
|
+
}
|
|
136
|
+
// 防止超出页面的上下限
|
|
137
|
+
if (this._currentIndex < 0) {
|
|
138
|
+
this._currentIndex = 0; // 保证当前页码不小于 0
|
|
139
|
+
}
|
|
140
|
+
else if (this._currentIndex > this._pageNum) {
|
|
141
|
+
this._currentIndex = this._pageNum; // 保证当前页码不大于最大页码
|
|
142
|
+
}
|
|
143
|
+
// 执行滑动到目标页码
|
|
144
|
+
this.slideTo(this._currentIndex);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Container } from "pixi.js";
|
|
2
|
+
import { LibPixiContainer } from '../Base/LibPixiContainer';
|
|
3
|
+
/** @description 类似轮播图,但是不会自动轮播
|
|
4
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiSlider-横向滑动图
|
|
5
|
+
*/
|
|
6
|
+
export declare class LibPixiSlider extends LibPixiContainer {
|
|
7
|
+
/** 当前幻灯片索引 */
|
|
8
|
+
private _currentIndex;
|
|
9
|
+
/** 滑动区域宽度 */
|
|
10
|
+
private _slideWidth;
|
|
11
|
+
/** 记录拖动开始时的X坐标 */
|
|
12
|
+
private _startX;
|
|
13
|
+
/** 偏移量 */
|
|
14
|
+
private _offsetX;
|
|
15
|
+
/** 最大索引 */
|
|
16
|
+
private _pageNum;
|
|
17
|
+
/** 记录开始时间 */
|
|
18
|
+
private _startTime;
|
|
19
|
+
private _isDragging;
|
|
20
|
+
/** 滑动内容 */
|
|
21
|
+
private _slideArea;
|
|
22
|
+
/** @description 滑动回调 */
|
|
23
|
+
private slideCallback;
|
|
24
|
+
/**
|
|
25
|
+
* @param width 宽度
|
|
26
|
+
* @param height 高度
|
|
27
|
+
* @param content 内容
|
|
28
|
+
* @param slideCallback 滑动结束回调
|
|
29
|
+
*/
|
|
30
|
+
constructor(width: number, height: number, content: Container, slideCallback: (pageIndex: number, _pageNum: number) => void);
|
|
31
|
+
/** @description 上一页 */
|
|
32
|
+
prev(): void;
|
|
33
|
+
/** @description 下一页 */
|
|
34
|
+
next(): void;
|
|
35
|
+
/** @description 滑动到指定索引
|
|
36
|
+
* @param index 索引
|
|
37
|
+
*/
|
|
38
|
+
private _slideTo;
|
|
39
|
+
/** @description 开始拖动 */
|
|
40
|
+
private _onDragStart;
|
|
41
|
+
/** @description 拖动中 */
|
|
42
|
+
private _onDragMove;
|
|
43
|
+
/** @description 结束拖动 */
|
|
44
|
+
private _onDragEnd;
|
|
45
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import gsap from "gsap";
|
|
2
|
+
import { libPixiOverflowHidden } from "../../Utils/LibPixiOverflowHidden";
|
|
3
|
+
import { LibPixiContainer } from '../Base/LibPixiContainer';
|
|
4
|
+
/** @description 类似轮播图,但是不会自动轮播
|
|
5
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiSlider-横向滑动图
|
|
6
|
+
*/
|
|
7
|
+
export class LibPixiSlider extends LibPixiContainer {
|
|
8
|
+
/**
|
|
9
|
+
* @param width 宽度
|
|
10
|
+
* @param height 高度
|
|
11
|
+
* @param content 内容
|
|
12
|
+
* @param slideCallback 滑动结束回调
|
|
13
|
+
*/
|
|
14
|
+
constructor(width, height, content, slideCallback) {
|
|
15
|
+
super(width, height);
|
|
16
|
+
/** 当前幻灯片索引 */
|
|
17
|
+
this._currentIndex = 0;
|
|
18
|
+
/** 滑动区域宽度 */
|
|
19
|
+
this._slideWidth = 0;
|
|
20
|
+
/** 记录拖动开始时的X坐标 */
|
|
21
|
+
this._startX = 0;
|
|
22
|
+
/** 偏移量 */
|
|
23
|
+
this._offsetX = 0;
|
|
24
|
+
/** 最大索引 */
|
|
25
|
+
this._pageNum = 0;
|
|
26
|
+
/** 记录开始时间 */
|
|
27
|
+
this._startTime = new Date().getTime();
|
|
28
|
+
/* 是否正在拖动 */
|
|
29
|
+
this._isDragging = false;
|
|
30
|
+
libPixiOverflowHidden(this);
|
|
31
|
+
this._slideWidth = width;
|
|
32
|
+
this._slideArea = content;
|
|
33
|
+
this.slideCallback = slideCallback;
|
|
34
|
+
this._pageNum = Math.floor(content.width / this._slideWidth) - 1;
|
|
35
|
+
this.addChild(content);
|
|
36
|
+
// 监听拖动事件
|
|
37
|
+
this.eventMode = "static";
|
|
38
|
+
this.cursor = "pointer";
|
|
39
|
+
this.on("pointerdown", this._onDragStart);
|
|
40
|
+
window.addEventListener("pointermove", this._onDragMove.bind(this));
|
|
41
|
+
window.addEventListener("pointerup", this._onDragEnd.bind(this));
|
|
42
|
+
}
|
|
43
|
+
/** @description 上一页 */
|
|
44
|
+
prev() {
|
|
45
|
+
this._slideTo(this._currentIndex - 1);
|
|
46
|
+
}
|
|
47
|
+
/** @description 下一页 */
|
|
48
|
+
next() {
|
|
49
|
+
this._slideTo(this._currentIndex + 1);
|
|
50
|
+
}
|
|
51
|
+
/** @description 滑动到指定索引
|
|
52
|
+
* @param index 索引
|
|
53
|
+
*/
|
|
54
|
+
_slideTo(index) {
|
|
55
|
+
if (index < 0) {
|
|
56
|
+
// 回弹到第一张
|
|
57
|
+
gsap.to(this._slideArea, { x: 0, duration: 0.25 });
|
|
58
|
+
this._currentIndex = 0;
|
|
59
|
+
}
|
|
60
|
+
else if (index > this._pageNum) {
|
|
61
|
+
// 回弹到最后一张
|
|
62
|
+
gsap.to(this._slideArea, {
|
|
63
|
+
x: -this._pageNum * this._slideWidth,
|
|
64
|
+
duration: 0.5,
|
|
65
|
+
});
|
|
66
|
+
this._currentIndex = this._pageNum;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
// 正常滑动
|
|
70
|
+
this._currentIndex = index;
|
|
71
|
+
gsap.to(this._slideArea, {
|
|
72
|
+
x: -this._currentIndex * this._slideWidth,
|
|
73
|
+
duration: 0.25,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
this.slideCallback(this._currentIndex, this._pageNum);
|
|
77
|
+
}
|
|
78
|
+
/** @description 开始拖动 */
|
|
79
|
+
_onDragStart(event) {
|
|
80
|
+
this._isDragging = true;
|
|
81
|
+
this._startX = event.global.x;
|
|
82
|
+
this._offsetX = this._slideArea.x;
|
|
83
|
+
gsap.killTweensOf(this._slideArea);
|
|
84
|
+
this._startTime = new Date().getTime();
|
|
85
|
+
}
|
|
86
|
+
/** @description 拖动中 */
|
|
87
|
+
_onDragMove(event) {
|
|
88
|
+
if (!this._isDragging)
|
|
89
|
+
return;
|
|
90
|
+
const moveX = event.pageX - this._startX;
|
|
91
|
+
this._slideArea.x = this._offsetX + moveX;
|
|
92
|
+
}
|
|
93
|
+
/** @description 结束拖动 */
|
|
94
|
+
_onDragEnd(event) {
|
|
95
|
+
if (!this._isDragging)
|
|
96
|
+
return;
|
|
97
|
+
this._isDragging = false;
|
|
98
|
+
const endTime = new Date().getTime() - this._startTime;
|
|
99
|
+
const slide = this._startX - event.pageX;
|
|
100
|
+
const slideSpeed = Math.abs(slide) / endTime;
|
|
101
|
+
//滑动距离阈值,滑动到一半以上必定翻页
|
|
102
|
+
const slideThreshold = this._slideWidth / 2;
|
|
103
|
+
//滑动速度阈值,滑动速度大于这个值,必定翻页
|
|
104
|
+
const speedThreshold = 0.275;
|
|
105
|
+
//如果滑动距离大于阈值,或速度大于阈值翻页
|
|
106
|
+
if (Math.abs(slide) > slideThreshold || slideSpeed > speedThreshold) {
|
|
107
|
+
slide > 0 ? this._currentIndex++ : this._currentIndex--;
|
|
108
|
+
}
|
|
109
|
+
this._slideTo(this._currentIndex);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Container } from "pixi.js";
|
|
2
|
+
export interface LibPixiSubAddMinMaxParams {
|
|
3
|
+
/** 最小按钮 */
|
|
4
|
+
minBtn: Container;
|
|
5
|
+
/** 最大按钮 */
|
|
6
|
+
maxBtn: Container;
|
|
7
|
+
/** 增加按钮 */
|
|
8
|
+
subBtn: Container;
|
|
9
|
+
/** 减少按钮 */
|
|
10
|
+
addBtn: Container;
|
|
11
|
+
/** 初始下注索引 */
|
|
12
|
+
initialBetIndex: number;
|
|
13
|
+
/** 下注金额列表 */
|
|
14
|
+
betAmountListLength: number;
|
|
15
|
+
/** 金额更新回调 */
|
|
16
|
+
onAmountIndex: (index: number) => void;
|
|
17
|
+
}
|
|
18
|
+
/** @description 最小、最大按钮和增减按钮功能及置灰逻辑
|
|
19
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiSubAddMinMax-数字控制器
|
|
20
|
+
*/
|
|
21
|
+
export declare class LibPixiSubAddMinMax {
|
|
22
|
+
/** 步进器 */
|
|
23
|
+
private baseNumSteper;
|
|
24
|
+
/** 最大最小按钮 */
|
|
25
|
+
private minBtn;
|
|
26
|
+
private maxBtn;
|
|
27
|
+
/** 增加减少按钮 */
|
|
28
|
+
private subBtn;
|
|
29
|
+
private addBtn;
|
|
30
|
+
/** 金额列表数量 */
|
|
31
|
+
private betAmountListLength;
|
|
32
|
+
/** 金额更新回调 */
|
|
33
|
+
onAmountIndex: (index: number) => void;
|
|
34
|
+
constructor(params: LibPixiSubAddMinMaxParams);
|
|
35
|
+
/** @description 点击最小按钮 */
|
|
36
|
+
min(): void;
|
|
37
|
+
/** @description 点击最大按钮 */
|
|
38
|
+
max(): void;
|
|
39
|
+
/** @description 点击减少按钮 */
|
|
40
|
+
sub(): void;
|
|
41
|
+
/** @description 点击增加按钮 */
|
|
42
|
+
add(): void;
|
|
43
|
+
/** @description 改变最小最大按钮状态及回调
|
|
44
|
+
* @param index 索引
|
|
45
|
+
*/
|
|
46
|
+
minMaxUpdateIndex(index: number): void;
|
|
47
|
+
/** @description 设置最大最小按钮置灰及恢复 */
|
|
48
|
+
private _setGrey;
|
|
49
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { libPixiFilter } from "../../Utils/LibPixiFilter"; //@ts-ignore
|
|
2
|
+
import { LibJsNumberStepper } from 'lyb-js/Misc/LibJsNumberStepper.js';
|
|
3
|
+
/** @description 最小、最大按钮和增减按钮功能及置灰逻辑
|
|
4
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiSubAddMinMax-数字控制器
|
|
5
|
+
*/
|
|
6
|
+
export class LibPixiSubAddMinMax {
|
|
7
|
+
constructor(params) {
|
|
8
|
+
/** 金额列表数量 */
|
|
9
|
+
this.betAmountListLength = 0;
|
|
10
|
+
const { minBtn, maxBtn, addBtn, subBtn, initialBetIndex, betAmountListLength, onAmountIndex, } = params;
|
|
11
|
+
this.minBtn = minBtn;
|
|
12
|
+
this.maxBtn = maxBtn;
|
|
13
|
+
this.subBtn = subBtn;
|
|
14
|
+
this.addBtn = addBtn;
|
|
15
|
+
this.onAmountIndex = onAmountIndex;
|
|
16
|
+
this.betAmountListLength = betAmountListLength;
|
|
17
|
+
//金额增减步进器
|
|
18
|
+
this.baseNumSteper = new LibJsNumberStepper(betAmountListLength, //@ts-ignore
|
|
19
|
+
(index) => {
|
|
20
|
+
this.onAmountIndex(index);
|
|
21
|
+
this.minMaxUpdateIndex(index);
|
|
22
|
+
});
|
|
23
|
+
//设置初始状态
|
|
24
|
+
this.minMaxUpdateIndex(initialBetIndex);
|
|
25
|
+
this.baseNumSteper.updateIndex(initialBetIndex);
|
|
26
|
+
}
|
|
27
|
+
/** @description 点击最小按钮 */
|
|
28
|
+
min() {
|
|
29
|
+
this.minMaxUpdateIndex(0);
|
|
30
|
+
this.onAmountIndex(0);
|
|
31
|
+
}
|
|
32
|
+
/** @description 点击最大按钮 */
|
|
33
|
+
max() {
|
|
34
|
+
const index = this.betAmountListLength - 1;
|
|
35
|
+
this.minMaxUpdateIndex(index);
|
|
36
|
+
this.onAmountIndex(index);
|
|
37
|
+
}
|
|
38
|
+
/** @description 点击减少按钮 */
|
|
39
|
+
sub() {
|
|
40
|
+
this.baseNumSteper.down("sub");
|
|
41
|
+
}
|
|
42
|
+
/** @description 点击增加按钮 */
|
|
43
|
+
add() {
|
|
44
|
+
this.baseNumSteper.down("add");
|
|
45
|
+
}
|
|
46
|
+
/** @description 改变最小最大按钮状态及回调
|
|
47
|
+
* @param index 索引
|
|
48
|
+
*/
|
|
49
|
+
minMaxUpdateIndex(index) {
|
|
50
|
+
if (index === 0) {
|
|
51
|
+
this._setGrey("min");
|
|
52
|
+
}
|
|
53
|
+
else if (index === this.betAmountListLength - 1) {
|
|
54
|
+
this._setGrey("max");
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
this._setGrey();
|
|
58
|
+
}
|
|
59
|
+
this.baseNumSteper.updateIndex(index);
|
|
60
|
+
}
|
|
61
|
+
/** @description 设置最大最小按钮置灰及恢复 */
|
|
62
|
+
_setGrey(type) {
|
|
63
|
+
this.minBtn.filters = [];
|
|
64
|
+
this.maxBtn.filters = [];
|
|
65
|
+
this.subBtn.filters = [];
|
|
66
|
+
this.addBtn.filters = [];
|
|
67
|
+
if (type === "min") {
|
|
68
|
+
this.minBtn.filters = [libPixiFilter("desaturate")];
|
|
69
|
+
this.subBtn.filters = [libPixiFilter("desaturate")];
|
|
70
|
+
}
|
|
71
|
+
else if (type === "max") {
|
|
72
|
+
this.maxBtn.filters = [libPixiFilter("desaturate")];
|
|
73
|
+
this.addBtn.filters = [libPixiFilter("desaturate")];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** @description 表格绘制并填入数字 */
|
|
2
|
+
import { Container } from "pixi.js";
|
|
3
|
+
export interface LibPixiTableParams {
|
|
4
|
+
/** 表格数据 */
|
|
5
|
+
data: (number | string)[][];
|
|
6
|
+
/** 单元格宽度 */
|
|
7
|
+
cellWidth?: number;
|
|
8
|
+
/** 单元格高度 */
|
|
9
|
+
cellHeight?: number;
|
|
10
|
+
/** 字体大小 */
|
|
11
|
+
fontSize?: number;
|
|
12
|
+
/** 字体颜色 */
|
|
13
|
+
fontColor?: string;
|
|
14
|
+
/** 线条厚度 */
|
|
15
|
+
lineWidth?: number;
|
|
16
|
+
/** 线条颜色 */
|
|
17
|
+
lineColor?: string;
|
|
18
|
+
}
|
|
19
|
+
/** @description 绘制表格并填充数字
|
|
20
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiTable-数字表格
|
|
21
|
+
*/
|
|
22
|
+
export declare class LibPixiTable extends Container {
|
|
23
|
+
/** 行数 */
|
|
24
|
+
private _rows;
|
|
25
|
+
/** 列数 */
|
|
26
|
+
private _cols;
|
|
27
|
+
/** 单元格宽度 */
|
|
28
|
+
private _cellWidth;
|
|
29
|
+
/** 单元格高度 */
|
|
30
|
+
private _cellHeight;
|
|
31
|
+
/** 字体大小 */
|
|
32
|
+
private _fontSize;
|
|
33
|
+
/** 线条宽度 */
|
|
34
|
+
private _lineWidth;
|
|
35
|
+
/** 字体颜色 */
|
|
36
|
+
private _fontColor;
|
|
37
|
+
/** 线条颜色 */
|
|
38
|
+
private _lineColor;
|
|
39
|
+
/** 二维数字数组 */
|
|
40
|
+
private _data;
|
|
41
|
+
constructor(params: LibPixiTableParams);
|
|
42
|
+
/** @description 绘制表格 */
|
|
43
|
+
private _drawTable;
|
|
44
|
+
/** @description 填充数字 */
|
|
45
|
+
private fillNumbers;
|
|
46
|
+
/** @description 创建数字文本
|
|
47
|
+
* @param number 数字
|
|
48
|
+
* @param col 列索引
|
|
49
|
+
* @param row 行索引
|
|
50
|
+
*/
|
|
51
|
+
private _createNumberText;
|
|
52
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/** @description 表格绘制并填入数字 */
|
|
2
|
+
import { Text, Container, Graphics } 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 = "#B4B4B8", fontSize = 24, lineWidth = 3, lineColor = "#B4B4B8", } = 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._drawTable();
|
|
21
|
+
this.fillNumbers();
|
|
22
|
+
}
|
|
23
|
+
/** @description 绘制表格 */
|
|
24
|
+
_drawTable() {
|
|
25
|
+
const tableWidth = this._cellWidth * this._cols;
|
|
26
|
+
const tableHeight = this._cellHeight * this._rows;
|
|
27
|
+
const graphics = new Graphics();
|
|
28
|
+
graphics.lineStyle(this._lineWidth, this._lineColor);
|
|
29
|
+
// 绘制表格外框
|
|
30
|
+
graphics.drawRect(0, 0, tableWidth, tableHeight);
|
|
31
|
+
// 绘制横线
|
|
32
|
+
for (let i = 1; i < this._rows; i++) {
|
|
33
|
+
graphics.moveTo(0, i * this._cellHeight);
|
|
34
|
+
graphics.lineTo(tableWidth, i * this._cellHeight);
|
|
35
|
+
}
|
|
36
|
+
// 绘制竖线
|
|
37
|
+
for (let j = 1; j < this._cols; j++) {
|
|
38
|
+
graphics.moveTo(j * this._cellWidth, 0);
|
|
39
|
+
graphics.lineTo(j * this._cellWidth, tableHeight);
|
|
40
|
+
}
|
|
41
|
+
this.addChild(graphics);
|
|
42
|
+
}
|
|
43
|
+
/** @description 填充数字 */
|
|
44
|
+
fillNumbers() {
|
|
45
|
+
for (let row = 0; row < this._rows; row++) {
|
|
46
|
+
for (let col = 0; col < this._cols; col++) {
|
|
47
|
+
const number = this._data[row][col];
|
|
48
|
+
this._createNumberText(number, col, row);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/** @description 创建数字文本
|
|
53
|
+
* @param number 数字
|
|
54
|
+
* @param col 列索引
|
|
55
|
+
* @param row 行索引
|
|
56
|
+
*/
|
|
57
|
+
_createNumberText(number, col, row) {
|
|
58
|
+
const text = new Text(number.toString(), {
|
|
59
|
+
_fontSize: this._fontSize,
|
|
60
|
+
fill: this._fontColor,
|
|
61
|
+
});
|
|
62
|
+
// 计算文本的居中位置
|
|
63
|
+
const x = col * this._cellWidth + this._cellWidth / 2;
|
|
64
|
+
const y = row * this._cellHeight + this._cellHeight / 2;
|
|
65
|
+
this.addChild(text);
|
|
66
|
+
text.anchor.set(0.5);
|
|
67
|
+
text.position.set(x, y);
|
|
68
|
+
libPixiScaleContainer(text, this._cellWidth * 0.9);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** @description 音频播放器
|
|
2
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiAudio-音频播放器
|
|
3
|
+
*/
|
|
4
|
+
export declare class LibPixiAudio {
|
|
5
|
+
/** 是否启用音效 */
|
|
6
|
+
effectEnabled: boolean;
|
|
7
|
+
/** 是否启用音乐 */
|
|
8
|
+
musicEnabled: boolean;
|
|
9
|
+
/** 音乐是否处于暂停状态 */
|
|
10
|
+
private _isMusicPaused;
|
|
11
|
+
/** 是否已切换后台 */
|
|
12
|
+
private _isBackground;
|
|
13
|
+
/** 当前音乐播放器 */
|
|
14
|
+
private _musicPlayer;
|
|
15
|
+
/** 当前正在播放的音效列表 */
|
|
16
|
+
private _playingList;
|
|
17
|
+
constructor();
|
|
18
|
+
/** @description 播放音效
|
|
19
|
+
* @param key 音效资源Key,内部会使用Assets.get(key)获取音频资源
|
|
20
|
+
* @param end 倒数几秒位置播放,单位秒
|
|
21
|
+
*/
|
|
22
|
+
playEffect(key: string, end?: number): Promise<void>;
|
|
23
|
+
/** @description 播放音乐
|
|
24
|
+
* @param key 音效资源Key,内部会使用Assets.get(key)获取音频资源
|
|
25
|
+
*/
|
|
26
|
+
playMusic(key: string): Promise<void>;
|
|
27
|
+
/** @description 暂停音乐 */
|
|
28
|
+
pauseMusic(): void;
|
|
29
|
+
/** @description 继续播放音乐 */
|
|
30
|
+
resumeMusic(): void;
|
|
31
|
+
/** @description 停止播放指定音效
|
|
32
|
+
* @param key 音效资源Key,内部会使用Assets.get(key)获取音频资源进行停止
|
|
33
|
+
*/
|
|
34
|
+
stopEffect(link: string): void;
|
|
35
|
+
/** @description 设置启用音效
|
|
36
|
+
* @param enabled 启用状态,false为禁用
|
|
37
|
+
*/
|
|
38
|
+
setEffectEnabled(enabled: boolean): void;
|
|
39
|
+
/** @description 设置启用音乐
|
|
40
|
+
* @param enabled 启用状态,false为禁用
|
|
41
|
+
*/
|
|
42
|
+
setMusicEnabled(enabled: boolean): void;
|
|
43
|
+
/** @description 设置音效和音乐播放状态
|
|
44
|
+
* @param status 播放状态,false为暂停
|
|
45
|
+
*/
|
|
46
|
+
private _setPlayStatus;
|
|
47
|
+
/** @description 设置静音音乐
|
|
48
|
+
* @param disabled 静音状态,true为静音
|
|
49
|
+
*/
|
|
50
|
+
private _setMusicMute;
|
|
51
|
+
/** @description 设置静音音效
|
|
52
|
+
* @param disabled 静音状态,true为静音
|
|
53
|
+
*/
|
|
54
|
+
private _setEffectMute;
|
|
55
|
+
}
|