框架允许自定义失去焦点时执行的操作

This commit is contained in:
MrZ626
2021-10-17 01:13:10 +08:00
parent 0099bf53cb
commit f9902a6ea5
2 changed files with 51 additions and 44 deletions

View File

@@ -215,7 +215,7 @@ function love.touchreleased(id,x,y)
end
end
local fnKey={NULL,NULL,NULL,NULL}
local fnKey={NULL,NULL,NULL,NULL,NULL,NULL,NULL}
local function noDevkeyPressed(key)
if key=="f1"then fnKey[1]()
elseif key=="f2"then fnKey[2]()
@@ -364,42 +364,9 @@ function love.resize(w,h)
SHADER.warning:send('w',w*SCR.dpi)
end
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
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 onFocus=NULL
function love.focus(f)onFocus(f)end
local yield=coroutine.yield
local function secondLoopThread()
@@ -737,10 +704,12 @@ function Z.setCursor(func)drawCursor=func end
--Change F1~F7 events of devmode (F8 mode)
function Z.setOnFnKeys(list)
for i=1,7 do
fnKey[i]=type(list[i])=='function'and list[i]or NULL
end
assert(type(list)=='table')
for i=1,7 do fnKey[i]=type(list[i])=='function'and list[i]or NULL 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
return Z

View File

@@ -97,7 +97,10 @@ netPLY= require'parts.netPlayer'
MODES= require'parts.modes'
--Init Zframework
do
Z.setIfPowerInfo(function()
return SETTING.powerInfo and LOADED
end)
do--Z.setCursor
local normImg=GC.DO{16,16,
{'fCirc',8,8,4},
{'setCL',1,1,1,.7},
@@ -123,9 +126,6 @@ do
end
end)
end
Z.setIfPowerInfo(function()
return SETTING.powerInfo and LOADED
end)
Z.setOnFnKeys({
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,
@@ -145,6 +145,44 @@ Z.setOnFnKeys({
function()for k,v in next,_G do print(k,v)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)
--Load settings and statistics