//
//  LMGameStartScene.m
//  Lemon_iOS_SDK_Demo
//
//  Created by syt on 14-3-31.
//  Copyright (c) 2014年 syt. All rights reserved.
//

#import "LMGameStartScene.h"

#import "LMPurchaseScene.h"

@implementation LMGameStartScene
{
    int _i;
    
    RootViewController *_rootvc;
    LMPurchaseScene *_purchase;
}

- (id)initWithFrame:(CGRect)frame rootViewController:(RootViewController *)rootViewController
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.backgroundColor = [UIColor whiteColor];
        _rootvc = rootViewController;
        
        UIView *sdkFunctionView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(self.frame.size.width-170, 20, 150, 20)];
        label.backgroundColor = [UIColor whiteColor];
        label.textAlignment = NSTextAlignmentCenter;
        label.text = [NSString stringWithFormat:@"UserID:%@",_rootvc.entity.userId];
        [sdkFunctionView addSubview:label];
        
        sdkFunctionView.backgroundColor = [UIColor whiteColor];
        
        [self addSubview:sdkFunctionView];
        
//        [self addButton:CGRectMake(10, 10, 115, 30) title:@"播放视频" action:@selector(showLogoVideoWithPath) superview:sdkFunctionView];
        [self addButton:CGRectMake(10, 10, 115, 30) title:@"获取可邀请好友" action:@selector(invitableKakaoFriend) superview:sdkFunctionView];
        [self addButton:CGRectMake(135, 10, 33, 30) title:@"充值" action:@selector(purchaseButtonClick) superview:sdkFunctionView];
        [self addButton:CGRectMake(178, 10, 66, 30) title:@"MemberKey" action:@selector(kakaoMemberKey) superview:sdkFunctionView];
        [self addButton:CGRectMake(254, 10, 66, 30) title:@"受邀数量" action:@selector(getKakaoInvitationEvent) superview:sdkFunctionView];
        [self addButton:CGRectMake(330, 10, 33, 30) title:@"绑定" action:@selector(bindkakao) superview:sdkFunctionView];
        
        [self addButton:CGRectMake(10, 50, 33, 30) title:@"登出" action:@selector(logout) superview:sdkFunctionView];
        [self addButton:CGRectMake(53, 50, 33, 30) title:@"删除" action:@selector(deleteKakao) superview:sdkFunctionView];
        [self addButton:CGRectMake(96, 50, 75, 30) title:@"kakao好友" action:@selector(getKakaoFriend) superview:sdkFunctionView];
        [self addButton:CGRectMake(257, 50, 66, 30) title:@"设置通知" action:@selector(msgSetting) superview:sdkFunctionView];
        
        [self addButton:CGRectMake(10, 90, 66, 30) title:@"广告展示" action:@selector(placement) superview:sdkFunctionView];
        
        [rootViewController.view addSubview:self];
        
        //显示悬浮用户中心按钮调用
        [[LMPlatform sharedInstance] showLemonCircleView:1 roleID:@"123456" payExt:@"test_payext"];
        
    }
    return self;
}

-(void)addButton:(CGRect)frame title:(NSString *)title action:(SEL)action superview:(UIView *)superview
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button.frame = frame;
    [button setTitle:title forState:UIControlStateNormal];
    [button addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
    [superview addSubview:button];
}

-(void)showLogoVideoWithPath
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"LemonLogoHorizontal" ofType:@"mp4"];
    
    [[LMPlatform sharedInstance] showLogoVideoWithPath:path backgroundColor:[UIColor colorWithRed:250.0/255.0 green:225.0/255.0 blue:0.0/255.0 alpha:1] andDelegate:_rootvc];
}

-(void)purchaseButtonClick
{
    _purchase = [[LMPurchaseScene alloc] initWithFrame:self.bounds rootViewController:_rootvc];
}

-(void)bindkakao
{
    [[LMPlatform sharedInstance] bindKakao];
}

-(void)placement
{
//    [[LMPlatform sharedInstance]placementWithName:@"In App Purchase"];
}

-(void)msgSetting
{
    [[LMPlatform sharedInstance] showAllowMessageSettingView];
}


-(void)getKakaoInvitationEvent
{
    [[LMPlatform sharedInstance]getKakaoInvitationEvent];
}



//注销
-(void)logout
{
    [[LMPlatform sharedInstance]kakaoLogoutWithCustomUI];
}


- (void)deleteKakao
{
    [[LMPlatform sharedInstance]deleteKakao];
}

//kakao好友
- (void)getKakaoFriend
{
    [[LMPlatform sharedInstance]kaKaoGetFriend];
   
    
}

//kakao可邀请好友
- (void)invitableKakaoFriend
{
    [[LMPlatform sharedInstance]invitableKakaoFriend:@"9068"];
}

- (void)kakaoMemberKey
{
    [[LMPlatform sharedInstance] kakaoMemberKey];
}

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"msg_bg" ofType:@"png"];
    LMDebugS(@"======path=%@",path);
    
    UIImage *shareImage=[UIImage imageWithContentsOfFile:path];
    
    NSData *imD=UIImagePNGRepresentation(shareImage);
    if(imD.length==0)imD=UIImageJPEGRepresentation(shareImage, 0);
}

- (void)showLeaderboard
{
    [[LMPlatform sharedInstance] gameCenterShowLeaderboardIdentifier:@"com.longtugame.wowm.leaderboardIdentifier.po"];
}

- (void)AchievementUploadScore
{
    
    [[LMPlatform sharedInstance] gameCenterUploadScoreWithAchievementIdentifier:@"CgkIu4HvaQbEAIQAw" andPercentComplete:20+ _i++];
}

//分享
-(void)unionShare
{
    [[LMPlatform sharedInstance] gameCenterShowAchievement];
}

- (void)showAchievement
{
    NSLog(@"%d",[self isAllowedNotification]);
    [[LMPlatform sharedInstance] cancellationOfTheCurrentAccount];
    
}

- (BOOL)isAllowedNotification
{
    //iOS8 check if user allow notification
    
    if([[UIApplication sharedApplication] respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) {// system is iOS8
        UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];
        
        if
            (UIUserNotificationTypeNone != setting.types) {
                
                return YES;
            }
    }
    else
    {//iOS7
        UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
        
        if(UIRemoteNotificationTypeNone != type)
            
            return YES;
    }
    
    
    return NO;
}
@end
