Merge branch '82-status-eines-jeweiligen-settings-sollte-in-den-settings-erkennbar-sein' into 'development'

Resolve "Status eines jeweiligen Settings sollte in den Settings erkennbar sein"

Closes #82

See merge request marcel.schwarz/software-projekt-2!132
This commit is contained in:
Aldin Duraki 2020-06-25 12:44:52 +00:00
commit 26b3b13459
4 changed files with 25 additions and 8 deletions

View File

@ -21,17 +21,15 @@ class ButtonNode: SKSpriteNode {
} }
} }
} }
var label: SKLabelNode
var onButtonPress: () -> () var onButtonPress: () -> ()
init(textureName: String, text: String, isEnabled: Bool, position: CGPoint, onButtonPress: @escaping () -> ()) { init(textureName: String, text: String, isEnabled: Bool, position: CGPoint, onButtonPress: @escaping () -> ()) {
self.onButtonPress = onButtonPress self.onButtonPress = onButtonPress
self.isEnabled = isEnabled self.isEnabled = isEnabled
let texture = SKTexture(imageNamed: textureName) 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.fontSize = 30
label.fontColor = SKColor.black label.fontColor = SKColor.black
label.zPosition = 1 label.zPosition = 1
@ -39,6 +37,9 @@ class ButtonNode: SKSpriteNode {
label.text = text label.text = text
label.name = "label" label.name = "label"
super.init(texture: texture, color: SKColor.white, size: texture.size())
self.position = position
self.addChild(label) self.addChild(label)
isUserInteractionEnabled = true isUserInteractionEnabled = true
} }

View File

@ -293,6 +293,11 @@ class EntityManager {
return entities.filter{$0 is Button && ($0 as! Button).name == buttonName }[0] as! Button 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? { func getHUD() -> HUD? {
return entities.filter{$0 is HUD}.first as? HUD return entities.filter{$0 is HUD}.first as? HUD
} }

View File

@ -11,11 +11,14 @@ import SpriteKit
class SettingsScene: SKScene { class SettingsScene: SKScene {
var entityManager = EntityManager.settingsEMInstance var entityManager = EntityManager.settingsEMInstance
var musicButtonText = ""
var isMusicDeactivatedByUserDefault = UserDefaults.standard.bool(forKey: "noMusic")
override func sceneDidLoad() { override func sceneDidLoad() {
entityManager.setScene(scene: self) entityManager.setScene(scene: self)
let positionX = self.size.width * 0.1 let positionX = self.size.width * 0.1
let positionY = self.size.height * 0.05 let positionY = self.size.height * 0.05
isMusicDeactivatedByUserDefault ? setMusicButtonTextByUserDefault(text: "OFF") : setMusicButtonTextByUserDefault(text: "ON")
entityManager.add(Button(name: "backToMenuScene", entityManager.add(Button(name: "backToMenuScene",
textureName: "yellow_button04", textureName: "yellow_button04",
text: "Back", text: "Back",
@ -26,26 +29,30 @@ class SettingsScene: SKScene {
})) }))
entityManager.add(Button(name: "StopMenuMusic", entityManager.add(Button(name: "StopMenuMusic",
textureName: "yellow_button04", textureName: "yellow_button04",
text: "ON/OFF", text: musicButtonText,
position: CGPoint(x: self.size.width * 0.6, y: self.size.height / 2), position: CGPoint(x: self.size.width * 0.6, y: self.size.height / 2),
onButtonPress: { onButtonPress: {
if SoundManager.sharedInstance.isMusicPlaying { if SoundManager.sharedInstance.isMusicPlaying {
SoundManager.sharedInstance.stopMenuMusic() SoundManager.sharedInstance.stopMenuMusic()
SoundManager.sharedInstance.isMusicEnabled = false SoundManager.sharedInstance.isMusicEnabled = false
self.entityManager.changeSettingsButtonText(buttonName: "StopMenuMusic", text: "OFF")
} else { } else {
SoundManager.sharedInstance.isMusicEnabled = true SoundManager.sharedInstance.isMusicEnabled = true
SoundManager.sharedInstance.startMenuMusic() SoundManager.sharedInstance.startMenuMusic()
self.entityManager.changeSettingsButtonText(buttonName: "StopMenuMusic", text: "ON")
} }
})) }))
entityManager.add(Button(name: "StopMovingBackground", entityManager.add(Button(name: "StopMovingBackground",
textureName: "yellow_button04", textureName: "yellow_button04",
text: "MOVE/STOP", text: "MOVE",
position: CGPoint(x: self.size.width * 0.6, y: self.size.height / 2 - 100), position: CGPoint(x: self.size.width * 0.6, y: self.size.height / 2 - 100),
onButtonPress: { onButtonPress: {
if BackgroundComponent.isMovingBackgroundEnabled { if BackgroundComponent.isMovingBackgroundEnabled {
BackgroundComponent.isMovingBackgroundEnabled = false BackgroundComponent.isMovingBackgroundEnabled = false
self.entityManager.changeSettingsButtonText(buttonName: "StopMovingBackground", text: "STOP")
} else { } else {
BackgroundComponent.isMovingBackgroundEnabled = true BackgroundComponent.isMovingBackgroundEnabled = true
self.entityManager.changeSettingsButtonText(buttonName: "StopMovingBackground", text: "MOVE")
} }
})) }))
entityManager.add(Label(fontnamed: "Courier-Bold", entityManager.add(Label(fontnamed: "Courier-Bold",
@ -83,6 +90,10 @@ class SettingsScene: SKScene {
entityManager.add(Background(size: self.size)) entityManager.add(Background(size: self.size))
} }
func setMusicButtonTextByUserDefault(text: String) {
self.musicButtonText = text
}
func loadScene(scene: SKScene) { func loadScene(scene: SKScene) {
let transition = SKTransition.flipVertical(withDuration: 0.5) let transition = SKTransition.flipVertical(withDuration: 0.5)
entityManager.entities.removeAll() entityManager.entities.removeAll()

View File

@ -27,7 +27,7 @@ class SoundManager {
do { do {
audioPlayer = try AVAudioPlayer(contentsOf: backgroundMainMenuAudio!) audioPlayer = try AVAudioPlayer(contentsOf: backgroundMainMenuAudio!)
} catch { } catch {
//TODO: Add logging os_log("backgroundMusic is broken", log: LOG, type: .error)
} }
audioPlayer.numberOfLoops = -1 audioPlayer.numberOfLoops = -1
audioPlayer.prepareToPlay() audioPlayer.prepareToPlay()