static int SoundVolume; // 0-14
static int MusicVolume; // 0-14


//установка нового значения громкости звука 0-15
SetNewSoundVolume(int volume)
{
  if( volume < 0 )
    volume = 0;
  if( volume > 15 )
    volume = 15;
  SoundVolume = volume;
  SetReg(GetDefaultRegPath(),"SoundVolume",volume*100/15);
  SetSoundVolume( volume*100/15 );
  MenuAction(714,999999,ACT_CHANGE_DIRECTION,(volume*247)/15);
}
//установка нового значения громкости музыки 0-15
SetNewMusicVolume(int volume)
{
  if( volume < 0 )
    volume = 0;
  if( volume > 15 )
    volume = 15;
  MusicVolume = volume;
  SetReg(GetDefaultRegPath(),"MusicVolume",volume*100/15);
  SetMusicVolume( volume*100/15 );
  MenuAction(715,999999,ACT_CHANGE_DIRECTION,(volume*247)/15);
}
//установка нового значения уровня детализации графики
SetNewGraphDetail(int detail)
{
  static int text = 0;
  if( !text )
  {
    int menu;
    menu = MenuFind(717,0);
    text = CreateText(3,ToScreenX(GetX(menu)),ToScreenY(GetY(menu))+1,GetZ(menu)+1,"High");
    Action(text,ACT_SET_BEHAVE,BEH_CENTER);
  }
  if( detail < 0 )
    detail = 0;
  if( detail > 2 )
    detail = 2;
  SetReg(GetDefaultRegPath(),"GraphDetail",detail);
  string str;
  if( detail==0 )
    str = GetString("menu","Low");
  else if( detail==1 )
    str = GetString("menu","Medium");
  else if( detail==2 )
    str = GetString("menu","High");
  Action(text,ACT_SET_TEXT,&str);
}
SetGraphLevel()
{
  int i;
  // Настройка уровня детализации
  static int LowLevelVid[] = { 123,120,133,144,158,159,167,170,171,174,176,191,195,199,
    766,768,770,778,780,781,783,787 };
  static int MediumLevelVid[] = { 106,108,119,121,138,140,177,178,185,187,189,755,756,757,758,787 };
//?102 гильза
//?127гильза
  if( GetReg(GetDefaultRegPath(),"GraphDetail","2")==0 )
  {
    for( i = 0; i < sizeof(LowLevelVid)/sizeof(int); i++ )
      SetVidData(LowLevelVid[i],VID_NOT_CREATE_AS_CHILD,1);
    SetVidData(910,VID_NO_CHILD+15,2);
    SetVidData(771,VID_NO_CHILD+14,2);
    SetVidData(772,VID_NO_CHILD+14,2);
    SetVidData(773,VID_NO_CHILD+14,2);
    SetVidData(774,VID_NO_CHILD+14,2);
    SetVidData(775,VID_NO_CHILD+14,2);
    SetVidData(776,VID_NO_CHILD+14,2);
  }
  else
  {
    for( i = 0; i < sizeof(LowLevelVid)/sizeof(int); i++ )
      SetVidData(LowLevelVid[i],VID_NOT_CREATE_AS_CHILD,0);
    SetVidData(910,VID_NO_CHILD+15,8);
    SetVidData(771,VID_NO_CHILD+14,14);
    SetVidData(772,VID_NO_CHILD+14,14);
    SetVidData(773,VID_NO_CHILD+14,14);
    SetVidData(774,VID_NO_CHILD+14,16);
    SetVidData(775,VID_NO_CHILD+14,14);
    SetVidData(776,VID_NO_CHILD+14,14);
  }
  if( GetReg(GetDefaultRegPath(),"GraphDetail","2")<=1 )
  {
    for( i = 0; i < sizeof(MediumLevelVid)/sizeof(int); i++ )
      SetVidData(MediumLevelVid[i],VID_NOT_CREATE_AS_CHILD,1);
    SetVidData(143,VID_NO_CHILD+14,5);
    SetVidData(901,VID_NO_CHILD+14,5);
  }
  else
  {
    for( i = 0; i < sizeof(MediumLevelVid)/sizeof(int); i++ )
      SetVidData(MediumLevelVid[i],VID_NOT_CREATE_AS_CHILD,0);
    SetVidData(143,VID_NO_CHILD+14,20);
    SetVidData(901,VID_NO_CHILD+14,10);
  }
}

CreateOptionsMenu(string file)
{
  int menu;
  MenuRelease();
  MenuLoad(file);
  SoundVolume = GetReg(GetDefaultRegPath(),"SoundVolume","100")*15/100;
  MusicVolume = GetReg(GetDefaultRegPath(),"MusicVolume","100")*15/100;
  SetNewSoundVolume( SoundVolume );
  SetNewMusicVolume( MusicVolume );
  SetNewGraphDetail( GetReg(GetDefaultRegPath(),"GraphDetail","2") );
}

TactOptionsMenu()
{
  if( MenuLClick() )
    if( MenuNVidUnderCursor()==716 ) // кнопки >, <
    {
      if( MenuNDirUnderCursor()==0 )
        SetNewSoundVolume( SoundVolume - 1 );
      else if( MenuNDirUnderCursor()==1 )
        SetNewSoundVolume( SoundVolume + 1 );
      else if( MenuNDirUnderCursor()==2 )
        SetNewMusicVolume( MusicVolume - 1 );
      else if( MenuNDirUnderCursor()==3 )
        SetNewMusicVolume( MusicVolume + 1 );
      else if( MenuNDirUnderCursor()==4 )
        SetNewGraphDetail( GetReg(GetDefaultRegPath(),"GraphDetail","2") - 1 );
      else if( MenuNDirUnderCursor()==5 )
        SetNewGraphDetail( GetReg(GetDefaultRegPath(),"GraphDetail","2") + 1 );
    }
    else if( MenuNVidUnderCursor()==717 )
      if( GetReg(GetDefaultRegPath(),"GraphDetail","2")==2 )
        SetNewGraphDetail( 0 );
      else
        SetNewGraphDetail( GetReg(GetDefaultRegPath(),"GraphDetail","2") + 1 );
}
