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
This commit is contained in:
127-Z3R0 2020-06-25 14:19:24 +02:00
parent 5d89636ebd
commit 2f664712d0
4 changed files with 28 additions and 5 deletions

View File

@ -50,6 +50,7 @@
AB671B252494ECF0003FBE8D /* EloHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB671B242494ECF0003FBE8D /* EloHelper.swift */; }; AB671B252494ECF0003FBE8D /* EloHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB671B242494ECF0003FBE8D /* EloHelper.swift */; };
ABA03DA0244BD54F00A66916 /* Base.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABA03D9F244BD54F00A66916 /* Base.swift */; }; ABA03DA0244BD54F00A66916 /* Base.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABA03D9F244BD54F00A66916 /* Base.swift */; };
ABC0C3732481509300387B8F /* MapUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC0C3722481509300387B8F /* MapUtils.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 */; }; C04783EE2468583F004961FB /* intro-music.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = C04783ED2468583F004961FB /* intro-music.mp3 */; };
C04783F024685995004961FB /* SettingsScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = C04783EF24685995004961FB /* SettingsScene.swift */; }; C04783F024685995004961FB /* SettingsScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = C04783EF24685995004961FB /* SettingsScene.swift */; };
C05BB9C4247D890C00411249 /* SliderComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = C05BB9C3247D890C00411249 /* SliderComponent.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 = "<group>"; }; AB671B242494ECF0003FBE8D /* EloHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EloHelper.swift; sourceTree = "<group>"; };
ABA03D9F244BD54F00A66916 /* Base.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Base.swift; sourceTree = "<group>"; }; ABA03D9F244BD54F00A66916 /* Base.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Base.swift; sourceTree = "<group>"; };
ABC0C3722481509300387B8F /* MapUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapUtils.swift; sourceTree = "<group>"; }; ABC0C3722481509300387B8F /* MapUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapUtils.swift; sourceTree = "<group>"; };
C00791EB24A4C1090063E413 /* SettingsButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsButton.swift; sourceTree = "<group>"; };
C04783ED2468583F004961FB /* intro-music.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = "intro-music.mp3"; sourceTree = "<group>"; }; C04783ED2468583F004961FB /* intro-music.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = "intro-music.mp3"; sourceTree = "<group>"; };
C04783EF24685995004961FB /* SettingsScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsScene.swift; sourceTree = "<group>"; }; C04783EF24685995004961FB /* SettingsScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsScene.swift; sourceTree = "<group>"; };
C05BB9C3247D890C00411249 /* SliderComponent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SliderComponent.swift; sourceTree = "<group>"; }; C05BB9C3247D890C00411249 /* SliderComponent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SliderComponent.swift; sourceTree = "<group>"; };
@ -239,6 +241,7 @@
9EEDE02C246FCD770096C735 /* SpinningLogoEntity.swift */, 9EEDE02C246FCD770096C735 /* SpinningLogoEntity.swift */,
3E6785412472CBEC007B9DE4 /* Way.swift */, 3E6785412472CBEC007B9DE4 /* Way.swift */,
C064E9AB246C151F0022B228 /* Label.swift */, C064E9AB246C151F0022B228 /* Label.swift */,
C00791EB24A4C1090063E413 /* SettingsButton.swift */,
); );
path = Entities; path = Entities;
sourceTree = "<group>"; sourceTree = "<group>";
@ -418,6 +421,7 @@
C064E9AA246C114C0022B228 /* LabelComponent.swift in Sources */, C064E9AA246C114C0022B228 /* LabelComponent.swift in Sources */,
3EBD242E245D9332003CECE7 /* Team.swift in Sources */, 3EBD242E245D9332003CECE7 /* Team.swift in Sources */,
9E174C88245DF1FF00209FF0 /* BackgroundComponent.swift in Sources */, 9E174C88245DF1FF00209FF0 /* BackgroundComponent.swift in Sources */,
C00791EC24A4C1090063E413 /* SettingsButton.swift in Sources */,
9E78ACBA245CBDAF00526FF7 /* HUD.swift in Sources */, 9E78ACBA245CBDAF00526FF7 /* HUD.swift in Sources */,
9EC2FBA72476B1EC00ABF11F /* PlayerInfoComponent.swift in Sources */, 9EC2FBA72476B1EC00ABF11F /* PlayerInfoComponent.swift in Sources */,
9EEDE02D246FCD770096C735 /* SpinningLogoEntity.swift in Sources */, 9EEDE02D246FCD770096C735 /* SpinningLogoEntity.swift in Sources */,

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

@ -66,6 +66,10 @@ class EntityManager {
scene.addChild(spinningLogoEntity.warsLetteringNode) scene.addChild(spinningLogoEntity.warsLetteringNode)
} }
if let settingsButtonEntity = entity as? SettingsButton {
scene.addChild(settingsButtonEntity.settingsButton)
}
if let wayEntity = entity as? Way { if let wayEntity = entity as? Way {
scene.addChild(wayEntity.localWayComponent) scene.addChild(wayEntity.localWayComponent)
} }
@ -293,6 +297,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 SettingsButton && ($0 as! SettingsButton).name == buttonName }[0] as! SettingsButton
button.settingsButton.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

@ -0,0 +1,9 @@
//
// SettingsButton.swift
// GoldWars
//
// Created by Tim Herbst on 25.06.20.
// Copyright © 2020 SP2. All rights reserved.
//
import Foundation