mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-15 21:45:19 +00:00
Update slot machine animation
This commit is contained in:
parent
081713ec6f
commit
0e9412fbc9
@ -762,13 +762,7 @@ public final class AnimatedStickerNode: ASDisplayNode {
|
||||
return self.playbackStatus.get()
|
||||
}
|
||||
|
||||
public var autoplay = true {
|
||||
didSet {
|
||||
if self.autoplay != oldValue {
|
||||
self.updateIsPlaying()
|
||||
}
|
||||
}
|
||||
}
|
||||
public var autoplay = false
|
||||
|
||||
public var visibility = false {
|
||||
didSet {
|
||||
@ -835,9 +829,12 @@ public final class AnimatedStickerNode: ASDisplayNode {
|
||||
strongSelf.directData = (directData, path, width, height, cachePathPrefix, source.fitzModifier)
|
||||
}
|
||||
if case let .still(position) = playbackMode {
|
||||
strongSelf.play(firstFrame: true)
|
||||
strongSelf.seekTo(position)
|
||||
} else if strongSelf.isPlaying {
|
||||
} else if strongSelf.isPlaying || strongSelf.autoplay {
|
||||
if strongSelf.autoplay {
|
||||
strongSelf.isSetUpForPlayback = false
|
||||
strongSelf.isPlaying = true
|
||||
}
|
||||
strongSelf.play()
|
||||
} else if strongSelf.canDisplayFirstFrame {
|
||||
strongSelf.play(firstFrame: true)
|
||||
@ -884,11 +881,14 @@ public final class AnimatedStickerNode: ASDisplayNode {
|
||||
}
|
||||
|
||||
private func updateIsPlaying() {
|
||||
guard !self.autoplay else {
|
||||
return
|
||||
}
|
||||
let isPlaying = self.visibility && self.isDisplaying
|
||||
if self.isPlaying != isPlaying {
|
||||
self.isPlaying = isPlaying
|
||||
if isPlaying {
|
||||
self.play(firstFrame: !self.autoplay)
|
||||
self.play()
|
||||
} else{
|
||||
self.pause()
|
||||
}
|
||||
@ -1091,7 +1091,6 @@ public final class AnimatedStickerNode: ASDisplayNode {
|
||||
var maybeFrameSource: AnimatedStickerFrameSource? = frameSourceHolder.with { $0 }?.syncWith { $0 }?.value
|
||||
if case .timestamp = position {
|
||||
} else {
|
||||
var maybeFrameSource: AnimatedStickerFrameSource?
|
||||
if let directData = directData {
|
||||
maybeFrameSource = AnimatedStickerDirectFrameSource(queue: queue, data: directData.0, width: directData.2, height: directData.3, cachePathPrefix: directData.4, fitzModifier: directData.5)
|
||||
if case .end = position {
|
||||
|
@ -146,9 +146,9 @@ public enum ManagedSlotMachineAnimationState: Equatable {
|
||||
|
||||
public final class SlotMachineAnimationNode: ASDisplayNode {
|
||||
private let backNode: ManagedAnimationNode
|
||||
private let leftReelNode: ManagedAnimationNode
|
||||
private let centerReelNode: ManagedAnimationNode
|
||||
private let rightReelNode: ManagedAnimationNode
|
||||
private let leftReelNode: DiceAnimatedStickerNode
|
||||
private let centerReelNode: DiceAnimatedStickerNode
|
||||
private let rightReelNode: DiceAnimatedStickerNode
|
||||
private let frontNode: ManagedAnimationNode
|
||||
|
||||
private var diceState: ManagedSlotMachineAnimationState? = nil
|
||||
@ -161,9 +161,10 @@ public final class SlotMachineAnimationNode: ASDisplayNode {
|
||||
public init(size: CGSize = CGSize(width: 184.0, height: 184.0)) {
|
||||
self.animationSize = size
|
||||
self.backNode = ManagedAnimationNode(size: self.animationSize)
|
||||
self.leftReelNode = ManagedAnimationNode(size: self.animationSize)
|
||||
self.centerReelNode = ManagedAnimationNode(size: self.animationSize)
|
||||
self.rightReelNode = ManagedAnimationNode(size: self.animationSize)
|
||||
let reelSize = CGSize(width: 384.0, height: 384.0)
|
||||
self.leftReelNode = DiceAnimatedStickerNode(size: reelSize)
|
||||
self.centerReelNode = DiceAnimatedStickerNode(size: reelSize)
|
||||
self.rightReelNode = DiceAnimatedStickerNode(size: reelSize)
|
||||
self.frontNode = ManagedAnimationNode(size: self.animationSize)
|
||||
|
||||
super.init()
|
||||
@ -261,7 +262,7 @@ class DiceAnimatedStickerNode: ASDisplayNode {
|
||||
self.intrinsicSize = size
|
||||
|
||||
self.animationNode = AnimatedStickerNode()
|
||||
self.animationNode.visibility = true
|
||||
self.animationNode.autoplay = true
|
||||
|
||||
super.init()
|
||||
|
||||
@ -281,6 +282,15 @@ class DiceAnimatedStickerNode: ASDisplayNode {
|
||||
}
|
||||
}
|
||||
|
||||
var initialized = false
|
||||
override func didLoad() {
|
||||
super.didLoad()
|
||||
|
||||
self.initialized = true
|
||||
self.advanceState()
|
||||
}
|
||||
|
||||
|
||||
private func advanceState() {
|
||||
guard !self.trackStack.isEmpty else {
|
||||
return
|
||||
@ -329,7 +339,7 @@ class DiceAnimatedStickerNode: ASDisplayNode {
|
||||
self.trackStack.append(item)
|
||||
self.didTryAdvancingState = false
|
||||
|
||||
if !self.animationNode.isPlaying {
|
||||
if !self.animationNode.isPlaying && self.initialized {
|
||||
self.advanceState()
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user