2 * This class is responsible for displaying the currently researched technologies in an overlay.
6 constructor(playerViewControl, selection)
8 this.buttons = Engine.GetGUIObjectByName("researchStartedButtons").children;
9 this.buttonHandlers = this.buttons.map((button, i) => new ResearchProgressButton(selection, i));
12 * Top coordinate of the research list.
13 * Changes depending on the number of displayed counters.
15 this.topOffset = g_OverlayCounterManager.lastHeight;
17 let updater = this.updateResearchProgress.bind(this);
18 registerSimulationUpdateHandler(updater);
19 playerViewControl.registerViewedPlayerChangeHandler(updater);
20 g_OverlayCounterManager.registerResizeHandler(this.setTopOffset.bind(this));
25 this.topOffset = offset;
28 updateResearchProgress()
30 let researchStarted = Engine.GuiInterfaceCall("GetStartedResearch", g_ViewedPlayer);
33 for (let techName in researchStarted)
35 if (i == this.buttons.length)
38 this.buttonHandlers[i++].onResearchedProgress(this.topOffset, techName, researchStarted[techName]);
41 while (i < this.buttons.length)
42 this.buttons[i++].hidden = true;
47 * This is an individual button displaying a tech currently researched by the currently viewed player.
49 class ResearchProgressButton
51 constructor(selection, i)
53 this.selection = selection;
54 this.button = Engine.GetGUIObjectByName("researchStartedButton[" + i + "]");
55 this.sprite = Engine.GetGUIObjectByName("researchStartedIcon[" + i + "]");
56 this.progress = Engine.GetGUIObjectByName("researchStartedProgressSlider[" + i + "]");
57 this.timeRemaining = Engine.GetGUIObjectByName("researchStartedTimeRemaining[" + i + "]");
58 this.paused = Engine.GetGUIObjectByName("researchPausedIcon[" + i + "]");
60 this.buttonHeight = this.button.size.bottom - this.button.size.top;
61 this.buttonTop = this.Margin + (this.Margin + this.buttonHeight) * i;
62 this.progressHeight = this.progress.size.bottom - this.progress.size.top;
63 this.progressTop = this.progress.size.top;
64 this.button.onPress = this.onPress.bind(this);
67 onResearchedProgress(offset, techName, researchStatus)
69 this.researcher = researchStatus.researcher;
71 let template = GetTechnologyData(techName, g_Players[g_ViewedPlayer].civ);
72 let modifier = "stretched:";
73 if (researchStatus.paused)
74 modifier += "color:0 0 0 127:grayscale:";
75 this.sprite.sprite = modifier + this.PortraitDirectory + template.icon;
77 let size = this.button.size;
78 size.top = offset + this.buttonTop;
79 size.bottom = size.top + this.buttonHeight;
80 this.button.size = size;
81 this.button.tooltip = getEntityNames(template);
82 if (researchStatus.paused)
83 this.button.tooltip += "\n" + translate(this.PausedResearchString);
84 this.button.hidden = false;
86 size = this.progress.size;
87 size.top = this.progressTop + this.progressHeight * researchStatus.progress;
88 this.progress.size = size;
90 this.timeRemaining.caption =
91 Engine.FormatMillisecondsIntoDateStringGMT(
92 researchStatus.timeRemaining,
93 translateWithContext("countdown format", this.CountdownFormat));
95 this.paused.hidden = !researchStatus.paused;
100 this.selection.selectAndMoveTo(this.researcher);
105 * Distance between consecutive buttons.
107 ResearchProgressButton.prototype.Margin = 4;
110 * Directory containing all icons.
112 ResearchProgressButton.prototype.PortraitDirectory = "session/portraits/";
115 * This format is used when displaying the remaining time of the currently viewed techs in research.
117 ResearchProgressButton.prototype.CountdownFormat = markForTranslationWithContext("countdown format", "m:ss");
119 // Translation: String displayed when the research is paused. E.g. by being garrisoned or when not the first item in the queue.
120 ResearchProgressButton.prototype.PausedResearchString = markForTranslation("This item is paused.");