From 22f5b00fce2df3f58ed0aab94ff12ddc69c7c5da Mon Sep 17 00:00:00 2001 From: elexis Date: Thu, 4 Feb 2016 17:14:46 +0000 Subject: [PATCH] Implement network-warnings, fixes #3264. Shows a notification if the local client or other players connections timeout or have bad latency. This was SVN commit r17730. --- binaries/data/config/default.cfg | 1 + .../gui/common/functions_global_object.js | 45 +++++++- .../data/mods/public/gui/common/global.xml | 18 +++ .../data/mods/public/gui/common/network.js | 104 +++++++++++++++++ .../mods/public/gui/gamesetup/gamesetup.js | 5 + .../mods/public/gui/gamesetup/gamesetup.xml | 1 + .../mods/public/gui/gamesetup/gamesetup_mp.js | 8 +- .../data/mods/public/gui/options/options.json | 6 + .../data/mods/public/gui/session/messages.js | 1 + .../data/mods/public/gui/session/session.js | 2 + source/gui/scripting/ScriptFunctions.cpp | 12 ++ source/network/NetClient.cpp | 108 +++++++++++++++++- source/network/NetClient.h | 12 +- source/network/NetMessage.cpp | 10 +- source/network/NetMessages.h | 19 ++- source/network/NetServer.cpp | 54 ++++++++- source/network/NetServer.h | 11 +- source/network/NetSession.cpp | 34 ++++++ source/network/NetSession.h | 27 ++++- source/network/NetTurnManager.cpp | 4 +- source/network/NetTurnManager.h | 5 +- 21 files changed, 468 insertions(+), 19 deletions(-) diff --git a/binaries/data/config/default.cfg b/binaries/data/config/default.cfg index cefb61b2e3..e1c48e7df4 100644 --- a/binaries/data/config/default.cfg +++ b/binaries/data/config/default.cfg @@ -352,6 +352,7 @@ enabledmods = "mod public" [overlay] fps = "false" ; Show frames per second in top right corner realtime = "false" ; Show current system time in top right corner +netwarnings = "true" ; Show warnings if the network connection is bad [profiler2] autoenable = false ; Enable HTTP server output at startup (default off for security/performance) diff --git a/binaries/data/mods/public/gui/common/functions_global_object.js b/binaries/data/mods/public/gui/common/functions_global_object.js index 428a756818..4fc6144a26 100644 --- a/binaries/data/mods/public/gui/common/functions_global_object.js +++ b/binaries/data/mods/public/gui/common/functions_global_object.js @@ -1,7 +1,6 @@ -/* - DESCRIPTION : Contains global GUI functions, which will later be accessible from every GUI script/file. - NOTES : So far, only the message box-related functions are implemented. -*/ +/** + * Contains global GUI functions accessible from every GUI script/file. + */ // ******************************************* // messageBox @@ -139,4 +138,42 @@ function updateCounters() var dataCounter = Engine.GetGUIObjectByName("dataCounter"); dataCounter.caption = caption; dataCounter.size = sprintf("100%%-100 40 100%%-5 %(bottom)s", { bottom: 40 + 14 * linesCount }); + dataCounter.hidden = linesCount == 0; +} + +/** + * Update the overlay with the most recent network warning of each client. + */ +function displayGamestateNotifications() +{ + let messages = []; + let maxTextWidth = 0; + + // TODO: Players who paused the game should be added here + + // Add network warnings + if (Engine.ConfigDB_GetValue("user", "overlay.netwarnings") == "true") + { + let netwarnings = getNetworkWarnings(); + messages = messages.concat(netwarnings.messages); + maxTextWidth = Math.max(maxTextWidth, netwarnings.maxTextWidth); + } + + // Resize textbox + let width = maxTextWidth + 20; + let height = 14 * messages.length; + + // Position left of the dataCounter + let top = "40"; + let right = Engine.GetGUIObjectByName("dataCounter").hidden ? "100%-15" : "100%-110"; + + let bottom = top + "+" + height; + let left = right + "-" + width; + + let gameStateNotifications = Engine.GetGUIObjectByName("gameStateNotifications"); + gameStateNotifications.caption = messages.join("\n"); + gameStateNotifications.hidden = !messages.length; + gameStateNotifications.size = left + " " + top + " " + right + " " + bottom; + + setTimeout(displayGamestateNotifications, 1000); } diff --git a/binaries/data/mods/public/gui/common/global.xml b/binaries/data/mods/public/gui/common/global.xml index 04fc871606..61632b4748 100644 --- a/binaries/data/mods/public/gui/common/global.xml +++ b/binaries/data/mods/public/gui/common/global.xml @@ -12,6 +12,24 @@ + + + +