← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~thenifker13/widelands/trunk into lp:widelands

 

Antonino Siena has proposed merging lp:~thenifker13/widelands/trunk into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1774596 in widelands: "Allow leaving game per keyboard shortcuts"
  https://bugs.launchpad.net/widelands/+bug/1774596

For more details, see:
https://code.launchpad.net/~thenifker13/widelands/trunk/+merge/368235

Window closing, opening OptionsMenu and exiting using the keyboard.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~thenifker13/widelands/trunk into lp:widelands.
=== modified file 'src/ui_basic/window.cc'
--- src/ui_basic/window.cc	2019-05-26 17:21:15 +0000
+++ src/ui_basic/window.cc	2019-06-02 09:57:53 +0000
@@ -101,6 +101,7 @@
 	   VT_B_PIXMAP_THICKNESS, VT_B_PIXMAP_THICKNESS, TP_B_PIXMAP_THICKNESS, BT_B_PIXMAP_THICKNESS);
 	set_top_on_click(true);
 	set_layout_toplevel(true);
+	focus();
 }
 
 /**
@@ -411,6 +412,21 @@
 	return true;
 }
 
+bool Window::handle_key(bool down, SDL_Keysym code) {
+	// Handles a key input and event and will close when pressing ESC
+
+	if (down) {
+		switch (code.sym) {
+			case SDLK_ESCAPE:
+				die();
+				return true;
+			default:
+				break;
+		}
+	}
+	return UI::Panel::handle_key(down, code);
+}
+
 /**
  * Close the window. Overwrite this virtual method if you want
  * to take some action before the window is destroyed, or to

=== modified file 'src/ui_basic/window.h'
--- src/ui_basic/window.h	2019-02-23 11:00:49 +0000
+++ src/ui_basic/window.h	2019-06-02 09:57:53 +0000
@@ -98,6 +98,7 @@
 	handle_mousemove(uint8_t state, int32_t mx, int32_t my, int32_t xdiff, int32_t ydiff) override;
 	bool handle_mousewheel(uint32_t which, int32_t x, int32_t y) override;
 	bool handle_tooltip() override;
+	bool handle_key(bool down, SDL_Keysym code) override;
 
 protected:
 	void die() override;

=== 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-02 09:57:53 +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);
 	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-02 09:57:53 +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
+					new GameExitConfirmBox(*get_parent(), igb_);
+				die();
+				return true;
+			default:
+				break;
+		}
+	}
+	return UI::Window::handle_key(down, code);
+}
+
 GameOptionsMenu::~GameOptionsMenu() {
 }
 

=== modified file 'src/wui/game_options_menu.h'
--- src/wui/game_options_menu.h	2019-02-23 11:00:49 +0000
+++ src/wui/game_options_menu.h	2019-06-02 09:57:53 +0000
@@ -32,8 +32,13 @@
 	GameOptionsMenu(InteractiveGameBase&,
 	                UI::UniqueWindow::Registry&,
 	                InteractiveGameBase::GameMainMenuWindows&);
+
+	bool handle_key(bool down, SDL_Keysym code) override;
+
+
 	~GameOptionsMenu();
 
+
 private:
 	InteractiveGameBase& igb_;
 	InteractiveGameBase::GameMainMenuWindows& windows_;

=== modified file 'src/wui/interactive_player.cc'
--- src/wui/interactive_player.cc	2019-05-31 19:31:45 +0000
+++ src/wui/interactive_player.cc	2019-06-02 09:57:53 +0000
@@ -487,7 +487,9 @@
 			map_view()->scroll_to_field(
 			   game().map().get_starting_pos(player_number_), MapView::Transition::Smooth);
 			return true;
-
+		case SDLK_ESCAPE:
+			new GameOptionsMenu(*this, options_, main_windows_);
+			return true;
 		case SDLK_KP_ENTER:
 		case SDLK_RETURN:
 			if (chat_provider_) {


Follow ups