require( "scripts/style.lua" );

local dlg_pause_timer = {
    name = "pnl_pause",
    category = "UI",
};

local dlg_pause_name = "pausemenu";

local buttonXLeft = 165;
local buttonXRight = 295;
local kButtonSpace = 70;
local buttonY = 45;
local buttonDeltaY = 80;

local kQuitMessage = "";

MakeDialog
{
    BitmapVisual
    {
        name="bmp_fade_pause",
        image    = "cutscenes/black",
        timer_settings = {
            name = "fade",
            category = "UI",
        },
        x = 512, y = 384,
        w = 1024, h = 768,
        
        WindowExt
        {
            name=dlg_pause_name,
            x=512, y=384,
            fit = true,
            
            timer_settings = dlg_pause_timer,
            state_handlers = {
                justcreated = function()
                    SuspendFXPool("");
                    ResumeFXPool("pause");
                    EnableWindow("pnl_water_barrel_rollover", false);
                    EnableWindow("pnl_fountain_rollover", false);
                    EnableWindow("pnl_gates_rollover", false);
                    EnableWindow("pnl_magic_object_rollover", false);
                    EnableWindow("pnl_storage_rollover", false);
                    ShowControl(dlg_pause_name);
                    PauseTimer("ui", "UI");
                    PauseTimer("panels", "UI");
                    PauseTimer("game", "game");
                    SetCursorAllowed(true);
                end;
                showing = function()
                    bmp_fade_pause_StartCurveCallBack("curves/fade.xml","fast_in","");
                    SetItemCount("pnl_pause_state", 1);
                end;
                hiding = function()
                    bmp_fade_pause_StartCurveCallBack("curves/fade.xml","fast_out","");
                end;
                hidden = function()
                    CloseWindow(kQuitMessage);
                    
                    if not EffectRunning() then
                        StartTimer("ui", "UI");
                        StartTimer("game", "game");
                        StartTimer("panels", "UI");
                    end;
                    
                    if RestoreEatenCursorState ~= nil then
                        RestoreEatenCursorState()
                    end;

                    ResumeFXPool("");
                    SuspendFXPool("pause");
                    SetItemCount("pnl_pause_state", 0);
                end;
            },

            Bitmap
            {
                image="backgrounds/dialog",
                x=kCenter,
                y=kCenter,

                SetStyle(ButtonStyle),
                
                -- RESUME
                Button
                {
                    flags = kHAlignCenter + kVAlignCenter,
                    label = "resume",
                    x = kCenter - kButtonSpace,
                    y = buttonY + buttonDeltaY * 0,
                    font = CreateNamedFont(MinionSbItSymbolSet, 24, ButtonBrown),
                    command = function()
                        HideControl(dlg_pause_name);
                    end;
                },
                
                -- RESTART
                Button
                {
                    flags = kHAlignCenter + kVAlignCenter,
                    label = "restart",
                    x = kCenter + kButtonSpace,
                    y = buttonY + buttonDeltaY * 0,
                    font = CreateNamedFont(MinionSbItSymbolSet, 24, ButtonBrown),
                    command = function()
                        EnableWindow(dlg_pause_name, false);
                        retval = DisplayDialog{
                                "scripts/dlg_yesno.lua",
                                title = "restart_quest_title",
                                body = "restart_quest_body",
                                image = "interface/dlg_yes_no/restart_1",
                                dlg_name = "dlg_quit_menu",
                                timer = {
                                    name = "pnl_quit",
                                    category = "quit",
                                },
                            };
                        if retval == "yes" then
                            kQuitMessage = "restart";
                            HideControl(dlg_pause_name);
                        else
                            EnableWindow(dlg_pause_name, true);
                        end;
                    end;
                },
                
                -- OPTIONS
                Button
                {
                    flags = kHAlignCenter + kVAlignCenter,
                    label = "options",
                    x = kCenter - kButtonSpace,
                    y = buttonY + buttonDeltaY * 1,
                    font = CreateNamedFont(MinionSbItSymbolSet, 24, ButtonBrown),
                    command = function()
                        EnableWindow(dlg_pause_name, false);
                        local stub = DoModal("scripts/options.lua");
                        EnableWindow(dlg_pause_name, true);
                    end;
                },
                
                -- HELP
                Button
                {
                    flags = kHAlignCenter + kVAlignCenter,
                    label = "help",
                    x = kCenter + kButtonSpace,
                    y = buttonY + buttonDeltaY * 1,
                    font = CreateNamedFont(MinionSbItSymbolSet, 24, ButtonBrown),
                    command = function()
                        DoModal("scripts/help.lua");
                    end;
                },
                
                
                -- MAP
                Button
                {
                    flags = kHAlignCenter + kVAlignCenter,
                    label = "map",
                    x = kCenter - kButtonSpace,
                    y = buttonY + buttonDeltaY * 2,
                    font = CreateNamedFont(MinionSbItSymbolSet, 24, ButtonBrown),
                    command = function()
                        EnableWindow(dlg_pause_name, false);
                        retval = DisplayDialog{
                                "scripts/dlg_yesno.lua",
                                title = "quit_map_title",
                                body = "quit_map_confirm",
                                image = "interface/dlg_yes_no/quit_to_map",
                                dlg_name = "dlg_quit_map",
                                timer = {
                                    name = "pnl_quit",
                                    category = "quit",
                                },
                            };
                        if retval == "yes" then
                            kQuitMessage = "map";
                            HideControl(dlg_pause_name);
                        else
                            EnableWindow(dlg_pause_name, true);
                        end;
                    end;
                },
                
                --QUIT
                Button
                {
                    flags = kHAlignCenter + kVAlignCenter,
                    label = "quit",
                    x = kCenter + kButtonSpace,
                    y = buttonY + buttonDeltaY * 2,
                    font = CreateNamedFont(MinionSbItSymbolSet, 24, ButtonBrown),
                    command = function()
                        EnableWindow(dlg_pause_name, false);
                        retval = DisplayDialog{
                                "scripts/dlg_yesno.lua",
                                title = "quit_menu_title",
                                body = "quit_menu_confirm",
                                image = "interface/dlg_yes_no/quit_to_menu",
                                dlg_name = "dlg_quit_menu",
                                timer = {
                                    name = "pnl_quit",
                                    category = "quit",
                                },
                            };
                        if retval == "yes" then
                            kQuitMessage = "quit";
                            HideControl(dlg_pause_name);
                        else
                            EnableWindow(dlg_pause_name, true);
                        end;
                    end;
                },

                -- LAMP FX

                WndFxSprite
                {
                    name = "left_lamp_firebugs_fx",
                    x = 0,
                    y = 0,
                    w = 580,
                    h = 310,
                    effect_position = "67,96",
                    file_name = "fx/lamp_firebugs.lua",
                    start_activate = true,
                    advance = 50,
                    anim_pool = "pause",
                    timer_settings = {
                        name = "control",
                        category = "control",
                    },
                },

                WndFxSprite
                {
                    name = "right_lamp_firebugs_fx",
                    x = 0,
                    y = 0,
                    w = 580,
                    h = 310,
                    effect_position = "518,96",
                    file_name = "fx/lamp_firebugs.lua",
                    start_activate = true,
                    advance = 50,
                    anim_pool = "pause",
                    timer_settings = {
                        name = "control",
                        category = "control",
                    },
                },

                WndFxSprite
                {
                    name = "left_lamp_light_fx",
                    x = 0,
                    y = 0,
                    w = 580,
                    h = 310,
                    effect_position = "67,96",
                    file_name = "fx/lamp_light.lua",
                    start_activate = true,
                    advance = 50,
                    anim_pool = "pause",
                    timer_settings = {
                        name = "control",
                        category = "control",
                    },
                },

                WndFxSprite
                {
                    name = "right_lamp_light_fx",
                    x = 0,
                    y = 0,
                    w = 580,
                    h = 310,
                    effect_position = "518,96",
                    file_name = "fx/lamp_light.lua",
                    start_activate = true,
                    advance = 50,
                    anim_pool = "pause",
                    timer_settings = {
                        name = "control",
                        category = "control",
                    },
                },
            },
        },
    },
};
