/[hegemonie]/hegemonie/MapEditor/MapController.m
ViewVC logotype

Diff of /hegemonie/MapEditor/MapController.m

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by gabby, Wed Aug 6 16:27:12 2003 UTC revision 1.7 by gabby, Thu Aug 14 15:20:33 2003 UTC
# Line 24  Line 24 
24  #include <AppKit/AppKit.h>  #include <AppKit/AppKit.h>
25  #include <AppKit/NSWindow.h>  #include <AppKit/NSWindow.h>
26  #include <AppKit/NSEvent.h>  #include <AppKit/NSEvent.h>
27    #include <AppKit/NSControl.h>
28    #include <AppKit/NSSlider.h>
29    #include <AppKit/NSProgressIndicator.h>
30  #include <Foundation/NSString.h>  #include <Foundation/NSString.h>
31  #include <Foundation/NSArray.h>  #include <Foundation/NSArray.h>
32    
# Line 65  Line 68 
68  {  {
69    self = [super init];    self = [super init];
70    _display = NO;    _display = NO;
   _enableTexture = YES;  
71    _editingMap = NO;    _editingMap = NO;
72      _moveMap = NO;
73    [_mapView setEditMap: _editingMap];    [_mapView setEditMap: _editingMap];
   //  _addLand = YES;  
   _sliderNbElements = 30;  
   _sliderSlope = 1;  
74    
75      //[_progressIndicator setDoubleValue: 0.0];
76    _texturesName = @"Map_default/Tex0.png";    _texturesName = @"Map_default/Tex0.png";
77    _colorsName = @"Map_default/sunrise.tiff";    _colorsName = @"Map_default/sunrise.tiff";
78    printf ("INIT MapController\n");    printf ("INIT MapController\n");
# Line 148  Line 149 
149      {      {
150        _display = NO;        _display = NO;
151        [_mapView displayTerrain: NO];        [_mapView displayTerrain: NO];
       //NSLog (@"_windows %@\n", _window);  
       //[_window makeFirstResponder: self];  
152    
153        if (!_mapModel)        if (!_mapModel)
154          _mapModel = [[MapModel alloc] init];          _mapModel = [[MapModel alloc] init];
# Line 238  Line 237 
237    [_panelSandHeapMap close];    [_panelSandHeapMap close];
238  }  }
239    
240    - (void) computeShadows: (id)sender
241    {
242      if (_display)
243        {
244          [_mapView displayTerrain: NO];
245    
246          [NSBundle loadNibNamed: @"MapShadowsPanel.gorm" owner: self];
247          //[_progressIndicator startAnimation: self];
248          //[_progressIndicator setStyle: NSProgressIndicatorBarStyle];
249          //[_progressIndicator setStyle: NSProgressIndicatorSpinningStyle];
250          [_progressIndicator setDoubleValue: 0.0];
251      //     [_map computeMapShadow: @"saveShadows.tiff"
252    //                   withSun: MakeCoord (0.0, 350.0, 0.0)
253    //                       and: _progressIndicator];
254          //[_progressIndicator stopAnimation: self];
255     //      [_map setTexture: NO];
256    //       _enableTexture = NO;
257    //       [_mapView displayTerrain: YES];
258          [NSApp runModalForWindow: _panelComputingShadows];
259    
260        }
261    }
262    
263    - (void) shadowsOkButton: (id)sender
264    {
265      printf ("ici\n");
266      //[_progressIndicator setDoubleValue: 0.0];
267      //[_progressIndicator startAnimation: self];
268      [_map computeMapShadow: @"saveShadows.tiff"
269                     withSun: MakeCoord (0.0, 350.0, 0.0)
270                         and: _progressIndicator];
271      //[_progressIndicator stopAnimation: self];
272      [NSApp stopModal];
273      [_panelComputingShadows close];
274    
275      [_map setTexture: NO];
276      _enableTexture = NO;
277      [_mapView displayTerrain: YES];
278    }
279    
280    - (void) shadowsCancelButton: (id)sender
281    {
282      [NSApp abortModal];
283      [_panelComputingShadows close];
284    }
285    
286    
287    - (void) saveMapToFile: (id)sender
288    {
289      if (_mapView)
290        if (![_map saveHeightFieldToFile: @"saveMap.tiff"])
291           NSRunAlertPanel(@"Warning!",
292                           @"Could not save the file !!",
293                           @"OK", nil, nil);
294    }
295    
296  /**  /**
297   * Create the color panel.   * Create the color panel.
298   */   */
# Line 319  Line 374 
374   */   */
375  - (void) changeView: (id)sender  - (void) changeView: (id)sender
376  {  {
377      [_mapView displayTerrain: NO];
378    _viewTop = !_viewTop;    _viewTop = !_viewTop;
379    [_mapView setViewTop: _viewTop];    [_mapView setViewTop: _viewTop];
380      _moveMap = NO;
381      [_mapView setMoveMap: _moveMap];
382    
383    coord_t eye = [_camera eye];    coord_t eye = [_camera eye];
384    
# Line 329  Line 387 
387    else    else
388      eye.y = 256.0;      eye.y = 256.0;
389    
390      //TEST_RELEASE (_camera);
391    
392    if (_viewTop)    if (_viewTop)
393      [_camera initWithFovy: 50.0      [_camera initWithFovy: 50.0
394                     aspect: 1.0                     aspect: 1.0
# Line 350  Line 410 
410    if (!_viewTop)    if (!_viewTop)
411      [_mapView setFogParameter];      [_mapView setFogParameter];
412    [_mapView reshape];    [_mapView reshape];
413      [_mapView displayTerrain: YES];
414    }
415    
416    - (void) _moveCameraForEditing
417    {
418      [_mapView displayTerrain: NO];
419      _viewTop = YES;
420      [_mapView setViewTop: _viewTop];
421    
422      coord_t eye;
423      eye.x = (double) ([_map xLength]) / 2.0;
424      eye.y = (double) (MAX([_map xLength],[_map zLength]) + 550)
425        / tan(DEGTORAD (50.0));
426      eye.z = (double) ([_map zLength]) / 2.0;
427    
428      //TEST_RELEASE (_camera);
429      [_camera initWithFovy: 50.0
430                     aspect: 1.0
431                      zNear: 5.0
432                       zFar: 100000.0
433                        eye: eye
434                     center: MakeCoord (eye.x, eye.y - 10.0, eye.z)
435                         up: MakeCoord (1.0, 0.0, 0.0)];
436    
437      [_mapView setCamera: _camera];
438      [_mapView reshape];
439  }  }
440    
441  /**  /**
# Line 365  Line 451 
451      }      }
452  }  }
453    
454    /*
455     * For editing the map.
456     */
457  - (void) editMap: (id)sender  - (void) editMap: (id)sender
458  {  {
459    _editingMap = !_editingMap;    if (_mapModel)
460    [_mapView setEditMap: _editingMap];      {
461          _editingMap = !_editingMap;
462          _moveMap = NO;
463    
464          if (_editingMap)
465            [self _moveCameraForEditing];
466    
467          [_mapView setEditMap: _editingMap];
468          [_mapView setMoveMap: _moveMap];
469          [_mapView displayTerrain: YES];
470        }
471    }
472    
473    /*
474     * For moving the map with the mouse.
475     */
476    - (void) moveMap: (id)sender
477    {
478      if (_mapModel)
479        {
480          _moveMap = !_moveMap;
481    
482          if (_moveMap)
483            {
484              _editingMap = NO;
485              [self _moveCameraForEditing];
486              [_mapView setEditMap: _editingMap];
487              [_mapView setMoveMap: _moveMap];
488              [_mapView displayTerrain: YES];
489            }
490          else
491            [_mapView setMoveMap: _moveMap];
492        }
493  }  }
494    
495  - (void) addLand: (id)sender  - (void) addLand: (id)sender
# Line 377  Line 498 
498      {      {
499        map_coord_t position = [_mapView positionOnTerrain];        map_coord_t position = [_mapView positionOnTerrain];
500        u_int8_t height = [_map heightAtPosition: position];        u_int8_t height = [_map heightAtPosition: position];
501        if (height + _sliderNbElements <= 255)        if (height + [_sliderNbElements intValue] <= 255)
502          height += _sliderNbElements;          height += [_sliderNbElements intValue];
503          else
504            height = 255;
505        [_map setHeightAtPosition: position        [_map setHeightAtPosition: position
506                         toHeight: height];                         toHeight: height];
507      }      }
# Line 390  Line 513 
513      {      {
514        map_coord_t position = [_mapView positionOnTerrain];        map_coord_t position = [_mapView positionOnTerrain];
515        u_int8_t height = [_map heightAtPosition: position];        u_int8_t height = [_map heightAtPosition: position];
516        if (height - _sliderNbElements >= 0)        if (height - [_sliderNbElements intValue] >= 0)
517          height -= _sliderNbElements;          height -= [_sliderNbElements intValue];
518          else
519            height = 0;
520        [_map setHeightAtPosition: position        [_map setHeightAtPosition: position
521                         toHeight: height];                         toHeight: height];
522      }      }
# Line 402  Line 527 
527    if ((_map != nil) & _editingMap)    if ((_map != nil) & _editingMap)
528      {      {
529        int i;        int i;
530        for (i = 0; i < _sliderNbElements; i++)        printf ("add sand %d\n", [_sliderNbElements intValue]);
531          for (i = 0; i < [_sliderNbElements intValue]; i++)
532          [MapSandHeap addSand: _map          [MapSandHeap addSand: _map
533                    atPosition: [_mapView positionOnTerrain]                    atPosition: [_mapView positionOnTerrain]
534                         slope: _sliderSlope];                         slope: [_sliderSlope intValue]];
535      }      }
536  }  }
537    
# Line 414  Line 540 
540    if ((_map != nil) & _editingMap)    if ((_map != nil) & _editingMap)
541      {      {
542        int i;        int i;
543        for (i = 0; i < _sliderNbElements; i++)        for (i = 0; i < [_sliderNbElements intValue]; i++)
544          [MapSandHeap subSand: _map          [MapSandHeap subSand: _map
545                    atPosition: [_mapView positionOnTerrain]                    atPosition: [_mapView positionOnTerrain]
546                         slope: _sliderSlope];                         slope: [_sliderSlope intValue]];
547      }      }
548  }  }
549    
# Line 523  Line 649 
649              }              }
650            break;            break;
651    
652            case 'k':
653              [_map setShadow: NO];
654              break;
655            case 'K':
656              [_map setShadow: YES];
657              break;
658    
659            case 'Q':
660              [NSApp terminate: nil];
661              break;
662    
663          default:          default:
664            [self _printKeys];            [self _printKeys];
665            break;            break;
# Line 530  Line 667 
667      }      }
668  }  }
669    
 // - (BOOL) becomeFirstResponder  
 // {  
 //   printf ("becomeFirstResponder\n");  
 //   return YES;  
 // }  
   
 // - (BOOL) acceptsFirstResponder  
 // {  
 //   printf ("acceptsFirstResponder\n");  
 //   return YES;  
 // }  
   
 // - (BOOL) performKeyEquivalent: (NSEvent *)theEvent  
 // {  
 //   printf ("performKeyEquivalent:\n");  
   
 //   return YES;  
 // }  
   
 // - (void) mouseDown: (NSEvent *)theEvent  
 // {  
 //   printf ("mouseDown:\n");  
 // }  
   
670  @end  @end

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26