Index: ps/trunk/binaries/data/mods/public/gui/session/ResearchProgress.js
===================================================================
--- ps/trunk/binaries/data/mods/public/gui/session/ResearchProgress.js
+++ ps/trunk/binaries/data/mods/public/gui/session/ResearchProgress.js
@@ -0,0 +1,107 @@
+/**
+ * This class is responsible for displaying the currently researched technologies in an overlay.
+ */
+class ResearchProgress
+{
+ constructor(playerViewControl)
+ {
+ this.buttons = Engine.GetGUIObjectByName("researchStartedButtons").children;
+ this.buttonHandlers = this.buttons.map((button, i) => new ResearchProgressButton(i));
+
+ /**
+ * Top coordinate of the research list.
+ * Changes depending on the number of displayed counters.
+ */
+ this.topOffset = 0;
+
+ let updater = this.updateResearchProgress.bind(this);
+ registerSimulationUpdateHandler(updater);
+ playerViewControl.registerViewedPlayerChangeHandler(updater);
+ }
+
+ setTopOffset(offset)
+ {
+ this.topOffset = offset;
+ }
+
+ updateResearchProgress()
+ {
+ let researchStarted = Engine.GuiInterfaceCall("GetStartedResearch", g_ViewedPlayer);
+
+ let i = 0;
+ for (let techName in researchStarted)
+ {
+ if (i == this.buttons.length)
+ break;
+
+ this.buttonHandlers[i++].onResearchedProgress(this.topOffset, techName, researchStarted[techName]);
+ }
+
+ while (i < this.buttons.length)
+ this.buttons[i++].hidden = true;
+ }
+}
+
+/**
+ * This is an individual button displaying a tech currently researched by the currently viewed player.
+ */
+class ResearchProgressButton
+{
+ constructor(i)
+ {
+ this.button = Engine.GetGUIObjectByName("researchStartedButton[" + i + "]");
+ this.sprite = Engine.GetGUIObjectByName("researchStartedIcon[" + i + "]");
+ this.progress = Engine.GetGUIObjectByName("researchStartedProgressSlider[" + i + "]");
+ this.timeRemaining = Engine.GetGUIObjectByName("researchStartedTimeRemaining[" + i + "]");
+
+ this.buttonHeight = this.button.size.bottom - this.button.size.top;
+ this.buttonTop = this.Margin + (this.Margin + this.buttonHeight) * i;
+ this.progressHeight = this.progress.size.bottom - this.progress.size.top;
+ this.progressTop = this.progress.size.top;
+ this.button.onPress = this.onPress.bind(this);
+ }
+
+ onResearchedProgress(offset, techName, researchStatus)
+ {
+ this.researcher = researchStatus.researcher;
+
+ let template = GetTechnologyData(techName, g_Players[g_ViewedPlayer].civ);
+ this.sprite.sprite = "stretched:" + this.PortraitDirectory + template.icon;
+
+ let size = this.button.size;
+ size.top = offset + this.buttonTop;
+ size.bottom = size.top + this.buttonHeight;
+ this.button.size = size;
+ this.button.tooltip = getEntityNames(template);
+ this.button.hidden = false;
+
+ size = this.progress.size;
+ size.top = this.progressTop + this.progressHeight * researchStatus.progress;
+ this.progress.size = size;
+
+ this.timeRemaining.caption =
+ Engine.FormatMillisecondsIntoDateStringGMT(
+ researchStatus.timeRemaining,
+ translateWithContext("countdown format", this.CountdownFormat));
+ }
+
+ onPress()
+ {
+ selectAndMoveTo(this.researcher);
+ }
+}
+
+/**
+ * Distance between consecutive buttons.
+ */
+ResearchProgressButton.prototype.Margin = 4;
+
+/**
+ * Directory containing all icons.
+ */
+ResearchProgressButton.prototype.PortraitDirectory = "session/portraits/";
+
+/**
+ * This format is used when displaying the remaining time of the currently viewed techs in research.
+ */
+ResearchProgressButton.prototype.CountdownFormat = markForTranslationWithContext("countdown format", "m:ss");
Index: ps/trunk/binaries/data/mods/public/gui/session/ResearchProgress.xml
===================================================================
--- ps/trunk/binaries/data/mods/public/gui/session/ResearchProgress.xml
+++ ps/trunk/binaries/data/mods/public/gui/session/ResearchProgress.xml
@@ -0,0 +1,10 @@
+
+
Index: ps/trunk/binaries/data/mods/public/gui/session/session.js
===================================================================
--- ps/trunk/binaries/data/mods/public/gui/session/session.js
+++ ps/trunk/binaries/data/mods/public/gui/session/session.js
@@ -21,6 +21,7 @@
var g_PauseControl;
var g_PauseOverlay;
var g_PlayerViewControl;
+var g_ResearchProgress;
var g_TradeDialog;
var g_TopPanel;
@@ -157,12 +158,6 @@
var g_HotkeyChangeHandlers = new Set();
/**
- * Top coordinate of the research list.
- * Changes depending on the number of displayed counters.
- */
-var g_ResearchListTop = 4;
-
-/**
* List of additional entities to highlight.
*/
var g_ShowGuarding = false;
@@ -288,6 +283,7 @@
g_PauseControl = new PauseControl();
g_PauseOverlay = new PauseOverlay(g_PauseControl);
g_Menu = new Menu(g_PauseControl, g_PlayerViewControl, g_Chat);
+ g_ResearchProgress = new ResearchProgress(g_PlayerViewControl);
g_TradeDialog = new TradeDialog(g_PlayerViewControl);
g_TopPanel = new TopPanel(g_PlayerViewControl, g_DiplomacyDialog, g_TradeDialog, g_ObjectivesDialog, g_GameSpeedControl);
@@ -730,7 +726,6 @@
displayPanelEntities();
updateGroups();
- updateResearchDisplay();
updateSelectionDetails();
updateBuildingPlacementPreview();
updateTimeNotifications();
@@ -947,55 +942,6 @@
Engine.CameraMoveTo(position.x, position.z);
}
-function updateResearchDisplay()
-{
- let researchStarted = Engine.GuiInterfaceCall("GetStartedResearch", g_ViewedPlayer);
-
- // Set up initial positioning.
- let buttonSideLength = Engine.GetGUIObjectByName("researchStartedButton[0]").size.right;
- for (let i = 0; i < 10; ++i)
- {
- let button = Engine.GetGUIObjectByName("researchStartedButton[" + i + "]");
- let size = button.size;
- size.top = g_ResearchListTop + (4 + buttonSideLength) * i;
- size.bottom = size.top + buttonSideLength;
- button.size = size;
- }
-
- let numButtons = 0;
- for (let tech in researchStarted)
- {
- // Show at most 10 in-progress techs.
- if (numButtons >= 10)
- break;
-
- let template = GetTechnologyData(tech, g_Players[g_ViewedPlayer].civ);
- let button = Engine.GetGUIObjectByName("researchStartedButton[" + numButtons + "]");
- button.hidden = false;
- button.tooltip = getEntityNames(template);
- button.onpress = (function(e) { return function() { selectAndMoveTo(e); }; })(researchStarted[tech].researcher);
-
- let icon = "stretched:session/portraits/" + template.icon;
- Engine.GetGUIObjectByName("researchStartedIcon[" + numButtons + "]").sprite = icon;
-
- // Scale the progress indicator.
- let size = Engine.GetGUIObjectByName("researchStartedProgressSlider[" + numButtons + "]").size;
-
- // Buttons are assumed to be square, so left/right offsets can be used for top/bottom.
- size.top = size.left + Math.round(researchStarted[tech].progress * (size.right - size.left));
- Engine.GetGUIObjectByName("researchStartedProgressSlider[" + numButtons + "]").size = size;
-
- Engine.GetGUIObjectByName("researchStartedTimeRemaining[" + numButtons + "]").caption =
- Engine.FormatMillisecondsIntoDateStringGMT(researchStarted[tech].timeRemaining, translateWithContext("countdown format", "m:ss"));
-
- ++numButtons;
- }
-
- // Hide unused buttons.
- for (let i = numButtons; i < 10; ++i)
- Engine.GetGUIObjectByName("researchStartedButton[" + i + "]").hidden = true;
-}
-
/**
* Toggles the display of status bars for all of the player's entities.
*
@@ -1152,5 +1098,5 @@
if (simState.ceasefireActive && Engine.ConfigDB_GetValue("user", "gui.session.ceasefirecounter") === "true")
counters.push(timeToString(simState.ceasefireTimeRemaining));
- g_ResearchListTop = 4 + 14 * counters.length;
+ g_ResearchProgress.setTopOffset(14 * counters.length);
}
Index: ps/trunk/binaries/data/mods/public/gui/session/session.xml
===================================================================
--- ps/trunk/binaries/data/mods/public/gui/session/session.xml
+++ ps/trunk/binaries/data/mods/public/gui/session/session.xml
@@ -87,6 +87,7 @@
+
Index: ps/trunk/binaries/data/mods/public/gui/session/session_objects/research_progress.xml
===================================================================
--- ps/trunk/binaries/data/mods/public/gui/session/session_objects/research_progress.xml
+++ ps/trunk/binaries/data/mods/public/gui/session/session_objects/research_progress.xml
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-