Merge lp:~widelands-dev/widelands/bug-1560454-mapdir into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 8015
Proposed branch: lp:~widelands-dev/widelands/bug-1560454-mapdir
Merge into: lp:widelands
Diff against target: 313 lines (+75/-11)
10 files modified
src/editor/ui_menus/main_menu_load_map.cc (+22/-2)
src/editor/ui_menus/main_menu_load_map.h (+2/-0)
src/editor/ui_menus/main_menu_load_or_save_map.cc (+14/-4)
src/editor/ui_menus/main_menu_load_or_save_map.h (+7/-1)
src/editor/ui_menus/main_menu_save_map.cc (+12/-3)
src/editor/ui_menus/main_menu_save_map.h (+4/-0)
src/editor/ui_menus/main_menu_save_map_make_directory.cc (+1/-0)
src/wui/mapdata.cc (+9/-0)
src/wui/mapdata.h (+3/-0)
src/wui/maptable.cc (+1/-1)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1560454-mapdir
Reviewer Review Type Date Requested Status
SirVer Approve
kaputtnik (community) testing Approve
Review via email: mp+294725@code.launchpad.net

Commit message

UI improvements for saving maps:
- Maps are now saved in a "My Maps" subdirectory to prevent overwriting of official maps
- Show full save path to user
- After creating a new directory, enter it
- Automatically focus directory name editbox when creating new directory
- Got rid of blank space in load map screen
- Made show map names/filenames button wide

To post a comment you must log in.
Revision history for this message
Miroslav Remák (miroslavr256) wrote :

For me it shows a different save path than where the map is actually saved: /widelands_working_dir/maps/My_Maps/map.wmf instead of /home/user/.widelands/maps/My_Maps/map.wmf. I guess that's because canonicalize_name does not take file system layers into account.

Revision history for this message
kaputtnik (franku) wrote :

> - Show full save path to user
This shows the wrong path. Here it is shown: /home/kaputtnik/widelands-repo/bug-1560454-mapdir/maps/My_Maps
Instead the map is saved in: /home/kaputtnik/.widelands/maps/My_Maps

> - After creating a new directory, enter it
Good idea :-) But it confuses a bit, because one couldn't see which folder is currently shown.

> - Automatically focus map name editbox when creating new map
I couldn't find this feature :-S Either it is not working or i do not understand it. If i create a new map nothing is shown to edit the name of the map. And if i want to save the map, the focus is always on the map, not in the menu (f.e. hitting "f" toggles Fullscreen). If i first choose the map options menu, there is also no focus on the map name edit box.

It is not possible anymore to store a map in a folder which was created prior this changes, because i couldn't go to the "previous folder". So my maps stored in folder ~/.widelands/maps/test/ could be loaded, but not saved in this folder anymore. One has to move the previous folders he created in ~/.widelands/maps into ~/.widelands/maps/My_Maps/ to save his own maps in his own folders again. Same goes for maps which are stored in ~/.widelands/maps/

As mentioned in the bug report i would like to see the "Shipped maps" in a sub folder in menu "Load map" where the shipped maps could be found. In menu "Save map" this folder shouldn't be shown then. I believe this would be the better approach. Isn't that possible?

Needs fixing because of "Show full path to the user".

review: Needs Fixing
Revision history for this message
GunChleoc (gunchleoc) wrote :

> > - Show full save path to user
> This shows the wrong path. Here it is shown: /home/kaputtnik/widelands-
> repo/bug-1560454-mapdir/maps/My_Maps
> Instead the map is saved in: /home/kaputtnik/.widelands/maps/My_Maps

I'll look into this.

> > - After creating a new directory, enter it
> Good idea :-) But it confuses a bit, because one couldn't see which folder is
> currently shown.

I'll remove this feature then

> > - Automatically focus map name editbox when creating new map
> I couldn't find this feature :-S Either it is not working or i do not
> understand it.

Sorry, I meant create directory, not create map.

> It is not possible anymore to store a map in a folder which was created prior
> this changes, because i couldn't go to the "previous folder". So my maps
> stored in folder ~/.widelands/maps/test/ could be loaded, but not saved in
> this folder anymore. One has to move the previous folders he created in
> ~/.widelands/maps into ~/.widelands/maps/My_Maps/ to save his own maps in his
> own folders again. Same goes for maps which are stored in ~/.widelands/maps/

Yes, they will have to be moved. Which is why I came up with the idea of displaying the full directory, so the user can go find the maps on their computer and fix.

> As mentioned in the bug report i would like to see the "Shipped maps" in a sub
> folder in menu "Load map" where the shipped maps could be found. In menu "Save
> map" this folder shouldn't be shown then. I believe this would be the better
> approach. Isn't that possible?

And how would this look when creating a new game then? All users, even those who don't have any own maps, will have to enter a "Shipped Maps" subfolder every time in order to start a new game?

Revision history for this message
kaputtnik (franku) wrote :

> > As mentioned in the bug report i would like to see the "Shipped maps" in a
> sub
> > folder in menu "Load map" where the shipped maps could be found. In menu
> "Save
> > map" this folder shouldn't be shown then. I believe this would be the better
> > approach. Isn't that possible?
>
> And how would this look when creating a new game then? All users, even those
> who don't have any own maps, will have to enter a "Shipped Maps" subfolder
> every time in order to start a new game?

Sorry, i forget always that "New game" and "Load map" is the same menu :-S

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 1127. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/130361026.
Appveyor build 964. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1560454_mapdir-964.

Revision history for this message
kaputtnik (franku) wrote :

> > > - Automatically focus map name editbox when creating new map
> > I couldn't find this feature :-S Either it is not working or i do not
> > understand it.
>
> Sorry, I meant create directory, not create map.

If i create a new directory the map name editbox isn't focused here ("f" button toggles fullscreen).

Revision history for this message
GunChleoc (gunchleoc) wrote :

Displaying the absolute path is less than trivial, because the LayeredFilesystem will iterate internally over all file systems until it finds a match. So, I decided to display the relative directory instead, both in the load and save screens.

> If i create a new directory the map name editbox isn't focused here ("f"
> button toggles fullscreen).

The shortcut for toggle fullscreen is CTRL+f, so I have no idea how you managed this.

What I am talking about is:

Old behaviour: Save Map -> Make Directory, click the edit box, start typing
New behaviour: Save Map -> Make Directory, start typing right away

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 1132. State: errored. Details: https://travis-ci.org/widelands/widelands/builds/130773045.
Appveyor build 969. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1560454_mapdir-969.

Revision history for this message
kaputtnik (franku) wrote :

Ahhh... now i got it. I've always tested the map name edit box (as the commit message says, even after you've changed it) but you meant the directory name edit box... This is a really good enhancement :-)

Showing the relative directory is IMHO ok. The position of this could be discussed... but i think we should discuss this if we have time to make a menu overhaul. I want to make some mockups with my suggestions if i am ready with the website code.

The "f" button toggles fullscreen without "CTRL" here. Just like it is explained in the help ;)

review: Approve (testing)
Revision history for this message
GunChleoc (gunchleoc) wrote :

Oops, I fixed the commit message. I don't get the problem with the fullscreen toggling while the text input is focused. You're right, it's without the Ctrl key.

Revision history for this message
kaputtnik (franku) wrote :

If the focus is in the directory name edit box, all works correct, no keyboard shortcuts works then.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Bunnybot encountered an error while working on this merge proposal:

The read operation timed out

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 1132. State: errored. Details: https://travis-ci.org/widelands/widelands/builds/130773045.
Appveyor build 969. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1560454_mapdir-969.

Revision history for this message
SirVer (sirver) wrote :

look at me! I did a codereview!!!

code lgtm. only one nit.

review: Approve
Revision history for this message
GunChleoc (gunchleoc) wrote :

LOL thanks!

Revision history for this message
GunChleoc (gunchleoc) wrote :

@bunnybot merge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/editor/ui_menus/main_menu_load_map.cc'
2--- src/editor/ui_menus/main_menu_load_map.cc 2016-04-06 09:23:04 +0000
3+++ src/editor/ui_menus/main_menu_load_map.cc 2016-06-07 09:07:42 +0000
4@@ -19,6 +19,9 @@
5
6 #include "editor/ui_menus/main_menu_load_map.h"
7
8+#include <boost/algorithm/string.hpp>
9+#include <boost/format.hpp>
10+
11 #include "base/i18n.h"
12 #include "editor/editorinteractive.h"
13 #include "io/filesystem/layered_filesystem.h"
14@@ -30,7 +33,8 @@
15 * Create all the buttons etc...
16 */
17 MainMenuLoadMap::MainMenuLoadMap(EditorInteractive& parent)
18- : MainMenuLoadOrSaveMap(parent, "load_map_menu", _("Load Map")) {
19+ : MainMenuLoadOrSaveMap(parent, 2, "load_map_menu", _("Load Map")) {
20+ set_current_directory(curdir_);
21
22 table_.selected.connect(boost::bind(&MainMenuLoadMap::entry_selected, this));
23 table_.double_clicked.connect(boost::bind(&MainMenuLoadMap::clicked_ok, boost::ref(*this)));
24@@ -45,7 +49,7 @@
25 const MapData& mapdata = maps_data_[table_.get_selected()];
26 if (g_fs->is_directory(mapdata.filename) &&
27 !Widelands::WidelandsMapLoader::is_widelands_map(mapdata.filename)) {
28- curdir_ = mapdata.filename;
29+ set_current_directory(mapdata.filename);
30 fill_table();
31 } else {
32 EditorInteractive& eia = dynamic_cast<EditorInteractive&>(*get_parent());
33@@ -54,6 +58,22 @@
34 }
35 }
36
37+void MainMenuLoadMap::set_current_directory(const std::string& filename) {
38+ curdir_ = filename;
39+
40+ std::string display_dir = curdir_.substr(basedir_.size());
41+ if (boost::starts_with(display_dir, "/")) {
42+ display_dir = display_dir.substr(1);
43+ }
44+ if (boost::starts_with(display_dir, "My_Maps")) {
45+ boost::replace_first(display_dir, "My_Maps", _("My Maps"));
46+ } else if (boost::starts_with(display_dir, "MP_Scenarios")) {
47+ boost::replace_first(display_dir, "MP_Scenarios", _("Multiplayer Scenarios"));
48+ }
49+ /** TRANSLATORS: The folder that a file will be saved to. */
50+ directory_info_.set_text((boost::format(_("Current Directory: %s")) % display_dir).str());
51+}
52+
53 /**
54 * Called when a entry is selected
55 */
56
57=== modified file 'src/editor/ui_menus/main_menu_load_map.h'
58--- src/editor/ui_menus/main_menu_load_map.h 2016-04-06 09:23:04 +0000
59+++ src/editor/ui_menus/main_menu_load_map.h 2016-06-07 09:07:42 +0000
60@@ -33,6 +33,8 @@
61
62 protected:
63 void clicked_ok() override;
64+ // Sets the current dir and updates labels.
65+ void set_current_directory(const std::string& filename) override;
66
67 private:
68 void entry_selected();
69
70=== modified file 'src/editor/ui_menus/main_menu_load_or_save_map.cc'
71--- src/editor/ui_menus/main_menu_load_or_save_map.cc 2016-04-20 07:58:14 +0000
72+++ src/editor/ui_menus/main_menu_load_or_save_map.cc 2016-06-07 09:07:42 +0000
73@@ -32,8 +32,10 @@
74 #include "map_io/widelands_map_loader.h"
75
76 MainMenuLoadOrSaveMap::MainMenuLoadOrSaveMap(EditorInteractive& parent,
77+ int no_of_bottom_rows,
78 const std::string& name,
79- const std::string& title)
80+ const std::string& title,
81+ const std::string& basedir)
82 : UI::Window(&parent, name, 0, 0, parent.get_inner_w() - 40, parent.get_inner_h() - 40, title),
83
84 // Values for alignment and size
85@@ -42,7 +44,7 @@
86 tablex_(padding_),
87 tabley_(buth_ + 2 * padding_),
88 tablew_(get_inner_w() * 7 / 12),
89- tableh_(get_inner_h() - tabley_ - 3 * buth_ - 2 * padding_),
90+ tableh_(get_inner_h() - tabley_ - (no_of_bottom_rows + 1) * buth_ - no_of_bottom_rows * padding_),
91 right_column_x_(tablew_ + 2 * padding_),
92 butw_((get_inner_w() - right_column_x_ - 2 * padding_) / 2),
93
94@@ -50,6 +52,11 @@
95 map_details_(
96 this, right_column_x_, tabley_, get_inner_w() - right_column_x_ - padding_, tableh_,
97 MapDetails::Style::kWui),
98+ directory_info_(this,
99+ padding_,
100+ get_inner_h() - 2 * buth_ - 4 * padding_,
101+ "",
102+ UI::Align::kLeft),
103 ok_(this,
104 "ok",
105 UI::g_fh1->fontset()->is_rtl() ? get_inner_w() / 2 - butw_ - padding_ : get_inner_w() / 2 + padding_,
106@@ -68,9 +75,10 @@
107 buth_,
108 g_gr->images().get("images/ui_basic/but1.png"),
109 _("Cancel")),
110- basedir_("maps"),
111+ basedir_(basedir),
112 has_translated_mapname_(false),
113 showing_mapames_(false) {
114+ g_fs->ensure_directory_exists(basedir_);
115 curdir_ = basedir_;
116
117 UI::Box* vbox = new UI::Box(this, tablex_, padding_, UI::Box::Horizontal, padding_, get_w());
118@@ -78,7 +86,7 @@
119 "show_mapnames",
120 0,
121 0,
122- butw_,
123+ 2 * butw_,
124 buth_,
125 g_gr->images().get("images/ui_basic/but1.png"),
126 _("Show Map Names"));
127@@ -155,6 +163,8 @@
128 // about the absolute filesystem top!) we manually add ".."
129 if (curdir_ != basedir_) {
130 maps_data_.push_back(MapData::create_parent_dir(curdir_));
131+ } else if (files.empty()) {
132+ maps_data_.push_back(MapData::create_empty_dir(curdir_));
133 }
134
135 MapData::DisplayType display_type;
136
137=== modified file 'src/editor/ui_menus/main_menu_load_or_save_map.h'
138--- src/editor/ui_menus/main_menu_load_or_save_map.h 2016-04-06 09:23:04 +0000
139+++ src/editor/ui_menus/main_menu_load_or_save_map.h 2016-06-07 09:07:42 +0000
140@@ -25,6 +25,7 @@
141 #include "editor/editorinteractive.h"
142 #include "ui_basic/button.h"
143 #include "ui_basic/checkbox.h"
144+#include "ui_basic/textarea.h"
145 #include "ui_basic/window.h"
146 #include "wui/mapdetails.h"
147 #include "wui/maptable.h"
148@@ -34,12 +35,16 @@
149 */
150 struct MainMenuLoadOrSaveMap : public UI::Window {
151 MainMenuLoadOrSaveMap(EditorInteractive& parent,
152+ int no_of_bottom_rows,
153 const std::string& name,
154- const std::string& title);
155+ const std::string& title,
156+ const std::string& basedir = "maps");
157
158 protected:
159 virtual void clicked_ok() = 0;
160 void toggle_mapnames();
161+ // Sets the current dir and updates labels.
162+ virtual void set_current_directory(const std::string& filename) = 0;
163 void fill_table();
164
165 bool compare_players(uint32_t, uint32_t);
166@@ -57,6 +62,7 @@
167 std::vector<MapData> maps_data_;
168 MapDetails map_details_;
169
170+ UI::Textarea directory_info_;
171 UI::Button ok_, cancel_;
172
173 const std::string basedir_;
174
175=== modified file 'src/editor/ui_menus/main_menu_save_map.cc'
176--- src/editor/ui_menus/main_menu_save_map.cc 2016-05-07 18:54:04 +0000
177+++ src/editor/ui_menus/main_menu_save_map.cc 2016-06-07 09:07:42 +0000
178@@ -49,7 +49,7 @@
179
180 // TODO(GunChleoc): Arabic: Make directory dialog: buttons need more height for Arabic.
181 MainMenuSaveMap::MainMenuSaveMap(EditorInteractive& parent)
182- : MainMenuLoadOrSaveMap(parent, "save_map_menu", _("Save Map")),
183+ : MainMenuLoadOrSaveMap(parent, 3, "save_map_menu", _("Save Map"), "maps/My_Maps"),
184
185 make_directory_(this,
186 "make_directory",
187@@ -74,6 +74,7 @@
188 buth_,
189 _("Filename:"),
190 UI::Align::kLeft) {
191+ set_current_directory(curdir_);
192
193 // Make room for edit_options_ button
194 map_details_.set_max_height(map_details_.get_h() - buth_ - padding_);
195@@ -131,7 +132,7 @@
196
197 if (g_fs->is_directory(complete_filename.c_str()) &&
198 !Widelands::WidelandsMapLoader::is_widelands_map(complete_filename)) {
199- curdir_ = complete_filename;
200+ set_current_directory(complete_filename);
201 fill_table();
202 } else { // Ok, save this map
203 Widelands::Map& map = eia().egbase().map();
204@@ -151,6 +152,7 @@
205 * Called, when the make directory button was clicked.
206 */
207 void MainMenuSaveMap::clicked_make_directory() {
208+ /** TRANSLATORS: A folder that hasn't been given a name yet */
209 MainMenuSaveMapMakeDirectory md(this, _("unnamed"));
210 if (md.run<UI::Panel::Returncodes>() == UI::Panel::Returncodes::kOk) {
211 g_fs->ensure_directory_exists(curdir_);
212@@ -201,7 +203,7 @@
213 assert(table_.has_selection());
214 const MapData& mapdata = maps_data_[table_.get_selected()];
215 if (mapdata.maptype == MapData::MapType::kDirectory) {
216- curdir_ = mapdata.filename;
217+ set_current_directory(mapdata.filename);
218 fill_table();
219 } else {
220 clicked_ok();
221@@ -216,6 +218,13 @@
222 ok_.set_enabled(!editbox_->text().empty());
223 }
224
225+void MainMenuSaveMap::set_current_directory(const std::string& filename) {
226+ curdir_ = filename;
227+ /** TRANSLATORS: The folder that a file will be saved to. */
228+ directory_info_.set_text((boost::format(_("Current Directory: %s"))
229+ % (_("My Maps") + curdir_.substr(basedir_.size()))).str());
230+}
231+
232 /**
233 * Save the map in the current directory with
234 * the current filename
235
236=== modified file 'src/editor/ui_menus/main_menu_save_map.h'
237--- src/editor/ui_menus/main_menu_save_map.h 2016-04-06 09:23:04 +0000
238+++ src/editor/ui_menus/main_menu_save_map.h 2016-06-07 09:07:42 +0000
239@@ -34,6 +34,10 @@
240 struct MainMenuSaveMap : public MainMenuLoadOrSaveMap {
241 MainMenuSaveMap(EditorInteractive& parent);
242
243+protected:
244+ // Sets the current dir and updates labels.
245+ void set_current_directory(const std::string& filename) override;
246+
247 private:
248 EditorInteractive & eia();
249 void clicked_ok();
250
251=== modified file 'src/editor/ui_menus/main_menu_save_map_make_directory.cc'
252--- src/editor/ui_menus/main_menu_save_map_make_directory.cc 2016-04-23 08:05:31 +0000
253+++ src/editor/ui_menus/main_menu_save_map_make_directory.cc 2016-06-07 09:07:42 +0000
254@@ -66,6 +66,7 @@
255 boost::ref(*this),
256 UI::Panel::Returncodes::kBack));
257 center_to_parent();
258+ edit_.focus();
259 }
260
261
262
263=== modified file 'src/wui/mapdata.cc'
264--- src/wui/mapdata.cc 2016-04-16 07:10:03 +0000
265+++ src/wui/mapdata.cc 2016-06-07 09:07:42 +0000
266@@ -131,11 +131,20 @@
267 }
268
269 // static
270+MapData MapData::create_empty_dir(const std::string& current_dir) {
271+ /** TRANSLATORS: This label is shown when a folder is empty */
272+ return MapData(current_dir, (boost::format("<%s>") % _("empty")).str());
273+}
274+
275+// static
276 MapData MapData::create_directory(const std::string& directory) {
277 std::string localized_name;
278 if (boost::equals(directory, "maps/MP_Scenarios")) {
279 /** TRANSLATORS: Directory name for MP Scenarios in map selection */
280 localized_name = _("Multiplayer Scenarios");
281+ } else if (boost::equals(directory, "maps/My_Maps")) {
282+ /** TRANSLATORS: Directory name for user maps in map selection */
283+ localized_name = _("My Maps");
284 } else {
285 localized_name = FileSystem::fs_filename(directory.c_str());
286 }
287
288=== modified file 'src/wui/mapdata.h'
289--- src/wui/mapdata.h 2016-02-06 18:58:57 +0000
290+++ src/wui/mapdata.h 2016-06-07 09:07:42 +0000
291@@ -89,6 +89,9 @@
292 /// Get the ".." directory
293 static MapData create_parent_dir(const std::string& current_dir);
294
295+ /// To display if the directory is empty and has no parent
296+ static MapData create_empty_dir(const std::string& current_dir);
297+
298 /// Create a subdirectory
299 static MapData create_directory(const std::string& directory);
300
301
302=== modified file 'src/wui/maptable.cc'
303--- src/wui/maptable.cc 2016-01-29 08:37:22 +0000
304+++ src/wui/maptable.cc 2016-06-07 09:07:42 +0000
305@@ -34,7 +34,7 @@
306
307 /** TRANSLATORS: Column title for number of players in map list */
308 add_column(35, _("Pl."), _("Number of players"), UI::Align::kHCenter);
309- add_column(get_w() - 35 - 115, "", _("The name of the map or scenario"), UI::Align::kLeft);
310+ add_column(get_w() - 35 - 115, _("Filename"), _("The name of the map or scenario"), UI::Align::kLeft);
311 add_column(115, _("Size"), _("The size of the map (Width x Height)"), UI::Align::kLeft);
312 set_sort_column(0);
313 }

Subscribers

People subscribed via source and target branches

to status/vote changes: