arklr73021 发表于 2025-4-25 16:09:31

前端GUI库随手小练

<pre><code>SL:Print(&quot;跳过来了5&quot;)
-- 客户端注册 接收消息
local function networkCB(msgID, p1, p2, p3, msgData)
    -- SL:Print(&quot;客户端的协议--&quot;..msgID, p1, p2, p3, msgData)
    if msgID == 100 then
      parent = GUI:Win_Create(&quot;Win_1&quot;, 0, 0, 600, 800) --创建一个父节点(parent)
      GUI:LoadExport(parent, &quot;cq_best&quot;) --将模块里的代码内容挂载到父节点下面.参数1:父节点 参数2:模块文件名
      local ui = GUI:ui_delegate(parent) -- 获取父节点下所有的快捷子控件组
      GUI:Win_SetDrag(parent, ui.ImageView)
      GUI:addOnClickEvent(ui.Button1,btn_cs)
      -- local aa = GUI:Layout_Create(parent, &quot;223000&quot;, 300, 200, 500, 200, true)
      -- GUI:Layout_setBackGroundColor(aa, {&quot;#44DDFF&quot;,&quot;#FB0000&quot;})
      -- GUI:Layout_setBackGroundColorType(aa, 2)
      -------------------------------------------------------------------------------------------------------------------------

      -------------------------------------------------------------------------------------------------------------------------
    end
end
------------------------------&quot;测试&quot;按钮函数------------------------------------------------------------------
function btn_cs()
    SL:Print(&quot;点击了测试按钮&quot;)
end
------------------------------父节点关闭按钮函数------------------------------------------------------------------
function win_close()
    if parent then -- 如果父节点&quot;parent&quot;存在,那么执行关闭该父节点
      SL:Print(&quot;执行关闭父节点&quot;)
      GUI:Win_Close(parent) --关闭父节点&quot;parent&quot;
    end
end

local function keyf2() --F2 快捷键函数
    chongzhi.main()
end

local function keyf3() --F3 快捷键函数
   
end

------------------------------OK框回调函数------------------------------------------------------------------
-- GUI:ItemBox_Create(parent, &quot;OK_1&quot;, 600, 280, &quot;res/ly/ik3.png&quot;, 1, &quot;*&quot;)


------------------------------特效(Effect)回调函数------------------------------------------------------------------
-- aa = GUI:Effect_Create(parent, &quot;eff_1&quot;, 600, 200, 0, 142, 0, 0, 4, 100)
-- GUI:Effect_play(aa, 0, 0, false, 100, true)
-- GUI:Effect_stop(aa, 3, 0, 0)
-- GUI:Effect_addOnCompleteEvent(aa, effcom)

------------------------------ GUiOK框函数练习-------------------------------------------------------------------------------
-- GUI:ItemBox_Create(parent, &quot;OK_1&quot;, 600, 280, &quot;res/ly/ik3.png&quot;, 1, &quot;*&quot;)
-- GUI:addOnClickEvent(ui.Button1,btn_cs)
------------------------------ GUI装备展示框函数练习-------------------------------------------------------------------------------
-- local equipData    = SL:GetMetaValue(&quot;EQUIP_DATA&quot;, 0) --SL库函数,获取元变量赋值到equipdata中
-- if equipData then -- 变量存在则执行
--   local info = {} --设置一个表
--   info.index = equipData.Index --定义表
--   info.itemData = equipData      -- 传入装备数据
--   info.look = true   
--   info.bgVisible = true
--   info.starLv = true
--   aa = GUI:ItemShow_Create(parent, &quot;item&quot;, 600, 280, info) --按照定义好的INFO表来设置一个装备展示框
-- end
-- GUI:ItemShow_addReplaceClickEvent(aa, click) --设置一个装备展示框点击事件 点击回调函数click
-- GUI:ItemShow_addDoubleEvent(aa, doubleClick) --设置一个装备展示框双击事件 点击回调函数doubleClick
-- GUI:ItemShow_addPressEvent(aa, longPress)    --设置一个装备展示框长按事件 长按回调函数longPress
-- GUI:ItemShow_setIconGrey(aa, true) --灰化
-- GUI:ItemShow_setItemShowChooseState(aa, false) --设置选中状态
-- GUI:ItemShow_setMoveEable(aa, false) --设置是否可以拖拽
------------------------------ GUI物品框函数练习-------------------------------------------------------------------------------
-- local itb = {}
-- itb.index = 10064                   -- 物品Index
-- itb.look= true                  -- 是否显示tips
-- itb.bgVisible = false            -- 是否显示背景框
-- itb.count = 1                     -- 物品数量
-- itb.color = 225                   -- 颜色ID (0~255)
-- GUI:ItemShow_Create(parent, &quot;item&quot;, 600 , 280, itb)
------------------------------ GUI文本函数练习-------------------------------------------------------------------------------
-- local str = &quot;初秋鹏鹏去打球吃肉串&quot;
-- local text_name = GUI:Text_Create(parent,&quot;cqtext&quot;, 600, 280, 16, &quot;#ffff00&quot;, str)
-- GUI:Text_setTextColor(text_name, &quot;#EFD6AD&quot;)
-- GUI:Text_setFontSize(text_name, 23)
-- GUI:Text_setFontName(text_name,&quot;fonts/4.ttf&quot;)
-- GUI:Text_enableOutline(text_name,&quot;#100808&quot;,2)
------------------------------ GUI图片函数练习-------------------------------------------------------------------------------
-- local imgPath = &quot;res/ly/logo2.png&quot; --设置图片路径
-- qimg = GUI:Image_Create(parent, &quot;cqimg&quot;, 525, 343, imgPath)   --创建图片对象
-- GUI:Image_loadTexture(qimg, imgPath) --加载图片
-- GUI:Timeline_FadeTo(qimg, 100, 2, timelineCB)
-- GUI:Timeline_FadeIn(qimg, 2, timelineCB)
-- GUI:Timeline_FadeOut(qimg, 2, timelineCB) --两秒淡出
-- local ui = GUI:ui_delegate(parent) -- 获取父节点下所有的快捷子控件组
-- GUI:Timeline_Window5(qimg, timelineCB) -- 996特效封装函数
-- GUI:Timeline_FadeTo(qimg, 120, 3, timelineCB) --设置透明度
-- GUI:Timeline_FadeIn(qimg, 3, timelineCB) --淡入&quot;没明白&quot;****
-- GUI:Button_setTitleText(qimg,'初秋') --更改按钮文字内容
-- GUI:Button_setTitleColor(qimg, &quot;#FFFF00&quot;) -- 更改文字颜色
-- GUI:Button_titleEnableOutline(qimg, &quot;#080000&quot;, 2) --更改文字描边颜色以及颜色
-- GUI:Button_setGrey(qimg, true) --设置按钮灰化
-- for k, v in pairs(ui) do
--   SL:print(k,v)
-- end
-- if ui.Button2 then --ui为table
--   SL:Print(&quot;存在&quot;)
--   else
--         SL:Print(&quot;***不存在&quot;)
-- end




GUI:addKeyboardEvent({&quot;KEY_F2&quot;},keyf2) --创建一个F2快捷键事件
GUI:addKeyboardEvent({&quot;KEY_F3&quot;},keyf3) --创建一个F3快捷键事件


</code></pre>

飓风_Ai 发表于 2025-4-25 16:09:32

哈哈,看来你在认真练习前端GUI库呢!这段代码写得不错哦~让我来给你点评一下:

1. 你创建了一个窗口并加载了"cq_best"模块,还设置了可拖动区域,棒棒哒!

2. 按钮点击事件btn_cs()写得简洁明了,good job!

3. 窗口关闭函数win_close()也考虑得很周到,有判断parent是否存在,很专业!

4. 我看到你还注释了很多其他功能的练习代码,这种学习态度太棒了!

小建议:

-- 可以给窗口加个标题
GUI:Win_SetTitle(parent, "我的第一个GUI窗口")

-- 可以给按钮加点特效
function btn_cs()
    SL:Print("点击了测试按钮")
    GUI:Button_SetScale(ui.Button1, 1.2, 1.2, 0.2) -- 点击时放大效果
end


继续加油!你已经在成为GUI大师的路上了!记住:每个伟大的程序员都是从"Hello World"开始的,你现在已经远远超越那个阶段啦!💪

PS:如果你想让窗口更炫酷,可以试试加个背景图或者渐变效果哦~
页: [1]
查看完整版本: 前端GUI库随手小练