| 1 | /* ************************************************************************* * |
| 2 | SDL-Ball - DX-Ball/Breakout remake with openGL and SDL for Linux |
| 3 | Copyright (C) 2008 Jimmy Christensen ( dusted at dusted dot dk ) |
| 4 | |
| 5 | This program is free software: you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation, either version 3 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | This program is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * ************************************************************************* */ |
| 18 | |
| 19 | |
| 20 | class highScoreClass { |
| 21 | private: |
| 22 | string name; |
| 23 | textureManager texMgr; |
| 24 | textureClass tex; |
| 25 | public: |
| 26 | |
| 27 | highScoreClass() |
| 28 | { |
| 29 | name=""; |
| 30 | texMgr.load(useTheme("/gfx/highscore/entername.png",setting.gfxTheme), tex); |
| 31 | } |
| 32 | |
| 33 | void draw() |
| 34 | { |
| 35 | |
| 36 | glLoadIdentity(); |
| 37 | glTranslatef(0,0,-3.0); |
| 38 | glColor4f(1,1,1,1); |
| 39 | |
| 40 | glBindTexture(GL_TEXTURE_2D, tex.prop.texture); |
| 41 | glBegin( GL_QUADS ); |
| 42 | glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 0.5f, 0.0f ); |
| 43 | glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 0.5f, 0.0f ); |
| 44 | glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,-0.5f, 0.0f ); |
| 45 | glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,-0.5f, 0.0f ); |
| 46 | glEnd( ); |
| 47 | |
| 48 | |
| 49 | glColor4f(1,1,1,1); |
| 50 | glText->write(name, FONT_MENUHIGHSCORE, 1, 2.0, 0.0, 0.0); |
| 51 | |
| 52 | } |
| 53 | |
| 54 | void type(SDL_Event e, menuClass &menu) |
| 55 | { |
| 56 | if(var.showHighScores == 1) |
| 57 | { |
| 58 | if(e.key.keysym.sym == SDLK_ESCAPE) |
| 59 | { |
| 60 | var.showHighScores = 0; |
| 61 | initNewGame(); |
| 62 | menu.refreshHighScoreList(); |
| 63 | var.menu = 7; |
| 64 | return; |
| 65 | } |
| 66 | |
| 67 | if(e.key.keysym.sym != SDLK_RETURN) |
| 68 | { |
| 69 | if ( (e.key.keysym.unicode & 0xFF80) == 0 && e.key.keysym.unicode != 0) { |
| 70 | if(e.key.keysym.sym == SDLK_BACKSPACE) |
| 71 | { |
| 72 | if(name.length() > 0) |
| 73 | name.erase(name.length()-1); |
| 74 | } else { |
| 75 | name += e.key.keysym.unicode; |
| 76 | } |
| 77 | } |
| 78 | } else { |
| 79 | var.showHighScores = 0; |
| 80 | ofstream hsList; |
| 81 | hsList.open(privFile.highScoreFile.data(), ios::out | ios::app); |
| 82 | hsList << "[" << player.level+1 << "]" << player.score << "|" << name << endl; |
| 83 | hsList.close(); |
| 84 | initNewGame(); |
| 85 | menu.refreshHighScoreList(); |
| 86 | resumeGame(); |
| 87 | var.titleScreenShow=1; |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | bool isHighScore() |
| 93 | { |
| 94 | int n; |
| 95 | int high=0; |
| 96 | struct score * slist = sortScores(&n); |
| 97 | for(int i = 0; i < n; i++) |
| 98 | { |
| 99 | if(player.score < slist[i].score) |
| 100 | { |
| 101 | high++; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | if(n>0) |
| 106 | delete[] slist; |
| 107 | |
| 108 | if(high < 20) |
| 109 | { |
| 110 | return(1); |
| 111 | } |
| 112 | return(0); |
| 113 | } |
| 114 | }; |