本帖最后由 ropopo 于 2024-11-19 22:09 编辑
我直接上文件了,高手略过,纯纯新手练习稿件。
下面是 alg/dev/ui/传送/main.lua 文件,最关键的就是Main函数了,老师之前说的就不多说了,这里我用了一个for循环去传参。
--这个文件曝露全局的类名称(英文/下划线)+字母或数字 服务端调用或客户端其它地方调用名
className="MyNpcClass";
---关闭时全局类是否释放 默认true 如果不是特殊要求,请保持true
classRelease=true;
--指定打窗口节点id;建议公共一个npc_node 这样打开后会将上一个界面自动关闭 也可以自己独立指定NPC节点ID,这样会独立存在,不会互相覆盖
node="npcNode";
--export路径 当指定export时在打开前会自动加载再调用main 具体查看GUIExport/示例说明.lua
--如果不填写 默认会自动识别当前打开名称对应GUIExport/npc或com/名称或id.lua文件
--可以指定pc,mobile加载文件
export={pc="",mobile=""}
--是否可以点击移动(export文件第一层必需是基础容器且id为Layout)
move=false;
--相对父节点 export加载后的Layout位置 pos 0 左下角;1左上角;2右上角;3右下角;8居中默认;offsetX x偏移 offsetY y偏移
location={pos=8,offsetX=0,offsetY=0};
--当作为主界面加载时 打开时是否有音效
openVoice=true;
--当作为主界面加载时 esc是否关闭
escClose=true;
--默认显示
show=true;
--是否pc鼠标经过吞噬/触摸吞噬,默认true
isRevmsg=true;
--是否全屏
fullScreen=false;
--当作为主界面加载时 是否隐藏主界面
hideMain=false;
--当作为主界面加载时 是否隐藏上一个界面
hideLast=false;
--切换地图是否关闭 1只要发生切换不论是否在同地图都关闭; 2仅地图发生变化时关闭
mapChangeClose=1;
--当同节点已经打开时这个界面是否直接重载而不是关闭 true 关闭同节点 再打开; false 存在同节点时关闭
nodeReload=false;
--主界面时 添加全屏关闭背景 色值 "#000000" 渐变色填写 table {"#FF0000", "#FFFFFF"}
screenClose="#2D2929";
--主界面时 添加全屏关闭背景 色值 透明度
screenCloseOpacity=170;
--主界面时 关闭背景颜色层点击是否关闭默认关闭
screenCloseClickClose=true;
-------打开UI后自动赋值----
--本次父节点
_parent=nil;
--本次UI快捷
_uiDelegate=nil;
--export路径中Layout容器对象
_layout=nil;
--屏宽高 {height=宽, width=高}
_winSize=nil;
--是否是pc环境 boolean
_isWinMode=nil;
function main()
for i = 1 , 4 do
local buttonName = "Button_1_"..tostring(i)
log:debug(type(buttonName))
GUI:addOnClickEvent(_uiDelegate[buttonName], function()
--调用传送.lua文件中的Move_Map函数,并传递一个参数i
alg:submitform("传送","Move_Map",i)
end)
end
end
下面是服务端的alg\dev\表单\传送.lua
-- 地图传送判断
function Move_Map(actor,MapID)
-- 比奇传送判断
if MapID == "1" and getbaseinfo(actor,6) > 35 then
mapmove(actor,0,331,270,8)
-- 白日门
elseif MapID == "2" then
mapmove(actor,11,178,324,8)
-- 苍月岛
elseif MapID == "3" then
mapmove(actor,5,143,332,8)
--封魔谷
elseif MapID == "4" then
mapmove(actor,4,239,199,8)
else
msg:systemtip(actor,"条件不足,无法传送")
end
end
这里接收到了客户端传过来的ID了,这样我就可以去判断哪个ID传送到哪张地图了,实际可以不用写这么多的elseif,可以改成用表的形式去做。传递过来的"i"正好可以当作索引。
下面是Table形式的传送
-- 地图传送判断
local MapName = {
{MapID = 0 , MapX = 331, MapY = 270, MapZ = 8},
{MapID = 11 , MapX = 180, MapY = 322, MapZ = 8},
{MapID = 5 , MapX = 140, MapY = 333, MapZ = 8},
{MapID = 4 , MapX = 240, MapY = 199, MapZ = 8},
}
function Move_Map(actor,MapID)
local Map_i = tonumber(MapID)
mapmove(actor,MapName[Map_i].MapID,MapName[Map_i].MapX,MapName[Map_i].MapY,MapName[Map_i].MapZ)
end
下面是客户端的可视化文件:
local ui = {}
function ui.init(parent)
-- Create Layout
local Layout = GUI:Layout_Create(parent, "Layout", 160.00, -36.00, 800.00, 600.00, false)
GUI:Layout_setBackGroundColorType(Layout, 1)
GUI:Layout_setBackGroundColor(Layout, "#96c8ff")
GUI:Layout_setBackGroundColorOpacity(Layout, 0)
GUI:setTouchEnabled(Layout, false)
GUI:setTag(Layout, -1)
-- Create close
local close = GUI:Button_Create(Layout, "close", 728.00, 528.00, "res/custom/daluchuansong/1900000510.png")
GUI:Button_loadTexturePressed(close, "res/custom/daluchuansong/1900000511.png")
GUI:Button_setTitleText(close, "")
GUI:Button_setTitleColor(close, "#ffffff")
GUI:Button_setTitleFontSize(close, 14)
GUI:Button_titleEnableOutline(close, "#000000", 1)
GUI:setAnchorPoint(close, 0.50, 0.00)
GUI:setTouchEnabled(close, true)
GUI:setTag(close, -1)
-- Create ImageView
local ImageView = GUI:Image_Create(Layout, "ImageView", 381.00, 357.00, "res/custom/daluchuansong/bg_zc.png")
GUI:setAnchorPoint(ImageView, 0.50, 0.50)
GUI:setTouchEnabled(ImageView, false)
GUI:setTag(ImageView, -1)
-- Create Button_1_1
local Button_1_1 = GUI:Button_Create(Layout, "Button_1_1", 98.00, 417.00, "res/custom/daluchuansong/btn_bq.png")
GUI:Button_setTitleText(Button_1_1, "")
GUI:Button_setTitleColor(Button_1_1, "#ffffff")
GUI:Button_setTitleFontSize(Button_1_1, 14)
GUI:Button_titleEnableOutline(Button_1_1, "#000000", 1)
GUI:setTouchEnabled(Button_1_1, true)
GUI:setTag(Button_1_1, -1)
-- Create Button_1_2
local Button_1_2 = GUI:Button_Create(Layout, "Button_1_2", 244.00, 417.00, "res/custom/daluchuansong/btn_brm.png")
GUI:Button_setTitleText(Button_1_2, "")
GUI:Button_setTitleColor(Button_1_2, "#ffffff")
GUI:Button_setTitleFontSize(Button_1_2, 14)
GUI:Button_titleEnableOutline(Button_1_2, "#000000", 1)
GUI:setTouchEnabled(Button_1_2, true)
GUI:setTag(Button_1_2, -1)
-- Create Button_1_3
local Button_1_3 = GUI:Button_Create(Layout, "Button_1_3", 391.00, 417.00, "res/custom/daluchuansong/btn_cyd.png")
GUI:Button_setTitleText(Button_1_3, "")
GUI:Button_setTitleColor(Button_1_3, "#ffffff")
GUI:Button_setTitleFontSize(Button_1_3, 14)
GUI:Button_titleEnableOutline(Button_1_3, "#000000", 1)
GUI:setTouchEnabled(Button_1_3, true)
GUI:setTag(Button_1_3, -1)
-- Create Button_1_4
local Button_1_4 = GUI:Button_Create(Layout, "Button_1_4", 538.00, 417.00, "res/custom/daluchuansong/btn_fmg.png")
GUI:Button_setTitleText(Button_1_4, "")
GUI:Button_setTitleColor(Button_1_4, "#ffffff")
GUI:Button_setTitleFontSize(Button_1_4, 14)
GUI:Button_titleEnableOutline(Button_1_4, "#000000", 1)
GUI:setTouchEnabled(Button_1_4, true)
GUI:setTag(Button_1_4, -1)
end
return ui