mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-10-09 03:20:48 +00:00
Fix dice
This commit is contained in:
parent
16d3b66f64
commit
25f654389a
@ -158,7 +158,9 @@ class PieChartComponentController: GeneralChartComponentController {
|
|||||||
visible: true)],
|
visible: true)],
|
||||||
totalValue: nil,
|
totalValue: nil,
|
||||||
tapAction: nil,
|
tapAction: nil,
|
||||||
hideAction: nil)
|
hideAction: { [weak self] in
|
||||||
|
self?.deselectSegment(completion: {})
|
||||||
|
})
|
||||||
return viewModel
|
return viewModel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
|
|||||||
|
|
||||||
if let telegramDice = self.telegramDice, let diceNode = self.animationNode as? ManagedDiceAnimationNode {
|
if let telegramDice = self.telegramDice, let diceNode = self.animationNode as? ManagedDiceAnimationNode {
|
||||||
if let value = telegramDice.value {
|
if let value = telegramDice.value {
|
||||||
diceNode.setState(value == 0 ? .rolling : .value(value))
|
diceNode.setState(value == 0 ? .rolling : .value(value, true))
|
||||||
} else {
|
} else {
|
||||||
diceNode.setState(.rolling)
|
diceNode.setState(.rolling)
|
||||||
}
|
}
|
||||||
@ -1169,6 +1169,13 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
|
|||||||
super.animateInsertion(currentTimestamp, duration: duration, short: short)
|
super.animateInsertion(currentTimestamp, duration: duration, short: short)
|
||||||
|
|
||||||
self.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2)
|
self.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2)
|
||||||
|
|
||||||
|
if let telegramDice = self.telegramDice, let diceNode = self.animationNode as? ManagedDiceAnimationNode, let item = self.item, item.message.effectivelyIncoming(item.context.account.peerId) {
|
||||||
|
if let value = telegramDice.value, value != 0 {
|
||||||
|
diceNode.setState(.rolling)
|
||||||
|
diceNode.setState(.value(value, false))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override func animateRemoved(_ currentTimestamp: Double, duration: Double) {
|
override func animateRemoved(_ currentTimestamp: Double, duration: Double) {
|
||||||
|
@ -10,7 +10,7 @@ import ManagedAnimationNode
|
|||||||
|
|
||||||
enum ManagedDiceAnimationState: Equatable {
|
enum ManagedDiceAnimationState: Equatable {
|
||||||
case rolling
|
case rolling
|
||||||
case value(Int32)
|
case value(Int32, Bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
final class ManagedDiceAnimationNode: ManagedAnimationNode, GenericAnimatedStickerNode {
|
final class ManagedDiceAnimationNode: ManagedAnimationNode, GenericAnimatedStickerNode {
|
||||||
@ -25,8 +25,6 @@ final class ManagedDiceAnimationNode: ManagedAnimationNode, GenericAnimatedStick
|
|||||||
self.emojis = emojis
|
self.emojis = emojis
|
||||||
|
|
||||||
super.init(size: CGSize(width: 184.0, height: 184.0))
|
super.init(size: CGSize(width: 184.0, height: 184.0))
|
||||||
|
|
||||||
self.trackTo(item: ManagedAnimationItem(source: .local("Dice_Rolling"), frames: ManagedAnimationFrameRange(startFrame: 0, endFrame: 60), duration: 1.0, loop: true))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
@ -41,7 +39,7 @@ final class ManagedDiceAnimationNode: ManagedAnimationNode, GenericAnimatedStick
|
|||||||
switch previousState {
|
switch previousState {
|
||||||
case .rolling:
|
case .rolling:
|
||||||
switch diceState {
|
switch diceState {
|
||||||
case let .value(value):
|
case let .value(value, _):
|
||||||
guard self.emojis.count == 6 else {
|
guard self.emojis.count == 6 else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -65,7 +63,7 @@ final class ManagedDiceAnimationNode: ManagedAnimationNode, GenericAnimatedStick
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.disposable.set(sticker.start(next: { [weak self] data in
|
self.disposable.set((sticker |> deliverOnMainQueue).start(next: { [weak self] data in
|
||||||
if let strongSelf = self {
|
if let strongSelf = self {
|
||||||
strongSelf.trackTo(item: ManagedAnimationItem(source: .resource(strongSelf.context.account.postbox.mediaBox, file.resource), frames: ManagedAnimationFrameRange(startFrame: 0, endFrame: 180), duration: 3.0))
|
strongSelf.trackTo(item: ManagedAnimationItem(source: .resource(strongSelf.context.account.postbox.mediaBox, file.resource), frames: ManagedAnimationFrameRange(startFrame: 0, endFrame: 180), duration: 3.0))
|
||||||
}
|
}
|
||||||
@ -83,35 +81,50 @@ final class ManagedDiceAnimationNode: ManagedAnimationNode, GenericAnimatedStick
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch diceState {
|
switch diceState {
|
||||||
case let .value(value):
|
case let .value(value, immediate):
|
||||||
guard self.emojis.count == 6 else {
|
guard self.emojis.count == 6 else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let file = self.emojis[Int(value) - 1]
|
let file = self.emojis[Int(value) - 1]
|
||||||
let dimensions = file.dimensions ?? PixelDimensions(width: 512, height: 512)
|
|
||||||
let fittedSize = dimensions.cgSize.aspectFilled(CGSize(width: 384.0, height: 384.0))
|
|
||||||
|
|
||||||
let fetched = freeMediaFileInteractiveFetched(account: self.context.account, fileReference: .standalone(media: file))
|
if let _ = self.context.account.postbox.mediaBox.completedResourcePath(file.resource) {
|
||||||
let sticker = Signal<Void, NoError> { subscriber in
|
if immediate {
|
||||||
let fetchedDisposable = fetched.start()
|
self.trackTo(item: ManagedAnimationItem(source: .resource(self.context.account.postbox.mediaBox, file.resource), frames: ManagedAnimationFrameRange(startFrame: 180, endFrame: 180), duration: 0.0))
|
||||||
let resourceDisposable = (chatMessageAnimationData(postbox: self.context.account.postbox, resource: file.resource, fitzModifier: nil, width: Int(fittedSize.width), height: Int(fittedSize.height), synchronousLoad: false)
|
} else {
|
||||||
|> filter { data in
|
self.trackTo(item: ManagedAnimationItem(source: .resource(self.context.account.postbox.mediaBox, file.resource), frames: ManagedAnimationFrameRange(startFrame: 0, endFrame: 180), duration: 3.0))
|
||||||
return data.complete
|
}
|
||||||
}).start(next: { next in
|
} else {
|
||||||
subscriber.putNext(Void())
|
self.setState(.rolling)
|
||||||
})
|
|
||||||
|
let dimensions = file.dimensions ?? PixelDimensions(width: 512, height: 512)
|
||||||
|
let fittedSize = dimensions.cgSize.aspectFilled(CGSize(width: 384.0, height: 384.0))
|
||||||
|
|
||||||
return ActionDisposable {
|
let fetched = freeMediaFileInteractiveFetched(account: self.context.account, fileReference: .standalone(media: file))
|
||||||
fetchedDisposable.dispose()
|
let sticker = Signal<Void, NoError> { subscriber in
|
||||||
resourceDisposable.dispose()
|
let fetchedDisposable = fetched.start()
|
||||||
|
let resourceDisposable = (chatMessageAnimationData(postbox: self.context.account.postbox, resource: file.resource, fitzModifier: nil, width: Int(fittedSize.width), height: Int(fittedSize.height), synchronousLoad: false)
|
||||||
|
|> filter { data in
|
||||||
|
return data.complete
|
||||||
|
}).start(next: { next in
|
||||||
|
subscriber.putNext(Void())
|
||||||
|
})
|
||||||
|
|
||||||
|
return ActionDisposable {
|
||||||
|
fetchedDisposable.dispose()
|
||||||
|
resourceDisposable.dispose()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.disposable.set((sticker |> deliverOnMainQueue).start(next: { [weak self] data in
|
||||||
|
if let strongSelf = self {
|
||||||
|
if immediate {
|
||||||
|
strongSelf.trackTo(item: ManagedAnimationItem(source: .resource(strongSelf.context.account.postbox.mediaBox, file.resource), frames: ManagedAnimationFrameRange(startFrame: 180, endFrame: 180), duration: 0.0))
|
||||||
|
} else {
|
||||||
|
strongSelf.trackTo(item: ManagedAnimationItem(source: .resource(strongSelf.context.account.postbox.mediaBox, file.resource), frames: ManagedAnimationFrameRange(startFrame: 0, endFrame: 180), duration: 3.0))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
self.disposable.set(sticker.start(next: { [weak self] data in
|
|
||||||
if let strongSelf = self {
|
|
||||||
strongSelf.trackTo(item: ManagedAnimationItem(source: .resource(strongSelf.context.account.postbox.mediaBox, file.resource), frames: ManagedAnimationFrameRange(startFrame: 0, endFrame: 180), duration: 3.0))
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
case .rolling:
|
case .rolling:
|
||||||
self.trackTo(item: ManagedAnimationItem(source: .local("Dice_Rolling"), frames: ManagedAnimationFrameRange(startFrame: 0, endFrame: 60), duration: 1.0, loop: true))
|
self.trackTo(item: ManagedAnimationItem(source: .local("Dice_Rolling"), frames: ManagedAnimationFrameRange(startFrame: 0, endFrame: 60), duration: 1.0, loop: true))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user