mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-25 01:55:07 +00:00
basic support for filtering campaigns based on completion status (#8451)
This commit is contained in:
parent
ea564e4501
commit
0bef2252a1
@ -1778,7 +1778,7 @@
|
||||
[/entry]
|
||||
[entry]
|
||||
name = "Subhraman Sarkar (LumiousE/babaissarkar)"
|
||||
email = "suvrax_AT_gmail.com"
|
||||
email = "suvrax_AT_gmail_DOT_com"
|
||||
[/entry]
|
||||
[entry]
|
||||
name = "sylecn"
|
||||
|
@ -227,6 +227,42 @@
|
||||
tooltip = _"Sort in approximate chronological order of story events"
|
||||
[/toggle_button]
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
horizontal_grow = true
|
||||
|
||||
[multimenu_button]
|
||||
id = "filter_completion"
|
||||
tooltip = _"Filter by campaign completion status"
|
||||
[option]
|
||||
checkbox = yes
|
||||
label = _ "Not Completed"
|
||||
#po: campaigns which the player hasn't beaten, rather than campaigns which the author hasn't finished writing
|
||||
tooltip = _ "Show campaigns not completed by player"
|
||||
[/option]
|
||||
[option]
|
||||
checkbox = yes
|
||||
label = _ "Completed: Bronze"
|
||||
tooltip = _ "Show campaigns completed at easiest difficulty"
|
||||
[/option]
|
||||
[option]
|
||||
checkbox = yes
|
||||
label = _ "Completed: Silver"
|
||||
tooltip = _ "Show campaigns completed at intermediate difficulties"
|
||||
[/option]
|
||||
[option]
|
||||
checkbox = yes
|
||||
label = _ "Completed: Gold"
|
||||
tooltip = _ "Show campaigns completed at hardest difficulty"
|
||||
[/option]
|
||||
[option]
|
||||
checkbox = yes
|
||||
label = _ "Completed: All"
|
||||
tooltip = _ "Show completed campaigns"
|
||||
[/option]
|
||||
[/multimenu_button]
|
||||
[/column]
|
||||
[/row]
|
||||
[/grid]
|
||||
[/panel]
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "gui/widgets/window.hpp"
|
||||
#include "preferences/game.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <functional>
|
||||
#include "utils/irdya_datetime.hpp"
|
||||
|
||||
@ -223,11 +224,32 @@ void campaign_selection::sort_campaigns(campaign_selection::CAMPAIGN_ORDER order
|
||||
}
|
||||
}
|
||||
|
||||
// List of which options has been selected in the completion filter multimenu_button
|
||||
boost::dynamic_bitset<> filter_comp_options = find_widget<multimenu_button>(this, "filter_completion", false).get_toggle_states();
|
||||
|
||||
bool exists_in_filtered_result = false;
|
||||
for(unsigned i = 0; i < levels.size(); ++i) {
|
||||
if(show_items[i]) {
|
||||
add_campaign_to_tree(levels[i]->data());
|
||||
bool completed = preferences::is_campaign_completed(levels[i]->data()["id"]);
|
||||
config::const_child_itors difficulties = levels[i]->data().child_range("difficulty");
|
||||
auto did_complete_at = [](const config& c) { return c["completed_at"].to_bool(); };
|
||||
|
||||
std::cout << levels[i]->data().debug() << std::endl << std::endl;
|
||||
|
||||
// Check for non-completion on every difficulty save the first.
|
||||
const bool only_first_completed = difficulties.size() > 1 &&
|
||||
std::none_of(difficulties.begin() + 1, difficulties.end(), did_complete_at);
|
||||
const bool completed_easy = only_first_completed && did_complete_at(difficulties.front());
|
||||
const bool completed_hardest = !difficulties.empty() && did_complete_at(difficulties.back());
|
||||
const bool completed_mid = completed && !completed_hardest && !completed_easy;
|
||||
|
||||
if( show_items[i] && (
|
||||
( (!completed) && filter_comp_options[0] ) // Selects all campaigns not finished by player
|
||||
|| ( completed && filter_comp_options[4] ) // Selects all campaigns finished by player
|
||||
|| ( completed_hardest && filter_comp_options[3] ) // Selects campaigns completed in hardest difficulty
|
||||
|| ( completed_easy && filter_comp_options[1] ) // Selects campaigns completed in easiest difficulty
|
||||
|| ( completed_mid && filter_comp_options[2]) // Selects campaigns completed in any other difficulty
|
||||
)) {
|
||||
add_campaign_to_tree(levels[i]->data());
|
||||
if (!exists_in_filtered_result) {
|
||||
exists_in_filtered_result = levels[i]->id() == was_selected;
|
||||
}
|
||||
@ -315,6 +337,13 @@ void campaign_selection::pre_show(window& window)
|
||||
/***** Setup campaign details. *****/
|
||||
multi_page& pages = find_widget<multi_page>(&window, "campaign_details", false);
|
||||
|
||||
multimenu_button& filter_comp = find_widget<multimenu_button>(&window, "filter_completion", false);
|
||||
connect_signal_notify_modified(filter_comp,
|
||||
std::bind(&campaign_selection::sort_campaigns, this, RANK, 1));
|
||||
for (unsigned j = 0; j < filter_comp.num_options(); j++) {
|
||||
filter_comp.select_option(j);
|
||||
}
|
||||
|
||||
for(const auto& level : engine_.get_levels_by_type_unfiltered(level_type::type::sp_campaign)) {
|
||||
const config& campaign = level->data();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user