[ts][player] popup is dismissed if button is pressed a second time.

This commit is contained in:
badlogic 2018-12-10 15:39:12 +01:00
parent c09b0673ac
commit 6596319c36
4 changed files with 12299 additions and 12228 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -53,6 +53,9 @@
/* Optional: list of animation names from which the user can choose. */ /* Optional: list of animation names from which the user can choose. */
animations: string[] animations: string[]
/* Optional: the default mix time used to switch between two animations. */
defaultMix: number
/* Optional: the name of the skin to be set. Default: the default skin. */ /* Optional: the name of the skin to be set. Default: the default skin. */
skin: string skin: string
@ -158,7 +161,7 @@
return; return;
} }
if (!isContained(this.dom, event.target)) { if (!isContained(this.dom, event.target)) {
this.dom.parentNode.removeChild(this.dom); this.dom.remove();
window.removeEventListener("click", windowClickListener); window.removeEventListener("click", windowClickListener);
dismissedListener(); dismissedListener();
dismissed = true; dismissed = true;
@ -354,6 +357,9 @@
if (typeof config.showControls === "undefined") if (typeof config.showControls === "undefined")
config.showControls = true; config.showControls = true;
if (typeof config.defaultMix === "undefined")
config.defaultMix = 0.25;
return config; return config;
} }
@ -507,7 +513,14 @@
return dom; return dom;
} }
private lastPopup: Popup;
showSpeedDialog (speedButton: HTMLElement) { showSpeedDialog (speedButton: HTMLElement) {
if (this.lastPopup) this.lastPopup.dom.remove()
if (this.lastPopup && findWithClass(this.lastPopup.dom, "spine-player-popup-title")[0].textContent == "Speed") {
this.lastPopup = null;
speedButton.classList.remove("spine-player-button-icon-speed-selected")
return;
}
let popup = new Popup(this.dom, this.playerControls, /*html*/` 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>
@ -533,9 +546,16 @@
popup.show(() => { popup.show(() => {
speedButton.classList.remove("spine-player-button-icon-speed-selected") speedButton.classList.remove("spine-player-button-icon-speed-selected")
}); });
this.lastPopup = popup;
} }
showAnimationsDialog (animationsButton: HTMLElement) { showAnimationsDialog (animationsButton: HTMLElement) {
if (this.lastPopup) this.lastPopup.dom.remove()
if (this.lastPopup && findWithClass(this.lastPopup.dom, "spine-player-popup-title")[0].textContent == "Animations") {
this.lastPopup = null;
animationsButton.classList.remove("spine-player-button-icon-animations-selected")
return;
}
if (!this.skeleton || this.skeleton.data.animations.length == 0) return; if (!this.skeleton || this.skeleton.data.animations.length == 0) return;
let popup = new Popup(this.dom, this.playerControls, /*html*/` let popup = new Popup(this.dom, this.playerControls, /*html*/`
@ -574,9 +594,16 @@
popup.show(() => { popup.show(() => {
animationsButton.classList.remove("spine-player-button-icon-animations-selected") animationsButton.classList.remove("spine-player-button-icon-animations-selected")
}); });
this.lastPopup = popup;
} }
showSkinsDialog (skinButton: HTMLElement) { showSkinsDialog (skinButton: HTMLElement) {
if (this.lastPopup) this.lastPopup.dom.remove()
if (this.lastPopup && findWithClass(this.lastPopup.dom, "spine-player-popup-title")[0].textContent == "Skins") {
this.lastPopup = null;
skinButton.classList.remove("spine-player-button-icon-skins-selected")
return;
}
if (!this.skeleton || this.skeleton.data.animations.length == 0) return; if (!this.skeleton || this.skeleton.data.animations.length == 0) return;
let popup = new Popup(this.dom, this.playerControls, /*html*/` let popup = new Popup(this.dom, this.playerControls, /*html*/`
@ -616,9 +643,16 @@
popup.show(() => { popup.show(() => {
skinButton.classList.remove("spine-player-button-icon-skins-selected") skinButton.classList.remove("spine-player-button-icon-skins-selected")
}); });
this.lastPopup = popup;
} }
showSettingsDialog (settingsButton: HTMLElement) { showSettingsDialog (settingsButton: HTMLElement) {
if (this.lastPopup) this.lastPopup.dom.remove()
if (this.lastPopup && findWithClass(this.lastPopup.dom, "spine-player-popup-title")[0].textContent == "Debug") {
this.lastPopup = null;
settingsButton.classList.remove("spine-player-button-icon-settings-selected")
return;
}
if (!this.skeleton || this.skeleton.data.animations.length == 0) return; if (!this.skeleton || this.skeleton.data.animations.length == 0) return;
let popup = new Popup(this.dom, this.playerControls, /*html*/` let popup = new Popup(this.dom, this.playerControls, /*html*/`
@ -653,6 +687,7 @@
popup.show(() => { popup.show(() => {
settingsButton.classList.remove("spine-player-button-icon-settings-selected") settingsButton.classList.remove("spine-player-button-icon-settings-selected")
}); });
this.lastPopup = popup;
} }
drawFrame (requestNextFrame = true) { drawFrame (requestNextFrame = true) {
@ -808,7 +843,7 @@
} }
this.skeleton = new Skeleton(skeletonData); this.skeleton = new Skeleton(skeletonData);
let stateData = new AnimationStateData(skeletonData); let stateData = new AnimationStateData(skeletonData);
stateData.defaultMix = 0.2; stateData.defaultMix = this.config.defaultMix;
this.animationState = new AnimationState(stateData); this.animationState = new AnimationState(stateData);
// Check if all controllable bones are in the skeleton // Check if all controllable bones are in the skeleton