// // GameLearnViewController.swift // Guibe // // Created by Max Hunt on 11/06/2019. // Copyright © 2019 8. All rights reserved. // import UIKit import AVKit class GameLearnViewController: UIViewController, AVAudioPlayerDelegate { @IBOutlet weak var mainButton: UIButton! @IBOutlet weak var textLabel: UILabel! @IBOutlet weak var progressBar: UIProgressView! @IBOutlet weak var nextBtn: UIButton! @IBAction func buttonPressed(_ sender: Any) { audioPlay(fName: self.fileName) } @IBAction func nextBtnPressed(_ sender: Any) { stepCounter += 1 stepThrough(ptr: stepCounter) } var stepCounter: Int = 0 var fileName: String = "" var player = AVAudioPlayer() override func viewDidLoad() { super.viewDidLoad() textLabel.text = "Now we will learn the different haptic patterns for navigationg with Guibe" textLabel.accessibilityLabel = "Now we will learn the different haptic patterns for navigationg with geibe" mainButton.accessibilityLabel = "Play vibration" mainButton.alpha = 0.0 // Do any additional setup after loading the view. } func stepThrough(ptr:Int) { switch ptr { case 1: beginJourney() self.fileName = "guibe_begin" case 2: arrivedAtDestination() self.fileName = "guibe_arrived" case 3: wrongDirection() self.fileName = "guibe_wrongdirection" case 4: turnRight() self.fileName = "guibe_right" case 5: turnLeft() self.fileName = "guibe_left" case 6: showDone() self.fileName = "guibe_arrived" case 7: nextPage() default: return } } func beginJourney() { UIView.animate(withDuration: 0.5, animations: {self.mainButton.alpha = 1.0}) self.textLabel.fadeTransition(0.5) self.textLabel.text = "This means \n'begin journey'" self.progressBar.setProgress(0.2, animated: true) self.textLabel.accessibilityLabel = "This means begin journey" } func arrivedAtDestination() { self.textLabel.fadeTransition(0.5) self.textLabel.text = "This means \n'arrived at destination'" self.progressBar.setProgress(0.4, animated: true) self.textLabel.accessibilityLabel = "This means arrived at destination" } func wrongDirection() { self.textLabel.fadeTransition(0.5) self.textLabel.text = "This means \n'you're walking in the wrong direction'" self.progressBar.setProgress(0.6, animated: true) self.textLabel.accessibilityLabel = "This means you're walking in the wrong direction" } func turnRight() { self.textLabel.fadeTransition(0.5) self.textLabel.text = "This means \n'turn right'" self.progressBar.setProgress(0.8, animated: true) self.textLabel.accessibilityLabel = "This means turn right" } func turnLeft() { self.textLabel.fadeTransition(0.5) self.textLabel.text = "This means \n'turn left'" self.progressBar.setProgress(1.0, animated: true) self.textLabel.accessibilityLabel = "This means turn left" } func showDone() { self.textLabel.fadeTransition(0.5) self.textLabel.text = "You are all set!" UIView.animate(withDuration: 0.5, animations: {self.mainButton.alpha = 0.0}) self.progressBar.alpha = 0.0 self.textLabel.accessibilityLabel = "You are all set" } func nextPage() { let nextViewController = self.storyboard?.instantiateViewController(withIdentifier: "screen7") as! R7adyViewController nextViewController.modalTransitionStyle = .crossDissolve self.present(nextViewController, animated: true, completion: nil) } func audioPlay (fName: String) { let path = Bundle.main.path(forResource: fName, ofType : "mp3")! let url = URL(fileURLWithPath : path) do { player = try AVAudioPlayer(contentsOf: url) player.delegate = self player.play() } catch { debugPrint("Error in playing sound file \(fName).mp3") } } } extension UIView { func fadeTransition(_ duration:CFTimeInterval) { let animation = CATransition() animation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut) animation.type = CATransitionType.fade animation.duration = duration layer.add(animation, forKey: CATransitionType.fade.rawValue) } }