Various improvements

This commit is contained in:
Ilya Laktyushin 2024-05-27 15:51:33 +04:00
parent c445821e6e
commit f0fa9461cd
10 changed files with 104 additions and 29 deletions

View File

@ -12297,7 +12297,7 @@ Sorry for the inconvenience.";
"Stars.Transfer.Balance" = "Balance";
"Stars.Transfer.Unavailable" = "Unavailable";
"Stars.Transfer.Unavailable" = "Sorry, no star purchases are available from your country.";
"Settings.Stars" = "Your Stars";

View File

@ -197,6 +197,7 @@ class CreateGiveawayHeaderItemNode: ItemListControllerHeaderItemNode {
self.backgroundNode.update(size: CGSize(width: layout.size.width, height: navigationBarHeight), transition: transition)
let component = AnyComponent(PremiumStarComponent(
theme: self.item.theme,
isIntro: true,
isVisible: true,
hasIdleAnimations: true,

View File

@ -267,6 +267,7 @@ private final class PremiumGiftCodeSheetContent: CombinedComponent {
let star = star.update(
component: PremiumStarComponent(
theme: theme,
isIntro: false,
isVisible: true,
hasIdleAnimations: true,

View File

@ -3210,6 +3210,7 @@ private final class PremiumIntroScreenComponent: CombinedComponent {
} else {
header = star.update(
component: PremiumStarComponent(
theme: environment.theme,
isIntro: isIntro,
isVisible: starIsVisible,
hasIdleAnimations: state.hasIdleAnimations,

View File

@ -183,7 +183,7 @@ private final class StarsContextImpl {
return
}
var transactions = state.transactions
transactions.insert(.init(id: "\(arc4random())", count: balance, date: Int32(Date().timeIntervalSince1970), peer: .appStore, title: nil, description: nil, photo: nil), at: 0)
transactions.insert(.init(id: "tmp_\(arc4random())", count: balance, date: Int32(Date().timeIntervalSince1970), peer: .appStore, title: nil, description: nil, photo: nil), at: 0)
self.updateState(StarsContext.State(flags: [.isPendingBalance], balance: state.balance + balance, transactions: transactions, canLoadMore: state.canLoadMore, isLoading: state.isLoading))
}
@ -433,10 +433,13 @@ private final class StarsTransactionsContextImpl {
if filteredTransactions != initialTransactions {
var existingIds = Set<String>()
for transaction in self._state.transactions {
existingIds.insert(transaction.id)
if !transaction.id.hasPrefix("tmp_") {
existingIds.insert(transaction.id)
}
}
var updatedState = self._state
updatedState.transactions.removeAll(where: { $0.id.hasPrefix("tmp_") })
for transaction in filteredTransactions.reversed() {
if !existingIds.contains(transaction.id) {
updatedState.transactions.insert(transaction, at: 0)

View File

@ -7,6 +7,7 @@ import SceneKit
import GZip
import AppBundle
import LegacyComponents
import TelegramPresentationData
private let sceneVersion: Int = 7
@ -69,25 +70,31 @@ public func loadCompressedScene(name: String, version: Int) -> SCNScene? {
}
public final class PremiumStarComponent: Component {
let theme: PresentationTheme
let isIntro: Bool
let isVisible: Bool
let hasIdleAnimations: Bool
let colors: [UIColor]?
let particleColor: UIColor?
public init(
theme: PresentationTheme,
isIntro: Bool,
isVisible: Bool,
hasIdleAnimations: Bool,
colors: [UIColor]? = nil
colors: [UIColor]? = nil,
particleColor: UIColor? = nil
) {
self.theme = theme
self.isIntro = isIntro
self.isVisible = isVisible
self.hasIdleAnimations = hasIdleAnimations
self.colors = colors
self.particleColor = particleColor
}
public static func ==(lhs: PremiumStarComponent, rhs: PremiumStarComponent) -> Bool {
return lhs.isIntro == rhs.isIntro && lhs.isVisible == rhs.isVisible && lhs.hasIdleAnimations == rhs.hasIdleAnimations && lhs.colors == rhs.colors
return lhs.theme === rhs.theme && lhs.isIntro == rhs.isIntro && lhs.isVisible == rhs.isVisible && lhs.hasIdleAnimations == rhs.hasIdleAnimations && lhs.colors == rhs.colors && lhs.particleColor == rhs.particleColor
}
public final class View: UIView, SCNSceneRendererDelegate, ComponentTaggedView {
@ -293,9 +300,10 @@ public final class PremiumStarComponent: Component {
self.sceneView.scene = scene
self.sceneView.delegate = self
if let node = scene.rootNode.childNode(withName: "star", recursively: false), let colors = self.component?.colors, let color = colors.first {
if let component = self.component, let node = scene.rootNode.childNode(withName: "star", recursively: false), let colors =
component.colors {
node.geometry?.materials.first?.diffuse.contents = generateDiffuseTexture(colors: colors)
let names: [String] = [
"particles_left",
"particles_right",
@ -304,10 +312,63 @@ public final class PremiumStarComponent: Component {
"particles_center"
]
let starNames: [String] = [
"coins_left",
"coins_right"
]
if let particleColor = component.particleColor {
for name in starNames {
if let node = scene.rootNode.childNode(withName: name, recursively: false), let particleSystem = node.particleSystems?.first {
particleSystem.particleIntensity = 1.0
particleSystem.particleIntensityVariation = 0.05
particleSystem.particleColor = particleColor
particleSystem.particleColorVariation = SCNVector4Make(0.07, 0.0, 0.1, 0.0)
node.isHidden = false
if let propertyControllers = particleSystem.propertyControllers, let sizeController = propertyControllers[.size], let colorController = propertyControllers[.color] {
let animation = CAKeyframeAnimation()
if let existing = colorController.animation as? CAKeyframeAnimation {
animation.keyTimes = existing.keyTimes
animation.values = existing.values?.compactMap { ($0 as? UIColor)?.alpha } ?? []
} else {
animation.values = [ 0.0, 1.0, 1.0, 0.0 ]
}
let opacityController = SCNParticlePropertyController(animation: animation)
particleSystem.propertyControllers = [
.size: sizeController,
.opacity: opacityController
]
}
}
}
}
for name in names {
if let node = scene.rootNode.childNode(withName: name, recursively: false), let particleSystem = node.particleSystems?.first, color.rgb != 0x6a94ff {
particleSystem.particleColor = color
particleSystem.particleColorVariation = SCNVector4Make(0, 0, 0, 0)
if let node = scene.rootNode.childNode(withName: name, recursively: false), let particleSystem = node.particleSystems?.first {
if let particleColor = component.particleColor {
particleSystem.particleIntensity = min(1.0, 2.0 * particleSystem.particleIntensity)
particleSystem.particleIntensityVariation = 0.05
particleSystem.particleColor = particleColor
particleSystem.particleColorVariation = SCNVector4Make(0.1, 0.0, 0.12, 0.0)
} else {
particleSystem.particleColorVariation = SCNVector4Make(0.12, 0.03, 0.035, 0.0)
}
if let propertyControllers = particleSystem.propertyControllers, let sizeController = propertyControllers[.size], let colorController = propertyControllers[.color] {
let animation = CAKeyframeAnimation()
if let existing = colorController.animation as? CAKeyframeAnimation {
animation.keyTimes = existing.keyTimes
animation.values = existing.values?.compactMap { ($0 as? UIColor)?.alpha } ?? []
} else {
animation.values = [ 0.0, 1.0, 1.0, 0.0 ]
}
let opacityController = SCNParticlePropertyController(animation: animation)
particleSystem.propertyControllers = [
.size: sizeController,
.opacity: opacityController
]
}
}
}
}
@ -600,6 +661,10 @@ public final class PremiumStarComponent: Component {
self.setup()
if let _ = component.particleColor {
self.sceneView.backgroundColor = component.theme.list.blocksBackgroundColor
}
self.sceneView.bounds = CGRect(origin: .zero, size: CGSize(width: availableSize.width * 2.0, height: availableSize.height * 2.0))
if self.sceneView.superview == self {
self.sceneView.center = CGPoint(x: availableSize.width / 2.0, y: availableSize.height / 2.0)

View File

@ -167,7 +167,7 @@ private final class StarsPurchaseScreenContentComponent: CombinedComponent {
static var body: Body {
let overscroll = Child(Rectangle.self)
let fade = Child(RoundedRectangle.self)
// let fade = Child(RoundedRectangle.self)
let text = Child(BalancedTextComponent.self)
let list = Child(VStack<Empty>.self)
let termsText = Child(BalancedTextComponent.self)
@ -203,21 +203,21 @@ private final class StarsPurchaseScreenContentComponent: CombinedComponent {
.position(CGPoint(x: overscroll.size.width / 2.0, y: -overscroll.size.height / 2.0))
)
let fade = fade.update(
component: RoundedRectangle(
colors: [
topBackgroundColor,
bottomBackgroundColor
],
cornerRadius: 0.0,
gradientDirection: .vertical
),
availableSize: CGSize(width: availableWidth, height: 300),
transition: context.transition
)
context.add(fade
.position(CGPoint(x: fade.size.width / 2.0, y: fade.size.height / 2.0))
)
// let fade = fade.update(
// component: RoundedRectangle(
// colors: [
// topBackgroundColor,
// bottomBackgroundColor
// ],
// cornerRadius: 0.0,
// gradientDirection: .vertical
// ),
// availableSize: CGSize(width: availableWidth, height: 300),
// transition: context.transition
// )
// context.add(fade
// .position(CGPoint(x: fade.size.width / 2.0, y: fade.size.height / 2.0))
// )
size.height += 183.0 + 10.0 + environment.navigationHeight - 56.0
@ -724,6 +724,7 @@ private final class StarsPurchaseScreenComponent: CombinedComponent {
let header = star.update(
component: PremiumStarComponent(
theme: environment.theme,
isIntro: true,
isVisible: starIsVisible,
hasIdleAnimations: state.hasIdleAnimations,
@ -732,7 +733,8 @@ private final class StarsPurchaseScreenComponent: CombinedComponent {
UIColor(rgb: 0xf09903),
UIColor(rgb: 0xf9b004),
UIColor(rgb: 0xfdd219)
]
],
particleColor: UIColor(rgb: 0xf9b004)
),
availableSize: CGSize(width: min(414.0, context.availableSize.width), height: 220.0),
transition: context.transition

View File

@ -428,7 +428,7 @@ private final class StarsTransactionSheetContent: CombinedComponent {
)
context.add(star
.position(CGPoint(x: context.availableSize.width / 2.0, y: star.size.height / 2.0 - 32.0))
.position(CGPoint(x: context.availableSize.width / 2.0, y: star.size.height / 2.0 - 19.0))
)
var originY: CGFloat = 0.0

View File

@ -383,6 +383,7 @@ final class StarsTransactionsScreenComponent: Component {
let starSize = self.starView.update(
transition: .immediate,
component: AnyComponent(PremiumStarComponent(
theme: environment.theme,
isIntro: true,
isVisible: true,
hasIdleAnimations: true,
@ -391,7 +392,8 @@ final class StarsTransactionsScreenComponent: Component {
UIColor(rgb: 0xf09903),
UIColor(rgb: 0xf9b004),
UIColor(rgb: 0xfdd219)
]
],
particleColor: UIColor(rgb: 0xf9b004)
)),
environment: {},
containerSize: CGSize(width: min(414.0, availableSize.width), height: 220.0)