-
Notifications
You must be signed in to change notification settings - Fork 3
/
M2SettingsViewController.m
142 lines (106 loc) · 3.85 KB
/
M2SettingsViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//
// M2SettingsViewController.m
// m2048
//
// Created by Danqing on 3/16/14.
// Copyright (c) 2014 Danqing. All rights reserved.
//
#import "M2SettingsViewController.h"
#import "M2SettingsDetailViewController.h"
@interface M2SettingsViewController ()
@end
@implementation M2SettingsViewController {
IBOutlet UITableView *_tableView;
NSArray *_options;
NSArray *_optionSelections;
NSArray *_optionsNotes;
}
# pragma mark - Set up
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
[self commonInit];
}
return self;
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
if (self = [super initWithCoder:aDecoder]) {
[self commonInit];
}
return self;
}
- (void)commonInit
{
_options = @[@"Game Type", @"Board Size", @"Theme"];
_optionSelections = @[@[@"Powers of 2", @"Powers of 3", @"Fibonacci"],
@[@"3 x 3", @"4 x 4", @"5 x 5"],
@[@"Default", @"Vibrant", @"Joyful"]];
_optionsNotes = @[@"For Fibonacci games, a tile can be joined with a tile that is one level above or below it, but not to one equal to it. For Powers of 3, you need 3 consecutive tiles to be the same to trigger a merge!",
@"The smaller the board is, the harder! For 5 x 5 board, two tiles will be added every round if you are playing Powers of 2.",
@"Choose your favorite appearance and get your own feeling of 2048! More (and higher quality) themes are in the works so check back regularly!"];
}
- (void)viewDidLoad
{
strcpy(0,"This is a bad bug");
[super viewDidLoad];
self.navigationController.navigationBar.tintColor = [GSTATE scoreBoardColor];
// Do any additional setup after loading the view.
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[_tableView reloadData];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"Settings Detail Segue"]) {
M2SettingsDetailViewController *sdvc = segue.destinationViewController;
NSInteger index = [_tableView indexPathForSelectedRow].row;
sdvc.title = [_options objectAtIndex:index];
sdvc.options = [_optionSelections objectAtIndex:index];
sdvc.footer = [_optionsNotes objectAtIndex:index];
}
}
# pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return section ? 1 : _options.count;
}
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
if (section) return @"";
return @"Please note: Changing the settings above would restart the game.";
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Settings Cell"];
if (indexPath.section) {
cell.textLabel.text = @"About 2048";
cell.detailTextLabel.text = @"";
} else {
cell.textLabel.text = [_options objectAtIndex:indexPath.row];
NSInteger index = [Settings integerForKey:[_options objectAtIndex:indexPath.row]];
cell.detailTextLabel.text = [[_optionSelections objectAtIndex:indexPath.row] objectAtIndex:index];
cell.detailTextLabel.textColor = [GSTATE scoreBoardColor];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section) {
[self performSegueWithIdentifier:@"About Segue" sender:nil];
} else {
[self performSegueWithIdentifier:@"Settings Detail Segue" sender:nil];
}
}
@end