From f1e54a6da440a956a871c3442ba3126c36744d78 Mon Sep 17 00:00:00 2001 From: Jakob Haag Date: Sat, 23 May 2020 11:47:40 +0200 Subject: [PATCH] Set different header and text in the submit button for attack an enemy base or move units between own bases --- GoldWars/GoldWars.xcodeproj/project.pbxproj | 32 +++++++++------------ GoldWars/GoldWars/Entities/Modal.swift | 12 ++++++-- GoldWars/GoldWars/Enums/ModalType.swift | 9 ------ GoldWars/GoldWars/Scenes/GameScene.swift | 21 +++++++++++--- 4 files changed, 40 insertions(+), 34 deletions(-) delete mode 100644 GoldWars/GoldWars/Enums/ModalType.swift diff --git a/GoldWars/GoldWars.xcodeproj/project.pbxproj b/GoldWars/GoldWars.xcodeproj/project.pbxproj index 86d5540..e16e8ec 100644 --- a/GoldWars/GoldWars.xcodeproj/project.pbxproj +++ b/GoldWars/GoldWars.xcodeproj/project.pbxproj @@ -41,7 +41,6 @@ 9EC2FBA72476B1EC00ABF11F /* PlayerInfoComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC2FBA62476B1EC00ABF11F /* PlayerInfoComponent.swift */; }; 9EC7E48B2461FBF700396BCD /* SliderNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC7E48A2461FBF700396BCD /* SliderNode.swift */; }; 9EC86B9F245C88A300796EF3 /* Modal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86B9E245C88A300796EF3 /* Modal.swift */; }; - 9EC86BA6245C8AD000796EF3 /* ModalType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86BA5245C8AD000796EF3 /* ModalType.swift */; }; 9EEDE02D246FCD770096C735 /* SpinningLogoEntity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EEDE02C246FCD770096C735 /* SpinningLogoEntity.swift */; }; 9EEDE02F246FCD800096C735 /* SpinningLogoComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EEDE02E246FCD800096C735 /* SpinningLogoComponent.swift */; }; AB0B88F6247AD89200C8DF66 /* SkillComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB0B88F5247AD89200C8DF66 /* SkillComponent.swift */; }; @@ -108,7 +107,6 @@ 9EC2FBA62476B1EC00ABF11F /* PlayerInfoComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerInfoComponent.swift; sourceTree = ""; }; 9EC7E48A2461FBF700396BCD /* SliderNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SliderNode.swift; sourceTree = ""; }; 9EC86B9E245C88A300796EF3 /* Modal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Modal.swift; sourceTree = ""; }; - 9EC86BA5245C8AD000796EF3 /* ModalType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModalType.swift; sourceTree = ""; }; 9ECD3699245C91F7008DEEBD /* GoldWars.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = GoldWars.entitlements; sourceTree = ""; }; 9EEDE02C246FCD770096C735 /* SpinningLogoEntity.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpinningLogoEntity.swift; sourceTree = ""; }; 9EEDE02E246FCD800096C735 /* SpinningLogoComponent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpinningLogoComponent.swift; sourceTree = ""; }; @@ -203,23 +201,23 @@ 116060F4245C56EA004E5A36 /* Components */ = { isa = PBXGroup; children = ( - C05BB9C3247D890C00411249 /* SliderComponent.swift */, - C064E9A7246C0EA50022B228 /* LabelNode.swift */, - 9E174C81245DD81D00209FF0 /* ButtonNode.swift */, - 8BB6FF3F2472B8F000162BBD /* SingeClickButtonNode.swift */, - 9EA3ABEA245C6DFA006BC61D /* BaseNode.swift */, - 9EC7E48A2461FBF700396BCD /* SliderNode.swift */, - C064E9A9246C114C0022B228 /* LabelComponent.swift */, - AB0B88F5247AD89200C8DF66 /* SkillComponent.swift */, - 9EEDE02E246FCD800096C735 /* SpinningLogoComponent.swift */, - 9E174C85245DD91500209FF0 /* ButtonComponent.swift */, - 9EA3ABE8245C6DAA006BC61D /* DefaultBaseComponent.swift */, - 9E78ACB7245CB75B00526FF7 /* TeamComponent.swift */, - 9E174C87245DF1FF00209FF0 /* BackgroundComponent.swift */, 9E04AFAE245E2B73002D5CFC /* AttackActionComponent.swift */, - 2086465B2461B66200817C23 /* TimerComponent.swift */, + 9E174C87245DF1FF00209FF0 /* BackgroundComponent.swift */, + 9EA3ABEA245C6DFA006BC61D /* BaseNode.swift */, + 9E174C85245DD91500209FF0 /* ButtonComponent.swift */, + 9E174C81245DD81D00209FF0 /* ButtonNode.swift */, + 9EA3ABE8245C6DAA006BC61D /* DefaultBaseComponent.swift */, 3E6785432472CC27007B9DE4 /* DefaultWayComponent.swift */, + C064E9A9246C114C0022B228 /* LabelComponent.swift */, + C064E9A7246C0EA50022B228 /* LabelNode.swift */, 9EC2FBA62476B1EC00ABF11F /* PlayerInfoComponent.swift */, + 8BB6FF3F2472B8F000162BBD /* SingeClickButtonNode.swift */, + AB0B88F5247AD89200C8DF66 /* SkillComponent.swift */, + C05BB9C3247D890C00411249 /* SliderComponent.swift */, + 9EC7E48A2461FBF700396BCD /* SliderNode.swift */, + 9EEDE02E246FCD800096C735 /* SpinningLogoComponent.swift */, + 9E78ACB7245CB75B00526FF7 /* TeamComponent.swift */, + 2086465B2461B66200817C23 /* TimerComponent.swift */, ); path = Components; sourceTree = ""; @@ -259,7 +257,6 @@ 9EC86BA2245C89B200796EF3 /* Enums */ = { isa = PBXGroup; children = ( - 9EC86BA5245C8AD000796EF3 /* ModalType.swift */, 3EBD242D245D9332003CECE7 /* Team.swift */, 3F745DEF246F48FC00CE7375 /* PlayerMoveType.swift */, ); @@ -401,7 +398,6 @@ 9E78ACB8245CB75B00526FF7 /* TeamComponent.swift in Sources */, 9E0E459724796262009817A6 /* GameCenterManager.swift in Sources */, 3FE19DB5246C7A22004827AB /* RoundCalculatorService.swift in Sources */, - 9EC86BA6245C8AD000796EF3 /* ModalType.swift in Sources */, 9EC239E1246878A900952F74 /* MultiplayerNetwork.swift in Sources */, 9EA3ABEB245C6DFA006BC61D /* BaseNode.swift in Sources */, 9E04AFAF245E2B73002D5CFC /* AttackActionComponent.swift in Sources */, diff --git a/GoldWars/GoldWars/Entities/Modal.swift b/GoldWars/GoldWars/Entities/Modal.swift index cbfa479..50747af 100644 --- a/GoldWars/GoldWars/Entities/Modal.swift +++ b/GoldWars/GoldWars/Entities/Modal.swift @@ -11,6 +11,7 @@ import GameplayKit enum ModalType: String{ case BaseDetails case BaseAttack + case BaseMoveOwnUnits } class Modal: GKEntity{ @@ -46,7 +47,11 @@ class Modal: GKEntity{ footer = SKLabelNode() case .BaseAttack: header = SKLabelNode(text: "Angriff") - body = SKLabelNode(text: "Schicke \(unitCount / 2) Einheiten") + body = SKLabelNode(text: "Schicke \(unitCount / 2)\nEinheiten") + footer = SKLabelNode() + case .BaseMoveOwnUnits: + header = SKLabelNode(text: "Formation") + body = SKLabelNode(text: "Sende \(unitCount / 2)\nEinheiten") footer = SKLabelNode() } @@ -75,9 +80,10 @@ class Modal: GKEntity{ addComponent(ButtonComponent(textureName: "yellow_button04", text: "Zurück", position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 105), isEnabled: true, onButtonPress: { EntityManager.gameEMInstance.removeModal() })) - case .BaseAttack: + case .BaseAttack, .BaseMoveOwnUnits: + let text = (modaltype == .BaseAttack) ? "Angriff" : "Senden" addComponent(SliderComponent(width: 300, position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 50))) - addComponent(ButtonComponent(textureName: "yellow_button04", text: "Senden", position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 105), isEnabled: true, onButtonPress: { + addComponent(ButtonComponent(textureName: "yellow_button04", text: text, position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 105), isEnabled: true, onButtonPress: { self.sendUnits(currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, gameScene: gameScene, collisionBase: collisionBase) EntityManager.gameEMInstance.removeModal() })) diff --git a/GoldWars/GoldWars/Enums/ModalType.swift b/GoldWars/GoldWars/Enums/ModalType.swift deleted file mode 100644 index 08faf8d..0000000 --- a/GoldWars/GoldWars/Enums/ModalType.swift +++ /dev/null @@ -1,9 +0,0 @@ -// -// ModalType.swift -// GoldWars -// -// Created by Niko Jochim on 01.05.20. -// Copyright © 2020 SP2. All rights reserved. -// - - diff --git a/GoldWars/GoldWars/Scenes/GameScene.swift b/GoldWars/GoldWars/Scenes/GameScene.swift index 0dc2a6d..b38524c 100644 --- a/GoldWars/GoldWars/Scenes/GameScene.swift +++ b/GoldWars/GoldWars/Scenes/GameScene.swift @@ -109,7 +109,8 @@ class GameScene: SKScene{ if !checkIfMoveIsAble() { return } - entityManager.add(Modal(modaltype: .BaseAttack, + let modaltype = setModalType() + entityManager.add(Modal(modaltype: modaltype, base: currentDraggedBase!, anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), gameScene: self, @@ -169,10 +170,22 @@ class GameScene: SKScene{ } func checkIfMoveIsAble() -> Bool{ - if collisionBase?.ownershipPlayer == currentDraggedBase?.ownershipPlayer { - return RoundCalculatorService.sharedInstance.numberOfOwnUnitMoves < 5 - } else { + if isAttackMove() { return RoundCalculatorService.sharedInstance.numberOfAttacks < 2 + } else { + return RoundCalculatorService.sharedInstance.numberOfOwnUnitMoves < 5 } } + + func setModalType() -> ModalType { + if isAttackMove() { + return .BaseAttack + } else { + return .BaseMoveOwnUnits + } + } + + func isAttackMove() -> Bool { + return collisionBase?.ownershipPlayer != currentDraggedBase?.ownershipPlayer + } }