cocoaTouch/MapConfigViewController.m
changeset 3374 0d522416d97f
parent 3373 c1ff724a5c34
child 3385 361bd29293f4
equal deleted inserted replaced
3373:c1ff724a5c34 3374:0d522416d97f
    33 	return SDLNet_TCP_Send(csd, [string UTF8String], length);
    33 	return SDLNet_TCP_Send(csd, [string UTF8String], length);
    34 }
    34 }
    35 
    35 
    36 -(void) engineProtocol:(NSInteger) port {
    36 -(void) engineProtocol:(NSInteger) port {
    37 	IPaddress ip;
    37 	IPaddress ip;
    38 	BOOL clientQuit, serverQuit;
    38 	BOOL serverQuit = NO;
    39 
    39     
    40     serverQuit = NO;
       
    41     clientQuit =NO;
       
    42 	if (SDLNet_Init() < 0) {
    40 	if (SDLNet_Init() < 0) {
    43 		NSLog(@"SDLNet_Init: %s", SDLNet_GetError());
    41 		NSLog(@"SDLNet_Init: %s", SDLNet_GetError());
    44         serverQuit = YES;
    42         serverQuit = YES;
    45 	}
    43 	}
    46 	
    44 	
    92     pthread_create(&thread_id, NULL, (void *)GenLandPreview, (void *)port);
    90     pthread_create(&thread_id, NULL, (void *)GenLandPreview, (void *)port);
    93     [self engineProtocol:port];
    91     [self engineProtocol:port];
    94 
    92 
    95     // draw the buffer (1 pixel per component, 0= transparent 1= color)
    93     // draw the buffer (1 pixel per component, 0= transparent 1= color)
    96     int xc = 0;
    94     int xc = 0;
    97     int yc = 0;
    95     int yc = -1;
    98     UIGraphicsBeginImageContext(CGSizeMake(256,128));      
    96     UIGraphicsBeginImageContext(CGSizeMake(256,128));      
    99     CGContextRef context = UIGraphicsGetCurrentContext();       
    97     CGContextRef context = UIGraphicsGetCurrentContext();       
   100     UIGraphicsPushContext(context);  
    98     UIGraphicsPushContext(context);  
   101     for (int i = 0; i < 32*128; i++) {
    99     for (int i = 0; i < 32*128; i++) {
   102         unsigned char byte = map[i];
   100         unsigned char byte = map[i];
   405             break;
   403             break;
   406     }
   404     }
   407     self.mapGenCommand = mapgen;
   405     self.mapGenCommand = mapgen;
   408     [self updatePreview];
   406     [self updatePreview];
   409     
   407     
   410     // nice animation for updating the table when needed
   408     // nice animation for updating the table when appropriate (on iphone)
   411     if (((oldPage == 0 || oldPage == 2) && newPage == 1) ||
   409     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
   412         (oldPage == 1 && (newPage == 0 || newPage == 2))) {
   410         if (((oldPage == 0 || oldPage == 2) && newPage == 1) ||
   413         [UIView beginAnimations:@"moving out table" context:NULL];
   411             (oldPage == 1 && (newPage == 0 || newPage == 2))) {
   414         self.tableView.frame = CGRectMake(480, 0, 185, 276);
   412             [UIView beginAnimations:@"moving out table" context:NULL];
   415         [UIView commitAnimations];
   413             self.tableView.frame = CGRectMake(480, 0, 185, 276);
   416         [self performSelector:@selector(moveTable) withObject:nil afterDelay:0.2];
   414             [UIView commitAnimations];
   417     }
   415             [self performSelector:@selector(moveTable) withObject:nil afterDelay:0.2];
       
   416         }
   418     oldPage = newPage;
   417     oldPage = newPage;
   419 }
   418 }
   420 
   419 
   421 // update data when table is not visible and then show it
   420 // update data when table is not visible and then show it
   422 -(void) moveTable {
   421 -(void) moveTable {
   455     self.segmentedControl.selectedSegmentIndex = 0;
   454     self.segmentedControl.selectedSegmentIndex = 0;
   456 
   455 
   457     self.templateFilterCommand = @"e$template_filter 0";
   456     self.templateFilterCommand = @"e$template_filter 0";
   458     self.mazeSizeCommand = @"e$maze_size 0";
   457     self.mazeSizeCommand = @"e$maze_size 0";
   459     self.mapGenCommand = @"e$mapgen 0";
   458     self.mapGenCommand = @"e$mapgen 0";
       
   459     self.lastIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
   460     
   460     
   461     oldValue = 5;
   461     oldValue = 5;
   462     oldPage = 0;
   462     oldPage = 0;
   463 }
   463 }
   464 
   464