FocusInfo.js
5.08 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
177
var Common = require('Common');
cc.Class({
extends: cc.Component,
properties: {
// TODO: to be a real Component?
//_fLeft:0,
//_fTop:0,
//_fWidth:0,
//_fHeight:0,
//_oFocusNode:null,//deprecated
_strTVLink: '',
_bEnable: false,
_fScaleFactor: 1.06,
_bIgnoreZIndex: false,
_iFlyDelayTime: 0,
_iFocusWeight: 100,
},
//ctor: function (fLeft,fTop,fWidth,fHeight,oFocusNode,strTVLink,bEnable,fnOnFocus,fnOnBlur) {
ctor: function () {
//this._fLeft=arguments[0];
//this._fTop=arguments[1];
//this._fWidth=arguments[2];
//this._fHeight=arguments[3];
//this._oFocusNode=arguments[4];
this._strTVLink = arguments[0];
this._bEnable = arguments[1];
this._fnOnFocus = arguments[2];
this._fnOnBlur = arguments[3];
//this._fLeft=fLeft;
//this._fTop=fTop;
//this._fWidth=fWidth;
//this._fHeight=fHeight;
//this._oFocusNode=oFocusNode;
},
init: function (/*fLeft,fTop,fWidth,fHeight,oFocusNode,*/strTVLink, bEnable, fnOnFocus, fnOnBlur, fScaleFactor) {
//this._fLeft=arguments[0];
//this._fTop=arguments[1];
//this._fWidth=arguments[2];
//this._fHeight=arguments[3];
//this._oFocusNode=arguments[4];
this._strTVLink = strTVLink;
this._bEnable = bEnable;
this._fnOnFocus = fnOnFocus;
this._fnOnBlur = fnOnBlur;
this._fScaleFactor = fScaleFactor;
//this._fLeft=fLeft;
//this._fTop=fTop;
this._fWidth = 0;
this._fHeight = 0;
//this._oFocusNode=oFocusNode;
this._oProbeInfo = {};
},
// use this for initialization
onLoad: function () {
//气泡式向上传递 通常收不到
//this.node.on('foucs', this._fnOnFocus || function(){},this);
//this.node.on('blur', this._fnOnBlur || function(){},this);
},
setFlyDelayTime: function (iDuration) {
this._iFlyDelayTime = iDuration;
},
getFlyDelayTime: function () {
return this._iFlyDelayTime;
},
setFocusWeight: function (iWeight) {
this._iFocusWeight = iWeight;
},
getFocusWeight: function () {
return this._iFocusWeight;
},
getLeft: function () {
//return this._fLeft;
return Common.SCREEN_WIDTH / 2 + (this.getX() - this.node.width / 2);
},
getTop: function () {
//return this._fTop;
return Common.SCREEN_HEIGHT / 2 - (this.getY() + this.node.height / 2);
},
getX: function () {
return Common.getX(this.node);
},
getY: function () {
return Common.getY(this.node);
},
getWidth: function () {
//return this._fWidth;
return this._fWidth || this.node.width; //有时候设计上元素会交叉,所以找焦点的时候只能设置虚拟尺寸
},
setFakeWidth: function (fWidth) {
this._fWidth = fWidth;
},
getHeight: function () {
return this._fHeight || this.node.height;
},
setFakeHeight: function (fHeight) {
this._fHeight = fHeight;
},
//getFocusNode:function(){
// return this._oFocusNode;
//},
//setFocusNode:function(oFocusNode){
// this._oFocusNode=oFocusNode;
//},
getTVLink: function () {
return this._strTVLink;
},
setTVLink: function (strTVLink) {
this._strTVLink = strTVLink;
},
getEnable: function () {
return this._bEnable;
},
setEnable: function (bEnable) {
this._bEnable = bEnable;
// cc.log("改变节点Enable属性:" + this.node.name+" : "+bEnable);
},
onFocus: function (fiFrom) {
if (this._fnOnFocus) {
this._fnOnFocus(fiFrom);
}
},
onBlur: function (fiTo) {
if (this._fnOnBlur) {
this._fnOnBlur(fiTo);
}
},
getScaleFactor: function () {
return this._fScaleFactor;
},
setScaleFactor: function (fScaleFactor) {
this._fScaleFactor = fScaleFactor;
},
ignoreZIndex: function (bool) {
this._bIgnoreZIndex = bool;
},
setFocusProbeInfo: function (oInfo) {
this._oProbeInfo = oInfo;
},
getFocusProbeInfo: function () {
return this._oProbeInfo;
},
onEnable: function () { //修改节点的active属性为true时会执行挂载组件的onEnable方法
//注意:子节点有ListView要慎用!会使所有未初始化数据的子节点也改变焦点状态
// cc.log("执行FocusInfo中onEnable方法");
// if (0 != this.node.name.indexOf('RoleInstallListCell') && 0 != this.node.name.indexOf('AchievementListCell')) {
this._bEnable = true;
// }
},
onDisable: function () { //修改节点的active属性为false时会执行挂载组件的onDisable方法
// cc.log("执行FocusInfo中onDisable方法" + this.node.name);
// if (0 != this.node.name.indexOf('CategoryListCell')) {
this._bEnable = false;
// cc.log("隐藏的名称:" + this.node.name);
// }
},
});