Impl. Modal Overlay

This commit is contained in:
Aldin Duraki 2020-06-02 11:55:17 +02:00
parent 4d2b7fe6ea
commit 08894325a5
5 changed files with 13 additions and 17 deletions

View File

@ -15,7 +15,7 @@ class SliderComponent: GKComponent {
init(width: CGFloat, position: CGPoint) {
sliderNode = SliderNode(width: width, position: position)
sliderNode.zPosition = 4
sliderNode.zPosition = 5
super.init()
}

View File

@ -39,6 +39,7 @@ class EntityManager {
scene.addChild(modalEntitiy.header)
scene.addChild(modalEntitiy.body)
scene.addChild(modalEntitiy.footer)
scene.addChild(modalEntitiy.overlay)
isModal = true
}
@ -279,6 +280,7 @@ class EntityManager {
modal.header.removeFromParent()
modal.body.removeFromParent()
modal.footer.removeFromParent()
modal.overlay.removeFromParent()
if let slider = modal.component(ofType: SliderComponent.self) {
slider.sliderNode.removeFromParent()

View File

@ -77,7 +77,7 @@ class HUD: GKEntity {
onButtonPress: { }
)
finishButton.size = CGSize(width: 80, height: 40)
finishButton.zPosition = 4
finishButton.zPosition = 2
super.init()
finishButton.onButtonPress = { [unowned self] in

View File

@ -23,6 +23,7 @@ class Modal: GKEntity{
var header: SKLabelNode
var body: SKLabelNode
var footer: SKLabelNode
var overlay: SKSpriteNode
init(modaltype: ModalType, base: Base, anchorPoint: CGPoint, gameScene: GameScene, currentDraggedBase: Base?, touchLocation: CGPoint, collisionBase: Base?) {
unitCount = base.unitCount
@ -31,14 +32,17 @@ class Modal: GKEntity{
background = SKSpriteNode(texture: texture, size: texture.size())
background.setScale(2.4)
background.position = anchorPoint
background.zPosition = 3
background.zPosition = 4
closeButton = ButtonNode(textureName: "red_cross", text: "", isEnabled: true, position: CGPoint(x: anchorPoint.x + 195, y: anchorPoint.y + 178), onButtonPress: {
EntityManager.gameEMInstance.removeModal()
})
closeButton.size = CGSize(width: 26, height: 26)
closeButton.zPosition = 4
closeButton.zPosition = 5
overlay = SKSpriteNode(color: UIColor.init(red: 0, green: 0, blue: 0, alpha: 0.7), size: gameScene.size)
overlay.anchorPoint = gameScene.anchorPoint
overlay.zPosition = 3
switch modaltype {
case .BaseDetails:
@ -58,7 +62,7 @@ class Modal: GKEntity{
self.header.position = CGPoint(x: anchorPoint.x, y: anchorPoint.y + 90)
self.header.fontName = "HelveticaNeue-Bold"
self.header.fontSize = 40
self.header.zPosition = 4
self.header.zPosition = 5
self.body.position = CGPoint(x: anchorPoint.x, y: anchorPoint.y - 20)
self.body.numberOfLines = 2
@ -66,12 +70,12 @@ class Modal: GKEntity{
self.body.horizontalAlignmentMode = SKLabelHorizontalAlignmentMode.center
self.body.fontName = "HelveticaNeue-Bold"
self.body.fontSize = 40
self.body.zPosition = 4
self.body.zPosition = 5
self.footer.position = CGPoint(x: anchorPoint.x, y: anchorPoint.y - 40)
self.footer.fontName = "HelveticaNeue-Bold"
self.footer.fontSize = 40
self.footer.zPosition = 4
self.footer.zPosition = 5
super.init()
@ -99,11 +103,6 @@ class Modal: GKEntity{
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

@ -80,11 +80,6 @@ class GameScene: SKScene{
spriteNode?.touchesBegan(touches, with: event)
if let baseEntity = entity as? Base {
if baseEntity.ownershipPlayer == GKLocalPlayer.local {
for child in self.children {
if(child.name != "fire"){
child.alpha = 0.3
}
}
entityManager.add(Modal(modaltype: .BaseDetails,
base: entity as! Base,
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2),