widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #17031
[Merge] lp:~widelands-dev/widelands/bug-1825932-open-games-clean-start into lp:widelands
Toni Förster has proposed merging lp:~widelands-dev/widelands/bug-1825932-open-games-clean-start into lp:widelands.
Commit message:
only display games for the same version and when they are open
* The list in the lobby has been renamed to "Open Games"
* only games a user can join will be listed
* when a game is running it gets removed from the list
* development builds are not displayed for normal builds
* no message is posted to the chat when the game can't be joined
* when host name is already taken show tooltip and draw red border
Requested reviews:
Widelands Developers (widelands-dev)
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1825932-open-games-clean-start/+merge/367311
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1825932-open-games-clean-start into lp:widelands.
=== modified file 'src/network/internet_gaming.cc'
--- src/network/internet_gaming.cc 2019-05-11 18:50:30 +0000
+++ src/network/internet_gaming.cc 2019-05-11 22:15:19 +0000
@@ -487,7 +487,7 @@
InternetGame* ing = new InternetGame();
ing->name = packet.string();
ing->build_id = packet.string();
- ing->connectable = (packet.string() == INTERNET_GAME_SETUP);
+ ing->connectable = packet.string();
gamelist_.push_back(*ing);
bool found = false;
@@ -498,10 +498,13 @@
break;
}
}
- if (!found)
+ if (!found && ing->connectable != INTERNET_GAME_RUNNING &&
+ (ing->build_id == build_id() || (ing->build_id.compare(0, 6, "build-") != 0
+ && build_id().compare(0, 6, "build-") != 0))) {
format_and_add_chat(
- "", "", true,
- (boost::format(_("The game %s is now available")) % ing->name).str());
+ "", "", true,
+ (boost::format(_("The game %s is now available")) % ing->name).str());
+ }
delete ing;
ing = nullptr;
=== modified file 'src/network/internet_gaming.h'
--- src/network/internet_gaming.h 2019-05-11 18:50:30 +0000
+++ src/network/internet_gaming.h 2019-05-11 22:15:19 +0000
@@ -43,7 +43,7 @@
struct InternetGame {
std::string name;
std::string build_id;
- bool connectable;
+ std::string connectable;
};
/**
@@ -178,6 +178,11 @@
return true;
}
+ void format_and_add_chat(const std::string& from,
+ const std::string& to,
+ bool system,
+ const std::string& msg);
+
private:
InternetGaming();
@@ -202,11 +207,6 @@
bool str2bool(std::string);
std::string bool2str(bool);
- void format_and_add_chat(const std::string& from,
- const std::string& to,
- bool system,
- const std::string& msg);
-
/**
* Does the real work of the login.
* \param relogin Whether this is a relogin. Only difference is that
=== modified file 'src/ui_basic/editbox.cc'
--- src/ui_basic/editbox.cc 2019-05-11 18:50:30 +0000
+++ src/ui_basic/editbox.cc 2019-05-11 22:15:19 +0000
@@ -85,7 +85,8 @@
: Panel(parent, x, y, w, h > 0 ? h : text_height(font_size) + 2 * margin_y),
m_(new EditBoxImpl),
history_active_(false),
- history_position_(-1) {
+ history_position_(-1),
+ warning_(false) {
set_thinks(false);
m_->background_style = g_gr->styles().editbox_style(style);
@@ -346,7 +347,7 @@
draw_background(dst, *m_->background_style);
// Draw border.
- if (get_w() >= 2 && get_h() >= 2) {
+ if (get_w() >= 2 && get_h() >= 2 && !warning_) {
static const RGBColor black(0, 0, 0);
// bottom edge
@@ -359,6 +360,25 @@
// left edge
dst.fill_rect(Recti(0, 0, 1, get_h() - 1), black);
dst.fill_rect(Recti(1, 0, 1, get_h() - 2), black);
+
+ } else {
+ // Draw a red border for warnings.
+ static const RGBColor red(255, 22, 22);
+
+ // bottom edge
+ dst.fill_rect(Recti(0, get_h() - 2, get_w(), 2), red);
+ // right edge
+ dst.fill_rect(Recti(get_w() - 2, 0, 2, get_h() -2), red);
+ // top edge
+ dst.fill_rect(Recti(0, 0, get_w() - 1, 1), red);
+ dst.fill_rect(Recti(0, 1, get_w() - 2, 1), red);
+ dst.brighten_rect(Recti(0, 0, get_w() - 1, 1), BUTTON_EDGE_BRIGHT_FACTOR);
+ dst.brighten_rect(Recti(0, 1, get_w() - 2, 1), BUTTON_EDGE_BRIGHT_FACTOR);
+ // left edge
+ dst.fill_rect(Recti(0, 0, 1, get_h() - 1), red);
+ dst.fill_rect(Recti(1, 0, 1, get_h() - 2), red);
+ dst.brighten_rect(Recti(0, 0, 1, get_h() - 1), BUTTON_EDGE_BRIGHT_FACTOR);
+ dst.brighten_rect(Recti(1, 0, 1, get_h() - 2), BUTTON_EDGE_BRIGHT_FACTOR);
}
if (has_focus()) {
=== modified file 'src/ui_basic/editbox.h'
--- src/ui_basic/editbox.h 2019-05-11 18:50:30 +0000
+++ src/ui_basic/editbox.h 2019-05-11 22:15:19 +0000
@@ -72,6 +72,10 @@
void draw(RenderTarget&) override;
+ void set_warning(bool warn) {
+ warning_ = warn;
+ }
+
private:
std::unique_ptr<EditBoxImpl> m_;
@@ -80,6 +84,7 @@
bool history_active_;
int16_t history_position_;
std::string history_[CHAT_HISTORY_SIZE];
+ bool warning_;
};
} // namespace UI
=== modified file 'src/ui_fsmenu/internet_lobby.cc'
--- src/ui_fsmenu/internet_lobby.cc 2019-05-11 18:50:30 +0000
+++ src/ui_fsmenu/internet_lobby.cc 2019-05-11 22:15:19 +0000
@@ -63,7 +63,7 @@
// Text labels
title(this, get_w() / 2, get_h() / 20, _("Metaserver Lobby"), UI::Align::kCenter),
clients_(this, get_w() * 4 / 125, get_h() * 15 / 100, _("Clients online:")),
- opengames_(this, get_w() * 17 / 25, get_h() * 15 / 100, _("List of games:")),
+ opengames_(this, get_w() * 17 / 25, get_h() * 15 / 100, _("Open Games:")),
servername_(this, get_w() * 17 / 25, get_h() * 63 / 100, _("Name of your server:")),
// Buttons
@@ -198,6 +198,9 @@
if (!chat.has_focus()) {
chat.unfocus_edit();
}
+ if (edit_servername_.has_focus()) {
+ change_servername();
+ }
}
void FullscreenMenuInternetLobby::clicked_ok() {
@@ -225,26 +228,22 @@
hostgame_.set_enabled(true);
joingame_.set_enabled(false);
std::string localservername = edit_servername_.text();
+ std::string localbuildid = build_id();
if (games != nullptr) { // If no communication error occurred, fill the list.
for (const InternetGame& game : *games) {
const Image* pic;
- if (game.connectable) {
- if (game.build_id == build_id())
- pic = g_gr->images().get("images/ui_basic/continue.png");
- else {
+ if (game.connectable == INTERNET_GAME_SETUP && game.build_id == localbuildid) {
+ // only clients with the same build number are displayed
+ pic = g_gr->images().get("images/ui_basic/continue.png");
+ opengames_list_.add(game.name, game, pic, false, game.build_id);
+ } else if (game.connectable == INTERNET_GAME_SETUP &&
+ game.build_id.compare(0, 6, "build-") != 0 &&
+ localbuildid.compare(0, 6, "build-") != 0) {
+ // only development clients are allowed to see games openend by such
pic = g_gr->images().get("images/ui_basic/different.png");
- }
- } else {
- pic = g_gr->images().get("images/ui_basic/stop.png");
- }
- // If one of the servers has the same name as the local name of the
- // clients server, we disable the 'hostgame' button to avoid having more
- // than one server with the same name.
- if (game.name == localservername) {
- hostgame_.set_enabled(false);
- }
- opengames_list_.add(game.name, game, pic, false, game.build_id);
+ opengames_list_.add(game.name, game, pic, false, game.build_id);
+ }
}
}
}
@@ -341,10 +340,8 @@
// remove focus from chat
if (opengames_list_.has_selection()) {
const InternetGame* game = &opengames_list_.get_selected();
- if (game->connectable)
+ if (game->connectable == INTERNET_GAME_SETUP)
joingame_.set_enabled(true);
- else
- joingame_.set_enabled(false);
}
}
@@ -353,7 +350,7 @@
// if the game is open try to connect it, if not do nothing.
if (opengames_list_.has_selection()) {
const InternetGame* game = &opengames_list_.get_selected();
- if (game->connectable)
+ if (game->connectable == INTERNET_GAME_SETUP)
clicked_joingame();
}
}
@@ -362,7 +359,8 @@
void FullscreenMenuInternetLobby::change_servername() {
// Allow client to enter a servername manually
hostgame_.set_enabled(true);
-
+ edit_servername_.set_tooltip("");
+ edit_servername_.set_warning(false);
// Check whether a server of that name is already open.
// And disable 'hostgame' button if yes.
const std::vector<InternetGame>* games = InternetGaming::ref().games();
@@ -370,6 +368,11 @@
for (const InternetGame& game : *games) {
if (game.name == edit_servername_.text()) {
hostgame_.set_enabled(false);
+ edit_servername_.set_warning(true);
+ edit_servername_.set_tooltip((boost::format
+ (_("The game %s is already running. Please choose a different name."))
+ % (boost::format("%s%s%s%s%s") %"<font bold=1 color="
+ % UI_FONT_CLR_WARNING.hex_value() % ">" % game.name % "</font>")).str());
}
}
}
@@ -415,10 +418,22 @@
// Save selected servername as default for next time and during that take care that the name is
// not empty.
std::string servername_ui = edit_servername_.text();
- if (servername_ui.empty()) {
- /** TRANSLATORS: This is shown for multiplayer games when no host */
- /** TRANSLATORS: server to connect to has been specified yet. */
- servername_ui = pgettext("server_name", "unnamed");
+
+ const std::vector<InternetGame>* games = InternetGaming::ref().games();
+ if (games != nullptr) {
+ for (const InternetGame& game : *games) {
+ if (servername_ui.empty()) {
+ uint32_t i = 1;
+ do {
+ /** TRANSLATORS: This is shown for multiplayer games when no host */
+ /** TRANSLATORS: server to connect to has been specified yet. */
+ servername_ui = (boost::format(_("unnamed %u")) % i++).str();
+ } while (servername_ui == game.name);
+ } else if (game.name == servername_ui) {
+ change_servername();
+ return;
+ }
+ }
}
g_options.pull_section("global").set_string("servername", servername_ui);
References