// // KMFunctionGuideMultiController.swift // Cisdem PDFMaster // // Created by Niehaoyu on 2023/12/6. // import Cocoa class KMFunctionGuideMultiController: NSViewController { @IBOutlet weak var contendView: NSView! @IBOutlet weak var titleInfoView: NSView! @IBOutlet weak var titleLabel: NSTextField! @IBOutlet weak var typeNameView: NSView! @IBOutlet weak var getStartBox: KMBox! @IBOutlet weak var getStartLabel: NSTextField! @IBOutlet weak var getStartButton: KMButton! @IBOutlet weak var learnButton: HyperLinkButton! @IBOutlet weak var nameHeightConst: NSLayoutConstraint! @IBOutlet weak var descriptionBGView: NSView! @IBOutlet weak var iconImage: NSImageView! @IBOutlet weak var previousButton: KMButton! @IBOutlet weak var nextButton: KMButton! @IBOutlet weak var desLabel: NSTextField! @IBOutlet weak var desSubLabel: NSTextField! let DigitalSignatureKey = "DigitalSignatureKey" let ComparePDFsKey = "ComparePDFsKey" let AIInfoKey = "AIInfoKey" var namesArr = Array() var currentNameKEY = String() var clickHandle: ((_ controller: KMFunctionGuideMultiController)->Void)? deinit { DistributedNotificationCenter.default.removeObserver(self) } override func viewDidLoad() { super.viewDidLoad() // Do view setup here. self.namesArr = [["name":"AI Tools", "key":AIInfoKey, "infoTitle":"Experience the Power of PDF AI Tools", "imageName":"whatNew_AIGuide", "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: "")]] let dict = self.namesArr.first as! NSDictionary self.currentNameKEY = dict["key"] as! String self.loadTypeNameView() self.reloadNameViewInfo() self.reloadDescriptionInfo() self.descriptionBGView.wantsLayer = true self.titleInfoView.wantsLayer = true self.getStartBox.wantsLayer = true self.getStartBox.layer?.cornerRadius = CGRectGetHeight(self.getStartBox.frame)/2 self.getStartBox.layer?.masksToBounds = true self.titleLabel.stringValue = NSLocalizedString("What‘s New", comment: "") self.getStartLabel.stringValue = NSLocalizedString("Buy Now", comment: "") self.learnButton.title = NSLocalizedString("Feedback", comment: "") self.learnButton.toolTip = NSLocalizedString("Feedback", comment: "") self.titleLabel.font = NSFont.SFProTextHeavyFont(20) self.getStartLabel.font = NSFont.SFProTextSemiboldFont(14) self.learnButton.font = NSFont.SFProTextSemiboldFont(14) self.desLabel.font = NSFont.SFProTextSemiboldFont(14) self.desSubLabel.font = NSFont.SFProTextRegularFont(14) self.getStartButton.wantsLayer = true self.getStartButton.mouseMoveCallback = { [weak self] mouseEntered in if KMAppearance.isDarkMode() { if mouseEntered { self?.getStartButton.layer?.backgroundColor = NSColor.white.withAlphaComponent(0.2).cgColor } else { self?.getStartButton.layer?.backgroundColor = NSColor.clear.cgColor } } else { if mouseEntered { self?.getStartButton.layer?.backgroundColor = NSColor.white.withAlphaComponent(0.2).cgColor } else { self?.getStartButton.layer?.backgroundColor = NSColor.clear.cgColor } } } self.learnButton.mouseMoveCallback = { [weak self] mouseEntered in if mouseEntered { self?.learnButton.setTitleColor(KMAppearance.KMColor_Interactive_M1()) } else { self?.learnButton.setTitleColor(KMAppearance.KMColor_Interactive_M0()) } } DistributedNotificationCenter.default().addObserver(self, selector: #selector(themeChange), name: NSNotification.Name(rawValue: "AppleInterfaceThemeChangedNotification"), object: nil) self.updateViewColor() } func loadTypeNameView() { // self.typeNameView.wantsLayer = true // self.typeNameView.layer?.backgroundColor = NSColor.red.cgColor var offsetY: CGFloat = 0 let itemHeight: CGFloat = 32 let viewHeight: CGFloat = itemHeight * CGFloat(self.namesArr.count) self.nameHeightConst.constant = viewHeight for i in 0...self.namesArr.count - 1 { let dict = self.namesArr[i] let nameItem: KMFunctionGuideNameItemView = KMFunctionGuideNameItemView.createFromNib()! nameItem.frame = CGRectMake(0, viewHeight - offsetY - itemHeight, CGRectGetWidth(self.typeNameView.frame), itemHeight) nameItem.infoDict = dict as! NSDictionary nameItem.clickHandle = {[weak self] view in self?.currentNameKEY = view.infoDict["key"] as! String self?.reloadNameViewInfo() self?.reloadDescriptionInfo() } nameItem.autoresizingMask = [.width, .maxYMargin] self.typeNameView.addSubview(nameItem) offsetY += itemHeight } if self.namesArr.count > 1 { self.previousButton.isHidden = false self.nextButton.isHidden = false } else { self.previousButton.isHidden = true self.nextButton.isHidden = true } } func reloadNameViewInfo() { for view in self.typeNameView.subviews { if view is KMFunctionGuideNameItemView { let itemView = view as! KMFunctionGuideNameItemView if itemView.infoDict["key"] as! String == self.currentNameKEY { itemView.isSelected = true } else { itemView.isSelected = false } } } } func reloadDescriptionInfo() { self.previousButton.isEnabled = true self.nextButton.isEnabled = true for i in 0...self.namesArr.count - 1 { let dict = self.namesArr[i] as! NSDictionary if dict["key"] as! String == self.currentNameKEY { self.desLabel.stringValue = NSLocalizedString(dict["infoTitle"] as! String, comment: "") self.desSubLabel.stringValue = NSLocalizedString(dict["description"] as! String, comment: "") self.iconImage.image = NSImage(named: dict["imageName"] as! String) } let keyValue = dict["key"] as! String if i == 0 && keyValue == self.currentNameKEY { self.previousButton.isEnabled = false } else if i == self.namesArr.count - 1 && keyValue == self.currentNameKEY { self.nextButton.isEnabled = false } } } func updateViewColor() { self.getStartBox.fillColor = KMAppearance.KMColor_Interactive_A0() self.getStartLabel.textColor = KMAppearance.KMColor_Layout_W0() self.learnButton.setTitleColor(KMAppearance.KMColor_Interactive_M0()) if KMAppearance.isDarkMode() { self.titleInfoView.layer?.backgroundColor = NSColor(red: 14/255.0, green: 17/255, blue: 20/255, alpha: 1).cgColor self.descriptionBGView.layer?.backgroundColor = NSColor(red: 40/255.0, green: 40/255, blue: 40/255, alpha: 1).cgColor self.titleLabel.textColor = NSColor.white self.desLabel.textColor = NSColor.white self.desSubLabel.textColor = NSColor(red: 200/255, green: 201/255, blue: 204/255, alpha: 1) self.getStartBox.fillColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 1) } else { self.titleInfoView.layer?.backgroundColor = NSColor(red: 249/255.0, green: 249/255, blue: 252/255, alpha: 1).cgColor self.descriptionBGView.layer?.backgroundColor = NSColor.white.cgColor self.titleLabel.textColor = NSColor(red: 0, green: 33/255, blue: 67/255, alpha: 1) self.desLabel.textColor = NSColor(red: 14/255, green: 17/255, blue: 20/255, alpha: 1) self.desSubLabel.textColor = NSColor(red: 14/255, green: 17/255, blue: 20/255, alpha: 1) self.getStartBox.fillColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 1) } for view in self.typeNameView.subviews { if view is KMFunctionGuideNameItemView { let itemView = view as! KMFunctionGuideNameItemView itemView.updateViewColor() } } } //MARK: IBAction @IBAction func getStartAction(_ sender: Any) { guard let callBack = self.clickHandle else { return } callBack(self) } @IBAction func learnMoreAction(_ sender: Any) { let url = URL(string:NSLocalizedString("https://forms.gle/crjCAW4cnF7eq1vQ6", comment: ""))! NSWorkspace.shared.open(url) } @IBAction func previousAction(_ sender: Any) { for i in 0...self.namesArr.count - 1 { let dict = self.namesArr[i] as! NSDictionary if dict["key"] as! String == self.currentNameKEY { if i > 0 { let preDic = self.namesArr[i-1] as! NSDictionary self.currentNameKEY = preDic["key"] as! String break } } } self.reloadNameViewInfo() self.reloadDescriptionInfo() } @IBAction func nextAction(_ sender: Any) { for i in 0...self.namesArr.count - 1 { let dict = self.namesArr[i] as! NSDictionary if dict["key"] as! String == self.currentNameKEY { if i < self.namesArr.count { let nextDic = self.namesArr[i+1] as! NSDictionary self.currentNameKEY = nextDic["key"] as! String break } } } self.reloadNameViewInfo() self.reloadDescriptionInfo() } @objc func themeChange() { DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) { self.updateViewColor() } } }