@urso/core 0.6.14 → 0.6.16-dev
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/.babelrc +11 -11
- package/LICENSE +20 -20
- package/README.md +227 -227
- package/build/js/index.js +1 -1
- package/build/js/index.js.LICENSE.txt +270 -38
- package/package.json +52 -52
- package/src/js/app.js +79 -79
- package/src/js/components/_info.js +11 -11
- package/src/js/components/base/_info.js +3 -3
- package/src/js/components/base/controller.js +78 -78
- package/src/js/components/debug/_info.js +7 -7
- package/src/js/components/debug/controller.js +38 -38
- package/src/js/components/debug/coords.js +23 -23
- package/src/js/components/debug/fps.js +36 -36
- package/src/js/components/debug/template.js +55 -55
- package/src/js/components/debug/timescale.js +60 -60
- package/src/js/components/deviceRotate/_info.js +3 -3
- package/src/js/components/deviceRotate/controller.js +86 -86
- package/src/js/components/fullscreen/_info.js +6 -6
- package/src/js/components/fullscreen/android.js +104 -104
- package/src/js/components/fullscreen/controller.js +76 -76
- package/src/js/components/fullscreen/desktop.js +49 -49
- package/src/js/components/fullscreen/ios.js +115 -115
- package/src/js/components/layersSwitcher/_info.js +4 -4
- package/src/js/components/layersSwitcher/config.js +26 -26
- package/src/js/components/layersSwitcher/controller.js +34 -34
- package/src/js/components/loader/_info.js +4 -4
- package/src/js/components/loader/controller.js +65 -65
- package/src/js/components/loader/template.js +70 -70
- package/src/js/components/soundInitialPopup/_info.js +3 -3
- package/src/js/components/soundInitialPopup/controller.js +42 -42
- package/src/js/components/soundInitialPopup/template.js +109 -109
- package/src/js/components/stateDriven/_info.js +3 -3
- package/src/js/components/stateDriven/controller.js +118 -118
- package/src/js/config/load.js +5 -5
- package/src/js/config/main.js +16 -16
- package/src/js/extra/_info.js +26 -26
- package/src/js/extra/browserEvents.js +51 -51
- package/src/js/extra/pixiPatch.js +150 -150
- package/src/js/extra/setTimeout.js +7 -7
- package/src/js/index.js +8 -8
- package/src/js/lib/_info.js +13 -13
- package/src/js/lib/cache.js +105 -105
- package/src/js/lib/composition.js +85 -85
- package/src/js/lib/device.js +1286 -1286
- package/src/js/lib/helper.js +556 -556
- package/src/js/lib/loader.js +136 -136
- package/src/js/lib/localData.js +15 -15
- package/src/js/lib/logger.js +69 -69
- package/src/js/lib/math.js +35 -35
- package/src/js/lib/objectPool.js +203 -203
- package/src/js/lib/time.js +18 -18
- package/src/js/lib/tween.js +147 -147
- package/src/js/modules/_info.js +12 -12
- package/src/js/modules/assets/_info.js +7 -7
- package/src/js/modules/assets/baseModel.js +20 -20
- package/src/js/modules/assets/config.js +37 -37
- package/src/js/modules/assets/controller.js +46 -46
- package/src/js/modules/assets/models/_info.js +11 -11
- package/src/js/modules/assets/models/atlas.js +8 -8
- package/src/js/modules/assets/models/audiosprite.js +27 -27
- package/src/js/modules/assets/models/bitmapFont.js +8 -8
- package/src/js/modules/assets/models/container.js +16 -16
- package/src/js/modules/assets/models/font.js +8 -8
- package/src/js/modules/assets/models/image.js +15 -15
- package/src/js/modules/assets/models/json.js +8 -8
- package/src/js/modules/assets/models/sound.js +14 -14
- package/src/js/modules/assets/models/spine.js +14 -14
- package/src/js/modules/assets/service.js +366 -366
- package/src/js/modules/i18n/_info.js +4 -4
- package/src/js/modules/i18n/config.js +17 -17
- package/src/js/modules/i18n/controller.js +79 -79
- package/src/js/modules/instances/_info.js +3 -3
- package/src/js/modules/instances/controller.js +357 -357
- package/src/js/modules/logic/_info.js +4 -4
- package/src/js/modules/logic/config/_info.js +2 -2
- package/src/js/modules/logic/config/sounds.js +23 -23
- package/src/js/modules/logic/controller.js +48 -48
- package/src/js/modules/logic/sounds.js +103 -103
- package/src/js/modules/objects/_info.js +13 -13
- package/src/js/modules/objects/baseModel.js +200 -200
- package/src/js/modules/objects/cache.js +99 -99
- package/src/js/modules/objects/controller.js +131 -131
- package/src/js/modules/objects/find.js +58 -58
- package/src/js/modules/objects/models/_info.js +27 -27
- package/src/js/modules/objects/models/atlasImage.js +50 -50
- package/src/js/modules/objects/models/bitmapText.js +37 -37
- package/src/js/modules/objects/models/button.js +189 -189
- package/src/js/modules/objects/models/buttonComposite.js +35 -35
- package/src/js/modules/objects/models/checkbox.js +96 -96
- package/src/js/modules/objects/models/collection.js +54 -54
- package/src/js/modules/objects/models/component.js +46 -46
- package/src/js/modules/objects/models/container.js +19 -19
- package/src/js/modules/objects/models/dragContainer.js +667 -667
- package/src/js/modules/objects/models/emitter.js +67 -67
- package/src/js/modules/objects/models/emitterFx.js +99 -99
- package/src/js/modules/objects/models/graphics.js +38 -38
- package/src/js/modules/objects/models/group.js +19 -19
- package/src/js/modules/objects/models/hitArea.js +104 -104
- package/src/js/modules/objects/models/image.js +34 -34
- package/src/js/modules/objects/models/imagesAnimation.js +113 -113
- package/src/js/modules/objects/models/mask.js +38 -38
- package/src/js/modules/objects/models/nineSlicePlane.js +30 -30
- package/src/js/modules/objects/models/scrollbox.js +64 -64
- package/src/js/modules/objects/models/slider.js +253 -253
- package/src/js/modules/objects/models/spine.js +287 -287
- package/src/js/modules/objects/models/text.js +59 -59
- package/src/js/modules/objects/models/textInput.js +66 -66
- package/src/js/modules/objects/models/toggle.js +180 -180
- package/src/js/modules/objects/models/world.js +19 -19
- package/src/js/modules/objects/propertyAdapter.js +587 -587
- package/src/js/modules/objects/proxy.js +294 -294
- package/src/js/modules/objects/selector.js +136 -136
- package/src/js/modules/objects/service.js +242 -242
- package/src/js/modules/objects/styles.js +210 -210
- package/src/js/modules/observer/_info.js +4 -4
- package/src/js/modules/observer/controller.js +99 -99
- package/src/js/modules/observer/events.js +52 -52
- package/src/js/modules/scenes/_info.js +8 -8
- package/src/js/modules/scenes/controller.js +119 -119
- package/src/js/modules/scenes/model.js +28 -28
- package/src/js/modules/scenes/pixiWrapper.js +336 -336
- package/src/js/modules/scenes/resolutions.js +173 -173
- package/src/js/modules/scenes/resolutionsConfig.js +73 -73
- package/src/js/modules/scenes/service.js +142 -142
- package/src/js/modules/soundManager/_info.js +3 -3
- package/src/js/modules/soundManager/controller.js +100 -100
- package/src/js/modules/soundManager/soundSprite.js +251 -251
- package/src/js/modules/statesManager/_info.js +12 -12
- package/src/js/modules/statesManager/action.js +68 -68
- package/src/js/modules/statesManager/actions/_info.js +3 -3
- package/src/js/modules/statesManager/all.js +23 -23
- package/src/js/modules/statesManager/configStates.js +71 -71
- package/src/js/modules/statesManager/controller.js +170 -170
- package/src/js/modules/statesManager/functionsStorage.js +82 -82
- package/src/js/modules/statesManager/helper.js +27 -27
- package/src/js/modules/statesManager/race.js +75 -75
- package/src/js/modules/statesManager/sequence.js +47 -47
- package/src/js/modules/template/_info.js +6 -6
- package/src/js/modules/template/controller.js +28 -28
- package/src/js/modules/template/model.js +11 -11
- package/src/js/modules/template/service.js +137 -137
- package/src/js/modules/template/types.js +46 -46
- package/src/js/modules/transport/_info.js +8 -8
- package/src/js/modules/transport/baseConnectionType.js +24 -24
- package/src/js/modules/transport/config.js +13 -13
- package/src/js/modules/transport/connectionTypes/_info.js +3 -3
- package/src/js/modules/transport/connectionTypes/websocket.js +74 -74
- package/src/js/modules/transport/connectionTypes/xhr.js +44 -44
- package/src/js/modules/transport/controller.js +48 -48
- package/src/js/modules/transport/decorator.js +17 -17
- package/src/js/modules/transport/service.js +153 -153
- package/src/js/templates/_info.js +4 -4
- package/src/js/templates/groups/_info.js +1 -1
- package/src/js/templates/scenes/_info.js +1 -1
- package/webpack.config.js +47 -47
|
@@ -1,253 +1,253 @@
|
|
|
1
|
-
class ModulesObjectsModelsSlider extends Urso.Core.Modules.Objects.BaseModel {
|
|
2
|
-
constructor(params) {
|
|
3
|
-
super(params);
|
|
4
|
-
|
|
5
|
-
this.type = Urso.types.objects.SLIDER;
|
|
6
|
-
this._sliderBg = null;
|
|
7
|
-
this._sliderHandle = null;
|
|
8
|
-
this._baseObject = null;
|
|
9
|
-
this._handleIsPulling = false;
|
|
10
|
-
this._points = [];
|
|
11
|
-
this._addBaseObject();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
setupParams(params) {
|
|
15
|
-
super.setupParams(params);
|
|
16
|
-
this.contents = [];
|
|
17
|
-
this.points = Urso.helper.recursiveGet('points', params, [0, 1]);
|
|
18
|
-
this.defaultValue = Urso.helper.recursiveGet('defaultValue', params, false);
|
|
19
|
-
this.bgTexture = Urso.helper.recursiveGet('bgTexture', params, false);
|
|
20
|
-
this.fillTexture = Urso.helper.recursiveGet('fillTexture', params, false);
|
|
21
|
-
this.handleTexture = Urso.helper.recursiveGet('handleTexture', params, false);
|
|
22
|
-
this.minValueTextModel = Urso.helper.recursiveGet('minValueTextModel', params, false);
|
|
23
|
-
this.maxValueTextModel = Urso.helper.recursiveGet('maxValueTextModel', params, false);
|
|
24
|
-
this.currentValueTextModel = Urso.helper.recursiveGet('currentValueTextModel', params, false);
|
|
25
|
-
this.isVertical = Urso.helper.recursiveGet('isVertical', params, false);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
_setVariables() {
|
|
29
|
-
if (this.isVertical) {
|
|
30
|
-
this.positionKey = 'y';
|
|
31
|
-
this.sizeKey = 'height';
|
|
32
|
-
} else {
|
|
33
|
-
this.positionKey = 'x';
|
|
34
|
-
this.sizeKey = 'width';
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
_createSliderTextures() {
|
|
39
|
-
this._sliderBg = this._createTexture(this.bgTexture);
|
|
40
|
-
|
|
41
|
-
if (this.fillTexture)
|
|
42
|
-
this._fillTexture = this._createFillTexture(this.fillTexture);
|
|
43
|
-
|
|
44
|
-
this._sliderHandle = this._createTexture(this.handleTexture);
|
|
45
|
-
|
|
46
|
-
this._setEvents(this._sliderBg._baseObject);
|
|
47
|
-
this._setEvents(this._sliderHandle._baseObject);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
_createFillTexture(model) {
|
|
51
|
-
const fillTexture = this._createTexture(model);
|
|
52
|
-
const { width, height } = fillTexture._baseObject;
|
|
53
|
-
this._fillMask = Urso.objects.create({
|
|
54
|
-
type: Urso.types.objects.GRAPHICS,
|
|
55
|
-
figure: {
|
|
56
|
-
rectangle: [0, 0, width, height]
|
|
57
|
-
},
|
|
58
|
-
x: -width * fillTexture.anchorX,
|
|
59
|
-
y: -height * fillTexture.anchorY,
|
|
60
|
-
}, this);
|
|
61
|
-
|
|
62
|
-
fillTexture._baseObject.mask = this._fillMask._baseObject;
|
|
63
|
-
return fillTexture
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
_createValueText() {
|
|
67
|
-
if (this.minValueTextModel) {
|
|
68
|
-
this.minValueText = Urso.objects.create(this.minValueTextModel, this);
|
|
69
|
-
this.minValueText.text = this._points[0];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (this.maxValueTextModel) {
|
|
73
|
-
this.maxValueText = Urso.objects.create(this.maxValueTextModel, this);
|
|
74
|
-
this.maxValueText.text = this._points.length <= 2 ? '100' : this._points[this._points.length - 1];
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (this.currentValueTextModel) {
|
|
78
|
-
this.currentValueText = Urso.objects.create(this.currentValueTextModel, this);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
_createTexture(model) {
|
|
83
|
-
if (model.type === Urso.types.objects.GRAPHICS || model.type === Urso.types.objects.IMAGE)
|
|
84
|
-
return Urso.objects.create(model, this);
|
|
85
|
-
else
|
|
86
|
-
Urso.logger.error('ModulesObjectsModelsSlider objects error: textures should be GRAPHICS or IMAGE type');
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
_setEvents(obj) {
|
|
90
|
-
obj.interactive = true;
|
|
91
|
-
obj.buttonMode = true;
|
|
92
|
-
|
|
93
|
-
obj
|
|
94
|
-
.on('pointerdown', this._onPointerDown.bind(this))
|
|
95
|
-
.on('pointerup', this._onPointerUp.bind(this))
|
|
96
|
-
.on('pointerupoutside', this._onPointerUp.bind(this))
|
|
97
|
-
.on('touchmove', this._onTouchmove.bind(this));
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
_onTouchmove(event) {
|
|
101
|
-
const position = this._getEventLocalPosition(event);
|
|
102
|
-
this._onPointerMove(position);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
_getEventLocalPosition(event) {
|
|
106
|
-
const world = Urso.objects.getWorld();
|
|
107
|
-
const worldScale = world._baseObject.scale;
|
|
108
|
-
|
|
109
|
-
const x = event.data.global.x / worldScale.x;
|
|
110
|
-
const y = event.data.global.y / worldScale.y;
|
|
111
|
-
|
|
112
|
-
return { x, y };
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
_addBaseObject() {
|
|
116
|
-
this._baseObject = new PIXI.Container();
|
|
117
|
-
|
|
118
|
-
this._setPoints();
|
|
119
|
-
this._setVariables();
|
|
120
|
-
this._createSliderTextures();
|
|
121
|
-
this._createValueText();
|
|
122
|
-
this._setDefaultValue();
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
_onPointerDown(obj) {
|
|
126
|
-
if (obj.target === this._sliderHandle._baseObject)
|
|
127
|
-
this._handleIsDragging = true;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
_onPointerMove({ x, y }) {
|
|
131
|
-
if (!this._handleIsDragging)
|
|
132
|
-
return
|
|
133
|
-
|
|
134
|
-
const value = this.isVertical ? y : x;
|
|
135
|
-
const globalPosition = this.toGlobal(this[this.positionKey])[this.positionKey];
|
|
136
|
-
|
|
137
|
-
if (value < globalPosition)
|
|
138
|
-
this._sliderHandle[this.positionKey] = 0;
|
|
139
|
-
else if (value >= globalPosition + this._sliderBg._baseObject[this.sizeKey])
|
|
140
|
-
this._sliderHandle[this.positionKey] = this._sliderBg._baseObject[this.sizeKey];
|
|
141
|
-
else
|
|
142
|
-
this._sliderHandle[this.positionKey] = value - globalPosition
|
|
143
|
-
|
|
144
|
-
this._updateValueOnMove()
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
_updateValueOnMove() {
|
|
148
|
-
const { value } = this._calculateClosestPoint(this._sliderHandle);
|
|
149
|
-
|
|
150
|
-
if (this.currentValueText)
|
|
151
|
-
this.currentValueText.text = value;
|
|
152
|
-
|
|
153
|
-
const data = { class: this.class, name: this.name, position: this._sliderHandle[this.positionKey] };
|
|
154
|
-
this.emit(Urso.events.MODULES_OBJECTS_SLIDER_HANDLE_MOVE, data)
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
_onPointerUp(obj) {
|
|
158
|
-
this._handleIsDragging = false;
|
|
159
|
-
let targetObj;
|
|
160
|
-
|
|
161
|
-
if (obj.target === this._sliderBg._baseObject)
|
|
162
|
-
targetObj = obj.data.getLocalPosition(obj.target)
|
|
163
|
-
else
|
|
164
|
-
targetObj = this._sliderHandle;
|
|
165
|
-
|
|
166
|
-
const { coord, value } = this._calculateClosestPoint(targetObj);
|
|
167
|
-
this._dropHandle(coord, value);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
_setPoints() {
|
|
171
|
-
if (this.points.length > 1) {
|
|
172
|
-
this._points = [...this.points];
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const firstPoint = this.points[0] > 0 ? 0 : this.points[0];
|
|
177
|
-
const lastPoint = this.points[0] > 0 ? this.points[0] : 0;
|
|
178
|
-
|
|
179
|
-
for (let i = firstPoint; i <= lastPoint; i++)
|
|
180
|
-
this._points.push(i);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
_setDefaultValue() {
|
|
184
|
-
if(!this.defaultValue)
|
|
185
|
-
this.defaultValue = this._points[0];
|
|
186
|
-
|
|
187
|
-
if (!this._points.includes(this.defaultValue))
|
|
188
|
-
this.defaultValue = this._points[0];
|
|
189
|
-
|
|
190
|
-
let value = this._points.indexOf(this.defaultValue) *
|
|
191
|
-
this._sliderBg._baseObject[this.sizeKey] / (this._points.length - 1);
|
|
192
|
-
|
|
193
|
-
this._setNewValue(value, this.defaultValue);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
_dropHandle(coord, value) {
|
|
197
|
-
const data = { class: this.class, name: this.name, position: coord, value: value };
|
|
198
|
-
|
|
199
|
-
this.emit(Urso.events.MODULES_OBJECTS_SLIDER_HANDLE_DROP, data);
|
|
200
|
-
this._setNewValue(coord, value);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
_calculateClosestPoint({ x, y }) {
|
|
204
|
-
const givenValue = this.isVertical ? y : x;
|
|
205
|
-
let value, coord;
|
|
206
|
-
|
|
207
|
-
if (this._points.length <= 2) {
|
|
208
|
-
coord = givenValue;
|
|
209
|
-
value = ~~(100 / this._sliderBg._baseObject[this.sizeKey] * givenValue);
|
|
210
|
-
}
|
|
211
|
-
// calculate closest point
|
|
212
|
-
else {
|
|
213
|
-
for (let i = 0; i < this._points.length; i++) {
|
|
214
|
-
let pointCoord = i * this._sliderBg._baseObject[this.sizeKey] / (this._points.length - 1);
|
|
215
|
-
|
|
216
|
-
if (typeof (coord) === 'number' && givenValue - pointCoord < coord - givenValue) {
|
|
217
|
-
coord = coord;
|
|
218
|
-
} else {
|
|
219
|
-
coord = pointCoord;
|
|
220
|
-
value = this._points[i];
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
return { coord, value };
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
_setFillMask() {
|
|
229
|
-
if (!this._fillMask)
|
|
230
|
-
return
|
|
231
|
-
|
|
232
|
-
const progress = (this._sliderHandle[this.positionKey] - this._sliderBg[this.positionKey]) *
|
|
233
|
-
100 / this._fillTexture._baseObject[this.sizeKey] * 0.01;
|
|
234
|
-
|
|
235
|
-
const scaleKey = this.isVertical ? 'scaleY' : 'scaleX';
|
|
236
|
-
this._fillMask[scaleKey] = progress;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
_setNewValue(coord, value) {
|
|
240
|
-
this._sliderHandle[this.positionKey] = coord;
|
|
241
|
-
|
|
242
|
-
if (this.currentValueText)
|
|
243
|
-
this.currentValueText.text = value;
|
|
244
|
-
|
|
245
|
-
this._setFillMask();
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
_subscribeOnce() {
|
|
249
|
-
this.addListener(Urso.events.MODULES_SCENES_MOUSE_NEW_POSITION, this._onPointerMove.bind(this));
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
module.exports = ModulesObjectsModelsSlider;
|
|
1
|
+
class ModulesObjectsModelsSlider extends Urso.Core.Modules.Objects.BaseModel {
|
|
2
|
+
constructor(params) {
|
|
3
|
+
super(params);
|
|
4
|
+
|
|
5
|
+
this.type = Urso.types.objects.SLIDER;
|
|
6
|
+
this._sliderBg = null;
|
|
7
|
+
this._sliderHandle = null;
|
|
8
|
+
this._baseObject = null;
|
|
9
|
+
this._handleIsPulling = false;
|
|
10
|
+
this._points = [];
|
|
11
|
+
this._addBaseObject();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
setupParams(params) {
|
|
15
|
+
super.setupParams(params);
|
|
16
|
+
this.contents = [];
|
|
17
|
+
this.points = Urso.helper.recursiveGet('points', params, [0, 1]);
|
|
18
|
+
this.defaultValue = Urso.helper.recursiveGet('defaultValue', params, false);
|
|
19
|
+
this.bgTexture = Urso.helper.recursiveGet('bgTexture', params, false);
|
|
20
|
+
this.fillTexture = Urso.helper.recursiveGet('fillTexture', params, false);
|
|
21
|
+
this.handleTexture = Urso.helper.recursiveGet('handleTexture', params, false);
|
|
22
|
+
this.minValueTextModel = Urso.helper.recursiveGet('minValueTextModel', params, false);
|
|
23
|
+
this.maxValueTextModel = Urso.helper.recursiveGet('maxValueTextModel', params, false);
|
|
24
|
+
this.currentValueTextModel = Urso.helper.recursiveGet('currentValueTextModel', params, false);
|
|
25
|
+
this.isVertical = Urso.helper.recursiveGet('isVertical', params, false);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
_setVariables() {
|
|
29
|
+
if (this.isVertical) {
|
|
30
|
+
this.positionKey = 'y';
|
|
31
|
+
this.sizeKey = 'height';
|
|
32
|
+
} else {
|
|
33
|
+
this.positionKey = 'x';
|
|
34
|
+
this.sizeKey = 'width';
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
_createSliderTextures() {
|
|
39
|
+
this._sliderBg = this._createTexture(this.bgTexture);
|
|
40
|
+
|
|
41
|
+
if (this.fillTexture)
|
|
42
|
+
this._fillTexture = this._createFillTexture(this.fillTexture);
|
|
43
|
+
|
|
44
|
+
this._sliderHandle = this._createTexture(this.handleTexture);
|
|
45
|
+
|
|
46
|
+
this._setEvents(this._sliderBg._baseObject);
|
|
47
|
+
this._setEvents(this._sliderHandle._baseObject);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
_createFillTexture(model) {
|
|
51
|
+
const fillTexture = this._createTexture(model);
|
|
52
|
+
const { width, height } = fillTexture._baseObject;
|
|
53
|
+
this._fillMask = Urso.objects.create({
|
|
54
|
+
type: Urso.types.objects.GRAPHICS,
|
|
55
|
+
figure: {
|
|
56
|
+
rectangle: [0, 0, width, height]
|
|
57
|
+
},
|
|
58
|
+
x: -width * fillTexture.anchorX,
|
|
59
|
+
y: -height * fillTexture.anchorY,
|
|
60
|
+
}, this);
|
|
61
|
+
|
|
62
|
+
fillTexture._baseObject.mask = this._fillMask._baseObject;
|
|
63
|
+
return fillTexture
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
_createValueText() {
|
|
67
|
+
if (this.minValueTextModel) {
|
|
68
|
+
this.minValueText = Urso.objects.create(this.minValueTextModel, this);
|
|
69
|
+
this.minValueText.text = this._points[0];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (this.maxValueTextModel) {
|
|
73
|
+
this.maxValueText = Urso.objects.create(this.maxValueTextModel, this);
|
|
74
|
+
this.maxValueText.text = this._points.length <= 2 ? '100' : this._points[this._points.length - 1];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (this.currentValueTextModel) {
|
|
78
|
+
this.currentValueText = Urso.objects.create(this.currentValueTextModel, this);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
_createTexture(model) {
|
|
83
|
+
if (model.type === Urso.types.objects.GRAPHICS || model.type === Urso.types.objects.IMAGE)
|
|
84
|
+
return Urso.objects.create(model, this);
|
|
85
|
+
else
|
|
86
|
+
Urso.logger.error('ModulesObjectsModelsSlider objects error: textures should be GRAPHICS or IMAGE type');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
_setEvents(obj) {
|
|
90
|
+
obj.interactive = true;
|
|
91
|
+
obj.buttonMode = true;
|
|
92
|
+
|
|
93
|
+
obj
|
|
94
|
+
.on('pointerdown', this._onPointerDown.bind(this))
|
|
95
|
+
.on('pointerup', this._onPointerUp.bind(this))
|
|
96
|
+
.on('pointerupoutside', this._onPointerUp.bind(this))
|
|
97
|
+
.on('touchmove', this._onTouchmove.bind(this));
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
_onTouchmove(event) {
|
|
101
|
+
const position = this._getEventLocalPosition(event);
|
|
102
|
+
this._onPointerMove(position);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
_getEventLocalPosition(event) {
|
|
106
|
+
const world = Urso.objects.getWorld();
|
|
107
|
+
const worldScale = world._baseObject.scale;
|
|
108
|
+
|
|
109
|
+
const x = event.data.global.x / worldScale.x;
|
|
110
|
+
const y = event.data.global.y / worldScale.y;
|
|
111
|
+
|
|
112
|
+
return { x, y };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
_addBaseObject() {
|
|
116
|
+
this._baseObject = new PIXI.Container();
|
|
117
|
+
|
|
118
|
+
this._setPoints();
|
|
119
|
+
this._setVariables();
|
|
120
|
+
this._createSliderTextures();
|
|
121
|
+
this._createValueText();
|
|
122
|
+
this._setDefaultValue();
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
_onPointerDown(obj) {
|
|
126
|
+
if (obj.target === this._sliderHandle._baseObject)
|
|
127
|
+
this._handleIsDragging = true;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
_onPointerMove({ x, y }) {
|
|
131
|
+
if (!this._handleIsDragging)
|
|
132
|
+
return
|
|
133
|
+
|
|
134
|
+
const value = this.isVertical ? y : x;
|
|
135
|
+
const globalPosition = this.toGlobal(this[this.positionKey])[this.positionKey];
|
|
136
|
+
|
|
137
|
+
if (value < globalPosition)
|
|
138
|
+
this._sliderHandle[this.positionKey] = 0;
|
|
139
|
+
else if (value >= globalPosition + this._sliderBg._baseObject[this.sizeKey])
|
|
140
|
+
this._sliderHandle[this.positionKey] = this._sliderBg._baseObject[this.sizeKey];
|
|
141
|
+
else
|
|
142
|
+
this._sliderHandle[this.positionKey] = value - globalPosition
|
|
143
|
+
|
|
144
|
+
this._updateValueOnMove()
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
_updateValueOnMove() {
|
|
148
|
+
const { value } = this._calculateClosestPoint(this._sliderHandle);
|
|
149
|
+
|
|
150
|
+
if (this.currentValueText)
|
|
151
|
+
this.currentValueText.text = value;
|
|
152
|
+
|
|
153
|
+
const data = { class: this.class, name: this.name, position: this._sliderHandle[this.positionKey] };
|
|
154
|
+
this.emit(Urso.events.MODULES_OBJECTS_SLIDER_HANDLE_MOVE, data)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
_onPointerUp(obj) {
|
|
158
|
+
this._handleIsDragging = false;
|
|
159
|
+
let targetObj;
|
|
160
|
+
|
|
161
|
+
if (obj.target === this._sliderBg._baseObject)
|
|
162
|
+
targetObj = obj.data.getLocalPosition(obj.target)
|
|
163
|
+
else
|
|
164
|
+
targetObj = this._sliderHandle;
|
|
165
|
+
|
|
166
|
+
const { coord, value } = this._calculateClosestPoint(targetObj);
|
|
167
|
+
this._dropHandle(coord, value);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
_setPoints() {
|
|
171
|
+
if (this.points.length > 1) {
|
|
172
|
+
this._points = [...this.points];
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const firstPoint = this.points[0] > 0 ? 0 : this.points[0];
|
|
177
|
+
const lastPoint = this.points[0] > 0 ? this.points[0] : 0;
|
|
178
|
+
|
|
179
|
+
for (let i = firstPoint; i <= lastPoint; i++)
|
|
180
|
+
this._points.push(i);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
_setDefaultValue() {
|
|
184
|
+
if(!this.defaultValue)
|
|
185
|
+
this.defaultValue = this._points[0];
|
|
186
|
+
|
|
187
|
+
if (!this._points.includes(this.defaultValue))
|
|
188
|
+
this.defaultValue = this._points[0];
|
|
189
|
+
|
|
190
|
+
let value = this._points.indexOf(this.defaultValue) *
|
|
191
|
+
this._sliderBg._baseObject[this.sizeKey] / (this._points.length - 1);
|
|
192
|
+
|
|
193
|
+
this._setNewValue(value, this.defaultValue);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
_dropHandle(coord, value) {
|
|
197
|
+
const data = { class: this.class, name: this.name, position: coord, value: value };
|
|
198
|
+
|
|
199
|
+
this.emit(Urso.events.MODULES_OBJECTS_SLIDER_HANDLE_DROP, data);
|
|
200
|
+
this._setNewValue(coord, value);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
_calculateClosestPoint({ x, y }) {
|
|
204
|
+
const givenValue = this.isVertical ? y : x;
|
|
205
|
+
let value, coord;
|
|
206
|
+
|
|
207
|
+
if (this._points.length <= 2) {
|
|
208
|
+
coord = givenValue;
|
|
209
|
+
value = ~~(100 / this._sliderBg._baseObject[this.sizeKey] * givenValue);
|
|
210
|
+
}
|
|
211
|
+
// calculate closest point
|
|
212
|
+
else {
|
|
213
|
+
for (let i = 0; i < this._points.length; i++) {
|
|
214
|
+
let pointCoord = i * this._sliderBg._baseObject[this.sizeKey] / (this._points.length - 1);
|
|
215
|
+
|
|
216
|
+
if (typeof (coord) === 'number' && givenValue - pointCoord < coord - givenValue) {
|
|
217
|
+
coord = coord;
|
|
218
|
+
} else {
|
|
219
|
+
coord = pointCoord;
|
|
220
|
+
value = this._points[i];
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return { coord, value };
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
_setFillMask() {
|
|
229
|
+
if (!this._fillMask)
|
|
230
|
+
return
|
|
231
|
+
|
|
232
|
+
const progress = (this._sliderHandle[this.positionKey] - this._sliderBg[this.positionKey]) *
|
|
233
|
+
100 / this._fillTexture._baseObject[this.sizeKey] * 0.01;
|
|
234
|
+
|
|
235
|
+
const scaleKey = this.isVertical ? 'scaleY' : 'scaleX';
|
|
236
|
+
this._fillMask[scaleKey] = progress;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
_setNewValue(coord, value) {
|
|
240
|
+
this._sliderHandle[this.positionKey] = coord;
|
|
241
|
+
|
|
242
|
+
if (this.currentValueText)
|
|
243
|
+
this.currentValueText.text = value;
|
|
244
|
+
|
|
245
|
+
this._setFillMask();
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
_subscribeOnce() {
|
|
249
|
+
this.addListener(Urso.events.MODULES_SCENES_MOUSE_NEW_POSITION, this._onPointerMove.bind(this));
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
module.exports = ModulesObjectsModelsSlider;
|