Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/session/unit_actions.js
Show First 20 Lines • Show All 678 Lines • ▼ Show 20 Lines | "actionCheck": function(target, selection) | ||||
"tooltip": actionInfo.tooltip, | "tooltip": actionInfo.tooltip, | ||||
"target": target, | "target": target, | ||||
"firstAbleEntity": actionInfo.entity | "firstAbleEntity": actionInfo.entity | ||||
}; | }; | ||||
}, | }, | ||||
"specificness": 0, | "specificness": 0, | ||||
}, | }, | ||||
"occupy-turret": | |||||
{ | |||||
"execute": function(target, action, selection, queued, pushFront) | |||||
{ | |||||
Engine.PostNetworkCommand({ | |||||
"type": "occupy-turret", | |||||
"entities": selection, | |||||
"target": action.target, | |||||
"queued": queued, | |||||
"pushFront": pushFront, | |||||
"formation": g_AutoFormation.getNull() | |||||
}); | |||||
Engine.GuiInterfaceCall("PlaySound", { | |||||
"name": "order_garrison", | |||||
"entity": action.firstAbleEntity | |||||
}); | |||||
return true; | |||||
}, | |||||
"getActionInfo": function(entState, targetState) | |||||
{ | |||||
if (!entState.turretable || !targetState || !targetState.turretHolder || | |||||
!playerCheck(entState, targetState, ["Player", "MutualAlly"])) | |||||
return false; | |||||
if (!targetState.turretHolder.turretPoints.find(point => | |||||
!point.allowedClasses || MatchesClassList(entState.identity.classes, point.allowedClasses))) | |||||
return false; | |||||
let occupiedTurrets = targetState.turretHolder.turretPoints.filter(point => point.entity != null); | |||||
let tooltip = sprintf(translate("Current turrets: %(occupied)s/%(capacity)s"), { | |||||
"occupied": occupiedTurrets.length, | |||||
"capacity": targetState.turretHolder.turretPoints.length | |||||
}); | |||||
if (occupiedTurrets.length == targetState.turretHolder.turretPoints.length) | |||||
tooltip = coloredText(tooltip, "orange"); | |||||
return { | |||||
"possible": true, | |||||
"tooltip": tooltip | |||||
}; | |||||
}, | |||||
"preSelectedActionCheck": function(target, selection) | |||||
{ | |||||
return preSelectedAction == ACTION_GARRISON && | |||||
(this.actionCheck(target, selection) || { | |||||
"type": "none", | |||||
"cursor": "action-garrison-disabled", | |||||
"target": null | |||||
}); | |||||
}, | |||||
"hotkeyActionCheck": function(target, selection) | |||||
{ | |||||
return Engine.HotkeyIsPressed("session.occupyturret") && | |||||
this.actionCheck(target, selection); | |||||
}, | |||||
"actionCheck": function(target, selection) | |||||
{ | |||||
let actionInfo = getActionInfo("occupy-turret", target, selection); | |||||
return actionInfo.possible && { | |||||
"type": "occupy-turret", | |||||
"cursor": "action-garrison", | |||||
"tooltip": actionInfo.tooltip, | |||||
"target": target | |||||
}; | |||||
}, | |||||
"specificness": 21, | |||||
}, | |||||
"garrison": | "garrison": | ||||
{ | { | ||||
"execute": function(target, action, selection, queued, pushFront) | "execute": function(target, action, selection, queued, pushFront) | ||||
{ | { | ||||
Engine.PostNetworkCommand({ | Engine.PostNetworkCommand({ | ||||
"type": "garrison", | "type": "garrison", | ||||
"entities": selection, | "entities": selection, | ||||
"target": action.target, | "target": action.target, | ||||
▲ Show 20 Lines • Show All 284 Lines • ▼ Show 20 Lines | "getActionInfo": function(entState, targetState) | ||||
"garrisoned": targetState.garrisonHolder.occupiedSlots, | "garrisoned": targetState.garrisonHolder.occupiedSlots, | ||||
"capacity": targetState.garrisonHolder.capacity | "capacity": targetState.garrisonHolder.capacity | ||||
}); | }); | ||||
if (targetState.garrisonHolder.occupiedSlots >= | if (targetState.garrisonHolder.occupiedSlots >= | ||||
targetState.garrisonHolder.capacity) | targetState.garrisonHolder.capacity) | ||||
tooltip = coloredText(tooltip, "orange"); | tooltip = coloredText(tooltip, "orange"); | ||||
} | } | ||||
else if (targetState && targetState.turretHolder && | |||||
playerCheck(entState, targetState, ["Player", "MutualAlly"])) | |||||
{ | |||||
data.command = "occupy-turret"; | |||||
data.target = targetState.id; | |||||
cursor = "action-garrison"; | |||||
let occupiedTurrets = targetState.turretHolder.turretPoints.filter(point => point.entity != null); | |||||
tooltip = sprintf(translate("Current turrets: %(occupied)s/%(capacity)s"), { | |||||
"occupied": occupiedTurrets.length, | |||||
"capacity": targetState.turretHolder.turretPoints.length | |||||
}); | |||||
if (occupiedTurrets.length >= targetState.turretHolder.turretPoints.length) | |||||
tooltip = coloredText(tooltip, "orange"); | |||||
} | |||||
else if (targetState && targetState.resourceSupply) | else if (targetState && targetState.resourceSupply) | ||||
{ | { | ||||
let resourceType = targetState.resourceSupply.type; | let resourceType = targetState.resourceSupply.type; | ||||
cursor = "action-gather-" + resourceType.specific; | cursor = "action-gather-" + resourceType.specific; | ||||
data.command = "gather-near-position"; | data.command = "gather-near-position"; | ||||
data.resourceType = resourceType; | data.resourceType = resourceType; | ||||
data.resourceTemplate = targetState.template; | data.resourceTemplate = targetState.template; | ||||
▲ Show 20 Lines • Show All 224 Lines • ▼ Show 20 Lines | "unload-all": { | ||||
}, | }, | ||||
"execute": function() | "execute": function() | ||||
{ | { | ||||
unloadAll(); | unloadAll(); | ||||
}, | }, | ||||
"allowedPlayers": ["Player", "Ally"] | "allowedPlayers": ["Player", "Ally"] | ||||
}, | }, | ||||
"unload-all-turrets": { | |||||
"getInfo": function(entStates) | |||||
{ | |||||
let count = 0; | |||||
for (let entState of entStates) | |||||
{ | |||||
if (!entState.turretHolder) | |||||
continue; | |||||
if (allowedPlayersCheck([entState], ["Player"])) | |||||
count += entState.turretHolder.turretPoints.filter(turretPoint => turretPoint.entity).length; | |||||
else | |||||
for (let turretPoint of entState.turretHolder.turretPoints) | |||||
if (turretPoint.entity && allowedPlayersCheck([GetEntityState(turretPoint.entity)], ["Player"])) | |||||
++count; | |||||
} | |||||
if (!count) | |||||
return false; | |||||
return { | |||||
"tooltip": colorizeHotkey("%(hotkey)s" + " ", "session.unloadturrets") + | |||||
translate("Unload Turrets."), | |||||
"icon": "garrison-out.png", | |||||
"count": count, | |||||
"enabled": true | |||||
}; | |||||
}, | |||||
"execute": function() | |||||
{ | |||||
unloadAllTurrets(); | |||||
}, | |||||
"allowedPlayers": ["Player", "Ally"] | |||||
}, | |||||
"delete": { | "delete": { | ||||
"getInfo": function(entStates) | "getInfo": function(entStates) | ||||
{ | { | ||||
return entStates.some(entState => !isUndeletable(entState)) ? | return entStates.some(entState => !isUndeletable(entState)) ? | ||||
{ | { | ||||
"tooltip": | "tooltip": | ||||
colorizeHotkey("%(hotkey)s" + " ", "session.kill") + | colorizeHotkey("%(hotkey)s" + " ", "session.kill") + | ||||
translate("Destroy the selected units or structures.") + "\n" + | translate("Destroy the selected units or structures.") + "\n" + | ||||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | "garrison": { | ||||
"execute": function() | "execute": function() | ||||
{ | { | ||||
inputState = INPUT_PRESELECTEDACTION; | inputState = INPUT_PRESELECTEDACTION; | ||||
preSelectedAction = ACTION_GARRISON; | preSelectedAction = ACTION_GARRISON; | ||||
}, | }, | ||||
"allowedPlayers": ["Player"] | "allowedPlayers": ["Player"] | ||||
}, | }, | ||||
"unload": { | "leave-turret": { | ||||
"getInfo": function(entStates) | "getInfo": function(entStates) | ||||
{ | { | ||||
if (entStates.every(entState => { | if (entStates.every(entState => !entState.turretable || | ||||
if (!entState.unitAI || !entState.turretParent) | entState.turretable.holder == INVALID_ENTITY)) | ||||
return true; | |||||
let parent = GetEntityState(entState.turretParent); | |||||
return !parent || !parent.garrisonHolder || parent.garrisonHolder.entities.indexOf(entState.id) == -1; | |||||
})) | |||||
return false; | return false; | ||||
return { | return { | ||||
"tooltip": translate("Unload"), | "tooltip": translate("Unload"), | ||||
"icon": "garrison-out.png", | "icon": "garrison-out.png", | ||||
"enabled": true | "enabled": true | ||||
}; | }; | ||||
}, | }, | ||||
"execute": function() | "execute": function(entStates) | ||||
{ | { | ||||
unloadSelection(); | if (!entStates.length) | ||||
return; | |||||
Engine.PostNetworkCommand({ | |||||
"type": "leave-turret", | |||||
"entities": entStates.filter(entState => entState.turretable && | |||||
entState.turretable.holder != INVALID_ENTITY).map(entState => entState.id) | |||||
}); | |||||
}, | }, | ||||
"allowedPlayers": ["Player"] | "allowedPlayers": ["Player"] | ||||
}, | }, | ||||
"repair": { | "repair": { | ||||
"getInfo": function(entStates) | "getInfo": function(entStates) | ||||
{ | { | ||||
if (entStates.every(entState => !entState.builder)) | if (entStates.every(entState => !entState.builder)) | ||||
▲ Show 20 Lines • Show All 344 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator