Skip to content

Commit

Permalink
Merge pull request #17 from g-liu/instructions-screen
Browse files Browse the repository at this point in the history
Instructions screen
  • Loading branch information
g-liu authored Mar 10, 2022
2 parents d1167c6 + 2da0819 commit 928a3f6
Show file tree
Hide file tree
Showing 11 changed files with 676 additions and 31 deletions.
24 changes: 24 additions & 0 deletions WordleWithFriends.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
6C94887C27D0AB15005252F1 /* LetterStateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C94887B27D0AB15005252F1 /* LetterStateTests.swift */; };
6C94887E27D0B4E4005252F1 /* KeyboardRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C94887D27D0B4E4005252F1 /* KeyboardRow.swift */; };
6C94F50227D5C23D00C19D43 /* Array+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C94F50127D5C23D00C19D43 /* Array+Extension.swift */; };
6C94F4F727D4494C00C19D43 /* GameInstructionsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C94F4F627D4494C00C19D43 /* GameInstructionsViewController.swift */; };
6C94F4FA27D44A8100C19D43 /* HorizontalSeparatorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C94F4F927D44A8100C19D43 /* HorizontalSeparatorView.swift */; };
6CBBCECF279BDC7D00875C30 /* Double+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CBBCECE279BDC7D00875C30 /* Double+Extension.swift */; };
6CBCC3CD2797565D005EB254 /* DismissableAlertController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CBCC3CC2797565D005EB254 /* DismissableAlertController.swift */; };
6CBCC3D1279764FF005EB254 /* CGPoint+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CBCC3D0279764FF005EB254 /* CGPoint+Extension.swift */; };
Expand Down Expand Up @@ -154,6 +156,8 @@
6C94887B27D0AB15005252F1 /* LetterStateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LetterStateTests.swift; sourceTree = "<group>"; };
6C94887D27D0B4E4005252F1 /* KeyboardRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyboardRow.swift; sourceTree = "<group>"; };
6C94F50127D5C23D00C19D43 /* Array+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Array+Extension.swift"; sourceTree = "<group>"; };
6C94F4F627D4494C00C19D43 /* GameInstructionsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameInstructionsViewController.swift; sourceTree = "<group>"; };
6C94F4F927D44A8100C19D43 /* HorizontalSeparatorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HorizontalSeparatorView.swift; sourceTree = "<group>"; };
6CBBCECE279BDC7D00875C30 /* Double+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Double+Extension.swift"; sourceTree = "<group>"; };
6CBCC3CC2797565D005EB254 /* DismissableAlertController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DismissableAlertController.swift; sourceTree = "<group>"; };
6CBCC3D0279764FF005EB254 /* CGPoint+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CGPoint+Extension.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -294,6 +298,7 @@
6C19F59C27921EFA00062083 /* AppDelegate.swift */,
6C19F59E27921EFA00062083 /* SceneDelegate.swift */,
6C19F5A027921EFA00062083 /* GameSetupViewController.swift */,
6C94F4F527D4493A00C19D43 /* How To Play */,
60D948072793BB0D00086C51 /* Settings */,
6C19F5D52792356500062083 /* ClueGuessViewController.swift */,
6C19F5A527921EFB00062083 /* Assets.xcassets */,
Expand Down Expand Up @@ -396,6 +401,23 @@
path = CustomKeyboard;
sourceTree = "<group>";
};
6C94F4F527D4493A00C19D43 /* How To Play */ = {
isa = PBXGroup;
children = (
6C94F4F827D44A7200C19D43 /* Views */,
6C94F4F627D4494C00C19D43 /* GameInstructionsViewController.swift */,
);
path = "How To Play";
sourceTree = "<group>";
};
6C94F4F827D44A7200C19D43 /* Views */ = {
isa = PBXGroup;
children = (
6C94F4F927D44A8100C19D43 /* HorizontalSeparatorView.swift */,
);
path = Views;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -560,7 +582,9 @@
6C19F5E527923B1400062083 /* WordGuessRow.swift in Sources */,
6C94887127D07FD4005252F1 /* WordleKeyboardInputView.swift in Sources */,
6CBBCECF279BDC7D00875C30 /* Double+Extension.swift in Sources */,
6C94F4FA27D44A8100C19D43 /* HorizontalSeparatorView.swift in Sources */,
6C19F60227923F8400062083 /* LetterTileView.swift in Sources */,
6C94F4F727D4494C00C19D43 /* GameInstructionsViewController.swift in Sources */,
6CBCC3CD2797565D005EB254 /* DismissableAlertController.swift in Sources */,
60D948062793AE1400086C51 /* GameSettingsViewController.swift in Sources */,
6C94887827D0AAD9005252F1 /* LetterState.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,13 @@
import UIKit

extension NSLayoutConstraint {
func with(priority: UILayoutPriority) -> NSLayoutConstraint {
self.priority = priority

return self
}

func with(priority: Int) -> NSLayoutConstraint {
return with(priority: UILayoutPriority(priority.asFloat))
}
}
26 changes: 26 additions & 0 deletions WordleWithFriends/Extensions/String+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,32 @@ extension String {
}
}

extension String {
var asAttributedString: NSAttributedString { .init(string: self) }

var bolded: NSMutableAttributedString {
.init(string: self, attributes: [.font: UIFont.boldSystemFont(ofSize: UIFont.labelFontSize)])
}

func appending(_ attributedString: NSAttributedString) -> NSMutableAttributedString {
let mutableString = NSMutableAttributedString(string: self)
mutableString.append(attributedString)

return mutableString
}
}

extension NSMutableAttributedString {
func appending(_ attributedString: NSAttributedString) -> NSMutableAttributedString {
append(attributedString)
return self
}

func appending(_ string: String) -> NSMutableAttributedString {
appending(string.asAttributedString)
}
}

extension StringProtocol {
subscript(offset: Int) -> Character {
self[index(startIndex, offsetBy: offset)]
Expand Down
26 changes: 25 additions & 1 deletion WordleWithFriends/GameSetupViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,30 @@ final class GameSetupViewController: UIViewController {
return button
}()

private lazy var instructionsButton: UIBarButtonItem = {
let button = UIBarButtonItem(title: "", style: .plain, target: self, action: #selector(showInstructions))
button.accessibilityLabel = "How to play"

return button
}()

private lazy var instructionsTextLabel: UILabel = {
let label = UILabel()
label.numberOfLines = 0
label.translatesAutoresizingMaskIntoConstraints = false
label.textAlignment = .center

return label
}()

private lazy var startGameButton: UIButton = {
let button = UIButton()
button.translatesAutoresizingMaskIntoConstraints = false
button.setTitle("Start", for: .normal)
button.addTarget(self, action: #selector(checkAndInitiateGame), for: .touchUpInside)
button.titleLabel?.font = .boldSystemFont(ofSize: 16.0)
button.titleLabel?.font = .boldSystemFont(ofSize: UIFont.buttonFontSize)
button.setTitleColor(.systemGray, for: .disabled)
button.setTitleColor(.systemGreen, for: .normal)
button.isEnabled = false
button.isHidden = true

Expand Down Expand Up @@ -138,6 +155,7 @@ final class GameSetupViewController: UIViewController {
view.backgroundColor = .systemBackground

navigationItem.leftBarButtonItem = settingsButton
navigationItem.rightBarButtonItem = instructionsButton

let stackView = UIStackView()
stackView.translatesAutoresizingMaskIntoConstraints = false
Expand Down Expand Up @@ -192,6 +210,12 @@ final class GameSetupViewController: UIViewController {
navigationController?.present(UINavigationController(rootViewController: vc), animated: true)
}

@objc private func showInstructions() {
let vc = GameInstructionsViewController()

navigationController?.present(UINavigationController(rootViewController: vc), animated: true)
}

func updateScreen() {
let clueLength = GameSettings.clueLength.readIntValue().spelledOut ?? " "
humanInstructionsTextLabel.text = "Enter your \(GameSettings.clueLength.readIntValue().spelledOut ?? " ")-letter clue below:"
Expand Down
Loading

0 comments on commit 928a3f6

Please sign in to comment.