KMFunctionGuideMultiController.swift 12 KB

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