-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFFriendApply.lua
More file actions
176 lines (144 loc) · 4.59 KB
/
FFriendApply.lua
File metadata and controls
176 lines (144 loc) · 4.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
--[[
好友申请列表
]]
local UIBase = require_ex("ui.base.UIBase")
local M = class("FFriendApply", UIBase)
local InitCount = 8
function M:ctor(closeCB)
if type(closeCB) == "function" then
self._closeCallback = closeCB
end
self.effRipple = true
self.effDark = true
UIBase.ctor(self)
self:init()
end
function M:init()
self._BindWidget = {
["panel_touch"] = {handle = handler(self, self.onClose)},
["panel_center/btn_close"] = {handle = handler(self, self.onClose)},
["panel_center/lv_list"] = {key = "lv_list"},
["temp_list"] = {},
}
self._listData = {}
self._initIdx = 1
self:initViews()
end
function M:initViews()
local uiNode = createCsbNode("subgame/catchFish/frendapply.csb")
self:addChild(uiNode, 1)
self._rootNode = uiNode
bindWidgetList(uiNode, self._BindWidget, self._widgets)
self._widgets.lv_list:stopAllActions()
self._widgets.lv_list:removeAllItems()
local list = Game:doPluginAPI("get", "friendApply")
if not list or #list == 0 then
if self._widgets.panel_empty then
self._widgets.panel_empty:setVisible(true)
end
return
end
if self._widgets.panel_empty then
self._widgets.panel_empty:setVisible(false)
end
self._listData = list
local amount = #list
local count = Number.min(amount, InitCount)
for i = 1, count do
self:addItem(i)
end
if count < amount then
self._initIdx = count + 1
self:scheduleUpdate()
end
self._widgets.lv_list:jumpToTop()
end
function M:addItem(idx)
idx = idx or self._initIdx
local v = self._listData[idx]
local item = self._widgets.temp_list:clone()
local panel_head, img_head, txt_name, img_online, img_offline, btn_accept, btn_refuse
panel_head = item:getChildByName("panel_head")
img_head = panel_head:getChildByName("img_head")
txt_name = item:getChildByName("txt_name")
img_online = item:getChildByName("img_onlie")
img_offline = item:getChildByName("img_offline")
btn_accept = item:getChildByName("btn_agree")
btn_refuse = item:getChildByName("btn_refuse")
Game:doPluginAPI("set", "headIcon", img_head, v.facelook, true)
txt_name:setString(v.nick)
if v.online == 1 then
img_online:setVisible(true)
img_offline:setVisible(false)
else
img_online:setVisible(false)
img_offline:setVisible(true)
end
if btn_accept then
btn_accept.uData = v
bindClickFunc(btn_accept, handler(self, self.onAccept))
end
if btn_refuse then
btn_refuse.uData = v
bindClickFunc(btn_refuse, handler(self, self.onRefuse))
end
item.uData = v
bindClickFunc(item, handler(self, self.onViewDetail))
item:setVisible(true)
self._widgets.lv_list:pushBackCustomItem(item)
end
function M:removeItem(item)
local idx = self._widgets.lv_list:getIndex(item)
if idx >= 0 then
self._widgets.lv_list:removeItem(idx)
if #self._widgets.lv_list:getItems() == 0 and self._widgets.panel_empty then
self._widgets.panel_empty:setVisible(true)
end
end
end
function M:updateFunc()
self:addItem()
self._initIdx = self._initIdx + 1
if self._initIdx > #self._listData then
self:unscheduleUpdate()
end
end
----------------------------------
-- 交互及回调
function M:onAccept(sender)
local v = sender.uData
Game:doPluginAPI("send", "friendApply", v.pid, FriendApply.accept, function()
self:removeItem(sender:getParent())
Game:tipMsg(Config.localize("friend_apply_accept"))
end)
end
function M:onRefuse(sender)
local v = sender.uData
Game:doPluginAPI("send", "friendApply", v.pid, FriendApply.refuse, function()
self:removeItem(sender:getParent())
Game:tipMsg(Config.localize("friend_apply_refuse"))
end)
end
function M:onViewDetail(sender)
local v = sender.uData
if DEBUG_OFFLINE then
Game:doPluginAPI("enter", "playerDetail", v)
return
end
local uid = v.pid or v.uid
local args
if not Game:doPluginAPI("get", "friend", uid) then
args = {
confirm_title = Config.localize("que_ding"),
confirm_func = NULL.F,
}
end
Game:doPluginAPI("send", "playerDetail", uid, args)
end
function M:onClose()
if self._closeCallback then
self._closeCallback()
end
self:destroy()
end
return M