/Volumes/Plantain/MyDocuments/Projects/MacTrek/MacTrek/App/PlayerListDataSource.m

00001 //
00002 //  PlayerListDataSource.m
00003 //  MacTrek
00004 //
00005 //  Created by Aqua on 02/06/2006.
00006 //  Copyright 2006 __MyCompanyName__. All rights reserved.
00007 //
00008 
00009 #import "PlayerListDataSource.h"
00010 
00011 
00012 @implementation PlayerListDataSource
00013 
00014 NSMutableArray *players = nil;
00015 
00016 - (id) init {
00017     self = [super init];
00018     if (self != nil) {
00019         universe = nil;
00020         players = [[NSMutableArray alloc] init];
00021         universe = [Universe defaultInstance];
00022         [self refreshData];
00023     }
00024     return self;
00025 }
00026 
00027 - (void) awakeFromNib {
00028     [notificationCenter addObserver:self selector:@selector(refreshData) name:@"SP_PLAYER_INFO"];   
00029 }
00030 
00031 // tie this to events that change players
00032 - (void) refreshData {
00033     
00034     // clean up
00035     [players removeAllObjects];
00036     
00037     // test for new
00038     if (universe == nil) {        
00039         return;
00040     }
00041     
00042     // find players
00043     for (int i = 0; i < UNIVERSE_MAX_PLAYERS; i++) {
00044         Player *player = [universe playerWithId:i];
00045         if ([player status] != PLAYER_FREE) {
00046             [players addObject:player];
00047             
00048         }        
00049     } 
00050     
00051     // show it
00052     // $$ performance hog, reload it not that often or make our own view....
00053     //[playerList reloadData];
00054 }
00055 
00056 - (int)numberOfRowsInTableView:(NSTableView *)aTableView {
00057     return [players count];
00058 }
00059 
00060 - (id)tableView:(NSTableView *)aTableView
00061     objectValueForTableColumn:(NSTableColumn *)aTableColumn
00062             row:(int)rowIndex {
00063     // get the player
00064     Player *player = [players objectAtIndex:rowIndex];
00065     
00066     if ([[aTableColumn identifier] isEqualToString:@"id"]) {
00067         return [player mapChars];        
00068     } else { // must be name
00069         return [player longName];
00070     }    
00071 }
00072 
00073 @end

Generated on Fri Jul 28 19:15:14 2006 for MacTrek by  doxygen 1.4.7