Fixed hidden buttons being stuck in "over" state
This commit is contained in:
parent
d4ae153685
commit
d61f9b7b2b
|
@ -35,6 +35,24 @@ module TS.SpaceTac.UI.Specs {
|
|||
expect(testgame.baseview.animations.simulate(obj, 'alpha')).toEqual([0.6, 0.5, 0.4, 0.3, 0.2]);
|
||||
});
|
||||
|
||||
it("blocks input while object is hidden", function () {
|
||||
let obj = { visible: true, alpha: 1, input: { enabled: true }, changeStateFrame: jasmine.createSpy("changeStateFrame"), freezeFrames: false };
|
||||
|
||||
testgame.baseview.animations.setVisible(obj, false, 0);
|
||||
expect(obj.visible).toBe(false);
|
||||
expect(obj.alpha).toBe(0);
|
||||
expect(obj.input.enabled).toBe(false);
|
||||
expect(obj.changeStateFrame).toHaveBeenCalledWith("Out");
|
||||
expect(obj.freezeFrames).toBe(true);
|
||||
|
||||
testgame.baseview.animations.setVisible(obj, true, 0);
|
||||
expect(obj.visible).toBe(true);
|
||||
expect(obj.alpha).toBe(1);
|
||||
expect(obj.input.enabled).toBe(true);
|
||||
expect(obj.changeStateFrame).toHaveBeenCalledTimes(1);
|
||||
expect(obj.freezeFrames).toBe(false);
|
||||
});
|
||||
|
||||
it("animates rotation", function () {
|
||||
let obj = { rotation: -Math.PI * 2.5 };
|
||||
let tween = testgame.ui.tweens.create(obj);
|
||||
|
|
|
@ -1,25 +1,20 @@
|
|||
module TS.SpaceTac.UI {
|
||||
interface PhaserGraphics {
|
||||
x: number;
|
||||
y: number;
|
||||
rotation: number;
|
||||
game: Phaser.Game;
|
||||
x: number
|
||||
y: number
|
||||
rotation: number
|
||||
game: Phaser.Game
|
||||
};
|
||||
|
||||
/**
|
||||
* Interface of an object that may be enabled/disabled.
|
||||
*/
|
||||
interface IAnimationEnableable {
|
||||
enabled: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface of an object that may be shown/hidden, with opacity transition.
|
||||
*/
|
||||
interface IAnimationFadeable {
|
||||
alpha: number;
|
||||
visible: boolean;
|
||||
input?: IAnimationEnableable;
|
||||
alpha: number
|
||||
visible: boolean
|
||||
input?: { enabled: boolean }
|
||||
changeStateFrame?: Function
|
||||
freezeFrames?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -73,11 +68,18 @@ module TS.SpaceTac.UI {
|
|||
tween.to({ alpha: alpha }, duration);
|
||||
if (obj.input) {
|
||||
let input = obj.input;
|
||||
tween.onComplete.addOnce(() => input.enabled = true);
|
||||
tween.onComplete.addOnce(() => {
|
||||
input.enabled = true
|
||||
obj.freezeFrames = false;
|
||||
});
|
||||
}
|
||||
tween.start();
|
||||
} else {
|
||||
obj.alpha = alpha;
|
||||
if (obj.input) {
|
||||
obj.input.enabled = true;
|
||||
obj.freezeFrames = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,6 +87,11 @@ module TS.SpaceTac.UI {
|
|||
* Hide an object, with opacity transition
|
||||
*/
|
||||
hide(obj: IAnimationFadeable, duration = 1000, alpha = 0): void {
|
||||
if (obj.changeStateFrame) {
|
||||
obj.changeStateFrame("Out");
|
||||
obj.freezeFrames = true;
|
||||
}
|
||||
|
||||
if (obj.input) {
|
||||
obj.input.enabled = false;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue