Skip to content

Commit

Permalink
Improve flow for changing class from market
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipthelen committed Jul 23, 2024
1 parent 1a2440f commit db3ba90
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 18 deletions.
14 changes: 14 additions & 0 deletions HabitRPG/Extensions/String-Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,21 @@ extension String {
return L10n.Classes.warriors
}
}
}

extension HabiticaClass {
var translatedName: String {
switch self {
case .warrior:
return L10n.Classes.warrior
case .mage:
return L10n.Classes.mage
case .healer:
return L10n.Classes.healer
case .rogue:
return L10n.Classes.rogue
}
}
}

// swiftlint:enable all
18 changes: 16 additions & 2 deletions HabitRPG/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,20 @@ public enum L10n {
public static var checkinYesterdaysDalies: String { return L10n.tr("Mainstrings", "checkin_yesterdays_dalies") }
/// Choose Task
public static var chooseTask: String { return L10n.tr("Mainstrings", "choose_task") }
/// Are you sure you want to change your class to %@? This will cost 3 gems.
public static func classChangeConfirm(_ p1: String) -> String {
/// Change class to %s for 3 Gems?
public static func classChangeConfirm(_ p1: UnsafePointer<CChar>) -> String {
return L10n.tr("Mainstrings", "class_change_confirm", p1)
}
/// This will switch which gear is unlocked in the shops, change your available skills, and reset your stat points.
public static var classChangeConfirmDescription: String { return L10n.tr("Mainstrings", "class_change_confirm_description") }
/// You can now use %@ skills and purchase gear from shops. Gain levels to earn stat points you can use to power up your skills.
public static func classChangeSuccessDescription(_ p1: String) -> String {
return L10n.tr("Mainstrings", "class_change_success_description", p1)
}
/// You're a %@!
public static func classChangeSuccessTitle(_ p1: String) -> String {
return L10n.tr("Mainstrings", "class_change_success_title", p1)
}
/// This item is only available to %s.\nOpen Settings to change class.
public static func classEquipmentShopDialog(_ p1: UnsafePointer<CChar>) -> String {
return L10n.tr("Mainstrings", "class_equipment_shop_dialog", p1)
Expand Down Expand Up @@ -478,6 +488,8 @@ public enum L10n {
public static var gold: String { return L10n.tr("Mainstrings", "gold") }
/// Gold is the **main form of currency** within Habitica and allows you to buy certain gear, quests, items, or even custom rewards you make for yourself.\n\n**Earn Gold** through completing tasks or quests, or through some Class skills. Higher **Perception stats** raise the amount of Gold you earn.\n\nIf you subscribe to Habitica, you can even use Gold to purchase a number of Gems determined by the length of time you’ve been subscribed.
public static var goldDescription: String { return L10n.tr("Mainstrings", "gold_description") }
/// Got it!
public static var gotIt: String { return L10n.tr("Mainstrings", "got_it") }
/// Great
public static var great: String { return L10n.tr("Mainstrings", "great") }
/// Group By
Expand Down Expand Up @@ -780,6 +792,8 @@ public enum L10n {
public static var openMysteryItem: String { return L10n.tr("Mainstrings", "open_mystery_item") }
/// Open Profile
public static var openProfile: String { return L10n.tr("Mainstrings", "open_profile") }
/// Open Stats
public static var openStats: String { return L10n.tr("Mainstrings", "open_stats") }
/// Open Website
public static var openWebsite: String { return L10n.tr("Mainstrings", "open_website") }
/// Organize By
Expand Down
22 changes: 19 additions & 3 deletions HabitRPG/GuidelinesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,40 @@

import UIKit
import Down
import SwiftUIX

class GuidelinesViewController: UIViewController {
@IBOutlet weak var textView: UITextView!

let activityIndicator = UIHostingView(rootView: HabiticaProgressView())

override func viewDidLoad() {
super.viewDidLoad()

view.addSubview(activityIndicator)

navigationItem.title = L10n.Titles.guidelines

let urlString = "https://s3.amazonaws.com/habitica-assets/mobileApp/endpoint/community-guidelines.md"
guard let url = URL(string: urlString) else {
return
}
if let text = try? String(contentsOf: url) {
textView.attributedText = try? Down(markdownString: text).toHabiticaAttributedString()
DispatchQueue.global(qos: .background).async { [weak self] in
if let text = try? String(contentsOf: url) {
let attributed = try? Down(markdownString: text).toHabiticaAttributedString()
DispatchQueue.main.async {
self?.textView.attributedText = attributed
self?.textView.isHidden = false
self?.activityIndicator.isHidden = true
}
}
}
}

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
activityIndicator.pin.center().size(44)
}

@IBAction func doneButtonTapped(_ sender: Any) {
dismiss(animated: true, completion: nil)
}
Expand Down
6 changes: 3 additions & 3 deletions HabitRPG/HRPGShopSectionHeaderCollectionReusableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ class HRPGShopSectionHeaderCollectionReusableView: UICollectionReusableView {

@objc
private func changeClassTapped() {
let dialog = HabiticaAlertController(title: L10n.classChangeConfirm(newClassName ?? ""))
dialog.addAction(title: L10n.yes, isMainAction: true) { _ in
let dialog = HabiticaAlertController(title: L10n.classChangeConfirm(newClassName ?? ""), message: L10n.classChangeConfirmDescription)
dialog.addAction(title: L10n.Settings.changeClass, style: .destructive, isMainAction: true) { _ in
if let action = self.onClassChange {
action()
}
}
dialog.addAction(title: L10n.no)
dialog.addCloseAction()
dialog.show()
}

Expand Down
19 changes: 16 additions & 3 deletions HabitRPG/Repositories/Implementations/UserRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,23 @@ class UserRepository: BaseRepository<UserLocalRepository> {
return Signal.empty
}
lastClassSelection = Date()
return SelectClassCall(class: habiticaClass).responseSignal
.flatMap(.latest, {[weak self] _ in
return self?.retrieveUser(withTasks: false, forced: true) ?? .empty
return SelectClassCall(class: habiticaClass).httpResponseSignal
.on(value: { response in
if response.statusCode == 200 {
let alert = HabiticaAlertController(
title: L10n.classChangeSuccessTitle(habiticaClass?.translatedName ?? ""),
message: L10n.classChangeSuccessDescription(habiticaClass?.translatedName ?? ""))
alert.addAction(title: L10n.gotIt, isMainAction: true)
alert.addAction(title: L10n.openStats) { _ in
RouterHandler.shared.handle(urlString: "/user/stats")
}
alert.show()
}
})
.flatMap(.latest, { _ in
return self.retrieveUser(withTasks: false, forced: true)
})
.take(first: 1)
.on(value: handleUserUpdate())
}

Expand Down
6 changes: 3 additions & 3 deletions HabitRPG/Storyboards/Base.lproj/Social.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="22505" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22504"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22685"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand Down Expand Up @@ -2709,7 +2709,7 @@
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
<systemColor name="systemRedColor">
<color red="1" green="0.23137254900000001" blue="0.18823529410000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color red="1" green="0.23137254901960785" blue="0.18823529411764706" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
</resources>
</document>
7 changes: 6 additions & 1 deletion HabitRPG/Strings/Base.lproj/Mainstrings.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1386,4 +1386,9 @@

"change_class_to" = "Change class to %@";
"unlock_x_gear_and_skills" = "Unlock %@ gear and skills";
"class_change_confirm" = "Are you sure you want to change your class to %@? This will cost 3 gems.";
"class_change_confirm" = "Change class to %s for 3 Gems?";
"class_change_confirm_description" = "This will switch which gear is unlocked in the shops, change your available skills, and reset your stat points.";
"class_change_success_title" = "You're a %@!";
"class_change_success_description" = "You can now use %@ skills and purchase gear from shops. Gain levels to earn stat points you can use to power up your skills.";
"got_it" = "Got it!";
"open_stats" = "Open Stats";
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,11 @@ class ShopCollectionViewDataSource: BaseReactiveCollectionViewDataSource<InAppRe
} else {
headerView.newClassName = selectedClassName
headerView.onClassChange = {
let selectedClass = self.selectedGearCategory == "mage" ? "wizard" : self.selectedGearCategory
self.userRepository.selectClass(HabiticaClass(rawValue: selectedClass ?? "")).observeCompleted {
let selectedClass = self.selectedInternalGearCategory
self.userRepository.selectClass(HabiticaClass(rawValue: selectedClass ?? "")).observeValues { _ in
self.retrieveShopInventory {
self.fetchGear()
}
collectionView.reloadData()
}
}
Expand Down
10 changes: 9 additions & 1 deletion HabitRPG/Utilities/RouterHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ class RouterHandler {
viewController.index = Int(string: link["index"] ?? "0") ?? 0
self.push(viewController)
}
register("/static/community-guidelines") {
let viewController = StoryboardScene.Social.guidelinesNavigationViewController.instantiate()
self.present(viewController)
}
register("/user/settings.*") {
self.displayTab(index: 4)
self.present(StoryboardScene.Settings.initialScene.instantiate())
Expand Down Expand Up @@ -404,7 +408,11 @@ class RouterHandler {

private func present(_ viewController: UIViewController) {
if let tabbarController = self.tabbarController {
tabbarController.present(viewController, animated: true, completion: nil)
var presenter: UIViewController = tabbarController
while presenter.isPresenting, let presented = presenter.presentedViewController {
presenter = presented
}
presenter.present(viewController, animated: true, completion: nil)
} else {
loadingController?.loadingFinishedAction = {[weak self] in
self?.tabbarController?.present(viewController, animated: true, completion: nil)
Expand Down

0 comments on commit db3ba90

Please sign in to comment.