Questions about ProtectedNode?

93 views
Skip to first unread message

guanghui

unread,
May 3, 2014, 9:54:42 PM5/3/14
to cocos2d-...@googlegroups.com, Liu Gary, 建峰 邹
Hi, 

Currently our UI system introduce a new class type named ProtectedNode, I have some questions about it.

I have found the following result:

1. It seems that all the internal Node members are added through addProtectedNode in Widget class implementation.

2.When adding a widget object into a layout, we could use addChild method.

Now my questions are:

1. Can we add a Node descendant object into the widget based scene graph by using addChild
2. If I want to add a Sprite into the Layout class, should we use addProtectedNode or addChild?
3. Suppose that we could only add widget descendant objects into the widget objects, should we forbidden adding nodes descendant objects into it?

My proposal is that:

If we call addChild method on Widget objects,  we only allow widget descendant objects to be added.
If we want to add node descendant objects into widget, we should use addProtectedNode instead.

Any thoughts?


Regards,
Guanghui

Ricardo Quesada

unread,
May 5, 2014, 7:24:41 PM5/5/14
to guanghui, cocos2d-...@googlegroups.com, Liu Gary, 建峰 邹
ProtectedNode was created because there was a requirement from the UI widgets.

The requirement basically said:

Some widgets are composed with other widgets. eg: A pre-defined Dialog could have 3 UIButtons as children.
A user should be able to add custom nodes to that dialog, but the pre-created children should not be removed if the user calls "removeAllChildren".

So, to answer your question, the answer is: It depends.

Use addProtectedChild() when you are creating a composed widget that should act as one.
Use addChild() when you are adding children that could be removed by the user.







--
You received this message because you are subscribed to the Google Groups "cocos2d JS development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cocos2d-js-dev...@googlegroups.com.
To post to this group, send email to cocos2d-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

guanghui

unread,
May 6, 2014, 2:50:16 AM5/6/14
to Ricardo Quesada, cocos2d-...@googlegroups.com, Liu Gary, 建峰 邹
Thanks, riq

could we merge the protectedNode functionality into the Widget class and make the addProtectedNode a protected method of the widget class?


Regards,
Guanghui

Ricardo Quesada

unread,
May 6, 2014, 3:10:38 AM5/6/14
to guanghui, cocos2d-...@googlegroups.com, Liu Gary, 建峰 邹
what's the purpose of doing that?
thanks.

guanghui

unread,
May 6, 2014, 3:22:28 AM5/6/14
to Ricardo Quesada, cocos2d-...@googlegroups.com, Liu Gary, 建峰 邹
Just for Simplicity and Cohesiveness.

We don’t need extra knowledge when we are developing new functionality. 

And the ProtectedNode is currently only used by the Widget class, it belongs to Widget class.

So I think for better cohesiveness, we should merge them into one.

We shouldn’t design for possible future extensibility which seems a little bit over-designed.


Regards,
Guanghui

Ricardo Quesada

unread,
May 6, 2014, 3:24:58 AM5/6/14
to guanghui, cocos2d-...@googlegroups.com, Liu Gary, 建峰 邹
Yes, perhaps it is a bit over-designed, however I don't think it will add simplicity, but it is a bit over-designed.

The current solution (ProtectedNode), and merging inside Widget are good for me.
But please, discuss it with Minggo and/or James. Whatever you decide is good for me.

guanghui

unread,
May 6, 2014, 3:36:30 AM5/6/14
to Ricardo Quesada, cocos2d-...@googlegroups.com, Liu Gary, 建峰 邹
Thanks for your patience.

I don’t want to be rude but express what I was thinking about.

Whether to merge it or not, I will discuss with Mingo and Jams later.


Regards,
Guanghui

Ricardo Quesada

unread,
May 6, 2014, 10:21:40 AM5/6/14
to guanghui, cocos2d-...@googlegroups.com, Liu Gary, 建峰 邹
Sorry, I don't what you are asking.


Ricardo Quesada

unread,
May 6, 2014, 10:26:04 AM5/6/14
to guanghui, cocos2d-...@googlegroups.com, Liu Gary, 建峰 邹
oops, I forgot the "know"... I meant: "I don't know what you are asking"

huabing.xu

unread,
May 6, 2014, 10:45:54 AM5/6/14
to guanghui, Ricardo Quesada, cocos2d-...@googlegroups.com, Liu Gary, 建峰 邹

Hi, Riq and Guanghui

In my opinion, our UI Node directly inherit from cocos2d:Node. 

1. It should be if we want to add cocos2d:Node or cocos2d:Sprite together with UI Node to the children of UI Node. 

In this situation, I guess we can reserve AddChild function as our API, and check the real type of Node, and route it to different internal function, to AddProtectedNodeChild or AddCocos2dNodeChild.


2. If we do not want to add a cocos2d:Node to the children of UI Node. I guess we can refer some concepts in CEGUI, which has a enclosed concepts of API, and used a global UIRenderer(whether openGL renderer, DirectX renderer, even cocos2d Renderer) to rendering the GUI.

I hope it could be helpful, thanks.

Best Regards
Harrison Xu

 Original Message 
Sender: Ricardo Quesada<ricardo...@gmail.com>
Recipient: guanghui<guang...@cocos2d-x.org>
Date: Tuesday, May 6, 2014 07:26
Subject: Re: [cocos2d-js-devel] Questions about ProtectedNode?

Xiaoming Zhang

unread,
May 6, 2014, 9:30:06 PM5/6/14
to huabing.xu, guanghui, Ricardo Quesada, cocos2d-...@googlegroups.com, Liu Gary, 建峰 邹
Don’t worry.
I will discuss it with Guanghui.

Best Regards
Minggo



Reply all
Reply to author
Forward
0 new messages