Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds partial ui::Layout support #155

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ quick_gen_project_*_autogen.sh
quick_gen_project_*_autogen.sh.meta
.exvim.app
*.swp
*.un~
tags

#/////////////////////////////////////////////////////////////////////////////
# webstorm files
Expand Down
15 changes: 13 additions & 2 deletions creator_project/packages/creator-luacpp-support/CreatorReader.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ enum EditBoxInputMode:byte {Any, EmailAddress, Numeric, PhoneNumber, URL, Decime
enum LabelOverflowType:byte {None, Clamp, Shrink, ResizeHeight, Toggle}
enum MaskType:byte {Rect, Ellipse, ImageStencil}
enum ColliderType:byte {BoxCollider, PolygonCollider, CircleCollider}
enum LayoutType:byte { None = 0, Horizontal = 1, Vertical = 2, Grid = 3 }
enum ResizeMode:byte { None = 0, Container = 1, Children = 2 }

// New nodes should be added at the end of the union
// no more than 255 union objects can be added
union AnyNode {Scene, Sprite, Label, Particle, TileMap, Node, Button, ProgressBar, ScrollView, CreatorScene,
EditBox, RichText, SpineSkeleton, VideoPlayer, WebView, Slider, Toggle, ToggleGroup, PageView, Mask, DragonBones, MotionStreak}
union AnyNode {Scene, Sprite, Label, Particle, TileMap, Node, Button, ProgressBar, ScrollView, CreatorScene,
EditBox, RichText, SpineSkeleton, VideoPlayer, WebView, Slider, Toggle, ToggleGroup, PageView,
Mask, DragonBones, MotionStreak, Layout}

table SceneGraph
{
Expand Down Expand Up @@ -180,6 +183,14 @@ table Button
ignoreContentAdaptWithSize:bool = false;
}

table Layout
{
node:Node;
layoutType:LayoutType;
resizeMode:ResizeMode;
backgroundVisible:bool = true;
}

table ProgressBar
{
node:Node;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class BuildWorker extends WorkerBase {
this._compileJsonToBinary(function() {
this._copyResources(copyReourceInfos);
Editor.Ipc.sendToAll('creator-luacpp-support:state-changed', 'finish', 100);

this._callback();
Utils.log('[creator-luacpp-support] build end');
}.bind(this));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ class Button extends Node {
}
}

module.exports = Button;
module.exports = Button;
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class FireParser {
fs.close(this._json_file);
}
});

}
}

Expand All @@ -130,4 +131,4 @@ function parse_fire(filenames, assetpath, path_to_json_files, uuidmaps) {
return uuid;
}

module.exports = parse_fire;
module.exports = parse_fire;
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const Node = require('./Node');
const Utils = require('./Utils');
const state = require('./Global').state;

class Layout extends Node {
// Example Layout structure
/* {
"__type__": "cc.Layout",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 4
},
"_enabled": true,
"_layoutSize": {
"__type__": "cc.Size",
"width": 200,
"height": 150
},
"_resize": 0,
"_N$layoutType": 0,
"_N$padding": 0,
"_N$cellSize": {
"__type__": "cc.Size",
"width": 40,
"height": 40
},
"_N$startAxis": 0,
"_N$paddingLeft": 0,
"_N$paddingRight": 0,
"_N$paddingTop": 0,
"_N$paddingBottom": 0,
"_N$spacingX": 0,
"_N$spacingY": 0,
"_N$verticalDirection": 1,
"_N$horizontalDirection": 0
} */
constructor(data) {
super(data);
this._jsonNode.object_type = 'Layout';
}

parse_properties() {
super.parse_properties();
this._properties = {node: this._properties};

let spr_component = Node.get_node_component_of_type(this._node_data, 'cc.Sprite');
this._properties.backgroundVisible = spr_component._enabled;

let lay_component = Node.get_node_component_of_type(this._node_data, 'cc.Layout');
this._properties.layoutType = lay_component._N$layoutType;
this._properties.resizeMode = lay_component._resize;

}
}

module.exports = Layout;
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ class MotionStreak extends Node {
}
}

module.exports = MotionStreak;
module.exports = MotionStreak;
31 changes: 17 additions & 14 deletions creator_project/packages/creator-luacpp-support/core/parser/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@ class Node {

static guess_type_from_components(components) {
// ScrollView, Button & ProgressBar should be before Sprite
let supported_components = ['cc.Button', 'cc.ProgressBar', 'cc.ScrollView',
let supported_components = ['cc.Button', 'cc.ProgressBar', 'cc.ScrollView', 'cc.Layout',
'cc.EditBox', 'cc.Label', 'sp.Skeleton', 'cc.Sprite',
'cc.ParticleSystem', 'cc.TiledMap', 'cc.Canvas', 'cc.RichText',
'cc.VideoPlayer', 'cc.WebView', 'cc.Slider', 'cc.Toggle', 'cc.ToggleGroup',
'cc.PageView', 'cc.Mask', 'dragonBones.ArmatureDisplay'];

if (!components)
return 'cc.Node';

let node_components = components.map(x => x.__type__);
// special case for object without components
if (node_components.length == 0)
return 'cc.Node';

for (let i = 0, len = supported_components.length; i < len; ++i) {
let supported = supported_components[i];
if (node_components.includes(supported)) {
Expand All @@ -72,16 +72,19 @@ class Node {
Utils.log('treat all unknown components as cc.Node')
return 'cc.Node';
}

static guess_type(node_data) {
let components = Node.get_node_components(node_data);
if (components)
return Node.guess_type_from_components(components);

if (components) {
let guessedType = Node.guess_type_from_components(components);
return guessedType;
}

// prefab don't have componets, should guess type from prefab node data
if (node_data._prefab)
if (node_data._prefab) {
return 'cc.Prefab';

};

return null;
}

Expand Down Expand Up @@ -147,7 +150,7 @@ class Node {
parse_properties() {
// 1st: parse self
this.parse_node_properties();

// 2nd: parse children
this.parse_children();
}
Expand Down Expand Up @@ -276,7 +279,7 @@ class Node {
addProp(props, 'skewX', result, 'skewX');
addProp(props, 'skewY', result, 'skewY');
addProp(props, 'opacity', result, 'opacity');


// position -> {x:, y:, curveType?, curveData?}
if (props.position) {
Expand Down Expand Up @@ -316,7 +319,7 @@ class Node {
else
{
let clip_content = JSON.parse(fs.readFileSync(uuidinfos[clip_uuid]));

// parse curveData
let animationClip = {
name: clip_content._name,
Expand Down Expand Up @@ -345,7 +348,7 @@ class Node {

// parse self animationclip
if (curveData.props)
animationClip.curveData.push({props: parseCurveDataProps(curveData.props)});
animationClip.curveData.push({props: parseCurveDataProps(curveData.props)});

anim.clips.push(animationClip);
state._clips[clip_uuid] = animationClip;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ let get_sprite_frame_json_by_uuid = function(uuid) {

let is_sprite_frame_from_texture_packer = function(uuid) {
let json = get_sprite_frame_json_by_uuid(uuid);
if (json)
if (json)
return json.content.atlas !== '';
else
return false;
Expand Down Expand Up @@ -86,7 +86,7 @@ let get_sprite_frame_name_by_uuid = function(uuid) {
sprite_frame_info.texture_path = path_info.relative_path;
sprite_frame_info.is_texture_packer = is_texture_packer;

let sprite_frame_uuid = sprite_frame_info.uuid;
let sprite_frame_uuid = sprite_frame_info.uuid;
state._sprite_frames[sprite_frame_uuid] = sprite_frame_info;

if (sprite_frame_uuid == uuid) {
Expand Down Expand Up @@ -164,16 +164,16 @@ let get_spine_info_by_uuid = function (uuid) {
let contents = fs.readFileSync(jsonfile);
let contents_json = JSON.parse(contents);
let current_dir = path.basename(jsonfile, '.json');

let res_dir = path.join(path.dirname(jsonfile), uuid);

let files = fs.readdirSync(res_dir);
files.forEach(function(file) {
let fullpath = path.join(res_dir, file);
//FIXME: have more than one json file?
state._uuid[uuid] = {fullpath: fullpath, relative_path: current_dir + '/' + file};
});

// get atlas path
state._uuid[uuid].atlas_url = get_relative_full_path_by_uuid(contents_json.atlasUrl.__uuid__);
// add to _uuid to copy resources
Expand Down Expand Up @@ -249,62 +249,53 @@ let create_node = function (node_type, node_data) {
const Prefab = require('./Prefab');
const DragonBones = require('./DragonBones');
const MotionStreak = require('./MotionStreak');
const Layout = require('./Layout');

let classType = null;

const classMap = {
'cc.Node': Node,
'cc.Sprite': Sprite,
'cc.Canvas': Canvas,
'cc.Label': Label,
'cc.RichText': RichText,
'cc.Button': Button,
'cc.ProgressBar': ProgressBar,
'cc.ScrollView': ScrollView,
'cc.EditBox': EditBox,
'cc.TiledMap': TiledMap,
'cc.ParticleSystem': ParticleSystem,
'sp.Skeleton': SpineSkeleton,
'cc.VideoPlayer': VideoPlayer,
'cc.WebView': WebView,
'cc.Slider': Slider,
'cc.Toggle': Toggle,
'cc.ToggleGroup': ToggleGroup,
'cc.PageView': PageView,
'cc.Mask': Mask,
'cc.Prefab': Prefab,
'dragonBones.ArmatureDisplay': DragonBones,
'cc.MotionStreak': MotionStreak,
'cc.Layout': Layout,
};

classType = classMap[node_type]

let n = null;
if (node_type === 'cc.Node')
n = new Node(node_data);
else if (node_type === 'cc.Sprite')
n = new Sprite(node_data);
else if (node_type === 'cc.Canvas')
n = new Canvas(node_data);
else if (node_type === 'cc.Label')
n = new Label(node_data);
else if (node_type === 'cc.RichText')
n = new RichText(node_data);
else if (node_type === 'cc.Button')
n = new Button(node_data);
else if (node_type === 'cc.ProgressBar')
n = new ProgressBar(node_data);
else if (node_type === 'cc.ScrollView')
n = new ScrollView(node_data);
else if (node_type === 'cc.EditBox')
n = new EditBox(node_data);
else if (node_type === 'cc.TiledMap')
n = new TiledMap(node_data);
else if (node_type === 'cc.ParticleSystem')
n = new ParticleSystem(node_data);
else if (node_type === 'sp.Skeleton')
n = new SpineSkeleton(node_data);
else if (node_type === 'cc.VideoPlayer')
n = new VideoPlayer(node_data);
else if (node_type === 'cc.WebView')
n = new WebView(node_data);
else if (node_type === 'cc.Slider')
n = new Slider(node_data);
else if (node_type === 'cc.Toggle')
n = new Toggle(node_data);
else if (node_type === 'cc.ToggleGroup')
n = new ToggleGroup(node_data);
else if (node_type === 'cc.PageView')
n = new PageView(node_data);
else if (node_type === 'cc.Mask')
n = new Mask(node_data);
else if (node_type === 'cc.Prefab')
n = new Prefab(node_data);
else if (node_type === 'dragonBones.ArmatureDisplay')
n = new DragonBones(node_data);
else if (node_type === 'cc.MotionStreak')
n = new MotionStreak(node_data);

if (n != null)

let isValid = typeof(classType) !== "undefined";
if (isValid)
{
n = new classType(node_data);
n.parse_properties();

}

return n;
}

/**
* remove a child from node's children by child's id
* @param {node} the Node that to be applied to
* @param {node} the Node that to be applied to
* @param {id} child's id
*/
let remove_child_by_id = function (node, id) {
Expand Down
1 change: 1 addition & 0 deletions creator_project/packages/creator-luacpp-support/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function _checkProject(opt) {
// 'profile' may be null
function _build(opt) {
if (_buildState !== 'sleep' && _buildState !== 'finish') {
//FIXME this never gets cleared, giving the impression that the plugin is constantly running
Editor.warn('[LuaCpp Support] Building in progress');
return;
}
Expand Down
Loading