Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
Display idle units in top panel Fix #130
Browse files Browse the repository at this point in the history
  • Loading branch information
LangLangBart committed Sep 29, 2022
1 parent c256dd1 commit 6a2978d
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 87 deletions.
Binary file added audio/interface/alarm/alarm_no_idle_unit_01.ogg
Binary file not shown.
9 changes: 9 additions & 0 deletions gui/session/boonGUI_XML/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@
text_valign="center"
tooltip_style="sessionToolTipCircle"
/>
<style
name="overlayBoldMedium"
font="sans-bold-stroke-16"
ghost="true"
textcolor="250 250 250"
text_align="center"
text_valign="center"
tooltip_style="sessionToolTipCircle"
/>
<style
name="overlaySmall"
font="sans-stroke-14"
Expand Down
4 changes: 4 additions & 0 deletions gui/session/hotkeys/misc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
<action on="KeyDown">findIdleUnit(g_MilitaryTypes);</action>
</object>

<object hotkey="selection.idleworker">
<action on="KeyDown">findIdleUnit(g_boonGUI_WorkerTypes);</action>
</object>

<object hotkey="selection.idleunit">
<action on="KeyDown">findIdleUnit(["!Domestic"]);</action>
</object>
Expand Down
20 changes: 0 additions & 20 deletions gui/session/minimap/MiniMap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,6 @@
</object>
<!-- Hover panel below the minimap -->
<object name="hoverPanel" type="image" sprite="minimapHoverPanel">
<!-- Idle Worker Button -->
<object
name="idleWorkerButton"
type="button"
size="84% 6% 98% 60%+1"
tooltip_style="sessionToolTipCircleBottom"
hotkey="selection.idleworker"
sprite="stretched:session/minimap-idle.png"
sprite_over="stretched:session/minimap-idle-highlight.png"
sprite_disabled="stretched:session/minimap-idle-disabled.png"
mouse_event_mask="texture:session/minimap-idle.png"
sound_pressed="audio/interface/ui/ui_button_click.ogg">
<!-- Total number of idle workers -->
<object
name="totalNumberIdleWorkers"
type="text"
style="resourceIdleWorker"
z="0"
/>
</object>
<!-- Flare Button -->
<object
name="flareButton"
Expand Down
10 changes: 0 additions & 10 deletions gui/session/minimap/MiniMapIdleWorkerButton~boongui.js

This file was deleted.

1 change: 0 additions & 1 deletion gui/session/minimap/MiniMapPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class MiniMapPanel
{
this.diplomacyColorsButton = new MiniMapDiplomacyColorsButton(diplomacyColors);
this.scoreButton = new MiniMapScoreButton();
this.idleWorkerButton = new MiniMapIdleWorkerButton(playerViewControl, idleWorkerClasses);
this.flareButton = new MiniMapFlareButton(playerViewControl);
this.miniMap = new MiniMap();
this.minimapPanel = Engine.GetGUIObjectByName("minimapPanel");
Expand Down
4 changes: 4 additions & 0 deletions gui/session/session~boongui.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
let g_stats;

// difference to 0AD's g_WorkerTypes is the exclusion of mercenaries
var g_boonGUI_WorkerTypes = ["FemaleCitizen", "Trader", "FishingBoat", "Citizen+!Mercenary"];


autociv_patchApplyN("init", function(target, that, args) {
const result = target.apply(that, args);
g_stats = new BoonGUIStats(g_PlayerViewControl);
Expand Down
6 changes: 4 additions & 2 deletions gui/session/stats/BoonGUIColorScales.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ class BoonGUIColorScales {
* @param {number} value
* @param {number} alpha
*/
getColor(key, value, alpha = 255) {
getColor(key, value, reverse = false, alpha = 255) {
const scale = this.scales.get(key);
if (!scale) return "white";
const range = scale.max - scale.min;
if (range === 0 || !isFinite(range) || value == null) return "white";
let percent = (value - scale.min) / range;
if (isNaN(percent)) return null;
percent = percent < 0 ? 0 : percent > 1 ? 1 : percent;
if (reverse)
percent = 1 - percent;
let r, g, b;
if (percent <= 0.5)
{
Expand All @@ -57,4 +59,4 @@ class BoonGUIColorScales {
}
return `${r} ${g} ${b} ${alpha}`;
}
}
}
5 changes: 3 additions & 2 deletions gui/session/stats/BoonGUIStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ class BoonGUIStats
this.shortGameInfoLabel.hidden = !g_IsObserver && !this.playerViewControl.changePerspective;
const shortGameInfoLabelPAD = this.shortGameInfoLabel.hidden ? "" : this.shortGameInfoLabel.size.bottom;
let y = (26 * (length + 1) + shortGameInfoLabelPAD);
this.statsTopPanel.root.size = `0 ${shortGameInfoLabelPAD} 935 ${y}`;
const shortGameInfoLabel_width = Engine.GetGUIObjectByName("shortGameInfoLabel").size.right;
this.statsTopPanel.root.size = `0 ${shortGameInfoLabelPAD} ${shortGameInfoLabel_width} ${y}`;
y = this.statsTopPanel.root.size.bottom + PAD;

const panelEntityButtons = Engine.GetGUIObjectByName("panelEntityButtons");
Expand Down Expand Up @@ -185,7 +186,7 @@ class BoonGUIStats
getPlayersStates()
{
return Engine.GuiInterfaceCall("boongui_GetOverlay", {
g_IsObserver, g_ViewedPlayer, g_LastTickTime
g_IsObserver, g_ViewedPlayer, g_LastTickTime, g_boonGUI_WorkerTypes
}).players ?? [];
}

Expand Down
2 changes: 1 addition & 1 deletion gui/session/stats/BoonGUIStats.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<object
name="shortGameInfoLabel"
type="text"
size="0 -10 935 25"
size="0 -10 965 25"
sprite="prettyBackgroundColor"
style="infoGameLabels"
/>
Expand Down
59 changes: 43 additions & 16 deletions gui/session/stats/BoonGUIStatsTopPanelRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class BoonGUIStatsTopPanelRow
this.popHighlight = Engine.GetGUIObjectByName(`${PREFIX}_popHighlight`);
this.popCount = Engine.GetGUIObjectByName(`${PREFIX}_popCount`);
this.popLimit = Engine.GetGUIObjectByName(`${PREFIX}_popLimit`);
this.idleUnitsHighlight = Engine.GetGUIObjectByName(`${PREFIX}_idleUnitsHighlight`);
// TODO, in observer mode the idle button is disabled, it shouldn't be.
this.idleUnitsHighlight.onPress = () => findIdleUnit(g_boonGUI_WorkerTypes);
this.idleUnitsCount = Engine.GetGUIObjectByName(`${PREFIX}_idleUnitsCount`);
this.idleRedIndicatorOverlay = Engine.GetGUIObjectByName(`${PREFIX}_idleRedIndicatorOverlay`);

this.resource = {
"counts": {},
Expand Down Expand Up @@ -86,7 +91,7 @@ class BoonGUIStatsTopPanelRow
this.coloredTeamBackground.sprite = `backcolor: ${state.teamColor} 115`;
this.coloredPlayerInfoBackground.sprite = `backcolor: ${state.playerColor} 115`;
this.coloredTeamBackground.hidden = state.team == -1;
// why doesn't this.coloredPlayerInfoBackground.size.left work ?

this.coloredPlayerInfoBackground.size = state.team != -1 ? "18 0 235 100%" : "0 0 235 100%";
this.team.caption = state.team != -1 ? `${state.team + 1}` : "";

Expand All @@ -96,10 +101,9 @@ class BoonGUIStatsTopPanelRow
this.playerHighlight.tooltip = setStringTags(state.name, { "color": state.playerColor });
this.playerHighlight.tooltip += state.team != -1 ? setStringTags("\nTeam " + this.team.caption, { "color": state.teamColor }) : "";
caption = Engine.IsAtlasRunning() ? "" : `${translateAISettings(g_InitAttributes.settings.PlayerData[state.index])}`;
font = "sans-stroke-14";
if (caption)
{
this.playerHighlight.tooltip += setStringTags(`\n${caption}`, { "color": "210 210 210", "font": "sans-stroke-14" });
}
this.playerHighlight.tooltip += setStringTags(`\n${caption}`, { "color": "210 210 210", font });

this.team.tooltip = this.playerHighlight.tooltip;
this.rating.tooltip = this.playerHighlight.tooltip;
Expand All @@ -114,7 +118,6 @@ class BoonGUIStatsTopPanelRow
tooltip += playerNick + "\n\n";
tooltip += `[icon="${Emblem}" displace="12 0"] \n`;
tooltip += `${civ.Name.padEnd(8)}\n`;
font = "sans-stroke-14";
tooltip += setStringTags(this.civIconHotkeyTooltip, { font });
this.civHighlight.tooltip = tooltip;

Expand Down Expand Up @@ -195,20 +198,41 @@ class BoonGUIStatsTopPanelRow
{
value = state.popCount;
color = scales.getColor("popCount", state.popCount);
this.popCount.caption = setStringTags(value, { "color": color }) + "/";
this.popCount.caption = setStringTags(normalizeValue(value), { "color": color }) + "/";
value = state.popLimit;
color = scales.getColor("popLimit", state.popCount);
this.popLimit.caption = setStringTags(value, { "color": color });
color = scales.getColor("popLimit", state.popLimit);
this.popLimit.caption = setStringTags(normalizeValue(value), { "color": color });
}
tooltip += "Pop" + g_Indent + g_Indent + " " + `${this.popCount.caption} ${this.popLimit.caption}\n`;
tooltip += "Max" + g_Indent + g_Indent + state.popMax;
tooltip += "Max" + g_Indent + g_Indent + normalizeValue(state.popMax);

this.popHighlight.tooltip = tooltip;

tooltip = "";
tooltip += playerNick + "\n";
value = state.idleUnits;
this.idleUnitsHighlight.enabled = g_ViewedPlayer == state.index;

this.idleRedIndicatorOverlay.sprite = "color:255 0 0 " + (Math.min(value, 18) * 10);
color = value > 0 ? "255 100 100" : "dimmedWhite";
font = value > 0 ? value > 99 ? "sans-bold-stroke-14" : "sans-bold-stroke-16" : "sans-stroke-14";
this.idleUnitsCount.caption = setStringTags(normalizeValue(value), { color, font });

tooltip += "Idle Worker" + g_Indent + g_Indent + " " + setStringTags(value, { color }) + "\n\n";
tooltip += "Counting:\n";
font = "sans-stroke-14";
for (const i in g_boonGUI_WorkerTypes)
{
tooltip += setStringTags(`- ${g_boonGUI_WorkerTypes[i]}\n`, { font });
}

tooltip += "\n" + setStringTags(this.idleUnitsTooltip, { font });
this.idleUnitsHighlight.tooltip = tooltip;


for (const resType of g_BoonGUIResTypes)
{
tooltip = "";
tooltip += playerNick + "\n";
tooltip += resourceNameFirstWord(resType) + " " + resourceIcon(resType) + "\n";

if (state.resourcesTechs[resType].length > 0)
Expand All @@ -228,15 +252,15 @@ class BoonGUIStatsTopPanelRow
const configResourceGatherersRates = Engine.ConfigDB_GetValue("user", "boongui.toppanel.resourceGatherersRates");

value = state.resourceGatherers[resType];
color = scales.getColor(`${resType}Gatherers`, value, 180);
color = scales.getColor(`${resType}Gatherers`, value, false, 180);
caption = isNaN(value) || value <= 0 ? setStringTags("0", { "color": "dimmedWhite" }) : value;
// For single lines, the gathering rates are displayed in the player color.
colorSingleRow = setStringTags(caption, (g_stats.lastPlayerLength > 1) ? { color } : { "color": state.playerColor });
this.resource.gatherers[resType].caption = configResourceGatherersRates === "Gatherers" ? colorSingleRow : "";
tooltip += setStringTags("Gatherers", { "color": value > 0 ? "white" : "dimmedWhite" }) + `${g_Indent}${g_Indent}${colorSingleRow}\n`;

value = state.resourceRates[resType];
color = scales.getColor(`${resType}Rates`, value, 180);
color = scales.getColor(`${resType}Rates`, value, false, 180);
caption = isNaN(value) || value <= 0 ? setStringTags("+0", { "color": "dimmedWhite" }) : `+${normalizeValue(value)}`;
colorSingleRow = setStringTags(caption, (g_stats.lastPlayerLength > 1) ? { color } : { "color": state.playerColor });
this.resource.rates[resType].caption = configResourceGatherersRates === "Rates" ? colorSingleRow : "";
Expand All @@ -247,23 +271,23 @@ class BoonGUIStatsTopPanelRow

value = state.classCounts.FemaleCitizen ?? 0;
color = scales.getColor("femaleCitizen", value);
this.femaleCitizen.caption = setStringTags(value, { color });
this.femaleCitizen.caption = setStringTags(normalizeValue(value), { color });
tooltip = "";
tooltip += playerNick + "\n";
tooltip += "Female Citizen" + g_Indent + this.femaleCitizen.caption;
this.femaleCitizenHighlight.tooltip = tooltip;

value = state.classCounts.Infantry ?? 0;
color = scales.getColor("infantry", value);
this.infantry.caption = setStringTags(value, { color });
this.infantry.caption = setStringTags(normalizeValue(value), { color });
tooltip = "";
tooltip += playerNick + "\n";
tooltip += "Infantry" + g_Indent + this.infantry.caption;
this.infantryHighlight.tooltip = tooltip;

value = state.classCounts.Cavalry ?? 0;
color = scales.getColor("cavalry", value);
this.cavalry.caption = setStringTags(value, { color });
this.cavalry.caption = setStringTags(normalizeValue(value), { color });
tooltip = "";
tooltip += playerNick + "\n";
tooltip += "Cavalry" + g_Indent + this.cavalry.caption;
Expand Down Expand Up @@ -323,7 +347,7 @@ class BoonGUIStatsTopPanelRow
color = scales.getColor("enemyUnitsKilledTotal", value);
this.enemyUnitsKilledTotal.caption = setStringTags(normalizeValue(value), { color });
value = state.unitsLostTotal;
color = scales.getColor("unitsLostTotal", value);
color = scales.getColor("unitsLostTotal", value, true);
this.unitsLostTotal.caption = setStringTags(normalizeValue(value), { color });
this.divideSign.caption = "|";

Expand Down Expand Up @@ -354,3 +378,6 @@ BoonGUIStatsTopPanelRow.prototype.civInfo = {
"civ": "",
"page": "page_structree.xml"
};

BoonGUIStatsTopPanelRow.prototype.idleUnitsTooltip = markForTranslation("Cycle through the idle workers of the player being viewed.\n" + colorizeHotkey("%(hotkey)s" + " ", "selection.idleworker"));

Loading

0 comments on commit 6a2978d

Please sign in to comment.