2006-03-20 17:12:09 +00:00
|
|
|
/*
|
2014-06-01 17:55:23 +00:00
|
|
|
* Portions of this file are copyright Rebirth contributors and licensed as
|
|
|
|
* described in COPYING.txt.
|
|
|
|
* Portions of this file are copyright Parallax Software and licensed
|
|
|
|
* according to the Parallax license below.
|
|
|
|
* See COPYING.txt for license details.
|
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
|
|
|
|
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
|
|
|
|
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
|
|
|
|
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
|
|
|
|
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
|
|
|
|
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
|
|
|
|
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
|
|
|
|
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
|
|
|
|
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
|
|
|
|
COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Inferno High Scores and Statistics System
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#include "scores.h"
|
2012-07-07 18:35:06 +00:00
|
|
|
#include "dxxerror.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "pstypes.h"
|
2010-02-07 06:00:10 +00:00
|
|
|
#include "window.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "gr.h"
|
|
|
|
#include "key.h"
|
2011-01-02 11:25:51 +00:00
|
|
|
#include "mouse.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "palette.h"
|
|
|
|
#include "game.h"
|
|
|
|
#include "gamefont.h"
|
|
|
|
#include "u_mem.h"
|
|
|
|
#include "newmenu.h"
|
|
|
|
#include "menu.h"
|
|
|
|
#include "player.h"
|
2016-10-15 00:53:19 +00:00
|
|
|
#include "object.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "screens.h"
|
2010-02-08 04:10:21 +00:00
|
|
|
#include "gamefont.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "mouse.h"
|
|
|
|
#include "joy.h"
|
|
|
|
#include "timer.h"
|
|
|
|
#include "text.h"
|
|
|
|
#include "strutil.h"
|
2009-03-03 12:55:27 +00:00
|
|
|
#include "rbaudio.h"
|
2015-01-17 18:31:42 +00:00
|
|
|
#include "physfsx.h"
|
2019-05-04 18:27:36 +00:00
|
|
|
#include "compiler-range_for.h"
|
2020-08-10 03:45:14 +00:00
|
|
|
#include "d_levelstate.h"
|
2019-05-04 18:27:36 +00:00
|
|
|
#include "d_range.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2016-09-24 18:06:11 +00:00
|
|
|
#if DXX_USE_OGL
|
2007-03-22 11:32:22 +00:00
|
|
|
#include "ogl_init.h"
|
|
|
|
#endif
|
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
#define VERSION_NUMBER 1
|
|
|
|
#define SCORES_FILENAME "descent.hi"
|
2016-10-20 02:11:39 +00:00
|
|
|
#define COOL_MESSAGE_LEN 50
|
2017-10-14 17:10:30 +00:00
|
|
|
namespace dcx {
|
|
|
|
constexpr std::integral_constant<unsigned, 10> MAX_HIGH_SCORES{};
|
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2020-09-21 03:18:12 +00:00
|
|
|
namespace dsx {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_I)
|
|
|
|
#define DXX_SCORE_STRUCT_PACK __pack__
|
|
|
|
#elif defined(DXX_BUILD_DESCENT_II)
|
|
|
|
#define DXX_SCORE_STRUCT_PACK
|
|
|
|
#endif
|
|
|
|
|
2013-12-22 22:03:07 +00:00
|
|
|
struct stats_info
|
|
|
|
{
|
2014-07-05 16:48:12 +00:00
|
|
|
callsign_t name;
|
2006-03-20 17:12:09 +00:00
|
|
|
int score;
|
|
|
|
sbyte starting_level;
|
|
|
|
sbyte ending_level;
|
|
|
|
sbyte diff_level;
|
|
|
|
short kill_ratio; // 0-100
|
|
|
|
short hostage_ratio; //
|
|
|
|
int seconds; // How long it took in seconds...
|
2013-12-22 22:03:07 +00:00
|
|
|
} DXX_SCORE_STRUCT_PACK;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2013-12-22 22:03:07 +00:00
|
|
|
struct all_scores
|
|
|
|
{
|
2006-03-20 17:12:09 +00:00
|
|
|
char signature[3]; // DHS
|
|
|
|
sbyte version; // version
|
|
|
|
char cool_saying[COOL_MESSAGE_LEN];
|
|
|
|
stats_info stats[MAX_HIGH_SCORES];
|
2013-12-22 22:03:07 +00:00
|
|
|
} DXX_SCORE_STRUCT_PACK;
|
2016-10-20 02:11:39 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_I)
|
|
|
|
static_assert(sizeof(all_scores) == 294, "high score size wrong");
|
|
|
|
#elif defined(DXX_BUILD_DESCENT_II)
|
|
|
|
static_assert(sizeof(all_scores) == 336, "high score size wrong");
|
|
|
|
#endif
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2020-12-20 20:39:07 +00:00
|
|
|
void scores_view(const stats_info *last_game, int citem);
|
2020-09-21 03:18:12 +00:00
|
|
|
|
2013-10-27 22:00:14 +00:00
|
|
|
static void scores_read(all_scores *scores)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
|
|
|
int fsize;
|
|
|
|
|
|
|
|
// clear score array...
|
2014-07-04 04:16:48 +00:00
|
|
|
*scores = {};
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2015-01-17 18:31:42 +00:00
|
|
|
RAIIPHYSFS_File fp{PHYSFS_openRead(SCORES_FILENAME)};
|
2015-01-17 18:31:42 +00:00
|
|
|
if (!fp)
|
|
|
|
{
|
2006-03-20 17:12:09 +00:00
|
|
|
// No error message needed, code will work without a scores file
|
2016-01-03 20:21:35 +00:00
|
|
|
strcpy(scores->cool_saying, TXT_REGISTER_DESCENT);
|
2014-07-05 16:48:12 +00:00
|
|
|
scores->stats[0].name = "Parallax";
|
|
|
|
scores->stats[1].name = "Matt";
|
|
|
|
scores->stats[2].name = "Mike";
|
|
|
|
scores->stats[3].name = "Adam";
|
|
|
|
scores->stats[4].name = "Mark";
|
|
|
|
scores->stats[5].name = "Jasen";
|
|
|
|
scores->stats[6].name = "Samir";
|
|
|
|
scores->stats[7].name = "Doug";
|
|
|
|
scores->stats[8].name = "Dan";
|
|
|
|
scores->stats[9].name = "Jason";
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2019-05-04 18:27:36 +00:00
|
|
|
range_for (const int i, xrange(10u))
|
2010-02-08 04:10:21 +00:00
|
|
|
scores->stats[i].score = (10-i)*1000;
|
2006-03-20 17:12:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fsize = PHYSFS_fileLength(fp);
|
|
|
|
|
|
|
|
if ( fsize != sizeof(all_scores) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Read 'em in...
|
2010-02-08 04:10:21 +00:00
|
|
|
PHYSFS_read(fp, scores, sizeof(all_scores), 1);
|
|
|
|
if ( (scores->version!=VERSION_NUMBER)||(scores->signature[0]!='D')||(scores->signature[1]!='H')||(scores->signature[2]!='S') ) {
|
2014-07-04 04:16:48 +00:00
|
|
|
*scores = {};
|
2006-03-20 17:12:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-27 22:00:14 +00:00
|
|
|
static void scores_write(all_scores *scores)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2015-01-17 18:31:42 +00:00
|
|
|
RAIIPHYSFS_File fp{PHYSFS_openWrite(SCORES_FILENAME)};
|
2015-01-17 18:31:42 +00:00
|
|
|
if (!fp)
|
|
|
|
{
|
2020-12-19 16:13:26 +00:00
|
|
|
nm_messagebox(menu_title{TXT_WARNING}, 1, TXT_OK, "%s\n'%s'", TXT_UNABLE_TO_OPEN, SCORES_FILENAME);
|
2006-03-20 17:12:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-02-08 04:10:21 +00:00
|
|
|
scores->signature[0]='D';
|
|
|
|
scores->signature[1]='H';
|
|
|
|
scores->signature[2]='S';
|
|
|
|
scores->version = VERSION_NUMBER;
|
|
|
|
PHYSFS_write(fp, scores,sizeof(all_scores), 1);
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 03:18:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace dcx {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2013-10-27 22:00:14 +00:00
|
|
|
static void int_to_string( int number, char *dest )
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2016-01-03 20:21:35 +00:00
|
|
|
int c;
|
2006-03-20 17:12:09 +00:00
|
|
|
char buffer[20],*p;
|
|
|
|
|
2016-01-03 20:21:35 +00:00
|
|
|
const auto l = snprintf(buffer, sizeof(buffer), "%d", number);
|
2006-03-20 17:12:09 +00:00
|
|
|
if (l<=3) {
|
|
|
|
// Don't bother with less than 3 digits
|
2016-01-03 20:21:35 +00:00
|
|
|
memcpy(dest, buffer, 4);
|
2006-03-20 17:12:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
c = 0;
|
|
|
|
p=dest;
|
2014-09-26 02:42:10 +00:00
|
|
|
for (int i=l-1; i>=0; i-- ) {
|
2006-03-20 17:12:09 +00:00
|
|
|
if (c==3) {
|
|
|
|
*p++=',';
|
|
|
|
c = 0;
|
|
|
|
}
|
|
|
|
c++;
|
|
|
|
*p++ = buffer[i];
|
|
|
|
}
|
|
|
|
*p++ = '\0';
|
2012-05-18 23:36:43 +00:00
|
|
|
d_strrev(dest);
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 03:18:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace dsx {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2013-10-27 22:00:14 +00:00
|
|
|
static void scores_fill_struct(stats_info * stats)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2019-03-03 00:31:08 +00:00
|
|
|
auto &Objects = LevelUniqueObjectState.Objects;
|
|
|
|
auto &vmobjptr = Objects.vmptr;
|
2017-08-13 20:38:31 +00:00
|
|
|
auto &plr = get_local_player();
|
|
|
|
stats->name = plr.callsign;
|
2016-10-15 00:53:19 +00:00
|
|
|
auto &player_info = get_local_plrobj().ctype.player_info;
|
|
|
|
stats->score = player_info.mission.score;
|
2017-08-13 20:38:31 +00:00
|
|
|
stats->ending_level = plr.level;
|
2019-07-16 04:00:50 +00:00
|
|
|
if (const auto robots_total = GameUniqueState.accumulated_robots)
|
|
|
|
stats->kill_ratio = (plr.num_kills_total * 100) / robots_total;
|
2008-02-24 14:41:27 +00:00
|
|
|
else
|
|
|
|
stats->kill_ratio = 0;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2019-07-16 04:00:50 +00:00
|
|
|
if (const auto hostages_total = GameUniqueState.total_hostages)
|
2016-10-15 00:53:19 +00:00
|
|
|
stats->hostage_ratio = (player_info.mission.hostages_rescued_total * 100) / hostages_total;
|
2008-02-24 14:41:27 +00:00
|
|
|
else
|
|
|
|
stats->hostage_ratio = 0;
|
|
|
|
|
2017-08-13 20:38:31 +00:00
|
|
|
stats->seconds = f2i(plr.time_total) + (plr.hours_total * 3600);
|
2008-02-24 14:41:27 +00:00
|
|
|
|
2019-06-27 03:26:20 +00:00
|
|
|
stats->diff_level = GameUniqueState.Difficulty_level;
|
2017-08-13 20:38:31 +00:00
|
|
|
stats->starting_level = plr.starting_level;
|
2008-02-24 14:41:27 +00:00
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2020-09-21 03:18:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace dcx {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2012-07-01 01:04:25 +00:00
|
|
|
static inline const char *get_placement_slot_string(const unsigned position)
|
|
|
|
{
|
|
|
|
switch(position)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
Int3();
|
2019-04-04 04:29:03 +00:00
|
|
|
DXX_BOOST_FALLTHROUGH;
|
2012-07-01 01:04:25 +00:00
|
|
|
case 0: return TXT_1ST;
|
|
|
|
case 1: return TXT_2ND;
|
|
|
|
case 2: return TXT_3RD;
|
|
|
|
case 3: return TXT_4TH;
|
|
|
|
case 4: return TXT_5TH;
|
|
|
|
case 5: return TXT_6TH;
|
|
|
|
case 6: return TXT_7TH;
|
|
|
|
case 7: return TXT_8TH;
|
|
|
|
case 8: return TXT_9TH;
|
|
|
|
case 9: return TXT_10TH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-21 03:18:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace dsx {
|
|
|
|
|
2016-12-10 17:51:08 +00:00
|
|
|
void scores_maybe_add_player()
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2019-03-03 00:31:08 +00:00
|
|
|
auto &Objects = LevelUniqueObjectState.Objects;
|
|
|
|
auto &vmobjptr = Objects.vmptr;
|
2010-02-08 04:10:21 +00:00
|
|
|
all_scores scores;
|
|
|
|
stats_info last_game;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
if ((Game_mode & GM_MULTI) && !(Game_mode & GM_MULTI_COOP))
|
|
|
|
return;
|
2010-02-08 04:10:21 +00:00
|
|
|
scores_read(&scores);
|
2016-10-15 00:53:19 +00:00
|
|
|
auto &player_info = get_local_plrobj().ctype.player_info;
|
2020-12-20 20:39:07 +00:00
|
|
|
const auto predicate = [player_mission_score = player_info.mission.score](const stats_info &stats) {
|
|
|
|
return player_mission_score > stats.score;
|
|
|
|
};
|
|
|
|
const auto begin_score_stats = std::begin(scores.stats);
|
|
|
|
const auto end_score_stats = std::end(scores.stats);
|
|
|
|
const auto iter_position = std::find_if(begin_score_stats, end_score_stats, predicate);
|
|
|
|
const auto position = std::distance(begin_score_stats, iter_position);
|
|
|
|
stats_info *const ptr_last_game = (iter_position == end_score_stats)
|
2020-12-20 20:39:07 +00:00
|
|
|
? &last_game
|
|
|
|
: nullptr;
|
|
|
|
if (ptr_last_game)
|
|
|
|
{
|
|
|
|
scores_fill_struct(ptr_last_game);
|
2006-03-20 17:12:09 +00:00
|
|
|
} else {
|
2020-12-20 20:39:07 +00:00
|
|
|
if (iter_position == begin_score_stats)
|
|
|
|
{
|
2020-05-02 21:18:42 +00:00
|
|
|
std::array<char, sizeof(scores.cool_saying)> text1{};
|
|
|
|
std::array<newmenu_item, 2> m{{
|
2015-01-18 01:58:31 +00:00
|
|
|
nm_item_text(TXT_COOL_SAYING),
|
|
|
|
nm_item_input(text1),
|
2015-03-22 18:49:21 +00:00
|
|
|
}};
|
2020-12-19 16:13:26 +00:00
|
|
|
newmenu_do2(menu_title{TXT_HIGH_SCORE}, menu_subtitle{TXT_YOU_PLACED_1ST}, m, unused_newmenu_subfunction, unused_newmenu_userdata);
|
2016-12-10 17:51:08 +00:00
|
|
|
strcpy(scores.cool_saying, text1[0] ? text1.data() : "No comment");
|
2006-03-20 17:12:09 +00:00
|
|
|
} else {
|
2020-12-19 16:13:26 +00:00
|
|
|
nm_messagebox(menu_title{TXT_HIGH_SCORE}, 1, TXT_OK, "%s %s!", TXT_YOU_PLACED, get_placement_slot_string(position));
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
2020-12-20 20:39:07 +00:00
|
|
|
// move everyone down...
|
|
|
|
std::move_backward(iter_position, std::prev(end_score_stats), end_score_stats);
|
|
|
|
scores_fill_struct(iter_position);
|
2010-02-08 04:10:21 +00:00
|
|
|
scores_write(&scores);
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
2020-12-20 20:39:07 +00:00
|
|
|
scores_view(ptr_last_game, position);
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 03:18:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace dcx {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2018-05-19 23:21:42 +00:00
|
|
|
__attribute_nonnull()
|
|
|
|
static void scores_rputs(grs_canvas &canvas, const grs_font &cv_font, const int x, const int y, char *const buffer)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
//replace the digit '1' with special wider 1
|
|
|
|
for (p=buffer;*p;p++)
|
|
|
|
if (*p=='1') *p=132;
|
|
|
|
|
2015-09-29 02:41:22 +00:00
|
|
|
int w, h;
|
2018-05-19 23:21:42 +00:00
|
|
|
gr_get_string_size(cv_font, buffer, &w, &h, nullptr);
|
|
|
|
gr_string(canvas, cv_font, FSPACX(x) - w, FSPACY(y), buffer, w, h);
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
2018-05-19 23:21:42 +00:00
|
|
|
__attribute_format_printf(5, 6)
|
|
|
|
static void scores_rprintf(grs_canvas &canvas, const grs_font &cv_font, const int x, const int y, const char *const format, ...)
|
2013-12-08 23:37:40 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
char buffer[128];
|
|
|
|
|
|
|
|
va_start(args, format );
|
|
|
|
vsnprintf(buffer,sizeof(buffer),format,args);
|
|
|
|
va_end(args);
|
2018-05-19 23:21:42 +00:00
|
|
|
scores_rputs(canvas, cv_font, x, y, buffer);
|
2013-12-08 23:37:40 +00:00
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2020-09-21 03:18:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace dsx {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2020-12-20 20:39:07 +00:00
|
|
|
static void scores_draw_item(grs_canvas &canvas, const grs_font &cv_font, const unsigned i, const stats_info *const stats)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
|
|
|
char buffer[20];
|
|
|
|
|
2008-02-24 14:41:27 +00:00
|
|
|
int y;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2008-02-24 14:41:27 +00:00
|
|
|
y = 77+i*9;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2008-02-24 14:41:27 +00:00
|
|
|
if (i==0)
|
|
|
|
y -= 8;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2008-02-24 14:41:27 +00:00
|
|
|
if ( i==MAX_HIGH_SCORES )
|
|
|
|
y += 8;
|
|
|
|
else
|
2018-05-19 23:21:42 +00:00
|
|
|
scores_rprintf(canvas, cv_font, 57, y - 3, "%d.", i + 1);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2008-02-24 14:41:27 +00:00
|
|
|
y -= 3;
|
|
|
|
|
2015-06-13 22:42:20 +00:00
|
|
|
const auto &&fspacx = FSPACX();
|
2016-10-15 00:53:16 +00:00
|
|
|
const auto &&fspacx66 = fspacx(66);
|
|
|
|
const auto &&fspacy_y = FSPACY(y);
|
2019-11-19 02:42:24 +00:00
|
|
|
if (!stats->name[0u])
|
2019-08-25 17:53:57 +00:00
|
|
|
{
|
2018-05-19 23:21:42 +00:00
|
|
|
gr_string(canvas, cv_font, fspacx66, fspacy_y, TXT_EMPTY);
|
2008-02-24 14:41:27 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-05-19 23:21:42 +00:00
|
|
|
gr_string(canvas, cv_font, fspacx66, fspacy_y, stats->name);
|
2008-02-24 14:41:27 +00:00
|
|
|
int_to_string(stats->score, buffer);
|
2018-05-19 23:21:42 +00:00
|
|
|
scores_rputs(canvas, cv_font, 149, y, buffer);
|
2008-02-24 14:41:27 +00:00
|
|
|
|
2018-05-19 23:21:42 +00:00
|
|
|
gr_string(canvas, cv_font, fspacx(166), fspacy_y, MENU_DIFFICULTY_TEXT(stats->diff_level));
|
2008-02-24 14:41:27 +00:00
|
|
|
|
|
|
|
if ( (stats->starting_level > 0 ) && (stats->ending_level > 0 ))
|
2018-05-19 23:21:42 +00:00
|
|
|
scores_rprintf(canvas, cv_font, 232, y, "%d-%d", stats->starting_level, stats->ending_level);
|
2008-02-24 14:41:27 +00:00
|
|
|
else if ( (stats->starting_level < 0 ) && (stats->ending_level > 0 ))
|
2018-05-19 23:21:42 +00:00
|
|
|
scores_rprintf(canvas, cv_font, 232, y, "S%d-%d", -stats->starting_level, stats->ending_level);
|
2008-02-24 14:41:27 +00:00
|
|
|
else if ( (stats->starting_level < 0 ) && (stats->ending_level < 0 ))
|
2018-05-19 23:21:42 +00:00
|
|
|
scores_rprintf(canvas, cv_font, 232, y, "S%d-S%d", -stats->starting_level, -stats->ending_level);
|
2008-02-24 14:41:27 +00:00
|
|
|
else if ( (stats->starting_level > 0 ) && (stats->ending_level < 0 ))
|
2018-05-19 23:21:42 +00:00
|
|
|
scores_rprintf(canvas, cv_font, 232, y, "%d-S%d", stats->starting_level, -stats->ending_level);
|
2008-02-24 14:41:27 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
int h, m, s;
|
|
|
|
h = stats->seconds/3600;
|
|
|
|
s = stats->seconds%3600;
|
|
|
|
m = s / 60;
|
|
|
|
s = s % 60;
|
2018-05-19 23:21:42 +00:00
|
|
|
scores_rprintf(canvas, cv_font, 276, y, "%d:%02d:%02d", h, m, s);
|
2008-02-24 14:41:27 +00:00
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 03:18:12 +00:00
|
|
|
struct scores_menu : window
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2020-12-20 20:39:07 +00:00
|
|
|
const int citem;
|
2010-12-10 23:18:17 +00:00
|
|
|
fix64 t1;
|
2020-09-21 03:18:12 +00:00
|
|
|
int looper = 0;
|
2010-02-08 04:10:21 +00:00
|
|
|
all_scores scores;
|
2020-12-20 20:39:07 +00:00
|
|
|
const stats_info last_game;
|
|
|
|
scores_menu(grs_canvas &src, int x, int y, int w, int h, int citem, const stats_info *last_game) :
|
|
|
|
window(src, x, y, w, h), citem(citem), t1(timer_query()), last_game(last_game ? *last_game : stats_info{})
|
|
|
|
{
|
|
|
|
}
|
2020-09-21 03:18:12 +00:00
|
|
|
virtual window_event_result event_handler(const d_event &) override;
|
2013-12-22 22:03:07 +00:00
|
|
|
};
|
2010-02-07 06:00:10 +00:00
|
|
|
|
2020-09-21 03:18:12 +00:00
|
|
|
window_event_result scores_menu::event_handler(const d_event &event)
|
2010-02-07 06:00:10 +00:00
|
|
|
{
|
2006-03-20 17:12:09 +00:00
|
|
|
int k;
|
2015-06-13 22:42:20 +00:00
|
|
|
const auto &&fspacx = FSPACX();
|
2015-06-13 22:42:20 +00:00
|
|
|
const auto &&fspacy = FSPACY();
|
|
|
|
int w = fspacx(290), h = fspacy(170);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2014-10-04 21:47:13 +00:00
|
|
|
switch (event.type)
|
2010-02-07 06:00:10 +00:00
|
|
|
{
|
2010-02-25 08:00:15 +00:00
|
|
|
case EVENT_WINDOW_ACTIVATED:
|
2020-10-12 03:28:26 +00:00
|
|
|
game_flush_inputs(Controls);
|
2010-02-25 08:00:15 +00:00
|
|
|
break;
|
|
|
|
|
2010-02-07 06:00:10 +00:00
|
|
|
case EVENT_KEY_COMMAND:
|
2011-01-14 09:51:13 +00:00
|
|
|
k = event_key_get(event);
|
2010-02-07 06:00:10 +00:00
|
|
|
switch( k ) {
|
|
|
|
case KEY_CTRLED+KEY_R:
|
2020-09-21 03:18:12 +00:00
|
|
|
if (citem < 0)
|
|
|
|
{
|
2010-02-07 06:00:10 +00:00
|
|
|
// Reset scores...
|
2020-12-19 16:13:26 +00:00
|
|
|
if (nm_messagebox_str(menu_title{nullptr}, nm_messagebox_tie(TXT_NO, TXT_YES), menu_subtitle{TXT_RESET_HIGH_SCORES}) == 1)
|
2020-10-22 02:26:16 +00:00
|
|
|
{
|
2010-02-08 04:10:21 +00:00
|
|
|
PHYSFS_delete(SCORES_FILENAME);
|
2020-09-21 03:18:12 +00:00
|
|
|
scores_view(&last_game, citem); // create new scores window
|
2014-08-06 02:10:49 +00:00
|
|
|
return window_event_result::close;
|
2010-02-07 06:00:10 +00:00
|
|
|
}
|
|
|
|
}
|
2014-08-06 02:10:49 +00:00
|
|
|
return window_event_result::handled;
|
2010-04-02 05:01:08 +00:00
|
|
|
case KEY_ENTER:
|
|
|
|
case KEY_SPACEBAR:
|
|
|
|
case KEY_ESC:
|
2014-08-06 02:10:49 +00:00
|
|
|
return window_event_result::close;
|
2010-02-07 06:00:10 +00:00
|
|
|
}
|
|
|
|
break;
|
2011-01-02 11:25:51 +00:00
|
|
|
|
|
|
|
case EVENT_MOUSE_BUTTON_DOWN:
|
|
|
|
case EVENT_MOUSE_BUTTON_UP:
|
2011-01-14 09:51:13 +00:00
|
|
|
if (event_mouse_get_button(event) == MBTN_LEFT || event_mouse_get_button(event) == MBTN_RIGHT)
|
2011-01-02 11:25:51 +00:00
|
|
|
{
|
2014-08-06 02:10:49 +00:00
|
|
|
return window_event_result::close;
|
2011-01-02 11:25:51 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2020-09-11 03:08:02 +00:00
|
|
|
#if DXX_MAX_BUTTONS_PER_JOYSTICK
|
2020-06-28 15:08:26 +00:00
|
|
|
case EVENT_JOYSTICK_BUTTON_DOWN:
|
|
|
|
return window_event_result::close;
|
2020-09-11 03:08:02 +00:00
|
|
|
#endif
|
2020-06-28 15:08:26 +00:00
|
|
|
|
2010-02-07 06:00:10 +00:00
|
|
|
case EVENT_IDLE:
|
|
|
|
timer_delay2(50);
|
|
|
|
break;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2010-02-07 06:00:10 +00:00
|
|
|
case EVENT_WINDOW_DRAW:
|
2017-11-05 20:49:08 +00:00
|
|
|
gr_set_default_canvas();
|
2010-04-03 09:10:20 +00:00
|
|
|
|
2017-04-08 16:48:20 +00:00
|
|
|
nm_draw_background(*grd_curcanv, ((SWIDTH - w) / 2) - BORDERX, ((SHEIGHT - h) / 2) - BORDERY, ((SWIDTH - w) / 2) + w + BORDERX, ((SHEIGHT - h) / 2) + h + BORDERY);
|
2010-02-07 06:00:10 +00:00
|
|
|
|
2017-02-11 21:42:37 +00:00
|
|
|
{
|
2020-09-21 03:18:12 +00:00
|
|
|
auto &canvas = w_canv;
|
2018-05-19 23:21:42 +00:00
|
|
|
auto &medium3_font = *MEDIUM3_FONT;
|
|
|
|
gr_string(canvas, medium3_font, 0x8000, fspacy(15), TXT_HIGH_SCORES);
|
2017-02-11 21:42:37 +00:00
|
|
|
gr_set_fontcolor(canvas, BM_XRGB(31, 26, 5), -1);
|
2018-05-19 23:21:42 +00:00
|
|
|
auto &game_font = *GAME_FONT;
|
|
|
|
gr_string(canvas, game_font, fspacx( 71), fspacy(50), TXT_NAME);
|
|
|
|
gr_string(canvas, game_font, fspacx(122), fspacy(50), TXT_SCORE);
|
|
|
|
gr_string(canvas, game_font, fspacx(167), fspacy(50), TXT_SKILL);
|
|
|
|
gr_string(canvas, game_font, fspacx(210), fspacy(50), TXT_LEVELS);
|
|
|
|
gr_string(canvas, game_font, fspacx(253), fspacy(50), TXT_TIME);
|
2010-02-07 06:00:10 +00:00
|
|
|
|
2020-09-21 03:18:12 +00:00
|
|
|
if (citem < 0)
|
2018-05-19 23:21:42 +00:00
|
|
|
gr_string(canvas, game_font, 0x8000, fspacy(175), TXT_PRESS_CTRL_R);
|
2010-02-07 06:00:10 +00:00
|
|
|
|
2017-02-11 21:42:37 +00:00
|
|
|
gr_set_fontcolor(canvas, BM_XRGB(28, 28, 28), -1);
|
2010-02-07 06:00:10 +00:00
|
|
|
|
2020-09-21 03:18:12 +00:00
|
|
|
gr_printf(canvas, game_font, 0x8000, fspacy(31), "%c%s%c - %s", 34, scores.cool_saying, 34, static_cast<const char *>(scores.stats[0].name));
|
2010-02-07 06:00:10 +00:00
|
|
|
|
2014-09-26 02:42:10 +00:00
|
|
|
for (int i=0; i<MAX_HIGH_SCORES; i++ ) {
|
2017-02-11 21:42:37 +00:00
|
|
|
gr_set_fontcolor(canvas, BM_XRGB(28 - i * 2, 28 - i * 2, 28 - i * 2), -1);
|
2020-09-21 03:18:12 +00:00
|
|
|
scores_draw_item(canvas, game_font, i, &scores.stats[i]);
|
2010-02-07 06:00:10 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 03:18:12 +00:00
|
|
|
if (citem > -1)
|
|
|
|
{
|
|
|
|
gr_set_fontcolor(canvas, BM_XRGB(7 + fades[looper], 7 + fades[looper], 7 + fades[looper]), -1);
|
|
|
|
if (timer_query() >= t1 + F1_0 / 128)
|
2010-02-07 06:00:10 +00:00
|
|
|
{
|
2020-09-21 03:18:12 +00:00
|
|
|
t1 = timer_query();
|
|
|
|
looper++;
|
|
|
|
if (looper > 63)
|
|
|
|
looper = 0;
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
2010-02-07 06:00:10 +00:00
|
|
|
|
2020-09-21 03:18:12 +00:00
|
|
|
scores_draw_item(canvas, game_font, citem, citem == MAX_HIGH_SCORES
|
|
|
|
? &last_game
|
|
|
|
: &scores.stats[citem]);
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
2017-02-11 21:42:37 +00:00
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
break;
|
2010-02-07 06:00:10 +00:00
|
|
|
case EVENT_WINDOW_CLOSE:
|
|
|
|
break;
|
|
|
|
default:
|
2006-03-20 17:12:09 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-08-06 02:10:49 +00:00
|
|
|
return window_event_result::ignored;
|
2010-02-07 06:00:10 +00:00
|
|
|
}
|
|
|
|
|
2020-12-20 20:39:07 +00:00
|
|
|
void scores_view(const stats_info *const last_game, int citem)
|
2010-02-07 06:00:10 +00:00
|
|
|
{
|
2020-09-21 03:18:12 +00:00
|
|
|
const auto &&fspacx320 = FSPACX(320);
|
|
|
|
const auto &&fspacy200 = FSPACY(200);
|
2020-12-20 20:39:07 +00:00
|
|
|
auto menu = window_create<scores_menu>(grd_curscreen->sc_canvas, (SWIDTH - fspacx320) / 2, (SHEIGHT - fspacy200) / 2, fspacx320, fspacy200, citem, last_game);
|
2010-02-07 06:00:10 +00:00
|
|
|
|
2010-07-31 12:09:38 +00:00
|
|
|
newmenu_free_background();
|
2010-02-07 06:00:10 +00:00
|
|
|
|
2010-02-08 04:10:21 +00:00
|
|
|
scores_read(&menu->scores);
|
2010-02-07 06:00:10 +00:00
|
|
|
|
|
|
|
set_screen_mode(SCREEN_MENU);
|
2010-04-03 10:16:53 +00:00
|
|
|
show_menus();
|
2020-09-21 03:18:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void scores_view_menu()
|
|
|
|
{
|
|
|
|
scores_view(nullptr, -1);
|
|
|
|
}
|
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|