Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/gui/session/menu.js
Show First 20 Lines • Show All 130 Lines • ▼ Show 20 Lines | if (!Engine.HasXmppClient()) | ||||
return; | return; | ||||
closeOpenDialogs(); | closeOpenDialogs(); | ||||
Engine.PushGuiPage("page_lobby.xml", { "dialog": true }); | Engine.PushGuiPage("page_lobby.xml", { "dialog": true }); | ||||
} | } | ||||
function chatMenuButton() | function chatMenuButton() | ||||
{ | { | ||||
closeOpenDialogs(); | g_Chat.openPage(); | ||||
openChat(); | |||||
} | } | ||||
function resignMenuButton() | function resignMenuButton() | ||||
{ | { | ||||
closeOpenDialogs(); | closeOpenDialogs(); | ||||
pauseGame(); | pauseGame(); | ||||
messageBox( | messageBox( | ||||
▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | callbackFunctionNames => { | ||||
for (let functionName of callbackFunctionNames) | for (let functionName of callbackFunctionNames) | ||||
if (global[functionName]) | if (global[functionName]) | ||||
global[functionName](); | global[functionName](); | ||||
resumeGame(); | resumeGame(); | ||||
}); | }); | ||||
} | } | ||||
function openChat(command = "") | |||||
{ | |||||
if (g_Disconnected) | |||||
return; | |||||
closeOpenDialogs(); | |||||
let chatAddressee = Engine.GetGUIObjectByName("chatAddressee"); | |||||
chatAddressee.selected = chatAddressee.list_data.indexOf(command); | |||||
Engine.GetGUIObjectByName("chatInput").focus(); | |||||
Engine.GetGUIObjectByName("chatDialogPanel").hidden = false; | |||||
updateChatHistory(); | |||||
} | |||||
function closeChat() | |||||
{ | |||||
Engine.GetGUIObjectByName("chatInput").caption = ""; | |||||
Engine.GetGUIObjectByName("chatInput").blur(); // Remove focus | |||||
Engine.GetGUIObjectByName("chatDialogPanel").hidden = true; | |||||
} | |||||
function resizeDiplomacyDialog() | function resizeDiplomacyDialog() | ||||
{ | { | ||||
let dialog = Engine.GetGUIObjectByName("diplomacyDialogPanel"); | let dialog = Engine.GetGUIObjectByName("diplomacyDialogPanel"); | ||||
let size = dialog.size; | let size = dialog.size; | ||||
let resTribCodesLength = g_ResourceData.GetTributableCodes().length; | let resTribCodesLength = g_ResourceData.GetTributableCodes().length; | ||||
if (resTribCodesLength) | if (resTribCodesLength) | ||||
{ | { | ||||
let tribSize = Engine.GetGUIObjectByName("diplomacyPlayer[0]_tribute[0]").size; | let tribSize = Engine.GetGUIObjectByName("diplomacyPlayer[0]_tribute[0]").size; | ||||
let widthOffset = resTribCodesLength * (tribSize.right - tribSize.left) / 2; | let widthOffset = resTribCodesLength * (tribSize.right - tribSize.left) / 2; | ||||
size.left -= widthOffset; | size.left -= widthOffset; | ||||
size.right += widthOffset; | size.right += widthOffset; | ||||
} | } | ||||
else | else | ||||
Engine.GetGUIObjectByName("diplomacyHeaderTribute").hidden = true; | Engine.GetGUIObjectByName("diplomacyHeaderTribute").hidden = true; | ||||
let firstRow = Engine.GetGUIObjectByName("diplomacyPlayer[0]").size; | let firstRow = Engine.GetGUIObjectByName("diplomacyPlayer[0]").size; | ||||
let heightOffset = (g_Players.length - 1) * (firstRow.bottom - firstRow.top) / 2; | let heightOffset = (g_Players.length - 1) * (firstRow.bottom - firstRow.top) / 2; | ||||
size.top -= heightOffset; | size.top -= heightOffset; | ||||
size.bottom += heightOffset; | size.bottom += heightOffset; | ||||
dialog.size = size; | dialog.size = size; | ||||
} | } | ||||
function initChatWindow() | |||||
{ | |||||
let filters = prepareForDropdown(g_ChatHistoryFilters.filter(chatFilter => !chatFilter.hidden)); | |||||
let chatHistoryFilter = Engine.GetGUIObjectByName("chatHistoryFilter"); | |||||
chatHistoryFilter.list = filters.text; | |||||
chatHistoryFilter.list_data = filters.key; | |||||
chatHistoryFilter.selected = 0; | |||||
Engine.GetGUIObjectByName("extendedChat").checked = | |||||
Engine.ConfigDB_GetValue("user", "chat.session.extended") == "true"; | |||||
resizeChatWindow(); | |||||
} | |||||
function resizeChatWindow() | |||||
{ | |||||
// Hide/show the panel | |||||
let chatHistoryPage = Engine.GetGUIObjectByName("chatHistoryPage"); | |||||
let extended = Engine.GetGUIObjectByName("extendedChat").checked; | |||||
chatHistoryPage.hidden = !extended; | |||||
// Resize the window | |||||
let chatDialogPanel = Engine.GetGUIObjectByName("chatDialogPanel"); | |||||
if (extended) | |||||
{ | |||||
chatDialogPanel.size = Engine.GetGUIObjectByName("chatDialogPanelLarge").size; | |||||
// Adjust the width so that the chat history is in the golden ratio | |||||
let chatHistory = Engine.GetGUIObjectByName("chatHistory"); | |||||
let height = chatHistory.getComputedSize().bottom - chatHistory.getComputedSize().top; | |||||
let width = (1 + Math.sqrt(5)) / 2 * height; | |||||
let size = chatDialogPanel.size; | |||||
size.left = -width / 2 - chatHistory.size.left; | |||||
size.right = width / 2 + chatHistory.size.left; | |||||
chatDialogPanel.size = size; | |||||
} | |||||
else | |||||
chatDialogPanel.size = Engine.GetGUIObjectByName("chatDialogPanelSmall").size; | |||||
} | |||||
function updateChatHistory() | |||||
{ | |||||
if (Engine.GetGUIObjectByName("chatDialogPanel").hidden || | |||||
!Engine.GetGUIObjectByName("extendedChat").checked) | |||||
return; | |||||
let chatHistoryFilter = Engine.GetGUIObjectByName("chatHistoryFilter"); | |||||
let selected = chatHistoryFilter.list_data[chatHistoryFilter.selected]; | |||||
Engine.GetGUIObjectByName("chatHistory").caption = | |||||
g_ChatHistory.filter(msg => msg.filter[selected]).map(msg => | |||||
Engine.ConfigDB_GetValue("user", "chat.timestamp") == "true" ? | |||||
sprintf(translate("%(time)s %(message)s"), { | |||||
"time": msg.timePrefix, | |||||
"message": msg.txt | |||||
}) : | |||||
msg.txt | |||||
).join("\n"); | |||||
} | |||||
function onToggleChatWindowExtended() | |||||
{ | |||||
Engine.ConfigDB_CreateAndWriteValueToFile("user", "chat.session.extended", String(Engine.GetGUIObjectByName("extendedChat").checked), "config/user.cfg"); | |||||
resizeChatWindow(); | |||||
Engine.GetGUIObjectByName("chatInput").focus(); | |||||
} | |||||
function openDiplomacy() | function openDiplomacy() | ||||
{ | { | ||||
closeOpenDialogs(); | closeOpenDialogs(); | ||||
if (g_ViewedPlayer < 1) | if (g_ViewedPlayer < 1) | ||||
return; | return; | ||||
g_IsDiplomacyOpen = true; | g_IsDiplomacyOpen = true; | ||||
▲ Show 20 Lines • Show All 871 Lines • ▼ Show 20 Lines | function openManual() | ||||
closeOpenDialogs(); | closeOpenDialogs(); | ||||
pauseGame(); | pauseGame(); | ||||
Engine.PushGuiPage("page_manual.xml", {}, resumeGame); | Engine.PushGuiPage("page_manual.xml", {}, resumeGame); | ||||
} | } | ||||
function closeOpenDialogs() | function closeOpenDialogs() | ||||
{ | { | ||||
closeMenu(); | closeMenu(); | ||||
closeChat(); | |||||
closeDiplomacy(); | closeDiplomacy(); | ||||
closeTrade(); | closeTrade(); | ||||
closeObjectives(); | closeObjectives(); | ||||
g_Chat.closePage(); | |||||
} | } | ||||
function formatTributeTooltip(playerID, resourceCode, amount) | function formatTributeTooltip(playerID, resourceCode, amount) | ||||
{ | { | ||||
return sprintf(translate("Tribute %(resourceAmount)s %(resourceType)s to %(playerName)s. Shift-click to tribute %(greaterAmount)s."), { | return sprintf(translate("Tribute %(resourceAmount)s %(resourceType)s to %(playerName)s. Shift-click to tribute %(greaterAmount)s."), { | ||||
"resourceAmount": amount, | "resourceAmount": amount, | ||||
"resourceType": resourceNameWithinSentence(resourceCode), | "resourceType": resourceNameWithinSentence(resourceCode), | ||||
"playerName": colorizePlayernameByID(playerID), | "playerName": colorizePlayernameByID(playerID), | ||||
"greaterAmount": amount < 500 ? 500 : amount + 500 | "greaterAmount": amount < 500 ? 500 : amount + 500 | ||||
}); | }); | ||||
} | } |
Wildfire Games · Phabricator