diff --git a/parts/backgrounds/custom.lua b/parts/backgrounds/custom.lua index 113e9ea2..97e0d77e 100644 --- a/parts/backgrounds/custom.lua +++ b/parts/backgrounds/custom.lua @@ -4,10 +4,12 @@ local back={} local image=false local alpha=.26 function back.draw() - gc.clear(.1,.1,.1) - gc.setColor(1,1,1,alpha) - local k=math.max(SCR.w/image:getWidth(),SCR.h/image:getHeight()) - mDraw(image,SCR.w*.5,SCR.h*.5,nil,k) + if image then + gc.clear(.1,.1,.1) + gc.setColor(1,1,1,alpha) + local k=math.max(SCR.w/image:getWidth(),SCR.h/image:getHeight()) + mDraw(image,SCR.w*.5,SCR.h*.5,nil,k) + end end function back.event(a,img) if a then alpha=a end diff --git a/parts/gameFuncs.lua b/parts/gameFuncs.lua index 88c90987..af4255d5 100644 --- a/parts/gameFuncs.lua +++ b/parts/gameFuncs.lua @@ -119,13 +119,17 @@ function applyBG() BG.lock() elseif SETTING.bg=='custom'then if love.filesystem.getInfo('conf/customBG')then - BG.unlock() - BG.set('custom') - gc.setDefaultFilter('linear','linear') - local image=gc.newImage(love.filesystem.newFile('conf/customBG')) - gc.setDefaultFilter('nearest','nearest') - BG.send(SETTING.bgAlpha,image) - BG.lock() + local res,image=pcall(gc.newImage,love.filesystem.newFile('conf/customBG')) + if res then + BG.unlock() + BG.set('custom') + gc.setDefaultFilter('linear','linear') + BG.send(SETTING.bgAlpha,image) + gc.setDefaultFilter('nearest','nearest') + BG.lock() + else + MES.new('error',text.customBGloadFailed) + end else SETTING.bg='off' applyBG() diff --git a/parts/language/lang_en.lua b/parts/language/lang_en.lua index 0fdb008a..9535d699 100644 --- a/parts/language/lang_en.lua +++ b/parts/language/lang_en.lua @@ -139,6 +139,7 @@ return{ keySettingInstruction="Press to bind key\nescape: cancel\nbackspace: delete", customBGhelp="Drop image file here to apply custom background", + customBGloadFailed="Unsupport image format for custom background", errorMsg="Techmino ran into a problem and needs to restart.\nYou can send the error log to the developers.", tryAnotherBuild="[Invalid UTF-8] If you are on Windows, try downloading Techmino-win32 or Techmino-win64 (different from what you are using now).", diff --git a/parts/language/lang_es.lua b/parts/language/lang_es.lua index dff46d10..bc3d7218 100644 --- a/parts/language/lang_es.lua +++ b/parts/language/lang_es.lua @@ -128,6 +128,7 @@ return{ -- keySettingInstruction="Press to bind key\nescape: cancel\nbackspace: delete", -- customBGhelp="Drop image file here to apply custom background", + -- customBGloadFailed="Unsupport image format for custom background", errorMsg="Ha ocurrido un error y Techmino necesita reiniciarse.\nSe creó un registro de error, puedes enviarlo al autor.", -- tryAnotherBuild="[Invalid UTF-8] If you are on Windows, try downloading Techmino-win32 or Techmino-win64 (different from what you are using now).", diff --git a/parts/language/lang_fr.lua b/parts/language/lang_fr.lua index 3ae2067b..3253bd4f 100644 --- a/parts/language/lang_fr.lua +++ b/parts/language/lang_fr.lua @@ -129,6 +129,7 @@ return{ -- keySettingInstruction="Press to bind key\nescape: cancel\nbackspace: delete", -- customBGhelp="Drop image file here to apply custom background", + -- customBGloadFailed="Unsupport image format for custom background", errorMsg="Une erreur est survenue et Techmino doit redémarrer.\nDes informations concernant l'erreur ont été créées, et vous pouvez les envoyer au créateur.", -- tryAnotherBuild="[Invalid UTF-8] If you are on Windows, try downloading Techmino-win32 or Techmino-win64 (different from what you are using now).", diff --git a/parts/language/lang_pt.lua b/parts/language/lang_pt.lua index 8970f9f3..3e4427e5 100644 --- a/parts/language/lang_pt.lua +++ b/parts/language/lang_pt.lua @@ -127,6 +127,7 @@ return{ -- keySettingInstruction="Press to bind key\nescape: cancel\nbackspace: delete", -- customBGhelp="Drop image file here to apply custom background", + -- customBGloadFailed="Unsupport image format for custom background", errorMsg="Um erro ocorreu e Techmino precisa reiniciar.\nInformação do erro foi criada, e você pode mandar ao autor.", -- tryAnotherBuild="[Invalid UTF-8] If you are on Windows, try downloading Techmino-win32 or Techmino-win64 (different from what you are using now).", diff --git a/parts/language/lang_zh.lua b/parts/language/lang_zh.lua index 16a752cb..2e2022c2 100644 --- a/parts/language/lang_zh.lua +++ b/parts/language/lang_zh.lua @@ -139,6 +139,7 @@ return{ keySettingInstruction="点击添加键位绑定\nesc取消选中\n退格键清空选中", customBGhelp="把图片文件拖到这个窗口里使用自定义背景", + customBGloadFailed="自定义背景的图片文件格式不支持", errorMsg="Techmino遭受了雷击,需要重新启动。\n我们已收集了一些错误信息,你可以向作者进行反馈。", tryAnotherBuild="[解码UTF-8错误] 如果你现在用的是Windows系统,请重新下载 Techmino-32位 或者 Techmino-64位 (和现在运行的不一样的那个)。", diff --git a/parts/language/lang_zh_grass.lua b/parts/language/lang_zh_grass.lua index e6fad900..fb9691d8 100644 --- a/parts/language/lang_zh_grass.lua +++ b/parts/language/lang_zh_grass.lua @@ -137,6 +137,7 @@ return{ keySettingInstruction="按绑定键\n退出:取消\n退格:删除", customBGhelp="将图像文件拖放到此处以应用自定义背景", + customBGloadFailed="不支持自定义背景的图像格式", errorMsg="技术米诺遇到问题,需要重新启动。\n您可以将错误日志发送给开发人员。", tryAnotherBuild="[无效UTF-8]如果您在Windows上,请尝试下载Techmino-win32或Techmino-win64(与您现在使用的不同)", diff --git a/parts/language/lang_zh_trad.lua b/parts/language/lang_zh_trad.lua index 0c664146..973ad203 100644 --- a/parts/language/lang_zh_trad.lua +++ b/parts/language/lang_zh_trad.lua @@ -139,6 +139,7 @@ return{ keySettingInstruction="點擊來設置鍵位\n按esc來取消選中\n按退格鍵來清除選中", customBGhelp="把圖片檔案拖到這個視窗裏使用自定義背景", + customBGloadFailed="自定義背景的圖片檔案格式不支持", errorMsg="Techmino遇到問題,需要重新啟動。\n我們已經收集了一些錯誤信息,你可以反饋給作者。", tryAnotherBuild="[無效的 UTF-8] 如果你使用的是Windows作業系統,請嘗試下載Techmino-win32或Techmino-win64(與你現在使用的不同的版本)。", diff --git a/parts/scenes/setting_video.lua b/parts/scenes/setting_video.lua index 89a2e4d4..3b79b60e 100644 --- a/parts/scenes/setting_video.lua +++ b/parts/scenes/setting_video.lua @@ -8,9 +8,13 @@ end function scene.fileDropped(file) - love.filesystem.write('conf/customBG',file:read('data')) - SETTING.bg='custom' - applyBG() + if pcall(gc.newImage,file)then + love.filesystem.write('conf/customBG',file:read('data')) + SETTING.bg='custom' + applyBG() + else + MES.new('error',text.customBGloadFailed) + end end local fakeBlock={{true}}