Adding Button to ModalEinheiten, you can now exit via Button and not anymore via Slider

This commit is contained in:
Chauntalle Schüle 2020-05-14 14:06:44 +02:00 committed by Chauntalle Schüle
parent a78b9269c0
commit c14731dff6
2 changed files with 39 additions and 31 deletions

View File

@ -11,24 +11,24 @@ import GameplayKit
class Modal: GKEntity{
var unitCount:Int
var modalEntityManager: EntityManager
init(modaltype: ModalType, base: Base, anchorPoint: CGPoint) {
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))
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))
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)
}))
}
}
@ -36,4 +36,11 @@ class Modal: GKEntity{
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)
}
}
}
}

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))
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))
}
}
@ -62,7 +62,7 @@ class GameScene: SKScene{
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
@ -70,6 +70,7 @@ class GameScene: SKScene{
}
}
if atPoint(touchLocation) == spriteNode && !entityManager.isModal {
spriteNode?.touchesBegan(touches, with: event)
if !entityManager.isModal {
@ -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))
}
}
}