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

Show progress in contrib level menus #2040

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1e4e892
show progress in levelsets
Narre Dec 28, 2021
04a74bc
Remove debug prints
Narre Dec 28, 2021
bc2d9ab
show progress in worldmaps (WIP)
Narre Dec 28, 2021
52939eb
Show the progress of the last worldmap instead of worldmap.stwm
Narre Dec 28, 2021
58d29bd
Show current worldmap by name instead of file path (WIP, temporary so…
Narre Dec 28, 2021
b909c73
Only show worldmap title if it doesn't match addon title and isn't empty
Narre Dec 28, 2021
57534e0
Optimise getting worldmap title
Narre Dec 28, 2021
dfbd5f9
Add a progress indicator for entire worlds (not just the current worl…
Narre Dec 28, 2021
530213c
Add my name to sorted_contrib_menu.cpp since I now wrote most of it
Narre Dec 28, 2021
21d2da2
Clean up the code
Narre Dec 28, 2021
d183fc7
Replace == "" with .empty()
Narre Dec 28, 2021
2385e16
Name official contrib levels' worldmaps consistently with the world name
Narre Dec 28, 2021
2dbe201
Remove unused line
Narre Dec 29, 2021
56a18ce
Fix division by zero
Narre Dec 29, 2021
45a7f56
Const correctness
Narre Dec 29, 2021
4ef2dcd
Only separate world and worldmap if not all levels are present in the…
Narre Dec 29, 2021
831ea4a
More const-ness
Narre Dec 29, 2021
6c3dc29
Code quality
Narre Jan 3, 2022
c3ea663
Remove unnecessary comments [ci skip]
Narre Jan 5, 2022
35c299d
Separate external includes [ci skip]
Narre Jan 11, 2022
18901b6
Move level counting logic for levelsets to LevelsetState
Narre Feb 7, 2022
3ad4cdc
Move level counting logic for worldmaps to WorldmapState
Narre Feb 7, 2022
e5b9fbd
Code quality
Narre Mar 9, 2022
30a696d
Code quality
Narre Aug 14, 2022
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
2 changes: 1 addition & 1 deletion data/levels/christmas2016/worldmap.stwm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(supertux-level
(version 3)
(name (_ "Christmas 2016"))
(name (_ "Christmas Special"))
(author "Carsten Wirtz")
Comment on lines +3 to 4
Copy link
Member

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 and Haloween 2014 -> Halloween Special.

Copy link
Contributor Author

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 the info file), but if you think I should change them back, I will. These don't show up anywhere in the game anyway.

Copy link
Member

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.

(license "CC-BY-SA 4.0 International")
(sector
Expand Down
2 changes: 1 addition & 1 deletion data/levels/community2016/worldmap.stwm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(supertux-level
(version 3)
(name (_ "Community Island 2020"))
(name (_ "Community Island"))
(author "alex")
(license "CC-BY-SA 4.0 International")
(sector
Expand Down
2 changes: 1 addition & 1 deletion data/levels/halloween2014/worldmap.stwm
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")
Expand Down
90 changes: 84 additions & 6 deletions src/supertux/menu/sorted_contrib_menu.cpp
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
Expand All @@ -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()
{
Expand All @@ -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;
}
Copy link
Member

Choose a reason for hiding this comment

The 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 LevelsetState method.


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;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as before, but for WorldmapState as well. The code is being repeated at this point.


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());
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/supertux/player_status.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ PlayerStatus::PlayerStatus() :
max_air_time(0),
max_earth_time(0),
worldmap_sprite("images/worldmap/common/tux.sprite"),
last_worldmap()
last_worldmap(),
last_worldmap_title()
{
reset();

Expand Down Expand Up @@ -128,6 +129,7 @@ PlayerStatus::write(Writer& writer)

writer.write("worldmap-sprite", worldmap_sprite, false);
writer.write("last-worldmap", last_worldmap, false);
writer.write("last-worldmap-title", last_worldmap_title, false);
}

void
Expand Down Expand Up @@ -163,6 +165,8 @@ PlayerStatus::read(const ReaderMapping& mapping)

mapping.get("worldmap-sprite", worldmap_sprite);
mapping.get("last-worldmap", last_worldmap);
if (!mapping.get("last-worldmap-title", last_worldmap_title))
last_worldmap_title = "";
}

std::string PlayerStatus::get_bonus_prefix() const
Expand Down
1 change: 1 addition & 0 deletions src/supertux/player_status.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The 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;
Expand Down
2 changes: 2 additions & 0 deletions src/worldmap/worldmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ WorldMap::WorldMap(const std::string& filename, Savegame& savegame, const std::s
// load worldmap objects
WorldMapParser parser(*this);
parser.load_worldmap(filename);

m_savegame.get_player_status().last_worldmap_title = m_name;
}

WorldMap::~WorldMap()
Expand Down