-
-
Notifications
You must be signed in to change notification settings - Fork 490
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
Show progress in contrib level menus #2040
Changes from 20 commits
1e4e892
04a74bc
bc2d9ab
52939eb
58d29bd
b909c73
57534e0
dfbd5f9
530213c
21d2da2
d183fc7
2385e16
2dbe201
56a18ce
45a7f56
4ef2dcd
831ea4a
6c3dc29
c3ea663
35c299d
18901b6
3ad4cdc
e5b9fbd
30a696d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
(supertux-level | ||
(version 3) | ||
(name (_ "Halloween 2014")) | ||
(name (_ "Halloween Special")) | ||
(author "Ingo Ruhnke") | ||
(contact "[email protected]") | ||
(license "CC-BY-SA 4.0 International") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
// SuperTux | ||
// Copyright (C) 2021 mrkubax10 <[email protected]> | ||
// 2021 Jiri Palecek <[email protected]> | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
|
@@ -17,15 +18,19 @@ | |
#include "supertux/menu/sorted_contrib_menu.hpp" | ||
|
||
#include <sstream> | ||
#include "util/gettext.hpp" | ||
|
||
#include "boost/format.hpp" | ||
|
||
#include "gui/menu_manager.hpp" | ||
#include "gui/menu_item.hpp" | ||
#include "gui/item_action.hpp" | ||
#include "supertux/savegame.hpp" | ||
#include "supertux/player_status.hpp" | ||
#include "supertux/levelset.hpp" | ||
#include "supertux/game_manager.hpp" | ||
#include "supertux/menu/contrib_levelset_menu.hpp" | ||
#include "gui/menu_manager.hpp" | ||
#include "gui/menu_item.hpp" | ||
#include "gui/item_action.hpp" | ||
#include "util/gettext.hpp" | ||
|
||
SortedContribMenu::SortedContribMenu(std::vector<std::unique_ptr<World>>& worlds, const std::string& contrib_type, const std::string& title, const std::string& empty_message) : | ||
m_world_folders() | ||
{ | ||
|
@@ -38,10 +43,83 @@ SortedContribMenu::SortedContribMenu(std::vector<std::unique_ptr<World>>& worlds | |
{ | ||
m_world_folders.push_back(worlds[i]->get_basedir()); | ||
std::string title_str; | ||
const auto savegame = Savegame::from_file(worlds[i]->get_savegame_filename()); | ||
|
||
if (worlds[i]->is_levelset()) | ||
title_str = "[" + worlds[i]->get_title() + "]"; | ||
{ | ||
uint32_t level_count = 0, solved_count = 0; | ||
const auto& state = savegame->get_levelset_state(worlds[i]->get_basedir()); | ||
|
||
for (const auto& level_state : state.level_states) | ||
{ | ||
if (level_state.filename.empty() || level_state.filename.back() == '~') continue; | ||
if (level_state.solved) ++solved_count; | ||
++level_count; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like this counting logic doesn't belong here, and could be better reused, if it was moved to a dedicated |
||
|
||
if (!level_count) | ||
{ | ||
title_str = str(boost::format(_("[%s] *NEW*")) % worlds[i]->get_title()); | ||
} | ||
else | ||
{ | ||
title_str = str(boost::format(_("[%s] (%u/%u; %u%%)")) % worlds[i]->get_title() % | ||
solved_count % level_count % (100 * solved_count / level_count)); | ||
} | ||
} | ||
else | ||
title_str = worlds[i]->get_title(); | ||
{ | ||
uint32_t island_level_count = 0, island_solved_count = 0, | ||
world_level_count = 0, world_solved_count = 0; | ||
std::string wm_filename = savegame->get_player_status().last_worldmap; | ||
|
||
if (wm_filename.empty()) | ||
wm_filename = worlds[i]->get_worldmap_filename(); | ||
|
||
wm_filename = "/" + wm_filename; | ||
|
||
const auto& state = savegame->get_worldmap_state(wm_filename); | ||
for (const auto& level_state : state.level_states) | ||
{ | ||
if (level_state.filename.empty()) continue; | ||
if (level_state.solved) ++island_solved_count; | ||
++island_level_count; | ||
} | ||
|
||
const auto levelset = std::unique_ptr<Levelset>(new Levelset(worlds[i]->get_basedir(), true)); | ||
world_level_count = levelset->get_num_levels(); | ||
const auto world_list = savegame->get_worldmaps(); | ||
|
||
for (const auto& world : world_list) | ||
{ | ||
const auto& world_state = savegame->get_worldmap_state(world); | ||
for (const auto& level_state : world_state.level_states) | ||
{ | ||
if (level_state.filename.empty()) continue; | ||
if (level_state.solved) ++world_solved_count; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as before, but for |
||
|
||
if (!island_level_count && !world_solved_count) | ||
title_str = str(boost::format(_("%s *NEW*")) % worlds[i]->get_title()); | ||
else | ||
{ | ||
const auto wm_title = savegame->get_player_status().last_worldmap_title; | ||
|
||
if (island_level_count == world_level_count) | ||
{ | ||
title_str = str(boost::format(_("%s (%u/%u; %u%%)")) % worlds[i]->get_title() % | ||
island_solved_count % island_level_count % (100 * island_solved_count / island_level_count)); | ||
} | ||
else | ||
{ | ||
title_str = str(boost::format(_("%s (%u/%u; %u%%) - %s (%u/%u; %u%%)")) % worlds[i]->get_title() % | ||
world_solved_count % world_level_count % (100 * world_solved_count / world_level_count) % | ||
wm_title % island_solved_count % island_level_count % | ||
(island_level_count ? (100 * island_solved_count / island_level_count) : 100)); | ||
} | ||
} | ||
} | ||
add_entry(world_id++, title_str).set_help(worlds[i]->get_description()); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,7 @@ class PlayerStatus final | |
|
||
std::string worldmap_sprite; /**< the sprite of Tux that should be used in worldmap */ | ||
std::string last_worldmap; /**< the last played worldmap */ | ||
std::string last_worldmap_title; /**< the title of the last played worldmap */ | ||
|
||
Comment on lines
+64
to
65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Marking this in case the worldmap data gets removed, this variable will be unnecessary. |
||
private: | ||
PlayerStatus(const PlayerStatus&) = delete; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were the name changes intended to be part of this PR? (They weren't mentioned in the PR desc)
There's also
Community Island 2020
->Community Island
andHaloween 2014
->Halloween Special
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed them because I originally had that check in place that would show both names from
info
and the name of the worldmap if the titles didn't match even if the level counts did. I removed that check now (that's what I wanted feedback about, but ultimately decided was pointless and removed it), so the titles don't need to be changed anymore. I still think it's better this way (the worldmap titles are consistent with the title in theinfo
file), but if you think I should change them back, I will. These don't show up anywhere in the game anyway.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a matter of principle, it would be preferable to discuss add-on renamings with the community, just to ensure that the new name makes sense and that everybody is fine with it.