Merge branch '64-view-visibility-unitcount-and-playername' into 'development'
Resolve "[View] Visibility UnitCount and Playername" Closes #64 See merge request marcel.schwarz/software-projekt-2!77
This commit is contained in:
commit
8b140b95b4
@ -23,9 +23,9 @@
|
||||
3E6785442472CC27007B9DE4 /* DefaultWayComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E6785432472CC27007B9DE4 /* DefaultWayComponent.swift */; };
|
||||
3EBD242C245D8044003CECE7 /* GameCenterHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EBD242B245D8044003CECE7 /* GameCenterHelper.swift */; };
|
||||
3EBD242E245D9332003CECE7 /* Team.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EBD242D245D9332003CECE7 /* Team.swift */; };
|
||||
8BB6FF402472B8F000162BBD /* SkillButtonNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8BB6FF3F2472B8F000162BBD /* SkillButtonNode.swift */; };
|
||||
3F745DF0246F48FC00CE7375 /* PlayerMoveType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F745DEF246F48FC00CE7375 /* PlayerMoveType.swift */; };
|
||||
3FE19DB5246C7A22004827AB /* RoundCalculatorService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FE19DB4246C7A22004827AB /* RoundCalculatorService.swift */; };
|
||||
8BB6FF402472B8F000162BBD /* SkillButtonNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8BB6FF3F2472B8F000162BBD /* SkillButtonNode.swift */; };
|
||||
9E04AFAF245E2B73002D5CFC /* AttackActionComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E04AFAE245E2B73002D5CFC /* AttackActionComponent.swift */; };
|
||||
9E11FF79245CD81100EED3BE /* Fire.sks in Resources */ = {isa = PBXBuildFile; fileRef = 9E11FF77245CD81100EED3BE /* Fire.sks */; };
|
||||
9E174C82245DD81D00209FF0 /* ButtonNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E174C81245DD81D00209FF0 /* ButtonNode.swift */; };
|
||||
@ -45,6 +45,7 @@
|
||||
9EA3ABEF245C834B006BC61D /* ModalContentComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EA3ABEE245C834B006BC61D /* ModalContentComponent.swift */; };
|
||||
9EBFD7552462CF5A00E1E219 /* SliderComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EBFD7542462CF5A00E1E219 /* SliderComponent.swift */; };
|
||||
9EC239E1246878A900952F74 /* MultiplayerNetwork.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC239E0246878A900952F74 /* MultiplayerNetwork.swift */; };
|
||||
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 */; };
|
||||
@ -97,9 +98,9 @@
|
||||
3E6785432472CC27007B9DE4 /* DefaultWayComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultWayComponent.swift; sourceTree = "<group>"; };
|
||||
3EBD242B245D8044003CECE7 /* GameCenterHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameCenterHelper.swift; sourceTree = "<group>"; };
|
||||
3EBD242D245D9332003CECE7 /* Team.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Team.swift; sourceTree = "<group>"; };
|
||||
8BB6FF3F2472B8F000162BBD /* SkillButtonNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SkillButtonNode.swift; sourceTree = "<group>"; };
|
||||
3F745DEF246F48FC00CE7375 /* PlayerMoveType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerMoveType.swift; sourceTree = "<group>"; };
|
||||
3FE19DB4246C7A22004827AB /* RoundCalculatorService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoundCalculatorService.swift; sourceTree = "<group>"; };
|
||||
8BB6FF3F2472B8F000162BBD /* SkillButtonNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SkillButtonNode.swift; sourceTree = "<group>"; };
|
||||
9E04AFAE245E2B73002D5CFC /* AttackActionComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttackActionComponent.swift; sourceTree = "<group>"; };
|
||||
9E11FF77245CD81100EED3BE /* Fire.sks */ = {isa = PBXFileReference; lastKnownFileType = file.sks; path = Fire.sks; sourceTree = "<group>"; };
|
||||
9E174C81245DD81D00209FF0 /* ButtonNode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ButtonNode.swift; sourceTree = "<group>"; };
|
||||
@ -119,6 +120,7 @@
|
||||
9EA3ABEE245C834B006BC61D /* ModalContentComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModalContentComponent.swift; sourceTree = "<group>"; };
|
||||
9EBFD7542462CF5A00E1E219 /* SliderComponent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SliderComponent.swift; sourceTree = "<group>"; };
|
||||
9EC239E0246878A900952F74 /* MultiplayerNetwork.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultiplayerNetwork.swift; sourceTree = "<group>"; };
|
||||
9EC2FBA62476B1EC00ABF11F /* PlayerInfoComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerInfoComponent.swift; sourceTree = "<group>"; };
|
||||
9EC7E48A2461FBF700396BCD /* SliderNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SliderNode.swift; sourceTree = "<group>"; };
|
||||
9EC86B9E245C88A300796EF3 /* Modal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Modal.swift; sourceTree = "<group>"; };
|
||||
9EC86BA5245C8AD000796EF3 /* ModalType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModalType.swift; sourceTree = "<group>"; };
|
||||
@ -241,6 +243,7 @@
|
||||
9EC7E48A2461FBF700396BCD /* SliderNode.swift */,
|
||||
3E6785432472CC27007B9DE4 /* DefaultWayComponent.swift */,
|
||||
8BB6FF3F2472B8F000162BBD /* SkillButtonNode.swift */,
|
||||
9EC2FBA62476B1EC00ABF11F /* PlayerInfoComponent.swift */,
|
||||
);
|
||||
path = Components;
|
||||
sourceTree = "<group>";
|
||||
@ -436,6 +439,7 @@
|
||||
3EBD242E245D9332003CECE7 /* Team.swift in Sources */,
|
||||
9E174C88245DF1FF00209FF0 /* BackgroundComponent.swift in Sources */,
|
||||
9E78ACBA245CBDAF00526FF7 /* HUD.swift in Sources */,
|
||||
9EC2FBA72476B1EC00ABF11F /* PlayerInfoComponent.swift in Sources */,
|
||||
9EEDE02D246FCD770096C735 /* SpinningLogoEntity.swift in Sources */,
|
||||
11738A3B24508F68004426F1 /* UnitType.swift in Sources */,
|
||||
9E174C86245DD91500209FF0 /* ButtonComponent.swift in Sources */,
|
||||
|
@ -18,6 +18,7 @@ class CancelBtnComponent: GKComponent {
|
||||
isEnabled: isEnabled,
|
||||
position: position,
|
||||
onButtonPress: onButtonPress)
|
||||
cancelBtnNode.zPosition = 4
|
||||
super.init()
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@ class ButtonComponent: GKComponent {
|
||||
isEnabled: isEnabled,
|
||||
position: position,
|
||||
onButtonPress: onButtonPress)
|
||||
buttonNode.zPosition = 4
|
||||
super.init()
|
||||
}
|
||||
|
||||
|
@ -8,14 +8,25 @@
|
||||
|
||||
import GameplayKit
|
||||
import SpriteKit
|
||||
import GameKit
|
||||
|
||||
class DefaultBaseComponent: GKComponent {
|
||||
var spriteNode: BaseNode
|
||||
var labelNode : SKLabelNode?
|
||||
|
||||
init(texture: SKTexture, position: CGPoint) {
|
||||
spriteNode = BaseNode(texture: texture, size: CGSize(width: 80, height: 80))
|
||||
spriteNode.position = position
|
||||
spriteNode.zPosition = 2
|
||||
super.init()
|
||||
labelNode = SKLabelNode(text: "")
|
||||
labelNode?.fontColor = SKColor.black
|
||||
labelNode?.horizontalAlignmentMode = .left
|
||||
labelNode?.verticalAlignmentMode = .center
|
||||
labelNode?.fontName = "AvenirNext-Bold"
|
||||
labelNode?.fontSize = 15
|
||||
labelNode?.position = CGPoint(x: position.x + 30 , y: position.y - 50 )
|
||||
labelNode?.zPosition = spriteNode.zPosition - 1
|
||||
}
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
|
@ -18,7 +18,7 @@ class DefaultWayComponent: GKComponent {
|
||||
shapeNode.path = pathToDraw
|
||||
shapeNode.strokeColor = UIColor(red: 0.852, green: 0.649, blue: 0.123, alpha: 1)
|
||||
shapeNode.lineWidth = 10
|
||||
shapeNode.zPosition = -1
|
||||
shapeNode.zPosition = 0
|
||||
super.init()
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@ class ModalBackgroundComponent: GKComponent {
|
||||
spriteNode = SKSpriteNode(texture: texture, size: texture.size())
|
||||
spriteNode.setScale(2)
|
||||
spriteNode.position = anchorPoint
|
||||
spriteNode.zPosition = 3
|
||||
super.init()
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ class ModalContentComponent: GKComponent{
|
||||
self.header.position = CGPoint(x: anchorPoint.x, y: anchorPoint.y + 125)
|
||||
self.header.fontName = "HelveticaNeue-Bold"
|
||||
self.header.fontSize = 40
|
||||
self.header.zPosition = 4
|
||||
|
||||
self.body = SKLabelNode(text: body)
|
||||
self.body.position = CGPoint(x: anchorPoint.x, y: anchorPoint.y - 20)
|
||||
@ -28,11 +29,13 @@ class ModalContentComponent: GKComponent{
|
||||
self.body.horizontalAlignmentMode = SKLabelHorizontalAlignmentMode.center
|
||||
self.body.fontName = "HelveticaNeue-Bold"
|
||||
self.body.fontSize = 40
|
||||
self.body.zPosition = 4
|
||||
|
||||
self.footer = SKLabelNode(text: footer)
|
||||
self.footer.position = CGPoint(x: anchorPoint.x, y: anchorPoint.y - 40)
|
||||
self.footer.fontName = "HelveticaNeue-Bold"
|
||||
self.footer.fontSize = 40
|
||||
self.footer.zPosition = 4
|
||||
super.init()
|
||||
}
|
||||
|
||||
|
61
GoldWars/GoldWars/Components/PlayerInfoComponent.swift
Normal file
61
GoldWars/GoldWars/Components/PlayerInfoComponent.swift
Normal file
@ -0,0 +1,61 @@
|
||||
//
|
||||
// PlayerInfoComponent.swift
|
||||
// GoldWars
|
||||
//
|
||||
// Created by Niko Jochim on 21.05.20.
|
||||
// Copyright © 2020 SP2. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import GameplayKit
|
||||
import GameKit
|
||||
|
||||
|
||||
class PlayerInfoComponent: GKComponent {
|
||||
|
||||
var hostLabel:SKLabelNode
|
||||
var hostUnitsLabel:SKLabelNode
|
||||
|
||||
var peerLabel:SKLabelNode
|
||||
var peerUnitsLabel:SKLabelNode
|
||||
var host: GKPlayer?
|
||||
var peer: GKPlayer?
|
||||
|
||||
init(size: CGSize) {
|
||||
if MatchmakingHelper.sharedInstance.isServer {
|
||||
host = GKLocalPlayer.local
|
||||
peer = MatchmakingHelper.sharedInstance.mpMatch?.players[0]
|
||||
} else {
|
||||
host = MatchmakingHelper.sharedInstance.mpMatch?.players[0]
|
||||
peer = GKLocalPlayer.local
|
||||
}
|
||||
hostLabel = SKLabelNode(text: host?.displayName)
|
||||
hostUnitsLabel = SKLabelNode(text: "500" )
|
||||
peerLabel = SKLabelNode(text: peer?.displayName)
|
||||
peerUnitsLabel = SKLabelNode(text: "500")
|
||||
super.init()
|
||||
hostLabel.position = CGPoint(x: size.width * 0.02, y: size.height * 0.95)
|
||||
hostLabel.horizontalAlignmentMode = .left
|
||||
peerLabel.position = CGPoint(x: size.width * 0.98, y: size.height * 0.95)
|
||||
peerLabel.horizontalAlignmentMode = .right
|
||||
hostUnitsLabel.position = CGPoint(x: size.width * 0.05, y: size.height * 0.9)
|
||||
peerUnitsLabel.position = CGPoint(x: size.width * 0.95, y: size.height * 0.9)
|
||||
setColor(labelNodes: [hostLabel,hostUnitsLabel,peerLabel,peerUnitsLabel])
|
||||
}
|
||||
|
||||
func update(){
|
||||
hostUnitsLabel.text = "\(EntityManager.sharedInstance.getUnitSum(by: host!))"
|
||||
peerUnitsLabel.text = "\(EntityManager.sharedInstance.getUnitSum(by: peer!))"
|
||||
}
|
||||
|
||||
func setColor(labelNodes: [SKLabelNode]) -> Void {
|
||||
for label in labelNodes {
|
||||
label.fontColor = SKColor.black
|
||||
}
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
}
|
@ -14,6 +14,7 @@ class SliderComponent: GKComponent {
|
||||
|
||||
init(width: CGFloat, position: CGPoint) {
|
||||
sliderNode = SliderNode(width: width, position: position)
|
||||
sliderNode.zPosition = 4
|
||||
super.init()
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@ class SliderNode :SKNode {
|
||||
sliderLine = SKShapeNode(rectOf: CGSize(width: width, height: 8))
|
||||
sliderLine.position = position
|
||||
sliderLine.fillColor = SKColor.white
|
||||
sliderLine.zPosition = 4
|
||||
sliderKnob = SliderKnob(circleOfRadius: 20)
|
||||
sliderKnob.min = position.x - width / 2
|
||||
sliderKnob.max = position.x + width / 2
|
||||
|
@ -17,7 +17,7 @@ class TeamComponent: GKComponent {
|
||||
|
||||
init(team: Team, player: GKPlayer, position: CGPoint) {
|
||||
fire = SKEmitterNode(fileNamed: "Fire")!
|
||||
fire.zPosition = -1
|
||||
fire.zPosition = 1
|
||||
fire.position = position
|
||||
fire.name = "fire"
|
||||
fire.particleColorSequence = nil
|
||||
|
@ -37,6 +37,11 @@ class Base: GKEntity{
|
||||
addComponent(TeamComponent(team: team!, player: player!, position: spritePos))
|
||||
self.unitCount = 500
|
||||
}
|
||||
if ownershipPlayer == GKLocalPlayer.local {
|
||||
self.component(ofType: DefaultBaseComponent.self)?.labelNode?.text = "\(unitCount)"
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
func doPlayerMoveTypeToBase(base: Base, playerMoveType: PlayerMoveType, units: Int) -> [GKEntity]{
|
||||
@ -44,6 +49,8 @@ class Base: GKEntity{
|
||||
base.ownershipPlayer = self.ownershipPlayer
|
||||
self.unitCount -= units
|
||||
base.unitCount += units
|
||||
self.component(ofType: DefaultBaseComponent.self)?.labelNode?.text = "\(self.unitCount)"
|
||||
base.component(ofType: DefaultBaseComponent.self)?.labelNode?.text = "\(base.unitCount)"
|
||||
DataService.sharedInstance.addMove(playerMove: PlayerMove(fromBase: self.baseID,
|
||||
toBase: base.baseID,
|
||||
unitCount: units * playerMoveType.rawValue))
|
||||
|
@ -33,6 +33,9 @@ class EntityManager {
|
||||
if let spriteNode = entity.component(ofType: DefaultBaseComponent.self)?.spriteNode {
|
||||
scene.addChild(spriteNode)
|
||||
}
|
||||
if let label = entity.component(ofType: DefaultBaseComponent.self)?.labelNode {
|
||||
scene.addChild(label)
|
||||
}
|
||||
if let fire = entity.component(ofType: TeamComponent.self)?.fire{
|
||||
scene.addChild(fire)
|
||||
}
|
||||
@ -82,6 +85,12 @@ class EntityManager {
|
||||
if let wayNode = entity.component(ofType: DefaultWayComponent.self)?.shapeNode {
|
||||
scene.addChild(wayNode)
|
||||
}
|
||||
if let playerInfos = entity.component(ofType: PlayerInfoComponent.self) {
|
||||
scene.addChild(playerInfos.hostLabel)
|
||||
scene.addChild(playerInfos.hostUnitsLabel)
|
||||
scene.addChild(playerInfos.peerLabel)
|
||||
scene.addChild(playerInfos.peerUnitsLabel)
|
||||
}
|
||||
}
|
||||
|
||||
func remove(_ entity: GKEntity) {
|
||||
@ -148,6 +157,11 @@ class EntityManager {
|
||||
entity.removeComponent(ofType: TeamComponent.self)
|
||||
}
|
||||
if getOwnerBySnapBase != nil {
|
||||
if getOwnerBySnapBase == GKLocalPlayer.local {
|
||||
base.component(ofType: DefaultBaseComponent.self)?.labelNode?.text = "\(base.unitCount)"
|
||||
}else {
|
||||
base.component(ofType: DefaultBaseComponent.self)?.labelNode?.text = ""
|
||||
}
|
||||
base.changeOwnership = true
|
||||
base.ownershipPlayer = getOwnerBySnapBase
|
||||
if (entity.component(ofType: TeamComponent.self) != nil) {
|
||||
@ -165,6 +179,9 @@ class EntityManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getHUD()?.component(ofType: PlayerInfoComponent.self)?.update()
|
||||
|
||||
}
|
||||
|
||||
func getSnapshotBaseById(baseId: Int, snapshotModel: SnapshotModel) -> BaseEntityModel{
|
||||
@ -245,8 +262,6 @@ class EntityManager {
|
||||
return entities.filter{$0 is HUD}[0]
|
||||
}
|
||||
|
||||
|
||||
|
||||
func getSnapshotModel() -> SnapshotModel {
|
||||
let bases = entities.filter{$0 is Base}
|
||||
var snapBase: [BaseEntityModel] = []
|
||||
@ -262,4 +277,13 @@ class EntityManager {
|
||||
func getTimer() -> TimerComponent {
|
||||
return entities.filter{$0 is HUD}[0].component(ofType: TimerComponent.self)!
|
||||
}
|
||||
func getUnitSum(by player: GKPlayer) -> Int{
|
||||
let bases = getBasesByPlayer(for: player)
|
||||
|
||||
var sum = 0
|
||||
for base in bases {
|
||||
sum += base.unitCount
|
||||
}
|
||||
return sum
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,9 @@ class HUD: GKEntity {
|
||||
|
||||
addComponent(TimerComponent(text: "",
|
||||
anchorPoint: CGPoint(x: size.width * 0.5, y: size.height * 0.9), duration: 30))
|
||||
|
||||
addComponent(PlayerInfoComponent(size: size))
|
||||
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
|
@ -46,7 +46,7 @@ class GameScene: SKScene{
|
||||
isMoveTouch = false
|
||||
currentDraggedBase!.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = currentDraggedBase!.position
|
||||
currentDraggedBase!.component(ofType: TeamComponent.self)?.fire.position = currentDraggedBase!.position
|
||||
|
||||
currentDraggedBase!.component(ofType: DefaultBaseComponent.self)?.labelNode?.position = CGPoint(x: currentDraggedBase!.position.x + 30, y: currentDraggedBase!.position.y - 50)
|
||||
addAttackDetails(touchLocation: touchLocation)
|
||||
}
|
||||
else {
|
||||
@ -152,6 +152,7 @@ class GameScene: SKScene{
|
||||
func moveFireAndBase(base: Base, touchLocation: CGPoint){
|
||||
base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = touchLocation
|
||||
base.component(ofType: TeamComponent.self)?.fire.position = touchLocation
|
||||
base.component(ofType: DefaultBaseComponent.self)?.labelNode?.position = CGPoint(x:touchLocation.x + 30, y: touchLocation.y - 50)
|
||||
}
|
||||
|
||||
func showNearestBases(base: Base){
|
||||
|
Loading…
Reference in New Issue
Block a user