2017-09-24 22:23:22 +00:00
|
|
|
module TK.SpaceTac.UI {
|
2018-05-15 14:57:45 +00:00
|
|
|
/**
|
|
|
|
* A single displayed message
|
|
|
|
*/
|
|
|
|
class Message extends UIContainer {
|
2017-05-22 20:41:34 +00:00
|
|
|
view: BaseView
|
2018-05-15 14:57:45 +00:00
|
|
|
background: UIBackground
|
|
|
|
text: UIText
|
2015-04-15 00:00:00 +00:00
|
|
|
|
2017-02-16 22:59:41 +00:00
|
|
|
constructor(parent: Messages, text: string, duration: number) {
|
2018-05-15 14:57:45 +00:00
|
|
|
super(parent.view);
|
2017-05-22 20:41:34 +00:00
|
|
|
|
|
|
|
this.view = parent.view;
|
2018-04-16 18:12:26 +00:00
|
|
|
let builder = new UIBuilder(this.view).in(this);
|
2017-05-22 20:41:34 +00:00
|
|
|
|
2018-05-15 14:57:45 +00:00
|
|
|
this.background = new UIBackground(this.view, this);
|
2015-04-15 00:00:00 +00:00
|
|
|
|
2018-04-16 18:12:26 +00:00
|
|
|
this.text = builder.text(text, 0, 0, { color: "#DBEFF9", shadow: true, size: 16, center: false, vcenter: false });
|
2015-04-15 00:00:00 +00:00
|
|
|
|
2018-05-15 14:57:45 +00:00
|
|
|
UITools.drawBackground(this.text, this.background, 6);
|
2017-05-22 20:41:34 +00:00
|
|
|
|
2018-05-15 14:57:45 +00:00
|
|
|
let bounds = UITools.getBounds(this);
|
2018-06-26 21:37:50 +00:00
|
|
|
this.setPosition(parent.view.getX(1) - bounds.width - 25, 25);
|
2017-05-22 20:41:34 +00:00
|
|
|
parent.view.timer.schedule(duration, () => this.hide());
|
2015-04-15 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2018-05-15 14:57:45 +00:00
|
|
|
/**
|
|
|
|
* Hide the message
|
|
|
|
*/
|
2015-04-15 00:00:00 +00:00
|
|
|
hide() {
|
2018-05-15 14:57:45 +00:00
|
|
|
this.view.animations.addAnimation<UIContainer>(this, { y: this.y + 50, alpha: 0 }, 400, "Circ.easeIn").then(() => this.destroy());
|
2017-05-22 20:41:34 +00:00
|
|
|
}
|
2015-04-15 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2018-05-15 14:57:45 +00:00
|
|
|
/**
|
|
|
|
* Visual notifications of game-related messages (eg. "Game saved"...)
|
|
|
|
*/
|
2015-04-15 00:00:00 +00:00
|
|
|
export class Messages {
|
|
|
|
// Link to parent view
|
2018-05-15 14:57:45 +00:00
|
|
|
view: BaseView
|
2015-04-15 00:00:00 +00:00
|
|
|
|
|
|
|
// Main group to hold the visual messages
|
2018-05-15 14:57:45 +00:00
|
|
|
container: UIContainer
|
2015-04-15 00:00:00 +00:00
|
|
|
|
2018-05-15 14:57:45 +00:00
|
|
|
constructor(view: BaseView) {
|
|
|
|
this.view = view;
|
|
|
|
this.container = new UIBuilder(view, view.messages_layer).container("messages");
|
2015-04-15 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2018-05-15 14:57:45 +00:00
|
|
|
/**
|
|
|
|
* Add a new message to the notifications
|
|
|
|
*/
|
2017-05-22 20:41:34 +00:00
|
|
|
addMessage(text: string, duration: number = 3000): void {
|
2018-05-15 14:57:45 +00:00
|
|
|
let message = new Message(this, text, duration);
|
|
|
|
let bounds = UITools.getBounds(message);
|
|
|
|
cfilter(this.container.list, Message).forEach(child => {
|
2018-06-26 21:37:50 +00:00
|
|
|
child.y += bounds.height + 15;
|
2018-05-15 14:57:45 +00:00
|
|
|
});
|
2018-06-26 21:37:50 +00:00
|
|
|
this.container.add(message);
|
2015-04-15 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|