mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-21 10:03:43 +00:00
Update the idle-worker-button onSimulationUpdate. Patch by svott, fixes #3736.
This was SVN commit r17674.
This commit is contained in:
@@ -7,17 +7,16 @@
|
||||
>
|
||||
<!-- Idle Worker Button -->
|
||||
<object size="100%-80 100%-80 100%-5 100%-5">
|
||||
<!-- TODO: We should disable this button if there are no idle workers. -->
|
||||
<object type="button"
|
||||
tooltip_style="sessionToolTip"
|
||||
hotkey="selection.idleworker"
|
||||
>
|
||||
<translatableAttribute id="tooltip">Find idle worker</translatableAttribute>
|
||||
<action on="Press">findIdleUnit(["Female", "Trader", "FishingBoat", "CitizenSoldier", "Healer"]);</action>
|
||||
<action on="MouseEnter">Engine.GetGUIObjectByName("idleOverlay").sprite = "stretched:session/minimap-idle-highlight.png";</action>
|
||||
<action on="MouseLeave">Engine.GetGUIObjectByName("idleOverlay").sprite = "stretched:session/minimap-idle.png";</action>
|
||||
<action on="MouseLeftPress">Engine.GetGUIObjectByName("idleOverlay").sprite = "stretched:session/minimap-idle.png";</action>
|
||||
<action on="MouseLeftRelease">Engine.GetGUIObjectByName("idleOverlay").sprite = "stretched:session/minimap-idle-highlight.png";</action>
|
||||
<action on="Press">if (g_HasIdleWorker) findIdleUnit(g_WorkerTypes);</action>
|
||||
<action on="MouseEnter">if (g_HasIdleWorker) Engine.GetGUIObjectByName("idleOverlay").sprite = "stretched:session/minimap-idle-highlight.png";</action>
|
||||
<action on="MouseLeave">if (g_HasIdleWorker) Engine.GetGUIObjectByName("idleOverlay").sprite = "stretched:session/minimap-idle.png";</action>
|
||||
<action on="MouseLeftPress">if (g_HasIdleWorker) Engine.GetGUIObjectByName("idleOverlay").sprite = "stretched:session/minimap-idle.png";</action>
|
||||
<action on="MouseLeftRelease">if (g_HasIdleWorker) Engine.GetGUIObjectByName("idleOverlay").sprite = "stretched:session/minimap-idle-highlight.png";</action>
|
||||
</object>
|
||||
</object>
|
||||
<!-- Minimap -->
|
||||
|
||||
@@ -81,6 +81,16 @@ var g_TemplateData = {}; // {id:template}
|
||||
var g_TemplateDataWithoutLocalization = {};
|
||||
var g_TechnologyData = {}; // {id:template}
|
||||
|
||||
/**
|
||||
* Unit classes to be checked for the idle-worker-hotkey.
|
||||
*/
|
||||
var g_WorkerTypes = ["Female", "Trader", "FishingBoat", "CitizenSoldier", "Healer"];
|
||||
|
||||
/**
|
||||
* Cache the idle worker status
|
||||
*/
|
||||
var g_HasIdleWorker = false;
|
||||
|
||||
function GetSimState()
|
||||
{
|
||||
if (!g_SimState)
|
||||
@@ -544,6 +554,36 @@ function changeGameSpeed(speed)
|
||||
Engine.SetSimRate(speed);
|
||||
}
|
||||
|
||||
function hasIdleWorker()
|
||||
{
|
||||
for (let workerType of g_WorkerTypes)
|
||||
{
|
||||
let idleUnits = Engine.GuiInterfaceCall("FindIdleUnits", {
|
||||
"idleClass": workerType,
|
||||
"prevUnit": undefined,
|
||||
"limit": 1,
|
||||
"excludeUnits": []
|
||||
});
|
||||
|
||||
if (idleUnits.length > 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function updateIdleWorkerButton()
|
||||
{
|
||||
g_HasIdleWorker = hasIdleWorker();
|
||||
|
||||
let idleWorkerButton = Engine.GetGUIObjectByName("idleOverlay");
|
||||
let prefix = "stretched:session/";
|
||||
|
||||
if (!g_HasIdleWorker)
|
||||
idleWorkerButton.sprite = prefix + "minimap-idle-disabled.png";
|
||||
else if (idleWorkerButton.sprite != prefix + "minimap-idle-highlight.png")
|
||||
idleWorkerButton.sprite = prefix + "minimap-idle.png";
|
||||
}
|
||||
|
||||
/**
|
||||
* Recomputes GUI state that depends on simulation state or selection state. Called directly every simulation
|
||||
* update (see session.xml), or from onTick when the selection has changed.
|
||||
@@ -577,6 +617,7 @@ function onSimulationUpdate()
|
||||
updateSelectionDetails();
|
||||
updateBuildingPlacementPreview();
|
||||
updateTimeNotifications();
|
||||
updateIdleWorkerButton();
|
||||
|
||||
if (Engine.GetPlayerID() > 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user