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

V3.4.9 #1348

Open
wants to merge 6 commits into
base: v3.4.9
Choose a base branch
from
3 changes: 3 additions & 0 deletions cocos2d/CCProgressNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ typedef NS_ENUM(NSUInteger, CCProgressNodeType) {
/** Progress start position. */
@property (nonatomic, readwrite) CGPoint midpoint;

/** Radial Reverse Direction */
@property (nonatomic, readwrite) BOOL reverseRadial;

/// -----------------------------------------------------------------------
/// @name Animating the Progress Node
/// -----------------------------------------------------------------------
Expand Down
29 changes: 23 additions & 6 deletions cocos2d/CCProgressNode.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ @implementation CCProgressNode {
@synthesize sprite = _sprite;
@synthesize type = _type;
@synthesize reverseDirection = _reverseDirection;
@synthesize reverseRadial = _reverseRadial;
@synthesize midpoint = _midpoint;
@synthesize barChangeRate = _barChangeRate;

Expand All @@ -76,6 +77,7 @@ -(id)initWithSprite:(CCSprite*) sprite
if(( self = [super init] )){
_type = CCProgressNodeTypeRadial;
_reverseDirection = NO;
_reverseRadial = NO;
_percentage = 0.f;
_verts = NULL;
_vertexCount = 0;
Expand Down Expand Up @@ -146,6 +148,15 @@ -(void)setReverseDirection:(BOOL)reverse
}
}

-(void)setReverseRadial:(BOOL)counterClockWise {
if(_reverseRadial != counterClockWise) {
_reverseRadial = counterClockWise;

_dirtyVertexData = YES;
_needsUpdateProgress = YES;
}
}

-(void)setColor:(CCColor*)c
{
_sprite.color = c;
Expand Down Expand Up @@ -259,10 +270,15 @@ -(void)setMidpoint:(CGPoint)midPoint
}

static inline CGPoint
BoundryTexCoord(int index)
BoundryTexCoord(int index, bool reverse)
{
static const CGPoint points[] = {{1,1}, {1,0}, {0,0}, {0,1}};
return points[index];
if (!reverse) {
static const CGPoint points[] = {{1,1}, {1,0}, {0,0}, {0,1}};
return points[index];
} else {
static const CGPoint points[] = {{0,1}, {0,0}, {1,0}, {1,1}};
return points[index];
}
}

///
Expand All @@ -283,6 +299,7 @@ -(void)updateRadial
float alpha = _percentage / 100.f;

float angle = 2.f*((float)M_PI) * ( _reverseDirection == YES ? alpha : 1.f - alpha);
angle *= (_reverseRadial == YES) ? -1.f : 1.f;

// We find the vector to do a hit detection based on the percentage
// We know the first vector is the one @ 12 o'clock (top,mid) so we rotate
Expand Down Expand Up @@ -314,8 +331,8 @@ -(void)updateRadial
for (int i = 0; i <= 4; ++i) {
int pIndex = (i + 3)%4;

CGPoint edgePtA = BoundryTexCoord(i % 4);
CGPoint edgePtB = BoundryTexCoord(pIndex);
CGPoint edgePtA = BoundryTexCoord(i % 4, _reverseRadial);
CGPoint edgePtB = BoundryTexCoord(pIndex, _reverseRadial);

// Remember that the top edge is split in half for the 12 o'clock position
// Let's deal with that here by finding the correct endpoints
Expand Down Expand Up @@ -385,7 +402,7 @@ -(void)updateRadial
_verts[1].position = [self vertexFromAlphaPoint:topMid];

for(int i = 0; i < index; ++i){
CGPoint alphaPoint = BoundryTexCoord(i);
CGPoint alphaPoint = BoundryTexCoord(i, _reverseRadial);
_verts[i+2].texCoord1 = [self textureCoordFromAlphaPoint:alphaPoint];
_verts[i+2].position = [self vertexFromAlphaPoint:alphaPoint];
}
Expand Down
2 changes: 2 additions & 0 deletions cocos2d/Support/CCFileUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ extern NSString * const CCFileUtilsSuffixiPhone;
extern NSString * const CCFileUtilsSuffixiPhoneHD;
extern NSString * const CCFileUtilsSuffixiPhone5;
extern NSString * const CCFileUtilsSuffixiPhone5HD;
extern NSString * const CCFileUtilsSuffixiPhone6Plus;
extern NSString * const CCFileUtilsSuffixiPhone6PlusHD;
extern NSString * const CCFileUtilsSuffixMac;
extern NSString * const CCFileUtilsSuffixMacHD;

Expand Down
14 changes: 14 additions & 0 deletions cocos2d/Support/CCFileUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
NSString * const CCFileUtilsSuffixiPhoneHD = @"iphonehd";
NSString * const CCFileUtilsSuffixiPhone5 = @"iphone5";
NSString * const CCFileUtilsSuffixiPhone5HD = @"iphone5hd";
NSString * const CCFileUtilsSuffixiPhone6Plus = @"iphone6plus";
NSString * const CCFileUtilsSuffixiPhone6PlusHD = @"iphone6plushd";
NSString * const CCFileUtilsSuffixMac = @"mac";
NSString * const CCFileUtilsSuffixMacHD = @"machd";
NSString * const CCFileUtilsSuffix2x = @"2x";
Expand Down Expand Up @@ -163,6 +165,8 @@ -(id) init
@"-hd", CCFileUtilsSuffixiPhoneHD,
@"-iphone5", CCFileUtilsSuffixiPhone5,
@"-iphone5hd", CCFileUtilsSuffixiPhone5HD,
@"-iphone6plus", CCFileUtilsSuffixiPhone6Plus,
@"-iphone6plushd", CCFileUtilsSuffixiPhone6PlusHD,
@"", CCFileUtilsSuffixDefault,
nil];

Expand All @@ -173,6 +177,8 @@ -(id) init
@"resources-iphonehd", CCFileUtilsSuffixiPhoneHD,
@"resources-iphone5", CCFileUtilsSuffixiPhone5,
@"resources-iphone5hd", CCFileUtilsSuffixiPhone5HD,
@"resources-iphone6plus", CCFileUtilsSuffixiPhone6Plus,
@"resources-iphone6plushd", CCFileUtilsSuffixiPhone6PlusHD,
@"", CCFileUtilsSuffixDefault,
nil];

Expand Down Expand Up @@ -223,6 +229,8 @@ - (void) buildSearchResolutionsOrder
[_searchResolutionsOrder addObject:CCFileUtilsSuffixiPadHD];
[_searchResolutionsOrder addObject:CCFileUtilsSuffixiPad];
if( _enableiPhoneResourcesOniPad ) {
[_searchResolutionsOrder addObject:CCFileUtilsSuffixiPhone6PlusHD];
[_searchResolutionsOrder addObject:CCFileUtilsSuffixiPhone6Plus];
[_searchResolutionsOrder addObject:CCFileUtilsSuffixiPhone5HD];
[_searchResolutionsOrder addObject:CCFileUtilsSuffixiPhoneHD];
}
Expand All @@ -240,6 +248,8 @@ - (void) buildSearchResolutionsOrder
{
// Terrible, terrible iPhone 6+ hack.
[self setiPadContentScaleFactor:2.0];
[_searchResolutionsOrder addObject:CCFileUtilsSuffixiPhone6PlusHD];
[_searchResolutionsOrder addObject:CCFileUtilsSuffixiPhone6Plus];
[_searchResolutionsOrder addObject:CCFileUtilsSuffixiPadHD];

[_searchResolutionsOrder addObject:CCFileUtilsSuffixiPhone5HD];
Expand Down Expand Up @@ -413,6 +423,10 @@ -(CGFloat) contentScaleForKey:(NSString*)k inDictionary:(NSDictionary *)dictiona
return 1.0*_iPhoneContentScaleFactor;
if( [key isEqualToString:CCFileUtilsSuffixiPhone5HD] )
return 2.0*_iPhoneContentScaleFactor;
if( [key isEqualToString:CCFileUtilsSuffixiPhone6PlusHD] )
return 2.0*_iPadContentScaleFactor;
if( [key isEqualToString:CCFileUtilsSuffixiPhone6Plus] )
return 1.0*_iPadContentScaleFactor;
if( [key isEqualToString:CCFileUtilsSuffixDefault] )
return 1.0;
#elif __CC_PLATFORM_MAC
Expand Down