Left-click the portrait to follow the entity

- Left-clicking the portrait of a unit will make the camera follow that
   unit (before: no action). A tooltip informs the player of this
   possibility.

 - Left-clicking the portrait of a structure will make the camera focus on
   that structure (before: no action). A tooltip informs the player of
   this possibility.

 - Double-clicking a hero/treasure icon will make the camera follow that
   hero/treasure (before: just focus on that hero/treasure).

 - Some minor related changes.

Fixes #6879
This commit is contained in:
abian 2024-09-02 13:22:18 +02:00 committed by Ralph Sennhauser
parent 230c7ca27d
commit 798cff1f6f
6 changed files with 46 additions and 19 deletions

View File

@ -1219,16 +1219,28 @@ function getResourceDropsiteTooltip(template)
}); });
} }
function showTemplateViewerOnRightClickTooltip() function getFocusOnLeftClickTooltip()
{ {
// Translation: Appears in a tooltip to indicate that right-clicking the corresponding GUI element will open the Template Details GUI page. // Translation: Appears in a tooltip to indicate that left-clicking the corresponding GUI element will center the view on the selected entity.
return translate("Right-click to view more information."); return translate("Left-click to focus.");
} }
function showTemplateViewerOnClickTooltip() function getFollowOnLeftClickTooltip()
{
// Translation: Appears in a tooltip to indicate that left-clicking the corresponding GUI element will make the camera follow the selected unit.
return translate("Left-click to follow.");
}
function getTemplateViewerOnRightClickTooltip()
{
// Translation: Appears in a tooltip to indicate that right-clicking the corresponding GUI element will open the Template Details GUI page.
return translate("Right-click for more information.");
}
function getTemplateViewerOnClickTooltip()
{ {
// Translation: Appears in a tooltip to indicate that clicking the corresponding GUI element will open the Template Details GUI page. // Translation: Appears in a tooltip to indicate that clicking the corresponding GUI element will open the Template Details GUI page.
return translate("Click to view more information."); return translate("Click for more information.");
} }
/** /**

View File

@ -45,7 +45,7 @@ class EntityBox
static compileTooltip(template) static compileTooltip(template)
{ {
return ReferencePage.buildText(template, this.prototype.TooltipFunctions) + "\n" + showTemplateViewerOnClickTooltip(); return ReferencePage.buildText(template, this.prototype.TooltipFunctions) + "\n" + getTemplateViewerOnClickTooltip();
} }
/** /**

View File

@ -479,8 +479,8 @@ EntitySelection.prototype.selectAndMoveTo = function(entityID)
this.reset(); this.reset();
this.addList([entityID]); this.addList([entityID]);
Engine.CameraMoveTo(entState.position.x, entState.position.z); setCameraFollow(entityID);
} };
/** /**
* Adds the formation members of a selected entities to the selection. * Adds the formation members of a selected entities to the selection.

View File

@ -324,9 +324,19 @@ function displaySingle(entState)
// TODO: we should require all entities to have icons // TODO: we should require all entities to have icons
Engine.GetGUIObjectByName("icon").sprite = template.icon ? ("stretched:session/portraits/" + template.icon) : "BackgroundBlack"; Engine.GetGUIObjectByName("icon").sprite = template.icon ? ("stretched:session/portraits/" + template.icon) : "BackgroundBlack";
if (template.icon) if (template.icon)
Engine.GetGUIObjectByName("iconBorder").onPressRight = () => { {
const iconBorder = Engine.GetGUIObjectByName("iconBorder");
// Actions on left click
iconBorder.onPress = () => {
setCameraFollow(entState.id);
};
// Actions on right click
iconBorder.onPressRight = () => {
showTemplateDetails(entState.template, playerState.civ); showTemplateDetails(entState.template, playerState.civ);
}; };
}
let detailedTooltip = [ let detailedTooltip = [
getAttackTooltip, getAttackTooltip,
@ -357,10 +367,12 @@ function displaySingle(entState)
getVisibleEntityClassesFormatted, getVisibleEntityClassesFormatted,
getAurasTooltip, getAurasTooltip,
getEntityTooltip, getEntityTooltip,
getTreasureTooltip, getTreasureTooltip
showTemplateViewerOnRightClickTooltip
].map(func => func(template))); ].map(func => func(template)));
const leftClickTooltip = hasClass(entState, "Unit") ? getFollowOnLeftClickTooltip() : getFocusOnLeftClickTooltip();
iconTooltips.push(leftClickTooltip + " " + getTemplateViewerOnRightClickTooltip());
Engine.GetGUIObjectByName("iconBorder").tooltip = iconTooltips.filter(tip => tip).join("\n"); Engine.GetGUIObjectByName("iconBorder").tooltip = iconTooltips.filter(tip => tip).join("\n");
Engine.GetGUIObjectByName("detailsAreaSingle").hidden = false; Engine.GetGUIObjectByName("detailsAreaSingle").hidden = false;

View File

@ -207,7 +207,7 @@ g_SelectionPanels.Construction = {
getGarrisonTooltip(template), getGarrisonTooltip(template),
getTurretsTooltip(template), getTurretsTooltip(template),
getPopulationBonusTooltip(template), getPopulationBonusTooltip(template),
showTemplateViewerOnRightClickTooltip(template) getTemplateViewerOnRightClickTooltip(template)
); );
@ -578,7 +578,7 @@ g_SelectionPanels.Queue = {
"neededSlots": queuedItem.neededSlots "neededSlots": queuedItem.neededSlots
})); }));
} }
tooltips.push(showTemplateViewerOnRightClickTooltip(template)); tooltips.push(getTemplateViewerOnRightClickTooltip(template));
data.button.tooltip = tooltips.join("\n"); data.button.tooltip = tooltips.join("\n");
data.countDisplay.caption = queuedItem.count > 1 ? queuedItem.count : ""; data.countDisplay.caption = queuedItem.count > 1 ? queuedItem.count : "";
@ -763,7 +763,7 @@ g_SelectionPanels.Research = {
getEntityNamesFormatted, getEntityNamesFormatted,
getEntityTooltip, getEntityTooltip,
getEntityCostTooltip, getEntityCostTooltip,
showTemplateViewerOnRightClickTooltip getTemplateViewerOnRightClickTooltip
].map(func => func(template)); ].map(func => func(template));
if (!requirementsPassed) if (!requirementsPassed)
@ -1058,7 +1058,7 @@ g_SelectionPanels.Training = {
getResourceDropsiteTooltip getResourceDropsiteTooltip
].map(func => func(template))); ].map(func => func(template)));
tooltips.push(showTemplateViewerOnRightClickTooltip()); tooltips.push(getTemplateViewerOnRightClickTooltip());
tooltips.push( tooltips.push(
formatBatchTrainingString(buildingsCountToTrainFullBatch, fullBatchSize, remainderBatch), formatBatchTrainingString(buildingsCountToTrainFullBatch, fullBatchSize, remainderBatch),
getRequirementsTooltip(requirementsMet, template.requirements, GetSimState().players[data.player].civ), getRequirementsTooltip(requirementsMet, template.requirements, GetSimState().players[data.player].civ),
@ -1180,7 +1180,8 @@ g_SelectionPanels.Upgrade = {
formatMatchLimitString(limits.matchLimit, limits.matchCount, limits.type), formatMatchLimitString(limits.matchLimit, limits.matchCount, limits.type),
getRequirementsTooltip(requirementsMet, data.item.requirements, GetSimState().players[data.player].civ), getRequirementsTooltip(requirementsMet, data.item.requirements, GetSimState().players[data.player].civ),
getNeededResourcesTooltip(neededResources), getNeededResourcesTooltip(neededResources),
showTemplateViewerOnRightClickTooltip()); getTemplateViewerOnRightClickTooltip()
);
tooltip = tooltips.filter(tip => tip).join("\n"); tooltip = tooltips.filter(tip => tip).join("\n");

View File

@ -386,14 +386,16 @@ function cancelUpgradeEntity()
} }
/** /**
* Set the camera to follow the given entity if it's a unit. * Focus the camera on the entity and follow if it's a unit.
* Otherwise stop following. * If that's not possible, stop any current follow.
*/ */
function setCameraFollow(entity) function setCameraFollow(entity)
{ {
let entState = entity && GetEntityState(entity); const entState = entity && GetEntityState(entity);
if (entState && hasClass(entState, "Unit")) if (entState && hasClass(entState, "Unit"))
Engine.CameraFollow(entity); Engine.CameraFollow(entity);
else if (entState?.position)
Engine.CameraMoveTo(entState.position.x, entState.position.z);
else else
Engine.CameraFollow(0); Engine.CameraFollow(0);
} }