bayuMIR/client/dev/GUILayout/game/tongyong/GmBoxOBJ.lua
2026-06-12 02:32:15 +08:00

196 lines
6.4 KiB
Lua

GmBoxOBJ = Up_BaseClassOBJ:new()
GmBoxOBJ.__cname = "GmBoxOBJ"
-- UI文件
GmBoxOBJ.UIfile = "game/Tongyong/GmBoxUI"
-- 配置文件
GmBoxOBJ.cfg = {}
GmBoxOBJ.other = nil
GmBoxOBJ.player = ""
function GmBoxOBJ:updata()
---* 读取自己信息
local self_name = SL:Get_USER_NAME()
GUI:Text_setString(self.ui.self_name, self_name)
GUI:Text_setString(self.ui.gm_level, self.other)
---* 处理操作对象
GUI:addOnClickEvent(self.ui.Button_2, function()
if self.player == "" then
self.player = GUI:TextInput_getString(self.ui.TextInput_1)
else
self.player = ""
end
self:setPlayer()
end)
GUI:addOnClickEvent(self.ui.Button_3, function()
GUI:Button_setTitleText(self.ui.Button_2, "清除")
GUI:TextInput_setString(self.ui.TextInput_1, nil)
self.player = self_name
self:setPlayer()
end)
self:setPlayer()
self:handleCommand()
end
function GmBoxOBJ:setPlayer()
if self.player ~= "" then
GUI:setVisible(self.ui.TextInput_1, false)
GUI:setVisible(self.ui.Player_name, true)
GUI:Text_setString(self.ui.Player_name, self.player)
GUI:Button_setTitleText(self.ui.Button_2, "清除")
else
GUI:setVisible(self.ui.TextInput_1, true)
GUI:setVisible(self.ui.Player_name, false)
GUI:Button_setTitleText(self.ui.Button_2, "确认")
end
end
----* 处理命令分类
function GmBoxOBJ:handleCommand()
local cfg = self.cfg
self.id = self.id or 1
GUI:ListView_removeAllItems(self.ui.feilei_ListView)
for i, v in ipairs(cfg) do
local fl_btn = string.format("feilei_%s", i)
self.ui[fl_btn] = GUI:Button_Create(self.ui.feilei_ListView, fl_btn, 0, 304, "res/public/1900000612.png")
GUI:Button_setTitleText(self.ui[fl_btn], v.name)
GUI:Button_setTitleColor(self.ui[fl_btn], self.id == i and "#00FFFF" or "#636363")
GUI:Button_setTitleFontSize(self.ui[fl_btn], 16)
GUI:setGrey(self.ui[fl_btn], self.id == i and false or true)
GUI:addOnClickEvent(self.ui[fl_btn], function()
GUI:Button_setTitleColor(self.ui[string.format("feilei_%s", self.id)], "#636363")
GUI:Button_setTitleColor(self.ui[fl_btn], "#00FFFF")
self.id = i
self:initFeiLei()
end)
end
self:initFeiLei()
end
----* 处理子分类
function GmBoxOBJ:initFeiLei()
self.z_id = 1
local cfg = self.cfg[self.id].list
GUI:ListView_removeAllItems(self.ui.Command_ListView)
for i, v in ipairs(cfg) do
local zfl_btn = string.format("zfl_btn_%d", i)
self.ui[zfl_btn] = GUI:Button_Create(self.ui.Command_ListView, zfl_btn, 0, 0,
string.format("res/public/%s.png", self.z_id == i and "bg_hhzy_01_1" or "bg_hhzy_01_3"))
GUI:Button_setTitleText(self.ui[zfl_btn], v.command)
GUI:Button_setTitleFontSize(self.ui[zfl_btn], 14)
GUI:setContentSize(self.ui[zfl_btn], 150, 30)
GUI:addOnClickEvent(self.ui[zfl_btn], function()
GUI:Button_loadTextureNormal(self.ui[string.format("zfl_btn_%d", self.z_id)], "res/public/bg_hhzy_01_3.png")
GUI:Button_loadTextureNormal(self.ui[zfl_btn], "res/public/bg_hhzy_01_1.png")
self.z_id = i
self:commendShow()
end)
end
self:commendShow()
end
---* 创建UI
function GmBoxOBJ:commendShow()
self.getinput = {}
GUI:removeAllChildren(self.ui.Commend_Layout)
local cfg = self.cfg[self.id].list[self.z_id]
if cfg then
local text_size = 0
for i, v in ipairs(cfg.comm or {}) do
if v[1] == "input" then
local width = string.len(v[2]) * 7
text_size = math.max(text_size, width)
end
end
for i, v in ipairs(cfg.comm or {}) do
local Show_list = string.format("Show_list_%d", i)
self.ui[Show_list] = GUI:Layout_Create(self.ui.Commend_Layout, Show_list, 0, 0, 260, 30, false)
GUI:Win_SetParam(self.ui[Show_list], #cfg.comm - i)
local list_Text = string.format("list_Text_%d", i)
self.ui[list_Text] = GUI:Text_Create(self.ui[Show_list], list_Text, 0, 18, 16, "#ffffff",
string.format("%s", v[1] ~= "ps" and v[2] .. ":" or "*备注:" .. v[2]))
GUI:setAnchorPoint(self.ui[list_Text], 0.00, 0.50)
if v[1] == "input" then
local list_input_bg = string.format("list_input_bg_%d", i)
self.ui[list_input_bg] = GUI:Image_Create(self.ui[Show_list], list_input_bg, text_size, 15,
"res/public/1900000668.png")
GUI:setAnchorPoint(self.ui[list_input_bg], 0.00, 0.50)
local list_input = string.format("list_input_%d", i)
self.ui[list_input] = GUI:TextInput_Create(self.ui[list_input_bg], list_input, 2, 2, 147, 25, 16)
table.insert(self.getinput, self.ui[list_input])
end
end
end
GUI:UserUILayout(self.ui.Commend_Layout, {
dir = 1,
addDir = 2,
interval = 0.4,
gap = { y = 2 },
sortfunc = function(lists)
table.sort(lists, function(a, b)
return GUI:Win_GetParam(a) > GUI:Win_GetParam(b)
end)
end
})
local function getinput()
local tbl = {}
for i, v in ipairs(self.getinput or {}) do
table.insert(tbl, GUI:TextInput_getString(v))
end
return tbl
end
GUI:addOnClickEvent(self.ui.Up_btn, function()
local data = {}
data.id = cfg.index
data.player = self.player
data.info = getinput()
ssrMessage:SubLink(self.__cname .. "_up", data)
end)
end
---* 注册事件
function GmBoxOBJ:EventBind()
local function GmBoxOBJ_Var_Reload(data)
if GUI:Win_IsNotNull(self._parent) then
if data.key == "{7}" then
self:updata()
end
end
end
SL:RegisterLUAEvent(LUA_EVENT_SERVER_VALUE_CHANGE, self.__cname, GmBoxOBJ_Var_Reload)
--关闭窗口
SL:RegisterLUAEvent(LUA_EVENT_CLOSEWIN, self.__cname, function(widgetName)
self:OnClose(widgetName)
end)
end
--关闭窗口
function GmBoxOBJ:OnClose(widgetName)
if widgetName == self.__cname then
self:UnRegisterEvent()
end
end
function GmBoxOBJ:UnRegisterEvent()
SL:UnRegisterLUAEvent(LUA_EVENT_SERVER_VALUE_CHANGE, self.__cname)
SL:UnRegisterLUAEvent(LUA_EVENT_CLOSEWIN, self.__cname)
end
return GmBoxOBJ