时间罗盘小界面模组

--星空露珠工作室制作

--时间罗盘

--作者韩永旗

--作者迷你号247312290

--罗盘时钟

--星空露珠工作室制作

--数字换中文

local Script = {}

local ui={"7578885190391279522-144925","7578885190391279522-144925_"}

--显示框 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},}

-- 组件启动时调用

function Script:OnStart()

-- self:AddTriggerEvent(TriggerEvent.UIButtonClick, self:OnUIButtonClick, "元件id")

self:AddTriggerEvent(TriggerEvent.GameAnyPlayerEnterGame, self.uiplayer)

end

local zhChar = {'一','二','三','四','五','六','七','八','九'}

function Script: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

--设置元件图片

function Script:setgip(p,id,url) CustomUI:SetTexture(p,ui[1],ui[2]..id,url) end

--设置元件大小

function Script:setsize(p,id,d,h) CustomUI:SetSize(p,ui[1],ui[2]..id,d,h) end

--设置元件位置

function Script:setpos(p,id,x,y) CustomUI:SetPosition(p,ui[1],ui[2]..id,x,y) end

--设置元件颜色

function Script:setcolor(p,id,color) CustomUI:SetColor(p,ui[1],ui[2]..id,color) end

--显示元件

function Script:show(p,id) CustomUI:ShowElement(p,ui[1],ui[2]..id) end

--隐藏元件

function Script:hide(p,id) CustomUI:HideElement(p,ui[1],ui[2]..id) end

--设置文字框

function Script:setstr(p,id,str) CustomUI:SetText(p,ui[1],ui[2]..id,str) end

--设置元件文字大小

function Script:setfontsize(p,id,size) CustomUI:SetFontSize(p, ui[1],ui[2]..id,size) end

--旋转元件

function Script: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

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

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

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

function Script:smoothrotateby(p,id,time,angle) CustomUI:SmoothRotateBy(p,ui[1],ui[2]..id,time,angle) end

--播放声音

function Script:music(p) Actor:PlaySoundEffectById(p,10948,15,1,false) end

--绘画界面

function Script:upui(p)

self:show(p,1)

--self:setpos(p,1,0,0)

self:setsize(p,1,0,0)

self:show(p,2)

self:setpos(p,2,-20,0)

self:setsize(p,2,400,25)

self:show(p,228)

self:setpos(p,228,-15,0)

self:setsize(p,228,70,20)

local t=os.date("*t",timeInterval)

self:setstr(p,228,t.year.."年")

self:setfontsize(p,228,15)

for k,v in pairs(data) do

local id=ui0[k]

self:show(p,id)

self:setpos(p,id,0,0)

self: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]..'日' elseif i==6 then str='星期伍' else str=v[1]..self:formatNumber(i-1) end else str=self:formatNumber(i)..v[1] end

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

--local color=Graphics:getRandomColor()

local color=string.format("0x%x",math.random(0,255))..string.format("%x",math.random(0,255))..string.format("%x",math.random(0,255))

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

self:show(p,id)

self:setpos(p,id,0,0)

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

self:setstr(p,id,str)

self:setcolor(p,id,color)

self:setfontsize(p,id,v[7])

self:smoothrotateto(p,id,4,angle)

end

self:ThreadWait(3)

end

self:ThreadWait(1)

self:uptime(p)

end

function Script:uptime(p)

threadpool:work(function()

local t=os.date("*t",timeInterval)

--print('当前时间:'..t.year.."年"..t.month.."月"..t.day.."日"..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]

threadpool:work(function() self:smoothrotateto(p,id,0.5,angle) end)

end

end)

self:music(p)

self:ThreadWait(1)

self:uptime(p)

end

function Script:uiplayer(e)

local p=e.CurEventParam.TriggerByPlayer

threadpool:work(function() self:upui(p) end)

end

--print(string.format("0x%x",math.random(0,255))..string.format("%x",math.random(0,255))..string.format("%x",math.random(0,255)))

return Script

相关推荐
qiqsevenqiqiqiqi1 分钟前
字符串模板
算法
十五年专注C++开发2 分钟前
Oat++: 一个轻量级、高性能、零依赖的 C++ Web 框架
开发语言·c++·web服务·oatpp
陈天伟教授3 分钟前
心电心音同步分析-案例:原型设计一
开发语言·人工智能·python·语言模型·架构
Allen_LVyingbo6 分钟前
量子计算Dirac Notation基本教学—从零基础到读懂量子信息论文(下)
开发语言·人工智能·python·数学建模·量子计算
Fcy64811 分钟前
算法基础详解(六)倍增思想与离散化思想
算法·快速幂·离散化·倍增算法
上海合宙LuatOS12 分钟前
LuatOS扩展库API——【exmodbus】MODBUS协议
物联网·lua·luatos
wjs202413 分钟前
Ruby File 类和方法
开发语言
xyq202417 分钟前
API 类别 - UI 核心
开发语言
wuweijianlove25 分钟前
算法调度问题中的代价模型与优化方法的技术5
算法
Dxy123931021630 分钟前
Python路径算法简介
开发语言·python·算法