1 /**
2  * @file sprite_display_scores.cc
3  * @brief Sprite wich display text of the score table
4  * @created 2003-04-30
5  * @date 2007-03-09
6  * @copyright 1991-2014 TLK Games
7  * @author Bruno Ethvignot
8  * @version $Revision: 24 $
9  */
10 /*
11  * copyright (c) 1991-2014 TLK Games all rights reserved
12  * $Id: sprite_display_scores.cc 24 2014-09-28 15:30:04Z bruno.ethvignot@gmail.com $
13  *
14  * TecnoballZ is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * TecnoballZ is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
27  * MA  02110-1301, USA.
28  */
29 #include "../include/sprite_display_scores.h"
30 #include "../include/sprite_display_menu.h"
31 #include "../include/handler_resources.h"
32 #include "../include/handler_players.h"
33 #include "../include/handler_high_score.h"
34 
35 /**
36  * Create the sprite displaying scores
37  */
sprite_display_scores()38 sprite_display_scores::sprite_display_scores ()
39 {
40   clear_sprite_members ();
41   offscreen_text = (bitmap_data *) NULL;
42   width_font = 8 * resolution;
43   heightfont = 8 * resolution;
44   if (resolution == 2)
45     {
46       space2next = 17;
47     }
48   else
49     {
50       space2next = 8;
51     }
52   run_offset = 0;
53   max_offset = TEXT_LARGE * TEXT_HAUTE;
54 }
55 
56 /**
57  * Release the sprite displaying scores
58  */
~sprite_display_scores()59 sprite_display_scores::~sprite_display_scores ()
60 {
61   if (offscreen_text)
62     delete offscreen_text;
63   if (bitmap_fonts)
64     delete bitmap_fonts;
65   bitmap_fonts = (bitmap_data *) NULL;
66   offscreen_text = (bitmap_data *) NULL;
67 }
68 
69 /**
70  * Perform some initializations
71  */
72 void
first_init(Uint32 x_offset)73 sprite_display_scores::first_init (Uint32 x_offset)
74 {
75 
76   load_bitmap_fonts (handler_resources::BITMAP_SCORES_FONTS);
77 
78 /* allocate 512 * 323 pixels buffer for scores text */
79   offscreen_text = new bitmap_data ();
80   offscreen_text->create_surface (TEXT_LARGE * width_font,
81                               TEXT_HAUTE * space2next);
82 
83   /* initialize sprite object */
84   make_sprite (offscreen_text);
85   enable ();
86   set_coordinates (32 * resolution + x_offset, 80 * resolution);
87   copyToText ();
88 }
89 
90 //------------------------------------------------------------------------------
91 // display the text menu into buffer memory
92 //------------------------------------------------------------------------------
93 Sint32
displayTxt()94 sprite_display_scores::displayTxt ()
95 {
96   //###################################################################
97   // display menu text
98   //###################################################################
99   char *desP1 = pixel_data;
100   Sint32 offSc = off_source;
101   Sint32 offDs = row_size;
102   Sint32 offD2 = row_size * (space2next - 1);
103   //Sint32 offD2 = row_size * 8 * resolution;
104   Sint32 *basPT = (Sint32 *) caract_adr;
105   char *p = scorestext;
106   char *c = ascii2code;
107   Sint32 a, b, j;
108   Sint32 offst = 0;
109   Sint32 oldva = run_offset;
110 
111   if (resolution == 1)
112     {
113       for (Sint32 k = 0; k < TEXT_HAUTE; k++, desP1 += offD2)
114         {                       //###########################################################
115           // display normal line of 32 characters
116           //###########################################################
117           for (j = 0; j < TEXT_LARGE; j++)
118             {
119               a = *(p++) - 32;
120               if (run_offset < max_offset && offst >= run_offset)
121                 run_offset++;
122               if (offst < max_offset)
123                 offst++;
124               if (a)
125                 {
126                   b = c[a];
127                   Sint32 *s = (Sint32 *) basPT;
128                   Sint32 *d = (Sint32 *) desP1;
129                   b = b << 3;
130                   s = (Sint32 *) ((char *) s + b);
131                   for (b = 0; b < 8; b++)
132                     {
133                       d[0] = s[0];
134                       d[1] = s[1];
135                       s = (Sint32 *) ((char *) s + offSc);
136                       d = (Sint32 *) ((char *) d + offDs);
137                     }
138                   if (run_offset > oldva)
139                     return 0;
140                 }
141               desP1 = desP1 + 8;
142             }
143         }
144     }
145   else
146     {
147 
148       for (Sint32 k = 0; k < TEXT_HAUTE; k++, desP1 += offD2)
149         {                       //###########################################################
150           // display normal line of 32 characters
151           //###########################################################
152           for (j = 0; j < TEXT_LARGE; j++)
153             {
154               a = *(p++) - 32;
155               if (run_offset < max_offset && offst >= run_offset)
156                 run_offset++;
157               if (offst < max_offset)
158                 offst++;
159               if (a)
160                 {
161                   b = c[a];
162                   Sint32 *s = (Sint32 *) basPT;
163                   Sint32 *d = (Sint32 *) desP1;
164                   b = b << 4;
165                   s = (Sint32 *) ((char *) s + b);
166                   for (b = 0; b < 16; b++)
167                     {
168                       d[0] = s[0];
169                       d[1] = s[1];
170                       d[2] = s[2];
171                       d[3] = s[3];
172                       s = (Sint32 *) ((char *) s + offSc);
173                       d = (Sint32 *) ((char *) d + offDs);
174                     }
175                   if (run_offset > oldva)
176                     return 0;
177                 }
178               desP1 = desP1 + 16;
179             }
180         }
181     }
182   return 1;
183 }
184 
185 /**
186  * Copy high score table into strings
187  */
188 void
copyToText()189 sprite_display_scores::copyToText ()
190 {
191   player_score *score = high_score->get_high_score_table ();
192   if (NULL == score)
193     {
194       return;
195     }
196   char *ptext = scorestext + TEXT_LARGE * 2;
197   for (Uint32 i = 0; i < handler_high_score::MAX_OF_HIGH_SCORES; i++)
198     {
199       char *pName = score[i].player_name;
200       for (Uint32 j = 0; j < handler_players::PLAYER_NAME_LENGTH; j++)
201         {
202           ptext[j] = pName[j];
203         }
204       integer_to_ascii (score[i].value, 6,  &ptext[7]);
205       integer_to_ascii (score[i].area_number, 1, &ptext[16]);
206       integer_to_ascii (score[i].level_number, 2, &ptext[21]);
207       ptext += TEXT_LARGE;
208     }
209 }
210 
211 //------------------------------------------------------------------------------
212 // scores table text
213 //------------------------------------------------------------------------------
214 char
215   sprite_display_scores::scorestext[] = "    TECNOBALL TOP TEN  "       //0
216   "NAME  SCORE  AREA LEVEL"     //1
217   "...... 000000  :1    01"     //2
218   "...... 000000  :1    01"     //3
219   "...... 000000  :1    01"     //4
220   "...... 000000  :1    01"     //5
221   "...... 000000  :1    01"     //6
222   "...... 000000  :1    01"     //7
223   "...... 000000  :1    01"     //8
224   "...... 000000  :1    01"     //9
225   "...... 000000  :1    01"     //10
226   "...... 000000  :1    01";    //11
227