#define  UTIL_HELPMENS_H aaa
//----------------------------------------------------------------------------
//  @brief
//        обработка help-менюшек
//        

//  @ingroup
    
//  2006Dec20 created. Zmanovsky Peter.
//  (C) 2006    Sigma-Team
//-----------------------------------------------------------------------------

static bool gbHelpMenuShown = false;
static int  giHelpMenuLev = -1;
static int arr[50];
static int arrSize = 0;

//------------------------------------------------------------------------------------------
HideHelpMenu()
{
	HideObjectsForMenu(0);
	int i;
	if(gbHelpMenuShown)
	{
		MenuRelease("maps/tip.men");
		for(i = 0; i < arrSize; i++)
			Destroy(arr[i]);
		arrSize = 0;
		Genocide(727);
	}
	gbHelpMenuShown = false;
	Pause2(0);
	SetCursor(CURSOR_OFF);
}


//------------------------------------------------------------------------------------------
ShowHelpMenu(int iLevNum)
{
	//Log("ShowHelpMenu " + itoa(iLevNum));
	if(gbHelpMenuShown)
	{
		HideHelpMenu();
	}
	//
	int size = Call_i(EXT_GetItemsCnt, iLevNum);
	if(!size)
		return;
	//
	HideObjectsForMenu(1);
	//
	gbHelpMenuShown = true;
	giHelpMenuLev = iLevNum;
	//
	int i, spr, curX, curY, vid, dir;
	string str;
	MenuLoad("maps/tip.men");
	Pause2(1);
	SetCursor(CURSOR_NORMAL);
	//
	/*if(size > 0 && (spr = MenuFind(4, 109)))
	{
		str = Call_ii(EXT_GetText, iLevNum, 0);
		Action(spr, ACT_SET_TEXT, &str);
	}*/
	if(size > 0 && (spr = MenuFind(3, 110)))
	{
		str = Call_ii(EXT_GetText, iLevNum, 0);
		Action(spr, ACT_SET_TEXT, &str);
	}
	//
	//spr = MenuFind(3, 111);
	spr = MenuFind(724);
	curX = GetX(spr);
	curY = GetY(spr)-GetZ(spr);
	if(spr)
	{
	#ifndef GAMEPLAY_FLY
		dir = (iLevNum / 100) * 5 + (iLevNum%100)+1;
		int dir2 = Call_ii(EXT_GetAbsDir, 724, dir);
		Action(spr, ACT_CHANGE_DIRECTION, dir2);
	#else
		int prev = spr;
		spr = CreateSprite(727, ToScreenX(curX), ToScreenY(curY) + GetZ(spr), GetZ(spr));
		Destroy(prev);
	#endif
		//
		//Log3("aaa = " + itoa(dir2) + " - " + itoa(dir) );
		//Action(spr, ACT_CHANGE_COOR, GetX(spr), GetY(spr)-GetZ(spr)+3000, 3000);
	}
	//Destroy(spr);
	//
	if(0)
	for(i = 2; i < size; i++)
	{
		int type = Call_ii(EXT_GetItemType, iLevNum, i);
		int hght = Call_ii(EXT_GetItemSize, iLevNum, i);
		//Log3("hght = " + itoa(hght));
		//
		if(type == 1)	//текст
		{
			str = Call_ii(EXT_GetText, iLevNum, i);
			spr = CreateSprite(3, ToScreenX(curX), ToScreenY(curY+(hght+1)/2+60), 60);
			Action(spr, ACT_SET_TEXT, &str);
			Action(spr,ACT_SET_BEHAVE,BEH_CENTER_X|BEH_CENTER_Y);
			//
			vid = Call_ii(EXT_GetVidNum, iLevNum, i);
			if(vid == 4)
				curY += HELPMENU_FONT4_VID_SIZE;
			else
				curY += hght;
			arr[arrSize] = spr;
			arrSize++;
		}
		else
		if(type == 2)	//картинка
		{
			vid = Call_ii(EXT_GetVidNum, iLevNum, i);
			dir = Call_ii(EXT_GetDirNum, iLevNum, i);
			dir = Call_ii(EXT_GetAbsDir, vid, dir);
			spr = CreateSprite(vid, ToScreenX(curX), ToScreenY(curY+(hght+1)/2+60), 60, dir);
			//curY += hght;		//*zm070111 - изменено по просьбе Михаила
			arr[arrSize] = spr;
			arrSize++;
		}
	}
}


//------------------------------------------------------------------------------------------
HelpMenuTact()
{
//	if(GetKey() && GetKey() != 'r' || (MenuLClick() && MenuNVidUnderCursor()==704 && GetDirection(MenuLClick()) == 17)
//		|| ( GetInputState() & INPUT_RCLICK ) || ( GetInputState() & INPUT_LCLICK ) )
	if(MenuLClick() && MenuNVidUnderCursor()==704 && GetDirection(MenuLClick()) == 17
		|| GetKey() == VK_ESCAPE || GetKey() == VK_RETURN || GetKey() == VK_SPACE)
	{
		HideHelpMenu();
		return 1;
	}
	//
	return 0;
}


//------------------------------------------------------------------------------------------
ReloadHelpMenu()
{
	if(gbHelpMenuShown)
		ShowHelpMenu(giHelpMenuLev);
}


//------------------------------------------------------------------------------------------
ShowCurHelp()
{
	#ifndef GAMEPLAY_FLY
		ShowHelpMenu(100*(LevelNumber-1)+giSubLevelNum);
	#else
		ShowHelpMenu(8);
	#endif
}

