From a77aded7aebe5410c89128ad94ab391b7ece1686 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Wed, 26 Dec 2018 15:31:53 -0500 Subject: Show adjacent scores when not in top --- play.c | 53 +++++++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/play.c b/play.c index 61df0ba..c5310ff 100644 --- a/play.c +++ b/play.c @@ -89,12 +89,6 @@ static void curse(void) { erase(); } -static void addchn(char ch, uint n) { - for (uint i = 0; i < n; ++i) { - addch(ch); - } -} - enum { ScoresTop = 15, ScoresY = 0, @@ -106,43 +100,55 @@ enum { }; static const char ScoresTitle[] = "TOP SCORES"; -static int scoreY(size_t i) { - if (i < ScoresTop) return ScoresY + 2 + i; - return ScoresY + 3 + ScoresTop; -} - -static void drawScore(size_t i) { +static void drawScore(int y, size_t i) { char buf[11]; snprintf(buf, sizeof(buf), "%3zu.", 1 + i); - mvaddstr(scoreY(i), ScoresX, buf); + mvaddstr(y, ScoresX, buf); snprintf(buf, sizeof(buf), "%10d", scores[i].score); - mvaddstr(scoreY(i), ScoreX, buf); + mvaddstr(y, ScoreX, buf); - mvaddstr(scoreY(i), NameX, scores[i].name); + mvaddstr(y, NameX, scores[i].name); struct tm *time = localtime(&scores[i].date); if (!time) err(EX_SOFTWARE, "localtime"); char date[sizeof("YYYY-MM-DD")]; strftime(date, sizeof(date), "%F", time); - mvaddstr(scoreY(i), DateX, date); + mvaddstr(y, DateX, date); } static void draw(size_t new) { - move(ScoresY, ScoresX + (ScoresWidth - sizeof(ScoresTitle) + 2) / 2); - addstr(ScoresTitle); - move(ScoresY + 1, ScoresX); - addchn('=', ScoresWidth); + mvaddstr( + ScoresY, ScoresX + (ScoresWidth - sizeof(ScoresTitle) + 2) / 2, + ScoresTitle + ); + mvhline(ScoresY + 1, ScoresX, '=', ScoresWidth); + + int newY; for (size_t i = 0; i < ScoresTop; ++i) { if (!scores[i].score) break; + if (i == new) newY = ScoresY + 2 + i; attr_set(i == new ? A_BOLD : A_NORMAL, 0, NULL); - drawScore(i); + drawScore(ScoresY + 2 + i, i); } if (new == ScoresLen) return; + if (new >= ScoresTop) { + newY = ScoresY + ScoresTop + 5; + mvhline(newY - 3, ScoresX, '=', ScoresWidth); + drawScore(newY - 2, new - 2); + drawScore(newY - 1, new - 1); attr_set(A_BOLD, 0, NULL); - drawScore(new); + drawScore(newY, new); + attr_set(A_NORMAL, 0, NULL); + if (new + 1 < ScoresLen && scores[new + 1].score) { + drawScore(newY + 1, new + 1); + } + if (new + 2 < ScoresLen && scores[new + 2].score) { + drawScore(newY + 2, new + 2); + } } + move(newY, NameX); } int main(void) { @@ -157,7 +163,7 @@ int main(void) { draw(index); if (index < ScoresLen) { attr_set(A_BOLD, 0, NULL); - mvgetnstr(scoreY(index), NameX, new.name, sizeof(new.name) - 1); + getnstr(new.name, sizeof(new.name) - 1); scoresLock(file); scoresRead(file); @@ -169,7 +175,6 @@ int main(void) { curs_set(0); getch(); endwin(); - printf( "This program is AGPLv3 Free Software!\n" "Code is available from .\n" -- cgit 1.4.1 =5bc99f81f551075f82f6d2438e4d80d768536fcb&follow=1'>Set txt mtimes to source mtimesJune McEnroe 2022-04-20Make (pun) the dependencies make (pun) more senseJune McEnroe 2022-04-17Add HenchJune McEnroe There are some truly horrifying and gruesome bits though. 2022-04-14Publish "Agency"June McEnroe 2022-04-13Swap dates so the difference is always positiveJune McEnroe 2022-04-04Update "Care"June McEnroe 2022-04-03Publish "Care"June McEnroe 2022-03-31Publish "Compassion"June McEnroe 2022-03-24Skip matches with ident chars on either sideJune McEnroe This fixes, for example, where the link gets placed on static regex_t regex(const char *pattern, int flags) in title.c. 2022-03-24Add The Invisible Life of Addie LaRueJune McEnroe So good, but so long. Reminded me of The Ten Thousand Doors of January at the beginning, and more of that N. K. Jemisin series about gods later. I like this interacting with gods and becoming something like one sort of thing. God, it took me a whole month (more?) to read and this is only my third book of the year :( I need some more novellas to read, but the other books I have from the library currently are also thick. 2022-03-22Source ~/.profile.local if it existsJune McEnroe 2022-03-18Publish "Addendum 2021"June McEnroe 2022-03-16Remove wcwidth portJune McEnroe DYLD_FORCE_FLAT_NAMESPACE no longer exists in macOS 12 so this approach doesn't work anymore. Moved to <https://git.causal.agency/jorts/tree/wcwidth> and compiled into <https://git.causal.agency/jorts/tree/ncurses>. 2022-03-16Remove -j4 from ./PlanJune McEnroe Plan learned to set this automatically! 2022-03-15Rewrite Linux install.sh for DebianJune McEnroe 2022-03-15Remove dashJune McEnroe