← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~borim/widelands/improveMessages into lp:widelands

 

Borim has proposed merging lp:~borim/widelands/improveMessages into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)

For more details, see:
https://code.launchpad.net/~borim/widelands/improveMessages/+merge/89129

the behavior of the del button and the del key was different in the messages menu. Also none of them was intuitive.

* Reworked the archive_or_restore function so, that all marked messages are "deleted" and if no messages were marked, the highlighted one is "deleted".

* del key and button have the same behavior
* add ability to scroll through the messages with up and down keys
-- 
https://code.launchpad.net/~borim/widelands/improveMessages/+merge/89129
Your team Widelands Developers is requested to review the proposed merge of lp:~borim/widelands/improveMessages into lp:widelands.
=== modified file 'src/ui_basic/table.cc'
--- src/ui_basic/table.cc	2011-11-30 21:38:37 +0000
+++ src/ui_basic/table.cc	2012-01-18 19:59:33 +0000
@@ -321,6 +321,31 @@
 }
 
 /**
+ * handle key presses
+ */
+bool Table<void *>::handle_key(bool down, SDL_keysym code)
+{
+	if (down) {
+		switch (code.sym) {
+		case SDLK_UP:
+		case SDLK_KP8:
+			move_selection(-1);
+			return true;
+
+		case SDLK_DOWN:
+		case SDLK_KP2:
+			move_selection(1);
+			return true;
+
+		default:
+			break; // not handled
+		}
+	}
+
+	return UI::Panel::handle_key(down, code);
+}
+
+/**
  * Handle mouse presses: select the appropriate entry
  */
 bool Table<void *>::handle_mousepress
@@ -381,6 +406,43 @@
 }
 
 /**
+ * move the currently selected entry up or down.
+ * \param offset positive value move the selection down and
+ *        negative values up.
+ */
+void Table<void *>::move_selection(const int32_t offset)
+{
+	const uint32_t num = size();
+	const uint32_t abs_offset = abs(offset);
+
+	if (!has_selection()) return;
+	if (abs_offset >= num) return;
+
+	uint32_t new_selection;
+
+	if ((offset < 0) && (m_selection < abs_offset))
+	{
+		new_selection = num - abs_offset + m_selection;
+	}
+	else
+	{
+		new_selection = m_selection + offset;
+		new_selection %= num;
+	}
+
+	select(new_selection);
+	//scroll to newly selected entry
+	if (m_scrollbar)
+	{
+		int32_t scroll_offset = 0;
+		if (new_selection > 0) scroll_offset = -1;
+
+		m_scrollbar->set_scrollpos
+			((new_selection + scroll_offset) * get_lineheight());
+	}
+}
+
+/**
  * Change the currently selected entry
  *
  * Args: i  the entry to select

=== modified file 'src/ui_basic/table.h'
--- src/ui_basic/table.h	2011-11-30 21:38:37 +0000
+++ src/ui_basic/table.h	2012-01-18 19:59:33 +0000
@@ -87,6 +87,7 @@
 	Entry_Record * find(Entry) const throw ();
 
 	void select(uint32_t);
+	void move_selection(int32_t offset);
 	struct No_Selection : public std::exception {
 		char const * what() const throw () {
 			return "UI::Table<Entry>: No selection";
@@ -104,6 +105,7 @@
 	void draw(RenderTarget &);
 	bool handle_mousepress  (Uint8 btn, int32_t x, int32_t y);
 	bool handle_mouserelease(Uint8 btn, int32_t x, int32_t y);
+	virtual bool handle_key(bool down, SDL_keysym code);
 };
 
 template <> struct Table<void *> : public Panel {
@@ -212,6 +214,7 @@
 	Entry_Record * find(const void * entry) const throw ();
 
 	void select(uint32_t);
+	void move_selection(int32_t offset);
 	struct No_Selection : public std::exception {
 		char const * what() const throw () {
 			return "UI::Table<void *>: No selection";
@@ -237,6 +240,7 @@
 	void draw(RenderTarget &);
 	bool handle_mousepress  (Uint8 btn, int32_t x, int32_t y);
 	bool handle_mouserelease(Uint8 btn, int32_t x, int32_t y);
+	virtual bool handle_key(bool down, SDL_keysym code);
 
 private:
 	bool default_compare_checkbox(uint32_t column, uint32_t a, uint32_t b);

=== modified file 'src/wui/game_message_menu.cc'
--- src/wui/game_message_menu.cc	2011-11-30 21:38:37 +0000
+++ src/wui/game_message_menu.cc	2012-01-18 19:59:33 +0000
@@ -50,6 +50,7 @@
 {
 	list = new UI::Table<uintptr_t>(this, 5, 35, 360, 110);
 	list->selected.connect(boost::bind(&GameMessageMenu::selected, this, _1));
+	list->double_clicked.connect(boost::bind(&GameMessageMenu::double_clicked, this, _1));
 	list->add_column (50, _("Select"), UI::Align_HCenter, true);
 	list->add_column (50, _("Status"), UI::Align_HCenter);
 	list->add_column(136, _("Title"));
@@ -239,6 +240,13 @@
 }
 
 /**
+ * a message was double clicked
+ */
+void GameMessageMenu::double_clicked(uint32_t const t) {
+	if (m_centerviewbtn->enabled()) center_view();
+}
+
+/**
  * Handle message menu hotkeys.
  */
 bool GameMessageMenu::handle_key(bool down, SDL_keysym code)
@@ -254,7 +262,7 @@
 			if (code.mod & KMOD_NUM)
 				break;
 		case SDLK_DELETE:
-			do_delete();
+			archive_or_restore();
 			return true;
 
 		default:
@@ -262,25 +270,7 @@
 		}
 	}
 
-	return UI::Panel::handle_key(down, code);
-}
-
-/**
- * Delete the currently selected message, if any.
- */
-void GameMessageMenu::do_delete()
-{
-	if (mode == Archive)
-		return;
-
-	if (!list->has_selection())
-		return;
-
-	Widelands::Game & game = iplayer().game();
-	game.send_player_command
-		(*new Widelands::Cmd_MessageSetStatusArchived
-			(game.get_gametime(), iplayer().player_number(),
-			 Message_Id(list->get_selected())));
+	return list->handle_key(down, code);
 }
 
 void GameMessageMenu::archive_or_restore()
@@ -289,27 +279,54 @@
 	uint32_t                  const gametime = game.get_gametime();
 	Widelands::Player       &       player   = iplayer().player();
 	Widelands::Player_Number  const plnum    = player.player_number();
+	bool work_done = false;
 
 	switch (mode) {
 	case Inbox:
+		//archive selected messages
 		for
 			(wl_index_range<uint8_t> i(0, list->size());
 			 i;
 			 ++i)
 			if (list->get_record(i.current).is_checked(ColSelect))
+			{
+				work_done = true;
 				game.send_player_command
 					(*new Widelands::Cmd_MessageSetStatusArchived
 					 	(gametime, plnum, Message_Id((*list)[i.current])));
+			}
+
+		//archive highlighted message, if nothing was selected
+		if (!work_done) {
+			if (!list->has_selection()) return;
+
+			game.send_player_command
+				(*new Widelands::Cmd_MessageSetStatusArchived
+					(gametime, plnum, Message_Id(list->get_selected())));
+		}
 		break;
 	case Archive:
+		//restore selected messages
 		for
 			(wl_index_range<uint8_t> i(0, list->size());
 			 i;
 			 ++i)
 			if (list->get_record(i.current).is_checked(ColSelect))
+			{
+				work_done = true;
 				game.send_player_command
 					(*new Widelands::Cmd_MessageSetStatusRead
 					 	(gametime, plnum, Message_Id((*list)[i.current])));
+			}
+
+		//restore highlighted message, if nothing was selected
+		if (!work_done) {
+			if (!list->has_selection()) return;
+
+			game.send_player_command
+				(*new Widelands::Cmd_MessageSetStatusRead
+					(gametime, plnum, Message_Id(list->get_selected())));
+		}
 		break;
 	}
 }

=== modified file 'src/wui/game_message_menu.h'
--- src/wui/game_message_menu.h	2011-11-30 21:38:37 +0000
+++ src/wui/game_message_menu.h	2012-01-18 19:59:33 +0000
@@ -55,10 +55,10 @@
 	enum Cols {ColSelect, ColStatus, ColTitle, ColTimeSent};
 
 	Interactive_Player & iplayer() const;
-	void                 selected(uint32_t);
+	void selected(uint32_t);
+	void double_clicked(uint32_t);
 
 	bool status_compare(uint32_t a, uint32_t b);
-	void do_delete();
 	void do_clear_selection();
 	void do_invert_selection();
 	void archive_or_restore();