Views/MessagesListView.m

00001 //
00002 //  MessagesListView.m
00003 //  MacTrek
00004 //
00005 //  Created by Aqua on 01/08/2006.
00006 //  Copyright 2006 Luky Soft. All rights reserved.
00007 //
00008 
00009 #import "MessagesListView.h"
00010 #import "MessageConstants.h"
00011 
00012 @implementation MessagesListView
00013 
00014 - (void) awakeFromNib {
00015     [super awakeFromNib];
00016     
00017     universe = [Universe defaultInstance];
00018 
00019     [notificationCenter addObserver:self selector:@selector(newMessage:) name:@"SP_S_MESSAGE" 
00020                              object:nil useLocks:NO useMainRunLoop:YES];
00021     [notificationCenter addObserver:self selector:@selector(newMessage:) name:@"PM_MESSAGE" 
00022                              object:nil useLocks:NO useMainRunLoop:NO]; // is already in main loop
00023     [notificationCenter addObserver:self selector:@selector(newMessage:) name:@"SPW_MESSAGE" 
00024                              object:nil useLocks:NO useMainRunLoop:YES];
00025     [notificationCenter addObserver:self selector:@selector(newMessageInDictionairy:) name:@"SP_MESSAGE" 
00026                              object:nil useLocks:NO useMainRunLoop:YES];    
00027     
00028     // user clicked on player list, disable our selection
00029     [notificationCenter addObserver:self selector:@selector(disableSelection) name:@"PV_PLAYER_SELECTION"];
00030     // user manually choose a destination, disable our selection
00031     // $$$ [notificationCenter addObserver:self selector:@selector(disableSelection) name:@""];
00032 }
00033 
00034 // tie this to events that change messages
00035 - (void) newMessage:(NSString *)message {
00036     
00037     if ((message == nil) ||
00038         ([message length] <= 0)) {        
00039         return;
00040     }
00041     
00042     // add it
00043 //    NSLog(@"MessagesListView.newMessage (%@)", message);
00044     [self addString:message];
00045 }
00046 
00047 - (void) newMessageInDictionairy:(NSDictionary*)package {
00048     
00049     NSString *message = [package objectForKey:@"message"];
00050     int flags   = [[package objectForKey:@"flags"] intValue];
00051     int from    = [[package objectForKey:@"from"] intValue];
00052     //int to      = [[package objectForKey:@"to"] intValue]; 
00053     
00054     if ((message == nil) ||
00055         ([message length] <= 0)) {
00056         NSLog(@"MessagesListView.newMessageInDictionairy empty message"); 
00057         return;
00058     }
00059     
00060     // find out the colour     
00061     NSColor *color = [NSColor grayColor];
00062     if (from >= 0 && from < UNIVERSE_MAX_PLAYERS) {
00063         color = [[[universe playerWithId:from] team] colorForTeam];
00064     }
00065         
00066     // A new type distress/macro call came in. parse it appropriately
00067     if (flags == (TEAM | DISTR | VALID)) {
00068         
00069         NSLog(@"MessagesListView.newMessageInDictionairy distress not parsed.. (%@)", message);
00070         return;
00071         /*
00072         Distress distress = new Distress(data, message, from);
00073         message = macro_handler.parseMacro(distress);
00074         if(message.length() < 0) {
00075             return;
00076         }
00077 
00078         flags ^= DISTR;
00079          */
00080     } 
00081     
00082     [self addString:message withColor:color];
00083 }
00084 
00085 - (void) newStringSelected:(NSString*)str { 
00086     [notificationCenter postNotificationName:@"MV_MESSAGE_SELECTION" object:self userInfo:str];
00087 }
00088 
00089 @end

Generated on Sat Aug 26 21:14:17 2006 for MacTrek by  doxygen 1.4.7