Skip to content

Commit

Permalink
shop and customization improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipthelen committed May 9, 2024
1 parent 1b71a0c commit 63d511d
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 36 deletions.
2 changes: 2 additions & 0 deletions HabitRPG/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2045,6 +2045,8 @@ public enum L10n {
public static var helpFaq: String { return L10n.tr("Mainstrings", "menu.help_faq") }
/// Inventory
public static var inventory: String { return L10n.tr("Mainstrings", "menu.inventory") }
/// Quest Shop
public static var questShop: String { return L10n.tr("Mainstrings", "menu.quest_shop") }
/// Select Class
public static var selectClass: String { return L10n.tr("Mainstrings", "menu.select_class") }
/// Shops
Expand Down
18 changes: 9 additions & 9 deletions HabitRPG/Storyboards/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -830,13 +830,13 @@
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="10" minimumInteritemSpacing="10" id="qCK-eG-irz">
<size key="itemSize" width="80" height="108"/>
<size key="headerReferenceSize" width="50" height="30"/>
<size key="headerReferenceSize" width="50" height="38"/>
<size key="footerReferenceSize" width="50" height="50"/>
<inset key="sectionInset" minX="8" minY="0.0" maxX="8" maxY="0.0"/>
</collectionViewFlowLayout>
<cells>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="Cell" id="UiJ-MI-3uz" customClass="CustomizationDetailCell" customModule="Habitica" customModuleProvider="target">
<rect key="frame" x="8" y="30" width="80" height="108"/>
<rect key="frame" x="8" y="38" width="80" height="108"/>
<autoresizingMask key="autoresizingMask"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
<rect key="frame" x="0.0" y="0.0" width="80" height="108"/>
Expand Down Expand Up @@ -879,31 +879,31 @@
</collectionViewCell>
</cells>
<collectionReusableView key="sectionHeaderView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="SectionHeader" id="fLQ-5C-sqc" customClass="CustomizationHeaderView" customModule="Habitica" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="428" height="30"/>
<rect key="frame" x="0.0" y="0.0" width="428" height="38"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" tag="1" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="1000" verticalCompressionResistancePriority="1000" text="" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="pWt-Qo-uxJ">
<rect key="frame" x="8" y="8" width="412" height="14"/>
<rect key="frame" x="8" y="12" width="412" height="24"/>
<constraints>
<constraint firstAttribute="height" priority="500" constant="26" id="AXg-RX-7v0"/>
<constraint firstAttribute="height" priority="500" constant="30" id="AXg-RX-7v0"/>
</constraints>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="12"/>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="13"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstItem="pWt-Qo-uxJ" firstAttribute="bottom" secondItem="fLQ-5C-sqc" secondAttribute="bottomMargin" id="ODz-cy-khT"/>
<constraint firstItem="pWt-Qo-uxJ" firstAttribute="bottom" secondItem="fLQ-5C-sqc" secondAttribute="bottomMargin" constant="6" id="ODz-cy-khT"/>
<constraint firstAttribute="trailingMargin" secondItem="pWt-Qo-uxJ" secondAttribute="trailing" id="XKO-lk-13o"/>
<constraint firstItem="pWt-Qo-uxJ" firstAttribute="top" secondItem="fLQ-5C-sqc" secondAttribute="topMargin" id="vDG-OY-uAD"/>
<constraint firstItem="pWt-Qo-uxJ" firstAttribute="top" secondItem="fLQ-5C-sqc" secondAttribute="topMargin" constant="4" id="vDG-OY-uAD"/>
<constraint firstItem="pWt-Qo-uxJ" firstAttribute="leading" secondItem="fLQ-5C-sqc" secondAttribute="leadingMargin" id="vPq-QS-7x4"/>
</constraints>
<connections>
<outlet property="label" destination="pWt-Qo-uxJ" id="SLw-2L-Pb8"/>
</connections>
</collectionReusableView>
<collectionReusableView key="sectionFooterView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="SectionFooter" id="6SS-98-tI6" customClass="CustomizationFooterView" customModule="Habitica" customModuleProvider="target">
<rect key="frame" x="0.0" y="138" width="428" height="50"/>
<rect key="frame" x="0.0" y="146" width="428" height="50"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="qTK-jZ-X4O">
Expand Down
3 changes: 2 additions & 1 deletion HabitRPG/Strings/Base.lproj/Mainstrings.strings
Original file line number Diff line number Diff line change
Expand Up @@ -782,11 +782,12 @@
"keep_tasks" = "Keep Tasks";
"delete_tasks" = "Delete Tasks";
"locations.market" = "Market";
"locations.quest_shop" = "Quests";
"locations.quest_shop" = "Quest Shop";
"locations.seasonal_shop" = "Seasonal Shop";
"locations.time_travelers_shop" = "Time Travelers";
"locations.customizations" = "Customizations";
"locations.stable" = "Stable";
"menu.quest_shop" = "Quests";
"NPCs.alex" = "Alex the Merchant";
"NPCs.daniel" = "Daniel the inn keeper";
"NPCs.ian" = "Ian the Quest Guide";
Expand Down
1 change: 1 addition & 0 deletions HabitRPG/Strings/de.lproj/Mainstrings.strings
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@
"locations.quest_shop" = "Quests";
"locations.seasonal_shop" = "Jahreszeitenmarkt";
"locations.stable" = "Stall";
"menu.quest_shop" = "Quests";
"NPCs.alex" = "Alex der Händler";
"NPCs.daniel" = "Daniel der Wirt";
"NPCs.ian" = "Ian der Quest-Guide";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ class AvatarDetailViewDataSource: BaseReactiveCollectionViewDataSource<Customiza
}
}

if sections[0].items.count == 1 && (sections[0].items[0].key?.isEmpty == true || sections[0].items[0].key == "0") {
sections[0].items.removeFirst()
sections[0].showIfEmpty = true
}

if customizationType == "background" {
sections = sections.filter({ section -> Bool in
return section.items.isEmpty == false
Expand Down Expand Up @@ -225,7 +230,7 @@ class AvatarDetailViewDataSource: BaseReactiveCollectionViewDataSource<Customiza
if newCustomizationLayout && indexPath.section == collectionView.numberOfSections - 1 {
footerView.purchaseButton.isHidden = true
footerView.hostingView.isHidden = false
let hostView = UIHostingView(rootView: CTAFooterView(type: customizationType, hasItems: !ownedCustomizations.isEmpty))
let hostView = UIHostingView(rootView: CTAFooterView(type: customizationType, hasItems: !sections[0].items.isEmpty))
footerView.hostingView.addSubview(hostView)
hostView.frame = CGRect(x: 0, y: 0, width: collectionView.frame.width, height: 200)
} else {
Expand Down
59 changes: 39 additions & 20 deletions HabitRPG/TableViewDataSources/AvatarGearDetailViewDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@

import Foundation
import Habitica_Models
import SwiftUIX

class AvatarGearDetailViewDataSource: BaseReactiveCollectionViewDataSource<GearProtocol> {

private let inventoryRepository = InventoryRepository()
private let userRepository = UserRepository()

var gearType: String

var newCustomizationLayout: Bool = false

private var ownedGear: [OwnedGearProtocol] = []

private var equippedKey: String?

var preferences: PreferencesProtocol?

init(type: String) {
init(type: String, newCustomizationLayout: Bool) {
gearType = type
self.newCustomizationLayout = newCustomizationLayout
super.init()
sections.append(ItemSection<GearProtocol>())

var predicate: NSPredicate
if gearType == "eyewear" || gearType == "headAccessory" {
predicate = NSPredicate(format: "gearSet != nil && type == 'headAccessory'")
if gearType == "eyewear" {
predicate = NSPredicate(format: "gearSet == 'glasses' && type == 'eyewear'")
}
if gearType == "headAccessory" {
predicate = NSPredicate(format: "gearSet == 'animal' && type == 'headAccessory'")
} else {
predicate = NSPredicate(format: "gearSet == 'animal' && type == 'back'")
}
Expand Down Expand Up @@ -89,23 +89,30 @@ class AvatarGearDetailViewDataSource: BaseReactiveCollectionViewDataSource<GearP
return CGSize.zero
}

func getTitle() -> String {
switch gearType {
case "headAccessory":
return L10n.animalEars
case "back":
return L10n.Avatar.animalTails
default:
return ""
}
}

private func configureSections(_ gear: [GearProtocol]) {
sections.removeAll()
sections.append(ItemSection<GearProtocol>())
sections[0].title = getTitle()
for gear in gear {
if let set = gear.gearSet {
if let index = sections.firstIndex(where: { (section) -> Bool in
return section.key == set
}) {
sections[index].items.append(gear)
} else {
sections.append(ItemSection<GearProtocol>(key: set, title: sectionTitle(set)))
sections.last?.items.append(gear)
if newCustomizationLayout {
if !owns(gear: gear) {
continue
}
} else {
sections[0].items.append(gear)
}
sections[0].items.append(gear)
}
sections[0].showIfEmpty = true
collectionView?.reloadData()
}

Expand All @@ -126,16 +133,28 @@ class AvatarGearDetailViewDataSource: BaseReactiveCollectionViewDataSource<GearP
}
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize {
return CGSize(width: collectionView.frame.width, height: 80)
}

override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
let view = super.collectionView(collectionView, viewForSupplementaryElementOfKind: kind, at: indexPath)
let section = visibleSections[indexPath.section]

if let headerView = view as? CustomizationHeaderView {
headerView.label.text = section.title
headerView.label.textColor = ThemeService.shared.theme.primaryTextColor
headerView.label.text = section.title?.localizedUppercase
headerView.label.textColor = ThemeService.shared.theme.quadTextColor
}
if let footerView = view as? CustomizationFooterView {
footerView.isHidden = true
if newCustomizationLayout && indexPath.section == collectionView.numberOfSections - 1 {
footerView.purchaseButton.isHidden = true
footerView.hostingView.isHidden = false
let hostView = UIHostingView(rootView: CTAFooterView(type: gearType, hasItems: !sections[0].items.isEmpty))
footerView.hostingView.addSubview(hostView)
hostView.frame = CGRect(x: 0, y: 0, width: collectionView.frame.width, height: 200)
} else {
footerView.isHidden = true
}
}

return view
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class SeasonalShopCollectionViewDataSource: ShopCollectionViewDataSource {
}) {
let newSection = ItemSection<InAppRewardProtocol>(title: category.text)
newSection.items = category.items
newSection.endDate = category.endDate
sections.append(newSection)
}
collectionView?.reloadData()
Expand Down
2 changes: 1 addition & 1 deletion HabitRPG/UI/General/MainMenuViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class MenuItem {
MenuItem(key: .stats, title: L10n.Titles.stats, vcInstantiator: StoryboardScene.User.attributePointsViewController.instantiate),
MenuItem(key: .achievements, title: L10n.Titles.achievements, vcInstantiator: StoryboardScene.User.achievementsCollectionViewController.instantiate),
MenuItem(key: .market, title: L10n.Locations.market, segue: StoryboardSegue.Main.showMarketSegue.rawValue),
MenuItem(key: .questShop, title: L10n.Locations.questShop, segue: StoryboardSegue.Main.showQuestShopSegue.rawValue),
MenuItem(key: .questShop, title: L10n.Menu.questShop, segue: StoryboardSegue.Main.showQuestShopSegue.rawValue),
MenuItem(key: .seasonalShop, title: L10n.Locations.seasonalShop, segue: StoryboardSegue.Main.showSeasonalShopSegue.rawValue),
MenuItem(key: .customizationShop, title: L10n.Locations.customizations, segue: StoryboardSegue.Main.showCustomizationShopSegue.rawValue, isHidden: true),
MenuItem(key: .timeTravelersShop, title: L10n.Locations.timeTravelersShop, segue: StoryboardSegue.Main.showTimeTravelersSegue.rawValue),
Expand Down
2 changes: 1 addition & 1 deletion HabitRPG/UI/Inventory/AvatarDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AvatarDetailViewController: BaseCollectionViewController, UICollectionView

if let type = customizationType {
if type == "eyewear" || type == "headAccessory" || type == "back" || type == "animalTails" {
gearDataSource = AvatarGearDetailViewDataSource(type: type)
gearDataSource = AvatarGearDetailViewDataSource(type: type, newCustomizationLayout: newCustomizationLayout)
gearDataSource?.collectionView = collectionView
} else {
customizationDataSource = AvatarDetailViewDataSource(type: type, group: customizationGroup, newCustomizationLayout: newCustomizationLayout)
Expand Down
8 changes: 6 additions & 2 deletions HabitRPG/UI/Inventory/AvatarOverviewViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ class AvatarOverviewViewController: BaseUIViewController, UIScrollViewDelegate {
override func applyTheme(theme: Theme) {
super.applyTheme(theme: theme)
bodySizeLabel.textColor = theme.primaryTextColor
containerview.backgroundColor = theme.offsetBackgroundColor
if theme.isDark {
containerview.backgroundColor = .gray10
} else {
containerview.backgroundColor = theme.offsetBackgroundColor
}
}

override func populateText() {
Expand Down Expand Up @@ -97,7 +101,7 @@ class AvatarOverviewViewController: BaseUIViewController, UIScrollViewDelegate {
wheelchairView.setup(title: L10n.Avatar.wheelchair) {[weak self] in
self?.openDetailView(type: "chair")
}
animalEarsView.setup(title: L10n.Avatar.head) {[weak self] in
animalEarsView.setup(title: L10n.animalEars) {[weak self] in
self?.openDetailView(type: "headAccessory")
}
backgroundView.setup(title: L10n.Avatar.background) {[weak self] in
Expand Down
6 changes: 5 additions & 1 deletion HabitRPG/Views/AvatarOverviewItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import UIKit
class AvatarOverviewItemView: UIView {
var imageView: NetworkImageView = {
let imageView = NetworkImageView()
imageView.backgroundColor = ThemeService.shared.theme.windowBackgroundColor
if ThemeService.shared.theme.isDark {
imageView.backgroundColor = .gray50
} else {
imageView.backgroundColor = ThemeService.shared.theme.windowBackgroundColor
}
imageView.layer.cornerRadius = 4
imageView.contentMode = .center
return imageView
Expand Down

0 comments on commit 63d511d

Please sign in to comment.