save the YASC messages in save file, and display them in score list; also auto-width and zoom

This commit is contained in:
Zeno Rogue 2024-02-23 00:39:12 +01:00
parent 55493cc364
commit 00b5fe3a22
3 changed files with 64 additions and 19 deletions

View File

@ -439,6 +439,7 @@ EX void checkmove() {
achievement_final(true); achievement_final(true);
if(cmode & sm::NORMAL) showMissionScreen(); if(cmode & sm::NORMAL) showMissionScreen();
} }
else yasc_message = "";
if(canmove && timerstopped) { if(canmove && timerstopped) {
timerstart = time(NULL); timerstart = time(NULL);

View File

@ -22,12 +22,16 @@ string csub(const string& str, int q) {
return str.substr(0, i); return str.substr(0, i);
} }
vector<int> column_width(POSSCORE+1, 4);
int colwidth(int scoredisplay) { int colwidth(int scoredisplay) {
if(scoredisplay == 0) return 5; return column_width[scoredisplay];
/* if(scoredisplay == 0) return 5;
if(scoredisplay == 1) return 16; if(scoredisplay == 1) return 16;
if(scoredisplay == 5) return 8; if(scoredisplay == 5) return 8;
if(scoredisplay == POSSCORE) return 8; if(scoredisplay == POSSCORE) return 8;
return 4; if(scoredisplay == 68) return yasc_width;
return 4; */
} }
bool isHardcore(score *S) { bool isHardcore(score *S) {
@ -91,6 +95,7 @@ string displayfor(int scoredisplay, score* S, bool shorten = false) {
if(scoredisplay == 67) return XLAT("cheats"); if(scoredisplay == 67) return XLAT("cheats");
if(scoredisplay == 66) return XLAT("saves"); if(scoredisplay == 66) return XLAT("saves");
if(scoredisplay == 197) return XLAT("players"); if(scoredisplay == 197) return XLAT("players");
if(scoredisplay == 68) return XLAT("where");
return csub(str, 5); return csub(str, 5);
} }
if(scoredisplay == 0 || scoredisplay == 65) { if(scoredisplay == 0 || scoredisplay == 65) {
@ -103,6 +108,7 @@ string displayfor(int scoredisplay, score* S, bool shorten = false) {
return buf; return buf;
} }
if(scoredisplay == POSSCORE) return modedesc(S); if(scoredisplay == POSSCORE) return modedesc(S);
if(scoredisplay == 68) return S->yasc_message + XLAT(" in %the1", eLand(S->box[68]));
if(scoredisplay == 1) { if(scoredisplay == 1) {
time_t tim = S->box[1]; time_t tim = S->box[1];
char buf[128]; strftime(buf, 128, "%c", localtime(&tim)); char buf[128]; strftime(buf, 128, "%c", localtime(&tim));
@ -162,27 +168,39 @@ void showPickScores() {
}; };
} }
int scale = 2;
void show() { void show() {
if(columns.size() == 0) { if(columns.size() == 0) {
columns.push_back(POSSCORE); columns.push_back(POSSCORE);
for(int i=0; i<POSSCORE; i++) columns.push_back(i); for(int i=0; i<POSSCORE; i++) {
if(i == 5) columns.push_back(68);
else if(i == 68) columns.push_back(5);
else columns.push_back(i);
}
} }
int y = vid.fsize * 5/2; int score_size = vid.fsize / scale;
int bx = vid.fsize; int y = score_size * 5/2;
int bx = score_size;
getcstat = 0; getcstat = 0;
displaystr(bx*4, vid.fsize, 0, vid.fsize, "#", forecolor, 16); displaystr(bx*4, score_size, 0, vid.fsize, "#", forecolor, 16);
displaystr(bx*8, vid.fsize, 0, vid.fsize, XLAT("ver"), forecolor, 16); displaystr(bx*8, score_size, 0, vid.fsize, XLAT("ver"), forecolor, 16);
int at = 9; int at = 9;
for(int i=0; i<=POSSCORE; i++) { for(int i=0; i<=POSSCORE; i++) {
int c = columns[i]; int c = columns[i];
if(bx*at > vid.xres) break; if(bx*at > vid.xres) break;
if(displaystr(bx*at, vid.fsize, 0, vid.fsize, displayfor(c, NULL, true), i == curcol ? 0xFFD500 : forecolor, 0)) string s = displayfor(c, NULL, true);
auto& cw = column_width[c];
cw = max(cw, textwidth(score_size, s) / bx + 1);
if(displaystr(bx*at, score_size, 0, score_size, s, i == curcol ? 0xFFD500 : forecolor, 0))
getcstat = 1000+i; getcstat = 1000+i;
at += colwidth(c); at += colwidth(c);
} }
vector<int> next_column_width(POSSCORE+1, 0);
if(scorefrom < 0) scorefrom = 0; if(scorefrom < 0) scorefrom = 0;
int id = 0; int id = 0;
@ -205,28 +223,40 @@ void show() {
rank++; rank++;
displaystr(bx*4, y, 0, vid.fsize, its(rank), col, 16); displaystr(bx*4, y, 0, score_size, its(rank), col, 16);
displaystr(bx*8, y, 0, vid.fsize, S.ver, col, 16); displaystr(bx*8, y, 0, score_size, S.ver, col, 16);
int at = 9; int at = 9;
for(int i=0; i<=POSSCORE; i++) { for(int i=0; i<=POSSCORE; i++) {
int c = columns[i]; int c = columns[i];
if(bx*at > vid.xres) break; if(bx*at > vid.xres) break;
at += colwidth(c); string s = displayfor(c, &S);
if(displaystr(bx*(at-1), y, 0, vid.fsize, displayfor(c, &S), col, 16)) auto& ncw = next_column_width[c];
getcstat = 1000+i; ncw = max(ncw, textwidth(score_size, s) / bx + 1);
if(c == 68) {
if(displaystr(bx*at, y, 0, score_size, s, col, 0))
getcstat = 1000+i;
at += colwidth(c);
}
else {
at += colwidth(c);
if(displaystr(bx*(at-1), y, 0, score_size, s, col, 16))
getcstat = 1000+i;
}
} }
y += vid.fsize*5/4; id++; y += score_size*5/4; id++;
} }
column_width = next_column_width;
int i0 = vid.yres - vid.fsize; int i0 = vid.yres - vid.fsize;
int xr = vid.xres / 80; int xr = vid.xres / 80;
displayButton(xr*10, i0, IFM("s - ") + XLAT("sort"), 's', 8); displayButton(xr*10, i0, IFM("s - ") + XLAT("sort"), 's', 8);
displayButton(xr*30, i0, IFM("t - ") + XLAT("choose"), 't', 8); displayButton(xr*30, i0, IFM("t - ") + XLAT("choose"), 't', 8);
displayButton(xr*50, i0, IFM(dialog::keyname(SDLK_ESCAPE) + " - ") + XLAT("go back"), '0', 8); displayButton(xr*50, i0, IFM("z - ") + XLAT("zoom"), 'z', 8);
displayButton(xr*70, i0, IFM(dialog::keyname(SDLK_ESCAPE) + " - ") + XLAT("go back"), '0', 8);
keyhandler = [] (int sym, int uni) { keyhandler = [] (int sym, int uni) {
if(DKEY == SDLK_LEFT || uni == 'h' || uni == 'a') { if(DKEY == SDLK_LEFT || uni == 'h' || uni == 'a') {
@ -246,6 +276,7 @@ void show() {
scorefrom -= 5; scorefrom -= 5;
else if(DKEY == SDLK_DOWN || uni == 'j' || uni == 'x') else if(DKEY == SDLK_DOWN || uni == 'j' || uni == 'x')
scorefrom += 5; scorefrom += 5;
else if(uni == 'z') scale = 3 - scale;
else if(sym == PSEUDOKEY_WHEELUP) else if(sym == PSEUDOKEY_WHEELUP)
scorefrom--; scorefrom--;
else if(sym == PSEUDOKEY_WHEELDOWN) else if(sym == PSEUDOKEY_WHEELDOWN)
@ -289,9 +320,11 @@ void load() {
addMessage(s0 + "Could not open the score file: " + scorefile); addMessage(s0 + "Could not open the score file: " + scorefile);
return; return;
} }
string *yasc = nullptr;
while(!feof(f)) { while(!feof(f)) {
char buf[120]; const int buflen = 1200;
if(fgets(buf, 120, f) == NULL) break; char buf[buflen];
if(fgets(buf, buflen, f) == NULL) break;
if(buf[0] == 'H' && buf[1] == 'y') { if(buf[0] == 'H' && buf[1] == 'y') {
score sc; bool ok = true; score sc; bool ok = true;
sc.box[MAXBOX-1] = 0; sc.box[MAXBOX-1] = 0;
@ -320,7 +353,14 @@ void load() {
if(sc.box[2] == 0) continue; // do not list zero scores if(sc.box[2] == 0) continue; // do not list zero scores
sc.box[POSSCORE] = modediff(&sc); sc.box[POSSCORE] = modediff(&sc);
if(ok && boxid > 20) scores.push_back(sc); if(ok && boxid > 20) {
scores.push_back(sc);
yasc = &scores.back().yasc_message;
}
}
if(buf[0] == 'Y' && buf[1] == 'A' && buf[2] == 'S' && buf[3] == 'C' && buf[4] == ' ') {
for(int i=5; i<buflen; i++) if(buf[i] == '\n' || buf[i] == '\r') buf[i] = 0;
*yasc = buf+5;
} }
} }
@ -329,6 +369,7 @@ void load() {
for(int i=0; i<POSSCORE; i++) sc.box[i] = save.box[i]; for(int i=0; i<POSSCORE; i++) sc.box[i] = save.box[i];
sc.box[POSSCORE] = 0; sc.box[POSSCORE] = 0;
sc.box[MAXBOX-1] = 1; sc.ver = "NOW"; sc.box[MAXBOX-1] = 1; sc.ver = "NOW";
sc.yasc_message = canmove ? "on the run" : yasc_message;
scores.push_back(sc); scores.push_back(sc);
fclose(f); fclose(f);

View File

@ -451,6 +451,8 @@ struct score {
string ver; string ver;
/** \brief all the data of the saved score, see applyBoxes() */ /** \brief all the data of the saved score, see applyBoxes() */
int box[MAXBOX]; int box[MAXBOX];
/** \brief yasc message */
string yasc_message;
}; };
#endif #endif
@ -620,7 +622,7 @@ EX void applyBoxes() {
if(saving) savecount--; if(saving) savecount--;
applyBoxNum(cheater, "number of cheats"); applyBoxNum(cheater, "number of cheats");
fakebox[boxid] = true; fakebox[boxid] = false;
if(saving) applyBoxSave(items[itOrbSafety] ? safetyland : cwt.at->land, "@safetyland"); if(saving) applyBoxSave(items[itOrbSafety] ? safetyland : cwt.at->land, "@safetyland");
else if(loading) firstland = safetyland = eLand(applyBoxLoad("@safetyland")); else if(loading) firstland = safetyland = eLand(applyBoxLoad("@safetyland"));
else lostin = eLand(save.box[boxid++]); else lostin = eLand(save.box[boxid++]);
@ -1139,6 +1141,7 @@ EX void saveStats(bool emergency IS(false)) {
anticheat::save(f); anticheat::save(f);
fprintf(f, "\n"); fprintf(f, "\n");
if(yasc_message != "") fprintf(f, "YASC %s\n", yasc_message.c_str());
} }
fprintf(f, "Played on: %s - %s (%d %s)\n", sbuf, buf, turncount, fprintf(f, "Played on: %s - %s (%d %s)\n", sbuf, buf, turncount,
shmup::on ? "knives" : "turns"); shmup::on ? "knives" : "turns");