From 2cccd9825d2a57135bb0db8b1536d15f18b0bd2f Mon Sep 17 00:00:00 2001 From: elexis Date: Thu, 21 Nov 2019 13:44:41 +0000 Subject: [PATCH] Rewrite lobby page to use class semantics, add more gamedetails labels, improve performance using batch processing and caching and gain possibility for game creation/player-join/leave events, refs #5387. Game selection details features: * Display victory conditions following their sending but missing display following bffe917914, refs 7b0f6f530c. * Display the host of the match and the game name in the selected game details following 61261d14fc, refs D1666. * Display mods if the mods differ (without having to attempt to join the game prior) following eca956a513. Performance features: * Implement batch message processing in the XmppClient to rebuild GUI objects only once when receiving backlog or returning from a match. * Implement Game class to cache gamelist, filter and sorting values, as they rarely change but are accessed often. * Cache sprintf objects. Security fixes: * Add escapeText in lobby/ to avoid players breaking the lobby for every participant, supersedes D720, comments by bb. * Do not hide broadcasted unrecognized chat commands that mods used as leaking private channels, fixes #5615. Defect fixes: * Fix XmppClient.cpp storing unused historic message types resulting in memory waste and unintentional replay of for instance disconnect/announcements messages following both e8dfde9ba6/D819 and 6bf74902a7/D2265, refs #3306. * Fix XmppClient.cpp victoryCondition -> victoryConditions gamesetup.js change from 6d54ab4c1f/D1240. * Fix leaderboard/profile page cancel hotkey closing the lobby dialog as well and removes cancel hotkey note from lobby_panels.xml from 960f2d7c31/D817 since the described issue was fixed by f9b529f2fb/D1701. * Fix lobby playing menu sound in a running game after having closed the lobby dialog following introduction in 960f2d7c31/D817. * Fix GUI on nick change by updating g_Username. * Update profile panel only with data matching the player requested. Hack erasure: * Object semantics make it cheap to add state and cache values, storing literals in properties while removing globals, adding events while decoupling components and gaining moddability. * Erase comments and translation comments stating that this would be IRC!!, supersedes D1136. * Introduce Status chat message type to supersede "/special" chat command + "isSpecial" property from bffe917914 (formerly g_specialKey e6840f5fca) deluxe hack. * Introduce System chat message type to supersede system errors disguising as chat from a mock user called "system". Code cleanups: * Move code from XML to JS. * Move size values from JS to XML, especially following 960f2d7c31/D817 and 7752219cef/D1051. * Rename "user" to "player". * Fix lobby/ eslint warnings, refs D2261. * Remove message.nick emptiness check from 0940db3fc0/D835, since XEP-0045 dictates that it is non-empty. * Add translated string for deleted subjects. * Add TODOs for some evident COList issues, refs #5638. Differential Revision: https://code.wildfiregames.com/D2412 This was SVN commit r23172. --- .../lobby/LeaderboardPage/LeaderboardList.js | 64 + .../lobby/LeaderboardPage/LeaderboardPage.js | 52 + .../lobby/LeaderboardPage/LeaderboardPage.xml | 33 + binaries/data/mods/public/gui/lobby/Lobby.js | 25 + .../lobby/LobbyPage/AnnouncementHandler.js | 20 + .../lobby/LobbyPage/Buttons/BuddyButton.js | 70 + .../gui/lobby/LobbyPage/Buttons/HostButton.js | 32 + .../gui/lobby/LobbyPage/Buttons/JoinButton.js | 130 ++ .../LobbyPage/Buttons/LeaderboardButton.js | 22 + .../lobby/LobbyPage/Buttons/ProfileButton.js | 22 + .../gui/lobby/LobbyPage/Buttons/QuitButton.js | 40 + .../LobbyPage/Chat/ChatCommandHandler.js | 166 ++ .../lobby/LobbyPage/Chat/ChatInputPanel.js | 52 + .../Chat/ChatMessages/ChatMessageEvents.js | 26 + .../Chat/ChatMessages/ChatMessageFormat.js | 69 + .../Chat/ChatMessages/ChatMessageFormatMe.js | 31 + .../Chat/ChatMessages/ChatMessageFormatSay.js | 38 + .../ChatMessages/ChatMessagePrivateWrapper.js | 32 + .../lobby/LobbyPage/Chat/ChatMessagesPanel.js | 52 + .../gui/lobby/LobbyPage/Chat/ChatPanel.js | 26 + .../gui/lobby/LobbyPage/Chat/ChatPanel.xml | 8 + .../StatusMessages/StatusMessageEvents.js | 153 ++ .../StatusMessages/StatusMessageFormat.js | 29 + .../SystemMessages/SystemMessageEvents.js | 56 + .../SystemMessages/SystemMessageFormat.js | 36 + .../lobby/LobbyPage/Chat/TimestampWrapper.js | 33 + .../gui/lobby/LobbyPage/ConnectionHandler.js | 74 + .../mods/public/gui/lobby/LobbyPage/Game.js | 338 ++++ .../public/gui/lobby/LobbyPage/GameDetails.js | 141 ++ .../gui/lobby/LobbyPage/GameDetails.xml | 25 + .../public/gui/lobby/LobbyPage/GameList.js | 221 +++ .../public/gui/lobby/LobbyPage/GameList.xml | 29 + .../gui/lobby/LobbyPage/GameListFilters.xml | 37 + .../LobbyPage/GameListFilters/MapSize.js | 25 + .../LobbyPage/GameListFilters/MapType.js | 25 + .../LobbyPage/GameListFilters/OpenGame.js | 24 + .../LobbyPage/GameListFilters/PlayerCount.js | 26 + .../lobby/LobbyPage/GameListFilters/Rating.js | 75 + .../public/gui/lobby/LobbyPage/KickStrings.js | 49 + .../public/gui/lobby/LobbyPage/LobbyPage.js | 73 + .../public/gui/lobby/LobbyPage/LobbyPage.xml | 55 + .../public/gui/lobby/LobbyPage/PlayerColor.js | 53 + .../public/gui/lobby/LobbyPage/PlayerList.js | 207 +++ .../public/gui/lobby/LobbyPage/PlayerList.xml | 20 + .../gui/lobby/LobbyPage/ProfilePanel.js | 125 ++ .../gui/lobby/LobbyPage/ProfilePanel.xml | 32 + .../public/gui/lobby/LobbyPage/Subject.js | 45 + .../public/gui/lobby/LobbyPage/Subject.xml | 11 + .../gui/lobby/ProfilePage/ProfilePage.js | 84 + .../gui/lobby/ProfilePage/ProfilePage.xml | 63 + .../mods/public/gui/lobby/XmppMessages.js | 115 ++ binaries/data/mods/public/gui/lobby/lobby.js | 1578 +---------------- binaries/data/mods/public/gui/lobby/lobby.xml | 22 +- .../mods/public/gui/lobby/lobby_panels.xml | 366 ---- binaries/data/mods/public/gui/page_lobby.xml | 4 +- .../gui/prelobby/common/feedback/feedback.js | 17 +- source/lobby/IXmppClient.h | 3 +- source/lobby/XmppClient.cpp | 81 +- source/lobby/XmppClient.h | 3 +- source/lobby/scripting/JSInterface_Lobby.cpp | 15 +- source/lobby/scripting/JSInterface_Lobby.h | 3 +- 61 files changed, 3407 insertions(+), 1974 deletions(-) create mode 100644 binaries/data/mods/public/gui/lobby/LeaderboardPage/LeaderboardList.js create mode 100644 binaries/data/mods/public/gui/lobby/LeaderboardPage/LeaderboardPage.js create mode 100644 binaries/data/mods/public/gui/lobby/LeaderboardPage/LeaderboardPage.xml create mode 100644 binaries/data/mods/public/gui/lobby/Lobby.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/AnnouncementHandler.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/Buttons/BuddyButton.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/Buttons/HostButton.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/Buttons/JoinButton.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/Buttons/LeaderboardButton.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/Buttons/ProfileButton.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/Buttons/QuitButton.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/Chat/ChatCommandHandler.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/Chat/ChatInputPanel.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/Chat/ChatMessages/ChatMessageEvents.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/Chat/ChatMessages/ChatMessageFormat.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/Chat/ChatMessages/ChatMessageFormatMe.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/Chat/ChatMessages/ChatMessageFormatSay.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/Chat/ChatMessages/ChatMessagePrivateWrapper.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/Chat/ChatMessagesPanel.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/Chat/ChatPanel.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/Chat/ChatPanel.xml create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/Chat/StatusMessages/StatusMessageEvents.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/Chat/StatusMessages/StatusMessageFormat.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/Chat/SystemMessages/SystemMessageEvents.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/Chat/SystemMessages/SystemMessageFormat.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/Chat/TimestampWrapper.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/ConnectionHandler.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/Game.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/GameDetails.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/GameDetails.xml create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/GameList.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/GameList.xml create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/GameListFilters.xml create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/GameListFilters/MapSize.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/GameListFilters/MapType.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/GameListFilters/OpenGame.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/GameListFilters/PlayerCount.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/GameListFilters/Rating.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/KickStrings.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/LobbyPage.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/LobbyPage.xml create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/PlayerColor.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/PlayerList.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/PlayerList.xml create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/ProfilePanel.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/ProfilePanel.xml create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/Subject.js create mode 100644 binaries/data/mods/public/gui/lobby/LobbyPage/Subject.xml create mode 100644 binaries/data/mods/public/gui/lobby/ProfilePage/ProfilePage.js create mode 100644 binaries/data/mods/public/gui/lobby/ProfilePage/ProfilePage.xml create mode 100644 binaries/data/mods/public/gui/lobby/XmppMessages.js delete mode 100644 binaries/data/mods/public/gui/lobby/lobby_panels.xml diff --git a/binaries/data/mods/public/gui/lobby/LeaderboardPage/LeaderboardList.js b/binaries/data/mods/public/gui/lobby/LeaderboardPage/LeaderboardList.js new file mode 100644 index 0000000000..ddc1804115 --- /dev/null +++ b/binaries/data/mods/public/gui/lobby/LeaderboardPage/LeaderboardList.js @@ -0,0 +1,64 @@ +/** + * This is class manages the content of the leaderboardlist, i.e. the list of highest rated players. + */ +class LeaderboardList +{ + constructor(xmppMessages) + { + this.selectionChangeHandlers = new Set(); + + this.leaderboardBox = Engine.GetGUIObjectByName("leaderboardBox"); + this.leaderboardBox.onSelectionChange = this.onSelectionChange.bind(this); + + let rebuild = this.rebuild.bind(this); + xmppMessages.registerXmppMessageHandler("game", "leaderboard", rebuild); + xmppMessages.registerXmppMessageHandler("system", "disconnected", rebuild); + + this.rebuild(); + } + + registerSelectionChangeHandler(handler) + { + this.selectionChangeHandlers.add(handler); + } + + onSelectionChange() + { + let playerName = this.selectedPlayer(); + for (let handler of this.selectionChangeHandlers) + handler(playerName); + } + + selectedPlayer() + { + return this.leaderboardBox.list[this.leaderboardBox.selected] || undefined; + } + + /** + * Update the leaderboard from data cached in C++. + */ + rebuild() + { + // TODO: Display placeholder if the data is not available + let boardList = Engine.GetBoardList().sort( + (a, b) => b.rating - a.rating); + + let list_name = []; + let list_rank = []; + let list_rating = []; + + boardList.forEach((entry, i) => { + list_name.push(escapeText(entry.name)); + list_rating.push(entry.rating); + list_rank.push(i + 1); + }); + + this.leaderboardBox.list_name = list_name; + this.leaderboardBox.list_rating = list_rating; + this.leaderboardBox.list_rank = list_rank; + this.leaderboardBox.list = list_name; + + if (this.leaderboardBox.selected >= this.leaderboardBox.list.length) + this.leaderboardBox.selected = -1; + } +} diff --git a/binaries/data/mods/public/gui/lobby/LeaderboardPage/LeaderboardPage.js b/binaries/data/mods/public/gui/lobby/LeaderboardPage/LeaderboardPage.js new file mode 100644 index 0000000000..95ccd93e4a --- /dev/null +++ b/binaries/data/mods/public/gui/lobby/LeaderboardPage/LeaderboardPage.js @@ -0,0 +1,52 @@ +/** + * The leaderboard page allows the player to view the highest rated players and update that list. + */ +class LeaderboardPage +{ + constructor(xmppMessages) + { + this.openPageHandlers = new Set(); + this.closePageHandlers = new Set(); + + this.leaderboardList = new LeaderboardList(xmppMessages); + + this.leaderboardPage = Engine.GetGUIObjectByName("leaderboardPage"); + + Engine.GetGUIObjectByName("leaderboardUpdateButton").onPress = this.onPressUpdate.bind(this); + Engine.GetGUIObjectByName("leaderboardPageBack").onPress = this.onPressClose.bind(this); + } + + registerOpenPageHandler(handler) + { + this.openPageHandlers.add(handler); + } + + registerClosePageHandler(handler) + { + this.closePageHandlers.add(handler); + } + + openPage() + { + this.leaderboardPage.hidden = false; + Engine.SetGlobalHotkey("cancel", this.onPressClose.bind(this)); + Engine.SendGetBoardList(); + + let playerName = this.leaderboardList.selectedPlayer(); + for (let handler of this.openPageHandlers) + handler(playerName); + } + + onPressUpdate() + { + Engine.SendGetBoardList(); + } + + onPressClose() + { + this.leaderboardPage.hidden = true; + + for (let handler of this.closePageHandlers) + handler(); + } +} diff --git a/binaries/data/mods/public/gui/lobby/LeaderboardPage/LeaderboardPage.xml b/binaries/data/mods/public/gui/lobby/LeaderboardPage/LeaderboardPage.xml new file mode 100644 index 0000000000..613ec15843 --- /dev/null +++ b/binaries/data/mods/public/gui/lobby/LeaderboardPage/LeaderboardPage.xml @@ -0,0 +1,33 @@ + +