Index: binaries/data/mods/public/gui/gamesetup/Chat/ChatInputAutocomplete.js =================================================================== --- binaries/data/mods/public/gui/gamesetup/Chat/ChatInputAutocomplete.js +++ binaries/data/mods/public/gui/gamesetup/Chat/ChatInputAutocomplete.js @@ -1,12 +1,13 @@ class ChatInputAutocomplete { - constructor(gameSettingControlManager, gameSettingsController, playerAssignmentsController) + constructor() { - this.gameSettingControlManager = gameSettingControlManager; this.entries = undefined; + } - playerAssignmentsController.registerPlayerAssignmentsChangeHandler(this.onAutocompleteChange.bind(this)); - gameSettingsController.registerSettingsChangeHandler(this.onAutocompleteChange.bind(this)); + setAutocompleteGetter(getter) + { + this.entryGetter = getter; } onAutocompleteChange() @@ -24,7 +25,10 @@ // Maps from priority to autocompletable strings let entries = { "0": [] }; - this.gameSettingControlManager.addAutocompleteEntries(entries); + if (!this.entryGetter) + return entries; + + this.entryGetter(this.entries); let allEntries = Object.keys(entries).sort((a, b) => +b - +a).reduce( (all, priority) => all.concat(entries[priority]), Index: binaries/data/mods/public/gui/gamesetup/Chat/ChatInputPanel.js =================================================================== --- binaries/data/mods/public/gui/gamesetup/Chat/ChatInputPanel.js +++ binaries/data/mods/public/gui/gamesetup/Chat/ChatInputPanel.js @@ -1,6 +1,6 @@ class ChatInputPanel { - constructor(netMessages, chatInputAutocomplete) + constructor(chatInputAutocomplete) { this.chatInputAutocomplete = chatInputAutocomplete; @@ -12,18 +12,12 @@ this.chatSubmitButton = Engine.GetGUIObjectByName("chatSubmitButton"); this.chatSubmitButton.onPress = this.onPress.bind(this); - - netMessages.registerNetMessageHandler("netstatus", this.onNetStatusMessage.bind(this)); } - onNetStatusMessage(message) + setEnabled(enabled) { - if (message.status == "disconnected") - { - reportDisconnect(message.reason, true); - this.chatInput.hidden = true; - this.chatSubmitButton.hidden = true; - } + this.chatInput.hidden = !enabled; + this.chatSubmitButton.hidden = !enabled; } onTab() Index: binaries/data/mods/public/gui/gamesetup/Chat/ChatMessagesPanel.js =================================================================== --- /dev/null +++ binaries/data/mods/public/gui/gamesetup/Chat/ChatMessagesPanel.js @@ -0,0 +1,39 @@ +/** + * This class stores and displays the chat history since the login and + * displays timestamps if enabled. + */ +class ChatMessagesPanel +{ + constructor(useTimestampWrapper) + { + this.chatHistory = ""; + + this.statusMessageFormat = new StatusMessageFormat(); + + if (useTimestampWrapper) + this.timestampWrapper = new TimestampWrapper(); + + this.chatText = Engine.GetGUIObjectByName("chatText"); + } + + addText(text) + { + if (this.timestampWrapper) + text = this.timestampWrapper.format(text); + + this.chatHistory += this.chatHistory ? "\n" + text : text; + this.chatText.addItem(text); + } + + addStatusMessage(text) + { + this.addText(this.statusMessageFormat.format(text)); + } + + clearChatMessages() + { + this.chatHistory = ""; + this.chatText.list = []; + this.chatText.list_data = []; + } +} Index: binaries/data/mods/public/gui/gamesetup/Chat/ChatPanel.js =================================================================== --- /dev/null +++ binaries/data/mods/public/gui/gamesetup/Chat/ChatPanel.js @@ -0,0 +1,80 @@ +/** + * This class handles a relatively generic chat panel. + */ +class ChatPanel +{ + constructor(useTimestampWrapper) + { + this.statusMessageFormat = new StatusMessageFormat(); + + this.chatMessagesPanel = new ChatMessagesPanel(useTimestampWrapper); + this.chatInputAutocomplete = new ChatInputAutocomplete(); + this.chatInputPanel = new ChatInputPanel(this.chatInputAutocomplete); + + this.chatPanel = Engine.GetGUIObjectByName("chatPanel"); + this.chatPanel.onWindowResized = () => this.updateHidden; + + this.hidden = false; + } + + setAutocompleteGetter(getter) + { + this.chatInputAutocomplete.setAutocompleteGetter(getter); + } + + onAutocompleteChange() + { + this.chatInputAutocomplete.onAutocompleteChange(); + } + + addText(text) + { + this.chatMessagesPanel.addText(text); + } + + addStatusMessage(text) + { + this.chatMessagesPanel.addStatusMessage(text); + } + + clearChatMessages() + { + this.chatMessagesPanel.clearChatMessages(); + } + + setEnabledInput(enabled) + { + this.chatInputPanel.setEnabled(enabled); + } + + getSize() + { + return this.chatPanel.size; + } + + setSize(size) + { + this.chatPanel.size = size; + this.updateHidden(); + } + + setHidden(hidden) + { + if (this.hidden !== hidden) + { + this.hidden = hidden; + this.updateHidden(); + } + } + + updateHidden() + { + let size = this.chatPanel.getComputedSize(); + this.chatPanel.hidden = this.hidden || size.right - size.left < this.MinimumWidth; + } +} + +/** + * Minimum amount of pixels required for the chat panel to be visible. + */ +ChatPanel.prototype.MinimumWidth = 96; Index: binaries/data/mods/public/gui/gamesetup/Chat/ChatPanel.xml =================================================================== --- binaries/data/mods/public/gui/gamesetup/Chat/ChatPanel.xml +++ binaries/data/mods/public/gui/gamesetup/Chat/ChatPanel.xml @@ -1,6 +1,8 @@ +