System.register(['../input/Pad'], function(exports_1) {
    var __extends = (this && this.__extends) || function (d, b) {
        for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
    var Pad_1;
    var State, MenuScreen, MenuItem;
    return {
        setters:[
            function (Pad_1_1) {
                Pad_1 = Pad_1_1;
            }],
        execute: function() {
            State = Phaser.State;
            MenuScreen = (function (_super) {
                __extends(MenuScreen, _super);
                function MenuScreen() {
                    var _this = this;
                    _super.apply(this, arguments);
                    this.menuItems = [];
                    this.menuIndex = 0;
                    this.style = { font: "40px Arial", fill: "#ececec", align: "center" };
                    this.styleActive = { font: "40px Arial", fill: "white", align: "center" };
                    this.positionMenuItems = function () {
                        _this.menuItems.reverse().forEach(function (item, index) {
                            item.textElement.position.set(_this.game.world.centerX - (item.textElement.width / 2), (_this.game.world.height - 70) - index * 70);
                        });
                        _this.menuItems.reverse();
                    };
                    this.updateActiveMenuItem = function () {
                        _this.menuItems.forEach(function (item, index) {
                            item.textElement.setStyle(index === _this.menuIndex ? _this.styleActive : _this.style);
                        });
                    };
                }
                MenuScreen.prototype.preload = function () {
                    this.game.load.image('menu_bg', 'assets/images/menu_bg.png');
                    this.game.load.audio('menu_music', 'assets/music/menu.ogg');
                    this.game.load.audio('menu_select', 'assets/sounds/menu_select.ogg');
                };
                MenuScreen.prototype.create = function () {
                    var _this = this;
                    this.game.stage.backgroundColor = '#201d1d';
                    this.game.add.sprite(0, 0, 'menu_bg');
                    this.music = this.game.add.audio('menu_music');
                    this.music.play();
                    var menuSelectSound = this.game.add.audio('menu_select');
                    this.game.input.gamepad.start();
                    this.pad = new Pad_1.Pad(this.game.input.gamepad.pad1);
                    this.pad.onUp = function () {
                        _this.menuIndex = Math.max(0, _this.menuIndex - 1);
                    };
                    this.pad.onDown = function () {
                        _this.menuIndex = Math.min(_this.menuItems.length - 1, _this.menuIndex + 1);
                    };
                    this.pad.onAnyArrow = function () {
                        _this.updateActiveMenuItem();
                    };
                    this.pad.onThree = function () {
                        var selectedMenuItem = _this.menuItems[_this.menuIndex];
                        menuSelectSound.play();
                        _this.game.add.tween(selectedMenuItem.textElement)
                            .to({ x: _this.game.world.width }, 300, Phaser.Easing.Bounce.Out, true)
                            .onComplete.add(function () {
                            if (selectedMenuItem.action) {
                                selectedMenuItem.action();
                            }
                        });
                    };
                    this.menuItems.push(new MenuItem(this, "Start", function () {
                        _this.game.state.start('actOne');
                    }));
                    this.positionMenuItems();
                    this.updateActiveMenuItem();
                };
                MenuScreen.prototype.shutdown = function () {
                    this.music.stop();
                };
                return MenuScreen;
            })(State);
            exports_1("MenuScreen", MenuScreen);
            MenuItem = (function () {
                function MenuItem(menu, caption, action) {
                    this.caption = caption;
                    this.action = action;
                    this.textElement = menu.game.add.text(0, 0, caption, menu.style);
                }
                return MenuItem;
            })();
        }
    }
});
//# sourceMappingURL=MenuScreen.js.map