潜在bug:如果调用两次灰度处理,则无法进行色彩还原
LayoutConfig.setWidgetEffectWithEnabled = function (widget,enable) { if(!widget){return;} widget.setTouchEnabled(enable); LayoutConfig.setWidgetGrayEffect(widget,!enable); }
LayoutConfig.setWidgetGrayEffect = function (widget,enable) { var shader = LayoutConfig.getShaderMap(enable ? "ui_gray" : "ui_normal"); if (widget) { var children = widget.getChildren(); for (var i in children) { LayoutConfig.setWidgetGrayEffect(children[i],enable); } if (!widget.getString) { widget.setShaderProgram(shader); } if (widget.getVirtualRenderer) { var children = widget.getVirtualRenderer().getChildren(); for (var i in children) { LayoutConfig.setWidgetGrayEffect(children[i],enable); } if (!widget.getVirtualRenderer().getString) { widget.getVirtualRenderer().setShaderProgram(shader); } } } };
LayoutConfig.getShaderMap = function (n) { var _s = this._shaderMap[n]; if (_s) { //cc.log("LayoutConfig.getShaderMap: " + n + " Cache"); return _s; } var b_n = "res/shader/" + n; var v_n = b_n + ".vsh"; var f_n = b_n + ".fsh"; _s = new cc.GLProgram(v_n,f_n); _s.addAttribute(cc.ATTRIBUTE_NAME_POSITION,cc.VERTEX_ATTRIB_POSITION); _s.addAttribute(cc.ATTRIBUTE_NAME_COLOR,cc.VERTEX_ATTRIB_COLOR); _s.addAttribute(cc.ATTRIBUTE_NAME_TEX_COORD,cc.VERTEX_ATTRIB_TEX_COORDS); _s.link(); _s.updateUniforms(); this._shaderMap[n] = _s; //cc.log("LayoutConfig.getShaderMap: " + n + " New"); return _s; };