author | koda |
Sun, 20 Jun 2010 18:35:59 +0200 | |
changeset 3523 | 6592fbb969da |
parent 3522 | 156c04c6a3d8 |
child 3532 | 04e2fea3e83a |
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); |
3522
156c04c6a3d8
add initial stubs for selecting weapons in the ifrontend
koda
parents:
3514
diff
changeset
|
30 |
voiceBeingPlayed = -1; |
156c04c6a3d8
add initial stubs for selecting weapons in the ifrontend
koda
parents:
3514
diff
changeset
|
31 |
|
156c04c6a3d8
add initial stubs for selecting weapons in the ifrontend
koda
parents:
3514
diff
changeset
|
32 |
// load all the voices names and store them into voiceArray |
156c04c6a3d8
add initial stubs for selecting weapons in the ifrontend
koda
parents:
3514
diff
changeset
|
33 |
// it's here and not in viewWillAppear because user cannot add/remove them |
156c04c6a3d8
add initial stubs for selecting weapons in the ifrontend
koda
parents:
3514
diff
changeset
|
34 |
NSArray *array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:VOICES_DIRECTORY() error:NULL]; |
156c04c6a3d8
add initial stubs for selecting weapons in the ifrontend
koda
parents:
3514
diff
changeset
|
35 |
self.voiceArray = array; |
3339 | 36 |
} |
37 |
||
38 |
- (void)viewWillAppear:(BOOL)animated { |
|
39 |
[super viewWillAppear:animated]; |
|
40 |
||
41 |
// this moves the tableview to the top |
|
42 |
[self.tableView setContentOffset:CGPointMake(0,0) animated:NO]; |
|
43 |
} |
|
44 |
||
3522
156c04c6a3d8
add initial stubs for selecting weapons in the ifrontend
koda
parents:
3514
diff
changeset
|
45 |
-(void) viewWillDisappear:(BOOL)animated { |
3339 | 46 |
[super viewWillDisappear:animated]; |
3353
a767dd3786b5
OpenAL makes a comeback! (might require some cleanup)
koda
parents:
3352
diff
changeset
|
47 |
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
|
48 |
openal_stopsound(voiceBeingPlayed); |
3353
a767dd3786b5
OpenAL makes a comeback! (might require some cleanup)
koda
parents:
3352
diff
changeset
|
49 |
voiceBeingPlayed = -1; |
3339 | 50 |
} |
51 |
} |
|
52 |
||
53 |
||
54 |
#pragma mark - |
|
55 |
#pragma mark Table view data source |
|
56 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
57 |
return 1; |
|
58 |
} |
|
59 |
||
60 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
61 |
return [self.voiceArray count]; |
|
62 |
} |
|
63 |
||
64 |
// 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
|
65 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
3339 | 66 |
|
67 |
static NSString *CellIdentifier = @"Cell"; |
|
68 |
||
69 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
|
70 |
if (cell == nil) { |
|
71 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
|
72 |
} |
|
73 |
||
74 |
NSString *voice = [[voiceArray objectAtIndex:[indexPath row]] stringByDeletingPathExtension]; |
|
75 |
cell.textLabel.text = voice; |
|
76 |
||
77 |
if ([voice isEqualToString:[teamDictionary objectForKey:@"voicepack"]]) { |
|
78 |
cell.accessoryType = UITableViewCellAccessoryCheckmark; |
|
79 |
self.lastIndexPath = indexPath; |
|
80 |
} else { |
|
81 |
cell.accessoryType = UITableViewCellAccessoryNone; |
|
82 |
} |
|
83 |
||
84 |
return cell; |
|
85 |
} |
|
86 |
||
87 |
||
88 |
#pragma mark - |
|
89 |
#pragma mark Table view delegate |
|
3340 | 90 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
3339 | 91 |
int newRow = [indexPath row]; |
92 |
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
|
93 |
||
94 |
if (newRow != oldRow) { |
|
3340 | 95 |
[teamDictionary setObject:[voiceArray objectAtIndex:newRow] forKey:@"voicepack"]; |
3339 | 96 |
|
97 |
// tell our boss to write this new stuff on disk |
|
98 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil]; |
|
99 |
[self.tableView reloadData]; |
|
100 |
||
101 |
self.lastIndexPath = indexPath; |
|
102 |
[self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
|
103 |
} |
|
104 |
[self.tableView deselectRowAtIndexPath:indexPath animated:YES]; |
|
3340 | 105 |
|
3353
a767dd3786b5
OpenAL makes a comeback! (might require some cleanup)
koda
parents:
3352
diff
changeset
|
106 |
if (voiceBeingPlayed >= 0) { |
a767dd3786b5
OpenAL makes a comeback! (might require some cleanup)
koda
parents:
3352
diff
changeset
|
107 |
openal_stopsound(voiceBeingPlayed); |
a767dd3786b5
OpenAL makes a comeback! (might require some cleanup)
koda
parents:
3352
diff
changeset
|
108 |
voiceBeingPlayed = -1; |
3339 | 109 |
} |
3340 | 110 |
|
3339 | 111 |
// the keyword static prevents re-initialization of the variable |
3340 | 112 |
NSString *voiceDir = [[NSString alloc] initWithFormat:@"%@/%@/",VOICES_DIRECTORY(),[voiceArray objectAtIndex:newRow]]; |
3339 | 113 |
NSArray *array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:voiceDir error:NULL]; |
3340 | 114 |
|
3339 | 115 |
int index = random() % [array count]; |
116 |
||
3353
a767dd3786b5
OpenAL makes a comeback! (might require some cleanup)
koda
parents:
3352
diff
changeset
|
117 |
voiceBeingPlayed = openal_loadfile([[voiceDir stringByAppendingString:[array objectAtIndex:index]] UTF8String]); |
3339 | 118 |
[voiceDir release]; |
3353
a767dd3786b5
OpenAL makes a comeback! (might require some cleanup)
koda
parents:
3352
diff
changeset
|
119 |
openal_playsound(voiceBeingPlayed); |
3339 | 120 |
} |
121 |
||
122 |
||
123 |
#pragma mark - |
|
124 |
#pragma mark Memory management |
|
3490 | 125 |
-(void) didReceiveMemoryWarning { |
3339 | 126 |
// Releases the view if it doesn't have a superview. |
127 |
[super didReceiveMemoryWarning]; |
|
128 |
// Relinquish ownership any cached data, images, etc that aren't in use. |
|
129 |
} |
|
130 |
||
3490 | 131 |
-(void) viewDidUnload { |
3353
a767dd3786b5
OpenAL makes a comeback! (might require some cleanup)
koda
parents:
3352
diff
changeset
|
132 |
openal_close(); |
a767dd3786b5
OpenAL makes a comeback! (might require some cleanup)
koda
parents:
3352
diff
changeset
|
133 |
voiceBeingPlayed = -1; |
3339 | 134 |
self.lastIndexPath = nil; |
135 |
self.teamDictionary = nil; |
|
136 |
self.voiceArray = nil; |
|
3490 | 137 |
[super viewDidUnload]; |
138 |
MSG_DIDUNLOAD(); |
|
3339 | 139 |
} |
140 |
||
3490 | 141 |
-(void) dealloc { |
3339 | 142 |
[voiceArray release]; |
143 |
[teamDictionary release]; |
|
144 |
[lastIndexPath release]; |
|
145 |
[super dealloc]; |
|
146 |
} |
|
147 |
||
148 |
||
149 |
@end |
|
150 |