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
1=== modified file 'src/editor/ui_menus/main_menu_save_map.cc'
2--- src/editor/ui_menus/main_menu_save_map.cc 2018-04-27 06:11:05 +0000
3+++ src/editor/ui_menus/main_menu_save_map.cc 2018-05-21 12:27:44 +0000
4@@ -77,17 +77,23 @@
5 table_.selected.connect(boost::bind(&MainMenuSaveMap::clicked_item, boost::ref(*this)));
6 table_.double_clicked.connect(
7 boost::bind(&MainMenuSaveMap::double_clicked_item, boost::ref(*this)));
8-
9- editbox_ = new UI::EditBox(
10- this, editbox_label_.get_x() + editbox_label_.get_w() + padding_, editbox_label_.get_y(),
11- tablew_ - editbox_label_.get_w() - padding_ + 1, buth_, 2, UI::PanelStyle::kWui);
12-
13+ table_.cancel.connect(boost::bind(&MainMenuSaveMap::die, this));
14+ table_.set_can_focus(true);
15+
16+ editbox_ =
17+ new UI::EditBox(this, editbox_label_.get_x() + editbox_label_.get_w() + padding_,
18+ editbox_label_.get_y(), tablew_ - editbox_label_.get_w() - padding_ + 1,
19+ buth_, 2, UI::PanelStyle::kWui);
20 editbox_->set_text(parent.egbase().map().get_name());
21+
22 editbox_->changed.connect(boost::bind(&MainMenuSaveMap::edit_box_changed, this));
23 edit_box_changed();
24+ editbox_->ok.connect(boost::bind(&MainMenuSaveMap::clicked_ok, boost::ref(*this)));
25+ editbox_->cancel.connect(boost::bind(&MainMenuSaveMap::reset_editbox_or_die, boost::ref(*this), parent.egbase().map().get_name()));
26
27 ok_.sigclicked.connect(boost::bind(&MainMenuSaveMap::clicked_ok, boost::ref(*this)));
28 cancel_.sigclicked.connect(boost::bind(&MainMenuSaveMap::die, boost::ref(*this)));
29+
30 make_directory_.sigclicked.connect(
31 boost::bind(&MainMenuSaveMap::clicked_make_directory, boost::ref(*this)));
32 edit_options_.sigclicked.connect(
33@@ -137,6 +143,8 @@
34 }
35 if (save_map(filename, !g_options.pull_section("global").get_bool("nozip", false))) {
36 die();
37+ } else {
38+ table_.focus();
39 }
40 }
41 }
42@@ -215,6 +223,14 @@
43 ok_.set_enabled(LayeredFileSystem::is_legal_filename(editbox_->text()));
44 }
45
46+void MainMenuSaveMap::reset_editbox_or_die(const std::string& current_filename) {
47+ if (editbox_->text() == current_filename) {
48+ die();
49+ } else {
50+ editbox_->set_text(current_filename);
51+ }
52+}
53+
54 void MainMenuSaveMap::set_current_directory(const std::string& filename) {
55 curdir_ = filename;
56 directory_info_.set_text(
57@@ -251,7 +267,7 @@
58 FileSystem::fs_filename(filename.c_str()))
59 .str();
60 UI::WLMessageBox mbox(
61- &eia(), _("Error Saving Map!"), s, UI::WLMessageBox::MBoxType::kOkCancel);
62+ this, _("Error Saving Map!"), s, UI::WLMessageBox::MBoxType::kOkCancel);
63 if (mbox.run<UI::Panel::Returncodes>() == UI::Panel::Returncodes::kBack)
64 return false;
65 }
66
67=== modified file 'src/editor/ui_menus/main_menu_save_map.h'
68--- src/editor/ui_menus/main_menu_save_map.h 2018-04-07 16:59:00 +0000
69+++ src/editor/ui_menus/main_menu_save_map.h 2018-05-21 12:27:44 +0000
70@@ -46,6 +46,8 @@
71 void clicked_item();
72 void double_clicked_item();
73 void edit_box_changed();
74+ /// Resets the map's filename in the editbox. If mapname didn't change, die().
75+ void reset_editbox_or_die(const std::string& current_filename);
76
77 bool save_map(std::string, bool);
78
79
80=== modified file 'src/ui_basic/table.cc'
81--- src/ui_basic/table.cc 2018-05-14 08:24:46 +0000
82+++ src/ui_basic/table.cc 2018-05-21 12:27:44 +0000
83@@ -329,6 +329,21 @@
84 bool Table<void*>::handle_key(bool down, SDL_Keysym code) {
85 if (down) {
86 switch (code.sym) {
87+ case SDLK_ESCAPE:
88+ cancel();
89+ return true;
90+
91+ case SDLK_TAB:
92+ // Let the panel handle the tab key
93+ return get_parent()->handle_key(true, code);
94+
95+ case SDLK_KP_ENTER:
96+ case SDLK_RETURN:
97+ if (selection_ != no_selection_index()) {
98+ double_clicked(selection_);
99+ }
100+ return true;
101+
102 case SDLK_a:
103 if (is_multiselect_ && (code.mod & KMOD_CTRL) && !empty()) {
104 multiselect_.clear();
105
106=== modified file 'src/ui_basic/table.h'
107--- src/ui_basic/table.h 2018-05-07 05:35:32 +0000
108+++ src/ui_basic/table.h 2018-05-21 12:27:44 +0000
109@@ -62,6 +62,7 @@
110 TableRows rowtype = TableRows::kSingle);
111 ~Table();
112
113+ boost::signals2::signal<void()> cancel;
114 boost::signals2::signal<void(uint32_t)> selected;
115 boost::signals2::signal<void(uint32_t)> double_clicked;
116
117@@ -122,7 +123,7 @@
118 void draw(RenderTarget&);
119 bool handle_mousepress(uint8_t btn, int32_t x, int32_t y);
120 bool handle_mousewheel(uint32_t which, int32_t x, int32_t y);
121- virtual bool handle_key(bool down, SDL_Keysym code);
122+ bool handle_key(bool down, SDL_Keysym code);
123 };
124
125 template <> class Table<void*> : public Panel {
126@@ -179,6 +180,7 @@
127 */
128 using CompareFn = boost::function<bool(uint32_t, uint32_t)>;
129
130+ boost::signals2::signal<void()> cancel;
131 boost::signals2::signal<void(uint32_t)> selected;
132 boost::signals2::signal<void(uint32_t)> double_clicked;
133
134
135=== modified file 'src/wui/game_main_menu_save_game.cc'
136--- src/wui/game_main_menu_save_game.cc 2018-05-13 07:15:39 +0000
137+++ src/wui/game_main_menu_save_game.cc 2018-05-21 12:27:44 +0000
138@@ -95,12 +95,14 @@
139
140 filename_editbox_.changed.connect(boost::bind(&GameMainMenuSaveGame::edit_box_changed, this));
141 filename_editbox_.ok.connect(boost::bind(&GameMainMenuSaveGame::ok, this));
142+ filename_editbox_.cancel.connect(boost::bind(&GameMainMenuSaveGame::reset_editbox_or_die, this, parent.game().save_handler().get_cur_filename()));
143
144 ok_.sigclicked.connect(boost::bind(&GameMainMenuSaveGame::ok, this));
145 cancel_.sigclicked.connect(boost::bind(&GameMainMenuSaveGame::die, this));
146
147 load_or_save_.table().selected.connect(boost::bind(&GameMainMenuSaveGame::entry_selected, this));
148 load_or_save_.table().double_clicked.connect(boost::bind(&GameMainMenuSaveGame::ok, this));
149+ load_or_save_.table().cancel.connect(boost::bind(&GameMainMenuSaveGame::die, this));
150
151 load_or_save_.fill_table();
152 load_or_save_.select_by_name(parent.game().save_handler().get_cur_filename());
153@@ -136,6 +138,15 @@
154 load_or_save_.clear_selections();
155 }
156
157+void GameMainMenuSaveGame::reset_editbox_or_die(const std::string& current_filename) {
158+ if (filename_editbox_.text() == current_filename) {
159+ die();
160+ } else {
161+ filename_editbox_.set_text(current_filename);
162+ load_or_save_.select_by_name(current_filename);
163+ }
164+}
165+
166 static void dosave(InteractiveGameBase& igbase, const std::string& complete_filename) {
167 Widelands::Game& game = igbase.game();
168
169
170=== modified file 'src/wui/game_main_menu_save_game.h'
171--- src/wui/game_main_menu_save_game.h 2018-04-07 16:59:00 +0000
172+++ src/wui/game_main_menu_save_game.h 2018-05-21 12:27:44 +0000
173@@ -54,6 +54,8 @@
174
175 /// Update buttons and table selection state
176 void edit_box_changed();
177+ /// Resets the savegame's name in the editbox. If savegame name didn't change, die().
178+ void reset_editbox_or_die(const std::string& current_filename);
179
180 /// Called when the OK button is clicked or the Return key pressed in the edit box.
181 void ok();
182@@ -77,9 +79,6 @@
183 UI::Button cancel_, ok_;
184
185 std::string curdir_;
186- std::string parentdir_;
187- std::string filename_;
188- bool overwrite_;
189 };
190
191 #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: