Skip to content

Commit

Permalink
improve shop sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipthelen committed Jun 6, 2024
1 parent 579930a commit 74c504c
Showing 14 changed files with 164 additions and 63 deletions.
2 changes: 1 addition & 1 deletion HabitRPG/Extensions/UIColor-Habitica.swift
Original file line number Diff line number Diff line change
@@ -89,7 +89,7 @@ extension UIColor {
case "warrior":
return .maroon50
case "healer":
return .yellow10
return .yellow50
case "mage", "wizard":
return .blue10
case "rogue":
2 changes: 1 addition & 1 deletion HabitRPG/Habitica-Info.plist
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>979</string>
<string>982</string>
<key>CustomDomain</key>
<string>${CUSTOM_DOMAIN}</string>
<key>DisableSSL</key>
3 changes: 3 additions & 0 deletions HabitRPG/LoadingViewController.swift
Original file line number Diff line number Diff line change
@@ -63,6 +63,9 @@ class LoadingViewController: UIHostingController<LoadingPage> {
.flatMap(.latest, {[weak self] (_) in
return self?.userRepository?.retrieveInboxConversations() ?? Signal.empty
})
.flatMap(.latest, {[weak self] (_) in
return self?.userRepository?.retrieveInAppRewards() ?? Signal.empty
})
.observeCompleted { [weak self] in
self?.userRepository = nil
if !hasUserData {
60 changes: 56 additions & 4 deletions HabitRPG/Storyboards/Base.lproj/Shop.storyboard
Original file line number Diff line number Diff line change
@@ -33,8 +33,8 @@
<view tag="3" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="d0L-2l-N3b">
<rect key="frame" x="12" y="4" width="351" height="82"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="1000" verticalCompressionResistancePriority="1000" axis="vertical" spacing="4" translatesAutoresizingMaskIntoConstraints="NO" id="NsK-Pe-aoA">
<rect key="frame" x="20" y="22" width="311" height="38"/>
<stackView opaque="NO" tag="7" contentMode="scaleToFill" verticalHuggingPriority="1000" verticalCompressionResistancePriority="1000" axis="vertical" spacing="4" translatesAutoresizingMaskIntoConstraints="NO" id="NsK-Pe-aoA">
<rect key="frame" x="20" y="10" width="311" height="62"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" tag="1" contentMode="left" horizontalHuggingPriority="251" text="Title" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="YSZ-kK-Prp">
<rect key="frame" x="0.0" y="0.0" width="311" height="17"/>
@@ -48,20 +48,71 @@
<color key="textColor" red="0.64723795650000004" green="0.63275462390000003" blue="0.67308568950000003" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<imageView hidden="YES" clipsSubviews="YES" userInteractionEnabled="NO" tag="4" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="7Ka-An-IDO" customClass="NetworkImageView" customModule="Habitica" customModuleProvider="target">
<rect key="frame" x="0.0" y="40" width="311" height="68"/>
<constraints>
<constraint firstAttribute="height" constant="68" id="68j-is-jQV"/>
</constraints>
</imageView>
<view tag="9" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="bh8-YU-6zH">
<rect key="frame" x="0.0" y="42" width="311" height="20"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="height" constant="20" id="XRD-oK-tXm"/>
</constraints>
</view>
</subviews>
<constraints>
<constraint firstAttribute="height" priority="1" constant="30" id="dXQ-lA-sUZ"/>
</constraints>
</stackView>
<view tag="5" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ybD-Am-Iwh">
<rect key="frame" x="0.0" y="50" width="351" height="32"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="1000" horizontalCompressionResistancePriority="1000" distribution="equalSpacing" spacing="1" translatesAutoresizingMaskIntoConstraints="NO" id="Q9X-3O-OdX">
<rect key="frame" x="150.5" y="0.0" width="50" height="32"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" tag="8" contentMode="center" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="Gold" translatesAutoresizingMaskIntoConstraints="NO" id="BWK-hp-qMV">
<rect key="frame" x="0.0" y="0.0" width="18" height="32"/>
<constraints>
<constraint firstAttribute="width" constant="18" id="xmg-Ic-KmL"/>
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" tag="6" contentMode="left" horizontalHuggingPriority="1000" verticalHuggingPriority="251" horizontalCompressionResistancePriority="1000" text="100" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="VZ0-x5-vUW">
<rect key="frame" x="25.5" y="0.0" width="24.5" height="32"/>
<constraints>
<constraint firstAttribute="width" priority="500" constant="24" id="Hdv-Jh-Am2"/>
</constraints>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="14"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstAttribute="width" priority="500" constant="50" id="Ghq-sO-YJH"/>
<constraint firstAttribute="height" constant="32" id="bnW-Zx-9gy"/>
</constraints>
</stackView>
</subviews>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstAttribute="height" constant="32" id="JnL-fw-G8t"/>
<constraint firstItem="Q9X-3O-OdX" firstAttribute="centerX" secondItem="ybD-Am-Iwh" secondAttribute="centerX" id="d5x-Nz-UY3"/>
<constraint firstAttribute="bottom" secondItem="Q9X-3O-OdX" secondAttribute="bottom" id="glj-tM-7K1"/>
</constraints>
</view>
</subviews>
<color key="backgroundColor" red="0.97592383620000001" green="0.97666221860000002" blue="0.97603815790000004" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" priority="500" constant="82" id="2YM-3h-TQw"/>
<constraint firstItem="NsK-Pe-aoA" firstAttribute="top" relation="greaterThanOrEqual" secondItem="d0L-2l-N3b" secondAttribute="top" constant="8" id="Fkz-Qf-JTP"/>
<constraint firstItem="NsK-Pe-aoA" firstAttribute="leading" secondItem="d0L-2l-N3b" secondAttribute="leading" constant="20" id="K8C-2o-qO8"/>
<constraint firstAttribute="trailing" secondItem="NsK-Pe-aoA" secondAttribute="trailing" constant="20" id="OCf-P4-DD3"/>
<constraint firstItem="NsK-Pe-aoA" firstAttribute="centerY" secondItem="d0L-2l-N3b" secondAttribute="centerY" id="czr-WG-oIg"/>
<constraint firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="NsK-Pe-aoA" secondAttribute="bottom" constant="8" id="sy5-Ze-qP0"/>
<constraint firstItem="ybD-Am-Iwh" firstAttribute="leading" secondItem="d0L-2l-N3b" secondAttribute="leading" id="RTL-in-ivU"/>
<constraint firstAttribute="bottom" secondItem="ybD-Am-Iwh" secondAttribute="bottom" id="SUl-3y-aOs"/>
<constraint firstItem="NsK-Pe-aoA" firstAttribute="centerY" secondItem="d0L-2l-N3b" secondAttribute="centerY" priority="999" id="czr-WG-oIg"/>
<constraint firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="NsK-Pe-aoA" secondAttribute="bottom" constant="8" identifier="bottomOffset" id="sy5-Ze-qP0"/>
<constraint firstAttribute="trailing" secondItem="ybD-Am-Iwh" secondAttribute="trailing" id="y7G-76-UFR"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="cornerRadius">
@@ -200,6 +251,7 @@
</scenes>
<color key="tintColor" red="0.6058621407" green="0.38462612029999999" blue="0.99835687880000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<resources>
<image name="Gold" width="18" height="18"/>
<image name="shop_separator_sparkle" width="9" height="9"/>
<image name="triangle" width="10" height="7"/>
<systemColor name="systemBackgroundColor">
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ class SeasonalShopCollectionViewDataSource: ShopCollectionViewDataSource {
override func loadCategories(_ categories: [ShopCategoryProtocol]) {
sections.removeAll()
for category in categories.sorted(by: { category1, category2 in
return (category1.items.first?.currency == "gold" ? 1 : 0) > (category2.items.first?.currency == "gold" ? 1 : 0)
return (category1.items.first?.currency == "gold" ? 1 : 0, category1.identifier == "quests" ? 10000 : findReleaseYear(key: category1.items.first?.key ?? "")) > (category2.items.first?.currency == "gold" ? 1 : 0, category1.identifier == "quests" ? 10000 : findReleaseYear(key: category2.items.first?.key ?? ""))
}) {
let newSection = ItemSection<InAppRewardProtocol>(title: category.text)
newSection.items = category.items
@@ -23,4 +23,13 @@ class SeasonalShopCollectionViewDataSource: ShopCollectionViewDataSource {
}
collectionView?.reloadData()
}

private func findReleaseYear(key: String) -> Int {
let result = key.filter({ $0.isNumber })
if result.isEmpty {
return 2014
} else {
return Int(result) ?? 0
}
}
}
17 changes: 16 additions & 1 deletion HabitRPG/TableViewDataSources/ShopCollectionViewDataSource.swift
Original file line number Diff line number Diff line change
@@ -267,7 +267,7 @@ class ShopCollectionViewDataSource: BaseReactiveCollectionViewDataSource<InAppRe
override func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if indexPath.section == 0 && needsGearSection {
if !hasGearSection() {
return CGSize(width: collectionView.bounds.width, height: 100)
return CGSize(width: collectionView.bounds.width, height: 200)
}
}
let section = visibleSections[indexPath.section]
@@ -309,11 +309,23 @@ class ShopCollectionViewDataSource: BaseReactiveCollectionViewDataSource<InAppRe
(cell.viewWithTag(1) as? UILabel)?.textColor = ThemeService.shared.theme.primaryTextColor
if armoireCount == 0 {
(cell.viewWithTag(2) as? UILabel)?.text = L10n.Shops.purchasedAllGearArmoireEmpty
cell.viewWithTag(4)?.isHidden = true
cell.viewWithTag(5)?.isHidden = true
cell.viewWithTag(9)?.isHidden = true
} else {
(cell.viewWithTag(2) as? UILabel)?.text = L10n.Shops.purchasedAllGear(armoireCount)
cell.viewWithTag(4)?.isHidden = false
if let imageView = (cell.viewWithTag(4)) as? NetworkImageView {
ImageManager.setImage(on: imageView, name: "shop_armoire")
}
cell.viewWithTag(5)?.isHidden = false
(cell.viewWithTag(8) as? UIImageView)?.image = HabiticaIcons.imageOfGold
cell.viewWithTag(9)?.isHidden = false
}
(cell.viewWithTag(2) as? UILabel)?.textColor = ThemeService.shared.theme.secondaryTextColor
cell.viewWithTag(3)?.backgroundColor = ThemeService.shared.theme.windowBackgroundColor
cell.viewWithTag(5)?.backgroundColor = ThemeService.shared.theme.offsetBackgroundColor.withAlphaComponent(0.3)
(cell.viewWithTag(6) as? UILabel)?.textColor = ThemeService.shared.theme.isDark ? .yellow500 : .yellow1
return cell
} else if let item = item(at: indexPath) {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ItemCell", for: indexPath)
@@ -336,6 +348,9 @@ class ShopCollectionViewDataSource: BaseReactiveCollectionViewDataSource<InAppRe
(cell.viewWithTag(2) as? UILabel)?.textColor = ThemeService.shared.theme.secondaryTextColor
(cell.viewWithTag(2) as? UILabel)?.attributedText = attributedStringInEmptySection(section: section)
cell.viewWithTag(3)?.backgroundColor = ThemeService.shared.theme.windowBackgroundColor
cell.viewWithTag(4)?.isHidden = true
cell.viewWithTag(5)?.isHidden = true
cell.viewWithTag(9)?.isHidden = true
return cell
}
}
8 changes: 5 additions & 3 deletions HabitRPG/TableviewCells/InAppRewardCell.swift
Original file line number Diff line number Diff line change
@@ -114,7 +114,9 @@ class InAppRewardCell: UICollectionViewCell {
}

if let currency = currency {
setCanAfford(price, currency: currency, user: user)
setCanAfford(price, currency: currency, user: user, isLocked: reward.locked)
} else {
currencyView.state = .normal
}
isPinned = false

@@ -173,10 +175,10 @@ class InAppRewardCell: UICollectionViewCell {
})
}

func setCanAfford(_ price: Float, currency: Currency, user: UserProtocol?) {
func setCanAfford(_ price: Float, currency: Currency, user: UserProtocol?, isLocked: Bool) {
var canAfford = false

if let user = user, currency == .gold {
if let user = user, currency == .gold {
canAfford = price <= user.stats?.gold ?? 0
} else {
canAfford = true
Loading

0 comments on commit 74c504c

Please sign in to comment.