MailReadView.lua
4.61 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
local MailReadView = dialog.uinode("ui/MailReadLayer.csb",import(".BaseView"))
function MailReadView:ctor()
MailReadView.super.ctor(self);
end
function MailReadView:show(info)
local scene = cc.Director:getInstance():getRunningScene()
local inst = MailReadView:create();
scene:addChild(inst, dialog.ZORDER_APP);
inst:setContentSize(cc.size(display.width,display.height));
ccui.Helper:doLayout(inst);
inst:init(info);
return inst;
end
function MailReadView:init(info)
self.btn_close = self:getChildByName("panel"):getChildByName("btn_close");
self.btn_close.fn = handler(self,self.onClose);
self.btn_close:addTouchEventListener(function(ref,type) self:onButtonClick(ref,type,self.btn_close.fn)end);
local mailInfo = MailInfo.getMailInfo(info.mail_id);
self:getChildByName("panel"):getChildByName("txt_title"):setString("标题:"..mailInfo.title);
local st = os.date("*t",info.time);
local writer = mailInfo.writer;
local desc = string.gsub(mailInfo.desc,"\\n","\n");
if info.mail_id == 200001 then
local data = protobuf.decode("share_msg.mail_give_t",info.bin_data,string.len(info.bin_data));
writer = data.send_user.nick;
desc = data.send_user.nick.."赠送给你";
mailInfo.item = "";
for i,v in ipairs(data.items) do
if i < #data.items then
desc = desc..v.cnt.."张"..ItemInfo.getItemInfo(v.id).name.."、";
mailInfo.item = mailInfo.item..v.id..","..v.cnt..";";
else
desc = desc..v.cnt.."张"..ItemInfo.getItemInfo(v.id).name;
mailInfo.item = mailInfo.item..v.id..","..v.cnt;
end
end
elseif info.mail_id == 300001 or info.mail_id == 300002 then
local data = protobuf.decode("share_msg.mail_give_t",info.bin_data,string.len(info.bin_data));
desc = writer.."发给用户 ";
mailInfo.item = "";
for i,v in ipairs(data.items) do
if i < #data.items then
desc = desc..v.cnt.."张"..ItemInfo.getItemInfo(v.id).name.."、";
mailInfo.item = mailInfo.item..v.id..","..v.cnt..";";
else
desc = desc..v.cnt.."张"..ItemInfo.getItemInfo(v.id).name;
mailInfo.item = mailInfo.item..v.id..","..v.cnt;
end
end
elseif info.mail_id == 500001 then
local data = protobuf.decode("share_msg.mail_exprie_rank_t",info.bin_data,string.len(info.bin_data));
mailInfo.item = "";
for i,v in ipairs(data.items) do
if i < #data.items then
mailInfo.item = mailInfo.item..v.id..","..v.cnt..";";
else
mailInfo.item = mailInfo.item..v.id..","..v.cnt;
end
end
if data.rank_type == 13 then
self:getChildByName("panel"):getChildByName("txt_title"):setString("标题:".."斗地主"..mailInfo.title);
end
end
self:getChildByName("panel"):getChildByName("txt_sender"):setString("发件人:"..writer.." "..st.year.."."..st.month.."."..st.day);
self:getChildByName("panel"):getChildByName("txt_content"):setString(desc);
local panel_goods = self:getChildByName("panel"):getChildByName("panel_goods");
if mailInfo.item and mailInfo.item ~= "" then
panel_goods:setVisible(true);
local _arr = StringUtil.split(mailInfo.item,";");
local len = #_arr*110;
local start_x = (800-len)/2;
for i,v in ipairs(_arr) do
local item = cc.CSLoader:createNode("ui/MailGoodsItem.csb");
item:setPosition(cc.p(start_x+(i-1)*110,60));
local itemArr = StringUtil.split(v,",");
item:getChildByName("icon"):loadTexture("res/iconsmall/"..itemArr[1]..".png");
local itemInfo = ItemInfo.getItemInfo(itemArr[1]);
item:getChildByName("txt_num"):setString(itemArr[2]);
panel_goods:addChild(item,0);
end
UserModel.getMailAttachment(info.idx);
else
panel_goods:setVisible(false);
end
panel_goods:getChildByName("img_mail_get"):setLocalZOrder(10);
self.nodes[1] = {self.btn_close};
self:updateSelectedState();
end
--关闭
function MailReadView:onClose()
self:close();
end
--返回键处理函数
function MailReadView:onKeypadBack()
self:close();
end
--确认键处理函数
function MailReadView:onKeypadOk()
local node = self.nodes[self.nodeIndex][self.selectedIndex];
if node and node.fn then
node.fn();
end
end
--左键处理函数
function MailReadView:onKeypadUp()
end
--右键处理函数
function MailReadView:onKeypadDown()
end
return MailReadView