Merge lp:~widelands-dev/widelands/bug-1696063-editor-save-map into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 8714
Proposed branch: lp:~widelands-dev/widelands/bug-1696063-editor-save-map
Merge into: lp:widelands
Diff against target: 191 lines (+55/-10)
6 files modified
src/editor/ui_menus/main_menu_save_map.cc (+22/-6)
src/editor/ui_menus/main_menu_save_map.h (+2/-0)
src/ui_basic/table.cc (+15/-0)
src/ui_basic/table.h (+3/-1)
src/wui/game_main_menu_save_game.cc (+11/-0)
src/wui/game_main_menu_save_game.h (+2/-3)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1696063-editor-save-map
Reviewer Review Type Date Requested Status
Klaus Halfmann Needs Resubmitting
Review via email: mp+345375@code.launchpad.net

Commit message

Fixed keyboard navigation with escape and enter for save map and save game screens. If the editbox is focused, eccape will reset the text if changed, and close the window if unchanged.

To post a comment you must log in.
Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 3488. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/377389086.
Appveyor build 3293. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1696063_editor_save_map-3293.

Revision history for this message
Klaus Halfmann (klaus-halfmann) wrote :

Code looks straight forward, while compile test this

Revision history for this message
Klaus Halfmann (klaus-halfmann) wrote :

Works as expected.

@bunnybot merge

review: Approve (compile, test)
Revision history for this message
bunnybot (widelandsofficial) wrote :

Error merging this proposal:

Output:
stdout:

stderr:
 M src/editor/ui_menus/main_menu_save_map.cc
 M src/editor/ui_menus/main_menu_save_map.h
 M src/ui_basic/table.cc
 M src/ui_basic/table.h
 M src/wui/game_main_menu_save_game.cc
 M src/wui/game_main_menu_save_game.h
Text conflict in src/editor/ui_menus/main_menu_save_map.cc
1 conflicts encountered.

Revision history for this message
Klaus Halfmann (klaus-halfmann) wrote :

Gun please check if I resolved the conflict correctly

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

Checked :)

@bunnybot merge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/editor/ui_menus/main_menu_save_map.cc'
--- src/editor/ui_menus/main_menu_save_map.cc 2018-04-27 06:11:05 +0000
+++ src/editor/ui_menus/main_menu_save_map.cc 2018-05-21 12:27:44 +0000
@@ -77,17 +77,23 @@
77 table_.selected.connect(boost::bind(&MainMenuSaveMap::clicked_item, boost::ref(*this)));77 table_.selected.connect(boost::bind(&MainMenuSaveMap::clicked_item, boost::ref(*this)));
78 table_.double_clicked.connect(78 table_.double_clicked.connect(
79 boost::bind(&MainMenuSaveMap::double_clicked_item, boost::ref(*this)));79 boost::bind(&MainMenuSaveMap::double_clicked_item, boost::ref(*this)));
8080 table_.cancel.connect(boost::bind(&MainMenuSaveMap::die, this));
81 editbox_ = new UI::EditBox(81 table_.set_can_focus(true);
82 this, editbox_label_.get_x() + editbox_label_.get_w() + padding_, editbox_label_.get_y(),82
83 tablew_ - editbox_label_.get_w() - padding_ + 1, buth_, 2, UI::PanelStyle::kWui);83 editbox_ =
8484 new UI::EditBox(this, editbox_label_.get_x() + editbox_label_.get_w() + padding_,
85 editbox_label_.get_y(), tablew_ - editbox_label_.get_w() - padding_ + 1,
86 buth_, 2, UI::PanelStyle::kWui);
85 editbox_->set_text(parent.egbase().map().get_name());87 editbox_->set_text(parent.egbase().map().get_name());
88
86 editbox_->changed.connect(boost::bind(&MainMenuSaveMap::edit_box_changed, this));89 editbox_->changed.connect(boost::bind(&MainMenuSaveMap::edit_box_changed, this));
87 edit_box_changed();90 edit_box_changed();
91 editbox_->ok.connect(boost::bind(&MainMenuSaveMap::clicked_ok, boost::ref(*this)));
92 editbox_->cancel.connect(boost::bind(&MainMenuSaveMap::reset_editbox_or_die, boost::ref(*this), parent.egbase().map().get_name()));
8893
89 ok_.sigclicked.connect(boost::bind(&MainMenuSaveMap::clicked_ok, boost::ref(*this)));94 ok_.sigclicked.connect(boost::bind(&MainMenuSaveMap::clicked_ok, boost::ref(*this)));
90 cancel_.sigclicked.connect(boost::bind(&MainMenuSaveMap::die, boost::ref(*this)));95 cancel_.sigclicked.connect(boost::bind(&MainMenuSaveMap::die, boost::ref(*this)));
96
91 make_directory_.sigclicked.connect(97 make_directory_.sigclicked.connect(
92 boost::bind(&MainMenuSaveMap::clicked_make_directory, boost::ref(*this)));98 boost::bind(&MainMenuSaveMap::clicked_make_directory, boost::ref(*this)));
93 edit_options_.sigclicked.connect(99 edit_options_.sigclicked.connect(
@@ -137,6 +143,8 @@
137 }143 }
138 if (save_map(filename, !g_options.pull_section("global").get_bool("nozip", false))) {144 if (save_map(filename, !g_options.pull_section("global").get_bool("nozip", false))) {
139 die();145 die();
146 } else {
147 table_.focus();
140 }148 }
141 }149 }
142}150}
@@ -215,6 +223,14 @@
215 ok_.set_enabled(LayeredFileSystem::is_legal_filename(editbox_->text()));223 ok_.set_enabled(LayeredFileSystem::is_legal_filename(editbox_->text()));
216}224}
217225
226void MainMenuSaveMap::reset_editbox_or_die(const std::string& current_filename) {
227 if (editbox_->text() == current_filename) {
228 die();
229 } else {
230 editbox_->set_text(current_filename);
231 }
232}
233
218void MainMenuSaveMap::set_current_directory(const std::string& filename) {234void MainMenuSaveMap::set_current_directory(const std::string& filename) {
219 curdir_ = filename;235 curdir_ = filename;
220 directory_info_.set_text(236 directory_info_.set_text(
@@ -251,7 +267,7 @@
251 FileSystem::fs_filename(filename.c_str()))267 FileSystem::fs_filename(filename.c_str()))
252 .str();268 .str();
253 UI::WLMessageBox mbox(269 UI::WLMessageBox mbox(
254 &eia(), _("Error Saving Map!"), s, UI::WLMessageBox::MBoxType::kOkCancel);270 this, _("Error Saving Map!"), s, UI::WLMessageBox::MBoxType::kOkCancel);
255 if (mbox.run<UI::Panel::Returncodes>() == UI::Panel::Returncodes::kBack)271 if (mbox.run<UI::Panel::Returncodes>() == UI::Panel::Returncodes::kBack)
256 return false;272 return false;
257 }273 }
258274
=== modified file 'src/editor/ui_menus/main_menu_save_map.h'
--- src/editor/ui_menus/main_menu_save_map.h 2018-04-07 16:59:00 +0000
+++ src/editor/ui_menus/main_menu_save_map.h 2018-05-21 12:27:44 +0000
@@ -46,6 +46,8 @@
46 void clicked_item();46 void clicked_item();
47 void double_clicked_item();47 void double_clicked_item();
48 void edit_box_changed();48 void edit_box_changed();
49 /// Resets the map's filename in the editbox. If mapname didn't change, die().
50 void reset_editbox_or_die(const std::string& current_filename);
4951
50 bool save_map(std::string, bool);52 bool save_map(std::string, bool);
5153
5254
=== 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-21 12:27:44 +0000
@@ -329,6 +329,21 @@
329bool Table<void*>::handle_key(bool down, SDL_Keysym code) {329bool Table<void*>::handle_key(bool down, SDL_Keysym code) {
330 if (down) {330 if (down) {
331 switch (code.sym) {331 switch (code.sym) {
332 case SDLK_ESCAPE:
333 cancel();
334 return true;
335
336 case SDLK_TAB:
337 // Let the panel handle the tab key
338 return get_parent()->handle_key(true, code);
339
340 case SDLK_KP_ENTER:
341 case SDLK_RETURN:
342 if (selection_ != no_selection_index()) {
343 double_clicked(selection_);
344 }
345 return true;
346
332 case SDLK_a:347 case SDLK_a:
333 if (is_multiselect_ && (code.mod & KMOD_CTRL) && !empty()) {348 if (is_multiselect_ && (code.mod & KMOD_CTRL) && !empty()) {
334 multiselect_.clear();349 multiselect_.clear();
335350
=== 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-21 12:27:44 +0000
@@ -62,6 +62,7 @@
62 TableRows rowtype = TableRows::kSingle);62 TableRows rowtype = TableRows::kSingle);
63 ~Table();63 ~Table();
6464
65 boost::signals2::signal<void()> cancel;
65 boost::signals2::signal<void(uint32_t)> selected;66 boost::signals2::signal<void(uint32_t)> selected;
66 boost::signals2::signal<void(uint32_t)> double_clicked;67 boost::signals2::signal<void(uint32_t)> double_clicked;
6768
@@ -122,7 +123,7 @@
122 void draw(RenderTarget&);123 void draw(RenderTarget&);
123 bool handle_mousepress(uint8_t btn, int32_t x, int32_t y);124 bool handle_mousepress(uint8_t btn, int32_t x, int32_t y);
124 bool handle_mousewheel(uint32_t which, int32_t x, int32_t y);125 bool handle_mousewheel(uint32_t which, int32_t x, int32_t y);
125 virtual bool handle_key(bool down, SDL_Keysym code);126 bool handle_key(bool down, SDL_Keysym code);
126};127};
127128
128template <> class Table<void*> : public Panel {129template <> class Table<void*> : public Panel {
@@ -179,6 +180,7 @@
179 */180 */
180 using CompareFn = boost::function<bool(uint32_t, uint32_t)>;181 using CompareFn = boost::function<bool(uint32_t, uint32_t)>;
181182
183 boost::signals2::signal<void()> cancel;
182 boost::signals2::signal<void(uint32_t)> selected;184 boost::signals2::signal<void(uint32_t)> selected;
183 boost::signals2::signal<void(uint32_t)> double_clicked;185 boost::signals2::signal<void(uint32_t)> double_clicked;
184186
185187
=== modified file 'src/wui/game_main_menu_save_game.cc'
--- src/wui/game_main_menu_save_game.cc 2018-05-13 07:15:39 +0000
+++ src/wui/game_main_menu_save_game.cc 2018-05-21 12:27:44 +0000
@@ -95,12 +95,14 @@
9595
96 filename_editbox_.changed.connect(boost::bind(&GameMainMenuSaveGame::edit_box_changed, this));96 filename_editbox_.changed.connect(boost::bind(&GameMainMenuSaveGame::edit_box_changed, this));
97 filename_editbox_.ok.connect(boost::bind(&GameMainMenuSaveGame::ok, this));97 filename_editbox_.ok.connect(boost::bind(&GameMainMenuSaveGame::ok, this));
98 filename_editbox_.cancel.connect(boost::bind(&GameMainMenuSaveGame::reset_editbox_or_die, this, parent.game().save_handler().get_cur_filename()));
9899
99 ok_.sigclicked.connect(boost::bind(&GameMainMenuSaveGame::ok, this));100 ok_.sigclicked.connect(boost::bind(&GameMainMenuSaveGame::ok, this));
100 cancel_.sigclicked.connect(boost::bind(&GameMainMenuSaveGame::die, this));101 cancel_.sigclicked.connect(boost::bind(&GameMainMenuSaveGame::die, this));
101102
102 load_or_save_.table().selected.connect(boost::bind(&GameMainMenuSaveGame::entry_selected, this));103 load_or_save_.table().selected.connect(boost::bind(&GameMainMenuSaveGame::entry_selected, this));
103 load_or_save_.table().double_clicked.connect(boost::bind(&GameMainMenuSaveGame::ok, this));104 load_or_save_.table().double_clicked.connect(boost::bind(&GameMainMenuSaveGame::ok, this));
105 load_or_save_.table().cancel.connect(boost::bind(&GameMainMenuSaveGame::die, this));
104106
105 load_or_save_.fill_table();107 load_or_save_.fill_table();
106 load_or_save_.select_by_name(parent.game().save_handler().get_cur_filename());108 load_or_save_.select_by_name(parent.game().save_handler().get_cur_filename());
@@ -136,6 +138,15 @@
136 load_or_save_.clear_selections();138 load_or_save_.clear_selections();
137}139}
138140
141void GameMainMenuSaveGame::reset_editbox_or_die(const std::string& current_filename) {
142 if (filename_editbox_.text() == current_filename) {
143 die();
144 } else {
145 filename_editbox_.set_text(current_filename);
146 load_or_save_.select_by_name(current_filename);
147 }
148}
149
139static void dosave(InteractiveGameBase& igbase, const std::string& complete_filename) {150static void dosave(InteractiveGameBase& igbase, const std::string& complete_filename) {
140 Widelands::Game& game = igbase.game();151 Widelands::Game& game = igbase.game();
141152
142153
=== modified file 'src/wui/game_main_menu_save_game.h'
--- src/wui/game_main_menu_save_game.h 2018-04-07 16:59:00 +0000
+++ src/wui/game_main_menu_save_game.h 2018-05-21 12:27:44 +0000
@@ -54,6 +54,8 @@
5454
55 /// Update buttons and table selection state55 /// Update buttons and table selection state
56 void edit_box_changed();56 void edit_box_changed();
57 /// Resets the savegame's name in the editbox. If savegame name didn't change, die().
58 void reset_editbox_or_die(const std::string& current_filename);
5759
58 /// Called when the OK button is clicked or the Return key pressed in the edit box.60 /// Called when the OK button is clicked or the Return key pressed in the edit box.
59 void ok();61 void ok();
@@ -77,9 +79,6 @@
77 UI::Button cancel_, ok_;79 UI::Button cancel_, ok_;
7880
79 std::string curdir_;81 std::string curdir_;
80 std::string parentdir_;
81 std::string filename_;
82 bool overwrite_;
83};82};
8483
85#endif // end of include guard: WL_WUI_GAME_MAIN_MENU_SAVE_GAME_H84#endif // end of include guard: WL_WUI_GAME_MAIN_MENU_SAVE_GAME_H

Subscribers

People subscribed via source and target branches

to status/vote changes: