Index: binaries/data/mods/public/gui/session/unit_actions.js =================================================================== --- binaries/data/mods/public/gui/session/unit_actions.js +++ binaries/data/mods/public/gui/session/unit_actions.js @@ -11,6 +11,8 @@ */ var g_PatrolTargets = ["Unit"]; +var disabledColor = { "color": "255 140 0" }; + /** * List of different actions units can execute, * this is mostly used to determine which actions can be executed @@ -563,6 +565,8 @@ return false; let tooltip; + let possible = true; + let disabled = false; switch (tradingDetails.type) { case "is first": @@ -587,25 +591,39 @@ break; case "set second": - if (tradingDetails.gain.traderGain == 0) // markets too close - return false; - - tooltip = translate("Right-click to set as destination trade market.") + "\n" + - sprintf(translate("Gain: %(gain)s"), { - "gain": getTradingTooltip(tradingDetails.gain) - }); + if (tradingDetails.gain.traderGain == 0) + { + possible = false; + disabled = true; + tooltip = setStringTags(translate("This market is too close to the origin market."), disabledColor); + } + else + tooltip = translate("Right-click to set as destination trade market.") + "\n" + + sprintf(translate("Gain: %(gain)s"), { + "gain": getTradingTooltip(tradingDetails.gain) + }); break; } return { - "possible": true, - "tooltip": tooltip + "possible": possible, + "tooltip": tooltip, + "disabled": disabled }; }, "actionCheck": function(target, selection) { let actionInfo = getActionInfo("setup-trade-route", target, selection); + + if (actionInfo.disabled) + return { + "type": "none", + "cursor": "action-setup-trade-route", + "target": null, + "tooltip": actionInfo.tooltip, + }; + if (!actionInfo.possible) return false; @@ -652,15 +670,22 @@ if (entState.garrisonHolder) extraCount += entState.garrisonHolder.garrisonedEntitiesCount; + let possible = true; + let disabled = false; if (targetState.garrisonHolder.garrisonedEntitiesCount + extraCount >= targetState.garrisonHolder.capacity) - tooltip = coloredText(tooltip, "orange"); + { + tooltip = setStringTags(tooltip, disabledColor); + disabled = true; + possible = false; + } if (!MatchesClassList(entState.identity.classes, targetState.garrisonHolder.allowedClasses)) return false; return { - "possible": true, - "tooltip": tooltip + "possible": possible, + "tooltip": tooltip, + "disabled": disabled }; }, "preSelectedActionCheck": function(target, selection) @@ -669,6 +694,14 @@ return false; let actionInfo = getActionInfo("garrison", target, selection); + if (actionInfo.disabled) + return { + "type": "none", + "cursor": "action-garrison-disabled", + "target": null, + "tooltip": actionInfo.tooltip, + }; + if (!actionInfo.possible) return { "type": "none", @@ -687,9 +720,17 @@ { let actionInfo = getActionInfo("garrison", target, selection); - if (!Engine.HotkeyIsPressed("session.garrison") || !actionInfo.possible) + if (!Engine.HotkeyIsPressed("session.garrison") || !actionInfo.possible && !actionInfo.disabled) return false; + if (actionInfo.disabled) + return { + "type": "none", + "cursor": "action-garrison-disabled", + "target": null, + "tooltip": actionInfo.tooltip, + }; + return { "type": "garrison", "cursor": "action-garrison", @@ -826,6 +867,8 @@ "getActionInfo": function(entState, targetState) { let tooltip; + let possible = true; + let disabled = true; // default to walking there (or attack-walking if hotkey pressed) let data = { "command": "walk" }; let cursor = ""; @@ -903,19 +946,26 @@ }; let gain = Engine.GuiInterfaceCall("GetTradingRouteGain", traderData); - if (gain && gain.traderGain) + if (gain) { data.command = "trade"; data.target = traderData.secondMarket; data.source = traderData.firstMarket; cursor = "action-setup-trade-route"; - tooltip = translate("Right-click to establish a default route for new traders.") + "\n" + - sprintf( - trader ? - translate("Gain: %(gain)s") : - translate("Expected gain: %(gain)s"), - { "gain": getTradingTooltip(gain) }); + if (gain.traderGain) + tooltip = translate("Right-click to establish a default route for new traders.") + "\n" + + sprintf( + trader ? + translate("Gain: %(gain)s") : + translate("Expected gain: %(gain)s"), + { "gain": getTradingTooltip(gain) }); + else + { + possible = false; + disabled = true; + tooltip = setStringTags(translate("This market is too close to the origin market."), disabledColor); + } } } else if ((targetState.needsRepair || targetState.foundation) && playerCheck(entState, targetState, ["Ally"])) @@ -941,10 +991,11 @@ return false; return { - "possible": true, + "possible": possible, "data": data, "position": targetState.position, "cursor": cursor, + "disabled": disabled, "tooltip": tooltip }; @@ -955,6 +1006,15 @@ return false; let actionInfo = getActionInfo("set-rallypoint", target, selection); + + if (actionInfo.disabled) + return { + "type": "none", + "cursor": actionInfo.cursor, + "target": null, + "tooltip": actionInfo.tooltip, + }; + if (!actionInfo.possible) return false; @@ -1554,7 +1614,7 @@ if (g_UnitActions[action] && g_UnitActions[action].getActionInfo) { let r = g_UnitActions[action].getActionInfo(entState, targetState, simState); - if (r && r.possible) // return true if it's possible for one of the entities + if (r && r.possible || r.disabled) // return true if it's possible for one of the entities return r; } }