diff --git a/Projects/CommonUI/CommonUI.xcodeproj/project.pbxproj b/Projects/CommonUI/CommonUI.xcodeproj/project.pbxproj index a2b680b..8b9fa8b 100644 --- a/Projects/CommonUI/CommonUI.xcodeproj/project.pbxproj +++ b/Projects/CommonUI/CommonUI.xcodeproj/project.pbxproj @@ -14,6 +14,9 @@ 537F80B2F39FD73F6F78F9B2 /* HomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47AA88AB7E000E21ED0BD7D8 /* HomeView.swift */; }; 7D319882A302F75CCE46A48C /* HomeQuizView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39A77FC9A0E2D7F62CA16E90 /* HomeQuizView.swift */; }; 951226DA2E2340E3000FDE3D /* QuizView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 951226D92E2340DC000FDE3D /* QuizView.swift */; }; + 951226E02E268D72000FDE3D /* OptionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 951226DF2E268D6F000FDE3D /* OptionView.swift */; }; + 951226E22E2690B9000FDE3D /* AnswerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 951226E12E2690B2000FDE3D /* AnswerView.swift */; }; + 951226E82E270A75000FDE3D /* QuizCompleteAlertView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 951226E72E270A75000FDE3D /* QuizCompleteAlertView.swift */; }; BAD8B768F782046D4AA1C073 /* RxCocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F3DE048BEDCB92B48F401061 /* RxCocoa.framework */; }; BE81B1F3E60D37D75A058D2B /* SnapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9CCDC15081A22BAED6318E3E /* SnapKit.framework */; }; CEADBDD98AC9921C05AAC1DA /* QuizCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7A9CE581345578C7C0F1F1A /* QuizCollectionViewCell.swift */; }; @@ -52,6 +55,9 @@ 951226D62E233E3E000FDE3D /* Colors.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Colors.xcassets; sourceTree = ""; }; 951226D72E233E3E000FDE3D /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 951226D92E2340DC000FDE3D /* QuizView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuizView.swift; sourceTree = ""; }; + 951226DF2E268D6F000FDE3D /* OptionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OptionView.swift; sourceTree = ""; }; + 951226E12E2690B2000FDE3D /* AnswerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnswerView.swift; sourceTree = ""; }; + 951226E72E270A75000FDE3D /* QuizCompleteAlertView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuizCompleteAlertView.swift; sourceTree = ""; }; 9CCDC15081A22BAED6318E3E /* SnapKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SnapKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; C28FE6392E1612667826E5C5 /* DiaryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiaryView.swift; sourceTree = ""; }; C69A8F84966D9255A07CB9B1 /* DefaultNavigationBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultNavigationBar.swift; sourceTree = ""; }; @@ -175,11 +181,14 @@ DFA6DB2905DB98838A8AEA6F /* Home */ = { isa = PBXGroup; children = ( + 951226E72E270A75000FDE3D /* QuizCompleteAlertView.swift */, 7CE59FBFD1AAA1B5E7B45FD5 /* HomeProgressView.swift */, 39A77FC9A0E2D7F62CA16E90 /* HomeQuizView.swift */, 47AA88AB7E000E21ED0BD7D8 /* HomeView.swift */, E7A9CE581345578C7C0F1F1A /* QuizCollectionViewCell.swift */, 951226D92E2340DC000FDE3D /* QuizView.swift */, + 951226DF2E268D6F000FDE3D /* OptionView.swift */, + 951226E12E2690B2000FDE3D /* AnswerView.swift */, ); path = Home; sourceTree = ""; @@ -272,12 +281,15 @@ files = ( F3DA12FF4D18AE405F2F6B08 /* BaseViewController.swift in Sources */, E0865F2849CCB89CC83D3B77 /* Coordinator.swift in Sources */, + 951226E22E2690B9000FDE3D /* AnswerView.swift in Sources */, E055AA66777B1D4CC8C884E4 /* CommonUIAssets.swift in Sources */, F7673E4248628D67F3542848 /* ChatView.swift in Sources */, FB3FE0AB8AE6868B6D5E241C /* DiaryView.swift in Sources */, + 951226E82E270A75000FDE3D /* QuizCompleteAlertView.swift in Sources */, 951226DA2E2340E3000FDE3D /* QuizView.swift in Sources */, 416C58AEE5E4491991982CFF /* HomeProgressView.swift in Sources */, 7D319882A302F75CCE46A48C /* HomeQuizView.swift in Sources */, + 951226E02E268D72000FDE3D /* OptionView.swift in Sources */, 537F80B2F39FD73F6F78F9B2 /* HomeView.swift in Sources */, CEADBDD98AC9921C05AAC1DA /* QuizCollectionViewCell.swift in Sources */, 473C96577A92DD6F71241A76 /* MyPageView.swift in Sources */, diff --git a/Projects/CommonUI/Sources/View/Home/AnswerView.swift b/Projects/CommonUI/Sources/View/Home/AnswerView.swift new file mode 100644 index 0000000..6ca487b --- /dev/null +++ b/Projects/CommonUI/Sources/View/Home/AnswerView.swift @@ -0,0 +1,116 @@ +// +// AnswerView.swift +// CommonUI +// +// Created by 박지윤 on 7/15/25. +// + +import Domain +import UIKit +import SnapKit +import RxSwift +import Then + +open class AnswerView: UIView { + var correctView = UIView() + var correctLabel = UILabel() + var wrongView = UIView() + var wrongLabel = UILabel() + + public enum AnswerType { + case correct + case wrong + } + + public init(text: String, type: AnswerType) { + super.init(frame: .zero) + initAttribute(type: type) + initUI(type: type) + bindDatas(text: text, type: type) + } + + public func bind(course: CourseVO) { + } + + public func bindDatas(text: String, type: AnswerType) { + switch type { + case .correct: + correctLabel.text = text + case .wrong: + wrongLabel.text = text + } + } + + func initAttribute(type: AnswerType) { + switch type { + case .correct: + correctView = correctView.then { + $0.layer.borderColor = UIColor.black.cgColor + $0.layer.borderWidth = 1 +// $0.backgroundColor = CommonUIAssets.LMGray6 + $0.layer.cornerRadius = 12 + } + + correctLabel = correctLabel.then { + $0.textColor = .black + // $0.textColor = CommonUIAssets.LMGray1 + $0.textAlignment = .center + $0.font = .systemFont(ofSize: 13, weight: .regular) + $0.numberOfLines = 0 + $0.setContentHuggingPriority(.required, for: .vertical) + $0.setContentCompressionResistancePriority(.required, for: .vertical) + } + case .wrong: + wrongView = wrongView.then { + $0.layer.borderColor = UIColor.black.cgColor + $0.layer.borderWidth = 1 +// $0.backgroundColor = CommonUIAssets.LMBlue + $0.layer.cornerRadius = 12 + } + + wrongLabel = wrongLabel.then { + $0.textColor = .black + // $0.textColor = CommonUIAssets.LMGray1 + $0.font = .systemFont(ofSize: 14, weight: .regular) + $0.numberOfLines = 0 + $0.setContentHuggingPriority(.required, for: .vertical) + $0.setContentCompressionResistancePriority(.required, for: .vertical) + } + } + } + + func initUI(type: AnswerType) { + switch type { + case .correct: + self.addSubview(correctView) + correctView.addSubview(correctLabel) + + correctView.snp.makeConstraints { + $0.verticalEdges.equalToSuperview() + $0.leading.equalToSuperview().inset(20) + } + + correctLabel.snp.makeConstraints { + $0.horizontalEdges.equalToSuperview().inset(16) + $0.verticalEdges.equalToSuperview().inset(12) + } + case .wrong: + self.addSubview(wrongView) + wrongView.addSubview(wrongLabel) + + wrongView.snp.makeConstraints { + $0.verticalEdges.equalToSuperview() + $0.leading.equalToSuperview().inset(20) + } + + wrongLabel.snp.makeConstraints { + $0.horizontalEdges.equalToSuperview().inset(16) + $0.verticalEdges.equalToSuperview().inset(12) + } + } + } + + required public init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +} diff --git a/Projects/CommonUI/Sources/View/Home/OptionView.swift b/Projects/CommonUI/Sources/View/Home/OptionView.swift new file mode 100644 index 0000000..543d20b --- /dev/null +++ b/Projects/CommonUI/Sources/View/Home/OptionView.swift @@ -0,0 +1,76 @@ +// +// OptionView.swift +// CommonUI +// +// Created by 박지윤 on 7/15/25. +// + +import Domain +import UIKit +import SnapKit +import RxSwift +import Then + +open class OptionView: UIView { + var optionView = UIView() + var optionLabel = UILabel() + + private let options = [ + "응. 너는 누구야?", + "네, 안녕하세요. 처음 뵙겠습니다.", + "왜요?" + ] + + public init(text: String) { + super.init(frame: .zero) + initAttribute() + initUI() + bindDatas(text: text) + } + + public func bindDatas(text: String) { + optionLabel.text = text + } + + public func bind(course: CourseVO) { + } + + func initAttribute() { + optionView = optionView.then { + $0.layer.borderColor = UIColor.black.cgColor + $0.layer.borderWidth = 1 +// $0.backgroundColor = CommonUIAssets.LMGray6 + $0.layer.cornerRadius = 12 + } + + optionLabel = optionLabel.then { + $0.textColor = .black +// $0.textColor = CommonUIAssets.LMGray1 + $0.textAlignment = .center + $0.font = .systemFont(ofSize: 13, weight: .regular) + $0.numberOfLines = 0 + $0.setContentHuggingPriority(.required, for: .vertical) + $0.setContentCompressionResistancePriority(.required, for: .vertical) + } + } + + func initUI() { + self.addSubview(optionView) + optionView.addSubview(optionLabel) + + optionView.snp.makeConstraints { + $0.top.bottom.equalToSuperview() + $0.leading.equalToSuperview().inset(100) + $0.trailing.equalToSuperview().inset(20) + } + + optionLabel.snp.makeConstraints { + $0.horizontalEdges.equalToSuperview().inset(16) + $0.verticalEdges.equalToSuperview().inset(12) + } + } + + required public init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +} diff --git a/Projects/CommonUI/Sources/View/Home/QuizCompleteAlertView.swift b/Projects/CommonUI/Sources/View/Home/QuizCompleteAlertView.swift new file mode 100644 index 0000000..9ba07a4 --- /dev/null +++ b/Projects/CommonUI/Sources/View/Home/QuizCompleteAlertView.swift @@ -0,0 +1,132 @@ +// +// QuizCompleteAlertView.swift +// CommonUI +// +// Created by 박지윤 on 7/16/25. +// + +import UIKit +import SnapKit +import Then + +public final class QuizCompleteAlertView: UIView { + + private let backgroundView = UIView().then { + $0.backgroundColor = UIColor.black.withAlphaComponent(0.4) + $0.alpha = 0.0 + } + + private let containerView = UIView().then { + $0.backgroundColor = .white + $0.layer.cornerRadius = 16 + $0.clipsToBounds = true + } + + private let titleLabel = UILabel().then { + $0.text = "퀴즈 완료!" + $0.textColor = .black + $0.font = .boldSystemFont(ofSize: 20) + $0.textAlignment = .center + $0.numberOfLines = 0 + } + + private let messageLabel = UILabel().then { + $0.text = "모든 질문에 잘 답변했어요 👏" + $0.textColor = .darkGray + $0.font = .systemFont(ofSize: 16) + $0.textAlignment = .center + $0.numberOfLines = 0 + } + + private let confirmButton = UIButton(type: .system).then { + $0.setTitle("확인", for: .normal) + $0.titleLabel?.font = .systemFont(ofSize: 16, weight: .medium) + $0.setTitleColor(.white, for: .normal) + $0.backgroundColor = .systemBlue + $0.layer.cornerRadius = 8 + } + + public override init(frame: CGRect) { + super.init(frame: frame) + setupView() + setupLayout() + confirmButton.addTarget(self, action: #selector(dismiss), for: .touchUpInside) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + private func setupView() { + self.addSubview(backgroundView) + self.addSubview(containerView) + + [titleLabel, messageLabel, confirmButton].forEach { + containerView.addSubview($0) + } + } + + private func setupLayout() { + backgroundView.snp.makeConstraints { + $0.edges.equalToSuperview() + } + + containerView.snp.makeConstraints { + $0.center.equalToSuperview() + $0.width.equalToSuperview().multipliedBy(0.8) + } + + titleLabel.snp.makeConstraints { + $0.top.equalToSuperview().inset(24) + $0.leading.trailing.equalToSuperview().inset(16) + } + + messageLabel.snp.makeConstraints { + $0.top.equalTo(titleLabel.snp.bottom).offset(12) + $0.leading.trailing.equalToSuperview().inset(16) + } + + confirmButton.snp.makeConstraints { + $0.top.equalTo(messageLabel.snp.bottom).offset(20) + $0.bottom.equalToSuperview().inset(20) + $0.centerX.equalToSuperview() + $0.width.equalTo(100) + $0.height.equalTo(40) + } + } + + public func show(in parentView: UIView) { + parentView.addSubview(self) + self.snp.makeConstraints { $0.edges.equalToSuperview() } + + UIView.animate(withDuration: 0.3) { + self.backgroundView.alpha = 1.0 + } + } + + @objc private func dismiss() { + UIView.animate(withDuration: 0.3, animations: { + self.backgroundView.alpha = 0.0 + }) { _ in + self.removeFromSuperview() + if let viewController = self.findViewController() { + if let navigationController = viewController.navigationController { + navigationController.popViewController(animated: true) + } else { + viewController.dismiss(animated: true, completion: nil) + } + } + } + } + + private func findViewController() -> UIViewController? { + var responder: UIResponder? = self + while responder != nil { + if let vc = responder as? UIViewController { + return vc + } + responder = responder?.next + } + return nil + } +} diff --git a/Projects/CommonUI/Sources/View/Home/QuizView.swift b/Projects/CommonUI/Sources/View/Home/QuizView.swift index 47057ae..5e369e2 100644 --- a/Projects/CommonUI/Sources/View/Home/QuizView.swift +++ b/Projects/CommonUI/Sources/View/Home/QuizView.swift @@ -5,3 +5,113 @@ // Created by 박지윤 on 7/13/25. // +import Domain +import UIKit +import SnapKit +import RxSwift +import Then + +open class QuizView: UIView { + var situationView = UIView() + var situationLabel = UILabel() + var questionView = UIView() + var questionLabel = UILabel() + + public enum ChatType { + case situation + case question + } + + public init(text: String, type: ChatType) { + super.init(frame: .zero) + initAttribute(type: type) + initUI(type: type) + bindDatas(text: text, type: type) + } + + public func bind(course: CourseVO) { + } + + func bindDatas(text: String, type: ChatType) { + switch type { + case .situation: + situationLabel.text = text + case .question: + questionLabel.text = text + } + } + + func initAttribute(type: ChatType) { + switch type { + case .situation: + situationView = situationView.then { + $0.layer.borderColor = UIColor.black.cgColor + $0.layer.borderWidth = 1 +// $0.backgroundColor = CommonUIAssets.LMGray6 + $0.layer.cornerRadius = 12 + } + + situationLabel = situationLabel.then { + $0.textColor = .black + // $0.textColor = CommonUIAssets.LMGray1 + $0.textAlignment = .center + $0.font = .systemFont(ofSize: 13, weight: .regular) + $0.numberOfLines = 0 + $0.setContentHuggingPriority(.required, for: .vertical) + $0.setContentCompressionResistancePriority(.required, for: .vertical) + } + case .question: + questionView = questionView.then { + $0.layer.borderColor = UIColor.black.cgColor + $0.layer.borderWidth = 1 +// $0.backgroundColor = CommonUIAssets.LMBlue + $0.layer.cornerRadius = 12 + } + + questionLabel = questionLabel.then { + $0.textColor = .black + // $0.textColor = CommonUIAssets.LMGray1 + $0.font = .systemFont(ofSize: 14, weight: .regular) + $0.numberOfLines = 0 + $0.setContentHuggingPriority(.required, for: .vertical) + $0.setContentCompressionResistancePriority(.required, for: .vertical) + } + } + } + + func initUI(type: ChatType) { + switch type { + case .situation: + self.addSubview(situationView) + situationView.addSubview(situationLabel) + + situationView.snp.makeConstraints { + $0.verticalEdges.equalToSuperview() + $0.centerX.equalToSuperview() + } + + situationLabel.snp.makeConstraints { + $0.horizontalEdges.equalToSuperview().inset(20) + $0.verticalEdges.equalToSuperview().inset(14) + } + case .question: + self.addSubview(questionView) + questionView.addSubview(questionLabel) + + questionView.snp.makeConstraints { + $0.verticalEdges.equalToSuperview() + $0.leading.equalToSuperview().inset(20) + } + + questionLabel.snp.makeConstraints { + $0.horizontalEdges.equalToSuperview().inset(16) + $0.verticalEdges.equalToSuperview().inset(12) + } + } + } + + required public init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +} + diff --git a/Projects/Home/Sources/View/QuizViewController.swift b/Projects/Home/Sources/View/QuizViewController.swift index baf59ed..91e08ec 100644 --- a/Projects/Home/Sources/View/QuizViewController.swift +++ b/Projects/Home/Sources/View/QuizViewController.swift @@ -14,78 +14,232 @@ public class QuizViewController: UIViewController { let navigationBar = DefaultNavigationBar(leftImage: CommonUIAssets.IconBack ?? nil, rightImage: nil, isRightButtonHidden: true) + let progressView = UIView() + let progressEntireView = UIView().then { + $0.backgroundColor = .gray + // $0.backgroundColor = CommonUIAssets.LMGray5 + $0.layer.cornerRadius = 3 + } let scrollView = UIScrollView() - let contentView = UIView() - let logoImageView = UIImageView().then { - $0.image = CommonUIAssets.smallLogo - $0.contentMode = .scaleAspectFit - } - let homeView = HomeView() - let homeProgressView = HomeProgressView() - let homeQuizView = HomeQuizView() - -// public init(homeViewModel: HomeViewModel) { -// self.viewModel = homeViewModel -// super.init() -// } + let quizStackView = UIStackView().then { + $0.axis = .vertical + $0.spacing = 18 + } + + let optionStackView = UIStackView().then { + $0.axis = .vertical + $0.spacing = 0 + } + + var currentQuestionIndex = 0 + var currentOptionStackView: UIStackView? + var currentFeedbackText = "" + var correctAnswers = [1, 1, 0] // 정답 인덱스 + + // public init(homeViewModel: HomeViewModel) { + // self.viewModel = homeViewModel + // super.init() + // } + init() { super.init(nibName: nil, bundle: nil) } - + required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } - + public override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) self.navigationController?.setNavigationBarHidden(true, animated: false) } - + public override func viewDidLoad() { super.viewDidLoad() setupViewProperty() setupHierarchy() setupLayout() bindDatas() + showSituation(index: 0) } - + public func setupViewProperty() { view.backgroundColor = CommonUIAssets.LMOrange4 - scrollView.backgroundColor = .yellow - contentView.backgroundColor = .red - - scrollView.do { - $0.showsVerticalScrollIndicator = false - $0.showsHorizontalScrollIndicator = false + + currentOptionStackView = currentOptionStackView?.then { + $0.backgroundColor = .orange + $0.axis = .vertical + $0.spacing = 0 } } public func setupHierarchy() { - [navigationBar, scrollView].forEach { view.addSubview($0) } - scrollView.addSubview(contentView) + [navigationBar, progressView, progressEntireView, scrollView].forEach { view.addSubview($0) } + scrollView.addSubview(quizStackView) } - + public func setupDelegate() { } - + public func setupLayout() { navigationBar.snp.makeConstraints { $0.top.equalTo(view.safeAreaLayoutGuide) $0.width.centerX.equalToSuperview() } - + + progressEntireView.snp.makeConstraints { + $0.height.equalTo(6) + $0.top.equalTo(navigationBar.snp.bottom).offset(20) + $0.width.equalToSuperview().inset(20) + $0.centerX.equalToSuperview() + } + scrollView.snp.makeConstraints { - $0.top.equalTo(navigationBar.snp.bottom) + $0.top.equalTo(progressEntireView.snp.bottom).offset(20) $0.horizontalEdges.bottom.equalToSuperview() } - - contentView.snp.makeConstraints { - $0.edges.equalToSuperview() - $0.width.equalToSuperview() + + quizStackView.snp.makeConstraints { + $0.top.equalToSuperview() + $0.leading.trailing.equalToSuperview() + $0.bottom.equalToSuperview() + $0.width.equalTo(scrollView.snp.width) } } - + func bindDatas() { navigationBar.setupViewProperty(title: "처음 보는 사람과 인사하기") } + + func showSituation(index: Int) { + let situations = [ + "당신은 체험 첫날, 안내 데스크에 도착했어요.\n직원 한 분이 다가오며 웃으면서 말을 걸어요.", + "점심 시간이 가까워지고 있어요.\n주변 사람들이 슬슬 자리를 정리하고 있어요.", + "동료가 다가와서 식사에 대해 물어봐요.\n어떤 반응을 할까요?" + ] + + guard index < situations.count else { + showEndMessage() + return + } + + let situationView = QuizView(text: situations[index], type: .situation) + quizStackView.addArrangedSubview(situationView) + + DispatchQueue.main.asyncAfter(deadline: .now() + 2) { + self.showQuestion(index: index) + } + } + + func showQuestion(index: Int) { + guard index == self.currentQuestionIndex else { return } + + let questions = [ + "안녕하세요. 혹시 실습생이신가요?", + "오늘 어떤 부서에 배정받으셨나요?", + "점심은 보통 몇 시에 먹을까요?" + ] + + let options = [ + ["응. 너는 누구야?", "네, 안녕하세요.", "왜요?"], + ["몰라요.", "총무팀이요!", "어디더라?"], + ["12시쯤이요.", "저녁이요?", "모르겠어요."] + ] + + let feedbacks = [ + "처음 본 사람에게 반말은 예의에 어긋나요.", + "부서를 정확히 말하는 게 좋아요.", + "점심 시간은 보통 12시입니다." + ] + + guard index < questions.count else { + self.showEndMessage() + return + } + + let questionView = QuizView(text: questions[index], type: .question) + quizStackView.addArrangedSubview(questionView) + + DispatchQueue.main.asyncAfter(deadline: .now() + 2) { + let optionStack = UIStackView().then { + $0.axis = .vertical + $0.spacing = 0 + } + + for i in 0..<3 { + let optionView = OptionView(text: options[index][i]) + optionView.tag = i + optionView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.handleOptionTap(_:)))) + optionView.isUserInteractionEnabled = true + optionStack.addArrangedSubview(optionView) + } + + self.quizStackView.addArrangedSubview(optionStack) + self.currentQuestionIndex = index + self.currentOptionStackView = optionStack + self.currentFeedbackText = feedbacks[index] + } + } + + @objc func handleOptionTap(_ sender: UITapGestureRecognizer) { + guard let selectedView = sender.view else { return } + guard let optionStack = currentOptionStackView else { return } + + let selectedIndex = selectedView.tag + let correctIndex = correctAnswers[currentQuestionIndex] + + for view in optionStack.arrangedSubviews { + if view != selectedView { + optionStack.removeArrangedSubview(view) + view.removeFromSuperview() + } + } + + if selectedIndex == correctIndex { + let feedback = AnswerView(text: currentFeedbackText, type: .correct) + quizStackView.addArrangedSubview(feedback) + + DispatchQueue.main.asyncAfter(deadline: .now() + 2) { + let nextIndex = self.currentQuestionIndex + 1 + self.currentQuestionIndex = nextIndex + self.showSituation(index: nextIndex) + } + } else { + let feedback = AnswerView(text: "다시 한 번 생각해보세요.", type: .wrong) + quizStackView.addArrangedSubview(feedback) + + DispatchQueue.main.asyncAfter(deadline: .now() + 2) { + let options = [ + ["응. 너는 누구야?", "네, 안녕하세요.", "왜요?"], + ["몰라요.", "총무팀이요!", "어디더라?"], + ["12시쯤이요.", "저녁이요?", "모르겠어요."] + ] + let index = self.currentQuestionIndex + let optionStack = UIStackView().then { + $0.axis = .vertical + $0.spacing = 0 + } + + for i in 0..<3 { + let optionView = OptionView(text: options[index][i]) + optionView.tag = i + optionView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.handleOptionTap(_:)))) + optionView.isUserInteractionEnabled = true + optionStack.addArrangedSubview(optionView) + } + + self.quizStackView.addArrangedSubview(optionStack) + self.currentOptionStackView = optionStack + } + } + } + + func showEndMessage() { + showQuizCompleteAlert() + } + + func showQuizCompleteAlert() { + let alertView = QuizCompleteAlertView() + alertView.show(in: view) + } }