11import Foundation
22import SpriteKit
3+ import UIKit
34
45protocol JustPlaySceneObserver : AnyObject {
56 func updateJustPlayScene( remainingTime: Int )
@@ -362,12 +363,14 @@ class JustPlayGameScene: GameScene, JustPlaySceneObserver {
362363class JustPlayScoreScene : SKScene {
363364 private let justPlayResult : JustPlayResult
364365 private let textColor = UIColor ( red: 240.0 / 255.0 , green: 239.0 / 255.0 , blue: 238.0 / 255.0 , alpha: 1.0 )
366+ private let background = UIColor ( red: 90.6 / 255.0 , green: 86.7 / 255.0 , blue: 70.6 / 255.0 , alpha: 1.0 )
365367
366368 init ( size: CGSize , proportionSet: ProportionSet , justPlayResult: JustPlayResult ) {
367369 self . justPlayResult = justPlayResult
368370 _ = proportionSet
369371 super. init ( size: size)
370- self . backgroundColor = UIColor ( red: 90.6 / 255.0 , green: 86.7 / 255.0 , blue: 70.6 / 255 , alpha: 1.0 )
372+ self . backgroundColor = background
373+ addBackgroundDecor ( )
371374 addLabels ( )
372375 addButtons ( )
373376 }
@@ -379,35 +382,21 @@ class JustPlayScoreScene: SKScene {
379382 private func addLabels( ) {
380383 let title = SKLabelNode ( fontNamed: " Optima-Bold " )
381384 title. text = " Level \( justPlayResult. levelCount) Complete "
382- title. fontSize = min ( size. width, size. height) * 0.07
385+ title. fontSize = min ( size. width, size. height) * 0.082
383386 title. fontColor = textColor
384- title. position = CGPoint ( x: size. width * 0.5 , y: size. height * 0.82 )
387+ title. position = CGPoint ( x: size. width * 0.5 , y: size. height * 0.84 )
385388 addChild ( title)
386389
387- let score = SKLabelNode ( fontNamed: " Optima-Bold " )
388- score. text = " Score: \( justPlayResult. lastScore) -> \( justPlayResult. score) "
389- score. fontSize = min ( size. width, size. height) * 0.052
390- score. fontColor = textColor
391- score. position = CGPoint ( x: size. width * 0.5 , y: size. height * 0.60 )
392- addChild ( score)
393-
394- let time = SKLabelNode ( fontNamed: " Optima-Bold " )
395- time. text = " Time Left: \( justPlayResult. leftTime) "
396- time. fontSize = min ( size. width, size. height) * 0.043
397- time. fontColor = textColor
398- time. position = CGPoint ( x: size. width * 0.5 , y: size. height * 0.50 )
399- addChild ( time)
390+ let panel = makeInfoPanel ( centerY: size. height * 0.57 , width: size. width * 0.84 , height: size. height * 0.34 )
391+ addChild ( panel)
400392
401- let extraTime = SKLabelNode ( fontNamed: " Optima-Bold " )
402- extraTime. text = " Extra Time: + \( justPlayResult. extraTime) "
403- extraTime. fontSize = min ( size. width, size. height) * 0.043
404- extraTime. fontColor = textColor
405- extraTime. position = CGPoint ( x: size. width * 0.5 , y: size. height * 0.43 )
406- addChild ( extraTime)
393+ addInfoLine ( icon: " star.circle.fill " , text: " Score " , value: " \( justPlayResult. score) " , y: size. height * 0.64 )
394+ addInfoLine ( icon: " clock.circle.fill " , text: " Time Left " , value: " \( justPlayResult. leftTime) " , y: size. height * 0.56 )
395+ addInfoLine ( icon: " plus.circle.fill " , text: " Extra Time " , value: " + \( justPlayResult. extraTime) " , y: size. height * 0.48 )
407396
408397 let helper = SKLabelNode ( fontNamed: " Optima-Bold " )
409398 helper. text = " Continue to the next level? "
410- helper. fontSize = min ( size. width, size. height) * 0.036
399+ helper. fontSize = min ( size. width, size. height) * 0.042
411400 helper. fontColor = textColor
412401 helper. position = CGPoint ( x: size. width * 0.5 , y: size. height * 0.31 )
413402 helper. alpha = 0.9
@@ -431,6 +420,69 @@ class JustPlayScoreScene: SKScene {
431420 levelChoice. position = CGPoint ( x: size. width * 0.28 , y: size. height * 0.17 )
432421 addChild ( levelChoice)
433422 }
423+
424+ private func addBackgroundDecor( ) {
425+ let topGlow = SKShapeNode ( circleOfRadius: size. width * 0.28 )
426+ topGlow. fillColor = UIColor ( white: 1.0 , alpha: 0.05 )
427+ topGlow. strokeColor = . clear
428+ topGlow. position = CGPoint ( x: size. width * 0.15 , y: size. height * 0.88 )
429+ topGlow. zPosition = - 2
430+ addChild ( topGlow)
431+
432+ let bottomGlow = SKShapeNode ( circleOfRadius: size. width * 0.32 )
433+ bottomGlow. fillColor = UIColor ( white: 1.0 , alpha: 0.04 )
434+ bottomGlow. strokeColor = . clear
435+ bottomGlow. position = CGPoint ( x: size. width * 0.88 , y: size. height * 0.14 )
436+ bottomGlow. zPosition = - 2
437+ addChild ( bottomGlow)
438+ }
439+
440+ private func makeInfoPanel( centerY: CGFloat , width: CGFloat , height: CGFloat ) -> SKShapeNode {
441+ let rect = CGRect ( x: - width / 2.0 , y: - height / 2.0 , width: width, height: height)
442+ let panel = SKShapeNode ( rect: rect, cornerRadius: min ( width, height) * 0.08 )
443+ panel. position = CGPoint ( x: size. width * 0.5 , y: centerY)
444+ panel. fillColor = UIColor ( white: 1.0 , alpha: 0.08 )
445+ panel. strokeColor = UIColor ( white: 1.0 , alpha: 0.18 )
446+ panel. lineWidth = 2.0
447+ panel. zPosition = - 1
448+ return panel
449+ }
450+
451+ private func addInfoLine( icon: String , text: String , value: String , y: CGFloat ) {
452+ let iconNode = SKSpriteNode ( texture: makeStatIconTexture ( symbolName: icon) )
453+ iconNode. size = CGSize ( width: size. height * 0.045 , height: size. height * 0.045 )
454+ iconNode. position = CGPoint ( x: size. width * 0.18 , y: y)
455+ addChild ( iconNode)
456+
457+ let line = SKLabelNode ( fontNamed: " Optima-Bold " )
458+ line. text = " \( text) : \( value) "
459+ line. horizontalAlignmentMode = . left
460+ line. verticalAlignmentMode = . center
461+ line. fontSize = min ( size. width, size. height) * 0.056
462+ line. fontColor = textColor
463+ line. position = CGPoint ( x: size. width * 0.22 , y: y)
464+ addChild ( line)
465+ }
466+
467+ private func makeStatIconTexture( symbolName: String ) -> SKTexture {
468+ let side = size. height * 0.06
469+ let renderer = UIGraphicsImageRenderer ( size: CGSize ( width: side, height: side) )
470+ let image = renderer. image { _ in
471+ let config = UIImage . SymbolConfiguration ( pointSize: side * 0.72 , weight: . semibold)
472+ let tint = textColor
473+ if let symbol = UIImage ( systemName: symbolName, withConfiguration: config) ?
474+ . withTintColor ( tint, renderingMode: . alwaysOriginal) {
475+ let symbolRect = CGRect (
476+ x: ( side - symbol. size. width) / 2.0 ,
477+ y: ( side - symbol. size. height) / 2.0 ,
478+ width: symbol. size. width,
479+ height: symbol. size. height
480+ )
481+ symbol. draw ( in: symbolRect)
482+ }
483+ }
484+ return SKTexture ( image: image)
485+ }
434486}
435487
436488class JustPlayLostScene : SKScene {
0 commit comments