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,44 @@
|
|
|
1
|
+
import { Container, Sprite } from "pixi.js";
|
|
2
|
+
import { libPixiEvent } from "../../Utils/LibPixiEvent";
|
|
3
|
+
/** @description 悬浮切换材质
|
|
4
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiButtonHover-按钮悬浮
|
|
5
|
+
*/
|
|
6
|
+
export class LibPixiButtonHover extends Container {
|
|
7
|
+
constructor(params) {
|
|
8
|
+
super();
|
|
9
|
+
const { texture, hoverTexture, tintColor } = params;
|
|
10
|
+
this._texture = texture;
|
|
11
|
+
this._hoverTexture = hoverTexture;
|
|
12
|
+
this._tintColor = tintColor;
|
|
13
|
+
//创建图标容器
|
|
14
|
+
const iconBox = new Container();
|
|
15
|
+
this.addChild(iconBox);
|
|
16
|
+
//创建图标
|
|
17
|
+
this._btn = new Sprite(texture);
|
|
18
|
+
iconBox.addChild(this._btn);
|
|
19
|
+
tintColor && (this._btn.tint = tintColor);
|
|
20
|
+
libPixiEvent(iconBox, "pointerenter", () => {
|
|
21
|
+
this._btn._texture = this._hoverTexture;
|
|
22
|
+
this._btn.tint = "#fff";
|
|
23
|
+
});
|
|
24
|
+
libPixiEvent(iconBox, "pointerleave", () => {
|
|
25
|
+
this._btn._texture = this._texture;
|
|
26
|
+
tintColor && (this._btn.tint = tintColor);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/** @description 切换材质
|
|
30
|
+
* @param texture 默认材质
|
|
31
|
+
* @param hoverTexture 悬浮材质
|
|
32
|
+
*/
|
|
33
|
+
toggleTexture(texture, hoverTexture) {
|
|
34
|
+
this._texture = texture;
|
|
35
|
+
this._hoverTexture = hoverTexture;
|
|
36
|
+
this._btn._texture = hoverTexture;
|
|
37
|
+
}
|
|
38
|
+
/** @description 屏蔽
|
|
39
|
+
* @param status 状态
|
|
40
|
+
*/
|
|
41
|
+
setDisabled(status) {
|
|
42
|
+
this._btn.tint = status ? "#7C7C7C" : this._tintColor || "#fff";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { LibPixiContainer } from "../Base/LibPixiContainer";
|
|
2
|
+
import type { Sprite } from "pixi.js";
|
|
3
|
+
export interface LibPixiCloseBtnParams {
|
|
4
|
+
/** 按钮素材 */
|
|
5
|
+
sprite: Sprite;
|
|
6
|
+
/** 点击回调 */
|
|
7
|
+
onClick: () => void;
|
|
8
|
+
}
|
|
9
|
+
/** @description 右上角关闭按钮,支持悬浮旋转动画
|
|
10
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiCloseBtn-关闭按钮
|
|
11
|
+
*/
|
|
12
|
+
export declare class LibPixiCloseBtn extends LibPixiContainer {
|
|
13
|
+
constructor(params: LibPixiCloseBtnParams);
|
|
14
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import gsap from "gsap";
|
|
2
|
+
import { LibPixiContainer } from "../Base/LibPixiContainer";
|
|
3
|
+
import { libPixiEvent } from "../../Utils/LibPixiEvent";
|
|
4
|
+
/** @description 右上角关闭按钮,支持悬浮旋转动画
|
|
5
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiCloseBtn-关闭按钮
|
|
6
|
+
*/
|
|
7
|
+
export class LibPixiCloseBtn extends LibPixiContainer {
|
|
8
|
+
constructor(params) {
|
|
9
|
+
const { sprite, onClick } = params;
|
|
10
|
+
super(sprite.width, sprite.height);
|
|
11
|
+
this.addChild(sprite);
|
|
12
|
+
sprite.anchor.set(0.5);
|
|
13
|
+
sprite.x = sprite.width / 2;
|
|
14
|
+
sprite.y = sprite.height / 2;
|
|
15
|
+
libPixiEvent(this, "pointerenter", () => {
|
|
16
|
+
gsap.to(sprite, {
|
|
17
|
+
duration: 0.25,
|
|
18
|
+
rotation: 180 * (Math.PI / 180),
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
libPixiEvent(this, "pointerleave", () => {
|
|
22
|
+
sprite.alpha = 1;
|
|
23
|
+
gsap.to(sprite, {
|
|
24
|
+
duration: 0.25,
|
|
25
|
+
rotation: 0,
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
libPixiEvent(this, "pointerdown", () => {
|
|
29
|
+
sprite.alpha = 0.5;
|
|
30
|
+
});
|
|
31
|
+
libPixiEvent(this, "pointerup", () => {
|
|
32
|
+
onClick();
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Container } from "pixi.js";
|
|
2
|
+
/** @description 底部弹出抽屉
|
|
3
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiDrawer-抽屉
|
|
4
|
+
*/
|
|
5
|
+
export declare class LibPixiDrawer extends Container {
|
|
6
|
+
/** 蒙版UI */
|
|
7
|
+
private _maskUI;
|
|
8
|
+
/** 抽屉容器 */
|
|
9
|
+
private _drawerContainer;
|
|
10
|
+
/**
|
|
11
|
+
* @param content 抽屉内容
|
|
12
|
+
*/
|
|
13
|
+
constructor(content: Container);
|
|
14
|
+
/** @description 关闭 */
|
|
15
|
+
close(): Promise<void>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
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 { Container } from "pixi.js";
|
|
11
|
+
import gsap from "gsap";
|
|
12
|
+
import { LibPixiRectBgColor } from '../Base/LibPixiRectBgColor';
|
|
13
|
+
/** @description 底部弹出抽屉
|
|
14
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiDrawer-抽屉
|
|
15
|
+
*/
|
|
16
|
+
export class LibPixiDrawer extends Container {
|
|
17
|
+
/**
|
|
18
|
+
* @param content 抽屉内容
|
|
19
|
+
*/
|
|
20
|
+
constructor(content) {
|
|
21
|
+
super();
|
|
22
|
+
//蒙版
|
|
23
|
+
this._maskUI = new LibPixiRectBgColor({
|
|
24
|
+
bgColor: "#000",
|
|
25
|
+
width: 1080,
|
|
26
|
+
height: 1920,
|
|
27
|
+
});
|
|
28
|
+
this.addChild(this._maskUI);
|
|
29
|
+
this._maskUI.alpha = 0;
|
|
30
|
+
this._maskUI.eventMode = "static";
|
|
31
|
+
//弹窗内容容器
|
|
32
|
+
this._drawerContainer = content;
|
|
33
|
+
this.addChild(this._drawerContainer);
|
|
34
|
+
this._drawerContainer.y = this._maskUI.height;
|
|
35
|
+
gsap.to(this._maskUI, {
|
|
36
|
+
duration: 0.25,
|
|
37
|
+
alpha: 0.5,
|
|
38
|
+
});
|
|
39
|
+
gsap.to(this._drawerContainer, {
|
|
40
|
+
duration: 0.25,
|
|
41
|
+
ease: "power1.out",
|
|
42
|
+
y: this._maskUI.height - this._drawerContainer.height,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/** @description 关闭 */
|
|
46
|
+
close() {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
gsap.to(this._drawerContainer, {
|
|
49
|
+
duration: 0.25,
|
|
50
|
+
y: this._maskUI.height,
|
|
51
|
+
});
|
|
52
|
+
yield gsap.to(this._maskUI, {
|
|
53
|
+
duration: 0.25,
|
|
54
|
+
delay: 0.125,
|
|
55
|
+
alpha: 0,
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Application, Container } from "pixi.js";
|
|
2
|
+
/** @description 监视帧率、Draw Call、Max Draw Call
|
|
3
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiPerforMon-性能监视器
|
|
4
|
+
*/
|
|
5
|
+
export declare class LibPixiPerforMon extends Container {
|
|
6
|
+
/** 数据收集时间间隔 (5秒) */
|
|
7
|
+
private readonly COLLECT_TIME;
|
|
8
|
+
/** 当前时间 */
|
|
9
|
+
private _nowTime;
|
|
10
|
+
/** 上次更新的时间 */
|
|
11
|
+
private _lastTime;
|
|
12
|
+
/** 当前绘制调用次数 */
|
|
13
|
+
private _drawCount;
|
|
14
|
+
/** 最大绘制调用次数 */
|
|
15
|
+
private _maxDrawCount;
|
|
16
|
+
/** 临时最大绘制调用次数 */
|
|
17
|
+
private _tempMaxDrawCount;
|
|
18
|
+
/** 上次收集数据的时间 */
|
|
19
|
+
private _lastCollectTime;
|
|
20
|
+
/** 渲染器 */
|
|
21
|
+
private _renderer;
|
|
22
|
+
/** 存储每个性能指标的文本对象 */
|
|
23
|
+
private _paramTxts;
|
|
24
|
+
/** 原始的 drawElements 方法 */
|
|
25
|
+
private _drawElements;
|
|
26
|
+
constructor(app: Application);
|
|
27
|
+
/** @description 初始化显示性能数据 */
|
|
28
|
+
init(): void;
|
|
29
|
+
/** @description 更新文本信息 */
|
|
30
|
+
private _setTxtInfo;
|
|
31
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { Container, UPDATE_PRIORITY, Ticker, } from "pixi.js";
|
|
2
|
+
import { LibPixiText } from '../Base/LibPixiText';
|
|
3
|
+
/** @description 监视帧率、Draw Call、Max Draw Call
|
|
4
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiPerforMon-性能监视器
|
|
5
|
+
*/
|
|
6
|
+
export class LibPixiPerforMon extends Container {
|
|
7
|
+
constructor(app) {
|
|
8
|
+
super();
|
|
9
|
+
/** 数据收集时间间隔 (5秒) */
|
|
10
|
+
this.COLLECT_TIME = 5 * 1000;
|
|
11
|
+
/** 当前时间 */
|
|
12
|
+
this._nowTime = 0;
|
|
13
|
+
/** 上次更新的时间 */
|
|
14
|
+
this._lastTime = 0;
|
|
15
|
+
/** 当前绘制调用次数 */
|
|
16
|
+
this._drawCount = 0;
|
|
17
|
+
/** 最大绘制调用次数 */
|
|
18
|
+
this._maxDrawCount = 0;
|
|
19
|
+
/** 临时最大绘制调用次数 */
|
|
20
|
+
this._tempMaxDrawCount = 0;
|
|
21
|
+
/** 上次收集数据的时间 */
|
|
22
|
+
this._lastCollectTime = 0;
|
|
23
|
+
/** 存储每个性能指标的文本对象 */
|
|
24
|
+
this._paramTxts = [];
|
|
25
|
+
for (let i = 0; i < 3; i++) {
|
|
26
|
+
const txt = new LibPixiText({
|
|
27
|
+
text: "",
|
|
28
|
+
fontWeight: "bold",
|
|
29
|
+
fontSize: 36,
|
|
30
|
+
shadow: ["#000", 45, 3, 5],
|
|
31
|
+
fontColor: "#fff",
|
|
32
|
+
});
|
|
33
|
+
this._paramTxts[i] = txt;
|
|
34
|
+
txt.x = 0;
|
|
35
|
+
txt.y = txt.height * i;
|
|
36
|
+
this.addChild(txt);
|
|
37
|
+
txt.alpha = 0.75;
|
|
38
|
+
}
|
|
39
|
+
this._renderer = app.renderer;
|
|
40
|
+
this._drawElements = this._renderer["gl"].drawElements;
|
|
41
|
+
this.init();
|
|
42
|
+
}
|
|
43
|
+
/** @description 初始化显示性能数据 */
|
|
44
|
+
init() {
|
|
45
|
+
this._renderer["gl"].drawElements = (...args) => {
|
|
46
|
+
this._drawElements.call(this._renderer["gl"], ...args);
|
|
47
|
+
this._drawCount++;
|
|
48
|
+
};
|
|
49
|
+
Ticker.shared.add(() => {
|
|
50
|
+
const fps = Ticker.system.FPS;
|
|
51
|
+
this._nowTime = performance.now();
|
|
52
|
+
if (this._nowTime - this._lastTime >= 100.0) {
|
|
53
|
+
this._setTxtInfo(0, Math.floor(fps).toFixed(0));
|
|
54
|
+
this._lastTime = this._nowTime;
|
|
55
|
+
}
|
|
56
|
+
if (this._nowTime - this._lastCollectTime < this.COLLECT_TIME) {
|
|
57
|
+
if (this._tempMaxDrawCount < this._drawCount) {
|
|
58
|
+
this._tempMaxDrawCount = this._drawCount;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
this._maxDrawCount = this._tempMaxDrawCount;
|
|
63
|
+
this._tempMaxDrawCount = 0;
|
|
64
|
+
this._lastCollectTime = this._nowTime;
|
|
65
|
+
}
|
|
66
|
+
this._setTxtInfo(1, this._drawCount);
|
|
67
|
+
this._setTxtInfo(2, this._maxDrawCount);
|
|
68
|
+
this._drawCount = 0;
|
|
69
|
+
}, UPDATE_PRIORITY.UTILITY);
|
|
70
|
+
}
|
|
71
|
+
/** @description 更新文本信息 */
|
|
72
|
+
_setTxtInfo(p, v) {
|
|
73
|
+
const fpsColor = (v) => {
|
|
74
|
+
this._paramTxts[p].style.fill = "#fff";
|
|
75
|
+
if (v <= 30) {
|
|
76
|
+
this._paramTxts[p].style.fill = "yellow";
|
|
77
|
+
}
|
|
78
|
+
if (v <= 20) {
|
|
79
|
+
this._paramTxts[p].style.fill = "red";
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const drawCallColor = (v) => {
|
|
83
|
+
this._paramTxts[p].style.fill = "#fff";
|
|
84
|
+
if (v >= 75) {
|
|
85
|
+
this._paramTxts[p].style.fill = "yellow";
|
|
86
|
+
}
|
|
87
|
+
if (v >= 100) {
|
|
88
|
+
this._paramTxts[p].style.fill = "red";
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const paramMapping = [
|
|
92
|
+
() => {
|
|
93
|
+
fpsColor(v);
|
|
94
|
+
return `Fps:${v}`;
|
|
95
|
+
},
|
|
96
|
+
() => {
|
|
97
|
+
drawCallColor(v);
|
|
98
|
+
return `Draw Call:${v}`;
|
|
99
|
+
},
|
|
100
|
+
() => {
|
|
101
|
+
drawCallColor(v);
|
|
102
|
+
return `Max Draw Call:${v}`;
|
|
103
|
+
},
|
|
104
|
+
];
|
|
105
|
+
this._paramTxts[p].text = paramMapping[p]();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Container, type Texture } from "pixi.js";
|
|
2
|
+
export interface LibPixiProgressParams {
|
|
3
|
+
/** 背景宽度 */
|
|
4
|
+
bgWidth: number;
|
|
5
|
+
/** 背景高度 */
|
|
6
|
+
bgHeight: number;
|
|
7
|
+
/** 进度条宽度 */
|
|
8
|
+
barWidth: number;
|
|
9
|
+
/** 进度条高度 */
|
|
10
|
+
barHeight: number;
|
|
11
|
+
/** 背景纹理 */
|
|
12
|
+
bgTexture: Texture;
|
|
13
|
+
/** 进度条纹理 */
|
|
14
|
+
barTexture: Texture;
|
|
15
|
+
}
|
|
16
|
+
/** @description 通过裁剪的方式显示进度条
|
|
17
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiProgress-进度条
|
|
18
|
+
*/
|
|
19
|
+
export declare class LibPixiProgress extends Container {
|
|
20
|
+
/** 光条图 */
|
|
21
|
+
private _progressBar;
|
|
22
|
+
/** 蒙版 */
|
|
23
|
+
private _maskGraphics;
|
|
24
|
+
constructor(params: LibPixiProgressParams);
|
|
25
|
+
/** @description 更新进度
|
|
26
|
+
* @param progress 进度值,范围从0到1
|
|
27
|
+
*/
|
|
28
|
+
setProgress(progress: number): void;
|
|
29
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Container, Graphics, Sprite } from "pixi.js";
|
|
2
|
+
/** @description 通过裁剪的方式显示进度条
|
|
3
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiProgress-进度条
|
|
4
|
+
*/
|
|
5
|
+
export class LibPixiProgress extends Container {
|
|
6
|
+
constructor(params) {
|
|
7
|
+
super();
|
|
8
|
+
const { bgWidth, bgHeight, barWidth, barHeight, bgTexture, barTexture } = params;
|
|
9
|
+
// 背景图
|
|
10
|
+
const background = new Sprite(bgTexture);
|
|
11
|
+
this.addChild(background);
|
|
12
|
+
// 光条图
|
|
13
|
+
this._progressBar = new Sprite(barTexture);
|
|
14
|
+
this.addChild(this._progressBar);
|
|
15
|
+
this._progressBar.x = (bgWidth - barWidth) / 2;
|
|
16
|
+
this._progressBar.y = (bgHeight - barHeight) / 2;
|
|
17
|
+
// 创建蒙版
|
|
18
|
+
const mask = new Graphics();
|
|
19
|
+
mask.beginFill(0xffffff);
|
|
20
|
+
mask.drawRect(0, 0, 0, this._progressBar.height);
|
|
21
|
+
mask.endFill();
|
|
22
|
+
this._progressBar.addChild(mask);
|
|
23
|
+
this._progressBar.mask = mask;
|
|
24
|
+
this._maskGraphics = mask;
|
|
25
|
+
}
|
|
26
|
+
/** @description 更新进度
|
|
27
|
+
* @param progress 进度值,范围从0到1
|
|
28
|
+
*/
|
|
29
|
+
setProgress(progress) {
|
|
30
|
+
const clampedProgress = Math.max(0, Math.min(1, progress));
|
|
31
|
+
this._maskGraphics.clear();
|
|
32
|
+
this._maskGraphics.beginFill(0xffffff);
|
|
33
|
+
this._maskGraphics.drawRect(0, 0, this._progressBar.width * clampedProgress, this._progressBar.height);
|
|
34
|
+
this._maskGraphics.endFill();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Container } from "pixi.js";
|
|
2
|
+
import { LibPixiContainer } from "../Base/LibPixiContainer";
|
|
3
|
+
export interface LibPixiScrollContainerParams {
|
|
4
|
+
/** 宽度 */
|
|
5
|
+
width: number;
|
|
6
|
+
/** 高度 */
|
|
7
|
+
height: number;
|
|
8
|
+
/** 滚动内容 */
|
|
9
|
+
scrollContent: Container;
|
|
10
|
+
/** 底部内边距 */
|
|
11
|
+
bottomMargin?: number;
|
|
12
|
+
}
|
|
13
|
+
/** @description 支持鼠标滚轮滚动、鼠标拖动、手指滑动,支持惯性滚动及回弹
|
|
14
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiScrollContainer-滚动容器
|
|
15
|
+
*/
|
|
16
|
+
export declare class LibPixiScrollContainer extends LibPixiContainer {
|
|
17
|
+
/** 开始位置 */
|
|
18
|
+
private _startY;
|
|
19
|
+
/** 惯性速度 */
|
|
20
|
+
private _velocity;
|
|
21
|
+
/** 上一次滚动时间 */
|
|
22
|
+
private _startTime;
|
|
23
|
+
/** 开始位置 */
|
|
24
|
+
private _startPosition;
|
|
25
|
+
/** 滚动速度 */
|
|
26
|
+
private _scrollSpeed;
|
|
27
|
+
/** 是否处于拖动状态 */
|
|
28
|
+
private _isDragging;
|
|
29
|
+
/** 滚动容器 */
|
|
30
|
+
_scrollContent: Container;
|
|
31
|
+
/** 遮罩 */
|
|
32
|
+
private _maskGraphics;
|
|
33
|
+
/** 滚动的内容 */
|
|
34
|
+
private _content;
|
|
35
|
+
constructor(params: LibPixiScrollContainerParams);
|
|
36
|
+
/** @description 设置滚动容器可视区宽高
|
|
37
|
+
* @param width 宽度
|
|
38
|
+
* @param height 高度
|
|
39
|
+
*/
|
|
40
|
+
setDimensions(width: number, height: number): void;
|
|
41
|
+
/** @description 返回顶部 */
|
|
42
|
+
scrollToTop(): void;
|
|
43
|
+
/** @description 往滚动内容添加元素 */
|
|
44
|
+
addContent(container: Container): void;
|
|
45
|
+
/** @description 按下 */
|
|
46
|
+
private _onDragStart;
|
|
47
|
+
/** @description 拖动 */
|
|
48
|
+
private _onDragMove;
|
|
49
|
+
/** @description 拖动结束 */
|
|
50
|
+
private _onDragEnd;
|
|
51
|
+
/** @description 滚轮滚动 */
|
|
52
|
+
private _onWheelScroll;
|
|
53
|
+
/** @description 惯性动画 */
|
|
54
|
+
private _applyInertia;
|
|
55
|
+
/** @description 限制滚动范围 */
|
|
56
|
+
private _limitScrollRange;
|
|
57
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { Container, Graphics, Sprite, } 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#LibPixiScrollContainer-滚动容器
|
|
6
|
+
*/
|
|
7
|
+
export class LibPixiScrollContainer extends LibPixiContainer {
|
|
8
|
+
constructor(params) {
|
|
9
|
+
const { width, height, scrollContent, bottomMargin = 50 } = params;
|
|
10
|
+
super(width, height);
|
|
11
|
+
/** 开始位置 */
|
|
12
|
+
this._startY = 0;
|
|
13
|
+
/** 惯性速度 */
|
|
14
|
+
this._velocity = 0;
|
|
15
|
+
/** 上一次滚动时间 */
|
|
16
|
+
this._startTime = 0;
|
|
17
|
+
/** 开始位置 */
|
|
18
|
+
this._startPosition = 0;
|
|
19
|
+
/** 滚动速度 */
|
|
20
|
+
this._scrollSpeed = 200;
|
|
21
|
+
/** 是否处于拖动状态 */
|
|
22
|
+
this._isDragging = false;
|
|
23
|
+
this._scrollContent = scrollContent;
|
|
24
|
+
// 创建内容容器
|
|
25
|
+
this._content = new Container();
|
|
26
|
+
this.addChild(this._content);
|
|
27
|
+
this._content.addChild(this._scrollContent);
|
|
28
|
+
// 创建底部占位
|
|
29
|
+
if (bottomMargin > 0) {
|
|
30
|
+
const bottom_box = new Sprite();
|
|
31
|
+
this._content.addChild(bottom_box);
|
|
32
|
+
bottom_box.y = this._content.height + bottomMargin;
|
|
33
|
+
}
|
|
34
|
+
// 创建遮罩
|
|
35
|
+
this._maskGraphics = new Graphics();
|
|
36
|
+
this.addChild(this._maskGraphics);
|
|
37
|
+
this._maskGraphics.clear();
|
|
38
|
+
this._maskGraphics.beginFill(0x000000);
|
|
39
|
+
this._maskGraphics.drawRect(0, 0, width, height);
|
|
40
|
+
this._maskGraphics.endFill();
|
|
41
|
+
this.mask = this._maskGraphics;
|
|
42
|
+
// 添加事件监听
|
|
43
|
+
this.eventMode = "static";
|
|
44
|
+
this.on("pointerdown", this._onDragStart, this);
|
|
45
|
+
this.on("pointermove", this._onDragMove, this);
|
|
46
|
+
this.on("pointerup", this._onDragEnd, this);
|
|
47
|
+
this.on("pointerupoutside", this._onDragEnd, this);
|
|
48
|
+
this.on("wheel", this._onWheelScroll, this);
|
|
49
|
+
}
|
|
50
|
+
/** @description 设置滚动容器可视区宽高
|
|
51
|
+
* @param width 宽度
|
|
52
|
+
* @param height 高度
|
|
53
|
+
*/
|
|
54
|
+
setDimensions(width, height) {
|
|
55
|
+
// 更新遮罩尺寸
|
|
56
|
+
this._maskGraphics.clear();
|
|
57
|
+
this._maskGraphics.beginFill(0x000000);
|
|
58
|
+
this._maskGraphics.drawRect(0, 0, width, height);
|
|
59
|
+
this._maskGraphics.endFill();
|
|
60
|
+
this.setSize(width, height);
|
|
61
|
+
}
|
|
62
|
+
/** @description 返回顶部 */
|
|
63
|
+
scrollToTop() {
|
|
64
|
+
this._content.y = 0;
|
|
65
|
+
}
|
|
66
|
+
/** @description 往滚动内容添加元素 */
|
|
67
|
+
addContent(container) {
|
|
68
|
+
this._scrollContent.addChild(container);
|
|
69
|
+
}
|
|
70
|
+
/** @description 按下 */
|
|
71
|
+
_onDragStart(event) {
|
|
72
|
+
if (this._content.height <= this._maskGraphics.height)
|
|
73
|
+
return;
|
|
74
|
+
const position = event.getLocalPosition(this);
|
|
75
|
+
this._startY = position.y - this._content.y;
|
|
76
|
+
this._isDragging = true;
|
|
77
|
+
this._velocity = 0;
|
|
78
|
+
this._startTime = Date.now();
|
|
79
|
+
this._startPosition = this._content.y;
|
|
80
|
+
gsap.killTweensOf(this._content);
|
|
81
|
+
}
|
|
82
|
+
/** @description 拖动 */
|
|
83
|
+
_onDragMove(event) {
|
|
84
|
+
if (this._isDragging) {
|
|
85
|
+
const position = event.data.getLocalPosition(this);
|
|
86
|
+
const newPosition = position.y - this._startY;
|
|
87
|
+
this._content.y = newPosition;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/** @description 拖动结束 */
|
|
91
|
+
_onDragEnd() {
|
|
92
|
+
this._isDragging = false;
|
|
93
|
+
const currentTime = Date.now();
|
|
94
|
+
const deltaTime = currentTime - this._startTime; // 计算停留时间
|
|
95
|
+
if (deltaTime < 250) {
|
|
96
|
+
// 如果停留时间在阈值内,计算惯性速度
|
|
97
|
+
this._velocity = (this._content.y - this._startPosition) / deltaTime;
|
|
98
|
+
this._applyInertia();
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
// 停留时间超出阈值,取消惯性
|
|
102
|
+
this._velocity = 0;
|
|
103
|
+
}
|
|
104
|
+
this._limitScrollRange();
|
|
105
|
+
}
|
|
106
|
+
/** @description 滚轮滚动 */
|
|
107
|
+
_onWheelScroll(event) {
|
|
108
|
+
// 如果内容高度小于遮罩高度,则不滚动
|
|
109
|
+
if (this._content.height <= this._maskGraphics.height)
|
|
110
|
+
return;
|
|
111
|
+
let y = this._content.y - event.deltaY * (this._scrollSpeed / 100);
|
|
112
|
+
//如果到达顶部,则不滚动
|
|
113
|
+
if (y > 0) {
|
|
114
|
+
y = 0;
|
|
115
|
+
}
|
|
116
|
+
//如果到达底部,则不滚动
|
|
117
|
+
else if (Math.abs(y) >= this._content.height - this._maskGraphics.height) {
|
|
118
|
+
y = -(this._content.height - this._maskGraphics.height);
|
|
119
|
+
}
|
|
120
|
+
gsap.to(this._content, {
|
|
121
|
+
duration: 0.25,
|
|
122
|
+
ease: "power1.out",
|
|
123
|
+
y,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
/** @description 惯性动画 */
|
|
127
|
+
_applyInertia() {
|
|
128
|
+
gsap.to(this._content, {
|
|
129
|
+
y: this._content.y + this._velocity * 250,
|
|
130
|
+
duration: 0.5,
|
|
131
|
+
ease: "power1.out",
|
|
132
|
+
onUpdate: this._limitScrollRange.bind(this),
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
/** @description 限制滚动范围 */
|
|
136
|
+
_limitScrollRange() {
|
|
137
|
+
//如果内容顶部离开了滚动容器顶部,则归位
|
|
138
|
+
if (this._content.y > 0) {
|
|
139
|
+
gsap.to(this._content, {
|
|
140
|
+
duration: 0.75,
|
|
141
|
+
y: 0,
|
|
142
|
+
ease: "elastic.out",
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
// 如果滚动距离大于内容高度减去遮罩高度
|
|
146
|
+
else if (Math.abs(this._content.y) >=
|
|
147
|
+
this._content.height - this._maskGraphics.height) {
|
|
148
|
+
// 如果内容高度大于遮罩高度,则滚动到底部
|
|
149
|
+
if (this._content.height > this._maskGraphics.height) {
|
|
150
|
+
const y = -(this._content.height - this._maskGraphics.height);
|
|
151
|
+
gsap.to(this._content, {
|
|
152
|
+
duration: 0.75,
|
|
153
|
+
y,
|
|
154
|
+
ease: "elastic.out",
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
// 否则静止不动
|
|
158
|
+
else {
|
|
159
|
+
gsap.to(this._content, {
|
|
160
|
+
duration: 0.25,
|
|
161
|
+
y: 0,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Container } from "pixi.js";
|
|
2
|
+
import { LibPixiContainer } from '../Base/LibPixiContainer';
|
|
3
|
+
export interface LibPixiScrollNumParams {
|
|
4
|
+
/** 滚动区域宽度 */
|
|
5
|
+
width: number;
|
|
6
|
+
/** 滚动区域高度 */
|
|
7
|
+
height: number;
|
|
8
|
+
/** 一页高度 */
|
|
9
|
+
pageHeight: number;
|
|
10
|
+
/** 滚动的容器 */
|
|
11
|
+
content: Container;
|
|
12
|
+
/** 总数 */
|
|
13
|
+
pageNum: number;
|
|
14
|
+
/** 松手回调 */
|
|
15
|
+
slideCallback?: (index: number) => void;
|
|
16
|
+
/** 滚动回调 */
|
|
17
|
+
scrollCallback?: (y: number, index: number) => void;
|
|
18
|
+
}
|
|
19
|
+
/** @description 通过鼠标或手指拖动数字列选择数字
|
|
20
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiScrollNum-数字滑动
|
|
21
|
+
*/
|
|
22
|
+
export declare class LibPixiScrollNum extends LibPixiContainer {
|
|
23
|
+
/** 当前幻灯片索引 */
|
|
24
|
+
private _currentIndex;
|
|
25
|
+
/** 滚动区域高度 */
|
|
26
|
+
private _scrollHeight;
|
|
27
|
+
/** 滑动区域高度 */
|
|
28
|
+
private _slideHeight;
|
|
29
|
+
/** 记录拖动开始时的Y坐标 */
|
|
30
|
+
private _startY;
|
|
31
|
+
/** 偏移量 */
|
|
32
|
+
private _offsetY;
|
|
33
|
+
/** 最大索引 */
|
|
34
|
+
private _pageNum;
|
|
35
|
+
/** 记录开始时间 */
|
|
36
|
+
private _startTime;
|
|
37
|
+
/** 是否正在拖动 */
|
|
38
|
+
private _isDragging;
|
|
39
|
+
/** 滑动内容 */
|
|
40
|
+
private _slideArea;
|
|
41
|
+
/** 滑动回调 */
|
|
42
|
+
private _slideCallback?;
|
|
43
|
+
/** 滚动回调 */
|
|
44
|
+
private _scrollCallback?;
|
|
45
|
+
constructor(params: LibPixiScrollNumParams);
|
|
46
|
+
/** @description 更新坐标
|
|
47
|
+
* @param y Y坐标
|
|
48
|
+
* @param index 页数索引
|
|
49
|
+
*/
|
|
50
|
+
updatePosition(y: number, index: number): void;
|
|
51
|
+
/** @description 滑动到指定索引
|
|
52
|
+
* @param index 页数索引
|
|
53
|
+
* @param animate 是否需要过渡动画
|
|
54
|
+
*/
|
|
55
|
+
slideTo(index: number, animate?: boolean): void;
|
|
56
|
+
/** @description 开始拖动 */
|
|
57
|
+
private _onDragStart;
|
|
58
|
+
/** @description 拖动中 */
|
|
59
|
+
private _onDragMove;
|
|
60
|
+
/** @description 结束拖动 */
|
|
61
|
+
private _onDragEnd;
|
|
62
|
+
}
|