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

  1. //
  2. // $Id: StatusController.m,v 1.7 1997/10/31 04:52:09 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: StatusController.m,v 1.7 1997/10/31 04:52:09 nygard Exp $");
  30.  
  31. #import "StatusController.h"
  32.  
  33. #import "GameManager.h"
  34.  
  35. //======================================================================
  36. // We need some visual representation of a game in progress, since one
  37. // instance of the application can host a game of three remote players,
  38. // and there would otherwise be no way of knowing when the game was
  39. // over.
  40. //======================================================================
  41.  
  42. #define StatusController_VERSION 1
  43.  
  44. @implementation StatusController
  45.  
  46. + (void) initialize
  47. {
  48.     if (self == [StatusController class])
  49.     {
  50.         [self setVersion:StatusController_VERSION];
  51.     }
  52. }
  53.  
  54. //----------------------------------------------------------------------
  55.  
  56. - initWithGameManager:(GameManager *)theGameManager
  57. {
  58.     NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
  59.     NSString *nibFile;
  60.     BOOL loaded;
  61.  
  62.     [super init];
  63.  
  64.     nibFile = @"GameStatus.nib";
  65.     loaded = [NSBundle loadNibNamed:nibFile owner:self];
  66.     if (loaded == NO)
  67.     {
  68.         NSLog (@"Could not load %@.", nibFile);
  69.         [super dealloc];
  70.         return nil;
  71.     }
  72.  
  73.     // The game manager owns the status controller.
  74.     gameManager = theGameManager;
  75.  
  76.     [self updateCurrentTurn];
  77.     [self updateGameStatus];
  78.     [self updatePlayerTable];
  79.  
  80.     [defaultCenter addObserver:self
  81.                    selector:@selector (updateGameStatus)
  82.                    name:EMGameStateChangedNotification
  83.                    object:gameManager];
  84.  
  85.     [defaultCenter addObserver:self
  86.                    selector:@selector (updateCurrentTurn)
  87.                    name:EMTurnChangedNotification
  88.                    object:gameManager];
  89.  
  90.     [defaultCenter addObserver:self
  91.                    selector:@selector (updatePlayerTable)
  92.                    name:EMPlayerStateChangedNotification
  93.                    object:gameManager];
  94.  
  95.     return self;
  96. }
  97.  
  98. //----------------------------------------------------------------------
  99.  
  100. - (void) dealloc
  101. {
  102.     [[NSNotificationCenter defaultCenter] removeObserver:self];
  103.     SNRelease (statusWindow);
  104.  
  105.     [super dealloc];
  106. }
  107.  
  108. //----------------------------------------------------------------------
  109.  
  110. - (void) showPanel
  111. {
  112.     [statusWindow orderFront:self];
  113. }
  114.  
  115. //----------------------------------------------------------------------
  116.  
  117. - (void) stopGame:sender
  118. {
  119.     if (gameManager != nil)
  120.         [gameManager stopGame];
  121. }
  122.  
  123. //----------------------------------------------------------------------
  124.  
  125. - (void) updateCurrentTurn
  126. {
  127.     [currentTurnTextfield setIntValue:[gameManager turnNumber]];
  128. }
  129.  
  130. //----------------------------------------------------------------------
  131.  
  132. - (void) updateGameStatus
  133. {
  134.     [gameStateTextfield setStringValue:[gameManager gameStatus]];
  135. }
  136.  
  137. //----------------------------------------------------------------------
  138.  
  139. - (void) updatePlayerTable
  140. {
  141.     [playerTable reloadData];
  142. }
  143.  
  144. //----------------------------------------------------------------------
  145.  
  146. - (BOOL) validateMenuItem:(NSMenuItem *)menuCell
  147. {
  148.     BOOL valid = NO;
  149.  
  150.     if (gameManager != nil)
  151.         valid = [gameManager validateMenuItem:menuCell];
  152.  
  153.     return valid;
  154. }
  155.  
  156. //======================================================================
  157. // NSTable Data Source
  158. //======================================================================
  159.  
  160. - (int) numberOfRowsInTableView:(NSTableView *)aTableView
  161. {
  162.     return 3;
  163. }
  164.  
  165. //----------------------------------------------------------------------
  166.  
  167. - tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
  168. {
  169.     NSString *identifier;
  170.     id tmp;
  171.  
  172.     tmp = nil;
  173.     identifier = [aTableColumn identifier];
  174.  
  175.     if ([identifier isEqualToString:@"Player"] == YES)
  176.     {
  177.         tmp = [NSNumber numberWithInt:rowIndex + 1];
  178.     }
  179.     else
  180.     {
  181.         if (gameManager != nil)
  182.             tmp = [[gameManager playerStatus:rowIndex + 1] objectForKey:identifier];;
  183.     }
  184.  
  185.     return tmp;
  186. }
  187.  
  188. @end
  189.