KMFunctionGuideMultiController.swift 11 KB

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