Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/GuiInterface.js
Show All 26 Lines | GuiInterface.prototype.Init = function() | ||||
this.placementWallEntities = undefined; | this.placementWallEntities = undefined; | ||||
this.placementWallLastAngle = 0; | this.placementWallLastAngle = 0; | ||||
this.notifications = []; | this.notifications = []; | ||||
this.renamedEntities = []; | this.renamedEntities = []; | ||||
this.miragedEntities = []; | this.miragedEntities = []; | ||||
this.timeNotificationID = 1; | this.timeNotificationID = 1; | ||||
this.timeNotifications = []; | this.timeNotifications = []; | ||||
this.entsRallyPointsDisplayed = []; | this.entsRallyPointsDisplayed = []; | ||||
this.entsWayPointsDisplayed = []; | |||||
this.entsWithAuraAndStatusBars = new Set(); | this.entsWithAuraAndStatusBars = new Set(); | ||||
this.enabledVisualRangeOverlayTypes = {}; | this.enabledVisualRangeOverlayTypes = {}; | ||||
}; | }; | ||||
/* | /* | ||||
* All of the functions defined below are called via Engine.GuiInterfaceCall(name, arg) | * All of the functions defined below are called via Engine.GuiInterfaceCall(name, arg) | ||||
* from GUI scripts, and executed here with arguments (player, arg). | * from GUI scripts, and executed here with arguments (player, arg). | ||||
* | * | ||||
▲ Show 20 Lines • Show All 916 Lines • ▼ Show 20 Lines | |||||
GuiInterface.prototype.GetPlayerEntities = function(player) | GuiInterface.prototype.GetPlayerEntities = function(player) | ||||
{ | { | ||||
return Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager).GetEntitiesByPlayer(player); | return Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager).GetEntitiesByPlayer(player); | ||||
}; | }; | ||||
GuiInterface.prototype.GetNonGaiaEntities = function() | GuiInterface.prototype.GetNonGaiaEntities = function() | ||||
{ | { | ||||
return Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager).GetNonGaiaEntities(); | return Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager).GetNonGaiaEntities(); | ||||
}; | }; | ||||
/** | |||||
* Displays the rally points of a given list of entities (carried in cmd.entities). | |||||
* | |||||
* The 'cmd' object may carry its own x/z coordinate pair indicating the location where the rally point should | |||||
* be rendered, in order to support instantaneously rendering a rally point marker at a specified location | |||||
* instead of incurring a delay while PostNetworkCommand processes the set-rallypoint command (see input.js). | |||||
* If cmd doesn't carry a custom location, then the position to render the marker at will be read from the | |||||
* RallyPoint component. | |||||
*/ | |||||
GuiInterface.prototype.DisplayRallyPoint = function(player, cmd) | |||||
{ | |||||
let cmpPlayer = QueryPlayerIDInterface(player); | |||||
// If there are some rally points already displayed, first hide them | GuiInterface.prototype.DisplayItineraryPoint = function (player, cmd, itineraryPointsDisplayed, renderer_IID, ent_IID) { | ||||
for (let ent of this.entsRallyPointsDisplayed) | let cmpPlayer = QueryPlayerIDInterface(player); | ||||
for (let ent of itineraryPointsDisplayed) | |||||
{ | { | ||||
let cmpRallyPointRenderer = Engine.QueryInterface(ent, IID_RallyPointRenderer); | let cmpItineraryPointRenderer = Engine.QueryInterface(ent, renderer_IID); | ||||
if (cmpRallyPointRenderer) | if (cmpItineraryPointRenderer) | ||||
cmpRallyPointRenderer.SetDisplayed(false); | cmpItineraryPointRenderer.SetDisplayed(false); | ||||
} | } | ||||
this.entsRallyPointsDisplayed = []; | itineraryPointsDisplayed = []; | ||||
// Show the rally points for the passed entities | |||||
for (let ent of cmd.entities) | for (let ent of cmd.entities) | ||||
{ | { | ||||
let cmpRallyPointRenderer = Engine.QueryInterface(ent, IID_RallyPointRenderer); | let cmpItineraryPointRenderer = Engine.QueryInterface(ent, renderer_IID); | ||||
if (!cmpRallyPointRenderer) | if (!cmpItineraryPointRenderer) | ||||
continue; | continue; | ||||
// entity must have a rally point component to display a rally point marker | let cmpItineraryPoint = Engine.QueryInterface(ent, ent_IID); | ||||
// (regardless of whether cmd specifies a custom location) | if (!cmpItineraryPoint) | ||||
let cmpRallyPoint = Engine.QueryInterface(ent, IID_RallyPoint); | |||||
if (!cmpRallyPoint) | |||||
continue; | continue; | ||||
// Verify the owner | // Verify the owner | ||||
let cmpOwnership = Engine.QueryInterface(ent, IID_Ownership); | let cmpOwnership = Engine.QueryInterface(ent, IID_Ownership); | ||||
if (!(cmpPlayer && cmpPlayer.CanControlAllUnits())) | if (!(cmpPlayer && cmpPlayer.CanControlAllUnits())) | ||||
if (!cmpOwnership || cmpOwnership.GetOwner() != player) | if (!cmpOwnership || cmpOwnership.GetOwner() != player) | ||||
continue; | continue; | ||||
// If the command was passed an explicit position, use that and | // If the command was passed an explicit position, use that and | ||||
// override the real rally point position; otherwise use the real position | // override the real rally point position; otherwise use the real position | ||||
let pos; | let pos; | ||||
if (cmd.x && cmd.z) | if (cmd.x && cmd.z) | ||||
pos = cmd; | pos = cmd; | ||||
else if (cmd.target) | |||||
pos = Engine.QueryInterface(cmd.target, IID_Position).GetPosition(); | |||||
else | else | ||||
pos = cmpRallyPoint.GetPositions()[0]; // may return undefined if no rally point is set | pos = cmpItineraryPoint.GetPositions()[0]; // may return undefined if no rally point is set | ||||
if (!pos) | |||||
continue; | |||||
if (pos) | |||||
{ | |||||
// Only update the position if we changed it (cmd.queued is set) | // Only update the position if we changed it (cmd.queued is set) | ||||
if ("queued" in cmd) | if ("queued" in cmd) | ||||
if (cmd.queued == true) | if (cmd.queued == true) | ||||
cmpRallyPointRenderer.AddPosition({ 'x': pos.x, 'y': pos.z }); // AddPosition takes a CFixedVector2D which has X/Y components, not X/Z | cmpItineraryPointRenderer.AddPosition({ 'x': pos.x, 'y': pos.z }); // AddPosition takes a CFixedVector2D which has X/Y components, not X/Z | ||||
else | else | ||||
cmpRallyPointRenderer.SetPosition({ 'x': pos.x, 'y': pos.z }); // SetPosition takes a CFixedVector2D which has X/Y components, not X/Z | cmpItineraryPointRenderer.SetPosition({ 'x': pos.x, 'y': pos.z }); // SetPosition takes a CFixedVector2D which has X/Y components, not X/Z | ||||
// rebuild the renderer when not set (when reading saved game or in case of building update) | // Rebuild the renderer when not set (when reading saved game or in case of building update) | ||||
else if (!cmpRallyPointRenderer.IsSet()) | else if (!cmpItineraryPointRenderer.IsSet()) | ||||
for (let posi of cmpRallyPoint.GetPositions()) | for (let posi of cmpItineraryPoint.GetPositions()) | ||||
cmpRallyPointRenderer.AddPosition({ 'x': posi.x, 'y': posi.z }); | cmpItineraryPointRenderer.AddPosition({ 'x': posi.x, 'y': posi.z }); | ||||
cmpRallyPointRenderer.SetDisplayed(true); | cmpItineraryPointRenderer.SetDisplayed(true); | ||||
itineraryPointsDisplayed.push(ent); | |||||
// remember which entities have their rally points displayed so we can hide them again | |||||
this.entsRallyPointsDisplayed.push(ent); | |||||
} | } | ||||
return itineraryPointsDisplayed; | |||||
} | } | ||||
/** | |||||
* Displays the rally points of a given list of entities (carried in cmd.entities). | |||||
* | |||||
* The 'cmd' object may carry its own x/z coordinate pair indicating the location where the rally point should | |||||
* be rendered, in order to support instantaneously rendering a rally point marker at a specified location | |||||
* instead of incurring a delay while PostNetworkCommand processes the set-rallypoint command (see input.js). | |||||
* If cmd doesn't carry a custom location, then the position to render the marker at will be read from the | |||||
* RallyPoint component. | |||||
*/ | |||||
GuiInterface.prototype.DisplayRallyPoint = function(player, cmd) | |||||
{ | |||||
this.entsRallyPointsDisplayed = this.DisplayItineraryPoint(player, cmd, this.entsRallyPointsDisplayed, IID_RallyPointRenderer, IID_RallyPoint) | |||||
}; | |||||
/** | |||||
* Displays the way points of a given list of entities (carried in cmd.entities). | |||||
* | |||||
* The 'cmd' object may carry its own x/z coordinate pair indicating the location where the way point should | |||||
* be rendered or a target to retrieve that location, in order to support instantaneously rendering a way point | |||||
* marker at a specified location instead of incurring a delay before PostNetworkCommand is processed. | |||||
* If cmd doesn't carry a custom location, then the position to render the marker at will be read from the | |||||
* WayPoint component. | |||||
*/ | |||||
GuiInterface.prototype.DisplayWayPoint = function(player, cmd) | |||||
{ | |||||
this.entsWayPointsDisplayed = this.DisplayItineraryPoint(player, cmd, this.entsWayPointsDisplayed, IID_WayPointRenderer, IID_WayPoint) | |||||
}; | }; | ||||
/** | /** | ||||
* Display the building placement preview. | * Display the building placement preview. | ||||
* cmd.template is the name of the entity template, or "" to disable the preview. | * cmd.template is the name of the entity template, or "" to disable the preview. | ||||
* cmd.x, cmd.z, cmd.angle give the location. | * cmd.x, cmd.z, cmd.angle give the location. | ||||
* | * | ||||
* Returns result object from CheckPlacement: | * Returns result object from CheckPlacement: | ||||
▲ Show 20 Lines • Show All 937 Lines • ▼ Show 20 Lines | let exposedFunctions = { | ||||
"GetFormationInfoFromTemplate": 1, | "GetFormationInfoFromTemplate": 1, | ||||
"IsStanceSelected": 1, | "IsStanceSelected": 1, | ||||
"SetSelectionHighlight": 1, | "SetSelectionHighlight": 1, | ||||
"GetAllBuildableEntities": 1, | "GetAllBuildableEntities": 1, | ||||
"SetStatusBars": 1, | "SetStatusBars": 1, | ||||
"GetPlayerEntities": 1, | "GetPlayerEntities": 1, | ||||
"GetNonGaiaEntities": 1, | "GetNonGaiaEntities": 1, | ||||
"DisplayRallyPoint": 1, | "DisplayWayPoint": 1, | ||||
"SetBuildingPlacementPreview": 1, | "SetBuildingPlacementPreview": 1, | ||||
"SetWallPlacementPreview": 1, | "SetWallPlacementPreview": 1, | ||||
"GetFoundationSnapData": 1, | "GetFoundationSnapData": 1, | ||||
"PlaySound": 1, | "PlaySound": 1, | ||||
"FindIdleUnits": 1, | "FindIdleUnits": 1, | ||||
"HasIdleUnits": 1, | "HasIdleUnits": 1, | ||||
"GetTradingRouteGain": 1, | "GetTradingRouteGain": 1, | ||||
"GetTradingDetails": 1, | "GetTradingDetails": 1, | ||||
"CanAttack": 1, | "CanAttack": 1, | ||||
"GetBatchTime": 1, | "GetBatchTime": 1, | ||||
"DisplayRallyPoint": 1, | |||||
"DisplayItineraryPoint": 1, | |||||
"IsMapRevealed": 1, | "IsMapRevealed": 1, | ||||
"SetPathfinderDebugOverlay": 1, | "SetPathfinderDebugOverlay": 1, | ||||
"SetPathfinderHierDebugOverlay": 1, | "SetPathfinderHierDebugOverlay": 1, | ||||
"SetObstructionDebugOverlay": 1, | "SetObstructionDebugOverlay": 1, | ||||
"SetMotionDebugOverlay": 1, | "SetMotionDebugOverlay": 1, | ||||
"SetRangeDebugOverlay": 1, | "SetRangeDebugOverlay": 1, | ||||
"EnableVisualRangeOverlayType": 1, | "EnableVisualRangeOverlayType": 1, | ||||
Show All 15 Lines |
Wildfire Games · Phabricator