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("box3")
local boxVault = resourceManager:getBoxVault()

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

createNameBox3(boxVault, spr, game, mission)


local startBorderX = 128 + 3;
local startBorderY = 96 - 3;

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, 7)
placeStandBorder(boxVault, spr, "o-ld", startBorderX, startBorderY, 2, 9)
placeStandBorder(boxVault, spr, "o-rd", startBorderX, startBorderY, 12, 7)
placeStandBorder(boxVault, spr, "o-rd", startBorderX, startBorderY, 10, 9)

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, 7)
placeStandBorder(boxVault, spr, "i-lu", startBorderX, startBorderY, 10, 7)

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


for i = 3, 6 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, 7)
placeStandBorder(boxVault, spr, "o-d", startBorderX, startBorderY, 11, 7)

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

local coreRoot = mission:getCoreRoot();

local stand = KrSprite(boxVault:GetSpriteResource("pupitr"))
stand:SetPos(startBorderX - 64, startBorderY, -1);
setNodeScale(stand, 1.2, 1);
stand:SetZDepth(-99);
addNodeAdopt(stand, coreRoot)

stand = KrSprite(boxVault:GetSpriteResource("setka0"))
stand:SetPos(startBorderX, startBorderY, -1);
stand:SetZDepth(-99);
addNodeAdopt(stand, coreRoot)


mission:setGroupCounts(4, 8);



-- шестерни

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


-- бэки окон

wndbg = KrSprite(boxVault:GetSpriteResource("win_bg_u"))
wndbg:SetPos(84, 73, -1);
wndbg:SetZDepth(-6);
addNodeAdopt(wndbg, coreRoot)

wndbg = KrSprite(boxVault:GetSpriteResource("win_bg_d"))
wndbg:SetPos(84, 581, -1);
wndbg:SetZDepth(-6);
addNodeAdopt(wndbg, coreRoot)

wndbg = KrSprite(boxVault:GetSpriteResource("win_bg_u"))
wndbg:SetPos(826, 73, -1);
wndbg:SetZDepth(-6);
addNodeAdopt(wndbg, coreRoot)

wndbg = KrSprite(boxVault:GetSpriteResource("win_bg_d"))
wndbg:SetPos(826, 581, -1);
wndbg:SetZDepth(-6);
addNodeAdopt(wndbg, coreRoot)

-- тени окон

wndbg = KrSprite(boxVault:GetSpriteResource("wnd_shadow"))
wndbg:SetPos(87, 75, -1);
wndbg:SetZDepth(-4);
addNodeAdopt(wndbg, coreRoot)

wndbg = KrSprite(boxVault:GetSpriteResource("wnd_shadow"))
wndbg:SetPos(829, 75, -1);
wndbg:SetZDepth(-4);
addNodeAdopt(wndbg, coreRoot)

wndbg = KrSprite(boxVault:GetSpriteResource("wnd_shadow"))
wndbg:SetPos(829, 585, -1);
wndbg:SetZDepth(-4);
addNodeAdopt(wndbg, coreRoot)

wndbg = KrSprite(boxVault:GetSpriteResource("wnd_shadow"))
wndbg:SetPos(87, 585, -1);
wndbg:SetZDepth(-4);
addNodeAdopt(wndbg, coreRoot)

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

local openCloseTime = 0.3;

local wnd = MusWnd(coreRoot, openCloseTime, 55)
local leftLeaf = KrSprite(boxVault:GetSpriteResource("winL_u"))
wnd:addLeaf(leftLeaf, true);
local rightLeaf = KrSprite(boxVault:GetSpriteResource("winR_u"))
wnd:addLeaf(rightLeaf, false);
wnd:getRoot():SetPos(143, 74, -1);
wnd:getRoot():SetZDepth(-3);
mission:addAnimationNode(wnd, luIdx)

wnd = MusWnd(coreRoot, openCloseTime, 55)
leftLeaf = KrSprite(boxVault:GetSpriteResource("winL_u"))
wnd:addLeaf(leftLeaf, true);
rightLeaf = KrSprite(boxVault:GetSpriteResource("winR_u"))
wnd:addLeaf(rightLeaf, false);
wnd:getRoot():SetPos(886, 74, -1);
wnd:getRoot():SetZDepth(-3);
mission:addAnimationNode(wnd, ruIdx)

wnd = MusWnd(coreRoot, openCloseTime, 55)
leftLeaf = KrSprite(boxVault:GetSpriteResource("winL_d"))
wnd:addLeaf(leftLeaf, true);
rightLeaf = KrSprite(boxVault:GetSpriteResource("winR_d"))
wnd:addLeaf(rightLeaf, false);
wnd:getRoot():SetPos(143, 584, -1);
wnd:getRoot():SetZDepth(-3);
mission:addAnimationNode(wnd, ldIdx)

wnd = MusWnd(coreRoot, openCloseTime, 55)
leftLeaf = KrSprite(boxVault:GetSpriteResource("winL_d"))
wnd:addLeaf(leftLeaf, true);
rightLeaf = KrSprite(boxVault:GetSpriteResource("winR_d"))
wnd:addLeaf(rightLeaf, false);
wnd:getRoot():SetPos(886, 584, -1);
wnd:getRoot():SetZDepth(-3);
mission:addAnimationNode(wnd, rdIdx)



--[[
local stand = KrSprite(boxVault:GetSpriteResource("pupitr"))
stand:SetPos(194, 104 - 64 * 3, -1);
-- setNodeScale(stand, 0.83, 0.80);
stand:SetZDepth(-18);
addNodeAdopt(stand, coreRoot)

stand = KrSprite(boxVault:GetSpriteResource("setka0"))
stand:SetPos(211 - 25 + 3, 110 - 25 + 2 - 64 * 3, -1);
stand:SetZDepth(-18);
addNodeAdopt(stand, coreRoot)
]]--

addMusicianPianBox3(boxVault, 1.577 * 1.5, "lu", coreRoot, mission, luIdx)
addMusicianPianBox3(boxVault, 1.577 * 1.5, "rd", coreRoot, mission, rdIdx)
addMusicianPianBox3(boxVault, 1.577 * 1.5, "ru", coreRoot, mission, ruIdx)
addMusicianPianBox3(boxVault, 1.577 * 1.5, "ld", coreRoot, mission, ldIdx)

-- addMusicianSkripBox3(boxVault, 2, 106, 138, coreRoot, mission, luIdx)
-- addMusicianTrubBox3(boxVault, 2, 912 + 21, 636 + 11, coreRoot, mission, rdIdx)
-- addMusicianManBox3(boxVault, 4, 912 + 10, 138, coreRoot, mission, ruIdx)
-- addMusicianPianBox3(boxVault, 0.8, 106, 624 + 21 + 5, coreRoot, mission, ldIdx)

-- addMusicianBarBox3(boxVault, 4, 106, 624 + 21 + 5, coreRoot, mission, ruIdx)

--[[


addMusicianSkripBox2(boxVault, 2, 137, 168, coreRoot, mission, luIdx)

addMusicianSkripBox2(boxVault, 2, 137, 624, coreRoot, mission, ldIdx)
-- addMusicianManBox2(boxVault, 3, 140, 624, coreRoot, mission, ldIdx)

addMusicianTrubBox2(boxVault, 2, 885, 165, coreRoot, mission, ruIdx)
-- addMusicianBarBox2(boxVault, 4, 877, 165, coreRoot, mission, ruIdx)

]]--

mission:setBG(spr)
-- mission:createHoleForMasterBar(221, 594, 580, 88);


	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)
