TCShowLiveView.m 121 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392
  1. //
  2. // TCShowLiveView.m
  3. // TCShow
  4. //
  5. // Created by AlexiChen on 16/4/14.
  6. // Copyright © 2016年 AlexiChen. All rights reserved.
  7. //
  8. #import "TCShowLiveView.h"
  9. #import "BogoGameListHeadView.h"
  10. #import "BGRedPackSendView.h"
  11. #import "VoiceMoreView.h"
  12. #define KBOTTOM_HEIGHT 50
  13. @implementation TCShowLiveView{
  14. UITapGestureRecognizer *_tapGesture;
  15. }
  16. #pragma mark - ----------------------- 直播生命周期 -----------------------
  17. - (void)releaseAll
  18. {
  19. _liveController = nil;
  20. [_liveInputView removeFromSuperview];
  21. [_bottomView removeFromSuperview];
  22. [_topView removeFromSuperview];
  23. if (_msgView.contentOffsetTimer)
  24. {
  25. [_msgView.contentOffsetTimer invalidate];
  26. _msgView.contentOffsetTimer = nil;
  27. }
  28. [[NSNotificationCenter defaultCenter] removeObserver:self];
  29. }
  30. - (void)dealloc
  31. {
  32. [self releaseAll];
  33. }
  34. #pragma mark 开始直播
  35. - (void)startLive
  36. {
  37. [_topView startLive];
  38. [_bottomView startLive];
  39. }
  40. #pragma mark 暂停直播
  41. - (void)pauseLive
  42. {
  43. [_topView pauseLive];
  44. [_bottomView pauseLive];
  45. // [self changeGameView];
  46. }
  47. #pragma mark 重新开始直播
  48. - (void)resumeLive
  49. {
  50. [_topView resumeLive];
  51. [_bottomView resumeLive];
  52. }
  53. #pragma mark 结束直播
  54. - (void)endLive
  55. {
  56. [_topView endLive];
  57. [_bottomView endLive];
  58. [_topView endLive];
  59. [self releaseAll];
  60. if (_goldFlowerView)
  61. {
  62. [_goldFlowerView closeGameAboutTimer];
  63. }
  64. }
  65. #pragma mark - ----------------------- 界面初始化等 -----------------------
  66. #pragma mark 初始化房间信息等
  67. - (instancetype)initWith:(id<FWShowLiveRoomAble>)liveItem liveController:(id<FWLiveControllerAble>)liveController
  68. {
  69. if (self = [super initWithFrame:CGRectZero])
  70. {
  71. _liveItem = liveItem;
  72. self.is_voice = liveItem.is_voice;
  73. _isHost = [liveItem isHost];
  74. _liveController = liveController;
  75. _roomIDStr = StringFromInt([_liveItem liveAVRoomId]);
  76. _currentDiamonds = [[IMAPlatform sharedInstance].host getDiamonds];
  77. [self addSomeListener];
  78. [self addOwnViews];
  79. if (!_isHost)
  80. {
  81. [self showCloseLiveBtn];
  82. }
  83. for (UIView *subView in self.superview) {
  84. [subView setLocalizedString];
  85. }
  86. }
  87. return self;
  88. }
  89. #pragma mark 请求完接口后,刷新直播间相关信息
  90. - (void)refreshLiveItem:(id<FWShowLiveRoomAble>)liveItem liveInfo:(CurrentLiveInfo *)liveInfo
  91. {
  92. _liveItem = liveItem;
  93. _currentLiveInfo = liveInfo;
  94. _isHost = [liveItem isHost];
  95. _roomIDStr = StringFromInt([_liveItem liveAVRoomId]);
  96. [_topView refreshLiveItem:liveItem liveInfo:liveInfo];
  97. [_liveInputView refreshLiveItem:liveItem liveInfo:liveInfo];
  98. [_bottomView refreshLiveItem:liveItem liveInfo:liveInfo];
  99. [_voicebottomView refreshLiveItem:liveItem liveInfo:liveInfo];
  100. if (self.currentLiveInfo.push_type.integerValue == 1) {
  101. _soundSetBt.hidden = !_isHost;
  102. }else{
  103. _soundSetBt.hidden = YES;
  104. }
  105. _live_in = liveInfo.live_in;
  106. _share_type = liveInfo.share_type;
  107. _private_share = liveInfo.private_share;
  108. if (liveInfo.game_log_id != 0 && liveInfo.live_in == FW_LIVE_STATE_ING)
  109. {
  110. // 当前直播间是否在进行游戏
  111. if ( self.game_log_id != liveInfo.game_log_id)
  112. {
  113. self.coinWindowNumber = 0;
  114. }
  115. if (liveInfo.game_log_id > self.game_log_id)
  116. {
  117. [self.gameDataArray removeAllObjects];
  118. self.canNotLoadData = NO;
  119. }
  120. self.game_log_id = liveInfo.game_log_id;
  121. self.game_log_id = liveInfo.game_log_id;
  122. [self loadGameData];
  123. }
  124. else
  125. {
  126. self.shouldReloadGame = NO;
  127. }
  128. }
  129. #pragma mark 添加子视图
  130. - (void)addOwnViews
  131. {
  132. // 头部视图
  133. WeakSelf
  134. _topView = [[TCShowLiveTopView alloc] initWith:_liveItem liveController:_liveController];
  135. _topView.clickVipBlock = ^(BOOL isClick) {
  136. [weakSelf clickShowVipView:nil];
  137. };
  138. [self addSubview:_topView];
  139. // 消息列表
  140. _msgView = [[TCShowLiveMessageView alloc] init];
  141. [self addSubview:_msgView];
  142. // 游戏视图高度
  143. _goldFlowerViewHeiht = 2*kPokerH+15+20+40;
  144. // 底部视图
  145. _bottomView = [[TCShowLiveBottomView alloc] init];
  146. _bottomView.isHost = _isHost;
  147. _bottomView.delegate = self;
  148. _bottomView.heartRect = CGRectMake(kScreenW-kDefaultMargin*2-kMyBtnWidth1*2+5, kScreenH-kDefaultMargin-kMyBtnWidth1+5 - MG_BOTTOM_MARGIN, kMyBtnWidth1-10, kMyBtnWidth1-10);
  149. [self addSubview:_bottomView];
  150. _voicebottomView = [[TCShowVoiceBottomView alloc] init];
  151. _voicebottomView.isHost = _isHost;
  152. _voicebottomView.delegate = self;
  153. _voicebottomView.heartRect = CGRectMake(kScreenW-kDefaultMargin*2-kMyBtnWidth1*2+5, kScreenH-kDefaultMargin-kMyBtnWidth1+5 - MG_BOTTOM_MARGIN, kMyBtnWidth1-10, kMyBtnWidth1-10);
  154. _voicebottomView.hidden = YES;
  155. [self addSubview:_voicebottomView];
  156. // 发送消息框
  157. _liveInputView = [[TCShowLiveInputView alloc] init];
  158. _liveInputView.delegate = self;
  159. _liveInputView.limitLength = kLiveInputViewLimitLength;
  160. _liveInputView.hidden = YES;
  161. _liveInputView.isHost = _isHost;
  162. [self addSubview:_liveInputView];
  163. _soundSetBt = [UIButton buttonWithType:UIButtonTypeCustom];
  164. [_soundSetBt setBackgroundImage:[UIImage imageNamed:@"live_sound_btn"] forState:UIControlStateNormal];
  165. // [_soundSetBt setImage:[UIImage imageNamed:@"live_sound_btn"] forState:UIControlStateNormal];
  166. //2020-1-3 修改音效位置
  167. _soundSetBt.frame = CGRectMake(kScreenW - kRealValue(44) - kRealValue(5), kScreenH / 2 + kRealValue(15+80), kRealValue(44), kRealValue(44));
  168. [_soundSetBt addTarget:self action:@selector(clickSound:) forControlEvents:UIControlEventTouchUpInside];
  169. // [_soundSetBt setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.4]];
  170. _soundSetBt.layer.masksToBounds = YES;
  171. _soundSetBt.layer.cornerRadius = kRealValue(44 / 2);
  172. [self addSubview:_soundSetBt];
  173. if (self.currentLiveInfo.push_type.integerValue == 1) {
  174. _soundSetBt.hidden = !_isHost;
  175. }else{
  176. _soundSetBt.hidden = YES;
  177. }
  178. _livewWishView = [MGShowLiveWishView new];
  179. //4-18 心愿单显示
  180. _livewWishView.hidden = YES;
  181. if ([_liveItem liveType] == FW_LIVE_TYPE_HOST) {
  182. [_livewWishView requestModel:@""];
  183. }
  184. else
  185. {
  186. [_livewWishView requestModel:_roomIDStr];
  187. }
  188. _livewWishView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.4];
  189. [self addSubview:_livewWishView];
  190. _liveVipBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  191. [_liveVipBtn addTarget:self action:@selector(clickShowVipView:) forControlEvents:UIControlEventTouchUpInside];
  192. [_liveVipBtn setImage:[UIImage imageNamed:ASLocalizedString(@"live_show_vipView")] forState:UIControlStateNormal];
  193. _liveVipBtn.hidden = [[GlobalVariables sharedInstance].appModel.open_noble isEqualToString:@"0"];
  194. _liveVipBtn.hidden = YES;
  195. [self addSubview:_liveVipBtn];
  196. // 创建礼物视图及礼物动画视图
  197. [self loadGiftView:[GiftListManager sharedInstance].giftMArray];
  198. }
  199. - (void)setIs_voice:(BOOL)is_voice
  200. {
  201. _is_voice = is_voice;
  202. if(_is_voice == YES)
  203. {
  204. }
  205. else
  206. {
  207. }
  208. }
  209. - (void)addSomeListener
  210. {
  211. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeMoney) name:@"moneyHaveChange" object:nil];
  212. _tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTapBlank:)];
  213. _tapGesture.delegate=self;
  214. _tapGesture.numberOfTapsRequired = 1;
  215. _tapGesture.numberOfTouchesRequired = 1;
  216. [self addGestureRecognizer:_tapGesture];
  217. }
  218. #pragma mark 是否显示关闭推流按钮
  219. - (void)showCloseLiveBtn
  220. {
  221. if (!_closeLiveBtn)
  222. {
  223. FWWeakify(self)
  224. UIImage *closeImage = [UIImage imageNamedL:@"bm_daily_task"];
  225. _closeLiveBtn = [[MenuButton alloc] initWithTitle:nil icon:closeImage action:^(id<MenuAbleItem> menu) {
  226. FWStrongify(self)
  227. [self addSubview:self.dailyTaskPop];
  228. }];
  229. [_closeLiveBtn setImage:closeImage forState:UIControlStateSelected];
  230. _closeLiveBtn.hidden = NO;
  231. [self addSubview:_closeLiveBtn];
  232. }
  233. }
  234. -(void)clickSound:(UIButton *)sender{
  235. [self hiddenGiftView];
  236. if (_uiDelegate && [_uiDelegate respondsToSelector:@selector(showSoundSetView:)])
  237. {
  238. [_uiDelegate showSoundSetView:self];
  239. }
  240. }
  241. #pragma mark - 贵族中心
  242. -(void)clickShowVipView:(UIButton *)sender{
  243. [self hiddenGiftView];
  244. if (_uiDelegate && [_uiDelegate respondsToSelector:@selector(showVipView:)])
  245. {
  246. [_uiDelegate showVipView:self];
  247. }
  248. }
  249. - (BMPopBaseView *)dailyTaskPop
  250. {
  251. _dailyTaskPop = [[[NSBundle mainBundle]loadNibNamed:@"BMPopBaseView" owner:self options:nil]lastObject];
  252. _dailyTaskPop.frame = CGRectMake(0, 0, kScreenW, kScreenH);
  253. [_dailyTaskPop updateUIframeWithWidth:kScreenW - 41 * 2 andHeight:kRealValue(460) andTitleStr:@"" andmyEunmType:BMEachDaytask];
  254. return _dailyTaskPop;
  255. }
  256. #pragma mark 钻石值的改变,刷新用户信息
  257. - (void)changeMoney
  258. {
  259. FWWeakify(self)
  260. [[IMAPlatform sharedInstance].host getMyInfo:^(AppBlockModel *blockModel) {
  261. FWStrongify(self)
  262. self.currentDiamonds = [[IMAPlatform sharedInstance].host getDiamonds];
  263. [self.giftView setDiamondsLabelTxt:[NSString stringWithFormat:@"%ld",(long)self.currentDiamonds]];
  264. }];
  265. }
  266. //#pragma mark 创建礼物视图及礼物动画视图
  267. //- (void)loadGiftView:(NSArray *)list
  268. //{
  269. // NSMutableArray *giftMArray = [NSMutableArray array];
  270. // if (list && [list isKindOfClass:[NSArray class]])
  271. // {
  272. // for (NSDictionary *key in list)
  273. // {
  274. // GiftModel *giftModel = [GiftModel mj_objectWithKeyValues:key];
  275. // [giftMArray addObject:giftModel];
  276. // }
  277. // }
  278. //
  279. // if ([giftMArray count]>4)
  280. // {
  281. // _giftViewHeight = kScreenW*0.56+kSendGiftContrainerHeight+4*kDefaultMargin;
  282. // }
  283. // else
  284. // {
  285. // _giftViewHeight = kScreenW*0.28+kSendGiftContrainerHeight+4*kDefaultMargin;
  286. // }
  287. //
  288. // // 礼物视图
  289. // _giftView = [[GiftView alloc]initWithFrame:CGRectMake(0, kScreenH, kScreenW, _giftViewHeight)];
  290. // _giftView.delegate = self;
  291. // _giftView.hidden = YES;
  292. // [_giftView setGiftView:giftMArray];
  293. // [self addSubview:_giftView];
  294. //
  295. // [self changeMoney];
  296. //}
  297. #pragma mark 创建礼物视图及礼物动画视图
  298. - (void)loadGiftView:(NSArray *)list
  299. {
  300. NSMutableArray *giftMArray = [NSMutableArray array];
  301. if (list && [list isKindOfClass:[NSArray class]])
  302. {
  303. for (NSDictionary *key in list)
  304. {
  305. GiftModel *giftModel = [GiftModel mj_objectWithKeyValues:key];
  306. [giftMArray addObject:giftModel];
  307. }
  308. }
  309. BOOL ret = NO;
  310. for (GiftModel *giftModel in giftMArray) {
  311. if (giftModel.list.count > 4) {
  312. ret = YES;
  313. break;
  314. }
  315. }
  316. WeakSelf
  317. _giftViewHeight = KGiftViewHeight;
  318. // 礼物视图
  319. _giftView = [[GiftView alloc]initWithFrame:CGRectMake(0, kScreenH, kScreenW, _giftViewHeight)];
  320. _giftView.isVoice = self.is_voice;
  321. _giftView.isHost = self.isHost;
  322. _giftView.delegate = self;
  323. _giftView.hidden = YES;
  324. _giftView.isVoice = YES;
  325. _giftView.isHost = self.isHost;
  326. _giftView.clickShadowBlock = ^(BOOL click) {
  327. [weakSelf hiddenGiftView];
  328. // [weakSelf.giftView hide];
  329. };
  330. [_giftView setGiftView:giftMArray];
  331. // [self addSubview:_giftView];
  332. [self changeMoney];
  333. }
  334. - (NSString *)roomId
  335. {
  336. return _roomIDStr;
  337. }
  338. - (void)relayoutFrameOfSubViews
  339. {
  340. CGRect rect = self.bounds;
  341. self.clipsToBounds = YES;
  342. if(self.is_voice)
  343. {
  344. [_topView setFrameAndLayout:CGRectMake(0, kStatusBarHeight + 15, 200, 50)];
  345. if(self.isRTL)
  346. {
  347. [_topView setFrameAndLayout:CGRectMake(kScreenW-200, kStatusBarHeight, 200, 50)];
  348. }
  349. }
  350. else
  351. {
  352. [_topView setFrameAndLayout:CGRectMake(0, kStatusBarHeight, rect.size.width, kLogoContainerViewHeight+66 + 56)];
  353. if(self.isRTL)
  354. {
  355. [_topView setFrameAndLayout:CGRectMake(kScreenW-rect.size.width, kStatusBarHeight, rect.size.width, kLogoContainerViewHeight+66 + 56)];
  356. }
  357. }
  358. if (_goldViewCanNotSee == NO && _goldFlowerView)
  359. {
  360. _bottomView.frame = CGRectMake(0, kScreenH-kMyBtnWidth1-kDefaultMargin-_goldFlowerViewHeiht - MG_BOTTOM_MARGIN, rect.size.width, kMyBtnWidth1);
  361. _liveInputView.frame = _bottomView.frame;
  362. CGFloat tmpY = kScreenH - kSendGiftContrainerHeight - 10 - COMMENT_TABLEVIEW_HEIGHT - _goldFlowerViewHeiht - MG_BOTTOM_MARGIN;
  363. _msgView.frame = CGRectMake(kDefaultMargin, tmpY, rect.size.width * 0.8, COMMENT_TABLEVIEW_HEIGHT);
  364. }
  365. else if (_guessSizeViewCanNotSee == NO && _guessSizeView)
  366. {
  367. _bottomView.frame = CGRectMake(0, kScreenH-kMyBtnWidth1-kDefaultMargin-kGuessSizeViewHeight - MG_BOTTOM_MARGIN, rect.size.width, kMyBtnWidth1);
  368. _liveInputView.frame = _bottomView.frame;
  369. CGFloat tmpY = kScreenH - kSendGiftContrainerHeight - 10 - COMMENT_TABLEVIEW_HEIGHT - kGuessSizeViewHeight - MG_BOTTOM_MARGIN;
  370. _msgView.frame = CGRectMake(kDefaultMargin, tmpY, rect.size.width * 0.8, COMMENT_TABLEVIEW_HEIGHT);
  371. }
  372. else
  373. {
  374. _bottomView.frame = CGRectMake(0, kScreenH-kMyBtnWidth1-kDefaultMargin - MG_BOTTOM_MARGIN, rect.size.width, kMyBtnWidth1);
  375. _liveInputView.frame = _bottomView.frame;
  376. CGFloat tmpY = kScreenH - kSendGiftContrainerHeight - 10 - COMMENT_TABLEVIEW_HEIGHT - MG_BOTTOM_MARGIN;
  377. _msgView.frame = CGRectMake(kDefaultMargin, tmpY, rect.size.width * 0.8, COMMENT_TABLEVIEW_HEIGHT);
  378. }
  379. // }
  380. _voicebottomView.frame = CGRectMake(0, kScreenH-kMyBtnWidth1-kDefaultMargin - MG_BOTTOM_MARGIN, rect.size.width, kMyBtnWidth1);
  381. _livewWishView.frame = CGRectMake(kDefaultMargin, _topView.bottom + kRealValue(5), kRealValue(120), kRealValue(40));
  382. _livewWishView.layer.masksToBounds = YES;
  383. _livewWishView.layer.cornerRadius = kRealValue(40 / 2);
  384. _liveInputView.height = KBOTTOM_HEIGHT;
  385. _liveInputView.y = kScreenH-KBOTTOM_HEIGHT;
  386. // -kDefaultMargin;
  387. if(self.is_voice)
  388. {
  389. _livewWishView.top -= 40;
  390. }
  391. _liveVipBtn.frame = CGRectMake(kScreenW - kRealValue(10) - kRealValue(60), kRealValue(150) + kRealValue(15), kRealValue(60), kRealValue(60));
  392. // [_livewWishView relayoutFrameOfSubViews];
  393. [_bottomView relayoutFrameOfSubViews];
  394. [_liveInputView relayoutFrameOfSubViews];
  395. [_msgView relayoutFrameOfSubViews];
  396. _closeLiveBtn.frame = CGRectMake(kScreenW - kDefaultMargin - 50 - 5, CGRectGetMaxY(self.topView.accountLabel.frame)+1.5*kDefaultMargin+kStatusBarHeight, 50 , 42);
  397. //
  398. // [_closeLiveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  399. //// make.width.equalTo(@(GourdViewWidth));
  400. //// make.height.equalTo(@(GourdViewHeight));
  401. //// make.right.equalTo(self);
  402. // make.centerX.equalTo(self.gourdView);
  403. // make.top.equalTo(self.gourdView.mas_bottom);
  404. // }];
  405. }
  406. #pragma mark - ----------------------- 其他 -----------------------
  407. - (void)onRecvLight:(NSString *)lightName
  408. {
  409. NSInteger praise = [_liveItem livePraise];
  410. [_liveItem setLivePraise:praise + 1];
  411. _bottomView.heartImgViewName = lightName;
  412. [_bottomView showLikeHeart];
  413. }
  414. #if kSupportIMMsgCache
  415. - (void)onRecvPraise:(AVIMCache *)cache
  416. {
  417. NSInteger praise = [_liveItem livePraise];
  418. [_liveItem setLivePraise:praise + cache.count];
  419. [_bottomView showLikeHeart:cache];
  420. }
  421. #endif
  422. #pragma mark 隐藏输入框
  423. - (void)hideInputView
  424. {
  425. if (_liveInputView.hidden)
  426. {
  427. return;
  428. }
  429. [_liveInputView resignFirstResponder];
  430. _liveInputView.hidden = YES;
  431. _bottomView.hidden = NO;
  432. _voicebottomView.hidden = NO;
  433. }
  434. #pragma mark - ----------------------- 发送消息、礼物消息 -----------------------
  435. #pragma mark 点击发送按钮发送消息
  436. - (void)sendMessage
  437. {
  438. NSString *msg = [_liveInputView.text trim];
  439. if (msg.length == 0)
  440. {
  441. return;
  442. }
  443. if (_liveInputView.barrageBtn.isSelected)
  444. { //弹幕消息
  445. [self sendBarrageMsg:msg];
  446. [_liveInputView setText:nil];
  447. }
  448. else
  449. { //普通消息F
  450. SendCustomMsgModel *scmm = [[SendCustomMsgModel alloc] init];
  451. scmm.msgType = MSG_TEXT;
  452. scmm.msg = _liveInputView.text;
  453. scmm.chatGroupID = [_liveItem liveIMChatRoomId];
  454. scmm.is_guardian = self.currentLiveInfo.is_guardian;
  455. scmm.guardianModel = [GlobalVariables sharedInstance].guardianModel;
  456. scmm.guardian_broadcast = [GlobalVariables sharedInstance].guardianModel.guardian_broadcast;
  457. scmm.guardian_remind = [GlobalVariables sharedInstance].guardianModel.guardian_remind;
  458. scmm.guardian_skin = [GlobalVariables sharedInstance].guardianModel.guardian_skin;
  459. scmm.guardian_gift = [GlobalVariables sharedInstance].guardianModel.guardian_gift;
  460. scmm.guardian_img = [GlobalVariables sharedInstance].guardianModel.guardian_img;
  461. scmm.guardian_kick = [GlobalVariables sharedInstance].guardianModel.guardian_kick;
  462. scmm.guardian_icon = [GlobalVariables sharedInstance].guardianModel.guardian_icon;
  463. scmm.is_vip = [NSString stringWithFormat:@"%ld",self.currentLiveInfo.is_vip];
  464. [[BGIMMsgHandler sharedInstance] sendCustomGroupMsg:scmm succ:nil fail:nil];
  465. [_liveInputView setText:nil];
  466. }
  467. [_liveInputView resignFirstResponder];
  468. }
  469. - (void)showRechargeAlert:(NSString *)message
  470. {
  471. FWWeakify(self)
  472. [FanweMessage alert:ASLocalizedString(@"余额不足")message:message destructiveAction:^{
  473. FWStrongify(self)
  474. if (_liveInputView.barrageBtn.isSelected &&!_liveInputView.isHost)
  475. { // 打开了 弹幕
  476. [self showRechargeView:_giftView];
  477. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  478. [self.liveInputView.textField resignFirstResponder];
  479. });
  480. }
  481. else
  482. {
  483. [self showRechargeView:_giftView];
  484. }
  485. } cancelAction:^{
  486. if (_liveInputView.barrageBtn.isSelected && !_liveInputView.isHost)
  487. {// 打开了 弹幕
  488. _liveInputView.hidden = NO;
  489. _bottomView.hidden = YES;
  490. [_liveInputView becomeFirstResponder];
  491. }
  492. }];
  493. }
  494. #pragma mark 发送弹幕消息
  495. - (void)sendBarrageMsg:(NSString*)message
  496. {
  497. _currentDiamonds = [[IMAPlatform sharedInstance].host getDiamonds];
  498. if (_currentDiamonds < self.BuguLive.appModel.bullet_screen_diamond && !_isHost)
  499. {
  500. [self showRechargeAlert:ASLocalizedString(@"当前余额不足,充值才能继续发送弹幕,是否去充值?")];
  501. return;
  502. }
  503. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  504. [mDict setObject:@"deal" forKey:@"ctl"];
  505. [mDict setObject:@"pop_msg" forKey:@"act"];
  506. [mDict setObject:_roomIDStr forKey:@"room_id"];
  507. [mDict setObject:message forKey:@"msg"];
  508. FWWeakify(self)
  509. [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
  510. FWStrongify(self)
  511. if ([responseJson toInt:@"status"] == 1)
  512. {
  513. // 本地金额递减
  514. self.currentDiamonds -= self.BuguLive.appModel.bullet_screen_diamond;
  515. if (self.currentDiamonds >= 0)
  516. {
  517. [self.giftView setDiamondsLabelTxt:[NSString stringWithFormat:@"%ld",(long)self.currentDiamonds]];
  518. if (self.BuguLive.appModel.open_diamond_game_module == 1)
  519. {
  520. // 更新游戏余额
  521. if (self.goldFlowerView)
  522. {
  523. self.goldFlowerView.coinView.gameRechargeView.accountLabel.text =[NSString stringWithFormat:@"%ld",(long)self.currentDiamonds];
  524. }
  525. }
  526. [[IMAPlatform sharedInstance].host setDiamonds:[NSString stringWithFormat:@"%ld",(long)self.currentDiamonds]];
  527. }
  528. }
  529. } FailureBlock:^(NSError *error) {
  530. }];
  531. }
  532. #pragma mark 点击发送礼物
  533. - (void)senGift:(GiftView *)giftView AndGiftModel:(GiftModel *)giftModel
  534. {
  535. _currentDiamonds = [[IMAPlatform sharedInstance].host getDiamonds];
  536. if (_currentDiamonds < giftModel.diamonds)
  537. {
  538. _giftView.sendBtn.hidden = NO;
  539. _giftView.continueContainerView.hidden = YES;
  540. [self showRechargeAlert:ASLocalizedString(@"当前余额不足,充值才能继续送礼,是否去充值?")];
  541. return;
  542. }
  543. if (_live_in == FW_LIVE_STATE_OVER)
  544. {
  545. SFriendObj* chattag = [[SFriendObj alloc]initWithUserId:[[[_liveItem liveHost]imUserId] intValue]];
  546. FWWeakify(self)
  547. [chattag sendGiftMsg:giftModel block:^(SResBase *resb, SIMMsgObj *thatmsg) {
  548. FWStrongify(self)
  549. if( !resb.msuccess )
  550. {
  551. [FanweMessage alert:resb.mmsg];
  552. }
  553. else
  554. { //如果成功了,刷新钻石
  555. self.currentDiamonds -= giftModel.diamonds;
  556. if (self.currentDiamonds >= 0)
  557. {
  558. [self.giftView setDiamondsLabelTxt:[NSString stringWithFormat:@"%ld",(long)self.currentDiamonds]];
  559. if (self.BuguLive.appModel.open_diamond_game_module == 1)
  560. {
  561. //更新游戏余额
  562. if (self.goldFlowerView)
  563. {
  564. self.goldFlowerView.coinView.gameRechargeView.accountLabel.text =[NSString stringWithFormat:@"%ld",(long)self.currentDiamonds];
  565. }
  566. else if (self.guessSizeView)
  567. {
  568. self.guessSizeView.gameRechargeView.accountLabel.text =[NSString stringWithFormat:@"%ld",(long)self.currentDiamonds];
  569. }
  570. }
  571. [[IMAPlatform sharedInstance].host setDiamonds:[NSString stringWithFormat:@"%ld",(long)self.currentDiamonds]];
  572. }
  573. [self showSendGiftSuccessWithModel:giftModel];
  574. }
  575. }];
  576. }
  577. else
  578. {
  579. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  580. [mDict setObject:@"deal" forKey:@"ctl"];
  581. [mDict setObject:@"pop_prop" forKey:@"act"];
  582. [mDict setObject:[NSString stringWithFormat:@"%ld",(long)giftModel.ID] forKey:@"prop_id"];
  583. if([BGUtils isBlankString:giftModel.num])
  584. {
  585. [mDict setObject:@"1" forKey:@"num"];
  586. }
  587. else
  588. {
  589. [mDict setObject:giftModel.num forKey:@"num"];
  590. } [mDict setObject:_roomIDStr forKey:@"room_id"];
  591. [mDict setObject:[NSString stringWithFormat:@"%ld",(long)giftModel.is_plus] forKey:@"is_plus"];
  592. if([GlobalVariables sharedInstance].giftSelecUserId)
  593. {
  594. [mDict setObject:[GlobalVariables sharedInstance].giftSelecUserId forKey:@"to_user_id"];
  595. }
  596. FWWeakify(self)
  597. [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
  598. FWStrongify(self)
  599. if ([responseJson toInt:@"status"] == 1)
  600. {
  601. self.currentDiamonds -= giftModel.diamonds;
  602. if (self.currentDiamonds >= 0)
  603. {
  604. [self.giftView setDiamondsLabelTxt:[NSString stringWithFormat:@"%ld",(long)self.currentDiamonds]];
  605. if (self.BuguLive.appModel.open_diamond_game_module == 1)
  606. {
  607. // 更新游戏余额
  608. if (self.goldFlowerView)
  609. {
  610. self.goldFlowerView.coinView.gameRechargeView.accountLabel.text =[NSString stringWithFormat:@"%ld",(long)self.currentDiamonds];
  611. }
  612. else if (self.guessSizeView)
  613. {
  614. self.guessSizeView.gameRechargeView.accountLabel.text =[NSString stringWithFormat:@"%ld",(long)self.currentDiamonds];
  615. }
  616. }
  617. [[IMAPlatform sharedInstance].host setDiamonds:[NSString stringWithFormat:@"%ld",(long)self.currentDiamonds]];
  618. }
  619. [self showSendGiftSuccessWithModel:giftModel];
  620. }
  621. } FailureBlock:^(NSError *error) {
  622. }];
  623. }
  624. // if (giftModel.is_much == 0 && ![[[IMAPlatform sharedInstance].host imUserId] isEqualToString:[[_liveItem liveHost] imUserId]])
  625. // {
  626. // [FanweMessage alert:[NSString stringWithFormat:ASLocalizedString(@"%@ 已发送"),giftModel.name]];
  627. // }
  628. }
  629. - (void)showSendGiftSuccessWithModel:(GiftModel *)giftModel
  630. {
  631. if (giftModel.is_much == 0 && ![[[IMAPlatform sharedInstance].host imUserId] isEqualToString:[[_liveItem liveHost] imUserId]])
  632. {
  633. // [FanweMessage alert:[NSString stringWithFormat:ASLocalizedString(@"%@ 已发送"),giftModel.name]];
  634. }
  635. }
  636. #pragma mark 显示充值界面
  637. - (void)showRechargeView:(GiftView *)giftView
  638. {
  639. [self hiddenGiftView];
  640. if (_serveceDelegate && [_serveceDelegate respondsToSelector:@selector(rechargeView:)])
  641. {
  642. [_serveceDelegate rechargeView:self];
  643. }
  644. }
  645. -(void)showGiftView:(NSString *)uid
  646. {
  647. __weak typeof(self) ws =self;
  648. [self changeMoney];
  649. _bottomView.hidden = YES;
  650. _giftView.hidden = NO;
  651. _giftView.selectUid = uid;
  652. [_giftView show:self.superview];
  653. [_giftView.shadowViews addGestureRecognizer:_tapGesture];
  654. if (_goldFlowerView)
  655. {
  656. _goldViewCanNotSee = YES;
  657. _goldFlowerView.frame = CGRectMake(0, kScreenH, kScreenW, _goldFlowerViewHeiht);
  658. _bottomView.heartRect = CGRectMake(kScreenW-kDefaultMargin*2-kMyBtnWidth1*2+5, kScreenH-kDefaultMargin-kMyBtnWidth1+5, kMyBtnWidth1-10, kMyBtnWidth1-10);
  659. [self relayoutFrameOfSubViews];
  660. _bottomView.switchGameViewBtn.transform = CGAffineTransformMakeRotation(M_PI);
  661. }
  662. if (_guessSizeView)
  663. {
  664. _guessSizeViewCanNotSee = YES;
  665. _guessSizeView.frame = CGRectMake(0, kScreenH, kScreenW, kGuessSizeViewHeight);
  666. _bottomView.heartRect = CGRectMake(kScreenW-kDefaultMargin*2-kMyBtnWidth1*2+5, kScreenH-kDefaultMargin-kMyBtnWidth1+5, kMyBtnWidth1-10, kMyBtnWidth1-10);
  667. [self relayoutFrameOfSubViews];
  668. _bottomView.switchGameViewBtn.transform = CGAffineTransformMakeRotation(M_PI);
  669. }
  670. if (_sdkDelegate && [_sdkDelegate respondsToSelector:@selector(hideReLiveSlide:)])
  671. {
  672. [_sdkDelegate hideReLiveSlide:YES];
  673. }
  674. [UIView animateWithDuration:0.1 animations:^{
  675. ws.giftView.frame = CGRectMake(0, kScreenH-_giftViewHeight - MG_BOTTOM_MARGIN, _giftView.frame.size.width, _giftView.frame.size.height);
  676. // ws.closeLiveBtn.hidden = YES;
  677. }completion:^(BOOL finished) {
  678. ws.msgView.hidden = YES;
  679. }];
  680. }
  681. #pragma mark - ----------------------- 代理方法 -----------------------
  682. #pragma mark 底部菜单视图代理(TCShowLiveBottomViewDelegate)
  683. - (void)onBottomViewClickMenus:(TCShowLiveBottomView *)bottomView fromButton:(UIButton *)button
  684. {
  685. if(bottomView == self.voicebottomView)
  686. {
  687. if(button.tag == EFunc_VOICE_GIFT)
  688. {
  689. [self showGift];
  690. }
  691. else if(button.tag == EFunc_VOICE_FACE)
  692. {
  693. if (_serveceDelegate && [_serveceDelegate respondsToSelector:@selector(clickFace:)])
  694. {
  695. [_serveceDelegate clickFace:self];
  696. }
  697. }
  698. else if(button.tag == EFunc_VOICE_MUSIC)
  699. {
  700. if (_serveceDelegate && [_serveceDelegate respondsToSelector:@selector(clickFace:)])
  701. {
  702. [_serveceDelegate clickMusic:self];
  703. }
  704. }
  705. else if(button.tag == EFunc_VOICE_CHART)
  706. {
  707. _bankerViewCanSee = NO;
  708. if (_serveceDelegate && [_serveceDelegate respondsToSelector:@selector(clickIM:)])
  709. {
  710. [_serveceDelegate clickIM:self];
  711. }
  712. }
  713. else if(button.tag == EFunc_VOICE_MORE)
  714. {
  715. if (_sdkDelegate && [_sdkDelegate respondsToSelector:@selector(clickVoiceMore:)])
  716. {
  717. [_sdkDelegate clickVoiceMore:self];
  718. }
  719. }
  720. else if(button.tag == EFunc_VOICE_CONNECT_MIKE)
  721. {
  722. if (_sdkDelegate && [_sdkDelegate respondsToSelector:@selector(clickVoiceMic:)])
  723. {
  724. [_sdkDelegate clickVoiceMic:self];
  725. }
  726. }
  727. else if(button.tag == EFunc_VOICE_INPUT)
  728. {
  729. _bankerViewCanSee = NO;
  730. [_liveInputView becomeFirstResponder];
  731. _liveInputView.hidden = NO;
  732. _bottomView.hidden = YES;
  733. _voicebottomView.hidden = YES;
  734. }
  735. else if(button.tag == EFunc_VOICE_GAME)
  736. {
  737. VoiceMoreView *gameView = [[[NSBundle mainBundle]loadNibNamed:@"VoiceMoreView" owner:self options:nil]lastObject];
  738. gameView.user_role = self.currentLiveInfo.user_role;
  739. gameView.liveId = self.currentLiveInfo.room_id;
  740. gameView.frame = CGRectMake(0, self.height - 430, self.width, 430);
  741. gameView.clickWishListBlock = ^{
  742. [self.serveceDelegate clickWishView:self];
  743. };
  744. gameView.clickManagementBlock = ^{
  745. [self.serveceDelegate clickRoomManage:self];
  746. };
  747. [gameView show:self type:FDPopTypeBottom];
  748. return;
  749. }
  750. return;
  751. }
  752. if(button.tag == EFunc_VOICE_GAME)
  753. {
  754. BogoGameListHeadView *gameView = [[[NSBundle mainBundle]loadNibNamed:@"BogoGameListHeadView" owner:self options:nil]lastObject];
  755. gameView.frame = CGRectMake(0, self.height - 240, self.width, 240);
  756. [gameView show:self type:FDPopTypeBottom];
  757. return;
  758. }
  759. if (button.tag == EFunc_RED_PACK)
  760. {
  761. BGRedPackSendView *readView = [[BGRedPackSendView alloc] init];
  762. // readView.video_id = self.video_id;
  763. // readView.userModel = user;
  764. readView.video_id = [NSString stringWithFormat:@"%d",_liveItem.liveAVRoomId];
  765. readView.frame = CGRectMake(40, 0, kRealValue(266), kRealValue(338));
  766. readView.centerX = self.centerX;
  767. readView.centerY = self.centerY;
  768. // readView.userModel = user;
  769. // readView.backgroundColor = kRedColor;
  770. // readView.diamonds = [NSString stringWithFormat:@"%@",responseJson[@"diamonds"]];
  771. [readView show:[AppDelegate sharedAppDelegate].topViewController.view type:FDPopTypeCenter];
  772. }
  773. if (button.tag == EFunc_GIFT)
  774. { // 发送礼物
  775. __weak typeof(self) ws =self;
  776. [self changeMoney];
  777. _voicebottomView.hidden = YES;
  778. _bottomView.hidden = YES;
  779. _giftView.hidden = NO;
  780. [_giftView show:self.superview];
  781. [_giftView.shadowViews addGestureRecognizer:_tapGesture];
  782. if (_goldFlowerView)
  783. {
  784. _goldViewCanNotSee = YES;
  785. _goldFlowerView.frame = CGRectMake(0, kScreenH, kScreenW, _goldFlowerViewHeiht);
  786. _bottomView.heartRect = CGRectMake(kScreenW-kDefaultMargin*2-kMyBtnWidth1*2+5, kScreenH-kDefaultMargin-kMyBtnWidth1+5, kMyBtnWidth1-10, kMyBtnWidth1-10);
  787. [self relayoutFrameOfSubViews];
  788. _bottomView.switchGameViewBtn.transform = CGAffineTransformMakeRotation(M_PI);
  789. }
  790. if (_guessSizeView)
  791. {
  792. _guessSizeViewCanNotSee = YES;
  793. _guessSizeView.frame = CGRectMake(0, kScreenH, kScreenW, kGuessSizeViewHeight);
  794. _bottomView.heartRect = CGRectMake(kScreenW-kDefaultMargin*2-kMyBtnWidth1*2+5, kScreenH-kDefaultMargin-kMyBtnWidth1+5, kMyBtnWidth1-10, kMyBtnWidth1-10);
  795. [self relayoutFrameOfSubViews];
  796. _bottomView.switchGameViewBtn.transform = CGAffineTransformMakeRotation(M_PI);
  797. }
  798. if (_sdkDelegate && [_sdkDelegate respondsToSelector:@selector(hideReLiveSlide:)])
  799. {
  800. [_sdkDelegate hideReLiveSlide:YES];
  801. }
  802. [UIView animateWithDuration:0.1 animations:^{
  803. ws.giftView.frame = CGRectMake(0, kScreenH-_giftViewHeight - MG_BOTTOM_MARGIN, _giftView.frame.size.width, _giftView.frame.size.height);
  804. // ws.closeLiveBtn.hidden = YES;
  805. }completion:^(BOOL finished) {
  806. ws.msgView.hidden = YES;
  807. }];
  808. }
  809. else if (button.tag == EFunc_CONNECT_MIKE)
  810. { // 连麦
  811. if (_serveceDelegate && [_serveceDelegate respondsToSelector:@selector(clickMikeBtn:)])
  812. {
  813. [_serveceDelegate clickMikeBtn:self];
  814. }
  815. }
  816. else if (button.tag == EFunc_SHARE)
  817. { // 分享
  818. if (_serveceDelegate && [_serveceDelegate respondsToSelector:@selector(clickShareBtn:)])
  819. {
  820. [_serveceDelegate clickShareBtn:self];
  821. }
  822. }
  823. else if (button.tag == EFunc_CHART)
  824. { // 私聊
  825. _bankerViewCanSee = NO;
  826. if (_serveceDelegate && [_serveceDelegate respondsToSelector:@selector(clickIM:)])
  827. {
  828. [_serveceDelegate clickIM:self];
  829. }
  830. }
  831. else if (button.tag == EFunc_INPUT)
  832. { // 显示消息输入
  833. _bankerViewCanSee = NO;
  834. [_liveInputView becomeFirstResponder];
  835. _liveInputView.hidden = NO;
  836. _bottomView.hidden = YES;
  837. _voicebottomView.hidden = YES;
  838. }
  839. else if (button.tag == EFunc_AUCTION && [self.BuguLive.appModel.open_pai_module integerValue] == 1)
  840. { // 竞拍
  841. if (_serveceDelegate && [_serveceDelegate respondsToSelector:@selector(clickAuction:)])
  842. {
  843. [_serveceDelegate clickAuction:self];
  844. }
  845. }
  846. else if (button.tag == EFunc_PK)
  847. {
  848. if (_serveceDelegate && [_serveceDelegate respondsToSelector:@selector(clickPkList:)])
  849. {
  850. [_serveceDelegate clickPkList:self];
  851. }
  852. }else if (button.tag == EFunc_SHOP)
  853. {
  854. if (_serveceDelegate && [_serveceDelegate respondsToSelector:@selector(clickShowShopView:)])
  855. {
  856. [_serveceDelegate clickShowShopView:self];
  857. }
  858. }
  859. else if (button.tag == EFunc_WISH){
  860. if (_serveceDelegate && [_serveceDelegate respondsToSelector:@selector(clickWishView:)])
  861. {
  862. [_serveceDelegate clickWishView:self];
  863. }
  864. }
  865. else if (button.tag == EFunc_CLOSE){
  866. if (_serveceDelegate && [_serveceDelegate respondsToSelector:@selector(clickCloseBtn:)])
  867. {
  868. [_serveceDelegate clickCloseBtn:self];
  869. }
  870. }
  871. #if kSupportH5Shopping
  872. else if (button.tag == EFunc_STARSHOP)
  873. { //星店
  874. if (_serveceDelegate && [_serveceDelegate respondsToSelector:@selector(clickStarShop:)])
  875. {
  876. [_serveceDelegate clickStarShop:self];
  877. }
  878. }
  879. #endif
  880. #if kSupportH5Shopping
  881. else if (button.tag == EFunc_SALES_SUSWINDOW)
  882. { // 缩放按钮
  883. return;
  884. AppDelegate *delegate = [AppDelegate sharedAppDelegate];
  885. if (delegate.sus_window.rootViewController)
  886. {
  887. [delegate.sus_window setSmallLiveScreen:YES vc:delegate.sus_window.rootViewController.childViewControllers[0] block:^(BOOL finished) {
  888. }];
  889. }
  890. }
  891. #endif
  892. else if (button.tag == EFunc_GAMES)
  893. { //游戏
  894. if (_serveceDelegate && [_serveceDelegate respondsToSelector:@selector(clickGameBtn:)])
  895. {
  896. [_serveceDelegate clickGameBtn:self];
  897. }
  898. }
  899. else if (button.tag == EFunc_BEGINGAMES)
  900. {
  901. if (_goldFlowerView || _guessSizeView)
  902. {
  903. //开始发牌
  904. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  905. [mDict setObject:@"games" forKey:@"ctl"];
  906. [mDict setObject:@"start" forKey:@"act"];
  907. [mDict setObject:@(_gameId) forKey:@"id"];
  908. [self changeBeginButtonWithCanBeginNext:NO];
  909. [self beginGame];
  910. FWWeakify(self)
  911. [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
  912. FWStrongify(self)
  913. if ([responseJson toInt:@"status"] == 1)
  914. {
  915. self.canNotLoadData = NO;
  916. if (self.goldFlowerView)
  917. {
  918. self.goldFlowerView.game_log_id = [responseJson toString:@"game_log_id"];
  919. }
  920. else if (self.guessSizeView)
  921. {
  922. self.guessSizeView.game_log_id = [responseJson toString:@"game_log_id"];
  923. }
  924. }
  925. else
  926. {
  927. [self changeBeginButtonWithCanBeginNext:YES];
  928. }
  929. } FailureBlock:^(NSError *error) {
  930. FWStrongify(self)
  931. [self changeBeginButtonWithCanBeginNext:YES];
  932. }];
  933. }
  934. }
  935. else if (button.tag == EFunc_SWITCHGAMEVIEW)
  936. {
  937. [self closeOrOpenGameView];
  938. }
  939. else if (button.tag == EFunc_LIVEPAY)//切换付费
  940. {
  941. if (_uiDelegate && [_uiDelegate respondsToSelector:@selector(clickChangePay:)])
  942. {
  943. [_uiDelegate clickChangePay:self];
  944. }
  945. }
  946. else if (button.tag == EFunc_MENTION)//提档
  947. {
  948. if (_uiDelegate && [_uiDelegate respondsToSelector:@selector(clickMention:)])
  949. {
  950. [_uiDelegate clickMention:self];
  951. }
  952. }
  953. else if (button.tag == EFunc_SWITCH_BANNER)//上庄下庄控制按钮
  954. {
  955. if (_goldFlowerView || _guessSizeView)
  956. {
  957. if (_banker_status == 0 || _banker_status == 2)
  958. {
  959. NSString * str = _banker_status == 0 ? ASLocalizedString(@"是否开启上庄?"): ASLocalizedString(@"确定要移除该庄家?");
  960. FWWeakify(self)
  961. [FanweMessage alert:ASLocalizedString(@"提示")message:str destructiveAction:^{
  962. FWStrongify(self)
  963. [self loadBankerRequest];
  964. } cancelAction:^{
  965. }];
  966. }
  967. else if (_banker_status == 1)
  968. {
  969. [self loadBankerRequest];
  970. }
  971. }
  972. }
  973. else if (button.tag == EFunc_GRAB_BANNER)
  974. {
  975. _bankerViewCanSee = YES;
  976. NSMutableDictionary *parmDict = [[NSMutableDictionary alloc]init];
  977. [parmDict setObject:@"games" forKey:@"ctl"];
  978. [parmDict setObject:@"userDiamonds" forKey:@"act"];
  979. FWWeakify(self)
  980. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  981. FWStrongify(self)
  982. if ([responseJson toInt:@"status"] == 1)
  983. {
  984. NSString *coinStr = [responseJson toString:@"user_diamonds"];
  985. self.bankerView.coin = coinStr;
  986. if (self.BuguLive.appModel.open_diamond_game_module == 1)
  987. {
  988. NSString *coinStr = [responseJson toString:@"user_diamonds"];
  989. //存入钻石
  990. [[IMAPlatform sharedInstance].host setDiamonds:[responseJson toString:@"user_diamonds"]];
  991. self.bankerView.myCoinLabel.text = [NSString stringWithFormat:ASLocalizedString(@"余额:%@"),coinStr];
  992. }
  993. else
  994. {
  995. NSString *coinStr = [responseJson toString:@"coin"];
  996. //存入游戏币
  997. [[IMAPlatform sharedInstance].host setUserCoin:[responseJson toString:@"coin"]];
  998. self.bankerView.myCoinLabel.text = [NSString stringWithFormat:ASLocalizedString(@"余额:%@"),coinStr];
  999. }
  1000. }
  1001. else
  1002. {
  1003. self.bottomView.grabBankerBtn.hidden = NO;
  1004. }
  1005. } FailureBlock:^(NSError *error) {
  1006. FWStrongify(self)
  1007. self.bottomView.grabBankerBtn.hidden = NO;
  1008. }];
  1009. [self displayBankerView];
  1010. }
  1011. else if (button.tag == EFunc_MORETOOLS)
  1012. {
  1013. //观众点击更多的插件按钮,目前放的是购物,我的小店
  1014. self.moreToolsView.hidden = NO;
  1015. SUS_WINDOW.window_Tap_Ges.enabled = NO;
  1016. SUS_WINDOW.window_Pan_Ges.enabled = NO;
  1017. FWWeakify(self)
  1018. [UIView animateWithDuration:0.5 animations:^{
  1019. FWStrongify(self)
  1020. self.moreToolsView.transform = CGAffineTransformMakeTranslation(0, -kScreenH);
  1021. } completion:^(BOOL finished) {
  1022. }];
  1023. }
  1024. else if (button.tag == EFunc_FULL_SCREEN)
  1025. {
  1026. // 全屏
  1027. if (_sdkDelegate && [_sdkDelegate respondsToSelector:@selector(clickFullScreen)])
  1028. {
  1029. [_sdkDelegate clickFullScreen];
  1030. }
  1031. }
  1032. }
  1033. - (void)loadBankerRequest
  1034. {
  1035. //开始发牌
  1036. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  1037. [mDict setObject:@"games" forKey:@"ctl"];
  1038. if (_banker_status == 0)
  1039. {
  1040. //开启上庄
  1041. [mDict setObject:@"openBanker" forKey:@"act"];
  1042. }
  1043. else if (_banker_status ==1)
  1044. {
  1045. //查看玩家申请上庄的信息
  1046. [mDict setObject:@"getBankerList" forKey:@"act"];
  1047. FWWeakify(self)
  1048. [UIView animateWithDuration:0.3 animations:^{
  1049. FWStrongify(self)
  1050. self.selectctBankerView.frame = CGRectMake((kScreenW - 280)/2, (kScreenH - 290)/2, 280, 290);
  1051. }];
  1052. }
  1053. else if (_banker_status ==2)
  1054. {
  1055. //展示下庄按钮的功能
  1056. [mDict setObject:@"stopBanker" forKey:@"act"];
  1057. }
  1058. _bottomView.switchBankerBtn.userInteractionEnabled = NO;
  1059. _bottomView.switchBankerBtn.hidden = NO;
  1060. _bottomView.switchBankerBtn.icon = [UIImage imageNamed:@"gm_game_wait"];
  1061. [_bottomView.switchBankerBtn setImage:[UIImage imageNamed:@"gm_game_wait"] forState:UIControlStateNormal];
  1062. [_bottomView.switchBankerBtn setImage:[UIImage imageNamed:@"gm_game_wait"] forState:UIControlStateHighlighted];
  1063. FWWeakify(self)
  1064. [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
  1065. FWStrongify(self)
  1066. if ([responseJson toInt:@"status"] == 1)
  1067. {
  1068. if (_banker_status==1)
  1069. {
  1070. NSArray *bankerList = responseJson[@"banker_list"];
  1071. [self.bankerListArr removeAllObjects];
  1072. for (NSDictionary * bankerDic in bankerList)
  1073. {
  1074. GameBankerModel * model = [GameBankerModel mj_objectWithKeyValues:bankerDic];
  1075. model.isSelect = NO;
  1076. [self.bankerListArr addObject:model];
  1077. }
  1078. self.bottomView.bankMessage = 0;
  1079. self.bottomView.bjsbadge.badgeText = nil;
  1080. self.selectctBankerView.dataArray = self.bankerListArr;
  1081. }
  1082. else if (_banker_status==2)
  1083. {
  1084. //状态为2,说明其点击按钮时处于上庄状态,点击按钮做下庄操作
  1085. self.gameBankerView.hidden = YES;
  1086. }
  1087. if([[responseJson allKeys] containsObject:@"banker_status"])
  1088. {
  1089. self.banker_status = [responseJson toInt:@"banker_status"];
  1090. }
  1091. else
  1092. {
  1093. //如果请求接口成功,但返回的数据没有上庄状态值,则自己改变上庄的状态值
  1094. if (self.banker_status == 0)
  1095. {
  1096. self.banker_status = 1;
  1097. }
  1098. else if (self.banker_status == 2)
  1099. {
  1100. self.banker_status = 0;
  1101. }
  1102. }
  1103. [self changeSwitchBankerBtn];
  1104. }
  1105. else
  1106. {
  1107. [self changeSwitchBankerBtn];
  1108. }
  1109. } FailureBlock:^(NSError *error) {
  1110. FWStrongify(self)
  1111. [self changeSwitchBankerBtn];
  1112. }];
  1113. }
  1114. #pragma mark TCShowLiveInputViewDelegate
  1115. - (void)sendMsg:(TCShowLiveInputView *)inputView
  1116. {
  1117. [self sendMessage];
  1118. }
  1119. #pragma mark - ----------------------- 手势相关 -----------------------
  1120. #pragma mark 单击空白处
  1121. - (void)onTapBlank:(UITapGestureRecognizer *)tap
  1122. {
  1123. if (tap.state == UIGestureRecognizerStateEnded)
  1124. {
  1125. BOOL isShowLight = YES; //是否显示点亮动画
  1126. [self.giftView hide];
  1127. _giftView.hidden = NO;
  1128. if (_serveceDelegate && [_serveceDelegate respondsToSelector:@selector(clickBlank:)])
  1129. {
  1130. [_serveceDelegate clickBlank:self];
  1131. }
  1132. if (_serveceDelegate && [_serveceDelegate respondsToSelector:@selector(closeGoodsView:)])
  1133. {
  1134. [_serveceDelegate closeGoodsView:self];
  1135. }
  1136. if (_serveceDelegate && [_serveceDelegate respondsToSelector:@selector(closeRechargeView:)])
  1137. {
  1138. [_serveceDelegate closeRechargeView:self];
  1139. }
  1140. if (_serveceDelegate && [_serveceDelegate respondsToSelector:@selector(moveAddFriendView)])
  1141. {
  1142. [_serveceDelegate moveAddFriendView];
  1143. }
  1144. if (_serveceDelegate && [_serveceDelegate respondsToSelector:@selector(closeGamesView:)])
  1145. {
  1146. [_serveceDelegate closeGamesView:self];
  1147. }
  1148. if (self.moreToolsView.hidden == NO)
  1149. {
  1150. isShowLight = NO;
  1151. FWWeakify(self)
  1152. [UIView animateWithDuration:0.5 animations:^{
  1153. FWStrongify(self)
  1154. self.moreToolsView.transform = CGAffineTransformIdentity;
  1155. } completion:^(BOOL finished) {
  1156. FWStrongify(self)
  1157. self.moreToolsView.hidden = YES;
  1158. }];
  1159. }
  1160. if ([_liveInputView isInputViewActive])
  1161. {
  1162. [_liveInputView resignFirstResponder];
  1163. isShowLight = NO;
  1164. }
  1165. else
  1166. {
  1167. if (!_liveInputView.hidden)
  1168. {
  1169. [self hideInputView];
  1170. }
  1171. }
  1172. //判断是否正在显示礼物列表
  1173. if (_giftView.isHidden == NO)
  1174. {
  1175. isShowLight = NO;
  1176. [self hiddenGiftView];
  1177. }
  1178. //发送点亮消息
  1179. if (isShowLight && !_isHost && _bottomView.canSendLightMsg && _bottomView.lightCount <= 7 && self.BuguLive.appModel.is_no_light != 1)
  1180. {
  1181. int index = arc4random() % 6;
  1182. NSString* imageName = [NSString stringWithFormat:@"heart%d",index];
  1183. _bottomView.heartImgViewName = imageName;
  1184. [_bottomView showLight];
  1185. SendCustomMsgModel *scmm = [[SendCustomMsgModel alloc] init];
  1186. scmm.msgType = MSG_LIGHT;
  1187. scmm.isShowLight = _canShowLightMessage;
  1188. scmm.msg = imageName;
  1189. scmm.is_guardian = self.currentLiveInfo.is_guardian;
  1190. scmm.is_vip = [NSString stringWithFormat:@"%ld",self.currentLiveInfo.is_vip];
  1191. scmm.chatGroupID = [_liveItem liveIMChatRoomId];
  1192. [[BGIMMsgHandler sharedInstance] sendCustomGroupMsg:scmm succ:nil fail:nil];
  1193. // 进入房间后,第一次点赞时,调用;用于计算:热门排序
  1194. if (_canShowLightMessage)
  1195. {
  1196. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  1197. [mDict setObject:@"video" forKey:@"ctl"];
  1198. [mDict setObject:@"like" forKey:@"act"];
  1199. [mDict setObject:_roomIDStr forKey:@"room_id"];
  1200. [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson){
  1201. } FailureBlock:^(NSError *error) {
  1202. }];
  1203. }
  1204. _canShowLightMessage = NO;
  1205. }
  1206. }
  1207. }
  1208. -(void)closeRechargeWithRechargeView:(RechargeView *)rechargeView{
  1209. [UIView animateWithDuration:0.5 animations:^{
  1210. rechargeView.transform = CGAffineTransformIdentity;
  1211. } completion:^(BOOL finished) {
  1212. rechargeView.hidden = YES;
  1213. }];
  1214. self.giftView.hidden = NO;
  1215. [self.giftView show:self];
  1216. [_giftView.shadowViews addGestureRecognizer:_tapGesture];
  1217. }
  1218. #pragma mark 隐藏giftView
  1219. - (void)hiddenGiftView
  1220. {
  1221. // self.closeLiveBtn.hidden = NO;
  1222. _bottomView.hidden = NO;
  1223. _voicebottomView.hidden = NO;
  1224. _msgView.hidden = NO;
  1225. if (_sdkDelegate && [_sdkDelegate respondsToSelector:@selector(hideReLiveSlide:)])
  1226. {
  1227. [_sdkDelegate hideReLiveSlide:NO];
  1228. }
  1229. // FWWeakify(self)
  1230. // [UIView animateWithDuration:0.1 animations:^{
  1231. //
  1232. // FWStrongify(self)
  1233. // self.giftView.frame = CGRectMake(0, self.frame.size.height, _giftView.frame.size.width, _giftView.frame.size.height);
  1234. //
  1235. // }completion:^(BOOL finished) {
  1236. // FWStrongify(self)
  1237. // self.giftView.hidden = YES;
  1238. // [_giftView hide];
  1239. // }];
  1240. if (_goldFlowerView && _goldViewCanNotSee == YES)
  1241. {
  1242. _goldViewCanNotSee = NO;
  1243. _goldFlowerView.frame = CGRectMake(0, kScreenH-_goldFlowerViewHeiht, kScreenW, _goldFlowerViewHeiht);
  1244. _bottomView.heartRect = CGRectMake(kScreenW-kDefaultMargin*2-kMyBtnWidth1*2+5, kScreenH-kDefaultMargin-kMyBtnWidth1+5-_goldFlowerViewHeiht, kMyBtnWidth1-10, kMyBtnWidth1-10);
  1245. [self relayoutFrameOfSubViews];
  1246. _bottomView.switchGameViewBtn.transform = CGAffineTransformIdentity;
  1247. }
  1248. else if (_guessSizeView && _guessSizeViewCanNotSee == YES)
  1249. {
  1250. _guessSizeViewCanNotSee = NO;
  1251. _guessSizeView.frame = CGRectMake(0, kScreenH-kGuessSizeViewHeight, kScreenW, kGuessSizeViewHeight);
  1252. _bottomView.heartRect = CGRectMake(kScreenW-kDefaultMargin*2-kMyBtnWidth1*2+5, kScreenH-kDefaultMargin-kMyBtnWidth1+5-kGuessSizeViewHeight, kMyBtnWidth1-10, kMyBtnWidth1-10);
  1253. [self relayoutFrameOfSubViews];
  1254. _bottomView.switchGameViewBtn.transform = CGAffineTransformIdentity;
  1255. }
  1256. }
  1257. #pragma mark 用来解决跟tableview等的手势冲突问题
  1258. - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
  1259. {
  1260. if ([touch.view isKindOfClass:[TCShowLiveView class]] && _isHost && _sdkDelegate && [_sdkDelegate respondsToSelector:@selector(hostReceiveTouch:)])
  1261. {
  1262. [_sdkDelegate hostReceiveTouch:touch];
  1263. }
  1264. if ([touch.view isKindOfClass:[UITextView class]] || [touch.view isKindOfClass:[TCShowLiveView class]])
  1265. {
  1266. return YES;
  1267. }
  1268. else if([touch.view isKindOfClass:[UIView class]] && (touch.view.tag == kPlane1Tag || touch.view.tag == kPlane2Tag || touch.view.tag == kFerrariTag || touch.view.tag == kLambohiniTag || touch.view.tag == kRocket1Tag))
  1269. {
  1270. return YES;
  1271. }
  1272. else
  1273. {
  1274. return NO;
  1275. }
  1276. }
  1277. #pragma mark ------------------------游戏相关---------------------------------
  1278. - (void)loadGameData
  1279. {
  1280. if (_canNotLoadData && !_shouldReloadGame)
  1281. {
  1282. _canNotLoadData = NO;
  1283. return;
  1284. }
  1285. _sureOnceGame = NO;
  1286. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  1287. [mDict setObject:@"games" forKey:@"ctl"];
  1288. [mDict setObject:@"get_video" forKey:@"act"];
  1289. if (_isHost || [_liveItem liveType] == 0)
  1290. {
  1291. // 主播前后台切换调用
  1292. [mDict setObject:@(_liveItem.liveAVRoomId) forKey:@"video_id"];
  1293. }
  1294. else if (_game_log_id)
  1295. {
  1296. [mDict setObject:@(_game_log_id) forKey:@"id"];
  1297. }
  1298. else
  1299. {
  1300. //防止gameLogID在外部被修改为0时请求游戏数据调用
  1301. [mDict setObject:@(_liveItem.liveAVRoomId) forKey:@"video_id"];
  1302. }
  1303. FWWeakify(self)
  1304. [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
  1305. FWStrongify(self)
  1306. if ([responseJson toInt:@"status"] == 1)
  1307. {
  1308. [self addGameDataWithDic:responseJson];
  1309. if (self.giftView.hidden == YES)
  1310. {
  1311. self.bottomView.hidden = NO;
  1312. }
  1313. }
  1314. else
  1315. {
  1316. [[BGHUDHelper sharedInstance] tipMessage:[responseJson toString:@"error"]];
  1317. if (self.giftView.hidden == YES)
  1318. {
  1319. self.bottomView.hidden = NO;
  1320. }
  1321. [self hidenAboutGameBtn];
  1322. }
  1323. } FailureBlock:^(NSError *error) {
  1324. FWStrongify(self)
  1325. if (self.giftView.hidden == YES)
  1326. {
  1327. self.bottomView.hidden = NO;
  1328. }
  1329. [self hidenAboutGameBtn];
  1330. }];
  1331. }
  1332. - (void)hidenAboutGameBtn
  1333. {
  1334. _bottomView.switchBankerBtn.hidden = YES;
  1335. _bottomView.switchGameViewBtn.hidden = YES;
  1336. _bottomView.beginGameBtn.hidden = YES;
  1337. _bottomView.grabBankerBtn.hidden = YES;
  1338. }
  1339. - (void)sendDataWithDic:(NSDictionary *)dic
  1340. {
  1341. #ifdef DEBUG
  1342. NSMutableDictionary * dicData = [NSMutableDictionary dictionary];
  1343. [dicData setObject:dic forKey:@"test_system_im"];
  1344. [dicData setObject:@"pushTest" forKey:@"act"];
  1345. [dicData setObject:@"games" forKey:@"ctl"];
  1346. [self.httpsManager POSTWithParameters:dicData SuccessBlock:^(NSDictionary *responseJson) {
  1347. NSLog(@"%@",[responseJson toString:@"status"]);
  1348. } FailureBlock:^(NSError *error) {
  1349. }];
  1350. #endif
  1351. }
  1352. //主播调
  1353. - (void)addGameView
  1354. {
  1355. if (_gameId != 4 && !_goldFlowerView)
  1356. {
  1357. _goldFlowerView = [[GoldFlowView alloc] initWithFrame:CGRectMake(0, kScreenH-_goldFlowerViewHeiht ,kScreenW, _goldFlowerViewHeiht) withBetArray:nil withIsHost:YES];
  1358. _goldFlowerView.isArc = _isArc;
  1359. _goldFlowerView.isHost = YES;
  1360. _goldFlowerView.delegate = self;
  1361. [self addSubview:_goldFlowerView];
  1362. [self sendSubviewToBack:_goldFlowerView];
  1363. _goldViewCanNotSee = NO;
  1364. _bottomView.switchGameViewBtn.transform = CGAffineTransformIdentity;
  1365. [self relayoutFrameOfSubViews];
  1366. [self showInPutView];
  1367. }
  1368. else if (_gameId == 4 && !_guessSizeView)
  1369. {
  1370. _guessSizeView = [[NSBundle mainBundle] loadNibNamed:@"GuessSizeView" owner:nil options:nil].lastObject;
  1371. _guessSizeView.frame = CGRectMake(0, kScreenH-kGuessSizeViewHeight, kScreenW, kGuessSizeViewHeight);
  1372. _guessSizeView.isArc = _isArc;
  1373. _guessSizeView.isHost = YES;
  1374. _guessSizeView.delegate = self;
  1375. [_guessSizeView creatLabel];
  1376. [_guessSizeView createButtomView];
  1377. [self addSubview:_guessSizeView];
  1378. [self sendSubviewToBack:_guessSizeView];
  1379. _guessSizeViewCanNotSee = NO;
  1380. _bottomView.switchGameViewBtn.transform = CGAffineTransformIdentity;
  1381. [self relayoutFrameOfSubViews];
  1382. [self showInPutView];
  1383. }
  1384. _bottomView.switchGameViewBtn.hidden = NO;
  1385. _bottomView.switchGameViewBtn.userInteractionEnabled = YES;
  1386. [self changeBeginButtonWithCanBeginNext:NO];
  1387. CGFloat height = _gameId == 4 ? kGuessSizeViewHeight : _goldFlowerViewHeiht;
  1388. _bottomView.heartRect = CGRectMake(kScreenW-kDefaultMargin*2-kMyBtnWidth1*2+5, kScreenH-kDefaultMargin-kMyBtnWidth1+5-height, kMyBtnWidth1-10, kMyBtnWidth1-10);
  1389. [self createGameHistoryView];
  1390. }
  1391. //观众调
  1392. - (void)loadGoldFlowerViewWithBetArray:(NSArray *) betArray withGameID:(NSInteger)gameID
  1393. {
  1394. _gameId = gameID;
  1395. if (_gameId != 4 && !_goldFlowerView)
  1396. {
  1397. _goldFlowerView = [[GoldFlowView alloc] initWithFrame:CGRectMake(0, kScreenH-_goldFlowerViewHeiht ,kScreenW, _goldFlowerViewHeiht) withBetArray:betArray withIsHost:NO];
  1398. _goldFlowerView.isHost = NO;
  1399. _goldFlowerView.delegate = self;
  1400. [self addSubview:_goldFlowerView];
  1401. [self sendSubviewToBack:_goldFlowerView];
  1402. _goldViewCanNotSee = NO;
  1403. _bottomView.switchGameViewBtn.transform = CGAffineTransformIdentity;
  1404. [self relayoutFrameOfSubViews];
  1405. [self showInPutView];
  1406. }
  1407. else if (_gameId == 4 && !_guessSizeView)
  1408. {
  1409. _guessSizeView = [[NSBundle mainBundle] loadNibNamed:@"GuessSizeView" owner:nil options:nil].lastObject;
  1410. _guessSizeView.frame = CGRectMake(0, kScreenH-kGuessSizeViewHeight, kScreenW, kGuessSizeViewHeight);
  1411. _guessSizeView.isHost = NO;
  1412. _guessSizeView.delegate = self;
  1413. _guessSizeView.betOptionArray = betArray;
  1414. [_guessSizeView creatLabel];
  1415. [_guessSizeView createButtomView];
  1416. [self addSubview:_guessSizeView];
  1417. [self sendSubviewToBack:_guessSizeView];
  1418. _guessSizeViewCanNotSee = NO;
  1419. _bottomView.switchGameViewBtn.transform = CGAffineTransformIdentity;
  1420. [self relayoutFrameOfSubViews];
  1421. [self showInPutView];
  1422. }
  1423. _bottomView.switchGameViewBtn.hidden = NO;
  1424. _bottomView.switchGameViewBtn.userInteractionEnabled = YES;
  1425. CGFloat height = gameID == 4 ? kGuessSizeViewHeight : _goldFlowerViewHeiht;
  1426. _bottomView.heartRect = CGRectMake(kScreenW-kDefaultMargin*2-kMyBtnWidth1*2+5, kScreenH-kDefaultMargin-kMyBtnWidth1+5-height, kMyBtnWidth1-10, kMyBtnWidth1-10);
  1427. [self createGameHistoryView];
  1428. }
  1429. #pragma mark -- 创建游戏记录视图和获胜奖励视图
  1430. - (void)createGameHistoryView
  1431. {
  1432. if (!_gamehistoryView)
  1433. {
  1434. _historyBgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
  1435. _historyBgView.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.4];
  1436. _historyBgView.hidden = YES;
  1437. [self addSubview:_historyBgView];
  1438. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(historyViewDown)];
  1439. [_historyBgView addGestureRecognizer:tap];
  1440. //游戏历史视图
  1441. _gamehistoryView = [[GameHistoryView alloc]initWithFrame:CGRectMake((kScreenW - 265)/2, kScreenH, 265, 400) withGameID:[NSString stringWithFormat:@"%ld",(long)_gameId]];
  1442. _gamehistoryView.layer.cornerRadius = 10;
  1443. _gamehistoryView.layer.masksToBounds = YES;
  1444. _gamehistoryView.backgroundColor = [UIColor whiteColor];
  1445. [self addSubview:_gamehistoryView];
  1446. _winBgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
  1447. _winBgView.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.4];
  1448. _winBgView.hidden = YES;
  1449. [self addSubview:_winBgView];
  1450. //游戏获胜视图
  1451. _gameWinView = [GameWinView EditNibFromXib];
  1452. _gameWinView.frame = CGRectMake((kScreenW - 320)/2, kScreenH, 320, 220);
  1453. _gameWinView.winBgView.layer.cornerRadius = 10;
  1454. _gameWinView.winBgView.layer.masksToBounds = YES;
  1455. _gameWinView.gameWinLab.textColor = kAppGrayColor1;
  1456. _gameWinView.delegate = self;
  1457. //字体加粗
  1458. [_gameWinView.gameWinLab setFont:[UIFont fontWithName:@"Helvetica-Bold" size:18]];
  1459. [self addSubview:_gameWinView];
  1460. // UITapGestureRecognizer *gameWinViewTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(gameWinViewDown)];
  1461. // UITapGestureRecognizer *winBgViewTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(gameWinViewDown)];
  1462. //[_gameWinView addGestureRecognizer:gameWinViewTap];
  1463. // [_winBgView addGestureRecognizer:winBgViewTap];
  1464. _bankerBgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
  1465. _bankerBgView.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.4];
  1466. _bankerBgView.hidden = YES;
  1467. [self addSubview:_bankerBgView];
  1468. UITapGestureRecognizer *bankerViewTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapBankerView)];
  1469. [_bankerBgView addGestureRecognizer:bankerViewTap];
  1470. //申请上庄视图
  1471. _bankerView = [ApplyBankerView EditNibFromXib];
  1472. [_bankerView createStyle];
  1473. _bankerView.delegate = self;
  1474. _bankerView.hidden = YES;
  1475. _bankerView.frame = CGRectMake((kScreenW - 255)/2, kScreenH, 255, 195);
  1476. _bankerView.video_id = [NSString stringWithFormat:@"%d",[_liveItem liveAVRoomId]];
  1477. [self addSubview:_bankerView];
  1478. [self createExchangeCoinView];
  1479. }
  1480. else
  1481. {
  1482. [_gamehistoryView changePositionWithGameID:[NSString stringWithFormat:@"%ld",(long)_gameId]];
  1483. }
  1484. }
  1485. #pragma mark 创建兑换视图
  1486. - (void)createExchangeCoinView
  1487. {
  1488. if (!_exchangeView)
  1489. {
  1490. _exchangeView = [ExchangeCoinView EditNibFromXib];
  1491. _exchangeView.exchangeType = 1;
  1492. _exchangeView.delegate = self;
  1493. _exchangeView.frame = CGRectMake((kScreenW - 300)/2, kScreenH, 300, 230);
  1494. _exchangeView.hidden = YES;
  1495. [_exchangeView createSomething];
  1496. [self addSubview:_exchangeView];
  1497. }
  1498. }
  1499. #pragma mark 弹出游戏历史视图
  1500. - (void)displayGameHistory
  1501. {
  1502. [self bringSubviewToFront:_historyBgView];
  1503. [self bringSubviewToFront:_gamehistoryView];
  1504. FWWeakify(self)
  1505. [UIView animateWithDuration:1.0 delay:0 usingSpringWithDamping:0.95 initialSpringVelocity:10 options: UIViewAnimationOptionCurveLinear animations:^{
  1506. FWStrongify(self)
  1507. self.historyBgView.hidden = NO;
  1508. self.gamehistoryView.frame = CGRectMake((kScreenW - 265)/2, (kScreenH - 400)/2 , 265, 400);
  1509. [self.gamehistoryView loadDataWithGameID:[NSString stringWithFormat:@"%ld",(long)self.gameId] withPodcastID:[[_liveItem liveHost] imUserId] withPage:@"50"];//加载游戏记录列表
  1510. } completion:^(BOOL finished) {
  1511. }];
  1512. }
  1513. #pragma mark 弹出兑换视图
  1514. - (void)displayExchangeView
  1515. {
  1516. [self changeMoney];
  1517. [_exchangeView obtainCoinProportion];
  1518. _bankerBgView.hidden = NO;
  1519. _exchangeView.hidden = NO;
  1520. [self bringSubviewToFront:_bankerBgView];
  1521. [self bringSubviewToFront:_exchangeView];
  1522. [_exchangeView.diamondLeftTextfield becomeFirstResponder];
  1523. FWWeakify(self)
  1524. [UIView animateWithDuration:0.3 animations:^{
  1525. FWStrongify(self)
  1526. self.exchangeView.frame = CGRectMake((kScreenW - 300)/2, (kScreenH - 350)/2, 300, 230);
  1527. }];
  1528. }
  1529. #pragma mark 弹出游戏获胜视图
  1530. - (void)displayGameWinWithGainModel:(GameGainModel *)gainModel
  1531. {
  1532. if (gainModel) {
  1533. _gameWinView.model = gainModel;
  1534. }
  1535. NSInteger giftCount = gainModel.gift_list.count;
  1536. _gameWinView.giftViewHeight.constant = giftCount > 0 ? 190 : 0;
  1537. _gameWinView.height = giftCount > 0 ? 410 : 220;
  1538. _gameWinView.model = gainModel;
  1539. [self bringSubviewToFront:_winBgView];
  1540. [self bringSubviewToFront:_gameWinView];
  1541. FWWeakify(self)
  1542. [UIView animateWithDuration:1.0 delay:0 usingSpringWithDamping:0.95 initialSpringVelocity:10 options: UIViewAnimationOptionCurveLinear animations:^{
  1543. FWStrongify(self)
  1544. self.winBgView.hidden = NO;
  1545. if (giftCount == 0) {
  1546. self.gameWinView.frame = CGRectMake((kScreenW - 320)/2, (kScreenH - 220)/2, 320, 220);
  1547. self.gameWinView.giftView.hidden = YES;
  1548. }
  1549. else
  1550. {
  1551. self.gameWinView.frame = CGRectMake((kScreenW - 320)/2, (kScreenH - 410)/2, 320, 410);
  1552. self.gameWinView.giftView.hidden = NO;
  1553. }
  1554. if (self.BuguLive.appModel.open_diamond_game_module == 1)
  1555. {
  1556. self.gameWinView.gameWinLab.text = [NSString stringWithFormat:@"%@%@",gainModel.gain,self.BuguLive.appModel.diamond_name];
  1557. }
  1558. else
  1559. {
  1560. self.gameWinView.gameWinLab.text = [NSString stringWithFormat:ASLocalizedString(@"%@游戏币"),gainModel.gain];
  1561. }
  1562. //先获取gameWinLab在gameWinView上的相对位置
  1563. CGPoint point1 = [_gameWinView.winBgView convertPoint:_gameWinView.gameWinLab.center toView:_gameWinView];
  1564. //再获取point1在self上的位置
  1565. _goldPoint = [_gameWinView convertPoint:point1 toView:self];
  1566. _coinPoint = CGPointMake(17.5, kScreenH - 20);
  1567. } completion:^(BOOL finished) {
  1568. FWStrongify(self)
  1569. //延迟一秒执行
  1570. if (giftCount == 0) {
  1571. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1572. if (self.winBgView.hidden == NO && self.winBgView)
  1573. {
  1574. [self manyCoinDown];
  1575. }
  1576. });
  1577. }
  1578. }];
  1579. }
  1580. #pragma mark 弹出申请上庄视图
  1581. - (void)displayBankerView
  1582. {
  1583. _bankerBgView.hidden = NO;
  1584. _bankerView.hidden = NO;
  1585. [self bringSubviewToFront:_bankerBgView];
  1586. [self bringSubviewToFront:_bankerView];
  1587. [_bankerView.coinTextfield becomeFirstResponder];
  1588. FWWeakify(self)
  1589. [UIView animateWithDuration:0.3 animations:^{
  1590. FWStrongify(self)
  1591. self.bankerView.frame = CGRectMake((kScreenW - 255)/2, (kScreenH - 280)/2, 255, 195); //中心195
  1592. }];
  1593. }
  1594. #pragma mark 选择上庄视图消失
  1595. - (void)selectBankerViewDown
  1596. {
  1597. FWWeakify(self)
  1598. [UIView animateWithDuration:0.3 animations:^{
  1599. FWStrongify(self)
  1600. self.selectctBankerView.frame = CGRectMake((kScreenW - 280)/2, kScreenH, 280, 290);
  1601. }];
  1602. }
  1603. #pragma mark 游戏历史视图下落
  1604. - (void)historyViewDown
  1605. {
  1606. FWWeakify(self)
  1607. [UIView animateWithDuration:0.3 animations:^{
  1608. FWStrongify(self)
  1609. self.historyBgView.hidden = YES;
  1610. self.gamehistoryView.frame = CGRectMake((kScreenW - 265)/2, kScreenH , 265, 400);
  1611. }];
  1612. }
  1613. #pragma mark 游戏获胜视图下落
  1614. - (void)gameWinViewDown
  1615. {
  1616. FWWeakify(self)
  1617. [UIView animateWithDuration:0.3 animations:^{
  1618. FWStrongify(self)
  1619. self.winBgView.hidden = YES;
  1620. self.gameWinView.frame = CGRectMake((kScreenW - 320)/2, kScreenH, 320, 220);
  1621. self.gameWinView.giftView.hidden = YES;
  1622. }];
  1623. }
  1624. - (void)tapBankerView
  1625. {
  1626. [self bankerViewDown];
  1627. }
  1628. #pragma mark 申请上庄视图下落
  1629. - (void)bankerViewDown
  1630. {
  1631. [_bankerView.coinTextfield resignFirstResponder];
  1632. [_exchangeView.diamondLeftTextfield resignFirstResponder];
  1633. _bankerView.coinTextfield.text = nil;
  1634. _exchangeView.diamondLeftTextfield.text = nil;
  1635. FWWeakify(self)
  1636. [UIView animateWithDuration:0.3 animations:^{
  1637. FWStrongify(self)
  1638. self.bankerView.frame = CGRectMake((kScreenW - 255)/2, kScreenH, 255, 195);
  1639. self.exchangeView.frame = CGRectMake((kScreenW - 300)/2, (kScreenH - 350)/2, 300, 230);
  1640. }completion:^(BOOL finished) {
  1641. FWStrongify(self)
  1642. self.bankerBgView.hidden = YES;
  1643. self.exchangeView.hidden = YES;
  1644. self.bankerView.hidden = YES;
  1645. }];
  1646. }
  1647. - (void)hiddenGrabBankerBtnWithCoin:(NSString *)coin
  1648. {
  1649. // _bottomView.grabBankerBtn.hidden = YES;
  1650. // _goldFlowerView.coinView.personCoinLab.text = coin;
  1651. // [_goldFlowerView judgmentBetView:[coin integerValue]];
  1652. }
  1653. #pragma mark 移除游戏历史和游戏获胜视图
  1654. - (void)removeGameHistoryAndGameWin
  1655. {
  1656. [_gamehistoryView removeFromSuperview];
  1657. [_historyBgView removeFromSuperview];
  1658. [_winBgView removeFromSuperview];
  1659. [_gameWinView removeFromSuperview];
  1660. [_selectctBankerView removeFromSuperview];
  1661. [_bankerBgView removeFromSuperview];
  1662. [_bankerView removeFromSuperview];
  1663. [_exchangeView removeFromSuperview];
  1664. _exchangeView = nil;
  1665. _gamehistoryView = nil;
  1666. }
  1667. #pragma mark 点击“充值”的代理
  1668. - (void)clickRecharge
  1669. {
  1670. if (_serveceDelegate && [_serveceDelegate respondsToSelector:@selector(rechargeView:)])
  1671. {
  1672. [_serveceDelegate rechargeView:self];
  1673. }
  1674. }
  1675. #pragma mark 兑换视图消失
  1676. - (void)exchangeViewDownWithExchangeCoinView:(ExchangeCoinView *)exchangeCoinView
  1677. {
  1678. if (_exchangeView == exchangeCoinView)
  1679. {
  1680. FWWeakify(self)
  1681. [UIView animateWithDuration:0.3 animations:^{
  1682. FWStrongify(self)
  1683. [self.exchangeView.diamondLeftTextfield resignFirstResponder];
  1684. self.exchangeView.diamondLeftTextfield.text = nil;
  1685. self.exchangeView.coinLabel.text = ASLocalizedString(@"0游戏币");
  1686. self.exchangeView.frame = CGRectMake((kScreenW - 300)/2, kScreenH, 300, 230);
  1687. } completion:^(BOOL finished) {
  1688. FWStrongify(self)
  1689. self.bankerBgView.hidden = YES;
  1690. self.exchangeView.hidden = YES;
  1691. }];
  1692. }
  1693. }
  1694. #pragma mark 游戏获胜金币下落
  1695. - (void)manyCoinDown
  1696. {
  1697. FWWeakify(self)
  1698. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1699. FWStrongify(self)
  1700. [self gameWinViewDown];
  1701. });
  1702. }
  1703. #pragma mark 庄家是否隐藏押注按钮
  1704. - (void)hiddenBetView:(BOOL)hidden
  1705. {
  1706. [_goldFlowerView.betViewArray enumerateObjectsUsingBlock:^(BetView * betView, NSUInteger idx, BOOL * _Nonnull stop){
  1707. if (idx < _goldFlowerView.betViewArray.count - 1)
  1708. {
  1709. betView.hidden = hidden;
  1710. }
  1711. }];
  1712. }
  1713. #pragma mark 金币移动动画(传入起始位置和终点位置)
  1714. - (void)coinMoveWithEnd:(CGPoint)end withBegin:(CGPoint)begin
  1715. {
  1716. UIImageView *breathImg = [[UIImageView alloc]init];
  1717. breathImg.width = 25;
  1718. breathImg.height = 25;
  1719. breathImg.center = begin;
  1720. breathImg.image = [UIImage imageNamed:@"coin"];
  1721. [self addSubview:breathImg];
  1722. [_coinImgArray addObject:breathImg];
  1723. [breathImg.layer addAnimation:[CAAnimation coinMoveAntimationWithBegin:breathImg.center
  1724. WithEnd:end
  1725. andMoveTime:kMoveAnimationDuration
  1726. andNarrowTime:kNarrowAnimationDuration
  1727. andNarrowFromValue:1.0f
  1728. andNarrowToValue:0.0f]
  1729. forKey:@"coinDown"];
  1730. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(kCoinMoveAnimationDuration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1731. if (breathImg)
  1732. {
  1733. [breathImg removeFromSuperview];
  1734. }
  1735. });
  1736. }
  1737. #pragma mark 主播下庄请求
  1738. - (void)closeBanker
  1739. {
  1740. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  1741. [mDict setObject:@"games" forKey:@"ctl"];
  1742. [mDict setObject:@"stopBanker" forKey:@"act"];
  1743. [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
  1744. if ([responseJson toInt:@"status"] ==1)
  1745. {
  1746. }
  1747. } FailureBlock:^(NSError *error) {
  1748. }];
  1749. }
  1750. #pragma mark 主播上庄请求
  1751. - (void)beginBanker
  1752. {
  1753. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  1754. [mDict setObject:@"games" forKey:@"ctl"];
  1755. [mDict setObject:@"openBanker" forKey:@"act"];
  1756. [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
  1757. if ([responseJson toInt:@"status"] ==1)
  1758. {
  1759. }
  1760. } FailureBlock:^(NSError *error) {
  1761. }];
  1762. }
  1763. #pragma mark 获取上庄玩家底金
  1764. - (void)obtainBankerCoin
  1765. {
  1766. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  1767. [mDict setObject:@"games" forKey:@"ctl"];
  1768. [mDict setObject:@"getBankerCoin" forKey:@"act"];
  1769. [mDict setObject:_roomIDStr forKey:@"video_id"];
  1770. FWWeakify(self)
  1771. [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
  1772. FWStrongify(self)
  1773. if ([responseJson toInt:@"status"] == 1)
  1774. {
  1775. GameBankerModel *model = [GameBankerModel mj_objectWithKeyValues:[responseJson objectForKey:@"data"]];
  1776. self.gameBankerView.bankerDesLabel.text = [NSString stringWithFormat:ASLocalizedString(@"剩余底金%@"),model.coin];
  1777. }
  1778. } FailureBlock:^(NSError *error) {
  1779. }];
  1780. }
  1781. #pragma mark 打开或关闭游戏视图
  1782. - (void)closeOrOpenGameView
  1783. {
  1784. if (_goldViewCanNotSee == NO && _goldFlowerView)
  1785. {
  1786. _goldViewCanNotSee = YES;
  1787. FWWeakify(self)
  1788. [UIView animateWithDuration:0.2 animations:^{
  1789. FWStrongify(self)
  1790. self.goldFlowerView.frame = CGRectMake(0, kScreenH, kScreenW, _goldFlowerViewHeiht);
  1791. self.bottomView.heartRect = CGRectMake(kScreenW-kDefaultMargin*2-kMyBtnWidth1*2+5, kScreenH-kDefaultMargin-kMyBtnWidth1+5, kMyBtnWidth1-10, kMyBtnWidth1-10);
  1792. [self relayoutFrameOfSubViews];
  1793. self.bottomView.switchGameViewBtn.transform = CGAffineTransformMakeRotation(M_PI);
  1794. } completion:^(BOOL finished) {
  1795. }];
  1796. }
  1797. else if (_goldViewCanNotSee == YES && _goldFlowerView)
  1798. {
  1799. //判断是否正在显示礼物列表
  1800. if (_giftView.isHidden == NO)
  1801. {
  1802. _bottomView.hidden = NO;
  1803. _msgView.hidden = NO;
  1804. // _giftView.frame = CGRectMake(0, self.frame.size.height, _giftView.frame.size.width, _giftView.frame.size.height);
  1805. // _giftView.hidden = YES;
  1806. [_giftView hide];
  1807. }
  1808. _goldViewCanNotSee = NO;
  1809. FWWeakify(self)
  1810. [UIView animateWithDuration:0.2 animations:^{
  1811. FWStrongify(self)
  1812. self.goldFlowerView.frame = CGRectMake(0, kScreenH-_goldFlowerViewHeiht, kScreenW, _goldFlowerViewHeiht);
  1813. self.bottomView.heartRect = CGRectMake(kScreenW-kDefaultMargin*2-kMyBtnWidth1*2+5, kScreenH-kDefaultMargin-kMyBtnWidth1+5-_goldFlowerViewHeiht, kMyBtnWidth1-10, kMyBtnWidth1-10);
  1814. [self relayoutFrameOfSubViews];
  1815. self.bottomView.switchGameViewBtn.transform = CGAffineTransformIdentity;
  1816. } completion:^(BOOL finished) {
  1817. }];
  1818. }
  1819. else if (_guessSizeViewCanNotSee == NO && _guessSizeView)
  1820. {
  1821. _guessSizeViewCanNotSee = YES;
  1822. [UIView animateWithDuration:0.2 animations:^{
  1823. _guessSizeView.frame = CGRectMake(0, kScreenH, kScreenW, kGuessSizeViewHeight);
  1824. _bottomView.heartRect = CGRectMake(kScreenW-kDefaultMargin*2-kMyBtnWidth1*2+5, kScreenH-kDefaultMargin-kMyBtnWidth1+5, kMyBtnWidth1-10, kMyBtnWidth1-10);
  1825. [self relayoutFrameOfSubViews];
  1826. _bottomView.switchGameViewBtn.transform = CGAffineTransformMakeRotation(M_PI);
  1827. } completion:^(BOOL finished) {
  1828. }];
  1829. }
  1830. else if (_guessSizeViewCanNotSee == YES && _guessSizeView)
  1831. {
  1832. //判断是否正在显示礼物列表
  1833. if (_giftView.isHidden == NO)
  1834. {
  1835. _bottomView.hidden = NO;
  1836. _msgView.hidden = NO;
  1837. // _giftView.frame = CGRectMake(0, self.frame.size.height, _giftView.frame.size.width, _giftView.frame.size.height);
  1838. // _giftView.hidden = YES;
  1839. [_giftView hide];
  1840. }
  1841. _guessSizeViewCanNotSee = NO;
  1842. [UIView animateWithDuration:0.2 animations:^{
  1843. _guessSizeView.frame = CGRectMake(0, kScreenH-kGuessSizeViewHeight, kScreenW, kGuessSizeViewHeight);
  1844. _bottomView.heartRect = CGRectMake(kScreenW-kDefaultMargin*2-kMyBtnWidth1*2+5, kScreenH-kDefaultMargin-kMyBtnWidth1+5-kGuessSizeViewHeight, kMyBtnWidth1-10, kMyBtnWidth1-10);
  1845. [self relayoutFrameOfSubViews];
  1846. _bottomView.switchGameViewBtn.transform = CGAffineTransformIdentity;
  1847. } completion:^(BOOL finished) {
  1848. }];
  1849. }
  1850. }
  1851. #pragma mark 更新游戏显示的coin
  1852. - (void)updateCoinLable:(long)coin
  1853. {
  1854. if (self.BuguLive.appModel.open_diamond_game_module == 1)
  1855. {
  1856. // 更新游戏余额
  1857. if (self.goldFlowerView)
  1858. {
  1859. self.goldFlowerView.coinView.gameRechargeView.accountLabel.text =[NSString stringWithFormat:@"%ld",(long)coin];
  1860. }
  1861. else if (_guessSizeView)
  1862. {
  1863. self.guessSizeView.gameRechargeView.accountLabel.text = [NSString stringWithFormat:@"%ld",(long)coin];
  1864. }
  1865. }
  1866. }
  1867. #pragma mark - ----------------------- 购物相关 -----------------------
  1868. - (void)clickStarShopButton
  1869. {
  1870. _bottomView.hidden = NO;
  1871. _closeLiveBtn.hidden = NO;
  1872. if (!_hadClickStarShop)
  1873. {
  1874. if (_serveceDelegate && [_serveceDelegate respondsToSelector:@selector(clickStarShop:)])
  1875. {
  1876. [_serveceDelegate clickStarShop:self];
  1877. }
  1878. _hadClickStarShop = YES;
  1879. FWWeakify(self)
  1880. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1881. FWStrongify(self)
  1882. self.hadClickStarShop = NO;
  1883. });
  1884. }
  1885. }
  1886. - (MoreToolsView *)moreToolsView
  1887. {
  1888. if (_moreToolsView == nil)
  1889. {
  1890. _moreToolsView = [[MoreToolsView alloc] initWithFrame:CGRectMake(kDefaultMargin, kScreenH, kScreenW-2*kDefaultMargin, kScreenH)];
  1891. _moreToolsView.delegate = self;
  1892. _moreToolsView.hidden = YES;
  1893. [self addSubview:_moreToolsView];
  1894. }
  1895. return _moreToolsView;
  1896. }
  1897. - (void)clickMoreToolsView:(MoreToolsView *)moreToolsView andToolsModel:(ToolsModel *)model
  1898. {
  1899. self.toolsTitle = model.title;
  1900. if ([model.title isEqual:ASLocalizedString(@"星店")])
  1901. {
  1902. [self clickStarShopButton];
  1903. }
  1904. else if ([model.title isEqual:ASLocalizedString(@"小店")])
  1905. {
  1906. if (_serveceDelegate && [_serveceDelegate respondsToSelector:@selector(clickMyShop:)])
  1907. {
  1908. [_serveceDelegate clickMyShop:self];
  1909. }
  1910. }
  1911. }
  1912. - (void)clickCancleWithMoreToolsView:(MoreToolsView *)moreToolsView
  1913. {
  1914. }
  1915. #pragma mark - ----------------------- 游戏推送相关处理 -----------------------
  1916. //游戏结束推送
  1917. - (void)gameOverWithCustomMessageModel:(CustomMessageModel *)customMessageModel
  1918. {
  1919. //如果接收到的推送时间戳小于当前时间戳则该游戏推送不执行
  1920. if ([customMessageModel.timestamp doubleValue] < _timestamp)
  1921. {
  1922. return;
  1923. }
  1924. _timestamp = [customMessageModel.timestamp doubleValue];
  1925. if (_isHost || [_liveItem liveType] == 0)
  1926. {
  1927. _bottomView.beginGameBtn.hidden = YES;
  1928. }
  1929. _bottomView.switchGameViewBtn.hidden = YES;
  1930. _bottomView.switchBankerBtn.hidden = YES;
  1931. _bottomView.grabBankerBtn.hidden = YES;
  1932. _bottomView.switchGameViewBtn.userInteractionEnabled = NO;
  1933. _bottomView.heartRect = CGRectMake(kScreenW-kDefaultMargin*2-kMyBtnWidth1*2+5, kScreenH-kDefaultMargin-kMyBtnWidth1+5, kMyBtnWidth1-10, kMyBtnWidth1-10);
  1934. _bottomView.bankMessage = 0;
  1935. _bottomView.bjsbadge.badgeText = nil;
  1936. [_goldFlowerView closeGameAboutTimer];
  1937. [_goldFlowerView removeFromSuperview];
  1938. [_guessSizeView disClockTime];
  1939. [_guessSizeView removeFromSuperview];
  1940. [self removeGameHistoryAndGameWin];
  1941. _isArc = NO;
  1942. // _goldFlowerView.isArc = NO;
  1943. _goldFlowerView = nil;
  1944. // _guessSizeView.isArc = NO;
  1945. _guessSizeView = nil;
  1946. [self relayoutFrameOfSubViews];
  1947. _game_log_id = 0;
  1948. [self.bankerListArr removeAllObjects];
  1949. self.gameBankerView.hidden = YES;
  1950. [self.selectctBankerView removeFromSuperview];
  1951. _selectctBankerView = nil;
  1952. [self changePayViewFrame];
  1953. [self showInPutView];
  1954. }
  1955. //游戏总的推送
  1956. - (void)gameAllMessageWithCustomMessageModel:(CustomMessageModel *)customMessageModel
  1957. {
  1958. //NSInteger actionInt = [customMessageModel.game_action integerValue];
  1959. //游戏操作,不同游戏略有不同:开始:1;下注:2;停止:3;结算:4;翻牌:5;
  1960. if (![self isShouldPlayer:customMessageModel.user_id] && [customMessageModel.user_id integerValue] != 0)
  1961. {
  1962. return;
  1963. }
  1964. if (_shouldReloadGame == YES )
  1965. {
  1966. if ([customMessageModel.game_action isEqualToString:@"1"])
  1967. {
  1968. _coinWindowNumber = 0;
  1969. }
  1970. else
  1971. {
  1972. [self.gameArray addObject:customMessageModel];
  1973. }
  1974. return;
  1975. }
  1976. //如果接收到的推送时间戳小于当前时间戳则该游戏推送不执行
  1977. if ([customMessageModel.timestamp doubleValue] < _timestamp)
  1978. {
  1979. return;
  1980. }
  1981. _timestamp = [customMessageModel.timestamp doubleValue];
  1982. if ([customMessageModel.game_log_id integerValue] > _game_log_id)
  1983. {
  1984. for (CustomMessageModel * model in self.gameDataArray)
  1985. {
  1986. //已经开始下一局游戏
  1987. if ([model.game_action integerValue] == 4 && [customMessageModel.game_action integerValue] == 1)
  1988. {
  1989. _hadBeginNext = YES;
  1990. }
  1991. }
  1992. [self.gameDataArray removeAllObjects];
  1993. _canNotLoadData = NO;
  1994. if (_goldFlowerView)
  1995. {
  1996. [_goldFlowerView.userBetArr removeAllObjects];
  1997. [_goldFlowerView.betArr removeAllObjects];
  1998. }
  1999. else if (_guessSizeView)
  2000. {
  2001. [_guessSizeView.userBetArr removeAllObjects];
  2002. [_guessSizeView.betArr removeAllObjects];
  2003. }
  2004. }
  2005. if ([customMessageModel.game_log_id integerValue] >= _game_log_id)
  2006. {
  2007. for (CustomMessageModel * model in self.gameDataArray)
  2008. {
  2009. if ([model isEqual:customMessageModel] )
  2010. {
  2011. return;
  2012. }
  2013. if (![customMessageModel.game_action isEqualToString:@"2"])
  2014. {
  2015. if ([model.game_action isEqual:customMessageModel.game_action] && [model.game_log_id isEqual:customMessageModel.game_log_id])
  2016. {
  2017. return;
  2018. }
  2019. }
  2020. }
  2021. [self.gameDataArray addObject:customMessageModel];
  2022. _game_log_id = [customMessageModel.game_log_id integerValue];
  2023. _gameAction = [customMessageModel.game_action intValue];
  2024. _gameId = [customMessageModel.game_id integerValue];
  2025. if (_goldFlowerView)
  2026. {
  2027. _goldFlowerView.gameAction = _gameAction;
  2028. }
  2029. if ([customMessageModel.game_action isEqualToString:@"1"])
  2030. {
  2031. _banker_status = [customMessageModel.banker_status integerValue];
  2032. if (_goldFlowerView.showPokerTimer)
  2033. {
  2034. [_goldFlowerView.showPokerTimer invalidate];
  2035. _goldFlowerView.showPokerTimer = nil;
  2036. }
  2037. if (_guessSizeView.showDiceTimer)
  2038. {
  2039. [_guessSizeView.showDiceTimer invalidate];
  2040. _guessSizeView.showDiceTimer = nil;
  2041. }
  2042. _bottomView.bankMessage = 0;
  2043. _bottomView.bjsbadge.badgeText = nil;
  2044. _coinWindowNumber = 0;
  2045. if (_isHost || [_liveItem liveType] == 0)
  2046. {
  2047. [self addGameView];
  2048. [self changeBeginButtonWithCanBeginNext:NO];
  2049. }
  2050. else
  2051. {
  2052. [self loadGoldFlowerViewWithBetArray:customMessageModel.bet_option withGameID:[customMessageModel.game_id integerValue]];
  2053. [self hideGameView];
  2054. }
  2055. _bottomView.switchGameViewBtn.hidden = NO;
  2056. if (_goldFlowerView)
  2057. {
  2058. _goldFlowerView.betOptionArray = customMessageModel.bet_option;
  2059. _goldFlowerView.game_log_id = customMessageModel.game_log_id;
  2060. //_game_log_id = [customMessageModel.game_log_id integerValue];
  2061. [self disAboutClick];
  2062. [_goldFlowerView overPokerKJTime:[customMessageModel.time intValue]];
  2063. [_goldFlowerView gameToPrepareTypeGoldenFlowerOrBull:customMessageModel.game_id card:customMessageModel.game_data.public_cards];
  2064. [_goldFlowerView loadOptionArray:customMessageModel.option];
  2065. }
  2066. else if (_guessSizeView)
  2067. {
  2068. _guessSizeView.betOptionArray = customMessageModel.bet_option;
  2069. _guessSizeView.game_log_id = customMessageModel.game_log_id;
  2070. [_guessSizeView disClockTime];
  2071. [_guessSizeView showTime:[customMessageModel.time intValue]];
  2072. [_guessSizeView loadOptionArray:customMessageModel.option];
  2073. _guessSizeView.canBet = YES;
  2074. }
  2075. [self loadBankerDataWithModel:customMessageModel withHadLeft:_shouldReloadGame];
  2076. _bottomView.switchBankerBtn.hidden = YES;
  2077. }
  2078. else if ([customMessageModel.game_action isEqualToString:@"2"])
  2079. {
  2080. NSArray * betArray = customMessageModel.game_data.bet;
  2081. if (_goldFlowerView)
  2082. {
  2083. [_goldFlowerView loadBetDataWithBetArray:betArray andUserBetArray:nil];
  2084. }
  2085. else if(_guessSizeView)
  2086. {
  2087. [_guessSizeView loadBetDataWithBetArray:betArray andUserBetArray:nil];
  2088. }
  2089. }
  2090. else if ([customMessageModel.game_action isEqualToString:@"3"])
  2091. {
  2092. if (_isHost || [_liveItem liveType] == 0)
  2093. {
  2094. [self changeBeginButtonWithCanBeginNext:YES];
  2095. }
  2096. _bottomView.switchGameViewBtn.hidden = YES;
  2097. _bottomView.switchGameViewBtn.userInteractionEnabled = NO;
  2098. [_goldFlowerView closeGameAboutTimer];
  2099. [_goldFlowerView removeFromSuperview];
  2100. [_guessSizeView removeFromSuperview];
  2101. _guessSizeView = nil;
  2102. [self removeGameHistoryAndGameWin];
  2103. _goldFlowerView = nil;
  2104. [self relayoutFrameOfSubViews];
  2105. _game_log_id = 0;
  2106. }
  2107. else if ([customMessageModel.game_action isEqualToString:@"4"])
  2108. {
  2109. _banker_status = [customMessageModel.banker_status integerValue];
  2110. NSArray * pokerArray = customMessageModel.game_data.cards_data;
  2111. NSInteger result = [customMessageModel.game_data.win integerValue];
  2112. NSArray * dicArr = customMessageModel.game_data.dices;
  2113. if (_gameId != 4)
  2114. {
  2115. for (id dic in pokerArray)
  2116. {
  2117. if (![dic isKindOfClass:[NSDictionary class]])
  2118. {
  2119. return;
  2120. }
  2121. }
  2122. if (pokerArray.count==3)
  2123. {
  2124. [self disAboutClick];
  2125. // [_goldFlowerView endAnmination];
  2126. [_goldFlowerView whetherBet:NO];
  2127. if (_goldFlowerView.smallArray.count == 0)
  2128. {
  2129. [_goldFlowerView creatPokerhiden:NO gameType:customMessageModel.game_id card:customMessageModel.game_data.public_cards];//记载发牌视图
  2130. [_goldFlowerView creatBetAmount:NO type:customMessageModel.game_id];//加载下注视图
  2131. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  2132. [_goldFlowerView startOpenCard:pokerArray[0] between:pokerArray[1] rigth:pokerArray[2] andResult:result gameId:customMessageModel.game_id]; });
  2133. }
  2134. else
  2135. {
  2136. [_goldFlowerView startOpenCard:pokerArray[0] between:pokerArray[1] rigth:pokerArray[2] andResult:result gameId:customMessageModel.game_id];
  2137. }
  2138. }
  2139. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  2140. //用户更新余额
  2141. [_goldFlowerView updateCoinWithID:customMessageModel.game_log_id];
  2142. [self gameEndAction];
  2143. // if (_isArc && kSupportArcGame) {
  2144. // [self onBottomViewClickMenus:_bottomView fromButton:_bottomView.beginGameBtn];
  2145. // }
  2146. });
  2147. }
  2148. else
  2149. {
  2150. _guessSizeView.canBet = NO;
  2151. [_guessSizeView disClockTime];
  2152. [_guessSizeView loadDiceWithDicesArr:dicArr andResultWinPostion:result];
  2153. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  2154. //用户更新余额
  2155. [_guessSizeView updateCoinWithID:customMessageModel.game_log_id];
  2156. [self gameEndAction];
  2157. });
  2158. }
  2159. _bottomView.switchBankerBtn.hidden = NO;
  2160. [self loadBankerDataWithModel:customMessageModel withHadLeft:_shouldReloadGame];
  2161. }
  2162. else if ([customMessageModel.game_action isEqualToString:@"5"])
  2163. {
  2164. }
  2165. else if ([customMessageModel.game_action isEqualToString:@"6"])
  2166. {
  2167. if (_sureOnceGame)
  2168. {
  2169. return;
  2170. }
  2171. if (_liveGameModel)
  2172. {
  2173. if ([customMessageModel.game_log_id isEqual:_liveGameModel.game_log_id])
  2174. {
  2175. //进入此判断说明先接收到了post请求中的数据返回后接收到推送的数据
  2176. _sureOnceGame = YES;
  2177. return;
  2178. }
  2179. }
  2180. //观众,主播调用进入直播间获取游戏数据的接口发送请求后收到的推送实现的方法
  2181. [self intoLiveRoomWithCustomMessageModel:customMessageModel];
  2182. }
  2183. }
  2184. }
  2185. - (void)gameEndAction
  2186. {
  2187. if (_gameBankerView.hidden == NO)
  2188. {
  2189. [self obtainBankerCoin];
  2190. }
  2191. if (_isHost || [_liveItem liveType] == 0)
  2192. {
  2193. if (_gameAction == 4)
  2194. {
  2195. [self changeBeginButtonWithCanBeginNext:YES];
  2196. }
  2197. }
  2198. }
  2199. - (void)showInPutView
  2200. {
  2201. if ([_liveInputView isInputViewActive])
  2202. {
  2203. [_liveInputView resignFirstResponder];
  2204. // 显示消息输入
  2205. _bankerViewCanSee = NO;
  2206. [_liveInputView becomeFirstResponder];
  2207. _liveInputView.hidden = NO;
  2208. _bottomView.hidden = YES;
  2209. }
  2210. }
  2211. - (BOOL)isShouldPlayer:(id) user
  2212. {
  2213. return [[IMAPlatform sharedInstance].host isCurrentHost:user];
  2214. }
  2215. //观众,主播调用进入直播间获取游戏数据的接口发送请求后收到的推送实现的方法
  2216. - (void)intoLiveRoomWithCustomMessageModel:(CustomMessageModel *)customMessageModel
  2217. {
  2218. if (![self isShouldPlayer:customMessageModel.user_id] && [customMessageModel.user_id integerValue] != 0)
  2219. {
  2220. return;
  2221. }
  2222. if (_goldFlowerView.showPokerTimer)
  2223. {
  2224. [_goldFlowerView.showPokerTimer invalidate];
  2225. _goldFlowerView.showPokerTimer = nil;
  2226. }
  2227. [_goldFlowerView removeFromSuperview];
  2228. _goldFlowerView = nil;
  2229. if (_guessSizeView.showDiceTimer)
  2230. {
  2231. [_guessSizeView.showDiceTimer invalidate];
  2232. _guessSizeView.showDiceTimer = nil;
  2233. }
  2234. [_guessSizeView removeFromSuperview];
  2235. _guessSizeView = nil;
  2236. NSInteger gameId = [customMessageModel.game_id integerValue];
  2237. _isArc = customMessageModel.auto_start == 1 ? YES : NO;
  2238. if(gameId != 0)
  2239. {
  2240. _gameId = [customMessageModel.game_id integerValue];
  2241. if(_isHost || [_liveItem liveType] == 0)
  2242. {
  2243. [self addGameView];
  2244. }
  2245. else if([_liveItem liveType] != 1)
  2246. {
  2247. [self loadGoldFlowerViewWithBetArray:customMessageModel.bet_option withGameID:gameId];
  2248. }
  2249. [self hideGameView];
  2250. if (_goldFlowerView) {
  2251. _goldFlowerView.game_log_id = customMessageModel.game_log_id;
  2252. // _goldFlowerView.betOptionArray = dic[@"bet_option"];
  2253. _goldFlowerView.betOptionArray = customMessageModel.bet_option;
  2254. [self disAboutClick];
  2255. [_goldFlowerView creatPokerhiden:NO gameType:customMessageModel.game_id card:customMessageModel.game_data.public_cards];//记载发牌视图
  2256. [_goldFlowerView creatBetAmount:NO type:customMessageModel.game_id];//加载下注视图
  2257. //倍率
  2258. [_goldFlowerView loadOptionArray:customMessageModel.option];
  2259. }
  2260. else if (_guessSizeView)
  2261. {
  2262. _guessSizeView.game_log_id = customMessageModel.game_log_id;
  2263. _guessSizeView.betOptionArray = customMessageModel.bet_option;
  2264. [_guessSizeView disClockTime];
  2265. [_guessSizeView loadOptionArray:customMessageModel.option];
  2266. }
  2267. }
  2268. if ([customMessageModel.game_status integerValue] == 1)// 游戏状态,1:游戏开始,2:游戏结束
  2269. {
  2270. _bottomView.grabBankerBtn.hidden = YES;
  2271. if (_goldFlowerView)
  2272. {
  2273. if ([_liveItem liveType] == 3 && !_isHost)
  2274. {
  2275. [_goldFlowerView whetherBet:YES];
  2276. }
  2277. else if ([_liveItem liveType] == 2)
  2278. {
  2279. [_goldFlowerView whetherBet:YES];
  2280. }
  2281. [_goldFlowerView timeCountDown:[customMessageModel.time intValue]];//开始倒计时
  2282. //加载更新下注的数据
  2283. [_goldFlowerView loadBetDataWithBetArray:customMessageModel.game_data.bet andUserBetArray:customMessageModel.game_data.user_bet];
  2284. }
  2285. else if (_guessSizeView)
  2286. {
  2287. _guessSizeView.canBet = YES;
  2288. [_guessSizeView showTime:[customMessageModel.time intValue]];
  2289. [_guessSizeView loadBetDataWithBetArray:customMessageModel.game_data.bet andUserBetArray:customMessageModel.game_data.user_bet];
  2290. }
  2291. }
  2292. else if([customMessageModel.game_status integerValue] == 2)//2:开牌中,3:游戏结束;注:投注中game_date不会有win、cards、type数据
  2293. {
  2294. _gameAction = 4;
  2295. if (_goldFlowerView)
  2296. {
  2297. _goldFlowerView.gameAction = _gameAction;
  2298. [self disAboutClick];
  2299. [_goldFlowerView whetherBet:NO];
  2300. NSArray * cardsArray = customMessageModel.game_data.cards_data;
  2301. [_goldFlowerView loadBetDataWithBetArray:customMessageModel.game_data.bet andUserBetArray:customMessageModel.game_data.user_bet];
  2302. [_goldFlowerView showPokerWithData:cardsArray andResult:customMessageModel.game_data.win];
  2303. }
  2304. else if (_guessSizeView)
  2305. {
  2306. _guessSizeView.canBet = NO;
  2307. [_guessSizeView disClockTime];
  2308. [_guessSizeView loadBetDataWithBetArray:customMessageModel.game_data.bet andUserBetArray:customMessageModel.game_data.user_bet];
  2309. [_guessSizeView loadDiceWithDicesArr:customMessageModel.game_data.dices andResultWinPostion:[customMessageModel.game_data.win integerValue]];
  2310. }
  2311. if (_isHost || [_liveItem liveType] == 0)
  2312. {
  2313. [self changeBeginButtonWithCanBeginNext:YES];
  2314. }
  2315. [self.gameArray removeAllObjects];
  2316. }
  2317. //创建游戏历史视图
  2318. [self createGameHistoryView];
  2319. _banker_status = [customMessageModel.banker_status integerValue];
  2320. _gameBankerModel = [GameBankerModel mj_objectWithKeyValues:customMessageModel.data[@"banker"]];
  2321. //处理游戏下庄相关的视图(用于调用get_video时)
  2322. [self loadBankerDataWithModel:customMessageModel withHadLeft:_shouldReloadGame];
  2323. NSInteger tmpCoin = [[IMAPlatform sharedInstance].host getUserCoin];
  2324. if (_goldFlowerView)
  2325. {
  2326. _goldFlowerView.coinView.gameRechargeView.accountLabel.text =[NSString stringWithFormat:@"%ld",(long)tmpCoin];
  2327. if ([_liveItem liveType] == 3 && !_isHost)
  2328. {
  2329. [_goldFlowerView judgmentBetView:tmpCoin];
  2330. }
  2331. else if ([_liveItem liveType] == 2 && !_isHost)
  2332. {
  2333. [_goldFlowerView judgmentBetView:tmpCoin];
  2334. }
  2335. }
  2336. else if (_guessSizeView)
  2337. {
  2338. _guessSizeView.gameRechargeView.accountLabel.text =[NSString stringWithFormat:@"%ld",(long)tmpCoin];
  2339. }
  2340. NSInteger index = 0;
  2341. if(self.bankerDataArr.count>0)
  2342. {
  2343. CustomMessageModel * firstModel = self.bankerDataArr[0];
  2344. double maxMicrotime = [firstModel.timestamp doubleValue];
  2345. //获取到时间戳最大的消息
  2346. for (NSInteger i=1; i<self.bankerDataArr.count; ++i)
  2347. {
  2348. CustomMessageModel * model = self.bankerDataArr[i];
  2349. double microtime = [model.timestamp doubleValue];
  2350. if (maxMicrotime<microtime)
  2351. {
  2352. maxMicrotime = microtime;
  2353. index = i;
  2354. }
  2355. }
  2356. }
  2357. if (_shouldReloadGame == YES)
  2358. {
  2359. _shouldReloadGame = NO;
  2360. if (_gameArray.count > 0 && _gameArray)
  2361. {
  2362. for (CustomMessageModel *msg in _gameArray)
  2363. {
  2364. [self gameAllMessageWithCustomMessageModel:msg];
  2365. }
  2366. }
  2367. if (_bankerDataArr.count>index )
  2368. {
  2369. [self gameBankerMessageWithCustomMessageModel:self.bankerDataArr[index]];
  2370. }
  2371. }
  2372. }
  2373. - (void)addGameDataWithDic:(NSDictionary *) responseJson
  2374. {
  2375. NSDictionary * dic = [responseJson objectForKey:@"data"];
  2376. if (dic && [dic isKindOfClass:[NSDictionary class]])
  2377. {
  2378. _liveGameModel = [LiveGameModel mj_objectWithKeyValues:dic];
  2379. if ([_liveGameModel.game_log_id integerValue]< _game_log_id)
  2380. {
  2381. return;
  2382. }
  2383. if (_sureOnceGame)
  2384. {
  2385. //进入此判断说明先接收到了接收到推送的数据数据返回后接收到请求返回的数据
  2386. return;
  2387. }
  2388. for (CustomMessageModel * model in self.gameDataArray)
  2389. {
  2390. if ([model.game_log_id isEqual:_liveGameModel.game_log_id] && [model.game_action isEqual:@"6"])
  2391. {
  2392. _sureOnceGame = YES;
  2393. return;
  2394. }
  2395. }
  2396. if (_goldFlowerView.showPokerTimer)
  2397. {
  2398. [_goldFlowerView.showPokerTimer invalidate];
  2399. _goldFlowerView.showPokerTimer = nil;
  2400. }
  2401. [_goldFlowerView removeFromSuperview];
  2402. _goldFlowerView = nil;
  2403. if (_guessSizeView.showDiceTimer)
  2404. {
  2405. [_guessSizeView.showDiceTimer invalidate];
  2406. _guessSizeView.showDiceTimer = nil;
  2407. }
  2408. if([dic toInt:@"game_id"] != 0)
  2409. {
  2410. _isArc = _liveGameModel.auto_start == 1 ? YES : NO;
  2411. _gameAction = 0;
  2412. _gameId = [_liveGameModel.game_id integerValue];
  2413. if(_isHost || [_liveItem liveType] == 0)
  2414. {
  2415. [self addGameView];
  2416. }
  2417. else if([_liveItem liveType] != 1)
  2418. {
  2419. [self loadGoldFlowerViewWithBetArray:_liveGameModel.bet_option withGameID:[dic toInt:@"game_id"]];
  2420. }
  2421. [self hideGameView];
  2422. if (_goldFlowerView) {
  2423. _goldFlowerView.game_log_id = _liveGameModel.game_log_id;
  2424. _goldFlowerView.game_id = _liveGameModel.game_id;
  2425. // _goldFlowerView.betOptionArray = dic[@"bet_option"];
  2426. _goldFlowerView.betOptionArray = _liveGameModel.bet_option;
  2427. [self disAboutClick];
  2428. [_goldFlowerView creatPokerhiden:NO gameType:_liveGameModel.game_id card:_liveGameModel.game_data.public_cards];//记载发牌视图
  2429. [_goldFlowerView creatBetAmount:NO type:_liveGameModel.game_id];//加载下注视图
  2430. //倍率
  2431. [_goldFlowerView loadOptionArray:_liveGameModel.option];
  2432. }
  2433. else if (_guessSizeView)
  2434. {
  2435. _guessSizeView.game_log_id = _liveGameModel.game_log_id;
  2436. _guessSizeView.betOptionArray = _liveGameModel.bet_option;
  2437. [_guessSizeView loadOptionArray:_liveGameModel.option];
  2438. [_guessSizeView disClockTime];
  2439. }
  2440. }
  2441. if ([_liveGameModel.game_status integerValue] == 1)// 游戏状态,1:游戏开始,2:游戏结束
  2442. {
  2443. if (_goldFlowerView)
  2444. {
  2445. if ([_liveItem liveType] == 3 && !_isHost)
  2446. {
  2447. [_goldFlowerView whetherBet:YES];
  2448. }
  2449. else if ([_liveItem liveType] == 2)
  2450. {
  2451. [_goldFlowerView whetherBet:YES];
  2452. }
  2453. [_goldFlowerView timeCountDown:[_liveGameModel.time intValue]];//开始倒计时
  2454. //加载更新下注的数据
  2455. [_goldFlowerView loadBetDataWithBetArray:_liveGameModel.game_data.bet andUserBetArray:_liveGameModel.game_data.user_bet];
  2456. }
  2457. else if (_guessSizeView)
  2458. {
  2459. _guessSizeView.canBet = YES;
  2460. [_guessSizeView showTime:[_liveGameModel.time intValue]];
  2461. [_guessSizeView loadBetDataWithBetArray:_liveGameModel.game_data.bet andUserBetArray:_liveGameModel.game_data.user_bet];
  2462. }
  2463. }
  2464. else if([_liveGameModel.game_status integerValue] == 2)//2:开牌中,3:游戏结束;注:投注中game_date不会有win、cards、type数据
  2465. {
  2466. _gameAction = 4;
  2467. if (_goldFlowerView)
  2468. {
  2469. _goldFlowerView.gameAction = _gameAction;
  2470. [self disAboutClick];
  2471. [_goldFlowerView whetherBet:NO];
  2472. NSArray * cardsArray = _liveGameModel.game_data.cards_data;
  2473. [_goldFlowerView loadBetDataWithBetArray:_liveGameModel.game_data.bet andUserBetArray:_liveGameModel.game_data.user_bet];
  2474. [_goldFlowerView showPokerWithData:cardsArray andResult:_liveGameModel.game_data.win];
  2475. }
  2476. else if (_guessSizeView)
  2477. {
  2478. _guessSizeView.canBet = NO;
  2479. [_guessSizeView disClockTime];
  2480. [_guessSizeView loadBetDataWithBetArray:_liveGameModel.game_data.bet andUserBetArray:_liveGameModel.game_data.user_bet];
  2481. [_guessSizeView loadDiceWithDicesArr:_liveGameModel.game_data.dices andResultWinPostion:[_liveGameModel.game_data.win integerValue]];
  2482. }
  2483. if (_isHost || [_liveItem liveType] == 0) {
  2484. [self changeBeginButtonWithCanBeginNext:YES];
  2485. }
  2486. [self.gameArray removeAllObjects];
  2487. }
  2488. //创建游戏历史视图
  2489. [self createGameHistoryView];
  2490. NSInteger tmpCoin = [[IMAPlatform sharedInstance].host getUserCoin];
  2491. if (_goldFlowerView)
  2492. {
  2493. _goldFlowerView.coinView.gameRechargeView.accountLabel.text =[NSString stringWithFormat:@"%ld",(long)tmpCoin];
  2494. if ([_liveItem liveType] == 3 && !_isHost)
  2495. {
  2496. [_goldFlowerView judgmentBetView:tmpCoin];
  2497. }
  2498. else if ([_liveItem liveType] == 2 && !_isHost)
  2499. {
  2500. [_goldFlowerView judgmentBetView:tmpCoin];
  2501. }
  2502. }
  2503. else if (_guessSizeView)
  2504. {
  2505. _guessSizeView.gameRechargeView.accountLabel.text =[NSString stringWithFormat:@"%ld",(long)tmpCoin];
  2506. }
  2507. _banker_status = [_liveGameModel.banker_status integerValue];
  2508. _gameBankerModel = _liveGameModel.banker;
  2509. if (_banker_status == 2)
  2510. {
  2511. _bottomView.switchBankerBtn.hidden = NO;
  2512. [self changeSwitchBankerBtn];
  2513. _bottomView.grabBankerBtn.hidden = YES;
  2514. self.gameBankerView.hidden = NO;
  2515. [self.gameBankerView.bankerImageView sd_setImageWithURL:[NSURL URLWithString:_liveGameModel.banker.banker_img] placeholderImage:[UIImage imageNamed:@"DefaultImg"]];
  2516. self.gameBankerView.bankerName.text = _liveGameModel.banker.banker_name;
  2517. self.gameBankerView.bankerDesLabel.text = [NSString stringWithFormat:ASLocalizedString(@"剩余底金%@"),_liveGameModel.banker.coin];
  2518. [self changeGameBankerView];
  2519. //庄家不能投注
  2520. if ([self isShouldPlayer:_liveGameModel.banker.banker_id])
  2521. {
  2522. [_goldFlowerView whetherBet:NO];
  2523. _guessSizeView.canBet = NO;
  2524. [self hiddenBetView:YES];
  2525. }
  2526. }
  2527. else if (_banker_status == 1)
  2528. {
  2529. _bottomView.grabBankerBtn.hidden = NO;
  2530. self.gameBankerView.hidden = YES;
  2531. _bankerView.leastCoinLabel.text = [NSString stringWithFormat:ASLocalizedString(@"底金:%@"),_liveGameModel.principal];
  2532. }
  2533. else
  2534. {
  2535. _bottomView.grabBankerBtn.hidden = YES;
  2536. self.gameBankerView.hidden = YES;
  2537. }
  2538. [self changePayViewFrame];
  2539. NSInteger index = 0;
  2540. if(self.bankerDataArr.count>0)
  2541. {
  2542. CustomMessageModel * firstModel = self.bankerDataArr[0];
  2543. double maxMicrotime = [firstModel.timestamp doubleValue];
  2544. //获取到时间戳最大的消息
  2545. for (NSInteger i=1; i<self.bankerDataArr.count; ++i)
  2546. {
  2547. CustomMessageModel * model = self.bankerDataArr[i];
  2548. double microtime = [model.timestamp doubleValue];
  2549. if (maxMicrotime<microtime)
  2550. {
  2551. maxMicrotime = microtime;
  2552. index = i;
  2553. }
  2554. }
  2555. }
  2556. //用于处理前后台切换时的推送
  2557. if (_shouldReloadGame == YES)
  2558. {
  2559. _shouldReloadGame = NO;
  2560. if (_gameArray.count > 0 && _gameArray)
  2561. {
  2562. for (CustomMessageModel *msg in _gameArray)
  2563. {
  2564. [self gameAllMessageWithCustomMessageModel:msg];
  2565. }
  2566. }
  2567. if (_bankerDataArr.count>index )
  2568. {
  2569. [self gameBankerMessageWithCustomMessageModel:self.bankerDataArr[index]];
  2570. }
  2571. }
  2572. }
  2573. }
  2574. - (void)hideGameView
  2575. {
  2576. if(_giftView.isHidden == NO)
  2577. {
  2578. if (_guessSizeView)
  2579. {
  2580. _guessSizeViewCanNotSee = YES;
  2581. _guessSizeView.frame = CGRectMake(0, kScreenH, kScreenW, kGuessSizeViewHeight);
  2582. }
  2583. else if (_goldFlowerView)
  2584. {
  2585. _goldViewCanNotSee = YES;
  2586. _goldFlowerView.frame = CGRectMake(0, kScreenH, kScreenW, _goldFlowerViewHeiht);
  2587. }
  2588. [self relayoutFrameOfSubViews];
  2589. _bottomView.hidden = YES;
  2590. _bottomView.heartRect = CGRectMake(kScreenW-kDefaultMargin*2-kMyBtnWidth1*2+5, kScreenH-kDefaultMargin-kMyBtnWidth1+5, kMyBtnWidth1-10, kMyBtnWidth1-10);
  2591. _bottomView.switchGameViewBtn.transform = CGAffineTransformMakeRotation(M_PI);
  2592. }
  2593. }
  2594. //如果收到游戏开始的推送之后在规定时间没有收到游戏结算推送时的处理方法
  2595. - (void)reloadGameData
  2596. {
  2597. if (_hadBeginNext)
  2598. {
  2599. _canNotLoadData = YES;
  2600. _hadBeginNext = NO;
  2601. }
  2602. for (CustomMessageModel * model in self.gameDataArray)
  2603. {
  2604. if ([model.game_action integerValue] == 4)
  2605. {
  2606. _canNotLoadData = YES;
  2607. }
  2608. }
  2609. if (!_canNotLoadData)
  2610. {
  2611. [self loadGameData];
  2612. }
  2613. }
  2614. //如果主播选择开始游戏之后五秒内没收到游戏开始推送的处理方法
  2615. - (void)beginGame
  2616. {
  2617. FWWeakify(self)
  2618. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  2619. FWStrongify(self)
  2620. for (CustomMessageModel * model in self.gameDataArray)
  2621. {
  2622. if ([model.game_action integerValue] == 1)
  2623. {
  2624. self.canNotLoadData = YES;
  2625. }
  2626. }
  2627. if (!_canNotLoadData)
  2628. {
  2629. [self loadGameData];
  2630. }
  2631. });
  2632. }
  2633. - (void)changeBeginButtonWithCanBeginNext:(BOOL )canBeginNext
  2634. {
  2635. if (canBeginNext)
  2636. {
  2637. _bottomView.beginGameBtn.userInteractionEnabled = YES;
  2638. _bottomView.beginGameBtn.icon = [UIImage imageNamed:@"gm_game_licensing"];
  2639. [_bottomView.beginGameBtn setImage:[UIImage imageNamed:@"gm_game_licensing"] forState:UIControlStateNormal];
  2640. [_bottomView.beginGameBtn setImage:[UIImage imageNamed:@"gm_game_licensing"] forState:UIControlStateHighlighted];
  2641. }
  2642. else
  2643. {
  2644. _bottomView.beginGameBtn.userInteractionEnabled = NO;
  2645. _bottomView.beginGameBtn.hidden = NO;
  2646. _bottomView.beginGameBtn.icon = [UIImage imageNamedL:@"gm_game_wait"];
  2647. [_bottomView.beginGameBtn setImage:[UIImage imageNamedL:@"gm_game_wait"] forState:UIControlStateNormal];
  2648. [_bottomView.beginGameBtn setImage:[UIImage imageNamedL:@"gm_game_wait"] forState:UIControlStateHighlighted];
  2649. }
  2650. }
  2651. //删除游戏倒计时的定时器和闹钟
  2652. - (void)disAboutClick
  2653. {
  2654. [_goldFlowerView closeGameAboutTimer];
  2655. if (_goldFlowerView.alarmClock)
  2656. {
  2657. [_goldFlowerView.alarmClock removeFromSuperview];
  2658. _goldFlowerView.alarmClock = nil;
  2659. }
  2660. }
  2661. - (NSMutableArray *)gameArray
  2662. {
  2663. if (_gameArray == nil)
  2664. {
  2665. _gameArray = [NSMutableArray array];
  2666. }
  2667. return _gameArray;
  2668. }
  2669. - (NSMutableArray *)gameDataArray
  2670. {
  2671. if (_gameDataArray == nil)
  2672. {
  2673. _gameDataArray = [NSMutableArray array];
  2674. }
  2675. return _gameDataArray;
  2676. }
  2677. #pragma mark ------------------------游戏上庄相关推送--------------------------------
  2678. - (void)gameBankerMessageWithCustomMessageModel:(CustomMessageModel *)customMessageModel
  2679. {
  2680. if (_shouldReloadGame == YES )
  2681. {
  2682. [self.bankerDataArr addObject:customMessageModel];
  2683. return;
  2684. }
  2685. if ([customMessageModel.timestamp doubleValue] < _timestamp)
  2686. {
  2687. return;
  2688. }
  2689. _timestamp = [customMessageModel.timestamp doubleValue];
  2690. NSString *principal = [customMessageModel.data objectForKey:@"principal"];
  2691. customMessageModel.banker_list = [customMessageModel.data objectForKey:@"banker_list"];
  2692. NSInteger action = [customMessageModel.action integerValue];
  2693. _banker_status = [customMessageModel.banker_status integerValue];
  2694. //上庄模块推送操作号,1:开启上庄,2:申请上庄,3:选择庄家,4:下庄
  2695. if (action == 1)
  2696. {
  2697. //主播
  2698. if (_isHost || [_liveItem liveType] == FW_LIVE_TYPE_HOST)
  2699. {
  2700. // _bottomView.switchBankerBtn.hidden = NO;
  2701. // _bottomView.switchBankerBtn.userInteractionEnabled = NO;
  2702. }
  2703. else
  2704. {
  2705. _bankerView.video_id = customMessageModel.room_id;
  2706. _bankerView.principal = principal;
  2707. _bankerView.leastCoinLabel.text = [NSString stringWithFormat:ASLocalizedString(@"底金:%@"),principal];
  2708. _bottomView.grabBankerBtn.hidden = NO;
  2709. }
  2710. }
  2711. else if (action ==2)
  2712. {
  2713. //只对主播做玩家上庄请求信息的展示
  2714. if (_isHost || [_liveItem liveType] == 0)
  2715. {
  2716. [self changeSwitchBankerBtn];
  2717. self.selectctBankerView.hidden = NO;
  2718. NSLog(@"~~~~~~~~%@",customMessageModel.banker_list);
  2719. if ([customMessageModel.banker_list isKindOfClass:[NSArray class]] && customMessageModel.banker_list.count>0)
  2720. {
  2721. [self.bankerListArr removeAllObjects];
  2722. for (NSDictionary * bankerDic in customMessageModel.banker_list)
  2723. {
  2724. GameBankerModel * model = [GameBankerModel mj_objectWithKeyValues:bankerDic];
  2725. model.isSelect = NO;
  2726. [self.bankerListArr addObject:model];
  2727. }
  2728. _bottomView.bankMessage = self.bankerListArr.count;
  2729. _bottomView.bjsbadge.badgeText = @"···";
  2730. self.selectctBankerView.dataArray = self.bankerListArr;
  2731. // [UIView animateWithDuration:0.3 animations:^{
  2732. // _selectctBankerView.frame = CGRectMake((kScreenW - 280)/2, (kScreenH - 290)/2, 280, 290);
  2733. // }];
  2734. }
  2735. }
  2736. }
  2737. else if (action == 3)
  2738. {
  2739. //选择玩家之后
  2740. customMessageModel.banker = [GameBankerModel mj_objectWithKeyValues:customMessageModel.data[@"banker"]];
  2741. [self loadBankerDataWithModel:customMessageModel withHadLeft:_shouldReloadGame];
  2742. }
  2743. else if (action == 4)
  2744. {
  2745. [self changeSwitchBankerBtn];
  2746. self.gameBankerView.hidden = YES;
  2747. [self.bankerListArr removeAllObjects];
  2748. customMessageModel.banker = [GameBankerModel mj_objectWithKeyValues:customMessageModel.data[@"banker"]];
  2749. if ([self isShouldPlayer:customMessageModel.banker.banker_id])
  2750. {
  2751. _goldFlowerView.banker = NO;
  2752. [self hiddenBetView:NO];
  2753. [_goldFlowerView updateCoinWithID:nil];
  2754. [_guessSizeView updateCoinWithID:nil];
  2755. }
  2756. _bottomView.grabBankerBtn.hidden = YES;
  2757. [self changePayViewFrame];
  2758. }
  2759. }
  2760. - (void)loadBankerDataWithModel:(CustomMessageModel *)customMessageModel withHadLeft:(BOOL) hadLeft
  2761. {
  2762. if (_banker_status == 2)
  2763. {
  2764. _bottomView.switchBankerBtn.hidden = NO;
  2765. self.gameBankerView.hidden = NO;
  2766. [self.gameBankerView.bankerImageView sd_setImageWithURL:[NSURL URLWithString:customMessageModel.banker.banker_img] placeholderImage:[UIImage imageNamed:@"DefaultImg"]];
  2767. self.gameBankerView.bankerName.text = customMessageModel.banker.banker_name;
  2768. self.gameBankerView.bankerDesLabel.text = [NSString stringWithFormat:ASLocalizedString(@"剩余底金%@"),customMessageModel.banker.coin];
  2769. [self changeGameBankerView];
  2770. self.bottomView.grabBankerBtn.hidden = YES;
  2771. _bottomView.bankMessage = 0;
  2772. _bottomView.bjsbadge.badgeText = nil;
  2773. if (!hadLeft)
  2774. {
  2775. //庄家不能投注
  2776. if ([self isShouldPlayer:customMessageModel.banker.banker_id])
  2777. {
  2778. _goldFlowerView.banker = YES;
  2779. _guessSizeView.canBet = NO;
  2780. [self hiddenBetView:YES];
  2781. [_goldFlowerView updateCoinWithID:nil];
  2782. [_guessSizeView updateCoinWithID:nil];
  2783. }
  2784. }
  2785. else
  2786. {
  2787. //庄家不能投注
  2788. if ([self isShouldPlayer:customMessageModel.banker.banker_id])
  2789. {
  2790. [_goldFlowerView whetherBet:NO];
  2791. _guessSizeView.canBet = NO;
  2792. [self hiddenBetView:YES];
  2793. }
  2794. }
  2795. //庄家不能投注
  2796. if ([self isShouldPlayer:customMessageModel.banker.banker_id])
  2797. {
  2798. _goldFlowerView.banker = YES;
  2799. _guessSizeView.canBet = NO;
  2800. [self hiddenBetView:YES];
  2801. [_goldFlowerView updateCoinWithID:nil];
  2802. [_guessSizeView updateCoinWithID:nil];
  2803. }
  2804. }
  2805. else if (_banker_status == 1)
  2806. {
  2807. _bottomView.grabBankerBtn.hidden = NO;
  2808. self.gameBankerView.hidden = YES;
  2809. if ([[customMessageModel.data allValues] containsObject:@"principal"]) {
  2810. _bankerView.leastCoinLabel.text = [NSString stringWithFormat:ASLocalizedString(@"底金:%@"),[customMessageModel.data objectForKey:@"principal"]];
  2811. }
  2812. }
  2813. else
  2814. {
  2815. _bottomView.grabBankerBtn.hidden = YES;
  2816. self.gameBankerView.hidden = YES;
  2817. }
  2818. [self changeSwitchBankerBtn];
  2819. [self changePayViewFrame];
  2820. }
  2821. - (GameBankerView *)gameBankerView
  2822. {
  2823. if (_gameBankerView == nil)
  2824. {
  2825. _gameBankerView = [[NSBundle mainBundle]loadNibNamed:@"GameBankerView" owner:nil options:nil].lastObject;
  2826. _gameBankerView.frame = CGRectMake(kDefaultMargin, CGRectGetMaxY(_topView.frame)+kDefaultMargin, 240, 50);
  2827. _gameBankerView.layer.cornerRadius = 25;
  2828. _gameBankerView.layer.masksToBounds = YES;
  2829. _gameBankerView.hidden = YES;
  2830. [self addSubview:_gameBankerView];
  2831. }
  2832. return _gameBankerView;
  2833. }
  2834. - (void)changeGameBankerView
  2835. {
  2836. CGSize titleSize = [self.gameBankerView.bankerName.text boundingRectWithSize:CGSizeMake(110, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;
  2837. CGSize nameSize = [self.gameBankerView.bankerDesLabel.text boundingRectWithSize:CGSizeMake(110, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]} context:nil].size;
  2838. CGFloat width = MAX(titleSize.width, nameSize.width);
  2839. width += 65;
  2840. if (_topView.priceView.hidden)
  2841. {
  2842. _gameBankerView.frame = CGRectMake(kDefaultMargin, CGRectGetMaxY(_topView.frame)+kDefaultMargin-30, width, 50);
  2843. }
  2844. else
  2845. {
  2846. _gameBankerView.frame = CGRectMake(kDefaultMargin, CGRectGetMaxY(_topView.frame)+kDefaultMargin, width, 50);
  2847. }
  2848. }
  2849. - (NSMutableArray *)bankerListArr
  2850. {
  2851. if (_bankerListArr == nil)
  2852. {
  2853. _bankerListArr = [NSMutableArray array];
  2854. }
  2855. return _bankerListArr;
  2856. }
  2857. - (NSMutableArray *)bankerDataArr
  2858. {
  2859. if (_bankerDataArr == nil)
  2860. {
  2861. _bankerDataArr = [NSMutableArray array];
  2862. }
  2863. return _bankerDataArr;
  2864. }
  2865. - (SelectBankerView *)selectctBankerView
  2866. {
  2867. if (_selectctBankerView == nil)
  2868. {
  2869. _selectctBankerView = [SelectBankerView EditNibFromXib];
  2870. _selectctBankerView.delegate = self;
  2871. _selectctBankerView.frame = CGRectMake((kScreenW - 280)/2, kScreenH, 280, 290);
  2872. [_selectctBankerView createStyle];
  2873. [self addSubview:_selectctBankerView];
  2874. }
  2875. return _selectctBankerView;
  2876. }
  2877. - (NSArray *)bankerSwitchArray
  2878. {
  2879. if (_bankerSwitchArray == nil)
  2880. {
  2881. //上庄状态,0:未开启上庄,1:玩家申请上庄,2:玩家上庄
  2882. //0 //显示上庄按钮图片 //1 显示查看玩家上庄请求消息的按钮图片 //2 显示下庄按钮的图片
  2883. _bankerSwitchArray = @[@"gm_open_banker",@"gm_apply_number",@"gm_close_banker"];
  2884. }
  2885. return _bankerSwitchArray;
  2886. }
  2887. - (void)changeSwitchBankerBtn
  2888. {
  2889. //上庄状态,0:未开启上庄,1:玩家申请上庄,2:玩家上庄
  2890. _bottomView.switchBankerBtn.userInteractionEnabled = YES;
  2891. _bottomView.switchBankerBtn.icon = [UIImage imageNamed:self.bankerSwitchArray[_banker_status]];
  2892. [_bottomView.switchBankerBtn setImage:[UIImage imageNamed:self.bankerSwitchArray[_banker_status]] forState:UIControlStateNormal];
  2893. [_bottomView.switchBankerBtn setImage:[UIImage imageNamed:self.bankerSwitchArray[_banker_status]] forState:UIControlStateHighlighted];
  2894. }
  2895. - (void)changePayViewFrame
  2896. {
  2897. if (_uiDelegate && [_uiDelegate respondsToSelector:@selector(changePayViewFrame:)])
  2898. {
  2899. [_uiDelegate changePayViewFrame:self];
  2900. }
  2901. }
  2902. - (void)closeGitfView
  2903. {
  2904. _bottomView.hidden = NO;
  2905. _msgView.hidden = NO;
  2906. [_giftView hide];
  2907. // _giftView.hidden = YES;
  2908. // _giftView.frame = CGRectMake(0, self.frame.size.height, _giftView.frame.size.width, _giftView.frame.size.height);
  2909. }
  2910. - (void)choseArcOrMrcGameWithView:(UIView *)gameView
  2911. {
  2912. NSString * str = _isArc ? ASLocalizedString(@"是否切换为手动发牌"): ASLocalizedString(@"是否切换为自动发牌");
  2913. FWWeakify(self)
  2914. [FanweMessage alert:ASLocalizedString(@"提示")message:str destructiveAction:^{
  2915. FWStrongify(self)
  2916. NSNumber * autoStart = !_isArc ? @1 : @0;
  2917. NSMutableDictionary * mDict = [NSMutableDictionary dictionary];
  2918. [mDict setObject:@"games" forKey:@"ctl"];
  2919. [mDict setObject:@"autoStart" forKey:@"act"];
  2920. [mDict setObject:autoStart forKey:@"auto_start"];
  2921. [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
  2922. if ([responseJson toInt:@"status"] == 1)
  2923. {
  2924. //取反,手动发牌点击之后变成自动发牌,自动发牌点击之后变成手动发牌
  2925. self.isArc = !self.isArc;
  2926. if ([gameView isKindOfClass:[GoldFlowView class]])
  2927. {
  2928. self.goldFlowerView.isArc = self.isArc;
  2929. }
  2930. else if ([gameView isKindOfClass:[GuessSizeView class]])
  2931. {
  2932. self.guessSizeView.isArc = self.isArc;
  2933. }
  2934. }
  2935. } FailureBlock:^(NSError *error) {
  2936. [[BGHUDHelper sharedInstance] tipMessage:[NSString stringWithFormat:@"%@",error]];
  2937. }];
  2938. } cancelAction:^{
  2939. }];
  2940. }
  2941. - (void)arcGame
  2942. {
  2943. if (_gameAction == 4 && _isArc )
  2944. {
  2945. if (_goldFlowerView.betArr.count>0)
  2946. {
  2947. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  2948. [self onBottomViewClickMenus:_bottomView fromButton:_bottomView.beginGameBtn];
  2949. });
  2950. }
  2951. else
  2952. {
  2953. [self onBottomViewClickMenus:_bottomView fromButton:_bottomView.beginGameBtn];
  2954. }
  2955. }
  2956. }
  2957. - (void)showGift {
  2958. // 发送礼物
  2959. __weak typeof(self) ws =self;
  2960. [self changeMoney];
  2961. _bottomView.hidden = YES;
  2962. _voicebottomView.hidden = YES;
  2963. _giftView.hidden = NO;
  2964. [_giftView show:self.superview];
  2965. // [_giftView.shadowViews addGestureRecognizer:_tapGesture];
  2966. if (_goldFlowerView)
  2967. {
  2968. _goldViewCanNotSee = YES;
  2969. _goldFlowerView.frame = CGRectMake(0, kScreenH, kScreenW, _goldFlowerViewHeiht);
  2970. _bottomView.heartRect = CGRectMake(kScreenW-kDefaultMargin*2-kMyBtnWidth1*2+5, kScreenH-kDefaultMargin-kMyBtnWidth1+5, kMyBtnWidth1-10, kMyBtnWidth1-10);
  2971. [self relayoutFrameOfSubViews];
  2972. _bottomView.switchGameViewBtn.transform = CGAffineTransformMakeRotation(M_PI);
  2973. }
  2974. if (_guessSizeView)
  2975. {
  2976. _guessSizeViewCanNotSee = YES;
  2977. _guessSizeView.frame = CGRectMake(0, kScreenH, kScreenW, kGuessSizeViewHeight);
  2978. _bottomView.heartRect = CGRectMake(kScreenW-kDefaultMargin*2-kMyBtnWidth1*2+5, kScreenH-kDefaultMargin-kMyBtnWidth1+5, kMyBtnWidth1-10, kMyBtnWidth1-10);
  2979. [self relayoutFrameOfSubViews];
  2980. _bottomView.switchGameViewBtn.transform = CGAffineTransformMakeRotation(M_PI);
  2981. }
  2982. if (_sdkDelegate && [_sdkDelegate respondsToSelector:@selector(hideReLiveSlide:)])
  2983. {
  2984. [_sdkDelegate hideReLiveSlide:YES];
  2985. }
  2986. [UIView animateWithDuration:0.1 animations:^{
  2987. ws.giftView.frame = CGRectMake(0, kScreenH-_giftViewHeight - MG_BOTTOM_MARGIN, _giftView.frame.size.width, _giftView.frame.size.height);
  2988. // ws.closeLiveBtn.hidden = YES;
  2989. }completion:^(BOOL finished) {
  2990. ws.msgView.hidden = YES;
  2991. }];
  2992. }
  2993. @end