Skip to content

Commit

Permalink
done with animations
Browse files Browse the repository at this point in the history
  • Loading branch information
lukehasawii committed Apr 29, 2023
1 parent 923402c commit 694d419
Show file tree
Hide file tree
Showing 6 changed files with 314 additions and 59 deletions.
37 changes: 29 additions & 8 deletions SoundboardQuiz/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@
<collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="10" minimumInteritemSpacing="10" id="2SH-bc-Smv">
<size key="itemSize" width="111.00000000000001" height="115"/>
<size key="headerReferenceSize" width="0.0" height="0.0"/>
<size key="footerReferenceSize" width="0.0" height="0.0"/>
<size key="footerReferenceSize" width="50" height="200"/>
<inset key="sectionInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>
</collectionViewFlowLayout>
<cells>
Expand Down Expand Up @@ -465,6 +465,10 @@
</connections>
</collectionViewCell>
</cells>
<collectionReusableView key="sectionFooterView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" id="a9o-n1-FIt">
<rect key="frame" x="0.0" y="115" width="159.33333333333331" height="200"/>
<autoresizingMask key="autoresizingMask"/>
</collectionReusableView>
<connections>
<outlet property="dataSource" destination="kJ7-Za-81c" id="7Ff-g3-Avk"/>
<outlet property="delegate" destination="kJ7-Za-81c" id="rAQ-4y-aBC"/>
Expand All @@ -483,28 +487,37 @@
<rect key="frame" x="0.0" y="0.0" width="160.33333333333334" height="552"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="10" minimumInteritemSpacing="0.0" id="ENa-04-gY6">
<collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="40" minimumInteritemSpacing="0.0" id="ENa-04-gY6">
<size key="itemSize" width="111" height="115"/>
<size key="headerReferenceSize" width="0.0" height="0.0"/>
<size key="footerReferenceSize" width="0.0" height="0.0"/>
<inset key="sectionInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>
<size key="footerReferenceSize" width="50" height="200"/>
<inset key="sectionInset" minX="10" minY="0.0" maxX="10" maxY="0.0"/>
</collectionViewFlowLayout>
<cells>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="soundPanel" id="ZDC-NG-9HK" customClass="SoundCollectionViewCell" customModule="SoundboardQuiz" customModuleProvider="target">
<rect key="frame" x="24.666666666666668" y="0.0" width="111" height="115"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<collectionViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" id="ZOX-xQ-y3C">
<collectionViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" id="tiy-hT-C5F">
<rect key="frame" x="0.0" y="0.0" width="111" height="115"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="4" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="0MS-cS-km3">
<rect key="frame" x="7.9999999999998472" y="13" width="95" height="89"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" misplaced="YES" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="4" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="0MS-cS-km3">
<rect key="frame" x="2" y="51" width="108" height="20"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="play.fill" catalog="system" translatesAutoresizingMaskIntoConstraints="NO" id="XBE-pD-YWX">
<rect key="frame" x="24" y="25.000000000000007" width="63" height="16.333333333333336"/>
<color key="tintColor" systemColor="labelColor"/>
</imageView>
</subviews>
<constraints>
<constraint firstAttribute="trailing" secondItem="XBE-pD-YWX" secondAttribute="trailing" constant="24" id="0Ez-xg-aww"/>
<constraint firstItem="0MS-cS-km3" firstAttribute="top" secondItem="XBE-pD-YWX" secondAttribute="bottom" constant="8" symbolic="YES" id="3nA-Rc-uBW"/>
<constraint firstItem="XBE-pD-YWX" firstAttribute="leading" secondItem="tiy-hT-C5F" secondAttribute="leading" constant="24" id="4RE-a6-c3W"/>
<constraint firstItem="XBE-pD-YWX" firstAttribute="top" secondItem="tiy-hT-C5F" secondAttribute="top" constant="23" id="8MI-EF-oFe"/>
</constraints>
</collectionViewCellContentView>
<color key="backgroundColor" systemColor="systemGreenColor"/>
<size key="customSize" width="111" height="115"/>
Expand All @@ -513,6 +526,10 @@
</connections>
</collectionViewCell>
</cells>
<collectionReusableView key="sectionFooterView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" id="FTM-nL-6Oq">
<rect key="frame" x="0.0" y="115" width="160.33333333333331" height="200"/>
<autoresizingMask key="autoresizingMask"/>
</collectionReusableView>
<connections>
<outlet property="dataSource" destination="20M-bQ-Faq" id="wRy-TC-739"/>
<outlet property="delegate" destination="20M-bQ-Faq" id="rnS-mC-BfW"/>
Expand All @@ -526,9 +543,13 @@
</scenes>
<resources>
<image name="arrow.forward" catalog="system" width="128" height="95"/>
<image name="play.fill" catalog="system" width="117" height="128"/>
<image name="shuffle" catalog="system" width="128" height="95"/>
<image name="theatermasks.fill" catalog="system" width="128" height="86"/>
<image name="trophy.fill" catalog="system" width="128" height="128"/>
<systemColor name="labelColor">
<color red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
Expand Down
7 changes: 7 additions & 0 deletions SoundboardQuiz/ImageCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,12 @@ class ImageCollectionViewCell: UICollectionViewCell {

}
}
override func prepareForReuse() {
secretName = nil
name = nil
imageFile = nil
secretImageFile = nil
backgroundColor = .systemRed
}

}
64 changes: 55 additions & 9 deletions SoundboardQuiz/MainGameViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,37 @@ class MainGameViewController: UIViewController {
}
subSounds = subSounds?.shuffled()

embeddedViewController1.shuffle()
embeddedViewController2.shuffle()


}
func addSoundItems(_ numItems: Int){

// for aSound in subSounds!{
// print(aSound.name!, terminator: ", ")
// }
// print()

if let sub = sounds?.shuffled() {
var slice = Array(sub[0..<min(numItems, sub.endIndex)])
while (slice.count < numItems) {
slice.append(sub.randomElement()!)
}
subSounds?.append(contentsOf: Array(slice))
}else{
print("error")
return
}

embeddedViewController1.reloadFromParentController()
embeddedViewController2.reloadFromParentController()
}
@IBAction func doAnimateNewItems(_ sender: Any) {

shuffle(itemCount: 8)
embeddedViewController1.reload()
embeddedViewController2.reload()
//shuffle(itemCount: 8)
addSoundItems(4)

if var subSounds {
subSounds = Array(subSounds[4..<min(8, subSounds.endIndex)])
//TODO: FIX FILLER FUNCTION

self.subSounds = subSounds
print("subsounds shrunk")
}else{
Expand All @@ -69,6 +85,29 @@ class MainGameViewController: UIViewController {
embeddedViewController2.disableUserInteractionAndAnimate()


}

func animate() {

//shuffle(itemCount: 8)
addSoundItems(4)

if var subSounds {
subSounds = Array(subSounds[4..<min(8, subSounds.endIndex)])
self.subSounds = subSounds
print("subsounds shrunk")
}else{
print("ERROR: subsounds not shrunk")
}
// do animate here
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
self.embeddedViewController1.disableUserInteractionAndAnimate()
self.embeddedViewController2.disableUserInteractionAndAnimate()

}



}
func populateSounds() {
if let sub = sounds?.shuffled(){
Expand All @@ -95,6 +134,9 @@ class MainGameViewController: UIViewController {
// Do any additional setup after loading the view.
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

shuffle(itemCount: 4)

if let vc = segue.destination as? SquareCollectionViewController,
segue.identifier == "soundViewSegue" {
self.embeddedViewController1 = vc
Expand All @@ -115,13 +157,17 @@ class MainGameViewController: UIViewController {
scoreLabel.text = "Score: \(score)"
let didSucceed = embeddedViewController1.correctCell(name: name)
print("did succeed? \(didSucceed)")
if(score > 0 && score % 4 == 0){
animate()

}
}

@IBAction func shuffleTapped(_ sender: Any) {
shuffle(itemCount: 4)

embeddedViewController1.shuffle()
embeddedViewController2.shuffle()
embeddedViewController1.reloadFromParentController()
embeddedViewController2.reloadFromParentController()

embeddedViewController1.reload()
embeddedViewController2.reload()
Expand Down
1 change: 1 addition & 0 deletions SoundboardQuiz/SoundCollectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ class SoundCollectionView: UICollectionView {
}
*/


}
14 changes: 12 additions & 2 deletions SoundboardQuiz/SoundCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,21 @@ class SoundCollectionViewCell: UICollectionViewCell {

private var secretSoundFile: URL?

public var imageFile: URL? {
public var soundFile: URL? {
get{
return secretSoundFile
}
set{
secretSoundFile = newValue
}
}
override func prepareForReuse() {
secretName = nil
name = nil
soundFile = nil
secretSoundFile = nil
backgroundColor = .systemGreen
}

// public var cellID: Int = {
// return lastNum
Expand All @@ -47,5 +54,8 @@ class SoundCollectionViewCell: UICollectionViewCell {
// super.init(coder: coder)
// SoundCollectionViewCell.lastNum = ((SoundCollectionViewCell.lastNum + 1) % Int.max)
// }

// override func layoutSubviews() {
// super.layoutSubviews()
// contentView.frame = contentView.frame.inset(by: UIEdgeInsets(top: 0, left: 0, bottom: 50, right: 0))
// }
}
Loading

0 comments on commit 694d419

Please sign in to comment.