| | |
| | | |
| | | struct Game_2_SelectModel:Hashable{ |
| | | var indexPath:IndexPath! |
| | | var model:Listen1SubModel! |
| | | var model:SimpleListenDataModel! |
| | | } |
| | | |
| | | class HomeListenGame_2_VC: BaseVC { |
| | |
| | | var rootViewModel:HomeListenFightViewModel! |
| | | private var listen1Model:Listen1Model! |
| | | private var selectModels = [Game_2_SelectModel]() |
| | | |
| | | private var datas = [SimpleListenDataModel]() |
| | | |
| | | private var currentPayCellIndex:IndexPath? |
| | | |
| | | private lazy var label_time:UILabel = { |
| | | let label = UILabel() |
| | |
| | | |
| | | private var timer:Timer? |
| | | private var times:Int = 600 |
| | | private var voicePlayer = VoicePlayer.share() |
| | | |
| | | required init(listen1Model:Listen1Model){ |
| | | super.init(nibName: nil, bundle: nil) |
| | | self.listen1Model = listen1Model |
| | | self.listen1Model.subjectList.shuffle() |
| | | |
| | | for v in listen1Model.photoList{ |
| | | v.type = 1 // 图片标识 |
| | | } |
| | | |
| | | for v in listen1Model.voiceList{ |
| | | v.type = 2 // 音频标识 |
| | | } |
| | | |
| | | datas.append(contentsOf: listen1Model.photoList) |
| | | datas.append(contentsOf: listen1Model.voiceList) |
| | | datas.shuffle() |
| | | } |
| | | |
| | | required init?(coder: NSCoder) { |
| | | fatalError("init(coder:) has not been implemented") |
| | | } |
| | | |
| | | override func viewDidAppear(_ animated: Bool) { |
| | | super.viewDidAppear(animated) |
| | | voicePlayer.delegate = self |
| | | } |
| | | |
| | | override func viewDidDisappear(_ animated: Bool) { |
| | | super.viewDidDisappear(animated) |
| | | voicePlayer.delegate = nil |
| | | timer?.invalidate() |
| | | } |
| | | |
| | | override func viewDidLoad() { |
| | |
| | | make.centerY.equalTo(label_surplusTitle) |
| | | make.height.equalTo(44) |
| | | } |
| | | |
| | | |
| | | |
| | | collectionView.delegate = self |
| | | collectionView.dataSource = self |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | private func nextQuesAction(){ |
| | | |
| | | } |
| | |
| | | extension HomeListenGame_2_VC:UICollectionViewDelegate{ |
| | | func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { |
| | | |
| | | if listen1Model.subjectList[indexPath.row].isOpen{ |
| | | if datas[indexPath.row].isOpen{ |
| | | print("已经展开过了");return |
| | | } |
| | | |
| | |
| | | print("重复点击");return |
| | | } |
| | | |
| | | let model = listen1Model.subjectList[indexPath.row] |
| | | let model = datas[indexPath.row] |
| | | |
| | | if selectModels.count >= 2{ |
| | | selectModels.removeFirst() |
| | |
| | | } |
| | | } |
| | | |
| | | let surplusListCount = listen1Model.subjectList.filter({$0.isOpen == false}).count |
| | | let surplusListCount = datas.filter({$0.isOpen == false}).count |
| | | if surplusListCount == 0{ |
| | | NotificationCenter.default.post(name: NextLession_Noti, object: ["gameId":listen1Model.data!.id,"gameIntegral":listen1Model.data!.integral]) |
| | | NotificationCenter.default.post(name: NextLession_Noti, object: ["gameId":listen1Model.data!.id,"gameIntegral":listen1Model.data!.answerIntegral]) |
| | | rootViewModel.answerItems[0] = self.listen1Model |
| | | timer?.invalidate() |
| | | } |
| | |
| | | |
| | | extension HomeListenGame_2_VC:UICollectionViewDataSource{ |
| | | func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { |
| | | let model = listen1Model.subjectList[indexPath.row] |
| | | let model = datas[indexPath.row] |
| | | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_ListenFight_Game_Pocket_CCell", for: indexPath) as! ListenFight_Game_Pocket_CCell |
| | | cell.setModel(model) |
| | | cell.voice_view.isHidden = model.correct.isEmpty |
| | | cell.indexPath = indexPath |
| | | cell.setSimpleModel(model) |
| | | cell.cellPayatIndex {[weak self] index in |
| | | self?.currentPayCellIndex = index |
| | | } |
| | | return cell |
| | | } |
| | | |
| | | func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { |
| | | return listen1Model.subjectList.count |
| | | return datas.count |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | extension HomeListenGame_2_VC:VoicePlayerDelegate{ |
| | | func playComplete() { |
| | | if let index = currentPayCellIndex{ |
| | | let cell = collectionView.cellForItem(at: index) as! ListenFight_Game_Pocket_CCell |
| | | cell.cellResotePay() |
| | | } |
| | | } |
| | | |
| | | func playing() { |
| | | |
| | | } |
| | | |
| | | } |