|
- local UIEditor = class("UIEditor" , require("NodeEditor"));
-
- function UIEditor:ctor()
- UIEditor.super.ctor(self);
- end
-
- function UIEditor:activate()
- UIEditor.super.activate(self);
- app.setting.OriginAnchor = cc.p(0,0);
- app.setting.SourceNodeNum = 0;
- app.setting.TargetNodeNum = 0;
- app:refreshSetting();
-
- self.mBackgroundNode = self:createUIBackground();
- app.mainLayer:addChild(self.mBackgroundNode , -100);
- end
-
- function UIEditor:unactivate()
- UIEditor.super.unactivate(self);
- if self.mBackgroundNode then
- self.mBackgroundNode:removeFromParent();
- self.mBackgroundNode = nil;
- end
- end
-
- -- 创建UI底图
- -- 创建UI底图
- -- 创建UI底图
- -- 创建UI底图
- -- 创建UI底图
- -- 创建UI底图
- -- 创建UI底图
- -- 创建UI底图
- -- 创建UI底图
- -- 创建UI底图
- -- 创建UI底图
- -- 创建UI底图
- function UIEditor:createUIBackground()
- local glNode = gl.glNodeCreate()
- glNode:setAnchorPoint(cc.p(0, 0))
-
- local function primitivesDraw(transform, transformUpdated)
- local node = self.node;
- if node then
- -- 绑定相机、世界矩阵
- cc.DrawPrimitives.setCamera(cc.Director:getInstance():getActiveCamera());
- cc.DrawPrimitives.setWorldTransform(node:getNodeToWorldTransform());
-
- -- 画矩形
- local rect = cc.rect(0 , 0 , node:getContentSize().width , node:getContentSize().height);
- cc.DrawPrimitives.drawSolidRect(cc.p(rect.x , rect.y), cc.p(rect.x + rect.width , rect.y + rect.height) , cc.c4f(0.6,0.6,0.6,1))
-
- -- 状态恢复
- gl.lineWidth(1)
- cc.DrawPrimitives.drawColor4B(255,255,255,255)
- cc.DrawPrimitives.setPointSize(1)
- end
- end
-
- glNode:registerScriptDrawHandler(primitivesDraw)
- return glNode;
- end
-
- function UIEditor:play()
- UIEditor.super.play(self)
- -- UIEffectNode需要重新播放下
- local function visit(node)
- if node.stop then
- node:stop()
- end
- if node.play then
- node:play()
- end
- end
- self.node:visitNode(visit);
- end
-
- -- 创建新的光效
- function UIEditor:newNode()
- self:closeNode();
- local node = self:createNode("Layout");
- self:initNode(node)
- node:ignoreContentAdaptWithSize(false);
- node:setSizeType(1);
- node:setSizePercent(cc.p(1,1));
- node:setAnchorPoint(cc.p(0,0));
- node:setBackGroundColorType(cc.LayoutBackGroundColorType.none);
- return node;
- end
-
- -- 关闭光效
- function UIEditor:closeNode()
- UIEditor.super.closeNode(self);
-
- end
-
- -- 初始化光效,添加到场景中
- function UIEditor:initNode(node)
- UIEditor.super.initNode(self , node);
- -- 默认播放更节点的动画
- if app.setting.PlayUIAnimation then
- self.node:playCurveAnimation()
- end
- end
-
- function UIEditor:relayoutAll()
- local function onNode(node)
- if type(node.requestDoLayout) == "function" then
- node:requestDoLayout();
- end
- return true;
- end
- -- 遍历所有子节点,把子UI取出来统一放在Items里
- if self.node then
- self.node:visitNode(onNode);
- end
- end
-
- -- 属性改变通知
- function UIEditor:onPropertyValueChanged(propName , newValue , oldValue)
- self:relayoutAll();
- end
-
- function UIEditor:createNode(nodeType)
- local node = UIEditor.super.createNode(self , nodeType);
- if node.enableAutoPlay then
- node:enableAutoPlay();
- end
- return node;
- end
-
- -- 各个派生类可以重写这个函数
- function UIEditor:save(filename)
-
- self.node:recalcAllPList();
- UIEditor.super.save(self, filename);
- local images = self.node:collectAllImage();
- if images then
- local msg = "保存UI" .. filename .. "成功,这个UI用到了这些图片:\r\n";
- for i , v in pairs(images) do
- msg = msg .. i .. " 用了 " .. v .. " 次\r\n";
- end
- alert(msg);
- end
- end
-
- return UIEditor;
|