+ sq_pushstring(vm, "statistics", -1);
+ if(SQ_FAILED(sq_get(vm, -2))) {
+ return;
+ }
+ Scripting::get_int(vm, "coins-collected", coins);
+ Scripting::get_int(vm, "coins-collected-total", total_coins);
+ Scripting::get_int(vm, "badguys-killed", badguys);
+ Scripting::get_int(vm, "badguys-killed-total", total_badguys);
+ Scripting::get_float(vm, "time-needed", time);
+ Scripting::get_int(vm, "secrets-found", secrets);
+ Scripting::get_int(vm, "secrets-found-total", total_secrets);
+ sq_pop(vm, 1);
+}
+
+void
+Statistics::draw_worldmap_info(DrawingContext& context)
+{
+ // skip draw if level was never played
+ if (coins == nv_coins) return;
+
+ // skip draw if stats were declared invalid
+ if (!valid) return;
+
+ context.draw_text(white_small_text, std::string("- ") + _("Best Level Statistics") + " -", Vector((WMAP_INFO_LEFT_X + WMAP_INFO_RIGHT_X) / 2, WMAP_INFO_TOP_Y1), ALIGN_CENTER, LAYER_GUI);
+
+ std::string caption_buf;
+ std::string stat_buf;
+ float posy = WMAP_INFO_TOP_Y2;
+ for (int stat_no = 0; stat_no < 4; stat_no++) {
+ switch (stat_no)
+ {
+ case 0:
+ caption_buf = _("Max coins collected:");
+ stat_buf = coins_to_string(coins, total_coins);
+ break;
+ case 1:
+ caption_buf = _("Max fragging:");
+ stat_buf = frags_to_string(badguys, total_badguys);
+ break;
+ case 2:
+ caption_buf = _("Min time needed:");
+ stat_buf = time_to_string(time);
+ break;
+ case 3:
+ caption_buf = _("Max secrets found:");
+ stat_buf = secrets_to_string(secrets, total_secrets);
+ break;
+ default:
+ log_debug << "Invalid stat requested to be drawn" << std::endl;
+ break;
+ }
+
+ context.draw_text(white_small_text, caption_buf, Vector(WMAP_INFO_LEFT_X, posy), ALIGN_LEFT, LAYER_GUI);
+ context.draw_text(white_small_text, stat_buf, Vector(WMAP_INFO_RIGHT_X, posy), ALIGN_RIGHT, LAYER_GUI);
+ posy += white_small_text->get_height() + 2;
+ }
+
+}
+
+void
+Statistics::draw_message_info(DrawingContext& context, std::string title)
+{
+ // skip draw if level was never played
+ // TODO: do we need this?
+ if (coins == nv_coins) return;
+
+ // skip draw if stats were declared invalid
+ if (!valid) return;
+
+ const float width = white_small_text->get_text_width("Max coins collected: 1111 / 1111");
+ const float left = (SCREEN_WIDTH - width) / 2;
+ const float right = (SCREEN_WIDTH + width) / 2;
+
+ context.draw_text(gold_text, title, Vector(SCREEN_WIDTH/2, 410), ALIGN_CENTER, LAYER_GUI);
+
+ char stat_buf[128];
+ int py = 450 + 18;
+
+ snprintf(stat_buf, sizeof(stat_buf), "%d/%d", coins, total_coins);
+ context.draw_text(white_small_text, _("Max coins collected:"), Vector(left, py), ALIGN_LEFT, LAYER_GUI);
+ context.draw_text(white_small_text, "%d / %d", Vector(right, py), ALIGN_RIGHT, LAYER_GUI);
+ py+=18;
+
+ snprintf(stat_buf, sizeof(stat_buf), "%d/%d", badguys, total_badguys);
+ context.draw_text(white_small_text, _("Max fragging:"), Vector(left, py), ALIGN_LEFT, LAYER_GUI);
+ context.draw_text(white_small_text, "%d / %d", Vector(right, py), ALIGN_RIGHT, LAYER_GUI);
+ py+=18;
+
+ int csecs = (int)(time * 100);
+ int mins = (int)(csecs / 6000);
+ int secs = (csecs % 6000) / 100;
+ snprintf(stat_buf, sizeof(stat_buf), "%02d:%02d", mins,secs);
+ context.draw_text(white_small_text, _("Min time needed:"), Vector(left, py), ALIGN_LEFT, LAYER_GUI);
+ context.draw_text(white_small_text, "%02d:%02d", Vector(right, py), ALIGN_RIGHT, LAYER_GUI);
+ py+=18;
+
+ snprintf(stat_buf, sizeof(stat_buf), "%d/%d", secrets, total_secrets);
+ context.draw_text(white_small_text, _("Max secrets found:"), Vector(left, py), ALIGN_LEFT, LAYER_GUI);
+ context.draw_text(white_small_text, "%d / %d", Vector(right, py), ALIGN_RIGHT, LAYER_GUI);
+ py+=18;