Merge lp:~widelands-dev/widelands/bug-1827182-sort-client-list into lp:widelands

Proposed by Toni Förster
Status: Merged
Merged at revision: 9097
Proposed branch: lp:~widelands-dev/widelands/bug-1827182-sort-client-list
Merge into: lp:widelands
Diff against target: 186 lines (+42/-16)
6 files modified
src/network/internet_gaming.cc (+10/-11)
src/ui_basic/panel.h (+1/-2)
src/ui_fsmenu/internet_lobby.cc (+12/-3)
src/ui_fsmenu/launch_mpg.cc (+6/-0)
src/wui/game_chat_panel.cc (+12/-0)
src/wui/game_chat_panel.h (+1/-0)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1827182-sort-client-list
Reviewer Review Type Date Requested Status
GunChleoc Approve
Review via email: mp+366843@code.launchpad.net

Commit message

sort the lobby client list by client type admin->irc

The admin users will be on top of the list, followed by registered
and unregistered. IRC user are at the bottom as they are already.

IRC user's join/part messages will also be displayed

Set focus to chat input in lobby & mp by default.

Clicking on the chatbox gives focus to input field. Clicking on any
other UI element removes focus.

To post a comment you must log in.
Revision history for this message
Toni Förster (stonerl) wrote :

I do need some help here. This is good as it is now, but I'd like to sort the irc/superuser/registered list alphabetically before inserting them into clientlist_. Can some tell me how to do this.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Define a compare functions for the table column in the UI, using the set_column_compare function. See campaign_select.cc for an example.

Then you will only need 1 vector for the clients without copying anything.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 4854. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/527360011.
Appveyor build 4635. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1827182_sort_client_list-4635.

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

I found a way to sort clientlist_ alphabetically.

But how do I tell the clientsonline_list_ in internet_lobby.cc that it should sort by client type as default. Currently, it just takes the list and I have to manually click on the "*"-header to sort it.

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

okay found it :D

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

Addressed your review, and one diff comment.

Revision history for this message
GunChleoc (gunchleoc) wrote :

LGTM :)

This branch can go in once codecheck has been fixed. If you don't want to trigger a compile for this, you can use

cmake/codecheck/CodeCheck.py src/* | grep -v "src/third_party"

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

Done. :)

Revision history for this message
GunChleoc (gunchleoc) wrote :

@bunnybot merge

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 4866. State: errored. Details: https://travis-ci.org/widelands/widelands/builds/527644741.
Appveyor build 4647. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1827182_sort_client_list-4647.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Refusing to merge, since Travis is not green. Use @bunnybot merge force for merging anyways.

Travis build 4866. State: errored. Details: https://travis-ci.org/widelands/widelands/builds/527644741.

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

Sorry I turned this into a lobby/chat cleanup merge request. Gun would you be so kind and have another look, please?

Revision history for this message
GunChleoc (gunchleoc) wrote :

I an crash this.

1. Host a new LAN game
2. Type something
3. Click on the icon next to your username

widelands: ../src/ui_basic/panel.h:267: bool UI::Panel::has_focus() const: Assertion `get_can_focus()' failed.

Thread 1 "widelands" received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
51 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) backtrace
#0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#1 0x00007ffff434c801 in __GI_abort () at abort.c:79
#2 0x00007ffff433c39a in __assert_fail_base (fmt=0x7ffff44c37d8 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0x5555576043e0 "get_can_focus()",
    file=file@entry=0x5555576043a0 "../src/ui_basic/panel.h", line=line@entry=267,
    function=function@entry=0x55555760cd20 <UI::Panel::has_focus() const::__PRETTY_FUNCTION__> "bool UI::Panel::has_focus() const") at assert.c:92
#3 0x00007ffff433c412 in __GI___assert_fail (assertion=0x5555576043e0 "get_can_focus()", file=0x5555576043a0 "../src/ui_basic/panel.h", line=267,
    function=0x55555760cd20 <UI::Panel::has_focus() const::__PRETTY_FUNCTION__> "bool UI::Panel::has_focus() const") at assert.c:101
#4 0x0000555556af02c4 in UI::Panel::has_focus (this=0x61a00023e590) at ../src/ui_basic/panel.h:267
#5 0x0000555556afc1d0 in UI::EditBox::draw (this=0x61a00023e590, dst=...) at ../src/ui_basic/editbox.cc:364
#6 0x0000555556b2e32d in UI::Panel::do_draw_inner (this=0x61a00023e590, dst=...) at ../src/ui_basic/panel.cc:755
#7 0x0000555556b2ea07 in UI::Panel::do_draw (this=0x61a00023e590, dst=...) at ../src/ui_basic/panel.cc:788
#8 0x0000555556b2e378 in UI::Panel::do_draw_inner (this=0x61a00023e280, dst=...) at ../src/ui_basic/panel.cc:759
#9 0x0000555556b2ea07 in UI::Panel::do_draw (this=0x61a00023e280, dst=...) at ../src/ui_basic/panel.cc:788
#10 0x0000555556b2e378 in UI::Panel::do_draw_inner (this=0x7fffffff5af0, dst=...) at ../src/ui_basic/panel.cc:759
#11 0x0000555556b2ea07 in UI::Panel::do_draw (this=0x7fffffff5af0, dst=...) at ../src/ui_basic/panel.cc:788
#12 0x0000555556b2a015 in UI::Panel::do_run (this=0x7fffffff5af0) at ../src/ui_basic/panel.cc:195
#13 0x00005555563898fe in UI::Panel::run<FullscreenMenuBase::MenuTarget> (this=0x7fffffff5af0) at ../src/ui_basic/panel.h:104
#14 0x0000555556a057ad in GameHost::run (this=0x7fffffff7470) at ../src/network/gamehost.cc:608
#15 0x0000555556376289 in WLApplication::mainmenu_multiplayer (this=0x611000000180) at ../src/wlapplication.cc:1275
#16 0x0000555556374a40 in WLApplication::mainmenu (this=0x611000000180) at ../src/wlapplication.cc:1113
#17 0x000055555636ba12 in WLApplication::run (this=0x611000000180) at ../src/wlapplication.cc:466
#18 0x00005555563677af in main (argc=1, argv=0x7fffffffde88) at ../src/main.cc:44

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

Hmm, you mean the icon in the client list, where you can choose your colour? Tried this, but I'm unable to crash it...

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

Okay it only crashes in when compiled in debug mode. Release builds don't crash. Weird.

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

Thats the way how Asserts work ... only in debug bilds.
I dont have that much time today, Ill try to throw it at the debugger.

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

Is this assert even correct? When calling has_focus() I expect either true or false. And it crashes here because it receives a false as answer but expects a true, which doesn't make much sense to me.

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

I'm pretty sure this assert is wrong here. Removed it in r9101.

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

Mhh, that assert looks valid fro me. Question is why this particular inputfield
does not have the corresponding flag set?

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

If you have any idea let me know. I'm running out of ideas.

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

I think this is a better fix:

 bool has_focus() const {
  return (get_can_focus() && parent_->focus_ == this);
 }

That can_ / has_focus handling is a bit different then I had expected, well

Works find for me now

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

Can you push your fix directly to this branch? Thanks allot.

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

Done

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

Some regression tais fail, but I dont think they are related:

./regression_test.py -b ./widelands

FAIL: test/maps/ship_transportation.wmf/scripting/test_rip_ship_before_picking_up_transporting_ware.lua

FAIL: test/maps/ship_transportation.wmf/scripting/test_rip_portdock_with_worker_and_ware_in_transit.lua

FAIL: test/maps/ship_transportation.wmf/scripting/test_rip_ports_with_worker_in_transit.lua

Ran 44 tests in 1493.063s

FAILED (failures=3)

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

> Some regression tais fail, but I dont think they are related:
>

Neither do I. Lets wait for travis.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Tested and working :)

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

Continuous integration builds have changed state:

Travis build 4895. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/528399156.
Appveyor build 4676. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1827182_sort_client_list-4676.

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

well :)

@bunnybot merge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/network/internet_gaming.cc'
--- src/network/internet_gaming.cc 2019-05-01 20:17:37 +0000
+++ src/network/internet_gaming.cc 2019-05-05 12:59:18 +0000
@@ -19,6 +19,7 @@
1919
20#include "network/internet_gaming.h"20#include "network/internet_gaming.h"
2121
22#include <algorithm>
22#include <memory>23#include <memory>
23#include <thread>24#include <thread>
2425
@@ -527,8 +528,7 @@
527 // Client received the new list of clients528 // Client received the new list of clients
528 uint8_t number = boost::lexical_cast<int>(packet.string()) & 0xff;529 uint8_t number = boost::lexical_cast<int>(packet.string()) & 0xff;
529 std::vector<InternetClient> old = clientlist_;530 std::vector<InternetClient> old = clientlist_;
530 // Push IRC users to a second list and add them to the back531 // Push admins/registred/IRC users to a temporary list and add them back later
531 std::vector<InternetClient> irc;
532 clientlist_.clear();532 clientlist_.clear();
533 log("InternetGaming: Received a client list update with %u items.\n", number);533 log("InternetGaming: Received a client list update with %u items.\n", number);
534 InternetClient inc;534 InternetClient inc;
@@ -537,12 +537,7 @@
537 inc.build_id = packet.string();537 inc.build_id = packet.string();
538 inc.game = packet.string();538 inc.game = packet.string();
539 inc.type = packet.string();539 inc.type = packet.string();
540 if (inc.type == INTERNET_CLIENT_IRC) {540
541 irc.push_back(inc);
542 // No "join" or "left" messages for IRC users
543 continue;
544 }
545 // No IRC client
546 clientlist_.push_back(inc);541 clientlist_.push_back(inc);
547542
548 bool found =543 bool found =
@@ -554,14 +549,18 @@
554 break;549 break;
555 }550 }
556 }551 }
557 if (!found)552 if (!found) {
558 format_and_add_chat(553 format_and_add_chat(
559 "", "", true, (boost::format(_("%s joined the lobby")) % inc.name).str());554 "", "", true, (boost::format(_("%s joined the lobby")) % inc.name).str());
555 }
560 }556 }
561 clientlist_.insert(clientlist_.end(), irc.begin(), irc.end());557
558 std::sort(clientlist_.begin(), clientlist_.end(),
559 [](const InternetClient &left, const InternetClient &right)
560 {return (left.name < right.name);});
562561
563 for (InternetClient& client : old) {562 for (InternetClient& client : old) {
564 if (client.name.size() && client.type != INTERNET_CLIENT_IRC) {563 if (client.name.size()) {
565 format_and_add_chat(564 format_and_add_chat(
566 "", "", true, (boost::format(_("%s left the lobby")) % client.name).str());565 "", "", true, (boost::format(_("%s left the lobby")) % client.name).str());
567 }566 }
568567
=== modified file 'src/ui_basic/panel.h'
--- src/ui_basic/panel.h 2019-03-17 11:44:04 +0000
+++ src/ui_basic/panel.h 2019-05-05 12:59:18 +0000
@@ -264,8 +264,7 @@
264 return flags_ & pf_can_focus;264 return flags_ & pf_can_focus;
265 }265 }
266 bool has_focus() const {266 bool has_focus() const {
267 assert(get_can_focus());267 return (get_can_focus() && parent_->focus_ == this);
268 return (parent_->focus_ == this);
269 }268 }
270 virtual void focus(bool topcaller = true);269 virtual void focus(bool topcaller = true);
271270
272271
=== modified file 'src/ui_fsmenu/internet_lobby.cc'
--- src/ui_fsmenu/internet_lobby.cc 2019-04-24 06:01:37 +0000
+++ src/ui_fsmenu/internet_lobby.cc 2019-05-05 12:59:18 +0000
@@ -39,9 +39,9 @@
39namespace {39namespace {
4040
41// Constants for convert_clienttype() / compare_clienttype()41// Constants for convert_clienttype() / compare_clienttype()
42const uint8_t kClientUnregistered = 0;42const uint8_t kClientSuperuser = 0;
43const uint8_t kClientRegistered = 1;43const uint8_t kClientRegistered = 1;
44const uint8_t kClientSuperuser = 2;44const uint8_t kClientUnregistered = 2;
45// 3 was INTERNET_CLIENT_BOT which is not used45// 3 was INTERNET_CLIENT_BOT which is not used
46const uint8_t kClientIRC = 4;46const uint8_t kClientIRC = 4;
47} // namespace47} // namespace
@@ -162,6 +162,9 @@
162 // try to connect to the metaserver162 // try to connect to the metaserver
163 if (!InternetGaming::ref().error() && !InternetGaming::ref().logged_in())163 if (!InternetGaming::ref().error() && !InternetGaming::ref().logged_in())
164 connect_to_metaserver();164 connect_to_metaserver();
165
166 // set focus to chat input
167 chat.focus_edit();
165}168}
166169
167void FullscreenMenuInternetLobby::layout() {170void FullscreenMenuInternetLobby::layout() {
@@ -191,6 +194,10 @@
191 if (InternetGaming::ref().update_for_games()) {194 if (InternetGaming::ref().update_for_games()) {
192 fill_games_list(InternetGaming::ref().games());195 fill_games_list(InternetGaming::ref().games());
193 }196 }
197 // unfocus chat window when other UI element has focus
198 if (!chat.has_focus()) {
199 chat.unfocus_edit();
200 }
194}201}
195202
196void FullscreenMenuInternetLobby::clicked_ok() {203void FullscreenMenuInternetLobby::clicked_ok() {
@@ -302,6 +309,7 @@
302 }309 }
303 prev_clientlist_len_ = clients->size();310 prev_clientlist_len_ = clients->size();
304 }311 }
312 clientsonline_list_.sort();
305}313}
306314
307/// called when an entry of the client list was doubleclicked315/// called when an entry of the client list was doubleclicked
@@ -324,12 +332,13 @@
324332
325 temp += text;333 temp += text;
326 chat.set_edit_text(temp);334 chat.set_edit_text(temp);
327 chat.focus();335 chat.focus_edit();
328 }336 }
329}337}
330338
331/// called when an entry of the server list was selected339/// called when an entry of the server list was selected
332void FullscreenMenuInternetLobby::server_selected() {340void FullscreenMenuInternetLobby::server_selected() {
341 // remove focus from chat
333 if (opengames_list_.has_selection()) {342 if (opengames_list_.has_selection()) {
334 const InternetGame* game = &opengames_list_.get_selected();343 const InternetGame* game = &opengames_list_.get_selected();
335 if (game->connectable)344 if (game->connectable)
336345
=== modified file 'src/ui_fsmenu/launch_mpg.cc'
--- src/ui_fsmenu/launch_mpg.cc 2019-04-26 11:33:10 +0000
+++ src/ui_fsmenu/launch_mpg.cc 2019-05-05 12:59:18 +0000
@@ -228,6 +228,7 @@
228 delete chat_;228 delete chat_;
229 chat_ = new GameChatPanel(this, get_w() * 3 / 80, get_h() * 17 / 30 + 0.5 * label_height_,229 chat_ = new GameChatPanel(this, get_w() * 3 / 80, get_h() * 17 / 30 + 0.5 * label_height_,
230 get_w() * 53 / 80, get_h() * 11 / 30, chat, UI::PanelStyle::kFsMenu);230 get_w() * 53 / 80, get_h() * 11 / 30, chat, UI::PanelStyle::kFsMenu);
231 chat_->focus_edit();
231}232}
232233
233/**234/**
@@ -372,6 +373,11 @@
372 ctrl_->think();373 ctrl_->think();
373 }374 }
374 refresh();375 refresh();
376
377 // unfocus chat window when other UI element has focus
378 if (!chat_->has_focus()) {
379 chat_->unfocus_edit();
380 }
375}381}
376382
377/**383/**
378384
=== modified file 'src/wui/game_chat_panel.cc'
--- src/wui/game_chat_panel.cc 2019-04-24 06:01:37 +0000
+++ src/wui/game_chat_panel.cc 2019-05-05 12:59:18 +0000
@@ -119,3 +119,15 @@
119 editbox.set_text("");119 editbox.set_text("");
120 aborted();120 aborted();
121}121}
122
123/**
124 * The mouse was clicked on this chatbox
125 */
126bool GameChatPanel::handle_mousepress(const uint8_t btn, int32_t, int32_t) {
127 if (btn == SDL_BUTTON_LEFT && get_can_focus()) {
128 focus_edit();
129 return true;
130 }
131
132 return false;
133}
122134
=== modified file 'src/wui/game_chat_panel.h'
--- src/wui/game_chat_panel.h 2019-03-17 11:44:04 +0000
+++ src/wui/game_chat_panel.h 2019-05-05 12:59:18 +0000
@@ -54,6 +54,7 @@
54 editbox.set_text(text);54 editbox.set_text(text);
55 }55 }
5656
57 bool handle_mousepress(uint8_t btn, int32_t x, int32_t y) override;
57 void focus_edit();58 void focus_edit();
58 void unfocus_edit();59 void unfocus_edit();
5960

Subscribers

People subscribed via source and target branches

to status/vote changes: