1 /*
2    File:        PageHallOfFame.cpp
3   Description: Hall of Fame page
4   Program:     BlockOut
5   Author:      Jean-Luc PONS
6 
7   This program is free software; you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation; either version 2 of the License, or
10   (at your option) any later version.
11 
12   This program is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16 */
17 
18 #include "Menu.h"
19 
20 
21 
Prepare(int iParam,void * pParam)22 void PageHallOfFame::Prepare(int iParam,void *pParam) {
23 
24   nbItem  = 10;
25   if(iParam<10)
26     selItem = iParam;
27   else
28     selItem = 0;
29 
30   strcpy(editText,"          ");
31   editPos = 0;
32   startEditTime = 0.0f;
33   editCursor = FALSE;
34   editScore = (SCOREREC *)pParam;
35   mParent->GetSetup()->GetHighScore(allScore);
36 
37   if( editScore ) {
38     editMode = TRUE;
39   } else {
40     editMode = FALSE;
41   }
42 
43 }
44 
GetPlayer()45 PLAYER_INFO *PageHallOfFame::GetPlayer() {
46 
47   strcpy(pInfo.name , allScore[selItem].name);
48   int i = (int)strlen(pInfo.name) - 1;
49   while(i>=0 && pInfo.name[i]==' ') {
50     pInfo.name[i]=0;
51     i--;
52   }
53   pInfo.highScore = allScore[0].score;
54   pInfo.rank = selItem + 1;
55 
56   return &pInfo;
57 
58 }
59 
Render()60 void PageHallOfFame::Render() {
61 
62   char tmp[256];
63 
64   sprintf(tmp,"HALL OF FAME %s",mParent->GetSetup()->GetName());
65   mParent->RenderTitle(tmp);
66   for(int i=0;i<10;i++) {
67     sprintf(tmp,"%2d ",i+1);
68     mParent->RenderText(0,i,(selItem==i) && !editMode,tmp);
69     mParent->RenderText(3,i,(selItem==i) && !editMode,allScore[i].name);
70     sprintf(tmp,"%7d ",allScore[i].score);
71     mParent->RenderText(13,i,(selItem==i) && !editMode,tmp);
72     sprintf(tmp,"[%s]",FormatDateShort(allScore[i].date));
73     mParent->RenderText(21,i,(selItem==i) && !editMode,tmp);
74   }
75   // Edition mode
76   if( editMode ) {
77     mParent->RenderText(3,selItem,FALSE,editText);
78     mParent->RenderText(3+editPos,selItem,editCursor,STR(" "));
79   }
80 
81 }
82 
Process(BYTE * keys,float fTime)83 int PageHallOfFame::Process(BYTE *keys,float fTime) {
84 
85   if( !editMode ) {
86 
87     ProcessDefault(keys,fTime);
88 
89     if( keys[SDLK_RETURN] ) {
90       mParent->ToPage(&mParent->scoreDetailsPage,selItem,allScore + selItem);
91       keys[SDLK_RETURN] = 0;
92     }
93 
94     if( keys[SDLK_ESCAPE] ) {
95        mParent->ToPage(&mParent->mainMenuPage);
96        keys[SDLK_ESCAPE] = 0;
97     }
98 
99   } else {
100     ProcessEdit(keys,fTime);
101   }
102 
103   return 0;
104 
105 }
106 
107 // ---------------------------------------------------------------------
108 
ProcessEdit(BYTE * keys,float fTime)109 void PageHallOfFame::ProcessEdit(BYTE *keys,float fTime) {
110 
111   if( startEditTime == 0.0f )
112     startEditTime = fTime;
113 
114   editCursor = ( (fround((startEditTime - fTime) * 2.0f)%2) == 0 );
115 
116   char c = GetChar(keys);
117   if( c>0 && editPos<10 ) {
118     editText[editPos] = c;
119     editPos++;
120   }
121 
122   // Delete
123   if( keys[SDLK_DELETE] || keys[SDLK_LEFT] || keys[SDLK_BACKSPACE] ) {
124     if( editPos>0 ) editPos--;
125     if( editPos<10 ) editText[editPos]=' ';
126     keys[SDLK_DELETE] = 0;
127     keys[SDLK_LEFT] = 0;
128     keys[SDLK_BACKSPACE] = 0;
129   }
130 
131   if( keys[SDLK_ESCAPE] || keys[SDLK_RETURN] ) {
132     // Record new name and save
133     strcpy(editScore->name,editText);
134     mParent->GetSetup()->SaveHighScore();
135     mParent->GetSetup()->GetHighScore(allScore);
136     editMode = FALSE;
137     keys[SDLK_ESCAPE] = 0;
138     keys[SDLK_RETURN] = 0;
139   }
140 
141 }
142 
143