From a78b9269c0dd603dbe29247f5600cddfa8a6d0a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chauntalle=20Schu=CC=88le?= Date: Thu, 14 May 2020 14:04:25 +0200 Subject: [PATCH 1/5] Adding modalButton to Entity Manager --- GoldWars/GoldWars/Entities/EntityManager.swift | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/GoldWars/GoldWars/Entities/EntityManager.swift b/GoldWars/GoldWars/Entities/EntityManager.swift index 0f7166c..6c92437 100644 --- a/GoldWars/GoldWars/Entities/EntityManager.swift +++ b/GoldWars/GoldWars/Entities/EntityManager.swift @@ -30,7 +30,7 @@ class EntityManager { } if let spriteNode = entity.component(ofType: ModalBackgroundComponent.self)?.spriteNode { scene.addChild(spriteNode) - isModal = true + //isModal = true } if let modal = entity.component(ofType: ModalContentComponent.self) { scene.addChild(modal.header) @@ -54,6 +54,7 @@ class EntityManager { } if let buttonNode = entity.component(ofType: ButtonComponent.self)?.buttonNode { scene.addChild(buttonNode) + isModal = true } if let nodes = entity.component(ofType: BackgroundComponent.self)?.nodes { for node in nodes { @@ -72,7 +73,7 @@ class EntityManager { } if let spriteNode = entity.component(ofType: ModalBackgroundComponent.self)?.spriteNode { spriteNode.removeFromParent() - isModal = false + //isModal = false } if let modal = entity.component(ofType: ModalContentComponent.self) { modal.header.removeFromParent() @@ -83,6 +84,10 @@ class EntityManager { sliderNode.sliderKnob.removeFromParent() sliderNode.sliderLine.removeFromParent() } + if let modalButton = entity.component(ofType: ButtonComponent.self) { + modalButton.buttonNode.removeFromParent() + isModal = false + } entities.remove(entity) } 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 2/5] 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)) } } } From 5feb8318735c5e62473fd72d611f9bde043992ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chauntalle=20Schu=CC=88le?= Date: Thu, 14 May 2020 14:09:45 +0200 Subject: [PATCH 3/5] =?UTF-8?q?Bug:=20couldn't=20exit=20Modal=20showing=20?= =?UTF-8?q?Basis=20Informationen,=20now=20possible=20through=20Button=20zu?= =?UTF-8?q?ru=CC=88ck?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GoldWars/GoldWars/Entities/Modal.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/GoldWars/GoldWars/Entities/Modal.swift b/GoldWars/GoldWars/Entities/Modal.swift index 8796202..ca588ad 100644 --- a/GoldWars/GoldWars/Entities/Modal.swift +++ b/GoldWars/GoldWars/Entities/Modal.swift @@ -21,6 +21,9 @@ class Modal: GKEntity{ case .BaseDetails: addComponent(ModalBackgroundComponent(anchorPoint: anchorPoint)) addComponent(ModalContentComponent(header: "Basis Information", body: "Diese Basis enthält \(base.unitCount) Einheiten", footer: "", anchorPoint: anchorPoint)) + addComponent(ButtonComponent(iconName: "", text: "Zurück", position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 120), isEnabled: true, onButtonPress: { + self.removeModalEntities(entityManager: self.modalEntityManager) + })) case .BaseAttack: addComponent(ModalBackgroundComponent(anchorPoint: anchorPoint)) addComponent(SliderComponent(width: 300, position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 50))) From 8342c2e550aa79a2121682fda175ff571315e220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chauntalle=20Schu=CC=88le?= Date: Thu, 14 May 2020 14:23:44 +0200 Subject: [PATCH 4/5] Bug fixed: gameScene blieb nach beenden der Anzeige von Modal Basis Informationen dunkel --- GoldWars/GoldWars/Entities/Modal.swift | 15 ++-- GoldWars/GoldWars/Scenes/GameScene.swift | 94 +++++++++++------------- 2 files changed, 51 insertions(+), 58 deletions(-) diff --git a/GoldWars/GoldWars/Entities/Modal.swift b/GoldWars/GoldWars/Entities/Modal.swift index ca588ad..516efb0 100644 --- a/GoldWars/GoldWars/Entities/Modal.swift +++ b/GoldWars/GoldWars/Entities/Modal.swift @@ -11,18 +11,16 @@ import GameplayKit class Modal: GKEntity{ var unitCount:Int - var modalEntityManager: EntityManager - init(modaltype: ModalType, base: Base, anchorPoint: CGPoint, entityManager: EntityManager) { + init(modaltype: ModalType, base: Base, anchorPoint: CGPoint, entityManager: EntityManager, gameScene: SKScene) { 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)) addComponent(ButtonComponent(iconName: "", text: "Zurück", position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 120), isEnabled: true, onButtonPress: { - self.removeModalEntities(entityManager: self.modalEntityManager) + self.removeModalEntities(entityManager: entityManager, gameScene: gameScene) })) case .BaseAttack: addComponent(ModalBackgroundComponent(anchorPoint: anchorPoint)) @@ -30,7 +28,7 @@ class Modal: GKEntity{ 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) + self.removeModalEntities(entityManager: entityManager, gameScene: gameScene) })) } } @@ -39,11 +37,16 @@ class Modal: GKEntity{ fatalError("init(coder:) has not been implemented") } - func removeModalEntities(entityManager: EntityManager){ + func removeModalEntities(entityManager: EntityManager, gameScene: SKScene){ for entity in entityManager.entities { if entityManager.isModal && entity.isMember(of: Modal.self) { entityManager.remove(entity) } + for child in gameScene.children { + if(child.name != "fire"){ + child.alpha = 1 + } + } } } } diff --git a/GoldWars/GoldWars/Scenes/GameScene.swift b/GoldWars/GoldWars/Scenes/GameScene.swift index b191ade..bb47730 100644 --- a/GoldWars/GoldWars/Scenes/GameScene.swift +++ b/GoldWars/GoldWars/Scenes/GameScene.swift @@ -22,55 +22,45 @@ class GameScene: SKScene{ entityManager.add(Background(size: self.size)) initMap() } - + func initMap() { MapFactory(scene: self, entityManager: self.entityManager).loadMap(playerCount: 2) } - + override func touchesEnded(_ touches: Set, with event: UIEvent?) { guard let touch = touches.first else { return } - + let touchLocation = touch.location(in: self) - - if isMoveTouch{ - isMoveTouch = false + + if isMoveTouch{ + isMoveTouch = false currentDraggedBase!.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = currentDraggedBasePos currentDraggedBase!.component(ofType: TeamComponent.self)?.fire.position = currentDraggedBasePos - - for base in currentDraggedBase!.adjacencyList { - if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode { - // TODO: change interaction based on collision instead of touchlocation - - 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), 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), entityManager: entityManager)) - } - - } - } - } + + for base in currentDraggedBase!.adjacencyList { + if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode { + // TODO: change interaction based on collision instead of touchlocation + + 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), entityManager: entityManager, gameScene: self)) + 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), entityManager: entityManager, gameScene: self)) + } + + } + } + } 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) - for child in self.children { - if(child.name != "fire"){ - child.alpha = 1 - } - } - } - - if atPoint(touchLocation) == spriteNode && !entityManager.isModal { spriteNode?.touchesBegan(touches, with: event) if !entityManager.isModal { @@ -81,33 +71,33 @@ class GameScene: SKScene{ } entityManager.add(Modal(modaltype: .BaseDetails, base: entity as! Base, - anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), entityManager: entityManager)) + anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), entityManager: entityManager, gameScene: self)) } } } } - + } - + override func touchesMoved(_ touches: Set, with event: UIEvent?) { guard let touch = touches.first else { return } let touchLocation = touch.location(in: self) - - for child in children { - if atPoint(touchLocation) == child { - child.touchesMoved(touches, with: event) - } - } - - for e in entityManager.entities{ - if let body = e.component(ofType: ModalContentComponent.self)?.body{ - body.text = "Schicke \( ((e.component(ofType: SliderComponent.self)?.sliderNode.getValue ?? 0) * CGFloat((e as! Modal).unitCount)).rounded(.up)) Einheiten " - } } - + + for child in children { + if atPoint(touchLocation) == child { + child.touchesMoved(touches, with: event) + } + } + + for e in entityManager.entities{ + if let body = e.component(ofType: ModalContentComponent.self)?.body{ + body.text = "Schicke \( ((e.component(ofType: SliderComponent.self)?.sliderNode.getValue ?? 0) * CGFloat((e as! Modal).unitCount)).rounded(.up)) Einheiten " + } } + let bases = entityManager.getBasesByTeam(for: .team1) - + for base in bases { if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode{ if !isMoveTouch { @@ -115,7 +105,7 @@ class GameScene: SKScene{ currentDraggedBase = base } isMoveTouch = true - + base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = touchLocation base.component(ofType: TeamComponent.self)?.fire.position = touchLocation for adjacencyBase in base.adjacencyList { From 1a1a821d9dd3a88983f9636ee4121ad6025fbb20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chauntalle=20Schu=CC=88le?= Date: Thu, 14 May 2020 18:36:13 +0200 Subject: [PATCH 5/5] Kommentare entfernt --- GoldWars/GoldWars/Entities/EntityManager.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/GoldWars/GoldWars/Entities/EntityManager.swift b/GoldWars/GoldWars/Entities/EntityManager.swift index c2d8239..38ef9a1 100644 --- a/GoldWars/GoldWars/Entities/EntityManager.swift +++ b/GoldWars/GoldWars/Entities/EntityManager.swift @@ -30,7 +30,6 @@ class EntityManager { } if let spriteNode = entity.component(ofType: ModalBackgroundComponent.self)?.spriteNode { scene.addChild(spriteNode) - //isModal = true } if let modal = entity.component(ofType: ModalContentComponent.self) { scene.addChild(modal.header) @@ -76,7 +75,6 @@ class EntityManager { } if let spriteNode = entity.component(ofType: ModalBackgroundComponent.self)?.spriteNode { spriteNode.removeFromParent() - //isModal = false } if let modal = entity.component(ofType: ModalContentComponent.self) { modal.header.removeFromParent()