From c14731dff6014d3eed69fec85fdeaab5653ecbf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chauntalle=20Schu=CC=88le?= Date: Thu, 14 May 2020 14:06:44 +0200 Subject: [PATCH] Adding Button to ModalEinheiten, you can now exit via Button and not anymore via Slider --- GoldWars/GoldWars/Entities/Modal.swift | 59 +++++++++++++----------- GoldWars/GoldWars/Scenes/GameScene.swift | 11 +++-- 2 files changed, 39 insertions(+), 31 deletions(-) diff --git a/GoldWars/GoldWars/Entities/Modal.swift b/GoldWars/GoldWars/Entities/Modal.swift index cdafa53..8796202 100644 --- a/GoldWars/GoldWars/Entities/Modal.swift +++ b/GoldWars/GoldWars/Entities/Modal.swift @@ -9,31 +9,38 @@ import GameplayKit class Modal: GKEntity{ - - var unitCount:Int - init(modaltype: ModalType, base: Base, anchorPoint: CGPoint) { - unitCount = base.unitCount - super.init() - switch modaltype{ - case .BaseDetails: - addComponent(ModalBackgroundComponent(anchorPoint: anchorPoint)) - addComponent(ModalContentComponent(header: "Basis Information", - body: "Diese Basis enthält \(base.unitCount) Einheiten", - footer: "", - anchorPoint: anchorPoint)) - case .BaseAttack: - addComponent(ModalBackgroundComponent(anchorPoint: anchorPoint)) - addComponent(SliderComponent(width: 300, position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 80))) - addComponent(ModalContentComponent(header: "Angriff", - body: "Schicke \(unitCount / 2) Einheiten", - footer: "", - anchorPoint: anchorPoint)) - } - } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - + var unitCount:Int + var modalEntityManager: EntityManager + + init(modaltype: ModalType, base: Base, anchorPoint: CGPoint, entityManager: EntityManager) { + unitCount = base.unitCount + modalEntityManager = entityManager + super.init() + switch modaltype{ + case .BaseDetails: + addComponent(ModalBackgroundComponent(anchorPoint: anchorPoint)) + addComponent(ModalContentComponent(header: "Basis Information", body: "Diese Basis enthält \(base.unitCount) Einheiten", footer: "", anchorPoint: anchorPoint)) + case .BaseAttack: + addComponent(ModalBackgroundComponent(anchorPoint: anchorPoint)) + addComponent(SliderComponent(width: 300, position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 50))) + addComponent(ModalContentComponent(header: "Angriff", body: "Schicke \(unitCount / 2) Einheiten", + footer: "", anchorPoint: anchorPoint)) + addComponent(ButtonComponent(iconName: "", text: "Senden", position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 120), isEnabled: true, onButtonPress: { + self.removeModalEntities(entityManager: self.modalEntityManager) + })) + } + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + func removeModalEntities(entityManager: EntityManager){ + for entity in entityManager.entities { + if entityManager.isModal && entity.isMember(of: Modal.self) { + entityManager.remove(entity) + } + } + } } diff --git a/GoldWars/GoldWars/Scenes/GameScene.swift b/GoldWars/GoldWars/Scenes/GameScene.swift index b306854..b191ade 100644 --- a/GoldWars/GoldWars/Scenes/GameScene.swift +++ b/GoldWars/GoldWars/Scenes/GameScene.swift @@ -46,12 +46,12 @@ class GameScene: SKScene{ if !(entityManager.getTeamByBase(base: currentDraggedBase!) == entityManager.getTeamByBase(base: base)){ entityManager.add(Modal(modaltype: .BaseAttack, base: currentDraggedBase!, - anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2))) + anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), entityManager: entityManager)) entityManager.update((currentDraggedBase?.attackBase(base: base, units: 100))!) }else { entityManager.add(Modal(modaltype: .BaseAttack, base: currentDraggedBase!, - anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2))) + anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), entityManager: entityManager)) } } @@ -60,15 +60,16 @@ class GameScene: SKScene{ else { for entity in entityManager.entities { let spriteNode = entity.component(ofType: DefaultBaseComponent.self)?.spriteNode - + if entityManager.isModal && entity.isMember(of: Modal.self) { - entityManager.remove(entity) + // entityManager.remove(entity) for child in self.children { if(child.name != "fire"){ child.alpha = 1 } } } + if atPoint(touchLocation) == spriteNode && !entityManager.isModal { spriteNode?.touchesBegan(touches, with: event) @@ -80,7 +81,7 @@ class GameScene: SKScene{ } entityManager.add(Modal(modaltype: .BaseDetails, base: entity as! Base, - anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2))) + anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), entityManager: entityManager)) } } }