-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhaserTooltip_simple.js
338 lines (275 loc) · 9.54 KB
/
PhaserTooltip_simple.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
class PhaserTooltip {
constructor(scene, pluginManager) {
/**
* A handy reference to the Plugin Manager that is responsible for this plugin.
* Can be used as a route to gain access to game systems and events.
*
* @name Phaser.Plugins.BasePlugin#pluginManager
* @type {Phaser.Plugins.PluginManager}
* @protected
* @since 3.8.0
*/
this.pluginManager = pluginManager;
/**
* A reference to the Game instance this plugin is running under.
*
* @name Phaser.Plugins.BasePlugin#game
* @type {Phaser.Game}
* @protected
* @since 3.8.0
*/
this.game = pluginManager.game;
/**
* A reference to the Scene that has installed this plugin.
* Only set if it's a Scene Plugin, otherwise `null`.
* This property is only set when the plugin is instantiated and added to the Scene, not before.
* You cannot use it during the `init` method, but you can during the `boot` method.
*
* @name Phaser.Plugins.BasePlugin#scene
* @type {?Phaser.Scene}
* @protected
* @since 3.8.0
*/
this.scene = scene;
/**
* A reference to the Scene Systems of the Scene that has installed this plugin.
* Only set if it's a Scene Plugin, otherwise `null`.
* This property is only set when the plugin is instantiated and added to the Scene, not before.
* You cannot use it during the `init` method, but you can during the `boot` method.
*
* @name Phaser.Plugins.BasePlugin#systems
* @type {?Phaser.Scenes.Systems}
* @protected
* @since 3.8.0
*/
this.systems = scene.sys;
/**
* The Sticks that this plugin is responsible for.
* @type {Set}
*/
this.sticks = null;
/**
* The Buttons that this plugin is responsible for.
* @type {Set}
*/
this.buttons = null;
/**
* Internal var to track the Input pointer total.
* @type {integer}
* @private
*/
this._pointerTotal = 0;
scene.sys.events.once('boot', this.boot, this);
this.tooltipCollection = {};
this.target = null;
}
/**
* The boot method.
*
* @private
*/
boot() {
this.systems.events.once('destroy', this.destroy, this);
// Because they may load the plugin via the Loader
if (this.systems.settings.active) {
this.start();
} else {
this.systems.events.on('start', this.start, this);
}
}
start() {
this.systems.events.on('update', this.update, this);
this.systems.events.once('shutdown', this.shutdown, this);
}
/**
* Called automatically by the Phaser Plugin Manager.
*
* Updates all Stick and Button objects.
*
* @param {integer} time - The current game timestep.
*/
update(time) {
}
/**
* Shuts down the event listeners for this plugin.
*/
shutdown() {
const eventEmitter = this.systems.events;
eventEmitter.off('update', this.update, this);
eventEmitter.off('shutdown', this.shutdown, this);
}
/**
* Removes and calls `destroy` on all Stick and Button objects in this plugin.
*/
destroy() {
this.shutdown();
// clean up //
}
test() {
console.log("test!");
}
hideTooltip(id, animate) {
if (animate) {
let isTweening = this.scene.tweens.isTweening(this.tooltipCollection[id].container);
if (isTweening) {
this.scene.tweens.killTweensOf(this.tooltipCollection[id].container);
}
this.tween = this.scene.tweens.add({
targets: this.tooltipCollection[id].container,
alpha: 0,
ease: 'Power1',
duration: 250,
delay: 0,
onComplete: o => {
//this.tween = null;
},
});
} else {
this.tooltipCollection[id].container.visible = false;
}
}
showTooltip(id, animate) {
if (animate) {
this.tooltipCollection[id].container.alpha = 0;
this.tooltipCollection[id].container.visible = true;
this.scene.children.bringToTop(this.tooltipCollection[id].container);
let isTweening = this.scene.tweens.isTweening(this.tooltipCollection[id].container);
if (isTweening) {
this.scene.tweens.killTweensOf(this.tooltipCollection[id].container);
}
this.tween = this.scene.tweens.add({
targets: this.tooltipCollection[id].container,
alpha: 1,
ease: 'Power1',
duration: 500,
delay: 0,
onComplete: o => {
//this.tween = null;
},
});
} else {
this.tooltipCollection[id].container.visible = true;
this.scene.children.bringToTop(this.tooltipCollection[id].container);
}
}
/**
*
*
* @param {*} options
* @memberof FloatingTextUI
*/
createTooltip(options) {
let background;
let container = this.scene.add.container(options.x, options.y);
let content;
if (options.content === undefined && options.text.text !== undefined) {
content = this.createLabel(container, options.x, options.y, options);
} else {
content = options.content;
}
if (options.hasBackground) {
background = this.createBackground(container, content, options.x, options.y, options.background.width, options.background.height, options);
content.x = background.rect.centerX - content.displayWidth * 0.5;
content.y = background.rect.centerY - content.displayHeight * 0.5;
}
container.add(content);
container.x = options.x;
container.y = options.y;
console.log(options, container, background);
this.tooltipCollection[options.id] = { container: container, target: options.target, options: options };
this.target = options.target;
return container;
}
/**
*
*
* @param {*} id
* @returns
* @memberof PhaserTooltip
*/
getTarget(id) {
return this.tooltipCollection[id].target;
}
/**
*
*
* @param {*} id
* @returns
* @memberof PhaserTooltip
*/
getPadding(id) {
var paddingTop = this.tooltipCollection[id].options.paddingTop || 12;
var paddingBottom = this.tooltipCollection[id].options.paddingBottom || 12;
var paddingLeft = this.tooltipCollection[id].options.paddingLeft || 16;
var paddingRight = this.tooltipCollection[id].options.paddingRight || 16;
return { paddingLeft: paddingLeft, paddingRight: paddingRight, paddingTop: paddingTop, paddingBottom: paddingBottom };
}
/**
*
*
* @param {*} x
* @param {*} y
* @param {*} options
* @memberof FloatingTextUI
*/
createLabel(container, x, y, options) {
let text = this.scene.add.text(x, y, options.text.text, {
fontFamily: options.text.fontFamily || 'new_rockerregular',
fontSize: options.text.fontSize || 19,
color: options.text.textColor || "#ffffff",
fontStyle: options.text.fontStyle || '',
align: options.text.align || 'center'
});
console.log(options);
if (options.hasShadow) {
let shadowColor = options.text.shadowColor || "#1e1e1e";
let blur = options.text.blur || 1;
let shadowStroke = options.text.shadowStroke || false;
let shadowFill = options.text.shadowFill || true;
text.setShadow(0, 0, shadowColor, blur, shadowStroke, shadowFill);
}
//Phaser.Display.Align.In.Center(text, background.rect);
return text;
}
/**
*
*
* @param {*} x
* @param {*} y
* @param {*} width
* @param {*} height
* @param {*} color
* @param {*} border
* @param {*} borderColor
* @memberof FloatingTextUI
*/
createBackground(container, content, x, y, width, height, options) {
var paddingTop = options.paddingTop || 12;
var paddingBottom = options.paddingBottom || 12;
var paddingLeft = options.paddingLeft || 16;
var paddingRight = options.paddingRight || 16;
let lineStyle = options.background.lineStyle || {
width: 2,
color: 0x000000,
alpha: 0.9
};
let fillStyle = options.background.fillStyle || {
color: 0x000000,
alpha: 0.9
};
var graphics = this.scene.add.graphics({
lineStyle: lineStyle,
fillStyle: fillStyle
});
let _width = width >= (content.displayWidth + paddingLeft + paddingRight) ? width : content.displayWidth + paddingLeft + paddingRight;
let _height = height >= (content.displayHeight + paddingTop + paddingBottom) ? height : content.displayHeight + paddingTop + paddingBottom;
var rect = new Phaser.Geom.Rectangle(0, 0, _width, _height);
rect.width = _width;
rect.height = _height;
graphics.fillRectShape(rect);
container.add(graphics);
return { rect: rect, graphic: graphics };
}
showLabel() {
}
}