Log.js
5.34 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
var Network = require('Network');
var Common = require('Common');
cc.Class({
extends: cc.Component,
properties: {
// foo: {
// default: null, // The default value will be used only when the component attaching
// to a node for the first time
// url: cc.Texture2D, // optional, default is typeof default
// serializable: true, // optional, default is true
// visible: true, // optional, default is true
// displayName: 'Foo', // optional
// readonly: false, // optional, default is false
// },
// ...
_iLogCount:0,
_oScene:null,
},
init: function (oScene) {
this._oScene=oScene;
},
// use this for initialization
onLoad: function () {
//设置本身节点的宽高透明
this.node.x=0;
this.node.y=0;
this.node.width=Common.SCREEN_WIDTH;
this.node.height=Common.SCREEN_HEIGHT;
let nodeLogMask=new cc.Node('LogMask');
nodeLogMask.x=0;
nodeLogMask.y=0;
this.node.addChild(nodeLogMask,10);
//设置为全屏遮罩
// let urlSplash = cc.url.raw('resources/Texture/splash_black.png');
// let textureFocus = cc.textureCache.addImage(urlSplash);
let spriteSplash=nodeLogMask.addComponent(cc.Sprite);
// spriteSplash.spriteFrame = new cc.SpriteFrame(textureFocus);
//TODO:2.0移除cc.textureCache
// cc.loader.loadRes("Texture/ui/splash_black",cc.SpriteFrame,function(error,spriteFrame){
// spriteSplash.spriteFrame=spriteFrame;
// });
//因为纹理2*2所以这里写死了
nodeLogMask.setScale(Common.SCREEN_WIDTH/2,Common.SCREEN_HEIGHT/2);
nodeLogMask.opacity=100;
// nodeLogMask.setLocalZOrder(400);//2.0中所有子节点都会在父节点之后渲染
let nodeLogList=new cc.Node('LogList');
nodeLogList.x = 20 - Common.SCREEN_WIDTH/2;
nodeLogList.y = Common.SCREEN_HEIGHT/2 - 20;
nodeLogList.setAnchorPoint(0,1);
this.node.addChild(nodeLogList,10);
// nodeLogList.setLocalZOrder(402);
this._nodeLogList = nodeLogList;
//this.node.color=new cc.Color(0, 0, 0); //黑色
//this.node.cascadeOpacity=false;
//this.node.parent=this._oScene.node;
//this.node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(Texture2D.);
//parentNode.cascadeOpacity=false;
},
//statics: {
serverD:function(strInfo){
},
screenD:function(strInfo){
this.flushLogToScreen(strInfo,'Debug');
},
serverI:function(strInfo){
},
screenI:function(strInfo){
this.flushLogToScreen(strInfo,'Info');
},
serverW:function(strInfo){
},
screenW:function(strInfo){
this.flushLogToScreen(strInfo,'Warning');
},
serverE:function(strInfo){
},
screenE:function(strInfo){
this.flushLogToScreen(strInfo,'Error');
},
flushLogToScreen:function(strInfo, strLevel){
let nodeInfo=new cc.Node('log_info_'+this._iLogCount);
let lblInfo=nodeInfo.addComponent(cc.Label);
this._iLogCount++;
//if _iLogCount>20
lblInfo.string=strLevel+':'+strInfo;//+(nodeInfo.width/2-Common.SCREEN_WIDTH/2);
lblInfo.fontSize=18;
lblInfo.lineHeight=20;
//nodeInfo.parent=this.node;
nodeInfo.parent=this._nodeLogList;
switch(strLevel){
case 'Debug':
nodeInfo.color=new cc.color(51,255,255,255);
break;
case 'Info':
nodeInfo.color=new cc.color(51,255,51,255);
break;
case 'Warning':
nodeInfo.color=new cc.color(255,255,51,255);
break;
case 'Error':
nodeInfo.color=new cc.color(255,51,51,255);
break;
default:
nodeInfo.color=new cc.color(255,255,255,255);
}
//nodeInfo.color=new cc.color(255,255,255,255);
nodeInfo.height=20;
nodeInfo.setAnchorPoint(0,1);
nodeInfo.y = -(this._iLogCount-1)*20;
// nodeInfo.setLocalZOrder(401);
this._nodeLogList.y = this._nodeLogList.y + ((this._iLogCount - parseInt(Common.SCREEN_HEIGHT/20)+1)>0 ? 20 : 0);
},
clearLogOnScreen : function () {
this._nodeLogList.destroy();
this._iLogCount = 0;
let nodeLogList=new cc.Node('LogList');
nodeLogList.x = 20 - Common.SCREEN_WIDTH/2;
nodeLogList.y = Common.SCREEN_HEIGHT/2 - 20;
nodeLogList.setAnchorPoint(0,1);
this.node.addChild(nodeLogList,10);
// nodeLogList.setLocalZOrder(402);
this._nodeLogList = nodeLogList;
},
flushLogToServer:function(){
}
//TODO:需要加一个清除(所有条目全删除)和删除日志(一条一条删除)的函数
//}
// called every frame, uncomment this function to activate update callback
// update: function (dt) {
// },
});