print("init Internal Menu begin");

local windowLeft = 333 + 8 + 4;
local windowTop = 153 - 20 - 10 - 5;

local fadeInBG = 0.2
local fadeOutBG = 0.2
local fadeInBtnsDelay = 0.2
local fadeInBtns = 0.1
local fadeOutBtns = 0.1


local menu = game:getSceneManager():getInternalMenu()
local vault = resourceManager:getVault(ResourceManager.COMMON)

-- local sprite = KrSprite(vault:GetSpriteResource("hatch"))
local sprite = KrSprite(vault:GetSpriteResource("hatch_black"))
setNodeScale(sprite, 256, 192);
-- aniFadeInFadeOut(sprite,0,.3,.3,60)
aniFadeInFadeOut(sprite,0,.3,.3,127)
menu:setBackground(sprite)


local windowBack = KrImNode()
windowBack:SetPos( windowLeft, windowTop, -1 )
local pageBG1 = KrSprite(vault:GetSpriteResource("Pergament_internal_menu"))
setNodeScale(pageBG1, 1, 476 / 450)
addNodeAdopt(pageBG1, windowBack)


aniFadeInFadeOut(windowBack,0,fadeInBG,fadeOutBG)

local startBorderX = 0;
local startBorderY = 0;

local standB = KrSprite(vault:GetSpriteResource("mbox_lu"))
standB:SetPos(startBorderX, startBorderY, -1);
addNodeAdopt(standB, windowBack)

startBorderX = startBorderX + 44;

standB = KrSprite(vault:GetSpriteResource("mbox_u"))
standB:SetPos(startBorderX, startBorderY, -1);
addNodeAdopt(standB, windowBack)

startBorderX = startBorderX + 64;

standB = KrSprite(vault:GetSpriteResource("mbox_u_gem"))
standB:SetPos(startBorderX, startBorderY, -1);
addNodeAdopt(standB, windowBack)


startBorderX = startBorderX + 128;

standB = KrSprite(vault:GetSpriteResource("mbox_u"))
standB:SetPos(startBorderX, startBorderY, -1);
addNodeAdopt(standB, windowBack)

startBorderX = startBorderX + 64;

standB = KrSprite(vault:GetSpriteResource("mbox_ru"))
standB:SetPos(startBorderX, startBorderY, -1);
addNodeAdopt(standB, windowBack)


startBorderX = startBorderX + 41;
startBorderY = startBorderY + 46;

for i = 0, 5 do

	standB = KrSprite(vault:GetSpriteResource("mbox_r"))
	standB:SetPos(startBorderX, startBorderY, -1);
	addNodeAdopt(standB, windowBack)

	startBorderY = startBorderY + 64;

end

standB = KrSprite(vault:GetSpriteResource("mbox_rd"))
standB:SetPos(startBorderX, startBorderY, -1);
addNodeAdopt(standB, windowBack)

startBorderX = startBorderX - 41 - 128;
startBorderY = startBorderY + 46;

standB = KrSprite(vault:GetSpriteResource("mbox_d"))
standB:SetPos(startBorderX, startBorderY, -1);
addNodeAdopt(standB, windowBack)


startBorderX = startBorderX - 128;

standB = KrSprite(vault:GetSpriteResource("mbox_d"))
standB:SetPos(startBorderX, startBorderY, -1);
addNodeAdopt(standB, windowBack)

startBorderX = startBorderX - 44;
startBorderY = startBorderY - 46;

standB = KrSprite(vault:GetSpriteResource("mbox_ld"))
standB:SetPos(startBorderX, startBorderY, -1);
addNodeAdopt(standB, windowBack)

startBorderY = startBorderY - 64;

for i = 0, 5 do

	standB = KrSprite(vault:GetSpriteResource("mbox_l"))
	standB:SetPos(startBorderX, startBorderY, -1);
	addNodeAdopt(standB, windowBack)

	startBorderY = startBorderY - 64;

end



menu:setBgSprite(windowBack)


-- create "Back to game" button

	local button = XButton();

	local width = 160
	local height = 40
	local sensX = -82
	local sensY = -20
	local textY = sensY + 10;

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

	local rHText = 255;
	local gHText = 255;
	local bHText = 255;
	local aHText = 216;

	local btnShift = 66;
		
	local x = windowLeft + 167
	local y = windowTop + 60

	initXBtn(button, "Btn_XXX", x, y, sensX, sensY, width, height, vault)
	initXButtonText(button, getText(getText("INTERNAL_MENU.BTN_BACK_TO_GAME")),
						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);
	aniFadeInFadeOut(button:getRoot(), fadeInBtnsDelay, fadeInBtns, fadeOutBtns)

	button:setAccelerator(XButton.ESCAPE);
	menu:setBackToGameButton(button)

	local shiftBtn = 70;
	y = y + shiftBtn


-- create "Reset" button

	local button = XButton();
	initXBtn(button, "Btn_XXX", x, y, sensX, sensY, width, height, vault)
	initXButtonText(button, getText(getText("INTERNAL_MENU.BTN_RESET")),
						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);
	aniFadeInFadeOut(button:getRoot(), fadeInBtnsDelay, fadeInBtns, fadeOutBtns)


	menu:setResetButton(button)

	y = y + shiftBtn

-- create "Add to favorites" button

	local button = XButton();
	initXBtn(button, "Btn_XXX", x, y, sensX, sensY, width, height, vault)
	initXButtonText(button, getText(getText("START_MENU.BUTTONS.BTN_SETTINGS")),
						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);
	aniFadeInFadeOut(button:getRoot(), fadeInBtnsDelay, fadeInBtns, fadeOutBtns)

	menu:setFavoriteButton(button)

	y = y + shiftBtn


-- create "Help" button

	local button = XButton();
	initXBtn(button, "Btn_XXX", x, y, sensX, sensY, width, height, vault)
	initXButtonText(button, getText(getText("INTERNAL_MENU.BTN_HELP")),
						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);
	aniFadeInFadeOut(button:getRoot(), fadeInBtnsDelay, fadeInBtns, fadeOutBtns)

	menu:setHelpButton(button)

	y = y + shiftBtn

-- create "Back to Room" button

	local button = XButton();
	initXBtn(button, "Btn_XXX", x, y, sensX, sensY, width, height, vault)
	initXButtonText(button, getText(getText("INTERNAL_MENU.BTN_BACK_TO_ROOM")),
						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);
	aniFadeInFadeOut(button:getRoot(), fadeInBtnsDelay, fadeInBtns, fadeOutBtns)


	menu:setBackToRoomButton(button)

	y = y + shiftBtn

-- create "Quit" button

	local button = XButton();
	initXBtn(button, "Btn_XXX", x, y, sensX, sensY, width, height, vault)
	initXButtonText(button, getText(getText("INTERNAL_MENU.BTN_QUIT")),
						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);
	aniFadeInFadeOut(button:getRoot(), fadeInBtnsDelay, fadeInBtns, fadeOutBtns)


	menu:setQuitButton(button)


print("init Internal Menu end");
