@urso/core 0.1.91 → 0.1.96

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.
@@ -0,0 +1,91 @@
1
+ const UrsoCoreModulesObjectsModelsToggle = require('./toggle');
2
+
3
+ class ModulesObjectsModelsCheckbox extends UrsoCoreModulesObjectsModelsToggle {
4
+ constructor(params) {
5
+ super(params);
6
+
7
+ this._isDisabled = false;
8
+ this._lable = null;
9
+ this._checkbox = null;
10
+
11
+ this.type = Urso.types.objects.CHECKBOX;
12
+
13
+ this._createCheckbox();
14
+
15
+ this.enable = this.enable.bind(this);
16
+ this.disable = this.disable.bind(this);
17
+ }
18
+
19
+ setupParams(params) {
20
+ super.setupParams(params);
21
+
22
+ this.contents = [];
23
+ this.action = Urso.helper.recursiveGet('action', params, () => { this.emit(Urso.events.MODULES_OBJECTS_CHECKBOX_PRESS, this.name) });
24
+ this.lable = Urso.helper.recursiveGet('lable', params, false);
25
+
26
+ this.defaultStatus = Urso.helper.recursiveGet('defaultStatus', params, 'unpressed'); //pressed or unpressed
27
+ }
28
+
29
+ _createCheckbox() {
30
+ this._toggleStatus = this.defaultStatus;
31
+ this._checkbox = this._createObject(this.buttonFrames[`${this.defaultStatus}Out`])
32
+
33
+ if (this.lable)
34
+ this._lable = this._createObject(this.lable);
35
+ }
36
+
37
+ _createObject(model) {
38
+ model = Urso.helper.objectClone(model);
39
+ let object = Urso.objects.create(model, this);
40
+
41
+ object._baseObject.interactive = true;
42
+ object._baseObject.buttonMode = true;
43
+
44
+ object._baseObject
45
+ .on('pointerdown', this._onButtonDown.bind(this))
46
+ .on('pointerup', this._onButtonUp.bind(this))
47
+ .on('pointerupoutside', this._onButtonUp.bind(this))
48
+ .on('pointerover', this._onButtonOver.bind(this))
49
+ .on('pointerout', this._onButtonOut.bind(this));
50
+
51
+ return object;
52
+ }
53
+
54
+ _addBaseObject() {
55
+ this._baseObject = new PIXI.Container();
56
+ };
57
+
58
+ _drawGraphics({ polygon, rectangle, fillColor }) {
59
+ if (!polygon && !rectangle)
60
+ return;
61
+
62
+ this._checkbox._baseObject.clear();
63
+ this._checkbox._baseObject.beginFill(fillColor);
64
+
65
+ if (polygon && polygon.length) {
66
+ this._checkbox._baseObject.drawPolygon(polygon);
67
+ } else if (rectangle && rectangle.length) {
68
+ this._checkbox._baseObject.drawRect(...rectangle)
69
+ }
70
+
71
+ this._checkbox._baseObject.endFill();
72
+ };
73
+
74
+ _changeTexture(key) {
75
+ if (!this.buttonFrames[key]) {
76
+ if (key === `${this._toggleStatus}Out`) {
77
+ Urso.logger.error('ModulesObjectsModelsButton assets error: no out image ' + this.buttonFrames.out);
78
+ return false;
79
+ }
80
+
81
+ this._changeTexture(`${this._toggleStatus}Out`); // load default texture for this key
82
+ return false;
83
+ }
84
+ if (this.buttonFrames[key].type === Urso.types.objects.GRAPHICS)
85
+ this._drawGraphics(this.buttonFrames[key].figure);
86
+ else
87
+ this._checkbox.changeTexture(this.buttonFrames[key].assetKey);
88
+ }
89
+ }
90
+
91
+ module.exports = ModulesObjectsModelsCheckbox;
@@ -0,0 +1,62 @@
1
+ class ModulesObjectsModelsScrollbox extends Urso.Core.Modules.Objects.BaseModel {
2
+ constructor(params) {
3
+ super(params);
4
+
5
+ this.type = Urso.types.objects.SCROLLBOX;
6
+ this._addBaseObject();
7
+ this._createContent();
8
+ }
9
+
10
+ setupParams(params) {
11
+ super.setupParams(params);
12
+
13
+ this.content = Urso.helper.recursiveGet('content', params, []);
14
+ this.dragScroll = Urso.helper.recursiveGet('dragScroll', params, true);
15
+ this.scrollType = Urso.helper.recursiveGet('scrollType', params, 3);
16
+ }
17
+
18
+ _getScrollboxParams(){
19
+ return {
20
+ boxWidth: this.width,
21
+ boxHeight: this.height,
22
+ dragScroll: this.dragScroll,
23
+ fade: true,
24
+ fadeScrollbarTime: 300
25
+ }
26
+ }
27
+
28
+ _setScrollWidth(){
29
+ if(this.scrollType === 1 || this.scrollType === 0){
30
+ this._baseObject.scrollWidth = this.width;
31
+ this._baseObject.overflowX = 'hidden';
32
+ }
33
+ }
34
+
35
+ _setScrollHeight(){
36
+ if(this.scrollType === 2 || this.scrollType === 0){
37
+ this._baseObject.scrollHeight = this.height;
38
+ this._baseObject.overflowY = 'hidden'
39
+ }
40
+ }
41
+
42
+ _createContent(){
43
+ this.content.forEach(child => {
44
+ let object = Urso.objects.create(child)
45
+ this._baseObject.content.addChild(object._baseObject)
46
+ })
47
+
48
+ this._baseObject.update();
49
+ }
50
+
51
+ _addBaseObject() {
52
+ const params = this._getScrollboxParams();
53
+
54
+ const Scrollbox = require('pixi-scrollbox').Scrollbox;
55
+ this._baseObject = new Scrollbox(params);
56
+
57
+ this._setScrollHeight();
58
+ this._setScrollWidth();
59
+ };
60
+ }
61
+
62
+ module.exports = ModulesObjectsModelsScrollbox
@@ -0,0 +1,154 @@
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
+
11
+ this._addBaseObject();
12
+ this._createSliderTextures();
13
+ this._createValueText();
14
+ this._setDefaultValue();
15
+ }
16
+
17
+ setupParams(params) {
18
+ super.setupParams(params);
19
+ this.contents = [];
20
+ this.points = Urso.helper.recursiveGet('points', params, [0, 1]);
21
+ this.defaultValue = Urso.helper.recursiveGet('defaultValue', params, this.points[0]);
22
+ this.bgTexture = Urso.helper.recursiveGet('bgTexture', params, false);
23
+ this.handleTexture = Urso.helper.recursiveGet('handleTexture', params, false);
24
+ this.minValueTextModel = Urso.helper.recursiveGet('minValueTextModel', params, false);
25
+ this.maxValueTextModel = Urso.helper.recursiveGet('maxValueTextModel', params, false);
26
+ this.currentValueTextModel = Urso.helper.recursiveGet('currentValueTextModel', params, false);
27
+ }
28
+
29
+ _createSliderTextures() {
30
+ this._sliderBg = this._createTexture(this.bgTexture);
31
+ this._sliderHandle = this._createTexture(this.handleTexture);
32
+
33
+ this._setEvents(this._sliderBg._baseObject);
34
+ this._setEvents(this._sliderHandle._baseObject);
35
+ }
36
+
37
+ _createValueText() {
38
+ if (this.minValueTextModel) {
39
+ this.minValueText = Urso.objects.create(this.minValueTextModel, this);
40
+ this.minValueText.text = this.points[0];
41
+ }
42
+
43
+ if (this.maxValueTextModel) {
44
+ this.maxValueText = Urso.objects.create(this.maxValueTextModel, this);
45
+ this.maxValueText.text = this.points.length <= 2 ? '100' : this.points[this.points.length - 1];
46
+ }
47
+
48
+ if(this.currentValueTextModel){
49
+ this.currentValueText = Urso.objects.create(this.currentValueTextModel, this);
50
+ }
51
+ }
52
+
53
+ _createTexture(model) {
54
+ if (model.type === Urso.types.objects.GRAPHICS || model.type === Urso.types.objects.IMAGE)
55
+ return Urso.objects.create(model, this);
56
+ else
57
+ Urso.logger.error('ModulesObjectsModelsSlider objects error: textures should be GRAPHICS or IMAGE type');
58
+ }
59
+
60
+ _setEvents(obj) {
61
+ obj.interactive = true;
62
+ obj.buttonMode = true;
63
+
64
+ obj
65
+ .on('pointerdown', this._onPointerDown.bind(this))
66
+ .on('pointerup', this._onPointerUp.bind(this))
67
+ .on('pointerupoutside', this._onPointerUp.bind(this))
68
+ }
69
+
70
+ _addBaseObject() {
71
+ this._baseObject = new PIXI.Container();
72
+ };
73
+
74
+ _onPointerDown(obj) {
75
+ if (obj.target === this._sliderHandle._baseObject)
76
+ this._handleIsDragging = true;
77
+ }
78
+
79
+ _onMouseMove({ x }) {
80
+ if (!this._handleIsDragging)
81
+ return
82
+
83
+ if (x < this.x)
84
+ this._sliderHandle.x = 0;
85
+ else if (x > this.x + this._sliderBg._baseObject.width)
86
+ this._sliderHandle.x = this._sliderBg._baseObject.width;
87
+ else
88
+ this._sliderHandle.x = x - this.x;
89
+ }
90
+
91
+ _onPointerUp(obj) {
92
+ this._handleIsDragging = false;
93
+ let x;
94
+
95
+ if (obj.target === this._sliderBg._baseObject) {
96
+ x = obj.data.getLocalPosition(obj.target).x;
97
+ } else
98
+ x = this._sliderHandle.x;
99
+
100
+ this._dropHandle(x);
101
+ }
102
+
103
+ _setDefaultValue(){
104
+ if(!this.defaultValue)
105
+ return
106
+
107
+ if(!this.points.includes(this.defaultValue))
108
+ this.defaultValue = this.points[0];
109
+
110
+ let x = this.points.indexOf(this.defaultValue) * this._sliderBg._baseObject.width / (this.points.length - 1);
111
+
112
+ this._setNewValue(x, this.defaultValue);
113
+ }
114
+
115
+ _dropHandle(x) {
116
+ let value;
117
+ let handleX;
118
+
119
+ if(this.points.length <= 2){
120
+ handleX = x;
121
+ value = ~~(100 / this._sliderBg._baseObject.width * x);
122
+ }
123
+ // calculate closest point
124
+ else{
125
+ for (let i = 0; i < this.points.length; i++) {
126
+ let pointX = i * this._sliderBg._baseObject.width / (this.points.length - 1);
127
+
128
+ if (typeof (handleX) === 'number' && x - pointX < handleX - x) {
129
+ handleX = handleX;
130
+ } else {
131
+ handleX = pointX;
132
+ value = this.points[i];
133
+ }
134
+ }
135
+ }
136
+
137
+ this._setNewValue(handleX, value)
138
+ }
139
+
140
+ _setNewValue(x, value){
141
+ this._sliderHandle.x = x;
142
+
143
+ if (this.currentValueText)
144
+ this.currentValueText.text = value;
145
+
146
+ this.emit(Urso.events.MODULES_OBJECTS_SLIDER_SET_NEW_VALUE, { name: this.name, value: value });
147
+ }
148
+
149
+ _subscribeOnce() {
150
+ this.addListener(Urso.events.MODULES_SCENES_MOUSE_NEW_POSITION, this._onMouseMove.bind(this));
151
+ }
152
+ }
153
+
154
+ module.exports = ModulesObjectsModelsSlider;
@@ -0,0 +1,55 @@
1
+ class ModulesObjectsModelsTextInput extends Urso.Core.Modules.Objects.BaseModel {
2
+ constructor(params) {
3
+ super(params);
4
+
5
+ this.type = Urso.types.objects.TEXTINPUT;
6
+ this.text = '';
7
+ this._addBaseObject();
8
+ this._setRestrictedSymbosl();
9
+ }
10
+
11
+ setupParams(params) {
12
+ super.setupParams(params);
13
+
14
+ this.input = Urso.helper.recursiveGet('input', params, false);
15
+ this.box = Urso.helper.recursiveGet('box', params, false);
16
+ this.numbersOnly = Urso.helper.recursiveGet('numbersOnly', params, false);
17
+ this.allowedSymbols = Urso.helper.recursiveGet('allowedSymbols', params, false);
18
+ this.substituteText = Urso.helper.recursiveGet('substituteText', params, false);
19
+ }
20
+
21
+ restrictInput(allowedSymbols) {
22
+ this._baseObject.restrict = allowedSymbols;
23
+ }
24
+
25
+ disable(){
26
+ this._baseObject.disabled = true
27
+ }
28
+
29
+ enable(){
30
+ this._baseObject.disabled = false
31
+ }
32
+
33
+ _setRestrictedSymbosl() {
34
+ if (this.numbersOnly) {
35
+ const regex = new RegExp('^[0-9]*');
36
+ this.restrictInput(regex);
37
+ } else if (this.allowedSymbols) {
38
+ this.restrictInput(this.allowedSymbols);
39
+ }
40
+ }
41
+
42
+ _onBlur(){
43
+ this.text = this._baseObject.text;
44
+ const data = {name: this.name, class: this.class, id: this.id, text: this.text};
45
+ this.emit(Urso.events.MODULES_OBJECTS_TEXTINPUT_BLUR, data);
46
+ }
47
+
48
+ _addBaseObject() {
49
+ this._baseObject = new PIXI.TextInput({ input: this.input, box: this.box });
50
+ this._baseObject.substituteText = this.substituteText;
51
+ this._baseObject.on('blur', this._onBlur.bind(this))
52
+ };
53
+ }
54
+
55
+ module.exports = ModulesObjectsModelsTextInput;
@@ -0,0 +1,165 @@
1
+
2
+ const UrsoCoreModulesObjectsModelsButton = require('./button');
3
+
4
+ class ModulesObjectsModelsToggle extends UrsoCoreModulesObjectsModelsButton {
5
+ constructor(params) {
6
+ super(params);
7
+
8
+ this._toggleStatus = 'unpressed';
9
+
10
+ this.type = Urso.types.objects.TOGGLE;
11
+ this._addBaseObject();
12
+
13
+ this.enable = this.enable.bind(this);
14
+ this.disable = this.disable.bind(this);
15
+ }
16
+
17
+ setupParams(params) {
18
+ super.setupParams(params);
19
+
20
+ this.buttonFrames = {
21
+ pressedOver: Urso.helper.recursiveGet('buttonFrames.pressedOver', params, false),
22
+ pressedOut: Urso.helper.recursiveGet('buttonFrames.pressedOut', params, false),
23
+ unpressedOver: Urso.helper.recursiveGet('buttonFrames.unpressedOver', params, false),
24
+ unpressedOut: Urso.helper.recursiveGet('buttonFrames.unpressedOut', params, false),
25
+ pressedDown: Urso.helper.recursiveGet('buttonFrames.pressedDown', params, false),
26
+ unpressedDown: Urso.helper.recursiveGet('buttonFrames.unpressedDown', params, false),
27
+ pressedDisabled: Urso.helper.recursiveGet('buttonFrames.pressedDisabled', params, false),
28
+ unpressedDisabled: Urso.helper.recursiveGet('buttonFrames.unpressedDisabled', params, false),
29
+ }
30
+ }
31
+
32
+ setButtonFrame(key, assetKey) {
33
+ this.buttonFrames[key] = assetKey;
34
+
35
+ if (this._isOver)
36
+ this._changeTexture(`${this._toggleStatus}Over`);
37
+ else if(this._isDown)
38
+ this._changeTexture(`${this._toggleStatus}Down`);
39
+ else if(this._isDisabled)
40
+ this._changeTexture(`${this._toggleStatus}Disabled`);
41
+ else
42
+ this._changeTexture(`${this._toggleStatus}Out`);
43
+ }
44
+
45
+ enable() {
46
+ if (!this._isDisabled)
47
+ return false;
48
+
49
+ if (this._isOver)
50
+ this._changeTexture(`${this._toggleStatus}Over`);
51
+ else
52
+ this._changeTexture(`${this._toggleStatus}Out`);
53
+
54
+ this._isDisabled = false;
55
+ }
56
+
57
+ disable() {
58
+ if (this._isDisabled)
59
+ return false;
60
+
61
+ this._changeTexture(`${this._toggleStatus}Disabled`);
62
+ this._isDisabled = true;
63
+ }
64
+
65
+ _addBaseObject() {
66
+ this._baseObject = new PIXI.Sprite();
67
+ this._changeTexture('unpressedOut');
68
+
69
+ this._baseObject.interactive = true;
70
+ this._baseObject.buttonMode = true;
71
+
72
+ if (this.pixelPerfectOver) {
73
+ //todo
74
+ }
75
+
76
+ if (this.pixelPerfectClick) {
77
+ //todo
78
+ }
79
+
80
+ this._baseObject
81
+ .on('pointerdown', this._onButtonDown.bind(this))
82
+ .on('pointerup', this._onButtonUp.bind(this))
83
+ .on('pointerupoutside', this._onButtonUp.bind(this))
84
+ .on('pointerover', this._onButtonOver.bind(this))
85
+ .on('pointerout', this._onButtonOut.bind(this));
86
+ };
87
+
88
+ _onButtonDown() {
89
+ if (this._isDisabled)
90
+ return false;
91
+
92
+ this._isDown = true;
93
+
94
+ if (this.keyDownAction)
95
+ this.keyDownAction();
96
+
97
+ if (this._isDisabled) //can be disabled after keyDownAction
98
+ return false;
99
+
100
+ this._changeTexture(`${this._toggleStatus}Down`);
101
+
102
+ this._toggleStatus = this._toggleStatus === 'pressed' ? 'unpressed' : 'pressed';
103
+ }
104
+
105
+ _onButtonUp() {
106
+ if (this._isDisabled)
107
+ return false;
108
+
109
+ this._isDown = false;
110
+
111
+ if (this.action)
112
+ this.action();
113
+
114
+ if (this._isDisabled) //can be disabled after action
115
+ return false;
116
+
117
+ if (this._isOver)
118
+ this._changeTexture(`${this._toggleStatus}Over`);
119
+ else
120
+ this._changeTexture(`${this._toggleStatus}Out`);
121
+ }
122
+
123
+ _onButtonOver() {
124
+ this._isOver = true;
125
+
126
+ if (this._isDisabled || this._isDown)
127
+ return false;
128
+
129
+ if (this.mouseOverAction)
130
+ this.mouseOverAction();
131
+
132
+ this._changeTexture(`${this._toggleStatus}Over`);
133
+ }
134
+
135
+ _onButtonOut() {
136
+ this._isOver = false;
137
+
138
+ if (this._isDisabled || this._isDown)
139
+ return false;
140
+
141
+ if (this.mouseOutAction)
142
+ this.mouseOutAction();
143
+
144
+ this._changeTexture(`${this._toggleStatus}Out`);
145
+ }
146
+
147
+ _changeTexture(key) {
148
+ let texture = Urso.cache.getTexture(this.buttonFrames[key]);
149
+
150
+ if (!texture) {
151
+ if (key === `${this._toggleStatus}Out`) {
152
+ Urso.logger.error('ModulesObjectsModelsButton assets error: no out image ' + this.buttonFrames.out);
153
+ return false;
154
+ }
155
+
156
+ this._changeTexture(`${this._toggleStatus}Out`); // load default texture for this key
157
+ return false;
158
+ }
159
+
160
+ this._baseObject.texture = texture;
161
+ return true;
162
+ }
163
+ }
164
+
165
+ module.exports = ModulesObjectsModelsToggle;
@@ -31,7 +31,9 @@ class PropertyAdapter {
31
31
  Urso.types.objects.COMPONENT,
32
32
  Urso.types.objects.CONTAINER,
33
33
  Urso.types.objects.GROUP,
34
- Urso.types.objects.WORLD
34
+ Urso.types.objects.WORLD,
35
+ Urso.types.objects.SLIDER,
36
+ Urso.types.objects.SCROLLBOX,
35
37
  ];
36
38
 
37
39
  this._typesWithoutAnchor = [
@@ -40,7 +42,10 @@ class PropertyAdapter {
40
42
  Urso.types.objects.HITAREA,
41
43
  Urso.types.objects.MASK,
42
44
  Urso.types.objects.SPINE,
43
- Urso.types.objects.WORLD
45
+ Urso.types.objects.SLIDER,
46
+ Urso.types.objects.TEXTINPUT,
47
+ Urso.types.objects.CHECKBOX,
48
+ Urso.types.objects.WORLD,
44
49
  ];
45
50
  }
46
51
 
@@ -8,6 +8,9 @@ class ModulesObserverConfig {
8
8
  MODULES_ASSETS_LAZYLOAD_FINISHED: 'modules.assets.lazyLoad.finished',
9
9
  MODULES_OBJECTS_BUTTON_PRESS: 'modules.objects.button.press',
10
10
  MODULES_OBJECTS_HIT_AREA_PRESS: 'modules.objects.hitArea.press',
11
+ MODULES_OBJECTS_SLIDER_SET_NEW_VALUE: 'modules.objects.slider.setNewValue',
12
+ MODULES_OBJECTS_CHECKBOX_PRESS: 'modules.objects.checkbox.press',
13
+ MODULES_OBJECTS_TEXTINPUT_BLUR: 'modules.objects.textinput.blur',
11
14
  MODULES_LOGIC_SOUNDS_DO: 'modules.soundManager.do',
12
15
  MODULES_SOUND_MANAGER_UPDATE_CFG: 'modules.soundManager.updateCfg',
13
16
  MODULES_SOUND_MANAGER_SET_GLOBAL_VOLUME: 'modules.soundManager.setGlobalVolume',
@@ -1,4 +1,4 @@
1
- class ModulesTemplateController {
1
+ class ModulesTemplateService {
2
2
  constructor() {
3
3
  this.singleton = true;
4
4
 
@@ -58,8 +58,11 @@ class ModulesTemplateController {
58
58
  if (!groupTemplate)
59
59
  Urso.logger.error('ModulesTemplateController group Template error ' + obj.groupName);
60
60
 
61
- this._parseAssets(groupTemplate.assets, groupTemplate._templatePath);
62
- this._parseObjects(groupTemplate.objects, groupTemplate._templatePath);
61
+ if (groupTemplate.assets)
62
+ this._parseAssets(groupTemplate.assets, groupTemplate._templatePath);
63
+
64
+ if (groupTemplate.objects)
65
+ this._parseObjects(groupTemplate.objects, groupTemplate._templatePath);
63
66
 
64
67
  this._mergeStylesAndAssets({ styles: groupTemplate.styles, assets: groupTemplate.assets })
65
68
 
@@ -119,4 +122,4 @@ class ModulesTemplateController {
119
122
 
120
123
  }
121
124
 
122
- module.exports = ModulesTemplateController;
125
+ module.exports = ModulesTemplateService;
@@ -32,7 +32,12 @@ class ModulesTemplateTypes {
32
32
  GROUP: 15,
33
33
  IMAGES_ANIMATION: 16,
34
34
  DRAGONBONES: 17,
35
- ATLASIMAGE: 18
35
+ ATLASIMAGE: 18,
36
+ SLIDER: 19,
37
+ TOGGLE: 20,
38
+ CHECKBOX: 21,
39
+ SCROLLBOX: 22,
40
+ TEXTINPUT: 23
36
41
  }
37
42
  }
38
43
  }