654 lines
22 KiB
JavaScript
654 lines
22 KiB
JavaScript
|
|
"use strict";
|
||
|
|
cc._RF.push(module, '5c013vN5KFCGKEPXIcgtbFA', 'gmcmd');
|
||
|
|
// Scripts/common/gmcmd.js
|
||
|
|
|
||
|
|
"use strict";
|
||
|
|
|
||
|
|
/*-----------------------------------------------------+
|
||
|
|
* GM命令处理类相关处理
|
||
|
|
* @author whjing2012@163.com
|
||
|
|
+-----------------------------------------------------*/
|
||
|
|
|
||
|
|
var _require = require("define"),
|
||
|
|
SCENE_TAG = _require.SCENE_TAG,
|
||
|
|
SCREEN_WIDTH = _require.SCREEN_WIDTH,
|
||
|
|
SCREEN_HEIGHT = _require.SCREEN_HEIGHT;
|
||
|
|
var GmCmd = {
|
||
|
|
getInstance: function getInstance() {
|
||
|
|
return this;
|
||
|
|
},
|
||
|
|
// 自定义gm命令
|
||
|
|
cli_cmds: [{
|
||
|
|
name: "关闭GM",
|
||
|
|
func: function func() {
|
||
|
|
this.show();
|
||
|
|
}
|
||
|
|
}, {
|
||
|
|
name: "net_ping",
|
||
|
|
func: function func() {
|
||
|
|
if (this.ping_timer_id) {
|
||
|
|
gcore.Timer.del(this.ping_timer_id);
|
||
|
|
this.ping_timer_id = undefined;
|
||
|
|
self.label.string = "";
|
||
|
|
} else {
|
||
|
|
this.ping_timer_id = gcore.Timer.set(function () {
|
||
|
|
client.socket.send(1198, {
|
||
|
|
time: this.get_ping_time()
|
||
|
|
});
|
||
|
|
}.bind(this), 1000, -1);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}, {
|
||
|
|
name: "断网",
|
||
|
|
func: function func() {
|
||
|
|
client.socket.breakws();
|
||
|
|
}
|
||
|
|
}, {
|
||
|
|
name: "FPS",
|
||
|
|
func: function func() {
|
||
|
|
cc.debug.setDisplayStats(cc.game.config.showFPS = !cc.game.config.showFPS);
|
||
|
|
}
|
||
|
|
}, {
|
||
|
|
name: "UI调试",
|
||
|
|
func: function func() {
|
||
|
|
this.openDebugUI();
|
||
|
|
}
|
||
|
|
}, {
|
||
|
|
name: "系统信息",
|
||
|
|
func: function func() {
|
||
|
|
cc.sys.dump();
|
||
|
|
}
|
||
|
|
}, {
|
||
|
|
name: "在线福利",
|
||
|
|
func: function func() {
|
||
|
|
require("onlinegift_controller").getInstance().openOnlineGiftView(true);
|
||
|
|
}
|
||
|
|
}, {
|
||
|
|
name: "DCBox",
|
||
|
|
func: function func() {
|
||
|
|
if (nx) {
|
||
|
|
nx.mbox("FPS:" + Math.floor(1 / cc.director.getDeltaTime()) + " DC:" + cc.renderer.drawCalls);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}],
|
||
|
|
// 处理输入信息
|
||
|
|
handleInput: function handleInput(msg) {
|
||
|
|
if (msg == '') {
|
||
|
|
return;
|
||
|
|
} else if (msg.charAt(0) == "@") {
|
||
|
|
// eval("nx.info("+msg.substr(1)+");");
|
||
|
|
return;
|
||
|
|
} else if (msg.charAt(0) == ".") {
|
||
|
|
var keys = msg.substr(1).split(".");
|
||
|
|
var o = window;
|
||
|
|
for (var i = 0, n = keys.length; i < n; i++) {
|
||
|
|
o = o[keys[i]];
|
||
|
|
}
|
||
|
|
nx.debug(o);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
this.saveMsg(msg);
|
||
|
|
client.socket.send(10399, {
|
||
|
|
msg: msg
|
||
|
|
});
|
||
|
|
},
|
||
|
|
get_ping_time: function get_ping_time() {
|
||
|
|
return cc.sys.now() % 10000000;
|
||
|
|
},
|
||
|
|
// 显示gm命令
|
||
|
|
show: function show() {
|
||
|
|
var _this = this;
|
||
|
|
// console.log( "顯示 2222222222222gm" );
|
||
|
|
// if( nx.bridge.vget( "gm" ) ) {
|
||
|
|
// nx.bridge.vset( "showGM", true );
|
||
|
|
// }
|
||
|
|
|
||
|
|
// if( !nx.bridge.vget( "showGM" ) ) {
|
||
|
|
// return;
|
||
|
|
// }
|
||
|
|
// if( this.root ) {
|
||
|
|
// this.root.active = ( this.root.active == false );
|
||
|
|
// return;
|
||
|
|
// }
|
||
|
|
|
||
|
|
client.socket.unbindCmd(10391, "gm");
|
||
|
|
client.socket.unbindCmd(10399, "gm");
|
||
|
|
client.socket.unbindCmd(1198, "gm");
|
||
|
|
this.move = false;
|
||
|
|
// console.log( "顯示 222222gm" );
|
||
|
|
var path = cc.path.join("prefab", "gm", "gm_panel");
|
||
|
|
nx.res.loadPrefab(path, function (_err, _fab) {
|
||
|
|
if (_err) {
|
||
|
|
nx.tbox(_err.message || "");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
_this.root = cc.instantiate(_fab);
|
||
|
|
_this.root.gm = true;
|
||
|
|
var gm_btn = _this.root.getChildByName("gm_btn");
|
||
|
|
_this.input = _this.root.getChildByName("editbox").getComponent(cc.EditBox);
|
||
|
|
_this.input.maxLength = 300;
|
||
|
|
_this.label = _this.root.getChildByName("msg").getComponent(cc.RichText);
|
||
|
|
_this.root.setPosition(-SCREEN_WIDTH * 0.5, -SCREEN_HEIGHT * 0.5);
|
||
|
|
// console.log( nx.bridge.ui + "顯示----" + this.root );
|
||
|
|
nx.bridge.ui.addToSceneNode(_this.root, SCENE_TAG.msg);
|
||
|
|
gm_btn.on(cc.Node.EventType.TOUCH_END, function (event) {
|
||
|
|
if (this.move) {
|
||
|
|
this.move = false;
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
if (this.debug_ui && this.debug_ui.active) {
|
||
|
|
this.debug_ui.active = false;
|
||
|
|
this.setDebugUIObjBorder(this.debug_ui_obj1, false);
|
||
|
|
}
|
||
|
|
this.showLayer();
|
||
|
|
}.bind(_this));
|
||
|
|
gm_btn.on(cc.Node.EventType.TOUCH_MOVE, function (event) {
|
||
|
|
var pos = event.getTouches()[0].getDelta();
|
||
|
|
this.root.x = this.root.x + pos.x;
|
||
|
|
this.root.y = this.root.y + pos.y;
|
||
|
|
if (pos.x !== 0 && pos.y !== 0) {
|
||
|
|
this.move = true;
|
||
|
|
}
|
||
|
|
}, _this);
|
||
|
|
_this.input.node.on('editing-did-ended', function () {
|
||
|
|
this.handleInput(this.input.string);
|
||
|
|
}, _this);
|
||
|
|
_this.cmds = nx.storage.getObject("gm_cmds").cmds || [];
|
||
|
|
if (_this.cmds.length > 0) {
|
||
|
|
_this.input.string = _this.cmds[_this.cmds.length - 1];
|
||
|
|
}
|
||
|
|
client.socket.bindCmd(10391, _this.on10391.bind(_this), "gm");
|
||
|
|
client.socket.bindCmd(10399, _this.on10399.bind(_this), "gm");
|
||
|
|
client.socket.bindCmd(1198, _this.on1198.bind(_this), "gm");
|
||
|
|
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, _this.onKeyDown, _this);
|
||
|
|
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP, _this.onKeyUp, _this);
|
||
|
|
_this.button = _this.root.getChildByName("Button");
|
||
|
|
});
|
||
|
|
},
|
||
|
|
// 显示gm面板
|
||
|
|
showLayer: function showLayer() {
|
||
|
|
this.layer = this.root.getChildByName("layer");
|
||
|
|
this.layer.active = !this.layer.active;
|
||
|
|
var btn_list = [{
|
||
|
|
name: "基础功能",
|
||
|
|
list: this.cli_cmds
|
||
|
|
}, {
|
||
|
|
name: "最近使用"
|
||
|
|
}];
|
||
|
|
if (game.configs && game.configs.gm_data) {
|
||
|
|
for (var k in game.configs.gm_data.data_list) {
|
||
|
|
var v = game.configs.gm_data.data_list[k];
|
||
|
|
if (v.is_show == 1) {
|
||
|
|
if (v.list.length == 0) {
|
||
|
|
btn_list.push({
|
||
|
|
name: v.tips,
|
||
|
|
msg: v.info
|
||
|
|
});
|
||
|
|
} else {
|
||
|
|
btn_list.push({
|
||
|
|
name: v.tips,
|
||
|
|
list: v.list
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
this.showGmList(true, btn_list);
|
||
|
|
// if( this.layer ) {
|
||
|
|
// this.layer.active = this.layer.active == false;
|
||
|
|
// return;
|
||
|
|
// } else {
|
||
|
|
|
||
|
|
// }
|
||
|
|
},
|
||
|
|
|
||
|
|
// 显示下级gm面板
|
||
|
|
showGmList: function showGmList(btn, btn_list) {
|
||
|
|
if (this.sub_layer && this.sub_layer.active && btn != true && this.sub_layer != btn.layer) {
|
||
|
|
this.sub_layer.active = false;
|
||
|
|
}
|
||
|
|
if (btn == true) {
|
||
|
|
for (var i = 0; i < btn_list.length; i++) {
|
||
|
|
var v = btn_list[i];
|
||
|
|
this.createGmButton(i, this.layer, v);
|
||
|
|
}
|
||
|
|
} else if (btn.layer) {
|
||
|
|
if (btn.layer.lately) {
|
||
|
|
btn.layer.destroy();
|
||
|
|
btn.layer = null;
|
||
|
|
this.sub_layer = null;
|
||
|
|
} else {
|
||
|
|
btn.layer.active = btn.layer.active == false;
|
||
|
|
this.sub_layer = btn.layer;
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
btn.layer = new cc.Node();
|
||
|
|
this.sub_layer = btn.layer;
|
||
|
|
this.layer.addChild(btn.layer);
|
||
|
|
btn.layer.setAnchorPoint(0, 1);
|
||
|
|
btn.layer.setPosition(0, btn.y - 25);
|
||
|
|
if (!btn_list) {
|
||
|
|
btn.layer.lately = true;
|
||
|
|
btn_list = [];
|
||
|
|
for (var i = 0; i < this.cmds.length; i++) {
|
||
|
|
btn_list.push({
|
||
|
|
name: this.cmds[i],
|
||
|
|
msg: this.cmds[i]
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
for (var i = 0; i < btn_list.length; i++) {
|
||
|
|
var v = btn_list[i];
|
||
|
|
this.createGmButton(i, btn.layer, v, 'common_1018');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
},
|
||
|
|
// 创建一个gm按钮
|
||
|
|
createGmButton: function createGmButton(i, layer, v, res) {
|
||
|
|
if (typeof v == "number") {
|
||
|
|
v = game.configs.gm_data.data_list[v];
|
||
|
|
if (v.list.length == 0) {
|
||
|
|
v = {
|
||
|
|
name: v.tips,
|
||
|
|
msg: v.info
|
||
|
|
};
|
||
|
|
} else {
|
||
|
|
v = {
|
||
|
|
name: v.tips,
|
||
|
|
list: v.list
|
||
|
|
};
|
||
|
|
}
|
||
|
|
}
|
||
|
|
var btn = this.createButton(v.name, v.func || function (event) {
|
||
|
|
if (v.msg) {
|
||
|
|
client.socket.send(10399, {
|
||
|
|
msg: v.msg
|
||
|
|
});
|
||
|
|
} else {
|
||
|
|
this.showGmList(event.target, v.list);
|
||
|
|
}
|
||
|
|
}, res);
|
||
|
|
btn.setPosition(i % 4 * 135 + 70, -(parseInt(i / 4) * 65 + 40));
|
||
|
|
layer.addChild(btn);
|
||
|
|
},
|
||
|
|
// 键盘按下事件
|
||
|
|
onKeyDown: function onKeyDown(event) {
|
||
|
|
this.keyCode = event.keyCode;
|
||
|
|
var func = function (time) {
|
||
|
|
if (!this.keyCode || !this.root.active) return;
|
||
|
|
switch (this.keyCode) {
|
||
|
|
case cc.macro.KEY.up:
|
||
|
|
if (this.cmds.length > 1) {
|
||
|
|
this.cmds.unshift(this.cmds.pop());
|
||
|
|
this.saveMsg(this.cmds.pop());
|
||
|
|
time = time || 1500;
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
case cc.macro.KEY.down:
|
||
|
|
if (this.cmds.length > 0) {
|
||
|
|
this.saveMsg(this.cmds[0]);
|
||
|
|
time = time || 600;
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
case cc.macro.KEY.enter:
|
||
|
|
this.handleInput(this.input.string);
|
||
|
|
time = null;
|
||
|
|
break;
|
||
|
|
case cc.macro.KEY.a:
|
||
|
|
this.moveDebugUIObjPos(-1, 0);
|
||
|
|
time = time || 100;
|
||
|
|
break;
|
||
|
|
case cc.macro.KEY.d:
|
||
|
|
this.moveDebugUIObjPos(1, 0);
|
||
|
|
time = time || 100;
|
||
|
|
break;
|
||
|
|
case cc.macro.KEY.w:
|
||
|
|
this.moveDebugUIObjPos(0, 1);
|
||
|
|
time = time || 100;
|
||
|
|
break;
|
||
|
|
case cc.macro.KEY.s:
|
||
|
|
this.moveDebugUIObjPos(0, -1);
|
||
|
|
time = time || 100;
|
||
|
|
break;
|
||
|
|
default:
|
||
|
|
time = null;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
if (time) {
|
||
|
|
gcore.Timer.set(func, time, 1, "gm_cmd_key_timer");
|
||
|
|
}
|
||
|
|
}.bind(this);
|
||
|
|
func(2000);
|
||
|
|
},
|
||
|
|
// 键盘释放事件
|
||
|
|
onKeyUp: function onKeyUp(event) {
|
||
|
|
if (this.keyCode == event.keyCode) {
|
||
|
|
this.keyCode = null;
|
||
|
|
}
|
||
|
|
},
|
||
|
|
// 协议返回处理
|
||
|
|
on10391: function on10391(data) {
|
||
|
|
//cc.log("DDDDDDDDDDDDDDDDDDD");
|
||
|
|
//cc.log(data);
|
||
|
|
|
||
|
|
var ret = eval(data.data);
|
||
|
|
if (data.type == 1) {
|
||
|
|
if (typeof ret == 'object') {
|
||
|
|
ret = JSON.stringify(ret);
|
||
|
|
} else {
|
||
|
|
ret = ret + '';
|
||
|
|
}
|
||
|
|
client.socket.send(10391, {
|
||
|
|
msg: ret
|
||
|
|
});
|
||
|
|
}
|
||
|
|
},
|
||
|
|
// gm命令结果
|
||
|
|
on10399: function on10399(data) {
|
||
|
|
if (data.msg.length < 500) {
|
||
|
|
// nx.tbox( data.msg );
|
||
|
|
}
|
||
|
|
nx.debug(data.msg.split("\n"));
|
||
|
|
},
|
||
|
|
on1198: function on1198(data) {
|
||
|
|
if (this.ping_timer_id) {
|
||
|
|
this.label.string = "time:<color=#00ff00>" + (this.get_ping_time() - data.time) + "</color>,msg_len:<color=#00ff00>" + client.socket.msg_list.length + "</color>";
|
||
|
|
}
|
||
|
|
},
|
||
|
|
// 保存信息
|
||
|
|
saveMsg: function saveMsg(msg) {
|
||
|
|
this.input.string = msg;
|
||
|
|
for (var i = this.cmds.length - 1; i >= 0; i--) {
|
||
|
|
if (this.cmds[i] == msg) {
|
||
|
|
this.cmds.splice(i, 1);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
this.cmds.push(msg);
|
||
|
|
if (this.cmds.length > 20) {
|
||
|
|
this.cmds.shift();
|
||
|
|
}
|
||
|
|
nx.storage.setObject("gm_cmds", {
|
||
|
|
cmds: this.cmds
|
||
|
|
});
|
||
|
|
},
|
||
|
|
// 创建一个gm按钮
|
||
|
|
createButton: function createButton(text, func, res) {
|
||
|
|
// var gm_btn = new cc.Node();
|
||
|
|
// gm_btn.setPosition(0, 0);
|
||
|
|
// var gm_buttom = gm_btn.addComponent(cc.Button);
|
||
|
|
// gm_buttom.target = gm_btn;
|
||
|
|
// gm_buttom.transition = cc.Button.Transition.SCALE;
|
||
|
|
// gm_buttom.duration = 0.1;
|
||
|
|
// gm_buttom.zoomScale = 1.1;
|
||
|
|
// var gm_sprite = gm_btn.addComponent(cc.Sprite);
|
||
|
|
// var frame = COMMON_ATLAS.getSpriteFrame(res || 'common_1017');
|
||
|
|
// gm_sprite.spriteFrame = frame;
|
||
|
|
// gm_sprite.type = cc.Sprite.Type.SLICED;
|
||
|
|
// var gm_label = this.createLabel(text, new cc.Color(0, 0, 0xff));
|
||
|
|
// gm_btn.addChild(gm_label);
|
||
|
|
// gm_btn.on(cc.Node.EventType.TOUCH_END, func, this);
|
||
|
|
|
||
|
|
var gm_btn = cc.instantiate(this.button);
|
||
|
|
gm_btn.active = true;
|
||
|
|
var label = gm_btn.getChildByName("Label").getComponent(cc.Label);
|
||
|
|
label.string = text;
|
||
|
|
gm_btn.on(cc.Node.EventType.TOUCH_END, func, this);
|
||
|
|
return gm_btn;
|
||
|
|
},
|
||
|
|
// 创建一个Label
|
||
|
|
createLabel: function createLabel(text, color, fontSize) {
|
||
|
|
var node = new cc.Node();
|
||
|
|
var label = node.addComponent(cc.Label);
|
||
|
|
node.obj = label;
|
||
|
|
label.string = text || '';
|
||
|
|
label.fontSize = fontSize || 24;
|
||
|
|
node.color = color || new cc.Color(255, 0, 0);
|
||
|
|
return node;
|
||
|
|
},
|
||
|
|
// DebugUi
|
||
|
|
openDebugUI: function openDebugUI() {
|
||
|
|
this.layer.active = false;
|
||
|
|
if (this.debug_ui) {
|
||
|
|
this.debug_ui.active = this.debug_ui.active == false;
|
||
|
|
this.setDebugUIObjBorder(this.debug_ui_obj1, false);
|
||
|
|
} else {
|
||
|
|
this.debug_ui = this.root.getChildByName("debug_ui");
|
||
|
|
this.debug_ui.active = true;
|
||
|
|
var o = {};
|
||
|
|
o.touch = this.debug_ui.getChildByName("touch_node");
|
||
|
|
o.name = this.debug_ui.getChildByName("name").getChildByName("msg").getComponent(cc.Label);
|
||
|
|
o.type = this.debug_ui.getChildByName("type").getChildByName("msg").getComponent(cc.Label);
|
||
|
|
o.node_w = this.debug_ui.getChildByName("node_w").getChildByName("editbox").getComponent(cc.EditBox);
|
||
|
|
o.node_h = this.debug_ui.getChildByName("node_h").getChildByName("editbox").getComponent(cc.EditBox);
|
||
|
|
o.node_sx = this.debug_ui.getChildByName("node_sx").getChildByName("editbox").getComponent(cc.EditBox);
|
||
|
|
o.node_sy = this.debug_ui.getChildByName("node_sy").getChildByName("editbox").getComponent(cc.EditBox);
|
||
|
|
o.node_ax = this.debug_ui.getChildByName("node_ax").getChildByName("editbox").getComponent(cc.EditBox);
|
||
|
|
o.node_ay = this.debug_ui.getChildByName("node_ay").getChildByName("editbox").getComponent(cc.EditBox);
|
||
|
|
o.node_wx = this.debug_ui.getChildByName("node_wx").getChildByName("editbox").getComponent(cc.EditBox);
|
||
|
|
o.node_wy = this.debug_ui.getChildByName("node_wy").getChildByName("editbox").getComponent(cc.EditBox);
|
||
|
|
o.node_x = this.debug_ui.getChildByName("node_x").getChildByName("editbox").getComponent(cc.EditBox);
|
||
|
|
o.node_y = this.debug_ui.getChildByName("node_y").getChildByName("editbox").getComponent(cc.EditBox);
|
||
|
|
o.node_c_r = this.debug_ui.getChildByName("node_c").getChildByName("editbox_r").getComponent(cc.EditBox);
|
||
|
|
o.node_c_g = this.debug_ui.getChildByName("node_c").getChildByName("editbox_g").getComponent(cc.EditBox);
|
||
|
|
o.node_c_b = this.debug_ui.getChildByName("node_c").getChildByName("editbox_b").getComponent(cc.EditBox);
|
||
|
|
o.node_c_a = this.debug_ui.getChildByName("node_c").getChildByName("editbox_a").getComponent(cc.EditBox);
|
||
|
|
o.show = this.debug_ui.getChildByName("show").getComponent(cc.Toggle);
|
||
|
|
o.child_btn = this.debug_ui.getChildByName("child_btn");
|
||
|
|
o.parent_btn = this.debug_ui.getChildByName("parent_btn");
|
||
|
|
o.scroll_content = this.debug_ui.getChildByName("scrollview").getComponent(cc.ScrollView).content;
|
||
|
|
o.scroll_item = o.scroll_content.getChildByName("item");
|
||
|
|
this.debug_ui_o = o;
|
||
|
|
this.setDebugUIEvt(o);
|
||
|
|
}
|
||
|
|
if (this.debug_ui.active) {
|
||
|
|
this.setDebugUIObj(this.input);
|
||
|
|
}
|
||
|
|
},
|
||
|
|
setDebugUIEvt: function setDebugUIEvt(o) {
|
||
|
|
o.touch.on(cc.Node.EventType.TOUCH_END, function (event) {
|
||
|
|
this.selectDebugUIObj(event.getTouches()[0].getLocation());
|
||
|
|
}, this);
|
||
|
|
o.show.node.on(cc.Node.EventType.TOUCH_END, function (event) {
|
||
|
|
this.debug_ui_obj1.active = !this.debug_ui_obj1.active;
|
||
|
|
}, this);
|
||
|
|
o.parent_btn.on(cc.Node.EventType.TOUCH_END, function (event) {
|
||
|
|
this.setDebugUIObj(this.debug_ui_obj.node || this.debug_ui_obj.parent);
|
||
|
|
}, this);
|
||
|
|
o.node_w.node.on('editing-did-ended', function (event) {
|
||
|
|
this.debug_ui_obj1.width = Number(o.node_w.string);
|
||
|
|
this.setDebugUIObjBorder(this.debug_ui_obj1, true);
|
||
|
|
}, this);
|
||
|
|
o.node_h.node.on('editing-did-ended', function (event) {
|
||
|
|
this.debug_ui_obj1.height = Number(o.node_h.string);
|
||
|
|
this.setDebugUIObjBorder(this.debug_ui_obj1, true);
|
||
|
|
}, this);
|
||
|
|
o.node_sx.node.on('editing-did-ended', function (event) {
|
||
|
|
this.debug_ui_obj1.scaleX = Number(o.node_sx.string);
|
||
|
|
this.setDebugUIObjBorder(this.debug_ui_obj1, true);
|
||
|
|
}, this);
|
||
|
|
o.node_sy.node.on('editing-did-ended', function (event) {
|
||
|
|
this.debug_ui_obj1.scaleY = Number(o.node_sy.string);
|
||
|
|
this.setDebugUIObjBorder(this.debug_ui_obj1, true);
|
||
|
|
}, this);
|
||
|
|
o.node_ax.node.on('editing-did-ended', function (event) {
|
||
|
|
this.debug_ui_obj1.setAnchorPoint(Number(o.node_ax.string), Number(o.node_ay.string));
|
||
|
|
this.setDebugUIObjBorder(this.debug_ui_obj1, true);
|
||
|
|
}, this);
|
||
|
|
o.node_ay.node.on('editing-did-ended', function (event) {
|
||
|
|
this.debug_ui_obj1.setAnchorPoint(Number(o.node_ax.string), Number(o.node_ay.string));
|
||
|
|
this.setDebugUIObjBorder(this.debug_ui_obj1, true);
|
||
|
|
}, this);
|
||
|
|
o.node_x.node.on('editing-did-ended', function (event) {
|
||
|
|
this.debug_ui_obj1.x = Number(o.node_x.string);
|
||
|
|
this.setDebugUIObjBorder(this.debug_ui_obj1, true);
|
||
|
|
}, this);
|
||
|
|
o.node_y.node.on('editing-did-ended', function (event) {
|
||
|
|
this.debug_ui_obj1.y = Number(o.node_y.string);
|
||
|
|
this.setDebugUIObjBorder(this.debug_ui_obj1, true);
|
||
|
|
}, this);
|
||
|
|
o.node_c_a.node.on('editing-did-ended', function (event) {
|
||
|
|
this.debug_ui_obj1.opacity = Number(o.node_c_a.string);
|
||
|
|
}, this);
|
||
|
|
o.node_c_r.node.on('editing-did-ended', function (event) {
|
||
|
|
this.setDebugUIObjColor(o);
|
||
|
|
}, this);
|
||
|
|
o.node_c_g.node.on('editing-did-ended', function (event) {
|
||
|
|
this.setDebugUIObjColor(o);
|
||
|
|
}, this);
|
||
|
|
o.node_c_b.node.on('editing-did-ended', function (event) {
|
||
|
|
this.setDebugUIObjColor(o);
|
||
|
|
}, this);
|
||
|
|
},
|
||
|
|
moveDebugUIObjPos: function moveDebugUIObjPos(x, y) {
|
||
|
|
if (!this.debug_ui || !this.debug_ui.active || !this.debug_ui_obj1) return;
|
||
|
|
this.debug_ui_obj1.setPosition(this.debug_ui_obj1.x + x, this.debug_ui_obj1.y + y);
|
||
|
|
this.setDebugUIObj(this.debug_ui_obj1);
|
||
|
|
},
|
||
|
|
setDebugUIObjColor: function setDebugUIObjColor(o) {
|
||
|
|
if (this.debug_ui_obj.fontColor) {
|
||
|
|
this.debug_ui_obj.fontColor = new cc.Color(Number(o.node_c_r.string), Number(o.node_c_g.string), Number(o.node_c_b.string));
|
||
|
|
} else if (this.debug_ui_obj1.color) {
|
||
|
|
this.debug_ui_obj.color = new cc.Color(Number(o.node_c_r.string), Number(o.node_c_g.string), Number(o.node_c_b.string));
|
||
|
|
}
|
||
|
|
},
|
||
|
|
setDebugUIObj: function setDebugUIObj(obj) {
|
||
|
|
if (!obj) return;
|
||
|
|
// nx.info("====>>>", obj.w_zIndex);
|
||
|
|
this.setDebugUIObjBorder(this.debug_ui_obj1, false);
|
||
|
|
if (this.debug_ui_obj != obj) {
|
||
|
|
this.updateChildNodes(obj);
|
||
|
|
}
|
||
|
|
this.debug_ui_obj = obj;
|
||
|
|
// nx.info(obj, obj.toString(), obj.__classname__, obj.getClassName);
|
||
|
|
var o = this.debug_ui_o;
|
||
|
|
var obj1 = obj.node || obj;
|
||
|
|
this.debug_ui_obj1 = obj1;
|
||
|
|
var c = obj.fontColor || obj1.color || {};
|
||
|
|
// nx.info(obj1.anchorX, obj1.anchorY, obj1);
|
||
|
|
o.show.isChecked = obj1.active;
|
||
|
|
o.name.string = obj1._name || obj.name || "";
|
||
|
|
o.type.string = cc.js.getClassName(obj) || "";
|
||
|
|
o.node_w.string = obj1.width || 0;
|
||
|
|
o.node_h.string = obj1.height || 0;
|
||
|
|
o.node_sx.string = obj1.scaleX || 0;
|
||
|
|
o.node_sy.string = obj1.scaleY || 0;
|
||
|
|
o.node_ax.string = obj1.anchorX;
|
||
|
|
o.node_ay.string = obj1.anchorY;
|
||
|
|
var pos = this.debug_ui_obj1.convertToWorldSpace(cc.v2(0, 0));
|
||
|
|
o.node_wx.string = pos.x || 0;
|
||
|
|
o.node_wy.string = pos.y || 0;
|
||
|
|
o.node_x.string = obj1.x || 0;
|
||
|
|
o.node_y.string = obj1.y || 0;
|
||
|
|
o.node_c_r.string = c.getR && c.getR() || 0;
|
||
|
|
o.node_c_g.string = c.getG && c.getG() || 0;
|
||
|
|
o.node_c_b.string = c.getB && c.getB() || 0;
|
||
|
|
o.node_c_a.string = obj1.opacity || 0;
|
||
|
|
this.setDebugUIObjBorder(obj1, true);
|
||
|
|
},
|
||
|
|
updateChildNodes: function updateChildNodes(obj) {
|
||
|
|
var items = this.debug_ui_items || [];
|
||
|
|
this.debug_ui_items = items;
|
||
|
|
for (var i = 0, n = items.length; i < n; i++) {
|
||
|
|
items[i].active = false;
|
||
|
|
}
|
||
|
|
var y = 0;
|
||
|
|
var id = 0;
|
||
|
|
//nx.info(obj._components, obj.children);
|
||
|
|
var nodes = obj._components || [];
|
||
|
|
for (var _i = 0, _n = nodes.length; _i < _n; _i++) {
|
||
|
|
if (nodes[_i].border) continue;
|
||
|
|
y = this.createDebugUIItem("c", id++, nodes[_i], y);
|
||
|
|
}
|
||
|
|
nodes = obj.children || [];
|
||
|
|
for (var _i2 = 0, _n2 = nodes.length; _i2 < _n2; _i2++) {
|
||
|
|
if (nodes[_i2].border) continue;
|
||
|
|
y = this.createDebugUIItem("n", id++, nodes[_i2], y);
|
||
|
|
}
|
||
|
|
this.debug_ui_o.scroll_content.height = -y;
|
||
|
|
},
|
||
|
|
createDebugUIItem: function createDebugUIItem(type, i, obj, y) {
|
||
|
|
var item = this.debug_ui_items[i];
|
||
|
|
if (!item) {
|
||
|
|
item = cc.instantiate(this.debug_ui_o.scroll_item);
|
||
|
|
item.on(cc.Node.EventType.TOUCH_END, function (event) {
|
||
|
|
this.setDebugUIObj(item.o);
|
||
|
|
}, this);
|
||
|
|
this.debug_ui_o.scroll_content.addChild(item);
|
||
|
|
}
|
||
|
|
this.debug_ui_items[i] = item;
|
||
|
|
item.active = true;
|
||
|
|
item.o = obj;
|
||
|
|
var obj1 = obj.node || obj;
|
||
|
|
item.getComponent(cc.Label).string = "[" + type + "]" + (cc.js.getClassName(obj) || "") + "(" + (obj1._name || obj.name || "name") + ")";
|
||
|
|
item.y = y;
|
||
|
|
//nx.info(item.getComponent(cc.Label).string, i, y);
|
||
|
|
return y - 30;
|
||
|
|
},
|
||
|
|
setDebugUIObjBorder: function setDebugUIObjBorder(obj, flag) {
|
||
|
|
if (!obj) return;
|
||
|
|
if (flag == false) {
|
||
|
|
if (obj && obj.draw_node) {
|
||
|
|
obj.draw_node.active = false;
|
||
|
|
}
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
if (!obj.draw_node) {
|
||
|
|
obj.draw_node = new cc.Node();
|
||
|
|
obj.draw_node.border = true;
|
||
|
|
obj.parent.addChild(obj.draw_node);
|
||
|
|
obj.draw_layer = obj.draw_node.addComponent(cc.Graphics);
|
||
|
|
// obj.draw_layer.fillColor = new cc.Color(0, 255, 0);
|
||
|
|
obj.draw_layer.strokeColor = new cc.Color(0, 255, 0);
|
||
|
|
obj.draw_layer.lineWidth = 2;
|
||
|
|
// nx.info(obj.anchorX, obj.anchorY, obj.x, obj.y, obj.width, obj.height, obj.draw_node.anchorX, obj.draw_node.anchorY, obj.parent.anchorX, obj.parent.anchorY);
|
||
|
|
}
|
||
|
|
|
||
|
|
obj.draw_node.active = true;
|
||
|
|
obj.draw_node.setAnchorPoint(obj.anchorX, obj.anchorY);
|
||
|
|
obj.draw_node.setPosition(obj.x, obj.y);
|
||
|
|
obj.draw_layer.clear();
|
||
|
|
obj.draw_layer.rect(-obj.width * obj.anchorX, -obj.height * obj.anchorY, obj.width, obj.height);
|
||
|
|
obj.draw_layer.stroke();
|
||
|
|
//obj.draw_layer.fill();
|
||
|
|
},
|
||
|
|
|
||
|
|
selectDebugUIObj: function selectDebugUIObj(pos) {
|
||
|
|
if (this.debug_ui && this.debug_ui.active) {
|
||
|
|
var newobj = this.matchDebugUIObj(cc.director.getScene(), 1, pos, null, 0);
|
||
|
|
this.setDebugUIObj(newobj);
|
||
|
|
}
|
||
|
|
},
|
||
|
|
matchDebugUIObj: function matchDebugUIObj(node, n, pos, obj, zindex) {
|
||
|
|
if (n > 100) return obj; // 只处理到一定深度
|
||
|
|
var nodes = node.children;
|
||
|
|
for (var i = 0, len = nodes.length; i < len; i++) {
|
||
|
|
if (nodes[i].active && !nodes[i].gm) {
|
||
|
|
if (n > 1 && this.hitObj(nodes[i], pos)) {
|
||
|
|
nodes[i].w_zIndex = zindex + i;
|
||
|
|
obj = this.compObj(nodes[i], obj);
|
||
|
|
}
|
||
|
|
obj = this.matchDebugUIObj(nodes[i], n + 1, pos, obj, zindex + i * 100000);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return obj;
|
||
|
|
},
|
||
|
|
hitObj: function hitObj(node, pos) {
|
||
|
|
var rect = node.getBoundingBoxToWorld();
|
||
|
|
return rect.contains(pos);
|
||
|
|
},
|
||
|
|
compObj: function compObj(obj, obj1) {
|
||
|
|
if (obj.width < 1 || obj.height < 1 || obj.width >= SCREEN_WIDTH || obj.height >= SCREEN_HEIGHT) {
|
||
|
|
return obj1;
|
||
|
|
} else if (!obj1) {
|
||
|
|
return obj;
|
||
|
|
// }else if(obj.w_zIndex > obj1.w_zIndex){
|
||
|
|
// return obj;
|
||
|
|
} else if (obj.width * obj.height < obj1.width * obj1.height) {
|
||
|
|
return obj;
|
||
|
|
}
|
||
|
|
return obj1;
|
||
|
|
}
|
||
|
|
};
|
||
|
|
module.exports = GmCmd;
|
||
|
|
|
||
|
|
cc._RF.pop();
|