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

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

00001 //#include <stdlib.h>
00002 //#include <vector>
00003 //#include <iostream>
00004 //#include <assert.h>
00005 #include "scoremenu.h"
00006 //#include "textures.h"
00007 
00008 
00009 #define X_START_GUI_POSITION 100
00010 #define Y_START_GUI_POSITION 100
00011 #define MARGIN 5
00012 #define WIDTH 200
00013 #define HEIGHT 20
00014 #define FADE_DRAW 40;
00015 
00016 using namespace JMenu;
00017 
00018 static void quit(void) {
00019   exit(0);
00020 }
00021 
00022 static ScoreMenu * cm;
00023 static bool isTrogdor(const char * buff) {
00024         if (buff[0] == 'T') 
00025         if (buff[1] == 'r') 
00026         if (buff[2] == 'o') 
00027         if (buff[3] == 'g') 
00028         if (buff[4] == 'd') 
00029         if (buff[5] == 'o') 
00030         if (buff[6] == 'r') 
00031         if (buff[7] == '\0') 
00032                 return true;
00033         return false;
00034 }
00035 
00036 ScoreMenu::ScoreMenu(MMNet::Game * game) {
00037         buffer = new char[200];
00038         //isDraw = FADE_DRAW+1;
00039 
00040         x=X_START_GUI_POSITION;
00041         y=Y_START_GUI_POSITION;
00042 
00043         cm = this;
00044         this->game = game;    
00045         
00046         knightKills = 0;
00047         knightDeaths = 0;
00048         thiefKills = 0;
00049         thiefDeaths = 0;
00050 
00051         isDraw = DRAW_TIME_LIMIT+1;
00052     
00053 }
00054 void ScoreMenu::init() {
00055         //thisGS = this;
00056     //float winWidth = glutGet(GLUT_WINDOW_WIDTH);
00057     float winHeight = glutGet(GLUT_WINDOW_HEIGHT);
00058 
00059     //GameState::client->setCallbackObject(cb);
00060     
00061     //menuInit();
00062         //menuClear();
00063 
00064   
00065         //player statistics
00066         int size = game->players.size();
00067         Kills = new Textfield*[size];
00068     Deaths = new Textfield*[size];
00069     PlayerNames = new Textfield*[size];
00070 
00071 
00072         PlayerNames_tf = new Textfield(x,y+HEIGHT,HEIGHT, WIDTH, 0 ,0, .3, 1, 1,1,0, GLUT_BITMAP_8_BY_13, 13);
00073         //menuAddTextfield(x,y,WIDTH,HEIGHT, Vector3(0,0,.3), Vector3(1,1,0));
00074         PlayerNames_tf->writeText("Player's Name");
00075         x += WIDTH + MARGIN;
00076 
00077         Deaths_tf = new Textfield(x,y+HEIGHT,HEIGHT, WIDTH, 0 ,.3, 0, 1,           1,0,1, GLUT_BITMAP_8_BY_13, 13);
00078         //Deaths[0] = menuAddTextfield(x,y,WIDTH,HEIGHT, Vector3(0,.3,0), Vector3(1,0,1));
00079         Deaths_tf->writeText("Deaths");
00080         x += WIDTH + MARGIN;
00081         
00082         Kills_tf = new Textfield(x,y+HEIGHT,HEIGHT, WIDTH, .3 ,0, 0, 1,           0,1,1, GLUT_BITMAP_8_BY_13, 13);
00083         //menuAddTextfield(x,y,WIDTH,HEIGHT, Vector3(.3,0,0), Vector3(0,1,1));
00084         Kills_tf->writeText("Kills");
00085         x = X_START_GUI_POSITION;
00086         y += HEIGHT     + MARGIN;
00087 
00088         for (int i=0; i<game->players.size(); i++) {
00089                 PlayerNames[i] = new Textfield(x,y+HEIGHT,HEIGHT, WIDTH, 0 ,0, .3, 1,           1,1,0, GLUT_BITMAP_8_BY_13, 13);
00090                 //menuAddTextfield(x,y,WIDTH,HEIGHT, Vector3(0,0,.3), Vector3(1,1,0));
00091                 if (isTrogdor(game->players[i]->getName())) { //how lame!
00092                         sprintf(buffer, "%s", game->players[i]->getName());
00093                 } else if (game->players[i]->getTeam() == MMNet::TeamKnights) {
00094                         sprintf(buffer, "Knight %s", game->players[i]->getName());
00095                 } else if (game->players[i]->getTeam() == MMNet::TeamThieves) {
00096                         sprintf(buffer, "Thief %s", game->players[i]->getName());
00097                 } else {
00098                         sprintf(buffer, "%s", game->players[i]->getName());
00099                 }
00100                 PlayerNames[i]->writeText(buffer);
00101                 x += WIDTH + MARGIN;
00102 
00103                 Deaths[i] = new Textfield(x,y+HEIGHT,HEIGHT, WIDTH, 0 ,.3, 0, 1,           1,0,1, GLUT_BITMAP_8_BY_13, 13);
00104                 //menuAddTextfield(x,y,WIDTH,HEIGHT, Vector3(0,.3,0), Vector3(1,0,1));
00105                 sprintf(buffer, "%d", game->players[i]->getDeaths());
00106                 Deaths[i]->writeText(buffer);
00107 
00108                 x += WIDTH + MARGIN;
00109                 Kills[i] = new Textfield(x,y+HEIGHT,HEIGHT, WIDTH, .3 ,0, 0, 1,           0,1,1, GLUT_BITMAP_8_BY_13, 13);
00110                 //menuAddTextfield(x,y,WIDTH,HEIGHT, Vector3(.3,0,0), Vector3(0,1,1));
00111                 sprintf(buffer, "%d", game->players[i]->getKills());
00112                 Kills[i]->writeText(buffer);
00113                 x = X_START_GUI_POSITION;
00114                 y += HEIGHT     + MARGIN;
00115         }
00116 
00117         //team statistics
00118         for (int i=0; i<game->players.size(); i++) {
00119                 if (game->players[i]->isNPC()) {
00120                         otherKills += game->players[i]->getKills();
00121                         otherDeaths += game->players[i]->getDeaths();
00122                 } else if (game->players[i]->getTeam() == MMNet::TeamKnights) {
00123                         knightKills += game->players[i]->getKills();
00124                         knightDeaths += game->players[i]->getDeaths();
00125                 } else if (game->players[i]->getTeam() == MMNet::TeamThieves) {
00126                         thiefKills += game->players[i]->getKills();
00127                         thiefDeaths += game->players[i]->getDeaths();
00128                 } else {
00129                         otherKills += game->players[i]->getKills();
00130                         otherDeaths += game->players[i]->getDeaths();
00131                 }
00132         }
00133 
00134         x += WIDTH + MARGIN;
00135         y += HEIGHT     + MARGIN;
00136         deathsTitle_tf = new Textfield(x,y+HEIGHT,HEIGHT, WIDTH, 0 ,0, 0, 1,           0,1,0, GLUT_BITMAP_8_BY_13, 13);
00137         deathsTitle_tf->writeText("Total Deaths");
00138         //temp = menuAddTextfield(x,y,WIDTH,HEIGHT, Vector3(0,0,0), Vector3(0,1,0));
00139         //temp->writeText("Total Deaths");
00140 
00141         x += WIDTH + MARGIN;
00142         killsTitle_tf = new Textfield(x,y+HEIGHT,HEIGHT, WIDTH, 0 ,0, 0, 1,           1,0,0, GLUT_BITMAP_8_BY_13, 13);
00143         killsTitle_tf->writeText("Total Kills");
00144         //temp = menuAddTextfield(x,y,WIDTH,HEIGHT, Vector3(0,0,0), Vector3(1,0,0));
00145         //temp->writeText("Total Kills");
00146 
00147         //show the top killer:death ratio first nah i'm too lazy
00148         y += HEIGHT     + MARGIN;       
00149         x = X_START_GUI_POSITION;
00150         thiefTitle_tf = new Textfield(x,y+HEIGHT,HEIGHT, WIDTH, 0 ,0, 0, 1,           0,0,1, GLUT_BITMAP_8_BY_13, 13);
00151         //temp = menuAddTextfield(x,y,WIDTH,HEIGHT, Vector3(0,0,0), Vector3(0,0,1));
00152         //if (thiefKills/thiefDeaths > knightKills/knightDeaths) {
00153                 thiefTitle_tf->writeText("Thieves");
00154                 x += WIDTH + MARGIN;
00155                 thiefDeaths_tf = new Textfield(x,y+HEIGHT,HEIGHT, WIDTH, 0 ,0, 0, 1,           0,1,0, GLUT_BITMAP_8_BY_13, 13);
00156                 //menuAddTextfield(x,y,WIDTH,HEIGHT, Vector3(0,0,0), Vector3(0,1,0));
00157                 sprintf(buffer, "%d", thiefDeaths);
00158                 thiefDeaths_tf->writeText(buffer);
00159                 x += WIDTH + MARGIN;
00160                 thiefKills_tf = new Textfield(x,y+HEIGHT,HEIGHT, WIDTH, 0 ,0, 0, 1,           1,0,0, GLUT_BITMAP_8_BY_13, 13);
00161                 //menuAddTextfield(x,y,WIDTH,HEIGHT, Vector3(0,0,0), Vector3(1,0,0));
00162                 sprintf(buffer, "%d", thiefKills);
00163                 thiefKills_tf->writeText(buffer);
00164 
00165                 y += HEIGHT     + MARGIN;       
00166                 x = X_START_GUI_POSITION;
00167                 knightTitle_tf = new Textfield(x,y+HEIGHT,HEIGHT, WIDTH, 0 ,0, 0, 1,           0,0,1, GLUT_BITMAP_8_BY_13, 13);
00168                 //temp = menuAddTextfield(x,y,WIDTH,HEIGHT, Vector3(0,0,0), Vector3(0,0,1));
00169                 knightTitle_tf->writeText("Knights");
00170                 x += WIDTH + MARGIN;
00171                 knightDeaths_tf = new Textfield(x,y+HEIGHT,HEIGHT, WIDTH, 0 ,0, 0, 1,           0,1,0, GLUT_BITMAP_8_BY_13, 13);
00172                 //menuAddTextfield(x,y,WIDTH,HEIGHT, Vector3(0,0,0), Vector3(0,1,0));
00173                 sprintf(buffer, "%d", knightDeaths);
00174                 knightDeaths_tf->writeText(buffer);
00175                 x += WIDTH + MARGIN;
00176                 knightKills_tf = new Textfield(x,y+HEIGHT,HEIGHT, WIDTH, 0 ,0, 0, 1,           1,0,0, GLUT_BITMAP_8_BY_13, 13);
00177                 //menuAddTextfield(x,y,WIDTH,HEIGHT, Vector3(0,0,0), Vector3(1,0,0));
00178                 sprintf(buffer, "%d", knightKills);
00179                 knightKills_tf->writeText(buffer);
00180 
00181                 y += HEIGHT     + MARGIN;       
00182                 x = X_START_GUI_POSITION;
00183                 otherTitle_tf = new Textfield(x,y+HEIGHT,HEIGHT, WIDTH, 0 ,0, 0, 1,           0,0,1, GLUT_BITMAP_8_BY_13, 13);
00184                 //temp = menuAddTextfield(x,y,WIDTH,HEIGHT, Vector3(0,0,0), Vector3(0,0,1));
00185                 otherTitle_tf->writeText("Others");
00186                 x += WIDTH + MARGIN;
00187                 otherDeaths_tf = new Textfield(x,y+HEIGHT,HEIGHT, WIDTH, 0 ,0, 0, 1,           0,1,0, GLUT_BITMAP_8_BY_13, 13);
00188                 //menuAddTextfield(x,y,WIDTH,HEIGHT, Vector3(0,0,0), Vector3(0,1,0));
00189                 sprintf(buffer, "%d", otherDeaths);
00190                 otherDeaths_tf->writeText(buffer);
00191                 x += WIDTH + MARGIN;
00192                 otherKills_tf = new Textfield(x,y+HEIGHT,HEIGHT, WIDTH, 0 ,0, 0, 1,           1,0,0, GLUT_BITMAP_8_BY_13, 13);
00193                 //menuAddTextfield(x,y,WIDTH,HEIGHT, Vector3(0,0,0), Vector3(1,0,0));
00194                 sprintf(buffer, "%d", otherKills);
00195                 otherKills_tf->writeText(buffer);
00196 /*      } else {
00197                 temp->writeText("Knights");
00198                 x += WIDTH + MARGIN;
00199                 temp = menuAddTextfield(x,y,WIDTH,HEIGHT, Vector3(0,1,0), Vector3(0,0,0));
00200                 sprintf(buffer, "%d", knightDeaths);
00201                 temp->writeText(buffer);
00202                 x += WIDTH + MARGIN;
00203                 temp = menuAddTextfield(x,y,WIDTH,HEIGHT, Vector3(1,0,0), Vector3(0,0,0));
00204                 sprintf(buffer, "%d", knightKills);
00205                 temp->writeText(buffer);
00206 
00207                 y += HEIGHT     + MARGIN;       
00208                 x = X_START_GUI_POSITION;
00209                 temp = menuAddTextfield(x,y,WIDTH,HEIGHT, Vector3(0,0,1), Vector3(0,0,0));
00210                 temp->writeText("Thieves");
00211                 x += WIDTH + MARGIN;
00212                 temp = menuAddTextfield(x,y,WIDTH,HEIGHT, Vector3(0,1,0), Vector3(0,0,0));
00213                 sprintf(buffer, "%d", thiefDeaths);
00214                 temp->writeText(buffer);
00215                 x += WIDTH + MARGIN;
00216                 temp = menuAddTextfield(x,y,WIDTH,HEIGHT, Vector3(1,0,0), Vector3(0,0,0));
00217                 sprintf(buffer, "%d", thiefKills);
00218                 temp->writeText(buffer);
00219         }*/
00220 
00221     //menuAddButton(20, winHeight - 50, 
00222     //                          60, 30, 
00223     //                          TEXTURE_EXIT_BUTTON,TEXTURE_EXIT_BUTTON_ON,TEXTURE_EXIT_BUTTON_OVER, 
00224     //                          quit);   
00225 
00226 }
00227 
00228 
00229 
00230 
00231 
00232 void ScoreMenu::display(void) {
00233   //This stuff should probably be done in display
00234   //glClearColor(0,0,0,0); //must have black background
00235   //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00236 
00237   //menuRender();
00238 
00239         Kills_tf->draw();
00240     Deaths_tf->draw();
00241     PlayerNames_tf->draw();
00242 
00243   for (int i=0; i<numPlayers; i++) {
00244                 Kills[i]->draw();
00245         Deaths[i]->draw();
00246         PlayerNames[i]->draw();
00247   }
00248 
00249                 knightKills_tf->draw();
00250                 knightDeaths_tf->draw();
00251                 thiefKills_tf->draw();
00252                 thiefDeaths_tf->draw();
00253                 otherKills_tf->draw();
00254                 otherDeaths_tf->draw();
00255 
00256                 killsTitle_tf->draw();
00257                 deathsTitle_tf->draw();
00258                 knightTitle_tf->draw();
00259                 thiefTitle_tf->draw();
00260                 otherTitle_tf->draw();
00261 
00262 
00263   //glutSwapBuffers();
00264 }
00265 
00266 void ScoreMenu::update(void) {
00267         for (int i=0; i<game->players.size(); i++) {
00268                 sprintf(buffer, "%d", game->players[i]->getDeaths());
00269 
00270                 Deaths[i]->writeText(buffer);
00271                 sprintf(buffer, "%d", game->players[i]->getKills());
00272                 Kills[i]->writeText(buffer);
00273         }
00274         numPlayers = game->players.size();
00275 
00276         knightKills = 0;
00277         knightDeaths = 0;
00278         thiefKills = 0;
00279         thiefDeaths = 0;
00280         otherKills = 0;
00281         otherDeaths = 0;
00282 
00283         //team statistics
00284         for (int i=0; i<game->players.size(); i++) {
00285                 //if (game->players[i]->isNPC()) {
00286                 //sprintf(buffer,"%s", game->players[i]->getName())
00287                 if (isTrogdor(game->players[i]->getName())) { //how lame!
00288                         otherKills += game->players[i]->getKills();
00289                         otherDeaths += game->players[i]->getDeaths();
00290                 } else if (game->players[i]->getTeam() == MMNet::TeamKnights) {
00291                         knightKills += game->players[i]->getKills();
00292                         knightDeaths += game->players[i]->getDeaths();
00293                 } else if (game->players[i]->getTeam() == MMNet::TeamThieves) {
00294                         thiefKills += game->players[i]->getKills();
00295                         thiefDeaths += game->players[i]->getDeaths();
00296                 } else {
00297                         otherKills += game->players[i]->getKills();
00298                         otherDeaths += game->players[i]->getDeaths();
00299                 }
00300         }
00301                 sprintf(buffer, "%d", thiefDeaths);
00302                 thiefDeaths_tf->writeText(buffer);
00303                 sprintf(buffer, "%d", thiefKills);
00304                 thiefKills_tf->writeText(buffer);
00305                 sprintf(buffer, "%d", knightDeaths);
00306                 knightDeaths_tf->writeText(buffer);
00307                 sprintf(buffer, "%d", knightKills);
00308                 knightKills_tf->writeText(buffer);
00309                 sprintf(buffer, "%d", otherDeaths);
00310                 otherDeaths_tf->writeText(buffer);
00311                 sprintf(buffer, "%d", otherKills);
00312                 otherKills_tf->writeText(buffer);
00313                 //glutPostRedisplay();
00314 }
00315 
00316 void ScoreMenu::exit() { 
00317     //GameState::client->setCallbackObject(NULL);
00318     //menuClear();
00319 }
00320 
00321 void ScoreMenu::draw() {
00322         if (isDraw < DRAW_TIME_LIMIT) {
00323                 update();
00324                 render();
00325                 isDraw++;
00326         }
00327 }
00328 
00329 void ScoreMenu::toggleDraw() {
00330         isDraw = 0;
00331 }
00332 
00333 void ScoreMenu::render() {
00334                 //glColor3f(0.0f,0,0);
00335 
00336                 // switch to projection mode
00337                 glMatrixMode(GL_PROJECTION);
00338                 // save previous matrix which contains the 
00339                 //settings for the perspective projection
00340                 glPushMatrix();
00341                 // reset matrix
00342                 glLoadIdentity();
00343                 // set a 2D orthographic projection
00344                 GLint vPort[4];
00345                 glGetIntegerv(GL_VIEWPORT, vPort);
00346 
00347                 gluOrtho2D(0, vPort[2], 0, vPort[3]);
00348                 // invert the y axis, down is positive
00349                 glScalef(1, -1, 1);
00350                 // mover the origin from the bottom left corner
00351                 // to the upper left corner
00352                 glTranslatef(0, -vPort[3], 0);
00353                 glMatrixMode(GL_MODELVIEW);
00354                 glPushMatrix();
00355                 glLoadIdentity();
00356 
00357                 //glEnable(GL_BLEND);           // Turn Blending On
00358                 //glDisable(GL_DEPTH_TEST);
00359                 //glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
00360 
00361                 glEnable(GL_BLEND);             // Turn Blending On
00362                 glDisable(GL_DEPTH_TEST);
00363                 glColor4f(0,0,0,.3);
00364                 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00365                 glBegin(GL_QUADS);
00366                         glVertex2f(X_START_GUI_POSITION-MARGIN,Y_START_GUI_POSITION-MARGIN);
00367                         glVertex2f(X_START_GUI_POSITION-MARGIN,y+HEIGHT+MARGIN);
00368                         glVertex2f(x+MARGIN+WIDTH,y+HEIGHT+MARGIN);
00369                         glVertex2f(x+MARGIN+WIDTH,Y_START_GUI_POSITION-MARGIN);
00370                 glEnd();
00371 
00372 
00373                 glDisable(GL_BLEND);            // Turn Blending Off
00374                 glEnable(GL_DEPTH_TEST);        // Turn Depth Testing On
00375 
00376                 display();
00377 
00378 
00379 
00380                 // set the current matrix to GL_PROJECTION
00381                 glMatrixMode(GL_PROJECTION);
00382                 // restore previous settings
00383                 glPopMatrix();
00384                 // get back to GL_MODELVIEW matrix
00385                 glMatrixMode(GL_MODELVIEW);
00386 }

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