Subversion Repository Public Repository

Nextrek

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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
//
//  DimensioneParallelaVC.m
//  StoryBoard
//
//  Created by BwbUser on 22/12/13.
//  Copyright (c) 2013 Odyssey. All rights reserved.
//

#import "DimensioneParallelaVC.h"
#import "Scena.h"
#import "SceneButton.h"
#import "TableCellButton.h"
#import "AboutVC.h"

@interface DimensioneParallelaVC (){
    Scena *scenaToShow;
}

@end

@implementation DimensioneParallelaVC

#pragma mark - Init

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) { }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [DATAMANAGER dimensioneParallelaJSON];
    
    [DATAMANAGER loadObjectsDimPar];
//    //NSLog(@"loadObjects - BOOL Value: %i", DATAMANAGER.sceneObject.boolValue);
    
    [DATAMANAGER loadScenaDimPar];
//    //NSLog(@"loadScena - BOOL Value: %i", DATAMANAGER.sceneObject.boolValue);
    
    if(DATAMANAGER.idScena && DATAMANAGER.idScena != 1000) {
        [self showSceneView:DATAMANAGER.idScena];
    }
    else {
        [self showSceneView:194];
    }
}

#pragma mark - View Management

- (void)showSceneView:(int)sceneId {
    
    [DATAMANAGER saveScenaDimPar:sceneId];
    //NSLog(@"Scena da mostrare - iPhone: %d", sceneId);
    
    //NSLog(@"Scena object - eventoCellValue: %i", DATAMANAGER.sceneObject.eventoCellValue);
    //NSLog(@"Scena object - eventoLettoValue: %i", DATAMANAGER.sceneObject.eventoLettoValue);
    //NSLog(@"Scena object - eventoArmValue: %i", DATAMANAGER.sceneObject.eventoArmValue);
    //NSLog(@"Scena object - eventoScrivValue: %i", DATAMANAGER.sceneObject.eventoScrivValue);
    //NSLog(@"Scena object - eventoDiarletValue: %i", DATAMANAGER.sceneObject.eventoDiarletValue);
    //NSLog(@"Scena object - eventoLitigioValue: %i", DATAMANAGER.sceneObject.eventoLitigioValue);
    //NSLog(@"Scena object - eventoBigliettoValue: %i", DATAMANAGER.sceneObject.eventoBigliettoValue);
    //NSLog(@"Scena object - oggettoFotoValue: %i", DATAMANAGER.sceneObject.oggettoFotoValue);
    //NSLog(@"Scena object - oggettoDiarValue: %i", DATAMANAGER.sceneObject.oggettoDiarValue);
    //NSLog(@"Scena object - oggettoBigliettoValue: %i", DATAMANAGER.sceneObject.oggettoBigliettoValue);
    
    for(Scena *aScena in DATAMANAGER.scene) {
        if(aScena.idScena - sceneId == 0) {
            scenaToShow = aScena;
        }
    }
    
    self.bkgVImgView.image = [UIImage imageNamed:scenaToShow.bckImage];
    
    if(!STR_ISNULL_OR_EMPTY(scenaToShow.testo)) {
        self.sceneText.hidden = NO;
        self.sceneText.text = scenaToShow.testo;
        [self.sceneText setContentOffset:CGPointMake(0, 0) animated:YES];
        
        CGRect frame = self.sceneText.frame;
        frame.size.height = self.sceneText.contentSize.height + 20;
        
        if(frame.size.height < 200) {
            self.sceneText.frame = frame;
        }
        else {
            self.sceneText.frame = IS_IPHONE_5 ? CGRectMake(5, 5, 470, frame.size.height + 20) : CGRectMake(5, 5, 470, frame.size.height + 20);
        }
    }
    else {
        self.sceneText.hidden = YES;
    }
    
    [self.sceneTable reloadData];
    
    self.sceneTable.frame = IS_IPHONE_5 ? CGRectMake(124, 320 - (50*[scenaToShow.buttons count]), 320, 50*[scenaToShow.buttons count]) : CGRectMake(80, 320 - (50*[scenaToShow.buttons count]), 320, 50*[scenaToShow.buttons count]);
    
    CGRect frame = self.sceneText.frame;
    frame.size.height = self.sceneText.contentSize.height + 20;
    
    if(frame.size.height < 200) {
        self.sceneText.frame = frame;
    }
    else {
        self.sceneText.frame = IS_IPHONE_5 ? CGRectMake(5, 5, 470, frame.size.height + 20) : CGRectMake(5, 5, 470, frame.size.height + 20);
    }
}

#pragma mark - Table view methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [scenaToShow.buttons count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
	return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *MyIdentifier = @"TableCellButton";
    
    TableCellButton *cell = (TableCellButton *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
    if (cell == nil)	{
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:MyIdentifier owner:self options:nil];
        cell = [topLevelObjects objectAtIndex:0];
    }
    
    SceneButton *sceneButton = ((SceneButton*)[scenaToShow.buttons objectAtIndex:indexPath.row]);
    //NSLog(@"Testo bottone: %@", sceneButton.text);
    
    cell.button.titleLabel.numberOfLines = 1;
    cell.button.titleLabel.adjustsFontSizeToFitWidth = YES;
    cell.button.titleLabel.lineBreakMode = NSLineBreakByClipping;
    
    // buttonPreCond
    // Vuol dire che se il l'elemento dell'array รจ "true" si vede il tasto con questa precodizione
    
    if([sceneButton.preCond rangeOfString:@"evento(cell,true)"].location != NSNotFound) {
        if(DATAMANAGER.sceneObject.eventoCellValue == NO) {
            cell.button.hidden = YES;
            cell.button.enabled = NO;
        }
    }
    else {
        cell.button.hidden = NO;
        cell.button.enabled = YES;
    }
    
    [cell.button setTitle:((SceneButton*)[scenaToShow.buttons objectAtIndex:indexPath.row]).text forState:UIControlStateNormal];
    
    [cell.button addTarget:self action:@selector(buttonHighlight:) forControlEvents:UIControlEventTouchDown];
    [cell.button addTarget:self action:@selector(doOpenNewScene:) forControlEvents:UIControlEventTouchUpInside];
    
    return cell;
}

- (void) buttonHighlight:(id)sender {
    UIButton *button = (UIButton*)sender;
    
    [button setBackgroundColor:[UIColor lightGrayColor]];
}

- (void) doOpenNewScene:(id)sender {
    UIButton *button = (UIButton*)sender;
    
    UITableViewCell *cell = (UITableViewCell *)button.superview.superview;
    NSIndexPath *indexPath = [self.sceneTable indexPathForCell:cell];
    
    SceneButton *sceneButton = ((SceneButton*)[scenaToShow.buttons objectAtIndex:indexPath.row]);
    
    if([sceneButton.targetId intValue] == 1001) {
        AboutVC *aboutVC = [[AboutVC alloc] initWithNibName:nil bundle:nil];
        aboutVC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
        [self presentViewController:aboutVC animated:YES completion:nil];
    }
    else {
        // buttonPostCond
        // Vuol dire che dopo aver cliccato un tasto con questa postcondizione il primo elemento dell'array oggetti viene settata a "true"
        
        if([sceneButton.postCond rangeOfString:@"evento(cell,true)"].location != NSNotFound) {
            DATAMANAGER.sceneObject.eventoCellValue = YES;
        }
        else if([sceneButton.postCond rangeOfString:@"evento(cell,false)"].location != NSNotFound){
            DATAMANAGER.sceneObject.eventoCellValue = NO;
        }
        
        DATAMANAGER.sceneObject.eventoLettoValue = [sceneButton.postCond rangeOfString:@"evento(letto,true)"].location != NSNotFound ? YES : NO;

        DATAMANAGER.sceneObject.eventoArmValue = [sceneButton.postCond rangeOfString:@"evento(arm,true)"].location != NSNotFound ? YES : NO;

        DATAMANAGER.sceneObject.eventoScrivValue = [sceneButton.postCond rangeOfString:@"evento(scriv,true)"].location != NSNotFound ? YES : NO;

        DATAMANAGER.sceneObject.oggettoFotoValue = [sceneButton.postCond rangeOfString:@"oggetto(foto,true)"].location != NSNotFound ? YES : NO;

        DATAMANAGER.sceneObject.oggettoDiarValue = [sceneButton.postCond rangeOfString:@"oggetto(diar,true)"].location != NSNotFound ? YES : NO;

        DATAMANAGER.sceneObject.eventoDiarletValue = [sceneButton.postCond rangeOfString:@"evento(diarlet,true)"].location != NSNotFound ? YES : NO;

        DATAMANAGER.sceneObject.eventoLitigioValue = [sceneButton.postCond rangeOfString:@"evento(litigio,true)"].location != NSNotFound ? YES : NO;

        DATAMANAGER.sceneObject.eventoLampValue = [sceneButton.postCond rangeOfString:@"evento(lamp,true)"].location != NSNotFound ? YES : NO;

        DATAMANAGER.sceneObject.oggettoBigliettoValue = [sceneButton.postCond rangeOfString:@"oggetto(biglietto,true)"].location != NSNotFound ? YES : NO;


        [self showSceneView:[sceneButton.targetId intValue]];
    }
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}

#pragma mark - Memory Managment

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)viewDidUnload {
    [super viewDidUnload];
}

@end

Commits for Nextrek/iOS/StoryBoard/StoryBoard/VC/iPhone/DimensioneParallelaVC.m

Diff revisions: vs.
Revision Author Commited Message
69 FAquili picture FAquili Thu 23 Jan, 2014 14:40:00 +0000

Storyboard real