Merge branch '43-ueberarbeitung-angriffsmodal' into 'development'

Resolve "Ueberarbeitung Angriffsmodal"

Closes #43

See merge request marcel.schwarz/software-projekt-2!62
This commit is contained in:
Aldin Duraki 2020-05-15 09:06:54 +00:00
commit 931161ccd7
3 changed files with 87 additions and 80 deletions

View File

@ -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)
@ -54,6 +53,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 {
@ -75,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()
@ -86,6 +85,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)
}

View File

@ -12,23 +12,24 @@ class Modal: GKEntity{
var unitCount:Int
init(modaltype: ModalType, base: Base, anchorPoint: CGPoint) {
init(modaltype: ModalType, base: Base, anchorPoint: CGPoint, entityManager: EntityManager, gameScene: SKScene) {
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))
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: entityManager, gameScene: gameScene)
}))
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))
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: entityManager, gameScene: gameScene)
}))
}
}
@ -36,4 +37,16 @@ class Modal: GKEntity{
fatalError("init(coder:) has not been implemented")
}
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
}
}
}
}
}

View File

@ -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, 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)))
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), entityManager: entityManager, gameScene: self))
}
}
@ -61,15 +61,6 @@ class GameScene: SKScene{
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 {
@ -80,7 +71,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, gameScene: self))
}
}
}