diff --git a/scripts/communityModules/chat/FloofChat.js b/scripts/communityModules/chat/FloofChat.js index 438adb662d..2e9a08f241 100644 --- a/scripts/communityModules/chat/FloofChat.js +++ b/scripts/communityModules/chat/FloofChat.js @@ -28,13 +28,18 @@ var appUUID = Uuid.generate(); var chatBar; var chatHistory; +var chatBarHistoryLimit = Settings.getValue(settingsRoot + "/chatBarHistoryLimit", 256); +var chatHistoryLimit = Settings.getValue(settingsRoot + "/chatHistoryLimit", 500); +var chatBarHistory = Settings.getValue(settingsRoot + "/chatBarHistory", ["Meow :3"]); var historyLog = []; - var visible = false; var historyVisible = false; var settingsRoot = "FloofChat"; +var darlingGotoUrl = "http://metaverse.darlingvr.club:8081/goto.json"; +var gotoJSONUrl = Settings.getValue(settingsRoot + "/gotoJSONUrl", darlingGotoUrl); + var muted = Settings.getValue(settingsRoot + "/muted", {"Local": false, "Domain": false, "Grid": false}); var ws; @@ -69,7 +74,7 @@ function init() { button.clicked.connect(toggleChatHistory); chatBar.fromQml.connect(fromQml); - chatBar.sendToQml(JSON.stringify({visible: false})); + chatBar.sendToQml(JSON.stringify({visible: false, history: chatBarHistory})); Controller.keyPressEvent.connect(keyPressEvent); Messages.messageReceived.connect(messageReceived); @@ -172,42 +177,76 @@ function chatColour(tab) { var chatBarChannel = "Local"; +function go2(msg) { + var dest = false; + var domainsList = []; + try { + domainsList = Script.require("http://metaverse.darlingvr.club:8081/goto.json"); + } catch (e) { + // + } + domainsList.forEach(function (domain) { + if (domain["Domain Name"].toLowerCase().indexOf(msg.toLowerCase()) !== -1 && !dest) { + dest = {"name": domain["Domain Name"], "url": domain["Visit"]}; + } + }); + return dest; +} -function gotoConfirm(url) { - var result = Window.confirm("Do you want to go to '" + ((url.indexOf("/") !== -1) ? url.split("/")[2] : url) + "'?"); +function gotoConfirm(url, name, confirm) { + confirm = confirm === undefined ? true : confirm; + name = name === undefined ? url : name; + var result = true; + if (confirm) { + result = Window.confirm("Do you want to go to '" + ((name.indexOf("/") !== -1) ? url.split("/")[2] : name) + "'?"); + } if (result) { location = url; } } function processChat(cmd) { + + function commandResult() { + msg = ""; + setVisible(false); + } + var msg = cmd.message; if (msg.indexOf("/") === 0) { msg = msg.substring(1); var commandList = msg.split(" "); + var tempList = commandList.concat(); + tempList.shift(); + var restOfMsg = tempList.join(" "); + + msg = "/" + msg; var cmd1 = commandList[0].toLowerCase(); if (cmd1 === "l") { chatBarChannel = "Local"; - msg = ""; + commandResult(); } if (cmd1 === "d") { chatBarChannel = "Domain"; - msg = ""; + commandResult(); } if (cmd1 === "g") { chatBarChannel = "Grid"; - msg = ""; + commandResult(); } - if (cmd1 === "goto") { - gotoConfirm(commandList[1]); - msg = ""; + if (cmd1 === "goto" || cmd1 === "gotos") { + var result = go2(restOfMsg); + if (result) { + gotoConfirm(result.url, result.name, (cmd1 === "goto")); + } else { + gotoConfirm(commandList[1], undefined, (cmd1 === "goto")); + } + commandResult(); } if (cmd1 === "me") { - var tempList = commandList; - tempList.shift(); - msg = cmd.avatarName + " " + tempList.join(" "); + msg = cmd.avatarName + " " + restOfMsg; cmd.avatarName = ""; } } @@ -415,12 +454,20 @@ function time() { function addToLog(msg, dp, colour, tab) { historyLog.push([time(), msg, dp, colour, tab]); chatHistory.emitScriptEvent(JSON.stringify({type: "MSG", data: [[time(), msg, dp, colour, tab]]})); - while (historyLog.length > 500) { + while (historyLog.length > chatHistoryLimit) { historyLog.shift(); } Settings.setValue(settingsRoot + "/HistoryLog", JSON.stringify(historyLog)) } +function addToChatBarHistory(msg) { + chatBarHistory.unshift(msg); + while (chatBarHistory.length > chatBarHistoryLimit) { + chatBarHistory.pop(); + } + Settings.setValue(settingsRoot + "/chatBarHistory", chatBarHistory); +} + function fromQml(message) { var cmd = {FAILED: true}; try { @@ -431,6 +478,7 @@ function fromQml(message) { if (!cmd.FAILED) { if (cmd.type === "MSG") { if (cmd.message !== "") { + addToChatBarHistory(cmd.message); if (cmd.event.modifiers === CONTROL_KEY) { cmd.avatarName = MyAvatar.displayName; cmd = processChat(cmd); diff --git a/scripts/communityModules/chat/FloofChat.qml b/scripts/communityModules/chat/FloofChat.qml index ef72b4886f..8d96bf7e42 100644 --- a/scripts/communityModules/chat/FloofChat.qml +++ b/scripts/communityModules/chat/FloofChat.qml @@ -11,6 +11,8 @@ Rectangle { Binding { target: window; property: 'shown'; value: false; when: Boolean(window) } Component.onDestruction: thing && thing.destroy() + property var hist : -1; + property var history : []; signal sendToScript(var message); color: "#00000000" @@ -28,18 +30,21 @@ Rectangle { } catch(e){ // } - if(!data.failed){ - if(data.cmd){ + if (!data.failed) { + if (data.cmd) { JSConsole.executeCommand(data.msg); } console.log(data.visible); - if(data.visible){ + if (data.visible) { thing.visible = true; textArea.focus = true; - } else if(!data.visible){ + } else if (!data.visible) { thing.visible = false; textArea.focus = false; } + if (data.history) { + history = data.history; + } } } @@ -64,13 +69,36 @@ Rectangle { clip: false font.pointSize: 20 - function _onEnterPressed(event) - { - sendMessage(JSON.stringify({type:"MSG",message:text,event:event})); + function _onEnterPressed(event) { + sendMessage(JSON.stringify({type:"MSG", message:text, event:event})); + history.unshift(text); text = ""; + hist = -1; } - Keys.onReturnPressed: { _onEnterPressed(event) } - Keys.onEnterPressed: { _onEnterPressed(event) } + + function upPressed(event) { + hist++; + if (hist > history.length-1) { + hist = history.length-1; + } + text = history[hist]; + } + function downPressed(event) { + hist--; + if (hist < -1) { + hist = -1; + } + if (hist === -1) { + text = ""; + } else{ + text = history[hist]; + } + } + + Keys.onReturnPressed: { _onEnterPressed(event); } + Keys.onEnterPressed: { _onEnterPressed(event); } + Keys.onUpPressed: { upPressed(event); } + Keys.onDownPressed: { downPressed(event); } } MouseArea {