print("Init Mission Ogorod")

local vault = resourceManager:getVault(ResourceManager.COMMON)

local loadingLabel = KrTextBox(game:getFontResource("occ24"), 150, 35, 1, KrTextBox.LEFT)
--loadingLabel:SetPos(10, 10, -1)
loadingLabel:SetPos(10, -500, -1)
setNodeScale(loadingLabel, 9)

mission:setLoadingLabel(loadingLabel)


resourceManager:initBoxVault("box2")
local boxVault = resourceManager:getBoxVault()

local spr = KrSprite(boxVault:GetSpriteResource("bg"))
-- local spr = KrSprite(boxVault:GetSpriteResource("shel_4"))

createNameBox3(boxVault, spr, game, mission)

local startBorderX = 125;
local startBorderY = 128;

placeStandBorder(boxVault, spr, "o-lu", startBorderX, startBorderY, 0, 2)
placeStandBorder(boxVault, spr, "o-lu", startBorderX, startBorderY, 2, 0)
placeStandBorder(boxVault, spr, "o-ru", startBorderX, startBorderY, 10, 0)
placeStandBorder(boxVault, spr, "o-ru", startBorderX, startBorderY, 12, 2)
placeStandBorder(boxVault, spr, "o-ld", startBorderX, startBorderY, 0, 6)
placeStandBorder(boxVault, spr, "o-ld", startBorderX, startBorderY, 2, 8)
placeStandBorder(boxVault, spr, "o-rd", startBorderX, startBorderY, 12, 6)
placeStandBorder(boxVault, spr, "o-rd", startBorderX, startBorderY, 10, 8)

placeStandBorder(boxVault, spr, "i-rd", startBorderX, startBorderY, 2, 2)
placeStandBorder(boxVault, spr, "i-ld", startBorderX, startBorderY, 10, 2)
placeStandBorder(boxVault, spr, "i-ru", startBorderX, startBorderY, 2, 6)
placeStandBorder(boxVault, spr, "i-lu", startBorderX, startBorderY, 10, 6)

for i = 3, 9 do
	placeStandBorder(boxVault, spr, "o-u", startBorderX, startBorderY, i, 0)
	placeStandBorder(boxVault, spr, "o-d", startBorderX, startBorderY, i, 8)
end


for i = 3, 5 do
	placeStandBorder(boxVault, spr, "o-l", startBorderX, startBorderY, 0, i)
	placeStandBorder(boxVault, spr, "o-r", startBorderX, startBorderY, 12, i)
end

placeStandBorder(boxVault, spr, "o-u", startBorderX, startBorderY, 1, 2)
placeStandBorder(boxVault, spr, "o-u", startBorderX, startBorderY, 11, 2)
placeStandBorder(boxVault, spr, "o-d", startBorderX, startBorderY, 1, 6)
placeStandBorder(boxVault, spr, "o-d", startBorderX, startBorderY, 11, 6)

placeStandBorder(boxVault, spr, "o-l", startBorderX, startBorderY, 2, 1)
placeStandBorder(boxVault, spr, "o-l", startBorderX, startBorderY, 2, 7)
placeStandBorder(boxVault, spr, "o-r", startBorderX, startBorderY, 10, 1)
placeStandBorder(boxVault, spr, "o-r", startBorderX, startBorderY, 10, 7)


local coreRoot = mission:getCoreRoot();


local stand = KrSprite(boxVault:GetSpriteResource("pupitr-l"))
stand:SetPos(125, 128 + 128, -1);
stand:SetZDepth(-10);
addNodeAdopt(stand, coreRoot)

stand = KrSprite(boxVault:GetSpriteResource("pupitr-r"))
stand:SetPos(125 + 640, 128 + 128, -1);
stand:SetZDepth(-10);
addNodeAdopt(stand, coreRoot)

stand = KrSprite(boxVault:GetSpriteResource("pupitr-c"))
stand:SetPos(125 + 128, 128, -1);
stand:SetZDepth(-18);
addNodeAdopt(stand, coreRoot)

stand = KrSprite(boxVault:GetSpriteResource("setka0"))
stand:SetPos(125, 128, -1);
stand:SetZDepth(-18);
addNodeAdopt(stand, coreRoot)

stand = KrSprite(boxVault:GetSpriteResource("setka0_sl"))
stand:SetPos(125, 128 + 128, -1);
stand:SetZDepth(-10);
addNodeAdopt(stand, coreRoot)

stand = KrSprite(boxVault:GetSpriteResource("setka0_sr"))
stand:SetPos(125 + 640, 128 + 128, -1);
stand:SetZDepth(-10);
addNodeAdopt(stand, coreRoot)


local luIdx = 0;
local ruIdx = 1;
local ldIdx = 2;
local rdIdx = 3;

mission:setGroupCounts(4, 0);

addMusicianManBox2(boxVault, 3.1 * 2, "lu", coreRoot, mission, luIdx)
addMusicianManBox2(boxVault, 3.1 * 2, "ld", coreRoot, mission, ldIdx)
addMusicianPianBox2(boxVault, 1.55, "ru", coreRoot, mission, ruIdx)
addMusicianBarBox2(boxVault, 3.1 * 2, "rd", coreRoot, mission, rdIdx)




-- створки окон

local openCloseTime = 0.3;

local wnd = MusCircleWnd(coreRoot, openCloseTime)
local leaf1 = KrSprite(boxVault:GetSpriteResource("win_shtor1"))
wnd:addLeaf(leaf1, 0.3927 * 2, -0.7854 - 0.3927 * 2);
local leaf2 = KrSprite(boxVault:GetSpriteResource("win_shtor1"))
wnd:addLeaf(leaf2, 0.3927, -0.7854 - 0.3927);
local leaf3 = KrSprite(boxVault:GetSpriteResource("win_shtor1"))
wnd:addLeaf(leaf3, 0, -0.7854);

wnd:getRoot():SetPos(211, 206, -1);
wnd:getRoot():SetZDepth(-11);
mission:addAnimationNode(wnd, luIdx)


local wnd = MusCircleWnd(coreRoot, openCloseTime)
local leaf1 = KrSprite(boxVault:GetSpriteResource("win_shtor2"))
wnd:addLeaf(leaf1, -0.3927 * 2, 0.7854 + 0.3927 * 2);
local leaf2 = KrSprite(boxVault:GetSpriteResource("win_shtor2"))
wnd:addLeaf(leaf2, -0.3927, 0.7854 + 0.3927);
local leaf3 = KrSprite(boxVault:GetSpriteResource("win_shtor2"))
wnd:addLeaf(leaf3, 0, 0.7854);

wnd:getRoot():SetPos(806, 203, -1);
wnd:getRoot():SetZDepth(-11);
mission:addAnimationNode(wnd, ruIdx)


local wnd = MusCircleWnd(coreRoot, openCloseTime)
local leaf1 = KrSprite(boxVault:GetSpriteResource("win_shtor3"))
wnd:addLeaf(leaf1, -0.3927 * 2, 0.7854 + 0.3927 * 2);
local leaf2 = KrSprite(boxVault:GetSpriteResource("win_shtor3"))
wnd:addLeaf(leaf2, -0.3927, 0.7854 + 0.3927);
local leaf3 = KrSprite(boxVault:GetSpriteResource("win_shtor3"))
wnd:addLeaf(leaf3, 0, 0.7854);

wnd:getRoot():SetPos(212, 563, -1);
wnd:getRoot():SetZDepth(-11);
mission:addAnimationNode(wnd, ldIdx)

local wnd = MusCircleWnd(coreRoot, openCloseTime)
local leaf1 = KrSprite(boxVault:GetSpriteResource("win_shtor4"))
wnd:addLeaf(leaf1, 0.3927 * 2, -0.7854 - 0.3927 * 2);
local leaf2 = KrSprite(boxVault:GetSpriteResource("win_shtor4"))
wnd:addLeaf(leaf2, 0.3927, -0.7854 - 0.3927);
local leaf3 = KrSprite(boxVault:GetSpriteResource("win_shtor4"))
wnd:addLeaf(leaf3, 0, -0.7854);

wnd:getRoot():SetPos(811, 568, -1);
wnd:getRoot():SetZDepth(-11);
mission:addAnimationNode(wnd, rdIdx)


-- бэки окон

local wndbg = KrSprite(boxVault:GetSpriteResource("win_back_1"))
wndbg:SetPos(211, 206, -1);
wndbg:SetZDepth(-13);
addNodeAdopt(wndbg, coreRoot)

wndbg = KrSprite(boxVault:GetSpriteResource("win_back_2"))
wndbg:SetPos(806, 203, -1);
wndbg:SetZDepth(-13);
addNodeAdopt(wndbg, coreRoot)

wndbg = KrSprite(boxVault:GetSpriteResource("win_back_3"))
wndbg:SetPos(212, 563, -1);
wndbg:SetZDepth(-13);
addNodeAdopt(wndbg, coreRoot)

wndbg = KrSprite(boxVault:GetSpriteResource("win_back_4"))
wndbg:SetPos(811, 568, -1);
wndbg:SetZDepth(-13);
addNodeAdopt(wndbg, coreRoot)


-- тени окон

wndbg = KrSprite(boxVault:GetSpriteResource("win_shad_1"))
wndbg:SetPos(211, 206, -1);
wndbg:SetZDepth(-12);
addNodeAdopt(wndbg, coreRoot)

wndbg = KrSprite(boxVault:GetSpriteResource("win_shad_2"))
wndbg:SetPos(806, 203, -1);
wndbg:SetZDepth(-12);
addNodeAdopt(wndbg, coreRoot)

wndbg = KrSprite(boxVault:GetSpriteResource("win_shad_3"))
wndbg:SetPos(212, 563, -1);
wndbg:SetZDepth(-12);
addNodeAdopt(wndbg, coreRoot)

wndbg = KrSprite(boxVault:GetSpriteResource("win_shad_4"))
wndbg:SetPos(811, 568, -1);
wndbg:SetZDepth(-12);
addNodeAdopt(wndbg, coreRoot)


mission:setBG(spr)

	local button = XButton();


	local x = 68
	local y = 18

	local width = 94
	local height = 30
	local sensX = -47
	local sensY = -15
	local textY = sensY + 3;

	local rText = 245;
	local gText = 203;
	local bText = 99;
	local aText = 216;

	local rHText = 255;
	local gHText = 255;
	local bHText = 255;
	local aHText = 216;
		
	initXBtn(button, "Btn_game", x, y, sensX, sensY, width, height, vault)
	initXButtonText(button, "GAME_SCREEN.HINT",
						sensX, textY, 
						width, height, 
						"occ24bg", KrTextBox.CENTER)

	button:setTextColor(rText, gText, bText, aText);
	button:setTextColorBType(XButton.NORMAL_HIGHLIGHTED, rHText, gHText, bHText, aHText);
	button:setTextColorBType(XButton.NORMAL_PRESSED, rHText, gHText, bHText, aHText);
	button:getRoot():SetPos(-200, -200, -1);

	mission:setHelpButton(button)

	button = XButton();

	x = x + 1024 - 68 - 68

	initXBtn(button, "Btn_game", x, y, sensX, sensY, width, height, vault)
	initXButtonText(button, "GAME_SCREEN.MENU",
						sensX, textY, 
						width, height, 
						"occ24bg", KrTextBox.CENTER)

	button:setTextColor(rText, gText, bText, aText);
	button:setTextColorBType(XButton.NORMAL_HIGHLIGHTED, rHText, gHText, bHText, aHText);
	button:setTextColorBType(XButton.NORMAL_PRESSED, rHText, gHText, bHText, aHText);

	mission:setExitButton(button)

fadingPlane = KrSprite(vault:GetSpriteResource("fadingPlane"))
fadingPlane:SetPos(0, 0, -1)
mission:setFadingPlaneSprite(fadingPlane)
