Skip to content

Commit

Permalink
Update hotkey filter to work with multi menu toggles
Browse files Browse the repository at this point in the history
  • Loading branch information
rocketBANG authored and jostephd committed Jan 6, 2019
1 parent 607a698 commit 1028be0
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 43 deletions.
1 change: 1 addition & 0 deletions changelog.md
Expand Up @@ -72,6 +72,7 @@
* The "Attack Enemy" dialog now shows inactive weapon specials in gray. (PR #3686)
* Taking screenshots in title screen is possible again (issue #3235)
* The "Recruit Unit" dialog is searchable by unit type name. (PR #3787)
* Add text filter to hotkeys preferences. (PR #3759)

## Version 1.14.5
### AI
Expand Down
3 changes: 3 additions & 0 deletions data/core/about.cfg
Expand Up @@ -1547,6 +1547,9 @@
[entry]
name = "RatArmy (fujimo-t)"
[/entry]
[entry]
name = "Reuben Rakete (rocketbang)"
[/entry]
[entry]
name = "Richard Yao (srk9)"
comment = "Bug fixes"
Expand Down
2 changes: 1 addition & 1 deletion data/gui/window/preferences/02_hotkeys.cfg
Expand Up @@ -50,7 +50,7 @@

[label]
definition = "default"
label = _ "Search:"
label = _ "Filter:"
[/label]
[/column]

Expand Down
69 changes: 29 additions & 40 deletions src/gui/dialogs/preferences_dialog.cpp
Expand Up @@ -143,7 +143,7 @@ preferences_dialog::preferences_dialog(const config& game_cfg, const PREFERENCE_

void preferences_dialog::on_filtertext_changed(text_box_base* textbox)
{
hotkey_name_filter_callback(*textbox->get_window());
hotkey_filter_callback(*textbox->get_window());
}

// Helper function to refresh resolution list
Expand Down Expand Up @@ -752,7 +752,7 @@ void preferences_dialog::post_build(window& window)
hotkey_menu.set_values(hotkey_category_entries);

connect_signal_notify_modified(hotkey_menu,
std::bind(&preferences_dialog::hotkey_type_filter_callback, this, std::ref(window)));
std::bind(&preferences_dialog::hotkey_filter_callback, this, std::ref(window)));

listbox& hotkey_list = setup_hotkey_list(window);

Expand Down Expand Up @@ -916,61 +916,50 @@ void preferences_dialog::remove_hotkey_callback(listbox& hotkeys)
find_widget<label>(hotkeys.get_row_grid(row_number), "lbl_hotkey", false).set_label(hotkey::get_names(hotkey_item.command));
}

void preferences_dialog::hotkey_name_filter_callback(window& window) const
void preferences_dialog::hotkey_filter_callback(window& window) const
{
const multimenu_button& hotkey_menu = find_widget<const multimenu_button>(&window, "hotkey_category_menu", false);
const text_box& name_filter = find_widget<const text_box>(&window, "filter", false);
std::string text = name_filter.get_value();
boost::algorithm::to_lower(text);

boost::dynamic_bitset<> toggle_states = hotkey_menu.get_toggle_states();
boost::dynamic_bitset<> res(visible_hotkeys_.size());

for (std::size_t h = 0; h < visible_hotkeys_.size(); ++h)
{
const std::string description_lower = boost::algorithm::to_lower_copy(visible_hotkeys_[h]->description.str(), std::locale::classic());

if (description_lower.find(text) != std::string::npos) {
res[h] = true;
}
else {
res[h] = false;
}
std::string text = name_filter.get_value();
boost::algorithm::to_lower(text);

if (toggle_states.none()) {
// Nothing selected. It means that *all* categories are shown.
toggle_states = ~toggle_states;
}

find_widget<listbox>(&window, "list_hotkeys", false).set_row_shown(res);
}
for (std::size_t h = 0; h < visible_hotkeys_.size(); ++h) {

void preferences_dialog::hotkey_type_filter_callback(window& window) const
{
const multimenu_button& hotkey_menu = find_widget<const multimenu_button>(&window, "hotkey_category_menu", false);
unsigned index = 0;

boost::dynamic_bitset<> toggle_states = hotkey_menu.get_toggle_states();
boost::dynamic_bitset<> res(visible_hotkeys_.size());

if(!toggle_states.none()) {
for(size_t h = 0; h < visible_hotkeys_.size(); ++h) {
unsigned index = 0;
const std::string description_lower = boost::algorithm::to_lower_copy(visible_hotkeys_[h]->description.str(), std::locale::classic());
// Either no text is entered or text matches description
bool textFilter = text.length() == 0 || description_lower.find(text) != std::string::npos;

for(const auto& name : cat_names_) {
if(visible_hotkeys_[h]->category == name.first) {
break;
} else {
++index;
}
for (const auto& name : cat_names_) {
if (visible_hotkeys_[h]->category == name.first) {
break;
}

if(index < toggle_states.size()) {
res[h] = toggle_states[index];
} else {
res[h] = false;
else {
++index;
}
}
} else {
// Nothing selected. It means that *all* categories are shown.
res = ~res;

if (index < toggle_states.size() && textFilter) {
res[h] = toggle_states[index];
}
else {
res[h] = false;
}
}


find_widget<listbox>(&window, "list_hotkeys", false).set_row_shown(res);

}

void preferences_dialog::on_advanced_prefs_list_select(listbox& list)
Expand Down
3 changes: 1 addition & 2 deletions src/gui/dialogs/preferences_dialog.hpp
Expand Up @@ -122,8 +122,7 @@ class preferences_dialog : public modal_dialog
void add_hotkey_callback(listbox& hotkeys);
void remove_hotkey_callback(listbox& hotkeys);
void default_hotkey_callback(window& window);
void hotkey_type_filter_callback(window& window) const;
void hotkey_name_filter_callback(window& window) const;
void hotkey_filter_callback(window& window) const;

group<preferences::LOBBY_JOINS> lobby_joins_group;

Expand Down

0 comments on commit 1028be0

Please sign in to comment.