Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/session/menu.js
Show First 20 Lines • Show All 480 Lines • ▼ Show 20 Lines | for (let stance of ["Ally", "Neutral", "Enemy"]) | ||||
}; })(i, stance); | }; })(i, stance); | ||||
} | } | ||||
} | } | ||||
function diplomacyFormatTributeButtons(i, hidden) | function diplomacyFormatTributeButtons(i, hidden) | ||||
{ | { | ||||
let resTribCodes = g_ResourceData.GetTributableCodes(); | let resTribCodes = g_ResourceData.GetTributableCodes(); | ||||
let r = 0; | let r = 0; | ||||
let buttons = {}; | |||||
let multipliers = {}; | |||||
let amounts = {}; | |||||
for (let resCode of resTribCodes) { | |||||
Stan: brace on newline. | |||||
multipliers[resCode] = 1; | |||||
amounts[resCode] = 0; | |||||
buttons[resCode] = null; | |||||
StanUnsubmitted Not Done Inline ActionsNot sure initialization is needed. Stan: Not sure initialization is needed. | |||||
} | |||||
for (let resCode of resTribCodes) | for (let resCode of resTribCodes) | ||||
{ | { | ||||
let button = Engine.GetGUIObjectByName("diplomacyPlayer[" + (i - 1) + "]_tribute[" + r + "]"); | let button = Engine.GetGUIObjectByName("diplomacyPlayer[" + (i - 1) + "]_tribute[" + r + "]"); | ||||
buttons[resCode] = button; | |||||
if (!button) | if (!button) | ||||
{ | { | ||||
warn("Current GUI limits prevent displaying more than " + r + " tribute buttons!"); | warn("Current GUI limits prevent displaying more than " + r + " tribute buttons!"); | ||||
break; | break; | ||||
} | } | ||||
Engine.GetGUIObjectByName("diplomacyPlayer[" + (i - 1) + "]_tribute[" + r + "]_image").sprite = "stretched:session/icons/resources/" + resCode + ".png"; | Engine.GetGUIObjectByName("diplomacyPlayer[" + (i - 1) + "]_tribute[" + r + "]_image").sprite = "stretched:session/icons/resources/" + resCode + ".png"; | ||||
button.hidden = hidden; | button.hidden = hidden; | ||||
setPanelObjectPosition(button, r, r + 1, 0); | setPanelObjectPosition(button, r, r + 1, 0); | ||||
++r; | ++r; | ||||
if (hidden) | if (hidden) | ||||
continue; | continue; | ||||
button.enabled = controlsPlayer(g_ViewedPlayer); | button.enabled = controlsPlayer(g_ViewedPlayer); | ||||
button.tooltip = formatTributeTooltip(i, resCode, 100); | button.tooltip = formatTributeTooltip(i, resCode, 100); | ||||
button.onPress = (function(i, resCode, button) { | button.onPress = (function(i, resCode, button) { | ||||
// Shift+click to send 500, shift+click+click to send 1000, etc. | // Shift+click to send 500, shift+click+click to send 1000, etc. | ||||
StanUnsubmitted Not Done Inline ActionsComment is a bit weird, maybe it could be improved. Stan: Comment is a bit weird, maybe it could be improved. | |||||
// See INPUT_MASSTRIBUTING in input.js | // See INPUT_MASSTRIBUTING in input.js | ||||
let multiplier = 1; | |||||
Not Done Inline ActionsOh I get it, this is a trick to store a variable without using a global and without saving it directly in a button property. elexis: Oh I get it, this is a trick to store a variable without using a global and without saving it… | |||||
return function() { | return function() { | ||||
let isMassTributePressed = Engine.HotkeyIsPressed("session.masstribute"); | let isMassTributePressed = Engine.HotkeyIsPressed("session.masstribute"); | ||||
if (isMassTributePressed) | if (isMassTributePressed) | ||||
{ | { | ||||
inputState = INPUT_MASSTRIBUTING; | inputState = INPUT_MASSTRIBUTING; | ||||
multiplier += multiplier == 1 ? 4 : 5; | multipliers[resCode] += multipliers[resCode] == 1 ? 4 : 5; | ||||
} | } | ||||
let amounts = {}; | amounts[resCode] = 100 * multipliers[resCode]; | ||||
for (let res of resTribCodes) | |||||
amounts[res] = 0; | |||||
amounts[resCode] = 100 * multiplier; | |||||
button.tooltip = formatTributeTooltip(i, resCode, amounts[resCode]); | button.tooltip = formatTributeTooltip(i, resCode, amounts[resCode]); | ||||
// This is in a closure so that we have access to `player`, `amounts`, and `multiplier` without some | // This is in a closure so that we have access to `player`, `amounts`, and `multiplier` without some | ||||
// evil global variable hackery. | // evil global variable hackery. | ||||
g_FlushTributing = function() { | g_FlushTributing = function() { | ||||
Engine.PostNetworkCommand({ "type": "tribute", "player": i, "amounts": amounts }); | Engine.PostNetworkCommand({ "type": "tribute", "player": i, "amounts": amounts }); | ||||
multiplier = 1; | for (let res of resTribCodes) { | ||||
StanUnsubmitted Not Done Inline Actionsbrace on new line. Stan: brace on new line. | |||||
button.tooltip = formatTributeTooltip(i, resCode, 100); | multipliers[res] = 1; | ||||
amounts[res] = 0; | |||||
buttons[res].tooltip = formatTributeTooltip(i, res, 100); | |||||
} | |||||
}; | }; | ||||
if (!isMassTributePressed) | if (!isMassTributePressed) | ||||
g_FlushTributing(); | g_FlushTributing(); | ||||
}; | }; | ||||
})(i, resCode, button); | })(i, resCode, button); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 728 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
brace on newline.