Show a red overlay over training/construction... icons that cannot be afforded.
This was SVN commit r12404.
This commit is contained in:
parent
9e35243976
commit
902fc4a541
@ -603,6 +603,7 @@
|
|||||||
<repeat count="4">
|
<repeat count="4">
|
||||||
<object name="unitBarterSellButton[n]" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottomBold">
|
<object name="unitBarterSellButton[n]" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottomBold">
|
||||||
<object name="unitBarterSellIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
|
<object name="unitBarterSellIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
|
||||||
|
<object name="unitBarterSellUnaffordable[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="colour: 255 0 0 60"/>
|
||||||
<object name="unitBarterSellAmount[n]" ghost="true" style="resourceText" type="text" size="0 0 100% 50%"/>
|
<object name="unitBarterSellAmount[n]" ghost="true" style="resourceText" type="text" size="0 0 100% 50%"/>
|
||||||
<object name="unitBarterSellSelection[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="stretched:session/icons/corners.png"/>
|
<object name="unitBarterSellSelection[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="stretched:session/icons/corners.png"/>
|
||||||
</object>
|
</object>
|
||||||
@ -612,6 +613,7 @@
|
|||||||
<repeat count="4">
|
<repeat count="4">
|
||||||
<object name="unitBarterBuyButton[n]" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottomBold">
|
<object name="unitBarterBuyButton[n]" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottomBold">
|
||||||
<object name="unitBarterBuyIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
|
<object name="unitBarterBuyIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
|
||||||
|
<object name="unitBarterBuyUnaffordable[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="colour: 255 0 0 60"/>
|
||||||
<object name="unitBarterBuyAmount[n]" ghost="true" style="resourceText" type="text" size="0 0 100% 50%"/>
|
<object name="unitBarterBuyAmount[n]" ghost="true" style="resourceText" type="text" size="0 0 100% 50%"/>
|
||||||
</object>
|
</object>
|
||||||
</repeat>
|
</repeat>
|
||||||
@ -822,6 +824,7 @@
|
|||||||
<repeat count="24">
|
<repeat count="24">
|
||||||
<object name="unitConstructionButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom">
|
<object name="unitConstructionButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom">
|
||||||
<object name="unitConstructionIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
|
<object name="unitConstructionIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
|
||||||
|
<object name="unitConstructionUnaffordable[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="colour: 255 0 0 127"/>
|
||||||
</object>
|
</object>
|
||||||
</repeat>
|
</repeat>
|
||||||
</object>
|
</object>
|
||||||
@ -835,6 +838,7 @@
|
|||||||
<object name="unitResearchButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom">
|
<object name="unitResearchButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom">
|
||||||
<object name="unitResearchIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
|
<object name="unitResearchIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
|
||||||
<object name="unitResearchSelection[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="colour: 255 0 0 127"/>
|
<object name="unitResearchSelection[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="colour: 255 0 0 127"/>
|
||||||
|
<object name="unitResearchUnaffordable[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="colour: 255 0 0 60"/>
|
||||||
</object>
|
</object>
|
||||||
</repeat>
|
</repeat>
|
||||||
<repeat count="8">
|
<repeat count="8">
|
||||||
@ -852,6 +856,7 @@
|
|||||||
<repeat count="24">
|
<repeat count="24">
|
||||||
<object name="unitTrainingButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom">
|
<object name="unitTrainingButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom">
|
||||||
<object name="unitTrainingIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
|
<object name="unitTrainingIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
|
||||||
|
<object name="unitTrainingUnaffordable[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="colour: 255 0 0 127"/>
|
||||||
</object>
|
</object>
|
||||||
</repeat>
|
</repeat>
|
||||||
</object>
|
</object>
|
||||||
@ -898,6 +903,7 @@
|
|||||||
<object name="unitGateButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom">
|
<object name="unitGateButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom">
|
||||||
<object name="unitGateIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
|
<object name="unitGateIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
|
||||||
<object name="unitGateSelection[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="stretched:session/icons/corners.png"/>
|
<object name="unitGateSelection[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="stretched:session/icons/corners.png"/>
|
||||||
|
<object name="unitGateUnaffordable[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="colour: 255 0 0 127"/>
|
||||||
</object>
|
</object>
|
||||||
</repeat>
|
</repeat>
|
||||||
</object>
|
</object>
|
||||||
|
@ -332,7 +332,20 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)
|
|||||||
case GATE:
|
case GATE:
|
||||||
var tooltip = item.tooltip;
|
var tooltip = item.tooltip;
|
||||||
if (item.template)
|
if (item.template)
|
||||||
tooltip += "\n" + getEntityCostTooltip(GetTemplateData(item.template));
|
{
|
||||||
|
var template = GetTemplateData(item.template);
|
||||||
|
tooltip += "\n" + getEntityCostTooltip(template);
|
||||||
|
|
||||||
|
var affordableMask = getGUIObjectByName("unitGateUnaffordable["+i+"]");
|
||||||
|
affordableMask.hidden = true;
|
||||||
|
|
||||||
|
var neededResources = Engine.GuiInterfaceCall("GetNeededResources", template.cost);
|
||||||
|
if (neededResources)
|
||||||
|
{
|
||||||
|
affordableMask.hidden = false;
|
||||||
|
tooltip += getNeededResourcesTooltip(neededResources);
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STANCE:
|
case STANCE:
|
||||||
@ -416,6 +429,8 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)
|
|||||||
// Button
|
// Button
|
||||||
var button = getGUIObjectByName("unit"+guiName+"Button["+i+"]");
|
var button = getGUIObjectByName("unit"+guiName+"Button["+i+"]");
|
||||||
var button1 = getGUIObjectByName("unit"+guiName+"Button["+(i+rowLength)+"]");
|
var button1 = getGUIObjectByName("unit"+guiName+"Button["+(i+rowLength)+"]");
|
||||||
|
var affordableMask = getGUIObjectByName("unit"+guiName+"Unaffordable["+i+"]");
|
||||||
|
var affordableMask1 = getGUIObjectByName("unit"+guiName+"Unaffordable["+(i+rowLength)+"]");
|
||||||
var icon = getGUIObjectByName("unit"+guiName+"Icon["+i+"]");
|
var icon = getGUIObjectByName("unit"+guiName+"Icon["+i+"]");
|
||||||
var selection = getGUIObjectByName("unit"+guiName+"Selection["+i+"]");
|
var selection = getGUIObjectByName("unit"+guiName+"Selection["+i+"]");
|
||||||
var pair = getGUIObjectByName("unit"+guiName+"Pair["+i+"]");
|
var pair = getGUIObjectByName("unit"+guiName+"Pair["+i+"]");
|
||||||
@ -553,23 +568,85 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)
|
|||||||
|
|
||||||
if (guiName == RESEARCH)
|
if (guiName == RESEARCH)
|
||||||
{
|
{
|
||||||
|
// Check resource requirements for first button
|
||||||
|
affordableMask.hidden = true;
|
||||||
|
var neededResources = Engine.GuiInterfaceCall("GetNeededResources", template.cost);
|
||||||
|
if (neededResources)
|
||||||
|
{
|
||||||
|
if (button.enabled !== false)
|
||||||
|
{
|
||||||
|
button.enabled = false;
|
||||||
|
affordableMask.hidden = false;
|
||||||
|
}
|
||||||
|
button.tooltip += getNeededResourcesTooltip(neededResources);
|
||||||
|
}
|
||||||
|
|
||||||
if (item.pair)
|
if (item.pair)
|
||||||
{
|
{
|
||||||
grayscale = "";
|
grayscale = "";
|
||||||
button1.enabled = true;
|
button1.enabled = true;
|
||||||
if (guiName == RESEARCH && !Engine.GuiInterfaceCall("CheckTechnologyRequirements", entType1))
|
|
||||||
|
if (!Engine.GuiInterfaceCall("CheckTechnologyRequirements", entType1))
|
||||||
{
|
{
|
||||||
button1.enabled = false;
|
button1.enabled = false;
|
||||||
button1.tooltip += "\n" + GetTechnologyData(entType1).requirementsTooltip;
|
button1.tooltip += "\n" + GetTechnologyData(entType1).requirementsTooltip;
|
||||||
grayscale = "grayscale:";
|
grayscale = "grayscale:";
|
||||||
}
|
}
|
||||||
icon1.sprite = "stretched:" + grayscale + "session/portraits/" +template1.icon;
|
icon1.sprite = "stretched:" + grayscale + "session/portraits/" +template1.icon;
|
||||||
|
|
||||||
|
// Check resource requirements for second button
|
||||||
|
affordableMask1.hidden = true;
|
||||||
|
neededResources = Engine.GuiInterfaceCall("GetNeededResources", template.cost);
|
||||||
|
if (neededResources)
|
||||||
|
{
|
||||||
|
if (button1.enabled !== false)
|
||||||
|
{
|
||||||
|
button1.enabled = false;
|
||||||
|
affordableMask1.hidden = false;
|
||||||
|
}
|
||||||
|
button1.tooltip += getNeededResourcesTooltip(neededResources);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pair.hidden = true;
|
pair.hidden = true;
|
||||||
button1.hidden = true;
|
button1.hidden = true;
|
||||||
|
affordableMask1.hidden = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (guiName == CONSTRUCTION || guiName == TRAINING)
|
||||||
|
{
|
||||||
|
affordableMask.hidden = true;
|
||||||
|
var totalCosts = {};
|
||||||
|
var trainNum = 1;
|
||||||
|
if (Engine.HotkeyIsPressed("session.batchtrain") && guiName == TRAINING)
|
||||||
|
{
|
||||||
|
var [batchSize, batchIncrement] = getTrainingBatchStatus(unitEntState.id, entType);
|
||||||
|
trainNum = batchSize + batchIncrement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Walls have no cost defined.
|
||||||
|
if (template.cost !== undefined)
|
||||||
|
for (var r in template.cost)
|
||||||
|
totalCosts[r] = Math.floor(template.cost[r] * trainNum);
|
||||||
|
|
||||||
|
var neededResources = Engine.GuiInterfaceCall("GetNeededResources", totalCosts);
|
||||||
|
if (neededResources)
|
||||||
|
{
|
||||||
|
var totalCost = 0;
|
||||||
|
if (button.enabled !== false)
|
||||||
|
{
|
||||||
|
for each (var resource in neededResources)
|
||||||
|
totalCost += resource;
|
||||||
|
|
||||||
|
button.enabled = false;
|
||||||
|
affordableMask.hidden = false;
|
||||||
|
var alpha = 75 + totalCost/6;
|
||||||
|
alpha = alpha > 150 ? 150 : alpha;
|
||||||
|
affordableMask.sprite = "colour: 255 0 0 " + (alpha);
|
||||||
|
}
|
||||||
|
button.tooltip += getNeededResourcesTooltip(neededResources);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -718,12 +795,28 @@ function setupUnitBarterPanel(unitEntState)
|
|||||||
var buyPrice = unitEntState.barterMarket.prices["buy"][resource];
|
var buyPrice = unitEntState.barterMarket.prices["buy"][resource];
|
||||||
amountToBuy = "+" + Math.round(sellPrice / buyPrice * amountToSell);
|
amountToBuy = "+" + Math.round(sellPrice / buyPrice * amountToSell);
|
||||||
}
|
}
|
||||||
|
|
||||||
var amount;
|
var amount;
|
||||||
if (j == 0)
|
if (j == 0)
|
||||||
{
|
{
|
||||||
button.onpress = (function(i){ return function() { g_barterSell = i; } })(i);
|
button.onpress = (function(i){ return function() { g_barterSell = i; } })(i);
|
||||||
amount = (i == g_barterSell) ? "-" + amountToSell : "";
|
if (i == g_barterSell)
|
||||||
}
|
{
|
||||||
|
amount = "-" + amountToSell;
|
||||||
|
|
||||||
|
var neededRes = {};
|
||||||
|
neededRes[resource] = amountToSell;
|
||||||
|
var neededResources = Engine.GuiInterfaceCall("GetNeededResources", neededRes);
|
||||||
|
var hidden = neededResources ? false : true;
|
||||||
|
for (var ii = 0; ii < BARTER_RESOURCES.length; ii++)
|
||||||
|
{
|
||||||
|
var affordableMask = getGUIObjectByName("unitBarterBuyUnaffordable["+ii+"]");
|
||||||
|
affordableMask.hidden = hidden;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
amount = "";
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var exchangeResourcesParameters = { "sell": BARTER_RESOURCES[g_barterSell], "buy": BARTER_RESOURCES[i], "amount": amountToSell };
|
var exchangeResourcesParameters = { "sell": BARTER_RESOURCES[g_barterSell], "buy": BARTER_RESOURCES[i], "amount": amountToSell };
|
||||||
|
@ -318,6 +318,18 @@ function getPopulationBonusTooltip(template)
|
|||||||
return popBonus;
|
return popBonus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a message with the amount of each resource needed to create an entity.
|
||||||
|
*/
|
||||||
|
function getNeededResourcesTooltip(resources)
|
||||||
|
{
|
||||||
|
var formatted = [];
|
||||||
|
for (var resource in resources)
|
||||||
|
formatted.push(resources[resource] + " [font=\"serif-12\"]" + getCostComponentDisplayName(resource) + "[/font]");
|
||||||
|
|
||||||
|
return "\n\n[font=\"serif-bold-13\"][color=\"red\"]Insufficient resources:[/color][/font]\n" + formatted.join(", ");
|
||||||
|
}
|
||||||
|
|
||||||
function getEntitySpeed(template)
|
function getEntitySpeed(template)
|
||||||
{
|
{
|
||||||
var speed = "";
|
var speed = "";
|
||||||
|
@ -567,6 +567,14 @@ GuiInterface.prototype.GetStartedResearch = function(player)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Used to show a red square over GUI elements you can't yet afford.
|
||||||
|
GuiInterface.prototype.GetNeededResources = function(player, amounts)
|
||||||
|
{
|
||||||
|
var cmpPlayer = QueryPlayerIDInterface(player, IID_Player);
|
||||||
|
return cmpPlayer.GetNeededResources(amounts);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
GuiInterface.prototype.PushNotification = function(notification)
|
GuiInterface.prototype.PushNotification = function(notification)
|
||||||
{
|
{
|
||||||
this.notifications.push(notification);
|
this.notifications.push(notification);
|
||||||
@ -1617,6 +1625,7 @@ var exposedFunctions = {
|
|||||||
"IsTechnologyResearched": 1,
|
"IsTechnologyResearched": 1,
|
||||||
"CheckTechnologyRequirements": 1,
|
"CheckTechnologyRequirements": 1,
|
||||||
"GetStartedResearch": 1,
|
"GetStartedResearch": 1,
|
||||||
|
"GetNeededResources": 1,
|
||||||
"GetNextNotification": 1,
|
"GetNextNotification": 1,
|
||||||
|
|
||||||
"GetAvailableFormations": 1,
|
"GetAvailableFormations": 1,
|
||||||
|
@ -160,22 +160,30 @@ Player.prototype.AddResources = function(amounts)
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Player.prototype.TrySubtractResources = function(amounts)
|
Player.prototype.GetNeededResources = function(amounts)
|
||||||
{
|
{
|
||||||
// Check if we can afford it all
|
// Check if we can afford it all
|
||||||
var amountsNeeded = {};
|
var amountsNeeded = {};
|
||||||
for (var type in amounts)
|
for (var type in amounts)
|
||||||
if (amounts[type] > this.resourceCount[type])
|
if (this.resourceCount[type] != undefined && amounts[type] > this.resourceCount[type])
|
||||||
amountsNeeded[type] = amounts[type] - this.resourceCount[type];
|
amountsNeeded[type] = amounts[type] - this.resourceCount[type];
|
||||||
|
|
||||||
var formattedAmountsNeeded = [];
|
if (Object.keys(amountsNeeded).length == 0)
|
||||||
for (var type in amountsNeeded)
|
return undefined;
|
||||||
formattedAmountsNeeded.push(type + ": " + amountsNeeded[type]);
|
return amountsNeeded;
|
||||||
|
};
|
||||||
|
|
||||||
|
Player.prototype.TrySubtractResources = function(amounts)
|
||||||
|
{
|
||||||
|
var amountsNeeded = this.GetNeededResources(amounts);
|
||||||
|
|
||||||
// If we don't have enough resources, send a notification to the player
|
// If we don't have enough resources, send a notification to the player
|
||||||
if (formattedAmountsNeeded.length)
|
if (amountsNeeded)
|
||||||
{
|
{
|
||||||
var notification = {"player": this.playerID, "message": "Insufficient resources - " + formattedAmountsNeeded.join(", ")};
|
var formatted = [];
|
||||||
|
for (var type in amountsNeeded)
|
||||||
|
formatted.push(amountsNeeded[type] + " " + type[0].toUpperCase() + type.substr(1) );
|
||||||
|
var notification = {"player": this.playerID, "message": "Insufficient resources - " + formatted.join(", ")};
|
||||||
var cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
|
var cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
|
||||||
cmpGUIInterface.PushNotification(notification);
|
cmpGUIInterface.PushNotification(notification);
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user