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