#define MAX_VOLUME_COUNT 10
int MouseSensitivity;// 0-100

static int SoundVolume; // 0-MAX_VOLUME_COUNT
static int MusicVolume; // 0-MAX_VOLUME_COUNT
static int MouseVolume;// 0-MAX_VOLUME_COUNT

#ifndef COMMON_DEFS_H
    #include "maps\common_defs.lgc"
#endif

//установка нового значения громкости звука 0-MAX_VOLUME_COUNT
SetNewSoundVolume(int volume)
{
  if( volume < 0 )
    volume = 0;
  if( volume > MAX_VOLUME_COUNT )
    volume = MAX_VOLUME_COUNT;
  SoundVolume = volume;
  SetValI("SoundVolume",volume*100/MAX_VOLUME_COUNT);
  SetSoundVolume( volume*100/MAX_VOLUME_COUNT );
  MenuAction(714,999999,ACT_CHANGE_DIRECTION,(volume*237)/MAX_VOLUME_COUNT);
}
//установка нового значения громкости музыки 0-MAX_VOLUME_COUNT
SetNewMusicVolume(int volume)
{
  if( volume < 0 )
    volume = 0;
  if( volume > MAX_VOLUME_COUNT )
    volume = MAX_VOLUME_COUNT;
  MusicVolume = volume;
  SetValI("MusicVolume",volume*100/MAX_VOLUME_COUNT);
  SetMusicVolume( volume*100/MAX_VOLUME_COUNT );
  MenuAction(715,999999,ACT_CHANGE_DIRECTION,(volume*237)/MAX_VOLUME_COUNT);
}
//установка нового значения чувствительности мышки 0-MAX_VOLUME_COUNT
SetNewMouseSensitivity(int volume)
{
  if( volume < 0 )
    volume = 0;
  if( volume > MAX_VOLUME_COUNT )
    volume = MAX_VOLUME_COUNT;
  MouseVolume = volume;
  MouseSensitivity = volume*100/MAX_VOLUME_COUNT;
  SetValI("MouseSensitivity",MouseSensitivity);
  MenuAction(719,999999,ACT_CHANGE_DIRECTION,(volume*237)/MAX_VOLUME_COUNT);
}
//установка нового значения уровня детализации графики
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);
  }*/
}

static int pCLicked = 0;
#define BT_SOUND    0
#define BT_MUSIC    1
#define BT_DELAY    2
#define BT_DIFF     3
#define BT_MOUSE    4

//------------------------------------------------------------------------------------------
ControlSndScroll( int pBtn, int iBarType )
{
    if( pCLicked && pCLicked != pBtn )
        return;
    //
    int len; len = GetVidData(GetUnitVid(pBtn), VID_SIZE_X);
    int height; height = GetVidData(GetUnitVid(pBtn), VID_SIZE_Y);
    //
//Log(itoa(GetInputX()) + " "+itoa(GetX(pBtn)));
    int x; x = GetInputX() - GetX(pBtn) + len / 2;
    int y; y = GetY(pBtn) - GetZ(pBtn);
    //
    if( x < 0 )
    {
        if( x < -30 || pCLicked != pBtn )
            return;
        x = 0;
    }
    if( x > len )
    {
        if( x > len + 30 || pCLicked != pBtn )
            return;
        x = len;
    }
    if( GetInputY() < y - height/2 )
    {
        if( GetInputY() < y - height/2 - 30 || pCLicked != pBtn )
            return;
    }
    if( GetInputY() > y + height/2 )
    {
        if( GetInputY() > y + height/2 + 30 || pCLicked != pBtn )
            return;
    }
    pCLicked = pBtn;
    //
    int val; val = x * MAX_VOLUME_COUNT / len;
/*    if( iBarType == BT_DELAY )
        val = x * (TEXT_DELAY_MAX-TEXT_DELAY_MIN) / len + TEXT_DELAY_MIN;
    else*/
    if( iBarType == BT_DIFF )
        val = (x * (3/*GT_COUNT*/-1) + len/2) / len;
    //
    if( iBarType == BT_MUSIC )
        SetNewMusicVolume(val);
    else
    if( iBarType == BT_SOUND )
        SetNewSoundVolume(val);
    else
    if( iBarType == BT_MOUSE )
        SetNewMouseSensitivity(val);
}

//------------------------------------------------------------------------------------------
//новая функция понадобилась из-за смены пользователей
AssignAllValues()
{
  SoundVolume = GetValI("SoundVolume","100")*MAX_VOLUME_COUNT/100;
  MusicVolume = GetValI("MusicVolume","70")*MAX_VOLUME_COUNT/100;
  MouseVolume = GetValI("MouseSensitivity","50")*MAX_VOLUME_COUNT/100;
  SetNewSoundVolume( SoundVolume );
  SetNewMusicVolume( MusicVolume );
  SetNewMouseSensitivity( MouseVolume );
//  SetNewGraphDetail( GetReg(GetDefaultRegPath(),"GraphDetail","2") );
}


//------------------------------------------------------------------------------------------
CreateOptionsMenu(string file)
{
  int menu;
//  MenuRelease();
  MenuLoad(file);
  AssignAllValues();
}

TactOptionsMenu()
{
    if( GetInputState()&INPUT_LDOWN )
    {
        ControlSndScroll( MenuFind(714), BT_SOUND );
        ControlSndScroll( MenuFind(715), BT_MUSIC );
        ControlSndScroll( MenuFind(719), BT_MOUSE );
    }
    else
        pCLicked = 0;

  if ( MenuLClick() )
      if ( MenuNVidUnderCursor()==716 ) // кнопки <
      {
          if ( GetDirection(MenuLClick()) == 0 )
            SetNewSoundVolume( SoundVolume - 1 );
          else if ( GetDirection(MenuLClick()) == 32 )
            SetNewMusicVolume( MusicVolume - 1 );
          else if ( GetDirection(MenuLClick()) == 64 )
            SetNewMouseSensitivity( MouseVolume - 1 );
      }
      else if ( MenuNVidUnderCursor()==718 ) // кнопки >
      {
          if ( GetDirection(MenuLClick()) == 0 )
            SetNewSoundVolume( SoundVolume + 1 );
          else if ( GetDirection(MenuLClick()) == 32 )
            SetNewMusicVolume( MusicVolume + 1 );
          else if ( GetDirection(MenuLClick()) == 64 )
            SetNewMouseSensitivity( MouseVolume + 1 );
      }
}
