Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/session/selection_panels.js
Show All 27 Lines | |||||
// Cache some formation info | // Cache some formation info | ||||
// Available formations per player | // Available formations per player | ||||
let g_AvailableFormations = new Map(); | let g_AvailableFormations = new Map(); | ||||
let g_FormationsInfo = new Map(); | let g_FormationsInfo = new Map(); | ||||
let g_SelectionPanels = {}; | let g_SelectionPanels = {}; | ||||
let g_BarterSell; | |||||
g_SelectionPanels.Alert = { | g_SelectionPanels.Alert = { | ||||
"getMaxNumberOfItems": function() | "getMaxNumberOfItems": function() | ||||
{ | { | ||||
return 3; | return 3; | ||||
}, | }, | ||||
"conflictsWith": ["Barter"], | "conflictsWith": ["Barter"], | ||||
"getItems": function(unitEntStates) | "getItems": function(unitEntStates) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | g_SelectionPanels.Barter = { | ||||
"getMaxNumberOfItems": function() | "getMaxNumberOfItems": function() | ||||
{ | { | ||||
return 4; | return 4; | ||||
}, | }, | ||||
"rowLength": 4, | "rowLength": 4, | ||||
"conflictsWith": ["Alert", "Garrison"], | "conflictsWith": ["Alert", "Garrison"], | ||||
"getItems": function(unitEntStates) | "getItems": function(unitEntStates) | ||||
{ | { | ||||
if (unitEntStates.every(state => !state.barterMarket)) | // If more than `rowLength` resources, don't display icons. | ||||
elexis: `rowLength` -> rowLength | |||||
if (unitEntStates.every(state => !state.isBarterMarket) || g_ResourceData.GetCodes().length > this.rowLength) | |||||
Done Inline ActionsRemove braces elexis: Remove braces | |||||
return []; | return []; | ||||
return g_ResourceData.GetCodes(); | return g_ResourceData.GetCodes(); | ||||
}, | }, | ||||
"setupButton": function(data) | "setupButton": function(data) | ||||
{ | { | ||||
// data.item is the resource name in this case | // Common code that only needs to run when the panel is opened. | ||||
elexisUnsubmitted Not Done Inline Actionscomment redundant with the jsdoc comment on the function elexis: comment redundant with the jsdoc comment on the function | |||||
let button = {}; | barterOpenCommon(data.item, data.i, "unitBarter"); | ||||
Done Inline Actionsstuff -> code elexis: stuff -> code | |||||
let icon = {}; | |||||
let amount = {}; | |||||
for (let a of BARTER_ACTIONS) | |||||
{ | |||||
button[a] = Engine.GetGUIObjectByName("unitBarter" + a + "Button[" + data.i + "]"); | |||||
icon[a] = Engine.GetGUIObjectByName("unitBarter" + a + "Icon[" + data.i + "]"); | |||||
amount[a] = Engine.GetGUIObjectByName("unitBarter" + a + "Amount[" + data.i + "]"); | |||||
} | |||||
let selectionIcon = Engine.GetGUIObjectByName("unitBarterSellSelection[" + data.i + "]"); | |||||
let amountToSell = BARTER_RESOURCE_AMOUNT_TO_SELL; | |||||
if (Engine.HotkeyIsPressed("session.massbarter")) | |||||
amountToSell *= BARTER_BUNCH_MULTIPLIER; | |||||
if (!g_BarterSell) | |||||
g_BarterSell = g_ResourceData.GetCodes()[0]; | |||||
amount.Sell.caption = "-" + amountToSell; | |||||
let prices; | |||||
for (let state of data.unitEntStates) | |||||
if (state.barterMarket) | |||||
{ | |||||
prices = state.barterMarket.prices; | |||||
break; | |||||
} | |||||
amount.Buy.caption = "+" + Math.round(prices.sell[g_BarterSell] / prices.buy[data.item] * amountToSell); | // Common code that needs to be run every simulation update. | ||||
bbUnsubmitted Not Done Inline ActionsThese comments probably belong better in function definition (where they are already), but idc. bb: These comments probably belong better in function definition (where they are already), but idc. | |||||
elexisUnsubmitted Not Done Inline Actionsthat what bb said elexis: that what bb said | |||||
barterUpdateCommon(data.item, data.i, "unitBarter", data.player); | |||||
let resource = getLocalizedResourceName(g_ResourceData.GetNames()[data.item], "withinSentence"); | // Final positioning. | ||||
elexisUnsubmitted Not Done Inline Actionsunneeded comment IMO elexis: unneeded comment IMO | |||||
button.Buy.tooltip = sprintf(translate("Buy %(resource)s"), { "resource": resource }); | let button = {}; | ||||
button.Sell.tooltip = sprintf(translate("Sell %(resource)s"), { "resource": resource }); | for (let action of g_BarterActions) | ||||
button[action] = Engine.GetGUIObjectByName("unitBarter" + action + "Button[" + data.i + "]"); | |||||
button.Sell.onPress = function() { | |||||
g_BarterSell = data.item; | |||||
updateSelectionDetails(); | |||||
}; | |||||
button.Buy.onPress = function() { | |||||
Engine.PostNetworkCommand({ | |||||
"type": "barter", | |||||
"sell": g_BarterSell, | |||||
"buy": data.item, | |||||
"amount": amountToSell | |||||
}); | |||||
}; | |||||
let isSelected = data.item == g_BarterSell; | |||||
let grayscale = isSelected ? "color: 0 0 0 100:grayscale:" : ""; | |||||
// do we have enough of this resource to sell? | |||||
let neededRes = {}; | |||||
neededRes[data.item] = amountToSell; | |||||
let canSellCurrent = Engine.GuiInterfaceCall("GetNeededResources", { | |||||
"cost": neededRes, | |||||
"player": data.player | |||||
}) ? "color:255 0 0 80:" : ""; | |||||
// Let's see if we have enough resources to barter. | |||||
neededRes = {}; | |||||
neededRes[g_BarterSell] = amountToSell; | |||||
let canBuyAny = Engine.GuiInterfaceCall("GetNeededResources", { | |||||
"cost": neededRes, | |||||
"player": data.player | |||||
}) ? "color:255 0 0 80:" : ""; | |||||
icon.Sell.sprite = canSellCurrent + "stretched:" + grayscale + "session/icons/resources/" + data.item + ".png"; | |||||
icon.Buy.sprite = canBuyAny + "stretched:" + grayscale + "session/icons/resources/" + data.item + ".png"; | |||||
button.Buy.hidden = isSelected; | |||||
button.Buy.enabled = controlsPlayer(data.player); | |||||
button.Sell.hidden = false; | |||||
selectionIcon.hidden = !isSelected; | |||||
setPanelObjectPosition(button.Sell, data.i, data.rowLength); | setPanelObjectPosition(button.Sell, data.i, data.rowLength); | ||||
setPanelObjectPosition(button.Buy, data.i + data.rowLength, data.rowLength); | setPanelObjectPosition(button.Buy, data.i + data.rowLength, data.rowLength); | ||||
return true; | return true; | ||||
} | } | ||||
}; | }; | ||||
g_SelectionPanels.Command = { | g_SelectionPanels.Command = { | ||||
▲ Show 20 Lines • Show All 1,052 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* If two panels need the same space, so they collide, | * If two panels need the same space, so they collide, | ||||
* the one appearing first in the order is rendered. | * the one appearing first in the order is rendered. | ||||
* | * | ||||
* Note that the panel needs to appear in the list to get rendered. | * Note that the panel needs to appear in the list to get rendered. | ||||
*/ | */ | ||||
let g_PanelsOrder = [ | let g_PanelsOrder = [ | ||||
// LEFT PANE | // LEFT PANE | ||||
"Barter", // Must always be visible on markets | "Barter", // Must always be visible on markets | ||||
Done Inline ActionsSlightly misleading, since the context here is determining the order and if there is a comment here, So the only reason Barter appears first could be a garrisonable market or a market with alert button. Not changing the comment should be good enough. elexis: Slightly misleading, since the context here is determining the order and if there is a comment… | |||||
"Garrison", // More important than Formation, as you want to see the garrisoned units in ships | "Garrison", // More important than Formation, as you want to see the garrisoned units in ships | ||||
"Alert", | "Alert", | ||||
"Formation", | "Formation", | ||||
"Stance", // Normal together with formation | "Stance", // Normal together with formation | ||||
// RIGHT PANE | // RIGHT PANE | ||||
"Gate", // Must always be shown on gates | "Gate", // Must always be shown on gates | ||||
"Pack", // Must always be shown on packable entities | "Pack", // Must always be shown on packable entities | ||||
Show All 11 Lines |
Wildfire Games · Phabricator
rowLength -> rowLength