textBox控件名让给真·文本框,输入框控件改名inputBox,更新历史界面使用文本框控件
This commit is contained in:
@@ -235,7 +235,7 @@ function love.textedited(text)
|
||||
end
|
||||
function love.textinput(text)
|
||||
local W=WIDGET.sel
|
||||
if W and W.type=="textBox"then
|
||||
if W and W.type=="inputBox"then
|
||||
if not W.regex or text:match(W.regex)then
|
||||
WIDGET.sel.value=WIDGET.sel.value..text
|
||||
SFX.play("move")
|
||||
|
||||
@@ -689,29 +689,29 @@ function WIDGET.newSelector(D)--name,x,y,w[,fText][,color],list,disp,code,hide
|
||||
return _
|
||||
end
|
||||
|
||||
local textBox={
|
||||
type="textBox",
|
||||
local inputBox={
|
||||
type="inputBox",
|
||||
keepFocus=true,
|
||||
ATV=0,--Activating time(0~4)
|
||||
value="",--Text contained
|
||||
}
|
||||
function textBox:reset()
|
||||
function inputBox:reset()
|
||||
self.ATV=0
|
||||
if not MOBILE then
|
||||
kb.setTextInput(true)
|
||||
end
|
||||
end
|
||||
function textBox:isAbove(x,y)
|
||||
function inputBox:isAbove(x,y)
|
||||
return
|
||||
x>self.x and
|
||||
y>self.y and
|
||||
x<self.x+self.w and
|
||||
y<self.y+self.h
|
||||
end
|
||||
function textBox:getCenter()
|
||||
function inputBox:getCenter()
|
||||
return self.x+self.w*.5,self.y
|
||||
end
|
||||
function textBox:update()
|
||||
function inputBox:update()
|
||||
local ATV=self.ATV
|
||||
if WIDGET.sel==self then
|
||||
if ATV<3 then self.ATV=ATV+1 end
|
||||
@@ -719,7 +719,7 @@ function textBox:update()
|
||||
if ATV>0 then self.ATV=ATV-.25 end
|
||||
end
|
||||
end
|
||||
function textBox:draw()
|
||||
function inputBox:draw()
|
||||
local x,y,w,h=self.x,self.y,self.w,self.h
|
||||
local ATV=self.ATV
|
||||
|
||||
@@ -748,16 +748,16 @@ function textBox:draw()
|
||||
end
|
||||
end
|
||||
end
|
||||
function textBox:getInfo()
|
||||
function inputBox:getInfo()
|
||||
return format("x=%d,y=%d,w=%d,h=%d",self.x+self.w*.5,self.y+self.h*.5,self.w,self.h)
|
||||
end
|
||||
function textBox:press()
|
||||
function inputBox:press()
|
||||
if MOBILE then
|
||||
local _,y1=SCR.xOy:transformPoint(0,self.y+self.h)
|
||||
kb.setTextInput(true,0,y1,1,1)
|
||||
end
|
||||
end
|
||||
function textBox:keypress(k)
|
||||
function inputBox:keypress(k)
|
||||
local t=self.value
|
||||
if #t>0 and EDITING==""then
|
||||
if k=="backspace"then
|
||||
@@ -773,7 +773,7 @@ function textBox:keypress(k)
|
||||
self.value=t
|
||||
end
|
||||
end
|
||||
function WIDGET.newTextBox(D)--name,x,y,w[,h][,font][,secret][,regex],hide
|
||||
function WIDGET.newInputBox(D)--name,x,y,w[,h][,font][,secret][,regex],hide
|
||||
local _={
|
||||
name= D.name,
|
||||
|
||||
@@ -793,38 +793,42 @@ function WIDGET.newTextBox(D)--name,x,y,w[,h][,font][,secret][,regex],hide
|
||||
regex= D.regex,
|
||||
hide= D.hide,
|
||||
}
|
||||
for k,v in next,textBox do _[k]=v end
|
||||
for k,v in next,inputBox do _[k]=v end
|
||||
setmetatable(_,widgetMetatable)
|
||||
return _
|
||||
end
|
||||
|
||||
local chatBox={
|
||||
type="chatBox",
|
||||
local textBox={
|
||||
type="textBox",
|
||||
scrollPos=0,
|
||||
scrollPix=0,
|
||||
sure=0,
|
||||
new=false,
|
||||
-- texts={},
|
||||
}
|
||||
function chatBox:reset()
|
||||
function textBox:reset()
|
||||
--haha nothing here, but techmino is fun!
|
||||
end
|
||||
function chatBox:isAbove(x,y)
|
||||
function textBox:setTexts(t)
|
||||
self.texts=t
|
||||
self.scrollPos=min(#self.texts,self.capacity)
|
||||
end
|
||||
function textBox:isAbove(x,y)
|
||||
return
|
||||
x>self.x and
|
||||
y>self.y and
|
||||
x<self.x+self.w and
|
||||
y<self.y+self.h
|
||||
end
|
||||
function chatBox:getCenter()
|
||||
function textBox:getCenter()
|
||||
return self.x+self.w*.5,self.y+self.w
|
||||
end
|
||||
function chatBox:update()
|
||||
function textBox:update()
|
||||
if self.sure>0 then
|
||||
self.sure=self.sure-1
|
||||
end
|
||||
end
|
||||
function chatBox:push(t)
|
||||
function textBox:push(t)
|
||||
ins(self.texts,t)
|
||||
if self.scrollPos==#self.texts-1 then
|
||||
self.scrollPos=self.scrollPos+1
|
||||
@@ -833,19 +837,17 @@ function chatBox:push(t)
|
||||
self.new=true
|
||||
end
|
||||
end
|
||||
function chatBox:drag(_,_,_,dy)
|
||||
function textBox:drag(_,_,_,dy)
|
||||
_=self.scrollPix+dy
|
||||
if _>30 then
|
||||
_=_-30
|
||||
self:scroll(-1)
|
||||
elseif _<-30 then
|
||||
_=_+30
|
||||
self:scroll(1)
|
||||
local sign=_>0 and 1 or -1
|
||||
while abs(_)>30 do
|
||||
_=_-30*sign
|
||||
self:scroll(-sign)
|
||||
end
|
||||
self.scrollPix=_
|
||||
end
|
||||
function chatBox:press(x,y)
|
||||
if x>self.x+self.w-40 and y<self.y+40 then
|
||||
function textBox:press(x,y)
|
||||
if not self.fix and x>self.x+self.w-40 and y<self.y+40 then
|
||||
if self.sure>0 then
|
||||
self:clear()
|
||||
self.sure=0
|
||||
@@ -854,7 +856,7 @@ function chatBox:press(x,y)
|
||||
end
|
||||
end
|
||||
end
|
||||
function chatBox:scroll(n)
|
||||
function textBox:scroll(n)
|
||||
if n<0 then
|
||||
self.scrollPos=max(self.scrollPos+n,min(#self.texts,self.capacity))
|
||||
else
|
||||
@@ -864,17 +866,20 @@ function chatBox:scroll(n)
|
||||
end
|
||||
end
|
||||
end
|
||||
function chatBox:clear()
|
||||
self.texts={}
|
||||
self.scrollPos=0
|
||||
SFX.play("fall")
|
||||
function textBox:clear()
|
||||
if not self.fix then
|
||||
self.texts={}
|
||||
self.scrollPos=0
|
||||
SFX.play("fall")
|
||||
end
|
||||
end
|
||||
function chatBox:draw()
|
||||
function textBox:draw()
|
||||
local x,y,w,h=self.x,self.y,self.w,self.h
|
||||
local texts=self.texts
|
||||
local scroll=self.scrollPos
|
||||
local cap=self.capacity
|
||||
|
||||
|
||||
--Frame
|
||||
gc.setLineWidth(4)
|
||||
gc.setColor(0,0,0,.3)
|
||||
@@ -882,34 +887,38 @@ function chatBox:draw()
|
||||
gc.setColor(1,1,1)
|
||||
gc.rectangle("line",x,y,w,h)
|
||||
|
||||
--Clear button
|
||||
setFont(30)
|
||||
mStr(self.sure>0 and"?"or"X",x+w-20,y-1)
|
||||
gc.rectangle("line",x+w-40,y,40,40)
|
||||
|
||||
--Texts
|
||||
for i=max(scroll-cap+1,1),scroll do
|
||||
gc.printf(texts[i],x+8,y+h-10-30*(scroll-i+1),w)
|
||||
end
|
||||
|
||||
--Slider
|
||||
if #texts>cap then
|
||||
gc.setLineWidth(2)
|
||||
gc.rectangle("line",x-25,y,20,h)
|
||||
local len=h*cap/#texts
|
||||
gc.setColor(COLOR[WIDGET.sel==self and"Y"or"W"])
|
||||
gc.rectangle("fill",x-22,y+(h-len-6)*(scroll-cap)/(#texts-cap)+3,14,len)
|
||||
end
|
||||
|
||||
--Draw
|
||||
setFont(30)
|
||||
gc.setColor(1,1,1)
|
||||
--Clear button
|
||||
if not self.fix then
|
||||
mStr(self.sure>0 and"?"or"X",x+w-20,y-1)
|
||||
gc.rectangle("line",x+w-40,y,40,40)
|
||||
end
|
||||
--New message
|
||||
if self.new and self.scrollPos~=#texts then
|
||||
gc.setColor(1,TIME()%.4<.2 and 1 or 0,0)
|
||||
gc.print("v",x+w-25,y+h-40)
|
||||
end
|
||||
|
||||
--Texts
|
||||
setFont(self.font)
|
||||
for i=max(scroll-cap+1,1),scroll do
|
||||
gc.printf(texts[i],x+8,y+h-10-self.lineH*(scroll-i+1),w)
|
||||
end
|
||||
end
|
||||
function chatBox:getInfo()
|
||||
function textBox:getInfo()
|
||||
return format("x=%d,y=%d,w=%d,h=%d",self.x+self.w*.5,self.y+self.h*.5,self.w,self.h)
|
||||
end
|
||||
function WIDGET.newChatBox(D)--name,x,y,w[,h][,font],hide
|
||||
function WIDGET.newTextBox(D)--name,x,y,w,h[,font][,fix],hide
|
||||
local _={
|
||||
name= D.name,
|
||||
|
||||
@@ -930,11 +939,15 @@ function WIDGET.newChatBox(D)--name,x,y,w[,h][,font],hide
|
||||
w= D.w,
|
||||
h= D.h,
|
||||
|
||||
capacity=int((D.h-10)/30),
|
||||
font= D.font or 30,
|
||||
fix=D.fix,
|
||||
texts={},
|
||||
hide= D.hide,
|
||||
}
|
||||
for k,v in next,chatBox do _[k]=v end
|
||||
_.lineH=7*(_.font/5)
|
||||
_.capacity=int((D.h-10)/_.lineH)
|
||||
|
||||
for k,v in next,textBox do _[k]=v end
|
||||
setmetatable(_,widgetMetatable)
|
||||
return _
|
||||
end
|
||||
@@ -1001,7 +1014,7 @@ end
|
||||
function WIDGET.press(x,y)
|
||||
local W=WIDGET.sel
|
||||
if not W then return end
|
||||
if W.type=="button"or W.type=="key"or W.type=="switch"or W.type=="selector"or W.type=="textBox"or W.type=="chatBox"then
|
||||
if W.type=="button"or W.type=="key"or W.type=="switch"or W.type=="selector"or W.type=="inputBox"or W.type=="textBox"then
|
||||
W:press(x,y)
|
||||
elseif W.type=="slider"then
|
||||
WIDGET.drag(x,y)
|
||||
@@ -1011,7 +1024,7 @@ end
|
||||
function WIDGET.drag(x,y,dx,dy)
|
||||
local W=WIDGET.sel
|
||||
if not W then return end
|
||||
if W.type=="slider"or W.type=="chatBox"then
|
||||
if W.type=="slider"or W.type=="textBox"then
|
||||
W:drag(x,y,dx,dy)
|
||||
elseif not W:isAbove(x,y)then
|
||||
WIDGET.sel=false
|
||||
@@ -1073,7 +1086,7 @@ function WIDGET.keyPressed(k)
|
||||
end
|
||||
else
|
||||
local W=WIDGET.sel
|
||||
if W and W.type=="textBox"then
|
||||
if W and W.type=="inputBox"then
|
||||
W:keypress(k)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,49 +1,35 @@
|
||||
local gc=love.graphics
|
||||
local max,min=math.max,math.min
|
||||
|
||||
local scene={}
|
||||
|
||||
local texts--Text list
|
||||
local scrollPos--Scroll down length
|
||||
local inited
|
||||
|
||||
function scene.sceneInit()
|
||||
BG.set("cubes")
|
||||
texts=require"parts/updateLog"
|
||||
scrollPos=1
|
||||
if not inited then
|
||||
inited=true
|
||||
WIDGET.active.texts:setTexts(require"parts/updateLog")
|
||||
end
|
||||
if newVersionLaunch then
|
||||
newVersionLaunch=false
|
||||
scrollPos=3
|
||||
end
|
||||
end
|
||||
|
||||
function scene.wheelMoved(_,y)
|
||||
wheelScroll(y)
|
||||
end
|
||||
function scene.keyDown(key)
|
||||
if key=="up"then
|
||||
scrollPos=max(scrollPos-6,1)
|
||||
elseif key=="down"then
|
||||
scrollPos=min(scrollPos+6,#texts-22)
|
||||
elseif key=="escape"then
|
||||
SCN.back()
|
||||
end
|
||||
end
|
||||
|
||||
function scene.draw()
|
||||
gc.setColor(.2,.2,.2,.7)
|
||||
gc.rectangle("fill",30,45,1000,632)
|
||||
gc.setColor(1,1,1)
|
||||
gc.setLineWidth(4)
|
||||
gc.rectangle("line",30,45,1000,632)
|
||||
setFont(20)
|
||||
for i=0,22 do
|
||||
gc.print(texts[scrollPos+i],40,50+27*i)
|
||||
function scene.keyDown(k)
|
||||
if k=="up"then
|
||||
WIDGET.active.texts:scroll(-5)
|
||||
elseif k=="down"then
|
||||
WIDGET.active.texts:scroll(5)
|
||||
elseif k=="pgup"then
|
||||
WIDGET.active.texts:scroll(-20)
|
||||
elseif k=="pgdown"then
|
||||
WIDGET.active.texts:scroll(20)
|
||||
end
|
||||
end
|
||||
|
||||
scene.widgetList={
|
||||
WIDGET.newKey{name="prev", x=1155, y=170,w=180,fText="↑",font=65,code=pressKey"up",hide=function()return scrollPos==1 end},
|
||||
WIDGET.newKey{name="next", x=1155, y=400,w=180,fText="↓",font=65,code=pressKey"down",hide=function()return scrollPos==#texts end},
|
||||
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,font=40,code=backScene},
|
||||
}
|
||||
|
||||
|
||||
@@ -65,8 +65,8 @@ local scene={}
|
||||
scene.widgetList={
|
||||
WIDGET.newText{name="title", x=80, y=50,font=70,align="L"},
|
||||
-- WIDGET.newButton{name="register", x=1140, y=100,w=170,h=80,color="green",code=function()SCN.swapTo("register","swipeR")end},
|
||||
WIDGET.newTextBox{name="email", x=380, y=200,w=500,h=60,regex="[0-9A-Za-z@._-]"},
|
||||
WIDGET.newTextBox{name="password", x=380, y=300,w=626,h=60,secret=true,regex="[ -~]"},
|
||||
WIDGET.newInputBox{name="email", x=380, y=200,w=500,h=60,regex="[0-9A-Za-z@._-]"},
|
||||
WIDGET.newInputBox{name="password", x=380, y=300,w=626,h=60,secret=true,regex="[ -~]"},
|
||||
WIDGET.newKey{name="login", x=1140, y=540,w=170,h=80,font=40,code=login},
|
||||
WIDGET.newButton{name="back", x=1140, y=640,w=170,h=80,font=40,code=backScene},
|
||||
}
|
||||
|
||||
@@ -1,23 +1,16 @@
|
||||
local gc=love.graphics
|
||||
|
||||
local chatBox=WIDGET.newChatBox{name="texts",x=50,y=50,w=1200,h=430}
|
||||
local textBox=WIDGET.newTextBox{name="texts",x=40,y=50,w=1200,h=430}
|
||||
local remain--People in chat room
|
||||
local heartBeatTimer
|
||||
local escapeTimer=0
|
||||
|
||||
local function _init()
|
||||
coroutine.yield()
|
||||
WIDGET.sel=WIDGET.active.text
|
||||
local texts=chatBox.texts
|
||||
if #texts==0 then
|
||||
chatBox:push{COLOR.dG,text.chatStart}
|
||||
elseif #texts>1 and texts[#texts][1]~=COLOR.dG then
|
||||
chatBox:push{COLOR.dG,text.chatHistory}
|
||||
end
|
||||
chatBox:scroll(1)
|
||||
WIDGET.sel=WIDGET.active.input
|
||||
end
|
||||
local function sendMessage()
|
||||
local W=WIDGET.active.text
|
||||
local W=WIDGET.active.input
|
||||
if #W.value>0 and wsWrite("T"..W.value)then
|
||||
W.value=""
|
||||
end
|
||||
@@ -29,6 +22,13 @@ function scene.sceneInit()
|
||||
heartBeatTimer=0
|
||||
remain=false
|
||||
|
||||
local texts=textBox.texts
|
||||
if #texts==0 then
|
||||
textBox:push{COLOR.dG,text.chatStart}
|
||||
elseif #texts>1 and texts[#texts][1]~=COLOR.dG then
|
||||
textBox:push{COLOR.dG,text.chatHistory}
|
||||
end
|
||||
textBox:scroll(1)
|
||||
TASK.new(_init)--Widgets are not initialized, so active after 1 frame
|
||||
TASK.new(TICK_wsRead)
|
||||
BG.set("none")
|
||||
@@ -44,9 +44,9 @@ function scene.wheelMoved(_,y)
|
||||
end
|
||||
function scene.keyDown(k)
|
||||
if k=="up"then
|
||||
chatBox:scroll(-1)
|
||||
textBox:scroll(-1)
|
||||
elseif k=="down"then
|
||||
chatBox:scroll(1)
|
||||
textBox:scroll(1)
|
||||
elseif k=="return"then
|
||||
sendMessage()
|
||||
elseif k=="escape"then
|
||||
@@ -65,14 +65,14 @@ function scene.socketRead(mes)
|
||||
local cmd=mes:sub(1,1)
|
||||
local args=splitStr(mes:sub(2),":")
|
||||
if cmd=="J"or cmd=="L"then
|
||||
chatBox:push{
|
||||
textBox:push{
|
||||
COLOR.lR,args[1],
|
||||
COLOR.dY,args[2].." ",
|
||||
COLOR.Y,text[cmd=="J"and"chatJoin"or"chatLeave"]
|
||||
}
|
||||
remain=tonumber(args[3])
|
||||
elseif cmd=="T"then
|
||||
chatBox:push{
|
||||
textBox:push{
|
||||
COLOR.W,args[1],
|
||||
COLOR.dY,args[2].." ",
|
||||
COLOR.sky,args[3]
|
||||
@@ -98,7 +98,8 @@ function scene.draw()
|
||||
end
|
||||
|
||||
scene.widgetList={
|
||||
chatBox,
|
||||
textBox,
|
||||
WIDGET.newInputBox{name="input",x=40, y=500,w=980,h=180,font=40},
|
||||
WIDGET.newButton{name="send", x=1140, y=540,w=170,h=80,font=40,code=sendMessage},
|
||||
WIDGET.newButton{name="back", x=1140, y=640,w=170,h=80,font=40,code=backScene},
|
||||
}
|
||||
|
||||
@@ -63,10 +63,10 @@ end
|
||||
scene.widgetList={
|
||||
WIDGET.newText{name="title", x=80, y=50,font=70,align="L"},
|
||||
WIDGET.newButton{name="login", x=1140, y=100,w=170,h=80,color="green",code=function()SCN.swapTo("login","swipeL")end},
|
||||
WIDGET.newTextBox{name="username", x=380, y=200,w=500,h=60,regex="[0-9A-Za-z_]"},
|
||||
WIDGET.newTextBox{name="email", x=380, y=300,w=626,h=60,regex="[0-9A-Za-z@._-]"},
|
||||
WIDGET.newTextBox{name="password", x=380, y=400,w=626,h=60,secret=true,regex="[ -~]"},
|
||||
WIDGET.newTextBox{name="password2", x=380, y=500,w=626,h=60,secret=true,regex="[ -~]"},
|
||||
WIDGET.newInputBox{name="username", x=380, y=200,w=500,h=60,regex="[0-9A-Za-z_]"},
|
||||
WIDGET.newInputBox{name="email", x=380, y=300,w=626,h=60,regex="[0-9A-Za-z@._-]"},
|
||||
WIDGET.newInputBox{name="password", x=380, y=400,w=626,h=60,secret=true,regex="[ -~]"},
|
||||
WIDGET.newInputBox{name="password2", x=380, y=500,w=626,h=60,secret=true,regex="[ -~]"},
|
||||
WIDGET.newButton{name="back", x=1140, y=640,w=170,h=80,font=40,code=backScene},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user