罗盘时钟lua迷你世界

--罗盘时钟

--星空露珠工作室制作

--作者:韩永旗

--数字换中文

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 zhChar[num]

elseif num>=10 then

if num==10 then return '十' end

if num%10==0 then return zhChar[math.floor(num/10)]..'十'

elseif num>10 and num<20 then return '十'..zhChar[num%10]

else return zhChar[math.floor(num/10)]..'十'..zhChar[num%10]

end

end

end

-- 测试一下:(禁用002)

--print(formatNumber(20))

迷你世界监听函数方便使用

local ui={'7382219973642268578','7382219973642268578_'}

--设置元件图片

local function setgip(p,id,url) Customui:setTexture(p,ui[1],ui[2]..id,url) end

--设置元件大小

local function setsize(p,id,d,h) Coustomui:setSize(p,ui[1],ui[2]..id,d,h) end

--设置元件位置

local function setpos(p,id,x,y) Trigger.UI:setPosition(p,ui[1],ui[2]..id,x,y) end

--设置元件颜色

local function setcolor(p,id,color) Trigger.UI:setColor(p,ui[1],ui[2]..id,color) end

--显示元件

local function show(p,id) Trigger.UI:showElement(p,ui[1],ui[2]..id) end

--隐藏元件

local function hide(p,id) Trigger.UI:hideElement(p,ui[1],ui[2]..id) end

--设置文字框

local function setstr(p,id,str) Trigger.UI:setText(p,ui[1],ui[2]..id,str) end

--设置元件文字大小

local function setfontsize(p,id,size) Trigger.UI:setFontSize(p, ui[1],ui[2]..id,size) end

--旋转元件

local function rotate(p,pi) Customui:rotateElement(p,ui[1],ui[2]..button.rotate1,pi) Trigger.UI:setText(p,ui[1],ui[2]..button.rotate2,pi) end

--元件平滑旋转到指定角度

local function smoothrotateto(p,id,time,angle) Customui:SmoothRotateTo(p,ui[1],ui[2]..id,time,angle) end

--元件平滑旋转到相对角度

local function smoothrotateby(p,id,time,angle) Customui:SmoothRotateBy(p,ui[1],ui[2]..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=ui0[k]

show(p,id)

setpos(p,id,0,0)

setsize(p,id,0,0)

local str=''

for i=v[2],v[3] do if v[1]=='星期' then if i==1 then str=v[1]..'日' else str=v[1]..formatNumber(i-1) end else str=formatNumber(i)..v[1] end

local id=ui0[k]+i+v[5]

local color=Trigger.Graphics:getRandomColor()

local angle=-(i+v[5]-1)*v[4]

show(p,id)

setpos(p,id,0,0)

setsize(p,id,v[6],20)

setstr(p,id,str)

setcolor(p,id,color)

setfontsize(p,id,v[7])

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.."日"..B[t.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=ui0[k]

local angle=(time[k]+v[5]-1)*v[4]

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)

相关推荐
Kalika0-08 分钟前
猴子吃桃-C语言
c语言·开发语言·数据结构·算法
代码雕刻家25 分钟前
课设实验-数据结构-单链表-文教文化用品品牌
c语言·开发语言·数据结构
小字节,大梦想2 小时前
【C++】二叉搜索树
数据结构·c++
我是哈哈hh2 小时前
专题十_穷举vs暴搜vs深搜vs回溯vs剪枝_二叉树的深度优先搜索_算法专题详细总结
服务器·数据结构·c++·算法·机器学习·深度优先·剪枝
丶Darling.3 小时前
LeetCode Hot100 | Day1 | 二叉树:二叉树的直径
数据结构·c++·学习·算法·leetcode·二叉树
labuladuo5203 小时前
Codeforces Round 977 (Div. 2) C2 Adjust The Presentation (Hard Version)(思维,set)
数据结构·c++·算法
Indigo_code3 小时前
【数据结构】【链表代码】合并有序链表
数据结构·windows·链表
jiyisuifeng19913 小时前
代码随想录训练营第54天|单调栈+双指针
数据结构·算法
我言秋日胜春朝★3 小时前
【C++】红黑树
数据结构
科技资讯早知道3 小时前
java计算机毕设课设—坦克大战游戏
java·开发语言·游戏·毕业设计·课程设计·毕设