project_files/HedgewarsMobile/Classes/MissionTrainingViewController.m
author antonc27 <antonc27@mail.ru>
Wed, 14 Mar 2018 00:25:31 +0100
branchios-develop
changeset 13191 0c1f3a8ba0bb
parent 13166 ba5c794adae3
child 13192 d6aea85111c7
permissions -rw-r--r--
- Fix missions regression: refactoring, WIP
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
     1
/*
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
     2
 * Hedgewars-iOS, a Hedgewars port for iOS devices
6700
e04da46ee43c the most important commit of the year
koda
parents: 6494
diff changeset
     3
 * Copyright (c) 2009-2012 Vittorio Giovara <vittorio.giovara@gmail.com>
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
     4
 *
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
     8
 *
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    12
 * GNU General Public License for more details.
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    13
 *
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    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: 6908
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    17
 */
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    18
6094
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
    19
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    20
#import "MissionTrainingViewController.h"
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    21
#import <QuartzCore/QuartzCore.h>
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    22
#import "GameInterfaceBridge.h"
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    23
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
    24
#define TRAINING_MISSION_TYPE @"Training"
6094
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
    25
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    26
@implementation MissionTrainingViewController
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    27
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11549
diff changeset
    28
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    29
    return rotationManager(interfaceOrientation);
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    30
}
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    31
6094
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
    32
#pragma mark -
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
    33
#pragma mark View management
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11549
diff changeset
    34
- (void)viewDidLoad
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
    35
{
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
    36
    [super viewDidLoad];
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
    37
    
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    38
    self.previewImage.layer.borderColor = [[UIColor darkYellowColor] CGColor];
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    39
    self.previewImage.layer.borderWidth = 3.8f;
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    40
    self.previewImage.layer.cornerRadius = 14;
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    41
6210
923c8414e3af fix runtime compability with ios 3.* (hopefully) and fix a small glitch in turning off music/sounds
koda
parents: 6100
diff changeset
    42
    if (IS_IPAD()) {
923c8414e3af fix runtime compability with ios 3.* (hopefully) and fix a small glitch in turning off music/sounds
koda
parents: 6100
diff changeset
    43
        [self.tableView setBackgroundColorForAnyTable:[UIColor darkBlueColorTransparent]];
923c8414e3af fix runtime compability with ios 3.* (hopefully) and fix a small glitch in turning off music/sounds
koda
parents: 6100
diff changeset
    44
        self.tableView.layer.borderColor = [[UIColor darkYellowColor] CGColor];
923c8414e3af fix runtime compability with ios 3.* (hopefully) and fix a small glitch in turning off music/sounds
koda
parents: 6100
diff changeset
    45
        self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
923c8414e3af fix runtime compability with ios 3.* (hopefully) and fix a small glitch in turning off music/sounds
koda
parents: 6100
diff changeset
    46
    } else {
923c8414e3af fix runtime compability with ios 3.* (hopefully) and fix a small glitch in turning off music/sounds
koda
parents: 6100
diff changeset
    47
        [self.tableView setBackgroundColorForAnyTable:[UIColor blackColorTransparent]];
923c8414e3af fix runtime compability with ios 3.* (hopefully) and fix a small glitch in turning off music/sounds
koda
parents: 6100
diff changeset
    48
        self.tableView.layer.borderColor = [[UIColor whiteColor] CGColor];
923c8414e3af fix runtime compability with ios 3.* (hopefully) and fix a small glitch in turning off music/sounds
koda
parents: 6100
diff changeset
    49
        self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
923c8414e3af fix runtime compability with ios 3.* (hopefully) and fix a small glitch in turning off music/sounds
koda
parents: 6100
diff changeset
    50
    }
6094
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
    51
    self.tableView.layer.borderWidth = 2.4f;
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    52
    self.tableView.layer.cornerRadius = 8;
6094
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
    53
    self.tableView.separatorColor = [UIColor whiteColor];
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    54
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    55
    self.descriptionLabel.textColor = [UIColor lightYellowColor];
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    56
}
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    57
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11549
diff changeset
    58
- (void)viewWillAppear:(BOOL)animated {
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
    59
    NSInteger randomSection = arc4random_uniform((int)[self.missionsTypes count]);
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
    60
    NSString *type = self.missionsTypes[randomSection];
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
    61
    NSArray *listOfIDs = [self listOfMissionsIDsForType:type];
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
    62
    NSInteger randomRow = arc4random_uniform((int)[listOfIDs count]);
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
    63
    
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
    64
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:randomRow inSection:randomSection];
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
    65
    [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionMiddle];
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    66
    [self tableView:self.tableView didSelectRowAtIndexPath:indexPath];
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    67
    [super viewWillAppear:animated];
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    68
}
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    69
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11549
diff changeset
    70
- (IBAction)buttonPressed:(id)sender {
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    71
    UIButton *button = (UIButton *)sender;
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    72
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    73
    if (button.tag == 0) {
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    74
        [[AudioManagerController mainManager] playBackSound];
11116
102684240fe8 - Interscreen transitions fixed
Anton Malmygin <antonc27@mail.ru>
parents: 10108
diff changeset
    75
        [self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    76
    } else {
6353
d8f62c805619 restore displaying statistics at the end of a game and restore warning lower views that they are going to appear
koda
parents: 6266
diff changeset
    77
        [GameInterfaceBridge registerCallingController:self];
6266
b02a1e92dba2 convert gameinterfacebridge in simple-to-use class methods
koda
parents: 6210
diff changeset
    78
        [GameInterfaceBridge startMissionGame:self.missionName];
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    79
    }
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    80
}
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    81
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
    82
#pragma mark - Missions dictionaries methods
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
    83
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
    84
- (NSDictionary *)newLocalizedMissionsDictionaryForType: (NSString *)type
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
    85
{
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
    86
    NSString *languageID = [HWUtils languageID];
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
    87
    
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
    88
    NSString *missionsDescLocation = [[NSString alloc] initWithFormat:@"%@/missions_en.txt",LOCALE_DIRECTORY()];
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
    89
    NSString *localizedMissionsDescLocation = [[NSString alloc] initWithFormat:@"%@/missions_%@.txt", LOCALE_DIRECTORY(), languageID];
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
    90
    
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
    91
    if (![languageID isEqualToString:@"en"] && [[NSFileManager defaultManager] fileExistsAtPath:localizedMissionsDescLocation])
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
    92
    {
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
    93
        NSDictionary *missionsDict = [self newMissionsDictionaryForType:type fromMissionsFile:missionsDescLocation];
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
    94
        NSDictionary *localizedMissionsDict = [self newMissionsDictionaryForType:type fromMissionsFile:localizedMissionsDescLocation];
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
    95
        
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
    96
        
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
    97
        NSMutableDictionary *tempMissionsDict = [[NSMutableDictionary alloc] init];
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
    98
        
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
    99
        for (NSString *key in [missionsDict allKeys])
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   100
        {
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   101
            if ([localizedMissionsDict objectForKey:key])
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   102
            {
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   103
                [tempMissionsDict setObject:[localizedMissionsDict objectForKey:key] forKey:key];
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   104
            }
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   105
            else
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   106
            {
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   107
                [tempMissionsDict setObject:[missionsDict objectForKey:key] forKey:key];
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   108
            }
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   109
        }
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   110
        
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   111
        
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   112
        return tempMissionsDict;
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   113
    }
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   114
    else
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   115
    {
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   116
        NSDictionary *missionsDict = [self newMissionsDictionaryForType:type fromMissionsFile:missionsDescLocation];
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   117
        
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   118
        
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   119
        return missionsDict;
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   120
    }
6094
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   121
}
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   122
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   123
- (NSDictionary *)newMissionsDictionaryForType:(NSString *)type fromMissionsFile:(NSString *)filePath
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   124
{
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   125
    NSMutableDictionary *missionsDict = [[NSMutableDictionary alloc] init];
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   126
    
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   127
    NSString *missionsFileContents = [[NSString alloc] initWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:NULL];
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   128
    NSArray *missionsLines = [missionsFileContents componentsSeparatedByString:@"\n"];
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   129
    
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   130
    NSString *directory = [self missionsDirectoryForType:type];
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   131
    for (NSString *line in missionsLines)
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   132
    {
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   133
        if ([line length] > 0)
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   134
        {
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   135
            NSUInteger firstDotLocation = [line rangeOfString:@"."].location;
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   136
            
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   137
            NSString *missionID = [line substringToIndex:firstDotLocation];
11239
a954853e9c00 - Fix for loading non-existing missions in MissionTrainingViewController
antonc27 <antonc27@mail.ru>
parents: 11220
diff changeset
   138
            
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   139
            NSString *missionFullPath = [NSString stringWithFormat:@"%@%@.lua", directory, missionID];
11239
a954853e9c00 - Fix for loading non-existing missions in MissionTrainingViewController
antonc27 <antonc27@mail.ru>
parents: 11220
diff changeset
   140
            if (![[NSFileManager defaultManager] fileExistsAtPath:missionFullPath])
a954853e9c00 - Fix for loading non-existing missions in MissionTrainingViewController
antonc27 <antonc27@mail.ru>
parents: 11220
diff changeset
   141
            {
a954853e9c00 - Fix for loading non-existing missions in MissionTrainingViewController
antonc27 <antonc27@mail.ru>
parents: 11220
diff changeset
   142
                continue;
a954853e9c00 - Fix for loading non-existing missions in MissionTrainingViewController
antonc27 <antonc27@mail.ru>
parents: 11220
diff changeset
   143
            }
a954853e9c00 - Fix for loading non-existing missions in MissionTrainingViewController
antonc27 <antonc27@mail.ru>
parents: 11220
diff changeset
   144
            
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   145
            NSString *nameOrDesc = [line substringFromIndex:firstDotLocation+1];
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   146
            
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   147
            NSString *missionParsedName = ([nameOrDesc hasPrefix:@"name="]) ? [nameOrDesc stringByReplacingOccurrencesOfString:@"name=" withString:@""] : nil;
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   148
            NSString *missionParsedDesc = ([nameOrDesc hasPrefix:@"desc="]) ? [nameOrDesc stringByReplacingOccurrencesOfString:@"desc=" withString:@""] : nil;
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   149
            
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   150
            if (![missionsDict objectForKey:missionID])
11119
f08d5bb1d2b0 - Fix for loading missions descriptions
antonc27 <antonc27@mail.ru>
parents: 11116
diff changeset
   151
            {
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   152
                NSMutableDictionary *missionDict = [[NSMutableDictionary alloc] init];
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   153
                [missionsDict setObject:missionDict forKey:missionID];
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   154
            }
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   155
            
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   156
            NSMutableDictionary *missionDict = [missionsDict objectForKey:missionID];
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   157
            
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   158
            if (missionParsedName)
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   159
            {
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   160
                [missionDict setObject:missionParsedName forKey:@"name"];
11119
f08d5bb1d2b0 - Fix for loading missions descriptions
antonc27 <antonc27@mail.ru>
parents: 11116
diff changeset
   161
            }
f08d5bb1d2b0 - Fix for loading missions descriptions
antonc27 <antonc27@mail.ru>
parents: 11116
diff changeset
   162
            
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   163
            if (missionParsedDesc)
11119
f08d5bb1d2b0 - Fix for loading missions descriptions
antonc27 <antonc27@mail.ru>
parents: 11116
diff changeset
   164
            {
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   165
                missionParsedDesc = [missionParsedDesc stringByReplacingOccurrencesOfString:@"\"" withString:@""];
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   166
                [missionDict setObject:missionParsedDesc forKey:@"desc"];
11119
f08d5bb1d2b0 - Fix for loading missions descriptions
antonc27 <antonc27@mail.ru>
parents: 11116
diff changeset
   167
            }
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   168
            
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   169
            [missionsDict setObject:missionDict forKey:missionID];
6094
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   170
        }
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   171
    }
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   172
    
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   173
    return missionsDict;
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   174
}
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   175
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   176
#pragma mark -
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   177
#pragma mark override setters/getters for better memory handling
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   178
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   179
- (NSArray *)missionsTypes
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   180
{
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   181
    if (!_missionsTypes)
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   182
    {
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   183
        _missionsTypes = @[ TRAINING_MISSION_TYPE ];
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   184
    }
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   185
    
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   186
    return _missionsTypes;
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   187
}
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   188
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   189
- (NSDictionary *)dictOfAllMissions
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   190
{
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   191
    if (!_dictOfAllMissions)
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   192
    {
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   193
        NSArray *types = [self missionsTypes];
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   194
        _dictOfAllMissions = @{ types[0] : [self dictOfTraining] };
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   195
    }
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   196
    
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   197
    return _dictOfAllMissions;
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   198
}
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   199
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   200
- (NSArray *)listOfTrainingIDs
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   201
{
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   202
    if (!_listOfTrainingIDs)
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   203
    {
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   204
        NSArray *sortedKeys = [[self.dictOfTraining allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   205
        _listOfTrainingIDs = [[NSArray alloc] initWithArray:sortedKeys];
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   206
    }
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   207
    
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   208
    return _listOfTrainingIDs;
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   209
}
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   210
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   211
- (NSDictionary *)dictOfTraining
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   212
{
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   213
    if (!_dictOfTraining)
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   214
    {
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   215
        _dictOfTraining = [self newLocalizedMissionsDictionaryForType:TRAINING_MISSION_TYPE];
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   216
    }
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   217
    
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   218
    return _dictOfTraining;
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   219
}
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   220
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   221
#pragma mark -
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   222
#pragma mark Missions types
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   223
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   224
- (NSString *)missionsDirectoryForType:(NSString *)type
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   225
{
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   226
    if ([type isEqualToString:TRAINING_MISSION_TYPE]) {
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   227
        return TRAININGS_DIRECTORY();
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   228
    }
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   229
    return nil;
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   230
}
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   231
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   232
- (NSArray *)listOfMissionsIDsForType:(NSString *)type
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   233
{
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   234
    if ([type isEqualToString:TRAINING_MISSION_TYPE]) {
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   235
        return self.listOfTrainingIDs;
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   236
    }
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   237
    return nil;
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   238
}
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   239
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   240
- (NSDictionary *)dictOfMissionsForType:(NSString *)type
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   241
{
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   242
    if ([type isEqualToString:TRAINING_MISSION_TYPE]) {
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   243
        return self.dictOfTraining;
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   244
    }
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   245
    return nil;
6094
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   246
}
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   247
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   248
#pragma mark -
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   249
#pragma mark Table view data source
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11549
diff changeset
   250
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   251
    return [self.missionsTypes count];
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   252
}
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   253
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11549
diff changeset
   254
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   255
    NSString *type = self.missionsTypes[section];
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   256
    NSArray *listOfIDs = [self listOfMissionsIDsForType:type];
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   257
    return [listOfIDs count];
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   258
}
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   259
13166
ba5c794adae3 - Some not-so-important pretty formatting
antonc27 <antonc27@mail.ru>
parents: 12872
diff changeset
   260
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
6094
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   261
    return (IS_IPAD()) ? self.tableView.rowHeight : 80;
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   262
}
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   263
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   264
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   265
    static NSString *CellIdentifier = @"CellTr";
6094
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   266
    NSInteger row = [indexPath row];
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   267
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   268
    UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   269
    if (cell == nil)
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11549
diff changeset
   270
        cell = [[UITableViewCell alloc] initWithStyle:(IS_IPAD()) ? UITableViewCellStyleDefault : UITableViewCellStyleSubtitle
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11549
diff changeset
   271
                                       reuseIdentifier:CellIdentifier];
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   272
    
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   273
    NSInteger section = [indexPath section];
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   274
    NSString *type = self.missionsTypes[section];
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   275
    NSArray *listOfIDs = [self listOfMissionsIDsForType:type];
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   276
    NSDictionary *dict = [self dictOfMissionsForType:type];
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   277
    
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   278
    NSString *missionID = [listOfIDs objectAtIndex:row];
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   279
    cell.textLabel.text = dict[missionID][@"name"];
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   280
    
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   281
    cell.textLabel.textColor = [UIColor lightYellowColor];
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   282
    //cell.textLabel.font = [UIFont fontWithName:@"Bradley Hand Bold" size:[UIFont labelFontSize]];
11549
893722a2a1f9 - Some warnings fixed with text alignment on iOS front-end
antonc27 <antonc27@mail.ru>
parents: 11323
diff changeset
   283
    cell.textLabel.textAlignment = (IS_IPAD()) ? NSTextAlignmentCenter : NSTextAlignmentLeft;
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   284
    cell.textLabel.backgroundColor = [UIColor clearColor];
6094
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   285
    cell.textLabel.adjustsFontSizeToFitWidth = YES;
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   286
    cell.detailTextLabel.text = (IS_IPAD()) ? nil : dict[missionID][@"desc"];
6094
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   287
    cell.detailTextLabel.textColor = [UIColor whiteColor];
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   288
    cell.detailTextLabel.backgroundColor = [UIColor clearColor];
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   289
    cell.detailTextLabel.adjustsFontSizeToFitWidth = YES;
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   290
    cell.detailTextLabel.numberOfLines = ([cell.detailTextLabel.text length] % 40);
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   291
    cell.detailTextLabel.baselineAdjustment = UIBaselineAdjustmentAlignCenters;
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   292
11218
08f20ffa5801 - Small adjust for cell selection color of Missions screen
antonc27 <antonc27@mail.ru>
parents: 11206
diff changeset
   293
    UIView *bgColorView = [[UIView alloc] init];
08f20ffa5801 - Small adjust for cell selection color of Missions screen
antonc27 <antonc27@mail.ru>
parents: 11206
diff changeset
   294
    bgColorView.backgroundColor = [UIColor colorWithRed:(85.0/255.0) green:(15.0/255.0) blue:(106.0/255.0) alpha:1.0];
08f20ffa5801 - Small adjust for cell selection color of Missions screen
antonc27 <antonc27@mail.ru>
parents: 11206
diff changeset
   295
    bgColorView.layer.masksToBounds = YES;
08f20ffa5801 - Small adjust for cell selection color of Missions screen
antonc27 <antonc27@mail.ru>
parents: 11206
diff changeset
   296
    cell.selectedBackgroundView = bgColorView;
08f20ffa5801 - Small adjust for cell selection color of Missions screen
antonc27 <antonc27@mail.ru>
parents: 11206
diff changeset
   297
    
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   298
    cell.backgroundColor = [UIColor blackColorTransparent];
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   299
    return cell;
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   300
}
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   301
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   302
#pragma mark -
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   303
#pragma mark Table view delegate
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11549
diff changeset
   304
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   305
    NSInteger section = [indexPath section];
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   306
    NSString *type = self.missionsTypes[section];
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   307
    NSArray *listOfIDs = [self listOfMissionsIDsForType:type];
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   308
    
6094
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   309
    NSInteger row = [indexPath row];
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   310
    self.missionName = [listOfIDs objectAtIndex:row];
6100
e6426c6b2882 sed commands should be tested beforehand
koda
parents: 6094
diff changeset
   311
    NSString *size = IS_IPAD() ? @"@2x" : @"";
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   312
    NSString *filePath = [[NSString alloc] initWithFormat:@"%@/Missions/%@/%@%@.png",GRAPHICS_DIRECTORY(), type, self.missionName, size];
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   313
    UIImage *img = [[UIImage alloc] initWithContentsOfFile:filePath];
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   314
    [self.previewImage setImage:img];
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   315
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   316
    NSDictionary *dict = [self dictOfMissionsForType:type];
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   317
    self.descriptionLabel.text = dict[self.missionName][@"desc"];
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   318
}
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   319
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   320
#pragma mark -
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   321
#pragma mark Memory management
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   322
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11549
diff changeset
   323
- (void)didReceiveMemoryWarning
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   324
{
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   325
    self.listOfTrainingIDs = nil;
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   326
    self.dictOfTraining = nil;
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   327
    self.dictOfAllMissions = nil;
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   328
    self.missionsTypes = nil;
6094
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   329
    // if you nil this one it won't get updated anymore
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   330
    //self.previewImage = nil;
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   331
    [super didReceiveMemoryWarning];
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   332
}
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   333
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   334
@end