Index: binaries/data/mods/public/gui/session/hotkeys/misc.xml =================================================================== --- binaries/data/mods/public/gui/session/hotkeys/misc.xml +++ binaries/data/mods/public/gui/session/hotkeys/misc.xml @@ -1,126 +0,0 @@ - - - - closeOpenDialogs(); - - - - openChat(); - - - - openChat(g_IsObserver ? "/observers" : "/allies"); - - - - openChat(g_LastChatAddressee); - - - - g_ShowGUI = !g_ShowGUI; - - - - toggleMenu(); - - - - toggleTrade(); - - - - toggleTutorial(); - - - - openGameSummary(); - - - - toggleConfigBool("silhouettes"); - - - - - var newSetting = !Engine.Renderer_GetShowSkyEnabled(); - Engine.Renderer_SetShowSkyEnabled(newSetting); - - - - - togglePause(); - - - - Engine.QuickSave(); - - - - Engine.QuickLoad(); - - - - performCommand(g_Selection.toList().map(ent => GetEntityState(ent)), "delete"); - - - - unloadAll(); - - - - stopUnits(g_Selection.toList()); - - - - backToWork(); - - - - updateSelectionDetails(); - updateSelectionDetails(); - - - - - updateSelectionDetails(); - updateBarterButtons(); - - - - updateSelectionDetails(); - updateBarterButtons(); - - - - - - findIdleUnit(g_MilitaryTypes); - - - - findIdleUnit(["!Domestic"]); - - - - clearSelection(); - - - - toggleRangeOverlay("Attack"); - - - - toggleRangeOverlay("Auras"); - - - - toggleRangeOverlay("Heal"); - - - - - g_ShowAllStatusBars = !g_ShowAllStatusBars; - recalculateStatusBarDisplay(); - - - Index: binaries/data/mods/public/gui/session/input.js =================================================================== --- binaries/data/mods/public/gui/session/input.js +++ binaries/data/mods/public/gui/session/input.js @@ -54,6 +54,45 @@ var doublePressTimer = 0; var prevHotkey = 0; +var g_Hotkeys = { + "session.backtowork": { "hotkeydown": () => backToWork() }, + "session.gui.tutorial.toggle": { "hotkeydown": () => toggleTutorial() }, + "silhouettes": { "hotkeydown": () => toggleConfigBool("silhouettes") }, + "session.stop": { "hotkeydown": () => stopUnits(g_Selection.toList()) }, + "quicksave": { "hotkeydown": () => Engine.QuickSave() }, + "quickload": { "hotkeydown": () => Engine.QuickLoad() }, + "session.kill": { "hotkeydown": () => performCommand(g_Selection.toList().map(ent => GetEntityState(ent)), "delete") }, + "session.unload": { "hotkeydown": () => unloadAll() }, + "session.batchtrain": { "hotkeydown": () => updateSelectionDetails(), "hotkeyup": () => updateSelectionDetails() }, + "session.massbarter": { "hotkeydown": () => { + updateSelectionDetails(); + updateBarterButtons(); + }, + "hotkeyup": () => { + updateSelectionDetails(); + updateBarterButtons(); + } }, + "cancel": { "hotkeydown": () => closeOpenDialogs() }, + "teamchat": { "hotkeydown": () => openChat(g_IsObserver ? "/observers" : "/allies") }, + "privatechat": { "hotkeydown": () => openChat(g_LastChatAddressee) }, + "session.gui.toggle": { "hotkeydown": () => g_ShowGUI = !g_ShowGUI }, + "showsky": { "hotkeydown": () => { + var newSetting = !Engine.Renderer_GetShowSkyEnabled(); + Engine.Renderer_SetShowSkyEnabled(newSetting); + } }, + // Find idle warrior - TODO: Potentially move this to own UI button? + "selection.idlewarrior": { "hotkeydown": () => findIdleUnit(g_MilitaryTypes) }, + "selection.idleunit": { "hotkeydown": () => findIdleUnit(["!Domestic"]) }, + "selection.cancel": { "hotkeydown": () => clearSelection() }, + "session.toggleattackrange": { "hotkeydown": () => toggleRangeOverlay("Attack") }, + "session.toggleaurasrange": { "hotkeydown": () => toggleRangeOverlay("Auras") }, + "session.togglehealrange": { "hotkeydown": () => toggleRangeOverlay("Heal") }, + "session.showstatusbars": { "hotkeydown": () => { + g_ShowAllStatusBars = !g_ShowAllStatusBars; + recalculateStatusBarDisplay(); + } } +}; + function updateCursorAndTooltip() { var cursorSet = false; @@ -787,6 +826,8 @@ g_ShowGuarded = (ev.type == "hotkeydown"); updateAdditionalHighlight(); } + else if (!!g_Hotkeys[ev.hotkey] && !!g_Hotkeys[ev.hotkey][ev.type]) + g_Hotkeys[ev.hotkey][ev.type](); if (inputState != INPUT_NORMAL && inputState != INPUT_SELECTING) clickedEntity = INVALID_ENTITY; 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,27 @@ // 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() {}; +/** + * Setting tooltips and hotkey descriptions for buttons plus enable or disable them. + */ +var g_GuiButtons = { + "menuButton": { "description": "Toggle the in-game menu." }, + "manualButton": { "description": "Show the game manual." }, + "saveGameButton": { "description": "Save the current game." }, + "summaryButton": { "description": "Show the summary dialog." }, + "lobbyButton": { "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": { "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." }, + "tradeButton1": { "description": "Barter & Trade" } +}; + function initSessionMenuButtons() { initMenuPosition(); @@ -74,6 +95,39 @@ resizeTradeDialog(); } +function updateMenuButtons() +{ + let colorizedHotkey = name => { + let hotkey = Engine.ConfigDB_GetValue("user", "hotkey." + name); + return !hotkey || hotkey == "unused" ? "" : setStringTags("\\[" + hotkey + "]", g_HotkeyTags); + } + + let getTooltip = (hotkey, description) => + colorizedHotkey(hotkey) == "" ? description : translate(description) != "" ? sprintf(translate("%(hotkey)s: " + description), { + "hotkey": colorizedHotkey(hotkey) + }) : colorizedHotkey(hotkey); + + for (let name in g_GuiButtons) + { + let button = g_GuiButtons[name]; + let enabled = !button.enabled || button.enabled(); + let guiObj = Engine.GetGUIObjectByName(name); + guiObj.enabled = enabled; + let hotkey = button.hotkey || guiObj.hotkey || ""; + + if ((!hotkey && !button.description) || !enabled) + continue; + + if (hotkey && Array.isArray(hotkey)) + guiObj.tooltip = hotkey.map(tooltip => + !!tooltip.showOnlyWhenUsed && colorizedHotkey(tooltip.hotkey) == "" ? "" : + getTooltip(tooltip.hotkey, tooltip.description)).join("\n"); + else + if (!hotkey || typeof(hotkey) == 'string') + guiObj.tooltip = getTooltip(hotkey, button.description || ""); + } +} + function initMenuPosition() { Engine.GetGUIObjectByName("menu").size = "100%-164 " + MENU_TOP + " 100% " + MENU_BOTTOM; @@ -130,12 +184,6 @@ Engine.PushGuiPage("page_lobby.xml", { "dialog": true }); } -function chatMenuButton() -{ - closeOpenDialogs(); - openChat(); -} - function diplomacyMenuButton() { closeOpenDialogs(); 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 @@ -24,9 +24,10 @@ style="StoneButtonFancy" size="0 32 100% 60" tooltip_style="sessionToolTip" + hotkey="chat" > Chat - chatMenuButton(); + openChat(); @@ -48,6 +49,7 @@ style="StoneButtonFancy" size="0 96 100% 124" tooltip_style="sessionToolTip" + hotkey="summary" > Summary openGameSummary(); @@ -62,7 +64,6 @@ hotkey="lobby" > Lobby - Show the multiplayer lobby in a dialog window. lobbyDialogButton(); @@ -83,6 +84,7 @@ style="StoneButtonFancy" size="0 192 100% 220" tooltip_style="sessionToolTip" + hotkey="pause" > Pause togglePause(); 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 @@ -688,9 +688,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) Index: binaries/data/mods/public/gui/session/top_panel/button_menu.xml =================================================================== --- binaries/data/mods/public/gui/session/top_panel/button_menu.xml +++ binaries/data/mods/public/gui/session/top_panel/button_menu.xml @@ -5,6 +5,7 @@ style="StoneButtonFancy" tooltip_style="sessionToolTip" z="70" + hotkey="session.gui.menu.toggle" >