@urso/core 0.1.93 → 0.1.98

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,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,169 @@
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.action = Urso.helper.recursiveGet('action', params, () => {
21
+ this.emit(Urso.events.MODULES_OBJECTS_TOGGLE_PRESS, { name: this.name, status: this._toggleStatus })
22
+ });
23
+
24
+ this.buttonFrames = {
25
+ pressedOver: Urso.helper.recursiveGet('buttonFrames.pressedOver', params, false),
26
+ pressedOut: Urso.helper.recursiveGet('buttonFrames.pressedOut', params, false),
27
+ unpressedOver: Urso.helper.recursiveGet('buttonFrames.unpressedOver', params, false),
28
+ unpressedOut: Urso.helper.recursiveGet('buttonFrames.unpressedOut', params, false),
29
+ pressedDown: Urso.helper.recursiveGet('buttonFrames.pressedDown', params, false),
30
+ unpressedDown: Urso.helper.recursiveGet('buttonFrames.unpressedDown', params, false),
31
+ pressedDisabled: Urso.helper.recursiveGet('buttonFrames.pressedDisabled', params, false),
32
+ unpressedDisabled: Urso.helper.recursiveGet('buttonFrames.unpressedDisabled', params, false),
33
+ }
34
+ }
35
+
36
+ setButtonFrame(key, assetKey) {
37
+ this.buttonFrames[key] = assetKey;
38
+
39
+ if (this._isOver)
40
+ this._changeTexture(`${this._toggleStatus}Over`);
41
+ else if(this._isDown)
42
+ this._changeTexture(`${this._toggleStatus}Down`);
43
+ else if(this._isDisabled)
44
+ this._changeTexture(`${this._toggleStatus}Disabled`);
45
+ else
46
+ this._changeTexture(`${this._toggleStatus}Out`);
47
+ }
48
+
49
+ enable() {
50
+ if (!this._isDisabled)
51
+ return false;
52
+
53
+ if (this._isOver)
54
+ this._changeTexture(`${this._toggleStatus}Over`);
55
+ else
56
+ this._changeTexture(`${this._toggleStatus}Out`);
57
+
58
+ this._isDisabled = false;
59
+ }
60
+
61
+ disable() {
62
+ if (this._isDisabled)
63
+ return false;
64
+
65
+ this._changeTexture(`${this._toggleStatus}Disabled`);
66
+ this._isDisabled = true;
67
+ }
68
+
69
+ _addBaseObject() {
70
+ this._baseObject = new PIXI.Sprite();
71
+ this._changeTexture('unpressedOut');
72
+
73
+ this._baseObject.interactive = true;
74
+ this._baseObject.buttonMode = true;
75
+
76
+ if (this.pixelPerfectOver) {
77
+ //todo
78
+ }
79
+
80
+ if (this.pixelPerfectClick) {
81
+ //todo
82
+ }
83
+
84
+ this._baseObject
85
+ .on('pointerdown', this._onButtonDown.bind(this))
86
+ .on('pointerup', this._onButtonUp.bind(this))
87
+ .on('pointerupoutside', this._onButtonUp.bind(this))
88
+ .on('pointerover', this._onButtonOver.bind(this))
89
+ .on('pointerout', this._onButtonOut.bind(this));
90
+ };
91
+
92
+ _onButtonDown() {
93
+ if (this._isDisabled)
94
+ return false;
95
+
96
+ this._isDown = true;
97
+
98
+ if (this.keyDownAction)
99
+ this.keyDownAction();
100
+
101
+ if (this._isDisabled) //can be disabled after keyDownAction
102
+ return false;
103
+
104
+ this._changeTexture(`${this._toggleStatus}Down`);
105
+
106
+ this._toggleStatus = this._toggleStatus === 'pressed' ? 'unpressed' : 'pressed';
107
+ }
108
+
109
+ _onButtonUp() {
110
+ if (this._isDisabled)
111
+ return false;
112
+
113
+ this._isDown = false;
114
+
115
+ if (this.action)
116
+ this.action();
117
+
118
+ if (this._isDisabled) //can be disabled after action
119
+ return false;
120
+
121
+ if (this._isOver)
122
+ this._changeTexture(`${this._toggleStatus}Over`);
123
+ else
124
+ this._changeTexture(`${this._toggleStatus}Out`);
125
+ }
126
+
127
+ _onButtonOver() {
128
+ this._isOver = true;
129
+
130
+ if (this._isDisabled || this._isDown)
131
+ return false;
132
+
133
+ if (this.mouseOverAction)
134
+ this.mouseOverAction();
135
+
136
+ this._changeTexture(`${this._toggleStatus}Over`);
137
+ }
138
+
139
+ _onButtonOut() {
140
+ this._isOver = false;
141
+
142
+ if (this._isDisabled || this._isDown)
143
+ return false;
144
+
145
+ if (this.mouseOutAction)
146
+ this.mouseOutAction();
147
+
148
+ this._changeTexture(`${this._toggleStatus}Out`);
149
+ }
150
+
151
+ _changeTexture(key) {
152
+ let texture = Urso.cache.getTexture(this.buttonFrames[key]);
153
+
154
+ if (!texture) {
155
+ if (key === `${this._toggleStatus}Out`) {
156
+ Urso.logger.error('ModulesObjectsModelsButton assets error: no out image ' + this.buttonFrames.out);
157
+ return false;
158
+ }
159
+
160
+ this._changeTexture(`${this._toggleStatus}Out`); // load default texture for this key
161
+ return false;
162
+ }
163
+
164
+ this._baseObject.texture = texture;
165
+ return true;
166
+ }
167
+ }
168
+
169
+ 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,10 @@ 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_TOGGLE_PRESS: 'modules.objects.toggle.press',
13
+ MODULES_OBJECTS_TEXTINPUT_BLUR: 'modules.objects.textinput.blur',
14
+ MODULES_OBJECTS_CHECKBOX_PRESS: 'modules.objects.checkbox.press',
11
15
  MODULES_LOGIC_SOUNDS_DO: 'modules.soundManager.do',
12
16
  MODULES_SOUND_MANAGER_UPDATE_CFG: 'modules.soundManager.updateCfg',
13
17
  MODULES_SOUND_MANAGER_SET_GLOBAL_VOLUME: 'modules.soundManager.setGlobalVolume',
@@ -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
  }