Quick Message hotbar.

Signed-off-by: Armored Dragon <publicmail@armoreddragon.com>
This commit is contained in:
Armored Dragon 2024-05-22 20:37:10 -05:00
parent 9bf5f3d0d3
commit 86f8e29096
No known key found for this signature in database
GPG key ID: C7207ACC3382AD8B
3 changed files with 116 additions and 1 deletions

View file

@ -20,11 +20,13 @@
var tablet;
var chat_overlay_window;
var app_button;
var quick_message;
const channels = ["domain", "local"];
var message_history = Settings.getValue("ArmoredChat-Messages", []) || [];
var max_local_distance = 20; // Maximum range for the local chat
var pal_data = AvatarManager.getPalData().data;
Controller.keyPressEvent.connect(keyPressEvent);
Messages.subscribe("chat");
Messages.messageReceived.connect(receivedMessage);
AvatarManager.avatarAddedEvent.connect((session_id) => {
@ -56,6 +58,10 @@
// Overlay button toggle
app_button.clicked.connect(toggleMainChatWindow);
quick_message = new OverlayWindow({
source: Script.resolvePath("./armored_chat_quick_message.qml"),
});
_openWindow();
}
function toggleMainChatWindow() {
@ -83,6 +89,7 @@
chat_overlay_window.closed.connect(toggleMainChatWindow);
chat_overlay_window.fromQml.connect(fromQML);
quick_message.fromQml.connect(fromQML);
}
function receivedMessage(channel, message) {
// Is the message a chat message?
@ -129,7 +136,6 @@
}
Settings.setValue("ArmoredChat-Messages", message_history);
}
function fromQML(event) {
console.log(`New QML event:\n${JSON.stringify(event)}`);
@ -170,6 +176,15 @@
break;
}
}
function keyPressEvent(event) {
switch (JSON.stringify(event.key)) {
case "16777220": // Enter key
quick_message.sendToQml({
type: "change_visibility",
value: true,
});
}
}
function _sendMessage(message, channel) {
Messages.sendMessage(
"chat",

View file

@ -198,6 +198,7 @@ Rectangle {
width: parent.width - 60
height: parent.height
placeholderText: pageVal.charAt(0).toUpperCase() + pageVal.slice(1) + " chat message..."
clip: false
Keys.onPressed: {
if ((event.key === Qt.Key_Return || event.key === Qt.Key_Enter) && !(event.modifiers & Qt.ShiftModifier)) {
event.accepted = true;

View file

@ -0,0 +1,99 @@
import QtQuick 2.5
import QtQuick.Controls 1.4
Rectangle {
id: root
property var window
Binding { target: root; property:'window'; value: parent.parent; when: Boolean(parent.parent) }
Binding { target: window; property: 'shown'; value: false; when: Boolean(window) }
Component.onDestruction: chat_bar && chat_bar.destroy()
property alias chat_bar: chat_bar
Rectangle {
id: chat_bar
parent: desktop
x: 0
y: parent.height - height
width: parent.width
height: 50
z: 99
visible: false
TextArea {
id: textArea
x: 0
width: parent.width
height: parent.height
text:""
textColor: "#ffffff"
clip: false
font.pointSize: 18
Keys.onReturnPressed: { _onEnterPressed(); }
Keys.onEnterPressed: { _onEnterPressed(); }
}
Text {
text: "Local message..."
font.pointSize: 16
color: "gray"
x: 0
width: parent.width
anchors.verticalCenter: parent.verticalCenter
visible: textArea.text == ""
}
Button {
id: button
x: parent.width - width
y: 0
width: 64
height: parent.height
clip: false
visible: true
Image {
id: image
width: 30
height: 30
fillMode: Image.PreserveAspectFit
visible: true
anchors.centerIn: parent
source: "./img/ui/send_white.png"
}
onClicked: {
_onEnterPressed();
}
}
}
function _onEnterPressed() {
changeVisibility(false)
toScript({type: "send_message", message: textArea.text, channel: "local"})
textArea.text = "";
}
function changeVisibility(state){
chat_bar.visible = state
if (state) textArea.forceActiveFocus();
else root.parent.forceActiveFocus();
}
// Messages from script
function fromScript(message) {
switch (message.type){
case "change_visibility":
changeVisibility(message.value)
break;
}
}
// Send message to script
function toScript(packet){
sendToScript(packet)
}
}