From 2f664712d0295430453ea73cebf9b86af516eefd Mon Sep 17 00:00:00 2001 From: 127-Z3R0 <81heti1bif@hft-stuttgart.de> Date: Thu, 25 Jun 2020 14:19:24 +0200 Subject: [PATCH] Add designated SettingsButton for ButtonNode-Visibility * modify EntityManager to add SettingsButton * implement Method to toggle Status on/off * in the ButtonNode make Label visible to change text after init --- GoldWars/GoldWars.xcodeproj/project.pbxproj | 4 ++++ GoldWars/GoldWars/Components/ButtonNode.swift | 11 ++++++----- GoldWars/GoldWars/Entities/EntityManager.swift | 9 +++++++++ GoldWars/GoldWars/Entities/SettingsButton.swift | 9 +++++++++ 4 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 GoldWars/GoldWars/Entities/SettingsButton.swift diff --git a/GoldWars/GoldWars.xcodeproj/project.pbxproj b/GoldWars/GoldWars.xcodeproj/project.pbxproj index bf2da7c..3bbb38a 100644 --- a/GoldWars/GoldWars.xcodeproj/project.pbxproj +++ b/GoldWars/GoldWars.xcodeproj/project.pbxproj @@ -50,6 +50,7 @@ AB671B252494ECF0003FBE8D /* EloHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB671B242494ECF0003FBE8D /* EloHelper.swift */; }; ABA03DA0244BD54F00A66916 /* Base.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABA03D9F244BD54F00A66916 /* Base.swift */; }; ABC0C3732481509300387B8F /* MapUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC0C3722481509300387B8F /* MapUtils.swift */; }; + C00791EC24A4C1090063E413 /* SettingsButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = C00791EB24A4C1090063E413 /* SettingsButton.swift */; }; C04783EE2468583F004961FB /* intro-music.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = C04783ED2468583F004961FB /* intro-music.mp3 */; }; C04783F024685995004961FB /* SettingsScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = C04783EF24685995004961FB /* SettingsScene.swift */; }; C05BB9C4247D890C00411249 /* SliderComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = C05BB9C3247D890C00411249 /* SliderComponent.swift */; }; @@ -119,6 +120,7 @@ AB671B242494ECF0003FBE8D /* EloHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EloHelper.swift; sourceTree = ""; }; ABA03D9F244BD54F00A66916 /* Base.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Base.swift; sourceTree = ""; }; ABC0C3722481509300387B8F /* MapUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapUtils.swift; sourceTree = ""; }; + C00791EB24A4C1090063E413 /* SettingsButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsButton.swift; sourceTree = ""; }; C04783ED2468583F004961FB /* intro-music.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = "intro-music.mp3"; sourceTree = ""; }; C04783EF24685995004961FB /* SettingsScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsScene.swift; sourceTree = ""; }; C05BB9C3247D890C00411249 /* SliderComponent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SliderComponent.swift; sourceTree = ""; }; @@ -239,6 +241,7 @@ 9EEDE02C246FCD770096C735 /* SpinningLogoEntity.swift */, 3E6785412472CBEC007B9DE4 /* Way.swift */, C064E9AB246C151F0022B228 /* Label.swift */, + C00791EB24A4C1090063E413 /* SettingsButton.swift */, ); path = Entities; sourceTree = ""; @@ -418,6 +421,7 @@ C064E9AA246C114C0022B228 /* LabelComponent.swift in Sources */, 3EBD242E245D9332003CECE7 /* Team.swift in Sources */, 9E174C88245DF1FF00209FF0 /* BackgroundComponent.swift in Sources */, + C00791EC24A4C1090063E413 /* SettingsButton.swift in Sources */, 9E78ACBA245CBDAF00526FF7 /* HUD.swift in Sources */, 9EC2FBA72476B1EC00ABF11F /* PlayerInfoComponent.swift in Sources */, 9EEDE02D246FCD770096C735 /* SpinningLogoEntity.swift in Sources */, 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..5856ccf 100644 --- a/GoldWars/GoldWars/Entities/EntityManager.swift +++ b/GoldWars/GoldWars/Entities/EntityManager.swift @@ -66,6 +66,10 @@ class EntityManager { scene.addChild(spinningLogoEntity.warsLetteringNode) } + if let settingsButtonEntity = entity as? SettingsButton { + scene.addChild(settingsButtonEntity.settingsButton) + } + if let wayEntity = entity as? Way { scene.addChild(wayEntity.localWayComponent) } @@ -293,6 +297,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 SettingsButton && ($0 as! SettingsButton).name == buttonName }[0] as! SettingsButton + button.settingsButton.label.text = text + } + func getHUD() -> HUD? { return entities.filter{$0 is HUD}.first as? HUD } diff --git a/GoldWars/GoldWars/Entities/SettingsButton.swift b/GoldWars/GoldWars/Entities/SettingsButton.swift new file mode 100644 index 0000000..fd5e628 --- /dev/null +++ b/GoldWars/GoldWars/Entities/SettingsButton.swift @@ -0,0 +1,9 @@ +// +// SettingsButton.swift +// GoldWars +// +// Created by Tim Herbst on 25.06.20. +// Copyright © 2020 SP2. All rights reserved. +// + +import Foundation