--[[
飺
    ħҰģʽԶýűһαֻҪýűֹͣ
    ÿνħ޿ʼϷԶҰáħ޳Ƿ޹ء
÷
    Ctrl+Pʼã[Զ]Alt+PageUp []Alt+PageDown [ָ]Alt+
			[Զ]Alt+¹ []Alt+Ϲ [ָ]Alt+м
    ùаCtrl+OȡãCtrl+SãCtrl+Qʾ

:
[200994]
1. ӽǴΪҰĲֲеϢʾ
2. Alt+UpҰùаCtrl+Qʾ
3. ޸˲ʱ⡣
[200996]
Ż˽ű룬δʾʱĴ
[200997]
ʾϢλãֹʾũͼϲŹۡ
[2009910]
ֵAlt+Ұñ档
    [Զ]Alt+¹ []Alt+Ϲ [ָ]Alt+м
[20091026]
Զʾֶ2ģʽĬΪ1Զģʽ
ʱϢʾ
[2010412]
˲
[201054]
1.޸˽űṹֹֻܳű
2.˲ֱͬʾӦС
[2010513]
˶d3dͼش롣
[2010527]
Ұģʽ¶£ĿǰҰģʽΪ12űҰģʽ011

                                       ߣҹ
                                       			]]

--ű

if getwshscriptversion() < 4 then
    msgbox('ʹø߰汾')
end

--û޸Ĵ
nSetkey=80        --80ΪPļ
nSetkeyC=16       --32Ϊctrlļ
nCancelkey=79     --79ΪOļ
nCancelkeyC=16    --32Ϊctrlļ
nSavekey=83       --83ΪFļ
nSavekeyC=16      --32Ϊctrlļ
nQuestkey=81      --81ΪQļ
iSetTimes=60000    --Ұñʾʱ()
iAutoSaves=1       --ǷԶ,1ΪԶ棬0Ϊʾ
--û޸Ĵ

setglobalint('iSetTime', iSetTimes)
setglobalint('iAutoSave', iAutoSaves)
setglobalint('iIsSet', 0)
setglobalint('iSetValue', 0)
setglobalint('iSetState', 0)
setglobalint('iLastTick', 0)
setglobalint('nShowstate', 0)
setglobalint('idWsh', 0)
setglobalint('ridWsh', 0)
setglobalint('idSet', 0)
setglobalint('ridSet', 0)
sOption='[Զ]Alt+PageUp []Alt+PageDown [ָ]Alt+ \n[ȡ]Ctrl+O []Ctrl+S [ʾ]Ctrl+Q'

function myd3dsettext(nShowstate,strText,nAlpha)
    war3w = getwar3window()
    win3wl,win3wr,win3wt,win3wb = getclientrect(war3w)
    x=(win3wr-win3wl)*0.05
    y=(win3wb-win3wt)*0.655
    if((win3wr-win3wl)<790) then
        iFontW=5
    elseif((win3wr-win3wl)>=790 and (win3wr-win3wl)<1010) then
        iFontW=6
    else
        iFontW=7
    end
    midWsh = getglobalvar('idWsh')
    mridWsh = getglobalvar('ridWsh')
    midSet = getglobalvar('idSet')
    mridSet = getglobalvar('ridSet')
    if nShowstate==0 then 
        midWsh, mridWsh = d3dsettext(midWsh, mridWsh,'֡', 5000, x, y, "", 0x0000ff, nAlpha, iFontW, 0, 500, 0, 0, 0,0,2000)    
        midSet, mridSet = d3dsettext(midSet, mridSet,strText, 5000, (iFontW*2)*4+3+x, y, "", 0xffffff, nAlpha, iFontW, 0, 500, 0, 0, 0,0,2000)
    elseif nShowstate==1 then
        midWsh, mridWsh = d3dsettext(midWsh, mridWsh,'֡',getglobalvar('iSetTime'), x, y, "", 0x0000ff, nAlpha, iFontW, 0, 500, 0, 0, 0,0,2000)    
        midSet, mridSet = d3dsettext(midSet, mridSet,strText, getglobalvar('iSetTime'), (iFontW*2)*4+3+x, y, "", 0xffffff, nAlpha, iFontW, 0, 500, 0, 0, 0,0,2000)
    else 
        midWsh, mridWsh = d3dsettext(midWsh, mridWsh,'֡',0, x, y, "", 0x0000ff, nAlpha, iFontW, 0, 500, 0, 0, 0,0,2000)    
        midSet, mridSet = d3dsettext(midSet, mridSet,strText, 0, (iFontW*2)*4+3+x, y, "", 0xffffff, nAlpha, iFontW, 0, 500, 0, 0, 0,0,2000)
    end
    setglobalint('idWsh', midWsh)
    setglobalint('ridWsh', mridWsh)
    setglobalint('idSet', midSet)
    setglobalint('ridSet', mridSet)
end

setkeywatch('keyhookfunc')
setmousewatch('mousehookfunc')

function keyhookfunc(keycode, controlkey, downorup)
    if 0==iswar3front() then return 0 end
    if 1==ischat() then return 0 end  
    if downorup==1 then return 0 end
    if getglobalvar('iSetState')==1 and keycode==nCancelkey and controlkey==nCancelkeyC then 
        setglobalint('iSetValue', 0)
        setglobalint('iSetState', 0)
        strText='Ұȡ'
        myd3dsettext(0,strText,255)        
        return 1
    end

    if getglobalvar('iSetState')==1 and keycode==nSavekey and controlkey==nSavekeyC then 
        setglobalint('iIsSet', 1)    
        setglobalint('iSetState', 0)
        strText='ǰҰģʽ'..tostring(getglobalvar('iSetValue'))..'\nҰѱ棡'
        myd3dsettext(0,strText,255)        
        return 1
    end

    if getglobalvar('iSetState')==1 and keycode==nQuestkey and controlkey==nSavekeyC then 
        strText='ǰҰģʽ'..tostring(getglobalvar('iSetValue'))..'\nʾ'..sOption
        myd3dsettext(1,strText,255)        
        return 1
    end

    if getglobalvar('iSetState')==0 and keycode==nSetkey and nSetkeyC==controlkey then 
        setglobalint('iLastTick', gettickcount())
        if getglobalvar('iSetValue')==0 then enablewshfunction(16, 0) end
        setglobalint('iSetState', 1)  
        strText='ʼҰã'..sOption
        myd3dsettext(1,strText,255)
        return 1

    elseif getglobalvar('iSetState')==1 and keycode==34 and (1==controlkey or 2==controlkey) then
        if getglobalvar('iSetValue')==0 then setglobalint('iSetValue', 12) end
        enablewshfunction(16, -1)
        setglobalint('iSetValue', getglobalvar('iSetValue')-1)
        if getglobalvar('iSetValue')<0 then
             setglobalint('iSetValue', 0)
        end
        strText='ǰҰģʽ'..tostring(getglobalvar('iSetValue'))
        myd3dsettext(0,strText,255)
        return 1

    elseif getglobalvar('iSetState')==1 and keycode==33 and (1==controlkey or 2==controlkey) then        
        enablewshfunction(16, 1)
        setglobalint('iSetValue', getglobalvar('iSetValue')+1) 
        if getglobalvar('iSetValue')>11 then
            setglobalint('iSetValue', 0)
        end
        strText='ǰҰģʽ'..tostring(getglobalvar('iSetValue'))
        myd3dsettext(0,strText,255)
        return 1

    elseif getglobalvar('iSetState')==1 and keycode==37 and (1==controlkey or 2==controlkey) then        
        enablewshfunction(16, 0)
        setglobalint('iSetValue', 0)
        strText='Ұѻָ'
        myd3dsettext(0,strText,255)        
        return 1
    end
    return 0
end

function mousehookfunc(msg)
    if 0==iswar3front() then return 0 end
    if 1==ischat() then return 0 end  
    if downorup==1 then return 0 end
    if getglobalvar('iSetState')==1 and 0 > getkeystate(18) and msg==21 then
        enablewshfunction(16, 1)
        setglobalint('iSetValue', getglobalvar('iSetValue')+1)    
        if getglobalvar('iSetValue')>11 then
            setglobalint('iSetValue', 0)
        end
        strText='ǰҰģʽ'..tostring(getglobalvar('iSetValue'))
        myd3dsettext(0,strText,255)
        return 1
    elseif getglobalvar('iSetState')==1 and 0 > getkeystate(18) and msg==22 then
	if getglobalvar('iSetValue')==0 then setglobalint('iSetValue', 12) end
        enablewshfunction(16, -1)
        setglobalint('iSetValue', getglobalvar('iSetValue')-1)
        if getglobalvar('iSetValue')<0 then
             setglobalint('iSetValue', 0)
        end
        strText='ǰҰģʽ'..tostring(getglobalvar('iSetValue'))
        myd3dsettext(0,strText,255)
        return 1
    elseif getglobalvar('iSetState')==1 and 0 > getkeystate(18) and msg==3 then
        enablewshfunction(16, 0)
        setglobalint('iSetValue', 0)
        strText='Ұѻָ'
        myd3dsettext(0,strText,255)  
        return 1
    else return 0
    end
end

runlua('View_Settings.j')