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: () -> ()
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
}

View File

@ -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
}

View File

@ -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()

View File

@ -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()