Rem *** Include File: chat.dba ***
Rem Created: 10/27/2003 11:03:59 PM

Rem Included in Project: C:\Program Files\Dark Basic Software\Dark Basic Professional\Projects\Duel2\Duel2.dbpro
`this file handles simplistic chat functions

dim GameChat$(10)
global ChatMode
global SK2ASCI$
function ChatPauseKey()
   `this pauses until all keys are released
   do
      if scancode()=0 then exit
      sync
   loop
endfunction
function OutChat(x,y)
   `this reads player text
   sk=scancode()
   if sk=28 then sk=15
   select sk
      case 14
         GameChat$(0)=left$(GameChat$(0),Len(GameChat$(0))-1)
         ChatPauseKey()
      endcase
      case 15
         if Online=1 and len(GameChat$(0))>0
            send net message string 0,GameChat$(0)
         endif
         AddChat(GameChat$(0))
         GameChat$(0)=""
         ChatMode=0
         ChatPauseKey()
      endcase
      case default
         char$=mid$(SK2ASCI$,sk)
         if char$<>"X" then GameChat$(0)=GameChat$(0)+char$
         ChatPauseKey()
      endcase
   endselect
   `debug("Chat="+GameChat$(0))
   text x,y,GameChat$(0)
endfunction

function UpdateChat()
   `this updates the chat display
   for n=1 to 9
      GameChat$(n)=GameChat$(n+1)
   next n
   GameChat$(n)=""
endfunction
function ShowChat(x,y)
   for n=1 to 10
      text x,y+20*(n-1),GameChat$(n)
   next n
endfunction
function AddChat(T$)
   UpdateChat()
   GameChat$(10)=T$
endfunction
function setSK2ASCI()
   `X marks blocked characters"
   `#1= unknown key
   `#14= backspace
   `#15=tab
   `#28= enter key
   `#29=left control key
   `#42=left shift
   `#54=right shift
   `56=Left Alt
   `#58=caps lock
   `59..... function keys f1
   msg$="X1234567890-=XX"
   msg$=msg$+"qwertyuiop[]XX"
   msg$=msg$+"asdfghjkl;'`X\zxcvbnm,./X*X X"
   SK2ASCI$=msg$
   dim GameChat$(10)
   `reply$=mid$(msg$,sk)
endfunction
