框架允许自定义失去焦点时执行的操作
This commit is contained in:
@@ -215,7 +215,7 @@ function love.touchreleased(id,x,y)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local fnKey={NULL,NULL,NULL,NULL}
|
local fnKey={NULL,NULL,NULL,NULL,NULL,NULL,NULL}
|
||||||
local function noDevkeyPressed(key)
|
local function noDevkeyPressed(key)
|
||||||
if key=="f1"then fnKey[1]()
|
if key=="f1"then fnKey[1]()
|
||||||
elseif key=="f2"then fnKey[2]()
|
elseif key=="f2"then fnKey[2]()
|
||||||
@@ -364,42 +364,9 @@ function love.resize(w,h)
|
|||||||
|
|
||||||
SHADER.warning:send('w',w*SCR.dpi)
|
SHADER.warning:send('w',w*SCR.dpi)
|
||||||
end
|
end
|
||||||
local function task_autoSoundOff()
|
|
||||||
while true do
|
local onFocus=NULL
|
||||||
coroutine.yield()
|
function love.focus(f)onFocus(f)end
|
||||||
local v=love.audio.getVolume()
|
|
||||||
love.audio.setVolume(math.max(v-.05,0))
|
|
||||||
if v==0 then return end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
local function task_autoSoundOn()
|
|
||||||
while true do
|
|
||||||
coroutine.yield()
|
|
||||||
local v=love.audio.getVolume()
|
|
||||||
if v<SETTING.mainVol then
|
|
||||||
love.audio.setVolume(math.min(v+.05,SETTING.mainVol,1))
|
|
||||||
else
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
function love.focus(f)
|
|
||||||
if f then
|
|
||||||
love.timer.step()
|
|
||||||
if SETTING.autoMute then
|
|
||||||
TASK.removeTask_code(task_autoSoundOff)
|
|
||||||
TASK.new(task_autoSoundOn)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if SCN.cur=='game'and SETTING.autoPause then
|
|
||||||
pauseGame()
|
|
||||||
end
|
|
||||||
if SETTING.autoMute then
|
|
||||||
TASK.removeTask_code(task_autoSoundOn)
|
|
||||||
TASK.new(task_autoSoundOff)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local yield=coroutine.yield
|
local yield=coroutine.yield
|
||||||
local function secondLoopThread()
|
local function secondLoopThread()
|
||||||
@@ -737,10 +704,12 @@ function Z.setCursor(func)drawCursor=func end
|
|||||||
|
|
||||||
--Change F1~F7 events of devmode (F8 mode)
|
--Change F1~F7 events of devmode (F8 mode)
|
||||||
function Z.setOnFnKeys(list)
|
function Z.setOnFnKeys(list)
|
||||||
for i=1,7 do
|
assert(type(list)=='table')
|
||||||
fnKey[i]=type(list[i])=='function'and list[i]or NULL
|
for i=1,7 do fnKey[i]=type(list[i])=='function'and list[i]or NULL end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Z.setOnFocus(func)onFocus=type(func)=='function'and func or NULL end
|
||||||
|
|
||||||
function Z.setOnQuit(func)onQuit=type(func)=='function'and func or NULL end
|
function Z.setOnQuit(func)onQuit=type(func)=='function'and func or NULL end
|
||||||
|
|
||||||
return Z
|
return Z
|
||||||
|
|||||||
46
main.lua
46
main.lua
@@ -97,7 +97,10 @@ netPLY= require'parts.netPlayer'
|
|||||||
MODES= require'parts.modes'
|
MODES= require'parts.modes'
|
||||||
|
|
||||||
--Init Zframework
|
--Init Zframework
|
||||||
do
|
Z.setIfPowerInfo(function()
|
||||||
|
return SETTING.powerInfo and LOADED
|
||||||
|
end)
|
||||||
|
do--Z.setCursor
|
||||||
local normImg=GC.DO{16,16,
|
local normImg=GC.DO{16,16,
|
||||||
{'fCirc',8,8,4},
|
{'fCirc',8,8,4},
|
||||||
{'setCL',1,1,1,.7},
|
{'setCL',1,1,1,.7},
|
||||||
@@ -123,9 +126,6 @@ do
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
Z.setIfPowerInfo(function()
|
|
||||||
return SETTING.powerInfo and LOADED
|
|
||||||
end)
|
|
||||||
Z.setOnFnKeys({
|
Z.setOnFnKeys({
|
||||||
function()MES.new('check',PROFILE.switch()and"profile start!"or"profile report copied!")end,
|
function()MES.new('check',PROFILE.switch()and"profile start!"or"profile report copied!")end,
|
||||||
function()MES.new('info',("System:%s[%s]\nluaVer:%s\njitVer:%s\njitVerNum:%s"):format(SYSTEM,jit.arch,_VERSION,jit.version,jit.version_num))end,
|
function()MES.new('info',("System:%s[%s]\nluaVer:%s\njitVer:%s\njitVerNum:%s"):format(SYSTEM,jit.arch,_VERSION,jit.version,jit.version_num))end,
|
||||||
@@ -145,6 +145,44 @@ Z.setOnFnKeys({
|
|||||||
function()for k,v in next,_G do print(k,v)end end,
|
function()for k,v in next,_G do print(k,v)end end,
|
||||||
function()if love["_openConsole"]then love["_openConsole"]()end end,
|
function()if love["_openConsole"]then love["_openConsole"]()end end,
|
||||||
})
|
})
|
||||||
|
do--Z.setOnFocus
|
||||||
|
local function task_autoSoundOff()
|
||||||
|
while true do
|
||||||
|
coroutine.yield()
|
||||||
|
local v=love.audio.getVolume()
|
||||||
|
love.audio.setVolume(math.max(v-.05,0))
|
||||||
|
if v==0 then return end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local function task_autoSoundOn()
|
||||||
|
while true do
|
||||||
|
coroutine.yield()
|
||||||
|
local v=love.audio.getVolume()
|
||||||
|
if v<SETTING.mainVol then
|
||||||
|
love.audio.setVolume(math.min(v+.05,SETTING.mainVol,1))
|
||||||
|
else
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Z.setOnFocus(function(f)
|
||||||
|
if f then
|
||||||
|
love.timer.step()
|
||||||
|
if SETTING.autoMute then
|
||||||
|
TASK.removeTask_code(task_autoSoundOff)
|
||||||
|
TASK.new(task_autoSoundOn)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if SCN.cur=='game'and SETTING.autoPause then
|
||||||
|
pauseGame()
|
||||||
|
end
|
||||||
|
if SETTING.autoMute then
|
||||||
|
TASK.removeTask_code(task_autoSoundOn)
|
||||||
|
TASK.new(task_autoSoundOff)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
Z.setOnQuit(destroyPlayers)
|
Z.setOnQuit(destroyPlayers)
|
||||||
|
|
||||||
--Load settings and statistics
|
--Load settings and statistics
|
||||||
|
|||||||
Reference in New Issue
Block a user