From a6ddfd500ba8a77ea947f9dd566fa2d66d321328 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Sat, 28 May 2022 21:58:06 +0800 Subject: [PATCH] Voltaire // Beep when recycling pages (each round), etc. --- .../CandidateUI/ctlCandidateHorizontal.swift | 18 ++++++++++-------- .../UI/CandidateUI/ctlCandidateVertical.swift | 18 ++++++++++-------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Source/UI/CandidateUI/ctlCandidateHorizontal.swift b/Source/UI/CandidateUI/ctlCandidateHorizontal.swift index 1d3b20f1..bfcb0953 100644 --- a/Source/UI/CandidateUI/ctlCandidateHorizontal.swift +++ b/Source/UI/CandidateUI/ctlCandidateHorizontal.swift @@ -248,7 +248,7 @@ public class ctlCandidateHorizontal: ctlCandidate { private var candidateView: HorizontalCandidateView private var prevPageButton: NSButton private var nextPageButton: NSButton - private var currentPage: UInt = 0 + private var currentPageIndex: UInt = 0 public init() { var contentRect = NSRect(x: 128.0, y: 128.0, width: 0.0, height: 0.0) @@ -325,14 +325,15 @@ public class ctlCandidateHorizontal: ctlCandidate { override public func reloadData() { candidateView.highlightedIndex = 0 - currentPage = 0 + currentPageIndex = 0 layoutCandidateView() } override public func showNextPage() -> Bool { guard delegate != nil else { return false } if pageCount == 1 { return highlightNextCandidate() } - currentPage = (currentPage + 1 >= pageCount) ? 0 : currentPage + 1 + if currentPageIndex + 1 >= pageCount { clsSFX.beep() } + currentPageIndex = (currentPageIndex + 1 >= pageCount) ? 0 : currentPageIndex + 1 candidateView.highlightedIndex = 0 layoutCandidateView() return true @@ -341,7 +342,8 @@ public class ctlCandidateHorizontal: ctlCandidate { override public func showPreviousPage() -> Bool { guard delegate != nil else { return false } if pageCount == 1 { return highlightPreviousCandidate() } - currentPage = (currentPage == 0) ? pageCount - 1 : currentPage - 1 + if currentPageIndex == 0 { clsSFX.beep() } + currentPageIndex = (currentPageIndex == 0) ? pageCount - 1 : currentPageIndex - 1 candidateView.highlightedIndex = 0 layoutCandidateView() return true @@ -368,13 +370,13 @@ public class ctlCandidateHorizontal: ctlCandidate { return UInt.max } - let result = currentPage * UInt(keyLabels.count) + index + let result = currentPageIndex * UInt(keyLabels.count) + index return result < delegate.candidateCountForController(self) ? result : UInt.max } override public var selectedCandidateIndex: UInt { get { - currentPage * UInt(keyLabels.count) + candidateView.highlightedIndex + currentPageIndex * UInt(keyLabels.count) + candidateView.highlightedIndex } set { guard let delegate = delegate else { @@ -382,7 +384,7 @@ public class ctlCandidateHorizontal: ctlCandidate { } let keyLabelCount = UInt(keyLabels.count) if newValue < delegate.candidateCountForController(self) { - currentPage = newValue / keyLabelCount + currentPageIndex = newValue / keyLabelCount candidateView.highlightedIndex = newValue % keyLabelCount layoutCandidateView() } @@ -410,7 +412,7 @@ extension ctlCandidateHorizontal { let count = delegate.candidateCountForController(self) let keyLabelCount = UInt(keyLabels.count) - let begin = currentPage * keyLabelCount + let begin = currentPageIndex * keyLabelCount for index in begin.. Bool { guard delegate != nil else { return false } if pageCount == 1 { return highlightNextCandidate() } - currentPage = (currentPage + 1 >= pageCount) ? 0 : currentPage + 1 + if currentPageIndex + 1 >= pageCount { clsSFX.beep() } + currentPageIndex = (currentPageIndex + 1 >= pageCount) ? 0 : currentPageIndex + 1 candidateView.highlightedIndex = 0 layoutCandidateView() return true @@ -345,7 +346,8 @@ public class ctlCandidateVertical: ctlCandidate { override public func showPreviousPage() -> Bool { guard delegate != nil else { return false } if pageCount == 1 { return highlightPreviousCandidate() } - currentPage = (currentPage == 0) ? pageCount - 1 : currentPage - 1 + if currentPageIndex == 0 { clsSFX.beep() } + currentPageIndex = (currentPageIndex == 0) ? pageCount - 1 : currentPageIndex - 1 candidateView.highlightedIndex = 0 layoutCandidateView() return true @@ -372,13 +374,13 @@ public class ctlCandidateVertical: ctlCandidate { return UInt.max } - let result = currentPage * UInt(keyLabels.count) + index + let result = currentPageIndex * UInt(keyLabels.count) + index return result < delegate.candidateCountForController(self) ? result : UInt.max } override public var selectedCandidateIndex: UInt { get { - currentPage * UInt(keyLabels.count) + candidateView.highlightedIndex + currentPageIndex * UInt(keyLabels.count) + candidateView.highlightedIndex } set { guard let delegate = delegate else { @@ -386,7 +388,7 @@ public class ctlCandidateVertical: ctlCandidate { } let keyLabelCount = UInt(keyLabels.count) if newValue < delegate.candidateCountForController(self) { - currentPage = newValue / keyLabelCount + currentPageIndex = newValue / keyLabelCount candidateView.highlightedIndex = newValue % keyLabelCount layoutCandidateView() } @@ -414,7 +416,7 @@ extension ctlCandidateVertical { let count = delegate.candidateCountForController(self) let keyLabelCount = UInt(keyLabels.count) - let begin = currentPage * keyLabelCount + let begin = currentPageIndex * keyLabelCount for index in begin..