Merge lp:~thenifker13-deactivatedaccount/widelands/trunk into lp:widelands

Proposed by Antonino Siena
Status: Work in progress
Proposed branch: lp:~thenifker13-deactivatedaccount/widelands/trunk
Merge into: lp:widelands
Diff against target: 265 lines (+90/-2)
15 files modified
src/editor/editorinteractive.cc (+3/-1)
src/editor/ui_menus/main_menu.cc (+16/-0)
src/editor/ui_menus/main_menu.h (+2/-0)
src/ui_basic/window.cc (+20/-0)
src/ui_basic/window.h (+1/-0)
src/ui_fsmenu/campaign_select.cc (+2/-0)
src/ui_fsmenu/loadgame.cc (+2/-0)
src/ui_fsmenu/mapselect.cc (+2/-0)
src/ui_fsmenu/scenario_select.cc (+2/-0)
src/wui/game_message_menu.cc (+4/-0)
src/wui/game_options_menu.cc (+22/-0)
src/wui/game_options_menu.h (+5/-0)
src/wui/interactive_player.cc (+3/-1)
src/wui/login_box.cc (+3/-0)
src/wui/story_message_box.cc (+3/-0)
To merge this branch: bzr merge lp:~thenifker13-deactivatedaccount/widelands/trunk
Reviewer Review Type Date Requested Status
Toni Förster Approve
Widelands Developers Pending
Review via email: mp+368235@code.launchpad.net

Description of the change

Window closing, opening OptionsMenu and exiting using the keyboard.

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

Continuous integration builds have changed state:

Travis build 5130. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/540341469.
Appveyor build 4912. State: failed. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_thenifker13_widelands_trunk-4912.

9124. By Antonino Siena

Added space to comment

Revision history for this message
Toni Förster (stonerl) wrote :

When a window looses focus, it cannot be closed by ESC any more. E.g. open the stats menu and then the mini map. The mini map can be closed with ESC but not the stats menu. Instead, the main menu opens.

review: Needs Fixing
Revision history for this message
Antonino Siena (thenifker13-deactivatedaccount) wrote :

Is it possible to access all windows(like in a vector/array)?

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 5136. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/540464281.
Appveyor build 4918. State: failed. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_thenifker13_widelands_trunk-4918.

Revision history for this message
GunChleoc (gunchleoc) wrote :

No, but you can access a Panel's children and parent internally. Have a look at Panel::do_think() to see how to iterate through a panel's children.

Revision history for this message
Antonino Siena (thenifker13-deactivatedaccount) wrote :

Fixed it - will push it now!

9125. By Antonino Siena

When closing a window using ESCAPE will cause the next open window to gain focus

Revision history for this message
Toni Förster (stonerl) wrote :

LGTM :)

There are some menus in the game, e.g. the tutorial screen, that do not handle the ESC key. That's not part of the feature but if you'd like to tip your toes into, it would be much appreciated.

review: Approve
Revision history for this message
Antonino Siena (thenifker13-deactivatedaccount) wrote :

I'm gonna look into these too, contemporary.

Revision history for this message
Antonino Siena (thenifker13-deactivatedaccount) wrote :

So you mean it should be implemented for 'story_message_box' too?

9126. By Antonino Siena

Allow ESCAPE to close story_message_box

9127. By Antonino Siena

Open and Close Editor menu using ESCAPE and exit from from Editor using ENTER

9128. By Antonino Siena

Added ESCAPE -> back functionality for main menu menues

Revision history for this message
GunChleoc (gunchleoc) wrote :

I have added some notes to the diff for further improvements that you can make.

Revision history for this message
Antonino Siena (thenifker13-deactivatedaccount) wrote :

Forgot to add the binding there, thanks.

Yes I want to add a binding for GameMessageMenu too, but I didnt figure
yet out how to properly bind in this case.
I tried it previously like this:
/SDL_Keysym esc = SDL_Keysym{SDL_SCANCODE_ESCAPE, SDLK_ESCAPE,
KMOD_NONE, 0}; list->cancel.connect(boost::bind(&UI::Window::handle_key,
boost::ref(*this), _1, _2)(true, esc) );/

Ok I just removed the else case as it is not necessary because of return
in the if case.

Am 04.06.19 um 17:44 schrieb GunChleoc:
> I have added some notes to the diff for further improvements that you can make.
>
> Diff comments:
>
>> === modified file 'src/ui_fsmenu/loadgame.cc'
>> --- src/ui_fsmenu/loadgame.cc 2019-05-26 17:21:15 +0000
>> +++ src/ui_fsmenu/loadgame.cc 2019-06-04 12:56:27 +0000
>> @@ -170,6 +170,10 @@
>> }
>>
>> bool FullscreenMenuLoadGame::handle_key(bool down, SDL_Keysym code) {
>> + if (code.sym == SDLK_ESCAPE)
> You should be able to define load_or_save_.table_.cancel.connect instead.
>
>> + FullscreenMenuLoadGame::clicked_back();
>> + return true;
>> +
>> if (!down)
>> return false;
>>
>>
>> === modified file 'src/wui/game_message_menu.cc'
>> --- src/wui/game_message_menu.cc 2019-05-26 17:21:15 +0000
>> +++ src/wui/game_message_menu.cc 2019-06-04 12:56:27 +0000
>> @@ -362,6 +362,10 @@
>> * Handle message menu hotkeys.
>> */
>> bool GameMessageMenu::handle_key(bool down, SDL_Keysym code) {
>> + // Special ESCAPE handling
>> + // When ESCAPE is pressed down is false
>> + if (code.sym == SDLK_ESCAPE)
>> + return UI::Window::handle_key(true, code);
> The difference for ths function is that it has
>
>
> return list->handle_key(down, code);
>
> on the bottom. Do an if-else around that and you might not need the special handling.
>
>> if (down) {
>> switch (code.sym) {
>> // Don't forget to change the tooltips if any of these get reassigned
>>
>> === modified file 'src/wui/game_options_menu.cc'
>> --- src/wui/game_options_menu.cc 2019-03-18 07:11:02 +0000
>> +++ src/wui/game_options_menu.cc 2019-06-04 12:56:27 +0000
>> @@ -101,6 +101,28 @@
>> center_to_parent();
>> }
>>
>> +bool GameOptionsMenu::handle_key(bool down, SDL_Keysym code) {
>> + if (down) {
>> + switch (code.sym) {
>> + case SDLK_ESCAPE:
>> + die();
>> + return true;
>> + case SDLK_RETURN:
>> + if ((code.mod & (KMOD_LCTRL | KMOD_RCTRL))) {
>> + igb_.end_modal<UI::Panel::Returncodes>(UI::Panel::Returncodes::kBack);
>> + return true;
>> + }
>> + else
> We try to avoid if/else/for without {}, because leaving them out can cause bugs.
>
>> + new GameExitConfirmBox(*get_parent(), igb_);
>> + die();
>> + return true;
>> + default:
>> + break;
>> + }
>> + }
>> + return UI::Window::handle_key(down, code);
>> +}
>> +
>> GameOptionsMenu::~GameOptionsMenu() {
>> }
>>
>

9129. By Antonino Siena

Removed unnecessary else-case

9130. By Antonino Siena

Proper ESCAPE handling

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 5153. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/541384195.
Appveyor build 4935. State: failed. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_thenifker13_widelands_trunk-4935.

Revision history for this message
GunChleoc (gunchleoc) wrote :

2 more comments.

This branch breaks map keyboard navigation with the arrow keys though as soon as a buildingwindow is open. So, BuildingWindow needs to check whether Window has handled the key and if not, delegate it to its parent_.

Revision history for this message
Antonino Siena (thenifker13-deactivatedaccount) wrote :

Firstly how do I check if the sibling I get from get_next_sibling() from Panel is actually one?
And from which windows should it be possible to navigate?

Revision history for this message
Antonino Siena (thenifker13-deactivatedaccount) wrote :

Trying in window.cc - doesnt work so far:
"
case SDLK_UP:
case SDLK_DOWN:
case SDLK_LEFT:
case SDLK_RIGHT:{
 Panel *p = get_parent();
 return p->handle_key(down, code);
}
"

Revision history for this message
Antonino Siena (thenifker13-deactivatedaccount) wrote :

No ideas?

Revision history for this message
Antonino Siena (thenifker13-deactivatedaccount) wrote :

Literally no one that has any idea?

Revision history for this message
GunChleoc (gunchleoc) wrote :

Sorry I didn't get back to you earlier, I don't have much time for Widelands at the moment.

I did some digging into the code, and for some weird reason, map movement with the arrow keys is implemented in InteractiveBase::think().

This is also creating problems for me in another branch, so I think I better have a look at it in a new branch, and then retest this branch once the other branch has been merged.

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

The other branch has been merged now. Can you please merge trunk into this one so that we can retest?

9131. By Antonino Siena

Merged trunk here

Revision history for this message
Antonino Siena (thenifker13-deactivatedaccount) wrote :

Merged trunk right now.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 5289. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/564632804.
Appveyor build 5064. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_thenifker13_widelands_trunk-5064.

Revision history for this message
Antonino Siena (thenifker13-deactivatedaccount) wrote :

Has someone else tested it already?

Revision history for this message
GunChleoc (gunchleoc) wrote :

I'm sorry, Launchpad did not notify us on your comments. *headdesk* Can you contact me personally via https://launchpad.net/~gunchleoc next time, so I won't miss this again? We will be moving to GitHub too next weekend. If you don't want to move with us, just let me know and I'll finish up this branch over there.

The files src/editor/ui_menus/main_menu.cc/h and src/wui/game_options_menu.cc/h now don't exist any more, because we replace them with toolbar menus. So, you'll have to merge trunk again before we can finalize this branch.

I have done some testing, and it is working well now :)

Revision history for this message
Antonino Siena (thenifker13-deactivatedaccount) wrote :

Ill do so. Id rather move to GitLab but GitHub should be fine.
When trying to merge I then got this compilation error I was unsure about:
"
../src/editor/editorinteractive.cc:844:8: error: expected type-specifier before ‘EditorMainMenu’
  844 | new EditorMainMenu(*this, mainmenu_);
      | ^~~~~~~~~~~~~~
"

Revision history for this message
GunChleoc (gunchleoc) wrote :

That's because the class EditorMainMenu does not exist any more. It has been replaced with UI::Dropdown<MainMenuEntry> mainmenu_.

Revision history for this message
Antonino Siena (thenifker13-deactivatedaccount) wrote :

Ok, good to know - Ill take a look at it the next days.

Am 08.09.19 um 17:28 schrieb GunChleoc:
> That's because the class EditorMainMenu does not exist any more. It has been replaced with UI::Dropdown<MainMenuEntry> mainmenu_.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Unmerged revisions

9131. By Antonino Siena

Merged trunk here

9130. By Antonino Siena

Proper ESCAPE handling

9129. By Antonino Siena

Removed unnecessary else-case

9128. By Antonino Siena

Added ESCAPE -> back functionality for main menu menues

9127. By Antonino Siena

Open and Close Editor menu using ESCAPE and exit from from Editor using ENTER

9126. By Antonino Siena

Allow ESCAPE to close story_message_box

9125. By Antonino Siena

When closing a window using ESCAPE will cause the next open window to gain focus

9124. By Antonino Siena

Added space to comment

9123. By Antonino Siena

Instant exit using CTRL+ENTER

9122. By Antonino Siena

Removed empty line and changed special ESCAPE handling a bit

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/editor/editorinteractive.cc'
2--- src/editor/editorinteractive.cc 2019-04-26 05:52:49 +0000
3+++ src/editor/editorinteractive.cc 2019-07-28 13:42:36 +0000
4@@ -566,7 +566,9 @@
5 case SDLK_F1:
6 helpmenu_.toggle();
7 return true;
8-
9+ case SDLK_ESCAPE:
10+ new EditorMainMenu(*this, mainmenu_);
11+ return true;
12 default:
13 break;
14 }
15
16=== modified file 'src/editor/ui_menus/main_menu.cc'
17--- src/editor/ui_menus/main_menu.cc 2019-02-23 11:00:49 +0000
18+++ src/editor/ui_menus/main_menu.cc 2019-07-28 13:42:36 +0000
19@@ -82,6 +82,22 @@
20 center_to_parent();
21 }
22
23+bool EditorMainMenu::handle_key(bool down, SDL_Keysym code) {
24+ if (down) {
25+ switch (code.sym) {
26+ case SDLK_ESCAPE:
27+ die();
28+ return true;
29+ case SDLK_RETURN:
30+ exit_btn();
31+ return true;
32+ default:
33+ break;
34+ }
35+ }
36+ return UI::Window::handle_key(down, code);
37+}
38+
39 void EditorMainMenu::new_map_btn() {
40 new MainMenuNewMap(eia());
41 die();
42
43=== modified file 'src/editor/ui_menus/main_menu.h'
44--- src/editor/ui_menus/main_menu.h 2019-02-23 11:00:49 +0000
45+++ src/editor/ui_menus/main_menu.h 2019-07-28 13:42:36 +0000
46@@ -32,6 +32,8 @@
47 struct EditorMainMenu : public UI::UniqueWindow {
48 EditorMainMenu(EditorInteractive&, UI::UniqueWindow::Registry&);
49
50+ bool handle_key(bool down, SDL_Keysym code) override;
51+
52 private:
53 EditorInteractive& eia();
54 UI::Box box_;
55
56=== modified file 'src/ui_basic/window.cc'
57--- src/ui_basic/window.cc 2019-07-27 11:20:37 +0000
58+++ src/ui_basic/window.cc 2019-07-28 13:42:36 +0000
59@@ -101,6 +101,7 @@
60 VT_B_PIXMAP_THICKNESS, VT_B_PIXMAP_THICKNESS, TP_B_PIXMAP_THICKNESS, BT_B_PIXMAP_THICKNESS);
61 set_top_on_click(true);
62 set_layout_toplevel(true);
63+ focus();
64 }
65
66 /**
67@@ -411,6 +412,25 @@
68 return true;
69 }
70
71+bool Window::handle_key(bool down, SDL_Keysym code) {
72+ // Handles a key input and event and will close when pressing ESC
73+
74+ if (down) {
75+ switch (code.sym) {
76+ case SDLK_ESCAPE: {
77+ die();
78+ Panel *ch = get_next_sibling();
79+ if (ch != nullptr)
80+ ch->focus();
81+ return true;
82+ }
83+ default:
84+ break;
85+ }
86+ }
87+ return UI::Panel::handle_key(down, code);
88+}
89+
90 /**
91 * Close the window. Overwrite this virtual method if you want
92 * to take some action before the window is destroyed, or to
93
94=== modified file 'src/ui_basic/window.h'
95--- src/ui_basic/window.h 2019-02-23 11:00:49 +0000
96+++ src/ui_basic/window.h 2019-07-28 13:42:36 +0000
97@@ -98,6 +98,7 @@
98 handle_mousemove(uint8_t state, int32_t mx, int32_t my, int32_t xdiff, int32_t ydiff) override;
99 bool handle_mousewheel(uint32_t which, int32_t x, int32_t y) override;
100 bool handle_tooltip() override;
101+ bool handle_key(bool down, SDL_Keysym code) override;
102
103 protected:
104 void die() override;
105
106=== modified file 'src/ui_fsmenu/campaign_select.cc'
107--- src/ui_fsmenu/campaign_select.cc 2019-05-26 17:21:15 +0000
108+++ src/ui_fsmenu/campaign_select.cc 2019-07-28 13:42:36 +0000
109@@ -74,6 +74,8 @@
110 table_.focus();
111 fill_table();
112 layout();
113+
114+ table_.cancel.connect(boost::bind(&FullscreenMenuCampaignSelect::clicked_back, boost::ref(*this)));
115 }
116
117 void FullscreenMenuCampaignSelect::layout() {
118
119=== modified file 'src/ui_fsmenu/loadgame.cc'
120--- src/ui_fsmenu/loadgame.cc 2019-05-26 17:21:15 +0000
121+++ src/ui_fsmenu/loadgame.cc 2019-07-28 13:42:36 +0000
122@@ -109,6 +109,8 @@
123 if (!load_or_save_.table().empty()) {
124 load_or_save_.table().select(0);
125 }
126+
127+ load_or_save_.table_.cancel.connect(boost::bind(&FullscreenMenuLoadGame::clicked_back, boost::ref(*this)));
128 }
129
130 void FullscreenMenuLoadGame::layout() {
131
132=== modified file 'src/ui_fsmenu/mapselect.cc'
133--- src/ui_fsmenu/mapselect.cc 2019-05-26 17:21:15 +0000
134+++ src/ui_fsmenu/mapselect.cc 2019-07-28 13:42:36 +0000
135@@ -298,6 +298,8 @@
136 table_.select(0);
137 }
138 set_has_selection();
139+
140+ table_.cancel.connect(boost::bind(&FullscreenMenuMapSelect::clicked_back, boost::ref(*this)));
141 }
142
143 /*
144
145=== modified file 'src/ui_fsmenu/scenario_select.cc'
146--- src/ui_fsmenu/scenario_select.cc 2019-05-26 17:21:15 +0000
147+++ src/ui_fsmenu/scenario_select.cc 2019-07-28 13:42:36 +0000
148@@ -118,6 +118,8 @@
149 table_.focus();
150 fill_table();
151 layout();
152+
153+ table_.cancel.connect(boost::bind(&FullscreenMenuScenarioSelect::clicked_back, boost::ref(*this)));
154 }
155
156 void FullscreenMenuScenarioSelect::layout() {
157
158=== modified file 'src/wui/game_message_menu.cc'
159--- src/wui/game_message_menu.cc 2019-06-25 07:34:58 +0000
160+++ src/wui/game_message_menu.cc 2019-07-28 13:42:36 +0000
161@@ -360,6 +360,10 @@
162 * Handle message menu hotkeys.
163 */
164 bool GameMessageMenu::handle_key(bool down, SDL_Keysym code) {
165+ // Special ESCAPE handling
166+ // When ESCAPE is pressed down is false
167+ if (code.sym == SDLK_ESCAPE)
168+ return UI::Window::handle_key(true, code);
169 if (down) {
170 switch (code.sym) {
171 // Don't forget to change the tooltips if any of these get reassigned
172
173=== modified file 'src/wui/game_options_menu.cc'
174--- src/wui/game_options_menu.cc 2019-03-18 07:11:02 +0000
175+++ src/wui/game_options_menu.cc 2019-07-28 13:42:36 +0000
176@@ -101,6 +101,28 @@
177 center_to_parent();
178 }
179
180+bool GameOptionsMenu::handle_key(bool down, SDL_Keysym code) {
181+ if (down) {
182+ switch (code.sym) {
183+ case SDLK_ESCAPE:
184+ die();
185+ return true;
186+ case SDLK_RETURN:
187+ if ((code.mod & (KMOD_LCTRL | KMOD_RCTRL))) {
188+ igb_.end_modal<UI::Panel::Returncodes>(UI::Panel::Returncodes::kBack);
189+ return true;
190+ }
191+
192+ new GameExitConfirmBox(*get_parent(), igb_);
193+ die();
194+ return true;
195+ default:
196+ break;
197+ }
198+ }
199+ return UI::Window::handle_key(down, code);
200+}
201+
202 GameOptionsMenu::~GameOptionsMenu() {
203 }
204
205
206=== modified file 'src/wui/game_options_menu.h'
207--- src/wui/game_options_menu.h 2019-02-23 11:00:49 +0000
208+++ src/wui/game_options_menu.h 2019-07-28 13:42:36 +0000
209@@ -32,8 +32,13 @@
210 GameOptionsMenu(InteractiveGameBase&,
211 UI::UniqueWindow::Registry&,
212 InteractiveGameBase::GameMainMenuWindows&);
213+
214+ bool handle_key(bool down, SDL_Keysym code) override;
215+
216+
217 ~GameOptionsMenu();
218
219+
220 private:
221 InteractiveGameBase& igb_;
222 InteractiveGameBase::GameMainMenuWindows& windows_;
223
224=== modified file 'src/wui/interactive_player.cc'
225--- src/wui/interactive_player.cc 2019-05-31 19:31:45 +0000
226+++ src/wui/interactive_player.cc 2019-07-28 13:42:36 +0000
227@@ -487,7 +487,9 @@
228 map_view()->scroll_to_field(
229 game().map().get_starting_pos(player_number_), MapView::Transition::Smooth);
230 return true;
231-
232+ case SDLK_ESCAPE:
233+ new GameOptionsMenu(*this, options_, main_windows_);
234+ return true;
235 case SDLK_KP_ENTER:
236 case SDLK_RETURN:
237 if (chat_provider_) {
238
239=== modified file 'src/wui/login_box.cc'
240--- src/wui/login_box.cc 2019-06-01 11:29:24 +0000
241+++ src/wui/login_box.cc 2019-07-28 13:42:36 +0000
242@@ -81,6 +81,9 @@
243 }
244
245 eb_nickname->focus();
246+
247+ eb_nickname->cancel.connect(boost::bind(&LoginBox::clicked_back, boost::ref(*this)));
248+ eb_password->cancel.connect(boost::bind(&LoginBox::clicked_back, boost::ref(*this)));
249 }
250
251 /// think function of the UI (main loop)
252
253=== modified file 'src/wui/story_message_box.cc'
254--- src/wui/story_message_box.cc 2019-02-23 11:00:49 +0000
255+++ src/wui/story_message_box.cc 2019-07-28 13:42:36 +0000
256@@ -97,6 +97,9 @@
257 case SDLK_RETURN:
258 clicked_ok();
259 return true;
260+ case SDLK_ESCAPE:
261+ clicked_ok();
262+ return UI::Window::handle_key(down, code);
263 default:
264 break; // not handled
265 }

Subscribers

People subscribed via source and target branches

to status/vote changes: