Changeset View
Standalone View
binaries/data/mods/public/gui/session/menu.js
Show First 20 Lines • Show All 308 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
closeOpenDialogs(); | closeOpenDialogs(); | ||||
if (g_ViewedPlayer < 1) | if (g_ViewedPlayer < 1) | ||||
return; | return; | ||||
g_IsDiplomacyOpen = true; | g_IsDiplomacyOpen = true; | ||||
updateDiplomacyPanel(); | |||||
elexis: (This call is actually needed as it updates the dialog even before the next sim update has… | |||||
} | |||||
function updateDiplomacyPanel() | |||||
Not Done Inline ActionsSpaces, somewhat meaningless variable name, how about updateTributeButton? elexis: Spaces, somewhat meaningless variable name, how about updateTributeButton? | |||||
Not Done Inline Actionsok for spaces, not about "meaningless". The important thing here is to say if we are really updating the panel, or opening it. And in the future, we may have other buttons which do not need to be updated. So i would be ok for "init" or something like that, but certainly not updateTributeButton. mimo: ok for spaces, not about "meaningless". The important thing here is to say if we are really… | |||||
Not Done Inline Actions
ok then elexis: > say if we are really updating the panel, or opening
ok then | |||||
{ | |||||
if (g_ViewedPlayer < 1 || !g_IsDiplomacyOpen) | |||||
return; | |||||
let isCeasefireActive = GetSimState().ceasefireActive; | let isCeasefireActive = GetSimState().ceasefireActive; | ||||
let hasSharedLos = GetSimState().players[g_ViewedPlayer].hasSharedLos; | |||||
// Get offset for one line | // Get offset for one line | ||||
let onesize = Engine.GetGUIObjectByName("diplomacyPlayer[0]").size; | let onesize = Engine.GetGUIObjectByName("diplomacyPlayer[0]").size; | ||||
let rowsize = onesize.bottom - onesize.top; | let rowsize = onesize.bottom - onesize.top; | ||||
// We don't include gaia | // We don't include gaia | ||||
for (let i = 1; i < g_Players.length; ++i) | for (let i = 1; i < g_Players.length; ++i) | ||||
{ | { | ||||
let myself = i == g_ViewedPlayer; | let myself = i == g_ViewedPlayer; | ||||
let playerInactive = isPlayerObserver(g_ViewedPlayer) || isPlayerObserver(i); | let playerInactive = isPlayerObserver(g_ViewedPlayer) || isPlayerObserver(i); | ||||
let hasAllies = g_Players.filter(player => player.isMutualAlly[g_ViewedPlayer]).length > 1; | let hasAllies = g_Players.filter(player => player.isMutualAlly[g_ViewedPlayer]).length > 1; | ||||
Not Done Inline Actions(guess I should have moved that variable to diplomacyFormatAttackRequestButton, as you are right that the subfunctions should determine specific uncommon hidden logic themselves) elexis: (guess I should have moved that variable to `diplomacyFormatAttackRequestButton`, as you are… | |||||
diplomacySetupTexts(i, rowsize); | diplomacySetupTexts(i, rowsize); | ||||
diplomacyFormatStanceButtons(i, myself || playerInactive || isCeasefireActive || g_Players[g_ViewedPlayer].teamsLocked); | diplomacyFormatStanceButtons(i, myself || playerInactive || isCeasefireActive || g_Players[g_ViewedPlayer].teamsLocked); | ||||
diplomacyFormatTributeButtons(i, myself || playerInactive); | diplomacyFormatTributeButtons(i, myself || playerInactive); | ||||
diplomacyFormatAttackRequestButton(i, myself || playerInactive || isCeasefireActive || !hasAllies || !g_Players[i].isEnemy[g_ViewedPlayer]); | diplomacyFormatAttackRequestButton(i, myself || playerInactive || isCeasefireActive || !hasAllies || !g_Players[i].isEnemy[g_ViewedPlayer]); | ||||
diplomacyFormatSpyRequestButton(i, myself || playerInactive || g_Players[i].isMutualAlly[g_ViewedPlayer] && hasSharedLos); | |||||
Not Done Inline ActionsTODO: We want that button disabled but not hidden if we don't have the tech researched, so we can read the tooltip (which also states that it requires Espionage. Therefore we don't need the hasSharedLos variable at all. (And if the button was to be hidden if we don't have the tech, it shouldt that be hidden if ... || !hasSharedLos) (The isCeasefire makes me question whether we should prohibit the bribing while ceasefire is active. The answer is no though :P) Do these GUI checks have equivalent simulation checks? Guess players would only shoot themselves in the foot if they would send such a command for an ally or themselves, so not important. elexis: **TODO:** We want that button disabled but not hidden if we don't have the tech researched, so… | |||||
Not Done Inline ActionsThe idea here is to have the same behaviour as for the attackRequest: the button is hidden for allies, so here it is also hidden for allies when you have the sharedlos as spies are then useless. mimo: The idea here is to have the same behaviour as for the attackRequest: the button is hidden for… | |||||
Not Done Inline ActionsAh yes, I was confused that the button is visible to allies, but it's indeed hidden if sharedlos is researched, ack. elexis: Ah yes, I was confused that the button is visible to allies, but it's indeed hidden if… | |||||
} | } | ||||
Engine.GetGUIObjectByName("diplomacyDialogPanel").hidden = false; | Engine.GetGUIObjectByName("diplomacyDialogPanel").hidden = false; | ||||
} | } | ||||
function diplomacySetupTexts(i, rowsize) | function diplomacySetupTexts(i, rowsize) | ||||
{ | { | ||||
// Apply offset | // Apply offset | ||||
let row = Engine.GetGUIObjectByName("diplomacyPlayer["+(i-1)+"]"); | let row = Engine.GetGUIObjectByName("diplomacyPlayer["+(i-1)+"]"); | ||||
▲ Show 20 Lines • Show All 104 Lines • ▼ Show 20 Lines | function diplomacyFormatAttackRequestButton(i, hidden) | ||||
button.hidden = hidden; | button.hidden = hidden; | ||||
if (hidden) | if (hidden) | ||||
return; | return; | ||||
button.enabled = controlsPlayer(g_ViewedPlayer); | button.enabled = controlsPlayer(g_ViewedPlayer); | ||||
button.tooltip = translate("Request your allies to attack this enemy"); | button.tooltip = translate("Request your allies to attack this enemy"); | ||||
button.onpress = (function(i) { return function() { | button.onpress = (function(i) { return function() { | ||||
Engine.PostNetworkCommand({ "type": "attack-request", "source": g_ViewedPlayer, "target": i }); | Engine.PostNetworkCommand({ "type": "attack-request", "source": g_ViewedPlayer, "target": i }); | ||||
}; })(i); | }; })(i); | ||||
Not Done Inline Actionsthx elexis: thx | |||||
} | } | ||||
function diplomacyFormatSpyRequestButton(i, hidden) | |||||
{ | |||||
let button = Engine.GetGUIObjectByName("diplomacySpyRequest["+(i-1)+"]"); | |||||
let template = GetTemplateData("special/spy"); | |||||
button.hidden = hidden || !template || GetSimState().players[g_ViewedPlayer].disabledTemplates["special/spy"]; | |||||
Not Done Inline Actions(Urgh, disabledTemplates is an object not an array, so this is a correct check even) elexis: (Urgh, disabledTemplates is an object not an array, so this is a correct check even) | |||||
if (button.hidden) | |||||
return; | |||||
button.enabled = controlsPlayer(g_ViewedPlayer); | |||||
let modifier = ""; | |||||
let tooltips = [translate("Bribe a random unit from this player and share its vision during 10 s.")]; | |||||
ItmsUnsubmitted Not Done Inline ActionsThis is not in sync with the value in the template (15s). Itms: This is not in sync with the value in the template (15s). | |||||
elexisUnsubmitted Not Done Inline Actionsunit -> trader? As we were considering to add a new button if we want other units to be bribed and as the GUI nowhere states that only traders are affected and players will totally not get that that's the case! (There is also no hint that players have to use the diplo panel for that feature, but as that is opened frequently even by newbies, they will likely discover that on their own) "during" seems wrong, perhaps 'share its vision briefly'? (Notice we can't display the exact timespan as that can differ depending on the template.) elexis: unit -> trader? As we were considering to add a new button if we want other units to be bribed… | |||||
mimoAuthorUnsubmitted Not Done Inline Actionsbut trader is specific to the public mod. Others could do differently, so the tooltip have to stay generic. Correct one would be "Bribe a random bribable unit", but that should be implicit. mimo: but trader is specific to the public mod. Others could do differently, so the tooltip have to… | |||||
elexisUnsubmitted Not Done Inline ActionsOkay, good enough as the tech explicitly refers to traders and we indeed don't want to complicate things for modders. elexis: Okay, good enough as the tech explicitly refers to traders and we indeed don't want to… | |||||
if (!button.enabled) | |||||
modifier = "color:0 0 0 127:grayscale:"; | |||||
else | |||||
{ | |||||
if (template.requiredTechnology) | |||||
{ | |||||
let technologyEnabled = Engine.GuiInterfaceCall("IsTechnologyResearched", { | |||||
"tech": template.requiredTechnology, | |||||
"player": g_ViewedPlayer | |||||
}); | |||||
if (!technologyEnabled) | |||||
{ | |||||
modifier = "color:0 0 0 127:grayscale:" | |||||
button.enabled = false; | |||||
tooltips.push(getRequiredTechnologyTooltip(technologyEnabled, template.requiredTechnology, GetSimState().players[g_ViewedPlayer].civ)); | |||||
} | |||||
} | |||||
if (template.cost) | |||||
{ | |||||
let neededResources = Engine.GuiInterfaceCall("GetNeededResources", { | |||||
"cost": template.cost, | |||||
"player": g_ViewedPlayer | |||||
}); | |||||
if (neededResources) | |||||
{ | |||||
if (button.enabled) | |||||
modifier = resourcesToAlphaMask(neededResources) +":"; | |||||
button.enabled = false; | |||||
tooltips.push(getNeededResourcesTooltip(neededResources)); | |||||
} | |||||
} | |||||
} | |||||
let icon = Engine.GetGUIObjectByName("diplomacySpyRequestImage["+(i-1)+"]"); | |||||
icon.sprite = modifier + "stretched:session/icons/economics.png"; | |||||
button.tooltip = tooltips.filter(tip => tip).join("\n"); | |||||
button.onpress = (function(i) { return function() { | |||||
Not Done Inline Actionstiny todo: onPress (engine doesn't complain, still preferable case and we should fix all occurances sometime) elexis: tiny todo: onPress (engine doesn't complain, still preferable case and we should fix all… | |||||
Not Done Inline Actionsok, and will fix a few other occurences of it in the same file. mimo: ok, and will fix a few other occurences of it in the same file. | |||||
Engine.PostNetworkCommand({ "type": "spy-request", "source": g_ViewedPlayer, "target": i }); | |||||
closeDiplomacy(); | |||||
}; })(i); | |||||
} | |||||
function closeDiplomacy() | function closeDiplomacy() | ||||
{ | { | ||||
g_IsDiplomacyOpen = false; | g_IsDiplomacyOpen = false; | ||||
Engine.GetGUIObjectByName("diplomacyDialogPanel").hidden = true; | Engine.GetGUIObjectByName("diplomacyDialogPanel").hidden = true; | ||||
} | } | ||||
function toggleDiplomacy() | function toggleDiplomacy() | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 470 Lines • Show Last 20 Lines |
(This call is actually needed as it updates the dialog even before the next sim update has arrived, which can take at an arbitrary amount of time if the game is paused or lagging and since the dialog isn't updated if closed)