lyb-pixi-js 1.1.14 → 1.1.16

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.
@@ -2,23 +2,31 @@ import { Container, type Texture } from "pixi.js";
2
2
  export interface LibPixiButtonHoverParams {
3
3
  /** 图标资源 */
4
4
  texture: Texture;
5
- /** 悬浮图标 */
6
- hoverTexture: Texture;
7
- /** 染色 */
5
+ /** 悬浮图标,type为"texture"时生效 */
6
+ hoverTexture?: Texture;
7
+ /** 默认颜色 */
8
8
  tintColor?: string;
9
+ /** 悬浮颜色,默认白色 */
10
+ hoverTintColor?: string;
11
+ /** 置灰颜色 */
12
+ disabledColor?: string;
9
13
  }
10
14
  /** @description 悬浮切换材质
11
15
  * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiButtonHover-按钮悬浮
12
16
  */
13
17
  export declare class LibPixiButtonHover extends Container {
18
+ /** 是否被禁用 */
19
+ private disabled;
14
20
  /** 按钮 */
15
21
  private _btn;
16
22
  /** 默认材质 */
17
23
  private _texture;
18
24
  /** 悬浮材质 */
19
- private _hoverTexture;
20
- /** 染色 */
25
+ private _hoverTexture?;
26
+ /** 默认颜色 */
21
27
  private _tintColor?;
28
+ /** 置灰颜色 */
29
+ private _disabledColor;
22
30
  constructor(params: LibPixiButtonHoverParams);
23
31
  /** @description 切换材质
24
32
  * @param texture 默认材质
@@ -6,22 +6,29 @@ import { libPixiEvent } from "../../Utils/LibPixiEvent";
6
6
  export class LibPixiButtonHover extends Container {
7
7
  constructor(params) {
8
8
  super();
9
- const { texture, hoverTexture, tintColor } = params;
9
+ /** 是否被禁用 */
10
+ this.disabled = false;
11
+ const { texture, hoverTexture, tintColor, hoverTintColor = "#fff", disabledColor = "#999", } = params;
10
12
  this._texture = texture;
11
13
  this._hoverTexture = hoverTexture;
12
14
  this._tintColor = tintColor;
13
- //创建图标容器
14
- const iconBox = new Container();
15
- this.addChild(iconBox);
15
+ this._disabledColor = disabledColor;
16
16
  //创建图标
17
17
  this._btn = new Sprite(texture);
18
- iconBox.addChild(this._btn);
18
+ this.addChild(this._btn);
19
+ this._btn.anchor.set(0.5);
19
20
  tintColor && (this._btn.tint = tintColor);
20
- libPixiEvent(iconBox, "pointerenter", () => {
21
- this._btn._texture = this._hoverTexture;
22
- this._btn.tint = "#fff";
21
+ libPixiEvent(this._btn, "pointerenter", () => {
22
+ if (this.disabled)
23
+ return;
24
+ this._btn.tint = hoverTintColor;
25
+ if (this._hoverTexture) {
26
+ this._btn._texture = this._hoverTexture;
27
+ }
23
28
  });
24
- libPixiEvent(iconBox, "pointerleave", () => {
29
+ libPixiEvent(this._btn, "pointerleave", () => {
30
+ if (this.disabled)
31
+ return;
25
32
  this._btn._texture = this._texture;
26
33
  tintColor && (this._btn.tint = tintColor);
27
34
  });
@@ -39,6 +46,8 @@ export class LibPixiButtonHover extends Container {
39
46
  * @param status 状态
40
47
  */
41
48
  setDisabled(status) {
42
- this._btn.tint = status ? "#7C7C7C" : this._tintColor || "#fff";
49
+ this.disabled = status;
50
+ this._btn.tint = status ? this._disabledColor : this._tintColor || "#fff";
51
+ this._btn.texture = this._texture;
43
52
  }
44
53
  }
@@ -1,36 +1,29 @@
1
- import type { Container } from "pixi.js";
2
1
  export interface LibPixiSubAddMinMaxParams {
3
- /** 最小按钮 */
4
- minBtn: Container;
5
- /** 最大按钮 */
6
- maxBtn: Container;
7
- /** 增加按钮 */
8
- subBtn: Container;
9
- /** 减少按钮 */
10
- addBtn: Container;
11
2
  /** 初始下注索引 */
12
3
  initialBetIndex: number;
13
4
  /** 下注金额列表 */
14
5
  betAmountListLength: number;
15
- /** 金额更新回调 */
6
+ /** 金额更新回调
7
+ * @param index 金额索引
8
+ */
16
9
  onAmountIndex: (index: number) => void;
10
+ /** 按钮置灰状态回调
11
+ * @param type 被置灰的按钮类型
12
+ */
13
+ onDisabled: (type?: "min" | "max") => void;
17
14
  }
18
15
  /** @description 最小、最大按钮和增减按钮功能及置灰逻辑
19
16
  * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiSubAddMinMax-数字控制器
20
17
  */
21
18
  export declare class LibPixiSubAddMinMax {
22
19
  /** 步进器 */
23
- private baseNumSteper;
24
- /** 最大最小按钮 */
25
- private minBtn;
26
- private maxBtn;
27
- /** 增加减少按钮 */
28
- private subBtn;
29
- private addBtn;
20
+ private _baseNumSteper;
30
21
  /** 金额列表数量 */
31
- private betAmountListLength;
22
+ private _betAmountListLength;
32
23
  /** 金额更新回调 */
33
- onAmountIndex: (index: number) => void;
24
+ private _onAmountIndex;
25
+ /** 按钮置灰状态回调 */
26
+ private _onDisabled;
34
27
  constructor(params: LibPixiSubAddMinMaxParams);
35
28
  /** @description 点击最小按钮 */
36
29
  min(): void;
@@ -44,6 +37,4 @@ export declare class LibPixiSubAddMinMax {
44
37
  * @param index 索引
45
38
  */
46
39
  minMaxUpdateIndex(index: number): void;
47
- /** @description 设置最大最小按钮置灰及恢复 */
48
- private _setGrey;
49
40
  }
@@ -1,76 +1,56 @@
1
- import { libPixiFilter } from "../../Utils/LibPixiFilter"; //@ts-ignore
2
- import { LibJsNumberStepper } from 'lyb-js/Misc/LibJsNumberStepper.js';
1
+ import { LibJsNumberStepper } from "lyb-js/Misc/LibJsNumberStepper.js";
3
2
  /** @description 最小、最大按钮和增减按钮功能及置灰逻辑
4
3
  * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiSubAddMinMax-数字控制器
5
4
  */
6
5
  export class LibPixiSubAddMinMax {
7
6
  constructor(params) {
8
7
  /** 金额列表数量 */
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;
8
+ this._betAmountListLength = 0;
9
+ const { initialBetIndex, betAmountListLength, onAmountIndex, onDisabled } = params;
10
+ this._onAmountIndex = onAmountIndex;
11
+ this._onDisabled = onDisabled;
12
+ this._betAmountListLength = betAmountListLength;
17
13
  //金额增减步进器
18
- this.baseNumSteper = new LibJsNumberStepper(betAmountListLength, //@ts-ignore
19
- (index) => {
20
- this.onAmountIndex(index);
14
+ this._baseNumSteper = new LibJsNumberStepper(betAmountListLength, (index) => {
15
+ this._onAmountIndex(index);
21
16
  this.minMaxUpdateIndex(index);
22
17
  });
23
18
  //设置初始状态
24
19
  this.minMaxUpdateIndex(initialBetIndex);
25
- this.baseNumSteper.updateIndex(initialBetIndex);
20
+ this._baseNumSteper.updateIndex(initialBetIndex);
26
21
  }
27
22
  /** @description 点击最小按钮 */
28
23
  min() {
29
24
  this.minMaxUpdateIndex(0);
30
- this.onAmountIndex(0);
25
+ this._onAmountIndex(0);
31
26
  }
32
27
  /** @description 点击最大按钮 */
33
28
  max() {
34
- const index = this.betAmountListLength - 1;
29
+ const index = this._betAmountListLength - 1;
35
30
  this.minMaxUpdateIndex(index);
36
- this.onAmountIndex(index);
31
+ this._onAmountIndex(index);
37
32
  }
38
33
  /** @description 点击减少按钮 */
39
34
  sub() {
40
- this.baseNumSteper.down("sub");
35
+ this._baseNumSteper.down("sub");
41
36
  }
42
37
  /** @description 点击增加按钮 */
43
38
  add() {
44
- this.baseNumSteper.down("add");
39
+ this._baseNumSteper.down("add");
45
40
  }
46
41
  /** @description 改变最小最大按钮状态及回调
47
42
  * @param index 索引
48
43
  */
49
44
  minMaxUpdateIndex(index) {
50
45
  if (index === 0) {
51
- this._setGrey("min");
46
+ this._onDisabled("min");
52
47
  }
53
- else if (index === this.betAmountListLength - 1) {
54
- this._setGrey("max");
48
+ else if (index === this._betAmountListLength - 1) {
49
+ this._onDisabled("max");
55
50
  }
56
51
  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")];
52
+ this._onDisabled();
74
53
  }
54
+ this._baseNumSteper.updateIndex(index);
75
55
  }
76
56
  }
package/README.md CHANGED
@@ -256,31 +256,29 @@ const libPixiParticleMove = new LibPixiJs.Base.LibPixiParticleMove({
256
256
  > 悬浮切换材质
257
257
 
258
258
  ```ts
259
- import { Texture } from "pixi.js";
260
- import { LibPixiButtonHover } from "./path/to/LibPixiButtonHover";
261
-
262
- //加载材质资源
263
- const defaultTexture: Texture = Texture.from("default-icon.png");
264
- const hoverTexture: Texture = Texture.from("hover-icon.png");
259
+ import { LibPixiButtonHover } from "lyb-pixi-js";
265
260
 
266
261
  //创建按钮实例
267
262
  const button = new LibPixiButtonHover({
268
- texture: defaultTexture,
269
- hoverTexture: hoverTexture,
270
- tintColor: "#FF0000", //可选:按钮的初始颜色
263
+ texture: PIXI.Texture.from('path/to/normal.png'),
264
+ hoverTexture: PIXI.Texture.from('path/to/hover.png'),
265
+ tintColor: "#ff0000", //默认颜色
266
+ hoverTintColor: "#00ff00", //悬浮颜色
267
+ disabledColor: "#cccccc" //禁用颜色
271
268
  });
272
269
 
273
- //设置按钮状态
274
- button.setDisabled(true); //禁用按钮
275
-
276
- //在Pixi.js应用的容器中添加按钮
277
- app.stage.addChild(button);
270
+ //启用/禁用按钮
271
+ button.setDisabled(false); //启用
272
+ button.setDisabled(true); //禁用
278
273
 
279
274
  //切换按钮材质
280
275
  button.toggleTexture(
281
- Texture.from("new-default.png"),
282
- Texture.from("new-hover.png")
276
+ PIXI.Texture.from('path/to/new_normal.png'),
277
+ PIXI.Texture.from('path/to/new_hover.png')
283
278
  );
279
+
280
+ //添加到Pixi舞台
281
+ app.stage.addChild(button);
284
282
  ```
285
283
 
286
284
  ### LibPixiCloseBtn-关闭按钮
@@ -477,40 +475,39 @@ slider.next();
477
475
  > 最小、最大按钮和增减按钮功能及置灰逻辑
478
476
 
479
477
  ```ts
480
- import { LibPixiSubAddMinMax } from "./path/to/LibPixiSubAddMinMax";
481
- import { Container } from "pixi.js";
478
+ import { LibPixiSubAddMinMax } from "lyb-pixi-js";
482
479
 
483
- //创建最小、最大、增加和减少按钮
484
- const minBtn = new Container();
485
- const maxBtn = new Container();
486
- const subBtn = new Container();
487
- const addBtn = new Container();
488
-
489
- //设置初始下注索引和金额列表数量
490
- const initialBetIndex = 0;
491
- const betAmountListLength = 5;
492
-
493
- //金额更新回调
494
- const onAmountIndex = (index: number) => {
495
- console.log(`当前金额索引: ${index}`);
496
- };
497
-
498
- //创建LibPixiSubAddMinMax实例
499
- const betAmountController = new LibPixiSubAddMinMax({
500
- minBtn,
501
- maxBtn,
502
- subBtn,
503
- addBtn,
504
- initialBetIndex,
505
- betAmountListLength,
506
- onAmountIndex,
480
+ //创建按钮实例
481
+ const betControl = new LibPixiSubAddMinMax({
482
+ minBtn: minButton, //最小按钮
483
+ maxBtn: maxButton, //最大按钮
484
+ subBtn: subButton, //减少按钮
485
+ addBtn: addButton, //增加按钮
486
+ initialBetIndex: 0, //初始下注索引
487
+ betAmountListLength: 10, //下注金额列表长度
488
+ onAmountIndex: (index) => {
489
+ console.log("当前下注金额索引:", index);
490
+ },
491
+ onDisabled: (type) => {
492
+ if (type === "min") {
493
+ minButton.tint = 0x999999; //禁用最小按钮
494
+ } else if (type === "max") {
495
+ maxButton.tint = 0x999999; //禁用最大按钮
496
+ } else {
497
+ minButton.tint = 0xFFFFFF; //启用最小按钮
498
+ maxButton.tint = 0xFFFFFF; //启用最大按钮
499
+ }
500
+ }
507
501
  });
508
502
 
509
- //绑定按钮事件
510
- minBtn.on("pointerdown", () => betAmountController.min());
511
- maxBtn.on("pointerdown", () => betAmountController.max());
512
- subBtn.on("pointerdown", () => betAmountController.sub());
513
- addBtn.on("pointerdown", () => betAmountController.add());
503
+ //设置初始状态
504
+ betControl.min(); //设置为最小值
505
+ betControl.max(); //设置为最大值
506
+ betControl.sub(); //减少下注
507
+ betControl.add(); //增加下注
508
+
509
+ //添加到Pixi舞台
510
+ app.stage.addChild(minButton, maxButton, subButton, addButton);
514
511
  ```
515
512
 
516
513
  ### LibPixiTable-数字表格
@@ -552,27 +549,27 @@ stage.addChild(table);
552
549
  ```ts
553
550
  const audioPlayer = new LibPixiAudio();
554
551
 
555
- // 播放音效
552
+ //播放音效
556
553
  audioPlayer.playEffect("effect-link").then(() => {
557
554
  console.log("音效播放完成");
558
555
  });
559
556
 
560
- // 播放音乐
557
+ //播放音乐
561
558
  audioPlayer.playMusic("music-link");
562
559
 
563
- // 暂停音乐
560
+ //暂停音乐
564
561
  audioPlayer.pauseMusic();
565
562
 
566
- // 继续播放音乐
563
+ //继续播放音乐
567
564
  audioPlayer.resumeMusic();
568
565
 
569
- // 停止指定音效
566
+ //停止指定音效
570
567
  audioPlayer.stopEffect("effect-link");
571
568
 
572
- // 设置启用音效
569
+ //设置启用音效
573
570
  audioPlayer.setEffectEnabled(false);
574
571
 
575
- // 设置启用音乐
572
+ //设置启用音乐
576
573
  audioPlayer.setMusicEnabled(false);
577
574
  ```
578
575
 
@@ -582,10 +579,10 @@ audioPlayer.setMusicEnabled(false);
582
579
 
583
580
  ```ts
584
581
  const nineGrid = libPixiCreateNineGrid({
585
- texture: yourTexture, // 传入纹理
586
- dotWidth: 10, // 四个角的宽度,可以是数字或者数组
587
- width: 200, // 宽度
588
- height: 150, // 高度
582
+ texture: yourTexture, //传入纹理
583
+ dotWidth: 10, //四个角的宽度,可以是数字或者数组
584
+ width: 200, //宽度
585
+ height: 150, //高度
589
586
  });
590
587
  ```
591
588
 
@@ -598,7 +595,7 @@ libPixiEvent(container, "pointerdown", (e) => {
598
595
  console.log("Pointer down event triggered", e);
599
596
  });
600
597
 
601
- // 只执行一次的事件
598
+ //只执行一次的事件
602
599
  libPixiEvent(
603
600
  container,
604
601
  "pointerup",
@@ -618,7 +615,7 @@ const closeEvent = libPixiEventControlled(container, "pointerdown", (e) => {
618
615
  console.log("Pointer down event triggered", e);
619
616
  });
620
617
 
621
- // 调用返回的函数关闭事件监听
618
+ //调用返回的函数关闭事件监听
622
619
  closeEvent();
623
620
  ```
624
621
 
@@ -627,10 +624,10 @@ closeEvent();
627
624
  > 滤镜
628
625
 
629
626
  ```ts
630
- const brightnessFilter = libPixiFilter("brightness", 1.2); // 设置亮度为1.2
631
- const blurFilter = libPixiFilter("blur"); // 设置模糊滤镜
632
- const desaturateFilter = libPixiFilter("desaturate"); // 设置去饱和滤镜
633
- const contrastFilter = libPixiFilter("contrast", 1.5); // 设置对比度为1.5
627
+ const brightnessFilter = libPixiFilter("brightness", 1.2); //设置亮度为1.2
628
+ const blurFilter = libPixiFilter("blur"); //设置模糊滤镜
629
+ const desaturateFilter = libPixiFilter("desaturate"); //设置去饱和滤镜
630
+ const contrastFilter = libPixiFilter("contrast", 1.5); //设置对比度为1.5
634
631
  ```
635
632
 
636
633
  ### LibPixiIntervalTrigger-间隔触发
@@ -640,15 +637,15 @@ const contrastFilter = libPixiFilter("contrast", 1.5); // 设置对比度为1.5
640
637
  ```ts
641
638
  const stopInterval = libPixiIntervalTrigger(() => {
642
639
  console.log("Triggered interval callback");
643
- }, [500, 1000]); // 随机间隔 500ms 到 1000ms
640
+ }, [500, 1000]); //随机间隔 500ms 到 1000ms
644
641
 
645
642
  //or
646
643
 
647
644
  const stopInterval = libPixiIntervalTrigger(() => {
648
645
  console.log("Triggered interval callback");
649
- }, 500); // 间隔 500ms
646
+ }, 500); //间隔 500ms
650
647
 
651
- // 停止间隔触发
648
+ //停止间隔触发
652
649
  stopInterval();
653
650
  ```
654
651
 
@@ -661,7 +658,7 @@ const stopOutsideClick = libPixiOutsideClick(container, button, () => {
661
658
  console.log("Container closed");
662
659
  });
663
660
 
664
- // 停止监听点击事件
661
+ //停止监听点击事件
665
662
  stopOutsideClick();
666
663
  ```
667
664
 
@@ -670,7 +667,7 @@ stopOutsideClick();
670
667
  > 为容器创建并应用一个矩形遮罩,用于隐藏溢出的内容,函数会返回遮罩,可控制是否显示遮罩
671
668
 
672
669
  ```ts
673
- const mask = libPixiOverflowHidden(container); // 为容器创建并应用矩形蒙版
670
+ const mask = libPixiOverflowHidden(container); //为容器创建并应用矩形蒙版
674
671
  ```
675
672
 
676
673
  ### LibPixiPromiseTickerTimeout-TickerPromise 定时器
@@ -690,7 +687,7 @@ libPixiPromiseTickerTimeout(1000, () => {
690
687
  > 元素超过指定宽度就缩放
691
688
 
692
689
  ```ts
693
- libPixiScaleContainer(container, 500, 300); // 容器超过 500px 宽度或 300px 高度时进行缩放
690
+ libPixiScaleContainer(container, 500, 300); //容器超过 500px 宽度或 300px 高度时进行缩放
694
691
  ```
695
692
 
696
693
  ### LibPixiShadow-阴影
@@ -716,6 +713,6 @@ const stopTimer = libPixiTickerTimeout(() => {
716
713
  console.log("Callback after delay");
717
714
  }, 1000);
718
715
 
719
- // 停止定时器
716
+ //停止定时器
720
717
  stopTimer();
721
718
  ```
@@ -29,11 +29,12 @@ export class LibPixiAudio {
29
29
  * @param status 播放状态,false为暂停
30
30
  */
31
31
  this._setPlayStatus = (status) => {
32
+ var _a, _b;
32
33
  if (status) {
33
- !this._isMusicPaused && this._musicPlayer.play();
34
+ !this._isMusicPaused && ((_a = this._musicPlayer) === null || _a === void 0 ? void 0 : _a.play());
34
35
  }
35
36
  else {
36
- this._musicPlayer.pause();
37
+ (_b = this._musicPlayer) === null || _b === void 0 ? void 0 : _b.pause();
37
38
  }
38
39
  this._playingList.forEach((item) => {
39
40
  if (status) {
@@ -87,6 +88,7 @@ export class LibPixiAudio {
87
88
  */
88
89
  playMusic(key) {
89
90
  return __awaiter(this, void 0, void 0, function* () {
91
+ var _a;
90
92
  //如果有音乐正在播放,则停止
91
93
  if (this._musicPlayer) {
92
94
  gsap.killTweensOf(this._musicPlayer);
@@ -95,7 +97,7 @@ export class LibPixiAudio {
95
97
  duration: 1,
96
98
  ease: "linear",
97
99
  });
98
- this._musicPlayer.pause();
100
+ (_a = this._musicPlayer) === null || _a === void 0 ? void 0 : _a.pause();
99
101
  }
100
102
  const url = Assets.get(key).url;
101
103
  this._musicPlayer.src = url;
@@ -122,13 +124,15 @@ export class LibPixiAudio {
122
124
  }
123
125
  /** @description 暂停音乐 */
124
126
  pauseMusic() {
127
+ var _a;
125
128
  this._isMusicPaused = true;
126
- this._musicPlayer.pause();
129
+ (_a = this._musicPlayer) === null || _a === void 0 ? void 0 : _a.pause();
127
130
  }
128
131
  /** @description 继续播放音乐 */
129
132
  resumeMusic() {
133
+ var _a;
130
134
  this._isMusicPaused = false;
131
- this._musicPlayer.play();
135
+ (_a = this._musicPlayer) === null || _a === void 0 ? void 0 : _a.play();
132
136
  }
133
137
  /** @description 停止播放指定音效
134
138
  * @param key 音效资源Key,内部会使用Assets.get(key)获取音频资源进行停止