lyb-pixi-js 1.12.40 → 1.12.41
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/LibPixiHeadingParagraphLayout.d.ts +18 -0
- package/Components/Custom/LibPixiHeadingParagraphLayout.js +27 -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 +40 -0
- package/Utils/LibPixiDialogManager/ui/LibPixiDialog.js +145 -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 -1
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { Ticker } from "pixi.js";
|
|
2
|
+
import Decimal from "decimal.js";
|
|
3
|
+
import { libPixiEvent } from "../../Utils/LibPixiEvent";
|
|
4
|
+
import { libPixiScaleContainer } from "../../Utils/LibPixiScaleContainer";
|
|
5
|
+
import { LibPixiContainer } from "../Base/LibPixiContainer";
|
|
6
|
+
import { LibPixiText } from "../Base/LibPixiText";
|
|
7
|
+
/** @description 动态缩放移动输入框 */
|
|
8
|
+
export class LibPixiInput extends LibPixiContainer {
|
|
9
|
+
constructor(params) {
|
|
10
|
+
const { width, height, bgColor, value = "" } = params;
|
|
11
|
+
super(width, height, bgColor);
|
|
12
|
+
/** 当前输入的值 */
|
|
13
|
+
this._value = "";
|
|
14
|
+
/** @description 失去焦点处理 */
|
|
15
|
+
this._onBlurHandler = () => {
|
|
16
|
+
const { type = "text", integer = false, min = 1, max = Infinity, } = this._params;
|
|
17
|
+
let text = this._input.value.trim();
|
|
18
|
+
//如果类型为字符串,则不参与校验
|
|
19
|
+
if (["text", "password"].includes(type))
|
|
20
|
+
return text;
|
|
21
|
+
//如果为空,则使用最小值
|
|
22
|
+
if (this._input.value === "")
|
|
23
|
+
text = min.toString();
|
|
24
|
+
//如果不能为负数,输入值小于最小值,则使用最小值
|
|
25
|
+
if (Number(text) < min)
|
|
26
|
+
text = min.toString();
|
|
27
|
+
//如果存在最大值,且输入值大于最大值,则使用最大值
|
|
28
|
+
if (max && Number(text) > max)
|
|
29
|
+
text = max.toString();
|
|
30
|
+
//如果要求整数,则取整
|
|
31
|
+
if (integer)
|
|
32
|
+
text = parseInt(text).toString();
|
|
33
|
+
//保留两位小数且不四舍五入
|
|
34
|
+
const value = new Decimal(Number(text));
|
|
35
|
+
text = value.toFixed(2, Decimal.ROUND_DOWN);
|
|
36
|
+
return text;
|
|
37
|
+
};
|
|
38
|
+
this.cursor = "text";
|
|
39
|
+
this._params = params;
|
|
40
|
+
this._value = value;
|
|
41
|
+
this._createInput();
|
|
42
|
+
this._createReadOnlyInput();
|
|
43
|
+
//聚焦
|
|
44
|
+
libPixiEvent(this, "pointertap", this._focus.bind(this));
|
|
45
|
+
const ticker = new Ticker();
|
|
46
|
+
ticker.add(() => {
|
|
47
|
+
if (this.destroyed) {
|
|
48
|
+
ticker.stop();
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
this._updateInputPosition();
|
|
52
|
+
});
|
|
53
|
+
ticker.start();
|
|
54
|
+
}
|
|
55
|
+
/** @description 设置值 */
|
|
56
|
+
setValue(v) {
|
|
57
|
+
const { onFormatValue, type = "text" } = this._params;
|
|
58
|
+
const value = v;
|
|
59
|
+
this._value = value;
|
|
60
|
+
if (type === "password") {
|
|
61
|
+
this._readonlyInput.text =
|
|
62
|
+
(onFormatValue === null || onFormatValue === void 0 ? void 0 : onFormatValue(value)) || "●".repeat(value.length);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
this._readonlyInput.text = (onFormatValue === null || onFormatValue === void 0 ? void 0 : onFormatValue(value)) || value;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** @description 创建输入框 */
|
|
69
|
+
_createInput() {
|
|
70
|
+
const { color = "#fff", maxLength = 999999, align = "left", type = "text", onInput = () => { }, fontFamily = "", bold = false, } = this._params;
|
|
71
|
+
this._input = document.createElement("input");
|
|
72
|
+
this._input.type = type;
|
|
73
|
+
this._input.maxLength = maxLength;
|
|
74
|
+
this._input.style.cssText = `
|
|
75
|
+
position: absolute;
|
|
76
|
+
border: none;
|
|
77
|
+
outline: none;
|
|
78
|
+
display: none;
|
|
79
|
+
background-color: transparent;
|
|
80
|
+
color: ${color};
|
|
81
|
+
text-align: ${align};
|
|
82
|
+
font-family: ${fontFamily};
|
|
83
|
+
font-weight: ${bold ? "bold" : "normal"}
|
|
84
|
+
`;
|
|
85
|
+
document.querySelector("#game").appendChild(this._input);
|
|
86
|
+
this._input.addEventListener("input", function () {
|
|
87
|
+
if (this.value.length > maxLength && type === "number") {
|
|
88
|
+
this.value = this.value.slice(0, maxLength);
|
|
89
|
+
}
|
|
90
|
+
onInput(this.value.trim());
|
|
91
|
+
});
|
|
92
|
+
this._input.addEventListener("paste", function (e) {
|
|
93
|
+
var _a, _b;
|
|
94
|
+
const paste = (_b = (_a = e.clipboardData) === null || _a === void 0 ? void 0 : _a.getData("text")) !== null && _b !== void 0 ? _b : "";
|
|
95
|
+
if (paste.length > maxLength) {
|
|
96
|
+
e.preventDefault();
|
|
97
|
+
this.value = paste.slice(0, maxLength);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
this._input.addEventListener("blur", this._blur.bind(this));
|
|
101
|
+
}
|
|
102
|
+
/** @description 创建只读输入框 */
|
|
103
|
+
_createReadOnlyInput() {
|
|
104
|
+
const { color = "#fff", value = "", width, height, fontSizeRatio = 0.5, align = "left", placeholder = "", placeholderColor, fontFamily = "", bold = false, } = this._params;
|
|
105
|
+
//创建描述
|
|
106
|
+
this._placeholder = new LibPixiText({
|
|
107
|
+
text: placeholder,
|
|
108
|
+
fontColor: placeholderColor,
|
|
109
|
+
fontSize: height * fontSizeRatio,
|
|
110
|
+
fontFamily,
|
|
111
|
+
fontWeight: bold ? "bold" : "normal",
|
|
112
|
+
});
|
|
113
|
+
this.addChild(this._placeholder);
|
|
114
|
+
this._placeholder.visible = !value;
|
|
115
|
+
this._placeholder.anchor.set(align === "left" ? 0 : 0.5, 0.5);
|
|
116
|
+
this._placeholder.position.set(align === "left" ? 0 : width / 2, height / 2);
|
|
117
|
+
//创建实际显示的文本
|
|
118
|
+
this._readonlyInput = new LibPixiText({
|
|
119
|
+
text: value,
|
|
120
|
+
fontColor: color,
|
|
121
|
+
fontSize: height * fontSizeRatio,
|
|
122
|
+
fontFamily,
|
|
123
|
+
fontWeight: bold ? "bold" : "normal",
|
|
124
|
+
});
|
|
125
|
+
this.addChild(this._readonlyInput);
|
|
126
|
+
this._readonlyInput.visible = !!value;
|
|
127
|
+
this._readonlyInput.anchor.set(align === "left" ? 0 : 0.5, 0.5);
|
|
128
|
+
this._readonlyInput.position.set(align === "left" ? 0 : width / 2, height / 2);
|
|
129
|
+
}
|
|
130
|
+
/** @description 聚焦 */
|
|
131
|
+
_focus() {
|
|
132
|
+
const { type } = this._params;
|
|
133
|
+
this._input.style.display = "block";
|
|
134
|
+
this._input.focus();
|
|
135
|
+
this._readonlyInput.visible = false;
|
|
136
|
+
this._placeholder.visible = false;
|
|
137
|
+
if (type === "number") {
|
|
138
|
+
this._input.value = this._value && Number(this._value).toString();
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
this._input.value = this._value;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/** @description 失焦 */
|
|
145
|
+
_blur() {
|
|
146
|
+
const { onValue, width } = this._params;
|
|
147
|
+
const value = this._onBlurHandler();
|
|
148
|
+
this.setValue(value);
|
|
149
|
+
this._input.style.display = "none";
|
|
150
|
+
libPixiScaleContainer(this._readonlyInput, width);
|
|
151
|
+
if (this._params.type === "number") {
|
|
152
|
+
this._readonlyInput.visible = true;
|
|
153
|
+
onValue === null || onValue === void 0 ? void 0 : onValue(Number(value));
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
onValue === null || onValue === void 0 ? void 0 : onValue(value);
|
|
157
|
+
//如果输入的值为空,并且启用了描述,并且没有默认值,则显示描述
|
|
158
|
+
if (value === "" && this._placeholder) {
|
|
159
|
+
this._placeholder.visible = true;
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
this._readonlyInput.visible = true;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/** @description 实时更新输入框位置 */
|
|
167
|
+
_updateInputPosition() {
|
|
168
|
+
const { width, height, x, y } = this.getBounds();
|
|
169
|
+
const { fontSizeRatio = 0.5 } = this._params;
|
|
170
|
+
this._input.style.width = `${width}px`;
|
|
171
|
+
this._input.style.height = `${height}px`;
|
|
172
|
+
this._input.style.fontSize = `${height * fontSizeRatio}px`;
|
|
173
|
+
if (LibPixiInput.stage.rotation === 0) {
|
|
174
|
+
this._input.style.left = `${x}px`;
|
|
175
|
+
this._input.style.top = `${y}px`;
|
|
176
|
+
this._input.style.width = `${width}px`;
|
|
177
|
+
this._input.style.height = `${height}px`;
|
|
178
|
+
this._input.style.fontSize = `${height * fontSizeRatio}px`;
|
|
179
|
+
this._input.style.transform = `rotate(0deg)`;
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
const centerX = x + width / 2;
|
|
183
|
+
const centerY = y + height / 2;
|
|
184
|
+
this._input.style.left = `${centerX - height / 2}px`;
|
|
185
|
+
this._input.style.top = `${centerY - width / 2}px`;
|
|
186
|
+
this._input.style.width = `${height}px`;
|
|
187
|
+
this._input.style.height = `${width}px`;
|
|
188
|
+
this._input.style.fontSize = `${width * fontSizeRatio}px`;
|
|
189
|
+
this._input.style.transform = `rotate(90deg)`;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
/** @description 设置输入框类型 */
|
|
193
|
+
toggleType(type) {
|
|
194
|
+
this._input.type = type;
|
|
195
|
+
this._params.type = type;
|
|
196
|
+
this.setValue(this._value);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BitmapText, Container, Sprite } from "pixi.js";
|
|
2
|
+
import { LibPixiText } from "../Base/LibPixiText";
|
|
3
|
+
type T = Sprite | LibPixiText | BitmapText;
|
|
4
|
+
interface LabelValueParams {
|
|
5
|
+
/** 描述 */
|
|
6
|
+
label: T;
|
|
7
|
+
/** 值 */
|
|
8
|
+
value: T;
|
|
9
|
+
/** 最大宽度 */
|
|
10
|
+
maxWidth?: number;
|
|
11
|
+
/** 间隔 */
|
|
12
|
+
gap?: number;
|
|
13
|
+
}
|
|
14
|
+
/** @description 自适应宽度的标签和值组件
|
|
15
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiLabelValue-标签值
|
|
16
|
+
*/
|
|
17
|
+
export declare class LibPixiLabelValue extends Container {
|
|
18
|
+
/** 描述 */
|
|
19
|
+
private _label;
|
|
20
|
+
/** 值 */
|
|
21
|
+
private _value;
|
|
22
|
+
/** 间隔 */
|
|
23
|
+
private _gap;
|
|
24
|
+
/** 最大宽度 */
|
|
25
|
+
private _maxWidth?;
|
|
26
|
+
constructor(params: LabelValueParams);
|
|
27
|
+
/** @description 更新坐标 */
|
|
28
|
+
updatePosition(): void;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Container } from "pixi.js";
|
|
2
|
+
import { libPixiScaleContainer } from "../../Utils/LibPixiScaleContainer";
|
|
3
|
+
/** @description 自适应宽度的标签和值组件
|
|
4
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiLabelValue-标签值
|
|
5
|
+
*/
|
|
6
|
+
export class LibPixiLabelValue extends Container {
|
|
7
|
+
constructor(params) {
|
|
8
|
+
super();
|
|
9
|
+
const { label, value, maxWidth, gap = 0 } = params;
|
|
10
|
+
this._label = label;
|
|
11
|
+
this._value = value;
|
|
12
|
+
this._maxWidth = maxWidth;
|
|
13
|
+
this._gap = gap;
|
|
14
|
+
this.addChild(this._label);
|
|
15
|
+
this._label.anchor.set(1, 0.5);
|
|
16
|
+
this.addChild(this._value);
|
|
17
|
+
this._value.anchor.set(0.5);
|
|
18
|
+
this.updatePosition();
|
|
19
|
+
}
|
|
20
|
+
/** @description 更新坐标 */
|
|
21
|
+
updatePosition() {
|
|
22
|
+
this._label.x = this._label.width * 0.5 - this._value.width * 0.5;
|
|
23
|
+
this._value.x = this._label.width * 0.5 + this._gap;
|
|
24
|
+
this._maxWidth && libPixiScaleContainer(this, this._maxWidth);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type 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
|
+
/** 当前适配模式 */
|
|
7
|
+
static ADAPT_MODE: "h" | "v" | "hv";
|
|
8
|
+
/** 数据收集时间间隔 (5秒) */
|
|
9
|
+
private readonly COLLECT_TIME;
|
|
10
|
+
/** 当前时间 */
|
|
11
|
+
private _nowTime;
|
|
12
|
+
/** 上次更新的时间 */
|
|
13
|
+
private _lastTime;
|
|
14
|
+
/** 当前绘制调用次数 */
|
|
15
|
+
private _drawCount;
|
|
16
|
+
/** 最大绘制调用次数 */
|
|
17
|
+
private _maxDrawCount;
|
|
18
|
+
/** 临时最大绘制调用次数 */
|
|
19
|
+
private _tempMaxDrawCount;
|
|
20
|
+
/** 上次收集数据的时间 */
|
|
21
|
+
private _lastCollectTime;
|
|
22
|
+
/** 整体宽度 */
|
|
23
|
+
private _containerWidth;
|
|
24
|
+
/** 整体高度 */
|
|
25
|
+
private _containerHeight;
|
|
26
|
+
/** 渲染器 */
|
|
27
|
+
private _renderer;
|
|
28
|
+
/** 原始的 drawElements 方法 */
|
|
29
|
+
private _drawElements;
|
|
30
|
+
/** 背景 */
|
|
31
|
+
private _bg;
|
|
32
|
+
/** FPS文本 */
|
|
33
|
+
private _fpsText;
|
|
34
|
+
/** Draw Call文本 */
|
|
35
|
+
private _drawCallText;
|
|
36
|
+
/** Max Draw Call文本 */
|
|
37
|
+
private _maxDrawCallText;
|
|
38
|
+
constructor(app: Application);
|
|
39
|
+
/** @description 初始化显示性能数据 */
|
|
40
|
+
init(): void;
|
|
41
|
+
/** @description 更新文本信息 */
|
|
42
|
+
private _setTextInfo;
|
|
43
|
+
/** @description 获取FPS颜色 */
|
|
44
|
+
getFpsColor(v: number): string;
|
|
45
|
+
/** @description 获取Draw Call颜色 */
|
|
46
|
+
getDrawCallColor(v: number): string;
|
|
47
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { LibJsResizeWatcher } from "lyb-js/Base/LibJsResizeWatcher.js";
|
|
2
|
+
import { Container, Ticker, UPDATE_PRIORITY, } from "pixi.js";
|
|
3
|
+
import { LibPixiRectangle } from "../Base/LibPixiRectangle";
|
|
4
|
+
import { LibPixiText } from "../Base/LibPixiText";
|
|
5
|
+
/** @description 监视帧率、Draw Call、Max Draw Call
|
|
6
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiPerforMon-性能监视器
|
|
7
|
+
*/
|
|
8
|
+
export class LibPixiPerforMon extends Container {
|
|
9
|
+
constructor(app) {
|
|
10
|
+
super();
|
|
11
|
+
/** 数据收集时间间隔 (5秒) */
|
|
12
|
+
this.COLLECT_TIME = 5 * 1000;
|
|
13
|
+
/** 当前时间 */
|
|
14
|
+
this._nowTime = 0;
|
|
15
|
+
/** 上次更新的时间 */
|
|
16
|
+
this._lastTime = 0;
|
|
17
|
+
/** 当前绘制调用次数 */
|
|
18
|
+
this._drawCount = 0;
|
|
19
|
+
/** 最大绘制调用次数 */
|
|
20
|
+
this._maxDrawCount = 0;
|
|
21
|
+
/** 临时最大绘制调用次数 */
|
|
22
|
+
this._tempMaxDrawCount = 0;
|
|
23
|
+
/** 上次收集数据的时间 */
|
|
24
|
+
this._lastCollectTime = 0;
|
|
25
|
+
/** 整体宽度 */
|
|
26
|
+
this._containerWidth = 590;
|
|
27
|
+
/** 整体高度 */
|
|
28
|
+
this._containerHeight = 50;
|
|
29
|
+
this.pivot.x = this._containerWidth / 2;
|
|
30
|
+
//创建背景
|
|
31
|
+
this._bg = new LibPixiRectangle(this._containerWidth, this._containerHeight, "#0000007e");
|
|
32
|
+
this.addChild(this._bg);
|
|
33
|
+
//创建内容容器
|
|
34
|
+
const content = new Container();
|
|
35
|
+
this.addChild(content);
|
|
36
|
+
content.x = 25;
|
|
37
|
+
content.y = this._containerHeight / 2;
|
|
38
|
+
//创建FPS文本
|
|
39
|
+
this._fpsText = new TextBox("FPS");
|
|
40
|
+
content.addChild(this._fpsText);
|
|
41
|
+
//创建Draw Call文本
|
|
42
|
+
this._drawCallText = new TextBox("Draw Call");
|
|
43
|
+
content.addChild(this._drawCallText);
|
|
44
|
+
this._drawCallText.x = 125;
|
|
45
|
+
//创建Max Draw Call文本
|
|
46
|
+
this._maxDrawCallText = new TextBox("Max Draw Call");
|
|
47
|
+
content.addChild(this._maxDrawCallText);
|
|
48
|
+
this._maxDrawCallText.x = 320;
|
|
49
|
+
this._renderer = app.renderer;
|
|
50
|
+
this._drawElements = this._renderer["gl"].drawElements;
|
|
51
|
+
this.init();
|
|
52
|
+
if (LibPixiPerforMon.ADAPT_MODE === "h") {
|
|
53
|
+
this.x = 1920 / 2;
|
|
54
|
+
}
|
|
55
|
+
else if (LibPixiPerforMon.ADAPT_MODE === "v") {
|
|
56
|
+
this.x = 1080 / 2;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
const resize = new LibJsResizeWatcher();
|
|
60
|
+
resize.on((w, h) => {
|
|
61
|
+
if (w > h) {
|
|
62
|
+
this.x = 1920 / 2;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
this.x = 1080 / 2;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/** @description 初始化显示性能数据 */
|
|
71
|
+
init() {
|
|
72
|
+
this._renderer["gl"].drawElements = (...args) => {
|
|
73
|
+
this._drawElements.call(this._renderer["gl"], ...args);
|
|
74
|
+
this._drawCount++;
|
|
75
|
+
};
|
|
76
|
+
Ticker.shared.add(() => {
|
|
77
|
+
const fps = Ticker.system.FPS;
|
|
78
|
+
this._nowTime = performance.now();
|
|
79
|
+
if (this._nowTime - this._lastTime >= 100.0) {
|
|
80
|
+
this._setTextInfo("fps", Number(Math.floor(fps).toFixed(0)));
|
|
81
|
+
this._lastTime = this._nowTime;
|
|
82
|
+
}
|
|
83
|
+
if (this._nowTime - this._lastCollectTime < this.COLLECT_TIME) {
|
|
84
|
+
if (this._tempMaxDrawCount < this._drawCount) {
|
|
85
|
+
this._tempMaxDrawCount = this._drawCount;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
this._maxDrawCount = this._tempMaxDrawCount;
|
|
90
|
+
this._tempMaxDrawCount = 0;
|
|
91
|
+
this._lastCollectTime = this._nowTime;
|
|
92
|
+
}
|
|
93
|
+
this._setTextInfo("drawCall", this._drawCount);
|
|
94
|
+
this._setTextInfo("maxDrawCall", this._maxDrawCount);
|
|
95
|
+
this._drawCount = 0;
|
|
96
|
+
}, UPDATE_PRIORITY.UTILITY);
|
|
97
|
+
}
|
|
98
|
+
/** @description 更新文本信息 */
|
|
99
|
+
_setTextInfo(p, v) {
|
|
100
|
+
const textObj = {
|
|
101
|
+
fps: this._fpsText,
|
|
102
|
+
drawCall: this._drawCallText,
|
|
103
|
+
maxDrawCall: this._maxDrawCallText,
|
|
104
|
+
};
|
|
105
|
+
const textBox = textObj[p];
|
|
106
|
+
textBox.updateValue(v);
|
|
107
|
+
if (p === "fps") {
|
|
108
|
+
textBox.updateColor(this.getFpsColor(v));
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
textBox.updateColor(this.getDrawCallColor(v));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/** @description 获取FPS颜色 */
|
|
115
|
+
getFpsColor(v) {
|
|
116
|
+
let color = "#00ff04";
|
|
117
|
+
if (v < 30) {
|
|
118
|
+
color = "#ffd20a";
|
|
119
|
+
}
|
|
120
|
+
if (v < 20) {
|
|
121
|
+
color = "#ff000d";
|
|
122
|
+
}
|
|
123
|
+
return color;
|
|
124
|
+
}
|
|
125
|
+
/** @description 获取Draw Call颜色 */
|
|
126
|
+
getDrawCallColor(v) {
|
|
127
|
+
let color = "#00ff04";
|
|
128
|
+
if (v >= 75) {
|
|
129
|
+
color = "#ffd20a";
|
|
130
|
+
}
|
|
131
|
+
if (v >= 100) {
|
|
132
|
+
color = "#ff000d";
|
|
133
|
+
}
|
|
134
|
+
return color;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/** 当前适配模式 */
|
|
138
|
+
LibPixiPerforMon.ADAPT_MODE = "hv";
|
|
139
|
+
class TextBox extends Container {
|
|
140
|
+
constructor(text, fontSize = 26) {
|
|
141
|
+
super();
|
|
142
|
+
const label = new LibPixiText({
|
|
143
|
+
text,
|
|
144
|
+
fontSize,
|
|
145
|
+
fontWeight: "bold",
|
|
146
|
+
});
|
|
147
|
+
this.addChild(label);
|
|
148
|
+
label.anchor.y = 0.5;
|
|
149
|
+
this._valueText = new LibPixiText({
|
|
150
|
+
text: "0",
|
|
151
|
+
fontSize,
|
|
152
|
+
fontWeight: "bold",
|
|
153
|
+
});
|
|
154
|
+
this.addChild(this._valueText);
|
|
155
|
+
this._valueText.anchor.y = 0.5;
|
|
156
|
+
this._valueText.x = label.width + 10;
|
|
157
|
+
}
|
|
158
|
+
/** @description 更改颜色 */
|
|
159
|
+
updateColor(color) {
|
|
160
|
+
this._valueText.style.fill = color;
|
|
161
|
+
}
|
|
162
|
+
/** @description 设置数值 */
|
|
163
|
+
updateValue(value) {
|
|
164
|
+
this._valueText.text = value;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
direction?: "h" | "v";
|
|
17
|
+
}
|
|
18
|
+
/** @description 通过裁剪的方式显示进度条
|
|
19
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiProgress-进度条
|
|
20
|
+
*/
|
|
21
|
+
export declare class LibPixiProgress extends Container {
|
|
22
|
+
/** 光条图 */
|
|
23
|
+
private _progressBar;
|
|
24
|
+
/** 蒙版 */
|
|
25
|
+
private _maskGraphics;
|
|
26
|
+
/** 方向 */
|
|
27
|
+
private _direction;
|
|
28
|
+
constructor(params: LibPixiProgressParams);
|
|
29
|
+
/** @description 更新进度
|
|
30
|
+
* @param progress 进度值,范围从0到1
|
|
31
|
+
*/
|
|
32
|
+
setProgress(progress: number): void;
|
|
33
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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, direction } = params;
|
|
9
|
+
this._direction = direction || "h";
|
|
10
|
+
// 背景图
|
|
11
|
+
const background = new Sprite(bgTexture);
|
|
12
|
+
this.addChild(background);
|
|
13
|
+
// 光条图
|
|
14
|
+
this._progressBar = new Sprite(barTexture);
|
|
15
|
+
this.addChild(this._progressBar);
|
|
16
|
+
this._progressBar.x = (bgWidth - barWidth) / 2;
|
|
17
|
+
this._progressBar.y = (bgHeight - barHeight) / 2;
|
|
18
|
+
// 创建蒙版
|
|
19
|
+
const mask = new Graphics();
|
|
20
|
+
mask.beginFill(0xffffff);
|
|
21
|
+
if (direction === "h") {
|
|
22
|
+
mask.drawRect(0, 0, 0, this._progressBar.height);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
mask.drawRect(0, 0, this._progressBar.width, 0);
|
|
26
|
+
}
|
|
27
|
+
mask.endFill();
|
|
28
|
+
this._progressBar.addChild(mask);
|
|
29
|
+
this._progressBar.mask = mask;
|
|
30
|
+
this._maskGraphics = mask;
|
|
31
|
+
}
|
|
32
|
+
/** @description 更新进度
|
|
33
|
+
* @param progress 进度值,范围从0到1
|
|
34
|
+
*/
|
|
35
|
+
setProgress(progress) {
|
|
36
|
+
const clampedProgress = Math.max(0, Math.min(1, progress));
|
|
37
|
+
this._maskGraphics.clear();
|
|
38
|
+
this._maskGraphics.beginFill(0xffffff);
|
|
39
|
+
if (this._direction === "h") {
|
|
40
|
+
this._maskGraphics.drawRect(0, 0, this._progressBar.width * clampedProgress, this._progressBar.height);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
this._maskGraphics.drawRect(0, this._progressBar.height * (1 - clampedProgress), this._progressBar.width, this._progressBar.height * clampedProgress);
|
|
44
|
+
}
|
|
45
|
+
this._maskGraphics.endFill();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { libJsDecimal } from "lyb-js/Math/LibJsDecimal.js";
|
|
2
|
+
import { Container, Sprite } from "pixi.js";
|
|
3
|
+
/** @description 设计图背景拼接
|
|
4
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiPuzzleBg-设计图背景拼接
|
|
5
|
+
*/
|
|
6
|
+
export class LibPixiPuzzleBg extends Container {
|
|
7
|
+
constructor(texture) {
|
|
8
|
+
super();
|
|
9
|
+
this.eventMode = "none";
|
|
10
|
+
// 背景
|
|
11
|
+
const bg = new Sprite(texture);
|
|
12
|
+
this.addChild(bg);
|
|
13
|
+
bg.visible = false;
|
|
14
|
+
//读取配置
|
|
15
|
+
const config = JSON.parse(localStorage.getItem("puzzle_bg_config") || "{}");
|
|
16
|
+
const { alpha, x, y } = config;
|
|
17
|
+
bg.alpha = alpha || 0.25;
|
|
18
|
+
bg.position.set(x || 0, y || 0);
|
|
19
|
+
//监听鼠标空格事件
|
|
20
|
+
document.addEventListener("keydown", (e) => {
|
|
21
|
+
if (e.ctrlKey && e.key.toLowerCase() === "q" && !e.shiftKey) {
|
|
22
|
+
e.preventDefault();
|
|
23
|
+
bg.visible = !bg.visible;
|
|
24
|
+
}
|
|
25
|
+
else if (e.code === "ArrowUp") {
|
|
26
|
+
bg.y -= 2;
|
|
27
|
+
}
|
|
28
|
+
else if (e.code === "ArrowDown") {
|
|
29
|
+
bg.y += 2;
|
|
30
|
+
}
|
|
31
|
+
else if (e.code === "ArrowLeft") {
|
|
32
|
+
bg.x -= 2;
|
|
33
|
+
}
|
|
34
|
+
else if (e.code === "ArrowRight") {
|
|
35
|
+
bg.x += 2;
|
|
36
|
+
}
|
|
37
|
+
if (e.code === "NumpadAdd" && bg.alpha < 1) {
|
|
38
|
+
bg.alpha = libJsDecimal(bg.alpha, 0.1, "+");
|
|
39
|
+
}
|
|
40
|
+
else if (e.code === "NumpadSubtract" && bg.alpha > 0) {
|
|
41
|
+
bg.alpha = libJsDecimal(bg.alpha, 0.1, "-");
|
|
42
|
+
}
|
|
43
|
+
localStorage.setItem("puzzle_bg_config", JSON.stringify({ alpha: bg.alpha, x: bg.x, y: bg.y }));
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Container, Texture } from "pixi.js";
|
|
2
|
+
import { LibPixiContainer } from "../Base/LibPixiContainer";
|
|
3
|
+
export interface LibPixiScrollContainerXParams {
|
|
4
|
+
/** 宽度 */
|
|
5
|
+
width: number;
|
|
6
|
+
/** 高度 */
|
|
7
|
+
height: number;
|
|
8
|
+
/** 滚动内容 */
|
|
9
|
+
scrollContent: Container;
|
|
10
|
+
/** 背景色,用于定位 */
|
|
11
|
+
bgColor?: string;
|
|
12
|
+
/** 自定义遮罩贴图 */
|
|
13
|
+
maskTexture?: Texture;
|
|
14
|
+
/** 遮罩X坐标 */
|
|
15
|
+
maskX?: number;
|
|
16
|
+
/** 遮罩Y坐标 */
|
|
17
|
+
maskY?: number;
|
|
18
|
+
}
|
|
19
|
+
/** @description 支持鼠标滚轮滚动、鼠标拖动、手指滑动,支持惯性滚动及回弹 */
|
|
20
|
+
export declare class LibPixiScrollContainerX extends LibPixiContainer {
|
|
21
|
+
/** 舞台 */
|
|
22
|
+
static stage: Container;
|
|
23
|
+
/** 开始位置 */
|
|
24
|
+
private _startX;
|
|
25
|
+
/** 惯性速度 */
|
|
26
|
+
private _velocity;
|
|
27
|
+
/** 上一次滚动时间 */
|
|
28
|
+
private _startTime;
|
|
29
|
+
/** 开始位置 */
|
|
30
|
+
private _startContentX;
|
|
31
|
+
/** 滚动速度 */
|
|
32
|
+
private _scrollSpeed;
|
|
33
|
+
/** 是否处于拖动状态 */
|
|
34
|
+
private _isDragging;
|
|
35
|
+
/** 左边距 */
|
|
36
|
+
private _leftMargin;
|
|
37
|
+
/** 右边距元素 */
|
|
38
|
+
private _rightMarginBox?;
|
|
39
|
+
/** 滚动容器 */
|
|
40
|
+
_scrollContent: Container;
|
|
41
|
+
/** 遮罩 */
|
|
42
|
+
private _maskGraphics;
|
|
43
|
+
/** 滚动的内容 */
|
|
44
|
+
private _content;
|
|
45
|
+
constructor(params: LibPixiScrollContainerXParams);
|
|
46
|
+
/** @description 添加边距 */
|
|
47
|
+
addMargin(leftMargin: number, rightMargin?: number): void;
|
|
48
|
+
/** @description 设置滚动容器可视区宽高
|
|
49
|
+
* @param width 宽度
|
|
50
|
+
* @param height 高度
|
|
51
|
+
*/
|
|
52
|
+
setDimensions(width: number, height: number): void;
|
|
53
|
+
/** @description 返回顶部 */
|
|
54
|
+
scrollToTop(): void;
|
|
55
|
+
/** @description 往滚动内容添加元素 */
|
|
56
|
+
addContent(container: Container): void;
|
|
57
|
+
/** @description 更新右边距坐标 */
|
|
58
|
+
private _updateRightMargin;
|
|
59
|
+
/** @description 按下 */
|
|
60
|
+
private _onDragStart;
|
|
61
|
+
/** @description 拖动 */
|
|
62
|
+
private _onDragMove;
|
|
63
|
+
/** @description 拖动结束 */
|
|
64
|
+
private _onDragEnd;
|
|
65
|
+
/** @description 滚轮滚动 */
|
|
66
|
+
private _onWheelScroll;
|
|
67
|
+
/** @description 惯性动画 */
|
|
68
|
+
private _applyInertia;
|
|
69
|
+
/** @description 限制滚动范围 */
|
|
70
|
+
private _limitScrollRange;
|
|
71
|
+
}
|