Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add progress bar to skills view. #359

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/modify.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ void parse_action(int command, char *string, DescriptorData *d);

/* PAGING */
/* page_string and page_string_desc will also start paging */
void page_string(CharData *ch, const char *str);
void page_string_desc(DescriptorData *d, const char *str);
void page_string(CharData *ch, std::string_view str);
void page_string_desc(DescriptorData *d, std::string_view str);

/* paging_printf will collect data, but you must then call start_paging */
template <typename... Args> void paging_printf(CharData *ch, std::string_view messg, Args &&...args) {
Expand Down
4 changes: 3 additions & 1 deletion include/string_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ bool is_equals(const std::string_view &lhs, const std::string_view &rhs);
// [[nodiscard]] bool matches_end(std::string_view lhs, std::string_view rhs);

// // Is 'needle' contained inside 'haystack' case insensitively?
// [[nodiscard]] bool matches_inside(std::string_view needle, std::string_view haystack);
// [[nodiscard]] bool matches_inside(std::string_view needle, std::string_view haystack);

[[nodiscard]] std::string progress_bar(int current, int wall = 0, int max = 1000);
58 changes: 22 additions & 36 deletions src/act.informative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3476,25 +3476,25 @@ ACMD(do_score) {

const char *proficiency_message(int proficiency) {
if (proficiency == 0)
return "not learned";
return "(not learned)";
else if (proficiency <= 100)
return "awful";
return "(awful)";
else if (proficiency <= 200)
return "bad";
return "(bad)";
else if (proficiency <= 400)
return "poor";
return "(poor)";
else if (proficiency <= 550)
return "average";
return "(average)";
else if (proficiency <= 700)
return "fair";
return "(fair)";
else if (proficiency <= 800)
return "good";
return "(good)";
else if (proficiency <= 850)
return "very good";
return "(very good)";
else if (proficiency <= 999)
return "superb";
return "(superb)";
else
return "mastered";
return "(mastered)";
}

#define MAX_CIRCLE 14
Expand Down Expand Up @@ -3773,14 +3773,11 @@ ACMD(do_listspells) {

ACMD(do_skills) {
int level_max_skill(CharData * ch, int level, int skill);
const char *fullmastered = " &7-&b*&0&7-&0";
const char *mastered = " * ";
const char *normal = " ";
const char *mastery;
int i, x;
CharData *tch;
char points[MAX_INPUT_LENGTH];
bool godpeek;
std::string result;

one_argument(argument, arg);

Expand All @@ -3794,17 +3791,14 @@ ACMD(do_skills) {
char_printf(ch, "There's nobody here by that name.\n");
return;
}
sprintf(buf, "%s knows of the following skills:\n", GET_NAME(tch));
result = fmt::format("{} knows of the following skills:\n", GET_NAME(tch));
godpeek = true;
} else {
strcpy(buf, "You know of the following skills:\n");
result = "You know of the following skills:\n";
tch = ch;
godpeek = false;
}

strcpy(buf2, buf);
points[0] = '\0';

/* do_skills crashes when performed by non-switched mobs. */
if (IS_NPC(ch) && !ch->desc)
return;
Expand All @@ -3818,28 +3812,20 @@ ACMD(do_skills) {
if (GET_SKILL(tch, i) <= 0)
continue;

if (godpeek)
sprintf(points, " (%4d/%4d/%4d)", GET_ISKILL(tch, i), return_max_skill(tch, i),
level_max_skill(tch, LVL_MAX_MORT, i));

/* Show a star if the skill is as good as possible. */
if (GET_ISKILL(tch, i) >= level_max_skill(tch, LVL_MAX_MORT, i))
mastery = fullmastered;
else if (GET_ISKILL(tch, i) >= return_max_skill(tch, i))
mastery = mastered;
else
mastery = normal;

/* Show exact skill numbers of mobs when switched. */
sprintf(buf1, "(%s)", proficiency_message(GET_ISKILL(tch, i)));
result += fmt::format("{:<22} {:<15} ", skills[i].name, proficiency_message(GET_ISKILL(tch, i)));
if (POSSESSED(tch) && GET_LEVEL(POSSESSOR(tch)) >= LVL_IMMORT) {
sprintf(buf, "%-22s %15s [%4d]%s%s\n", skills[i].name, buf1, GET_ISKILL(tch, i), mastery, points);
result += fmt::format("[{:4d}]", GET_ISKILL(tch, i));
} else {
sprintf(buf, "%-22s %15s%s%s\n", skills[i].name, buf1, mastery, points);
result += progress_bar(GET_ISKILL(tch, i), return_max_skill(tch, i));
}
if (godpeek) {
result += fmt::format("({:4d}/{:4d}/{:4d})", GET_ISKILL(tch, i), return_max_skill(tch, i),
level_max_skill(tch, LVL_MAX_MORT, i));
}
strcat(buf2, buf);
result += "\n";
}
page_string(ch, buf2);
page_string(ch, result);
}

static int scan_chars(CharData *ch, int room, int dis, int dir, int seen_any) {
Expand Down
4 changes: 2 additions & 2 deletions src/modify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -958,12 +958,12 @@ void start_paging(CharData *ch) {
start_paging_desc(ch->desc);
}

void page_string(CharData *ch, const char *str) {
void page_string(CharData *ch, std::string_view str) {
if (ch->desc)
page_string_desc(ch->desc, str);
}

void page_string_desc(DescriptorData *d, const char *str) {
void page_string_desc(DescriptorData *d, std::string_view str) {
paging_addstr(d, str);
if (!d->page_outbuf->empty())
start_paging_desc(d);
Expand Down
27 changes: 27 additions & 0 deletions src/string_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,30 @@ bool matches_start(std::string_view lhs, std::string_view rhs) {
// auto haystack_low = haystack | std::ranges::views::transform(tolower);
// return !std::ranges::search(haystack_low, needle_low).empty();
// }

std::string progress_bar(int current, int wall, int max) {
double percentage = static_cast<double>(current) / max * 100;
double level_percentage = static_cast<double>(current) / wall * 100;

if (level_percentage < percentage || max < wall)
return "";

// Define progress bar lengths
const int bar_length = 40;

if (current >= max) {
return fmt::format("[{:#^{}}]", " MASTERED ", bar_length);
}

// Calculate filled portion for each bar
int fill = static_cast<int>(percentage / 100 * bar_length);
int wall_position = static_cast<int>(level_percentage / 100 * bar_length);

// Create progress bars
std::string progress_bar = "[" + std::string(fill, '#') + std::string(wall_position - fill, '=');
if (bar_length - wall_position > 0)
progress_bar += std::string(bar_length - wall_position, '-');
progress_bar += "]";

return progress_bar;
}
Loading