--------------------------------------------------------------------------------
--  File     : Hut_1st_floor_Statuette
--  Author(s): Prokopovich Larisa
--
--  Summary  : Скрипт управления локацией.
--
--  Copyright © 2012 Floodlight Games.  All rights reserved.
--------------------------------------------------------------------------------
LOC_1FLOOR				= "Hut_1st_floor"

M_STATUE				= "M_STATUE"		--место для руки

I_STATUETTE_HAND		= "STATUETTE_HAND"	--рука статуи
I_CHEST_KEY				= "CHEST_KEY"		--ключ от сундука
I_BOX					= "BOX"				--ящик 
I_BOX_COVER				= "BOX_COVER"		--крышка ящика
I_BOX_SHADOW			= "BOX_SHADOW"		--тень ящика

V_HAND					= "SOLDIER_HAND"	--анимация поднимания руки
--------------------------------------------------------------------------------
box_pos = ctypes:Vector2(347/810, 773/1080)
boxCover_pos = ctypes:Vector2(425/810, 851/1080)
key_pos = ctypes:Vector2(396/810, 812/1080)
--------------------------------------------------------------------------------
function OnSerialize(system)
	statuette_time = system:Serialize(statuette_time)
end
--------------------------------------------------------------------------------
function OnFirstEntry()
	cstore:SetKey("Close_up_Statuette", 0)
	room:GetItem(V_HAND):Disable()
	statuette_time = room:GetVideoTime(room:GetItem(V_HAND))
	
	stars:Show(M_STATUE, "4")
	stars:Show(V_HAND, "4")
	stars:Show(I_CHEST_KEY, "4")
end
--------------------------------------------------------------------------------
function OnMouseClickOnBack()
	chapter:ExitCloseup()
	return true
end
--------------------------------------------------------------------------------
function OnMouseClickOnItem(item)
	local itemName = item:GetName()
	
	if itemName == "M_STATUE" then						--статуэтка
		comment:Add("CMT_Statue_Player")
		return true
	
	elseif (itemName == V_HAND) and						--рука статуэтки
		   not(item:IsEnabled()) then
		item:Enable()
		stars:Hide(V_HAND)
		item:SetAnimPause(false)
		room:AddCtrlAnimation(V_HAND, -1)
		room.sfx:Play ("turn_arm")	--звук "поворачиваем руку, выдвигается полка"
		
		--переместить ящик
		local sceneSize = room:GetNoZoomSize()
		local box_pos1 = ctypes:Vector2(math.floor(box_pos.x * sceneSize.x), math.floor(box_pos.y * sceneSize.y))
		room:GetItem(I_BOX).effects:PlayMove(box_pos1, statuette_time)
		local boxCover_pos1 = ctypes:Vector2(math.floor(boxCover_pos.x * sceneSize.x), math.floor(boxCover_pos.y * sceneSize.y))
		room:GetItem(I_BOX_COVER).effects:PlayMove(boxCover_pos1, statuette_time)
		local key_pos1 = ctypes:Vector2(math.floor(key_pos.x * sceneSize.x), math.floor(key_pos.y * sceneSize.y))
		local key = room:GetItem(I_CHEST_KEY)
		key:Show()
		key.effects:PlayMove(key_pos1, statuette_time)
		
		--проявить тень
		local shadow = room:GetItem(I_BOX_SHADOW)
		shadow:Show()
		local color = shadow:GetColor()
		local color1 = shadow:GetColor()
		color1:SetNormalAlpha(0)
		shadow:SetColor(color1)
		shadow.effects:PlayColor(color, statuette_time)
		
		cstore:SetKey("Close_up_Statuette", 2)
		return true
	
	elseif itemName == I_CHEST_KEY then					--ключ от сундука
		cstore:SetKey("Close_up_Statuette", 3)
		pick_panel:AddItems(itemName, true)
		room:MarkCompleted()
		return true
	end
end
--------------------------------------------------------------------------------
function OnClickItemOnItem(item)
	local itemName = item:GetName()
					
	if cursor:IsItemNameEqual(I_STATUETTE_HAND) then	--руку на место для руки   
		if itemName == M_STATUE then
			cursor:RemoveItem()
			item:Hide()
			local hand_video = room:GetItem(V_HAND)
			hand_video:Show()
			hand_video:PlayAnimation()
			hand_video:SetAnimPause(true)
			room.sfx:Play ("insert_arm")	--звук "вставляем руку в статую"
			cstore:SetKey("Close_up_Statuette", 1)
			return true
		end
	end
end
--------------------------------------------------------------------------------
-- Окончание анимации поднятия руки
function OnAnimationComplete_SOLDIER_HAND(forced)
	if forced == true then
		room:VideoSeekToEnd(room:GetItem("SOLDIER_HAND"))
		
		sceneSize = room:GetNoZoomSize()
		local box_pos1 = ctypes:Vector2(math.floor(box_pos.x * sceneSize.x), math.floor(box_pos.y * sceneSize.y))
		room:GetItem(I_BOX):SetPosition(box_pos1)
		local boxCover_pos1 = ctypes:Vector2(math.floor(boxCover_pos.x * sceneSize.x), math.floor(boxCover_pos.y * sceneSize.y))
		room:GetItem(I_BOX_COVER):SetPosition(boxCover_pos1)
		
		local key = room:GetItem(I_CHEST_KEY)
		local key_pos1 = ctypes:Vector2(math.floor(key_pos.x * sceneSize.x), math.floor(key_pos.y * sceneSize.y))
		key:Show()
		key:SetPosition(key_pos1)
		
		room:GetItem(I_BOX_SHADOW):Show()
	end
end
