print("init Credits Window begin");


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

local fadeInDelay = 0
local fadeInTime = 0.4
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)

local kranx_l = KrSprite(vault:GetSpriteResource("kranx_l"))
kranx_l:SetPos(185 - pageX, 693 - pageY - shiftY, -1)
addNodeAdopt(kranx_l, windowBack)

local kranx_r = KrSprite(vault:GetSpriteResource("kranx_r"))
kranx_r:SetPos(837 - pageX, 692 - pageY - shiftY, -1)
addNodeAdopt(kranx_r, windowBack)

menu:setImageFrame(windowBack)


-- Pages

pageX = pageX - 7;
pageY = pageY - 39;

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

local lvault = resourceManager:getVault(ResourceManager.LOADING)

local shAvaX = -7;
local shAvaY = -33 - 19;

local pageSpr = KrSprite(lvault:GetSpriteResource("Porechnov"))
pageSpr:SetPos(319 - pageX + shAvaX, 269 - pageY + shAvaY, -1);
addNodeAdopt(pageSpr, page1)

local pageSpr = KrSprite(lvault:GetSpriteResource("Yuzvovich"))
pageSpr:SetPos(425 - pageX + shAvaX, 479  - pageY + shAvaY, -1);
addNodeAdopt(pageSpr, page1)

local pageSpr = KrSprite(lvault:GetSpriteResource("Chaliy"))
pageSpr:SetPos(815 - pageX + shAvaX, 224 - pageY + shAvaY, -1);
addNodeAdopt(pageSpr, page1)

local pageSpr = KrSprite(lvault:GetSpriteResource("Oleynik"))
pageSpr:SetPos(608 - pageX + shAvaX, 478 - pageY + shAvaY, -1);
addNodeAdopt(pageSpr, page1)

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

local pageTextBox = KrTextBox(game:getFontResource("occ24b"), 205, 319, 2, KrTextBox.RIGHT);
pageTextBox:SetTextMultiLineColored( getText("CREDITS.Porechnov") );
pageTextBox:SetPos(leftPageTextX + 138 - 3 - 9, 190 - pageY - 33 - 15, -1);
addNodeAdopt(pageTextBox, page1)

pageTextBox = KrTextBox(game:getFontResource("occ24b"), 194, 133, 2, KrTextBox.LEFT);
pageTextBox:SetTextMultiLineColored( getText("CREDITS.Yuzvovich") );
pageTextBox:SetPos(leftPageTextX + 180 - 128 - 3 - 9, 467 - pageY - 33 - 15, -1);
addNodeAdopt(pageTextBox, page1)

pageTextBox = KrTextBox(game:getFontResource("occ24b"), 160, 133, 2, KrTextBox.LEFT);
pageTextBox:SetTextMultiLineColored( getText("CREDITS.Chaliy") );
pageTextBox:SetPos(leftPageTextX + 562 - 128 - 3 - 9, 193 - pageY - 33 - 15, -1);
addNodeAdopt(pageTextBox, page1)

pageTextBox = KrTextBox(game:getFontResource("occ24b"), 175, 100, 2, KrTextBox.RIGHT);
pageTextBox:SetTextMultiLineColored( getText("CREDITS.Oleynik") );
pageTextBox:SetPos(leftPageTextX + 681 - 128 - 3 - 9, 464 - pageY - 33 - 15, -1);
addNodeAdopt(pageTextBox, page1)

aniFadeInFadeOut(page1, fadeInTime, 0.2, 0.2, 255)

menu:addPage(page1);


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

pageTextBox = KrTextBox(game:getFontResource("occ24b"), 194, 173, 2, KrTextBox.LEFT);
pageTextBox:SetTextMultiLineColored( getText("CREDITS.DryomovTitle") );
pageTextBox:SetPos(leftPageTextX + 29, 190 - pageY - 33 - 15, -1);
addNodeAdopt(pageTextBox, page2)

pageTextBox = KrTextBox(game:getFontResource("occ24b"), 194, 173, 2, KrTextBox.RIGHT);
pageTextBox:SetTextMultiLineColored( getText("CREDITS.Dryomov") );
pageTextBox:SetPos(335 - 137, 190 - pageY - 33 - 15 + 40, -1);
addNodeAdopt(pageTextBox, page2)

pageTextBox = KrTextBox(game:getFontResource("occ24b"), 250, 133, 2, KrTextBox.LEFT);
pageTextBox:SetTextMultiLineColored( getText("CREDITS.KuzmitchTitle") );
pageTextBox:SetPos(leftPageTextX + 29, 190 - pageY - 33 - 15 + 125 - 20, -1);
addNodeAdopt(pageTextBox, page2)

pageTextBox = KrTextBox(game:getFontResource("occ24b"), 194, 173, 2, KrTextBox.RIGHT);
pageTextBox:SetTextMultiLineColored( getText("CREDITS.Kuzmitch") );
pageTextBox:SetPos(335 - 137, 190 - pageY - 33 - 15 + 125 + 40 - 20, -1);
addNodeAdopt(pageTextBox, page2)

pageTextBox = KrTextBox(game:getFontResource("occ24b"), 194, 133, 2, KrTextBox.LEFT);
pageTextBox:SetTextMultiLineColored( getText("CREDITS.SosninTitle") );
pageTextBox:SetPos(leftPageTextX + 29, 190 - pageY - 33 - 15 + 230 - 20, -1);
addNodeAdopt(pageTextBox, page2)

pageTextBox = KrTextBox(game:getFontResource("occ24b"), 194, 133, 2, KrTextBox.RIGHT);
pageTextBox:SetTextMultiLineColored( getText("CREDITS.Sosnin") );
pageTextBox:SetPos(335 - 137, 190 - pageY - 33 - 15 + 230 + 40 - 20, -1);
addNodeAdopt(pageTextBox, page2)

pageTextBox = KrTextBox(game:getFontResource("occ24b"), 394, 133, 2, KrTextBox.LEFT);
pageTextBox:SetTextMultiLineColored( getText("CREDITS.ProducersTitle") );
pageTextBox:SetPos(leftPageTextX + 29, 190 - pageY - 33 - 15 + 335 - 20, -1);
addNodeAdopt(pageTextBox, page2)

pageTextBox = KrTextBox(game:getFontResource("occ24b"), 194, 133, 2, KrTextBox.RIGHT);
pageTextBox:SetTextMultiLineColored( getText("CREDITS.Producers") );
pageTextBox:SetPos(335 - 137, 190 - pageY - 33 - 15 + 335 + 40 - 20, -1);
addNodeAdopt(pageTextBox, page2)


pageTextBox = KrTextBox(game:getFontResource("occ24b"), 194, 173, 2, KrTextBox.LEFT);
pageTextBox:SetTextMultiLineColored( getText("CREDITS.ThanksTitle") );
pageTextBox:SetPos(rightPageTextX + 29, 190 - pageY - 33 - 15, -1);
addNodeAdopt(pageTextBox, page2)

pageTextBox = KrTextBox(game:getFontResource("occ24b"), 294, 500, 2, KrTextBox.RIGHT);
pageTextBox:SetTextMultiLineColored( getText("CREDITS.Thanks") );
pageTextBox:SetPos(rightPageTextX + 25, 190 - pageY - 33 - 15 + 40, -1);
addNodeAdopt(pageTextBox, page2)

menu:addPage(page2);

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

	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 Credits Window end");


