author | Grigory Ustinov <grenka@altlinux.org> |
Wed, 25 Sep 2019 21:03:59 +0300 | |
changeset 15418 | 36c263a6141d |
parent 13166 | ba5c794adae3 |
permissions | -rw-r--r-- |
3829 | 1 |
/* |
2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices |
|
6700 | 3 |
* Copyright (c) 2009-2012 Vittorio Giovara <vittorio.giovara@gmail.com> |
3829 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
8441
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3829 | 17 |
*/ |
18 |
||
3547 | 19 |
|
20 |
#import "SingleSchemeViewController.h" |
|
21 |
#import <QuartzCore/QuartzCore.h> |
|
6078
8c0cc07731e5
headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
5982
diff
changeset
|
22 |
|
3547 | 23 |
|
3573 | 24 |
#define LABEL_TAG 12345 |
25 |
#define SLIDER_TAG 54321 |
|
3781
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3753
diff
changeset
|
26 |
#define SWITCH_TAG 67890 |
3573 | 27 |
|
4211
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
28 |
|
3547 | 29 |
@implementation SingleSchemeViewController |
3781
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3753
diff
changeset
|
30 |
@synthesize schemeName, schemeDictionary, basicSettingList, gameModifierArray; |
3547 | 31 |
|
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11292
diff
changeset
|
32 |
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
3547 | 33 |
return rotationManager(interfaceOrientation); |
34 |
} |
|
35 |
||
36 |
#pragma mark - |
|
37 |
#pragma mark View lifecycle |
|
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11292
diff
changeset
|
38 |
- (void)viewDidLoad { |
3547 | 39 |
[super viewDidLoad]; |
40 |
||
3753 | 41 |
// title, description, image name (+btn) |
5185
7607a64e1853
remove the trailing _en from scheme data and use the macros available instead of creating a string every time
koda
parents:
5181
diff
changeset
|
42 |
NSArray *mods = [[NSArray alloc] initWithContentsOfFile:GAMEMODS_FILE()]; |
3547 | 43 |
self.gameModifierArray = mods; |
3697 | 44 |
|
3753 | 45 |
// title, image name (+icon), default value, max value, min value |
5185
7607a64e1853
remove the trailing _en from scheme data and use the macros available instead of creating a string every time
koda
parents:
5181
diff
changeset
|
46 |
NSArray *basicSettings = [[NSArray alloc] initWithContentsOfFile:BASICFLAGS_FILE()]; |
3547 | 47 |
self.basicSettingList = basicSettings; |
3697 | 48 |
|
3659 | 49 |
self.title = NSLocalizedString(@"Edit scheme preferences",@""); |
3547 | 50 |
} |
51 |
||
52 |
// load from file |
|
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11292
diff
changeset
|
53 |
- (void)viewWillAppear:(BOOL) animated { |
3547 | 54 |
[super viewWillAppear:animated]; |
3697 | 55 |
|
3659 | 56 |
NSString *schemeFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.schemeName]; |
3781
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3753
diff
changeset
|
57 |
NSMutableDictionary *scheme = [[NSMutableDictionary alloc] initWithContentsOfFile:schemeFile]; |
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3753
diff
changeset
|
58 |
self.schemeDictionary = scheme; |
3697 | 59 |
|
3547 | 60 |
[self.tableView reloadData]; |
61 |
} |
|
62 |
||
63 |
// save to file |
|
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11292
diff
changeset
|
64 |
- (void)viewWillDisappear:(BOOL) animated { |
3547 | 65 |
[super viewWillDisappear:animated]; |
3697 | 66 |
|
3659 | 67 |
NSString *schemeFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.schemeName]; |
3781
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3753
diff
changeset
|
68 |
[self.schemeDictionary writeToFile:schemeFile atomically:YES]; |
3547 | 69 |
} |
70 |
||
6672
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
71 |
// force a redraw of the game mod section to reposition the slider |
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11292
diff
changeset
|
72 |
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { |
6672
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
73 |
if (IS_IPAD() == NO) |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
74 |
return; |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
75 |
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationFade]; |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
76 |
} |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
77 |
|
3547 | 78 |
#pragma mark - |
3659 | 79 |
#pragma mark editableCellView delegate |
3547 | 80 |
// set the new value |
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11292
diff
changeset
|
81 |
- (void)saveTextFieldValue:(NSString *)textString withTag:(NSInteger)tagValue { |
3782 | 82 |
if (tagValue == 0) { |
83 |
// delete old file |
|
84 |
[[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.schemeName] error:NULL]; |
|
85 |
// update filename |
|
86 |
self.schemeName = textString; |
|
87 |
// save new file |
|
88 |
[self.schemeDictionary writeToFile:[NSString stringWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.schemeName] atomically:YES]; |
|
89 |
} else { |
|
90 |
[self.schemeDictionary setObject:textString forKey:@"description"]; |
|
91 |
} |
|
3547 | 92 |
} |
93 |
||
94 |
#pragma mark - |
|
95 |
#pragma mark Table view data source |
|
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11292
diff
changeset
|
96 |
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { |
3547 | 97 |
return 3; |
98 |
} |
|
99 |
||
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11292
diff
changeset
|
100 |
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
3547 | 101 |
switch (section) { |
102 |
case 0: |
|
3782 | 103 |
return 2; |
3547 | 104 |
break; |
105 |
case 1: |
|
4000
ddc4a09889e7
engine: reorder GameFlags and update files, frontend and other stuff
koda
parents:
3996
diff
changeset
|
106 |
return [[self.schemeDictionary objectForKey:@"basic"] count]; |
3547 | 107 |
break; |
108 |
case 2: |
|
4000
ddc4a09889e7
engine: reorder GameFlags and update files, frontend and other stuff
koda
parents:
3996
diff
changeset
|
109 |
return [[self.schemeDictionary objectForKey:@"gamemod"] count]; |
3547 | 110 |
default: |
111 |
break; |
|
112 |
} |
|
113 |
return 0; |
|
114 |
} |
|
115 |
||
3573 | 116 |
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
3547 | 117 |
static NSString *CellIdentifier0 = @"Cell0"; |
118 |
static NSString *CellIdentifier1 = @"Cell1"; |
|
119 |
static NSString *CellIdentifier2 = @"Cell2"; |
|
3697 | 120 |
|
3547 | 121 |
UITableViewCell *cell = nil; |
3659 | 122 |
EditableCellView *editableCell = nil; |
3547 | 123 |
NSInteger row = [indexPath row]; |
3697 | 124 |
|
3547 | 125 |
switch ([indexPath section]) { |
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11292
diff
changeset
|
126 |
case 0: { |
3659 | 127 |
editableCell = (EditableCellView *)[aTableView dequeueReusableCellWithIdentifier:CellIdentifier0]; |
128 |
if (editableCell == nil) { |
|
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11292
diff
changeset
|
129 |
editableCell = [[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault |
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11292
diff
changeset
|
130 |
reuseIdentifier:CellIdentifier0]; |
3659 | 131 |
editableCell.delegate = self; |
3547 | 132 |
} |
3782 | 133 |
editableCell.tag = row; |
134 |
editableCell.selectionStyle = UITableViewCellSelectionStyleNone; |
|
135 |
editableCell.imageView.image = nil; |
|
3659 | 136 |
editableCell.detailTextLabel.text = nil; |
8441 | 137 |
|
3782 | 138 |
if (row == 0) { |
139 |
editableCell.textField.text = self.schemeName; |
|
4284
57a501a69e5f
update iFrontend with new schemes and weaps, fix up smaller glitches
koda
parents:
4213
diff
changeset
|
140 |
editableCell.textField.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; |
3782 | 141 |
} else { |
3825 | 142 |
editableCell.minimumCharacters = 0; |
3782 | 143 |
editableCell.textField.font = [UIFont systemFontOfSize:[UIFont labelFontSize]]; |
144 |
editableCell.textField.text = [self.schemeDictionary objectForKey:@"description"]; |
|
145 |
editableCell.textField.placeholder = NSLocalizedString(@"You can add a description if you wish",@""); |
|
146 |
} |
|
3659 | 147 |
cell = editableCell; |
3547 | 148 |
break; |
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11292
diff
changeset
|
149 |
} |
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11292
diff
changeset
|
150 |
case 1: { |
3573 | 151 |
cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier1]; |
152 |
NSDictionary *detail = [self.basicSettingList objectAtIndex:row]; |
|
153 |
// need to offset this section (see format in CommodityFunctions.m and above) |
|
3547 | 154 |
if (cell == nil) { |
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11292
diff
changeset
|
155 |
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 |
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11292
diff
changeset
|
156 |
reuseIdentifier:CellIdentifier1]; |
3697 | 157 |
|
6672
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
158 |
UISlider *slider = [[UISlider alloc] init]; |
3573 | 159 |
[slider addTarget:self action:@selector(sliderChanged:) forControlEvents:UIControlEventValueChanged]; |
160 |
[cell.contentView addSubview:slider]; |
|
3697 | 161 |
|
3573 | 162 |
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 7, 200, 30)]; |
163 |
label.tag = LABEL_TAG; |
|
164 |
label.backgroundColor = [UIColor clearColor]; |
|
165 |
label.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; |
|
166 |
[cell.contentView addSubview:label]; |
|
3547 | 167 |
} |
3697 | 168 |
|
5982
283be2ca54a7
mad several updates to the resource copying phase in the ios project file, changed paths of some images and added some smaller forts version
koda
parents:
5208
diff
changeset
|
169 |
UIImage *img = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/icon%@.png",ICONS_DIRECTORY(), |
283be2ca54a7
mad several updates to the resource copying phase in the ios project file, changed paths of some images and added some smaller forts version
koda
parents:
5208
diff
changeset
|
170 |
[[self.basicSettingList objectAtIndex:row] objectForKey:@"image"]]]; |
3623 | 171 |
cell.imageView.image = img; |
3697 | 172 |
|
3573 | 173 |
UILabel *cellLabel = (UILabel *)[cell.contentView viewWithTag:LABEL_TAG]; |
11131
29d0a5c04b3b
- Localization for SingleSchemeViewController fixed
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
174 |
NSString *basicSettingTitleKey = [[self.basicSettingList objectAtIndex:row] objectForKey:@"title"]; |
29d0a5c04b3b
- Localization for SingleSchemeViewController fixed
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
175 |
cellLabel.text = NSLocalizedStringFromTable(basicSettingTitleKey, @"Scheme", nil); |
5181 | 176 |
cellLabel.adjustsFontSizeToFitWidth = YES; |
3697 | 177 |
|
3916
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
178 |
// can't use the viewWithTag method because row is dynamic |
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
179 |
UISlider *cellSlider = nil; |
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
180 |
for (UIView *oneView in cell.contentView.subviews) { |
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
181 |
if ([oneView isMemberOfClass:[UISlider class]]) { |
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
182 |
cellSlider = (UISlider *)oneView; |
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
183 |
break; |
8441 | 184 |
} |
3916
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
185 |
} |
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
186 |
cellSlider.tag = SLIDER_TAG + row; |
4211
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
187 |
cellSlider.maximumValue = [[detail objectForKey:@"max"] floatValue]; |
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
188 |
cellSlider.minimumValue = [[detail objectForKey:@"min"] floatValue]; |
3781
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3753
diff
changeset
|
189 |
cellSlider.value = [[[self.schemeDictionary objectForKey:@"basic"] objectAtIndex:row] floatValue]; |
6672
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
190 |
// redraw the slider here |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
191 |
NSInteger hOffset = 260; |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
192 |
NSInteger vOffset = 12; |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
193 |
NSInteger sliderLength = 150; |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
194 |
if (IS_IPAD()) { |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
195 |
hOffset = 310; |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
196 |
sliderLength = 230; |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
197 |
if (IS_ON_PORTRAIT()) { |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
198 |
hOffset = 50; |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
199 |
vOffset = 40; |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
200 |
sliderLength = 285; |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
201 |
} |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
202 |
} |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
203 |
cellSlider.frame = CGRectMake(hOffset, vOffset, sliderLength, 23); |
3697 | 204 |
|
11291
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11279
diff
changeset
|
205 |
NSString *prestring = [self localizedValueStringForKey:basicSettingTitleKey andSlider:cellSlider]; |
4211
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
206 |
|
4210
caa9b08990eb
revert 4200:dd54999c2822 - it was breaking schemes. koda. just leave this alone until next release
nemo
parents:
4208
diff
changeset
|
207 |
// forced to use this weird format otherwise the label disappears when size of the text is bigger than the original |
3574 | 208 |
while ([prestring length] <= 4) |
209 |
prestring = [NSString stringWithFormat:@" %@",prestring]; |
|
210 |
cell.detailTextLabel.text = prestring; |
|
3697 | 211 |
|
3574 | 212 |
cell.selectionStyle = UITableViewCellSelectionStyleBlue; |
3547 | 213 |
break; |
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11292
diff
changeset
|
214 |
} |
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11292
diff
changeset
|
215 |
case 2: { |
3573 | 216 |
cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier2]; |
3547 | 217 |
if (cell == nil) { |
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11292
diff
changeset
|
218 |
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle |
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11292
diff
changeset
|
219 |
reuseIdentifier:CellIdentifier2]; |
3547 | 220 |
UISwitch *onOff = [[UISwitch alloc] init]; |
221 |
[onOff addTarget:self action:@selector(toggleSwitch:) forControlEvents:UIControlEventValueChanged]; |
|
222 |
cell.accessoryView = onOff; |
|
223 |
} |
|
3697 | 224 |
|
4000
ddc4a09889e7
engine: reorder GameFlags and update files, frontend and other stuff
koda
parents:
3996
diff
changeset
|
225 |
UISwitch *switcher = (UISwitch *)cell.accessoryView; |
ddc4a09889e7
engine: reorder GameFlags and update files, frontend and other stuff
koda
parents:
3996
diff
changeset
|
226 |
switcher.tag = SWITCH_TAG + row; |
ddc4a09889e7
engine: reorder GameFlags and update files, frontend and other stuff
koda
parents:
3996
diff
changeset
|
227 |
[switcher setOn:[[[self.schemeDictionary objectForKey:@"gamemod"] objectAtIndex:row] boolValue] animated:NO]; |
8441 | 228 |
|
5982
283be2ca54a7
mad several updates to the resource copying phase in the ios project file, changed paths of some images and added some smaller forts version
koda
parents:
5208
diff
changeset
|
229 |
UIImage *image = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/btn%@.png",ICONS_DIRECTORY(), |
283be2ca54a7
mad several updates to the resource copying phase in the ios project file, changed paths of some images and added some smaller forts version
koda
parents:
5208
diff
changeset
|
230 |
[[self.gameModifierArray objectAtIndex:row] objectForKey:@"image"]]]; |
3547 | 231 |
cell.imageView.image = image; |
6095 | 232 |
cell.imageView.layer.cornerRadius = 6.0f; |
233 |
cell.imageView.layer.masksToBounds = YES; |
|
11131
29d0a5c04b3b
- Localization for SingleSchemeViewController fixed
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
234 |
NSString *gameModTitleKey = [[self.gameModifierArray objectAtIndex:row] objectForKey:@"title"]; |
29d0a5c04b3b
- Localization for SingleSchemeViewController fixed
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
235 |
cell.textLabel.text = NSLocalizedStringFromTable(gameModTitleKey, @"Scheme", nil); |
29d0a5c04b3b
- Localization for SingleSchemeViewController fixed
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
236 |
NSString *gameModDescKey = [[self.gameModifierArray objectAtIndex:row] objectForKey:@"description"]; |
29d0a5c04b3b
- Localization for SingleSchemeViewController fixed
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
237 |
cell.detailTextLabel.text = NSLocalizedStringFromTable(gameModDescKey, @"Scheme", nil); |
4000
ddc4a09889e7
engine: reorder GameFlags and update files, frontend and other stuff
koda
parents:
3996
diff
changeset
|
238 |
cell.detailTextLabel.adjustsFontSizeToFitWidth = YES; |
ddc4a09889e7
engine: reorder GameFlags and update files, frontend and other stuff
koda
parents:
3996
diff
changeset
|
239 |
cell.detailTextLabel.minimumFontSize = 6; |
3697 | 240 |
|
3574 | 241 |
cell.selectionStyle = UITableViewCellSelectionStyleNone; |
3547 | 242 |
} |
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11292
diff
changeset
|
243 |
} |
3697 | 244 |
|
3547 | 245 |
return cell; |
246 |
} |
|
247 |
||
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11292
diff
changeset
|
248 |
- (void)toggleSwitch:(id)sender { |
3547 | 249 |
UISwitch *theSwitch = (UISwitch *)sender; |
3781
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3753
diff
changeset
|
250 |
NSMutableArray *array = [self.schemeDictionary objectForKey:@"gamemod"]; |
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3753
diff
changeset
|
251 |
[array replaceObjectAtIndex:theSwitch.tag-SWITCH_TAG withObject:[NSNumber numberWithBool:theSwitch.on]]; |
3547 | 252 |
} |
253 |
||
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11292
diff
changeset
|
254 |
- (void)sliderChanged:(id)sender { |
3573 | 255 |
// the slider that changed is sent as object |
256 |
UISlider *theSlider = (UISlider *)sender; |
|
257 |
// create the indexPath of the row of the slider |
|
3781
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3753
diff
changeset
|
258 |
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:theSlider.tag-SLIDER_TAG inSection:1]; |
3573 | 259 |
// get its cell |
260 |
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath]; |
|
4211
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
261 |
// grab the associated labels |
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
262 |
UILabel *detailLabel = (UILabel *)cell.detailTextLabel; |
3573 | 263 |
// modify it |
4211
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
264 |
|
11279
c0d6f6ffa798
- Fix for localization of game settings detailLabel in SingleSchemeViewController
antonc27 <antonc27@mail.ru>
parents:
11148
diff
changeset
|
265 |
NSString *basicSettingTitleKey = [[self.basicSettingList objectAtIndex:[indexPath row]] objectForKey:@"title"]; |
11291
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11279
diff
changeset
|
266 |
detailLabel.text = [self localizedValueStringForKey:basicSettingTitleKey andSlider:theSlider]; |
4211
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
267 |
|
3781
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3753
diff
changeset
|
268 |
// save changes in the main array |
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3753
diff
changeset
|
269 |
NSMutableArray *array = [self.schemeDictionary objectForKey:@"basic"]; |
11148
064a53861759
- Refactoring in order to remove some warning related to using of int instead of NSInteger
antonc27 <antonc27@mail.ru>
parents:
11131
diff
changeset
|
270 |
[array replaceObjectAtIndex:theSlider.tag-SLIDER_TAG withObject:[NSNumber numberWithInteger:theSlider.value]]; |
3573 | 271 |
} |
3547 | 272 |
|
273 |
#pragma mark - |
|
274 |
#pragma mark Table view delegate |
|
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11292
diff
changeset
|
275 |
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
3573 | 276 |
UITableViewCell *cell = [aTableView cellForRowAtIndexPath:indexPath]; |
3659 | 277 |
EditableCellView *editableCell = nil; |
3573 | 278 |
UISlider *cellSlider = nil; |
3697 | 279 |
|
3573 | 280 |
switch ([indexPath section]) { |
281 |
case 0: |
|
3659 | 282 |
editableCell = (EditableCellView *)cell; |
283 |
[editableCell replyKeyboard]; |
|
3573 | 284 |
break; |
285 |
case 1: |
|
3781
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3753
diff
changeset
|
286 |
cellSlider = (UISlider *)[cell.contentView viewWithTag:[indexPath row]+SLIDER_TAG]; |
3573 | 287 |
[cellSlider setValue:[[[self.basicSettingList objectAtIndex:[indexPath row]] objectForKey:@"default"] floatValue] animated:YES]; |
288 |
[self sliderChanged:cellSlider]; |
|
289 |
//cell.detailTextLabel.text = [[[self.basicSettingList objectAtIndex:[indexPath row]] objectForKey:@"default"] stringValue]; |
|
290 |
break; |
|
291 |
case 2: |
|
3574 | 292 |
/*sw = (UISwitch *)cell.accessoryView; |
3573 | 293 |
[sw setOn:!sw.on animated:YES]; |
3574 | 294 |
[self toggleSwitch:sw];*/ |
3573 | 295 |
break; |
296 |
default: |
|
297 |
break; |
|
3547 | 298 |
} |
3697 | 299 |
|
3547 | 300 |
[aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
301 |
} |
|
302 |
||
13166
ba5c794adae3
- Some not-so-important pretty formatting
antonc27 <antonc27@mail.ru>
parents:
12872
diff
changeset
|
303 |
- (NSString *)tableView:(UITableView *)aTableView titleForHeaderInSection:(NSInteger)section { |
3659 | 304 |
NSString *sectionTitle = nil; |
305 |
switch (section) { |
|
306 |
case 0: |
|
307 |
sectionTitle = NSLocalizedString(@"Scheme Name", @""); |
|
308 |
break; |
|
309 |
case 1: |
|
310 |
sectionTitle = NSLocalizedString(@"Game Settings", @""); |
|
311 |
break; |
|
312 |
case 2: |
|
313 |
sectionTitle = NSLocalizedString(@"Game Modifiers", @""); |
|
314 |
break; |
|
315 |
default: |
|
316 |
DLog(@"nope"); |
|
317 |
break; |
|
318 |
} |
|
319 |
return sectionTitle; |
|
320 |
} |
|
3547 | 321 |
|
13166
ba5c794adae3
- Some not-so-important pretty formatting
antonc27 <antonc27@mail.ru>
parents:
12872
diff
changeset
|
322 |
- (CGFloat)tableView:(UITableView *)aTableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { |
6672
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
323 |
if ([indexPath section] == 0) |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
324 |
return aTableView.rowHeight; |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
325 |
else if ([indexPath section] == 1) |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
326 |
return IS_ON_PORTRAIT() ? 72 : aTableView.rowHeight; |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
327 |
else |
4113 | 328 |
return 56; |
329 |
} |
|
330 |
||
11291
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11279
diff
changeset
|
331 |
#pragma mark - Helper methods |
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11279
diff
changeset
|
332 |
|
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11279
diff
changeset
|
333 |
- (NSString *)localizedValueStringForKey:(NSString *)keyString andSlider:(UISlider *)slider |
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11279
diff
changeset
|
334 |
{ |
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11279
diff
changeset
|
335 |
NSInteger sliderValue = (NSInteger)slider.value; |
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11279
diff
changeset
|
336 |
|
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11279
diff
changeset
|
337 |
if ([keyString isEqualToString:@"Turn Time"] && sliderValue == 100) |
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11279
diff
changeset
|
338 |
return @"∞"; |
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11279
diff
changeset
|
339 |
else if ([keyString isEqualToString:@"Water Rise Amount"] && sliderValue == 100) |
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11279
diff
changeset
|
340 |
return NSLocalizedString(@"Nvr", @"Short for 'Never'"); |
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11279
diff
changeset
|
341 |
else if ([keyString isEqualToString:@"Crate Drop Turns"] && sliderValue == 0) |
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11279
diff
changeset
|
342 |
return NSLocalizedString(@"Nvr", @"Short for 'Never'"); |
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11279
diff
changeset
|
343 |
else if ([keyString isEqualToString:@"Mines Time"] && sliderValue == -1) |
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11279
diff
changeset
|
344 |
return NSLocalizedString(@"Rnd", @"Short for 'Random'"); |
11292
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11291
diff
changeset
|
345 |
else if ([keyString isEqualToString:@"World Edge"]) |
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11291
diff
changeset
|
346 |
switch (sliderValue) |
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11291
diff
changeset
|
347 |
{ |
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11291
diff
changeset
|
348 |
case 0: |
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11291
diff
changeset
|
349 |
return NSLocalizedString(@"None", nil); |
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11291
diff
changeset
|
350 |
|
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11291
diff
changeset
|
351 |
case 1: |
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11291
diff
changeset
|
352 |
return NSLocalizedString(@"Wrap", nil); |
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11291
diff
changeset
|
353 |
|
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11291
diff
changeset
|
354 |
case 2: |
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11291
diff
changeset
|
355 |
return NSLocalizedString(@"Bounce", nil); |
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11291
diff
changeset
|
356 |
|
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11291
diff
changeset
|
357 |
case 3: |
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11291
diff
changeset
|
358 |
return NSLocalizedString(@"Sea", nil); |
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11291
diff
changeset
|
359 |
|
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11291
diff
changeset
|
360 |
default: |
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11291
diff
changeset
|
361 |
return @""; |
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11291
diff
changeset
|
362 |
} |
11291
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11279
diff
changeset
|
363 |
else |
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11279
diff
changeset
|
364 |
return [NSString stringWithFormat:@"%ld", (long)sliderValue]; |
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11279
diff
changeset
|
365 |
} |
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11279
diff
changeset
|
366 |
|
3547 | 367 |
#pragma mark - |
368 |
#pragma mark Memory management |
|
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11292
diff
changeset
|
369 |
|
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11292
diff
changeset
|
370 |
- (void)didReceiveMemoryWarning { |
3547 | 371 |
[super didReceiveMemoryWarning]; |
3781
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3753
diff
changeset
|
372 |
self.basicSettingList = nil; |
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3753
diff
changeset
|
373 |
self.gameModifierArray = nil; |
3547 | 374 |
} |
375 |
||
376 |
@end |