111 lines
3.4 KiB
Lua
111 lines
3.4 KiB
Lua
local FamilyJoinAndCreate = {}
|
|
|
|
local M = FamilyJoinAndCreate
|
|
|
|
function FamilyJoinAndCreate.new(root)
|
|
setmetatable(M, { __index = root })
|
|
local self = setmetatable({}, { __index = M })
|
|
local fgCtr = ControllerManager.GetController(NewGroupController)
|
|
local createOrJoin = self._view:GetController('createOrJoin')
|
|
|
|
|
|
self._currenIndex = 0
|
|
self.tex_num = self._view:GetChild('text_inputNum')
|
|
|
|
self._view:GetChild('btn_joinFamily').onClick:Add(function()
|
|
createOrJoin.selectedIndex = 1
|
|
end)
|
|
self._view:GetChild('btn_createFamily').onClick:Add(function()
|
|
createOrJoin.selectedIndex = 0
|
|
end)
|
|
self._view:GetChild('list_num').onClickItem:Set(handler(self, self.OnNumButtonAction))
|
|
|
|
local input_name = self._view:GetChild('input_name')
|
|
local input_wxId = self._view:GetChild('input_wxId')
|
|
input_name.onChanged:Set(function()
|
|
input_name.alpha = 1
|
|
end)
|
|
input_name.onFocusOut:Set(function()
|
|
if #input_name.text > 0 then
|
|
input_name.alpha = 1
|
|
else
|
|
input_name.alpha = 0.5
|
|
end
|
|
end)
|
|
|
|
input_wxId.onChanged:Set(function()
|
|
input_wxId.alpha = 1
|
|
end)
|
|
input_wxId.onFocusOut:Set(function()
|
|
if #input_wxId.text > 0 then
|
|
input_wxId.alpha = 1
|
|
else
|
|
input_wxId.alpha = 0.5
|
|
end
|
|
end)
|
|
self._view:GetChild('btn_create').onClick:Add(function()
|
|
fgCtr:FG_GroupList(function(res)
|
|
fgCtr:FG_CreateGroup(input_name.text, 1, 2, function(res)
|
|
if res.ReturnCode == 0 then
|
|
self.familyType.selectedIndex = 1
|
|
self:ConnetFamily(1, DataManager.groups.groupList, true)
|
|
else
|
|
ViewUtil.ErrorTip(res.ReturnCode, '创建大联盟失败!')
|
|
end
|
|
end)
|
|
end)
|
|
end)
|
|
return self
|
|
end
|
|
|
|
function M:OnNumButtonAction(context)
|
|
local item = context.data
|
|
local index = self._view:GetChild('list_num'):GetChildIndex(item)
|
|
if index < 9 or index == 10 then
|
|
if (self._currenIndex < 6) then
|
|
self._currenIndex = self._currenIndex + 1
|
|
self.tex_num.text = self.tex_num.text .. (index < 9 and index + 1 or index - 10)
|
|
if (self._currenIndex == 6) then
|
|
self:JoinRoom(self.tex_num.text)
|
|
end
|
|
end
|
|
elseif index == 9 then
|
|
self:ClearNumTex()
|
|
else
|
|
if (self._currenIndex > 0) then
|
|
self._currenIndex = self._currenIndex - 1
|
|
self.tex_num.text = string.sub(self.tex_num.text, 0, self._currenIndex)
|
|
end
|
|
end
|
|
end
|
|
|
|
function M:ClearNumTex()
|
|
self.tex_num.text = ""
|
|
self._currenIndex = 0
|
|
end
|
|
|
|
function M:JoinRoom(roomId)
|
|
local fgCtr = ControllerManager.GetController(NewGroupController)
|
|
--后端似乎还未调通
|
|
self:ClearNumTex()
|
|
fgCtr:FG_JoinGroup(tonumber(roomId), function(res)
|
|
if res.ReturnCode ~= 0 then
|
|
ViewUtil.ShowOneChooose("加入失败" .. res.ReturnCode)
|
|
else
|
|
end
|
|
end)
|
|
--先换成邀请玩家
|
|
-- fgCtr:FG_AddMember(self._group.id, tonumber(roomId), function(res)
|
|
-- if (res.ReturnCode == 0) then
|
|
-- ViewUtil.ShowBannerOnScreenCenter('添加成功!', 1)
|
|
-- else
|
|
-- ViewUtil.ErrorTip(res.ReturnCode, '邀请玩家失败!')
|
|
-- end
|
|
|
|
-- self:ChangeNumber(fgCtr, self._group.id, 0, self._group.total_member_num1, false,
|
|
-- 1)
|
|
-- end)
|
|
end
|
|
|
|
return M
|