Don't mix locally installed python libs when building
[0ad.git] / binaries / data / mods / public / gui / session / ResearchProgress.js
blob7c82160878bc1e1171b5f593b8969b089361849a
1 /**
2  * This class is responsible for displaying the currently researched technologies in an overlay.
3  */
4 class ResearchProgress
6         constructor(playerViewControl, selection)
7         {
8                 this.buttons = Engine.GetGUIObjectByName("researchStartedButtons").children;
9                 this.buttonHandlers = this.buttons.map((button, i) => new ResearchProgressButton(selection, i));
11                 /**
12                  * Top coordinate of the research list.
13                  * Changes depending on the number of displayed counters.
14                  */
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));
21         }
23         setTopOffset(offset)
24         {
25                 this.topOffset = offset;
26         }
28         updateResearchProgress()
29         {
30                 let researchStarted = Engine.GuiInterfaceCall("GetStartedResearch", g_ViewedPlayer);
32                 let i = 0;
33                 for (let techName in researchStarted)
34                 {
35                         if (i == this.buttons.length)
36                                 break;
38                         this.buttonHandlers[i++].onResearchedProgress(this.topOffset, techName, researchStarted[techName]);
39                 }
41                 while (i < this.buttons.length)
42                         this.buttons[i++].hidden = true;
43         }
46 /**
47  * This is an individual button displaying a tech currently researched by the currently viewed player.
48  */
49 class ResearchProgressButton
51         constructor(selection, i)
52         {
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);
65         }
67         onResearchedProgress(offset, techName, researchStatus)
68         {
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;
96         }
98         onPress()
99         {
100                 this.selection.selectAndMoveTo(this.researcher);
101         }
105  * Distance between consecutive buttons.
106  */
107 ResearchProgressButton.prototype.Margin = 4;
110  * Directory containing all icons.
111  */
112 ResearchProgressButton.prototype.PortraitDirectory = "session/portraits/";
115  * This format is used when displaying the remaining time of the currently viewed techs in research.
116  */
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.");