Skip to content

Commit

Permalink
add empty state
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipthelen committed May 21, 2024
1 parent 2311bbf commit 3eb85fb
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 8 deletions.
10 changes: 10 additions & 0 deletions HabitRPG/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2517,8 +2517,18 @@ public enum L10n {
public static var customizationNotes: String { return L10n.tr("Mainstrings", "shops.customization_notes") }
/// You can only purchase gear for your current class
public static var otherClassDisclaimer: String { return L10n.tr("Mainstrings", "shops.other_class_disclaimer") }
/// You own all of these items
public static var ownAllItems: String { return L10n.tr("Mainstrings", "shops.own_all_items") }
/// You already have all your class equipment! More will be released during the Grand Galas, near the solstices and equinoxes.
public static var purchasedAllGear: String { return L10n.tr("Mainstrings", "shops.purchased_all_gear") }
/// You can try them on by customizing your avatar.
public static var tryOnCustomizeAvatar: String { return L10n.tr("Mainstrings", "shops.try_on_customize_avatar") }
/// You can try them on by customizing your avatar. Be sure to check back later for next month’s options!
public static var tryOnCustomizeAvatarReturnNextMonth: String { return L10n.tr("Mainstrings", "shops.try_on_customize_avatar_return_next_month") }
/// You can try them on by customizing your avatar. Be sure to check back later for next season’s options!
public static var tryOnCustomizeAvatarReturnNextSeason: String { return L10n.tr("Mainstrings", "shops.try_on_customize_avatar_return_next_season") }
/// You can try them on by Equipment. Be sure to check back later for next month’s options!
public static var tryOnEquipment: String { return L10n.tr("Mainstrings", "shops.try_on_equipment") }
}

public enum Skills {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ class CustomizationRepository: BaseRepository<CustomizationLocalRepository> {
self?.userLocalRepository.updateUser(id: userID, balanceDiff: -(value / 4.0))
self?.userLocalRepository.updateUser(id: userID, updateUser: user)
}
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()+1) {
ToastManager.show(text: L10n.purchased(text), color: .green)
if value > 0 {
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()+1) {
ToastManager.show(text: L10n.purchased(text), color: .green)
}
}
})
}
Expand Down
58 changes: 57 additions & 1 deletion HabitRPG/Storyboards/Base.lproj/Shop.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22684"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22685"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -62,6 +62,62 @@
</constraints>
<size key="customSize" width="375" height="90"/>
</collectionViewCell>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="EmptyItemCell" id="Vnw-5e-x3a" userLabel="EmptyItemCell">
<rect key="frame" x="0.0" y="165" width="375" height="90"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO">
<rect key="frame" x="0.0" y="0.0" width="375" height="90"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<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"/>
<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"/>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="14"/>
<color key="textColor" red="0.64723795650000004" green="0.63275462390000003" blue="0.67308568950000003" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" tag="2" contentMode="left" horizontalHuggingPriority="251" text="Subtitle" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="qFC-b8-LSl">
<rect key="frame" x="0.0" y="21" width="311" height="17"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" red="0.64723795650000004" green="0.63275462390000003" blue="0.67308568950000003" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstAttribute="height" priority="1" constant="30" id="dXQ-lA-sUZ"/>
</constraints>
</stackView>
</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"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="cornerRadius">
<real key="value" value="4"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</view>
</subviews>
</view>
<constraints>
<constraint firstAttribute="trailing" secondItem="d0L-2l-N3b" secondAttribute="trailing" constant="12" id="NND-ZA-pb7"/>
<constraint firstItem="d0L-2l-N3b" firstAttribute="leading" secondItem="Vnw-5e-x3a" secondAttribute="leading" constant="12" id="f1P-WU-jGe"/>
<constraint firstAttribute="bottom" secondItem="d0L-2l-N3b" secondAttribute="bottom" constant="4" id="ttS-zR-2bI"/>
<constraint firstItem="d0L-2l-N3b" firstAttribute="top" secondItem="Vnw-5e-x3a" secondAttribute="top" constant="4" id="zsD-OA-wYY"/>
</constraints>
<size key="customSize" width="375" height="90"/>
</collectionViewCell>
</cells>
<collectionReusableView key="sectionHeaderView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" restorationIdentifier="sectionHeader" reuseIdentifier="sectionHeader" id="70u-KL-mp3" customClass="HRPGShopSectionHeaderCollectionReusableView" customModule="Habitica" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="375" height="75"/>
Expand Down
5 changes: 5 additions & 0 deletions HabitRPG/Strings/Base.lproj/Mainstrings.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,11 @@
"shops.other_class_disclaimer" = "You can only purchase gear for your current class";
"shops.purchased_all_gear" = "You already have all your class equipment! More will be released during the Grand Galas, near the solstices and equinoxes.";
"shops.customization_notes" = "Want to change up your looks? You came to the right place! We get new options all the time.";
"shops.own_all_items" = "You own all of these items";
"shops.try_on_customize_avatar_return_next_month" = "You can try them on by customizing your avatar. Be sure to check back later for next month’s options!";
"shops.try_on_customize_avatar_return_next_season" = "You can try them on by customizing your avatar. Be sure to check back later for next season’s options!";
"shops.try_on_customize_avatar" = "You can try them on by customizing your avatar.";
"shops.try_on_equipment" = "You can try them on by Equipment. Be sure to check back later for next month’s options!";
"purchased" = "You purchased %@";
"buy_reward" = "You bought '%@' for %@ gold";
"notifications.unallocated_stat_points" = "You have **%d unallocated Stat Points**";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class AvatarDetailViewDataSource: BaseReactiveCollectionViewDataSource<Customiza
private var ownedCustomizations: [OwnedCustomizationProtocol] = []
private var customizationSets: [String: CustomizationSetProtocol] = [:]

private var equippedKey: String?
var equippedKey: String?

private var preferences: PreferencesProtocol?

Expand Down
28 changes: 26 additions & 2 deletions HabitRPG/TableViewDataSources/ShopCollectionViewDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class ShopCollectionViewDataSource: BaseReactiveCollectionViewDataSource<InAppRe
newSection.items = category.items
newSection.key = category.identifier
newSection.endDate = category.endDate
newSection.showIfEmpty = true
sections.append(newSection)
}
collectionView?.reloadData()
Expand Down Expand Up @@ -192,7 +193,11 @@ class ShopCollectionViewDataSource: BaseReactiveCollectionViewDataSource<InAppRe
if section == 0 && needsGearSection && !hasGearSection() {
return 1
} else {
return super.collectionView(collectionView, numberOfItemsInSection: section)
let sectionCount = super.collectionView(collectionView, numberOfItemsInSection: section)
if sectionCount == 0 {
return 1
}
return sectionCount
}
}

Expand Down Expand Up @@ -255,6 +260,9 @@ class ShopCollectionViewDataSource: BaseReactiveCollectionViewDataSource<InAppRe
return CGSize(width: collectionView.bounds.width, height: 80)
}
}
if visibleSections[indexPath.section].items.isEmpty {
return CGSize(width: collectionView.bounds.width, height: 84)
}
return CGSize(width: 90, height: 120)
}

Expand All @@ -277,8 +285,24 @@ class ShopCollectionViewDataSource: BaseReactiveCollectionViewDataSource<InAppRe
}
}
return cell
} else {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "EmptyItemCell", for: indexPath)
(cell.viewWithTag(1) as? UILabel)?.text = L10n.Shops.ownAllItems
(cell.viewWithTag(1) as? UILabel)?.textColor = ThemeService.shared.theme.primaryTextColor
let section = visibleSections[indexPath.section]
if section.key == "backgrounds" {
(cell.viewWithTag(2) as? UILabel)?.text = L10n.Shops.tryOnCustomizeAvatarReturnNextMonth
} else if section.key == "color" || section.key == "skin" {
(cell.viewWithTag(2) as? UILabel)?.text = L10n.Shops.tryOnCustomizeAvatarReturnNextSeason
} else if section.key == "mystery_sets" {
(cell.viewWithTag(2) as? UILabel)?.text = L10n.Shops.tryOnEquipment
} else {
(cell.viewWithTag(2) as? UILabel)?.text = L10n.Shops.tryOnCustomizeAvatar
}
(cell.viewWithTag(2) as? UILabel)?.textColor = ThemeService.shared.theme.secondaryTextColor
cell.viewWithTag(3)?.backgroundColor = ThemeService.shared.theme.windowBackgroundColor
return cell
}
return collectionView.dequeueReusableCell(withReuseIdentifier: "ItemCell", for: indexPath)
}

override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
Expand Down
13 changes: 12 additions & 1 deletion HabitRPG/UI/Inventory/AvatarDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,18 @@ class AvatarDetailViewController: BaseCollectionViewController, UICollectionView
let cell = collectionView.cellForItem(at: indexPath)
if let datasource = customizationDataSource, let customization = datasource.item(at: indexPath) {
if !customization.isPurchasable || datasource.owns(customization: customization) == true {
userRepository.updateUser(key: customization.userPath, value: customization.key ?? "").observeCompleted {}
var key = customization.key ?? ""
if customization.key == datasource.equippedKey {
if customization.type == "background" {
key = datasource.equippedKey ?? ""
customizationRepository.unlock(path: "background.\(key)", value: 0, text: "").observeCompleted {}
} else if customization.type == "hair" && customizationGroup != "color" {
key = "0"
} else {
return
}
}
userRepository.updateUser(key: customization.userPath, value: key).observeCompleted {}
} else {
if customization.set?.key?.contains("timeTravel") == true {
showTimeTravelDialog()
Expand Down
3 changes: 2 additions & 1 deletion HabitRPG/Views/AvatarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,15 @@ class AvatarView: UIView {
private func setLayout(_ imageView: UIImageView, type: String) {
var offset: CGFloat = 0
if !(viewDictionary["mount-head"] ?? false) && size == .regular {
offset = 28
offset = 24
if viewDictionary["pet"] ?? false {
offset -= 3
}
}
if nameDictionary["mount-head"]??.contains("Kangaroo") == true && size == .regular {
offset = 16
}
offset *= (self.bounds.size.height / 147)
let name = nameDictionary[type] ?? ""
if let name = name, specialConstraintsDictionary[name] != nil {
specialConstraintsDictionary[name]?(self, imageView, size, offset)
Expand Down

0 comments on commit 3eb85fb

Please sign in to comment.