Gui/OutfitMenuController.m

00001 //
00002 //  OutfitMenuController.m
00003 //  MacTrek
00004 //
00005 //  Created by Aqua on 27/05/2006.
00006 //  Copyright 2006 Luky Soft. All rights reserved.
00007 //
00008 
00009 #import "OutfitMenuController.h"
00010 
00011 
00012 @implementation OutfitMenuController
00013 
00014 char teamMask = 0xFF;
00015 Universe *universe = nil;
00016 
00017 // this we should not do, let the user make a choice (esp. when FED is blocked) $$
00018 // thus start empty and disable the play button
00019 char myTeam = TEAM_FED;
00020 char myship = SHIP_CA;
00021 
00022 - (id) init {
00023     self = [super init];
00024     if (self != nil) {
00025         // the server will send SP_MASK to tell us in which team we are welcome
00026         [notificationCenter addObserver:self selector:@selector(handleTeamMask:) name:@"SP_MASK" object:nil];
00027         universe = [Universe defaultInstance];
00028     }
00029     return self;
00030 }
00031 
00032 - (void) awakeFromNib { 
00033     NSLog(@"OutfitMenuController.awakeFromNib reached");
00034 }
00035 
00036 - (void) handleTeamMask:(NSNumber *) mask{
00037     
00038     char newTeamMask = [mask charValue];
00039     if (newTeamMask != teamMask) {
00040         
00041         // $$ hmm teamMask seems to shifted, Kli becomes Rom etc..
00042         
00043         // store the mask
00044         teamMask = newTeamMask;
00045         
00046         // check
00047         if (universe == nil) {
00048             NSLog(@"OutfitMenuController.handleTeamMask NO ! my universe is too small");
00049             return;
00050         }
00051         
00052         // enable or disable buttons
00053         Team *team;
00054         bool open;       
00055         
00056         team = [universe teamWithId:TEAM_FED];
00057         open = (([team bitMask] & teamMask) != 0);
00058         [fedButton setEnabled:open];        
00059         [fedButton setTitle:[NSString stringWithFormat:@"%d\nFederation", [team count]]];
00060         
00061         team = [universe teamWithId:TEAM_KLI];
00062         open = (([team bitMask] & teamMask) != 0);
00063         [kliButton setEnabled:open];
00064         [kliButton setTitle:[NSString stringWithFormat:@"%d\nKlingon", [team count]]];
00065         
00066         team = [universe teamWithId:TEAM_ORI];
00067         open = (([team bitMask] & teamMask) != 0);
00068         [oriButton setEnabled:open];
00069         [oriButton setTitle:[NSString stringWithFormat:@"%d\nOrion", [team count]]];
00070         
00071         team = [universe teamWithId:TEAM_ROM];
00072         open = (([team bitMask] & teamMask) != 0);
00073         [romButton setEnabled:open];       
00074         [romButton setTitle:[NSString stringWithFormat:@"%d\nRomulan", [team count]]];
00075     }    
00076 }
00077 
00078 - (IBAction)selectTeam:(id)sender {
00079 
00080     // check if the player is really selecting
00081     // or deselecting
00082     if ([sender state] == NSOffState) {
00083         // no way
00084         [sender setState:NSOnState];
00085     }
00086     
00087     // deselect all other buttons
00088     // and set the selected team
00089     if (sender != fedButton) {
00090         [fedButton setState: NSOffState];
00091     } else {
00092         myTeam = TEAM_FED;
00093     }
00094     if (sender != romButton) {
00095         [romButton setState: NSOffState];
00096     } else {
00097         myTeam = TEAM_ROM;
00098     }
00099     if (sender != kliButton) {
00100         [kliButton setState: NSOffState];
00101     } else {
00102         myTeam = TEAM_KLI;
00103     }
00104     if (sender != oriButton) {
00105         [oriButton setState: NSOffState];
00106     } else {
00107         myTeam = TEAM_ORI;
00108     }
00109 }
00110 
00111 - (IBAction)selectShip:(id)sender {
00112     // deselect all other buttons
00113     // and set the selected ship
00114     if (sender != scButton) {
00115         [scButton setState: NSOffState];
00116     } else {
00117         myship = SHIP_SC;
00118     }    
00119     if (sender != ddButton) {
00120         [ddButton setState: NSOffState];
00121     } else {
00122         myship = SHIP_DD;
00123     }    
00124     if (sender != caButton) {
00125         [caButton setState: NSOffState];
00126     } else {
00127         myship = SHIP_CA;
00128     }    
00129     if (sender != bbButton) {
00130         [bbButton setState: NSOffState];
00131     } else {
00132         myship = SHIP_BB;
00133     }    
00134     if (sender != asButton) {
00135         [asButton setState: NSOffState];
00136     } else {
00137         myship = SHIP_AS;
00138     }    
00139     if (sender != sbButton) {
00140         [sbButton setState: NSOffState];
00141     } else {
00142         myship = SHIP_SB;
00143     }  
00144 }
00145 
00146 - (IBAction)play:(id)sender {
00147     
00148     // ask if this is a valid team for me
00149     // note: team is minus one $$
00150     [notificationCenter postNotificationName:@"COMM_SEND_TEAM_REQ" 
00151                                       object:nil 
00152                                     userInfo:[NSDictionary dictionaryWithObjectsAndKeys: 
00153                                         [NSNumber numberWithChar:(myTeam - 1)] , @"team",
00154                                         [NSNumber numberWithChar:myship] , @"ship", 
00155                                         nil]];
00156     
00157     // server responds with SP_PICKOK
00158     // or SP_PICKNOK the latter should deselect all choices
00159     // $$ check outfit
00160 }
00161 
00162 - (void) setInstructionFieldToDefault {
00163     [self setInstructionField:@"-"];
00164 }
00165 
00166 - (void) setInstructionField:(NSString *)message {
00167     
00168     if (messageTextField == nil) { // very strange, we get called by nibInstantiate asm code before we awoke..
00169         return;
00170     }
00171     
00172     if ([[messageTextField stringValue] isEqualToString:message]) {
00173         return; // no need to update
00174     }
00175     [messageTextField setStringValue:message]; 
00176 }
00177 
00178 @end

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