mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 21:34:08 -07:00
Fix #548 (GUI should give feedback when training queue entry is blocked), based on patch from fcxSanya
This was SVN commit r8071.
This commit is contained in:
parent
0fa0181f0c
commit
fae4a3da24
4 changed files with 46 additions and 1 deletions
|
|
@ -10,6 +10,10 @@ var g_DevSettings = {
|
|||
controlAll: false
|
||||
};
|
||||
|
||||
// Indicate when one of the current player's training queues is blocked
|
||||
// (this is used to support population counter blinking)
|
||||
var g_IsTrainingQueueBlocked = false;
|
||||
|
||||
// Cache EntityStates
|
||||
var g_EntityStates = {}; // {id:entState}
|
||||
|
||||
|
|
@ -107,6 +111,12 @@ function onTick()
|
|||
|
||||
// Run timers
|
||||
updateTimers();
|
||||
|
||||
// When training is blocked, flash population (alternates colour every 500msec)
|
||||
if (g_IsTrainingQueueBlocked && (Date.now() % 1000) < 500)
|
||||
getGUIObjectByName("resourcePop").textcolor = "255 0 0";
|
||||
else
|
||||
getGUIObjectByName("resourcePop").textcolor = "0 0 0";
|
||||
}
|
||||
|
||||
function onSimulationUpdate()
|
||||
|
|
@ -169,4 +179,6 @@ function updatePlayerDisplay(simState)
|
|||
getGUIObjectByName("resourceStone").caption = playerState.resourceCounts.stone;
|
||||
getGUIObjectByName("resourceMetal").caption = playerState.resourceCounts.metal;
|
||||
getGUIObjectByName("resourcePop").caption = playerState.popCount + "/" + playerState.popLimit;
|
||||
|
||||
g_IsTrainingQueueBlocked = playerState.trainingQueueBlocked;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,8 @@ GuiInterface.prototype.GetSimulationState = function(player)
|
|||
"color": cmpPlayer.GetColour(),
|
||||
"popCount": cmpPlayer.GetPopulationCount(),
|
||||
"popLimit": cmpPlayer.GetPopulationLimit(),
|
||||
"resourceCounts": cmpPlayer.GetResourceCounts()
|
||||
"resourceCounts": cmpPlayer.GetResourceCounts(),
|
||||
"trainingQueueBlocked": cmpPlayer.IsTrainingQueueBlocked()
|
||||
};
|
||||
ret.players.push(playerData);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ Player.prototype.Init = function()
|
|||
this.popUsed = 0; // population of units owned by this player
|
||||
this.popReserved = 0; // population of units currently being trained
|
||||
this.popLimit = 50; // maximum population
|
||||
this.trainingQueueBlocked = false; // indicates whether any training queue is currently blocked
|
||||
this.resourceCount = {
|
||||
"food": 2000,
|
||||
"wood": 1500,
|
||||
|
|
@ -84,6 +85,21 @@ Player.prototype.GetPopulationLimit = function()
|
|||
return this.popLimit;
|
||||
};
|
||||
|
||||
Player.prototype.IsTrainingQueueBlocked = function()
|
||||
{
|
||||
return this.trainingQueueBlocked;
|
||||
};
|
||||
|
||||
Player.prototype.BlockTrainingQueue = function()
|
||||
{
|
||||
this.trainingQueueBlocked = true;
|
||||
};
|
||||
|
||||
Player.prototype.UnBlockTrainingQueue = function()
|
||||
{
|
||||
this.trainingQueueBlocked = false;
|
||||
};
|
||||
|
||||
Player.prototype.GetResourceCounts = function()
|
||||
{
|
||||
return this.resourceCount;
|
||||
|
|
|
|||
|
|
@ -156,6 +156,11 @@ TrainingQueue.prototype.ResetQueue = function()
|
|||
|
||||
TrainingQueue.prototype.OnOwnershipChanged = function(msg)
|
||||
{
|
||||
// Unset flag that previous owner's training queue may be blocked
|
||||
var cmpPlayer = QueryPlayerIDInterface(msg.from, IID_Player);
|
||||
if (cmpPlayer && this.queue.length > 0)
|
||||
cmpPlayer.UnBlockTrainingQueue();
|
||||
|
||||
// Reset the training queue whenever the owner changes.
|
||||
// (This should prevent players getting surprised when they capture
|
||||
// an enemy building, and then loads of the enemy's civ's soldiers get
|
||||
|
|
@ -250,9 +255,16 @@ TrainingQueue.prototype.ProgressTimeout = function(data)
|
|||
{
|
||||
// No slots available - don't train this batch now
|
||||
// (we'll try again on the next timeout)
|
||||
|
||||
// Set flag that training queue is blocked
|
||||
cmpPlayer.BlockTrainingQueue();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// Unset flag that training queue is blocked
|
||||
cmpPlayer.UnBlockTrainingQueue();
|
||||
|
||||
item.trainingStarted = true;
|
||||
}
|
||||
|
||||
|
|
@ -274,6 +286,10 @@ TrainingQueue.prototype.ProgressTimeout = function(data)
|
|||
if (this.queue.length == 0)
|
||||
{
|
||||
this.timer = undefined;
|
||||
|
||||
// Unset flag that training queue is blocked
|
||||
// (This might happen when the player unqueues all batches)
|
||||
cmpPlayer.UnBlockTrainingQueue();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue