project_files/HedgewarsMobile/Classes/MissionTrainingViewController.m
author alfadur
Tue, 14 Jan 2020 01:40:23 +0300
changeset 15544 77551d5e0a3b
parent 13199 e17efd663125
permissions -rw-r--r--
send 🦔 on round end
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"
13192
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
    25
#define CHALLENGE_MISSION_TYPE @"Challenge"
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
    26
#define SCENARIO_MISSION_TYPE @"Scenario"
6094
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
    27
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    28
@implementation MissionTrainingViewController
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    29
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11549
diff changeset
    30
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    31
    return rotationManager(interfaceOrientation);
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    32
}
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    33
6094
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
    34
#pragma mark -
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
    35
#pragma mark View management
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11549
diff changeset
    36
- (void)viewDidLoad
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
    37
{
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
    38
    [super viewDidLoad];
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
    39
    
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    40
    self.previewImage.layer.borderColor = [[UIColor darkYellowColor] CGColor];
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    41
    self.previewImage.layer.borderWidth = 3.8f;
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    42
    self.previewImage.layer.cornerRadius = 14;
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    43
6210
923c8414e3af fix runtime compability with ios 3.* (hopefully) and fix a small glitch in turning off music/sounds
koda
parents: 6100
diff changeset
    44
    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
    45
        [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
    46
        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
    47
        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
    48
    } else {
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 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
    50
        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
    51
        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
    52
    }
6094
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
    53
    self.tableView.layer.borderWidth = 2.4f;
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    54
    self.tableView.layer.cornerRadius = 8;
6094
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
    55
    self.tableView.separatorColor = [UIColor whiteColor];
6083
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
    self.descriptionLabel.textColor = [UIColor lightYellowColor];
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    58
}
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    59
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11549
diff changeset
    60
- (void)viewWillAppear:(BOOL)animated {
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
    61
    NSInteger randomSection = arc4random_uniform((int)[self.missionsTypes count]);
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
    62
    NSString *type = self.missionsTypes[randomSection];
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
    63
    NSArray *listOfIDs = [self listOfMissionsIDsForType:type];
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
    64
    NSInteger randomRow = arc4random_uniform((int)[listOfIDs count]);
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
    65
    
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
    66
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:randomRow inSection:randomSection];
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
    67
    [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
    68
    [self tableView:self.tableView didSelectRowAtIndexPath:indexPath];
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    69
    [super viewWillAppear:animated];
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    70
}
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    71
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11549
diff changeset
    72
- (IBAction)buttonPressed:(id)sender {
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    73
    UIButton *button = (UIButton *)sender;
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    74
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    75
    if (button.tag == 0) {
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    76
        [[AudioManagerController mainManager] playBackSound];
11116
102684240fe8 - Interscreen transitions fixed
Anton Malmygin <antonc27@mail.ru>
parents: 10108
diff changeset
    77
        [self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    78
    } 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
    79
        [GameInterfaceBridge registerCallingController:self];
13199
e17efd663125 - Fix missions path, still needs refactoring...
antonc27 <antonc27@mail.ru>
parents: 13192
diff changeset
    80
        [GameInterfaceBridge startMissionGame:self.missionSubPath];
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    81
    }
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    82
}
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
    83
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
    84
#pragma mark - Missions dictionaries methods
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
    85
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
    86
- (NSDictionary *)newLocalizedMissionsDictionaryForType: (NSString *)type
11220
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 *languageID = [HWUtils languageID];
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
    89
    
13192
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
    90
    NSString *missionsDescLocation = [[NSString alloc] initWithFormat:@"%@/missions_en.txt", LOCALE_DIRECTORY()];
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
    91
    NSString *localizedMissionsDescLocation = [[NSString alloc] initWithFormat:@"%@/missions_%@.txt", LOCALE_DIRECTORY(), languageID];
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
    92
    
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
    93
    if (![languageID isEqualToString:@"en"] && [[NSFileManager defaultManager] fileExistsAtPath:localizedMissionsDescLocation])
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
    94
    {
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
    95
        NSDictionary *missionsDict = [self newMissionsDictionaryForType:type fromMissionsFile:missionsDescLocation];
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
    96
        NSDictionary *localizedMissionsDict = [self newMissionsDictionaryForType:type fromMissionsFile:localizedMissionsDescLocation];
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
    97
        
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
        NSMutableDictionary *tempMissionsDict = [[NSMutableDictionary alloc] init];
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
        for (NSString *key in [missionsDict allKeys])
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
            if ([localizedMissionsDict objectForKey: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
                [tempMissionsDict setObject:[localizedMissionsDict objectForKey:key] forKey:key];
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
            else
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
                [tempMissionsDict setObject:[missionsDict objectForKey:key] forKey:key];
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
        
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
        return tempMissionsDict;
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   115
    }
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   116
    else
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   117
    {
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   118
        NSDictionary *missionsDict = [self newMissionsDictionaryForType:type fromMissionsFile:missionsDescLocation];
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   119
        
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   120
        
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   121
        return missionsDict;
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   122
    }
6094
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   123
}
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   124
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   125
- (NSDictionary *)newMissionsDictionaryForType:(NSString *)type fromMissionsFile:(NSString *)filePath
11220
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
    NSMutableDictionary *missionsDict = [[NSMutableDictionary alloc] init];
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   128
    
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   129
    NSString *missionsFileContents = [[NSString alloc] initWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:NULL];
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   130
    NSArray *missionsLines = [missionsFileContents componentsSeparatedByString:@"\n"];
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   131
    
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   132
    NSString *directory = [self missionsDirectoryForType:type];
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   133
    for (NSString *line in missionsLines)
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
        if ([line length] > 0)
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
            NSUInteger firstDotLocation = [line rangeOfString:@"."].location;
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   138
            
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   139
            NSString *missionID = [line substringToIndex:firstDotLocation];
11239
a954853e9c00 - Fix for loading non-existing missions in MissionTrainingViewController
antonc27 <antonc27@mail.ru>
parents: 11220
diff changeset
   140
            
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   141
            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
   142
            if (![[NSFileManager defaultManager] fileExistsAtPath:missionFullPath])
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
                continue;
a954853e9c00 - Fix for loading non-existing missions in MissionTrainingViewController
antonc27 <antonc27@mail.ru>
parents: 11220
diff changeset
   145
            }
a954853e9c00 - Fix for loading non-existing missions in MissionTrainingViewController
antonc27 <antonc27@mail.ru>
parents: 11220
diff changeset
   146
            
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   147
            NSString *nameOrDesc = [line substringFromIndex:firstDotLocation+1];
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   148
            
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   149
            NSString *missionParsedName = ([nameOrDesc hasPrefix:@"name="]) ? [nameOrDesc stringByReplacingOccurrencesOfString:@"name=" withString:@""] : nil;
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   150
            NSString *missionParsedDesc = ([nameOrDesc hasPrefix:@"desc="]) ? [nameOrDesc stringByReplacingOccurrencesOfString:@"desc=" withString:@""] : nil;
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   151
            
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   152
            if (![missionsDict objectForKey:missionID])
11119
f08d5bb1d2b0 - Fix for loading missions descriptions
antonc27 <antonc27@mail.ru>
parents: 11116
diff changeset
   153
            {
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   154
                NSMutableDictionary *missionDict = [[NSMutableDictionary alloc] init];
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   155
                [missionsDict setObject:missionDict forKey:missionID];
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   156
            }
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
            NSMutableDictionary *missionDict = [missionsDict objectForKey:missionID];
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
            if (missionParsedName)
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   161
            {
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   162
                [missionDict setObject:missionParsedName forKey:@"name"];
11119
f08d5bb1d2b0 - Fix for loading missions descriptions
antonc27 <antonc27@mail.ru>
parents: 11116
diff changeset
   163
            }
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
            if (missionParsedDesc)
11119
f08d5bb1d2b0 - Fix for loading missions descriptions
antonc27 <antonc27@mail.ru>
parents: 11116
diff changeset
   166
            {
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   167
                missionParsedDesc = [missionParsedDesc stringByReplacingOccurrencesOfString:@"\"" withString:@""];
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   168
                [missionDict setObject:missionParsedDesc forKey:@"desc"];
11119
f08d5bb1d2b0 - Fix for loading missions descriptions
antonc27 <antonc27@mail.ru>
parents: 11116
diff changeset
   169
            }
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   170
            
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   171
            [missionsDict setObject:missionDict forKey:missionID];
6094
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   172
        }
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   173
    }
11220
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
    return missionsDict;
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   176
}
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   177
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   178
#pragma mark -
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   179
#pragma mark override setters/getters for better memory handling
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   180
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   181
- (NSArray *)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
    if (!_missionsTypes)
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   184
    {
13192
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   185
        _missionsTypes = @[ TRAINING_MISSION_TYPE, CHALLENGE_MISSION_TYPE, SCENARIO_MISSION_TYPE ];
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   186
    }
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
    return _missionsTypes;
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   189
}
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   190
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   191
- (NSDictionary *)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
    if (!_dictOfAllMissions)
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   194
    {
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   195
        NSArray *types = [self missionsTypes];
13192
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   196
        _dictOfAllMissions = @{ types[0] : self.dictOfTraining,
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   197
                                types[1] : self.dictOfChallenge,
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   198
                                types[2] : self.dictOfScenario };
13191
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
    
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   201
    return _dictOfAllMissions;
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   202
}
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 *)listOfTrainingIDs
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   205
{
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   206
    if (!_listOfTrainingIDs)
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   207
    {
13192
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   208
        _listOfTrainingIDs = [[self.dictOfTraining allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   209
    }
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   210
    
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   211
    return _listOfTrainingIDs;
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
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   214
- (NSDictionary *)dictOfTraining
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   215
{
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   216
    if (!_dictOfTraining)
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
        _dictOfTraining = [self newLocalizedMissionsDictionaryForType:TRAINING_MISSION_TYPE];
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   219
    }
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   220
    
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   221
    return _dictOfTraining;
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   222
}
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   223
13192
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   224
- (NSArray *)listOfChallengeIDs
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   225
{
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   226
    if (!_listOfChallengeIDs)
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   227
    {
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   228
        _listOfChallengeIDs = [[self.dictOfChallenge allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   229
    }
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   230
    
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   231
    return _listOfChallengeIDs;
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   232
}
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   233
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   234
- (NSDictionary *)dictOfChallenge
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   235
{
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   236
    if (!_dictOfChallenge)
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   237
    {
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   238
        _dictOfChallenge = [self newLocalizedMissionsDictionaryForType:CHALLENGE_MISSION_TYPE];
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   239
    }
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   240
    
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   241
    return _dictOfChallenge;
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   242
}
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   243
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   244
- (NSArray *)listOfScenarioIDs
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   245
{
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   246
    if (!_listOfScenarioIDs)
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   247
    {
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   248
        _listOfScenarioIDs = [[self.dictOfScenario allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   249
    }
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   250
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   251
    return _listOfScenarioIDs;
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   252
}
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   253
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   254
- (NSDictionary *)dictOfScenario
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   255
{
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   256
    if (!_dictOfScenario)
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   257
    {
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   258
        _dictOfScenario = [self newLocalizedMissionsDictionaryForType:SCENARIO_MISSION_TYPE];
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   259
    }
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   260
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   261
    return _dictOfScenario;
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   262
}
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   263
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   264
#pragma mark -
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   265
#pragma mark Missions types
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   266
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   267
- (NSString *)missionsDirectoryForType:(NSString *)type
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   268
{
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   269
    if ([type isEqualToString:TRAINING_MISSION_TYPE]) {
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   270
        return TRAININGS_DIRECTORY();
13192
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   271
    } else if ([type isEqualToString:CHALLENGE_MISSION_TYPE]) {
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   272
        return CHALLENGE_DIRECTORY();
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   273
    } else if ([type isEqualToString:SCENARIO_MISSION_TYPE]) {
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   274
        return SCENARIO_DIRECTORY();
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   275
    }
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   276
    return nil;
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
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   279
- (NSArray *)listOfMissionsIDsForType:(NSString *)type
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   280
{
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   281
    if ([type isEqualToString:TRAINING_MISSION_TYPE]) {
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   282
        return self.listOfTrainingIDs;
13192
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   283
    } else if ([type isEqualToString:CHALLENGE_MISSION_TYPE]) {
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   284
        return self.listOfChallengeIDs;
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   285
    } else if ([type isEqualToString:SCENARIO_MISSION_TYPE]) {
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   286
        return self.listOfScenarioIDs;
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   287
    }
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   288
    return nil;
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   289
}
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   290
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   291
- (NSDictionary *)dictOfMissionsForType:(NSString *)type
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   292
{
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   293
    if ([type isEqualToString:TRAINING_MISSION_TYPE]) {
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   294
        return self.dictOfTraining;
13192
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   295
    } else if ([type isEqualToString:CHALLENGE_MISSION_TYPE]) {
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   296
        return self.dictOfChallenge;
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   297
    } else if ([type isEqualToString:SCENARIO_MISSION_TYPE]) {
d6aea85111c7 - Fix missions regression: presentation of list is good, still problem with path during launching
antonc27 <antonc27@mail.ru>
parents: 13191
diff changeset
   298
        return self.dictOfScenario;
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   299
    }
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   300
    return nil;
6094
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   301
}
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   302
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   303
#pragma mark -
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   304
#pragma mark Table view data source
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11549
diff changeset
   305
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   306
    return [self.missionsTypes count];
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   307
}
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   308
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11549
diff changeset
   309
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   310
    NSString *type = self.missionsTypes[section];
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   311
    NSArray *listOfIDs = [self listOfMissionsIDsForType:type];
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   312
    return [listOfIDs count];
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   313
}
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   314
13166
ba5c794adae3 - Some not-so-important pretty formatting
antonc27 <antonc27@mail.ru>
parents: 12872
diff changeset
   315
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
6094
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   316
    return (IS_IPAD()) ? self.tableView.rowHeight : 80;
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   317
}
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   318
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   319
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   320
    static NSString *CellIdentifier = @"CellTr";
6094
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   321
    NSInteger row = [indexPath row];
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   322
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   323
    UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   324
    if (cell == nil)
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11549
diff changeset
   325
        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
   326
                                       reuseIdentifier:CellIdentifier];
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   327
    
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   328
    NSInteger section = [indexPath section];
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   329
    NSString *type = self.missionsTypes[section];
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   330
    NSArray *listOfIDs = [self listOfMissionsIDsForType:type];
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   331
    NSDictionary *dict = [self dictOfMissionsForType:type];
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   332
    
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   333
    NSString *missionID = [listOfIDs objectAtIndex:row];
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   334
    cell.textLabel.text = dict[missionID][@"name"];
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   335
    
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   336
    cell.textLabel.textColor = [UIColor lightYellowColor];
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   337
    //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
   338
    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
   339
    cell.textLabel.backgroundColor = [UIColor clearColor];
6094
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   340
    cell.textLabel.adjustsFontSizeToFitWidth = YES;
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   341
    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
   342
    cell.detailTextLabel.textColor = [UIColor whiteColor];
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   343
    cell.detailTextLabel.backgroundColor = [UIColor clearColor];
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   344
    cell.detailTextLabel.adjustsFontSizeToFitWidth = YES;
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   345
    cell.detailTextLabel.numberOfLines = ([cell.detailTextLabel.text length] % 40);
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   346
    cell.detailTextLabel.baselineAdjustment = UIBaselineAdjustmentAlignCenters;
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   347
11218
08f20ffa5801 - Small adjust for cell selection color of Missions screen
antonc27 <antonc27@mail.ru>
parents: 11206
diff changeset
   348
    UIView *bgColorView = [[UIView alloc] init];
08f20ffa5801 - Small adjust for cell selection color of Missions screen
antonc27 <antonc27@mail.ru>
parents: 11206
diff changeset
   349
    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
   350
    bgColorView.layer.masksToBounds = YES;
08f20ffa5801 - Small adjust for cell selection color of Missions screen
antonc27 <antonc27@mail.ru>
parents: 11206
diff changeset
   351
    cell.selectedBackgroundView = bgColorView;
08f20ffa5801 - Small adjust for cell selection color of Missions screen
antonc27 <antonc27@mail.ru>
parents: 11206
diff changeset
   352
    
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   353
    cell.backgroundColor = [UIColor blackColorTransparent];
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   354
    return cell;
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   355
}
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   356
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   357
#pragma mark -
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   358
#pragma mark Table view delegate
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11549
diff changeset
   359
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   360
    NSInteger section = [indexPath section];
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   361
    NSString *type = self.missionsTypes[section];
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   362
    NSArray *listOfIDs = [self listOfMissionsIDsForType:type];
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   363
    
6094
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   364
    NSInteger row = [indexPath row];
13199
e17efd663125 - Fix missions path, still needs refactoring...
antonc27 <antonc27@mail.ru>
parents: 13192
diff changeset
   365
    NSString *missionID = [listOfIDs objectAtIndex:row];
e17efd663125 - Fix missions path, still needs refactoring...
antonc27 <antonc27@mail.ru>
parents: 13192
diff changeset
   366
    self.missionSubPath = [NSString stringWithFormat:@"%@/%@", type, missionID];
6100
e6426c6b2882 sed commands should be tested beforehand
koda
parents: 6094
diff changeset
   367
    NSString *size = IS_IPAD() ? @"@2x" : @"";
13199
e17efd663125 - Fix missions path, still needs refactoring...
antonc27 <antonc27@mail.ru>
parents: 13192
diff changeset
   368
    NSString *filePath = [NSString stringWithFormat:@"%@/Missions/%@%@.png",GRAPHICS_DIRECTORY(), self.missionSubPath, size];
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   369
    UIImage *img = [[UIImage alloc] initWithContentsOfFile:filePath];
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   370
    [self.previewImage setImage:img];
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   371
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   372
    NSDictionary *dict = [self dictOfMissionsForType:type];
13199
e17efd663125 - Fix missions path, still needs refactoring...
antonc27 <antonc27@mail.ru>
parents: 13192
diff changeset
   373
    self.descriptionLabel.text = dict[missionID][@"desc"];
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   374
}
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   375
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   376
#pragma mark -
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   377
#pragma mark Memory management
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   378
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11549
diff changeset
   379
- (void)didReceiveMemoryWarning
11220
32366eb83383 - Refactoring of Missions screen:
antonc27 <antonc27@mail.ru>
parents: 11218
diff changeset
   380
{
13191
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   381
    self.listOfTrainingIDs = nil;
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   382
    self.dictOfTraining = nil;
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   383
    self.dictOfAllMissions = nil;
0c1f3a8ba0bb - Fix missions regression: refactoring, WIP
antonc27 <antonc27@mail.ru>
parents: 13166
diff changeset
   384
    self.missionsTypes = nil;
6094
16b12a6417d1 added iphone interface for missions/trainings page, setters/getters unlocked
koda
parents: 6084
diff changeset
   385
    // 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
   386
    //self.previewImage = nil;
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   387
    [super didReceiveMemoryWarning];
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   388
}
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   389
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
diff changeset
   390
@end