widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #13449
[Merge] lp:~widelands-dev/widelands/bug-1733280-replay_filenames into lp:widelands
GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1733280-replay_filenames into lp:widelands.
Commit message:
Added a checkbox to toggle filenames when loading a replay. This is on per default, as one would never want to toggle them off except on low resolution.
Requested reviews:
Widelands Developers (widelands-dev)
Related bugs:
Bug #1733280 in widelands: "Add filenames to list of replays"
https://bugs.launchpad.net/widelands/+bug/1733280
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1733280-replay_filenames/+merge/345566
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1733280-replay_filenames into lp:widelands.
=== modified file 'src/ui_basic/table.cc'
--- src/ui_basic/table.cc 2018-05-14 08:24:46 +0000
+++ src/ui_basic/table.cc 2018-05-15 05:28:21 +0000
@@ -134,6 +134,13 @@
column.btn->set_title(title);
}
+void Table<void*>::set_column_tooltip(uint8_t col, const std::string& tooltip) {
+ assert(col < columns_.size());
+ Column& column = columns_.at(col);
+ assert(column.btn);
+ column.btn->set_tooltip(tooltip);
+}
+
/**
* Set a custom comparison function for sorting of the given column.
*/
@@ -437,7 +444,14 @@
selected(selection_);
}
-void Table<void*>::multiselect(uint32_t row) {
+/**
+ * If 'force' is true, adds the given 'row' to the selection, ignoring everything else.
+ */
+void Table<void*>::multiselect(uint32_t row, bool force) {
+ if (force) {
+ select(row);
+ return;
+ }
if (is_multiselect_) {
// Ranged selection with Shift
if (SDL_GetModState() & KMOD_SHIFT) {
=== modified file 'src/ui_basic/table.h'
--- src/ui_basic/table.h 2018-05-07 05:35:32 +0000
+++ src/ui_basic/table.h 2018-05-15 05:28:21 +0000
@@ -76,6 +76,7 @@
/// Text conventions: Title Case for the 'title'
void set_column_title(uint8_t col, const std::string& title);
+ void set_column_tooltip(uint8_t col, const std::string& tooltip);
void clear();
void set_sort_column(uint8_t col);
@@ -101,7 +102,7 @@
EntryRecord* find(Entry) const;
void select(uint32_t);
- void multiselect(uint32_t row);
+ void multiselect(uint32_t row, bool force = false);
uint32_t toggle_entry(uint32_t row);
void move_selection(int32_t offset);
struct NoSelection : public std::exception {
@@ -189,6 +190,7 @@
TableColumnType column_type = TableColumnType::kFixed);
void set_column_title(uint8_t col, const std::string& title);
+ void set_column_tooltip(uint8_t col, const std::string& tooltip);
void set_column_compare(uint8_t col, const CompareFn& fn);
void clear();
@@ -247,7 +249,7 @@
EntryRecord* find(const void* entry) const;
void select(uint32_t);
- void multiselect(uint32_t row);
+ void multiselect(uint32_t row, bool force = false);
uint32_t toggle_entry(uint32_t row);
void move_selection(int32_t offset);
struct NoSelection : public std::exception {
=== modified file 'src/ui_fsmenu/loadgame.cc'
--- src/ui_fsmenu/loadgame.cc 2018-05-13 07:15:39 +0000
+++ src/ui_fsmenu/loadgame.cc 2018-05-15 05:28:21 +0000
@@ -48,7 +48,7 @@
UI::PanelStyle::kFsMenu,
true),
- is_replay_(is_replay) {
+ is_replay_(is_replay), showing_filenames_(false) {
// Make sure that we have some space to work with.
main_box_.set_size(get_w(), get_w());
@@ -57,6 +57,10 @@
main_box_.add_inf_space();
main_box_.add(&title_, UI::Box::Resizing::kAlign, UI::Align::kCenter);
main_box_.add_inf_space();
+ if (is_replay_) {
+ show_filenames_ = new UI::Checkbox(&main_box_, Vector2i::zero(), _("Show Filenames"));
+ main_box_.add(show_filenames_, UI::Box::Resizing::kFullSize);
+ }
main_box_.add_inf_space();
main_box_.add(&info_box_, UI::Box::Resizing::kExpandBoth);
main_box_.add_space(padding_);
@@ -89,6 +93,12 @@
load_or_save_.table().double_clicked.connect(
boost::bind(&FullscreenMenuLoadGame::clicked_ok, boost::ref(*this)));
+ if (is_replay_) {
+ show_filenames_->changed.connect(
+ boost::bind(&FullscreenMenuLoadGame::toggle_filenames, boost::ref(*this)));
+ show_filenames_->set_state(true);
+ }
+
fill_table();
if (!load_or_save_.table().empty()) {
load_or_save_.table().select(0);
@@ -107,6 +117,23 @@
main_box_.get_w() - tablew_ - right_column_margin_, tableh_);
}
+void FullscreenMenuLoadGame::toggle_filenames() {
+ showing_filenames_ = show_filenames_->get_state();
+
+ // Remember selection
+ const std::set<uint32_t> selected = load_or_save_.table().selections();
+ // Fill table again
+ fill_table();
+
+ // Restore selection items
+ // TODO(GunChleoc): It would be nice to have a function to just change the entry texts
+ for (const uint32_t selectme : selected) {
+ load_or_save_.table().multiselect(selectme, true);
+ }
+ entry_selected();
+}
+
+
void FullscreenMenuLoadGame::clicked_ok() {
if (load_or_save_.table().selections().size() != 1) {
return;
@@ -128,7 +155,7 @@
}
void FullscreenMenuLoadGame::fill_table() {
- load_or_save_.fill_table();
+ load_or_save_.fill_table(showing_filenames_);
}
const std::string& FullscreenMenuLoadGame::filename() const {
=== modified file 'src/ui_fsmenu/loadgame.h'
--- src/ui_fsmenu/loadgame.h 2018-04-07 16:59:00 +0000
+++ src/ui_fsmenu/loadgame.h 2018-05-15 05:28:21 +0000
@@ -26,6 +26,7 @@
#include "logic/game_settings.h"
#include "ui_basic/box.h"
#include "ui_basic/button.h"
+#include "ui_basic/checkbox.h"
#include "ui_basic/panel.h"
#include "ui_basic/textarea.h"
#include "ui_fsmenu/load_map_or_game.h"
@@ -53,6 +54,7 @@
private:
void layout() override;
+ void toggle_filenames();
UI::Box main_box_;
UI::Box info_box_;
@@ -65,6 +67,9 @@
std::string filename_;
bool is_replay_;
+
+ UI::Checkbox* show_filenames_;
+ bool showing_filenames_;
};
#endif // end of include guard: WL_UI_FSMENU_LOADGAME_H
=== modified file 'src/wui/load_or_save_game.cc'
--- src/wui/load_or_save_game.cc 2018-05-14 06:59:39 +0000
+++ src/wui/load_or_save_game.cc 2018-05-15 05:28:21 +0000
@@ -120,10 +120,8 @@
_("Mode"), (boost::format("%s %s") % mode_tooltip_1 % mode_tooltip_2).str());
}
table_.add_column(0, _("Description"),
- filetype_ == FileType::kReplay ?
- _("Map name (start of replay)") :
- _("The filename that the game was saved under followed by the map’s name, "
- "or the map’s name followed by the last objective achieved."),
+ _("The filename that the game was saved under followed by the map’s name, "
+ "or the map’s name followed by the last objective achieved."),
UI::Align::kLeft, UI::TableColumnType::kFlexible);
table_.set_column_compare(
0, boost::bind(&LoadOrSaveGame::compare_date_descending, this, _1, _2));
@@ -299,7 +297,7 @@
return delete_;
}
-void LoadOrSaveGame::fill_table() {
+void LoadOrSaveGame::fill_table(bool show_filenames) {
clear_selections();
table_.clear();
@@ -310,6 +308,8 @@
gamefiles = filter(g_fs->list_directory(kReplayDir), [](const std::string& fn) {
return boost::ends_with(fn, kReplayExtension);
});
+ // Update description column title for replays
+ table_.set_column_tooltip(2, show_filenames ? _("Filename: Map name (start of replay)") : _("Map name (start of replay)"));
} else {
gamefiles = g_fs->list_directory(kSaveDir);
}
@@ -460,8 +460,9 @@
}
te.set_string(1, gametypestring);
if (filetype_ == FileType::kReplay) {
+ const std::string map_basename = show_filenames ? map_filename(gamedata.filename, gamedata.mapname, localize_autosave_) : gamedata.mapname;
te.set_string(2, (boost::format(pgettext("mapname_gametime", "%1% (%2%)")) %
- gamedata.mapname % gamedata.gametime)
+ map_basename % gamedata.gametime)
.str());
} else {
te.set_string(
=== modified file 'src/wui/load_or_save_game.h'
--- src/wui/load_or_save_game.h 2018-04-27 06:11:05 +0000
+++ src/wui/load_or_save_game.h 2018-05-15 05:28:21 +0000
@@ -57,7 +57,7 @@
void select_by_name(const std::string& name);
/// Read savegame/replay files and fill the table and games data.
- void fill_table();
+ void fill_table(bool show_filenames = false);
/// The table panel
UI::Table<uintptr_t const>& table();
Follow ups
-
[Merge] lp:~widelands-dev/widelands/bug-1733280-replay_filenames into lp:widelands
From: noreply, 2018-06-08
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1733280-replay_filenames into lp:widelands
From: GunChleoc, 2018-06-08
-
[Merge] lp:~widelands-dev/widelands/bug-1733280-replay_filenames into lp:widelands
From: bunnybot, 2018-06-08
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1733280-replay_filenames into lp:widelands
From: Notabilis, 2018-06-07
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1733280-replay_filenames into lp:widelands
From: GunChleoc, 2018-06-07
-
[Merge] lp:~widelands-dev/widelands/bug-1733280-replay_filenames into lp:widelands
From: bunnybot, 2018-06-05
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1733280-replay_filenames into lp:widelands
From: Notabilis, 2018-06-04
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1733280-replay_filenames into lp:widelands
From: GunChleoc, 2018-06-04
-
[Merge] lp:~widelands-dev/widelands/bug-1733280-replay_filenames into lp:widelands
From: bunnybot, 2018-06-01
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1733280-replay_filenames into lp:widelands
From: Notabilis, 2018-06-01
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1733280-replay_filenames into lp:widelands
From: GunChleoc, 2018-05-31
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1733280-replay_filenames into lp:widelands
From: Notabilis, 2018-05-31
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1733280-replay_filenames into lp:widelands
From: GunChleoc, 2018-05-31
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1733280-replay_filenames into lp:widelands
From: Notabilis, 2018-05-28
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1733280-replay_filenames into lp:widelands
From: GunChleoc, 2018-05-28
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1733280-replay_filenames into lp:widelands
From: Notabilis, 2018-05-27
-
[Merge] lp:~widelands-dev/widelands/bug-1733280-replay_filenames into lp:widelands
From: bunnybot, 2018-05-16
-
[Merge] lp:~widelands-dev/widelands/bug-1733280-replay_filenames into lp:widelands
From: bunnybot, 2018-05-15