Skip to content

Commit

Permalink
修复重复游戏后,分数展示失败。
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoyuexing committed Jul 12, 2018
1 parent 93fb0c7 commit 00e6bce
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 91 deletions.
18 changes: 11 additions & 7 deletions framework/Basic/src/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ class Main extends eui.UILayer {
private userID:string;
private roomID:any;
private timer:egret.Timer;
private loginLayer:Login;
private roomLayer:Room;


protected createChildren(): void {
Expand All @@ -54,6 +52,15 @@ class Main extends eui.UILayer {

private async runGame() {
Toast.initRes(this, "resource/loading/toast-bg.png");

var rootView = new egret.Sprite();
rootView.width = this.stage.width;
rootView.height = this.stage.height;
rootView.x = 0;
rootView.y = 0;
this.addChild(rootView);
SceneManager.init(rootView);

egret.ImageLoader.crossOrigin = "anonymous";
await this.getWxUserInfo();
// SceneManager.init(this);
Expand Down Expand Up @@ -183,8 +190,7 @@ class Main extends eui.UILayer {
this.removeEvent();
var obj = {roomID: this.roomID, gameMode:MatchvsData.gameMode,isInvite:false,isRestart:true};
MatchvsData.gameMode = true;
this.roomLayer = new Room();
this.addChild(this.roomLayer);
SceneManager.showScene(Room,obj);
break;
}
}
Expand All @@ -209,9 +215,7 @@ class Main extends eui.UILayer {

protected createGameScene(): void {
// this.removeEvent()
this.loginLayer = new Login();
this.addChild(this.loginLayer)
// SceneManager.showScene(Login);
SceneManager.showScene(Login);
}
/**
* 根据name关键字创建一个Bitmap对象。name属性请参考resources/resource.json配置文件的内容。
Expand Down
90 changes: 54 additions & 36 deletions framework/Basic/src/SceneManager.ts
Original file line number Diff line number Diff line change
@@ -1,59 +1,75 @@
class SceneManager {
public static currentScene: egret.DisplayObjectContainer;
public static root: egret.DisplayObjectContainer;
public static isAnimation: boolean = false;
public static sceneStack: egret.DisplayObjectContainer[] = [];
public static init(root: egret.DisplayObjectContainer) {
this.root = root;
}

public static showScene(scene: any, par?): egret.DisplayObject {
if (!this.root) { console.error("SceneManager not be init()"); return; }
if (!scene) { console.log("scene is null"); }
// console.log("send",scene.constructor)
var index = -1;
for (var i = 0; i < this.root.numChildren; i++) {
var child = this.root.getChildAt(i);
if (child.constructor == scene) {
index = i;
scene = child;
if (scene.onShow) scene.onShow(par);

}
if (!scene) { console.error("scene is null"); return; }
//hide top
if (this.root.numChildren > 0) {
var top: any = this.root.getChildAt(this.root.numChildren - 1);
top.onHide && top.onHide();
}

if (index >= 0) {
// console.log("[SceneManager] back scene to front.:" + scene.constructor + "@" + scene.hashCode);
this.root.swapChildren(scene, this.root.getChildAt(this.root.numChildren - 1));
} else {
scene = new scene(par);
if (scene.onShow) {
// console.log(scene.constructor ,"onShow");
scene.onShow(par);
}
this.root.addChild(scene);
//new a scene
scene = new scene(par);
scene.name = scene.constructor.name
scene.onShow && scene.onShow(par);
//show currentScene
this.root.addChild(scene);

if (SceneManager.isAnimation) {
scene.x = 480;
egret.Tween.get(scene, { loop: false }).to({ x: 0, y: 0 }, 300, egret.Ease.circInOut);
}
// this.sceneStack.push(scene);
// console.log("[SceneManager] show scene:" + scene.constructor + "@" + scene.hashCode);
// this.currentScene && this.root.removeChild(this.currentScene);
// this.currentScene = sceene;
// console.log("[SceneManager] remove scene:" + this.currentScene);
// }
console.log("[SceneManager] show scene:" + scene.constructor.name + "@" + scene.hashCode);
}

public static back() {
public static back(): boolean {
if (this.root.numChildren > 0) {
var perScene = this.root.getChildAt(this.root.numChildren - 1);
var perScene: any = this.root.getChildAt(this.root.numChildren - 1);
if (perScene) {
this.root.removeChild(perScene);
console.log("[SceneManager] Back to scene:" + perScene.name);
perScene.onHide && perScene.onHide();
if (!SceneManager.isAnimation) {
if (this.root.numChildren > 1) {
var top: any = this.root.getChildAt(this.root.numChildren - 2);
console.log("[SceneManager] Back, from scene:" + perScene.constructor.name + "@" + perScene.hashCode+" to "+top.constructor.name+"@"+top.hashCode);
top.onShow && top.onShow();


}
this.root.removeChild(perScene);
} else {
perScene.x = 0;
egret.Tween.get(perScene, { loop: false }).to({ x: 800, y: 0 }, 600, egret.Ease.quadIn).call(function () {
perScene.x = 0;
this.root.removeChild(perScene);
}.bind(this));
//show top
if (this.root.numChildren > 1) {
var top: any = this.root.getChildAt(this.root.numChildren - 2);
top.onShow && top.onShow();
top.x = -480;
egret.Tween.get(top, { loop: false }).to({ x: 0, y: 0 }, 400, egret.Ease.backIn);
}
}

return true;
} else {
console.warn('[WARN] preScene is undefine');
return false;
}
} else {
console.warn("[SceneManager] Do`t Back!");
return false;
}
else {
console.warn("[SceneManager] Not Back!");
}

}


public static JumpResultUI(p3,p1,p2,iswin,islandwin,timestr , roomid:string){
SceneManager.root.removeChildren();
let re = new ResultUI();
Expand All @@ -75,5 +91,7 @@ class SceneManager {
SceneManager.root.addChild(errpage);
}
}




5 changes: 3 additions & 2 deletions framework/Basic/src/matchvs/PokeMatchvsEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ class PokeMatchvsEngine {
/**
* 踢人
*/
public kickPlayer(userID:number) {
var result = MatchvsData.MatchvsReq.kickPlayer(userID,"你无法跟我一起游戏了");
public kickPlayer(userID:number,name:string) {
var obj = {nickName:name,proto:"你无法跟我一起游戏了"}
var result = MatchvsData.MatchvsReq.kickPlayer(userID,JSON.stringify(obj));
egret.log("踢出" +userID+"result:"+result);
return result;
}
Expand Down
8 changes: 2 additions & 6 deletions framework/Basic/src/scene/Game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ class Game extends eui.Component implements eui.UIComponent {
}
break;
case MatchvsMessage.MATCHVS_JOINROOM_RSP:
var MatchDialog = new MatchDialog(e.data.roomID);
this.addChild(MatchDialog);
// SceneManager.showScene(MatchDialog,e.data.roomID);
SceneManager.showScene(MatchDialog,e.data.roomID);
break;
}
}
Expand All @@ -100,9 +98,7 @@ class Game extends eui.Component implements eui.UIComponent {
private startRoomScene(roomID:string) {
var obj = {roomID: roomID, gameMode:MatchvsData.gameMode,isInvite:this.isInvite,isRestart:true};
this.removeEvent();
var Room = new Room(obj);
this.addChild(Room);
// SceneManager.showScene(Room,obj);
SceneManager.showScene(Room,obj);
this.isInvite = false;
}

Expand Down
11 changes: 3 additions & 8 deletions framework/Basic/src/scene/Login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,21 @@ class Login extends eui.Component implements eui.UIComponent {
Toast.initRes(this, "resource/loading/toast-bg.png");

}
// public tweenGroup: egret.tween.TweenGroup;

protected partAdded(partName: string, instance: any): void {
super.partAdded(partName, instance);
instance.addEventListener(egret.TouchEvent.TOUCH_TAP, function (e: egret.TouchEvent) {
// Toast.show("click:" + partName);
if (partName == "btn_login") {
// Toast.show("ceshi");
if (MatchvsData.loginStatus) {
MatchvsData.loginStatus = false;
var gameLayer = new Game();
this.addChild(gameLayer);
SceneManager.showScene(Game);
} else {
Toast.show("登录失败,重试中");
egret.log("重新登录",GlobalData.myUser.userID+"/n"+GlobalData.myUser.token);
PokeMatchvsEngine.getInstance.init(MatchvsData.pChannel,MatchvsData.pPlatform,MatchvsData.gameID);
}
} else if (partName == "rank_list") {
var rankList = new RankList();
this.addChild(rankList);
SceneManager.showScene(RankList);
}

}, this);
Expand All @@ -35,7 +31,6 @@ class Login extends eui.Component implements eui.UIComponent {

protected childrenCreated(): void {
super.childrenCreated();
// this.that.btnAnim.play();
}

}
17 changes: 8 additions & 9 deletions framework/Basic/src/scene/Result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ResultUI extends eui.Component implements eui.UIComponent {
private _landlordText:string = "";
private _peasant1Text:string = "";
private _peasant2Text:string = "";

private userInfo = [];


public constructor() {
Expand Down Expand Up @@ -217,19 +217,18 @@ class ResultUI extends eui.Component implements eui.UIComponent {
this.integral_peasant1.text = this._peasant1Text;
this.integral_peasant2.text = this._peasant2Text;


this.head_landlord.source = landLord.avator;
this.nickName_landlord.text = landLord.nickName;


var obj = {nickName:landLord.nickName,pointValue:landLord.avator};
this.userInfo.push(obj);
this.head_peasant1.source = peasant1.avator;
this.nickName_peasant1.text = peasant1.nickName;


var obj1 = {nickName:peasant1.nickName,pointValue:peasant1.avator};
this.userInfo.push(obj1);
this.head_peasant2.source = peasant2.avator;
this.nickName_peasant2.text = peasant2.nickName;


var obj2 = {nickName:peasant2.nickName,pointValue:peasant2.avator};
this.userInfo.push(obj2);
//重置我的分数和上报分数到服务器
this.reSetMyScore();

Expand All @@ -240,7 +239,7 @@ class ResultUI extends eui.Component implements eui.UIComponent {
*/
private backConfirm(isGameMode) {
if(isGameMode) {
var obj = {roomID: this.roomID, gameMode:MatchvsData.gameMode,isInvite:false,isRestart:true};
var obj = {roomID: this.roomID, gameMode:MatchvsData.gameMode,isInvite:false,isRestart:true,roomInfo:this.userInfo};
SceneManager.showScene(Room,obj);
} else{
PokeMatchvsEngine.getInstance.leaveRoom("战斗结束了");
Expand Down
20 changes: 17 additions & 3 deletions framework/Basic/src/scene/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Room extends eui.Component implements eui.UIComponent {
private actionViewList = [];
private actionTextViewList = [];
private beKickedOutName = "";
private restartRoomInfo = [];

public constructor() {
super();
Expand Down Expand Up @@ -56,6 +57,7 @@ class Room extends eui.Component implements eui.UIComponent {
if (obj.isRestart) {
this.restart(this.roomID);
}
this.restartRoomInfo = obj.roomInfo;
}


Expand Down Expand Up @@ -218,6 +220,8 @@ class Room extends eui.Component implements eui.UIComponent {
SceneManager.back();
break;
case MatchvsMessage.MATCHVS_KICK_PLAYER_NOTIFY:
console.log('Room');
console.log('Room',JSON.stringify(e.data)+"2");
this.removeView(e.data);
if(e.data.owner !== GlobalData.myUser.userID) {
this.isOwnew(false);
Expand Down Expand Up @@ -292,8 +296,9 @@ class Room extends eui.Component implements eui.UIComponent {
* 玩家退出将玩家的信息从页面上消失
*/
private removeView(data:any) {
console.log('Room',JSON.stringify(data));
var id;
if (data.userId === undefined) {
if (data.userId == undefined) {
id = data.userID;
} else {
id = data.userId;
Expand Down Expand Up @@ -344,7 +349,7 @@ class Room extends eui.Component implements eui.UIComponent {
PokeMatchvsRep.getInstance.addEventListener(MatchvsMessage.MATCHVS_KICK_PLAYER,this.onEvent,this);
for (var i = 0;i < this.userPlayer.length; i++) {
if (name === this.userPlayer[i].nickName) {
PokeMatchvsEngine.getInstance.kickPlayer(this.userPlayer[i].userID);
PokeMatchvsEngine.getInstance.kickPlayer(this.userPlayer[i].userID,name);
}
}
this.beKickedOutName = instance.text;
Expand Down Expand Up @@ -402,9 +407,18 @@ class Room extends eui.Component implements eui.UIComponent {
var user:GUser = new GUser;
var arr = JSON.parse(userPlayer[i].userProfile);
if(arr.userID !== GlobalData.myUser.userID) {
if (this.restartRoomInfo.length > 0) {
for (var a in this.restartRoomInfo) {
if (arr.nickName == this.restartRoomInfo[a].nickName) {
user.pointValue = this.restartRoomInfo[a].pointValue;
}
}
}
user.nickName =arr.nickName;
user.avator = arr.avator;
user.pointValue = arr.pointValue;
if (user.pointValue == undefined) {
user.pointValue = arr.pointValue;
}
user.userID = userPlayer[i].userId;
this.userPlayer.push(user);
}
Expand Down
Loading

0 comments on commit 00e6bce

Please sign in to comment.