diff --git a/TowerForge/TowerForge/GameModule/GameWorld.swift b/TowerForge/TowerForge/GameModule/GameWorld.swift index 5fc6f616..c25cbb91 100644 --- a/TowerForge/TowerForge/GameModule/GameWorld.swift +++ b/TowerForge/TowerForge/GameModule/GameWorld.swift @@ -22,6 +22,7 @@ class GameWorld { private let worldBounds: CGRect unowned var delegate: SceneManagerDelegate? + unowned var statePopupDelegate: StatePopupDelegate? init(scene: GameScene?, screenSize: CGRect, mode: Mode, gameRoom: GameRoom? = nil, currentPlayer: GamePlayer? = nil) { @@ -94,7 +95,7 @@ class GameWorld { func presentStatePopup() { let popup = StatePopupNode() - popup.delegate = self + popup.delegate = statePopupDelegate // TODO: Refactor this popup.zPosition = 10_000 popup.name = "popup" @@ -115,15 +116,3 @@ extension GameWorld: UnitSelectionNodeDelegate { position: position, player: .ownPlayer)) } } - -// TODO: Fill the function -extension GameWorld: StatePopupDelegate { - func onMenu() { - // - } - - func onResume() { - // - } - -} diff --git a/TowerForge/TowerForge/GameViewController.swift b/TowerForge/TowerForge/GameViewController.swift index 6428900f..a7661b6f 100644 --- a/TowerForge/TowerForge/GameViewController.swift +++ b/TowerForge/TowerForge/GameViewController.swift @@ -10,10 +10,12 @@ import SpriteKit class GameViewController: UIViewController { private var gameWorld: GameWorld? var gameMode: Mode? + var isPaused = false var gameRoom: GameRoom? var currentPlayer: GamePlayer? @IBAction private func onStatePressed(_ sender: Any) { + isPaused = true gameWorld?.presentStatePopup() } @@ -47,6 +49,7 @@ class GameViewController: UIViewController { mode: self.gameMode ?? .captureTheFlag, gameRoom: gameRoom, currentPlayer: currentPlayer) self.gameWorld?.delegate = self + self.gameWorld?.statePopupDelegate = self } } @@ -81,6 +84,7 @@ extension GameViewController: SceneManagerDelegate { // Present the scene gameScene.sceneManagerDelegate = self gameScene.updateDelegate = self + gameScene.statePopupDelegate = self showScene(scene: gameScene) setUpGameWorld(scene: gameScene) } @@ -95,3 +99,12 @@ extension GameViewController: SceneManagerDelegate { } } } + +extension GameViewController: StatePopupDelegate { + func onMenu() { + } + + func onResume() { + isPaused = false + } +} diff --git a/TowerForge/TowerForge/Nodes/StatePopupNode.swift b/TowerForge/TowerForge/Nodes/StatePopupNode.swift index 4caee868..541d378f 100644 --- a/TowerForge/TowerForge/Nodes/StatePopupNode.swift +++ b/TowerForge/TowerForge/Nodes/StatePopupNode.swift @@ -9,6 +9,7 @@ import Foundation import UIKit protocol StatePopupDelegate: AnyObject { + var isPaused: Bool { get } func onMenu() func onResume() } diff --git a/TowerForge/TowerForge/Scenes/GameScene.swift b/TowerForge/TowerForge/Scenes/GameScene.swift index 19f313d5..91419eaa 100644 --- a/TowerForge/TowerForge/Scenes/GameScene.swift +++ b/TowerForge/TowerForge/Scenes/GameScene.swift @@ -11,6 +11,7 @@ import GameplayKit class GameScene: SKScene { unowned var updateDelegate: SceneUpdateDelegate? unowned var sceneManagerDelegate: SceneManagerDelegate? + unowned var statePopupDelegate: StatePopupDelegate? private var lastUpdatedTimeInterval = TimeInterval(0) private var cameraNode: TFCameraNode? private var isPan = false @@ -21,11 +22,17 @@ class GameScene: SKScene { } override func touchesBegan(_ touches: Set, with event: UIEvent?) { + if statePopupDelegate?.isPaused ?? false { + return + } super.touchesBegan(touches, with: event) isPan = false } override func touchesEnded(_ touches: Set, with event: UIEvent?) { + if statePopupDelegate?.isPaused ?? false { + return + } super.touchesEnded(touches, with: event) guard let touch = touches.first else { return @@ -39,6 +46,9 @@ class GameScene: SKScene { } override func touchesMoved(_ touches: Set, with event: UIEvent?) { + if statePopupDelegate?.isPaused ?? false { + return + } super.touchesMoved(touches, with: event) guard let touch = touches.first else { return @@ -55,6 +65,9 @@ class GameScene: SKScene { } override func update(_ currentTime: TimeInterval) { + if statePopupDelegate?.isPaused ?? false { + return + } if lastUpdatedTimeInterval == TimeInterval(0) { lastUpdatedTimeInterval = currentTime }