var
MyNewGuid = cc.Node.extend({
ctor: function (guidList) {
this._super();
this._flag = 0;
this.Root = null;
this.clipper = null;
this.bg = null;
this.guidList = guidList;
this._touchRect = null;
},
startGuid: function () {
this.endGuid();
if (this._flag > this.guidList.length) {
return;
}
this.showMask(this.getNodeBox(this.guidList[this._flag]));
},
getNodeBox: function (guidInfo) {
if (!guidInfo) {
return
}
var fileName = guidInfo["name"];
if (eval("h1global.curUIMgr." + fileName + "&& h1global.curUIMgr." + fileName + ".is_show")) {
var rootNode = eval("h1global.curUIMgr." + fileName + ".rootUINode");
if (this.Root !== rootNode) {
this.Root = rootNode;
}
var infos = guidInfo["path"].split("/");
var node = null;
if (infos.length <= 0) {
return
} else if (infos.length === 1) {
node = ccui.helper.seekWidgetByName(this.Root, infos[0]);
} else {
node = this.Root.getChildByName(infos[0]);
for (var i = 1; i < infos.length + 1; i++) {
node = node.getChildByName(infos[i]);
}
}
var pt = node.getParent().convertToWorldSpace(node.getPosition());
//通过node锚点计算,矩形大小
pt.x -= node.width * node.anchorX;
pt.y -= node.height * node.anchorY;
var Dots = [
cc.p(pt.x, pt.y),
cc.p(pt.x, pt.y + node.height),
cc.p(pt.x + node.width, pt.y + node.height),
cc.p(pt.x + node.width, pt.y),
];
this._touchRect = cc.rect(pt.x, pt.y, node.width, node.height);
return Dots;
}
},
showMask: function (dots) {
this.bg = ccui.ImageView.create("res/ui/UnionHallUI/bg_hall_img_1.png");
this.bg.setOpacity(70);
this.Root.addChild(this.bg);
this.bg.setPosition(cc.p(this.Root.getContentSize().width*0.5,this.Root.getContentSize().height*0.5));
this.bg.setTouchEnabled(true);
this.bg.setSwallowTouches(true);
this.addListener();
var stencil = this.stencil(dots);
this.clipper = new cc.ClippingNode(stencil);
this.Root.addChild(this.clipper);
},
stencil: function (dots) {
var shape = new cc.DrawNode();
var triangle = dots;
var green = cc.color(0, 78, 165, 255);
shape.drawPoly(triangle, green, 3, green);
return shape;
},
endGuid: function () {
if (!this.check()) {
return;
}
this.bg.removeFromParent();
this.clipper.removeFromParent();
},
add: function () {
this._flag++;
},
check: function () {
if (!this.Root || !this.clipper) {
return false;
}
return true;
},
onTouchBegan:function (touch, event) {
if (!this._touchRect) {
return true;
}
var pt = touch.getLocation();
var ret = cc.rectContainsPoint(this._touchRect, pt);
if (ret){
this.bg.setSwallowTouches(false);
}else {
this.bg.setSwallowTouches(true);
}
return ret;
},
addListener: function () {
// 点击事件
cc.eventManager.addListener(cc.EventListener.create({
event: cc.EventListener.TOUCH_ONE_BY_ONE,
onTouchBegan: this.onTouchBegan.bind(this)
}), this.bg);
},
})
浙公网安备 33010602011771号