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

Support for CCSpriteBatchNode #276

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
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
43 changes: 43 additions & 0 deletions CocosBuilder/CCSpriteBatchNode/CCBPProperties.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>inheritsFrom</key>
<string>CCNode</string>
<key>canHaveChildren</key>
<true/>
<key>canBeRootNode</key>
<true/>
<key>className</key>
<string>CCSpriteBatchNode</string>
<key>editorClassName</key>
<string>CCSpriteBatchNode</string>
<key>requireChildClass</key>
<array>
<string>CCSprite</string>
</array>
<key>properties</key>
<array>
<dict>
<key>displayName</key>
<string>CCSpriteBatchNode</string>
<key>name</key>
<string>CCSpriteBatchNode</string>
<key>type</key>
<string>Separator</string>
<key>dontSetInEditor</key>
<true/>
</dict>
<dict>
<key>animatable</key>
<false/>
<key>displayName</key>
<string>Atlas Name</string>
<key>type</key>
<string>TextureAtlas</string>
<key>name</key>
<string>textureAtlas</string>
</dict>
</array>
</dict>
</plist>
44 changes: 44 additions & 0 deletions CocosBuilder/CCSpriteBatchNode/CCSpriteBatchNode-Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.cocosbuilder.plug.node.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>CFPlugInDynamicRegisterFunction</key>
<string></string>
<key>CFPlugInDynamicRegistration</key>
<string>NO</string>
<key>CFPlugInFactories</key>
<dict>
<key>00000000-0000-0000-0000-000000000000</key>
<string>MyFactoryFunction</string>
</dict>
<key>CFPlugInTypes</key>
<dict>
<key>00000000-0000-0000-0000-000000000000</key>
<array>
<string>00000000-0000-0000-0000-000000000000</string>
</array>
</dict>
<key>CFPlugInUnloadFunction</key>
<string></string>
</dict>
</plist>
7 changes: 7 additions & 0 deletions CocosBuilder/CCSpriteBatchNode/CCSpriteBatchNode-Prefix.pch
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//
// Prefix header for all source files of the 'CCSpriteBatchNode' target in the 'CCSpriteBatchNode' project
//

#ifdef __OBJC__
#import <Cocoa/Cocoa.h>
#endif
2 changes: 2 additions & 0 deletions CocosBuilder/CCSpriteBatchNode/en.lproj/InfoPlist.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* Localized versions of Info.plist keys */

7 changes: 5 additions & 2 deletions CocosBuilder/Cocos2D iPhone/CCBXCocos2diPhoneWriter.m
Original file line number Diff line number Diff line change
@@ -65,6 +65,7 @@ - (void) setupPropTypes
[propTypes addObject:@"BlockCCControl"];
[propTypes addObject:@"FloatScale"];
[propTypes addObject:@"FloatXY"];
[propTypes addObject:@"TextureAtlas"];
}

- (id) init
@@ -401,7 +402,8 @@ - (void) writeProperty:(id) prop type:(NSString*)type name:(NSString*)name platf
}
else if ([type isEqualToString:@"Texture"]
|| [type isEqualToString:@"FntFile"]
|| [type isEqualToString:@"CCBFile"])
|| [type isEqualToString:@"CCBFile"]
|| [type isEqualToString:@"TextureAtlas"])
{
[self writeCachedString:prop isPath: YES];
}
@@ -578,7 +580,8 @@ - (void) cacheStringsForNode:(NSDictionary*) node
}
else if ([type isEqualToString:@"FntFile"]
|| [type isEqualToString:@"Texture"]
|| [type isEqualToString:@"CCBFile"])
|| [type isEqualToString:@"CCBFile"]
|| [type isEqualToString:@"TextureAtlas"])
{
[self addToStringCache:value isPath:YES];
}
222 changes: 222 additions & 0 deletions CocosBuilder/CocosBuilder.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions CocosBuilder/ccBuilder/CCBReaderInternal.m
Original file line number Diff line number Diff line change
@@ -235,6 +235,13 @@ + (void) setProp:(NSString*)name ofType:(NSString*)type toValue:(id)serializedVa
[TexturePropertySetter setTextureForNode:node andProperty:name withFile:spriteFile];
[extraProps setObject:spriteFile forKey:name];
}
else if ([type isEqualToString:@"TextureAtlas"])
{
NSString* textureAtlasFile = serializedValue;
if (!textureAtlasFile) textureAtlasFile = @"";
[TexturePropertySetter setTextureAtlasForNode:node andProperty:name withFile:textureAtlasFile];
[extraProps setObject:textureAtlasFile forKey:name];
}
else if ([type isEqualToString:@"Color3"])
{
ccColor3B c = [CCBReaderInternal deserializeColor3:serializedValue];
7 changes: 7 additions & 0 deletions CocosBuilder/ccBuilder/CCBWriterInternal.m
Original file line number Diff line number Diff line change
@@ -370,6 +370,13 @@ + (NSMutableDictionary*) dictionaryFromCCObject:(CCNode *)node

serializedValue = spriteFile;
}
else if ([type isEqualToString:@"TextureAtlas"])
{
NSString* textureAtlasFile = [extraProps objectForKey:name];
if (!textureAtlasFile) textureAtlasFile = @"";

serializedValue = textureAtlasFile;
}
else if ([type isEqualToString:@"Color3"])
{
NSValue* colorValue = [node valueForKey:name];
15 changes: 15 additions & 0 deletions CocosBuilder/ccBuilder/CCNode+Batching.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// CCNode+Batching.h
// CocosBuilder
//
// Created by Nick Verigakis on 28/01/2013.
//
//

#import "CCNode.h"

@interface CCNode (Batching)

- (BOOL)isChildOfSpriteBatchNode;

@end
31 changes: 31 additions & 0 deletions CocosBuilder/ccBuilder/CCNode+Batching.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// CCNode+Batching.m
// CocosBuilder
//
// Created by Nick Verigakis on 28/01/2013.
//
//

#import "CCNode+Batching.h"
#import "cocos2d.h"

@implementation CCNode (Batching)

- (BOOL)isChildOfSpriteBatchNode
{
return [self isNodeChildOfSpriteBatchNode:self];
}

- (BOOL)isNodeChildOfSpriteBatchNode:(CCNode *)node
{
if (node.parent) {
if ([node.parent isKindOfClass:[CCSpriteBatchNode class]])
return YES;
else
[self isNodeChildOfSpriteBatchNode:node.parent];
}

return NO;
}

@end
13 changes: 13 additions & 0 deletions CocosBuilder/ccBuilder/CocosBuilderAppDelegate.m
Original file line number Diff line number Diff line change
@@ -90,6 +90,7 @@
#import "NodeGraphPropertySetter.h"
#import "CCBSplitHorizontalView.h"
#import "SpriteSheetSettingsWindow.h"
#import "CCNode+Batching.h"


#import <ExceptionHandling/NSExceptionHandler.h>
@@ -1601,6 +1602,18 @@ - (BOOL) addCCObject:(CCNode *)obj toParent:(CCNode*)parent atIndex:(int)index
return NO;
}

if ([parent isKindOfClass:[CCSpriteBatchNode class]] || [parent isChildOfSpriteBatchNode])
{
CCSpriteBatchNode *batchNode = (CCSpriteBatchNode *)parent;
CCSprite *child = (CCSprite *)obj;

if (child.texture.name != batchNode.textureAtlas.texture.name)
{
self.errorDescription = [NSString stringWithFormat: @"A batch node sprite must have the same texture as the batch node's texture atlas"];
return NO;
}
}

[self saveUndoState];

// Add object and change zOrder of objects after this child
3 changes: 3 additions & 0 deletions CocosBuilder/ccBuilder/InspectorBlock.m
Original file line number Diff line number Diff line change
@@ -25,11 +25,14 @@
#import "InspectorBlock.h"
#import "CCBGlobals.h"
#import "CCNode+NodeInfo.h"
#import "CocosBuilderAppDelegate.h"

@implementation InspectorBlock

- (void) setSelector:(NSString *)selector
{
[[CocosBuilderAppDelegate appDelegate] saveUndoStateWillChangeProperty:@"selector"];

if (!selector) selector = @"";
[selection setExtraProp:selector forKey:propertyName];
}
13 changes: 13 additions & 0 deletions CocosBuilder/ccBuilder/InspectorSpriteFrame.m
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@
#import "CCNode+NodeInfo.h"
#import "SequencerHandler.h"
#import "SequencerSequence.h"
#import "CCNode+Batching.h"

@implementation InspectorSpriteFrame

@@ -68,6 +69,11 @@ - (void) selectedResource:(id)sender

if (res.type == kCCBResTypeImage)
{
// Children of batch nodes
// should only be set with sprite frames.
if ([selection isChildOfSpriteBatchNode])
return;

sf = [ResourceManagerUtil relativePathFromAbsolutePath:res.filePath];
ssf = kCCBUseRegularFile;
[ResourceManagerUtil setTitle:sf forPopup:popup];
@@ -78,6 +84,13 @@ - (void) selectedResource:(id)sender
RMSpriteFrame* frame = item;
sf = frame.spriteFrameName;
ssf = [ResourceManagerUtil relativePathFromAbsolutePath:frame.spriteSheetFile];

// Children of batch nodes should only
// change their sprite frame to one belonging
// to the plist that corresponds to their texture atlas.
if ([selection isChildOfSpriteBatchNode] && ![ssf isEqualToString:[selection extraPropForKey:[NSString stringWithFormat:@"%@Sheet", propertyName]]])
return;

[ResourceManagerUtil setTitle:[NSString stringWithFormat:@"%@/%@",ssf,sf] forPopup:popup];
}

33 changes: 33 additions & 0 deletions CocosBuilder/ccBuilder/InspectorTextureAtlas.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* CocosBuilder: http://www.cocosbuilder.com
*
* Copyright (c) 2012 Zynga Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#import "InspectorValue.h"

@interface InspectorTextureAtlas : InspectorValue
{
IBOutlet NSPopUpButton* popup;
IBOutlet NSMenu* menu;
}

@end
73 changes: 73 additions & 0 deletions CocosBuilder/ccBuilder/InspectorTextureAtlas.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* CocosBuilder: http://www.cocosbuilder.com
*
* Copyright (c) 2012 Zynga Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#import "InspectorTextureAtlas.h"
#import "CCBGlobals.h"
#import "TexturePropertySetter.h"
#import "ResourceManager.h"
#import "ResourceManagerUtil.h"
#import "CocosBuilderAppDelegate.h"
#import "CCNode+NodeInfo.h"

@implementation InspectorTextureAtlas

- (void) willBeAdded
{
// Setup menu
NSString* sf = [selection extraPropForKey:propertyName];

[ResourceManagerUtil populateResourcePopup:popup resType:kCCBResTypeImage allowSpriteFrames:NO selectedFile:sf selectedSheet:NULL target:self];
}

- (void) selectedResource:(id)sender
{
[[CocosBuilderAppDelegate appDelegate] saveUndoStateWillChangeProperty:propertyName];

id item = [sender representedObject];

// Fetch info about the sprite name
NSString* sf = NULL;

if ([item isKindOfClass:[RMResource class]])
{
RMResource* res = item;

if (res.type == kCCBResTypeImage)
{
sf = [ResourceManagerUtil relativePathFromAbsolutePath:res.filePath];
[ResourceManagerUtil setTitle:sf forPopup:popup];
}
}

// Set the properties and sprite frames
if (sf)
{
[selection setExtraProp:sf forKey:propertyName];
[TexturePropertySetter setTextureAtlasForNode:selection andProperty:propertyName withFile:sf];
}

[self updateAffectedProperties];
}

@end
483 changes: 483 additions & 0 deletions CocosBuilder/ccBuilder/InspectorTextureAtlas.xib

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion CocosBuilder/ccBuilder/ResourceManager.m
Original file line number Diff line number Diff line change
@@ -435,7 +435,9 @@ - (int) getResourceTypeForFile:(NSString*) file
}
else if ([ext isEqualToString:@"png"]
|| [ext isEqualToString:@"jpg"]
|| [ext isEqualToString:@"jpeg"])
|| [ext isEqualToString:@"jpeg"]
|| [ext isEqualToString:@"pvr"]
|| [ext isEqualToString:@"ccz"])
{
return kCCBResTypeImage;
}
2 changes: 2 additions & 0 deletions CocosBuilder/ccBuilder/TexturePropertySetter.h
Original file line number Diff line number Diff line change
@@ -31,6 +31,8 @@

+ (void) setTextureForNode:(CCNode*)node andProperty:(NSString*) prop withFile:(NSString*) spriteFile;

+ (void) setTextureAtlasForNode:(CCNode*)node andProperty:(NSString*) prop withFile:(NSString*) atlasFile;

+ (void) setFontForNode:(CCNode*)node andProperty:(NSString*) prop withFile:(NSString*) fontFile;

+ (NSString*) fontForNode:(CCNode*)node andProperty:(NSString*) prop;
22 changes: 22 additions & 0 deletions CocosBuilder/ccBuilder/TexturePropertySetter.m
Original file line number Diff line number Diff line change
@@ -114,6 +114,28 @@ + (void) setTextureForNode:(CCNode*)node andProperty:(NSString*) prop withFile:(
[node setValue:texture forKey:prop];
}

+ (void) setTextureAtlasForNode:(CCNode*)node andProperty:(NSString*) prop withFile:(NSString*) atlasFile
{
CCTextureAtlas* textureAtlas = NULL;

if (atlasFile && ![atlasFile isEqualToString:@""])
{
@try
{
NSString* fileName = [[ResourceManager sharedManager] toAbsolutePath:atlasFile];
CCTexture2D *texture = [[CCTextureCache sharedTextureCache] addImage:fileName];
textureAtlas = [[[CCTextureAtlas alloc] initWithTexture:texture capacity:29] autorelease];
}
@catch (NSException *exception)
{
textureAtlas = NULL;
}
}

if (textureAtlas)
[node setValue:textureAtlas forKey:prop];
}

+ (void) setFontForNode:(CCNode*)node andProperty:(NSString*) prop withFile:(NSString*) fontFile
{
NSString* absPath = NULL;