1 /*
2  * Copyright (C) 2017-2020 by the Widelands Development Team
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18 
19 #include "ui_fsmenu/campaigndetails.h"
20 
21 #include "base/i18n.h"
22 #include "graphic/text_layout.h"
23 #include "ui_basic/scrollbar.h"
24 
CampaignDetails(Panel * parent)25 CampaignDetails::CampaignDetails(Panel* parent)
26    : UI::Box(parent, 0, 0, UI::Box::Vertical),
27      name_label_(this,
28                  0,
29                  0,
30                  UI::Scrollbar::kSize,
31                  0,
32                  UI::PanelStyle::kFsMenu,
33                  "",
34                  UI::Align::kLeft,
35                  UI::MultilineTextarea::ScrollMode::kNoScrolling),
36      descr_(this, 0, 0, UI::Scrollbar::kSize, 0, UI::PanelStyle::kFsMenu) {
37 
38 	constexpr int kPadding = 4;
39 	add(&name_label_, UI::Box::Resizing::kFullSize);
40 	add_space(kPadding);
41 	add(&descr_, UI::Box::Resizing::kExpandBoth);
42 }
43 
update(const CampaignData & campaigndata)44 void CampaignDetails::update(const CampaignData& campaigndata) {
45 	name_label_.set_text((boost::format("<rt>%s%s</rt>") %
46 	                      /** TRANSLATORS: Header for campaign name */
47 	                      as_heading(_("Campaign"), UI::PanelStyle::kFsMenu, true) %
48 	                      as_content(campaigndata.descname, UI::PanelStyle::kFsMenu))
49 	                        .str());
50 
51 	std::string description = "";
52 
53 	if (campaigndata.visible) {
54 		description = (boost::format("%s%s") %
55 		               /** TRANSLATORS: Header for campaign tribe */
56 		               as_heading(_("Tribe"), UI::PanelStyle::kFsMenu) %
57 		               as_content(campaigndata.tribename, UI::PanelStyle::kFsMenu))
58 		                 .str();
59 		description = (boost::format("%s%s") % description %
60 		               /** TRANSLATORS: Header for campaign difficulty */
61 		               as_heading(_("Difficulty"), UI::PanelStyle::kFsMenu))
62 		                 .str();
63 		description = (boost::format("%s%s") % description %
64 		               as_content(campaigndata.difficulty_description, UI::PanelStyle::kFsMenu))
65 		                 .str();
66 
67 		description = (boost::format("%s%s") % description %
68 		               /** TRANSLATORS: Header for campaign description */
69 		               as_heading(_("Description"), UI::PanelStyle::kFsMenu))
70 		                 .str();
71 		description = (boost::format("%s%s") % description %
72 		               as_content(campaigndata.description, UI::PanelStyle::kFsMenu))
73 		                 .str();
74 	}
75 
76 	description = (boost::format("<rt>%s</rt>") % description).str();
77 	descr_.set_text(description);
78 	descr_.scroll_to_top();
79 }
80