mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-20 16:05:19 +00:00
GUI2/Achievements: code cleanup, use VGETTEXT
This commit is contained in:
parent
98c21e1bf2
commit
75a47689ea
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
#include "gui/dialogs/achievements_dialog.hpp"
|
#include "gui/dialogs/achievements_dialog.hpp"
|
||||||
|
|
||||||
|
#include "formula/string_utils.hpp"
|
||||||
#include "game_config_manager.hpp"
|
#include "game_config_manager.hpp"
|
||||||
#include "gettext.hpp"
|
#include "gettext.hpp"
|
||||||
#include "gui/widgets/drawing.hpp"
|
#include "gui/widgets/drawing.hpp"
|
||||||
@ -39,7 +40,6 @@ REGISTER_DIALOG(achievements_dialog)
|
|||||||
|
|
||||||
achievements_dialog::achievements_dialog()
|
achievements_dialog::achievements_dialog()
|
||||||
: modal_dialog(window_id())
|
: modal_dialog(window_id())
|
||||||
, achieve_()
|
|
||||||
, last_selected_(prefs::get().selected_achievement_group())
|
, last_selected_(prefs::get().selected_achievement_group())
|
||||||
, achievements_box_(nullptr)
|
, achievements_box_(nullptr)
|
||||||
, content_names_(nullptr)
|
, content_names_(nullptr)
|
||||||
@ -53,11 +53,9 @@ void achievements_dialog::pre_show()
|
|||||||
connect_signal_notify_modified(*content_names_, std::bind(&achievements_dialog::set_achievements_row, this));
|
connect_signal_notify_modified(*content_names_, std::bind(&achievements_dialog::set_achievements_row, this));
|
||||||
|
|
||||||
achievements_box_ = find_widget<listbox>("achievements_list", false, true);
|
achievements_box_ = find_widget<listbox>("achievements_list", false, true);
|
||||||
|
|
||||||
std::vector<achievement_group> groups = game_config_manager::get()->get_achievements();
|
|
||||||
int selected = 0;
|
int selected = 0;
|
||||||
|
|
||||||
for(const auto& list : groups) {
|
for(const auto& list : game_config_manager::get()->get_achievements()) {
|
||||||
// only display the achievements for the first dropdown option on first showing the dialog
|
// only display the achievements for the first dropdown option on first showing the dialog
|
||||||
if(list.content_for_ == last_selected_ || last_selected_ == "") {
|
if(list.content_for_ == last_selected_ || last_selected_ == "") {
|
||||||
selected = content_list.size();
|
selected = content_list.size();
|
||||||
@ -93,48 +91,54 @@ void achievements_dialog::set_achievements_row()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
widget_data row;
|
const bool in_progress = ach.max_progress_ != 0 && ach.current_progress_ != -1;
|
||||||
widget_item item;
|
const auto in_progress_name = !in_progress
|
||||||
|
? ach.name_
|
||||||
|
: t_string(VGETTEXT("$title ($count/$total)", {{
|
||||||
|
{"title", ach.name_},
|
||||||
|
{"count", std::to_string(ach.current_progress_)},
|
||||||
|
{"total", std::to_string(ach.max_progress_)}
|
||||||
|
}}));
|
||||||
|
|
||||||
item["label"] = !ach.achieved_ ? ach.icon_ : ach.icon_completed_;
|
grid& newrow = achievements_box_->add_row(widget_data{
|
||||||
row.emplace("icon", item);
|
{ "icon", {
|
||||||
|
{ "label", ach.achieved_
|
||||||
|
? ach.icon_completed_
|
||||||
|
: ach.icon_
|
||||||
|
}
|
||||||
|
}},
|
||||||
|
{ "name", {
|
||||||
|
{ "label", ach.achieved_
|
||||||
|
? ach.name_completed_
|
||||||
|
: in_progress_name
|
||||||
|
}
|
||||||
|
}},
|
||||||
|
{ "description", {
|
||||||
|
{ "label", ach.achieved_
|
||||||
|
? t_string(markup::span_color("green", ach.description_completed_))
|
||||||
|
: ach.description_
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
});
|
||||||
|
|
||||||
if(!ach.achieved_) {
|
auto achievement_progress = static_cast<progress_bar*>(newrow.find("achievement_progress", false));
|
||||||
t_string name = ach.name_;
|
if(in_progress) {
|
||||||
if(ach.max_progress_ != 0 && ach.current_progress_ != -1) {
|
achievement_progress->set_percentage((ach.current_progress_ / double(ach.max_progress_)) * 100);
|
||||||
name += (formatter() << " (" << ach.current_progress_ << "/" << ach.max_progress_).str();
|
|
||||||
}
|
|
||||||
item["label"] = name;
|
|
||||||
} else {
|
|
||||||
item["label"] = ach.name_completed_;
|
|
||||||
item["definition"] = "gold_large";
|
|
||||||
}
|
|
||||||
row.emplace("name", item);
|
|
||||||
|
|
||||||
if(!ach.achieved_) {
|
|
||||||
item["label"] = ach.description_;
|
|
||||||
} else {
|
|
||||||
item["label"] = markup::span_color("green", ach.description_completed_);
|
|
||||||
}
|
|
||||||
row.emplace("description", item);
|
|
||||||
|
|
||||||
grid& newrow = achievements_box_->add_row(row);
|
|
||||||
progress_bar* achievement_progress = static_cast<progress_bar*>(newrow.find("achievement_progress", false));
|
|
||||||
if(ach.max_progress_ != 0 && ach.current_progress_ != -1) {
|
|
||||||
achievement_progress->set_percentage((ach.current_progress_/double(ach.max_progress_))*100);
|
|
||||||
} else {
|
} else {
|
||||||
achievement_progress->set_visible(gui2::widget::visibility::invisible);
|
achievement_progress->set_visible(gui2::widget::visibility::invisible);
|
||||||
}
|
}
|
||||||
|
|
||||||
label* name = static_cast<label*>(newrow.find("name", false));
|
auto name = static_cast<styled_widget*>(newrow.find("name", false));
|
||||||
canvas& canvas = name->get_canvas(0);
|
name->get_canvas(0).set_variable("achieved", wfl::variant(ach.achieved_));
|
||||||
canvas.set_variable("achieved", wfl::variant(ach.achieved_));
|
|
||||||
|
|
||||||
set_sub_achievements(newrow, ach);
|
set_sub_achievements(newrow, ach);
|
||||||
}
|
}
|
||||||
|
|
||||||
label* achieved_label = find_widget<label>("achievement_count", false, true);
|
auto& achieved_label = find_widget<label>("achievement_count");
|
||||||
achieved_label->set_label(_("Completed")+" "+std::to_string(achieved_count)+"/"+std::to_string(list.achievements_.size()));
|
achieved_label.set_label(VGETTEXT("Completed $count/$total", {
|
||||||
|
{"count", std::to_string(achieved_count)} ,
|
||||||
|
{"total", std::to_string(list.achievements_.size())}
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void achievements_dialog::set_sub_achievements(grid& newrow, const achievement& ach)
|
void achievements_dialog::set_sub_achievements(grid& newrow, const achievement& ach)
|
||||||
@ -144,14 +148,11 @@ void achievements_dialog::set_sub_achievements(grid& newrow, const achievement&
|
|||||||
// set any sub achievements
|
// set any sub achievements
|
||||||
for(const sub_achievement& sub_ach : ach.sub_achievements_)
|
for(const sub_achievement& sub_ach : ach.sub_achievements_)
|
||||||
{
|
{
|
||||||
if(i == sub_achievements_limit)
|
if(i == sub_achievements_limit) {
|
||||||
{
|
|
||||||
ERR_CONFIG << "Too many sub achievements";
|
ERR_CONFIG << "Too many sub achievements";
|
||||||
break;
|
break;
|
||||||
}
|
} else {
|
||||||
else
|
drawing* img = static_cast<drawing*>(newrow.find("sub_icon" + std::to_string(i), false));
|
||||||
{
|
|
||||||
drawing* img = static_cast<drawing*>(newrow.find("sub_icon"+std::to_string(i), false));
|
|
||||||
img->set_label(sub_ach.achieved_ ? sub_ach.icon_completed_ : sub_ach.icon_);
|
img->set_label(sub_ach.achieved_ ? sub_ach.icon_completed_ : sub_ach.icon_);
|
||||||
img->set_tooltip(sub_ach.description_);
|
img->set_tooltip(sub_ach.description_);
|
||||||
}
|
}
|
||||||
@ -161,7 +162,7 @@ void achievements_dialog::set_sub_achievements(grid& newrow, const achievement&
|
|||||||
// if an achievement hasn't defined the maximum possible sub-achievements, hide the [image]s for the rest
|
// if an achievement hasn't defined the maximum possible sub-achievements, hide the [image]s for the rest
|
||||||
for(; i < sub_achievements_limit; i++)
|
for(; i < sub_achievements_limit; i++)
|
||||||
{
|
{
|
||||||
static_cast<drawing*>(newrow.find("sub_icon"+std::to_string(i), false))->set_visible(visibility::invisible);
|
newrow.find("sub_icon" + std::to_string(i), false)->set_visible(visibility::invisible);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,6 @@ public:
|
|||||||
achievements_dialog();
|
achievements_dialog();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
achievements achieve_;
|
|
||||||
std::string last_selected_;
|
std::string last_selected_;
|
||||||
listbox* achievements_box_;
|
listbox* achievements_box_;
|
||||||
menu_button* content_names_;
|
menu_button* content_names_;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user