// // NuovaPartitaController.swift // spotTheSpy // // Created by Paolo Alberti on 11/05/18. // Copyright © 2018 Paolo. All rights reserved. // import UIKit class NuovaPartitaController: UIViewController, BWWalkthroughViewControllerDelegate { @IBOutlet var sfondoView: UIImageView! @IBOutlet var mainView: UIView! @IBOutlet var viewDesc: UIView! @IBOutlet var viewConfig: UIView! @IBOutlet var playerAdd: UIButton! @IBOutlet var playerRem: UIButton! @IBOutlet var playerCount: UILabel! @IBOutlet var spyCount: UILabel! @IBOutlet var minuteAdd: UIButton! @IBOutlet var minuteRem: UIButton! @IBOutlet var minuteCount: UILabel! @IBOutlet var graphicSel: UISegmentedControl! @IBOutlet var iniziaBtn: UIButton! @IBOutlet var locationBtn: UIButton! @IBOutlet var regoleBtn: UIButton! @IBOutlet var descLabel: UILabel! @IBOutlet var giocatoriLabel: UILabel! @IBOutlet var spieLabel: UILabel! @IBOutlet var durataLabel: UILabel! @IBOutlet var immaginiLabel: UILabel! override func viewDidLoad() { super.viewDidLoad() DataManager.shared.NuovaPartitaC = self DataManager.shared.cambiaStile(stile: DataManager.shared.stileGrafica) DataManager.shared.rimuoviNotifiche() viewDesc.cornerRadius = 5 viewDesc.applyGradient(colours: [grigio, UIColor.white]) viewDesc.borderWidth = 2 viewDesc.borderColor = grigioscuro2 viewConfig.cornerRadius = 5 viewConfig.applyGradient(colours: [grigio, UIColor.white]) viewConfig.borderWidth = 2 viewConfig.borderColor = grigioscuro2 iniziaBtn.cornerRadius = 5 iniziaBtn.applyGradient(colours: [bluscuro, blu]) iniziaBtn.borderWidth = 2 iniziaBtn.borderColor = grigio locationBtn.cornerRadius = 5 locationBtn.applyGradient(colours: [bluscuro, blu]) locationBtn.borderWidth = 2 locationBtn.borderColor = grigio regoleBtn.cornerRadius = 5 regoleBtn.applyGradient(colours: [bluscuro, blu]) regoleBtn.borderWidth = 2 regoleBtn.borderColor = grigio graphicSel.backgroundColor = .clear graphicSel.tintColor = .clear graphicSel.setTitleTextAttributes([NSAttributedStringKey.font : UIFont(name: fontBurbank, size: 18)!, NSAttributedStringKey.foregroundColor: UIColor.lightGray], for: .normal) graphicSel.setTitleTextAttributes([NSAttributedStringKey.font : UIFont(name: fontBurbank, size: 18)!, NSAttributedStringKey.foregroundColor: UIColor.orange], for: .selected) descLabel.text = NSLocalizedString("Desc_config", comment: "") giocatoriLabel.text = NSLocalizedString("Numero Giocatori", comment: "") spieLabel.text = NSLocalizedString("Numero Spie", comment: "") durataLabel.text = NSLocalizedString("Durata partita", comment: "") immaginiLabel.text = NSLocalizedString("Stile immagini", comment: "") iniziaBtn.setTitle(NSLocalizedString("Inizia", comment: ""), for: .normal) locationBtn.setTitle(NSLocalizedString("Locations", comment: ""), for: .normal) regoleBtn.setTitle(NSLocalizedString("Regole", comment: ""), for: .normal) // Carico le impostazioni generali della Partita switch DataManager.shared.stileGrafica { case "a": self.graphicSel.selectedSegmentIndex = 0 case "b": self.graphicSel.selectedSegmentIndex = 1 case "c": self.graphicSel.selectedSegmentIndex = 2 default: break } self.playerCount.text = String(DataManager.shared.nGiocatori) self.spyCount.text = String(DataManager.shared.nSpie) self.minuteCount.text = String(DataManager.shared.nMinuti) // Ridimensiono la schermata delle Opzioni per i diversi Device (NON uso l'Auto Layout) var scale = self.view.frame.size.width/414 if (UIDevice.current.userInterfaceIdiom == .pad) { scale = self.view.frame.size.height/736 } mainView.transform = CGAffineTransform(scaleX: scale, y: scale) } @IBAction func iniziaPartita(_ sender: UIButton) { Sound.play(file: "click.mp3") DataManager.shared.lightGen.impactOccurred() DataManager.shared.avviaPartita() DataManager.shared.salvaImpostazioni() performSegue(withIdentifier: "newGame", sender: sender) } @IBAction func addPlayer(_ sender: Any) { DataManager.shared.lightGen.impactOccurred() DataManager.shared.nGiocatori += 1 self.playerCount.text = String(DataManager.shared.nGiocatori) if DataManager.shared.nGiocatori > DataManager.shared.nMinuti { DataManager.shared.nMinuti += 1 self.minuteCount.text = String(DataManager.shared.nMinuti) } DataManager.shared.nSpie = Int(ceil(Double(DataManager.shared.nGiocatori) / Double(DataManager.shared.modSpie))) self.spyCount.text = String(DataManager.shared.nSpie) } @IBAction func remPlayer(_ sender: Any) { DataManager.shared.lightGen.impactOccurred() // Se non sono ancora sceso sotto la soglia del numero minimo di giocatori (3) if DataManager.shared.nGiocatori > DataManager.shared.minGiocatori { DataManager.shared.nGiocatori -= 1 self.playerCount.text = String(DataManager.shared.nGiocatori) if DataManager.shared.nGiocatori < DataManager.shared.nMinuti && DataManager.shared.nMinuti > DataManager.shared.minMinuti { DataManager.shared.nMinuti -= 1 self.minuteCount.text = String(DataManager.shared.nMinuti) } } DataManager.shared.nSpie = Int(ceil(Double(DataManager.shared.nGiocatori) / Double(DataManager.shared.modSpie))) self.spyCount.text = String(DataManager.shared.nSpie) } @IBAction func addMinute(_ sender: Any) { DataManager.shared.lightGen.impactOccurred() DataManager.shared.nMinuti += 1 self.minuteCount.text = String(DataManager.shared.nMinuti) } @IBAction func remMinute(_ sender: Any) { DataManager.shared.lightGen.impactOccurred() if DataManager.shared.nMinuti > DataManager.shared.minMinuti { DataManager.shared.nMinuti -= 1 self.minuteCount.text = String(DataManager.shared.nMinuti) } } @IBAction func selStyle(_ sender: UISegmentedControl) { DataManager.shared.lightGen.impactOccurred() switch self.graphicSel.selectedSegmentIndex { case 0: DataManager.shared.cambiaStile(stile: "a"); case 1: DataManager.shared.cambiaStile(stile: "b"); case 2: DataManager.shared.cambiaStile(stile: "c"); default: break } } @IBAction func showLoc(_ sender: UIButton) { DataManager.shared.lightGen.impactOccurred() Sound.play(file: "page") } @IBAction func mostraRegole(_ sender: UIButton) { mostraWalkthrough() } func mostraWalkthrough() { // Get view controllers and build the walkthrough let stb = UIStoryboard(name: "Main", bundle: nil) let walkthrough = stb.instantiateViewController(withIdentifier: "container") as! BWWalkthroughViewController let page_uno = stb.instantiateViewController(withIdentifier: "tut1") //let pag_due = stb.instantiateViewController(withIdentifier: "tut2") let page_tre = stb.instantiateViewController(withIdentifier: "tut3") let page_quattro = stb.instantiateViewController(withIdentifier: "tut4") let page_cinque = stb.instantiateViewController(withIdentifier: "tut5") let page_sei = stb.instantiateViewController(withIdentifier: "tut6") // Attach the pages to the master walkthrough.delegate = self walkthrough.add(viewController:page_uno) //walkthrough.add(viewController:pag_due) walkthrough.add(viewController:page_tre) walkthrough.add(viewController:page_quattro) walkthrough.add(viewController:page_cinque) walkthrough.add(viewController:page_sei) self.present(walkthrough, animated: true, completion: nil) } func walkthroughCloseButtonPressed() { self.dismiss(animated: true, completion: nil) } }