Hi All,

Inspired by Melchior's new property interface (and copying most of his 
techniques), I've written an enhancement to the chat interface that allows 
users to write chat messages much more easily. The patches below binds a 
keyboard handler to the "-" key, creating a nice easy way to compose chat 
messages without needing the normal chat window. 

This feature was suggested on the IRC channel a couple of nights ago. I don't 
remember who it was - but they have my thanks for suggesting it.

I fully expect that the key will be re-assigned later as part of the general 
discussion of keyboard bindings, but there is at least some logic to it: I'm 
planning a menu-system for the chat allowing people to compose canned messages 
("KSFO Traffic, G-MWLX is downwind, runway 28L") with a couple of key presses, 
for which I'm hoping to use the 1-9 keys.

If someone could review it and commit to CVS, I would be very grateful. 

As always, comments are very welcome - my aim it to make the text-based chat 
interface usable for the 0.9.11 release as a stop-gap until the FG-COM becomes 
the standard.

Best regards to all - and a happy Thanksgiving for those celebrating it!

-Stuart

Index: keyboard.xml
===================================================================
RCS file: /var/cvs/FlightGear-0.9/data/keyboard.xml,v
retrieving revision 1.101
diff -u -r1.101 keyboard.xml
--- keyboard.xml    13 Nov 2007 14:42:44 -0000    1.101
+++ keyboard.xml    22 Nov 2007 21:01:55 -0000
@@ -354,7 +354,17 @@
   </mod-up>
  </key>
 
- <key n="46">
+  <key n="45">
+    <name>-</name>
+    <repeatable type="bool">false</repeatable>
+    <desc>Compose Chat</desc>
+    <binding>
+      <command>nasal</command>
+      <script>multiplayer.compose_message()</script>
+    </binding>
+  </key>
+
+  <key n="46">
   <name>.</name>
   <desc>Right brake</desc>
   <binding>


Index: multiplayer.nas
===================================================================
RCS file: /var/cvs/FlightGear-0.9/data/Nasal/multiplayer.nas,v
retrieving revision 1.3
diff -u -r1.3 multiplayer.nas
--- multiplayer.nas    15 Oct 2007 18:27:42 -0000    1.3
+++ multiplayer.nas    22 Nov 2007 21:53:40 -0000
@@ -72,7 +72,6 @@
    }
 }
 
-
 settimer(func {
   # Call-back to ensure we see our own messages.
   setlistener("/sim/multiplay/chat", func(n) { echo_message(n.getValue(), 
getprop("/sim/multiplay/callsign")); });
@@ -82,4 +81,71 @@
 
 }, 1);
 
+# Message composition function, activated using the - key.
+var prefix = "Chat Message:";
+var input = "";
+var kbdlistener = nil;
+
+compose_message = func() 
+{
+  input = prefix;
+  gui.popupTip(input, 1000000);        
+  
+  kbdlistener = setlistener("/devices/status/keyboard/event", func {
+    var event = cmdarg();
+    var key = event.getNode("key");
+    
+    # Only check the key when pressed.
+    if (!event.getNode("pressed").getValue())
+        return;
+    
+    if (handle_key(key.getValue()))
+        key.setValue(0);           # drop key event
+  });
+}
 
+handle_key = func(key)
+{
+  if (key == `\n` or key == `\r`) 
+  {  
+    # CR/LF -> send the message
+    
+    # Trim off the prefix
+    input = substr(input, size(prefix), size(input) - size(prefix));
+    # Send the message and switch off the listener.
+    setprop("/sim/multiplay/chat", input);
+    removelistener(kbdlistener);
+    gui.popdown();
+    return 1;
+  }
+  elsif (key == 8) 
+  {
+    # backspace -> remove a character
+    
+    if (size(input) > size(prefix))
+    {
+      input = substr(input, 0, size(input) - 1);
+      gui.popupTip(input, 1000000);        
+      return 1;
+    }
+  }
+  elsif (key == 27) 
+  {
+    # escape -> cancel
+    removelistener(kbdlistener);
+    gui.popdown();
+    return 1;
+  } 
+  elsif ((key > 31) and (key < 128))
+  {
+    # Normal character - add it to the input
+    input ~= chr(key);
+    gui.popupTip(input, 1000000);        
+    return 1;
+  }
+  else
+  {
+    # Unknown character - pass through
+    return 0;    
+  }
+}





      ___________________________________________________________
Yahoo! Answers - Got a question? Someone out there knows the answer. Try it
now.
http://uk.answers.yahoo.com/ 

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to