--============================================================================
--  pause.lua
--  Copyright (c) 2009, Bamtang Games. All Rights Reserved.
------------------------------------------------------------------------------
require( "scripts/style.lua" );

kButtonSpacing = 49; -- Put our buttons 60 pixels apart
kButtonY = 53; -- Three buttons means center 60 pixels above the center

-- When this dialog is popped up, we're entering pause state, so
-- let's just notify TGameState now.
SetState(kPause, true);
InsideGame(false);

--function removeOptions() 
--    PopModal("pausemenu");
--end

MakeDialog {
    -- Name the modal dialog
    name="pausemenu";

    PauseWindow {
        x = 0; y = 0;
        w = 800; h = 600;

        Bitmap {
            name = "bmpPanelBlack";
            image = "images/gui/ae_background";
            alpha = true;
            x = 0; y = 0;
            w = 800; h = 600;
        };

        Bitmap {
            name = "bmpPanelContainer";
            image = "images/gui/ae_panelmenu";
            x = kCenter;
            y = 113;

            SetStyle(ButtonStyle);
            Button {
                x = kCenter;
                y = kButtonY;
                name = "resumebutton";
                close = true; -- Just close this window
                cancel=true;
                graphics = ResumeButtonGraphics;
                command=
                    function()
                        InsideGame(true);
                        SetState( kPause, false );
                    end;
            };

            Button {
                x = kCenter;
                y = kButtonY + (kButtonSpacing * 1);
                name = "restartbutton";
                graphics = RestartButtonGraphics;
                command=
                    function()
                        result = DisplayDialog {
                            "scripts/yesno.lua";
                            title = ''; 
                            body = 'restartlevelconfirm'
                        };
                        if result == 'yes' then
                            PopModal("pausemenu");
                            SetState(kPause, false);
                            -- Our game processes this message--it's not
                            -- handled by Playground
                            msg = SendMessage("restartLevel");
                            handleMessage(msg);
                        end
                    end;
            };

            Button {
                x = kCenter;
                y = kButtonY + (kButtonSpacing * 2);
                name = "btnHelp";
                graphics = Help2ButtonGraphics; 
                command =
                    function()
                        DoModal("scripts/help.lua");
                    end;
            };

            Button {
                x=kCenter;
                y=kButtonY + (kButtonSpacing * 3);
                name="optionsbutton";
                graphics = Options2ButtonGraphics; 
                command=
                    function()
                        -- Pop up an options screen
                        DoModal("scripts/options.lua");
                    end
            };

            -- MainMenu.
            Bitmap {
                name = "bmpMainMenuDisabled";
                image = gLocalizedPath.."images/buttons/ae_mainmenu_n";
                x = kCenter;
                y = kButtonY + (kButtonSpacing * 4);
            };
            Button {
                name = "btnMainMenu";
                x = kCenter;
                y = kButtonY + (kButtonSpacing * 4);
                graphics = MainMenuButtonGraphics; 
                command =
                    function()
                        result = DisplayDialog {
                            "scripts/yesno.lua";
                            title = ''; 
                            body = 'quitconfirm'
                        };
                        if result == 'yes' then
                            -- Our game processes this message--it's not
                            -- handled by Playground
                            SendGameMessage("quit");
                            SetState(kPause, false);
                        end
                    end
            };
        };
    };
}
