Index: binaries/data/mods/public/gui/session/menu.js =================================================================== --- binaries/data/mods/public/gui/session/menu.js +++ binaries/data/mods/public/gui/session/menu.js @@ -66,6 +66,23 @@ // Redefined every time someone makes a tribute (so we can save some data in a closure). Called in input.js handleInputBeforeGui. var g_FlushTributing = function() {}; +var g_MenuButtons = { + "menuButton": { "hotkey": "session.gui.menu.toggle", "description": "Toggle in-game menu." }, + "manualButton": { "description": "Show the game manual." }, + "saveGameButton": { "description": "Save the current game." }, + "summaryButton": { "hotkey": "summary", "description": "Show the summary dialog." }, + "lobbyButton": { "hotkey": "lobby", "description": "Show the multiplayer lobby in a dialog.", "enabled": () => Engine.HasXmppClient() }, + "chatButton": { "hotkey": [ + { "hotkey": "chat", "description": translate("Chat"), "showOnlyWhenUsed": true }, + { "hotkey": "teamchat", "description": translate("Team chat"), "showOnlyWhenUsed": true }, + { "hotkey": "privatechat", "description": translate("Private chat"), "showOnlyWhenUsed": true } + ] }, + "optionsButton": { "description": "Show the options dialog." }, + "pauseButton": { "hotkey": "pause", "description": "Toggle pause the game.", "enabled": () => !g_IsObserver || !g_IsNetworked || g_IsController }, + "menuResignButton": { "description": "Resign from the current game.", "enabled": () => !g_IsObserver }, + "menuExitButton": { "description": "Exit from the current game." } +}; + function initSessionMenuButtons() { initMenuPosition(); @@ -74,6 +91,34 @@ resizeTradeDialog(); } +function updateMenuButtons() +{ + let colorizedHotkey = name => { + let hotkey = Engine.ConfigDB_GetValue("user", "hotkey." + name); + return hotkey != "unused" && hotkey != "" ? coloredText("\\[" + hotkey + "]", g_HotkeyColor) : ""; + } + + let getTooltip = (hotkey, description) => + colorizedHotkey(hotkey) == "" ? translate(description) : description != "" ? sprintf(translate("%(hotkey)s: " + description), { + "hotkey": colorizedHotkey(hotkey) + }) : colorizedHotkey(hotkey); + + for (let name in g_MenuButtons) + { + let button = g_MenuButtons[name]; + let enabled = !button.enabled || button.enabled() + Engine.GetGUIObjectByName(name).enabled = enabled; + if ((!button.hotkey && !button.description) || !enabled) + continue; + if (button.hotkey && Array.isArray(button.hotkey)) + Engine.GetGUIObjectByName(name).tooltip = button.hotkey.map(tooltip => + tooltip.showOnlyWhenUsed !== undefined && colorizedHotkey(tooltip.hotkey) == "" ? "" : + getTooltip(tooltip.hotkey, tooltip.description)).join("\n"); + else if (!button.hotkey || typeof(button.hotkey) == 'string') + Engine.GetGUIObjectByName(name).tooltip = getTooltip(button.hotkey || "", button.description || ""); + } +} + function initMenuPosition() { Engine.GetGUIObjectByName("menu").size = "100%-164 " + MENU_TOP + " 100% " + MENU_BOTTOM; Index: binaries/data/mods/public/gui/session/menu.xml =================================================================== --- binaries/data/mods/public/gui/session/menu.xml +++ binaries/data/mods/public/gui/session/menu.xml @@ -62,7 +62,6 @@ hotkey="lobby" > Lobby - Show the multiplayer lobby in a dialog window. lobbyDialogButton(); Index: binaries/data/mods/public/gui/session/session.js =================================================================== --- binaries/data/mods/public/gui/session/session.js +++ binaries/data/mods/public/gui/session/session.js @@ -613,9 +613,7 @@ alphaLabel.hidden = isPlayer && !viewPlayer.hidden; alphaLabel.size = isPlayer ? "50%+44 0 100%-283 100%" : "155 0 85%-279 100%"; - Engine.GetGUIObjectByName("pauseButton").enabled = !g_IsObserver || !g_IsNetworked || g_IsController; - Engine.GetGUIObjectByName("menuResignButton").enabled = !g_IsObserver; - Engine.GetGUIObjectByName("lobbyButton").enabled = Engine.HasXmppClient(); + updateMenuButtons(); } function reportPerformance(time)