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

相关推荐
雾里看山8 分钟前
顺序表VS单链表VS带头双向循环链表
数据结构·链表
好好研究3 小时前
学习栈和队列的插入和删除操作
数据结构·学习
Luna-player5 小时前
黑布淡入淡出效果
经验分享·游戏
挺菜的5 小时前
【算法刷题记录(简单题)003】统计大写字母个数(java代码实现)
java·数据结构·算法
2401_858286116 小时前
125.【C语言】数据结构之归并排序递归解法
c语言·开发语言·数据结构·算法·排序算法·归并排序
双叶8367 小时前
(C++)学生管理系统(正式版)(map数组的应用)(string应用)(引用)(文件储存的应用)(C++教学)(C++项目)
c语言·开发语言·数据结构·c++
学不动CV了10 小时前
数据结构---链表结构体、指针深入理解(三)
c语言·arm开发·数据结构·stm32·单片机·链表
算法_小学生12 小时前
LeetCode 287. 寻找重复数(不修改数组 + O(1) 空间)
数据结构·算法·leetcode
Wo3Shi4七14 小时前
哈希冲突
数据结构·算法·go
V我五十买鸡腿15 小时前
顺序栈和链式栈
c语言·数据结构·笔记·算法