Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/session/session.js
Show First 20 Lines • Show All 194 Lines • ▼ Show 20 Lines | |||||
*/ | */ | ||||
var g_WorkerTypes = ["FemaleCitizen", "Trader", "FishingBoat", "CitizenSoldier"]; | var g_WorkerTypes = ["FemaleCitizen", "Trader", "FishingBoat", "CitizenSoldier"]; | ||||
/** | /** | ||||
* Unit classes to be checked for the military-only-selection modifier and for the idle-warrior-hotkey. | * Unit classes to be checked for the military-only-selection modifier and for the idle-warrior-hotkey. | ||||
*/ | */ | ||||
var g_MilitaryTypes = ["Melee", "Ranged"]; | var g_MilitaryTypes = ["Melee", "Ranged"]; | ||||
/** | |||||
* Setting tooltips, hotkey descriptions in tooltips and enable/disable states of the GUI buttons. | |||||
*/ | |||||
var g_GuiButtons = () => { return { | |||||
"menuButton": { "description": "Toggle the in-game menu." }, | |||||
"manualButton": { "description": "Show the game manual." }, | |||||
"saveGameButton": { "description": "Save the current game." }, | |||||
"summaryButton": { "description": "Show the summary dialog." }, | |||||
"lobbyButton": { "description": "Show the multiplayer lobby in a dialog.", "enabled": Engine.HasXmppClient() }, | |||||
"chatButton": { "hotkey": [ | |||||
{ "hotkey": "chat", "description": translate("Chat"), "showOnlyWhenUsed": true }, | |||||
{ "hotkey": "teamchat", "description": translate("Team chat"), "showOnlyWhenUsed": true }, | |||||
{ "hotkey": "privatechat", "description": translate("Private chat"), "showOnlyWhenUsed": true } | |||||
] }, | |||||
"optionsButton": { "description": "Show the options dialog." }, | |||||
"pauseButton": { "description": "Toggle pause the game.", "enabled": !g_IsObserver || !g_IsNetworked || g_IsController }, | |||||
"menuResignButton": { "description": "Resign from the current game.", "enabled": !g_IsObserver }, | |||||
"menuExitButton": { "description": "Exit from the current game." }, | |||||
"tradeButton1": { "description": "Barter & Trade" }, | |||||
"idleWorkerButton": { "description": "Find idle worker." }, | |||||
"diplomacyColorsButton": { "description": "Toggle Diplomacy Colors." }, | |||||
"tradeHelp": { | |||||
"description": colorizeHotkey( | |||||
translate("Select one type of goods you want to modify by clicking on it, and then use the arrows of the other types to modify their shares. You can also press %(hotkey)s while selecting one type of goods to bring its share to 100%%."), | |||||
"session.fulltradeswap") | |||||
}, | |||||
"barterHelp": { | |||||
"description": sprintf( | |||||
translate("Start by selecting the resource you wish to sell from the upper row. For each time the lower buttons are pressed, %(quantity)s of the upper resource will be sold for the displayed quantity of the lower. Press and hold %(hotkey)s to temporarily multiply the traded amount by %(multiplier)s."), { | |||||
"quantity": g_BarterResourceSellQuantity, | |||||
"hotkey": colorizeHotkey("%(hotkey)s", "session.massbarter"), | |||||
"multiplier": g_BarterMultiplier | |||||
}) | |||||
}, | |||||
"chatInput": { | |||||
"description": translateWithContext("chat input", "Type the message to send.") + "\n" + | |||||
colorizeAutocompleteHotkey() + | |||||
colorizeHotkey("\n" + translate("Press %(hotkey)s to open the public chat."), "chat") + | |||||
colorizeHotkey( | |||||
"\n" + (g_IsObserver ? | |||||
translate("Press %(hotkey)s to open the observer chat.") : | |||||
translate("Press %(hotkey)s to open the ally chat.")), | |||||
"teamchat") + | |||||
colorizeHotkey("\n" + translate("Press %(hotkey)s to open the previously selected private chat."), "privatechat") | |||||
} | |||||
} }; | |||||
function GetSimState() | function GetSimState() | ||||
{ | { | ||||
if (!g_SimState) | if (!g_SimState) | ||||
g_SimState = deepfreeze(Engine.GuiInterfaceCall("GetSimulationState")); | g_SimState = deepfreeze(Engine.GuiInterfaceCall("GetSimulationState")); | ||||
return g_SimState; | return g_SimState; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | function init(initData, hotloadData) | ||||
updatePlayerData(); | updatePlayerData(); | ||||
g_BarterSell = g_ResourceData.GetCodes()[0]; | g_BarterSell = g_ResourceData.GetCodes()[0]; | ||||
initializeMusic(); // before changing the perspective | initializeMusic(); // before changing the perspective | ||||
initSessionMenuButtons(); | initSessionMenuButtons(); | ||||
groupHotkeysMappedSameKey(); | |||||
for (let slot in Engine.GetGUIObjectByName("panelEntityPanel").children) | for (let slot in Engine.GetGUIObjectByName("panelEntityPanel").children) | ||||
initPanelEntities(slot); | initPanelEntities(slot); | ||||
g_DiplomacyColorPalette = Engine.ReadJSONFile(g_SettingsDirectory + "diplomacy_colors.json"); | g_DiplomacyColorPalette = Engine.ReadJSONFile(g_SettingsDirectory + "diplomacy_colors.json"); | ||||
g_DisplayedPlayerColors = g_Players.map(player => player.color); | g_DisplayedPlayerColors = g_Players.map(player => player.color); | ||||
updateViewedPlayerDropdown(); | updateViewedPlayerDropdown(); | ||||
▲ Show 20 Lines • Show All 124 Lines • ▼ Show 20 Lines | Engine.GuiInterfaceCall("UpdateDisplayedPlayerColors", { | ||||
"showAllStatusBars": g_ShowAllStatusBars, | "showAllStatusBars": g_ShowAllStatusBars, | ||||
"selected": g_Selection.toList() | "selected": g_Selection.toList() | ||||
}); | }); | ||||
updateGUIObjects(); | updateGUIObjects(); | ||||
} | } | ||||
/** | /** | ||||
* Depends on the current player (g_IsObserver). | * Setting enable/disable state and tooltip with hotkey information to GUI Buttons. | ||||
*/ | */ | ||||
function updateHotkeyTooltips() | function updateGuiButtons() | ||||
{ | { | ||||
Engine.GetGUIObjectByName("chatInput").tooltip = | let colorizedHotkey = name => { | ||||
translateWithContext("chat input", "Type the message to send.") + "\n" + | let hotkey = Engine.ConfigDB_GetValue("user", "hotkey." + name); | ||||
colorizeAutocompleteHotkey() + | return !hotkey || hotkey == "unused" ? "" : setStringTags("\\[" + hotkey + "]", g_HotkeyTags); | ||||
colorizeHotkey("\n" + translate("Press %(hotkey)s to open the public chat."), "chat") + | } | ||||
colorizeHotkey( | |||||
"\n" + (g_IsObserver ? | |||||
translate("Press %(hotkey)s to open the observer chat.") : | |||||
translate("Press %(hotkey)s to open the ally chat.")), | |||||
"teamchat") + | |||||
colorizeHotkey("\n" + translate("Press %(hotkey)s to open the previously selected private chat."), "privatechat"); | |||||
Engine.GetGUIObjectByName("idleWorkerButton").tooltip = | let getTooltip = (hotkey, description) => | ||||
colorizeHotkey("%(hotkey)s" + " ", "selection.idleworker") + | colorizedHotkey(hotkey) == "" ? description : translate(description) != "" ? sprintf(translate("%(hotkey)s: " + description), { | ||||
translate("Find idle worker"); | "hotkey": colorizedHotkey(hotkey) | ||||
}) : colorizedHotkey(hotkey); | |||||
Engine.GetGUIObjectByName("diplomacyColorsButton").tooltip = | let buttons = g_GuiButtons(); | ||||
colorizeHotkey("%(hotkey)s" + " ", "diplomacycolors") + | for (let name in buttons) | ||||
translate("Toggle Diplomacy Colors"); | { | ||||
let button = buttons[name]; | |||||
let enabled = button.enabled == undefined || button.enabled; | |||||
let guiObj = Engine.GetGUIObjectByName(name); | |||||
guiObj.enabled = enabled; | |||||
let hotkey = button.hotkey || guiObj.hotkey || ""; | |||||
Engine.GetGUIObjectByName("tradeHelp").tooltip = colorizeHotkey( | if ((!hotkey && !button.description) || !enabled) | ||||
translate("Select one type of goods you want to modify by clicking on it, and then use the arrows of the other types to modify their shares. You can also press %(hotkey)s while selecting one type of goods to bring its share to 100%%."), | continue; | ||||
"session.fulltradeswap"); | |||||
Engine.GetGUIObjectByName("barterHelp").tooltip = sprintf( | if (hotkey && Array.isArray(hotkey)) | ||||
translate("Start by selecting the resource you wish to sell from the upper row. For each time the lower buttons are pressed, %(quantity)s of the upper resource will be sold for the displayed quantity of the lower. Press and hold %(hotkey)s to temporarily multiply the traded amount by %(multiplier)s."), { | guiObj.tooltip = hotkey.map(tooltip => | ||||
"quantity": g_BarterResourceSellQuantity, | !!tooltip.showOnlyWhenUsed && colorizedHotkey(tooltip.hotkey) == "" ? "" : | ||||
"hotkey": colorizeHotkey("%(hotkey)s", "session.massbarter"), | getTooltip(tooltip.hotkey, tooltip.description)).join("\n"); | ||||
"multiplier": g_BarterMultiplier | else | ||||
}); | if (!hotkey || typeof(hotkey) == 'string') | ||||
guiObj.tooltip = getTooltip(hotkey, button.description || ""); | |||||
} | |||||
} | } | ||||
function initPanelEntities(slot) | function initPanelEntities(slot) | ||||
{ | { | ||||
let button = Engine.GetGUIObjectByName("panelEntityButton[" + slot + "]"); | let button = Engine.GetGUIObjectByName("panelEntityButton[" + slot + "]"); | ||||
button.onPress = function() { | button.onPress = function() { | ||||
let panelEnt = g_PanelEntities.find(ent => ent.slot !== undefined && ent.slot == slot); | let panelEnt = g_PanelEntities.find(ent => ent.slot !== undefined && ent.slot == slot); | ||||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | if (g_DevSettings.changePerspective) | ||||
Engine.SetPlayerID(g_ViewedPlayer); | Engine.SetPlayerID(g_ViewedPlayer); | ||||
g_IsObserver = isPlayerObserver(g_ViewedPlayer); | g_IsObserver = isPlayerObserver(g_ViewedPlayer); | ||||
} | } | ||||
Engine.SetViewedPlayer(g_ViewedPlayer); | Engine.SetViewedPlayer(g_ViewedPlayer); | ||||
updateDisplayedPlayerColors(); | updateDisplayedPlayerColors(); | ||||
updateTopPanel(); | updateTopPanel(); | ||||
updateChatAddressees(); | updateChatAddressees(); | ||||
updateHotkeyTooltips(); | updateGuiButtons(); | ||||
// updateHotkeyTooltips(); | |||||
ffffffff: remove | |||||
// Update GUI and clear player-dependent cache | // Update GUI and clear player-dependent cache | ||||
g_TemplateData = {}; | g_TemplateData = {}; | ||||
Engine.GuiInterfaceCall("ResetTemplateModified"); | Engine.GuiInterfaceCall("ResetTemplateModified"); | ||||
onSimulationUpdate(); | onSimulationUpdate(); | ||||
if (g_IsDiplomacyOpen) | if (g_IsDiplomacyOpen) | ||||
openDiplomacy(); | openDiplomacy(); | ||||
▲ Show 20 Lines • Show All 118 Lines • ▼ Show 20 Lines | function updateTopPanel() | ||||
Engine.GetGUIObjectByName("population").hidden = !isPlayer; | Engine.GetGUIObjectByName("population").hidden = !isPlayer; | ||||
Engine.GetGUIObjectByName("diplomacyButton1").hidden = !isPlayer; | Engine.GetGUIObjectByName("diplomacyButton1").hidden = !isPlayer; | ||||
Engine.GetGUIObjectByName("tradeButton1").hidden = !isPlayer; | Engine.GetGUIObjectByName("tradeButton1").hidden = !isPlayer; | ||||
Engine.GetGUIObjectByName("observerText").hidden = isPlayer; | Engine.GetGUIObjectByName("observerText").hidden = isPlayer; | ||||
let alphaLabel = Engine.GetGUIObjectByName("alphaLabel"); | let alphaLabel = Engine.GetGUIObjectByName("alphaLabel"); | ||||
alphaLabel.hidden = isPlayer && !viewPlayer.hidden; | alphaLabel.hidden = isPlayer && !viewPlayer.hidden; | ||||
alphaLabel.size = isPlayer ? "50%+44 0 100%-283 100%" : "155 0 85%-279 100%"; | alphaLabel.size = isPlayer ? "50%+44 0 100%-283 100%" : "155 0 85%-279 100%"; | ||||
Engine.GetGUIObjectByName("pauseButton").enabled = !g_IsObserver || !g_IsNetworked || g_IsController; | |||||
Engine.GetGUIObjectByName("menuResignButton").enabled = !g_IsObserver; | |||||
Engine.GetGUIObjectByName("lobbyButton").enabled = Engine.HasXmppClient(); | |||||
} | } | ||||
function reportPerformance(time) | function reportPerformance(time) | ||||
{ | { | ||||
let settings = g_GameAttributes.settings; | let settings = g_GameAttributes.settings; | ||||
Engine.SubmitUserReport("profile", 3, JSON.stringify({ | Engine.SubmitUserReport("profile", 3, JSON.stringify({ | ||||
"time": time, | "time": time, | ||||
"map": settings.Name, | "map": settings.Name, | ||||
▲ Show 20 Lines • Show All 1,052 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
remove