creator_to_cocos2dx icon indicating copy to clipboard operation
creator_to_cocos2dx copied to clipboard

Layout support

Open minggo opened this issue 8 years ago • 17 comments

minggo avatar Jun 27 '17 03:06 minggo

yes, layout support is very important

samge1988 avatar Jan 25 '18 07:01 samge1988

Is there a way to list out the limitations of implementing the Layout support, in such a way to maybe get someone else to help implement that?

After being parsed by the core/parsers, seems like flatbuffers generates some code, then it goes through it here. I'm not familiar with flatbuffers but the _generated file seems to need input files but I don't know enough to take the next step.

Is there a file that is supposed to be fed to flatbuffers that isn't in the repo? Seems like it should be some sort of IDL, but I don't see anything in the repo.

Seems like we'd need to

  • add a new parser to core/parser
  • add some sort of data to flatbuffer's source IDL file
  • add a createLayout & parseLayout to CreatorReader.cpp

I'm not familiar with much of this but maybe someone else can help guide me

tankorsmash avatar Feb 03 '18 14:02 tankorsmash

I will write a doc about how it work, then other developers can join to develop it.

minggo avatar Feb 05 '18 03:02 minggo

Great! Looking forward to learning more about how this plugin works.

tankorsmash avatar Feb 05 '18 03:02 tankorsmash

@tankorsmash i added this wiki, please let me know if something is missed. And you are appreciated to improve it too.

minggo avatar Feb 05 '18 08:02 minggo

@minggo Great thank you!

tankorsmash avatar Feb 05 '18 21:02 tankorsmash

https://github.com/tankorsmash/creator_to_cocos2dx/tree/add_layout_support I've started a branch for this. I'll continue to investigate, but I wanted to write progress down as I could use some guidance.

I've modified the .fbs, I've added a placeholder Layout.js, I've hooked up the Util.js node guessing to use Layout.

The problem I'm running into now is that the cocos2d::ui:Layout* node child isn't being built at all by the getSceneGraph() call, whereas before I started working on this, it would be detected and parsed as a Node. In other words, instead of being parsed incorrectly as Node, it is now not being built at all among the children of the scene = reader->getSceneGraph().

The structure of the scene in my sample project and their names are:

  • Canvas ("Canvas")
  • Layout ("sample_layout")
  • Button ("sample_button") \-> Label ("sample_button_label")

My question is what am I doing wrong that's causing the Layout node, sample_layout, to not be generated by the reader instance? I suspected that it was because Layout.js was effectively empty, but I checked out Button.js and it doesn't really do much else besides set a few properties. I would expect that with how it's written now, the generated Layout node would have been missing a few properties rather than not parsed at all.

Thanks again for writing the wiki, I've also created an issue where I made a few changes to it too.

edit: Realized I missed the convert_fire_to_json, trying that now.

edit2: That didn't work and hasn't been edited in about a year, so maybe it's not used anymore. Am now trying to edit CreatorReader.cpp which is looking like that's the piece I missed.

tankorsmash avatar Feb 07 '18 22:02 tankorsmash

Realized I missed the convert_fire_to_json, trying that now

Did you mean convert_fire_to_json.py? It is not used. I will remove it now.

minggo avatar Feb 08 '18 01:02 minggo

Yeah, thanks!

tankorsmash avatar Feb 08 '18 01:02 tankorsmash

I've updated CreatorReader.h/.cpp and I've got the nodes generating, I'll update the wiki to make sure that's covered, then add the support for the resizing and I think we'll be cool here, thanks for the help.

I'm not familiar with lua, so once I'm done, maybe someone else can come in afterwards and make sure I didn't mess any of that up.

tankorsmash avatar Feb 08 '18 01:02 tankorsmash

Cool, waiting your for PR.

minggo avatar Feb 08 '18 01:02 minggo

I've got my fork exporting Layouts now, which works well enough for the usecase I was trying to solve, but it doesn't support the padding/magin and layout options.

Basically mine just adds in a Layout and uses the background color from the editor, sort of how it worked in Cocos Studio, since I'm unfamiliar with the new stuff. Is that something you're still interested in getting a pull request for?

edit: hold on, doesn't seem to support children properly, I'll need to keep working on it.

tankorsmash avatar Feb 13 '18 18:02 tankorsmash

The lack of children wasn't a problem in the plugin, I was cloning the widget and since Label isn't ui::Text (and therefore not a ui::Widget), it's not cloned by ui::Widget.clone, which I suppose is something a little more broad than this plugin, I think.

Seems like everything implemented is working as intended.

tankorsmash avatar Feb 14 '18 05:02 tankorsmash

Any progress for the Layout? @tankorsmash

drelaptop avatar Mar 27 '18 01:03 drelaptop

@drelaptop My fork seems to be working, more or less, as of the latest Feb 21st commit. Some weirdness of the sprite background where I still need to set the background fill type to NONE sometimes (most of the time?), but otherwise it was enough for me to port from studio to creator

There's the two options that aren't supported, the Resize and Layout types, but I didn't use them in Studio. I didn't want to make a PR because it didnt have that, but I could if the half-baked support would be okay with people, I'll do it.

tankorsmash avatar Mar 27 '18 02:03 tankorsmash

This great job is meaningful for plugin users, even though two options not supported, so I suggest you to make a PR, just add comments into that PR what have been supported, what not supported. you can add the unfinished feature if you have free time recently, you don't have to if not.

drelaptop avatar Mar 27 '18 02:03 drelaptop

@drelaptop Thanks for the thought.

Made a PR here that mentions the limitations, hopefully someone else can find a way to use it too.

tankorsmash avatar Mar 29 '18 01:03 tankorsmash