GameWinView.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //
  2. // GameWinView.m
  3. // BuguLive
  4. //
  5. // Created by yy on 16/12/6.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. //
  8. #import "GameWinView.h"
  9. #import "GameGiftCell.h"
  10. @implementation GameWinView
  11. + (instancetype)EditNibFromXib
  12. {
  13. return [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil].lastObject;
  14. }
  15. -(void)awakeFromNib
  16. {
  17. [super awakeFromNib];
  18. self.giftCollectionView.delegate = self;
  19. self.giftCollectionView.dataSource = self;
  20. self.giftView.hidden = YES;
  21. self.gratuityBtn.layer.cornerRadius = 15;
  22. self.gratuityBtn.layer.masksToBounds = YES;
  23. self.gratuityBtn.backgroundColor = kAppMainColor;
  24. self.giftCollectionView.backgroundColor = [UIColor whiteColor];
  25. [self.giftCollectionView registerNib:[UINib nibWithNibName:@"GameGiftCell" bundle:nil] forCellWithReuseIdentifier:@"GameGiftCell"];
  26. if ([GlobalVariables sharedInstance].appModel.open_diamond_game_module == 1)
  27. {
  28. self.gameCoinImageView.image = [UIImage imageNamed:@"com_diamond_1"];
  29. }
  30. else
  31. {
  32. self.gameCoinImageView.image = [UIImage imageNamed:@"gm_coin"];
  33. }
  34. self.closeView.userInteractionEnabled = YES;
  35. UITapGestureRecognizer * gester = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickCloseView)];
  36. [self.closeView addGestureRecognizer:gester];
  37. }
  38. -(void)setModel:(GameGainModel *)model
  39. {
  40. _model = model;
  41. [self.giftCollectionView reloadData];
  42. }
  43. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  44. {
  45. return self.model.gift_list.count;
  46. }
  47. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  48. {
  49. GameGiftCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"GameGiftCell" forIndexPath:indexPath] ;
  50. cell.model = self.model.gift_list[indexPath.item];
  51. return cell ;
  52. }
  53. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  54. {
  55. //选中之后礼物图标改变
  56. for (GiftModel * giftModel in self.model.gift_list) {
  57. giftModel.isSelected = NO;
  58. }
  59. GiftModel * selectModel = self.model.gift_list[indexPath.item];
  60. selectModel.isSelected = YES;
  61. self.model.gift_list[indexPath.item] = selectModel;
  62. [self.giftCollectionView reloadData];
  63. }
  64. -(void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath
  65. {
  66. }
  67. //点击打赏按钮
  68. - (IBAction)clickGratuityBtn:(id)sender {
  69. BOOL haveSelected = NO;
  70. for (int i=0; i<self.model.gift_list.count; i++) {
  71. GiftModel *giftModel = self.model.gift_list[i];
  72. if (giftModel.isSelected) {
  73. if ([[IMAPlatform sharedInstance].host getDiamonds] < giftModel.diamonds) {
  74. [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:ASLocalizedString(@"用户%@不足"),self.BuguLive.appModel.diamond_name]];
  75. return;
  76. }
  77. //刷新用户信息
  78. haveSelected = YES;
  79. if (_delegate && [_delegate respondsToSelector:@selector(senGift:AndGiftModel:)]) {
  80. [_delegate senGift:nil AndGiftModel:giftModel];
  81. }
  82. }
  83. }
  84. if (!haveSelected) {
  85. [FanweMessage alert:ASLocalizedString(@"还没选择礼物哦")];
  86. }
  87. }
  88. -(void)clickCloseView
  89. {
  90. if (_delegate && [_delegate respondsToSelector:@selector(gameWinViewDown)]) {
  91. [_delegate gameWinViewDown];
  92. }
  93. }
  94. @end