Changeset View
Standalone View
binaries/data/mods/public/gui/session/unit_actions.js
/** | /** | ||||
* Specifies which template should indicate the target location of a player command, | * Specifies which template should indicate the target location of a player command, | ||||
* given a command type. | * given a command type. | ||||
*/ | */ | ||||
var g_TargetMarker = { | var g_TargetMarker = { | ||||
"move": "special/target_marker" | "move": "special/target_marker", | ||||
// TODO: Add proper marker | |||||
"map_ping": "special/target_marker" | |||||
}; | }; | ||||
/** | /** | ||||
* Which enemy entity types will be attacked on sight when patroling. | * Which enemy entity types will be attacked on sight when patroling. | ||||
*/ | */ | ||||
var g_PatrolTargets = ["Unit"]; | var g_PatrolTargets = ["Unit"]; | ||||
/** | /** | ||||
Show All 33 Lines | "execute": function(target, action, selection, queued) | ||||
Engine.PostNetworkCommand({ | Engine.PostNetworkCommand({ | ||||
"type": "walk", | "type": "walk", | ||||
"entities": selection, | "entities": selection, | ||||
"x": target.x, | "x": target.x, | ||||
"z": target.z, | "z": target.z, | ||||
"queued": queued | "queued": queued | ||||
}); | }); | ||||
DrawTargetMarker(target); | drawTargetMarker(target); | ||||
Engine.GuiInterfaceCall("PlaySound", { | Engine.GuiInterfaceCall("PlaySound", { | ||||
"name": "order_walk", | "name": "order_walk", | ||||
"entity": selection[0] | "entity": selection[0] | ||||
}); | }); | ||||
return true; | return true; | ||||
}, | }, | ||||
Show All 34 Lines | "execute": function(target, action, selection, queued) | ||||
"type": "attack-walk", | "type": "attack-walk", | ||||
"entities": selection, | "entities": selection, | ||||
"x": target.x, | "x": target.x, | ||||
"z": target.z, | "z": target.z, | ||||
"targetClasses": targetClasses, | "targetClasses": targetClasses, | ||||
"queued": queued | "queued": queued | ||||
}); | }); | ||||
DrawTargetMarker(target); | drawTargetMarker(target); | ||||
Engine.GuiInterfaceCall("PlaySound", { | Engine.GuiInterfaceCall("PlaySound", { | ||||
"name": "order_walk", | "name": "order_walk", | ||||
"entity": selection[0] | "entity": selection[0] | ||||
}); | }); | ||||
return true; | return true; | ||||
}, | }, | ||||
▲ Show 20 Lines • Show All 130 Lines • ▼ Show 20 Lines | "execute": function(target, action, selection, queued) | ||||
"x": target.x, | "x": target.x, | ||||
"z": target.z, | "z": target.z, | ||||
"target": action.target, | "target": action.target, | ||||
"targetClasses": { "attack": g_PatrolTargets }, | "targetClasses": { "attack": g_PatrolTargets }, | ||||
"queued": queued, | "queued": queued, | ||||
"allowCapture": false | "allowCapture": false | ||||
}); | }); | ||||
DrawTargetMarker(target); | drawTargetMarker(target); | ||||
Engine.GuiInterfaceCall("PlaySound", { "name": "order_patrol", "entity": selection[0] }); | Engine.GuiInterfaceCall("PlaySound", { "name": "order_patrol", "entity": selection[0] }); | ||||
return true; | return true; | ||||
}, | }, | ||||
"getActionInfo": function(entState, targetState) | "getActionInfo": function(entState, targetState) | ||||
{ | { | ||||
if (!entState.unitAI || !entState.unitAI.canPatrol) | if (!entState.unitAI || !entState.unitAI.canPatrol) | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 1,187 Lines • ▼ Show 20 Lines | if (entState.capturePoints && entState.capturePoints[entState.player] < entState.maxCapturePoints / 2) | ||||
return translate("You cannot destroy this entity as you own less than half the capture points"); | return translate("You cannot destroy this entity as you own less than half the capture points"); | ||||
if (!entState.identity.canDelete) | if (!entState.identity.canDelete) | ||||
return translate("This entity is undeletable"); | return translate("This entity is undeletable"); | ||||
return false; | return false; | ||||
} | } | ||||
function DrawTargetMarker(target) | function drawTargetMarker(target) | ||||
{ | { | ||||
Engine.GuiInterfaceCall("AddTargetMarker", { | Engine.GuiInterfaceCall("AddTargetMarker", { | ||||
"template": g_TargetMarker.move, | "template": g_TargetMarker.move, | ||||
"x": target.x, | "x": target.x, | ||||
"z": target.z | "z": target.z | ||||
}); | }); | ||||
} | } | ||||
function displayMapPing(target, playerID) | |||||
elexis: as far as I know we used lowercase (could be corrected above too), but all of the JS GUI should… | |||||
{ | |||||
Engine.GuiInterfaceCall("AddTargetMarker", { | |||||
"template": g_TargetMarker.map_ping, | |||||
"x": target.x, | |||||
"z": target.z | |||||
}); | |||||
//TODO: is there a better way to call the ping function of the minimap? | |||||
Done Inline ActionsAlternatives include JSInterface_*.cpp, or calling calling C++ code directly via GUIInterface. But calling the minimap object directly doesn't sound too bad. That would be better cleaned if passing a JS object { "position": new Vector2D(x, y), "color": ...", ... } to C++. elexis: Alternatives include `JSInterface_*.cpp`, or calling calling C++ code directly via… | |||||
Done Inline Actions
Yep, that's why. Imarok: > Maybe that's why the "ping" variable is here, to signal that the copying is finished.
Yep… | |||||
let minimap = Engine.GetGUIObjectByName("minimap"); | |||||
minimap.ping_x = target.x; | |||||
minimap.ping_z = target.z; | |||||
elexisUnsubmitted Done Inline ActionsShould be minimap.ping_position = target elexis: Should be `minimap.ping_position = target`
The Vector2D <-> JS Value conversion is already… | |||||
minimap.ping_color = rgbToGuiColor(g_DisplayedPlayerColors[playerID]); | |||||
minimap.ping = true; | |||||
// TODO: Create a new sound and play it here | |||||
Engine.PlayUISound("audio/interface/ui/chat_alert.ogg", false); | |||||
} | |||||
function findGatherType(gatherer, supply) | function findGatherType(gatherer, supply) | ||||
{ | { | ||||
if (!gatherer.resourceGatherRates || !supply) | if (!gatherer.resourceGatherRates || !supply) | ||||
return undefined; | return undefined; | ||||
if (gatherer.resourceGatherRates[supply.type.generic + "." + supply.type.specific]) | if (gatherer.resourceGatherRates[supply.type.generic + "." + supply.type.specific]) | ||||
return supply.type.specific; | return supply.type.specific; | ||||
▲ Show 20 Lines • Show All 68 Lines • Show Last 20 Lines |
as far as I know we used lowercase (could be corrected above too), but all of the JS GUI should become OOP anyway