From fae4a3da24ce2bfdd85bfbee2d170e82bbed8d25 Mon Sep 17 00:00:00 2001 From: Ykkrosh Date: Sat, 4 Sep 2010 13:24:52 +0000 Subject: [PATCH] Fix #548 (GUI should give feedback when training queue entry is blocked), based on patch from fcxSanya This was SVN commit r8071. --- .../data/mods/public/gui/session_new/session.js | 12 ++++++++++++ .../public/simulation/components/GuiInterface.js | 3 ++- .../mods/public/simulation/components/Player.js | 16 ++++++++++++++++ .../simulation/components/TrainingQueue.js | 16 ++++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/binaries/data/mods/public/gui/session_new/session.js b/binaries/data/mods/public/gui/session_new/session.js index 51bdd4e79b..4d6c62ac8b 100644 --- a/binaries/data/mods/public/gui/session_new/session.js +++ b/binaries/data/mods/public/gui/session_new/session.js @@ -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; } diff --git a/binaries/data/mods/public/simulation/components/GuiInterface.js b/binaries/data/mods/public/simulation/components/GuiInterface.js index a79fc17bb5..e7f3e5833b 100644 --- a/binaries/data/mods/public/simulation/components/GuiInterface.js +++ b/binaries/data/mods/public/simulation/components/GuiInterface.js @@ -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); } diff --git a/binaries/data/mods/public/simulation/components/Player.js b/binaries/data/mods/public/simulation/components/Player.js index fcca86a41c..ac98e6af80 100644 --- a/binaries/data/mods/public/simulation/components/Player.js +++ b/binaries/data/mods/public/simulation/components/Player.js @@ -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; diff --git a/binaries/data/mods/public/simulation/components/TrainingQueue.js b/binaries/data/mods/public/simulation/components/TrainingQueue.js index 0e360ebdd5..3fe8321970 100644 --- a/binaries/data/mods/public/simulation/components/TrainingQueue.js +++ b/binaries/data/mods/public/simulation/components/TrainingQueue.js @@ -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 {