MessageHistory Issue #2065 and 2066

Topics: Developer Forum
Aug 19, 2006 at 1:24 PM
I tried to attach this information in the issue tracker but I kept getting an error message, so I'll put in here if there is room:

Created a MessageHistory class to handle on going history of every message during the users game.

' User: thorkia
' Date: 8/19/2006
' Time: 8:12 AM
'
' Class to handle message display and history
'
' What Needs to be done:
' 1. Add code to create a new instance when game starts
' 2. Alter code so that every message that displays is added to the message history
' 3. Add a new command to the main loop so display the message history

Imports System
Imports System.Collections
imports System.Collections.Generic

Public Class MessageHistory

Private m_MessageList As List(of Message)

Private Const LINESPERSCREEN as Integer = 30
Private Const MAXSTRINGLENGTH as Integer = 40

Public Sub New()
Dim m_MessageList As New List(of Message)
End Sub

'Display the message you want in the standard message locations
'Also add the message to the message list
Public Sub DisplayMessage(ByVal Text As String, Optional ByVal ForeColor As Integer = 15, Optional ByVal BackColor As Integer = 0)
Dim NewMessage As new Message(Text, ForeColor,BackColor)
m_MessageList.Add(NewMessage)

If Text>MAXSTRINGLENGTH Then
Dim messages As String()
messages = Divide(Text)
WriteAt(1,0,messages(0),ForeColor,BackColor)
WriteAt(1,1,messages(1),ForeColor,BackColor)
Else
WriteAt(1,0,Text,ForeColor,BackColor)
End If
End Sub

Public Sub AddMessage(ByVal Text As String, Optional ByVal ForeColor As Integer = 15, Optional ByVal BackColor As Integer = 0)
Dim NewMessage As new Message(Text, ForeColor,BackColor)
m_MessageList.Add(NewMessage)
End Sub

Public Sub DisplayHistoryMostRecentFirst
Dim index As Integer
Dim rowcount As Integer

Console.Clear()
For index = m_MessageList.Count To 1
rowcount = 0
Do While rowcount<LINESPERSCREEN
If m_MessageList.Item(index).Text.Length>MAXSTRINGLENGTH Then
Dim messages As String()
messages = Divide(m_MessageList.Item(index).Text)
WriteAt(1,rowcount,messages(0),mMessageList.Item(index).ForeColor,mMessageList.Item(index).BackColor)
WriteAt(1,rowcount+1,messages(1),mMessageList.Item(index).ForeColor,mMessageList.Item(index).BackColor)
rowcount = rowcount+2
Else
WriteAt(1,rowcount,mMessageList.Item(index).Text,mMessageList.Item(index).ForeColor,m_MessageList.Item(index).BackColor)
rowcount = rowcount + 1
End If
Loop
WriteAt(1,rowcount,"Press esc to stop, any other key to continue")
If Console.ReadKey().Key=ConsoleKey.Escape Then
Exit For
End If
Next
Console.Clear()
End Sub

Public Sub DisplayHistoryOldestFirst
Dim index As Integer
Dim rowcount As Integer

Console.Clear()
For index = 1 to m_MessageList.Count
rowcount = 0
Do While rowcount<LINESPERSCREEN
If m_MessageList.Item(index).Text.Length>MAXSTRINGLENGTH Then
Dim messages As String()
messages = Divide(m_MessageList.Item(index).Text)
WriteAt(1,rowcount,messages(0),mMessageList.Item(index).ForeColor,mMessageList.Item(index).BackColor)
WriteAt(1,rowcount+1,messages(1),mMessageList.Item(index).ForeColor,mMessageList.Item(index).BackColor)
rowcount = rowcount+2
Else
WriteAt(1,rowcount,mMessageList.Item(index).Text,mMessageList.Item(index).ForeColor,m_MessageList.Item(index).BackColor)
rowcount = rowcount + 1
End If
Loop
WriteAt(1,rowcount,"Press esc to stop, any other key to continue")
If Console.ReadKey().Key=ConsoleKey.Escape Then
Exit For
End If
Next
Console.Clear()
End Sub

'Divide the string in to to strings if it's too long
Private Function Divide(byval Message as String) As String()

Dim splitstring(2) As String
Dim position As Integer

For position = MAXSTRINGLENGTH To 1
If Message.Substring(position) = " " Then
Exit for
End If
Next

splitstring(0) = Message.Substring(0,position)
splitstring(1) = Message.Substring(position+1)

Return splitstring
End Function

End Class


'Basic Message Class to contain all necessary information for a message
Public Class Message
Private m_Message as String
Private m_ForeColor As Integer
Private m_BackColor As Integer

Public Sub New(ByVal Message As String, Optional ByVal ForeColor As Integer = 15, Optional ByVal BackColor As Integer = 0)
m_Message = Message
m_ForeColor = ForeColor
m_BackColor = BackColor
End Sub

Public ReadOnly Property Text() As string
Get
Return m_Message
End Get
End Property

Public ReadOnly Property ForeColor() As Integer
Get
Return m_ForeColor
End Get
End Property

Public ReadOnly Property BackColor() As Integer
Get
Return m_BackColor
End Get
End Property

End Class
Coordinator
Aug 22, 2006 at 12:24 AM
Thanks, this looks good.

I'll see about integrating it over the weekend.