Merge branch '102-ueberarbeitung-slider' into 'development'

Resolve "Ueberarbeitung Slider"

Closes #102

See merge request marcel.schwarz/software-projekt-2!128
This commit is contained in:
Marcel Schwarz 2020-06-18 21:10:50 +00:00
commit 0b2b552d16
5 changed files with 82 additions and 70 deletions

View File

@ -12,12 +12,14 @@ import SpriteKit
class SliderNode :SKNode { class SliderNode :SKNode {
var sliderLine :SKShapeNode var sliderLine :SKShapeNode
var sliderKnob :SliderKnob var hiddenKnob :SliderKnob
var silderKnob :SKSpriteNode
var width: CGFloat var width: CGFloat
var getValue: CGFloat{ var getValue: CGFloat{
get{ get{
return ((sliderKnob.position.x.rounded() - sliderKnob.min) / width) silderKnob.position = hiddenKnob.position
return ((hiddenKnob.position.x.rounded() - hiddenKnob.min) / width)
} }
} }
@ -27,19 +29,28 @@ class SliderNode :SKNode {
sliderLine.position = position sliderLine.position = position
sliderLine.fillColor = SKColor.white sliderLine.fillColor = SKColor.white
sliderLine.zPosition = 4 sliderLine.zPosition = 4
sliderKnob = SliderKnob(circleOfRadius: 20)
sliderKnob.min = position.x - width / 2
sliderKnob.max = position.x + width / 2
sliderKnob.fillColor = SKColor.red
sliderKnob.zPosition = sliderLine.zPosition + 1
sliderKnob.position = CGPoint(x: sliderLine.position.x, y: sliderLine.position.y + 1)
super.init()
hiddenKnob = SliderKnob(circleOfRadius: 58 )
hiddenKnob.min = position.x - width / 2
hiddenKnob.max = position.x + width / 2
hiddenKnob.fillColor = SKColor.red
hiddenKnob.alpha = 0.001
hiddenKnob.zPosition = sliderLine.zPosition + 1
hiddenKnob.position = CGPoint(x: sliderLine.position.x, y: sliderLine.position.y + 1)
silderKnob = SKSpriteNode(texture: SKTexture(imageNamed: "yellow_boxTick"))
silderKnob.position = hiddenKnob.position
silderKnob.zPosition = hiddenKnob.zPosition - 1
silderKnob.size = CGSize(width: 50, height: 50)
super.init()
self.name = "slider"
} }
required init?(coder aDecoder: NSCoder) { required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented") fatalError("init(coder:) has not been implemented")
} }
} }
class SliderKnob: SKShapeNode { class SliderKnob: SKShapeNode {
@ -60,6 +71,7 @@ class SliderKnob: SKShapeNode {
} }
if(self.position.x >= max){ if(self.position.x >= max){
self.position.x = max self.position.x = max
} }
} }
} }

View File

@ -88,8 +88,9 @@ class EntityManager {
} }
} }
if let sliderNode = entity.component(ofType: SliderComponent.self)?.sliderNode { if let sliderNode = entity.component(ofType: SliderComponent.self)?.sliderNode {
scene.addChild(sliderNode.sliderKnob) scene.addChild(sliderNode.hiddenKnob)
scene.addChild(sliderNode.sliderLine) scene.addChild(sliderNode.sliderLine)
scene.addChild(sliderNode.silderKnob)
} }
if let labelNode = entity.component(ofType: LabelComponent.self)?.labelNode { if let labelNode = entity.component(ofType: LabelComponent.self)?.labelNode {
scene.addChild(labelNode) scene.addChild(labelNode)
@ -102,8 +103,9 @@ class EntityManager {
spriteNode.removeFromParent() spriteNode.removeFromParent()
} }
if let sliderNode = entity.component(ofType: SliderComponent.self)?.sliderNode { if let sliderNode = entity.component(ofType: SliderComponent.self)?.sliderNode {
sliderNode.sliderKnob.removeFromParent() sliderNode.hiddenKnob.removeFromParent()
sliderNode.sliderLine.removeFromParent() sliderNode.sliderLine.removeFromParent()
sliderNode.silderKnob.removeFromParent()
} }
if let modalButton = entity.component(ofType: ButtonComponent.self) { if let modalButton = entity.component(ofType: ButtonComponent.self) {
modalButton.buttonNode.removeFromParent() modalButton.buttonNode.removeFromParent()
@ -336,7 +338,7 @@ class EntityManager {
if let slider = modal.component(ofType: SliderComponent.self) { if let slider = modal.component(ofType: SliderComponent.self) {
slider.sliderNode.removeFromParent() slider.sliderNode.removeFromParent()
slider.sliderNode.sliderKnob.removeFromParent() slider.sliderNode.hiddenKnob.removeFromParent()
slider.sliderNode.sliderLine.removeFromParent() slider.sliderNode.sliderLine.removeFromParent()
} }

View File

@ -101,7 +101,7 @@ class HUD: GKEntity {
roundsLabel = SKLabelNode(fontNamed: "Courier-Bold") roundsLabel = SKLabelNode(fontNamed: "Courier-Bold")
roundLabel = SKLabelNode(fontNamed: "Courier-Bold") roundLabel = SKLabelNode(fontNamed: "Courier-Bold")
blockWholeScreenPane = SKSpriteNode(color: UIColor.init(red: 0, green: 0, blue: 0, alpha: 0.7), size: size) blockWholeScreenPane = SKSpriteNode(color: UIColor.init(red: 0, green: 0, blue: 0, alpha: 0), size: size)
blockWholeScreenPane.position = CGPoint(x: size.width * 0.5, y: size.height * 0.5) blockWholeScreenPane.position = CGPoint(x: size.width * 0.5, y: size.height * 0.5)
blockWholeScreenPane.zPosition = 899 blockWholeScreenPane.zPosition = 899
blockWholeScreenPane.isHidden = true blockWholeScreenPane.isHidden = true

View File

@ -53,11 +53,11 @@ class Modal: GKEntity{
switch modaltype { switch modaltype {
case .BaseAttack: case .BaseAttack:
header = SKLabelNode(text: "Angriff") header = SKLabelNode(text: "Angriff")
body = SKLabelNode(text: "Schicke \(unitCount / 2)\nEinheiten") body = SKLabelNode(text: "\(unitCount / 2) Einheiten")
footer = SKLabelNode() footer = SKLabelNode()
case .BaseMoveOwnUnits: case .BaseMoveOwnUnits:
header = SKLabelNode(text: "Formation") header = SKLabelNode(text: "Formation")
body = SKLabelNode(text: "Sende \(unitCount / 2)\nEinheiten") body = SKLabelNode(text: "\(unitCount / 2) Einheiten")
footer = SKLabelNode() footer = SKLabelNode()
case .PauseGame: case .PauseGame:
header = SKLabelNode(text: "Pause") header = SKLabelNode(text: "Pause")
@ -71,7 +71,7 @@ class Modal: GKEntity{
self.header.fontSize = 40 self.header.fontSize = 40
self.header.zPosition = 5 self.header.zPosition = 5
self.body.position = CGPoint(x: anchorPoint.x, y: anchorPoint.y - 20) self.body.position = CGPoint(x: anchorPoint.x, y: anchorPoint.y + 15)
self.body.numberOfLines = 2 self.body.numberOfLines = 2
self.body.preferredMaxLayoutWidth = 390 self.body.preferredMaxLayoutWidth = 390
self.body.horizontalAlignmentMode = SKLabelHorizontalAlignmentMode.center self.body.horizontalAlignmentMode = SKLabelHorizontalAlignmentMode.center
@ -86,17 +86,14 @@ class Modal: GKEntity{
super.init() super.init()
switch modaltype{
case .BaseAttack, .BaseMoveOwnUnits:
let text = (modaltype == .BaseAttack) ? "Angriff" : "Senden" let text = (modaltype == .BaseAttack) ? "Angriff" : "Senden"
addComponent(SliderComponent(width: 300, position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 50))) addComponent(SliderComponent(width: 300, position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 15)))
addComponent(ButtonComponent(textureName: "yellow_button04", text: text, 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 - 95), isEnabled: true, onButtonPress: {
self.sendUnits(currentDraggedBase: currentDraggedBase, touchLocation: touchLocation!, gameScene: gameScene, collisionBase: collisionBase) self.sendUnits(currentDraggedBase: currentDraggedBase, touchLocation: touchLocation!, gameScene: gameScene, collisionBase: collisionBase)
EntityManager.gameEMInstance.removeModal() EntityManager.gameEMInstance.removeModal()
})) }))
default:
break
}
} }
required init?(coder: NSCoder) { required init?(coder: NSCoder) {

View File

@ -81,6 +81,7 @@ class GameScene: SKScene{
if GameCenterManager.sharedInstance.gameEnded && !gameEndEffects { if GameCenterManager.sharedInstance.gameEnded && !gameEndEffects {
gameEnd() gameEnd()
} }
} }
func addAttackDetails(touchLocation: CGPoint){ func addAttackDetails(touchLocation: CGPoint){
@ -119,7 +120,7 @@ class GameScene: SKScene{
} else if Int(GameScene.sendUnits) == currentDraggedBase?.unitCount { } else if Int(GameScene.sendUnits) == currentDraggedBase?.unitCount {
GameScene.sendUnits -= 1 GameScene.sendUnits -= 1
} }
modal.body.text = "Schicke \(GameScene.sendUnits) Einheiten " modal.body.text = "\(GameScene.sendUnits) Einheiten "
} }
} }
} }