--============================================================================
--  findobjects.lua
--  Copyright (c) 2009, Bamtang Games. All Rights Reserved.
------------------------------------------------------------------------------

require("scripts/style.lua");

ObjectFont = {
    titleFont,
    14,
    Color(42, 0, 0, 255),
}

ButtonFont = {
    textFont,
    24,
    Color(254, 211, 126),
}

BodyFont = {
    textFont,
    20,
    BlackColor,
}

TooltipFont = {
    textFont,
    16,
    BlackColor,
}

CounterFont = {
    titleFont,
    14,
    Color(255, 242, 108),
}

function DoNamePanel(id, posX, posY)
    return Group {
        Bitmap {
            name="PanelName"..id,
            x = posX,
            y = posY,
            w = 133,
            h = 30,

            Bitmap {
                name = "Vignette"..id,
                image = "images/gui/ae_points_elements",
                x = 0,
                y = 8,
            },

            Text {
                font = ObjectFont,
                name="txtNameObject"..id,
                x = 13,
                y = 7,
                w = 120,
                h = 28,
                flags = kHAlignLeft,
                label = "#Namesdfssdfd1234"..id,
            }
        }
    }
end

function MakeNameList(initX, initY)
    local windows = {};
    local count = 0;
    for k = 0, 2 do
        for p = 0, 2 do
            table.insert(windows, DoNamePanel(count, initX + 134*k, initY + 20*p));
            count = count + 1;
        end
    end
    return Group(windows);
end


function DoTextCounter(id, posX, posY)
    return Group {
        Text {
            font = CounterFont,
            name="txtCounter"..id,
            x = posX,
            y = posY,
            w = 50,
            h = 20,
            flags = kHAlignCenter,
            label = "#00/00",
        },
    }
end

function MakeCounterInventory(initX, initY)
    local windows = {};
    local count = 0;
    for m = 0, 2 do
        for n = 0, 2 do
            table.insert(windows, DoTextCounter(count, initX + 73*n, initY + 75*m));
            count = count + 1;
        end
    end
    return Group(windows);
end

function DoBgAnimated()
    return Group {
        CutsceneWnd {
            w = 800,
            h = 600,
            cutsceneFile = kCutsceneFile,
            onFinish = false,
        };
    }
end

function MakeBgAnimated()
    local windows = {};
    if (kCutsceneFile ~= "") then
        table.insert(windows, DoBgAnimated());
    end

    return Group(windows);
end

MakeDialog {
    name = "FindObjectGame",

    MakeBgAnimated();

    EffectWindow {
        name = "BackEffectsWindow";
        x = 0; y = 0;
        w = 800; h = 600;
    };

    FindObjectWindow {
        name = "FindObjectWindow",
        x = 0,
        y = 0,
        w = 800,
        h = 600,
        Bitmap {
            name="PanelInventory",
            image="images/gui/findobjects/ae_openedbag",
            align = kHAlignLeft + kVAlignTop,
            x = -15;
            y = 204;
            MakeCounterInventory(42, 84),
            SetStyle(ButtonStyle),
            Button {
                name = "btnHidePanel";
                graphics = ExitInventoryButtonGraphics;
                sound = "";
                rolloversound = "";
                x = 215,
                y = 256,
                command =
                    function()
                        hideInventory();
                    end
            };
        };
        ToolTipWindow {
            name = "ToolTip";
            x = 0; y = 0;
            w = 379; h = 93;
            Bitmap {
                name = "bmpBg";
                image="images/gui/tooltip_bg";
                align = kHAlignLeft + kVAlignTop;
                x = 0; y = 0;
            };
            Text {
                font = TooltipFont;
                name = "lblToolTip";
                x = 0; y = 0;
                w = 150; h = 60;
                padding = true;
                flags = kHAlignLeft + kVAlignTop;
                label = "#tool tip";
            };
        };
    },

    EffectWindow {
        name = "TopEffectsWindow";
        x = 0; y = 0;
        w = 800; h = 600;
    };

---[[
    HudWindow {
        x = 0,
        y = 0,
        w = 800,
        h = 600,
        name = "HudWindow",
        Bitmap {
            name = "PanelHUD",
            image = "images/gui/findobjects/ae_gui_top",
            x = 0,
            y = 481,
            MakeNameList(248, 43),
            Text {
                font = BodyFont,
                name = "TextSceneCleared",
                x = 247, y = 47,
                w = 400, h = 60,
                flags = kHAlignCenter + kVAlignCenter,
                label = "lblSceneCleared",
            },
            -- Button HINT.
            SetStyle(ButtonStyle),
            Button {
                name = "btnHintDisabled",
                graphics = {"images/gui/findobjects/ae_hints_n"},
                sound = "audio/sfx/snd_no_hint.ogg",
                rolloversound = "",
                x = 97, y = 24,
            },
            Button {
                x = 97,
                y = 24,
                name = "btnHint",
                graphics = HintsButtonGraphics;
                command =
                    function()
                        onButtonHint();
                    end
            },
            Bitmap {
                name = "bmpHint_x",
                image = "images/gui/numbers/ae_hint_x",
                x = 158,
                y = 35
            },
            Bitmap {
                name = "bmpHint_number",
                image = "images/gui/numbers/ae_hint_1",
                x = 171,
                y = 34
            },
            -- Button MAP.
            Bitmap {
                name = "bmpMapDisabled",
                image = "images/gui/findobjects/ae_map_n",
                x = 78,
                y = 75,
            },
            Button {
                x = 78,
                y = 75,
                name = "btnMap",
                graphics = MapButtonGraphics,
                command =
                    function()
                        local proceed = onButtonMap();
                        if (proceed) then
                            local level = getIdCurrentLevel();
                            local done1 = isSceneCompleted(level, 0);
                            local done2 = isSceneCompleted(level, 1);
                            local done3 = isSceneCompleted(level, 2);
                            checkRoom(done1, done2, done3);
                            done1 = isPuzzlesSceneCompleted(level, 0);
                            done2 = isPuzzlesSceneCompleted(level, 1);
                            done3 = isPuzzlesSceneCompleted(level, 2);
                            allPuzzlesComplete(done1, done2, done3);
                            local lock1 = isSceneLocked(level, 0);
                            local lock2 = isSceneLocked(level, 1);
                            local lock3 = isSceneLocked(level, 2);
                            gotoMap(level + 1, lock1, lock2, lock3);
                        end
                    end
            },
            Bitmap {
                name = "bmpMap",
                image = gLocalizedPath.."images/ae_map_text",
                x = 153,
                y = 75,
            },
        },

        Bitmap {
            name = "bmpTenMinutes";
            image = "images/gui/numbers/ae_time_0";
            x = 684;
            y = 505;
        };
        Bitmap {
            name = "bmpUnitsMinutes";
            image = "images/gui/numbers/ae_time_0";
            x = 702;
            y = 505;
        };
        Bitmap {
            name = "bmpTwoPoints";
            image = "images/gui/numbers/ae_time_points";
            x = 719;
            y = 515;
        };
        Bitmap {
            name = "bmpTenSeconds";
            image = "images/gui/numbers/ae_time_0";
            x = 731;
            y = 505;
        };
        Bitmap {
            name = "bmpUnitsSeconds";
            image = "images/gui/numbers/ae_time_0";
            x = 749;
            y = 505;
        };

        SetStyle(ButtonStyle),
        Button {
            x = 652,
            y = 544,
            name = "pause",
            graphics = MenuButtonFindObjectsGraphics,
            command =
                function()
                    if IsHudEnabled() then
                        DoModal("scripts/pause.lua");
                    end
                end
        },
    },
--]]
---[[
    TopWindow {
        name = "TopObjectWindow",
        x = 0,
        y = 0,
        w = 800,
        h = 600,
    },
    FadeWindow {
        w = 800,
        h = 600,
        name = "FadeWindow",
        Bitmap {
            image = "images/panelblack",
            name = "bmpPanelBlack",
            x = 0,
            y = 0,
        }
    },
--]]
}
