Custom image from clipboard (#1157)
* Update how text renders in button and key * Add a placeholder * Add actual code and language entry * Sort buttons * Alter to keep original behaviour * I HAVE OCD * Add back legacy behaviour
This commit is contained in:
@@ -15,6 +15,7 @@ local timer=love.timer.getTime
|
|||||||
local next=next
|
local next=next
|
||||||
local floor,ceil=math.floor,math.ceil
|
local floor,ceil=math.floor,math.ceil
|
||||||
local max,min=math.max,math.min
|
local max,min=math.max,math.min
|
||||||
|
local match=string.match
|
||||||
local sub,ins,rem=string.sub,table.insert,table.remove
|
local sub,ins,rem=string.sub,table.insert,table.remove
|
||||||
local xOy=SCR.xOy
|
local xOy=SCR.xOy
|
||||||
local FONT=FONT
|
local FONT=FONT
|
||||||
@@ -142,13 +143,21 @@ local button={
|
|||||||
type='button',
|
type='button',
|
||||||
mustHaveText=true,
|
mustHaveText=true,
|
||||||
ATV=0,-- Activating time(0~8)
|
ATV=0,-- Activating time(0~8)
|
||||||
|
textAlreadyWrapped=false,-- Text already wrapped? (Managed by :setObject, can be override, this will be true if obj has a '\n')
|
||||||
}
|
}
|
||||||
function button:reset()
|
function button:reset()
|
||||||
self.ATV=0
|
self.ATV=0
|
||||||
end
|
end
|
||||||
function button:setObject(obj)
|
function button:setObject(obj)
|
||||||
if type(obj)=='string' or type(obj)=='number' then
|
if type(obj)=='string' or type(obj)=='number' then
|
||||||
self.obj=gc.newText(FONT.get(self.font,self.fType),obj)
|
if match(obj,"\n") then
|
||||||
|
self.textAlreadyWrapped=true
|
||||||
|
self.obj=gc.newText(FONT.get(self.font,self.fType))
|
||||||
|
self.obj:addf(obj,self.w-self.edge*2,(self.align=='L' and 'left') or (self.align=='R' and 'right') or 'center')
|
||||||
|
else
|
||||||
|
self.textAlreadyWrapped=false
|
||||||
|
self.obj=gc.newText(FONT.get(self.font,self.fType),obj)
|
||||||
|
end
|
||||||
elseif obj then
|
elseif obj then
|
||||||
self.obj=obj
|
self.obj=obj
|
||||||
end
|
end
|
||||||
@@ -194,16 +203,7 @@ function button:draw()
|
|||||||
local ox,oy=obj:getWidth()*.5,obj:getHeight()*.5
|
local ox,oy=obj:getWidth()*.5,obj:getHeight()*.5
|
||||||
local y0=y+h*.5
|
local y0=y+h*.5
|
||||||
gc_setColor(1,1,1,.2+ATV*.05)
|
gc_setColor(1,1,1,.2+ATV*.05)
|
||||||
if self.align=='M' then
|
if self.align=='L' or self.textAlreadyWrapped then
|
||||||
local x0=x+w*.5
|
|
||||||
local kx=obj:type()=='Text' and min(w/ox/2,1) or 1
|
|
||||||
gc_draw(obj,x0-1,y0-1,nil,kx,1,ox,oy)
|
|
||||||
gc_draw(obj,x0-1,y0+1,nil,kx,1,ox,oy)
|
|
||||||
gc_draw(obj,x0+1,y0-1,nil,kx,1,ox,oy)
|
|
||||||
gc_draw(obj,x0+1,y0+1,nil,kx,1,ox,oy)
|
|
||||||
gc_setColor(r*.55,g*.55,b*.55)
|
|
||||||
gc_draw(obj,x0,y0,nil,kx,1,ox,oy)
|
|
||||||
elseif self.align=='L' then
|
|
||||||
local edge=self.edge
|
local edge=self.edge
|
||||||
gc_draw(obj,x+edge-1,y0-1-oy)
|
gc_draw(obj,x+edge-1,y0-1-oy)
|
||||||
gc_draw(obj,x+edge-1,y0+1-oy)
|
gc_draw(obj,x+edge-1,y0+1-oy)
|
||||||
@@ -219,6 +219,15 @@ function button:draw()
|
|||||||
gc_draw(obj,x0+1,y0+1-oy)
|
gc_draw(obj,x0+1,y0+1-oy)
|
||||||
gc_setColor(r*.55,g*.55,b*.55)
|
gc_setColor(r*.55,g*.55,b*.55)
|
||||||
gc_draw(obj,x0,y0-oy)
|
gc_draw(obj,x0,y0-oy)
|
||||||
|
else--if self.align=='M' then
|
||||||
|
local x0=x+w*.5
|
||||||
|
local kx=obj:type()=='Text' and min(w/ox/2,1) or 1
|
||||||
|
gc_draw(obj,x0-1,y0-1,nil,kx,1,ox,oy)
|
||||||
|
gc_draw(obj,x0-1,y0+1,nil,kx,1,ox,oy)
|
||||||
|
gc_draw(obj,x0+1,y0-1,nil,kx,1,ox,oy)
|
||||||
|
gc_draw(obj,x0+1,y0+1,nil,kx,1,ox,oy)
|
||||||
|
gc_setColor(r*.55,g*.55,b*.55)
|
||||||
|
gc_draw(obj,x0,y0,nil,kx,1,ox,oy)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function button:getInfo()
|
function button:getInfo()
|
||||||
@@ -290,13 +299,21 @@ local key={
|
|||||||
type='key',
|
type='key',
|
||||||
mustHaveText=true,
|
mustHaveText=true,
|
||||||
ATV=0,-- Activating time(0~4)
|
ATV=0,-- Activating time(0~4)
|
||||||
|
textAlreadyWrapped=false,---See button.setObject (line 146)
|
||||||
}
|
}
|
||||||
function key:reset()
|
function key:reset()
|
||||||
self.ATV=0
|
self.ATV=0
|
||||||
end
|
end
|
||||||
function key:setObject(obj)
|
function key:setObject(obj)
|
||||||
if type(obj)=='string' or type(obj)=='number' then
|
if type(obj)=='string' or type(obj)=='number' then
|
||||||
self.obj=gc.newText(FONT.get(self.font,self.fType),obj)
|
if match(obj,"\n") then
|
||||||
|
self.textAlreadyWrapped=true
|
||||||
|
self.obj=gc.newText(FONT.get(self.font,self.fType))
|
||||||
|
self.obj:addf(obj,self.w-self.edge*2,(self.align=='L' and 'left') or (self.align=='R' and 'right') or 'center')
|
||||||
|
else
|
||||||
|
self.textAlreadyWrapped=false
|
||||||
|
self.obj=gc.newText(FONT.get(self.font,self.fType),obj)
|
||||||
|
end
|
||||||
elseif obj then
|
elseif obj then
|
||||||
self.obj=obj
|
self.obj=obj
|
||||||
end
|
end
|
||||||
@@ -354,14 +371,15 @@ function key:draw()
|
|||||||
-- Drawable
|
-- Drawable
|
||||||
local obj=self.obj
|
local obj=self.obj
|
||||||
local ox,oy=obj:getWidth()*.5,obj:getHeight()*.5
|
local ox,oy=obj:getWidth()*.5,obj:getHeight()*.5
|
||||||
|
|
||||||
gc_setColor(r,g,b)
|
gc_setColor(r,g,b)
|
||||||
if align=='M' then
|
if align=='L' or self.textAlreadyWrapped then
|
||||||
local kx=obj:type()=='Text' and min(w/ox/2,1) or 1
|
gc_draw(obj,x+self.edge,y+h*.5-oy)
|
||||||
gc_draw(obj,x+w*.5,y+h*.5,nil,kx,1,ox,oy)
|
|
||||||
elseif align=='L' then
|
|
||||||
gc_draw(obj,x+self.edge,y-oy+h*.5)
|
|
||||||
elseif align=='R' then
|
elseif align=='R' then
|
||||||
gc_draw(obj,x+w-self.edge-ox*2,y-oy+h*.5)
|
gc_draw(obj,x+w-self.edge-ox*2,y-oy+h*.5)
|
||||||
|
else--if align=='M' then
|
||||||
|
local kx=obj:type()=='Text' and min(w/ox/2,1) or 1
|
||||||
|
gc_draw(obj,x+w*.5,y+h*.5,nil,kx,1,ox,oy)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function key:getInfo()
|
function key:getInfo()
|
||||||
@@ -1382,10 +1400,13 @@ function WIDGET.setLang(widgetText)
|
|||||||
t=W.name or "##"
|
t=W.name or "##"
|
||||||
W.color=COLOR.dV
|
W.color=COLOR.dV
|
||||||
end
|
end
|
||||||
if type(t)=='string' and W.font then
|
if type(W.setObject)=='function' then
|
||||||
t=gc.newText(FONT.get(W.font),t)
|
W:setObject(t)
|
||||||
|
elseif type(t)=='string' and W.font then
|
||||||
|
W.obj=gc.newText(FONT.get(W.font or 30),t)
|
||||||
|
else
|
||||||
|
W.obj=t
|
||||||
end
|
end
|
||||||
W.obj=t
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -587,6 +587,7 @@ C. Gamepad
|
|||||||
bg_on="Normal BG",
|
bg_on="Normal BG",
|
||||||
bg_off="No BG",
|
bg_off="No BG",
|
||||||
bg_custom="Custom BG",
|
bg_custom="Custom BG",
|
||||||
|
bg_custom_base64="Paste image as BG\n(PNG/JPG in Base64)",
|
||||||
defaultBG="Default BG",
|
defaultBG="Default BG",
|
||||||
resetDbg="Reset to default",
|
resetDbg="Reset to default",
|
||||||
lockBG="Lock BG",
|
lockBG="Lock BG",
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ return {
|
|||||||
|
|
||||||
|
|
||||||
keySettingInstruction="Nhấn một phím để gán phím đó\nescape (esc): Hủy\nbackspace: Xoá",
|
keySettingInstruction="Nhấn một phím để gán phím đó\nescape (esc): Hủy\nbackspace: Xoá",
|
||||||
customBGhelp=not MOBILE and "Kéo một tấm ảnh vào đây để áp dụng ảnh nền tuỳ chỉnh" or "Chưa hỗ trợ ảnh nền cho điện thoại",
|
customBGhelp="Kéo một tấm ảnh vào đây để áp dụng ảnh nền tuỳ chỉnh",
|
||||||
customBGloadFailed="Định dạng ảnh không được hỗ trợ",
|
customBGloadFailed="Định dạng ảnh không được hỗ trợ",
|
||||||
|
|
||||||
errorMsg="Techmino bị lỗi và cần phải được khởi động lại\nBạn có thể gửi error log để giúp dev sửa game nhanh hơn.",
|
errorMsg="Techmino bị lỗi và cần phải được khởi động lại\nBạn có thể gửi error log để giúp dev sửa game nhanh hơn.",
|
||||||
@@ -583,6 +583,7 @@ C. Tay cầm chơi game (Gamepad):
|
|||||||
bg_on="Ảnh nền thường",
|
bg_on="Ảnh nền thường",
|
||||||
bg_off="Không ảnh nền",
|
bg_off="Không ảnh nền",
|
||||||
bg_custom="Ảnh nền tự chọn",
|
bg_custom="Ảnh nền tự chọn",
|
||||||
|
bg_custom_base64="Dán ảnh và cài thành ảnh nền\n(PNG/JPG ở format Base64)",
|
||||||
defaultBG="Nền mặc định",
|
defaultBG="Nền mặc định",
|
||||||
resetDbg='Đặt lại',
|
resetDbg='Đặt lại',
|
||||||
lockBG="Khóa ảnh nền",
|
lockBG="Khóa ảnh nền",
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ function scene.draw()
|
|||||||
gc.push('transform')
|
gc.push('transform')
|
||||||
gc.setColor(1,1,1)
|
gc.setColor(1,1,1)
|
||||||
local T=skinLib[1]
|
local T=skinLib[1]
|
||||||
gc.translate(-200,1410-WIDGET.scrollPos) -- -200
|
gc.translate(0,1610-WIDGET.scrollPos)
|
||||||
gc.setShader(SHADER.blockSatur)
|
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.draw(T,435,0)gc.draw(T,465,0)gc.draw(T,465,30)gc.draw(T,495,30)
|
||||||
gc.setShader(SHADER.fieldSatur)
|
gc.setShader(SHADER.fieldSatur)
|
||||||
@@ -50,7 +50,7 @@ local function _msaaShow(S)
|
|||||||
return S==0 and 0 or 2^S
|
return S==0 and 0 or 2^S
|
||||||
end
|
end
|
||||||
|
|
||||||
scene.widgetScrollHeight=900
|
scene.widgetScrollHeight=1200
|
||||||
scene.widgetList={
|
scene.widgetList={
|
||||||
WIDGET.newText{name='title', x=640,y=15,lim=630,font=80},
|
WIDGET.newText{name='title', x=640,y=15,lim=630,font=80},
|
||||||
|
|
||||||
@@ -93,9 +93,9 @@ scene.widgetList={
|
|||||||
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.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.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=1290,w=200,h=60,code=function() SETTING.bg='on' ; applySettings() end},
|
WIDGET.newKey{name='bg_on', x=680,y=1290,w=200,h=60,font=25,code=function() SETTING.bg='on' ; applySettings() end},
|
||||||
WIDGET.newKey{name='bg_off', x=900,y=1290,w=200,h=60,code=function() SETTING.bg='off'; applySettings() end},
|
WIDGET.newKey{name='bg_off', x=900,y=1290,w=200,h=60,font=25,code=function() SETTING.bg='off'; applySettings() end},
|
||||||
WIDGET.newKey{name='bg_custom', x=1120,y=1290,w=200,h=60,
|
WIDGET.newKey{name='bg_custom', x=1120,y=1290,w=200,h=60,font=25,
|
||||||
code=function()
|
code=function()
|
||||||
if love.filesystem.getInfo('conf/customBG') then
|
if love.filesystem.getInfo('conf/customBG') then
|
||||||
SETTING.bg='custom'
|
SETTING.bg='custom'
|
||||||
@@ -117,7 +117,7 @@ scene.widgetList={
|
|||||||
end,
|
end,
|
||||||
hideF=function() return SETTING.bg=='on' end
|
hideF=function() return SETTING.bg=='on' end
|
||||||
},
|
},
|
||||||
WIDGET.newSelector{name='defaultBG', x=680,y=1365,w=200,color='G',
|
WIDGET.newSelector{name='defaultBG', x=680,y=1465,w=200,color='G',
|
||||||
list={'space','bg1','bg2','rainbow','rainbow2','aura','rgb','glow','matrix','cubes','tunnel','galaxy','quarks','blockfall','blockrain','blockhole','blockspace'},
|
list={'space','bg1','bg2','rainbow','rainbow2','aura','rgb','glow','matrix','cubes','tunnel','galaxy','quarks','blockfall','blockrain','blockhole','blockspace'},
|
||||||
disp=SETval('defaultBG'),
|
disp=SETval('defaultBG'),
|
||||||
code=function(v)
|
code=function(v)
|
||||||
@@ -126,7 +126,7 @@ scene.widgetList={
|
|||||||
end,
|
end,
|
||||||
hideF=function() return SETTING.bg~='on' end
|
hideF=function() return SETTING.bg~='on' end
|
||||||
},
|
},
|
||||||
WIDGET.newKey{name='resetDbg',x=870,y=1365,w=140,h=60,font=15,
|
WIDGET.newKey{name='resetDbg',x=680,y=1540,w=200,h=60,font=20,
|
||||||
code=function()
|
code=function()
|
||||||
SETTING.defaultBG='space'
|
SETTING.defaultBG='space'
|
||||||
scene.widgetList.defaultBG:reset()
|
scene.widgetList.defaultBG:reset()
|
||||||
@@ -134,7 +134,20 @@ scene.widgetList={
|
|||||||
end,
|
end,
|
||||||
hideF=function() return SETTING.bg~='on' or SETTING.defaultBG=='space' end
|
hideF=function() return SETTING.bg~='on' or SETTING.defaultBG=='space' end
|
||||||
},
|
},
|
||||||
WIDGET.newSwitch{name='lockBG',x=1170,y=1365,lim=200,
|
WIDGET.newKey{name='bg_custom_base64',x=1010,y=1502.5,w=420,h=135,align='M',
|
||||||
|
code=function()
|
||||||
|
local okay,data=pcall(love.data.decode,"data","base64",love.system.getClipboardText())
|
||||||
|
if okay and pcall(gc.newImage,data) then
|
||||||
|
love.filesystem.write('conf/customBG',data)
|
||||||
|
SETTING.bg='custom'
|
||||||
|
applySettings()
|
||||||
|
else
|
||||||
|
MES.new('error',text.customBGloadFailed)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
-- hideF=function() return SETTING.bg=='off' end
|
||||||
|
},
|
||||||
|
WIDGET.newSwitch{name='lockBG',x=450,y=1465,lim=200,
|
||||||
disp=SETval('lockBG'),
|
disp=SETval('lockBG'),
|
||||||
code=function()
|
code=function()
|
||||||
SETTING.lockBG=not SETTING.lockBG
|
SETTING.lockBG=not SETTING.lockBG
|
||||||
@@ -143,7 +156,7 @@ scene.widgetList={
|
|||||||
hideF=function() return SETTING.bg~='on' end
|
hideF=function() return SETTING.bg~='on' end
|
||||||
},
|
},
|
||||||
|
|
||||||
WIDGET.newSwitch{name='noTheme',x=1170,y=1435,
|
WIDGET.newSwitch{name='noTheme',x=450,y=1540,
|
||||||
disp=SETval('noTheme'),
|
disp=SETval('noTheme'),
|
||||||
code=function()
|
code=function()
|
||||||
SETTING.noTheme=not SETTING.noTheme
|
SETTING.noTheme=not SETTING.noTheme
|
||||||
@@ -159,12 +172,12 @@ scene.widgetList={
|
|||||||
end
|
end
|
||||||
},
|
},
|
||||||
|
|
||||||
WIDGET.newSelector{name='blockSatur', x=600,y=1440,w=300,color='lN',
|
WIDGET.newSelector{name='blockSatur', x=800,y=1640,w=300,color='lN',
|
||||||
list={'normal','soft','gray','light','color'},
|
list={'normal','soft','gray','light','color'},
|
||||||
disp=SETval('blockSatur'),
|
disp=SETval('blockSatur'),
|
||||||
code=function(v) SETTING.blockSatur=v; applySettings() end
|
code=function(v) SETTING.blockSatur=v; applySettings() end
|
||||||
},
|
},
|
||||||
WIDGET.newSelector{name='fieldSatur', x=600,y=1540,w=300,color='lN',
|
WIDGET.newSelector{name='fieldSatur', x=800,y=1740,w=300,color='lN',
|
||||||
list={'normal','soft','gray','light','color'},
|
list={'normal','soft','gray','light','color'},
|
||||||
disp=SETval('fieldSatur'),
|
disp=SETval('fieldSatur'),
|
||||||
code=function(v) SETTING.fieldSatur=v; applySettings() end
|
code=function(v) SETTING.fieldSatur=v; applySettings() end
|
||||||
|
|||||||
Reference in New Issue
Block a user