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:
commit
931161ccd7
@ -30,7 +30,6 @@ class EntityManager {
|
|||||||
}
|
}
|
||||||
if let spriteNode = entity.component(ofType: ModalBackgroundComponent.self)?.spriteNode {
|
if let spriteNode = entity.component(ofType: ModalBackgroundComponent.self)?.spriteNode {
|
||||||
scene.addChild(spriteNode)
|
scene.addChild(spriteNode)
|
||||||
isModal = true
|
|
||||||
}
|
}
|
||||||
if let modal = entity.component(ofType: ModalContentComponent.self) {
|
if let modal = entity.component(ofType: ModalContentComponent.self) {
|
||||||
scene.addChild(modal.header)
|
scene.addChild(modal.header)
|
||||||
@ -54,6 +53,7 @@ class EntityManager {
|
|||||||
}
|
}
|
||||||
if let buttonNode = entity.component(ofType: ButtonComponent.self)?.buttonNode {
|
if let buttonNode = entity.component(ofType: ButtonComponent.self)?.buttonNode {
|
||||||
scene.addChild(buttonNode)
|
scene.addChild(buttonNode)
|
||||||
|
isModal = true
|
||||||
}
|
}
|
||||||
if let nodes = entity.component(ofType: BackgroundComponent.self)?.nodes {
|
if let nodes = entity.component(ofType: BackgroundComponent.self)?.nodes {
|
||||||
for node in nodes {
|
for node in nodes {
|
||||||
@ -75,7 +75,6 @@ class EntityManager {
|
|||||||
}
|
}
|
||||||
if let spriteNode = entity.component(ofType: ModalBackgroundComponent.self)?.spriteNode {
|
if let spriteNode = entity.component(ofType: ModalBackgroundComponent.self)?.spriteNode {
|
||||||
spriteNode.removeFromParent()
|
spriteNode.removeFromParent()
|
||||||
isModal = false
|
|
||||||
}
|
}
|
||||||
if let modal = entity.component(ofType: ModalContentComponent.self) {
|
if let modal = entity.component(ofType: ModalContentComponent.self) {
|
||||||
modal.header.removeFromParent()
|
modal.header.removeFromParent()
|
||||||
@ -86,6 +85,10 @@ class EntityManager {
|
|||||||
sliderNode.sliderKnob.removeFromParent()
|
sliderNode.sliderKnob.removeFromParent()
|
||||||
sliderNode.sliderLine.removeFromParent()
|
sliderNode.sliderLine.removeFromParent()
|
||||||
}
|
}
|
||||||
|
if let modalButton = entity.component(ofType: ButtonComponent.self) {
|
||||||
|
modalButton.buttonNode.removeFromParent()
|
||||||
|
isModal = false
|
||||||
|
}
|
||||||
entities.remove(entity)
|
entities.remove(entity)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,30 +10,43 @@ import GameplayKit
|
|||||||
|
|
||||||
class Modal: GKEntity{
|
class Modal: GKEntity{
|
||||||
|
|
||||||
var unitCount:Int
|
var unitCount:Int
|
||||||
|
|
||||||
init(modaltype: ModalType, base: Base, anchorPoint: CGPoint) {
|
init(modaltype: ModalType, base: Base, anchorPoint: CGPoint, entityManager: EntityManager, gameScene: SKScene) {
|
||||||
unitCount = base.unitCount
|
unitCount = base.unitCount
|
||||||
super.init()
|
super.init()
|
||||||
switch modaltype{
|
switch modaltype{
|
||||||
case .BaseDetails:
|
case .BaseDetails:
|
||||||
addComponent(ModalBackgroundComponent(anchorPoint: anchorPoint))
|
addComponent(ModalBackgroundComponent(anchorPoint: anchorPoint))
|
||||||
addComponent(ModalContentComponent(header: "Basis Information",
|
addComponent(ModalContentComponent(header: "Basis Information", body: "Diese Basis enthält \(base.unitCount) Einheiten", footer: "", anchorPoint: anchorPoint))
|
||||||
body: "Diese Basis enthält \(base.unitCount) Einheiten",
|
addComponent(ButtonComponent(iconName: "", text: "Zurück", position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 120), isEnabled: true, onButtonPress: {
|
||||||
footer: "",
|
self.removeModalEntities(entityManager: entityManager, gameScene: gameScene)
|
||||||
anchorPoint: anchorPoint))
|
}))
|
||||||
case .BaseAttack:
|
case .BaseAttack:
|
||||||
addComponent(ModalBackgroundComponent(anchorPoint: anchorPoint))
|
addComponent(ModalBackgroundComponent(anchorPoint: anchorPoint))
|
||||||
addComponent(SliderComponent(width: 300, position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 80)))
|
addComponent(SliderComponent(width: 300, position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 50)))
|
||||||
addComponent(ModalContentComponent(header: "Angriff",
|
addComponent(ModalContentComponent(header: "Angriff", body: "Schicke \(unitCount / 2) Einheiten",
|
||||||
body: "Schicke \(unitCount / 2) Einheiten",
|
footer: "", anchorPoint: anchorPoint))
|
||||||
footer: "",
|
addComponent(ButtonComponent(iconName: "", text: "Senden", position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 120), isEnabled: true, onButtonPress: {
|
||||||
anchorPoint: anchorPoint))
|
self.removeModalEntities(entityManager: entityManager, gameScene: gameScene)
|
||||||
}
|
}))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
required init?(coder: NSCoder) {
|
||||||
fatalError("init(coder:) has not been implemented")
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,42 +34,33 @@ class GameScene: SKScene{
|
|||||||
|
|
||||||
let touchLocation = touch.location(in: self)
|
let touchLocation = touch.location(in: self)
|
||||||
|
|
||||||
if isMoveTouch{
|
if isMoveTouch{
|
||||||
isMoveTouch = false
|
isMoveTouch = false
|
||||||
currentDraggedBase!.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = currentDraggedBasePos
|
currentDraggedBase!.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = currentDraggedBasePos
|
||||||
currentDraggedBase!.component(ofType: TeamComponent.self)?.fire.position = currentDraggedBasePos
|
currentDraggedBase!.component(ofType: TeamComponent.self)?.fire.position = currentDraggedBasePos
|
||||||
|
|
||||||
for base in currentDraggedBase!.adjacencyList {
|
for base in currentDraggedBase!.adjacencyList {
|
||||||
if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode {
|
if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode {
|
||||||
// TODO: change interaction based on collision instead of touchlocation
|
// TODO: change interaction based on collision instead of touchlocation
|
||||||
|
|
||||||
if !(entityManager.getTeamByBase(base: currentDraggedBase!) == entityManager.getTeamByBase(base: base)){
|
if !(entityManager.getTeamByBase(base: currentDraggedBase!) == entityManager.getTeamByBase(base: base)){
|
||||||
entityManager.add(Modal(modaltype: .BaseAttack,
|
entityManager.add(Modal(modaltype: .BaseAttack,
|
||||||
base: currentDraggedBase!,
|
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))!)
|
entityManager.update((currentDraggedBase?.attackBase(base: base, units: 100))!)
|
||||||
}else {
|
}else {
|
||||||
entityManager.add(Modal(modaltype: .BaseAttack,
|
entityManager.add(Modal(modaltype: .BaseAttack,
|
||||||
base: currentDraggedBase!,
|
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))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for entity in entityManager.entities {
|
for entity in entityManager.entities {
|
||||||
let spriteNode = entity.component(ofType: DefaultBaseComponent.self)?.spriteNode
|
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 {
|
if atPoint(touchLocation) == spriteNode && !entityManager.isModal {
|
||||||
spriteNode?.touchesBegan(touches, with: event)
|
spriteNode?.touchesBegan(touches, with: event)
|
||||||
if !entityManager.isModal {
|
if !entityManager.isModal {
|
||||||
@ -80,7 +71,7 @@ class GameScene: SKScene{
|
|||||||
}
|
}
|
||||||
entityManager.add(Modal(modaltype: .BaseDetails,
|
entityManager.add(Modal(modaltype: .BaseDetails,
|
||||||
base: entity as! Base,
|
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))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -94,16 +85,16 @@ class GameScene: SKScene{
|
|||||||
}
|
}
|
||||||
let touchLocation = touch.location(in: self)
|
let touchLocation = touch.location(in: self)
|
||||||
|
|
||||||
for child in children {
|
for child in children {
|
||||||
if atPoint(touchLocation) == child {
|
if atPoint(touchLocation) == child {
|
||||||
child.touchesMoved(touches, with: event)
|
child.touchesMoved(touches, with: event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for e in entityManager.entities{
|
for e in entityManager.entities{
|
||||||
if let body = e.component(ofType: ModalContentComponent.self)?.body{
|
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 "
|
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)
|
let bases = entityManager.getBasesByTeam(for: .team1)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user