00001
00002
00003
00004
00005
00006
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];
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
00029 [notificationCenter addObserver:self selector:@selector(disableSelection) name:@"PV_PLAYER_SELECTION"];
00030
00031
00032 }
00033
00034
00035 - (void) newMessage:(NSString *)message {
00036
00037 if ((message == nil) ||
00038 ([message length] <= 0)) {
00039 return;
00040 }
00041
00042
00043
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
00053
00054 if ((message == nil) ||
00055 ([message length] <= 0)) {
00056 NSLog(@"MessagesListView.newMessageInDictionairy empty message");
00057 return;
00058 }
00059
00060
00061 NSColor *color = [NSColor grayColor];
00062 if (from >= 0 && from < UNIVERSE_MAX_PLAYERS) {
00063 color = [[[universe playerWithId:from] team] colorForTeam];
00064 }
00065
00066
00067 if (flags == (TEAM | DISTR | VALID)) {
00068
00069 NSLog(@"MessagesListView.newMessageInDictionairy distress not parsed.. (%@)", message);
00070 return;
00071
00072
00073
00074
00075
00076
00077
00078
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