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

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