diff --git a/Zframework/init.lua b/Zframework/init.lua index 1f3d9630..877dc575 100644 --- a/Zframework/init.lua +++ b/Zframework/init.lua @@ -40,6 +40,7 @@ LANG= require"Zframework.languages" TASK= require"Zframework.task" FILE= require"Zframework.file" PROFILE=require"Zframework.profile" +THEME= require"Zframework.theme" local ms,kb=love.mouse,love.keyboard diff --git a/Zframework/theme.lua b/Zframework/theme.lua new file mode 100644 index 00000000..eb97578b --- /dev/null +++ b/Zframework/theme.lua @@ -0,0 +1,74 @@ +local THEME={ + cur=false,--Current theme +} +local themeColor={ + xmas={COLOR.red,COLOR.white,COLOR.green}, + sprfes={COLOR.red,COLOR.orange,COLOR.yellow}, +} + +function THEME.calculate(Y,M,D) + if not Y then Y,M,D=os.date"%Y",os.date"%m",os.date"%d"end + --Festival calculate within one statement + return + --Christmas + M=="12"and math.abs(D-25)<4 and + "xmas"or + + --Spring festival + M<"03"and math.abs((({ + --Festival days. Jan 26=26, Feb 1=32, etc. + 24,43,32,22,40,29,49,38,26,45, + 34,23,41,31,50,39,28,47,36,25, + 43,32,22,41,29,48,37,26,44,34, + 23,42,31,50,39,28,46,35,24,43, + 32,22,41,30,48,37,26,45,33,23, + 42,32,50,39,28,46,35,24,43,33, + 21,40, + })[Y-2000]or -26)-((M-1)*31+D))<6 and + "sprfes"or + + --Z day (Feb./Mar./Apr./May./June 26) + math.abs(M-4)<=2 and D+0==26 and + "zday"or + + "classic" +end + +function THEME.set(theme) + if theme=="classic"then + BG.setDefault("space") + BGM.setDefault("blank") + elseif theme=="xmas"then + BG.setDefault("snow") + BGM.setDefault("mXmas") + LOG.print("==============",COLOR.red) + LOG.print("Merry Christmas!",COLOR.white) + LOG.print("==============",COLOR.red) + elseif theme=="sprfes"then + BG.setDefault("firework") + BGM.setDefault("spring festival") + LOG.print(" ★☆☆★",COLOR.red) + LOG.print("新年快乐!",COLOR.white) + LOG.print(" ★☆☆★",COLOR.red) + elseif theme=="zday"then + BG.setDefault("lanterns") + BGM.setDefault("overzero") + else + return + end + THEME.cur=theme + BG.set() + BGM.play() + return true +end + +function THEME.getThemeColor(theme) + if not theme then theme=THEME.cur end + return themeColor[theme] +end + +function THEME.fresh() + THEME.set(THEME.calculate(os.date"%Y",os.date"%m",os.date"%d")) +end + +return THEME \ No newline at end of file diff --git a/Zframework/widget.lua b/Zframework/widget.lua index ab5169cb..7f30d0b5 100644 --- a/Zframework/widget.lua +++ b/Zframework/widget.lua @@ -974,19 +974,13 @@ function WIDGET.set(list) for i=1,#list do list[i]:reset() end - if THEME and SCN.cur~="custom_field"then - local c1,c2,c3 - if THEME=="xMas"then - c1,c2,c3=COLOR.red,COLOR.white,COLOR.green - elseif THEME=="sprFes"then - c1,c2,c3=COLOR.red,COLOR.orange,COLOR.yellow - else - return - end + if SCN.cur~="custom_field"then + local colorList=THEME.getThemeColor() + if not colorList then return end local rnd=math.random for _,W in next,list do if W.color and not W.fText then - W.color=rnd()<.3 and c1 or rnd()<.5 and c2 or c3 + W.color=colorList[rnd(#colorList)] end end end diff --git a/main.lua b/main.lua index 3d55620e..605a09a2 100644 --- a/main.lua +++ b/main.lua @@ -29,32 +29,6 @@ WSCONN=false LATEST_VERSION=false ERRDATA={} ---Festival check within one statement -THEME=( - --Christmas - os.date"%m"=="12"and math.abs(os.date"%d"-25)<4 and - "Xmas"or - - --Spring festival - os.date"%m"<"03"and math.abs((({ - --Festival days. Jan 26=26, Feb 1=32, etc. - 24,43,32,22,40,29,49,38,26,45, - 34,23,41,31,50,39,28,47,36,25, - 43,32,22,41,29,48,37,26,44,34, - 23,42,31,50,39,28,46,35,24,43, - 32,22,41,30,48,37,26,45,33,23, - 42,32,50,39,28,46,35,24,43,33, - 21,40, - })[os.date"%Y"-2000]or -26)-((os.date"%m"-1)*31+os.date"%d"))<6 and - "sprFes"or - - --Z day (Feb./Mar./Apr./May./June 26) - math.abs(os.date"%m"-4)<=2 and os.date"%d"+0==26 and - "zDay"or - - false -) - --System setting math.randomseed(os.time()*626) love.keyboard.setKeyRepeat(true) @@ -406,18 +380,4 @@ do STAT.version=VERSION_CODE FILE.save(STAT,"conf/data","q") end -end - -if THEME=="Xmas"then - BG.setDefault("snow") - BGM.setDefault("mXmas") -elseif THEME=="sprFes"then - BG.setDefault("firework") - BGM.setDefault("spring festival") -elseif THEME=="zDay"then - BG.setDefault("lanterns") - BGM.setDefault("overzero") -else - BG.setDefault("space") - BGM.setDefault("blank") end \ No newline at end of file diff --git a/parts/scenes/app_cmd.lua b/parts/scenes/app_cmd.lua index fae885f9..4f93008a 100644 --- a/parts/scenes/app_cmd.lua +++ b/parts/scenes/app_cmd.lua @@ -470,30 +470,13 @@ function commands.setbg(name) end end function commands.theme(name) - if name=="classic"then - THEME=false - BG.setDefault("space") - BGM.setDefault("blank") - BGM.play() - elseif name=="xmas"then - THEME="xMas" - BG.setDefault("snow") - BGM.setDefault("mXmas") - BGM.play() - elseif name=="sprfes"then - THEME="sprFes" - BG.setDefault("firework") - BGM.setDefault("spring festival") - BGM.play() - elseif name=="zday"then - THEME="zDay" - BG.setDefault("lanterns") - BGM.setDefault("overzero") - BGM.play() - else - if name~=""then + if name~=""then + if THEME.set(name)then + log("Theme set to: "..name) + else log("No theme called "..name) end + else log{C.water,"Usage: theme [themeName]"} end end diff --git a/parts/scenes/intro.lua b/parts/scenes/intro.lua index 52f5ddbf..94be7b00 100644 --- a/parts/scenes/intro.lua +++ b/parts/scenes/intro.lua @@ -8,8 +8,6 @@ local scene={} local t1,t2,animateType function scene.sceneInit() - BG.set() - BGM.play() t1,t2=0,0--Timer animateType={rnd(5),rnd(5),rnd(5),rnd(5),rnd(5),rnd(5),rnd(5),rnd(5)}--Random animation type end diff --git a/parts/scenes/load.lua b/parts/scenes/load.lua index d275463d..8b24e32a 100644 --- a/parts/scenes/load.lua +++ b/parts/scenes/load.lua @@ -182,15 +182,7 @@ local loadingThread=coroutine.create(function() authToken=USER.authToken, }) ]] - if THEME=="Xmas"then - LOG.print("==============",COLOR.red) - LOG.print("Merry Christmas!",COLOR.white) - LOG.print("==============",COLOR.red) - elseif THEME=="sprFes"then - LOG.print(" ★☆☆★",COLOR.red) - LOG.print("新年快乐!",COLOR.white) - LOG.print(" ★☆☆★",COLOR.red) - end + THEME.fresh() while true do if math.random()<.126 then upFloor()