!!!пока что не используется
#define  UTIL_USERS_H aaa
//----------------------------------------------------------------------------
//  @brief
//        обработка системы профилей
//        

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

#define MAX_USERS_CNT	11

#define ERROR_SFX	    1

#define UM_NONE			0
#define UM_LIST			1
#define UM_NEW			2
#define UM_DEL			3
#define UM_MAXUSER		4

//------------------------------------------------------------------------------------------
int gaUserSprites[MAX_USERS_CNT];
int giNewCurUser = -1;
string gsNewUserName;
int giUserMenuType = UM_NONE;
bool gbMainMenuAfter = false;

//------------------------------------------------------------------------------------------
GetUserSpriteNum(int spr)
{
	int i;
	for(i = 0; i < MAX_USERS_CNT; i++)
	{
		if(gaUserSprites[i] == spr)
			return i;
	}
	return -1;
}


//------------------------------------------------------------------------------------------
NewUserTact()
{
	if(giUserMenuType != UM_NEW)
		return;
	//
	static int siBlinkTime = 0;
	if(!siBlinkTime)
		siBlinkTime = GetTime();
	//
	int spr;
	spr = MenuFind(3, 59);
	if(spr)
	{
		string str;
		str = gsNewUserName;
		if( (GetTime()-siBlinkTime) % 1000 >= 500 )
			str = str + "\\";
		Action(spr, ACT_SET_TEXT, &str);
	}
	//
	int key;
	key = GetKey();
	if( key==VK_BACK && strlen(gsNewUserName) > 0 )
		gsNewUserName[strlen(gsNewUserName)-1] = 0;
	else
	if(key)
	{
		//*zm070206 - сказали убрать
		//if(key >= 'a' && key <= 'z')
		//	key = key + ('A'-'a');
		//
		if(strlen(gsNewUserName) >= 11)
			PlaySFX(ERROR_SFX);
		else
		if((key >= 'a' && key <= 'z') || (key >= 'A' && key <= 'Z') || (key >= '0' && key <= '9'))
			gsNewUserName += Printf("%c",key);
		else
		if( key && key < 255 )	//нажата неверная клавиша
			PlaySFX(ERROR_SFX);
	}
}


//------------------------------------------------------------------------------------------
HideUsersMenSprites(bool bHide)
{
	int newVid = 3;
	if(bHide)
		newVid = 9;
	//
	int i, spr;
	for(i = 0; i < MAX_USERS_CNT; i++)
	{
		spr = MenuFind(3, 9 + i);
		if(spr)
		{
			if(i == 0)
				Action(spr, ACT_CHANGE_VID, newVid);
			else
				Action(spr, ACT_SET_INVISIBLE, bHide);
		}
	}
	//
	int act = ANI_MENUSTAND;
	if(bHide)
		act = ANI_MENUDISABLE;
	//
	for(i = FirstSprite(); i; i = NextSprite())
	{
		if(GetUnitVid(i) == 704 && GetDirection(i) >= 0 && GetDirection(i) <= 3
			|| GetUnitVid(i) == 736)
		{
			Action(i, act);
		}
	}
}


//------------------------------------------------------------------------------------------
ShowUserNew(bool bMainMenuAfter)
{
	if(Call_v(EXT_GetUsersCnt) >= MAX_USERS_CNT)
	{
		giUserMenuType = UM_MAXUSER;
		//MenuRelease();
		HideUsersMenSprites(true);
		MenuLoad("maps\\user_maxerror.men");
		return;
	}
	//
	giUserMenuType = UM_NEW;
	gbMainMenuAfter = bMainMenuAfter;
	//MenuRelease();
	HideUsersMenSprites(true);
	if(bMainMenuAfter)
		MenuLoad("maps\\user_new_firstuser.men");
	else
		MenuLoad("maps\\user_new.men");
	gsNewUserName = "";
	NewUserTact();
}


//------------------------------------------------------------------------------------------
RefreshUserList()
{
	int i, spr, num, ii, j;
	string str;
	num = Call_v(EXT_GetUsersCnt);
	//
	if(MenuLClick() && MenuNVidUnderCursor()==736)
	{
		j = GetUserSpriteNum(MenuLClick());
		if(j >= 0 && j < num)
			giNewCurUser = j;
		else
		{
			ShowUserNew(false);
			return;
		}
	}
	//
	for(i = 0; i < num; i++)
	{
		str = Call_i(EXT_GetUsrNameG, i);
		spr = MenuFind(3, 9 + i);
		if(spr)
			Action(spr, ACT_SET_TEXT, &str);
		//
		spr = gaUserSprites[i];
		if(spr)
		{
			if(i == giNewCurUser)	//текущий пользователь
				Action(spr, ACT_CHANGE_DIRECTION, 150);
			else
				Action(spr, ACT_CHANGE_DIRECTION, 0);
		}
	}
}


//------------------------------------------------------------------------------------------
ShowUserDel()
{
	giUserMenuType = UM_DEL;
	//MenuRelease();
	HideUsersMenSprites(true);
	MenuLoad("maps\\user_delete.men");
}


//------------------------------------------------------------------------------------------
ShowUserList()
{
	int i, spr;
	string str;
	//
	giUserMenuType = UM_LIST;
	MenuRelease();
	MenuLoad("maps\\user_list.men");
	HideUsersMenSprites(false);
	for(i = 0; i < MAX_USERS_CNT; i++)
	{
		str = "";
		spr = MenuFind(3, 9 + i);
		if(spr)
			Action(spr, ACT_SET_TEXT, &str);
		gaUserSprites[i] = 0;
	}
	//
	for(spr = FirstSprite(); spr; spr = NextSprite())
	{
		if(GetUnitVid(spr)==736)
		{
			i = GetDirection(spr);
			if(i >= 0 && i < MAX_USERS_CNT)
				gaUserSprites[i] = spr;
		}
	}
	//
	giNewCurUser = Call_v(EXT_GetCurUserG);
	//
	RefreshUserList();
}


//------------------------------------------------------------------------------------------
HideUserList(bool bSave)
{
	giUserMenuType = UM_NONE;
	//MenuRelease("maps\\user_list.men");
	//
	if(bSave && giNewCurUser >= 0 && giNewCurUser < MAX_USERS_CNT)
	{
		Call_i(EXT_SetCurUserG, giNewCurUser);
		AssignAllValues();
	}
}


//------------------------------------------------------------------------------------------
AddNewUser()
{
	int ret;
	ret = Call_s(EXT_AddUser, gsNewUserName);
	if(ret)
	{
		if(!gbMainMenuAfter)
			ShowUserList();
		else
			HideUserList(false);
	}
	else
		PlaySFX(ERROR_SFX);
}


//------------------------------------------------------------------------------------------
UsersMenuTact()
{
	if(giUserMenuType == UM_NONE)
		ShowUserList();
	//
	int PressedDir;
	PressedDir = -1;
	if(MenuLClick() && MenuNVidUnderCursor()==704)
		PressedDir = GetDirection(MenuLClick());
	//
	if(giUserMenuType == UM_LIST)
	{
		RefreshUserList();
		//
		if(giUserMenuType == UM_LIST)
		{
			if((PressedDir == 1) || (GetKey()==VK_RETURN))	//кнопка Select
				HideUserList(true);
			if(PressedDir == 0)	//кнопка New
				ShowUserNew(false);
			if(PressedDir == 2)	//кнопка Delete
				ShowUserDel();
			if((PressedDir == 3) || (GetKey()==VK_ESCAPE))	//кнопка Cancel
				HideUserList(false);
		}
		PressedDir = -1;
	}
	//
	if(giUserMenuType == UM_MAXUSER)
	{
		if((PressedDir == 0) || (GetKey()==VK_ESCAPE) || (GetKey()==VK_RETURN))
			ShowUserList();
		PressedDir = -1;
	}
	//
	if(giUserMenuType == UM_NEW)
	{
		NewUserTact();
		if((PressedDir == 22) || (GetKey()==VK_RETURN))	//кнопка Ok
			AddNewUser();
		else
		if((PressedDir == 23) || (GetKey()==VK_ESCAPE))	//кнопка Cancel
		{
			if(Call_v(EXT_GetCurUserG) >= 0 || PressedDir == 23)	//по кнопке можно уйти
			{
				if(!gbMainMenuAfter)
					ShowUserList();
				else
					HideUserList(false);
			}
		}
		PressedDir = -1;
	}
	//
	if(giUserMenuType == UM_DEL)
	{
		if((PressedDir == 30))	//кнопка Yes
		{
			if(giNewCurUser >= 0 && giNewCurUser < MAX_USERS_CNT)
				Call_i(EXT_DeleteUserG, giNewCurUser);
			ShowUserList();
		}
		else
		if((PressedDir == 31) || (GetKey()==VK_ESCAPE))	//кнопка Cancel
			ShowUserList();
		PressedDir = -1;
	}
	//
	return (giUserMenuType == UM_NONE);
}

