1 /*
2 * Copyright (C) 2002-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 "wui/maptable.h"
20
21 #include "base/i18n.h"
22 #include "graphic/graphic.h"
23 #include "io/filesystem/filesystem.h"
24
MapTable(UI::Panel * parent,int32_t x,int32_t y,uint32_t w,uint32_t h,UI::PanelStyle style)25 MapTable::MapTable(
26 UI::Panel* parent, int32_t x, int32_t y, uint32_t w, uint32_t h, UI::PanelStyle style)
27 : UI::Table<uintptr_t>(parent, x, y, w, h, style) {
28
29 /** TRANSLATORS: Column title for number of players in map list */
30 add_column(35, _("Pl."), _("Number of players"), UI::Align::kCenter);
31 add_column(0, _("Filename"), _("The name of the map or scenario"), UI::Align::kLeft,
32 UI::TableColumnType::kFlexible);
33 add_column(90, _("Size"), _("The size of the map (Width x Height)"));
34 set_sort_column(0);
35 }
36
fill(const std::vector<MapData> & entries,MapData::DisplayType type)37 void MapTable::fill(const std::vector<MapData>& entries, MapData::DisplayType type) {
38 clear();
39
40 for (size_t i = 0; i < entries.size(); ++i) {
41 const MapData& mapdata = entries[i];
42 UI::Table<uintptr_t const>::EntryRecord& te = add(i);
43
44 if (mapdata.maptype == MapData::MapType::kDirectory) {
45 te.set_string(0, "");
46 te.set_picture(
47 1, g_gr->images().get("images/ui_basic/ls_dir.png"), mapdata.localized_name);
48 te.set_string(2, "");
49 } else {
50 te.set_string(0, (boost::format("(%i)") % mapdata.nrplayers).str());
51
52 std::string picture = "images/ui_basic/ls_wlmap.png";
53 if (mapdata.maptype == MapData::MapType::kScenario) {
54 picture = "images/ui_basic/ls_wlscenario.png";
55 } else if (mapdata.maptype == MapData::MapType::kSettlers2) {
56 picture = "images/ui_basic/ls_s2map.png";
57 }
58
59 if (type == MapData::DisplayType::kFilenames) {
60 set_column_title(1, _("Filename"));
61 te.set_picture(1, g_gr->images().get(picture),
62 FileSystem::filename_without_ext(mapdata.filename.c_str()));
63 } else {
64 set_column_title(1, _("Map Name"));
65 if (type == MapData::DisplayType::kMapnames) {
66 te.set_picture(1, g_gr->images().get(picture), mapdata.name);
67 } else {
68 te.set_picture(1, g_gr->images().get(picture), mapdata.localized_name);
69 }
70 }
71
72 te.set_string(2, (boost::format("%u x %u") % mapdata.width % mapdata.height).str());
73 }
74 }
75 sort();
76 layout();
77 }
78