diff --git a/Nasal/multiplayer.nas b/Nasal/multiplayer.nas new file mode 100644 index 000000000..312b1adf7 --- /dev/null +++ b/Nasal/multiplayer.nas @@ -0,0 +1,85 @@ +# Multiplayer Chat +# ================ +# +# 1) Display chat messages from other aircraft to +# the screen using screen.nas +# +# 2) Display a complete history of chat via dialog. +# +# 3) Allow chat messages to be written by the user. + +var messages = {}; + +check_messages = func +{ + + var mp = props.globals.getNode("/ai/models").getChildren("multiplayer"); + + foreach (i; mp) + { + var lmsg = getprop(i.getPath() ~ "/sim/multiplay/chat"); + var lcallsign = getprop(i.getPath() ~ "/callsign"); + + if ((lmsg != nil) and (lmsg != "") and (lcallsign != nil) and (lcallsign != "")) + { + #print("Call Sign: " ~ lcallsign); + #print("lmsg: " ~ lmsg); + #print("Freq: " ~ ltransmitfreq); + + if ((! contains(messages, lcallsign)) or (lmsg != messages[lcallsign])) + { + # Indicate we've seen this message. + messages[lcallsign] = lmsg; + echo_message(lmsg, lcallsign); + } + } + } + + # Check for new messages every couple of seconds. + settimer(check_messages, 3); +} + +echo_message = func(msg, callsign) +{ + if (callsign != nil) + { + msg = callsign ~ ": " ~ msg; + } + + var ldisplay = getprop("/sim/multiplay/chat_display"); + + if ((ldisplay != nil) and (ldisplay == "1")) + { + # Only display the message to screen if configured. + setprop("/sim/messages/ai-plane", msg); + } + + # Add the chat to the chat history. + var lchat = getprop("/sim/multiplay/chat_history"); + + if (lchat == nil) + { + setprop("/sim/multiplay/chat_history", msg); + } + else + { + if (substr(lchat, size(lchat) -1, 1) != "\n") + { + lchat = lchat ~ "\n"; + } + + setprop("/sim/multiplay/chat_history", lchat ~ msg); + } +} + + +settimer(func { + # Call-back to ensure we see our own messages. + setlistener("/sim/multiplay/chat", func{ echo_message(cmdarg().getValue(), getprop("/sim/multiplay/callsign")); }); + + # check for new messages + check_messages(); + +}, 1); + + diff --git a/gui/dialogs/chat.xml b/gui/dialogs/chat.xml new file mode 100644 index 000000000..0fec4b754 --- /dev/null +++ b/gui/dialogs/chat.xml @@ -0,0 +1,71 @@ + + + + chat + false + vbox + + + hbox + + + compose + 500 + true + fill + 50 + /sim/multiplay/chat_compose + + + + + + + + hbox + true + + + + + + true + + diff --git a/gui/dialogs/chat_full.xml b/gui/dialogs/chat_full.xml new file mode 100644 index 000000000..1e52e9f23 --- /dev/null +++ b/gui/dialogs/chat_full.xml @@ -0,0 +1,98 @@ + + + + chat_full + false + vbox + + + + + + + + + fill + 550 + 120 + 20 + true + true + false + /sim/multiplay/chat_history + + + + + + + + hbox + + + compose + true + fill + 50 + 500 + /sim/multiplay/chat_compose + + + + + + + + + + + + hbox + true + + + + + + + + true + + diff --git a/gui/dialogs/rendering.xml b/gui/dialogs/rendering.xml index 4832983a0..b335e147c 100644 --- a/gui/dialogs/rendering.xml +++ b/gui/dialogs/rendering.xml @@ -24,6 +24,15 @@ + + left + + /sim/multiplay/chat_display + + dialog-apply + + + left diff --git a/gui/menubar.xml b/gui/menubar.xml index 09c11a837..7794aadb8 100644 --- a/gui/menubar.xml +++ b/gui/menubar.xml @@ -152,6 +152,15 @@ + + + + + dialog-show + chat + + + diff --git a/preferences.xml b/preferences.xml index 0d88027f0..f994b3ad7 100644 --- a/preferences.xml +++ b/preferences.xml @@ -12,6 +12,11 @@ Started September 2000 by David Megginson, david@megginson.com + + + Hello + 118500000 + false