home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / Fracas20867210102007.psc / Fracas_VB / ChatForm.frm < prev    next >
Text File  |  2001-07-10  |  12KB  |  420 lines

  1. VERSION 5.00
  2. Begin VB.Form ChatForm 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "Chat"
  5.    ClientHeight    =   3555
  6.    ClientLeft      =   45
  7.    ClientTop       =   360
  8.    ClientWidth     =   9510
  9.    Icon            =   "ChatForm.frx":0000
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   3555
  14.    ScaleWidth      =   9510
  15.    ShowInTaskbar   =   0   'False
  16.    StartUpPosition =   1  'CenterOwner
  17.    Begin VB.CommandButton ExitBut 
  18.       Caption         =   "Exit"
  19.       Height          =   285
  20.       Left            =   8520
  21.       TabIndex        =   26
  22.       Top             =   3120
  23.       Width           =   855
  24.    End
  25.    Begin VB.CommandButton SendBut 
  26.       Caption         =   "Send"
  27.       Height          =   285
  28.       Left            =   7560
  29.       TabIndex        =   25
  30.       Top             =   3120
  31.       Width           =   855
  32.    End
  33.    Begin VB.TextBox ChatText 
  34.       Height          =   285
  35.       Left            =   120
  36.       TabIndex        =   24
  37.       Text            =   "Text1"
  38.       Top             =   3120
  39.       Width           =   7335
  40.    End
  41.    Begin VB.Label TextSlot 
  42.       Caption         =   "Label1"
  43.       Height          =   225
  44.       Index           =   11
  45.       Left            =   1560
  46.       TabIndex        =   23
  47.       Top             =   2520
  48.       Width           =   7815
  49.    End
  50.    Begin VB.Label NameSlot 
  51.       Alignment       =   2  'Center
  52.       Caption         =   "Label1"
  53.       Height          =   225
  54.       Index           =   11
  55.       Left            =   120
  56.       TabIndex        =   22
  57.       Top             =   2520
  58.       Width           =   1215
  59.    End
  60.    Begin VB.Label TextSlot 
  61.       Caption         =   "Label1"
  62.       Height          =   225
  63.       Index           =   10
  64.       Left            =   1560
  65.       TabIndex        =   21
  66.       Top             =   2280
  67.       Width           =   7815
  68.    End
  69.    Begin VB.Label NameSlot 
  70.       Alignment       =   2  'Center
  71.       Caption         =   "Label1"
  72.       Height          =   225
  73.       Index           =   10
  74.       Left            =   120
  75.       TabIndex        =   20
  76.       Top             =   2280
  77.       Width           =   1215
  78.    End
  79.    Begin VB.Label TextSlot 
  80.       Caption         =   "Label1"
  81.       Height          =   225
  82.       Index           =   9
  83.       Left            =   1560
  84.       TabIndex        =   19
  85.       Top             =   2040
  86.       Width           =   7815
  87.    End
  88.    Begin VB.Label NameSlot 
  89.       Alignment       =   2  'Center
  90.       Caption         =   "Label1"
  91.       Height          =   225
  92.       Index           =   9
  93.       Left            =   120
  94.       TabIndex        =   18
  95.       Top             =   2040
  96.       Width           =   1215
  97.    End
  98.    Begin VB.Label TextSlot 
  99.       Caption         =   "Label1"
  100.       Height          =   225
  101.       Index           =   8
  102.       Left            =   1560
  103.       TabIndex        =   17
  104.       Top             =   1800
  105.       Width           =   7815
  106.    End
  107.    Begin VB.Label NameSlot 
  108.       Alignment       =   2  'Center
  109.       Caption         =   "Label1"
  110.       Height          =   225
  111.       Index           =   8
  112.       Left            =   120
  113.       TabIndex        =   16
  114.       Top             =   1800
  115.       Width           =   1215
  116.    End
  117.    Begin VB.Label TextSlot 
  118.       Caption         =   "Label1"
  119.       Height          =   225
  120.       Index           =   7
  121.       Left            =   1560
  122.       TabIndex        =   15
  123.       Top             =   1560
  124.       Width           =   7815
  125.    End
  126.    Begin VB.Label NameSlot 
  127.       Alignment       =   2  'Center
  128.       Caption         =   "Label1"
  129.       Height          =   225
  130.       Index           =   7
  131.       Left            =   120
  132.       TabIndex        =   14
  133.       Top             =   1560
  134.       Width           =   1215
  135.    End
  136.    Begin VB.Label TextSlot 
  137.       Caption         =   "Label1"
  138.       Height          =   225
  139.       Index           =   6
  140.       Left            =   1560
  141.       TabIndex        =   13
  142.       Top             =   1320
  143.       Width           =   7815
  144.    End
  145.    Begin VB.Label NameSlot 
  146.       Alignment       =   2  'Center
  147.       Caption         =   "Label1"
  148.       Height          =   225
  149.       Index           =   6
  150.       Left            =   120
  151.       TabIndex        =   12
  152.       Top             =   1320
  153.       Width           =   1215
  154.    End
  155.    Begin VB.Label TextSlot 
  156.       Caption         =   "Label1"
  157.       Height          =   225
  158.       Index           =   5
  159.       Left            =   1560
  160.       TabIndex        =   11
  161.       Top             =   1080
  162.       Width           =   7815
  163.    End
  164.    Begin VB.Label NameSlot 
  165.       Alignment       =   2  'Center
  166.       Caption         =   "Label1"
  167.       Height          =   225
  168.       Index           =   5
  169.       Left            =   120
  170.       TabIndex        =   10
  171.       Top             =   1080
  172.       Width           =   1215
  173.    End
  174.    Begin VB.Label TextSlot 
  175.       Caption         =   "Label1"
  176.       Height          =   225
  177.       Index           =   4
  178.       Left            =   1560
  179.       TabIndex        =   9
  180.       Top             =   840
  181.       Width           =   7815
  182.    End
  183.    Begin VB.Label NameSlot 
  184.       Alignment       =   2  'Center
  185.       Caption         =   "Label1"
  186.       Height          =   225
  187.       Index           =   4
  188.       Left            =   120
  189.       TabIndex        =   8
  190.       Top             =   840
  191.       Width           =   1215
  192.    End
  193.    Begin VB.Label TextSlot 
  194.       Caption         =   "Label1"
  195.       Height          =   225
  196.       Index           =   3
  197.       Left            =   1560
  198.       TabIndex        =   7
  199.       Top             =   600
  200.       Width           =   7815
  201.    End
  202.    Begin VB.Label NameSlot 
  203.       Alignment       =   2  'Center
  204.       Caption         =   "Label1"
  205.       Height          =   225
  206.       Index           =   3
  207.       Left            =   120
  208.       TabIndex        =   6
  209.       Top             =   600
  210.       Width           =   1215
  211.    End
  212.    Begin VB.Label TextSlot 
  213.       Caption         =   "Label1"
  214.       Height          =   225
  215.       Index           =   2
  216.       Left            =   1560
  217.       TabIndex        =   5
  218.       Top             =   360
  219.       Width           =   7815
  220.    End
  221.    Begin VB.Label NameSlot 
  222.       Alignment       =   2  'Center
  223.       Caption         =   "Label1"
  224.       Height          =   225
  225.       Index           =   2
  226.       Left            =   120
  227.       TabIndex        =   4
  228.       Top             =   360
  229.       Width           =   1215
  230.    End
  231.    Begin VB.Label TextSlot 
  232.       Caption         =   "Label1"
  233.       Height          =   225
  234.       Index           =   1
  235.       Left            =   1560
  236.       TabIndex        =   3
  237.       Top             =   120
  238.       Width           =   7815
  239.    End
  240.    Begin VB.Label NameSlot 
  241.       Alignment       =   2  'Center
  242.       Caption         =   "Label1"
  243.       Height          =   225
  244.       Index           =   1
  245.       Left            =   120
  246.       TabIndex        =   2
  247.       Top             =   120
  248.       Width           =   1215
  249.    End
  250.    Begin VB.Label TextSlot 
  251.       Caption         =   "Label1"
  252.       Height          =   225
  253.       Index           =   12
  254.       Left            =   1560
  255.       TabIndex        =   1
  256.       Top             =   2760
  257.       Width           =   7815
  258.    End
  259.    Begin VB.Label NameSlot 
  260.       Alignment       =   2  'Center
  261.       Caption         =   "Label1"
  262.       Height          =   225
  263.       Index           =   12
  264.       Left            =   120
  265.       TabIndex        =   0
  266.       Top             =   2760
  267.       Width           =   1215
  268.    End
  269. End
  270. Attribute VB_Name = "ChatForm"
  271. Attribute VB_GlobalNameSpace = False
  272. Attribute VB_Creatable = False
  273. Attribute VB_PredeclaredId = True
  274. Attribute VB_Exposed = False
  275. Option Explicit
  276. Option Base 1
  277.  
  278. Const NUM_CHAT_LINES = 12
  279.  
  280. Private Sub Form_Load()
  281.  
  282. Dim i As Integer
  283.  
  284. For i = 1 To NUM_CHAT_LINES
  285.   NameSlot(i).Caption = vbNullString
  286.   TextSlot(i).Caption = vbNullString
  287.   NameSlot(i).BackColor = ChatForm.BackColor
  288.   TextSlot(i).BackColor = ChatForm.BackColor
  289.   ChatText.Text = vbNullString
  290.   SendBut.Default = True
  291. Next i
  292.  
  293. End Sub
  294.  
  295. Private Sub ExitBut_Click()
  296.  
  297. Me.Hide
  298.  
  299. End Sub
  300.  
  301. Private Sub SendBut_Click()
  302.  
  303. Dim Sender As Integer
  304. Dim HumanCt As Integer
  305. Dim i As Integer
  306.  
  307. 'Leave if not in a network game
  308. If MyNetworkRole = NW_NONE Then Exit Sub
  309.  
  310. 'We are in a network game.  Send this text on out.
  311. If ChatText.Text = vbNullString Then Exit Sub
  312.  
  313. If MyClientIndex = 0 Then
  314.   'We're a server, and we could have *several* humans on this machine chatting.
  315.   'If there's only one human, then that's the sender.  Otherwise, the sender is HOST.
  316.   HumanCt = 0
  317.   For i = 1 To MAX_PLAYERS
  318.     If PlayerType(i) = PTYPE_HUMAN Then
  319.       HumanCt = HumanCt + 1
  320.       Sender = i
  321.     End If
  322.   Next i
  323.   If HumanCt <> 1 Then Sender = 0
  324. Else
  325.   'We're a client, the sender is us.
  326.   Sender = MyClientIndex
  327. End If
  328.  
  329. 'Send it to the network.
  330. SendChatToNetwork Sender, RemoveLeadingSpace(ChatText.Text), 0
  331. 'Update our own chat lines.
  332. ChatTextReceived Sender, RemoveLeadingSpace(ChatText.Text)
  333.  
  334. ChatText.Text = vbNullString
  335. ChatText.SetFocus
  336.  
  337. End Sub
  338.  
  339. Public Sub ChatTextReceived(PlayerNum As Integer, TextLine As String)
  340.  
  341. Dim ChName As String
  342. Dim ChBackColor As Long
  343. Dim ChForeColor As Long
  344. Dim TxBackColor As Long
  345. Dim TxForeColor As Long
  346. Dim TxBold As Boolean
  347.  
  348. BumpUpChatLines
  349.  
  350. If PlayerNum = 0 Then
  351.   ChName = "Host"
  352.   ChBackColor = vbWhite
  353.   ChForeColor = vbBlack
  354.   TxBackColor = ChatForm.BackColor
  355.   TxForeColor = vbBlack
  356. Else
  357.   ChName = PlayerName(PlayerNum)
  358.   ChBackColor = PlayerColorCodes(Player(PlayerNum))
  359.   ChForeColor = PlayerTextColor(Player(PlayerNum))
  360.   TxBackColor = ChatForm.BackColor
  361.   TxForeColor = vbBlack
  362. End If
  363.  
  364. TxBold = False
  365. If LCase(Left(TextLine, 3)) = "/me" Then
  366.   TextLine = Right(TextLine, Len(TextLine) - 3)
  367.   TextLine = RemoveLeadingSpace(TextLine)
  368.   If TextLine = vbNullString Then TextLine = "..."
  369.   TextLine = ChName & " " & TextLine
  370.   TxBold = True
  371.   TxBackColor = ChBackColor
  372.   ChName = vbNullString
  373.   ChBackColor = ChatForm.BackColor
  374. End If
  375.  
  376. NameSlot(NUM_CHAT_LINES).Caption = ChName
  377. NameSlot(NUM_CHAT_LINES).BackColor = ChBackColor
  378. NameSlot(NUM_CHAT_LINES).ForeColor = ChForeColor
  379. TextSlot(NUM_CHAT_LINES).FontBold = TxBold
  380. TextSlot(NUM_CHAT_LINES).Caption = TextLine
  381. TextSlot(NUM_CHAT_LINES).BackColor = TxBackColor
  382. TextSlot(NUM_CHAT_LINES).ForeColor = TxForeColor
  383.  
  384. End Sub
  385.  
  386. Private Sub BumpUpChatLines()
  387.  
  388. Dim i As Integer
  389.  
  390. 'This sub just moves everything up one slot to make room for a new chat line.
  391.  
  392. For i = 2 To NUM_CHAT_LINES
  393.   NameSlot(i - 1).Caption = NameSlot(i).Caption
  394.   NameSlot(i - 1).BackColor = NameSlot(i).BackColor
  395.   NameSlot(i - 1).ForeColor = NameSlot(i).ForeColor
  396.   TextSlot(i - 1).FontBold = TextSlot(i).FontBold
  397.   TextSlot(i - 1).Caption = TextSlot(i).Caption
  398.   TextSlot(i - 1).BackColor = TextSlot(i).BackColor
  399.   TextSlot(i - 1).ForeColor = TextSlot(i).ForeColor
  400. Next i
  401.  
  402. End Sub
  403.  
  404. Private Function RemoveLeadingSpace(MyStr As String)
  405.  
  406. Dim Done As Boolean
  407.  
  408. Done = False
  409. Do
  410.   If Left(MyStr, 1) = " " Then
  411.     MyStr = Right(MyStr, Len(MyStr) - 1)
  412.   Else
  413.     Done = True
  414.   End If
  415. Loop Until Done = True
  416.  
  417. RemoveLeadingSpace = MyStr
  418.  
  419. End Function
  420.