Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Related Pages  

/home/rdbrown/doxygen/cse125g1/src/game/client/PlayerSlot.cpp

00001 #include "LobbyGS.h"
00002 #include "menu/widgets.h"
00003 
00004 using namespace MMGUI;
00005 
00006 PlayerSlot::PlayerSlot(Game *game, LobbyGS *parent, int slot, int x, int y) : Frame(x, y, SLOT_WIDTH, SLOT_HEIGHT) {
00007     this->parent = parent;
00008     this->game = game;                            
00009     this->slot = slot;
00010     
00011     setBorder(2);
00012     setMargin(1);
00013             
00014     nameField = new Textfield(WidgetAlignTop, SLOT_WIDTH - 6, 18);
00015     nameField->setBGColor(0.1, 0.1, 0.1);
00016     nameField->alignCenter();
00017     addChild(nameField);
00018     
00019     teamField = new Textfield(WidgetAlignBottom, SLOT_WIDTH - 6, 18);
00020     teamField->setBGColor(0.1, 0.1, 0.1);
00021     teamField->alignCenter();
00022     addChild(teamField);
00023     
00024     image = NULL;
00025     
00026     clear();
00027 }         
00028             
00029 void PlayerSlot::clear() {
00030     player = NULL;
00031     
00032     // Clear the fields
00033     nameField->clearText();
00034     teamField->clearText();
00035     
00036     setBorderColor(0.1, 0.1, 0.1);
00037     
00038     clearImage();
00039     
00040     last.valid = last.ready = false;
00041     last.team = TeamNone;
00042     last.model = PlayerModelNone;
00043 }
00044 
00045 bool PlayerSlot::isValid() { 
00046     return player != NULL; 
00047 };
00048         
00049 bool PlayerSlot::isReady() { 
00050     return last.ready; 
00051 }        
00052         
00053 bool PlayerSlot::isLocalPlayer() {                
00054     if(player != NULL) {
00055         return player->isLocalPlayer();
00056     }
00057     return false;
00058 }
00059 
00060 void PlayerSlot::update() {
00061 
00062     bool result = false;
00063     
00064     if(game->players.size() <= slot) {
00065         if(last.valid) {
00066             clear();
00067             glutPostRedisplay();
00068             return;
00069         }
00070         return;
00071     }
00072     
00073     if(last.valid == false || player != NULL) {
00074         player = game->players[slot];
00075         nameField->setText(player->getName());
00076         last.valid = true;
00077         result = true;
00078     }
00079     
00080     // Check if the team changed.
00081     if(player->getTeam() != last.team) {
00082         switch(player->getTeam()) {
00083             case TeamKnights:
00084                 teamField->setText("Knight");
00085                 break;
00086             case TeamThieves:
00087                 teamField->setText("Thief");
00088                 break;
00089             default:
00090                 teamField->clearText();
00091                 break;
00092         }
00093         last.team = player->getTeam();
00094         result = true;
00095     }
00096     
00097     // see if the ready state has changed.
00098     if(last.ready != player->isReady()) {
00099         last.ready = player->isReady();
00100         result = true;
00101     }
00102     
00103     // check if the player model changed.
00104     if(last.model != player->model) {
00105         last.model = player->model;
00106         switch(last.model) {
00107             case PlayerModelSheriff:
00108                 setImage(TEXTURE_HEADSHOT_SHERIFF); 
00109                 break; 
00110             case PlayerModelGuard:
00111                 setImage(TEXTURE_HEADSHOT_GUARD); 
00112                 break; 
00113             case PlayerModelRobinHood:
00114                 setImage(TEXTURE_HEADSHOT_ROBIN);
00115                 break; 
00116             case PlayerModelLittleJohn:
00117                 setImage(TEXTURE_HEADSHOT_LITTLEJOHN); 
00118                 break; 
00119             default:
00120                 clearImage();
00121                 break;                     
00122         }
00123         result = true;
00124     }
00125     
00126     if(result) {
00127         updateColors();
00128         glutPostRedisplay();
00129     }
00130 }
00131         
00132 bool PlayerSlot::isPlayer(MMNet::Player *player) {
00133     return this->player == player;
00134 }   
00135 
00136 void PlayerSlot::clearImage() {
00137     if(image != NULL) {
00138         removeChild(image);
00139         delete image;
00140         image = NULL;
00141     }
00142 }
00143 
00144 void PlayerSlot::setImage(GLuint texture) {
00145     clearImage();
00146     image = new Image(texture, WidgetAlignCenter, content_width(), content_height() - 40); 
00147     addChild(image);
00148 }
00149                
00150 void PlayerSlot::updateColors() {
00151     if(last.valid == false) {
00152         setBorderColor(0.1, 0.1, 0.1);
00153         // Grey out if not valid                    
00154         nameField->setBGColor(0.1, 0.1, 0.1);
00155         teamField->setBGColor(0.1, 0.1, 0.1);
00156         return;
00157     }
00158     
00159     // update the team field and the frames border to match the team
00160     if(last.team == TeamThieves) {
00161         setBorderColor(0.0, 0.5, 0.0);
00162         teamField->setBGColor(0.0, 0.5, 0.0);
00163     } else if(last.team == TeamKnights) {
00164         setBorderColor(0.5, 0.2, 0.0);
00165         teamField->setBGColor(0.5, 0.2, 0.0); 
00166     } else {
00167         setBorderColor(0.3, 0.3, 0.3);        
00168         teamField->setBGColor(0.3, 0.3, 0.3);                 
00169     }
00170 
00171     if(isLocalPlayer()) {                
00172         if(isReady()) {                    
00173             // If we're the local player and we're ready, use bright blue
00174             nameField->setBGColor(0.0, 0.0, 0.8);
00175         } else {
00176             // Otherwise, just a dim blue
00177             nameField->setBGColor(0.0, 0.0, 0.2);
00178         }
00179     } else {
00180         if(isReady()) {
00181             // If we're another player and we're ready, use bright green.
00182             nameField->setBGColor(0.0, 0.8, 0.0);
00183         } else {
00184             // If we're another player and we're ready, use bright green.
00185             nameField->setBGColor(0.0, 0.2, 0.0);
00186         }                
00187     }                        
00188 }
00189 

Generated on Thu Aug 18 16:03:08 2005 for Robin Hood: Thieves & Knights by doxygen1.2.18