00001
00002
00003
00004
00005 #include "scoremenu.h"
00006
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
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
00056
00057 float winHeight = glutGet(GLUT_WINDOW_HEIGHT);
00058
00059
00060
00061
00062
00063
00064
00065
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
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
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
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
00091 if (isTrogdor(game->players[i]->getName())) {
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
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
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
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
00139
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
00145
00146
00147
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
00152
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
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
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
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
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
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
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
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
00194 sprintf(buffer, "%d", otherKills);
00195 otherKills_tf->writeText(buffer);
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226 }
00227
00228
00229
00230
00231
00232 void ScoreMenu::display(void) {
00233
00234
00235
00236
00237
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
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
00284 for (int i=0; i<game->players.size(); i++) {
00285
00286
00287 if (isTrogdor(game->players[i]->getName())) {
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
00314 }
00315
00316 void ScoreMenu::exit() {
00317
00318
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
00335
00336
00337 glMatrixMode(GL_PROJECTION);
00338
00339
00340 glPushMatrix();
00341
00342 glLoadIdentity();
00343
00344 GLint vPort[4];
00345 glGetIntegerv(GL_VIEWPORT, vPort);
00346
00347 gluOrtho2D(0, vPort[2], 0, vPort[3]);
00348
00349 glScalef(1, -1, 1);
00350
00351
00352 glTranslatef(0, -vPort[3], 0);
00353 glMatrixMode(GL_MODELVIEW);
00354 glPushMatrix();
00355 glLoadIdentity();
00356
00357
00358
00359
00360
00361 glEnable(GL_BLEND);
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);
00374 glEnable(GL_DEPTH_TEST);
00375
00376 display();
00377
00378
00379
00380
00381 glMatrixMode(GL_PROJECTION);
00382
00383 glPopMatrix();
00384
00385 glMatrixMode(GL_MODELVIEW);
00386 }