From c650f268f6b5d8e620c8ea7608a884baee315844 Mon Sep 17 00:00:00 2001 From: C6H12O6 + NaCl + H2O <106439598+SweetSea-ButImNotSweet@users.noreply.github.com> Date: Mon, 13 Nov 2023 11:15:58 +0700 Subject: [PATCH] Make a scene for showing full text (like manual) but for convenience use (#1043) --- parts/gameFuncs.lua | 18 ++++++++ parts/scenes/about.lua | 4 +- parts/scenes/dict.lua | 84 ++++++++++++++----------------------- parts/scenes/history.lua | 30 ------------- parts/scenes/legals.lua | 34 --------------- parts/scenes/main.lua | 2 +- parts/scenes/manual.lua | 36 ---------------- parts/scenes/textReader.lua | 47 +++++++++++++++++++++ 8 files changed, 99 insertions(+), 156 deletions(-) delete mode 100644 parts/scenes/history.lua delete mode 100644 parts/scenes/legals.lua delete mode 100644 parts/scenes/manual.lua create mode 100644 parts/scenes/textReader.lua diff --git a/parts/gameFuncs.lua b/parts/gameFuncs.lua index 3b4b337b..f3a2ce35 100644 --- a/parts/gameFuncs.lua +++ b/parts/gameFuncs.lua @@ -1227,6 +1227,24 @@ do-- function pressKey(k) return cache[k] end end +do-- function goTextReader{text,size,bg} + -- @MrZ626 I don't know where to put, please, deal with them for me lol + local cache={} + function goTextReader(D) + local f + local hash=D + local text,size,bg=D[1],D[2],D[3] + if type(D[1])=='function' then f=D[1] end + + if not cache[hash] then + cache[hash]=function() + if f then text=f();f=nil end + SCN.go('textReader',nil,text,size,bg) + end + end + return cache[hash] + end +end do-- SETXXX(k) local warnList={ 'das','arr','dascut','dropcut','sddas','sdarr', diff --git a/parts/scenes/about.lua b/parts/scenes/about.lua index cd8cd346..430c7283 100644 --- a/parts/scenes/about.lua +++ b/parts/scenes/about.lua @@ -41,8 +41,8 @@ end scene.widgetList={ WIDGET.newButton{name='staff', x=1140,y=340,w=200,h=80,font=35,code=goScene'staff'}, - WIDGET.newButton{name='his', x=1140,y=440,w=200,h=80,font=35,code=goScene'history'}, - WIDGET.newButton{name='legals', x=1140,y=540,w=200,h=80,font=35,code=goScene'legals'}, + WIDGET.newButton{name='his', x=1140,y=440,w=200,h=80,font=35,code=goTextReader{function() return require"parts.updateLog":split("\n") end,20,'cubes'}}, + WIDGET.newButton{name='legals', x=1140,y=540,w=200,h=80,font=35,code=goTextReader{function() return love.filesystem.read("legals.md"):split('\n') or "[legals.md not found]" end,15,'cubes'}}, 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/scenes/dict.lua b/parts/scenes/dict.lua index 9bdabb41..9123f861 100644 --- a/parts/scenes/dict.lua +++ b/parts/scenes/dict.lua @@ -70,30 +70,11 @@ end} -- Necessary local functions -- Update the infobox -local function _updateInfoBox(c) +local function _updateContentBox() local _t,t - if c==nil then - if listBox.selected==0 then - if text.dict.helpText then - _t,t=true,text.dict.helpText:repD( - CHAR.key.up,CHAR.key.down,CHAR.key.left,CHAR.key.right, - CHAR.controller.dpadU,CHAR.controller.dpadD,CHAR.controller.dpadL,CHAR.controller.dpadR, - CHAR.controller.xboxX,CHAR.controller.xboxY,CHAR.controller.xboxA,CHAR.controller.xboxB, - CHAR.icon.help,CHAR.icon.copy,CHAR.icon.globe,CHAR.key.winMenu - ) - else -- Fallback - listBox.selected=lastSelected - scene.widgetList.help.color=COLOR.Z - MES.new("error","Cannot found the Help text! Maybe just a mistake?") - return - end - else - _t,t=pcall(function() return _getList()[listBox.selected].content end) - end - if _t then c=t else c={""} end - _t,t=nil,nil - end - local _w,c=FONT.get(currentFontSize):getWrap(c,840) + _t,t=pcall(function() return _getList()[listBox.selected].content end) + if not _t then t={"???"} end + local _w,c=FONT.get(currentFontSize):getWrap(t,840) textBox:setTexts(c) end -- Clear the result @@ -101,7 +82,7 @@ local function _clearResult() TABLE.cut(result) listBox.selected,lastSelected,searchWait,lastSearch=1,1,0,false scene.widgetList.copy.hide=false - _updateInfoBox() + _updateContentBox() end -- Search through the dictionary local function _search() @@ -124,7 +105,7 @@ local function _search() if #result>0 then SFX.play('reach') end lastSearch=input - _updateInfoBox() + _updateContentBox() end -- Jump over n items @@ -132,7 +113,7 @@ local function _jumpover(key,n) local dir=(key=='left' or key=='pageup') and 'up' or 'down' for _=1,n or 1 do scene.widgetList.listBox:arrowKey(dir) end - _updateInfoBox() + _updateContentBox() lastSelected=listBox.selected scene.widgetList.copy.hide=false end @@ -152,7 +133,7 @@ local function _setZoom(z) textBox.font=currentFontSize textBox.lineH=currentFontSize*7/5 -- Recalculate the line's height textBox.capacity=math.ceil((textBox.h-10)/textBox.lineH) - _updateInfoBox() + _updateContentBox() MES.new("check",z~=0 and text.dict.sizeChanged:repD(currentFontSize) or text.dict.sizeReset,1.26) end @@ -173,10 +154,9 @@ function scene.enter() result={} searchWait=0 - lastSelected=0 + lastSelected=1 lastSearch=false listBox:setList(_getList()) - scene.widgetList.help.color=COLOR.Z if not MOBILE then WIDGET.focus(inputBox) end BG.set('rainbow') @@ -212,7 +192,7 @@ function scene.keyDown(key) _clearResult() inputBox:clear() SFX.play('hold') - _updateInfoBox() + _updateContentBox() end elseif key=='escape' then if inputBox:hasText() then @@ -221,12 +201,16 @@ function scene.keyDown(key) SCN.back() end elseif key=='f1' then - -- inputBox:clear() - -- _clearResult() - listBox.selected=listBox.selected==0 and lastSelected or 0 - scene.widgetList.help.color=listBox.selected==0 and COLOR.W or COLOR.Z - searchWait=0 - _updateInfoBox() + goTextReader{ + function() return ( + text.dict.helpText:repD( + CHAR.key.up,CHAR.key.down,CHAR.key.left,CHAR.key.right, + CHAR.controller.dpadU,CHAR.controller.dpadD,CHAR.controller.dpadL,CHAR.controller.dpadR, + CHAR.controller.xboxX,CHAR.controller.xboxY,CHAR.controller.xboxA,CHAR.controller.xboxB, + CHAR.icon.help,CHAR.icon.copy,CHAR.icon.globe,CHAR.key.winMenu) + ):split('\n') + end, + currentFontSize,'rainbow'}() -- ***ONLY USE FOR HOTLOADING ZICTIONARY WHILE IN GAME!*** -- ***Please commenting out this code if you don't use*** @@ -294,25 +278,21 @@ function scene.update(dt) _search() end end - if listBox.selected~=lastSelected and listBox.selected~=0 then - scene.widgetList.help.color=COLOR.Z + if listBox.selected~=lastSelected then lastSelected=listBox.selected - scene.widgetList.copy.hide=false - _updateInfoBox() + _updateContentBox() end end function scene.draw() -- Draw background gc.setColor(COLOR.dX) - gc.rectangle('fill',1194,335,80,370,5) - gc.rectangle('fill',1194,180,80,80,5) -- Help key + gc.rectangle('fill',1194,260,80,370,5) -- Draw outline gc.setLineWidth(2) gc.setColor(COLOR.Z) - gc.rectangle('line',1194,335,80,370,5) - gc.line(1194,555,1274,555) - gc.rectangle('line',1194,180,80,80,5) -- Help key + gc.rectangle('line',1194,260,80,370) + gc.line(1194,480,1274,480) if searchWait>0 then local r=TIME()*2 @@ -328,17 +308,15 @@ scene.widgetList={ listBox, inputBox, textBox, - WIDGET.newKey{name='link',x=1234,y=595,w=60,font=45,fText=CHAR.icon.globe,code=pressKey'application',hideF=function() return not (listBox.selected>0 and _getList()[listBox.selected].url) end}, - WIDGET.newKey{name='copy',x=1234,y=665,w=60,font=40,fText=CHAR.icon.copy,code=pressKey'cC',hideF=function() return not (listBox.selected>0) end}, + WIDGET.newKey{name='link',x=1234,y=520,w=60,font=45,fText=CHAR.icon.globe,code=pressKey'application',hideF=function() return not (listBox.selected>0 and _getList()[listBox.selected].url) end}, + WIDGET.newKey{name='copy',x=1234,y=590,w=60,font=40,fText=CHAR.icon.copy,code=pressKey'cC',hideF=function() return not (listBox.selected>0) end}, - WIDGET.newKey{name='zoomin',x=1234,y=375,w=60,font=40,fText=CHAR.icon.zoomIn,code=function() _setZoom(5) end}, - WIDGET.newKey{name='zoomout',x=1234,y=445,w=60,font=40,fText=CHAR.icon.zoomOut,code=function() _setZoom(-5) end}, - WIDGET.newKey{name='resetzoom',x=1234,y=515,w=60,font=40,fText=CHAR.icon.zoomDefault,code=function() _setZoom(0) end}, - - WIDGET.newKey{name='help',x=1234,y=220,w=60,font=40,fText=CHAR.icon.help,code=pressKey'f1'}, + WIDGET.newKey{name='zoomin',x=1234,y=300,w=60,font=40,fText=CHAR.icon.zoomIn,code=function() _setZoom(5) end}, + WIDGET.newKey{name='zoomout',x=1234,y=370,w=60,font=40,fText=CHAR.icon.zoomOut,code=function() _setZoom(-5) end}, + WIDGET.newKey{name='resetzoom',x=1234,y=440,w=60,font=40,fText=CHAR.icon.zoomDefault,code=function() _setZoom(0) end}, WIDGET.newButton{name='back',x=1185,y=60,w=170,h=80,sound='back',font=60,fText=CHAR.icon.back,code=backScene}, - WIDGET.newText{name='buttontip',x=1274,y=110,w=762,h=60,font=40,align='R',fText=CHAR.controller.xboxY.."/[F1]: "..CHAR.icon.help,hideF=function() return MOBILE end}, + WIDGET.newKey{name='help',x=1170,y=140,w=200,h=60,font=40,fText=CHAR.controller.xboxY.."/[F1]: "..CHAR.icon.help,code=pressKey'f1'}, } -- NOTE: The gap between Link-Copy, Zoom is 60*1.5-10=80 :) The gap between 2 buttons in one group is 60+10=70 return scene diff --git a/parts/scenes/history.lua b/parts/scenes/history.lua deleted file mode 100644 index ee1c9435..00000000 --- a/parts/scenes/history.lua +++ /dev/null @@ -1,30 +0,0 @@ -local scene={} - -function scene.enter() - BG.set('cubes') - scene.widgetList.texts:setTexts(require"parts.updateLog":split("\n")) -end - -function scene.wheelMoved(_,y) - WHEELMOV(y) -end -function scene.keyDown(key) - if key=='up' then - scene.widgetList.texts:scroll(-5) - elseif key=='down' then - scene.widgetList.texts:scroll(5) - elseif key=='pageup' then - scene.widgetList.texts:scroll(-20) - elseif key=='pagedown' then - scene.widgetList.texts:scroll(20) - elseif key=='escape' then - SCN.back() - end -end - -scene.widgetList={ - WIDGET.newTextBox{name='texts',x=30,y=45,w=1000,h=640,font=20,fix=true}, - WIDGET.newButton{name='back',x=1140,y=640,w=170,h=80,sound='back',font=60,fText=CHAR.icon.back,code=backScene}, -} - -return scene diff --git a/parts/scenes/legals.lua b/parts/scenes/legals.lua deleted file mode 100644 index 6e20b268..00000000 --- a/parts/scenes/legals.lua +++ /dev/null @@ -1,34 +0,0 @@ -local scene={} -function scene.enter() - BG.set('cubes') - local fileData=love.filesystem.read("legals.md") - if fileData then - scene.widgetList.texts:setTexts(fileData:split('\n')) - else - scene.widgetList.texts:setTexts{"[legals.md not found]"} - end -end - -function scene.wheelMoved(_,y) - WHEELMOV(y) -end -function scene.keyDown(key) - if key=='up' then - scene.widgetList.texts:scroll(-5) - elseif key=='down' then - scene.widgetList.texts:scroll(5) - elseif key=='pageup' then - scene.widgetList.texts:scroll(-20) - elseif key=='pagedown' then - scene.widgetList.texts:scroll(20) - elseif key=='escape' then - SCN.back() - end -end - -scene.widgetList={ - WIDGET.newTextBox{name='texts',x=30,y=45,w=1000,h=640,font=15,fix=true}, - WIDGET.newButton{name='back',x=1140,y=640,w=170,h=80,sound='back',font=60,fText=CHAR.icon.back,code=backScene}, -} - -return scene diff --git a/parts/scenes/main.lua b/parts/scenes/main.lua index d4864a4e..1a36cbef 100644 --- a/parts/scenes/main.lua +++ b/parts/scenes/main.lua @@ -117,7 +117,7 @@ function scene.keyDown(key,isRep) end elseif key=='m' then if _testButton(13) then - SCN.go('manual') + goTextReader{function() return FILE.load('parts/language/manual_'..(SETTING.locale:find'zh' and 'zh' or SETTING.locale:find'ja' and 'ja' or SETTING.locale:find'vi' and 'vi' or 'en')..'.txt','-string'):split('\n') or "[manual file not found]" end,15,'cubes'}() end elseif key=='c' then enterConsole() diff --git a/parts/scenes/manual.lua b/parts/scenes/manual.lua deleted file mode 100644 index 33f39098..00000000 --- a/parts/scenes/manual.lua +++ /dev/null @@ -1,36 +0,0 @@ -local scene={} - -function scene.enter() - BG.set('cubes') - local fileData=FILE.load('parts/language/manual_'..(SETTING.locale:find'zh' and 'zh' or SETTING.locale:find'ja' and 'ja' or SETTING.locale:find'vi' and 'vi' or 'en')..'.txt','-string') - if fileData then - scene.widgetList.texts:setTexts(fileData:split('\n')) - else - scene.widgetList.texts:setTexts{"[manual file not found]"} - end - -end - -function scene.wheelMoved(_,y) - WHEELMOV(y) -end -function scene.keyDown(key) - if key=='up' then - scene.widgetList.texts:scroll(-5) - elseif key=='down' then - scene.widgetList.texts:scroll(5) - elseif key=='pageup' then - scene.widgetList.texts:scroll(-20) - elseif key=='pagedown' then - scene.widgetList.texts:scroll(20) - elseif key=='escape' then - SCN.back() - end -end - -scene.widgetList={ - WIDGET.newTextBox{name='texts',x=30,y=45,w=1000,h=640,font=15,fix=true}, - WIDGET.newButton{name='back',x=1140,y=640,w=170,h=80,sound='back',font=60,fText=CHAR.icon.back,code=backScene}, -} - -return scene diff --git a/parts/scenes/textReader.lua b/parts/scenes/textReader.lua new file mode 100644 index 00000000..fd6e1eea --- /dev/null +++ b/parts/scenes/textReader.lua @@ -0,0 +1,47 @@ +local scene={} +local texts=WIDGET.newTextBox{name='texts',x=30,y=45,w=1000,h=640,font=20,fix=true} + +function scene.enter() + --[[ + Argument: + [1] - Text (in table format). Default to "No text!" + [2] - Font size (in number) + [3] - Background (in string format) + ]] + + if SCN.args[2] then + assert(type(SCN.args[2]=='number'), "2nd argument (font size) must be a number!") + scene.widgetList.texts=WIDGET.newTextBox{name='texts',x=30,y=45,w=1000,h=640,font=SCN.args[2],fix=true} + end + if SCN.args[3] then + assert(type(SCN.args[3]=='string'), "3rd argument (background) must be a string!") + end + + BG.set(SCN.args[3]) + scene.widgetList.texts:setTexts(SCN.args[1] and SCN.args[1] or {"No text!"}) + +end + +function scene.wheelMoved(_,y) + WHEELMOV(y) +end +function scene.keyDown(key) + if key=='up' then + scene.widgetList.texts:scroll(-5) + elseif key=='down' then + scene.widgetList.texts:scroll(5) + elseif key=='pageup' then + scene.widgetList.texts:scroll(-20) + elseif key=='pagedown' then + scene.widgetList.texts:scroll(20) + elseif key=='escape' then + SCN.back() + end +end + +scene.widgetList={ + texts, + WIDGET.newButton{name='back',x=1140,y=640,w=170,h=80,sound='back',font=60,fText=CHAR.icon.back,code=backScene}, +} + +return scene