HomeView.swift 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import SwiftUI
  2. struct HomeView: View {
  3. @EnvironmentObject private var language: LanguageStore
  4. @EnvironmentObject private var store: GameStore
  5. @EnvironmentObject private var platform: PlatformBootstrap
  6. let openDaily: () -> Void
  7. let newGame: () -> Void
  8. var body: some View {
  9. GeometryReader { geometry in
  10. ScrollView(showsIndicators: false) {
  11. Group {
  12. if geometry.size.width >= 800 && geometry.size.width > geometry.size.height {
  13. HStack(spacing: 70) {
  14. brand(compact: false).frame(maxWidth: .infinity)
  15. VStack(spacing: 30) { dailyCard; bestScore; gameButtons }.frame(maxWidth: 420)
  16. }.padding(40).frame(maxWidth: 1040).frame(minHeight: geometry.size.height)
  17. } else {
  18. VStack(spacing: 0) {
  19. Spacer(minLength: 12)
  20. brand(compact: store.resumableGame != nil || geometry.size.height < 660)
  21. Spacer(minLength: 18)
  22. dailyCard.padding(.horizontal, 26)
  23. Spacer(minLength: 16)
  24. bestScore
  25. Spacer(minLength: 18)
  26. gameButtons.padding(.horizontal, 38)
  27. Spacer(minLength: 16)
  28. }.frame(maxWidth: 580).frame(minHeight: geometry.size.height)
  29. }
  30. }.frame(maxWidth: .infinity)
  31. }.background { SoftBackground() }
  32. }
  33. }
  34. private func brand(compact: Bool) -> some View {
  35. VStack(spacing: compact ? 8 : 10) {
  36. JokerEmblem(size: compact ? 94 : 112)
  37. Text("JOKER").font(.system(size: compact ? 36 : 41, weight: .black, design: .rounded)).tracking(7).padding(.leading, 7)
  38. .foregroundStyle(Palette.ink)
  39. HStack(spacing: 12) {
  40. Rectangle().fill(Palette.line).frame(width: 26, height: 1)
  41. Text("S U D O K U").font(.system(size: 11, weight: .semibold)).tracking(3).foregroundStyle(Palette.blue)
  42. Rectangle().fill(Palette.line).frame(width: 26, height: 1)
  43. }
  44. Text(language.text("Every square holds a possibility")).font(.system(size: 13)).tracking(language.selected == .english ? 0.5 : 3).foregroundStyle(Palette.muted).padding(.top, 9)
  45. }.accessibilityElement(children: .combine)
  46. }
  47. private var bestScore: some View {
  48. VStack(spacing: 9) {
  49. Text(language.text("Best Score")).font(.system(size: 14)).foregroundStyle(Palette.muted)
  50. HStack(spacing: 9) {
  51. Image(systemName: "trophy.fill").font(.system(size: 23)).foregroundStyle(Palette.gold)
  52. Text(store.statistics.bestScore.formatted()).font(.system(size: 33, weight: .medium, design: .rounded)).monospacedDigit().foregroundStyle(Palette.ink)
  53. }
  54. }
  55. }
  56. private var gameButtons: some View {
  57. VStack(spacing: 13) {
  58. if let saved = store.resumableGame {
  59. PrimaryButton(title: "Continue Game") { store.resume(saved) }.accessibilityIdentifier("home.continue")
  60. Text("\(language.text(saved.dayKey == nil ? saved.difficulty.title : "Daily Challenge")) · \(saved.timeText)")
  61. .font(.system(size: 12)).foregroundStyle(Palette.muted)
  62. PrimaryButton(title: "New Game", outlined: true, action: newGame).accessibilityIdentifier("home.newGame")
  63. } else {
  64. PrimaryButton(title: "New Game", action: newGame).accessibilityIdentifier("home.newGame")
  65. }
  66. HStack {
  67. Spacer()
  68. Button {
  69. ClickAudio.shared.play()
  70. platform.presentSurvey(language: language.selected)
  71. } label: {
  72. Label(language.text("Player Survey"), systemImage: "bubble.left.and.bubble.right.fill")
  73. .font(.system(size: 13, weight: .semibold)).padding(.horizontal, 16).frame(minHeight: 44)
  74. .foregroundStyle(Palette.blue).background(.white, in: Capsule())
  75. .shadow(color: Palette.blue.opacity(0.16), radius: 8, y: 4)
  76. }.buttonStyle(.plain).disabled(platform.surveyURL == nil)
  77. .opacity(platform.surveyURL == nil ? 0.5 : 1)
  78. .accessibilityIdentifier("home.survey")
  79. }
  80. }
  81. }
  82. private var dailyCard: some View {
  83. Button {
  84. ClickAudio.shared.play()
  85. openDaily()
  86. } label: {
  87. HStack(spacing: 17) {
  88. ZStack {
  89. RoundedRectangle(cornerRadius: 15).fill(.white.opacity(0.18)).frame(width: 55, height: 60)
  90. Image(systemName: "calendar.badge.checkmark").font(.system(size: 29, weight: .medium))
  91. }
  92. VStack(alignment: .leading, spacing: 7) {
  93. Text(language.text("Daily Challenge")).font(.system(size: 13, weight: .medium)).foregroundStyle(.white.opacity(0.8))
  94. Text(language.date(.now))
  95. .font(.system(size: 22, weight: .semibold, design: .rounded))
  96. Text(language.text("A puzzle a day. A moment to shine.")).font(.system(size: 10)).minimumScaleFactor(0.8).lineLimit(1).foregroundStyle(.white.opacity(0.78))
  97. }
  98. Spacer(minLength: 0)
  99. Image(systemName: "chevron.right").font(.system(size: 14, weight: .semibold)).foregroundStyle(.white.opacity(0.8))
  100. }
  101. .foregroundStyle(.white).padding(20)
  102. .background(LinearGradient(colors: [Color(red: 0.28, green: 0.65, blue: 0.98), Palette.blue], startPoint: .topLeading, endPoint: .bottomTrailing), in: RoundedRectangle(cornerRadius: 22))
  103. .overlay(alignment: .topTrailing) {
  104. Circle().stroke(.white.opacity(0.08), lineWidth: 20).frame(width: 90).offset(x: 20, y: -35).clipped()
  105. }
  106. .clipShape(RoundedRectangle(cornerRadius: 22))
  107. .shadow(color: Palette.blue.opacity(0.15), radius: 15, y: 9)
  108. }.buttonStyle(.plain)
  109. }
  110. }