Changeset View
Standalone View
binaries/data/mods/public/gui/session/selection_panels.js
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | g_SelectionPanels.Alert = { | ||||
}, | }, | ||||
"getItems": function(unitEntStates) | "getItems": function(unitEntStates) | ||||
{ | { | ||||
return unitEntStates.some(state => !!state.alertRaiser) ? ["raise", "end"] : []; | return unitEntStates.some(state => !!state.alertRaiser) ? ["raise", "end"] : []; | ||||
}, | }, | ||||
"setupButton": function(data) | "setupButton": function(data) | ||||
{ | { | ||||
data.button.onPress = function() { | data.button.onPress = function() { | ||||
switch (data.item) | switch (data.item) | ||||
Lint: ESLintBear (default-case): `Expected a default case.` | |||||
{ | { | ||||
case "raise": | case "raise": | ||||
raiseAlert(); | raiseAlert(); | ||||
return; | return; | ||||
case "end": | case "end": | ||||
endOfAlert(); | endOfAlert(); | ||||
return; | return; | ||||
} | } | ||||
}; | }; | ||||
switch (data.item) | switch (data.item) | ||||
Lint: ESLintBear (default-case) Expected a default case. Lint: ESLintBear (default-case): `Expected a default case.` | |||||
{ | { | ||||
case "raise": | case "raise": | ||||
data.icon.sprite = "stretched:session/icons/bell_level1.png"; | data.icon.sprite = "stretched:session/icons/bell_level1.png"; | ||||
data.button.tooltip = translate("Raise an alert!"); | data.button.tooltip = translate("Raise an alert!"); | ||||
break; | break; | ||||
case "end": | case "end": | ||||
data.button.tooltip = translate("End of alert."); | data.button.tooltip = translate("End of alert."); | ||||
data.icon.sprite = "stretched:session/icons/bell_level0.png"; | data.icon.sprite = "stretched:session/icons/bell_level0.png"; | ||||
▲ Show 20 Lines • Show All 555 Lines • ▼ Show 20 Lines | "getItems": function(unitEntStates) | ||||
if (unitEntStates.length == 1) | if (unitEntStates.length == 1) | ||||
return !unitEntStates[0].production || !unitEntStates[0].production.technologies ? ret : | return !unitEntStates[0].production || !unitEntStates[0].production.technologies ? ret : | ||||
unitEntStates[0].production.technologies.map(tech => ({ | unitEntStates[0].production.technologies.map(tech => ({ | ||||
"tech": tech, | "tech": tech, | ||||
"techCostMultiplier": unitEntStates[0].production.techCostMultiplier, | "techCostMultiplier": unitEntStates[0].production.techCostMultiplier, | ||||
"researchFacilityId": unitEntStates[0].id | "researchFacilityId": unitEntStates[0].id | ||||
})); | })); | ||||
for (let state of unitEntStates) | for (let state of unitEntStates) | ||||
Not Done Inline ActionsFiltered, not sorted. Freagarach: Filtered, not sorted. | |||||
Done Inline Actionsthey are sorted, first the ones not upgrading and then the ones upgrading Silier: they are sorted, first the ones not upgrading and then the ones upgrading | |||||
Not Done Inline ActionsYou are right, my bad. Freagarach: You are right, my bad. | |||||
{ | { | ||||
if (!state.production || !state.production.technologies) | if (!state.production || !state.production.technologies) | ||||
continue; | continue; | ||||
// Remove the techs we already have in ret (with the same name and techCostMultiplier) | // Remove the techs we already have in ret (with the same name and techCostMultiplier) | ||||
let filteredTechs = state.production.technologies.filter( | let filteredTechs = state.production.technologies.filter( | ||||
tech => tech != null && !ret.some( | tech => tech != null && !ret.some( | ||||
item => | item => | ||||
(item.tech == tech || | (item.tech == tech || | ||||
item.tech.pair && | item.tech.pair && | ||||
tech.pair && | tech.pair && | ||||
item.tech.bottom == tech.bottom && | item.tech.bottom == tech.bottom && | ||||
item.tech.top == tech.top) && | item.tech.top == tech.top) && | ||||
Object.keys(item.techCostMultiplier).every( | Object.keys(item.techCostMultiplier).every( | ||||
k => item.techCostMultiplier[k] == state.production.techCostMultiplier[k]) | k => item.techCostMultiplier[k] == state.production.techCostMultiplier[k]) | ||||
)); | )); | ||||
if (filteredTechs.length + ret.length <= this.getMaxNumberOfItems() && | if (filteredTechs.length + ret.length <= this.getMaxNumberOfItems() && | ||||
getNumberOfRightPanelButtons() <= this.getMaxNumberOfItems() * (filteredTechs.some(tech => !!tech.pair) ? 1 : 2)) | getNumberOfRightPanelButtons() <= this.getMaxNumberOfItems() * (filteredTechs.some(tech => !!tech.pair) ? 1 : 2)) | ||||
ret = ret.concat(filteredTechs.map(tech => ({ | ret = ret.concat(filteredTechs.map(tech => ({ | ||||
"tech": tech, | "tech": tech, | ||||
"techCostMultiplier": state.production.techCostMultiplier, | "techCostMultiplier": state.production.techCostMultiplier, | ||||
"researchFacilityId": state.id | "researchFacilityId": state.id | ||||
}))); | }))); | ||||
Not Done Inline ActionsYou already filter those above, right? Freagarach: You already filter those above, right? | |||||
Done Inline Actionsno, i did not Silier: no, i did not | |||||
} | } | ||||
return ret; | return ret; | ||||
}, | }, | ||||
"hideItem": function(i, rowLength) // Called when no item is found | "hideItem": function(i, rowLength) // Called when no item is found | ||||
{ | { | ||||
Engine.GetGUIObjectByName("unitResearchButton[" + i + "]").hidden = true; | Engine.GetGUIObjectByName("unitResearchButton[" + i + "]").hidden = true; | ||||
// We also remove the paired tech and the pair symbol | // We also remove the paired tech and the pair symbol | ||||
Engine.GetGUIObjectByName("unitResearchButton[" + (i + rowLength) + "]").hidden = true; | Engine.GetGUIObjectByName("unitResearchButton[" + (i + rowLength) + "]").hidden = true; | ||||
Engine.GetGUIObjectByName("unitResearchPair[" + i + "]").hidden = true; | Engine.GetGUIObjectByName("unitResearchPair[" + i + "]").hidden = true; | ||||
}, | }, | ||||
"setupButton": function(data) | "setupButton": function(data) | ||||
{ | { | ||||
if (!data.item.tech) | if (!data.item.tech) | ||||
{ | { | ||||
g_SelectionPanels.Research.hideItem(data.i, data.rowLength); | g_SelectionPanels.Research.hideItem(data.i, data.rowLength); | ||||
return false; | return false; | ||||
} | } | ||||
// Start position (start at the bottom) | // Start position (start at the bottom) | ||||
Not Done Inline ActionsisUpgrading bb: isUpgrading | |||||
let position = data.i + data.rowLength; | let position = data.i + data.rowLength; | ||||
// Only show the top button for pairs | // Only show the top button for pairs | ||||
if (!data.item.tech.pair) | if (!data.item.tech.pair) | ||||
Engine.GetGUIObjectByName("unitResearchButton[" + data.i + "]").hidden = true; | Engine.GetGUIObjectByName("unitResearchButton[" + data.i + "]").hidden = true; | ||||
// Set up the tech connector | // Set up the tech connector | ||||
let pair = Engine.GetGUIObjectByName("unitResearchPair[" + data.i + "]"); | let pair = Engine.GetGUIObjectByName("unitResearchPair[" + data.i + "]"); | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | for (let tech of data.item.tech.pair ? [data.item.tech.bottom, data.item.tech.top] : [data.item.tech]) | ||||
{ | { | ||||
if (!req.entities) | if (!req.entities) | ||||
continue; | continue; | ||||
let entityCounts = []; | let entityCounts = []; | ||||
for (let entity of req.entities) | for (let entity of req.entities) | ||||
{ | { | ||||
let current = 0; | let current = 0; | ||||
switch (entity.check) | switch (entity.check) | ||||
Lint: ESLintBear (default-case) Expected a default case. Lint: ESLintBear (default-case): `Expected a default case.` | |||||
{ | { | ||||
case "count": | case "count": | ||||
current = playerState.classCounts[entity.class] || 0; | current = playerState.classCounts[entity.class] || 0; | ||||
break; | break; | ||||
case "variants": | case "variants": | ||||
current = playerState.typeCountsByClass[entity.class] ? | current = playerState.typeCountsByClass[entity.class] ? | ||||
Object.keys(playerState.typeCountsByClass[entity.class]).length : 0; | Object.keys(playerState.typeCountsByClass[entity.class]).length : 0; | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | for (let tech of data.item.tech.pair ? [data.item.tech.bottom, data.item.tech.top] : [data.item.tech]) | ||||
else if (neededResources) | else if (neededResources) | ||||
{ | { | ||||
button.enabled = false; | button.enabled = false; | ||||
modifier += resourcesToAlphaMask(neededResources) + ":"; | modifier += resourcesToAlphaMask(neededResources) + ":"; | ||||
} | } | ||||
else | else | ||||
button.enabled = controlsPlayer(data.player); | button.enabled = controlsPlayer(data.player); | ||||
if (data.unitEntStates.every(state => state.upgrade && state.upgrade.isUpgrading)) | |||||
bbUnsubmitted Not Done Inline ActionsShouldn't we make this else if and move above the else above? bb: Shouldn't we make this `else if` and move above the `else` above? | |||||
SilierAuthorUnsubmitted Done Inline Actionsor it would be above "not enough resources" and that would not show up, or under and this would not show up if player would have lack of resources, do we want that ? Silier: or it would be above "not enough resources" and that would not show up, or under and this would… | |||||
{ | |||||
button.enabled = false; | |||||
modifier += "color:0 0 0 127:grayscale:"; | |||||
Not Done Inline Actions(That modifier asks for a variable somewhere.) Freagarach: (That modifier asks for a variable somewhere.) | |||||
button.tooltip += "\n" + coloredText(translate("Cannot research while upgrading."), "red"); | |||||
} | |||||
if (template.icon) | if (template.icon) | ||||
icon.sprite = modifier + "stretched:session/portraits/" + template.icon; | icon.sprite = modifier + "stretched:session/portraits/" + template.icon; | ||||
setPanelObjectPosition(button, position, data.rowLength); | setPanelObjectPosition(button, position, data.rowLength); | ||||
// Prepare to handle the top button (if any) | // Prepare to handle the top button (if any) | ||||
position -= data.rowLength; | position -= data.rowLength; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | let technologyEnabled = Engine.GuiInterfaceCall("IsTechnologyResearched", { | ||||
"tech": template.requiredTechnology, | "tech": template.requiredTechnology, | ||||
"player": data.player | "player": data.player | ||||
}); | }); | ||||
let unitIds = data.unitEntStates.map(status => status.id); | let unitIds = data.unitEntStates.map(status => status.id); | ||||
let [buildingsCountToTrainFullBatch, fullBatchSize, remainderBatch] = | let [buildingsCountToTrainFullBatch, fullBatchSize, remainderBatch] = | ||||
getTrainingStatus(unitIds, data.item, data.playerState); | getTrainingStatus(unitIds, data.item, data.playerState); | ||||
let trainNum = buildingsCountToTrainFullBatch * fullBatchSize + remainderBatch; | let trainNum = buildingsCountToTrainFullBatch * fullBatchSize + remainderBatch; | ||||
Not Done Inline ActionsisUpgrading sounds like a better name bb: isUpgrading sounds like a better name | |||||
let neededResources; | let neededResources; | ||||
if (template.cost) | if (template.cost) | ||||
neededResources = Engine.GuiInterfaceCall("GetNeededResources", { | neededResources = Engine.GuiInterfaceCall("GetNeededResources", { | ||||
"cost": multiplyEntityCosts(template, trainNum), | "cost": multiplyEntityCosts(template, trainNum), | ||||
"player": data.player | "player": data.player | ||||
}); | }); | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | "setupButton": function(data) | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
data.button.enabled = controlsPlayer(data.player); | data.button.enabled = controlsPlayer(data.player); | ||||
if (neededResources) | if (neededResources) | ||||
modifier = resourcesToAlphaMask(neededResources) + ":"; | modifier = resourcesToAlphaMask(neededResources) + ":"; | ||||
} | } | ||||
if (data.unitEntStates.every(state => state.upgrade && state.upgrade.isUpgrading)) | |||||
bbUnsubmitted Not Done Inline Actionsidem bb: idem | |||||
StanUnsubmitted Not Done Inline ActionsYou might want to put the fastest to check first. Could be snake oil. Stan: You might want to put the fastest to check first. Could be snake oil. | |||||
{ | |||||
data.button.enabled = false; | |||||
modifier = "color:0 0 0 127:grayscale:"; | |||||
data.button.tooltip += "\n" + coloredText(translate("Cannot train while upgrading."), "red"); | |||||
Not Done Inline Actions*train or research ? bb: *train or research ?
or `produce` ? | |||||
Done Inline Actionsresearch is done in separate panel, here is only unit training Silier: research is done in separate panel, here is only unit training | |||||
Not Done Inline Actionsright, in that case the comment above bb: right, in that case the comment above | |||||
} | |||||
if (template.icon) | if (template.icon) | ||||
data.icon.sprite = modifier + "stretched:session/portraits/" + template.icon; | data.icon.sprite = modifier + "stretched:session/portraits/" + template.icon; | ||||
let index = data.i + getNumberOfRightPanelButtons(); | let index = data.i + getNumberOfRightPanelButtons(); | ||||
setPanelObjectPosition(data.button, index, data.rowLength); | setPanelObjectPosition(data.button, index, data.rowLength); | ||||
return true; | return true; | ||||
} | } | ||||
Show All 14 Lines | "getItems": function(unitEntStates) | ||||
return unitEntStates[0].upgrade && unitEntStates[0].upgrade.upgrades; | return unitEntStates[0].upgrade && unitEntStates[0].upgrade.upgrades; | ||||
}, | }, | ||||
"setupButton": function(data) | "setupButton": function(data) | ||||
{ | { | ||||
let template = GetTemplateData(data.item.entity); | let template = GetTemplateData(data.item.entity); | ||||
if (!template) | if (!template) | ||||
return false; | return false; | ||||
let technologyEnabled = true; | let technologyEnabled = true; | ||||
Not Done Inline ActionsisProducing ? bb: isProducing ? | |||||
if (data.item.requiredTechnology) | if (data.item.requiredTechnology) | ||||
technologyEnabled = Engine.GuiInterfaceCall("IsTechnologyResearched", { | technologyEnabled = Engine.GuiInterfaceCall("IsTechnologyResearched", { | ||||
"tech": data.item.requiredTechnology, | "tech": data.item.requiredTechnology, | ||||
"player": data.player | "player": data.player | ||||
}); | }); | ||||
let neededResources = data.item.cost && Engine.GuiInterfaceCall("GetNeededResources", { | let neededResources = data.item.cost && Engine.GuiInterfaceCall("GetNeededResources", { | ||||
Show All 23 Lines | if (!progress) | ||||
getEntityCostComponentsTooltipString(data.item, undefined, data.unitEntStates.length), | getEntityCostComponentsTooltipString(data.item, undefined, data.unitEntStates.length), | ||||
formatLimitString(limits.entLimit, limits.entCount, limits.entLimitChangers), | formatLimitString(limits.entLimit, limits.entCount, limits.entLimitChangers), | ||||
getRequiredTechnologyTooltip(technologyEnabled, data.item.requiredTechnology, GetSimState().players[data.player].civ), | getRequiredTechnologyTooltip(technologyEnabled, data.item.requiredTechnology, GetSimState().players[data.player].civ), | ||||
getNeededResourcesTooltip(neededResources), | getNeededResourcesTooltip(neededResources), | ||||
showTemplateViewerOnRightClickTooltip()); | showTemplateViewerOnRightClickTooltip()); | ||||
tooltip = tooltips.filter(tip => tip).join("\n"); | tooltip = tooltips.filter(tip => tip).join("\n"); | ||||
data.button.onPress = function() { upgradeEntity(data.item.entity); }; | data.button.onPress = function() { upgradeEntity(data.item.entity); }; | ||||
Not Done Inline ActionsWhy not filter in the helper? Or don't do the undefined check therein (since that function is only called from here)? Freagarach: Why not filter in the helper? Or don't do the undefined check therein (since that function is… | |||||
Done Inline Actionsso we do not pass bunch of not needed entity states, Silier: so we do not pass bunch of not needed entity states,
also in helper one would need to get… | |||||
} | } | ||||
else if (isUpgrading) | else if (isUpgrading) | ||||
{ | { | ||||
tooltip = translate("Cancel Upgrading"); | tooltip = translate("Cancel Upgrading"); | ||||
data.button.onPress = function() { cancelUpgradeEntity(); }; | data.button.onPress = function() { cancelUpgradeEntity(); }; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
tooltip = translate("Cannot upgrade when the entity is already upgrading."); | tooltip = translate("Cannot upgrade when the entity is already upgrading."); | ||||
Not Done Inline ActionsSetStringTags? Refs. D2151. Freagarach: SetStringTags? Refs. D2151. | |||||
Done Inline ActionsI do not see how setStringTags is more perf helpful than coloredText. Silier: I do not see how setStringTags is more perf helpful than coloredText.
setStringTags requires… | |||||
Not Done Inline ActionsSure, I just wanted to mention it ;) Freagarach: Sure, I just wanted to mention it ;) | |||||
data.button.onPress = function() {}; | data.button.onPress = function() {}; | ||||
} | } | ||||
data.button.enabled = controlsPlayer(data.player); | data.button.enabled = controlsPlayer(data.player); | ||||
data.button.tooltip = tooltip; | data.button.tooltip = tooltip; | ||||
data.button.onPressRight = function() { | data.button.onPressRight = function() { | ||||
showTemplateDetails(data.item.entity); | showTemplateDetails(data.item.entity); | ||||
}; | }; | ||||
let modifier = ""; | let modifier = ""; | ||||
if (!isUpgrading) | if (!isUpgrading) | ||||
if (progress || !technologyEnabled || limits.canBeAddedCount == 0 && | if (progress || !technologyEnabled || limits.canBeAddedCount == 0 && | ||||
!hasSameRestrictionCategory(data.item.entity, data.unitEntStates[0].template)) | !hasSameRestrictionCategory(data.item.entity, data.unitEntStates[0].template)) | ||||
{ | { | ||||
data.button.enabled = false; | data.button.enabled = false; | ||||
modifier = "color:0 0 0 127:grayscale:"; | modifier = "color:0 0 0 127:grayscale:"; | ||||
} | } | ||||
else if (neededResources) | else if (neededResources) | ||||
{ | { | ||||
data.button.enabled = false; | data.button.enabled = false; | ||||
modifier = resourcesToAlphaMask(neededResources) + ":"; | modifier = resourcesToAlphaMask(neededResources) + ":"; | ||||
} | } | ||||
if (data.unitEntStates.every(state => state.production && state.production.queue && state.production.queue.length)) | |||||
bbUnsubmitted Not Done Inline Actionssortof idem bb: sortof idem | |||||
{ | |||||
data.button.enabled = false; | |||||
modifier = "color:0 0 0 127:grayscale:"; | |||||
data.button.tooltip += "\n" + coloredText(translate("Cannot upgrade while training or researching"), "red"); | |||||
Not Done Inline Actions+. Freagarach: +`.` | |||||
Not Done Inline Actions^ Freagarach: ^ | |||||
} | |||||
data.icon.sprite = modifier + "stretched:session/" + | data.icon.sprite = modifier + "stretched:session/" + | ||||
(data.item.icon || "portraits/" + template.icon); | (data.item.icon || "portraits/" + template.icon); | ||||
data.countDisplay.caption = data.unitEntStates.length > 1 ? data.unitEntStates.length : ""; | data.countDisplay.caption = data.unitEntStates.length > 1 ? data.unitEntStates.length : ""; | ||||
let progressOverlay = Engine.GetGUIObjectByName("unitUpgradeProgressSlider[" + data.i + "]"); | let progressOverlay = Engine.GetGUIObjectByName("unitUpgradeProgressSlider[" + data.i + "]"); | ||||
if (isUpgrading) | if (isUpgrading) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 68 Lines • Show Last 20 Lines |
Expected a default case.