print("init Message Window begin");


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

local fadeInDelay = 0
local fadeInTime = 1
local fadeOutTime = 1

local windowLeft = 390
local windowTop = 273

local shiftX = 0
local shiftY = -20

local frameW = 260
local frameH = 180

pi = 3.1415926535897932384626433832795

-- Создание бакграунда
-- Должен добавляться раньше всех. Ибо в противном случае он накрывает
-- остальные контролы и не дает им мышь

-- 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 sprite = KrSprite(vault:GetSpriteResource("hatch"))
sprite:SetColor(KrColorTransform(KrRGBA(0, 0, 0, 96)), -1);
--sprite:SetPos(-windowLeft, -windowTop, -1)
menu:setBackground(sprite)
menu:setBackgroundSize(game:screenWidth(), game:screenHeight())
]]--

windowLeft = 356
windowTop = 273


local windowBack = KrSprite(vault:GetSpriteResource("book_bg"))
aniFadeInFadeOut(windowBack, fadeInDelay, fadeInTime, fadeOutTime, 255)

local pageX = 60;
local pageY = 130;

windowBack:SetPos(pageX, pageY + shiftY, -1)
menu:setImageFrame(windowBack)

-- Pages

pageX = pageX - 6;
pageY = pageY - 39;

local page1 = KrImNode()
-- page1:SetPos(0, shiftY, -1);

local pageSpr = KrSprite(vault:GetSpriteResource("help_master_bar"))
pageSpr:SetPos(307 - pageX, 349 - pageY, -1);
addNodeAdopt(pageSpr, page1)

pageSpr = KrSprite(vault:GetSpriteResource("help_drag"))
pageSpr:SetPos(353 - pageX, 563 - pageY, -1);
addNodeAdopt(pageSpr, page1)

pageSpr = KrSprite(vault:GetSpriteResource("help_over"))
pageSpr:SetPos(710 - pageX, 271 - pageY, -1);
addNodeAdopt(pageSpr, page1)

pageSpr = KrSprite(vault:GetSpriteResource("help_over_bar"))
pageSpr:SetPos(674 - pageX, 540 - pageY, -1);
addNodeAdopt(pageSpr, page1)

local leftPageTextX = 128 - pageX - 2;
local rightPageTextX = 530 - pageX - 4;

local pageTextBox = KrTextBox(game:getFontResource("occ24b"), 368, 62, 2, KrTextBox.LEFT);
pageTextBox:SetTextMultiLineColored( getText("HELP.1") );
pageTextBox:SetPos(leftPageTextX + 14, 146 - pageY, -1);
addNodeAdopt(pageTextBox, page1)

pageTextBox = KrTextBox(game:getFontResource("occ24b"), 368, 62, 2, KrTextBox.LEFT);
pageTextBox:SetTextMultiLineColored( getText("HELP.2") );
pageTextBox:SetPos(leftPageTextX, 222 - pageY, -1);
addNodeAdopt(pageTextBox, page1)

pageTextBox = KrTextBox(game:getFontResource("occ24b"), 368, 62, 2, KrTextBox.LEFT);
pageTextBox:SetTextMultiLineColored( getText("HELP.3") );
pageTextBox:SetPos(leftPageTextX, 401 - pageY, -1);
addNodeAdopt(pageTextBox, page1)

pageTextBox = KrTextBox(game:getFontResource("occ24b"), 368, 62, 2, KrTextBox.LEFT);
pageTextBox:SetTextMultiLineColored( getText("HELP.4") );
pageTextBox:SetPos(leftPageTextX, 443 - pageY, -1);
addNodeAdopt(pageTextBox, page1)

pageTextBox = KrTextBox(game:getFontResource("occ24b"), 368, 62, 2, KrTextBox.LEFT);
pageTextBox:SetTextMultiLineColored( getText("HELP.5") );
pageTextBox:SetPos(rightPageTextX + 14, 146 - pageY, -1);
addNodeAdopt(pageTextBox, page1)

pageTextBox = KrTextBox(game:getFontResource("occ24b"), 368, 62, 2, KrTextBox.LEFT);
pageTextBox:SetTextMultiLineColored( getText("HELP.6") );
pageTextBox:SetPos(rightPageTextX + 14, 368 - pageY, -1);
addNodeAdopt(pageTextBox, page1)


menu:addPage(page1);


local page2 = KrImNode()
-- page2:SetPos(0, shiftY, -1);

pageSpr = KrSprite(vault:GetSpriteResource("help_music_stand"))
pageSpr:SetPos(238 - pageX, 288 - pageY, -1);
addNodeAdopt(pageSpr, page2)

pageSpr = KrSprite(vault:GetSpriteResource("help_hint"))
pageSpr:SetPos(399 - pageX, 546 - pageY - 10, -1);
addNodeAdopt(pageSpr, page2)

pageSpr = KrSprite(vault:GetSpriteResource("help_musician"))
pageSpr:SetPos(602 - pageX, 362 - pageY + 24, -1);
addNodeAdopt(pageSpr, page2)

pageSpr = KrSprite(vault:GetSpriteResource("help_column"))
pageSpr:SetPos(780 - pageX, 311 - pageY + 24, -1);
addNodeAdopt(pageSpr, page2)

pageTextBox = KrTextBox(game:getFontResource("occ24b"), 368, 62, 2, KrTextBox.LEFT);
pageTextBox:SetTextMultiLineColored( getText("HELP.7") );
pageTextBox:SetPos(leftPageTextX + 19, 146 - pageY, -1);
addNodeAdopt(pageTextBox, page2)


pageTextBox = KrTextBox(game:getFontResource("occ24b"), 368, 62 * 2, 2, KrTextBox.LEFT);
pageTextBox:SetTextMultiLineColored( getText("HELP.8") );
pageTextBox:SetPos(leftPageTextX + 6, 436 - pageY + 10, -1);
addNodeAdopt(pageTextBox, page2)

pageTextBox = KrTextBox(game:getFontResource("occ24b"), 400, 62 * 2, 2, KrTextBox.LEFT);
pageTextBox:SetTextMultiLineColored( getText("HELP.9") );
pageTextBox:SetPos(rightPageTextX + 9, 146 - pageY, -1);
addNodeAdopt(pageTextBox, page2)

pageTextBox = KrTextBox(game:getFontResource("occ24b"), 400, 62 * 2 + 30, 2, KrTextBox.LEFT);
pageTextBox:SetTextMultiLineColored( getText("HELP.10") );
pageTextBox:SetPos(rightPageTextX + 9, 453 - pageY + 5 + 24, -1);
addNodeAdopt(pageTextBox, page2)

menu:addPage(page2);


local page3 = KrImNode()

pageSpr = KrSprite(vault:GetSpriteResource("help_red"))
pageSpr:SetPos(307 - pageX, 349 - pageY + 10, -1);
addNodeAdopt(pageSpr, page3)

pageSpr = KrSprite(vault:GetSpriteResource("help_vert1"))
pageSpr:SetPos(628 - pageX, 480 - pageY - 127, -1);
addNodeAdopt(pageSpr, page3)

pageSpr = KrSprite(vault:GetSpriteResource("help_vert2"))
pageSpr:SetPos(787 - pageX, 480 - pageY - 127, -1);
addNodeAdopt(pageSpr, page3)

pageSpr = KrSprite(vault:GetSpriteResource("help_equal"))
pageSpr:SetPos(696 - pageX, 480 - pageY - 127, -1);
addNodeAdopt(pageSpr, page3)

leftPageTextX = 128 - pageX;
rightPageTextX = 530 - pageX;

pageTextBox = KrTextBox(game:getFontResource("occ24b"), 368, 150, 2, KrTextBox.LEFT);
pageTextBox:SetTextMultiLineColored( getText("HELP.11") );
pageTextBox:SetPos(leftPageTextX + 14, 146 - pageY, -1);
addNodeAdopt(pageTextBox, page3)

pageTextBox = KrTextBox(game:getFontResource("occ24b"), 368, 402, 2, KrTextBox.LEFT);
pageTextBox:SetTextMultiLineColored( getText("HELP.12") );
pageTextBox:SetPos(rightPageTextX + 11, 146 - pageY, -1);
addNodeAdopt(pageTextBox, page3)

pageTextBox = KrTextBox(game:getFontResource("occ24b"), 368, 402, 2, KrTextBox.LEFT);
pageTextBox:SetTextMultiLineColored( getText("HELP.12-1") );
pageTextBox:SetPos(rightPageTextX + 11, 475 - pageY, -1);
addNodeAdopt(pageTextBox, page3)

menu:addPage(page3);

---------------------------------------------------

	local button = XButton();

	local x = 1024 - 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.MENU",
						sensX, textY, 
						width, height, 
						"occ24bg", KrTextBox.CENTER)

	aniFadeInFadeOut(button:getRoot(),fadeInDelay, fadeInTime, fadeOutTime, 255)
	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:setAccelerator(XButton.ESCAPE);
	menu:setButton(button);



	button = XButton();
	initXBtn(button, "Btn_arrow_l", 194, 623 + shiftY, -47, -43, 54, 62, vault)
	aniFadeInFadeOut(button:getRoot(),fadeInDelay, fadeInTime, fadeOutTime, 255)
	menu:setLeftArrowButton(button);

	button = XButton();
	initXBtn(button, "Btn_arrow_r", 829, 624 + shiftY, -8, -32, 49, 60, vault)
	aniFadeInFadeOut(button:getRoot(),fadeInDelay, fadeInTime, fadeOutTime, 255)
	menu:setRightArrowButton(button);

-- create and init textBox

local width = 250;
local height= 150;

local textBox = KrTextBox(game:getFontResource("occ24"), width, height, 2, KrTextBox.CENTER);
aniFadeInFadeOut(textBox, fadeInDelay, fadeInTime , fadeOutTime)

textBox:SetPos(windowLeft + 40 + width/2, windowTop + 35 + height/2, -1);

menu:setTextBox(textBox);

-- end crate text box

print("init Message Window end");


