print("init Message Window begin");


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


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


windowLeft = 1024 / 2 - 344 / 2;
windowTop = 768 / 2 - 220 / 2 - 60;


-- menu:getRoot():SetPos(windowLeft, windowTop, -1)


--[[
local sprite = KrSprite(vault:GetSpriteResource("hatch"))
sprite:SetColor(KrColorTransform(KrRGBA(0, 0, 0, 96)), -1);
-- aniFadeInFadeOut(sprite,0,.3,.2,96)
-- sprite:SetPos(-windowLeft, -windowTop, -1)
menu:setBackground(sprite)
menu:setBackgroundSize(game:screenWidth(), game:screenHeight())
]]--


local windowBack = KrSprite(vault:GetSpriteResource("Pergament_XL"))
-- aniPoolMesageWindow(windowBack);
aniFadeInFadeOut(windowBack,0,.3,.2,255)
--aniPoolMesageWindow(windowBack, nil,nil,nil,6,4,900,900);

windowBack:SetPos(windowLeft, windowTop, -1)
menu:setImageFrame(windowBack)
--menu:setBackground(windowBack)

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;

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

startBorderY = startBorderY + 64;

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

startBorderY = startBorderY + 64;

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;

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

startBorderY = startBorderY - 64;

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

-----------------------------------------------
print("Create left button");


	local button = XButton();

	local width = 97
	local height = 40
	local sensX = -48
	local sensY = -21
	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 button = XButton();

	initXBtn(button, "Brn_XX", windowLeft + (88 + 254) / 2, windowTop + 170, sensX, sensY, width, height, vault)
	initXButtonText(button, "OK",
						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(),  0, 0.3, 0.2)

	button:setAccelerator(XButton.ENTER);
	menu:setButton(button);


-- create and init textBox

local width = 250;
local height= 150;

local textBox = KrTextBox(game:getFontResource("occ24"), width, height, 2, KrTextBox.CENTER);
aniFadeInFadeOut(textBox,  0, 0.3, 0.2)
textBox:SetPos(windowLeft + 40 + width/2, windowTop + 35 + height/2, -1);

textBox:SetText("Заголовок", 0)
menu:setTextBox(textBox)

-- end crate text box
print("init Message Window end");



