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

@ -10,58 +10,70 @@ import SpriteKit
class SliderNode :SKNode {
var sliderLine :SKShapeNode
var sliderKnob :SliderKnob
var width: CGFloat
var getValue: CGFloat{
get{
return ((sliderKnob.position.x.rounded() - sliderKnob.min) / width)
}
}
init(width: CGFloat, position: CGPoint) {
self.width = width
sliderLine = SKShapeNode(rectOf: CGSize(width: width, height: 8))
sliderLine.position = position
sliderLine.fillColor = SKColor.white
var sliderLine :SKShapeNode
var hiddenKnob :SliderKnob
var silderKnob :SKSpriteNode
var width: CGFloat
var getValue: CGFloat{
get{
silderKnob.position = hiddenKnob.position
return ((hiddenKnob.position.x.rounded() - hiddenKnob.min) / width)
}
}
init(width: CGFloat, position: CGPoint) {
self.width = width
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
sliderKnob.fillColor = SKColor.red
sliderKnob.zPosition = sliderLine.zPosition + 1
sliderKnob.position = CGPoint(x: sliderLine.position.x, y: sliderLine.position.y + 1)
super.init()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
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) {
fatalError("init(coder:) has not been implemented")
}
}
class SliderKnob: SKShapeNode {
var min = CGFloat()
var max = CGFloat()
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
let touchLocation = touch.location(in: self.scene!)
if self.position.x >= min - 1 && self.position.x <= max + 1{
self.position.x = touchLocation.x
}
if(self.position.x <= min){
self.position.x = min
}
if(self.position.x >= max){
self.position.x = max
}
}
}
var min = CGFloat()
var max = CGFloat()
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
let touchLocation = touch.location(in: self.scene!)
if self.position.x >= min - 1 && self.position.x <= max + 1{
self.position.x = touchLocation.x
}
if(self.position.x <= min){
self.position.x = min
}
if(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 {
scene.addChild(sliderNode.sliderKnob)
scene.addChild(sliderNode.hiddenKnob)
scene.addChild(sliderNode.sliderLine)
scene.addChild(sliderNode.silderKnob)
}
if let labelNode = entity.component(ofType: LabelComponent.self)?.labelNode {
scene.addChild(labelNode)
@ -102,8 +103,9 @@ class EntityManager {
spriteNode.removeFromParent()
}
if let sliderNode = entity.component(ofType: SliderComponent.self)?.sliderNode {
sliderNode.sliderKnob.removeFromParent()
sliderNode.hiddenKnob.removeFromParent()
sliderNode.sliderLine.removeFromParent()
sliderNode.silderKnob.removeFromParent()
}
if let modalButton = entity.component(ofType: ButtonComponent.self) {
modalButton.buttonNode.removeFromParent()
@ -336,7 +338,7 @@ class EntityManager {
if let slider = modal.component(ofType: SliderComponent.self) {
slider.sliderNode.removeFromParent()
slider.sliderNode.sliderKnob.removeFromParent()
slider.sliderNode.hiddenKnob.removeFromParent()
slider.sliderNode.sliderLine.removeFromParent()
}

View File

@ -101,7 +101,7 @@ class HUD: GKEntity {
roundsLabel = 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.zPosition = 899
blockWholeScreenPane.isHidden = true

View File

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

View File

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