mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-07-12 04:55:29 +00:00
Adding new function to show status messages for lacking resources when building and training units.
This was SVN commit r6231.
This commit is contained in:
@@ -731,7 +731,8 @@ function performHeal( evt )
|
||||
// Make sure we have enough resources.
|
||||
if ( pool[resource] - evt.target.actions.heal.cost * evt.target.traits.creation.cost[resource] < 0 )
|
||||
{
|
||||
console.write( "Not enough " + resource.toString() + " for healing." );
|
||||
//console.write( "Not enough " + resource.toString() + " for healing." );
|
||||
showMessage("Not enough " + resource.toString() + " for healing.");
|
||||
return;
|
||||
}
|
||||
break;
|
||||
@@ -836,7 +837,8 @@ function performRepair( evt )
|
||||
var amount = parseInt( fraction * parseInt(resources[r]) );
|
||||
if( this.player.resources[r.toString()] < amount )
|
||||
{
|
||||
console.write("Can't repair - not enough " + r.toString());
|
||||
//console.write("Can't repair - not enough " + r.toString());
|
||||
showMessage("Can't repair - not enough " + r.toString());
|
||||
evt.preventDefault();
|
||||
return;
|
||||
}
|
||||
@@ -1451,7 +1453,8 @@ function entityStartProduction( evt )
|
||||
else
|
||||
{
|
||||
// If not, output the error message.
|
||||
console.write(result);
|
||||
//console.write(result);
|
||||
showMessage(result);
|
||||
evt.preventDefault();
|
||||
return;
|
||||
}
|
||||
@@ -1481,7 +1484,8 @@ function entityStartProduction( evt )
|
||||
var res = TECH_RESOURCES[i];
|
||||
if( this.player.resources[res] < tech[res] )
|
||||
{
|
||||
console.write( "Cannot afford " + evt.name + ": need " + tech[res] + " " + res );
|
||||
//console.write( "Cannot afford " + evt.name + ": need " + tech[res] + " " + res );
|
||||
showMessage( "Cannot afford " + evt.name + ": need " + tech[res] + " " + res );
|
||||
evt.preventDefault();
|
||||
return;
|
||||
}
|
||||
@@ -1732,7 +1736,8 @@ function attemptAddToBuildQueue( entity, create_tag, tab, list )
|
||||
}
|
||||
else
|
||||
{ // If not, output the error message.
|
||||
console.write(result);
|
||||
//console.write(result);
|
||||
showMessage(result);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -2226,3 +2231,67 @@ function getBuildingLimit( category/*, gameMode*/ )
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Not exactly entity related funcions, but I wanted it to be accessible from gui/test/ and scripts/ scripts, as they have
|
||||
* to call this function. If anyone know of better place for these functions, please tell me.
|
||||
*/
|
||||
|
||||
/*
|
||||
* showMessage(string) - This function should be used when there is some info that should be showed to the user.
|
||||
* It is used for example for informing the user about the lack of resources for building or training a unit.
|
||||
* The message gets removed after WAIT milliseconds.
|
||||
*/
|
||||
|
||||
const MAX_MESSAGES = 6; //max. messages at a time.
|
||||
const WAIT = 15000; //during what time a message will be shown.
|
||||
|
||||
var messagesList = new Array();
|
||||
|
||||
function showMessage(text)
|
||||
{
|
||||
var message = getGUIObjectByName("globalMessage");
|
||||
|
||||
if (messagesList.length == MAX_MESSAGES)
|
||||
{
|
||||
messagesList.pop();
|
||||
}
|
||||
|
||||
messagesList.unshift(text);
|
||||
updateMessageView();
|
||||
message.hidden = false;
|
||||
|
||||
/*
|
||||
* This is made so only the first message, calls hideMessage().
|
||||
*/
|
||||
if (messagesList.length == 1)
|
||||
{
|
||||
setTimeout(hideMessage, WAIT);
|
||||
}
|
||||
}
|
||||
|
||||
function hideMessage()
|
||||
{
|
||||
messagesList.pop();
|
||||
|
||||
if (messagesList.length == 0)
|
||||
{
|
||||
getGUIObjectByName("globalMessage").hidden = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
updateMessageView();
|
||||
setTimeout(hideMessage, WAIT);
|
||||
}
|
||||
}
|
||||
|
||||
function updateMessageView()
|
||||
{
|
||||
var result = "";
|
||||
for (var i=0; i < messagesList.length; i++)
|
||||
{
|
||||
result = result + messagesList[i] + "\n";
|
||||
}
|
||||
getGUIObjectByName("globalMessage").caption = result;
|
||||
}
|
||||
Reference in New Issue
Block a user