pixuireactcomponents 1.1.21 → 1.1.22
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/README.md +5 -5
- package/index.d.ts +15 -15
- package/index.js +16 -16
- package/package.json +11 -11
- package/tools/EventDispatcherJs.d.ts +10 -10
- package/tools/EventDispatcherJs.js +71 -71
- package/tools/Logger.d.ts +6 -6
- package/tools/Logger.js +138 -138
- package/tools/tools.md +21 -21
- package/ui/components/button/Button.d.ts +5 -5
- package/ui/components/button/Button.js +37 -37
- package/ui/components/carousel/Carousel.d.ts +5 -5
- package/ui/components/carousel/Carousel.js +219 -219
- package/ui/components/dropdown/Dropdown.d.ts +30 -30
- package/ui/components/dropdown/Dropdown.js +92 -92
- package/ui/components/dropdown/DropdownOptionUI.d.ts +11 -11
- package/ui/components/dropdown/DropdownOptionUI.js +28 -28
- package/ui/components/dropdown/DropdownSpreadMainUI.d.ts +9 -9
- package/ui/components/dropdown/DropdownSpreadMainUI.js +27 -27
- package/ui/components/dropdown/DropdownUnspreadMainUI.d.ts +9 -9
- package/ui/components/dropdown/DropdownUnspreadMainUI.js +27 -27
- package/ui/components/gradient/GradientText.d.ts +63 -63
- package/ui/components/gradient/GradientText.js +329 -329
- package/ui/components/outlinetext/OutlineText.d.ts +73 -73
- package/ui/components/outlinetext/OutlineText.js +157 -157
- package/ui/components/progress/Progress.d.ts +34 -34
- package/ui/components/progress/Progress.js +142 -142
- package/ui/components/slapface/Slapface.d.ts +12 -12
- package/ui/components/slapface/Slapface.js +224 -227
- package/ui/components/slapface/less/Slapface.less +125 -0
- package/ui/components/slider/Slider.d.ts +57 -57
- package/ui/components/slider/Slider.js +289 -289
- package/ui/components/tab/Tab.d.ts +6 -6
- package/ui/components/tab/Tab.js +27 -27
- package/ui/components/tab/Tabs.d.ts +12 -12
- package/ui/components/tab/Tabs.js +54 -54
- package/ui/ui.md +1 -1
|
@@ -1,329 +1,329 @@
|
|
|
1
|
-
var __extends = (this && this.__extends) || (function () {
|
|
2
|
-
var extendStatics = function (d, b) {
|
|
3
|
-
extendStatics = Object.setPrototypeOf ||
|
|
4
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
-
return extendStatics(d, b);
|
|
7
|
-
};
|
|
8
|
-
return function (d, b) {
|
|
9
|
-
if (typeof b !== "function" && b !== null)
|
|
10
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
-
extendStatics(d, b);
|
|
12
|
-
function __() { this.constructor = d; }
|
|
13
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
-
};
|
|
15
|
-
})();
|
|
16
|
-
import { Component, h } from 'preact';
|
|
17
|
-
var GradientText = /** @class */ (function (_super) {
|
|
18
|
-
__extends(GradientText, _super);
|
|
19
|
-
function GradientText(props) {
|
|
20
|
-
var _this = _super.call(this, props) || this;
|
|
21
|
-
_this.isPrintLog = false;
|
|
22
|
-
_this.textObj = null;
|
|
23
|
-
_this.gradientObj = null;
|
|
24
|
-
_this.state = {
|
|
25
|
-
style: props.style,
|
|
26
|
-
text: props.text,
|
|
27
|
-
color: props.color,
|
|
28
|
-
fontSize: props.fontSize,
|
|
29
|
-
font: props.font,
|
|
30
|
-
alignment: props.alignment,
|
|
31
|
-
direction: props.direction,
|
|
32
|
-
colorTop: props.colorTop,
|
|
33
|
-
colorBottom: props.colorBottom,
|
|
34
|
-
colorLeft: props.colorLeft,
|
|
35
|
-
colorRight: props.colorLeft,
|
|
36
|
-
fitRectTransform: props.fitRectTransform,
|
|
37
|
-
richText: props.richText,
|
|
38
|
-
alignByGeometry: props.alignByGeometry,
|
|
39
|
-
horizontalOverflow: props.horizontalOverflow,
|
|
40
|
-
verticalOverflow: props.verticalOverflow,
|
|
41
|
-
bestFit: props.bestFit,
|
|
42
|
-
raycastTarget: props.raycastTarget,
|
|
43
|
-
fontStyle: props.fontStyle,
|
|
44
|
-
lineSpacing: props.lineSpacing,
|
|
45
|
-
};
|
|
46
|
-
return _this;
|
|
47
|
-
}
|
|
48
|
-
GradientText.prototype.componentDidUpdate = function () {
|
|
49
|
-
console.log('componentDidUpdate');
|
|
50
|
-
this.updateGradientText();
|
|
51
|
-
};
|
|
52
|
-
GradientText.getDerivedStateFromProps = function (props, state) {
|
|
53
|
-
console.log('getDerivedStateFromProps props:' + JSON.stringify(props));
|
|
54
|
-
console.log('getDerivedStateFromProps old state:' + JSON.stringify(state));
|
|
55
|
-
if (props.text !== state.text ||
|
|
56
|
-
props.color !== state.color ||
|
|
57
|
-
props.fontSize !== state.fontSize ||
|
|
58
|
-
props.alignment !== state.alignment ||
|
|
59
|
-
props.direction !== state.direction ||
|
|
60
|
-
props.colorTop !== state.colorTop ||
|
|
61
|
-
props.colorBottom !== state.colorBottom ||
|
|
62
|
-
props.colorLeft !== state.colorLeft ||
|
|
63
|
-
props.colorRight !== state.colorRight ||
|
|
64
|
-
props.fitRectTransform !== state.fitRectTransform ||
|
|
65
|
-
props.richText !== state.richText ||
|
|
66
|
-
props.alignByGeometry !== state.alignByGeometry ||
|
|
67
|
-
props.horizontalOverflow !== state.horizontalOverflow ||
|
|
68
|
-
props.verticalOverflow !== state.verticalOverflow ||
|
|
69
|
-
props.bestFit !== state.bestFit ||
|
|
70
|
-
props.raycastTarget !== state.raycastTarget ||
|
|
71
|
-
props.fontStyle !== state.fontStyle ||
|
|
72
|
-
props.lineSpacing !== state.lineSpacing) {
|
|
73
|
-
return {
|
|
74
|
-
text: props.text && props.text !== state.text ? props.text : state.text,
|
|
75
|
-
color: props.color && props.color !== state.color ? props.color : state.color,
|
|
76
|
-
fontSize: props.fontSize && props.fontSize !== state.fontSize ? props.fontSize : state.fontSize,
|
|
77
|
-
font: props.font && props.font !== state.font ? props.font : state.font,
|
|
78
|
-
alignment: props.alignment && props.alignment !== state.alignment ? props.alignment : state.alignment,
|
|
79
|
-
direction: props.direction && props.direction !== state.direction ? props.direction : state.direction,
|
|
80
|
-
colorTop: props.colorTop && props.colorTop !== state.colorTop ? props.colorTop : state.colorTop,
|
|
81
|
-
colorBottom: props.colorBottom && props.colorBottom !== state.colorBottom ? props.colorBottom : state.colorBottom,
|
|
82
|
-
colorLeft: props.colorLeft && props.colorLeft !== state.colorLeft ? props.colorLeft : state.colorLeft,
|
|
83
|
-
colorRight: props.colorRight && props.colorRight !== state.colorRight ? props.colorRight : state.colorRight,
|
|
84
|
-
fitRectTransform: props.fitRectTransform && props.fitRectTransform !== state.fitRectTransform ? props.fitRectTransform : state.fitRectTransform,
|
|
85
|
-
richText: props.richText && props.richText !== state.richText ? props.richText : state.richText,
|
|
86
|
-
alignByGeometry: props.alignByGeometry && props.alignByGeometry !== state.alignByGeometry ? props.alignByGeometry : state.alignByGeometry,
|
|
87
|
-
horizontalOverflow: props.horizontalOverflow && props.horizontalOverflow !== state.horizontalOverflow ? props.horizontalOverflow : state.horizontalOverflow,
|
|
88
|
-
verticalOverflow: props.verticalOverflow && props.verticalOverflow !== state.verticalOverflow ? props.verticalOverflow : state.verticalOverflow,
|
|
89
|
-
bestFit: props.bestFit && props.bestFit !== state.bestFit ? props.bestFit : state.bestFit,
|
|
90
|
-
raycastTarget: props.raycastTarget && props.raycastTarget !== state.raycastTarget ? props.raycastTarget : state.raycastTarget,
|
|
91
|
-
fontStyle: props.fontStyle && props.fontStyle !== state.fontStyle ? props.fontStyle : state.fontStyle,
|
|
92
|
-
lineSpacing: props.lineSpacing && props.lineSpacing !== state.lineSpacing ? props.lineSpacing : state.lineSpacing,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
return null;
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
GradientText.prototype.getCSharp = function () {
|
|
100
|
-
if (!window.require) {
|
|
101
|
-
console.error('need puerts env');
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
104
|
-
var CS = window.require('csharp');
|
|
105
|
-
if (!CS) {
|
|
106
|
-
console.error('need puerts env');
|
|
107
|
-
return null;
|
|
108
|
-
}
|
|
109
|
-
return CS;
|
|
110
|
-
};
|
|
111
|
-
GradientText.prototype.onLoad = function (e) {
|
|
112
|
-
this.printLog('OnLoad');
|
|
113
|
-
var CS = this.getCSharp();
|
|
114
|
-
if (CS == null) {
|
|
115
|
-
console.error('Get CS error');
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
var windowId = window.external.id;
|
|
119
|
-
var puerts = window.require('puerts');
|
|
120
|
-
var handle = e.target.attachment.handle;
|
|
121
|
-
var attachment = CS.com.tencent.pandora.CSharpInterface.GetSlotAttachmentByHandle(windowId, handle);
|
|
122
|
-
if (!attachment) {
|
|
123
|
-
console.error("can't get relected attachment, handle:".concat(handle));
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
var placeholder = attachment.GetMountingGameObject();
|
|
127
|
-
this.textObj = placeholder.AddComponent(puerts.$typeof(CS.UnityEngine.UI.Text));
|
|
128
|
-
this.gradientObj = placeholder.AddComponent(puerts.$typeof(CS.UiEffect.GradientColor));
|
|
129
|
-
this.updateGradientText();
|
|
130
|
-
};
|
|
131
|
-
GradientText.prototype.updateGradientText = function () {
|
|
132
|
-
var textStr = !this.state.text || typeof (this.state.text) != 'string' ? '' : this.state.text;
|
|
133
|
-
var color = !this.state.color || typeof (this.state.color) != 'string' ? '#FFFFFFFF' : this.state.color;
|
|
134
|
-
var fontSize = !this.state.fontSize || typeof (this.state.fontSize) != 'number' ? 18 : this.state.fontSize;
|
|
135
|
-
var font = !this.state.font || typeof (this.state.font) != 'string' ? 'gamefont' : this.state.font;
|
|
136
|
-
var alignment = !this.state.alignment || typeof (this.state.alignment) != 'string' ? 'UpperLeft' : this.state.alignment;
|
|
137
|
-
var direction = !this.state.direction || typeof (this.state.direction) != 'string' ? 'Both' : this.state.direction;
|
|
138
|
-
var colorTop = !this.state.colorTop || typeof (this.state.colorTop) != 'string' ? '#FFFFFFFF' : this.state.colorTop;
|
|
139
|
-
var colorBottom = !this.state.colorBottom || typeof (this.state.colorBottom) != 'string' ? '#000000FF' : this.state.colorBottom;
|
|
140
|
-
var colorLeft = !this.state.colorLeft || typeof (this.state.colorLeft) != 'string' ? '#FF0000FF' : this.state.colorLeft;
|
|
141
|
-
var colorRight = !this.state.colorRight || typeof (this.state.colorRight) != 'string' ? '#0000FFFF' : this.state.colorLeft;
|
|
142
|
-
var fitRectTransform = !this.state.fitRectTransform || typeof (this.state.fitRectTransform) != 'boolean' ? false : this.state.fitRectTransform;
|
|
143
|
-
var richText = !this.state.richText || typeof (this.state.richText) != 'boolean' ? true : this.state.richText;
|
|
144
|
-
var alignByGeometry = !this.state.alignByGeometry || typeof (this.state.alignByGeometry) != 'boolean' ? false : this.state.alignByGeometry;
|
|
145
|
-
var horizontalOverflow = !this.state.horizontalOverflow || typeof (this.state.horizontalOverflow) != 'string' ? 'Warp' : this.state.horizontalOverflow;
|
|
146
|
-
var verticalOverflow = !this.state.verticalOverflow || typeof (this.state.verticalOverflow) != 'string' ? 'Truncate' : this.state.verticalOverflow;
|
|
147
|
-
var bestFit = !this.state.bestFit || typeof (this.state.bestFit) != 'boolean' ? false : this.state.bestFit;
|
|
148
|
-
var raycastTarget = !this.state.raycastTarget || typeof (this.state.raycastTarget) != 'boolean' ? true : this.state.raycastTarget;
|
|
149
|
-
var fontStyle = !this.state.fontStyle || typeof (this.state.fontStyle) != 'string' ? 'Normal' : this.state.fontStyle;
|
|
150
|
-
var lineSpacing = !this.state.lineSpacing || typeof (this.state.lineSpacing) != 'number' ? 1 : this.state.lineSpacing;
|
|
151
|
-
if (this.textObj) {
|
|
152
|
-
this.textObj.text = textStr;
|
|
153
|
-
this.textObj.fontSize = fontSize;
|
|
154
|
-
this.textObj.font = this.transFont(font);
|
|
155
|
-
this.textObj.alignment = this.transAlignment(alignment);
|
|
156
|
-
this.textObj.color = this.colorRgb(color);
|
|
157
|
-
this.textObj.richText = richText;
|
|
158
|
-
this.textObj.alignByGeometry = alignByGeometry;
|
|
159
|
-
this.textObj.horizontalOverflow = this.transHorizontalOverflow(horizontalOverflow);
|
|
160
|
-
this.textObj.verticalOverflow = this.transVerticalOverflow(verticalOverflow);
|
|
161
|
-
this.textObj.bestFit = bestFit;
|
|
162
|
-
this.textObj.raycastTarget = raycastTarget;
|
|
163
|
-
this.textObj.fontStyle = this.transFontStyle(fontStyle);
|
|
164
|
-
this.textObj.lineSpacing = lineSpacing;
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
this.printLog('empty CS.UnityEngine.UI.Text');
|
|
168
|
-
}
|
|
169
|
-
if (this.gradientObj) {
|
|
170
|
-
this.gradientObj.direction = this.transDirection(direction);
|
|
171
|
-
this.gradientObj.colorTop = this.colorRgb(colorTop);
|
|
172
|
-
this.gradientObj.colorBottom = this.colorRgb(colorBottom);
|
|
173
|
-
this.gradientObj.colorRight = this.colorRgb(colorRight);
|
|
174
|
-
this.gradientObj.colorLeft = this.colorRgb(colorLeft);
|
|
175
|
-
this.gradientObj.m_fitRectTransform = fitRectTransform;
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
this.printLog('empty CS.UiEffect.GradientColor');
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
GradientText.prototype.transFont = function (fontName) {
|
|
182
|
-
var CS = this.getCSharp();
|
|
183
|
-
return CS.com.tencent.pandora.TextPartner.GetFont.Invoke(fontName);
|
|
184
|
-
};
|
|
185
|
-
GradientText.prototype.transHorizontalOverflow = function (str) {
|
|
186
|
-
var CS = this.getCSharp();
|
|
187
|
-
if (str == 'Warp') {
|
|
188
|
-
return CS.UnityEngine.HorizontalWrapMode.Wrap;
|
|
189
|
-
}
|
|
190
|
-
else if (str == 'Overflow') {
|
|
191
|
-
return CS.UnityEngine.HorizontalWrapMode.Overflow;
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
console.error('invaild HorizontalOverflow');
|
|
195
|
-
return CS.UnityEngine.HorizontalWrapMode.Wrap;
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
GradientText.prototype.transVerticalOverflow = function (str) {
|
|
199
|
-
var CS = this.getCSharp();
|
|
200
|
-
if (str == 'Truncate') {
|
|
201
|
-
return CS.UnityEngine.VerticalWrapMode.Truncate;
|
|
202
|
-
}
|
|
203
|
-
else if (str == 'Overflow') {
|
|
204
|
-
return CS.UnityEngine.VerticalWrapMode.Overflow;
|
|
205
|
-
}
|
|
206
|
-
else {
|
|
207
|
-
console.error('invaild VerticalOverflow');
|
|
208
|
-
return CS.UnityEngine.VerticalWrapMode.Truncate;
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
GradientText.prototype.transFontStyle = function (str) {
|
|
212
|
-
var CS = this.getCSharp();
|
|
213
|
-
if (str == 'Normal') {
|
|
214
|
-
return CS.UnityEngine.FontStyle.Normal;
|
|
215
|
-
}
|
|
216
|
-
else if (str == 'Bold') {
|
|
217
|
-
return CS.UnityEngine.FontStyle.Bold;
|
|
218
|
-
}
|
|
219
|
-
else if (str == 'Italic') {
|
|
220
|
-
return CS.UnityEngine.FontStyle.Italic;
|
|
221
|
-
}
|
|
222
|
-
else if (str == 'BoldAndItalic') {
|
|
223
|
-
return CS.UnityEngine.FontStyle.BoldAndItalic;
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
console.error('invaild FontStyle');
|
|
227
|
-
return CS.UnityEngine.FontStyle.Normal;
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
GradientText.prototype.colorRgb = function (colorStr) {
|
|
231
|
-
this.printLog("colorList[i]/255[".concat(0 / 255, "]"));
|
|
232
|
-
this.printLog("colorStr[".concat(colorStr, "]"));
|
|
233
|
-
//十六进制颜色值的正则表达式
|
|
234
|
-
var reg = /^#([0-9a-fA-f]{0,}|)$/;
|
|
235
|
-
var matchRes = colorStr.toString().toLowerCase().match(reg);
|
|
236
|
-
var transColor = '';
|
|
237
|
-
this.printLog("matchRes".concat(JSON.stringify(matchRes)));
|
|
238
|
-
if (matchRes.length > 0)
|
|
239
|
-
transColor = matchRes[matchRes.length - 1];
|
|
240
|
-
var colorList = [];
|
|
241
|
-
while (transColor != '') {
|
|
242
|
-
var hex = '0x' + transColor.substring(0, 2);
|
|
243
|
-
this.printLog("hex[".concat(hex, "]"));
|
|
244
|
-
colorList.push(parseInt(hex, 16));
|
|
245
|
-
transColor = transColor.substring(2, transColor.length);
|
|
246
|
-
}
|
|
247
|
-
var r, g, b, a = 1;
|
|
248
|
-
for (var i = 0; i < colorList.length; i++) {
|
|
249
|
-
this.printLog("colorList i[".concat(i, "]item[").concat(colorList[i], "]"));
|
|
250
|
-
if (i == 0 && colorList[i] != null && colorList[i] != undefined) {
|
|
251
|
-
r = colorList[i] / 255;
|
|
252
|
-
}
|
|
253
|
-
if (i == 1 && colorList[i] != null && colorList[i] != undefined) {
|
|
254
|
-
g = colorList[i] / 255;
|
|
255
|
-
}
|
|
256
|
-
if (i == 2 && colorList[i] != null && colorList[i] != undefined) {
|
|
257
|
-
b = colorList[i] / 255;
|
|
258
|
-
}
|
|
259
|
-
if (i == 3 && colorList[i] != null && colorList[i] != undefined) {
|
|
260
|
-
a = colorList[i] / 255;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
this.printLog("New Color r[".concat(r, "]g[").concat(g, "]b[").concat(b, "]a[").concat(a, "]"));
|
|
264
|
-
var CS = this.getCSharp();
|
|
265
|
-
return CS.UnityEngine.Color(r, g, b, a);
|
|
266
|
-
};
|
|
267
|
-
GradientText.prototype.printLog = function (text) {
|
|
268
|
-
if (this.isPrintLog) {
|
|
269
|
-
console.log(text);
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
GradientText.prototype.transDirection = function (direction) {
|
|
273
|
-
var CS = this.getCSharp();
|
|
274
|
-
if (direction == 'Both') {
|
|
275
|
-
return CS.UiEffect.GradientColor.DIRECTION.Both;
|
|
276
|
-
}
|
|
277
|
-
else if (direction == 'Vertical') {
|
|
278
|
-
return CS.UiEffect.GradientColor.DIRECTION.Vertical;
|
|
279
|
-
}
|
|
280
|
-
else if (direction == 'Horizontal') {
|
|
281
|
-
return CS.UiEffect.GradientColor.DIRECTION.Horizontal;
|
|
282
|
-
}
|
|
283
|
-
else {
|
|
284
|
-
console.error('invaild direction');
|
|
285
|
-
return CS.UiEffect.GradientColor.DIRECTION.Both;
|
|
286
|
-
}
|
|
287
|
-
};
|
|
288
|
-
GradientText.prototype.transAlignment = function (alignment) {
|
|
289
|
-
var CS = this.getCSharp();
|
|
290
|
-
if (alignment == 'UpperLeft') {
|
|
291
|
-
return CS.UnityEngine.TextAnchor.UpperLeft;
|
|
292
|
-
}
|
|
293
|
-
else if (alignment == 'UpperCenter') {
|
|
294
|
-
return CS.UnityEngine.TextAnchor.UpperCenter;
|
|
295
|
-
}
|
|
296
|
-
else if (alignment == 'UpperRight') {
|
|
297
|
-
return CS.UnityEngine.TextAnchor.UpperRight;
|
|
298
|
-
}
|
|
299
|
-
else if (alignment == 'MiddleCenter') {
|
|
300
|
-
return CS.UnityEngine.TextAnchor.MiddleCenter;
|
|
301
|
-
}
|
|
302
|
-
else if (alignment == 'MiddleLeft') {
|
|
303
|
-
return CS.UnityEngine.TextAnchor.MiddleLeft;
|
|
304
|
-
}
|
|
305
|
-
else if (alignment == 'MiddleRight') {
|
|
306
|
-
return CS.UnityEngine.TextAnchor.MiddleRight;
|
|
307
|
-
}
|
|
308
|
-
else if (alignment == 'LowerLeft') {
|
|
309
|
-
return CS.UnityEngine.TextAnchor.LowerLeft;
|
|
310
|
-
}
|
|
311
|
-
else if (alignment == 'LowerCenter') {
|
|
312
|
-
return CS.UnityEngine.TextAnchor.LowerCenter;
|
|
313
|
-
}
|
|
314
|
-
else if (alignment == 'LowerRight') {
|
|
315
|
-
return CS.UnityEngine.TextAnchor.LowerRight;
|
|
316
|
-
}
|
|
317
|
-
else {
|
|
318
|
-
console.error('invaild alignment');
|
|
319
|
-
return CS.UnityEngine.TextAnchor.UpperLeft;
|
|
320
|
-
}
|
|
321
|
-
};
|
|
322
|
-
GradientText.prototype.render = function (props) {
|
|
323
|
-
var style = !props.style ? { width: '200px', height: '200px', backgroundColor: '#FF00FFFF' } : props.style;
|
|
324
|
-
this.printLog('OnRender');
|
|
325
|
-
return (h("pixslot", { style: style, src: 'pixui://method:placeholder', onLoad: this.onLoad.bind(this) }));
|
|
326
|
-
};
|
|
327
|
-
return GradientText;
|
|
328
|
-
}(Component));
|
|
329
|
-
export { GradientText };
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
import { Component, h } from 'preact';
|
|
17
|
+
var GradientText = /** @class */ (function (_super) {
|
|
18
|
+
__extends(GradientText, _super);
|
|
19
|
+
function GradientText(props) {
|
|
20
|
+
var _this = _super.call(this, props) || this;
|
|
21
|
+
_this.isPrintLog = false;
|
|
22
|
+
_this.textObj = null;
|
|
23
|
+
_this.gradientObj = null;
|
|
24
|
+
_this.state = {
|
|
25
|
+
style: props.style,
|
|
26
|
+
text: props.text,
|
|
27
|
+
color: props.color,
|
|
28
|
+
fontSize: props.fontSize,
|
|
29
|
+
font: props.font,
|
|
30
|
+
alignment: props.alignment,
|
|
31
|
+
direction: props.direction,
|
|
32
|
+
colorTop: props.colorTop,
|
|
33
|
+
colorBottom: props.colorBottom,
|
|
34
|
+
colorLeft: props.colorLeft,
|
|
35
|
+
colorRight: props.colorLeft,
|
|
36
|
+
fitRectTransform: props.fitRectTransform,
|
|
37
|
+
richText: props.richText,
|
|
38
|
+
alignByGeometry: props.alignByGeometry,
|
|
39
|
+
horizontalOverflow: props.horizontalOverflow,
|
|
40
|
+
verticalOverflow: props.verticalOverflow,
|
|
41
|
+
bestFit: props.bestFit,
|
|
42
|
+
raycastTarget: props.raycastTarget,
|
|
43
|
+
fontStyle: props.fontStyle,
|
|
44
|
+
lineSpacing: props.lineSpacing,
|
|
45
|
+
};
|
|
46
|
+
return _this;
|
|
47
|
+
}
|
|
48
|
+
GradientText.prototype.componentDidUpdate = function () {
|
|
49
|
+
console.log('componentDidUpdate');
|
|
50
|
+
this.updateGradientText();
|
|
51
|
+
};
|
|
52
|
+
GradientText.getDerivedStateFromProps = function (props, state) {
|
|
53
|
+
console.log('getDerivedStateFromProps props:' + JSON.stringify(props));
|
|
54
|
+
console.log('getDerivedStateFromProps old state:' + JSON.stringify(state));
|
|
55
|
+
if (props.text !== state.text ||
|
|
56
|
+
props.color !== state.color ||
|
|
57
|
+
props.fontSize !== state.fontSize ||
|
|
58
|
+
props.alignment !== state.alignment ||
|
|
59
|
+
props.direction !== state.direction ||
|
|
60
|
+
props.colorTop !== state.colorTop ||
|
|
61
|
+
props.colorBottom !== state.colorBottom ||
|
|
62
|
+
props.colorLeft !== state.colorLeft ||
|
|
63
|
+
props.colorRight !== state.colorRight ||
|
|
64
|
+
props.fitRectTransform !== state.fitRectTransform ||
|
|
65
|
+
props.richText !== state.richText ||
|
|
66
|
+
props.alignByGeometry !== state.alignByGeometry ||
|
|
67
|
+
props.horizontalOverflow !== state.horizontalOverflow ||
|
|
68
|
+
props.verticalOverflow !== state.verticalOverflow ||
|
|
69
|
+
props.bestFit !== state.bestFit ||
|
|
70
|
+
props.raycastTarget !== state.raycastTarget ||
|
|
71
|
+
props.fontStyle !== state.fontStyle ||
|
|
72
|
+
props.lineSpacing !== state.lineSpacing) {
|
|
73
|
+
return {
|
|
74
|
+
text: props.text && props.text !== state.text ? props.text : state.text,
|
|
75
|
+
color: props.color && props.color !== state.color ? props.color : state.color,
|
|
76
|
+
fontSize: props.fontSize && props.fontSize !== state.fontSize ? props.fontSize : state.fontSize,
|
|
77
|
+
font: props.font && props.font !== state.font ? props.font : state.font,
|
|
78
|
+
alignment: props.alignment && props.alignment !== state.alignment ? props.alignment : state.alignment,
|
|
79
|
+
direction: props.direction && props.direction !== state.direction ? props.direction : state.direction,
|
|
80
|
+
colorTop: props.colorTop && props.colorTop !== state.colorTop ? props.colorTop : state.colorTop,
|
|
81
|
+
colorBottom: props.colorBottom && props.colorBottom !== state.colorBottom ? props.colorBottom : state.colorBottom,
|
|
82
|
+
colorLeft: props.colorLeft && props.colorLeft !== state.colorLeft ? props.colorLeft : state.colorLeft,
|
|
83
|
+
colorRight: props.colorRight && props.colorRight !== state.colorRight ? props.colorRight : state.colorRight,
|
|
84
|
+
fitRectTransform: props.fitRectTransform && props.fitRectTransform !== state.fitRectTransform ? props.fitRectTransform : state.fitRectTransform,
|
|
85
|
+
richText: props.richText && props.richText !== state.richText ? props.richText : state.richText,
|
|
86
|
+
alignByGeometry: props.alignByGeometry && props.alignByGeometry !== state.alignByGeometry ? props.alignByGeometry : state.alignByGeometry,
|
|
87
|
+
horizontalOverflow: props.horizontalOverflow && props.horizontalOverflow !== state.horizontalOverflow ? props.horizontalOverflow : state.horizontalOverflow,
|
|
88
|
+
verticalOverflow: props.verticalOverflow && props.verticalOverflow !== state.verticalOverflow ? props.verticalOverflow : state.verticalOverflow,
|
|
89
|
+
bestFit: props.bestFit && props.bestFit !== state.bestFit ? props.bestFit : state.bestFit,
|
|
90
|
+
raycastTarget: props.raycastTarget && props.raycastTarget !== state.raycastTarget ? props.raycastTarget : state.raycastTarget,
|
|
91
|
+
fontStyle: props.fontStyle && props.fontStyle !== state.fontStyle ? props.fontStyle : state.fontStyle,
|
|
92
|
+
lineSpacing: props.lineSpacing && props.lineSpacing !== state.lineSpacing ? props.lineSpacing : state.lineSpacing,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
GradientText.prototype.getCSharp = function () {
|
|
100
|
+
if (!window.require) {
|
|
101
|
+
console.error('need puerts env');
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
var CS = window.require('csharp');
|
|
105
|
+
if (!CS) {
|
|
106
|
+
console.error('need puerts env');
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
return CS;
|
|
110
|
+
};
|
|
111
|
+
GradientText.prototype.onLoad = function (e) {
|
|
112
|
+
this.printLog('OnLoad');
|
|
113
|
+
var CS = this.getCSharp();
|
|
114
|
+
if (CS == null) {
|
|
115
|
+
console.error('Get CS error');
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
var windowId = window.external.id;
|
|
119
|
+
var puerts = window.require('puerts');
|
|
120
|
+
var handle = e.target.attachment.handle;
|
|
121
|
+
var attachment = CS.com.tencent.pandora.CSharpInterface.GetSlotAttachmentByHandle(windowId, handle);
|
|
122
|
+
if (!attachment) {
|
|
123
|
+
console.error("can't get relected attachment, handle:".concat(handle));
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
var placeholder = attachment.GetMountingGameObject();
|
|
127
|
+
this.textObj = placeholder.AddComponent(puerts.$typeof(CS.UnityEngine.UI.Text));
|
|
128
|
+
this.gradientObj = placeholder.AddComponent(puerts.$typeof(CS.UiEffect.GradientColor));
|
|
129
|
+
this.updateGradientText();
|
|
130
|
+
};
|
|
131
|
+
GradientText.prototype.updateGradientText = function () {
|
|
132
|
+
var textStr = !this.state.text || typeof (this.state.text) != 'string' ? '' : this.state.text;
|
|
133
|
+
var color = !this.state.color || typeof (this.state.color) != 'string' ? '#FFFFFFFF' : this.state.color;
|
|
134
|
+
var fontSize = !this.state.fontSize || typeof (this.state.fontSize) != 'number' ? 18 : this.state.fontSize;
|
|
135
|
+
var font = !this.state.font || typeof (this.state.font) != 'string' ? 'gamefont' : this.state.font;
|
|
136
|
+
var alignment = !this.state.alignment || typeof (this.state.alignment) != 'string' ? 'UpperLeft' : this.state.alignment;
|
|
137
|
+
var direction = !this.state.direction || typeof (this.state.direction) != 'string' ? 'Both' : this.state.direction;
|
|
138
|
+
var colorTop = !this.state.colorTop || typeof (this.state.colorTop) != 'string' ? '#FFFFFFFF' : this.state.colorTop;
|
|
139
|
+
var colorBottom = !this.state.colorBottom || typeof (this.state.colorBottom) != 'string' ? '#000000FF' : this.state.colorBottom;
|
|
140
|
+
var colorLeft = !this.state.colorLeft || typeof (this.state.colorLeft) != 'string' ? '#FF0000FF' : this.state.colorLeft;
|
|
141
|
+
var colorRight = !this.state.colorRight || typeof (this.state.colorRight) != 'string' ? '#0000FFFF' : this.state.colorLeft;
|
|
142
|
+
var fitRectTransform = !this.state.fitRectTransform || typeof (this.state.fitRectTransform) != 'boolean' ? false : this.state.fitRectTransform;
|
|
143
|
+
var richText = !this.state.richText || typeof (this.state.richText) != 'boolean' ? true : this.state.richText;
|
|
144
|
+
var alignByGeometry = !this.state.alignByGeometry || typeof (this.state.alignByGeometry) != 'boolean' ? false : this.state.alignByGeometry;
|
|
145
|
+
var horizontalOverflow = !this.state.horizontalOverflow || typeof (this.state.horizontalOverflow) != 'string' ? 'Warp' : this.state.horizontalOverflow;
|
|
146
|
+
var verticalOverflow = !this.state.verticalOverflow || typeof (this.state.verticalOverflow) != 'string' ? 'Truncate' : this.state.verticalOverflow;
|
|
147
|
+
var bestFit = !this.state.bestFit || typeof (this.state.bestFit) != 'boolean' ? false : this.state.bestFit;
|
|
148
|
+
var raycastTarget = !this.state.raycastTarget || typeof (this.state.raycastTarget) != 'boolean' ? true : this.state.raycastTarget;
|
|
149
|
+
var fontStyle = !this.state.fontStyle || typeof (this.state.fontStyle) != 'string' ? 'Normal' : this.state.fontStyle;
|
|
150
|
+
var lineSpacing = !this.state.lineSpacing || typeof (this.state.lineSpacing) != 'number' ? 1 : this.state.lineSpacing;
|
|
151
|
+
if (this.textObj) {
|
|
152
|
+
this.textObj.text = textStr;
|
|
153
|
+
this.textObj.fontSize = fontSize;
|
|
154
|
+
this.textObj.font = this.transFont(font);
|
|
155
|
+
this.textObj.alignment = this.transAlignment(alignment);
|
|
156
|
+
this.textObj.color = this.colorRgb(color);
|
|
157
|
+
this.textObj.richText = richText;
|
|
158
|
+
this.textObj.alignByGeometry = alignByGeometry;
|
|
159
|
+
this.textObj.horizontalOverflow = this.transHorizontalOverflow(horizontalOverflow);
|
|
160
|
+
this.textObj.verticalOverflow = this.transVerticalOverflow(verticalOverflow);
|
|
161
|
+
this.textObj.bestFit = bestFit;
|
|
162
|
+
this.textObj.raycastTarget = raycastTarget;
|
|
163
|
+
this.textObj.fontStyle = this.transFontStyle(fontStyle);
|
|
164
|
+
this.textObj.lineSpacing = lineSpacing;
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
this.printLog('empty CS.UnityEngine.UI.Text');
|
|
168
|
+
}
|
|
169
|
+
if (this.gradientObj) {
|
|
170
|
+
this.gradientObj.direction = this.transDirection(direction);
|
|
171
|
+
this.gradientObj.colorTop = this.colorRgb(colorTop);
|
|
172
|
+
this.gradientObj.colorBottom = this.colorRgb(colorBottom);
|
|
173
|
+
this.gradientObj.colorRight = this.colorRgb(colorRight);
|
|
174
|
+
this.gradientObj.colorLeft = this.colorRgb(colorLeft);
|
|
175
|
+
this.gradientObj.m_fitRectTransform = fitRectTransform;
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
this.printLog('empty CS.UiEffect.GradientColor');
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
GradientText.prototype.transFont = function (fontName) {
|
|
182
|
+
var CS = this.getCSharp();
|
|
183
|
+
return CS.com.tencent.pandora.TextPartner.GetFont.Invoke(fontName);
|
|
184
|
+
};
|
|
185
|
+
GradientText.prototype.transHorizontalOverflow = function (str) {
|
|
186
|
+
var CS = this.getCSharp();
|
|
187
|
+
if (str == 'Warp') {
|
|
188
|
+
return CS.UnityEngine.HorizontalWrapMode.Wrap;
|
|
189
|
+
}
|
|
190
|
+
else if (str == 'Overflow') {
|
|
191
|
+
return CS.UnityEngine.HorizontalWrapMode.Overflow;
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
console.error('invaild HorizontalOverflow');
|
|
195
|
+
return CS.UnityEngine.HorizontalWrapMode.Wrap;
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
GradientText.prototype.transVerticalOverflow = function (str) {
|
|
199
|
+
var CS = this.getCSharp();
|
|
200
|
+
if (str == 'Truncate') {
|
|
201
|
+
return CS.UnityEngine.VerticalWrapMode.Truncate;
|
|
202
|
+
}
|
|
203
|
+
else if (str == 'Overflow') {
|
|
204
|
+
return CS.UnityEngine.VerticalWrapMode.Overflow;
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
console.error('invaild VerticalOverflow');
|
|
208
|
+
return CS.UnityEngine.VerticalWrapMode.Truncate;
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
GradientText.prototype.transFontStyle = function (str) {
|
|
212
|
+
var CS = this.getCSharp();
|
|
213
|
+
if (str == 'Normal') {
|
|
214
|
+
return CS.UnityEngine.FontStyle.Normal;
|
|
215
|
+
}
|
|
216
|
+
else if (str == 'Bold') {
|
|
217
|
+
return CS.UnityEngine.FontStyle.Bold;
|
|
218
|
+
}
|
|
219
|
+
else if (str == 'Italic') {
|
|
220
|
+
return CS.UnityEngine.FontStyle.Italic;
|
|
221
|
+
}
|
|
222
|
+
else if (str == 'BoldAndItalic') {
|
|
223
|
+
return CS.UnityEngine.FontStyle.BoldAndItalic;
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
console.error('invaild FontStyle');
|
|
227
|
+
return CS.UnityEngine.FontStyle.Normal;
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
GradientText.prototype.colorRgb = function (colorStr) {
|
|
231
|
+
this.printLog("colorList[i]/255[".concat(0 / 255, "]"));
|
|
232
|
+
this.printLog("colorStr[".concat(colorStr, "]"));
|
|
233
|
+
//十六进制颜色值的正则表达式
|
|
234
|
+
var reg = /^#([0-9a-fA-f]{0,}|)$/;
|
|
235
|
+
var matchRes = colorStr.toString().toLowerCase().match(reg);
|
|
236
|
+
var transColor = '';
|
|
237
|
+
this.printLog("matchRes".concat(JSON.stringify(matchRes)));
|
|
238
|
+
if (matchRes.length > 0)
|
|
239
|
+
transColor = matchRes[matchRes.length - 1];
|
|
240
|
+
var colorList = [];
|
|
241
|
+
while (transColor != '') {
|
|
242
|
+
var hex = '0x' + transColor.substring(0, 2);
|
|
243
|
+
this.printLog("hex[".concat(hex, "]"));
|
|
244
|
+
colorList.push(parseInt(hex, 16));
|
|
245
|
+
transColor = transColor.substring(2, transColor.length);
|
|
246
|
+
}
|
|
247
|
+
var r, g, b, a = 1;
|
|
248
|
+
for (var i = 0; i < colorList.length; i++) {
|
|
249
|
+
this.printLog("colorList i[".concat(i, "]item[").concat(colorList[i], "]"));
|
|
250
|
+
if (i == 0 && colorList[i] != null && colorList[i] != undefined) {
|
|
251
|
+
r = colorList[i] / 255;
|
|
252
|
+
}
|
|
253
|
+
if (i == 1 && colorList[i] != null && colorList[i] != undefined) {
|
|
254
|
+
g = colorList[i] / 255;
|
|
255
|
+
}
|
|
256
|
+
if (i == 2 && colorList[i] != null && colorList[i] != undefined) {
|
|
257
|
+
b = colorList[i] / 255;
|
|
258
|
+
}
|
|
259
|
+
if (i == 3 && colorList[i] != null && colorList[i] != undefined) {
|
|
260
|
+
a = colorList[i] / 255;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
this.printLog("New Color r[".concat(r, "]g[").concat(g, "]b[").concat(b, "]a[").concat(a, "]"));
|
|
264
|
+
var CS = this.getCSharp();
|
|
265
|
+
return CS.UnityEngine.Color(r, g, b, a);
|
|
266
|
+
};
|
|
267
|
+
GradientText.prototype.printLog = function (text) {
|
|
268
|
+
if (this.isPrintLog) {
|
|
269
|
+
console.log(text);
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
GradientText.prototype.transDirection = function (direction) {
|
|
273
|
+
var CS = this.getCSharp();
|
|
274
|
+
if (direction == 'Both') {
|
|
275
|
+
return CS.UiEffect.GradientColor.DIRECTION.Both;
|
|
276
|
+
}
|
|
277
|
+
else if (direction == 'Vertical') {
|
|
278
|
+
return CS.UiEffect.GradientColor.DIRECTION.Vertical;
|
|
279
|
+
}
|
|
280
|
+
else if (direction == 'Horizontal') {
|
|
281
|
+
return CS.UiEffect.GradientColor.DIRECTION.Horizontal;
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
console.error('invaild direction');
|
|
285
|
+
return CS.UiEffect.GradientColor.DIRECTION.Both;
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
GradientText.prototype.transAlignment = function (alignment) {
|
|
289
|
+
var CS = this.getCSharp();
|
|
290
|
+
if (alignment == 'UpperLeft') {
|
|
291
|
+
return CS.UnityEngine.TextAnchor.UpperLeft;
|
|
292
|
+
}
|
|
293
|
+
else if (alignment == 'UpperCenter') {
|
|
294
|
+
return CS.UnityEngine.TextAnchor.UpperCenter;
|
|
295
|
+
}
|
|
296
|
+
else if (alignment == 'UpperRight') {
|
|
297
|
+
return CS.UnityEngine.TextAnchor.UpperRight;
|
|
298
|
+
}
|
|
299
|
+
else if (alignment == 'MiddleCenter') {
|
|
300
|
+
return CS.UnityEngine.TextAnchor.MiddleCenter;
|
|
301
|
+
}
|
|
302
|
+
else if (alignment == 'MiddleLeft') {
|
|
303
|
+
return CS.UnityEngine.TextAnchor.MiddleLeft;
|
|
304
|
+
}
|
|
305
|
+
else if (alignment == 'MiddleRight') {
|
|
306
|
+
return CS.UnityEngine.TextAnchor.MiddleRight;
|
|
307
|
+
}
|
|
308
|
+
else if (alignment == 'LowerLeft') {
|
|
309
|
+
return CS.UnityEngine.TextAnchor.LowerLeft;
|
|
310
|
+
}
|
|
311
|
+
else if (alignment == 'LowerCenter') {
|
|
312
|
+
return CS.UnityEngine.TextAnchor.LowerCenter;
|
|
313
|
+
}
|
|
314
|
+
else if (alignment == 'LowerRight') {
|
|
315
|
+
return CS.UnityEngine.TextAnchor.LowerRight;
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
console.error('invaild alignment');
|
|
319
|
+
return CS.UnityEngine.TextAnchor.UpperLeft;
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
GradientText.prototype.render = function (props) {
|
|
323
|
+
var style = !props.style ? { width: '200px', height: '200px', backgroundColor: '#FF00FFFF' } : props.style;
|
|
324
|
+
this.printLog('OnRender');
|
|
325
|
+
return (h("pixslot", { style: style, src: 'pixui://method:placeholder', onLoad: this.onLoad.bind(this) }));
|
|
326
|
+
};
|
|
327
|
+
return GradientText;
|
|
328
|
+
}(Component));
|
|
329
|
+
export { GradientText };
|