KMFunctionGuideMultiController.swift 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. //
  2. // KMFunctionGuideMultiController.swift
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by Niehaoyu on 2023/12/6.
  6. //
  7. import Cocoa
  8. class KMFunctionGuideMultiController: NSViewController {
  9. @IBOutlet weak var contendView: NSView!
  10. @IBOutlet weak var titleInfoView: NSView!
  11. @IBOutlet weak var titleLabel: NSTextField!
  12. @IBOutlet weak var typeNameView: NSView!
  13. @IBOutlet weak var getStartBox: KMBox!
  14. @IBOutlet weak var getStartLabel: NSTextField!
  15. @IBOutlet weak var getStartButton: KMButton!
  16. @IBOutlet weak var learnButton: HyperLinkButton!
  17. @IBOutlet weak var nameHeightConst: NSLayoutConstraint!
  18. @IBOutlet weak var descriptionBGView: NSView!
  19. @IBOutlet weak var iconImage: NSImageView!
  20. @IBOutlet weak var previousButton: KMButton!
  21. @IBOutlet weak var nextButton: KMButton!
  22. @IBOutlet weak var desLabel: NSTextField!
  23. @IBOutlet weak var desSubLabel: NSTextField!
  24. let DigitalSignatureKey = "DigitalSignatureKey"
  25. let ComparePDFsKey = "ComparePDFsKey"
  26. let AIInfoKey = "AIInfoKey"
  27. var namesArr = Array<Any>()
  28. var currentNameKEY = String()
  29. var clickHandle: ((_ controller: KMFunctionGuideMultiController)->Void)?
  30. deinit {
  31. DistributedNotificationCenter.default.removeObserver(self)
  32. }
  33. override func viewDidLoad() {
  34. super.viewDidLoad()
  35. // Do view setup here.
  36. self.namesArr = [["name":"AI Tools",
  37. "key":AIInfoKey,
  38. "infoTitle":"Experience the Power of PDF AI Tools",
  39. "imageName":"whatNew_AIGuide",
  40. "description":NSLocalizedString("• AI Summarize with a deep understanding of document", comment: "") + "\n" + NSLocalizedString("• AI Translate your document without leaving a PDF", comment: "") + "\n" + NSLocalizedString("• Check grammar, fix spelling errors to ensure a professional file", comment: "") + "\n" + NSLocalizedString("• Rewrite your PDF to enhance style and polish content", comment: "")]]
  41. let dict = self.namesArr.first as! NSDictionary
  42. self.currentNameKEY = dict["key"] as! String
  43. self.loadTypeNameView()
  44. self.reloadNameViewInfo()
  45. self.reloadDescriptionInfo()
  46. self.descriptionBGView.wantsLayer = true
  47. self.titleInfoView.wantsLayer = true
  48. self.getStartBox.wantsLayer = true
  49. self.getStartBox.layer?.cornerRadius = CGRectGetHeight(self.getStartBox.frame)/2
  50. self.getStartBox.layer?.masksToBounds = true
  51. self.titleLabel.stringValue = NSLocalizedString("What‘s New", comment: "")
  52. self.getStartLabel.stringValue = NSLocalizedString("Buy Now", comment: "")
  53. self.learnButton.title = NSLocalizedString("Feedback", comment: "")
  54. self.learnButton.toolTip = NSLocalizedString("Feedback", comment: "")
  55. self.titleLabel.font = NSFont.SFProTextHeavyFont(20)
  56. self.getStartLabel.font = NSFont.SFProTextSemiboldFont(14)
  57. self.learnButton.font = NSFont.SFProTextSemiboldFont(14)
  58. self.desLabel.font = NSFont.SFProTextSemiboldFont(14)
  59. self.desSubLabel.font = NSFont.SFProTextRegularFont(14)
  60. self.getStartButton.wantsLayer = true
  61. self.getStartButton.mouseMoveCallback = { [weak self] mouseEntered in if KMAppearance.isDarkMode() {
  62. if mouseEntered {
  63. self?.getStartButton.layer?.backgroundColor = NSColor.white.withAlphaComponent(0.2).cgColor
  64. } else {
  65. self?.getStartButton.layer?.backgroundColor = NSColor.clear.cgColor
  66. }
  67. } else {
  68. if mouseEntered {
  69. self?.getStartButton.layer?.backgroundColor = NSColor.white.withAlphaComponent(0.2).cgColor
  70. } else {
  71. self?.getStartButton.layer?.backgroundColor = NSColor.clear.cgColor
  72. }
  73. }
  74. }
  75. self.learnButton.mouseMoveCallback = { [weak self] mouseEntered in
  76. if mouseEntered {
  77. self?.learnButton.setTitleColor(KMAppearance.KMColor_Interactive_M1())
  78. } else {
  79. self?.learnButton.setTitleColor(KMAppearance.KMColor_Interactive_M0())
  80. }
  81. }
  82. DistributedNotificationCenter.default().addObserver(self, selector: #selector(themeChange), name: NSNotification.Name(rawValue: "AppleInterfaceThemeChangedNotification"), object: nil)
  83. self.updateViewColor()
  84. }
  85. func loadTypeNameView() {
  86. // self.typeNameView.wantsLayer = true
  87. // self.typeNameView.layer?.backgroundColor = NSColor.red.cgColor
  88. var offsetY: CGFloat = 0
  89. let itemHeight: CGFloat = 32
  90. let viewHeight: CGFloat = itemHeight * CGFloat(self.namesArr.count)
  91. self.nameHeightConst.constant = viewHeight
  92. for i in 0...self.namesArr.count - 1 {
  93. let dict = self.namesArr[i]
  94. let nameItem: KMFunctionGuideNameItemView = KMFunctionGuideNameItemView.createFromNib()!
  95. nameItem.frame = CGRectMake(0, viewHeight - offsetY - itemHeight, CGRectGetWidth(self.typeNameView.frame), itemHeight)
  96. nameItem.infoDict = dict as! NSDictionary
  97. nameItem.clickHandle = { view in
  98. self.currentNameKEY = view.infoDict["key"] as! String
  99. self.reloadNameViewInfo()
  100. self.reloadDescriptionInfo()
  101. }
  102. nameItem.autoresizingMask = [.width, .maxYMargin]
  103. self.typeNameView.addSubview(nameItem)
  104. offsetY += itemHeight
  105. }
  106. if self.namesArr.count > 1 {
  107. self.previousButton.isHidden = false
  108. self.nextButton.isHidden = false
  109. } else {
  110. self.previousButton.isHidden = true
  111. self.nextButton.isHidden = true
  112. }
  113. }
  114. func reloadNameViewInfo() {
  115. for view in self.typeNameView.subviews {
  116. if view is KMFunctionGuideNameItemView {
  117. let itemView = view as! KMFunctionGuideNameItemView
  118. if itemView.infoDict["key"] as! String == self.currentNameKEY {
  119. itemView.isSelected = true
  120. } else {
  121. itemView.isSelected = false
  122. }
  123. }
  124. }
  125. }
  126. func reloadDescriptionInfo() {
  127. self.previousButton.isEnabled = true
  128. self.nextButton.isEnabled = true
  129. for i in 0...self.namesArr.count - 1 {
  130. let dict = self.namesArr[i] as! NSDictionary
  131. if dict["key"] as! String == self.currentNameKEY {
  132. self.desLabel.stringValue = NSLocalizedString(dict["infoTitle"] as! String, comment: "")
  133. self.desSubLabel.stringValue = NSLocalizedString(dict["description"] as! String, comment: "")
  134. self.iconImage.image = NSImage(named: dict["imageName"] as! String)
  135. }
  136. let keyValue = dict["key"] as! String
  137. if i == 0 && keyValue == self.currentNameKEY {
  138. self.previousButton.isEnabled = false
  139. } else if i == self.namesArr.count - 1 && keyValue == self.currentNameKEY {
  140. self.nextButton.isEnabled = false
  141. }
  142. }
  143. }
  144. func updateViewColor() {
  145. self.getStartBox.fillColor = KMAppearance.KMColor_Interactive_A0()
  146. self.getStartLabel.textColor = KMAppearance.KMColor_Layout_W0()
  147. self.learnButton.setTitleColor(KMAppearance.KMColor_Interactive_M0())
  148. if KMAppearance.isDarkMode() {
  149. self.titleInfoView.layer?.backgroundColor = NSColor(red: 14/255.0, green: 17/255, blue: 20/255, alpha: 1).cgColor
  150. self.descriptionBGView.layer?.backgroundColor = NSColor(red: 40/255.0, green: 40/255, blue: 40/255, alpha: 1).cgColor
  151. self.titleLabel.textColor = NSColor.white
  152. self.desLabel.textColor = NSColor.white
  153. self.desSubLabel.textColor = NSColor(red: 200/255, green: 201/255, blue: 204/255, alpha: 1)
  154. self.getStartBox.fillColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 1)
  155. } else {
  156. self.titleInfoView.layer?.backgroundColor = NSColor(red: 249/255.0, green: 249/255, blue: 252/255, alpha: 1).cgColor
  157. self.descriptionBGView.layer?.backgroundColor = NSColor.white.cgColor
  158. self.titleLabel.textColor = NSColor(red: 0, green: 33/255, blue: 67/255, alpha: 1)
  159. self.desLabel.textColor = NSColor(red: 14/255, green: 17/255, blue: 20/255, alpha: 1)
  160. self.desSubLabel.textColor = NSColor(red: 14/255, green: 17/255, blue: 20/255, alpha: 1)
  161. self.getStartBox.fillColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 1)
  162. }
  163. for view in self.typeNameView.subviews {
  164. if view is KMFunctionGuideNameItemView {
  165. let itemView = view as! KMFunctionGuideNameItemView
  166. itemView.updateViewColor()
  167. }
  168. }
  169. }
  170. //MARK: IBAction
  171. @IBAction func getStartAction(_ sender: Any) {
  172. guard let callBack = self.clickHandle else {
  173. return
  174. }
  175. callBack(self)
  176. }
  177. @IBAction func learnMoreAction(_ sender: Any) {
  178. let url = URL(string:NSLocalizedString("https://forms.gle/crjCAW4cnF7eq1vQ6", comment: ""))!
  179. NSWorkspace.shared.open(url)
  180. }
  181. @IBAction func previousAction(_ sender: Any) {
  182. for i in 0...self.namesArr.count - 1 {
  183. let dict = self.namesArr[i] as! NSDictionary
  184. if dict["key"] as! String == self.currentNameKEY {
  185. if i > 0 {
  186. let preDic = self.namesArr[i-1] as! NSDictionary
  187. self.currentNameKEY = preDic["key"] as! String
  188. break
  189. }
  190. }
  191. }
  192. self.reloadNameViewInfo()
  193. self.reloadDescriptionInfo()
  194. }
  195. @IBAction func nextAction(_ sender: Any) {
  196. for i in 0...self.namesArr.count - 1 {
  197. let dict = self.namesArr[i] as! NSDictionary
  198. if dict["key"] as! String == self.currentNameKEY {
  199. if i < self.namesArr.count {
  200. let nextDic = self.namesArr[i+1] as! NSDictionary
  201. self.currentNameKEY = nextDic["key"] as! String
  202. break
  203. }
  204. }
  205. }
  206. self.reloadNameViewInfo()
  207. self.reloadDescriptionInfo()
  208. }
  209. @objc func themeChange() {
  210. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
  211. self.updateViewColor()
  212. }
  213. }
  214. }