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

local countIcons = 0;
local countButtons = 0;

function closeMetamap()
    SwapToModal("scripts/loading.lua");
end

function MakeIcon(posx, posy)
    countIcons = countIcons + 1;
    return Group {
        Bitmap {
            name = "bmpIcon"..countIcons.."_n";
            image = "gpx/screens/icon_metamap_icon_n";
            x = posx; y = posy;
        };
        Bitmap {
            name = "bmpIcon"..countIcons.."_d";
            image = "gpx/screens/icon_metamap_icon_n";
            x = posx; y = posy;
        };
    };
end

function MakeButton(typeBtn, posx, posy, goalX, goalY)
    local BtnGpx = { };
    local BtnGpxF = { };
    local modeGame = "";
    if (typeBtn == "classic") then
        modeGame = "Classic"
        BtnGpx = ClassicButtonGpx;
        BtnGpxF = ClassicButtonGpxF;
    elseif (typeBtn == "blitz") then
        modeGame = "Blitz"
        BtnGpx = BlitzButtonGpx;
        BtnGpxF = BlitzButtonGpxF;
    elseif (typeBtn == "strategy") then
        modeGame = "Strategy"
        BtnGpx = StrategyButtonGpx;
        BtnGpxF = StrategyButtonGpxF;
    elseif (typeBtn == "cradle") then
        modeGame = "Rome"
        BtnGpx = CradleButtonGpx;
        BtnGpxF = CradleButtonGpxF;
    elseif (typeBtn == "joker") then
        modeGame = "Joker"
        BtnGpx = JockerButtonGpx;
        BtnGpxF = JockerButtonGpxF;
    end

    countButtons = countButtons + 1;
    local index = countButtons;

    if not goalX then
        goalX = posx;
    end
    if not goalY then
        goalY = posy;
    end

    return Group {
        clsMetamapButton {
            name = "mbtn_"..countButtons;
            id = countButtons;
            type = typeBtn;

            x = posx; y = posy;
            w = 57; h = 58;

            Button {
                name = "btnMetamap";
                graphics = BtnGpx;
                command = function()
                    gGameMode = modeGame;
                    SetState(kPause, false);
                    gfn_onMetamapButton_Pressed(index);
                    --DoModal('scripts/finish_quest.lua');
                end
            };

            Bitmap {
                name = "bmpLock";
                image = "gpx/screens/icon_metamap_locked";
            };
            Button {
                name = "btnFinish";
                graphics = BtnGpxF;
                command = function()
                    gGameMode = modeGame;
                    SetState(kPause, false);
                    gfn_onMetamapButton_Pressed(index);
                    --DoModal('scripts/finish_quest.lua');
                end
            };
        };

        Bitmap {
            name = "bmpIconGoal_"..countButtons;
            image = "gpx/screens/icon_goal_metamap";
            x = goalX; y = goalY;
        };
    };
end

MakeDialog {
    name = "MetamapDialog";

    wndMetamap {
        w = 1024; h = 768;

        Bitmap {
            image = "gpx/screens/metamap_background";
            name = "bmpPanelBg";
            x = 0; y = 0;
        };

        Text {
            name = "lblTestMode";
            label = "#Test mode [T]";
            font = Font18White;
            x = 5; y = 730;
            w = 250; h = 40;
            flags = kHAlignLeft + kVAlignCenter;
        };

        SetStyle(PanelButtonStyle);
        --Button {
        --    name = "btnBack";
        --    label = 'btnBack';
        --    font = Font18,
        --    x = 859; y = 720;
        --    command = function()
        --        gfn_onMetamapButton_Back();
        --    end
        --};

        -- Icons
        MakeIcon(101, 153);
        MakeIcon(246, 349);
        MakeIcon(359, 398);
        MakeIcon(469, 516);
        MakeIcon(566, 597);
        MakeIcon(889, 605);
        MakeIcon(783, 468);
        MakeIcon(743, 378);
        MakeIcon(610, 231);
        MakeIcon(489, 80);

        SetStyle(MetamapButtonStyle);

        -- Mountain.
        MakeButton("classic",   118, 211);    -- 1
        MakeButton("classic",    61, 226);
        MakeButton("strategy",   24, 284);
        MakeButton("strategy",   18, 342);
        MakeButton("classic",    46, 400);   -- 5
        MakeButton("strategy",  103, 406);
        MakeButton("strategy",  160, 373);
        MakeButton("classic",   116, 315);
        MakeButton("classic",   173, 283);
        MakeButton("strategy",  230, 288);     -- 10

        -- Forest.
        MakeButton("blitz",     374, 456);      -- 11
        MakeButton("blitz",     316, 484);
        MakeButton("classic",   258, 516);
        MakeButton("strategy",  203, 552);
        MakeButton("blitz",     145, 583);    -- 15
        MakeButton("classic",   140, 641);
        MakeButton("joker",     197, 674);
        MakeButton("strategy",  253, 636);
        MakeButton("joker",     292, 578);
        MakeButton("strategy",  348, 545);     -- 20
        MakeButton("joker",     405, 515);

        -- City.
        MakeButton("cradle",    612, 660);
        MakeButton("classic",   669, 686);
        MakeButton("blitz",     726, 680);
        MakeButton("cradle",    711, 622);     -- 25
        MakeButton("joker",     654, 597);
        MakeButton("strategy",  616, 537);
        MakeButton("blitz",     642, 479);
        MakeButton("cradle",    699, 502);
        MakeButton("strategy",  739, 560);   -- 30
        MakeButton("joker",     775, 618);
        MakeButton("cradle",    831, 625);

        -- Beach.
        MakeButton("strategy",  840, 432);
        MakeButton("blitz",     897, 411);
        MakeButton("joker",     954, 366);      -- 35
        MakeButton("classic",   963, 308);
        MakeButton("cradle",    959, 250);
        MakeButton("blitz",     932, 192);
        MakeButton("cradle",    875, 174);
        MakeButton("joker",     819, 174);   -- 40
        MakeButton("blitz",     762, 204);
        MakeButton("cradle",    734, 262);
        MakeButton("joker",     730, 320);

        -- Space.
        MakeButton("blitz",     554, 248);
        MakeButton("joker",     497, 260);     -- 45
        MakeButton("cradle",    441, 239);
        MakeButton("strategy",  386, 196);
        MakeButton("joker",     380, 138);
        MakeButton("blitz",     386,  80);
        MakeButton("cradle",    427,  22);    -- 50
        MakeButton("joker",     486,   7);
        MakeButton("blitz",     544,  22);
        MakeButton("classic",   575,  81);
        MakeButton("cradle",    556, 139);
        MakeButton("classic",   509, 161);      -- 55
        MakeButton("strategy",  452, 138);
    };

    SetStyle(PanelButtonStyle);
    Button {
        name = "btnBack";
        label = 'btnBack';
        font = Font18,
        x = 859; y = 720;
        command = function()
            gfn_onMetamapButton_Back();
        end
    };
    
};
