local sfx,muz = GetSoundValue()
local x0 = 430;
local x1 = 675;

local slider =
{
  w = 23;
  h = 53;
  x0 = x0;
  x1 = x1;
  sfx = {x = sfx/100*(x1 - x0) + x0; y = 279-26; id = -129};  -- слайдер звуков
  muz = {x = muz/100*(x1 - x0) + x0; y = 213-26; id = -130};  -- слайдер музыки
}

local aktiv = -131          -- кнопка "фуллскрин" выделена
local vkl = -132          -- кнопка "фуллскрин" нажата
local options = -133        -- фон
local prinyatnazhim = -134      -- кнопка "принять" нажата
local prinyatvkl = -135        -- кнопка "принять" выделена
local optvyhodnazhim = -136      -- кнопка "выход" нажата
local optvyhodvkl = -137      -- кнопка "выход" выделена
local fullgalka = -138        -- галка на фуллскрине

------------------------------------------------------------
--  function: showOptions
------------------------------------------------------------
-- function ESCPressed(nCount)
  -- if STATE == 0 then
     -- closeOptions()
  -- end;
-- end;
function showOptions()
optionsrun=true
  sfx,muz = GetSoundValue()
  Write("sfx="..sfx.."; muz="..muz.."\n")
  slider.sfx.x = sfx/100*(slider.x1 - slider.x0) + slider.x0
  slider.muz.x = muz/100*(slider.x1 - slider.x0) + slider.x0

  addstaticobjecttogame(options    ,"menu_texture1",274+6,136-26    ,"",0  ,58 ,497,365)
  addstaticobjecttogame(optvyhodvkl  ,"menu_texture1",399+6,421-26    ,"",485,0  ,120,53 )
  addstaticobjecttogame(optvyhodnazhim,"menu_texture1",399+6,423-26    ,"",365,0  ,120,51 )
  addstaticobjecttogame(prinyatvkl  ,"menu_texture1",555+6,423-26    ,"",289,0  ,76 ,51 )
  addstaticobjecttogame(prinyatnazhim  ,"menu_texture1",555+6,423-26    ,"",212,0  ,77 ,51 )
  addstaticobjecttogame(slider.muz.id  ,"menu_texture1",slider.muz.x,213-26,"",189,0  ,23 ,53 )
  addstaticobjecttogame(slider.sfx.id  ,"menu_texture1",slider.sfx.x,279-26,"",189,0  ,23 ,53 )
  addstaticobjecttogame(aktiv      ,"menu_texture1",610+6,359-26     ,"",95 ,0  ,66 ,45 )
  addstaticobjecttogame(vkl      ,"menu_texture1",610+6,359-26    ,"",28 ,0  ,67 ,46 )
  addstaticobjecttogame(fullgalka    ,"menu_texture1",630+6,364-26    ,"",161,0  ,28 ,29 )
    
  speciale_action(4,options)
  speciale_action(4,optvyhodvkl)
  speciale_action(4,optvyhodnazhim)
  speciale_action(4,prinyatvkl)
  speciale_action(4,prinyatnazhim)
  speciale_action(4,slider.muz.id)
  speciale_action(4,slider.sfx.id)
  speciale_action(4,aktiv)
  speciale_action(4,vkl)
  speciale_action(4,fullgalka)
  
  set_visible_object(optvyhodnazhim,false)
  set_visible_object(prinyatnazhim,false)
  set_visible_object(vkl,false)
  set_visible_object(slider.muz.id,true)
  set_visible_object(slider.sfx.id,true)
  set_visible_object(fullgalka,GetScreenMode())
  set_visible_object(options,true)
  
  SetAlfaValue(prinyatvkl,0.01)
  SetAlfaValue(optvyhodvkl,0.01)
  SetAlfaValue(aktiv,0.01)
  
  OnMouseOver(prinyatvkl)
  OnMouseOver(optvyhodvkl)
  OnMouseOver(aktiv)
    
  setInputFunction("optionsGameInput")
  local pressedButton = nil
  local dx = 0
  
------------------------------------------------------------
--  function: moveSlider
------------------------------------------------------------
  function moveSlider()
    moveEye()
    local x,y = GetCursorPos()
    local x0,x1 = slider.x0, slider.x1
    if x > x0 + dx and x < x1 - slider.w + dx then
      if pressedButton == slider.muz.id then
        slider.muz.x = x - dx
        SetObjectPosition(pressedButton,slider.muz.x,slider.muz.y)
      else
        slider.sfx.x = x - dx
        SetObjectPosition(pressedButton,slider.sfx.x,slider.sfx.y)
      end
    elseif x >= x1 - slider.w + dx then
      if pressedButton == slider.muz.id then
        slider.muz.x = x1
        SetObjectPosition(pressedButton,slider.muz.x,slider.muz.y)
      else
        slider.sfx.x = x1
        SetObjectPosition(pressedButton,slider.sfx.x,slider.sfx.y)
      end
    elseif x <= x0 + dx then
      if pressedButton == slider.muz.id then
        slider.muz.x = x0
        SetObjectPosition(pressedButton,slider.muz.x,slider.muz.y)
      else
        slider.sfx.x = x0
        SetObjectPosition(pressedButton,slider.sfx.x,slider.sfx.y)
      end
    end
  end

  
------------------------------------------------------------
--  function: closeOptions
------------------------------------------------------------
  --local 
  function closeOptions()
  optionsrun=false
    del_object_from_game(optvyhodnazhim)
    del_object_from_game(optvyhodvkl)
    del_object_from_game(prinyatnazhim)
    del_object_from_game(prinyatvkl)
    del_object_from_game(slider.muz.id)
    del_object_from_game(slider.sfx.id)
    del_object_from_game(aktiv)
    del_object_from_game(vkl)
    del_object_from_game(options)
    del_object_from_game(fullgalka)
    
    setInputFunction()
      if fromIngameMenu then
      fromIngameMenu=false
      showIngameMenu()
      ingame_menu = true    
return;end

  end
  
  
------------------------------------------------------------
--  function: optionsGameInput
------------------------------------------------------------
  function galochka()
    set_visible_object(fullgalka,GetScreenMode())
  end;

  function optionsGameInput(sender, obj_id,param2)
    Write(sender.."; "..obj_id.."\n")
    -- ОК
    if threeStateButton(sender,obj_id,param2,prinyatvkl,prinyatnazhim) then
      closeOptions()
    end
    -- ОТМЕНА
    if threeStateButton(sender,obj_id,param2,optvyhodvkl,optvyhodnazhim) then
      seteffectvalue(sfx)
      setmusucvalue(muz)
      closeOptions()
    end
    -- ФУЛЛСКРИН
    if threeStateButton(sender,obj_id,param2,aktiv,vkl) then
      tofullscrean()
      StartTimer(434645,0.2,"galochka",true)
      
    end
    -- СЛАЙДЕРЫ
    if sender == 1 or sender == 6 then
      if pressedButton == slider.muz.id then
        local val = (slider.muz.x - slider.x0)/(slider.x1 - slider.x0)*100
        Write("val= "..val.."\n")
        setmusucvalue(val)
        savesetings()
      end
      if pressedButton == slider.sfx.id then
        local val = (slider.sfx.x - slider.x0)/(slider.x1 - slider.x0)*100
        Write("val= "..val.."\n")
        seteffectvalue(val)
        savesetings()
      end
      pressedButton = nil
      MouseMove = moveEye
    end
    
    if sender == 5 then
      local x,y = GetCursorPos()
      if x >= slider.sfx.x and x <= slider.sfx.x + slider.w and y >= slider.sfx.y and y <= slider.sfx.y + slider.h then
        pressedButton = slider.sfx.id
        dx = x - slider.sfx.x
        MouseMove = moveSlider
      end
      if x >= slider.muz.x and x <= slider.muz.x + slider.w and y >= slider.muz.y and y <= slider.muz.y + slider.h then
        pressedButton = slider.muz.id
        dx = x - slider.muz.x
        MouseMove = moveSlider
      end
    end
  end
end


