// // XPPKAction.m // YUMI // // Created by YUMI on 2024/01/01. // #import "XPPKAction.h" #import "XPRoomMoreMenuActionContext.h" #import "RoomInfoModel.h" #import "DJDKMIMOMColor.h" #import "TTPopup.h" #import "BaseViewController.h" #import "XPRoomPKViewController.h" #import "XPAcrossRoomPKViewController.h" #import "XPAnchorPKViewController.h" #import "AccountInfoStorage.h" @implementation XPPKAction #pragma mark - 同房PK模式 + (instancetype)roomPKOpenAction { XPPKAction *action = [[XPPKAction alloc] init]; action.title = YMLocalizedString(@"XPMoreMenuPresenter1"); action.imageName = @"room_pk_menu_icon"; action.type = RoomMoreMenuType_Room_PK_Open; action.titleColor = [DJDKMIMOMColor appCellBackgroundColor]; return action; } + (instancetype)roomPKCloseAction { XPPKAction *action = [[XPPKAction alloc] init]; action.title = YMLocalizedString(@"XPMoreMenuPresenter26"); action.imageName = @"room_pk_menu_icon"; action.type = RoomMoreMenuType_Room_PK_Close; action.titleColor = [DJDKMIMOMColor appCellBackgroundColor]; return action; } #pragma mark - 跨房PK + (instancetype)acrossRoomPKOpenAction { XPPKAction *action = [[XPPKAction alloc] init]; action.title = YMLocalizedString(@"XPMoreMenuPresenter31"); action.imageName = @"crossroom_pk_menu_icon"; action.type = RoomMoreMenuType_Room_Across_PK_Open; action.titleColor = [DJDKMIMOMColor appCellBackgroundColor]; return action; } + (instancetype)acrossRoomPKCloseAction{ XPPKAction *action = [[XPPKAction alloc] init]; action.title = YMLocalizedString(@"XPMoreMenuPresenter31"); action.imageName = @"crossroom_pk_menu_icon"; action.type = RoomMoreMenuType_Room_Across_PK_Close; action.titleColor = [DJDKMIMOMColor appCellBackgroundColor]; return action; } #pragma mark - 主播PK + (instancetype)anchorPKOpenAction { XPPKAction *action = [[XPPKAction alloc] init]; action.title = YMLocalizedString(@"XPMoreMenuPresenter33"); action.imageName = @"room_more_menu_anchor_pk"; action.type = RoomMoreMenuType_Room_Anchor_PK_Open; action.titleColor = [DJDKMIMOMColor appCellBackgroundColor]; return action; } + (instancetype)anchorPKCloseAction { XPPKAction *action = [[XPPKAction alloc] init]; action.title = YMLocalizedString(@"XPMoreMenuPresenter32"); action.imageName = @"room_more_menu_anchor_pk"; action.type = RoomMoreMenuType_Room_Anchor_PK_Close; action.titleColor = [DJDKMIMOMColor appCellBackgroundColor]; return action; } #pragma mark - 相亲模式 + (instancetype)datingOpenAction { XPPKAction *action = [[XPPKAction alloc] init]; action.title = YMLocalizedString(@"XPMoreMenuPresenter8"); action.imageName = @"room_more_menu_dating"; action.type = RoomMoreMenuType_Room_Dating_Open; action.titleColor = [DJDKMIMOMColor appCellBackgroundColor]; return action; } + (instancetype)datingCloseAction { XPPKAction *action = [[XPPKAction alloc] init]; action.title = YMLocalizedString(@"XPMoreMenuPresenter29"); action.imageName = @"room_more_menu_dating"; action.type = RoomMoreMenuType_Room_Dating_Close; action.titleColor = [DJDKMIMOMColor appCellBackgroundColor]; return action; } #pragma mark - 根据房间信息创建Action + (instancetype)roomPKActionWithRoomInfo:(RoomInfoModel *)roomInfo { return roomInfo.roomModeType == RoomModeType_Open_PK_Mode ? [self roomPKOpenAction] : [self roomPKCloseAction]; } + (instancetype)corssPKActionWithRoomInfo:(RoomInfoModel *)roomInfo { return roomInfo.roomModeType == RoomModeType_Open_AcrossRoomPK_mode ? [self acrossRoomPKCloseAction] : [self acrossRoomPKOpenAction]; } + (instancetype)blindActionWithRoomInfo:(RoomInfoModel *)roomInfo { return roomInfo.roomModeType == RoomModeType_Open_Blind ? [self datingCloseAction] : [self datingOpenAction]; } #pragma mark - XPRoomMoreMenuAction - (BOOL)canExecuteWithContext:(XPRoomMoreMenuActionContext *)context { NSLog(@"=== XPPKAction canExecuteWithContext ==="); NSLog(@"Action 类型: %ld, 标题: %@", (long)self.type, self.title); // 所有PK相关的Action都可以执行 return YES; } - (void)executeWithContext:(XPRoomMoreMenuActionContext *)context { NSLog(@"=== XPPKAction executeWithContext ==="); NSLog(@"Action 类型: %ld, 标题: %@", (long)self.type, self.title); switch (self.type) { case RoomMoreMenuType_Room_PK_Open: [self executeRoomPKOpen:context]; break; case RoomMoreMenuType_Room_PK_Close: [self executeRoomPKClose:context]; break; case RoomMoreMenuType_Room_Across_PK_Open: [self executeAcrossRoomPKOpen:context]; break; case RoomMoreMenuType_Room_Across_PK_Close: [self executeAcrossRoomPKClose:context]; break; case RoomMoreMenuType_Room_Anchor_PK_Open: [self executeAnchorPKOpen:context]; break; case RoomMoreMenuType_Room_Anchor_PK_Close: [self executeAnchorPKClose:context]; break; case RoomMoreMenuType_Room_Dating_Open: [self executeDatingOpen:context]; break; case RoomMoreMenuType_Room_Dating_Close: [self executeDatingClose:context]; break; default: NSLog(@"❌ 未知的PK Action类型: %ld", (long)self.type); break; } } #pragma mark - 私有执行方法 - (void)executeRoomPKOpen:(XPRoomMoreMenuActionContext *)context { NSLog(@"执行开启同房PK模式"); // 检查房间模式冲突 if (context.roomInfo.roomModeType == RoomModeType_Open_Blind) { [self showErrorToast:YMLocalizedString(@"XPRoomMoreMenuViewController20") context:context]; [self dismissViewController:context]; return; } if (context.roomInfo.roomModeType == RoomModeType_Open_AcrossRoomPK_mode) { [self showErrorToast:YMLocalizedString(@"XPRoomMoreMenuViewController21") context:context]; [self dismissViewController:context]; return; } // 跳转到同房PK页面 [self dismissViewController:context]; XPRoomPKViewController *roomPKVC = [[XPRoomPKViewController alloc] initWithDelegate:context.hostDelegate]; [context.hostDelegate.getCurrentNav pushViewController:roomPKVC animated:YES]; } - (void)executeRoomPKClose:(XPRoomMoreMenuActionContext *)context { NSLog(@"执行关闭同房PK模式"); // 跳转到同房PK页面 [self dismissViewController:context]; XPRoomPKViewController *roomPKVC = [[XPRoomPKViewController alloc] initWithDelegate:context.hostDelegate]; [context.hostDelegate.getCurrentNav pushViewController:roomPKVC animated:YES]; } - (void)executeAcrossRoomPKOpen:(XPRoomMoreMenuActionContext *)context { NSLog(@"执行开启跨房PK"); // 检查房间模式冲突 if (context.roomInfo.roomModeType == RoomModeType_Open_Blind) { [self showErrorToast:YMLocalizedString(@"XPRoomMoreMenuViewController13") context:context]; [self dismissViewController:context]; return; } if (context.roomInfo.roomModeType == RoomModeType_Open_PK_Mode) { [self showErrorToast:YMLocalizedString(@"XPRoomMoreMenuViewController14") context:context]; [self dismissViewController:context]; return; } // 跳转到跨房PK页面 [self dismissViewController:context]; NSString *roomUid = [NSString stringWithFormat:@"%ld", context.roomInfo.uid]; XPAcrossRoomPKViewController *acrossRoomPKVC = [[XPAcrossRoomPKViewController alloc] initWithRoomUid:roomUid]; [context.hostDelegate.getCurrentNav presentViewController:acrossRoomPKVC animated:YES completion:nil]; } - (void)executeAcrossRoomPKClose:(XPRoomMoreMenuActionContext *)context { NSLog(@"执行关闭跨房PK"); [self showErrorToast:YMLocalizedString(@"XPRoomMoreMenuViewController15") context:context]; [self dismissViewController:context]; } - (void)executeAnchorPKOpen:(XPRoomMoreMenuActionContext *)context { NSLog(@"执行开启主播PK"); if (context.hostDelegate.getRoomInfo.pkMatchStartTime) { // PK匹配中,显示取消匹配确认框 TTAlertConfig *config = [[TTAlertConfig alloc] init]; config.message = YMLocalizedString(@"XPRoomMoreMenuViewController16"); [TTPopup alertWithConfig:config confirmHandler:^{ NSString *roomUid = [NSString stringWithFormat:@"%ld", context.roomInfo.uid]; // [context.hostDelegate requestCancelMatchRandomPK:roomUid]; } cancelHandler:^{ }]; } else { // 跳转到主播PK页面 [self dismissViewController:context]; NSString *roomUid = [NSString stringWithFormat:@"%ld", context.roomInfo.uid]; XPAnchorPKViewController *anchorPKVC = [[XPAnchorPKViewController alloc] initWithRoomUid:roomUid]; [context.hostDelegate.getCurrentNav presentViewController:anchorPKVC animated:YES completion:nil]; } } - (void)executeAnchorPKClose:(XPRoomMoreMenuActionContext *)context { NSLog(@"执行关闭主播PK"); if (context.roomInfo.pkState == AcrossRoomPkStateTypePenalty) { if ([context.roomInfo.winUid isEqualToString:[AccountInfoStorage instance].getUid]) { // 赢 if (context.roomInfo.roundId) { // [context.hostDelegate requestFinishAnchorPK:[NSString stringWithFormat:@"%ld", context.roomInfo.roundId]]; } } else if ([context.roomInfo.winUid isEqualToString:context.roomInfo.pkUid]) { // 输,不需要操作 } else { // 平局 if (context.roomInfo.roundId) { // [context.hostDelegate requestFinishAnchorPK:[NSString stringWithFormat:@"%ld", context.roomInfo.roundId]]; } } } else { if (context.roomInfo.roundId) { // [context.hostDelegdate requestFinishAnchorPK:[NSString stringWithFormat:@"%ld", context.roomInfo.roundId]]; } } } - (void)executeDatingOpen:(XPRoomMoreMenuActionContext *)context { NSLog(@"执行开启相亲模式"); // 检查房间模式冲突 if (context.roomInfo.roomModeType == RoomModeType_Open_AcrossRoomPK_mode) { [self showErrorToast:YMLocalizedString(@"XPRoomMoreMenuViewController6") context:context]; [self dismissViewController:context]; return; } if (context.roomInfo.roomModeType == RoomModeType_Open_PK_Mode) { [self showErrorToast:YMLocalizedString(@"XPRoomMoreMenuViewController7") context:context]; [self dismissViewController:context]; return; } // 显示确认框 TTAlertConfig *config = [[TTAlertConfig alloc] init]; config.message = YMLocalizedString(@"XPRoomMoreMenuViewController8"); config.confirmButtonConfig.title = YMLocalizedString(@"XPRoomMoreMenuViewController9"); [TTPopup alertWithConfig:config confirmHandler:^{ NSString *roomUid = [NSString stringWithFormat:@"%ld", context.roomInfo.uid]; // [context.hostDelegate openRoomDating:roomUid]; } cancelHandler:^{ }]; } - (void)executeDatingClose:(XPRoomMoreMenuActionContext *)context { NSLog(@"执行关闭相亲模式"); // 显示确认框 TTAlertConfig *config = [[TTAlertConfig alloc] init]; config.title = YMLocalizedString(@"XPRoomMoreMenuViewController10"); config.message = YMLocalizedString(@"XPRoomMoreMenuViewController11"); config.confirmButtonConfig.title = YMLocalizedString(@"XPRoomMoreMenuViewController12"); [TTPopup alertWithConfig:config confirmHandler:^{ NSString *roomUid = [NSString stringWithFormat:@"%ld", context.roomInfo.uid]; // [context.hostDelegate closeRoomDating:roomUid]; } cancelHandler:^{ }]; } #pragma mark - 辅助方法 - (void)showErrorToast:(NSString *)message context:(XPRoomMoreMenuActionContext *)context { if (context.presentingViewController && [context.presentingViewController respondsToSelector:@selector(showErrorToast:)]) { BaseViewController *viewController = (BaseViewController *)context.presentingViewController; [viewController showErrorToast:message]; } } - (void)dismissViewController:(XPRoomMoreMenuActionContext *)context { if (context.presentingViewController && [context.presentingViewController respondsToSelector:@selector(dismissViewControllerAnimated:completion:)]) { BaseViewController *viewController = (BaseViewController *)context.presentingViewController; [viewController dismissViewControllerAnimated:NO completion:nil]; } } @end