fix
无故事王国
2024-06-13 5c9191f42013d24360a3ef9e7ddd701c5a1a6209
DolphinEnglishLearnStudent/Moudle/Home/Listen/VC/HomeListenGame_2_VC.swift
@@ -9,7 +9,7 @@
struct Game_2_SelectModel:Hashable{
            var indexPath:IndexPath!
            var model:Listen1SubModel!
            var model:SimpleListenDataModel!
}
class HomeListenGame_2_VC: BaseVC {
@@ -18,6 +18,10 @@
            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()
@@ -44,15 +48,38 @@
            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() {
@@ -82,7 +109,7 @@
                                    make.centerY.equalTo(label_surplusTitle)
                                    make.height.equalTo(44)
                        }
                        collectionView.delegate = self
                        collectionView.dataSource = self
@@ -120,6 +147,7 @@
                        }
            }
            private func nextQuesAction(){
            }
@@ -150,7 +178,7 @@
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
                        }
@@ -158,7 +186,7 @@
                                    print("重复点击");return
                        }
                        let model = listen1Model.subjectList[indexPath.row]
                        let model = datas[indexPath.row]
                        if selectModels.count >= 2{
                                    selectModels.removeFirst()
@@ -204,9 +232,9 @@
                                                }
                                    }
                                    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()
                                    }
@@ -218,15 +246,18 @@
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
            }
}
@@ -264,3 +295,17 @@
                        }
            }
}
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() {
            }
}