enter_password_on_mouse_scene14 = {}

enter_password_on_mouse_scene14.params = 
{
	password = {6,8,3},	
	sounds_on_click = "mini_game_enter_password_on_mouse_scene14_button_01",
	sound_error = "mini_game_enter_password_on_mouse_scene14_error_01"
}

function enter_password_on_mouse_scene14.Reset(_owner)
	enter_password_on_mouse_scene14.current_sequence = {}	
	local w = _owner.GetWidgets()
	while not w.IsEnd() do
		local button = __cast(w.Get(), sf.gui.CButtonWidget)
		if button then
			button.DisableButton(false)
		end
		w.Next()
	end 
	_owner.OnMouseMove(sf.misc.IntVector(-1000,-1000), 0, true)
end

function enter_password_on_mouse_scene14.OnMouseMove(_owner, _pos, _state, _broadcast)
	return true
end

function enter_password_on_mouse_scene14.OnChildAction(_owner, _action, _child)

	if	_action.c_str() == "pressed" then		
		local number = tonumber(_child.GetId().c_str())
		if number then
			if enter_password_on_mouse_scene14.params.sounds_on_click then
				sf.core.g_Application.GetAudioManager().Play(enter_password_on_mouse_scene14.params.sounds_on_click, -2, -2, -2, -2, -2)
			end

			table.insert(enter_password_on_mouse_scene14.current_sequence, number)
			
			local current_length = #enter_password_on_mouse_scene14.current_sequence
			local target_length = #enter_password_on_mouse_scene14.params.password
			
			assert(current_length <= target_length)
			
			if current_length == target_length then
				-- нажали необходимое количество кнопок
				local correctly = true
				for i=1, target_length do
					local n1 = enter_password_on_mouse_scene14.current_sequence[i]
					local n2 = enter_password_on_mouse_scene14.params.password[i]
					if n1 ~= n2 then
						correctly = false
						break
					end
				end
				if not correctly then
					-- если неправильно нажали кнопки, то все сбрасываем
					enter_password_on_mouse_scene14.Reset(_owner)
					if enter_password_on_mouse_scene14.params.sound_error then
						sf.core.g_Application.GetAudioManager().Play(enter_password_on_mouse_scene14.params.sound_error, -2, -2, -2, -2, -2)
					end
				else
					-- заканчиваем игру
					_owner.SetGameResult(1)
					_owner.OnEndGame()
				end
			else
				-- делаем только что нажатую кнопку недоступной
				local button = __cast(_child, sf.gui.CButtonWidget)
				assert(button)
				button.DisableButton(true)
				_owner.OnMouseMove(sf.misc.IntVector(-1000,-1000), 0, true) 
			end
		end
	end
end

function enter_password_on_mouse_scene14.OnPreferredSize(_owner)
	return sminigames.OnPreferredSize(_owner)
end 

function enter_password_on_mouse_scene14.Init(_owner)
	sminigames.SetStandartScriptName(_owner, enter_password_on_mouse_scene14)
	enter_password_on_mouse_scene14.Reset(_owner)
end
