
require( "scripts/style.lua" );
require( "scripts/ui/style_text.lua" );
require( "scripts/ui/colors.lua" );

GrayColor = Color(180,180,180,255);

gardenpath = GetCurrGardenPath();
gardenstring = GetCurrGardenString();

local kIniFile = "config/ui/lab_"..tostring(GetCount("curr_garden"))..".ini";

kSlotLine1X = 190;
kSlotLine2X = 140;

kSlotLine1Y = 357;
kSlotLine2Y = 547;

kSlotXLine1Delta = 140;
kSlotXLine2Delta = 130;
--[[
local kPlant1Color;
local kPlant2Color;
local kPlant3Color;

if GetCount("curr_garden") == 1 then
   kPlant1Color = Lab_Garden_1_Plant_1;
   kPlant2Color = Lab_Garden_1_Plant_2;
   kPlant3Color = Lab_Garden_1_Plant_3;
end;
if GetCount("curr_garden") == 2 then
   kPlant1Color = Lab_Garden_2_Plant_1;
   kPlant2Color = Lab_Garden_2_Plant_2;
   kPlant3Color = Lab_Garden_2_Plant_3;
end;
if GetCount("curr_garden") == 3 then
   kPlant1Color = Lab_Garden_3_Plant_1;
   kPlant2Color = Lab_Garden_3_Plant_2;
   kPlant3Color = Lab_Garden_3_Plant_3;
end;
if GetCount("curr_garden") == 4 then
   kPlant1Color = Lab_Garden_4_Plant_1;
   kPlant2Color = Lab_Garden_4_Plant_2;
   kPlant3Color = Lab_Garden_4_Plant_3;
end;
if GetCount("curr_garden") == 5 then
   kPlant1Color = Lab_Garden_5_Plant_1;
   kPlant2Color = Lab_Garden_5_Plant_2;
   kPlant3Color = Lab_Garden_5_Plant_3;
end;
--]]
TxtFlower1Count = {
    font = {MinionSymbolSet, 16, WhiteColor},
    flags = kVAlignCenter + kHAlignRight,
    w = 35, h = 16,
};
TxtFlower2Count = {
    font = {MinionSymbolSet, 16, WhiteColor},
    flags = kVAlignCenter + kHAlignRight,
    w = 35, h = 16,
};
TxtFlower3Count = {
    font = {MinionSymbolSet, 16, WhiteColor},
    flags = kVAlignCenter + kHAlignRight,
    w = 35, h = 16,
};
TxtSellButton = {
    font = {MinionSbItSymbolSet, 15, ButtonBrown},
    flags = kVAlignCenter + kHAlignRight,
    w = 25, h = 15,
    x = kCenter+6, y = kCenter,
};
TxtSellButtonShadow = {
    font = {MinionSbItSymbolSet, 15, ButtonYellow},
    flags = kVAlignCenter + kHAlignRight,
    w = 25, h = 15,
    x = kCenter+7, y = kCenter+1,
};

--------
FontShelves = {
  standardFont,
  16,
  WhiteColor
};

FontRecipes = {
  standardFont,
  18,
  WhiteColor
};

FontStorageCount = {
  standardFont,
  18,
  WhiteColor
};

FontBudCount = {
  standardFont,
  20,
  WhiteColor
};

FontMoney = {
  MinionSymbolSet,
  22,
  CaptionYellow
};
FontMoneyShadow = {
  MinionSymbolSet,
  22,
  CaptionBrown
};

FontPotionCost = {
  standardFont,
  20,
  WhiteColor
};

FontStationTitle = {
  standardFont,
  20,
  BlackColor
};

ButtonSell = {
  gardenpath.."laboratory/but_sell",
  gardenpath.."laboratory/but_sell_p",
  gardenpath.."laboratory/but_sell_a",
};

SellScreenButtonSound = {
    ClickSound="audio/sfx/game_ui/button_clickUI.ogg";
    OverSound ="audio/sfx/game_ui/button_rolloverUI.ogg";
};

PotionButtonSound = {
    ClickSound="audio/sfx/potion/potion_receipt_click.ogg";
    OverSound = "audio/sfx/potion/potion_receipt_rollover.ogg";
};

BudButtonSound = {
    ClickSound="audio/sfx/potion/flower_bud_click.ogg";
    OverSound = "";
    --OverSound="audio/sfx/main_menu/button_rollover.ogg";
};

SellBudButtonSound = {
    ClickSound="audio/sfx/potion/fruit_sell.ogg";
    OverSound = "";
    --OverSound="audio/sfx/main_menu/button_rollover.ogg";
};

SmallGoldImage = {
    image = "game/common/laboratory/gold",
};

CreateIngridients = function(slot_name, num, val_x, val_y)
    return Group
    {
        Bitmap
        {
            name = "back"..num..slot_name,
            image = "game/common/laboratory/scroll_center",
            x = val_x,
            y = val_y,
            
            Bitmap
            {
                name = "ingr"..num..slot_name,
                image = gardenpath.."camomile/flower_01.png",
                scale = 1.0,
                x = kCenter - 25,
                y = kCenter,
            },

            Bitmap
            {
                name = "pointer"..num..slot_name,
                image = "interface/game/pointer",
                x = kCenter + 55,
                y = kCenter,
            },
            
            Bitmap
            {
                name = "cross"..num..slot_name,
                image = "interface/game/cross",
                x = kCenter + 55,
                y = kCenter,
            },

            Text
            {
                name = "count"..num..slot_name,
                font = CreateNamedFont(MinionSymbolSet, 22, WhiteColor),
                x = kCenter + 26,
                y = kCenter,
                h = 30,
                w = 80,
                flags = kHAlignCenter + kVAlignCenter,
                label = "0",
            },

            Text
            {
                name = "have"..num..slot_name,
                font = CreateNamedFont(MinionSymbolSet, 22, WhiteColor),
                x = kCenter + 46,
                y = kCenter,
                h = 30,
                w = 80,
                flags = kHAlignCenter + kVAlignCenter,
                label = "#".."(99)",
            },
        },
    };
end;

CreateSlot = function(slot_name, pic_name, cost, val_x, val_y, potion_name)
    MakeDialog
    {
        Window
        {
            name = slot_name,
            x = val_x,
            y = val_y,
            h = 230,
            w = 200,

            BitmapVisual
            {
                name = "glow_"..slot_name,
                image="game/common/laboratory/potion_makeable.png",
                blendmode="additive",
                x = 100,
                y = 108,
            },
            
            Bitmap
            {
                x = kCenter,
                y = 33,
                h = 128,
                w = 128,

                ButtonExt
                {
                    name="button"..slot_name,
                    sound = PotionButtonSound.ClickSound,
                    rolloversound = PotionButtonSound.OverSound,
                    x = 64, y = 64,
                    type = kPush,
                    graphics = {pic_name, pic_name, pic_name.."_a",},
                    command = function()
                        AssemblyPotion(slot_name);
                    end,
                    
                    WndProgressVertical
                    {
                        name = "pic_progress"..slot_name,
                        x = kCenter + 9,
                        y = kCenter + 52,
                        h = 128,
                        w = 128,
                        
                        picture_back = "",
                        picture_progress = pic_name.."_progress",
                        fill_coef = 0,
                    },
                    
                    Bitmap
                    {
                        name="holder_a"..slot_name,
                        image=pic_name.."_holder_a",
                        x = 0, y = 0,
                    },
                    
                    Bitmap
                    {
                        name="holder"..slot_name,
                        image=pic_name.."_holder",
                        x = 0, y = 0,
                    },
                    
                },
            },

            Bitmap
            {
                name = "quest_glow_"..slot_name,
                image="game/common/laboratory/recipe_quest",
                x = kCenter,
                y = 165,
                SetStyle(TxtRecipeQuestScrollShadow),
                Text
                {
                    x = kCenter+1,
                    y = kCenter+1,
                    label = "recipe_quest_tag",
                },
                SetStyle(TxtRecipeQuestScroll),
                Text
                {
                    x = kCenter,
                    y = kCenter,
                    label = "recipe_quest_tag",
                },
            },

            WndFxSprite
            {
                name = "quest_sparkle_"..slot_name,
                x = kCenter,
                y = kCenter,
                w = 200,
                h = 200,
                effect_position = "100,100",
                file_name = "fx/quest_potion.lua",
                start_activate = false,
                advance = 100,
                anim_pool = "laboratory",
                timer_settings = {
                    name = "ui",
                    category = "UI",
                },
            },

            Bitmap
            {
                name = "pic_cost_"..slot_name,
                image="game/common/laboratory/potion_support",
                x = kCenter,
                y = 133,
                SetStyle(TxtRecipePriceScrollShadow),
                Text
                {
                    name = "shadow_cost_"..slot_name,
                    x = kCenter + 14,
                    y = kCenter + 5,
                    label = "#"..GetString("caption_outline", tostring(cost)),
                },
                SetStyle(TxtRecipePriceScroll),
                Text
                {
                    name = "cost_"..slot_name,
                    x = kCenter + 13,
                    y = kCenter + 4,
                    label = "#"..GetString("caption_outline", tostring(cost)),
                },
            },
            
        },
        
        Window
        {
            name = "recipe"..slot_name,
            x = val_x + 28,
            y = val_y - 245,
            h = 388,
            w = 200,
            
            -- INGRIDIENTS
            --[[
            CreateIngridients(slot_name, 6, 0, 0);
            CreateIngridients(slot_name, 5, 0, 70);
            CreateIngridients(slot_name, 4, 0, 140);
            CreateIngridients(slot_name, 3, 0, 210);
            CreateIngridients(slot_name, 2, 0, 280);
            CreateIngridients(slot_name, 1, 0, 350);
            --]]
            CreateIngridients(slot_name, 3, 0, 54);
            CreateIngridients(slot_name, 2, 0, 124);
            CreateIngridients(slot_name, 1, 0, 194);
            
            CreateIngridients(slot_name, 6, 0, 0);
            CreateIngridients(slot_name, 5, 0, 0);
            CreateIngridients(slot_name, 4, 0, 0);
            
            Bitmap
            {
                image="game/common/laboratory/scroll_bottom",
                x = 0,
                y = 245,
            },
            
            Bitmap
            {
                name = "recipe_name_top_scroll",
                image = "game/common/laboratory/scroll_top",
                x = 0,
                y = 0,
                SetStyle(TxtRecipeNameScrollShadow),
                Text
                {
                    x = 1,
                    y = 34,
                    label = "#"..GetString("blue_outline", GetString(potion_name)),
                },
                SetStyle(TxtRecipeNameScroll),
                Text
                {
                    x = 0,
                    y = 33,
                    label = "#"..GetString("blue_outline", GetString(potion_name)),
                },
            },
        },
    };
end;

CreateSlot1 = function(cost)
    CreateSlot("Slot1", gardenpath.."laboratory/potions/pot_01", cost, kSlotLine1X, kSlotLine1Y, gardenstring.."_potion1_name");
end;

CreateSlot2 = function(cost)
    CreateSlot("Slot2", gardenpath.."laboratory/potions/pot_02", cost, kSlotLine1X + kSlotXLine1Delta, kSlotLine1Y, gardenstring.."_potion2_name");
    MakeDialog
    {
        BitmapVisual
        {
            name = "potion_2_hider",
            x = kSlotLine1X + kSlotXLine1Delta + 100,
            y = kSlotLine1Y + 115,
            image = gardenpath.."laboratory/potions/potion_2_hider",
            timer_settings = {
                name = "panels",
                category = "UI",
            },
        },
    };
end;

CreateSlot3 = function(cost)
    CreateSlot("Slot3", gardenpath.."laboratory/potions/pot_03", cost, kSlotLine1X + kSlotXLine1Delta * 2, kSlotLine1Y, gardenstring.."_potion3_name");
    MakeDialog
    {
        BitmapVisual
        {
            name = "potion_3_hider",
            x = kSlotLine1X + 2 * kSlotXLine1Delta + 100,
            y = kSlotLine1Y + 115,
            image = gardenpath.."laboratory/potions/potion_3_hider",
            timer_settings = {
                name = "panels",
                category = "UI",
            },
        },
    };
end;

CreateSlot4 = function(cost)
    CreateSlot("Slot4", gardenpath.."laboratory/potions/pot_04", cost, kSlotLine1X + kSlotXLine1Delta * 3, kSlotLine1Y, gardenstring.."_potion4_name");
    MakeDialog
    {
        BitmapVisual
        {
            name = "potion_4_hider",
            x = kSlotLine1X + 3 * kSlotXLine1Delta + 100,
            y = kSlotLine1Y + 115,
            image = gardenpath.."laboratory/potions/potion_4_hider",
            timer_settings = {
                name = "panels",
                category = "UI",
            },
        },
    };
end;

CreateSlot5 = function(cost)
    CreateSlot("Slot5", gardenpath.."laboratory/potions/pot_05", cost, kSlotLine2X, kSlotLine2Y, gardenstring.."_potion5_name");
    MakeDialog
    {
        BitmapVisual
        {
            name = "potion_5_hider",
            x = kSlotLine2X + 100,
            y = kSlotLine2Y + 115,
            image = gardenpath.."laboratory/potions/potion_5_hider",
            timer_settings = {
                name = "panels",
                category = "UI",
            },
        },
    };
end;

CreateSlot6 = function(cost)
    CreateSlot("Slot6", gardenpath.."laboratory/potions/pot_06", cost, kSlotLine2X + kSlotXLine2Delta, kSlotLine2Y, gardenstring.."_potion6_name");
    MakeDialog
    {
        BitmapVisual
        {
            name = "potion_6_hider",
            x = kSlotLine2X + kSlotXLine2Delta + 100,
            y = kSlotLine2Y + 115,
            image = gardenpath.."laboratory/potions/potion_6_hider",
            timer_settings = {
                name = "panels",
                category = "UI",
            },
        },
    };
end;

CreateSlot7 = function(cost)
    CreateSlot("Slot7", gardenpath.."laboratory/potions/pot_07", cost, kSlotLine2X + kSlotXLine2Delta * 2, kSlotLine2Y, gardenstring.."_potion7_name");
    MakeDialog
    {
        BitmapVisual
        {
            name = "potion_7_hider",
            x = kSlotLine2X + 2 * kSlotXLine2Delta + 100,
            y = kSlotLine2Y + 115,
            image = gardenpath.."laboratory/potions/potion_7_hider",
            timer_settings = {
                name = "panels",
                category = "UI",
            },
        },
    };
end;

CreateSlot8 = function(cost)
    CreateSlot("Slot8", gardenpath.."laboratory/potions/pot_08", cost, kSlotLine2X + kSlotXLine2Delta * 3, kSlotLine2Y, gardenstring.."_potion8_name");
    MakeDialog
    {
        BitmapVisual
        {
            name = "potion_8_hider",
            x = kSlotLine2X + 3 * kSlotXLine2Delta + 100,
            y = kSlotLine2Y + 115,
            image = gardenpath.."laboratory/potions/potion_8_hider",
            timer_settings = {
                name = "panels",
                category = "UI",
            },
        },
    };
end;

CreateSlot9 = function(cost)
    CreateSlot("Slot9", gardenpath.."laboratory/potions/pot_09", cost, kSlotLine2X + kSlotXLine2Delta * 4, kSlotLine2Y, gardenstring.."_potion9_name");
    MakeDialog
    {
        BitmapVisual
        {
            name = "potion_9_hider",
            x = kSlotLine2X + 4 * kSlotXLine2Delta + 100,
            y = kSlotLine2Y + 115,
            image = gardenpath.."laboratory/potions/potion_9_hider",
            timer_settings = {
                name = "panels",
                category = "UI",
            },
        },
    };
end;

SpawnSellButtons = function(item_name, x_fx, y_fx, index, tex_name)
    return Group
    {
        SetStyle(BtnSellScreen_Sell),
        ButtonVisual
        {
            name = item_name.."_sell_1",
            x = 117,
            y = 120,
            on_click = function()
                SellOneFlower(item_name, tex_name, x_fx, y_fx, index);
            end;
            SetStyle(TxtSellButtonShadow),
            Text
            {
                label = "sell_1",
            },
            SetStyle(TxtSellButton),
            Text
            {
                label = "sell_1",
            },
         },
        ButtonVisual
        {
            name = item_name.."_sell_all",
            x = 183,
            y = 120,
            on_click = function()
                SellAllFlower(item_name, tex_name, x_fx, y_fx, index);
            end;
            SetStyle(TxtSellButtonShadow),
            Text
            {
                label = "sell_all",
            },
            SetStyle(TxtSellButton),
            Text
            {
                label = "sell_all",
            },
         },
    };
end;

SpawnSellPotionButtons = function(item_name, x_fx, y_fx, index, tex_name)
    return Group
    {
        SetStyle(BtnSellScreen_Sell),
        ButtonVisual
        {
            name = item_name.."_sell_1",
            x = 117,
            y = 120,
            on_click = function()
                SellOne(item_name, tex_name, x_fx, y_fx, index);
            end;
            SetStyle(TxtSellButtonShadow),
            Text
            {
                label = "sell_1",
            },
            SetStyle(TxtSellButton),
            Text
            {
                label = "sell_1",
            },
         },
        ButtonVisual
        {
            name = item_name.."_sell_all",
            x = 183,
            y = 120,
            on_click = function()
                SellAll(item_name, tex_name, x_fx, y_fx, index);
            end;
            SetStyle(TxtSellButtonShadow),
            Text
            {
                label = "sell_all",
            },
            SetStyle(TxtSellButton),
            Text
            {
                label = "sell_all",
            },
         },
    };
end;

SpawnFlowerPrice = function(item_name, x_link, y_link)
    return Group
    {
        SetStyle(SmallGoldImage),
        BitmapVisual
        {
            name = item_name.."_gold",
            x = x_link, y = y_link,
        },
        
        SetStyle(TxtFlowerPriceShadow),
        Text
        {
            name = "price_"..item_name.."_shadow",
            x = x_link-16, y = y_link-22,
        },
        SetStyle(TxtFlowerPrice),
        Text
        {
            name = "price_"..item_name,
            x = x_link-17, y = y_link-23,
        },
    };
end;

SpawnPotionPrice = function(item_name, x_link, y_link)
    return Group
    {
        Bitmap
        {
            name = item_name.."_price_tag",
            x = x_link,
            y = y_link,
            image = "game/common/laboratory/shelf_tab",
            
            SetStyle(SmallGoldImage),
            BitmapVisual
            {
                name = item_name.."_gold",
                x = 32, y = 58,
            },
            SetStyle(TxtPotionPriceShadow),
            Text
            {
                name = "price_"..item_name.."_shadow",
                x = 14, y = 34,
            },
            SetStyle(TxtPotionPrice),
            Text
            {
                name = "price_"..item_name,
                x = 13, y = 33,
            },
        }
    };
end;

SpawnPotionQuestTag = function(item_name, x_link, y_link)
    return Group
    {
        Bitmap
        {
            name = item_name.."_quest_tag",
            x = x_link-12,
            y = y_link+15,
            scale = 0.7,
            image = "game/common/laboratory/potion_quest_tag",
            
            SetStyle(TxtPotionQuestTagShadow),
            Text
            {
                label = "potion_quest_tag",
                x = kCenter-3, y = kCenter+2,
            },
            SetStyle(TxtPotionQuestTag),
            Text
            {
                label = "potion_quest_tag",
                x = kCenter-4, y = kCenter+1,
            },
        }
    };
end;

SpawnPotionSellControls = function(potion_name, tag, x_link, y_link, index, tex_particle)
    return Group
    {
        BtnSell
        {
            name = potion_name,
            ini_file = kIniFile,
            ini_tag  = tag,
            x = x_link,
            y = y_link,
            w = 300,
            h = 300,
            actions = {"PotionClick",},
            context = {potion_name, potion_name.."_enabled"},
            context_change = function(item, old_val, new_val)
                if (item == potion_name) and (GetCount(potion_name.."_enabled") == 1) then
                    Invoke_SetClickable(potion_name, new_val > 0)
                    EnableWindow(potion_name.."_price_tag", new_val > 0);
                    EnableWindow("lbl_"..potion_name, new_val > 0);
                    EnableWindow("lbl_"..potion_name.."_shh", new_val > 0);
                    if new_val == 0 then
                        EnableWindow(potion_name.."_sell_1", false);
                        EnableWindow(potion_name.."_sell_all", false);
                    end;
                end;
                if (item == potion_name.."_enabled") then
                    if (new_val == 1) and (old_val == 1) then
                        EnableWindow(potion_name.."_hider", false);
                    end;
                    if (new_val == 1) and (old_val == 0) then
                        Invoke_SetLocked(potion_name, false);
                        Invoke_StartCurveCallBack(potion_name.."_hider", "curves/recipe_unhide.xml","","");
                    end;
                    if new_val == 0 then
                        EnableWindow("lbl_"..potion_name, false);
                        EnableWindow(potion_name.."_price_tag", false);
                        Invoke_SetLocked(potion_name, true);
                    end;
                end;
            end;
            on_enter = function()
                if GetCount(potion_name) > 0 then
                    EnableWindow(potion_name.."_sell_1", true);
                    EnableWindow(potion_name.."_sell_all", true);
                end;
            end;
            on_exit = function()
                EnableWindow(potion_name.."_sell_1", false);
                EnableWindow(potion_name.."_sell_all", false);
            end;
            
            SpawnSellPotionButtons(potion_name, x_link, y_link, index, tex_particle),
        },
    };
end;

SpawnFlowerSellControls = function(flower_name, flower_top_lvl, lvl_enable, tag, x_link, y_link, index, tex_particle)
    return Group
    {
        BtnSell
        {
            name = flower_name,
            ini_file = kIniFile,
            ini_tag  = tag,
            x = x_link,
            y = y_link,
            w = 300,
            h = 300,
            actions = {"PotionClick",},
            context = {flower_name, flower_top_lvl},
            context_change = function(item, old_val, new_val)
                if (item == flower_name) then
                    Invoke_SetClickable(flower_name, new_val > 0);
                    if new_val == 0 then
                        EnableWindow(flower_name.."_sell_1", false);
                        EnableWindow(flower_name.."_sell_all", false);
                    end;
                end;
                if (item == flower_top_lvl) then
                    Invoke_SetLocked(flower_name, new_val < lvl_enable);
                    EnableWindow("lbl_"..flower_name, new_val >= lvl_enable);
                    EnableWindow("lbl_"..flower_name.."_shh", new_val >= lvl_enable);
                    if new_val >= lvl_enable then
                        Invoke_SetClickable(flower_name, GetCount(flower_name) > 0);
                    end;
                    Invoke_SetVisible(flower_name.."_gold", new_val >= lvl_enable);
                    EnableWindow("price_"..flower_name, new_val >= lvl_enable);
                    EnableWindow("price_"..flower_name.."_shadow", new_val >= lvl_enable);
                end;
            end;
            on_enter = function()
                if GetCount(flower_name) > 0 then
                    EnableWindow(flower_name.."_sell_1", true);
                    EnableWindow(flower_name.."_sell_all", true);
                end;
            end;
            on_exit = function()
                EnableWindow(flower_name.."_sell_1", false);
                EnableWindow(flower_name.."_sell_all", false);
            end;
            
            SpawnSellButtons(flower_name, x_link, y_link, index, tex_particle),
        },
    };
end;

SpawnText = function(item_name, x_link, y_link)
    return Group
    {
        TextVisual
        {
            name = "lbl_"..item_name.."_shh",
            x = x_link+1,
            y = y_link-2,
            label = "",
            font = {MinionSymbolSet, 16, ButtonBrown},
            context = {item_name,},
            context_change = function(item, old_val, new_val)
                Invoke_SetText("lbl_"..item_name.."_shh", GetString("brown_outline", tostring(new_val)));
            end;
        },
        TextVisual
        {
            name = "lbl_"..item_name,
            x = x_link,
            y = y_link-3,
            label = "",
            font = {MinionSymbolSet, 16, WhiteColor},
            context = {item_name,},
            context_change = function(item, old_val, new_val)
                Invoke_SetText("lbl_"..item_name, GetString("brown_outline", tostring(new_val)));
            end;
        },
    };
end;

MakeDialog
{
    Bitmap
    {
        image="game/common/laboratory/back",
        
        WndFxSprite
        {
            name = "falling_leaves_fx",
            x = 0,
            y = 0,
            w = 1024,
            h = 768,
            effect_position = "256,192",
            file_name = "fx/laboratory/falling_leaves.lua",
            start_activate = true,
            advance = 0,
            anim_pool = "laboratory",
            timer_settings = {
                name = "ui",
                category = "UI",
            },
        },

        WndFxSprite
        {
            name = "light_rays_fx",
            x = 0,
            y = 0,
            w = 1024,
            h = 768,
            effect_position = "256,192",
            file_name = "fx/laboratory/light_rays.lua",
            start_activate = true,
            advance = 0,
            anim_pool = "laboratory",
            timer_settings = {
                name = "ui",
                category = "UI",
            },
        },

        SellScreen
        {
            w = 1024,
            h = 768,
            name = "sell_screen",
            
            storage_progress_position = "70,75",

            -- STOREHOUSE
            Bitmap
            {
                name = "store01",
                image=gardenpath.."laboratory/storehouse/01.png",
                x = 10,
                y = 30,
                scale = 0.55,
            },

            Bitmap
            {
                name = "store02",
                image=gardenpath.."laboratory/storehouse/02.png",
                x = 10,
                y = 30,
                scale = 0.55,
            },

            Bitmap
            {
                name = "store03",
                image=gardenpath.."laboratory/storehouse/03.png",
                x = 10,
                y = 30,
                scale = 0.55,
            },

            Bitmap
            {
                name = "store04",
                image=gardenpath.."laboratory/storehouse/04.png",
                x = 10,
                y = 30,
                scale = 0.55,
            },
            
            Bitmap
            {
                image = "game/common/progress/flower_text_back",
                x = 10,
                y = 65,

                TextVisual
                {
                    name = "txt_lab_storage_shadow",
                    flags = kHAlignCenter + kVAlignCenter,
                    font = CreateNamedFont(MinionSbItSymbolSet, 23, GreenOutline),
                    x = 38, y = kCenter+3,
                    h = 23, w = 40,
                    context = {"bud_collected",},
                    context_change = function(item, old_val, new_val)
                        txt_lab_storage_shadow_SetText(GetString("green_outline", tostring(new_val)));
                    end;
                },
                TextVisual
                {
                    name = "txt_lab_storage",
                    flags = kHAlignCenter + kVAlignCenter,
                    font = CreateNamedFont(MinionSbItSymbolSet, 23, BudGold),
                    x = 37, y = kCenter+2,
                    h = 23, w = 40,
                    context = {"bud_collected",},
                    context_change = function(item, old_val, new_val)
                        txt_lab_storage_SetText(GetString("green_outline", tostring(new_val)));
                    end;
                },
                
                TextVisual
                {
                    name = "txt_lab_storage_cap_shadow",
                    flags = kHAlignLeft + kVAlignCenter,
                    font = CreateNamedFont(MinionSbItSymbolSet, 18, GreenOutline),
                    x = 76, y = kCenter+3,
                    h = 20, w = 40,
                    context = {"storage_capacity",},
                    context_change = function(item, old_val, new_val)
                        txt_lab_storage_cap_shadow_SetText(GetString("green_outline", "/"..tostring(new_val)));
                    end;
                },
                TextVisual
                {
                    name = "txt_lab_storage_cap",
                    flags = kHAlignLeft + kVAlignCenter,
                    font = CreateNamedFont(MinionSbItSymbolSet, 18, Green),
                    x = 75, y = kCenter+2,
                    h = 20, w = 40,
                    context = {"storage_capacity",},
                    context_change = function(item, old_val, new_val)
                        txt_lab_storage_cap_SetText(GetString("green_outline", "/"..tostring(new_val)));
                    end;
                },
            },

            WndFxSprite
            {
                x = kCenter - 10,
                y = kCenter - 320,
                w = 400,
                h = 400,
                effect_position = "200,200",
                file_name = "fx/boiler_boil.lua",
                start_activate = true,
                advance = 0,
                anim_pool = "laboratory",
                timer_settings = {
                    name = "panels",
                    category = "UI",
                },
            },


            Bitmap
            {
                name = "boiler",
                image="game/common/laboratory/boiler.png", 
                x = kCenter-10,
                y = 0,--kCenter - 166,
            },

            -- LAMPS

            WndFxSprite
            {
                name = "left_lamp_firebugs_fx",
                x = 0,
                y = 0,
                w = 1024,
                h = 768,
                effect_position = "220,148",
                file_name = "fx/laboratory/lamp_firebugs.lua",
                start_activate = true,
                advance = 0,
                anim_pool = "laboratory",
                timer_settings = {
                    name = "ui",
                    category = "UI",
                },
            },

            WndFxSprite
            {
                name = "right_lamp_firebugs_fx",
                x = 0,
                y = 0,
                w = 1024,
                h = 768,
                effect_position = "780,148",
                file_name = "fx/laboratory/lamp_firebugs.lua",
                start_activate = true,
                advance = 0,
                anim_pool = "laboratory",
                timer_settings = {
                    name = "ui",
                    category = "UI",
                },
            },

            WndFxSprite
            {
                name = "left_lamp_light_fx",
                x = 0,
                y = 0,
                w = 1024,
                h = 768,
                effect_position = "220,148",
                file_name = "fx/laboratory/lamp_light.lua",
                start_activate = true,
                advance = 0,
                anim_pool = "laboratory",
                timer_settings = {
                    name = "ui",
                    category = "UI",
                },
            },

            WndFxSprite
            {
                name = "right_lamp_light_fx",
                x = 0,
                y = 0,
                w = 1024,
                h = 768,
                effect_position = "780,148",
                file_name = "fx/laboratory/lamp_light.lua",
                start_activate = true,
                advance = 0,
                anim_pool = "laboratory",
                timer_settings = {
                    name = "ui",
                    category = "UI",
                },
            },


            -- MONEY
            Text
            {
                name = "money_shadow",
                font = FontMoneyShadow,
                x = 895,
                y = 735,
                h = 30,
                w = 100,
                flags = kHAlignCenter + kVAlignCenter,
            },
            Text
            {
                name = "money",
                font = FontMoney,
                x = 894,
                y = 734,
                h = 30,
                w = 100,
                flags = kHAlignCenter + kVAlignCenter,
            },
            
            -- shelves
            SetStyle(TextStyle),
            CreateOndineText(20, CaptionBrown, 14, 9, "#"..GetString("caption_outline", GetString("flower_shelf")), 125, 20),
            CreateOndineText(20, CaptionYellow, 13, 8, "#"..GetString("caption_outline", GetString("flower_shelf")), 125, 20),
            
            CreateOndineText(20, CaptionBrown, 858, 9, "#"..GetString("caption_outline", GetString("potion_shelf")), 165, 20),
            CreateOndineText(20, CaptionYellow, 857, 8, "#"..GetString("caption_outline", GetString("potion_shelf")), 165, 20),
            
            CreateOndineText(21, CaptionBrown, 410, 351, "#"..GetString("caption_outline", GetString("recipe_shelf")), 185, 26),
            CreateOndineText(21, CaptionYellow, 409, 350, "#"..GetString("caption_outline", GetString("recipe_shelf")), 185, 26),
            
            -- FLOWERS START ---------------------------------------
            
            -- Flower count
            SetStyle(TxtFlower1Count),
            SpawnText("camomile_bud_1", 100, 150),
            SpawnText("camomile_bud_2", 100, 205),
            SpawnText("camomile_bud_3", 100, 260),
            SetStyle(TxtFlower2Count),
            SpawnText("cornflower_bud_1", 100, 345),
            SpawnText("cornflower_bud_2", 100, 400),
            SpawnText("cornflower_bud_3", 100, 460),
            SetStyle(TxtFlower3Count),
            SpawnText("rose_bud_1", 100, 545),
            SpawnText("rose_bud_2", 100, 600),
            SpawnText("rose_bud_3", 100, 650),
            
            -- Flower prices
            SpawnFlowerPrice("camomile_bud_1", 25, 155),
            SpawnFlowerPrice("camomile_bud_2", 25, 210),
            SpawnFlowerPrice("camomile_bud_3", 25, 265),
            SpawnFlowerPrice("cornflower_bud_1", 25, 350),
            SpawnFlowerPrice("cornflower_bud_2", 25, 405),
            SpawnFlowerPrice("cornflower_bud_3", 25, 465),
            SpawnFlowerPrice("rose_bud_1", 25, 550),
            SpawnFlowerPrice("rose_bud_2", 25, 605),
            SpawnFlowerPrice("rose_bud_3", 25, 660),
            
            -- Flower pictures
            BtnSell
            {
                name = "camomile_bud_1",
                ini_file = kIniFile,
                ini_tag  = "BTN_CAMOMILE_1",
                x = 80,
                y = 150,
                w = 300,
                h = 300,
                actions = {"PotionClick",},
                context = {"camomile_bud_1", "camomile_top_level"},
                context_change = function(item, old_val, new_val)
                    if (item == "camomile_bud_1") then
                        camomile_bud_1_SetClickable(new_val > 0);
                        if new_val == 0 then
                            EnableWindow("camomile_bud_1_sell_1", false);
                            EnableWindow("camomile_bud_1_sell_all", false);
                        end;
                    end;
                    if (item == "camomile_top_level") then
                        camomile_bud_1_SetLocked(new_val < 1);
                        if new_val >= 1 then
                            camomile_bud_1_SetClickable(GetCount("camomile_bud_1") > 0);
                        end;
                        
                        camomile_bud_1_gold_SetVisible(new_val >= 1);
                        EnableWindow("price_camomile_bud_1", new_val >= 1);
                        EnableWindow("price_camomile_bud_1_shadow", new_val >= 1);
                    end;
                end;
                on_enter = function()
                    if GetCount("camomile_bud_1") > 0 then
                        EnableWindow("camomile_bud_1_sell_1", true);
                        EnableWindow("camomile_bud_1_sell_all", true);
                    end;
                end;
                on_exit = function()
                    EnableWindow("camomile_bud_1_sell_1", false);
                    EnableWindow("camomile_bud_1_sell_all", false);
                end;
                
                SpawnSellButtons("camomile_bud_1", 80, 150, 1, gardenpath.."camomile/flower_01"),
            },
            SpawnFlowerSellControls("camomile_bud_2", "camomile_top_level", 2, "BTN_CAMOMILE_2", 80, 205, 2, gardenpath.."camomile/flower_02");
            SpawnFlowerSellControls("camomile_bud_3", "camomile_top_level", 3, "BTN_CAMOMILE_3", 80, 260, 3, gardenpath.."camomile/flower_03");
            SpawnFlowerSellControls("cornflower_bud_1", "cornflower_top_level", 1, "BTN_CORNFLOWER_1", 80, 345, 4, gardenpath.."cornflower/flower_01");
            SpawnFlowerSellControls("cornflower_bud_2", "cornflower_top_level", 2, "BTN_CORNFLOWER_2", 80, 400, 5, gardenpath.."cornflower/flower_02");
            SpawnFlowerSellControls("cornflower_bud_3", "cornflower_top_level", 3, "BTN_CORNFLOWER_3", 80, 460, 6, gardenpath.."cornflower/flower_03");
            SpawnFlowerSellControls("rose_bud_1", "rose_top_level", 1, "BTN_ROSE_1", 80, 540, 7, gardenpath.."rose/flower_01");
            SpawnFlowerSellControls("rose_bud_2", "rose_top_level", 2, "BTN_ROSE_2", 80, 600, 8, gardenpath.."rose/flower_02");
            SpawnFlowerSellControls("rose_bud_3", "rose_top_level", 3, "BTN_ROSE_3", 80, 655, 9, gardenpath.."rose/flower_03");
            -- FLOWERS FINISHED ------------------------------------
            
            -- POTIONS START ---------------------------------------
            SpawnPotionPrice("potion_1", 960, 45),
            SpawnPotionPrice("potion_2", 960, 115),
            SpawnPotionPrice("potion_3", 960, 185),
            SpawnPotionPrice("potion_4", 960, 255),
            SpawnPotionPrice("potion_5", 960, 325),
            SpawnPotionPrice("potion_6", 960, 395),
            SpawnPotionPrice("potion_7", 960, 465),
            SpawnPotionPrice("potion_8", 960, 535),
            SpawnPotionPrice("potion_9", 960, 605),
            SpawnPotionQuestTag("potion_1", 815, 46),
            SpawnPotionQuestTag("potion_2", 815, 116),
            SpawnPotionQuestTag("potion_3", 815, 186),
            SpawnPotionQuestTag("potion_4", 815, 256),
            SpawnPotionQuestTag("potion_5", 815, 326),
            SpawnPotionQuestTag("potion_6", 815, 396),
            SpawnPotionQuestTag("potion_7", 815, 466),
            SpawnPotionQuestTag("potion_8", 815, 536),
            SpawnPotionQuestTag("potion_9", 815, 606),

            SetStyle(TxtPotionCount),
            SpawnText("potion_1", 870, 85),
            SpawnText("potion_2", 870, 155),
            SpawnText("potion_3", 870, 225),
            SpawnText("potion_4", 870, 295),
            SpawnText("potion_5", 870, 365),
            SpawnText("potion_6", 870, 435),
            SpawnText("potion_7", 870, 505),
            SpawnText("potion_8", 870, 575),
            SpawnText("potion_9", 870, 645),
            
            BtnSell
            {
                name = "potion_1",
                ini_file = kIniFile,
                ini_tag  = "BTN_POTION_1",
                x = 935,
                y = 96,
                w = 300,
                h = 300,
                actions = {"PotionClick"},
                context = {"potion_1", "potion_1_enabled",},
                context_change = function(item, old_val, new_val)
                    if (item == "potion_1") and (GetCount("potion_1_enabled") == 1) then
                        potion_1_SetClickable(new_val > 0);
                        EnableWindow("potion_1_price_tag", new_val > 0);
                        EnableWindow("lbl_potion_1", new_val > 0);
                        EnableWindow("lbl_potion_1_shh", new_val > 0);
                        if new_val == 0 then
                            EnableWindow("potion_1_sell_1", false);
                            EnableWindow("potion_1_sell_all", false);
                        end;
                    end;
                    if (item == "potion_1_enabled") then
                        if (new_val == 1) and (old_val == 0) then
                            potion_1_SetLocked(false);
                        end;
                        if new_val == 0 then
                            EnableWindow("lbl_potion_1", false);
                            EnableWindow("potion_1_price_tag", false);
                            potion_1_SetLocked(true);
                        end;
                    end;
                end;
                on_enter = function()
                    if GetCount("potion_1") > 0 then
                        EnableWindow("potion_1_sell_1", true);
                        EnableWindow("potion_1_sell_all", true);
                    end;
                end;
                on_exit = function()
                    EnableWindow("potion_1_sell_1", false);
                    EnableWindow("potion_1_sell_all", false);
                end;
                
                SpawnSellPotionButtons("potion_1", 935, 96, 1, gardenpath.."laboratory/potions_store/pot_01"),
            },
            SpawnPotionSellControls("potion_2", "BTN_POTION_2", 935, 166, 2, gardenpath.."laboratory/potions_store/pot_02");
            SpawnPotionSellControls("potion_3", "BTN_POTION_3", 935, 236, 3, gardenpath.."laboratory/potions_store/pot_03");
            SpawnPotionSellControls("potion_4", "BTN_POTION_4", 935, 306, 4, gardenpath.."laboratory/potions_store/pot_04");
            SpawnPotionSellControls("potion_5", "BTN_POTION_5", 935, 376, 5, gardenpath.."laboratory/potions_store/pot_05");
            SpawnPotionSellControls("potion_6", "BTN_POTION_6", 935, 446, 6, gardenpath.."laboratory/potions_store/pot_06");
            SpawnPotionSellControls("potion_7", "BTN_POTION_7", 935, 516, 7, gardenpath.."laboratory/potions_store/pot_07");
            SpawnPotionSellControls("potion_8", "BTN_POTION_8", 935, 586, 8, gardenpath.."laboratory/potions_store/pot_08");
            SpawnPotionSellControls("potion_9", "BTN_POTION_9", 935, 656, 9, gardenpath.."laboratory/potions_store/pot_09");
            -- POTIONS FINISHED ------------------------------------
            
            -- RETURN
            SetStyle(ButtonStyle),
            ButtonExt
            {
                font = CreateNamedFont(MinionSbItSymbolSet, 28, ButtonBrown),
                sound = SellScreenButtonSound.ClickSound,
                rolloversound = SellScreenButtonSound.OverSound,
                mask = "buttons/uibutton_alfa",
                graphics = UIButtonGraphics,
                label = "back",
                name = "resume",
                x = 73,
                y = 733,
                state_handlers = {
                    justcreated = function()
                        ActivateControl("resume");
                        SetItemCount("pnl_sell_screen_state", 2);
                    end;
                },
                command = function()
                    SetItemCount("pnl_sell_screen_state", 0);
                    CloseWindow("no");
                    StartTimerCategory("game");
                    kPauseDlgShowAllowed = true;
                    EnableWindow("start_fx", true);
                end,
            },
            SetStyle({}),
            ButtonExt
            {
                font = CreateFont(20, WhiteColor),
                sound = SellScreenButtonSound.ClickSound,
                rolloversound = SellScreenButtonSound.OverSound,
                label = "quit",
                name = "quit_menu",
                cancel = true,
                x = 142,
                y = 840,
                w = 20,h=10,
                state_handlers = {
                    justcreated = function()
                        ActivateControl("quit_menu");
                    end;
                },
                command = function()
                    if (GetCount("hint_group_lab") ~= 1) and (GetCount("hint_sell_buds") ~= 1) then
                        HM_HideHint();
                        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
                            CloseWindow("yes");
                        else
                            HM_RestoreHint();
                        end;
                    end;
                end,
            },
        },
    },
}