Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 45.28 KB | None | 0 0
  1. //
  2. // MixMatchViewController.m
  3. // cmcd_fcb_critters
  4. //
  5. // Created by Li, Yun on 6/2/11.
  6. // Copyright 2011 __MyCompanyName__. All rights reserved.
  7. //
  8.  
  9. #import "MixMatchViewController.h"
  10. #import <UIKit/UIKit.h>
  11. #import <CoreData/CoreData.h>
  12. #import <CoreGraphics/CGGeometry.h>
  13. #include <QuartzCore/QuartzCore.h>
  14.  
  15. #import "MainViewController.h"
  16. #import "SettingsViewController.h"
  17. #import "cmcd_fcb_crittersAppDelegate.h"
  18.  
  19.  
  20.  
  21. //demetions for iPad;
  22. static NSUInteger pageWidth_iPad = 768;
  23. static NSUInteger topHeight_iPad = 696;
  24. static NSUInteger bottomHeight_iPad = 308;
  25. //demetions for iPhone
  26. static NSUInteger pageWidth_iPhone = 320;
  27. static NSUInteger topHeight_iPhone = 318;
  28. static NSUInteger bottomHeight_iPhone = 142;
  29.  
  30. @implementation MixMatchViewController
  31.  
  32. @synthesize myIndex;
  33. @synthesize topText;
  34. @synthesize largeText;
  35. @synthesize smallText;
  36. @synthesize animalText;
  37. @synthesize animalTextCH1;
  38. @synthesize animalTextCH2;
  39. @synthesize animalNames;
  40. @synthesize centerBar;
  41. @synthesize numberNames;
  42. @synthesize topCards;
  43. @synthesize bottomCards;
  44. @synthesize cardTop;
  45. @synthesize cardBottom;
  46. @synthesize cardSet;
  47. @synthesize home;
  48. @synthesize pages;
  49. @synthesize tiles;
  50.  
  51. @synthesize bottomKeys;
  52. @synthesize topKeys;
  53.  
  54. @synthesize buttonTimer;
  55. @synthesize narrationTimer;
  56. @synthesize pageControl;
  57. @synthesize delegate;
  58.  
  59. @synthesize homeButtonPushedTime;
  60. @synthesize matches;
  61. @synthesize successPlayers;
  62.  
  63. // Utility method for accessing the main controller (which houses our views)
  64. - (MainViewController*)getMainViewController {
  65. return [(cmcd_fcb_crittersAppDelegate*)[[UIApplication sharedApplication] delegate] mainViewController];
  66. }
  67.  
  68. - (cmcd_fcb_crittersAppDelegate*)getAppDelegate {
  69. return (cmcd_fcb_crittersAppDelegate*)[[UIApplication sharedApplication] delegate];
  70. }
  71. - (void)viewDidLoad {
  72. [super viewDidLoad];
  73. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  74.  
  75. // check to see what the state of our mute button should be
  76. if ([NSUserDefaults standardUserDefaults]) {
  77. cardSet = [[NSUserDefaults standardUserDefaults] objectForKey:@"cardSet"];
  78. NSLog(@"set the card set!");
  79. }
  80. self.tiles = ([[cardSet objectForKey:@"tiles"] integerValue]);
  81. self.pages = ([[cardSet objectForKey:@"tiles"] integerValue]*10);
  82. NSLog(@"the pages are, the tiles are : %d, %d",pages, tiles);
  83. [self loadNumberNames];
  84. [self loadAnimalNames];
  85. [self resetKeys];
  86.  
  87. if (cardTop) {
  88. cardTop = nil;
  89. [cardTop release];
  90. }
  91. if (cardBottom) {
  92. cardBottom = nil;
  93. [cardBottom release];
  94. }
  95. /* Set up the SP dialog window */
  96.  
  97. CGRect topFrame;
  98. CGRect bottomFrame;
  99. /* We only use the top frame in Mix & Match mode */
  100. NSUInteger pageWidth;
  101. NSUInteger topHeight;
  102. NSUInteger bottomHeight;
  103.  
  104.  
  105. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
  106. pageWidth = pageWidth_iPad;
  107. topHeight =topHeight_iPad;
  108. bottomHeight =bottomHeight_iPad;
  109. }
  110. else{
  111. pageWidth = pageWidth_iPhone;
  112. topHeight =topHeight_iPhone;
  113. bottomHeight =bottomHeight_iPhone;
  114. }
  115. topFrame = CGRectMake(0, 0, pageWidth, topHeight);
  116. bottomFrame = CGRectMake(0, topHeight, pageWidth, bottomHeight);
  117.  
  118. //top
  119. self.cardTop = [[Scroller alloc] initWithFrame:topFrame];
  120. cardTop.region = @"t";
  121. cardTop.pagingEnabled = YES;
  122. cardTop.contentSize = CGSizeMake(pageWidth*pages, topHeight);
  123. cardTop.showsHorizontalScrollIndicator = NO;
  124. cardTop.showsVerticalScrollIndicator = NO;
  125. cardTop.scrollsToTop = NO;
  126. cardTop.delegate = self;
  127.  
  128. cardTop.scrollEnabled = FALSE;
  129. [self.view addSubview:cardTop];
  130. [self.view sendSubviewToBack:cardTop];
  131. //bottom
  132. self.cardBottom = [[Scroller alloc] initWithFrame:bottomFrame];
  133. cardBottom.region = @"b";
  134. cardBottom.pagingEnabled = YES;
  135. cardBottom.contentSize = CGSizeMake(pageWidth*pages, bottomHeight);
  136. cardBottom.showsHorizontalScrollIndicator = NO;
  137. cardBottom.showsVerticalScrollIndicator = NO;
  138. cardBottom.scrollsToTop = NO;
  139. cardBottom.delegate = self;
  140. [self.view addSubview:cardBottom];
  141. [self.view sendSubviewToBack:cardBottom];
  142.  
  143.  
  144. [self loadScrollView:0 withRegion:@"t"];
  145. //[self loadScrollView:1 withRegion:@"t"];
  146. //[self loadScrollView:2 withRegion:@"t"];
  147.  
  148. [self loadScrollView:0 withRegion:@"b"];
  149. //[self loadScrollView:1 withRegion:@"b"];
  150. //[self loadScrollView:2 withRegion:@"b"];
  151.  
  152. //match
  153. matches = [[NSMutableArray alloc] init];
  154. //[self showMatches];
  155. topText.text = @"Double Tap Image to Confirm a Match";
  156. UIColor *grey = [UIColor colorWithRed:0.52 green:0.52 blue:0.52 alpha:1.0];
  157. topText.textColor = grey;
  158. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
  159. animalText.font = [UIFont fontWithName:@"Helvetica-Bold" size:32];
  160. animalText.textAlignment = UITextAlignmentCenter;
  161. animalTextCH1.font = [UIFont fontWithName:@"Helvetica-Bold" size:32];
  162. animalTextCH1.textAlignment = UITextAlignmentRight;
  163. animalTextCH2.font = [UIFont fontWithName:@"Helvetica-Bold" size:32];
  164. animalTextCH2.textAlignment = UITextAlignmentLeft;
  165. centerBar.font = [UIFont fontWithName:@"Helvetica-Bold" size:32];
  166. centerBar.textAlignment = UITextAlignmentCenter;
  167. // largeText.font = [UIFont fontWithName:@"Helvetica-Bold" size:280];
  168. // largeText.textAlignment = UITextAlignmentCenter;
  169. smallText.font = [UIFont fontWithName:@"Helvetica-Bold" size:44];
  170. smallText.textAlignment = UITextAlignmentLeft;
  171. topText.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
  172. topText.textAlignment = UITextAlignmentCenter;
  173.  
  174. [self becomeFirstResponder];
  175.  
  176.  
  177. }
  178. else{
  179. animalText.font = [UIFont fontWithName:@"Helvetica-Bold" size:17];
  180. animalText.textAlignment = UITextAlignmentCenter;
  181. animalTextCH1.font = [UIFont fontWithName:@"Helvetica-Bold" size:17];
  182. animalTextCH1.textAlignment = UITextAlignmentRight;
  183. animalTextCH2.font = [UIFont fontWithName:@"Helvetica-Bold" size:17];
  184. animalTextCH2.textAlignment = UITextAlignmentLeft;
  185. centerBar.font = [UIFont fontWithName:@"Helvetica-Bold" size:17];
  186. centerBar.textAlignment = UITextAlignmentCenter;
  187. // largeText.font = [UIFont fontWithName:@"Helvetica-Bold" size:100];
  188. // largeText.textAlignment = UITextAlignmentCenter;
  189. smallText.font = [UIFont fontWithName:@"Helvetica-Bold" size:17];
  190. smallText.textAlignment = UITextAlignmentLeft;
  191. topText.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
  192. topText.textAlignment = UITextAlignmentCenter;
  193. [self becomeFirstResponder];
  194. }
  195.  
  196. [pool release];
  197. }
  198.  
  199. - (void)loadNumberNames {
  200. NSLog(@"%@", cardSet);
  201. NSString *docs = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
  202. NSString *plist = [NSString stringWithFormat:@"%@_number_%@", [cardSet objectForKey:@"prefix"], [cardSet objectForKey:@"language"]];
  203. NSString *path = [NSString stringWithFormat:@"%@/%@/%@.plist", docs, [cardSet objectForKey:@"prefix"], plist];
  204.  
  205. NSLog(@"plistPath: %@", path);
  206. NSFileManager *fileManager = [NSFileManager defaultManager];
  207. if (![fileManager fileExistsAtPath:path]) {
  208. NSLog(@"reading plist from nib");
  209. path = [[NSBundle mainBundle] pathForResource:plist ofType:@"plist"];
  210. }
  211.  
  212. self.numberNames = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
  213. }
  214. - (void)loadAnimalNames {
  215. NSLog(@"%@", cardSet);
  216. NSString *docs = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
  217. NSString *plist = [NSString stringWithFormat:@"%@_animal_%@", [cardSet objectForKey:@"prefix"], [cardSet objectForKey:@"language"]];
  218. NSString *path = [NSString stringWithFormat:@"%@/%@/%@.plist", docs, [cardSet objectForKey:@"prefix"], plist];
  219.  
  220. NSLog(@"plistPath: %@", path);
  221. NSFileManager *fileManager = [NSFileManager defaultManager];
  222. if (![fileManager fileExistsAtPath:path]) {
  223. NSLog(@"reading plist from nib");
  224. path = [[NSBundle mainBundle] pathForResource:plist ofType:@"plist"];
  225. }
  226.  
  227. self.animalNames = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
  228. }
  229. /*****************
  230. * BUTTON ACTIONS
  231. *****************/
  232.  
  233. - (BOOL) isTapAndHold {
  234. if ([NSUserDefaults standardUserDefaults]) {
  235. return [[NSUserDefaults standardUserDefaults] boolForKey:@"tapAndHold"];
  236. }
  237. return FALSE;
  238. }
  239. - (IBAction)homeButtonDown:(id)sender {
  240. homeButtonPushedTime = [NSDate date];
  241. if ([self isTapAndHold]) {
  242. buttonTimer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(pushedHomeButton:) userInfo:homeButtonPushedTime repeats: NO];
  243. }
  244. }
  245.  
  246. - (IBAction)homeButtonUp:(id)sender {
  247. homeButtonPushedTime = NULL;
  248. if (![self isTapAndHold]) {
  249. [self pushedHomeButton:NULL];
  250. }
  251. }
  252.  
  253. - (void) pushedHomeButton:(id)timer {
  254. if ([self isTapAndHold] && (NSDate*)[timer userInfo] != homeButtonPushedTime) return;
  255.  
  256. [(cmcd_fcb_crittersAppDelegate*)[[UIApplication sharedApplication] delegate] playButtonSound];
  257. [self.delegate mixMatchViewControllerDidFinish:self];
  258. }
  259. /**************************************************
  260. * AUDIO TODO: Move this to app delegate like music
  261. **************************************************/
  262. - (void) playSound:(NSString *)file {
  263. [(cmcd_fcb_crittersAppDelegate*)[[UIApplication sharedApplication] delegate] playSound:file];
  264. }
  265.  
  266. - (void) playNarration:(NSString *)prefix forCard:(NSString *)index forType:(NSString *)type inLanguage:(NSString *) lang{
  267. [(cmcd_fcb_crittersAppDelegate*)[[UIApplication sharedApplication] delegate] playNarration:prefix forCard:index forType:type inLanguage:lang];
  268. }
  269.  
  270. - (void) playFancyNarration:(NSString *)number forCount:(NSString *)count forType:(NSString *)type {
  271. NSLog(@"fancy!");
  272. BOOL twoParts = YES;
  273. NSArray *fcbExceptions = [NSArray arrayWithObjects:@"2", @"15", @"16", @"17", nil];
  274.  
  275. if ([[cardSet objectForKey:@"language"] isEqualToString:@"ch"]) {
  276. twoParts = NO;
  277. }
  278. if (([[cardSet objectForKey:@"language"] isEqualToString:@"ch"]) && ([[cardSet objectForKey:@"prefix"] isEqualToString:@"fcb"]) && ([fcbExceptions containsObject:number])) {
  279. twoParts = NO;
  280. }
  281.  
  282. if (twoParts) {
  283. self.myIndex = number;
  284. NSString *file = [NSString stringWithFormat:@"%@_%@_no", [cardSet objectForKey:@"prefix"], count];
  285. [(cmcd_fcb_crittersAppDelegate*)[[UIApplication sharedApplication] delegate] playVoiceover:file inLanguage:[cardSet objectForKey:@"language"]];
  286. narrationTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(playAnimal:) userInfo:type repeats: NO];
  287. } else {
  288. NSString *file = [NSString stringWithFormat:@"%@_%@_%@", [cardSet objectForKey:@"prefix"], number, count];
  289. [(cmcd_fcb_crittersAppDelegate*)[[UIApplication sharedApplication] delegate] playVoiceover:file inLanguage:[cardSet objectForKey:@"language"]];
  290. }
  291. }
  292.  
  293. - (void) playAnimal:(NSTimer *) timer{
  294. NSString *type = timer.userInfo;
  295. NSLog(@"type: %@", type);
  296. [self playNarration:[cardSet objectForKey:@"prefix"] forCard:myIndex forType:type inLanguage:[cardSet objectForKey:@"language"]];
  297.  
  298. }
  299. - (void) playSingleAnimal:(NSTimer *) timer{
  300. [self playNarration:[cardSet objectForKey:@"prefix"] forCard:myIndex forType:@"sa" inLanguage:[cardSet objectForKey:@"language"]];
  301.  
  302. }
  303. - (void) playMultipleAnimal:(NSTimer *) timer{
  304. [self playNarration:[cardSet objectForKey:@"prefix"] forCard:myIndex forType:@"ma" inLanguage:[cardSet objectForKey:@"language"]];
  305.  
  306. }
  307.  
  308. /*****************
  309. * GAME PLAY
  310. *****************/
  311.  
  312. - (void)tapDetectingImageView:(TapCard *)view gotSingleTapAtPoint:(CGPoint)tapPoint {
  313. NSLog(@"got single tap in the %@ region at %f", view.whichRegion, tapPoint.x);
  314.  
  315. NSString *bottomIndex = [[bottomCards objectAtIndex:[self whichPage:cardBottom.contentOffset]] cardIndex];
  316. NSString *topIndex = [[topCards objectAtIndex:[self whichPage:cardTop.contentOffset]] cardIndex];
  317.  
  318.  
  319. //the top image, animal index
  320. int intIndex =[topIndex intValue]%tiles;
  321. if( intIndex==0){ intIndex=tiles;}
  322. NSString *animalIndex = [NSString stringWithFormat:@"%d", intIndex];
  323. self.myIndex = animalIndex;
  324. //the top image, animal number
  325. int intNumber =[topIndex intValue]%10;
  326. if( intNumber==0){ intNumber=10;}
  327. NSString *animalNumber = [NSString stringWithFormat:@"%d", intNumber];
  328.  
  329. // topIndex = [NSString stringWithFormat:@"%d", intIndex];
  330. int intIndex2 =[bottomIndex intValue]%10;
  331. if( intIndex2==0){ intIndex2=10;}
  332. bottomIndex = [NSString stringWithFormat:@"%d", intIndex2];
  333. NSLog(@"intIndex = %d", intIndex);
  334.  
  335. if (([view.whichRegion isEqualToString:@"t"])) {
  336.  
  337. // chinese requires special positioning
  338. if([[cardSet objectForKey:@"language"] isEqualToString:@"ch"]) {
  339. centerBar.text = @"|";
  340. animalTextCH1.text = [[animalNames objectForKey:animalIndex] objectForKey:@"l"];
  341. animalTextCH2.text = [[animalNames objectForKey:animalIndex] objectForKey:@"r"];
  342. } else {
  343.  
  344. if (intNumber==1) {
  345. animalText.text = [animalNames objectForKey:animalIndex];
  346. } else {
  347. animalText.text = [animalNames objectForKey:animalIndex];
  348. }
  349.  
  350. }
  351. NSLog(@"animal index: %@, animal number:%@ ",animalIndex, animalNumber);
  352. //single/multiple animal(s)
  353. if (intNumber == 1) {
  354. [self playFancyNarration:animalIndex forCount:animalNumber forType:@"sa"];
  355. } else {
  356. [self playFancyNarration:animalIndex forCount:animalNumber forType:@"ma"];
  357. }
  358. } else if (([view.whichRegion isEqualToString:@"b"])) {
  359.  
  360. largeText.text = [[numberNames objectForKey:bottomIndex] objectForKey:@"r"];
  361. smallText.text = [[numberNames objectForKey:bottomIndex] objectForKey:@"l"];
  362.  
  363. if(([[cardSet objectForKey:@"language"] isEqualToString:@"es"]) || ([[cardSet objectForKey:@"language"] isEqualToString:@"fr"]))
  364. {
  365. [self playNarration:[cardSet objectForKey:@"prefix"] forCard:bottomIndex forType:@"noun" inLanguage:[cardSet objectForKey:@"language"]];
  366. }
  367. else
  368. {
  369. [self playNarration:[cardSet objectForKey:@"prefix"] forCard:bottomIndex forType:@"no" inLanguage:[cardSet objectForKey:@"language"]];
  370. }
  371.  
  372. }
  373. }
  374.  
  375. - (void)tapDetectingImageView:(TapCard *)view gotDoubleTapAtPoint:(CGPoint)tapPoint {
  376. NSLog(@"got double tap in the %@ region", view.whichRegion);
  377. int tpage = [self whichPage:cardTop.contentOffset];
  378. int bpage = [self whichPage:cardBottom.contentOffset];
  379. CardViewController *tc = [topCards objectAtIndex:tpage];
  380. CardViewController *bc = [bottomCards objectAtIndex:bpage];
  381. // make sure the indexes match & that we haven't already matched this pair
  382. [self matchCards:tc.cardNumber otherIndex:bc.cardNumber cardIndex:tc.cardIndex];
  383. }
  384. -(int)whichPage:(CGPoint)point {
  385. /* We only use the top frame in Mix & Match mode */
  386. NSUInteger pageWidth;
  387.  
  388. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
  389. pageWidth = pageWidth_iPad;
  390. }
  391. else{
  392. pageWidth = pageWidth_iPhone;
  393. }
  394. int page = point.x / pageWidth;
  395. return page;
  396. }
  397. -(void)matchCards:(NSString *)topIndex otherIndex:(NSString *)bottomIndex cardIndex:(NSString *)index{
  398. UIColor *green = [UIColor colorWithRed:0.38 green:0.54 blue:0.38 alpha:1.0];
  399. UIColor *red = [UIColor colorWithRed:0.75 green:0.23 blue:0.23 alpha:1.0];
  400. if([matches containsObject:index]){
  401. cardTop.scrollEnabled = TRUE;
  402. }
  403. if (([topIndex isEqualToString:bottomIndex]&& (![matches containsObject:index]))) {
  404. [matches addObject:index];
  405. //[self showMatches];
  406. NSArray *successSounds = [NSArray arrayWithObjects:@"fca_uni_1", @"fca_uni_2", nil];
  407. int i = arc4random() % ([successSounds count]);
  408. NSLog(@"success: %d, index: %@", i, index);
  409. [self playSound:@"fca_uni_3"];
  410.  
  411. [self playSound:[successSounds objectAtIndex:i]];
  412. cardTop.scrollEnabled = TRUE;
  413. topText.textColor = green;
  414. // UIColor *grey = [UIColor colorWithRed:0.52 green:0.52 blue:0.52 alpha:1.0];
  415. // instructionText.text = @"Swipe Image to Continue";
  416. // instructionText.textColor = grey;
  417. NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(displayInstruction:) userInfo:nil repeats: NO];
  418.  
  419. }
  420. else{
  421. [self playSound:@"fca_uni_8"];
  422. topText.textColor = red;
  423. }
  424.  
  425. }
  426. - (void) displayInstruction:(NSTimer *) timer{
  427. UIColor *grey = [UIColor colorWithRed:0.52 green:0.52 blue:0.52 alpha:1.0];
  428. topText.text = @"Swipe Image to Continue";
  429. topText.textColor = grey;
  430. }
  431. - (void)loadScrollView:(int)page withRegion:(NSString *)region{
  432. /* We only use the top frame in Mix & Match mode */
  433. NSUInteger pageWidth;
  434. NSUInteger topHeight;
  435. NSUInteger bottomHeight;
  436.  
  437. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
  438. pageWidth = pageWidth_iPad;
  439. topHeight =topHeight_iPad;
  440. bottomHeight =bottomHeight_iPad;
  441. }
  442. else{
  443. pageWidth = pageWidth_iPhone;
  444. topHeight =topHeight_iPhone;
  445. bottomHeight =bottomHeight_iPhone;
  446. }
  447. if (page < 0) return;
  448. if (page >= pages) return;
  449. int bn =[[bottomKeys objectAtIndex:page]intValue]%10;
  450. if( bn==0){ bn=10;}
  451. NSString *bottomNumber = [NSString stringWithFormat:@"%d", bn];
  452. int tn =[[topKeys objectAtIndex:page]intValue]%10;
  453. if( tn==0){ tn=10;}
  454. NSString *topNumber = [NSString stringWithFormat:@"%d", tn];
  455. // NSLog(@"loading page %d for region %@", page, region);
  456. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  457.  
  458. // NSLog(@"the key is: %d and number is %d",page,n);
  459. // NSString *number = [NSString stringWithFormat:@"%d", n];
  460. if ([region isEqualToString:@"t"])
  461. {
  462. CardViewController *tcvc = [topCards objectAtIndex:page];
  463. if ((NSNull *)tcvc == [NSNull null]) {
  464. tcvc = [[CardViewController alloc] initWithPageNumber3:page withRegion:@"t" withNumber:topNumber withCard:[topKeys objectAtIndex:page]];
  465.  
  466. CGRect frame = cardTop.frame;
  467. frame.origin.x = frame.size.width * page;
  468. frame.origin.y = 0;
  469. TapCard *tapCard = [self createTapCard:[topKeys objectAtIndex:page] forRegion:region forNumber:topNumber withFrame:frame];
  470.  
  471. [cardTop addSubview:tapCard];
  472. [tcvc.tapCards addObject:tapCard];
  473. [topCards replaceObjectAtIndex:page withObject:tcvc];
  474. [tcvc release];
  475. NSLog(@"the top key is: %@ and top number is %@",[topKeys objectAtIndex:page],topNumber);
  476.  
  477. }
  478. }
  479. else if ([region isEqualToString:@"b"]){
  480. CardViewController *bcvc = [bottomCards objectAtIndex:page];
  481. if ((NSNull *)bcvc == [NSNull null]) {
  482. bcvc = [[CardViewController alloc] initWithPageNumber3:page withRegion:@"b" withNumber:bottomNumber withCard:[bottomKeys objectAtIndex:page]];
  483.  
  484. CGFloat x = pageWidth * page;
  485. CGFloat y = 0;
  486.  
  487.  
  488. CGRect frame = CGRectMake(x, y, pageWidth, bottomHeight);
  489. TapCard *tapCard = [self createBandCard:[bottomKeys objectAtIndex:page] forRegion:region forNumber:bottomNumber withFrame:frame];
  490. if(page ==0)
  491. {
  492. largeText.text = [[numberNames objectForKey:bottomNumber] objectForKey:@"r"];
  493. smallText.text = [[numberNames objectForKey:bottomNumber] objectForKey:@"l"];
  494. }
  495. [cardBottom addSubview:tapCard];
  496. [bcvc.tapCards addObject:tapCard];
  497. [bottomCards replaceObjectAtIndex:page withObject:bcvc];
  498. [bcvc release];
  499.  
  500. NSLog(@"the bottom key is: %@ and bottom number is %@",[bottomKeys objectAtIndex:page],bottomNumber);
  501. }
  502. }
  503. //NSLog(@"the top key is: %@ and top number is %@",[topKeys objectAtIndex:page],topNumber);
  504. //NSLog(@"the bottom key is: %@ and bottom number is %@",[bottomKeys objectAtIndex:page],bottomNumber);
  505. [pool release];
  506. }
  507.  
  508. - (TapCard *) createTapCard:(NSString *)index forRegion:(NSString *)region forNumber:(NSString *)number withFrame:(CGRect)frame {
  509. NSString *docs = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
  510.  
  511. int intIndex = [index intValue]%tiles;
  512. int intNumber = [index intValue]%10;
  513. if(intIndex == 0)
  514. {intIndex =tiles;}
  515. if(intNumber == 0)
  516. {intNumber =10;}
  517. NSString *animalIndex = [NSString stringWithFormat:@"%d",intIndex];
  518. NSString *numberIndex = [NSString stringWithFormat:@"%d",intNumber];
  519.  
  520. UIImage *image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@/%@_%@_art_%@.jpg", docs, [cardSet objectForKey:@"prefix"], [cardSet objectForKey:@"prefix"], animalIndex, number]];
  521. NSLog(@"%@/%@/%@_%@_art_%@.jpg", docs, [cardSet objectForKey:@"prefix"], [cardSet objectForKey:@"prefix"], animalIndex, number);
  522. TapCard *tapCard = [[TapCard alloc] initWithImage: image];
  523.  
  524. tapCard.cardIndex = animalIndex;
  525. tapCard.cardNumber =number;
  526. tapCard.whichRegion =region;
  527. tapCard.frame = frame;
  528. tapCard.delegate = self;
  529. [tapCard autorelease];
  530.  
  531. return tapCard;
  532. }
  533. - (TapCard *) createBandCard:(NSString *)index forRegion:(NSString *)region forNumber:(NSString *)number withFrame:(CGRect)frame {
  534. /*
  535. NSString *docs = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
  536. int pages;
  537. if([cardSet objectForKey:@"prefix"]==@"fca")
  538. {
  539. pages = pages20;
  540. }
  541. else if([cardSet objectForKey:@"prefix"]==@"fcb")
  542. {
  543. pages = pages30;
  544. }
  545. int intIndex = [index intValue]%pages;
  546. if(intIndex == 0)
  547. {intIndex =pages;}
  548. index = [NSString stringWithFormat:@"%d",intIndex];
  549. if([cardSet objectForKey:@"language"]==@"ch")
  550. {
  551. centerBar.text = @"|";
  552. animalTextCH1.text = [NSString stringWithFormat:@"", [[animalNames objectForKey:index] objectForKey:@"l"]];
  553. animalTextCH2.text = [NSString stringWithFormat:@"", [[animalNames objectForKey:index] objectForKey:@"r"]];
  554. }
  555. else{
  556. animalText.text = [NSString stringWithFormat:@"", [animalNames objectForKey:index]];
  557. }
  558.  
  559. UIImage *image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@/%@_%@_art_%@.jpg", docs, [cardSet objectForKey:@"prefix"], [cardSet objectForKey:@"prefix"], index, number]];
  560. //NSLog(@"%@/%@/%@_%@_art_%@.jpg", docs, [cardSet objectForKey:@"prefix"], [cardSet objectForKey:@"prefix"], index, number);
  561. TapCard *tapCard = [[TapCard alloc] initWithImage: image];
  562.  
  563. tapCard.cardIndex = index;
  564. tapCard.cardNumber =number;
  565. tapCard.whichRegion =region;
  566. tapCard.frame = frame;
  567. tapCard.delegate = self;
  568. [tapCard autorelease];
  569.  
  570. return tapCard;
  571. */
  572.  
  573. int intIndex = [index intValue]%tiles;
  574. if(intIndex == 0)
  575. {intIndex =tiles;}
  576. index = [NSString stringWithFormat:@"%d",intIndex];
  577. //NSString *docs = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
  578. // UIImage *image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@/%@_%@_art_%@.jpg", docs, [cardSet objectForKey:@"prefix"], [cardSet objectForKey:@"prefix"], index, number]];
  579. UIImage *image = [UIImage imageWithContentsOfFile:@""];
  580.  
  581. largeText.text = [NSString stringWithFormat:@"", [[numberNames objectForKey:index] objectForKey:@"r"]];
  582. smallText.text = [NSString stringWithFormat:@"", [[numberNames objectForKey:index] objectForKey:@"l"]];
  583. NSLog(@"%@_%@_art_%@.jpg", [cardSet objectForKey:@"prefix"], index, number);
  584. TapCard *tapCard = [[TapCard alloc] initWithImage: image];
  585.  
  586. tapCard.cardIndex = index;
  587. tapCard.cardNumber =number;
  588. tapCard.whichRegion =region;
  589. tapCard.frame = frame;
  590. tapCard.delegate = self;
  591. [tapCard autorelease];
  592.  
  593. return tapCard;
  594.  
  595. }
  596. - (void)unloadScrollView:(int)page withRegion:(NSString *)region{
  597. /* We only use the top frame in Mix & Match mode */
  598. NSUInteger pageWidth;
  599. NSUInteger topHeight;
  600. NSUInteger bottomHeight;;
  601.  
  602. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
  603. pageWidth = pageWidth_iPad;
  604. topHeight =topHeight_iPad;
  605. bottomHeight =bottomHeight_iPad;
  606. }
  607. else{
  608. pageWidth = pageWidth_iPhone;
  609. topHeight =topHeight_iPhone;
  610. bottomHeight =bottomHeight_iPhone;
  611. }
  612. if (page < 0) return;
  613. if (page >= pages) return;
  614.  
  615. // NSLog(@"unloading page %d for region %@", page, region);
  616. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  617. if ([region isEqualToString:@"t"]) {
  618. CardViewController *tcvc = [topCards objectAtIndex:page];
  619. if ((NSNull *)tcvc != [NSNull null]) {
  620. for (int i = 0; i < [tcvc.tapCards count]; i++) {
  621. [[tcvc.tapCards objectAtIndex:i] removeFromSuperview];
  622. }
  623. [topCards replaceObjectAtIndex:page withObject:[NSNull null]];
  624. }
  625. }
  626. else{
  627. CardViewController *bcvc = [bottomCards objectAtIndex:page];
  628. if ((NSNull *)bcvc != [NSNull null]) {
  629. for (int i = 0; i < [bcvc.tapCards count]; i++) {
  630. [[bcvc.tapCards objectAtIndex:i] removeFromSuperview];
  631. }
  632. [bottomCards replaceObjectAtIndex:page withObject:[NSNull null]];
  633. }
  634. }
  635. [pool release];
  636. }
  637.  
  638.  
  639.  
  640. - (void) resetKeys {
  641. /* We only use the top frame in Mix & Match mode */
  642.  
  643.  
  644. topCards = [[NSMutableArray alloc] initWithCapacity:pages];
  645. bottomCards = [[NSMutableArray alloc] initWithCapacity:pages];
  646. for (int i = 0; i < pages; i++) {
  647. [topCards addObject:[NSNull null]];
  648. [bottomCards addObject:[NSNull null]];
  649. }
  650. topKeys = [[NSMutableArray alloc] initWithCapacity:pages];
  651. bottomKeys = [[NSMutableArray alloc] initWithCapacity:pages];
  652. for (int i = 0; i < pages-2; i++) {
  653. [topKeys addObject:[NSString stringWithFormat:@"%d", i+1]];
  654. [bottomKeys addObject:[NSString stringWithFormat:@"%d", i+1]];
  655. }
  656.  
  657. //int b;
  658. int t;
  659. for(int i = 0; i < pages-2; i++ ) {
  660. //b=i;
  661. /*b = arc4random() % (numbers);
  662. if(b==0)
  663. {
  664. b=10;
  665. }
  666. */
  667. t = arc4random() % (pages-2);
  668. [topKeys exchangeObjectAtIndex:i withObjectAtIndex:t];
  669. //[bottomKeys exchangeObjectAtIndex:i withObjectAtIndex: b];
  670. }
  671. int b;
  672. //int t;
  673. for(int i = 0; i < pages-2; i++ ) {
  674. b=i;
  675. /*b = arc4random() % (numbers);
  676. if(b==0)
  677. {
  678. b=10;
  679. }
  680. */
  681. // t = arc4random() % (pages*numbers-2);
  682. //[topKeys exchangeObjectAtIndex:i withObjectAtIndex:t];
  683. [bottomKeys exchangeObjectAtIndex:i withObjectAtIndex: b];
  684. }
  685.  
  686. [topKeys insertObject:[topKeys objectAtIndex:pages-3] atIndex:0];
  687. [topKeys addObject:[topKeys objectAtIndex:1]];
  688. [bottomKeys insertObject:[bottomKeys objectAtIndex:pages-3] atIndex:0];
  689. [bottomKeys addObject:[bottomKeys objectAtIndex:1]];
  690. // NSLog(@" top cards: %d, top keys: %@, bottom cards: %d, bottom keys: %@", [topCards count],[topKeys objectAtIndex:0],[bottomCards count],[bottomKeys objectAtIndex:0]);
  691. }
  692.  
  693. - (void) resetPage {
  694. /* We only use the top frame in Mix & Match mode */
  695. NSUInteger topHeight;
  696.  
  697.  
  698. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
  699. topHeight =topHeight_iPad;
  700. }
  701. else{
  702. topHeight =topHeight_iPhone;
  703.  
  704. }
  705.  
  706. CGRect tFrame = cardTop.frame;
  707. tFrame.origin.x = 0;
  708. tFrame.origin.y = 0;
  709. [cardTop scrollRectToVisible:tFrame animated:NO];
  710.  
  711. CGRect bFrame = cardBottom.frame;
  712. bFrame.origin.x = 0;
  713. bFrame.origin.y = topHeight;
  714. [cardBottom scrollRectToVisible:bFrame animated:NO];
  715. }
  716.  
  717. - (void)scrollViewDidScroll:(Scroller *)sender {
  718. // We don't want a "feedback loop" between the UIPageControl and the scroll delegate in
  719. // which a scroll event generated from the user hitting the page control triggers updates from
  720. // the delegate method. We use a boolean to disable the delegate logic when the page control is used.
  721.  
  722. if (pageControlUsed) {
  723. // do nothing - the scroll was initiated from the page control, not the user dragging
  724. return;
  725. }
  726.  
  727. // Switch the indicator when more than 50% of the previous/next page is visible
  728. CGFloat pageWidth = sender.frame.size.width;
  729. int page = floor((sender.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
  730.  
  731. // load the visible page and the page on either side of it (to avoid flashes when the user starts scrolling)
  732. [self loadScrollView:page-1 withRegion:sender.region];
  733. [self loadScrollView:page withRegion:sender.region];
  734. [self loadScrollView:page+1 withRegion:sender.region];
  735.  
  736. [self unloadScrollView:page+5 withRegion:sender.region];
  737. [self unloadScrollView:page-5 withRegion:sender.region];
  738.  
  739. pageControl.currentPage = page;
  740. pageControl.region = sender.region;
  741.  
  742.  
  743. // A possible optimization would be to unload the views+controllers which are no longer visible
  744. }
  745.  
  746. // At the begin of scroll dragging, reset the boolean used when scrolls originate from the UIPageControl
  747. - (void)scrollViewWillBeginDragging:(Scroller *)scrollView {
  748.  
  749. NSLog(@"scrollViewWillBeginDragging");
  750. pageControlUsed = NO;
  751. pageControl.region = scrollView.region;
  752.  
  753. // play the swoosh as the scroll starts
  754. [self playSound:@"fca_uni_3"];
  755. // clear out any animal names
  756. if ([scrollView.region isEqualToString:@"t"]) {
  757. animalText.text = nil;
  758. centerBar.text = nil;
  759. animalTextCH1.text = nil;
  760. animalTextCH1.text = nil;
  761.  
  762. } else if ([scrollView.region isEqualToString:@"b"]){
  763. largeText.text = nil;
  764. smallText.text = nil;
  765. }
  766. }
  767.  
  768. // At the end of scroll animation, reset the boolean used when scrolls originate from the UIPageControl
  769. - (void)scrollViewDidEndDecelerating:(Scroller *)scrollView {
  770. pageControl.region = scrollView.region;
  771. pageControlUsed = NO;
  772. /* We only use the top frame in Mix & Match mode */
  773. NSUInteger pageWidth;
  774.  
  775. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
  776. pageWidth = pageWidth_iPad;
  777. }
  778. else{
  779. pageWidth = pageWidth_iPhone;
  780. }
  781. CGRect frame = scrollView.frame;
  782. // if we meet one of the end points for the scroll loop, switch back to the matching picture
  783. if (scrollView.contentOffset.x == 0) {
  784. [scrollView scrollRectToVisible:CGRectMake((pages-2)*pageWidth,0,pageWidth,frame.size.height) animated:NO];
  785. } else if (scrollView.contentOffset.x == (pages-1)*pageWidth) {
  786. [scrollView scrollRectToVisible:CGRectMake(pageWidth,0,pageWidth,frame.size.height) animated:NO];
  787. }
  788. NSString *bottomIndex = [[bottomCards objectAtIndex:[self whichPage:cardBottom.contentOffset]] cardIndex];
  789. NSString *topIndex = [[topCards objectAtIndex:[self whichPage:cardTop.contentOffset]] cardIndex];
  790. topText.text = @"Double Tap Image to Confirm a Match";
  791. UIColor *grey = [UIColor colorWithRed:0.52 green:0.52 blue:0.52 alpha:1.0];
  792. topText.textColor = grey;
  793. if([matches containsObject:topIndex]){
  794. cardTop.scrollEnabled = TRUE;
  795. }
  796. else{
  797. cardTop.scrollEnabled = FALSE;
  798. }
  799. //the top image, animal index
  800. int intIndex =[topIndex intValue]%tiles;
  801. if( intIndex==0){ intIndex=tiles;}
  802. NSString *animalIndex = [NSString stringWithFormat:@"%d", intIndex];
  803. self.myIndex = animalIndex;
  804. //the top image, animal number
  805. int intNumber =[topIndex intValue]%10;
  806. if( intNumber==0){ intNumber=10;}
  807. NSString *animalNumber = [NSString stringWithFormat:@"%d", intNumber];
  808.  
  809. // topIndex = [NSString stringWithFormat:@"%d", intIndex];
  810. int intIndex2 =[bottomIndex intValue]%10;
  811. if( intIndex2==0){ intIndex2=10;}
  812. bottomIndex = [NSString stringWithFormat:@"%d", intIndex2];
  813. NSLog(@"intIndex = %d", intIndex);
  814.  
  815. /////////////////////////// need to consider chinese
  816. if ([scrollView.region isEqualToString:@"t"])
  817. {
  818.  
  819. //single/multiple animal(s)
  820. if ([[NSUserDefaults standardUserDefaults] boolForKey:@"autoNarrate"]) {
  821. NSLog(@"animal index: %@, animal number:%@ ",animalIndex, animalNumber);
  822. if([[cardSet objectForKey:@"language"] isEqualToString:@"ch"])
  823. {
  824. centerBar.text = @"|";
  825. animalTextCH1.text = [[animalNames objectForKey:animalIndex] objectForKey:@"l"];
  826. animalTextCH2.text = [[animalNames objectForKey:animalIndex] objectForKey:@"r"];
  827. }
  828. else
  829. {
  830. animalText.text=nil;
  831. if(intNumber==1)
  832. {
  833. animalText.text = [animalNames objectForKey:animalIndex];
  834. }
  835. else
  836. {
  837. animalText.text = [animalNames objectForKey:animalIndex];
  838. }
  839. }
  840. if(intNumber==1)
  841. {
  842. // NSString *file = [NSString stringWithFormat:@"%@_1_no",[cardSet objectForKey:@"prefix"]];
  843. //[self playVoiceover:file inLanguage:[cardSet objectForKey:@"language"]];
  844. if([[cardSet objectForKey:@"language"] isEqualToString:@"en"])
  845. {
  846. [self playNarration:[cardSet objectForKey:@"prefix"] forCard:@"1" forType:@"no" inLanguage:[cardSet objectForKey:@"language"]];
  847. NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.7 target:self selector:@selector(playSingleAnimal:) userInfo:nil repeats: NO];
  848.  
  849. }
  850. else if([[cardSet objectForKey:@"language"] isEqualToString:@"es"])
  851. {
  852. [self playNarration:[cardSet objectForKey:@"prefix"] forCard:@"1" forType:@"no" inLanguage:[cardSet objectForKey:@"language"]];
  853. NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.7 target:self selector:@selector(playSingleAnimal:) userInfo:nil repeats: NO];
  854. }
  855.  
  856. else if([[cardSet objectForKey:@"language"] isEqualToString:@"fr"])
  857. {
  858.  
  859.  
  860. if(([[cardSet objectForKey:@"prefix"] isEqualToString:@"fcb"]) && (([animalIndex isEqualToString:@"2"])||([animalIndex isEqualToString:@"15"])||([animalIndex isEqualToString:@"16"])||([animalIndex isEqualToString:@"17"])))
  861. {
  862. [self playNarration:[cardSet objectForKey:@"prefix"] forCard:animalIndex forType:@"1" inLanguage:[cardSet objectForKey:@"language"]];
  863. }
  864. else
  865. {
  866. [self playNarration:[cardSet objectForKey:@"prefix"] forCard:@"1" forType:@"no" inLanguage:[cardSet objectForKey:@"language"]];
  867. NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.7 target:self selector:@selector(playSingleAnimal:) userInfo:nil repeats: NO];
  868. }
  869.  
  870. }
  871. else if([[cardSet objectForKey:@"language"] isEqualToString:@"ch"])
  872. {
  873. [self playNarration:[cardSet objectForKey:@"prefix"] forCard:animalIndex forType:@"1" inLanguage:[cardSet objectForKey:@"language"]];
  874. }
  875. }
  876. else
  877. {
  878. NSLog(@"animal index: %@, animal number:%@ ",animalIndex, animalNumber);
  879. if([[cardSet objectForKey:@"language"] isEqualToString:@"en"])
  880. {
  881. [self playNarration:[cardSet objectForKey:@"prefix"] forCard:animalNumber forType:@"no" inLanguage:[cardSet objectForKey:@"language"]];
  882. NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.7 target:self selector:@selector(playMultipleAnimal:) userInfo:nil repeats: NO];
  883.  
  884. }
  885. else if([[cardSet objectForKey:@"language"] isEqualToString:@"es"])
  886. {
  887. [self playNarration:[cardSet objectForKey:@"prefix"] forCard:animalNumber forType:@"no" inLanguage:[cardSet objectForKey:@"language"]];
  888. NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.7 target:self selector:@selector(playMultipleAnimal:) userInfo:nil repeats: NO];
  889. }
  890. else if([[cardSet objectForKey:@"language"] isEqualToString:@"fr"])
  891. {
  892. if(([[cardSet objectForKey:@"prefix"] isEqualToString:@"fcb"]) && (([animalIndex isEqualToString:@"2"])||([animalIndex isEqualToString:@"15"])||([animalIndex isEqualToString:@"16"])||([animalIndex isEqualToString:@"17"])))
  893. {
  894. [self playNarration:[cardSet objectForKey:@"prefix"] forCard:animalIndex forType:animalNumber inLanguage:[cardSet objectForKey:@"language"]];
  895. }
  896. else
  897. {
  898. [self playNarration:[cardSet objectForKey:@"prefix"] forCard:animalNumber forType:@"no" inLanguage:[cardSet objectForKey:@"language"]];
  899. NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.7 target:self selector:@selector(playMultipleAnimal:) userInfo:nil repeats: NO];
  900. }
  901. }
  902. else if([[cardSet objectForKey:@"language"] isEqualToString:@"ch"])
  903. {
  904. [self playNarration:[cardSet objectForKey:@"prefix"] forCard:animalIndex forType:animalNumber inLanguage:[cardSet objectForKey:@"language"]];
  905. }
  906. }
  907. }
  908. }
  909. else if ([scrollView.region isEqualToString:@"b"])
  910. {
  911.  
  912. largeText.text = [[numberNames objectForKey:bottomIndex] objectForKey:@"r"];
  913. smallText.text = [[numberNames objectForKey:bottomIndex] objectForKey:@"l"];
  914. if ([[NSUserDefaults standardUserDefaults] boolForKey:@"autoNarrate"]) {
  915. NSLog(@"the text for bottomIndex: %@, %@, %@",largeText.text,smallText.text, bottomIndex);
  916. if(([[cardSet objectForKey:@"language"] isEqualToString:@"es"]) || ([[cardSet objectForKey:@"language"] isEqualToString:@"fr"]))
  917. {
  918. [self playNarration:[cardSet objectForKey:@"prefix"] forCard:bottomIndex forType:@"noun" inLanguage:[cardSet objectForKey:@"language"]];
  919. }
  920. else
  921. {
  922. [self playNarration:[cardSet objectForKey:@"prefix"] forCard:bottomIndex forType:@"no" inLanguage:[cardSet objectForKey:@"language"]];
  923. }
  924. }
  925. }
  926.  
  927.  
  928.  
  929. /*
  930. // shared data for autonarrate and automatch
  931. NSString *lang = [cardSet objectForKey:@"language"];
  932. NSString *bottomIndex = [[bottomCards objectAtIndex:[self whichPage:cardBottom.contentOffset]] cardNumber];
  933. NSString *topIndex = [[topCards objectAtIndex:[self whichPage:cardTop.contentOffset]] cardNumber];
  934. NSString *index = [[topCards objectAtIndex:[self whichPage:cardTop.contentOffset]] cardIndex];
  935. NSLog(@"index:%@", index);
  936. if([matches containsObject:index]){
  937. cardTop.scrollEnabled = TRUE;
  938. }
  939. else{
  940. cardTop.scrollEnabled = FALSE;
  941. }
  942.  
  943.  
  944.  
  945.  
  946. // if autonarrate is on, speak the selected animal's name
  947. // TODO: Refactor this into a method
  948.  
  949. // NSDictionary *names = [self.cardNames objectForKey:lang];
  950. if ([scrollView.region isEqualToString:@"t"]){
  951. if([cardSet objectForKey:@"language"]==@"ch"){
  952. centerBar.text = @"|";
  953. animalTextCH1.text = [[animalNames objectForKey:topIndex] objectForKey:@"l"];
  954. animalTextCH2.text = [[animalNames objectForKey:topIndex] objectForKey:@"r"];
  955. }
  956. else{
  957. int intIndex2= [index intValue];
  958. intIndex2 = intIndex2%pages;
  959. index= [NSString stringWithFormat:@"%d",intIndex2];
  960. //animalText.text = [animalNames objectForKey:topIndex];
  961. if ([[NSUserDefaults standardUserDefaults] boolForKey:@"autoNarrate"]) {
  962. int intIndex = [topIndex intValue];
  963.  
  964. if(intIndex%10==1){
  965. NSLog(@"index: %@",topIndex);
  966. if(([cardSet objectForKey:@"language"]==@"es") || ([cardSet objectForKey:@"language"]==@"fr")){
  967. [self playNarration:[cardSet objectForKey:@"prefix"] forCard:@"1" forType:@"noun" inLanguage:[cardSet objectForKey:@"language"]];
  968. }
  969. else{
  970. [self playNarration:[cardSet objectForKey:@"prefix"] forCard:@"1" forType:@"no" inLanguage:[cardSet objectForKey:@"language"]];
  971. }
  972.  
  973. self.myIndex = index;
  974. NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.7 target:self selector:@selector(playSingleAnimal:) userInfo:nil repeats: NO];
  975. //[self playSecondNarration:[cardSet objectForKey:@"prefix"] forCard:index forType:@"sa" inLanguage:[cardSet objectForKey:@"language"] withTimer:timer];
  976. }
  977. else{
  978. intIndex = intIndex%10;
  979. if(intIndex==0)
  980. {intIndex=10;}
  981. NSString *stringIdex = [NSString stringWithFormat:@"%d", intIndex];
  982. NSLog(@"index: %@",index);
  983. if(([cardSet objectForKey:@"language"]==@"es") || ([cardSet objectForKey:@"language"]==@"fr")){
  984. [self playNarration:[cardSet objectForKey:@"prefix"] forCard:stringIdex forType:@"noun" inLanguage:[cardSet objectForKey:@"language"]];
  985. }
  986. else{
  987. [self playNarration:[cardSet objectForKey:@"prefix"] forCard:stringIdex forType:@"no" inLanguage:[cardSet objectForKey:@"language"]];
  988. }
  989. self.myIndex = index;
  990. NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.7 target:self selector:@selector(playMultipleAnimal:) userInfo:nil repeats: NO];
  991.  
  992. // [self playSecondNarration:[cardSet objectForKey:@"prefix"] forCard:index forType:@"ma" inLanguage:[cardSet objectForKey:@"language"] withTimer:timer];
  993. }
  994. }
  995. }
  996.  
  997. }
  998.  
  999.  
  1000.  
  1001. else if ([scrollView.region isEqualToString:@"b"]){
  1002. NSLog(@"autoNarrate is on");
  1003.  
  1004. largeText.text = [[numberNames objectForKey:bottomIndex] objectForKey:@"r"];
  1005. smallText.text = [[numberNames objectForKey:bottomIndex] objectForKey:@"l"];
  1006. if ([[NSUserDefaults standardUserDefaults] boolForKey:@"autoNarrate"]) {
  1007. if(([cardSet objectForKey:@"language"]==@"es") || ([cardSet objectForKey:@"language"]==@"fr")){
  1008. [self playNarration:[cardSet objectForKey:@"prefix"] forCard:bottomIndex forType:@"noun" inLanguage:lang];
  1009. }else{
  1010. [self playNarration:[cardSet objectForKey:@"prefix"] forCard:bottomIndex forType:@"no" inLanguage:lang];
  1011. }
  1012.  
  1013. }
  1014.  
  1015. }
  1016. */
  1017. // if automatch is on, show if we're now matched
  1018. //if ([[NSUserDefaults standardUserDefaults] boolForKey:@"autoMatch"]) {
  1019. // [self matchCards:topIndex otherIndex:bottomIndex];
  1020. // }
  1021. }
  1022.  
  1023. - (IBAction)changePage:(id)sender {
  1024. NSLog(@"changePage");
  1025. int page = pageControl.currentPage;
  1026.  
  1027. // load the visible page and the page on either side of it (to avoid flashes when the user starts scrolling)
  1028. // [self loadScrollView:page-1 withRegion:pageControl.region];
  1029. // [self loadScrollView:page withRegion:pageControl.region];
  1030. // [self loadScrollView:page+1 withRegion:pageControl.region];
  1031.  
  1032. Scroller *card;
  1033.  
  1034. if ([pageControl.region isEqualToString:@"t"]) {
  1035. card = cardTop;
  1036. } else {
  1037. card = cardBottom;
  1038. }
  1039.  
  1040. // update the scroll view to the appropriate page
  1041. CGRect frame = card.frame;
  1042. frame.origin.x = frame.size.width * page;
  1043. frame.origin.y = 0;
  1044. [card scrollRectToVisible:frame animated:YES];
  1045.  
  1046. // Set the boolean used when scrolls originate from the UIPageControl. See scrollViewDidScroll: above.
  1047. pageControlUsed = YES;
  1048. [card release];
  1049. }
  1050. /*********************
  1051. * BORING DELEGATE STUFF
  1052. *********************/
  1053.  
  1054. - (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag {
  1055. }
  1056.  
  1057. - (void)audioPlayerDecodeErrorDidOccur:(AVAudioPlayer *)player error:(NSError *)error {
  1058. }
  1059.  
  1060. -(BOOL)canBecomeFirstResponder {
  1061. return YES;
  1062. }
  1063.  
  1064. -(void)viewDidAppear:(BOOL)animated {
  1065. [self becomeFirstResponder];
  1066. // largeText.delegate=self;
  1067. // smallText.delegate=self;
  1068. //[self showAlert];
  1069. }
  1070.  
  1071.  
  1072.  
  1073. - (void)settingsViewControllerDidFinish:(SettingsViewController *)controller{
  1074. [self dismissModalViewControllerAnimated:YES];
  1075. }
  1076.  
  1077.  
  1078. - (void)didReceiveMemoryWarning {
  1079. // Releases the view if it doesn't have a superview.
  1080. [super didReceiveMemoryWarning];
  1081.  
  1082. // Release any cached data, images, etc. that aren't in use.
  1083. }
  1084.  
  1085.  
  1086. - (void)viewDidUnload {
  1087. [super viewDidUnload];
  1088. //largeText.delegate=self;
  1089. // smallText.delegate=self;
  1090. // Release any retained subviews of the main view.
  1091. // e.g. self.myOutlet = nil;
  1092. }
  1093.  
  1094. - (void)dealloc {
  1095. [super dealloc];
  1096.  
  1097. [animalNames release];
  1098. [animalText release];
  1099. [animalTextCH1 release];
  1100. [animalTextCH2 release];
  1101. [bottomCards release];
  1102. [bottomKeys release];
  1103. [cardBottom release];
  1104. [cardSet release];
  1105. [cardTop release];
  1106. [centerBar release];
  1107. [home release];
  1108. [largeText release];
  1109. [narrationTimer release];
  1110. [numberNames release];
  1111. [smallText release];
  1112. [topCards release];
  1113. [topKeys release];
  1114.  
  1115. }
  1116.  
  1117. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement