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

function closeAchievements()
    PopModal("AchievementDialog");
end

function MakeIcon(id, px, py)
    local strId = ""..id;
    if id < 10 then
        strId = "0"..id;
    end
    return Group {
        Bitmap {
            name = "bmpIcon_"..id.."_on";
            image = "gpx/achieve/achievement_"..strId;
            x = px; y = py;
        };

        Bitmap {
            name = "bmpIcon_"..id.."_off";
            image = "gpx/achieve/achievement_locked";
            x = px; y = py;
        };
    };
end

function MakeAchievementsIcons(px, py, tw, th, cols, rows, total)
    local countIcons = 0;
    local windows = {};
    for r = 0, rows - 1 do
        for c = 0, cols - 1 do
            if (countIcons < total) then
                countIcons = countIcons + 1;
                table.insert(windows, MakeIcon(countIcons, px + tw*c, py + th*r));
            end
        end
    end

    return Group(windows);
end

MakeDialog {
    name = "AchievementDialog";

    wndAchievements {
        x = 0; y = 0; w = 1024; h = 768;

        avatar_boy  = { x = 785; y = 320 };
        avatar_girl = { x = 800; y = 312 };
        avatar_cat  = { x = 800; y = 345 };
        avatar_dog  = { x = 800; y = 314 };

        Bitmap {
            name = "AchieveFade";
            alpha = true;
            x = 0; y = 0; w = 1024; h = 768;

            clsText {
                label = "lblAchievement";
                font = Font48;
                Scale = 0.65;
                Space = -5;
                x = 86; y = 25; w = 450; h = 57;
                flags = kHAlignCenter + kVAlignCenter;
            };

            Bitmap {
                image = "gpx/achieve/achievements_meter_mask";
                x = 592; y = 117;

                Text {
                    name  = "lbl25";
                    label = "#25%";
                    font  = Font24;
                    x = 10; y = 338;
                    w = 70; h = 40;
                    flags = kHAlignCenter + kVAlignTop;
                };
                Text {
                    name  = "lbl50";
                    label = "#50%";
                    font  = Font24;
                    x = 10; y = 223;
                    w = 70; h = 40;
                    flags = kHAlignCenter + kVAlignTop;
                };
                Text {
                    name  = "lbl75";
                    label = "#75%";
                    font  = Font24;
                    x = 10; y = 108;;
                    w = 70; h = 40;
                    flags = kHAlignCenter + kVAlignTop;
                };
            };

            MakeAchievementsIcons(60, 117, 102, 101, 5, 4, 20);

            Bitmap {
                image = "gpx/achieve/avatar_podium";
                x = 790; y = 560;
            };
            Text {
                name = "name";
                font = Font18;
                x = 822; y = 577; w = 147; h = 32;
                flags = kHAlignCenter + kVAlignCenter;
            };
            Text {
                name = "AchieveQuantity";
                font = Font34Yellow;
                x = 842; y = 645; w = 103; h = 39;
                flags = kHAlignCenter + kVAlignCenter;
            };
            Bitmap {
                image = "gpx/achieve/achievements_textavatar";
                x = 794; y = 117;
            };
            Text {
                name = "txtAchieve1";
                font = Font22;
                x = 800; y = 138; w = 210; h = 40;
                flags = kHAlignCenter + kVAlignCenter;
            };
            Text {
                name = "txtAchieve2";
                font = Font40;
                x = 800; y = 178; w = 210; h = 80;
                flags = kHAlignCenter + kVAlignCenter;
            };
            Text {
                name = "txtAchieve3";
                font = Font22;
                x = 800; y = 258; w = 210; h = 40;
                flags = kHAlignCenter + kVAlignCenter;
            };

            Text {
                name  = "lblAchieveQuestMode";
                label = "lblAchieveQuestMode";
                font = Font20White;
                x = 8; y = 718;
                w = 600; h = 40;
                flags = kHAlignLeft + kVAlignCenter;
            };

            SetStyle(PauseButtonStyle);
            Button {
                name = "btnBack";
                label = "btnBack";
                x = 802; y = 710;
                command = function()
                    gfn_OnBackAchievements();
                end
            };
        };

        Bitmap {
            image = "gpx/screens/panel_background";
            name = "bmpPanelBlack";
            alpha = true;
        };

        wndToolTip {
            name = "wndToolTip";
            x = 0; y = 0;
            w = 512; h = 200;

            margin_x  = 10;
            margin_y  = 5;
            fade_secs = 0.3;

            Bitmap {
                name = "bmpBg";
                image="gpx/screens/tooltip_bg";
                x = 0; y = 0;
            };
            Text {
                name = "lblToolTip";
                font = Font20;
                label = "#tool tip";
                x = 0; y = 0;
                w = 450; h = 150;
                padding = true;
                flags = kHAlignLeft + kVAlignTop;
            };
        };
    };
};
