Skip to content
This repository was archived by the owner on Nov 18, 2019. It is now read-only.
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
15 changes: 14 additions & 1 deletion GKAchievementHandler.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
@interface GKAchievementHandler : NSObject <GKAchievementHandlerDelegate>
{
UIView *_topView; /**< Reference to top view of UIApplication. */
UIWindow *_keyWindow; /**< Reference to top view of UIApplication. */
NSMutableArray *_queue; /**< Queue of achievement notifiers to display. */
UIImage *_image; /**< Logo to display in notifications. */
}
Expand All @@ -47,4 +47,17 @@
*/
- (void)notifyAchievementTitle:(NSString *)title andMessage:(NSString *)message;

/**
* Show an achievement notification with a message manually added.
* @param title The title of the achievement.
* @param message Description of the achievement.
* @param icon Icon of the achievement
*/
- (void)notifyAchievementTitleAndIcon:(NSString *)title andMessage:(NSString *)message withIcon:(UIImage*)icon;

/**
* Show an user configured achievement notification
*/
- (void)notifyAchievementTitleAndIcon:(GKAchievementNotification*)notification;

@end
43 changes: 34 additions & 9 deletions GKAchievementHandler.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ - (void)displayNotification:(GKAchievementNotification *)notification
[notification setImage:nil];
}

[_topView addSubview:notification];
/** when in landscape mode, adding notification view to the topview is the easiest way to get the nofitication displayed in landscape mode instead of setting view.transform manually */
if(_keyWindow.rootViewController) {
[_keyWindow.rootViewController.view addSubview:notification];
}
else {
[_keyWindow addSubview:notification];
}
[notification animateIn];
}

Expand All @@ -60,7 +66,7 @@ - (id)init
self = [super init];
if (self != nil)
{
_topView = [[UIApplication sharedApplication] keyWindow];
_keyWindow = [[UIApplication sharedApplication] keyWindow];
_queue = [[NSMutableArray alloc] initWithCapacity:0];
self.image = [UIImage imageNamed:@"gk-icon.png"];
}
Expand All @@ -69,17 +75,16 @@ - (id)init

- (void)dealloc
{
[_queue release];
[_image release];
[super dealloc];
// [_queue release];
// [_image release];
// [super dealloc];
}

#pragma mark -

- (void)notifyAchievement:(GKAchievementDescription *)achievement
{
GKAchievementNotification *notification = [[[GKAchievementNotification alloc] initWithAchievementDescription:achievement] autorelease];
notification.frame = kGKAchievementFrameStart;
GKAchievementNotification *notification = [[GKAchievementNotification alloc] initWithAchievementDescription:achievement];
notification.handlerDelegate = self;

[_queue addObject:notification];
Expand All @@ -91,8 +96,7 @@ - (void)notifyAchievement:(GKAchievementDescription *)achievement

- (void)notifyAchievementTitle:(NSString *)title andMessage:(NSString *)message
{
GKAchievementNotification *notification = [[[GKAchievementNotification alloc] initWithTitle:title andMessage:message] autorelease];
notification.frame = kGKAchievementFrameStart;
GKAchievementNotification *notification = [[GKAchievementNotification alloc] initWithTitle:title andMessage:message];
notification.handlerDelegate = self;

[_queue addObject:notification];
Expand All @@ -102,6 +106,27 @@ - (void)notifyAchievementTitle:(NSString *)title andMessage:(NSString *)message
}
}

- (void)notifyAchievementTitleAndIcon:(NSString *)title andMessage:(NSString *)message withIcon:(UIImage*)icon {
GKAchievementNotification *notification = [[GKAchievementNotification alloc] initWithTitle:title andMessage:message];

notification.handlerDelegate = self;
[notification setImage:icon];

[_queue addObject:notification];
if ([_queue count] == 1)
{
[self displayNotification:notification];
}
}

- (void)notifyAchievementTitleAndIcon:(GKAchievementNotification*)notification {
[_queue addObject:notification];
if ([_queue count] == 1)
{
[self displayNotification:notification];
}
}

#pragma mark -
#pragma mark GKAchievementHandlerDelegate implementation

Expand Down
68 changes: 68 additions & 0 deletions GKAchievementNotification.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@

#import <UIKit/UIKit.h>

@class GKAchievementDescription;

@class GKAchievementNotification;

#define kGKAchievementAnimeTime 0.4f
#define kGKAchievementDisplayTime 1.75f

#define kGKAchievementDefaultiPhoneSize CGSizeMake(284.f, 52.f);
#define kGKAchievementDefaultiPadSize CGSizeMake(426.f, 52.f);

#define kGKAchievementDefaultBackground @"gk-notification.png"

/*
#define kGKAchievementDefaultSize CGRectMake(0.0f, 0.0f, 284.0f, 52.0f);
#define kGKAchievementFrameStart CGRectMake(18.0f, -53.0f, 284.0f, 52.0f);
#define kGKAchievementFrameEnd CGRectMake(18.0f, 10.0f, 284.0f, 52.0f);
Expand All @@ -21,6 +29,7 @@
#define kGKAchievementText2 CGRectMake(10.0, 20.0f, 264.0f, 22.0f);
#define kGKAchievementText1WLogo CGRectMake(45.0, 6.0f, 229.0f, 22.0f);
#define kGKAchievementText2WLogo CGRectMake(45.0, 20.0f, 229.0f, 22.0f);
*/

#pragma mark -

Expand Down Expand Up @@ -75,6 +84,28 @@

UILabel *_textLabel; /**< Text label used to display achievement title. */
UILabel *_detailLabel; /**< Text label used to display achievement description. */

CGPoint _position; /* center, automatically changes according to device orientation, normally you don't need to change this */
CGSize _size; /* notification window size */

CGPoint _iconPosition; /* position of the icon */
CGSize _iconSize; /* size of the icon, default = 34 * 34 */

CGPoint _titlePosition; /* position of the title */
CGSize _titleSize; /* size of the title textbox, default = 229 * 22 */

CGPoint _descriptionPosition; /* position of the description */
CGSize _descriptionSize; /* size of the description box, default = 229 * 22 */

/*
background image
*/
UIImage* _backgroundImage;
/*
Strech coordinates of the background image,
default (8.0f, 0.0f);
*/
CGPoint _backgroundStretch;

id<GKAchievementHandlerDelegate> _handlerDelegate; /**< Reference to nofification handler. */
}
Expand All @@ -96,6 +127,28 @@
/** Reference to nofification handler. */
@property (nonatomic, retain) id<GKAchievementHandlerDelegate> handlerDelegate;

/* notification position, automatically adjusted according to device orientation(center horizontally) */
@property (nonatomic, readonly) CGPoint position;

/* notification view size, changing this will also cause @iconSize, @titleSize and @descriptionSize to be adjusted automatically */
@property (nonatomic, readonly) CGSize size;


@property (nonatomic, readwrite) CGSize iconSize;

@property (nonatomic, readwrite) CGSize titleSize;
@property (nonatomic, readwrite) CGPoint titlePosition;

@property (nonatomic, readwrite) CGSize descriptionSize;
@property (nonatomic, readwrite) CGPoint descriptionPosition;


/* position of the icon */
@property (nonatomic, readwrite) CGPoint iconPosition;
@property (nonatomic, readwrite) CGPoint backgroundStrech;

@property (nonatomic, readonly) UIImage* backgroundImage;

#pragma mark -

/**
Expand Down Expand Up @@ -129,4 +182,19 @@
*/
- (void)setImage:(UIImage *)image;


/**
* Set the position of the notification
*/
- (void)setPosition:(CGPoint)position;
/**
* Set the size of the notification view
*/
- (void)setSize:(CGSize)size;

/*
* Set the background image
*/
- (void)setCustomBackgroundImage:(NSString*)background;

@end
Loading