罗盘时钟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 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)

相关推荐
上位机妹子12 分钟前
C 语言 数组删除指定元素(快慢指针法)
c语言·数据结构·算法
郝学胜-神的一滴2 小时前
C++ Templates 01:拨开迷雾,读懂C++模板经典著作
开发语言·c++·程序人生·游戏·游戏引擎·软件构建
C++ 老炮儿的技术栈3 小时前
有符号变量与无符号变量的区别
服务器·开发语言·前端·数据结构·c++·算法·c
Martina_03214 小时前
AI生成3D场景第一次进入总卡一下?用6步排查Shader编译、纹理上传与预加载
图像处理·人工智能·游戏·3d·ai·自然语言处理·游戏策划
keyipatience4 小时前
跳表详细解析
开发语言·数据结构·c++·算法·跳表
小小、码农4 小时前
〖Linux文件系统〗:彻底打通文件 IO 全链路
linux·开发语言·数据结构·c++·系统
INGNIGHT6 小时前
1897 · 会议室 3(扫描线)
数据结构·算法
All for pursuit.6 小时前
【贪心-2】253.会议室 II
数据结构·c++·算法·leetcode
开开心心_Every6 小时前
文件夹批量创建工具支持同级和多层级
运维·服务器·游戏·jupyter·智能手机·pdf·postman
Logic1019 小时前
C语言/数据结构字符串题解:按字符类型重排(数字→字母→符号)——三趟扫描稳定分区
c语言·数据结构·字符串·时间复杂度·计数排序·算法题·ascii