mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-20 09:16:01 +08:00
[ts] Fixed popup not being hidden, clean up.
This commit is contained in:
parent
87b9821e00
commit
97bc10ba28
20
spine-ts/build/spine-player.d.ts
vendored
20
spine-ts/build/spine-player.d.ts
vendored
@ -1680,7 +1680,7 @@ declare module spine.webgl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module spine {
|
declare module spine {
|
||||||
interface SpinePlayerConfig {
|
export interface SpinePlayerConfig {
|
||||||
jsonUrl: string;
|
jsonUrl: string;
|
||||||
jsonField: string;
|
jsonField: string;
|
||||||
binaryUrl: string;
|
binaryUrl: string;
|
||||||
@ -1737,7 +1737,7 @@ declare module spine {
|
|||||||
loading: (player: SpinePlayer, delta: number) => void;
|
loading: (player: SpinePlayer, delta: number) => void;
|
||||||
downloader: spine.Downloader;
|
downloader: spine.Downloader;
|
||||||
}
|
}
|
||||||
interface Viewport {
|
export interface Viewport {
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
width: number;
|
width: number;
|
||||||
@ -1747,7 +1747,7 @@ declare module spine {
|
|||||||
padTop: string | number;
|
padTop: string | number;
|
||||||
padBottom: string | number;
|
padBottom: string | number;
|
||||||
}
|
}
|
||||||
class SpinePlayer {
|
export class SpinePlayer {
|
||||||
private config;
|
private config;
|
||||||
parent: HTMLElement;
|
parent: HTMLElement;
|
||||||
dom: HTMLElement;
|
dom: HTMLElement;
|
||||||
@ -1766,7 +1766,7 @@ declare module spine {
|
|||||||
private playTime;
|
private playTime;
|
||||||
private selectedBones;
|
private selectedBones;
|
||||||
private cancelId;
|
private cancelId;
|
||||||
private lastPopup;
|
popup: Popup;
|
||||||
error: boolean;
|
error: boolean;
|
||||||
skeleton: Skeleton;
|
skeleton: Skeleton;
|
||||||
animationState: AnimationState;
|
animationState: AnimationState;
|
||||||
@ -1792,12 +1792,24 @@ declare module spine {
|
|||||||
private calculateAnimationViewport;
|
private calculateAnimationViewport;
|
||||||
private drawFrame;
|
private drawFrame;
|
||||||
stopRendering(): void;
|
stopRendering(): void;
|
||||||
|
private hidePopup;
|
||||||
private showSpeedDialog;
|
private showSpeedDialog;
|
||||||
private showAnimationsDialog;
|
private showAnimationsDialog;
|
||||||
private showSkinsDialog;
|
private showSkinsDialog;
|
||||||
private showSettingsDialog;
|
private showSettingsDialog;
|
||||||
private showError;
|
private showError;
|
||||||
}
|
}
|
||||||
|
class Popup {
|
||||||
|
private id;
|
||||||
|
private button;
|
||||||
|
private player;
|
||||||
|
dom: HTMLElement;
|
||||||
|
private className;
|
||||||
|
constructor(id: string, button: HTMLElement, player: SpinePlayer, parent: HTMLElement, htmlContent: string);
|
||||||
|
hide(id: string): boolean;
|
||||||
|
show(): void;
|
||||||
|
}
|
||||||
|
export {};
|
||||||
}
|
}
|
||||||
declare function CodeMirror(el: Element, config: any): void;
|
declare function CodeMirror(el: Element, config: any): void;
|
||||||
declare module spine {
|
declare module spine {
|
||||||
|
|||||||
@ -3702,7 +3702,7 @@ var spine;
|
|||||||
break;
|
break;
|
||||||
case spine.SpacingMode.Proportional:
|
case spine.SpacingMode.Proportional:
|
||||||
var sum = 0;
|
var sum = 0;
|
||||||
for (var i = 0; i < boneCount;) {
|
for (var i = 0, n = spacesCount - 1; i < n;) {
|
||||||
var bone = bones[i];
|
var bone = bones[i];
|
||||||
var setupLength = bone.data.length;
|
var setupLength = bone.data.length;
|
||||||
if (setupLength < PathConstraint.epsilon) {
|
if (setupLength < PathConstraint.epsilon) {
|
||||||
@ -12252,42 +12252,29 @@ var spine;
|
|||||||
SpinePlayer.prototype.stopRendering = function () {
|
SpinePlayer.prototype.stopRendering = function () {
|
||||||
this.stopRequestAnimationFrame = true;
|
this.stopRequestAnimationFrame = true;
|
||||||
};
|
};
|
||||||
|
SpinePlayer.prototype.hidePopup = function (id) {
|
||||||
|
return this.popup && this.popup.hide(id);
|
||||||
|
};
|
||||||
SpinePlayer.prototype.showSpeedDialog = function (speedButton) {
|
SpinePlayer.prototype.showSpeedDialog = function (speedButton) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
if (this.lastPopup) {
|
var id = "speed";
|
||||||
this.lastPopup.dom.remove();
|
if (this.hidePopup(id))
|
||||||
if (findWithClass(this.lastPopup.dom, "spine-player-popup-title").textContent == "Speed") {
|
|
||||||
this.lastPopup = null;
|
|
||||||
speedButton.classList.remove("spine-player-button-icon-speed-selected");
|
|
||||||
return;
|
return;
|
||||||
}
|
var popup = new Popup(id, speedButton, this, this.playerControls, "\n<div class=\"spine-player-popup-title\">Speed</div>\n<hr>\n<div class=\"spine-player-row\" style=\"align-items:center;padding:8px\">\n<div class=\"spine-player-column\">\n\t<div class=\"spine-player-speed-slider\" style=\"margin-bottom:4px\"></div>\n\t<div class=\"spine-player-row\" style=\"justify-content:space-between\"><div>0.1x</div><div>1x</div><div>2x</div></div>\n</div>\n</div>");
|
||||||
}
|
|
||||||
var popup = new Popup(this.dom, this.playerControls, "\n<div class=\"spine-player-popup-title\">Speed</div>\n<hr>\n<div class=\"spine-player-row\" style=\"align-items:center;padding:8px\">\n<div class=\"spine-player-column\">\n\t<div class=\"spine-player-speed-slider\" style=\"margin-bottom:4px\"></div>\n\t<div class=\"spine-player-row\" style=\"justify-content:space-between\"><div>0.1x</div><div>1x</div><div>2x</div></div>\n</div>\n</div>");
|
|
||||||
var slider = new Slider(2, 0.1, true);
|
var slider = new Slider(2, 0.1, true);
|
||||||
findWithClass(popup.dom, "spine-player-speed-slider").appendChild(slider.create());
|
findWithClass(popup.dom, "spine-player-speed-slider").appendChild(slider.create());
|
||||||
slider.setValue(this.speed / 2);
|
slider.setValue(this.speed / 2);
|
||||||
slider.change = function (percentage) { return _this.speed = percentage * 2; };
|
slider.change = function (percentage) { return _this.speed = percentage * 2; };
|
||||||
speedButton.classList.add("spine-player-button-icon-speed-selected");
|
popup.show();
|
||||||
popup.show(function () {
|
|
||||||
speedButton.classList.remove("spine-player-button-icon-speed-selected");
|
|
||||||
popup.dom.remove();
|
|
||||||
_this.lastPopup = null;
|
|
||||||
});
|
|
||||||
this.lastPopup = popup;
|
|
||||||
};
|
};
|
||||||
SpinePlayer.prototype.showAnimationsDialog = function (animationsButton) {
|
SpinePlayer.prototype.showAnimationsDialog = function (animationsButton) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
if (this.lastPopup) {
|
var id = "animations";
|
||||||
this.lastPopup.dom.remove();
|
if (this.hidePopup(id))
|
||||||
if (findWithClass(this.lastPopup.dom, "spine-player-popup-title").textContent == "Animations") {
|
|
||||||
this.lastPopup = null;
|
|
||||||
animationsButton.classList.remove("spine-player-button-icon-animations-selected");
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!this.skeleton || !this.skeleton.data.animations.length)
|
if (!this.skeleton || !this.skeleton.data.animations.length)
|
||||||
return;
|
return;
|
||||||
var popup = new Popup(this.dom, this.playerControls, "<div class=\"spine-player-popup-title\">Animations</div><hr><ul class=\"spine-player-list\"></ul>");
|
var popup = new Popup(id, animationsButton, this, this.playerControls, "<div class=\"spine-player-popup-title\">Animations</div><hr><ul class=\"spine-player-list\"></ul>");
|
||||||
var rows = findWithClass(popup.dom, "spine-player-list");
|
var rows = findWithClass(popup.dom, "spine-player-list");
|
||||||
this.skeleton.data.animations.forEach(function (animation) {
|
this.skeleton.data.animations.forEach(function (animation) {
|
||||||
if (_this.config.animations && _this.config.animations.indexOf(animation.name) < 0)
|
if (_this.config.animations && _this.config.animations.indexOf(animation.name) < 0)
|
||||||
@ -12306,27 +12293,16 @@ var spine;
|
|||||||
_this.play();
|
_this.play();
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
animationsButton.classList.add("spine-player-button-icon-animations-selected");
|
popup.show();
|
||||||
popup.show(function () {
|
|
||||||
animationsButton.classList.remove("spine-player-button-icon-animations-selected");
|
|
||||||
popup.dom.remove();
|
|
||||||
_this.lastPopup = null;
|
|
||||||
});
|
|
||||||
this.lastPopup = popup;
|
|
||||||
};
|
};
|
||||||
SpinePlayer.prototype.showSkinsDialog = function (skinButton) {
|
SpinePlayer.prototype.showSkinsDialog = function (skinButton) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
if (this.lastPopup) {
|
var id = "skins";
|
||||||
this.lastPopup.dom.remove();
|
if (this.hidePopup(id))
|
||||||
if (findWithClass(this.lastPopup.dom, "spine-player-popup-title").textContent == "Skins") {
|
|
||||||
this.lastPopup = null;
|
|
||||||
skinButton.classList.remove("spine-player-button-icon-skins-selected");
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!this.skeleton || !this.skeleton.data.animations.length)
|
if (!this.skeleton || !this.skeleton.data.animations.length)
|
||||||
return;
|
return;
|
||||||
var popup = new Popup(this.dom, this.playerControls, "<div class=\"spine-player-popup-title\">Skins</div><hr><ul class=\"spine-player-list\"></ul>");
|
var popup = new Popup(id, skinButton, this, this.playerControls, "<div class=\"spine-player-popup-title\">Skins</div><hr><ul class=\"spine-player-list\"></ul>");
|
||||||
var rows = findWithClass(popup.dom, "spine-player-list");
|
var rows = findWithClass(popup.dom, "spine-player-list");
|
||||||
this.skeleton.data.skins.forEach(function (skin) {
|
this.skeleton.data.skins.forEach(function (skin) {
|
||||||
if (_this.config.skins && _this.config.skins.indexOf(skin.name) < 0)
|
if (_this.config.skins && _this.config.skins.indexOf(skin.name) < 0)
|
||||||
@ -12344,27 +12320,16 @@ var spine;
|
|||||||
_this.skeleton.setSlotsToSetupPose();
|
_this.skeleton.setSlotsToSetupPose();
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
skinButton.classList.add("spine-player-button-icon-skins-selected");
|
popup.show();
|
||||||
popup.show(function () {
|
|
||||||
skinButton.classList.remove("spine-player-button-icon-skins-selected");
|
|
||||||
popup.dom.remove();
|
|
||||||
_this.lastPopup = null;
|
|
||||||
});
|
|
||||||
this.lastPopup = popup;
|
|
||||||
};
|
};
|
||||||
SpinePlayer.prototype.showSettingsDialog = function (settingsButton) {
|
SpinePlayer.prototype.showSettingsDialog = function (settingsButton) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
if (this.lastPopup) {
|
var id = "settings";
|
||||||
this.lastPopup.dom.remove();
|
if (this.hidePopup(id))
|
||||||
if (findWithClass(this.lastPopup.dom, "spine-player-popup-title").textContent == "Debug") {
|
|
||||||
this.lastPopup = null;
|
|
||||||
settingsButton.classList.remove("spine-player-button-icon-settings-selected");
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!this.skeleton || !this.skeleton.data.animations.length)
|
if (!this.skeleton || !this.skeleton.data.animations.length)
|
||||||
return;
|
return;
|
||||||
var popup = new Popup(this.dom, this.playerControls, "<div class=\"spine-player-popup-title\">Debug</div><hr><ul class=\"spine-player-list\"></li>");
|
var popup = new Popup(id, settingsButton, this, this.playerControls, "<div class=\"spine-player-popup-title\">Debug</div><hr><ul class=\"spine-player-list\"></li>");
|
||||||
var rows = findWithClass(popup.dom, "spine-player-list");
|
var rows = findWithClass(popup.dom, "spine-player-list");
|
||||||
var makeItem = function (label, name) {
|
var makeItem = function (label, name) {
|
||||||
var row = createElement("<li class=\"spine-player-list-item\"></li>");
|
var row = createElement("<li class=\"spine-player-list-item\"></li>");
|
||||||
@ -12383,13 +12348,7 @@ var spine;
|
|||||||
makeItem("Clipping", "clipping");
|
makeItem("Clipping", "clipping");
|
||||||
makeItem("Points", "points");
|
makeItem("Points", "points");
|
||||||
makeItem("Hulls", "hulls");
|
makeItem("Hulls", "hulls");
|
||||||
settingsButton.classList.add("spine-player-button-icon-settings-selected");
|
popup.show();
|
||||||
popup.show(function () {
|
|
||||||
settingsButton.classList.remove("spine-player-button-icon-settings-selected");
|
|
||||||
popup.dom.remove();
|
|
||||||
_this.lastPopup = null;
|
|
||||||
});
|
|
||||||
this.lastPopup = popup;
|
|
||||||
};
|
};
|
||||||
SpinePlayer.prototype.showError = function (message, error) {
|
SpinePlayer.prototype.showError = function (message, error) {
|
||||||
if (error === void 0) { error = null; }
|
if (error === void 0) { error = null; }
|
||||||
@ -12410,35 +12369,49 @@ var spine;
|
|||||||
}());
|
}());
|
||||||
spine.SpinePlayer = SpinePlayer;
|
spine.SpinePlayer = SpinePlayer;
|
||||||
var Popup = (function () {
|
var Popup = (function () {
|
||||||
function Popup(player, parent, htmlContent) {
|
function Popup(id, button, player, parent, htmlContent) {
|
||||||
|
this.id = id;
|
||||||
|
this.button = button;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.dom = createElement("<div class=\"spine-player-popup spine-player-hidden\"></div>");
|
this.dom = createElement("<div class=\"spine-player-popup spine-player-hidden\"></div>");
|
||||||
this.dom.innerHTML = htmlContent;
|
this.dom.innerHTML = htmlContent;
|
||||||
parent.appendChild(this.dom);
|
parent.appendChild(this.dom);
|
||||||
|
this.className = "spine-player-button-icon-" + id + "-selected";
|
||||||
}
|
}
|
||||||
Popup.prototype.show = function (dismissedListener) {
|
Popup.prototype.hide = function (id) {
|
||||||
|
this.dom.remove();
|
||||||
|
this.button.classList.remove(this.className);
|
||||||
|
if (this.id == id) {
|
||||||
|
this.player.popup = null;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Popup.prototype.show = function () {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
this.player.popup = this;
|
||||||
|
this.button.classList.add(this.className);
|
||||||
this.dom.classList.remove("spine-player-hidden");
|
this.dom.classList.remove("spine-player-hidden");
|
||||||
var dismissed = false;
|
var dismissed = false;
|
||||||
var resize = function () {
|
var resize = function () {
|
||||||
if (!dismissed)
|
if (!dismissed)
|
||||||
requestAnimationFrame(resize);
|
requestAnimationFrame(resize);
|
||||||
var bottomOffset = Math.abs(_this.dom.getBoundingClientRect().bottom - _this.player.getBoundingClientRect().bottom);
|
var playerDom = _this.player.dom;
|
||||||
var rightOffset = Math.abs(_this.dom.getBoundingClientRect().right - _this.player.getBoundingClientRect().right);
|
var bottomOffset = Math.abs(playerDom.getBoundingClientRect().bottom - playerDom.getBoundingClientRect().bottom);
|
||||||
var maxHeight = _this.player.clientHeight - bottomOffset - rightOffset;
|
var rightOffset = Math.abs(playerDom.getBoundingClientRect().right - playerDom.getBoundingClientRect().right);
|
||||||
_this.dom.style.maxHeight = maxHeight + "px";
|
_this.dom.style.maxHeight = (playerDom.clientHeight - bottomOffset - rightOffset) + "px";
|
||||||
};
|
};
|
||||||
requestAnimationFrame(resize);
|
requestAnimationFrame(resize);
|
||||||
var justClicked = true;
|
var justClicked = true;
|
||||||
var windowClickListener = function (event) {
|
var windowClickListener = function (event) {
|
||||||
if (justClicked) {
|
if (justClicked || _this.player.popup != _this) {
|
||||||
justClicked = false;
|
justClicked = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!_this.dom.contains(event.target)) {
|
if (!_this.dom.contains(event.target)) {
|
||||||
_this.dom.remove();
|
_this.dom.remove();
|
||||||
window.removeEventListener("click", windowClickListener);
|
window.removeEventListener("click", windowClickListener);
|
||||||
dismissedListener();
|
_this.button.classList.remove(_this.className);
|
||||||
|
_this.player.popup = null;
|
||||||
dismissed = true;
|
dismissed = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -196,7 +196,7 @@ module spine {
|
|||||||
private playTime = 0;
|
private playTime = 0;
|
||||||
private selectedBones: Bone[];
|
private selectedBones: Bone[];
|
||||||
private cancelId = 0;
|
private cancelId = 0;
|
||||||
private lastPopup: Popup;
|
popup: Popup;
|
||||||
|
|
||||||
/* True if the player is unable to load or render the skeleton. */
|
/* True if the player is unable to load or render the skeleton. */
|
||||||
public error: boolean;
|
public error: boolean;
|
||||||
@ -749,7 +749,7 @@ module spine {
|
|||||||
let delta = this.time.delta;
|
let delta = this.time.delta;
|
||||||
|
|
||||||
// Load the skeleton if the assets are ready.
|
// Load the skeleton if the assets are ready.
|
||||||
var loading = this.assetManager.isLoadingComplete();
|
let loading = this.assetManager.isLoadingComplete();
|
||||||
if (!this.skeleton && loading) this.loadSkeleton();
|
if (!this.skeleton && loading) this.loadSkeleton();
|
||||||
let skeleton = this.skeleton;
|
let skeleton = this.skeleton;
|
||||||
let config = this.config;
|
let config = this.config;
|
||||||
@ -781,7 +781,7 @@ module spine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Determine the viewport.
|
// Determine the viewport.
|
||||||
var viewport = this.viewport;
|
let viewport = this.viewport;
|
||||||
viewport.x = this.currentViewport.x - (this.currentViewport.padLeft as number),
|
viewport.x = this.currentViewport.x - (this.currentViewport.padLeft as number),
|
||||||
viewport.y = this.currentViewport.y - (this.currentViewport.padBottom as number),
|
viewport.y = this.currentViewport.y - (this.currentViewport.padBottom as number),
|
||||||
viewport.width = this.currentViewport.width + (this.currentViewport.padLeft as number) + (this.currentViewport.padRight as number),
|
viewport.width = this.currentViewport.width + (this.currentViewport.padLeft as number) + (this.currentViewport.padRight as number),
|
||||||
@ -880,16 +880,15 @@ module spine {
|
|||||||
this.stopRequestAnimationFrame = true;
|
this.stopRequestAnimationFrame = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private hidePopup (id: string): boolean {
|
||||||
|
return this.popup && this.popup.hide(id);
|
||||||
|
}
|
||||||
|
|
||||||
private showSpeedDialog (speedButton: HTMLElement) {
|
private showSpeedDialog (speedButton: HTMLElement) {
|
||||||
if (this.lastPopup) {
|
let id = "speed";
|
||||||
this.lastPopup.dom.remove();
|
if (this.hidePopup(id)) return;
|
||||||
if (findWithClass(this.lastPopup.dom, "spine-player-popup-title").textContent == "Speed") {
|
|
||||||
this.lastPopup = null;
|
let popup = new Popup(id, speedButton, this, this.playerControls, /*html*/`
|
||||||
speedButton.classList.remove("spine-player-button-icon-speed-selected")
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let popup = new Popup(this.dom, this.playerControls, /*html*/`
|
|
||||||
<div class="spine-player-popup-title">Speed</div>
|
<div class="spine-player-popup-title">Speed</div>
|
||||||
<hr>
|
<hr>
|
||||||
<div class="spine-player-row" style="align-items:center;padding:8px">
|
<div class="spine-player-row" style="align-items:center;padding:8px">
|
||||||
@ -902,27 +901,15 @@ module spine {
|
|||||||
findWithClass(popup.dom, "spine-player-speed-slider").appendChild(slider.create());
|
findWithClass(popup.dom, "spine-player-speed-slider").appendChild(slider.create());
|
||||||
slider.setValue(this.speed / 2);
|
slider.setValue(this.speed / 2);
|
||||||
slider.change = (percentage) => this.speed = percentage * 2;
|
slider.change = (percentage) => this.speed = percentage * 2;
|
||||||
speedButton.classList.add("spine-player-button-icon-speed-selected")
|
popup.show();
|
||||||
popup.show(() => {
|
|
||||||
speedButton.classList.remove("spine-player-button-icon-speed-selected")
|
|
||||||
popup.dom.remove();
|
|
||||||
this.lastPopup = null;
|
|
||||||
});
|
|
||||||
this.lastPopup = popup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private showAnimationsDialog (animationsButton: HTMLElement) {
|
private showAnimationsDialog (animationsButton: HTMLElement) {
|
||||||
if (this.lastPopup) {
|
let id = "animations";
|
||||||
this.lastPopup.dom.remove();
|
if (this.hidePopup(id)) return;
|
||||||
if (findWithClass(this.lastPopup.dom, "spine-player-popup-title").textContent == "Animations") {
|
|
||||||
this.lastPopup = null;
|
|
||||||
animationsButton.classList.remove("spine-player-button-icon-animations-selected")
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!this.skeleton || !this.skeleton.data.animations.length) return;
|
if (!this.skeleton || !this.skeleton.data.animations.length) return;
|
||||||
|
|
||||||
let popup = new Popup(this.dom, this.playerControls,
|
let popup = new Popup(id, animationsButton, this, this.playerControls,
|
||||||
/*html*/`<div class="spine-player-popup-title">Animations</div><hr><ul class="spine-player-list"></ul>`);
|
/*html*/`<div class="spine-player-popup-title">Animations</div><hr><ul class="spine-player-list"></ul>`);
|
||||||
|
|
||||||
let rows = findWithClass(popup.dom, "spine-player-list");
|
let rows = findWithClass(popup.dom, "spine-player-list");
|
||||||
@ -944,27 +931,15 @@ module spine {
|
|||||||
this.play();
|
this.play();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
animationsButton.classList.add("spine-player-button-icon-animations-selected")
|
popup.show();
|
||||||
popup.show(() => {
|
|
||||||
animationsButton.classList.remove("spine-player-button-icon-animations-selected")
|
|
||||||
popup.dom.remove();
|
|
||||||
this.lastPopup = null;
|
|
||||||
});
|
|
||||||
this.lastPopup = popup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private showSkinsDialog (skinButton: HTMLElement) {
|
private showSkinsDialog (skinButton: HTMLElement) {
|
||||||
if (this.lastPopup) {
|
let id = "skins";
|
||||||
this.lastPopup.dom.remove();
|
if (this.hidePopup(id)) return;
|
||||||
if (findWithClass(this.lastPopup.dom, "spine-player-popup-title").textContent == "Skins") {
|
|
||||||
this.lastPopup = null;
|
|
||||||
skinButton.classList.remove("spine-player-button-icon-skins-selected")
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!this.skeleton || !this.skeleton.data.animations.length) return;
|
if (!this.skeleton || !this.skeleton.data.animations.length) return;
|
||||||
|
|
||||||
let popup = new Popup(this.dom, this.playerControls,
|
let popup = new Popup(id, skinButton, this, this.playerControls,
|
||||||
/*html*/`<div class="spine-player-popup-title">Skins</div><hr><ul class="spine-player-list"></ul>`);
|
/*html*/`<div class="spine-player-popup-title">Skins</div><hr><ul class="spine-player-list"></ul>`);
|
||||||
|
|
||||||
let rows = findWithClass(popup.dom, "spine-player-list");
|
let rows = findWithClass(popup.dom, "spine-player-list");
|
||||||
@ -984,28 +959,15 @@ module spine {
|
|||||||
this.skeleton.setSlotsToSetupPose();
|
this.skeleton.setSlotsToSetupPose();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
popup.show();
|
||||||
skinButton.classList.add("spine-player-button-icon-skins-selected")
|
|
||||||
popup.show(() => {
|
|
||||||
skinButton.classList.remove("spine-player-button-icon-skins-selected")
|
|
||||||
popup.dom.remove();
|
|
||||||
this.lastPopup = null;
|
|
||||||
});
|
|
||||||
this.lastPopup = popup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private showSettingsDialog (settingsButton: HTMLElement) {
|
private showSettingsDialog (settingsButton: HTMLElement) {
|
||||||
if (this.lastPopup) {
|
let id = "settings";
|
||||||
this.lastPopup.dom.remove();
|
if (this.hidePopup(id)) return;
|
||||||
if (findWithClass(this.lastPopup.dom, "spine-player-popup-title").textContent == "Debug") {
|
|
||||||
this.lastPopup = null;
|
|
||||||
settingsButton.classList.remove("spine-player-button-icon-settings-selected")
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!this.skeleton || !this.skeleton.data.animations.length) return;
|
if (!this.skeleton || !this.skeleton.data.animations.length) return;
|
||||||
|
|
||||||
let popup = new Popup(this.dom, this.playerControls, /*html*/`<div class="spine-player-popup-title">Debug</div><hr><ul class="spine-player-list"></li>`);
|
let popup = new Popup(id, settingsButton, this, this.playerControls, /*html*/`<div class="spine-player-popup-title">Debug</div><hr><ul class="spine-player-list"></li>`);
|
||||||
|
|
||||||
let rows = findWithClass(popup.dom, "spine-player-list");
|
let rows = findWithClass(popup.dom, "spine-player-list");
|
||||||
let makeItem = (label: string, name: string) => {
|
let makeItem = (label: string, name: string) => {
|
||||||
@ -1017,7 +979,6 @@ module spine {
|
|||||||
s.change = (value) => debug[name] = value;
|
s.change = (value) => debug[name] = value;
|
||||||
rows.appendChild(row);
|
rows.appendChild(row);
|
||||||
};
|
};
|
||||||
|
|
||||||
makeItem("Bones", "bones");
|
makeItem("Bones", "bones");
|
||||||
makeItem("Regions", "regions");
|
makeItem("Regions", "regions");
|
||||||
makeItem("Meshes", "meshes");
|
makeItem("Meshes", "meshes");
|
||||||
@ -1026,14 +987,7 @@ module spine {
|
|||||||
makeItem("Clipping", "clipping");
|
makeItem("Clipping", "clipping");
|
||||||
makeItem("Points", "points");
|
makeItem("Points", "points");
|
||||||
makeItem("Hulls", "hulls");
|
makeItem("Hulls", "hulls");
|
||||||
|
popup.show();
|
||||||
settingsButton.classList.add("spine-player-button-icon-settings-selected")
|
|
||||||
popup.show(() => {
|
|
||||||
settingsButton.classList.remove("spine-player-button-icon-settings-selected")
|
|
||||||
popup.dom.remove();
|
|
||||||
this.lastPopup = null;
|
|
||||||
});
|
|
||||||
this.lastPopup = popup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private showError (message: string, error: Error = null) {
|
private showError (message: string, error: Error = null) {
|
||||||
@ -1052,41 +1006,55 @@ module spine {
|
|||||||
|
|
||||||
class Popup {
|
class Popup {
|
||||||
public dom: HTMLElement;
|
public dom: HTMLElement;
|
||||||
|
private className: string;
|
||||||
|
|
||||||
constructor (private player: HTMLElement, parent: HTMLElement, htmlContent: string) {
|
constructor (private id: string, private button: HTMLElement, private player: SpinePlayer, parent: HTMLElement, htmlContent: string) {
|
||||||
this.dom = createElement(/*html*/`<div class="spine-player-popup spine-player-hidden"></div>`);
|
this.dom = createElement(/*html*/`<div class="spine-player-popup spine-player-hidden"></div>`);
|
||||||
this.dom.innerHTML = htmlContent;
|
this.dom.innerHTML = htmlContent;
|
||||||
parent.appendChild(this.dom);
|
parent.appendChild(this.dom);
|
||||||
|
this.className = "spine-player-button-icon-" + id + "-selected";
|
||||||
}
|
}
|
||||||
|
|
||||||
show (dismissedListener: () => void) {
|
hide (id: string): boolean {
|
||||||
|
this.dom.remove();
|
||||||
|
this.button.classList.remove(this.className);
|
||||||
|
if (this.id == id) {
|
||||||
|
this.player.popup = null;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
show () {
|
||||||
|
this.player.popup = this;
|
||||||
|
this.button.classList.add(this.className);
|
||||||
this.dom.classList.remove("spine-player-hidden");
|
this.dom.classList.remove("spine-player-hidden");
|
||||||
|
|
||||||
// Make sure the popup isn't bigger than the player.
|
// Make sure the popup isn't bigger than the player.
|
||||||
let dismissed = false;
|
let dismissed = false;
|
||||||
let resize = () => {
|
let resize = () => {
|
||||||
if (!dismissed) requestAnimationFrame(resize);
|
if (!dismissed) requestAnimationFrame(resize);
|
||||||
let bottomOffset = Math.abs(this.dom.getBoundingClientRect().bottom - this.player.getBoundingClientRect().bottom);
|
let playerDom = this.player.dom;
|
||||||
let rightOffset = Math.abs(this.dom.getBoundingClientRect().right - this.player.getBoundingClientRect().right);
|
let bottomOffset = Math.abs(playerDom.getBoundingClientRect().bottom - playerDom.getBoundingClientRect().bottom);
|
||||||
let maxHeight = this.player.clientHeight - bottomOffset - rightOffset;
|
let rightOffset = Math.abs(playerDom.getBoundingClientRect().right - playerDom.getBoundingClientRect().right);
|
||||||
this.dom.style.maxHeight = maxHeight + "px";
|
this.dom.style.maxHeight = (playerDom.clientHeight - bottomOffset - rightOffset) + "px";
|
||||||
}
|
}
|
||||||
requestAnimationFrame(resize);
|
requestAnimationFrame(resize);
|
||||||
|
|
||||||
// Dismiss when clicking somewhere outside the popup.
|
// Dismiss when clicking somewhere outside the popup.
|
||||||
let justClicked = true;
|
let justClicked = true;
|
||||||
let windowClickListener = (event: any) => {
|
let windowClickListener = (event: any) => {
|
||||||
if (justClicked) {
|
if (justClicked || this.player.popup != this) {
|
||||||
justClicked = false;
|
justClicked = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!this.dom.contains(event.target)) {
|
if (!this.dom.contains(event.target)) {
|
||||||
this.dom.remove();
|
this.dom.remove();
|
||||||
window.removeEventListener("click", windowClickListener);
|
window.removeEventListener("click", windowClickListener);
|
||||||
dismissedListener();
|
this.button.classList.remove(this.className);
|
||||||
|
this.player.popup = null;
|
||||||
dismissed = true;
|
dismissed = true;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
window.addEventListener("click", windowClickListener);
|
window.addEventListener("click", windowClickListener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user