author | nemo |
Sun, 20 Jun 2010 22:35:10 -0400 | |
changeset 3526 | a1d2180fef42 |
parent 3514 | 59dbd31e9953 |
child 3522 | 156c04c6a3d8 |
permissions | -rw-r--r-- |
3339 | 1 |
// |
3352 | 2 |
// VoicesViewController.m |
3339 | 3 |
// HedgewarsMobile |
4 |
// |
|
5 |
// Created by Vittorio on 02/04/10. |
|
6 |
// Copyright 2010 __MyCompanyName__. All rights reserved. |
|
7 |
// |
|
8 |
||
3340 | 9 |
#import "VoicesViewController.h" |
3339 | 10 |
#import "CommodityFunctions.h" |
3353
a767dd3786b5
OpenAL makes a comeback! (might require some cleanup)
koda
parents:
3352
diff
changeset
|
11 |
#import "openalbridge.h" |
3339 | 12 |
|
13 |
||
14 |
@implementation VoicesViewController |
|
3340 | 15 |
@synthesize teamDictionary, voiceArray, lastIndexPath; |
3339 | 16 |
|
17 |
||
18 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
|
19 |
return rotationManager(interfaceOrientation); |
|
20 |
} |
|
21 |
||
22 |
||
23 |
#pragma mark - |
|
24 |
#pragma mark View lifecycle |
|
25 |
- (void)viewDidLoad { |
|
26 |
[super viewDidLoad]; |
|
27 |
srandom(time(NULL)); |
|
28 |
||
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
29 |
openal_init(20); |
3339 | 30 |
} |
31 |
||
32 |
- (void)viewWillAppear:(BOOL)animated { |
|
33 |
[super viewWillAppear:animated]; |
|
34 |
||
35 |
// this moves the tableview to the top |
|
36 |
[self.tableView setContentOffset:CGPointMake(0,0) animated:NO]; |
|
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
37 |
voiceBeingPlayed = -1; |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
38 |
|
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
39 |
// load all the voices names and store them into voiceArray |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
40 |
NSArray *array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:VOICES_DIRECTORY() error:NULL]; |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
41 |
self.voiceArray = array; |
3339 | 42 |
} |
43 |
||
44 |
/* |
|
45 |
- (void)viewDidAppear:(BOOL)animated { |
|
46 |
[super viewDidAppear:animated]; |
|
47 |
} |
|
48 |
*/ |
|
49 |
||
50 |
- (void)viewWillDisappear:(BOOL)animated { |
|
51 |
[super viewWillDisappear:animated]; |
|
3353
a767dd3786b5
OpenAL makes a comeback! (might require some cleanup)
koda
parents:
3352
diff
changeset
|
52 |
if(voiceBeingPlayed >= 0) { |
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
53 |
openal_stopsound(voiceBeingPlayed); |
3353
a767dd3786b5
OpenAL makes a comeback! (might require some cleanup)
koda
parents:
3352
diff
changeset
|
54 |
voiceBeingPlayed = -1; |
3339 | 55 |
} |
56 |
} |
|
57 |
||
58 |
||
59 |
#pragma mark - |
|
60 |
#pragma mark Table view data source |
|
61 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
62 |
return 1; |
|
63 |
} |
|
64 |
||
65 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
66 |
return [self.voiceArray count]; |
|
67 |
} |
|
68 |
||
69 |
// Customize the appearance of table view cells. |
|
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
70 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
3339 | 71 |
|
72 |
static NSString *CellIdentifier = @"Cell"; |
|
73 |
||
74 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
|
75 |
if (cell == nil) { |
|
76 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
|
77 |
} |
|
78 |
||
79 |
NSString *voice = [[voiceArray objectAtIndex:[indexPath row]] stringByDeletingPathExtension]; |
|
80 |
cell.textLabel.text = voice; |
|
81 |
||
82 |
if ([voice isEqualToString:[teamDictionary objectForKey:@"voicepack"]]) { |
|
83 |
cell.accessoryType = UITableViewCellAccessoryCheckmark; |
|
84 |
self.lastIndexPath = indexPath; |
|
85 |
} else { |
|
86 |
cell.accessoryType = UITableViewCellAccessoryNone; |
|
87 |
} |
|
88 |
||
89 |
return cell; |
|
90 |
} |
|
91 |
||
92 |
||
93 |
#pragma mark - |
|
94 |
#pragma mark Table view delegate |
|
3340 | 95 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
3339 | 96 |
int newRow = [indexPath row]; |
97 |
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
|
98 |
||
99 |
if (newRow != oldRow) { |
|
3340 | 100 |
[teamDictionary setObject:[voiceArray objectAtIndex:newRow] forKey:@"voicepack"]; |
3339 | 101 |
|
102 |
// tell our boss to write this new stuff on disk |
|
103 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil]; |
|
104 |
[self.tableView reloadData]; |
|
105 |
||
106 |
self.lastIndexPath = indexPath; |
|
107 |
[self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
|
108 |
} |
|
109 |
[self.tableView deselectRowAtIndexPath:indexPath animated:YES]; |
|
3340 | 110 |
|
3353
a767dd3786b5
OpenAL makes a comeback! (might require some cleanup)
koda
parents:
3352
diff
changeset
|
111 |
if (voiceBeingPlayed >= 0) { |
a767dd3786b5
OpenAL makes a comeback! (might require some cleanup)
koda
parents:
3352
diff
changeset
|
112 |
openal_stopsound(voiceBeingPlayed); |
a767dd3786b5
OpenAL makes a comeback! (might require some cleanup)
koda
parents:
3352
diff
changeset
|
113 |
voiceBeingPlayed = -1; |
3339 | 114 |
} |
3340 | 115 |
|
3339 | 116 |
// the keyword static prevents re-initialization of the variable |
3340 | 117 |
NSString *voiceDir = [[NSString alloc] initWithFormat:@"%@/%@/",VOICES_DIRECTORY(),[voiceArray objectAtIndex:newRow]]; |
3339 | 118 |
NSArray *array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:voiceDir error:NULL]; |
3340 | 119 |
|
3339 | 120 |
int index = random() % [array count]; |
121 |
||
3353
a767dd3786b5
OpenAL makes a comeback! (might require some cleanup)
koda
parents:
3352
diff
changeset
|
122 |
voiceBeingPlayed = openal_loadfile([[voiceDir stringByAppendingString:[array objectAtIndex:index]] UTF8String]); |
3339 | 123 |
[voiceDir release]; |
3353
a767dd3786b5
OpenAL makes a comeback! (might require some cleanup)
koda
parents:
3352
diff
changeset
|
124 |
openal_playsound(voiceBeingPlayed); |
3339 | 125 |
} |
126 |
||
127 |
||
128 |
#pragma mark - |
|
129 |
#pragma mark Memory management |
|
3490 | 130 |
-(void) didReceiveMemoryWarning { |
3339 | 131 |
// Releases the view if it doesn't have a superview. |
132 |
[super didReceiveMemoryWarning]; |
|
133 |
// Relinquish ownership any cached data, images, etc that aren't in use. |
|
134 |
} |
|
135 |
||
3490 | 136 |
-(void) viewDidUnload { |
3353
a767dd3786b5
OpenAL makes a comeback! (might require some cleanup)
koda
parents:
3352
diff
changeset
|
137 |
openal_close(); |
a767dd3786b5
OpenAL makes a comeback! (might require some cleanup)
koda
parents:
3352
diff
changeset
|
138 |
voiceBeingPlayed = -1; |
3339 | 139 |
self.lastIndexPath = nil; |
140 |
self.teamDictionary = nil; |
|
141 |
self.voiceArray = nil; |
|
3490 | 142 |
[super viewDidUnload]; |
143 |
MSG_DIDUNLOAD(); |
|
3339 | 144 |
} |
145 |
||
3490 | 146 |
-(void) dealloc { |
3339 | 147 |
[voiceArray release]; |
148 |
[teamDictionary release]; |
|
149 |
[lastIndexPath release]; |
|
150 |
[super dealloc]; |
|
151 |
} |
|
152 |
||
153 |
||
154 |
@end |
|
155 |