From 19ea76dc4c426f200d44cc8cec886d66fbdb40c2 Mon Sep 17 00:00:00 2001 From: C6H12O6 + NaCl + H2O <106439598+SweetSea-ButImNotSweet@users.noreply.github.com> Date: Sun, 31 Dec 2023 20:35:48 +0700 Subject: [PATCH] No theme and default BG and patch BG bug when hitting F11 (#1070) * Add setting slot for no theme & default BG * Whitelist 4 seasons theme + blocking console's theme command if theme disabled * Small update theme.lua * Expose the WIDGET.setOnChange() to use in setting_video.lua * Shorten "Use custom B.G." to "Custom B.G." * Shorten theme code, and edit the UI * Add lock BG * Add VI translation * Fullscreen patch * Modify UI * Small change * Undo a mistake --- main.lua | 7 +-- parts/gameFuncs.lua | 48 ++++++++++--------- parts/gameTables.lua | 3 ++ parts/language/lang_en.lua | 6 ++- parts/language/lang_vi.lua | 5 ++ parts/scenes/app_console.lua | 10 ++-- parts/scenes/setting_video.lua | 74 +++++++++++++++++++++++------- parts/theme.lua | 84 +++++++++++++++++----------------- 8 files changed, 150 insertions(+), 87 deletions(-) diff --git a/main.lua b/main.lua index 965bcfb7..95091435 100644 --- a/main.lua +++ b/main.lua @@ -49,7 +49,7 @@ SCR.setSize(1280,720) -- Initialize Screen size BGM.setMaxSources(5) VOC.setDiversion(.62) -WIDGET.setOnChange(function() +ChangeButtonColorIfThemeUsed=function() if SCN.cur~='net_game' and SCN.cur~='custom_field' then local colorList=THEME.getThemeColor() if colorList then @@ -60,7 +60,8 @@ WIDGET.setOnChange(function() end end end -end) +end +WIDGET.setOnChange(ChangeButtonColorIfThemeUsed) -- Create shortcuts setFont=FONT.set @@ -191,7 +192,7 @@ Z.setOnFnKeys({ Z.setOnGlobalKey('f11',function() if not MOBILE then SETTING.fullscreen=not SETTING.fullscreen - applySettings() + applySettings('fullscreen') saveSettings() end end) diff --git a/parts/gameFuncs.lua b/parts/gameFuncs.lua index 209db401..cd5cffeb 100644 --- a/parts/gameFuncs.lua +++ b/parts/gameFuncs.lua @@ -115,7 +115,7 @@ do-- function applySettings() light={.2,.8}, color={-.2,1.2}, } - function applySettings() + function applySettings(arg) -- Apply language text=LANG.get(SETTING.locale) WIDGET.setLang(text.WidgetText) @@ -157,30 +157,34 @@ do-- function applySettings() SHADER.fieldSatur:send('k',m[2]) -- Apply BG - if SETTING.bg=='on' then - BG.unlock() - BG.set() - elseif SETTING.bg=='off' then - BG.unlock() - BG.set('fixColor',SETTING.bgAlpha,SETTING.bgAlpha,SETTING.bgAlpha) - BG.lock() - elseif SETTING.bg=='custom' then - if love.filesystem.getInfo('conf/customBG') then - local res,image=pcall(GC.newImage,love.filesystem.newFile('conf/customBG')) - if res then - BG.unlock() - GC.setDefaultFilter('linear','linear') - BG.set('custom',SETTING.bgAlpha,image) - GC.setDefaultFilter('nearest','nearest') - BG.lock() - else - MES.new('error',text.customBGloadFailed) - end - else-- Switch off when custom BG not found - SETTING.bg='off' + if not (arg and arg=='fullscreen') then + if SETTING.bg=='on' then + BG.unlock() + BG.setDefault(SETTING.defaultBG) + BG.set() + if SETTING.lockBG then BG.lock() end + elseif SETTING.bg=='off' then BG.unlock() BG.set('fixColor',SETTING.bgAlpha,SETTING.bgAlpha,SETTING.bgAlpha) BG.lock() + elseif SETTING.bg=='custom' then + if love.filesystem.getInfo('conf/customBG') then + local res,image=pcall(GC.newImage,love.filesystem.newFile('conf/customBG')) + if res then + BG.unlock() + GC.setDefaultFilter('linear','linear') + BG.set('custom',SETTING.bgAlpha,image) + GC.setDefaultFilter('nearest','nearest') + BG.lock() + else + MES.new('error',text.customBGloadFailed) + end + else-- Switch off when custom BG not found + SETTING.bg='off' + BG.unlock() + BG.set('fixColor',SETTING.bgAlpha,SETTING.bgAlpha,SETTING.bgAlpha) + BG.lock() + end end end end diff --git a/parts/gameTables.lua b/parts/gameTables.lua index 1269cd92..7543b25e 100644 --- a/parts/gameTables.lua +++ b/parts/gameTables.lua @@ -659,6 +659,9 @@ do-- Userdata tables msaa=0, bg='on', bgAlpha=.26, + defaultBG='space', + lockBG=false, + noTheme=false, powerInfo=false, clickFX=true, warn=true, diff --git a/parts/language/lang_en.lua b/parts/language/lang_en.lua index 2ba768b1..55c1ca0a 100644 --- a/parts/language/lang_en.lua +++ b/parts/language/lang_en.lua @@ -587,7 +587,11 @@ C. Gamepad bg_on="Normal B.G.", bg_off="No B.G.", - bg_custom="Use Custom B.G.", + bg_custom="Custom B.G.", + defaultBG="Default B.G.", + resetDbg="Reset default B.G.", + lockBG="Lock B.G.", + noTheme="Disable theme", blockSatur="Block Saturation", fieldSatur="Field Saturation", diff --git a/parts/language/lang_vi.lua b/parts/language/lang_vi.lua index d3c67894..95fa050c 100644 --- a/parts/language/lang_vi.lua +++ b/parts/language/lang_vi.lua @@ -599,6 +599,11 @@ C. Tay cầm chơi game (Gamepad): bg_on="Ảnh nền thường", bg_off="Không ảnh nền", bg_custom="Ảnh nền tự chọn", + defaultBG="Nền mặc định", + -- resetDbg='Đặt lại →', + resetDbg="Đặt lại ảnh nền mặc định", + lockBG="Khóa ảnh nền", + noTheme="Tắt theme", blockSatur="Độ đậm gạch", fieldSatur="Độ đậm bảng", diff --git a/parts/scenes/app_console.lua b/parts/scenes/app_console.lua index 7b7916eb..bb6d5dbc 100644 --- a/parts/scenes/app_console.lua +++ b/parts/scenes/app_console.lua @@ -501,10 +501,14 @@ local commands={} do commands.theme={ code=function(name) if name~="" then - if THEME.set(name) then - log("Theme set to: "..name) + if SETTING.noTheme then + log{"Theme is ",C.R,"disabled",C.Z,"! Please re-enable it before trying this command again"} else - log("No theme called "..name) + if THEME.set(name) then + log("Theme set to: "..name) + else + log("No theme called "..name) + end end else log{C.A,"Usage: theme "} diff --git a/parts/scenes/setting_video.lua b/parts/scenes/setting_video.lua index 35bf108b..a81330b6 100644 --- a/parts/scenes/setting_video.lua +++ b/parts/scenes/setting_video.lua @@ -30,7 +30,7 @@ function scene.draw() gc.push('transform') gc.setColor(1,1,1) local T=skinLib[1] - gc.translate(0,1410-WIDGET.scrollPos) + gc.translate(-200,1410-WIDGET.scrollPos) -- -200 gc.setShader(SHADER.blockSatur) gc.draw(T,435,0)gc.draw(T,465,0)gc.draw(T,465,30)gc.draw(T,495,30) gc.setShader(SHADER.fieldSatur) @@ -84,15 +84,15 @@ scene.widgetList={ WIDGET.newSwitch{name='warn', x=450,y=1340,lim=360,disp=SETval('warn'), code=SETrev('warn')}, WIDGET.newSwitch{name='clickFX', x=950,y=980,lim=360,disp=SETval('clickFX'), code=function() SETTING.clickFX=not SETTING.clickFX; applySettings() end}, - WIDGET.newSwitch{name='power', x=950,y=1050,lim=360,disp=SETval('powerInfo'), code=function() SETTING.powerInfo=not SETTING.powerInfo; applySettings() end}, - WIDGET.newSwitch{name='clean', x=950,y=1120,lim=360,disp=SETval('cleanCanvas'), code=function() SETTING.cleanCanvas=not SETTING.cleanCanvas; applySettings() end}, - WIDGET.newSwitch{name='fullscreen', x=950,y=1190,lim=360,disp=SETval('fullscreen'), code=function() SETTING.fullscreen=not SETTING.fullscreen; applySettings() end,hideF=function() return MOBILE end}, - WIDGET.newSwitch{name='portrait', x=950,y=1190,lim=360,disp=SETval('portrait'), code=function() SETTING.portrait=not SETTING.portrait; saveSettings(); MES.new('warn',text.settingWarn2,6.26) end,hideF=function() return not MOBILE end}, - WIDGET.newSlider{name='msaa', x=950,y=1250,lim=360,w=200,axis={0,4,1},show=_msaaShow,disp=function() return SETTING.msaa==0 and 0 or math.log(SETTING.msaa,2) end,code=function(v) SETTING.msaa=v==0 and 0 or 2^v; saveSettings(); if TASK.lock('warnMessage',6.26) then MES.new('warn',text.settingWarn2,6.26) end end}, + WIDGET.newSwitch{name='power', x=950,y=1030,lim=360,disp=SETval('powerInfo'), code=function() SETTING.powerInfo=not SETTING.powerInfo; applySettings() end}, + WIDGET.newSwitch{name='clean', x=950,y=1100,lim=360,disp=SETval('cleanCanvas'), code=function() SETTING.cleanCanvas=not SETTING.cleanCanvas; applySettings() end}, + WIDGET.newSwitch{name='fullscreen', x=950,y=1150,lim=360,disp=SETval('fullscreen'), code=function() SETTING.fullscreen=not SETTING.fullscreen; applySettings() end,hideF=function() return MOBILE end}, + WIDGET.newSwitch{name='portrait', x=950,y=1150,lim=360,disp=SETval('portrait'), code=function() SETTING.portrait=not SETTING.portrait; saveSettings(); MES.new('warn',text.settingWarn2,6.26) end,hideF=function() return not MOBILE end}, + WIDGET.newSlider{name='msaa', x=950,y=1220,lim=360,w=200,axis={0,4,1},show=_msaaShow,disp=function() return SETTING.msaa==0 and 0 or math.log(SETTING.msaa,2) end,code=function(v) SETTING.msaa=v==0 and 0 or 2^v; saveSettings(); if TASK.lock('warnMessage',6.26) then MES.new('warn',text.settingWarn2,6.26) end end}, - WIDGET.newKey{name='bg_on', x=680,y=1340,w=200,h=80,code=function() SETTING.bg='on'; applySettings() end}, - WIDGET.newKey{name='bg_off', x=900,y=1340,w=200,h=80,code=function() SETTING.bg='off'; applySettings() end}, - WIDGET.newKey{name='bg_custom', x=1120,y=1340,w=200,h=80, + WIDGET.newKey{name='bg_off', x=680,y=1290,w=200,h=60,code=function() SETTING.bg='off'; applySettings() end}, + WIDGET.newKey{name='bg_on', x=900,y=1290,w=200,h=60,code=function() SETTING.bg='on' ; applySettings() end}, + WIDGET.newKey{name='bg_custom', x=1120,y=1290,w=200,h=60, code=function() if love.filesystem.getInfo('conf/customBG') then SETTING.bg='custom' @@ -101,8 +101,8 @@ scene.widgetList={ MES.new('info',text.customBGhelp) end end - }, - WIDGET.newSlider{name='bgAlpha', x=1020,y=1430,w=200, + }, + WIDGET.newSlider{name='bgAlpha', x=1020,y=1365,w=200, axis={0,.8},disp=SETval('bgAlpha'), code=function(v) SETTING.bgAlpha=v @@ -113,18 +113,60 @@ scene.widgetList={ end end, hideF=function() return SETTING.bg=='on' end - }, + }, + WIDGET.newSelector{name='defaultBG', x=1120,y=1365,w=200,color='G', + limit=370, + list=BG.getList(), + disp=SETval('defaultBG'), + code=function(v) + SETTING.defaultBG=v + applySettings() + end, + hideF=function() return SETTING.bg~='on' end + }, + WIDGET.newKey{name='resetDbg',x=900,y=1365,w=200,h=60,font=25, + code=function() + SETTING.defaultBG='space' + scene.widgetList.defaultBG:reset() + applySettings() + end, + hideF=function() return SETTING.bg~='on' or SETTING.defaultBG=='space' end + }, + WIDGET.newSwitch{name='lockBG',x=1170,y=1485, + disp=SETval('lockBG'), + code=function() + SETTING.lockBG=not SETTING.lockBG + applySettings() + end, + hideF=function() return SETTING.bg~='on' end + }, - WIDGET.newSelector{name='blockSatur', x=800,y=1440,w=300,color='lN', + WIDGET.newSwitch{name='noTheme',x=1170,y=1545, + disp=SETval('noTheme'), + code=function() + SETTING.noTheme=not SETTING.noTheme + local ct=THEME.calculate() + if SETTING.noTheme and type(ct)=='string' and string.sub(ct,1,6)~='season' then + if TASK.lock('warnMessage',6.26) then + MES.new('warn',text.settingWarn2,6.26) + end + else + THEME.set(THEME.calculate()) + ChangeButtonColorIfThemeUsed() + end + end + }, + + WIDGET.newSelector{name='blockSatur', x=600,y=1440,w=300,color='lN', list={'normal','soft','gray','light','color'}, disp=SETval('blockSatur'), code=function(v) SETTING.blockSatur=v; applySettings() end - }, - WIDGET.newSelector{name='fieldSatur', x=800,y=1540,w=300,color='lN', + }, + WIDGET.newSelector{name='fieldSatur', x=600,y=1540,w=300,color='lN', list={'normal','soft','gray','light','color'}, disp=SETval('fieldSatur'), code=function(v) SETTING.fieldSatur=v; applySettings() end - }, + }, WIDGET.newButton{name='back', x=1140,y=640,w=170,h=80,sound='back',font=60,fText=CHAR.icon.back,code=backScene}, } diff --git a/parts/theme.lua b/parts/theme.lua index 2bbd6997..49add864 100644 --- a/parts/theme.lua +++ b/parts/theme.lua @@ -59,48 +59,48 @@ function THEME.calculate(Y,M,D) end function THEME.set(theme) - if theme=='xmas' then - BG.setDefault('snow') - BGM.setDefault('xmas') - MES.new('info',"==Merry Christmas==") - elseif theme=='birth' then - BG.setDefault('firework') - BGM.setDefault('magicblock') - elseif theme=='sprfes' then - BG.setDefault('firework') - BGM.setDefault('spring festival') - MES.new('info',"★☆新年快乐☆★") - elseif theme=='halloween' then - BG.setDefault('glow') - BGM.setDefault('antispace') - MES.new('info',">>Happy halloween<<") - elseif theme=='zday1' then - BG.setDefault('lanterns') - BGM.setDefault('overzero') - elseif theme=='zday2' then - BG.setDefault('lanterns') - BGM.setDefault('jazz nihilism') - elseif theme=='zday3' then - BG.setDefault('lanterns') - BGM.setDefault('empty') - elseif theme=='season1' then - BG.setDefault('space') - BGM.setDefault('null') - elseif theme=='season2' then - BG.setDefault('space') - BGM.setDefault('nil') - elseif theme=='season3' then - BG.setDefault('space') - BGM.setDefault('vacuum') - elseif theme=='season4' then - BG.setDefault('space') - BGM.setDefault('space') - elseif theme=='fool' then - BG.setDefault('blockrain') - BGM.setDefault('how feeling') - else - return - end + local seasonT={'null','nil','vaccum','space'} + -- Note: by default, the background will be 'space' unless user changed + -- Because 4 seasonal themes are basically the normal theme, not special like others + if type(theme)=='string' and string.sub(theme,1,6)=='season' then + local n=tonumber(string.sub(theme,7)) + if 0>Happy halloween<<") + elseif theme=='zday1' then + BG.setDefault('lanterns') + BGM.setDefault('overzero') + elseif theme=='zday2' then + BG.setDefault('lanterns') + BGM.setDefault('jazz nihilism') + elseif theme=='zday3' then + BG.setDefault('lanterns') + BGM.setDefault('empty') + elseif theme=='fool' then + BG.setDefault('blockrain') + BGM.setDefault('how feeling') + else + return + end + else THEME.set(THEME.calculate('0',os.date('%m'),'0')) return end + THEME.cur=theme BG.set() BGM.play()