print("init Settings Window begin");

local windowLeft = 1024 / 2 - 284 / 2;
local windowTop = 768 / 2 - 348 / 2;

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

local font = game:getFontResource("occ24bg")

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


-- 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:setImageFrame(sprite)


local windowBack = KrSprite(vault:GetSpriteResource("Pergament_player_list"))
windowBack:SetPos( windowLeft, windowTop, -1 )
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_new_player"))
standB:SetPos(startBorderX, startBorderY, -1);
addNodeAdopt(standB, windowBack)

startBorderX = startBorderX + 36;

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


startBorderX = startBorderX + 128;

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

startBorderX = startBorderX + 36;

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


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

for i = 0, 3 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 - 72;

standB = KrSprite(vault:GetSpriteResource("mbox_d_new_player"))
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, 3 do

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

	startBorderY = startBorderY - 64;

end

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


menu:setBgSprite(windowBack)

local ctrlY = windowTop;

local title = KrTextBox(game:getFontResource("occ24b"), 284, 50, 2, KrTextBox.CENTER);
ctrlY = ctrlY + 50
title:SetPos(windowLeft + 284 / 2, ctrlY, -1);
setTextColor(title, 255, 249, 177, 255);

aniFadeInFadeOut(title, fadeInBtnsDelay, fadeInBtns, fadeOutBtns)

title:SetText(getText("SETTINGS_WINDOW.LBL_TITLE"), 0)
menu:setTextBox(title)

vers = KrTextBox(game:getFontResource("occ24"), 100, 50, 2, KrTextBox.LEFT);
setNodeScale(vers, 0.7, 0.7)
vers:SetPos(windowLeft + 250 - 127, windowTop + 326 - 76, -1);
setTextColor(vers, 255, 249, 177, 255);

aniFadeInFadeOut(vers, fadeInBtnsDelay, fadeInBtns, fadeOutBtns)

menu:setVersionLabel(vers)



-- create volume label

local textBox = KrTextBox(game:getFontResource("occ24b"), 284, 50, 2, KrTextBox.CENTER);
ctrlY = ctrlY + 22 + 24
textBox:SetPos(windowLeft, ctrlY, -1);
setTextColor(textBox, 255, 246, 11, 255);
textBox:SetText(getText("SETTINGS_WINDOW.LBL_VOLUME"), 0)
aniFadeInFadeOut(textBox, fadeInBtnsDelay, fadeInBtns, fadeOutBtns)
menu:setVolumeSliderLabel(textBox);

-- local slider = Slider()
-- slider:getRoot():SetPos(400, 260, -1)
-- menu:setVolumeSlider(slider)


local slider = Slider()
slider:setWidth(220)
slider:setHeight(28)

	local leftBtn = XButton();
	initXBtn(leftBtn, "Slider_left", 0, 0, 0, 0, 11, 28, vault)
	slider:setLeftButton(leftBtn)
	
	local rightBtn = XButton();
	initXBtn(rightBtn, "Slider_right", 0, 0, 0, 0, 11, 28, vault)
	slider:setRightButton(rightBtn)

local backRoot = KrImNode()
local back;
local bgX = 0;
for i = 0, 4 do
	back  = KrSprite(vault:GetSpriteResource("Slider_bg"))
	back:SetPos(bgX, 0, -1);
	addNodeAdopt(back, backRoot)
	bgX = bgX + 36;
end
backRoot:SetPos(16, 6, -1);
slider:setBackground(backRoot)
	
--	local trav = BarTraveller(vault:GetSpriteResource("traveler"), 28)
--	trav:setSlideStep(8)
	local trav = SliderButton()
	initXBtn(trav, "traveler", 0, 0, 0, 0, 23, 28, vault)
	slider:setSliderTraveller(trav)
	slider:setStep(.05)
	slider:init()

	
ctrlY = ctrlY + 35
slider:getRoot():SetPos(408, ctrlY, -1)
	
aniFadeInFadeOut(slider:getRoot(), fadeInBtnsDelay, fadeInBtns, fadeOutBtns)
menu:setVolumeSlider(slider)


-- create "Done" 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;
		
	initXBtn(button, "Brn_XX", 510, 560 - 50, sensX, sensY, width, height, vault)
	initXButtonText(button, getText(getText("MESSAGE_WINDOW.BTN_DONE")),
						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:setDoneButton(button)


-- create "Show hints" button and label

local textBox = KrTextBox(game:getFontResource("occ24b"), 110, 50, 2, KrTextBox.CENTER);
setTextColor(textBox, 255, 246, 11, 255);
ctrlY = ctrlY + 28 + 15 + 10
textBox:SetPos(-434, ctrlY, -1);
textBox:SetText(getText("SETTINGS_WINDOW.LBL_SHOW_HINTS"), 0)
aniFadeInFadeOut(textBox, fadeInBtnsDelay, fadeInBtns, fadeOutBtns)
menu:setShowHintsLabel(textBox);

--

	local button = XButton();
	initXBtn(button, "Checkbox", -551, ctrlY + 3, sensX, sensY, width, height, vault)
	aniFadeInFadeOut(button:getRoot(), fadeInBtnsDelay, fadeInBtns, fadeOutBtns)
	menu:setShowHintsButton(button)

-- create "Fullscreen mode" button and label

local textBox = KrTextBox(game:getFontResource("occ24b"), 110, 50, 2, KrTextBox.CENTER);
setTextColor(textBox, 255, 246, 11, 255);
ctrlY = ctrlY + 28 + 15 + 10 - 24 - 24
textBox:SetPos(434, ctrlY, -1);
textBox:SetText(getText("SETTINGS_WINDOW.LBL_FULLSCREEN"), 0)
aniFadeInFadeOut(textBox, fadeInBtnsDelay, fadeInBtns, fadeOutBtns)
menu:setFullScreenModeLabel(textBox);

--

	local button = XButton();
	initXBtn(button, "Checkbox", 551, ctrlY + 3, sensX, sensY, width, height, vault)
	aniFadeInFadeOut(button:getRoot(), fadeInBtnsDelay, fadeInBtns, fadeOutBtns)
	menu:setFullScreenModeButton(button)


print("init Settings Window end");


