Make a scene for showing full text (like manual) but for convenience use (#1043)

This commit is contained in:
C6H12O6 + NaCl + H2O
2023-11-13 11:15:58 +07:00
committed by GitHub
parent 55800e307f
commit c650f268f6
8 changed files with 99 additions and 156 deletions

View File

@@ -1227,6 +1227,24 @@ do-- function pressKey(k)
return cache[k] return cache[k]
end end
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) do-- SETXXX(k)
local warnList={ local warnList={
'das','arr','dascut','dropcut','sddas','sdarr', 'das','arr','dascut','dropcut','sddas','sdarr',

View File

@@ -41,8 +41,8 @@ end
scene.widgetList={ scene.widgetList={
WIDGET.newButton{name='staff', x=1140,y=340,w=200,h=80,font=35,code=goScene'staff'}, 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='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=goScene'legals'}, 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}, WIDGET.newButton{name='back', x=1140,y=640,w=170,h=80,sound='back',font=60,fText=CHAR.icon.back,code=backScene},
} }

View File

@@ -70,30 +70,11 @@ end}
-- Necessary local functions -- Necessary local functions
-- Update the infobox -- Update the infobox
local function _updateInfoBox(c) local function _updateContentBox()
local _t,t local _t,t
if c==nil then _t,t=pcall(function() return _getList()[listBox.selected].content end)
if listBox.selected==0 then if not _t then t={"???"} end
if text.dict.helpText then local _w,c=FONT.get(currentFontSize):getWrap(t,840)
_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)
textBox:setTexts(c) textBox:setTexts(c)
end end
-- Clear the result -- Clear the result
@@ -101,7 +82,7 @@ local function _clearResult()
TABLE.cut(result) TABLE.cut(result)
listBox.selected,lastSelected,searchWait,lastSearch=1,1,0,false listBox.selected,lastSelected,searchWait,lastSearch=1,1,0,false
scene.widgetList.copy.hide=false scene.widgetList.copy.hide=false
_updateInfoBox() _updateContentBox()
end end
-- Search through the dictionary -- Search through the dictionary
local function _search() local function _search()
@@ -124,7 +105,7 @@ local function _search()
if #result>0 then SFX.play('reach') end if #result>0 then SFX.play('reach') end
lastSearch=input lastSearch=input
_updateInfoBox() _updateContentBox()
end end
-- Jump over n items -- Jump over n items
@@ -132,7 +113,7 @@ local function _jumpover(key,n)
local dir=(key=='left' or key=='pageup') and 'up' or 'down' local dir=(key=='left' or key=='pageup') and 'up' or 'down'
for _=1,n or 1 do scene.widgetList.listBox:arrowKey(dir) end for _=1,n or 1 do scene.widgetList.listBox:arrowKey(dir) end
_updateInfoBox() _updateContentBox()
lastSelected=listBox.selected lastSelected=listBox.selected
scene.widgetList.copy.hide=false scene.widgetList.copy.hide=false
end end
@@ -152,7 +133,7 @@ local function _setZoom(z)
textBox.font=currentFontSize textBox.font=currentFontSize
textBox.lineH=currentFontSize*7/5 -- Recalculate the line's height textBox.lineH=currentFontSize*7/5 -- Recalculate the line's height
textBox.capacity=math.ceil((textBox.h-10)/textBox.lineH) 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) MES.new("check",z~=0 and text.dict.sizeChanged:repD(currentFontSize) or text.dict.sizeReset,1.26)
end end
@@ -173,10 +154,9 @@ function scene.enter()
result={} result={}
searchWait=0 searchWait=0
lastSelected=0 lastSelected=1
lastSearch=false lastSearch=false
listBox:setList(_getList()) listBox:setList(_getList())
scene.widgetList.help.color=COLOR.Z
if not MOBILE then WIDGET.focus(inputBox) end if not MOBILE then WIDGET.focus(inputBox) end
BG.set('rainbow') BG.set('rainbow')
@@ -212,7 +192,7 @@ function scene.keyDown(key)
_clearResult() _clearResult()
inputBox:clear() inputBox:clear()
SFX.play('hold') SFX.play('hold')
_updateInfoBox() _updateContentBox()
end end
elseif key=='escape' then elseif key=='escape' then
if inputBox:hasText() then if inputBox:hasText() then
@@ -221,12 +201,16 @@ function scene.keyDown(key)
SCN.back() SCN.back()
end end
elseif key=='f1' then elseif key=='f1' then
-- inputBox:clear() goTextReader{
-- _clearResult() function() return (
listBox.selected=listBox.selected==0 and lastSelected or 0 text.dict.helpText:repD(
scene.widgetList.help.color=listBox.selected==0 and COLOR.W or COLOR.Z CHAR.key.up,CHAR.key.down,CHAR.key.left,CHAR.key.right,
searchWait=0 CHAR.controller.dpadU,CHAR.controller.dpadD,CHAR.controller.dpadL,CHAR.controller.dpadR,
_updateInfoBox() 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!*** -- ***ONLY USE FOR HOTLOADING ZICTIONARY WHILE IN GAME!***
-- ***Please commenting out this code if you don't use*** -- ***Please commenting out this code if you don't use***
@@ -294,25 +278,21 @@ function scene.update(dt)
_search() _search()
end end
end end
if listBox.selected~=lastSelected and listBox.selected~=0 then if listBox.selected~=lastSelected then
scene.widgetList.help.color=COLOR.Z
lastSelected=listBox.selected lastSelected=listBox.selected
scene.widgetList.copy.hide=false _updateContentBox()
_updateInfoBox()
end end
end end
function scene.draw() function scene.draw()
-- Draw background -- Draw background
gc.setColor(COLOR.dX) gc.setColor(COLOR.dX)
gc.rectangle('fill',1194,335,80,370,5) gc.rectangle('fill',1194,260,80,370,5)
gc.rectangle('fill',1194,180,80,80,5) -- Help key
-- Draw outline -- Draw outline
gc.setLineWidth(2) gc.setLineWidth(2)
gc.setColor(COLOR.Z) gc.setColor(COLOR.Z)
gc.rectangle('line',1194,335,80,370,5) gc.rectangle('line',1194,260,80,370)
gc.line(1194,555,1274,555) gc.line(1194,480,1274,480)
gc.rectangle('line',1194,180,80,80,5) -- Help key
if searchWait>0 then if searchWait>0 then
local r=TIME()*2 local r=TIME()*2
@@ -328,17 +308,15 @@ scene.widgetList={
listBox, listBox,
inputBox, inputBox,
textBox, 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='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=665,w=60,font=40,fText=CHAR.icon.copy,code=pressKey'cC',hideF=function() return not (listBox.selected>0) 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='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=445,w=60,font=40,fText=CHAR.icon.zoomOut,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=515,w=60,font=40,fText=CHAR.icon.zoomDefault,code=function() _setZoom(0) end}, WIDGET.newKey{name='resetzoom',x=1234,y=440,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.newButton{name='back',x=1185,y=60,w=170,h=80,sound='back',font=60,fText=CHAR.icon.back,code=backScene}, 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 -- 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 return scene

View File

@@ -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

View File

@@ -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

View File

@@ -117,7 +117,7 @@ function scene.keyDown(key,isRep)
end end
elseif key=='m' then elseif key=='m' then
if _testButton(13) 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 end
elseif key=='c' then elseif key=='c' then
enterConsole() enterConsole()

View File

@@ -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

View File

@@ -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