require( "scripts/style.lua" );

local pnl_fountain_rollover_name = "pnl_fountain_rollover";
local pnl_fountain_upg_name = "pnl_fountain_upg";

function Spawn_FountainRollOverPanel(position_x, position_y, badge_x, badge_y)
    return Group
    {
        ButtonVisual
        {
            name = "badge_fountain",
            x=badge_x,y=badge_y,
            
            tex_normal = "buttons/buttonup",
            tex_over   = "buttons/buttonrollover",
            tex_push   = "buttons/buttondown",
            rect      = "-13,33;16,33;58,20;58,-20;14,-33;-17,-33;-62,-18;-62,24;",
            actions   = {"ShopClick",},
            context = {"lvl_fountain", "lock_fountain"},
            snd_click    = GameScreenButtonSound.ClickSound,
            snd_over     = GameScreenButtonSound.OverSound,
            context_change = function(item, old_val, new_val)
                if (item == "lvl_fountain") then
                    badge_fountain_SetLocked(new_val == 3);
                end;
                if (item == "lock_fountain") then
                    badge_fountain_SetLocked(new_val == 1);
                end;
            end;
            on_click = function()
                if GetCount("lvl_fountain") == 2 then
                    EnableWindow(pnl_fountain_upg_name, false);
                    if GetCount("money") >= costs.fountain_2 then
                        RemoveItem("money", costs.fountain_2);
                        SupplyItem("lvl_fountain", 1);
                        if (GetCount("curr_garden") == 4) then
                            ShowControl("quest_mirror_dlg");
                        end;
                    else
                        CR_SwitchToDefault();
                        DisplayDialog {
                            "scripts/ok.lua",
                            body = "upgrade_not_enough_money",
                            title = "",
                        };
                    end;
                end;
                if GetCount("lvl_fountain") == 1 then
                    if GetCount("money") >= costs.fountain_1 then
                        RemoveItem("money", costs.fountain_1);
                        SupplyItem("lvl_fountain", 1);
                    else
                        EnableWindow(pnl_fountain_upg_name, false);
                        CR_SwitchToDefault();
                        DisplayDialog {
                            "scripts/ok.lua",
                            body = "upgrade_not_enough_money",
                            title = "",
                        };
                    end;
                end;
            end;
            on_enter = function()
                EnableWindow(pnl_fountain_upg_name, true);
            end;
            on_exit  = function()
                EnableWindow(pnl_fountain_upg_name, false);
            end;
            
            SetStyle(TextStyle),
            TextVisual
            {
                name = "fnt_badge_sh",
                font = CreateNamedFont(MinionSymbolSet, 22, ButtonYellow),
                x = kCenter+1, y = kCenter+1,
                w = 180, h = 22,
                context = {"lvl_fountain",},
                context_change = function(item, old_val, new_val)
                    if new_val == 1 then
                        fnt_badge_sh_SetText(GetString("button_outline", GetString("restore")));
                    end;
                    if new_val == 2 then
                        fnt_badge_sh_SetText(GetString("button_outline", GetString("upgrade")));
                    end;
                end;
            },
            TextVisual
            {
                name = "fnt_badge",
                font = CreateNamedFont(MinionSymbolSet, 22, ButtonBrown),
                x = kCenter, y = kCenter,
                w = 180, h = 22,
                context = {"lvl_fountain",},
                context_change = function(item, old_val, new_val)
                    if new_val == 1 then
                        fnt_badge_SetText(GetString("button_outline", GetString("restore")));
                    end;
                    if new_val == 2 then
                        fnt_badge_SetText(GetString("button_outline", GetString("upgrade")));
                    end;
                end;
            },
        },
        
        WindowExt
        {
            name = pnl_fountain_rollover_name,
            x=position_x, y=position_y,
            w=254,h=168,
            
            state_handlers = {
                justcreated = function()
                    EnableWindow(pnl_fountain_rollover_name, false);
                end;
                showed = function()
                    EnableWindow(pnl_fountain_rollover_name, true);
                end,
                hidden = function()
                    EnableWindow(pnl_fountain_rollover_name, false);
                end,
            },
            
            BitmapVisual
            {
                x=127,y=84,
                name = "picture",
                image="interface/game/pop_up_object/rollover_obj",
                
                SetStyle(TextStyle),
                CreateMinionText(24, CaptionYellow, kCenter, 22, "fountain_rollover_title", 100, 24),
                
                TextVisual
                {
                    name = "fountain_descr_body",
                    flags = kHAlignCenter + kVAlignCenter,
                    font = CreateNamedFont(MinionSymbolSet, 18, WhiteColor),
                    x = kCenter, y = kCenter,
                    w = 250, h = 50,
                    context = {"lvl_fountain",},
                    context_change = function(item, old_val, new_val)
                        if new_val == 1 then
                            fountain_descr_body_SetText(GetString("fountain_rollover_destroyed_body"));
                        end;
                        if new_val == 2 then
                            fountain_descr_body_SetText(GetString("fountain_rollover_body", 
                                tostring(mechanics.fountain.production_amount_lvl_2),
                                tostring(mechanics.fountain.production_time_lvl_2)));
                        end;
                        if new_val == 3 then
                            fountain_descr_body_SetText(GetString("fountain_rollover_body", 
                                tostring(mechanics.fountain.production_amount_lvl_3),
                                tostring(mechanics.fountain.production_time_lvl_3)));
                        end;
                    end;
                },
            },
        },
        
        
        WindowExt
        {
            name = pnl_fountain_upg_name,
            x=position_x, y=position_y,
            w=254,h=168,
            
            state_handlers = {
                justcreated = function()
                    EnableWindow(pnl_fountain_upg_name, false);
                end;
                showed = function()
                    EnableWindow(pnl_fountain_upg_name, true);
                end,
                hidden = function()
                    EnableWindow(pnl_fountain_upg_name, false);
                end,
            },
            
            BitmapVisual
            {
                x=127,y=84,
                name = "picture",
                image="interface/game/pop_up_object/rollover_obj",
                
                Bitmap
                {
                    image = "interface/game/pop_up_object/gold_small",
                    x=kCenter-20,y=115,
                },
                
                SetStyle(TextStyle),
                TextVisual
                {
                    name = "fnt_upg_title",
                    flags = kHAlignCenter + kVAlignCenter,
                    font = CreateNamedFont(MinionSymbolSet, 24, CaptionYellow),
                    x = kCenter, y = 22,
                    w = 200, h = 24,
                    context = {"lvl_fountain",},
                    context_change = function(item, old_val, new_val)
                        if new_val == 1 then
                            fnt_upg_title_SetText(GetString("fountain_upgrade_title_lvl_2"));
                        end;
                        if new_val == 2 then
                            fnt_upg_title_SetText(GetString("fountain_upgrade_title_lvl_3"));
                        end;
                    end;
                },

                TextVisual
                {
                    name = "fountain_upg_price",
                    flags = kHAlignCenter + kVAlignCenter,
                    font = CreateNamedFont(MinionSymbolSet, 20, CaptionYellow),
                    x = kCenter+20, y = 120,
                    w = 180, h = 20,
                    context = {"lvl_fountain",},
                    context_change = function(item, old_val, new_val)
                        if new_val == 1 then
                            fountain_upg_price_SetText(tostring(costs.fountain_1));
                        end;
                        if new_val == 2 then
                            fountain_upg_price_SetText(tostring(costs.fountain_2));
                        end;
                    end;
                },
                
                TextVisual
                {
                    name = "fountain_upg_body",
                    flags = kHAlignCenter + kVAlignCenter,
                    font = CreateNamedFont(MinionSymbolSet, 18, WhiteColor),
                    x = kCenter, y = kCenter,
                    w = 250, h = 50,
                    context = {"lvl_fountain",},
                    context_change = function(item, old_val, new_val)
                        if new_val == 1 then
                            fountain_upg_body_SetText(GetString("fountain_upgrade_body_lvl_2", 
                                tostring(mechanics.fountain.production_amount_lvl_2), 
                                tostring(mechanics.fountain.production_time_lvl_2)));
                        end;
                        if new_val == 2 then
                            fountain_upg_body_SetText(GetString("fountain_upgrade_body_lvl_3", 
                                tostring(mechanics.fountain.production_amount_lvl_3), 
                                tostring(mechanics.fountain.production_time_lvl_3)));
                        end;
                    end;
                },
            },
        },
    };
end;