--罗盘时钟
--星空露珠工作室制作
--作者:韩永旗
--数字换中文
local zhChar = {'一','二','三','四','五','六','七','八','九'}
function formatNumber( num )
if type(num)~='number' then return num..'is not a num' end
if num>99 then return num..'不是两位数' end
if num==0 then return '零'
elseif num>0 and num<10 then return zhCharnum
elseif num>=10 then
if num==10 then return '十' end
if num%10==0 then return zhCharmath.floor(num/10)..'十'
elseif num>10 and num<20 then return '十'..zhCharnum%10
else return zhCharmath.floor(num/10)..'十'..zhCharnum%10
end
end
end
-- 测试一下:(禁用002)
--print(formatNumber(20))
迷你世界监听函数方便使用
local ui={'7382219973642268578','7382219973642268578_'}
--设置元件图片
local function setgip(p,id,url) Customui:setTexture(p,ui1,ui2..id,url) end
--设置元件大小
local function setsize(p,id,d,h) Coustomui:setSize(p,ui1,ui2..id,d,h) end
--设置元件位置
local function setpos(p,id,x,y) Trigger.UI:setPosition(p,ui1,ui2..id,x,y) end
--设置元件颜色
local function setcolor(p,id,color) Trigger.UI:setColor(p,ui1,ui2..id,color) end
--显示元件
local function show(p,id) Trigger.UI:showElement(p,ui1,ui2..id) end
--隐藏元件
local function hide(p,id) Trigger.UI:hideElement(p,ui1,ui2..id) end
--设置文字框
local function setstr(p,id,str) Trigger.UI:setText(p,ui1,ui2..id,str) end
--设置元件文字大小
local function setfontsize(p,id,size) Trigger.UI:setFontSize(p, ui1,ui2..id,size) end
--旋转元件
local function rotate(p,pi) Customui:rotateElement(p,ui1,ui2..button.rotate1,pi) Trigger.UI:setText(p,ui1,ui2..button.rotate2,pi) end
--元件平滑旋转到指定角度
local function smoothrotateto(p,id,time,angle) Customui:SmoothRotateTo(p,ui1,ui2..id,time,angle) end
--元件平滑旋转到相对角度
local function smoothrotateby(p,id,time,angle) Customui:SmoothRotateBy(p,ui1,ui2..id,time,angle) end
--播放声音
local function music(p) Player:playMusic(p,10948,50,1,false) end
等待时间
local function wait(time)
local v1 = time
if logidx then
Trigger.Debug:ReportActionRunData(logidx, status_idx, 1, v1)
end
if v1 == nil then
print("-- func_1 Warnning -- param is nil:", v1)
return
end
if Trigger and Trigger.wait then
return Trigger:wait(v1)
end
end
设置参数大小数量文字位置
--显示框 2 年份228 节日158
local ui0={3,64,125,150,183,215}
local data={{'秒',0,59,6,1,370, 15},{'分',0,59,6,1,300, 14},{'时',0,23,15,1,235, 13},{'星期',1,7,45,0,185, 13},{'号',1,31,11.25,0,135, 12},{'月',1,12,30,0,75, 13},}
设置界面大小位置
local p=247312290
local function upui(p)
show(p,1)
-- setpos(p,1,0,0)
setsize(p,1,0,0)
show(p,2)
setpos(p,2,-20,0)
setsize(p,2,400,25)
show(p,228)
setpos(p,228,-15,0)
setsize(p,228,70,20)
setstr(p,228,'2024年')
setfontsize(p,228,15)
设置秒分时等等 日期界面
for k,v in pairs(data) do
local id=ui0k
show(p,id)
setpos(p,id,0,0)
setsize(p,id,0,0)
local str=''
for i=v2,v3 do if v1=='星期' then if i==1 then str=v1..'日' else str=v1..formatNumber(i-1) end else str=formatNumber(i)..v1 end
local id=ui0k+i+v5
local color=Trigger.Graphics:getRandomColor()
local angle=-(i+v5-1)*v4
show(p,id)
setpos(p,id,0,0)
setsize(p,id,v6,20)
setstr(p,id,str)
setcolor(p,id,color)
setfontsize(p,id,v7)
smoothrotateto(p,id,4,angle)
end
wait(3)
end
wait(1)
uptime(p)
end
每秒加一时间角度换算刷新界面
function uptime(p)
local t=os.date("*t",timeInterval)
--print('当前时间:'..t.year.."年"..t.month.."月"..t.day.."日"..Bt.wday..t.hour..":"..t.min ..":"..t.sec)
local time={t.sec,t.min,t.hour,t.wday,t.day,t.month,t.year}
for k,v in pairs(data) do
local id=ui0k
local angle=(timek+v5-1)*v4
smoothrotateto(p,id,0.6,angle)
end
music(p)
wait(1)
uptime(p)
end
玩家进入游戏执行
local function EventMain_1(e)
local p=e.eventobjid
upui(p)
end
ScriptSupportEvent:registerEvent_NoError('Game.AnyPlayer.EnterGame', EventMain_1)