home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / OPENSTEP / Games / Empire-0.6-MIS / WorldMapController.m < prev    next >
Encoding:
Text File  |  1997-10-30  |  5.0 KB  |  195 lines

  1. //
  2. // $Id: WorldMapController.m,v 1.9 1997/10/31 04:52:15 nygard Exp $
  3. //
  4.  
  5. //
  6. //  This file is a part of Empire, a game of exploration and conquest.
  7. //  Copyright (C) 1996  Steve Nygard
  8. //
  9. //  This program is free software; you can redistribute it and/or modify
  10. //  it under the terms of the GNU General Public License as published by
  11. //  the Free Software Foundation; either version 2 of the License, or
  12. //  (at your option) any later version.
  13. //
  14. //  This program is distributed in the hope that it will be useful,
  15. //  but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. //  GNU General Public License for more details.
  18. //
  19. //  You should have received a copy of the GNU General Public License
  20. //  along with this program; if not, write to the Free Software
  21. //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. //
  23. //  You may contact the author by:
  24. //     e-mail:  nygard@telusplanet.net
  25. //
  26.  
  27. #import "Empire.h"
  28.  
  29. RCSID ("$Id: WorldMapController.m,v 1.9 1997/10/31 04:52:15 nygard Exp $");
  30.  
  31. #import "WorldMapController.h"
  32.  
  33. #import "EmpireImageVendor.h"
  34. #import "EmPlayer.h"
  35. #import "GameManager.h"
  36. #import "Unit.h"
  37. #import "WorldMapView.h"
  38.  
  39. static int panelCount = 0;
  40.  
  41. //======================================================================
  42. // The WorldMapController loads the World Map window, and passes
  43. // messages from the world map view along to the delegate.
  44. //
  45. // That may be a little redundant, and the setDelegate could just
  46. // set the delegate of the WorldMapView...
  47. //======================================================================
  48.  
  49. #define WorldMapController_VERSION 1
  50.  
  51. @implementation WorldMapController
  52.  
  53. + (void) initialize
  54. {
  55.     if (self == [WorldMapController class])
  56.     {
  57.         [self setVersion:WorldMapController_VERSION];
  58.     }
  59. }
  60.  
  61. //----------------------------------------------------------------------
  62.  
  63. - (void) awakeFromNib
  64. {
  65.     NSString *imagePath;
  66.     NSImage *image;
  67.  
  68.     imagePath = [[NSBundle mainBundle] pathForImageResource:@"mwi_world_map.tiff"];
  69.     NSAssert (imagePath != nil, @"Couldn't find mwi_world_map.tiff");
  70.  
  71.     image = [[[NSImage alloc] initWithContentsOfFile:imagePath] autorelease];
  72.     NSAssert (image != nil, @"Couldn't load mwi_world_map.tiff");
  73.  
  74.     [worldMapWindow setMiniwindowImage:image];
  75. }
  76.  
  77. //----------------------------------------------------------------------
  78.  
  79. - init
  80. {
  81.     NSString *nibFile;
  82.     BOOL loaded;
  83.     NSRect frameRect;
  84.  
  85.     [super init];
  86.  
  87.     worldMapView = nil;
  88.  
  89.     nibFile = @"WorldMap.nib";
  90.     loaded = [NSBundle loadNibNamed:nibFile owner:self];
  91.     if (loaded == NO)
  92.     {
  93.         NSLog (@"Could not load %@.", nibFile);
  94.         [super dealloc];
  95.         return nil;
  96.     }
  97.  
  98.     frameRect = [worldMapWindow frame];
  99.     frameRect.origin.x += panelCount * 24;
  100.     frameRect.origin.y -= panelCount * 24;
  101.     [worldMapWindow setFrameOrigin:frameRect.origin];
  102.  
  103.     panelCount = (panelCount + 1) % 5;
  104.  
  105.     return self;
  106. }
  107.  
  108. //----------------------------------------------------------------------
  109.  
  110. - (void) dealloc
  111. {
  112.     SNRelease (worldMapWindow);
  113.  
  114.     [super dealloc];
  115. }
  116.  
  117. //----------------------------------------------------------------------
  118.  
  119. - (void) setMap:(Map *)aMap
  120. {
  121.     [worldMapView setMap:aMap];
  122. }
  123.  
  124. //----------------------------------------------------------------------
  125.  
  126. - (void) setDelegate:newDelegate
  127. {
  128.     delegate = newDelegate;
  129.  
  130.     if (delegate == nil)
  131.         [worldMapWindow setDelegate:self];
  132.     else
  133.         [worldMapWindow setDelegate:delegate];
  134. }
  135.  
  136. //----------------------------------------------------------------------
  137.  
  138. - (void) setTitle:(NSString *)newTitle autosaveFrame:(BOOL)autosaveFlag
  139. {
  140.     BOOL okay;
  141.  
  142.     [worldMapWindow setTitle:newTitle];
  143.     if (autosaveFlag == YES)
  144.     {
  145.         okay = [worldMapWindow setFrameAutosaveName:newTitle];
  146.         if (okay == NO)
  147.             NSLog (@"Could not set frame autosave name of World Map panel.");
  148.     }
  149. }
  150.  
  151. //----------------------------------------------------------------------
  152.  
  153. - (void) showPanel
  154. {
  155.     [worldMapWindow makeKeyAndOrderFront:self];
  156. }
  157.  
  158. //======================================================================
  159. // MapView Delegate
  160. //======================================================================
  161.  
  162. - (void) mouseDown:(unsigned int)modifierFlags atLocation:(EMMapLocation)target
  163. {
  164.     if (delegate != nil)
  165.         [delegate mouseDown:modifierFlags atLocation:target];
  166. }
  167.  
  168. //----------------------------------------------------------------------
  169.  
  170. - (void) mouseUp:(unsigned int)modifierFlags atLocation:(EMMapLocation)target
  171. {
  172.     if (delegate != nil)
  173.         [delegate mouseUp:modifierFlags atLocation:target];
  174. }
  175.  
  176. //----------------------------------------------------------------------
  177.  
  178. - (void) rightMouseDown:(unsigned int)modifierFlags atLocation:(EMMapLocation)target
  179. {
  180. }
  181.  
  182. //----------------------------------------------------------------------
  183.  
  184. - (void) rightMouseUp:(unsigned int)modifierFlags atLocation:(EMMapLocation)target
  185. {
  186. }
  187.  
  188. //----------------------------------------------------------------------
  189.  
  190. - (void) keyDown:(NSEvent *)theEvent 
  191. {
  192. }
  193.  
  194. @end
  195.