forked from mirrors/0ad
6ec5855136
Add tooltips for buttons that can be triggered with hotkeys. Unassign menu animation onTick function after the animation finished, refs9a00398e24. Cleans unused openMenu following5aae5ee55a. Differential Revision: https://code.wildfiregames.com/D2380 This was SVN commit r23080.
91 lines
2.3 KiB
JavaScript
91 lines
2.3 KiB
JavaScript
/**
|
|
* This class is concerned with setting up the text input field and the send button.
|
|
*/
|
|
class ChatInput
|
|
{
|
|
constructor()
|
|
{
|
|
this.selectedCommand = "";
|
|
this.chatSubmitHandlers = [];
|
|
this.chatSubmittedHandlers = [];
|
|
|
|
this.chatInput = Engine.GetGUIObjectByName("chatInput");
|
|
this.chatInput.onPress = this.submitChatInput.bind(this);
|
|
this.chatInput.onTab = this.autoComplete.bind(this);
|
|
|
|
this.sendChat = Engine.GetGUIObjectByName("sendChat");
|
|
this.sendChat.onPress = this.submitChatInput.bind(this);
|
|
|
|
registerHotkeyChangeHandler(this.onHotkeyChange.bind(this));
|
|
}
|
|
|
|
onHotkeyChange()
|
|
{
|
|
let tooltip = this.getInputHotkeyTooltip() + this.getOpenHotkeyTooltip();
|
|
this.chatInput.tooltip = tooltip;
|
|
this.sendChat.tooltip = tooltip;
|
|
}
|
|
|
|
getInputHotkeyTooltip()
|
|
{
|
|
return translateWithContext("chat input", "Type the message to send.") + "\n" +
|
|
colorizeAutocompleteHotkey();
|
|
}
|
|
|
|
getOpenHotkeyTooltip()
|
|
{
|
|
return 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");
|
|
}
|
|
|
|
/**
|
|
* The functions registered using this function will be called sequentially
|
|
* when the user submits chat, until one of them returns true.
|
|
*/
|
|
registerChatSubmitHandler(handler)
|
|
{
|
|
this.chatSubmitHandlers.push(handler);
|
|
}
|
|
|
|
/**
|
|
* The functions registered using this function will be called after the user submitted chat input.
|
|
*/
|
|
registerChatSubmittedHandler(handler)
|
|
{
|
|
this.chatSubmittedHandlers.push(handler);
|
|
}
|
|
|
|
/**
|
|
* Called each time the addressee dropdown changes selection.
|
|
*/
|
|
onSelectionChange(command)
|
|
{
|
|
this.selectedCommand = command;
|
|
}
|
|
|
|
autoComplete()
|
|
{
|
|
let playernames = [];
|
|
for (let player in g_PlayerAssignments)
|
|
playernames.push(g_PlayerAssignments[player].name);
|
|
autoCompleteText(this.chatInput, playernames);
|
|
}
|
|
|
|
submitChatInput()
|
|
{
|
|
let text = this.chatInput.caption;
|
|
if (!text.length)
|
|
return;
|
|
|
|
this.chatSubmitHandlers.some(handler => handler(text, this.selectedCommand));
|
|
|
|
for (let handler of this.chatSubmittedHandlers)
|
|
handler();
|
|
}
|
|
}
|