标签:const inf cmd ddp number style 提取 text img
点击不同按钮弹出同一个面板上的不同效果,通过传入类型来判断:
this.btnRight.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onUpgradeforgift,this);
this.btnLeft.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onPayforgift,this);
private onUpgradeforgift(evt:egret.TouchEvent){
manager.PopupManager.addPopup(new UpgradeForGift(2));
}
private onPayforgift(evt:egret.TouchEvent){
manager.PopupManager.addPopup(new UpgradeForGift(1));
}
UpgradeForGift.ts文件:
module view{
export class UpgradeForGift extends BasePanel{
private static INVITE_FRIEND_CALL_ABCK:string = "INVITE_FRIEND_CALL_ABCK";
private btn_back:eui.Image;
private cellScroller:eui.Scroller;
private cellGroup:eui.Group;
private list:utils.List;
public inviteGiftImg:eui.Image; //邀请送礼包
public upgradeImg:eui.Image; //好友升级送豪礼 根据类型判断显示不同的标题
private rewardDes:eui.Label; //根据类型的不同,显示不同的文字
private smallTitle:eui.Label;
private tip:eui.Image;
private inviteeRewardInfo:Array<any>
public info:Array<any>
private inviteeArr:Array<any>;
private InviteeLevel:number;
private rewardArr:Array<any>;
private _dataArr:Array<any>;
public panelType:number
private addReward:Array<any>
public constructor(type:number) { //传入用于判断类型的参数
super();
this.panelType = type;//1充值返 2等级返
this.onLoadUI("resource/eui_skins/invitefriend/UpgradeforGift.exml", this.init,"UpgradeforGift");
}
private init(){
// this.inviteTitle.source = "invitefriend_json.gift_2";
this.btnClose = this.btn_back;
this.btnCloseAddListener();
this.onCloseFun = this.hide;
this.list = new utils.List(100,1,view.UpgradeItemForGift,0,0,"",true,this.cellGroup);
if(this.panelType == 1)
{
this.upgradeImg.source = "invitefriend_json.gift_1";
this.upgradeImg.x = 353;
this.rewardDes.text = "当您邀请的好友每次充值购买礼包时,您都可以获得礼包内元宝数量的20%作为奖励。";
this.smallTitle.text = "您的邀请返利";
this.tip.visible = false;
var cmd:Net.InvitePayRewardCommand = new Net.InvitePayRewardCommand(); //不同的类型发送不同的协议
cmd.sucessCallBack = this.setData.bind(this);
cmd.send();
}
else if(this.panelType == 2)
{
this.upgradeImg.source = "invitefriend_json.gift_2";
this.upgradeImg.x = 278;
this.rewardDes.text = "当您邀请的好友主城到达相应等级时,您可以获得相应的等级奖励。";
this.smallTitle.text = "您的好友升级奖励";
this.tip.visible = true;
var cmd:Net.InviteeLevelRewardInfoCmd = new Net.InviteeLevelRewardInfoCmd();
cmd.sucessCallBack = this.setData.bind(this);
cmd.send();
}
// observer.ComDispatcher.addGlobalEventListerner(InviteFriend.INVITE_FRIEND_CALL_ABCK,this.shareSuccuess,this);
}
private setData(obj:Object){ //返回数据
this._dataArr = [];
if(!obj){
return;
}
var arr:Array<any>;
if(this.panelType == 1)
{
arr = obj["InvitePayArr"]; //通过打断点来知道对象的各个属性,InvitePayArr就是对象obj的一个属性,是一个数组,以此来获得属性。
var _index:number = 0;
for(var i:number = 0; i < arr.length; i++)
{
var _friends:Object = arr[i]; //将每条数据都提取出来,并将各个属性都声明出来做备用。
var _InviteeName:string = _friends["InviteeName"];
var _InviteePic:string = _friends["InviteePic"];
var _InviteeUid:string = _friends["InviteeUid"];
var _productId:string = _friends["productId"];
var _status:number = Number(_friends["InviteeRewardInfo"]);
if(_status == 0) //如果有要满足的另外一个限定条件,则可以这样用if限定
{
var _obj:Object = new Object(); //通过将所要用到的所有对象的属性都封装到一个对象里,来方便以后对数据的使用
_obj["InviteeName"] = _InviteeName;
_obj["InviteePic"] = _InviteePic;
_obj["InviteeUid"] = _InviteeUid;
_obj["productId"] = _productId;
_obj["status"] = _status;
_obj["index"] = _index++;
_obj["panelType"] = this.panelType; //如果要用到其他的一些属性,也可以封装到这个对象里,如用于判断类型的panelType,状态status,索引index
this._dataArr.push(_obj);
}
}
}
else if(this.panelType == 2)
{
arr= obj["InviteeArr"]; //好友数组
this.addReward = obj["addReward"];//获取奖励的数组
this.tip.addEventListener(egret.TouchEvent.TOUCH_TAP,this.showTip,this);
for(var i:number = 0; i < arr.length; i++)
{
var _friends:Object = arr[i];
var _InviteeLevel:number = Number(_friends["InviteeLevel"]);
var _InviteeName:string = _friends["InviteeName"];
var _InviteePic:string = _friends["InviteePic"];
var _InviteeUid:string = _friends["InviteeUid"];
var _statusArr:Array<number> = _friends["InviteeRewardInfo"].split("|");
var _index:number = 0;
for(var j:number = 0; j < _statusArr.length; j++)
{
if(_InviteeLevel >= this.addReward[j]["Level"] && Number(_statusArr[j]) == 0)
{
var _obj:Object = new Object();
_obj["InviteeName"] = _InviteeName;
_obj["InviteeLevel"] = _InviteeLevel;
_obj["rewardLevel"] = this.addReward[j]["Level"];
_obj["InviteePic"] = _InviteePic;
_obj["InviteeUid"] = _InviteeUid;
_obj["status"] = Number(_statusArr[j]);
_obj["index"] = _index++;
_obj["panelType"] = this.panelType;
this._dataArr.push(_obj);
}
}
}
}
this.list.data = this._dataArr; //判断类型后,将不同的数据装进数组中就好,而不用分别装进两个数组,再通过不同类型设置list的值。
}
private showTip(){
manager.PopupManager.addPopup(new view.Tip("",this.addReward),false,true);
}
private sortOrderByStr(arr: Array<any>, str: string) {
var str1: any;
var str2: any;
arr.sort((a, b) => {
str1 = a[str];
str2 = b[str];
return str1 - str2;
});
}
private hide(): void {
manager.PopupManager.removePopup(this);
this.dispose();
}
public dispose(){
super.dispose();
}
}
}
egret中通过判断不同的类型来使同一个UI面板上显示不同的效果
标签:const inf cmd ddp number style 提取 text img
原文地址:http://www.cnblogs.com/RitaLee/p/7088509.html