diff --git a/GoldWars/GoldWars/Components/ButtonNode.swift b/GoldWars/GoldWars/Components/ButtonNode.swift index b98164a..8129fa9 100644 --- a/GoldWars/GoldWars/Components/ButtonNode.swift +++ b/GoldWars/GoldWars/Components/ButtonNode.swift @@ -21,17 +21,15 @@ class ButtonNode: SKSpriteNode { } } } - + var label: SKLabelNode var onButtonPress: () -> () init(textureName: String, text: String, isEnabled: Bool, position: CGPoint, onButtonPress: @escaping () -> ()) { self.onButtonPress = onButtonPress self.isEnabled = isEnabled let texture = SKTexture(imageNamed: textureName) - super.init(texture: texture, color: SKColor.white, size: texture.size()) - self.position = position - - let label = SKLabelNode(fontNamed: "Courier-Bold") + + label = SKLabelNode(fontNamed: "Courier-Bold") label.fontSize = 30 label.fontColor = SKColor.black label.zPosition = 1 @@ -39,6 +37,9 @@ class ButtonNode: SKSpriteNode { label.text = text label.name = "label" + super.init(texture: texture, color: SKColor.white, size: texture.size()) + self.position = position + self.addChild(label) isUserInteractionEnabled = true } diff --git a/GoldWars/GoldWars/Entities/EntityManager.swift b/GoldWars/GoldWars/Entities/EntityManager.swift index 375bbb2..0621bf1 100644 --- a/GoldWars/GoldWars/Entities/EntityManager.swift +++ b/GoldWars/GoldWars/Entities/EntityManager.swift @@ -293,6 +293,11 @@ class EntityManager { return entities.filter{$0 is Button && ($0 as! Button).name == buttonName }[0] as! Button } + func changeSettingsButtonText(buttonName: String, text: String) { + let button = entities.filter{$0 is Button && ($0 as! Button).name == buttonName }[0] as! Button + button.component(ofType: ButtonComponent.self)?.buttonNode.label.text = text + } + func getHUD() -> HUD? { return entities.filter{$0 is HUD}.first as? HUD } diff --git a/GoldWars/GoldWars/SettingsScene.swift b/GoldWars/GoldWars/SettingsScene.swift index 2e0760d..b408c84 100644 --- a/GoldWars/GoldWars/SettingsScene.swift +++ b/GoldWars/GoldWars/SettingsScene.swift @@ -11,11 +11,14 @@ import SpriteKit class SettingsScene: SKScene { var entityManager = EntityManager.settingsEMInstance + var musicButtonText = "" + var isMusicDeactivatedByUserDefault = UserDefaults.standard.bool(forKey: "noMusic") override func sceneDidLoad() { entityManager.setScene(scene: self) let positionX = self.size.width * 0.1 let positionY = self.size.height * 0.05 + isMusicDeactivatedByUserDefault ? setMusicButtonTextByUserDefault(text: "OFF") : setMusicButtonTextByUserDefault(text: "ON") entityManager.add(Button(name: "backToMenuScene", textureName: "yellow_button04", text: "Back", @@ -26,26 +29,30 @@ class SettingsScene: SKScene { })) entityManager.add(Button(name: "StopMenuMusic", textureName: "yellow_button04", - text: "ON/OFF", + text: musicButtonText, position: CGPoint(x: self.size.width * 0.6, y: self.size.height / 2), onButtonPress: { if SoundManager.sharedInstance.isMusicPlaying { SoundManager.sharedInstance.stopMenuMusic() SoundManager.sharedInstance.isMusicEnabled = false + self.entityManager.changeSettingsButtonText(buttonName: "StopMenuMusic", text: "OFF") } else { SoundManager.sharedInstance.isMusicEnabled = true SoundManager.sharedInstance.startMenuMusic() + self.entityManager.changeSettingsButtonText(buttonName: "StopMenuMusic", text: "ON") } })) entityManager.add(Button(name: "StopMovingBackground", textureName: "yellow_button04", - text: "MOVE/STOP", + text: "MOVE", position: CGPoint(x: self.size.width * 0.6, y: self.size.height / 2 - 100), onButtonPress: { if BackgroundComponent.isMovingBackgroundEnabled { BackgroundComponent.isMovingBackgroundEnabled = false + self.entityManager.changeSettingsButtonText(buttonName: "StopMovingBackground", text: "STOP") } else { BackgroundComponent.isMovingBackgroundEnabled = true + self.entityManager.changeSettingsButtonText(buttonName: "StopMovingBackground", text: "MOVE") } })) entityManager.add(Label(fontnamed: "Courier-Bold", @@ -83,6 +90,10 @@ class SettingsScene: SKScene { entityManager.add(Background(size: self.size)) } + func setMusicButtonTextByUserDefault(text: String) { + self.musicButtonText = text + } + func loadScene(scene: SKScene) { let transition = SKTransition.flipVertical(withDuration: 0.5) entityManager.entities.removeAll() diff --git a/GoldWars/GoldWars/SoundManager.swift b/GoldWars/GoldWars/SoundManager.swift index 55b7037..fc39933 100644 --- a/GoldWars/GoldWars/SoundManager.swift +++ b/GoldWars/GoldWars/SoundManager.swift @@ -27,7 +27,7 @@ class SoundManager { do { audioPlayer = try AVAudioPlayer(contentsOf: backgroundMainMenuAudio!) } catch { - //TODO: Add logging + os_log("backgroundMusic is broken", log: LOG, type: .error) } audioPlayer.numberOfLoops = -1 audioPlayer.prepareToPlay()