Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

TribesGUI.HUDMessagePane


00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
class HUDMessagePane extends HUDList;

import enum EMessageType from ClientSideCharacter;

var() config String TemplateMessageLabelName	"Name of the template label properties";
var() config int	MaxMessages					"Max numer of messages to be displayed at once";
var() config int	MaxDisplayableLines			"Max number of actual text lines allowed in the display";

var() config bool	bAlwaysVisible				"Whether the message window is always visible";
var() config bool	bScrollable					"Whether the message window is scrollable";

var() config float	MessageFadeDuration			"How long irrelevant messages should take to fade away";
var() config float	MessageLifetime				"Fixed lifetime for messages";
var() config float	SecondsPerWord				"Number of seconds per word";
var() config float	MinimumLifetime				"Lower bound on message lifetime";

var() config String MessageStyles[EMessageType.MAX_MESSAGE_TYPES];

var HUDTextMessage PaddingMessage;
var int TotalLines;
var int FirstLineOffset;

var ObjectPool MessagePool;

function InitElement()
{
	super.InitElement();

	MessagePool = new class'Engine.ObjectPool';
}

// functions to be implemented in subclasses
function GetNewMessages(ClientSideCharacter c);

// will only be valid after the window HAS a message
function int GetLineHeight(Canvas canvas)
{
	if(children[0] != None)
		return HUDMessage(children[0]).GetLineHeight(canvas);

	// default value?
	return 8;
}

function UpdateData(ClientSideCharacter c)
{
	// get the messages from the clientsidecharacter
	GetNewMessages(c);

	// update the data after new messages have been added,
	// so that they get the current TimeSeconds
	super.UpdateData(c);

	// check all the messages for validity
	UpdateMessageVisibility();
}

function AddMessage(HUDMessage newMessage)
{
	local Array<String> messageWords;
	
	newMessage.AppearTime = TimeSeconds;
	newMessage.FadeOutDuration = MessageFadeDuration;
	if(MessageLifetime > 0)
		newMessage.Lifetime = MessageLifetime;
	else if(SecondsPerWord > 0)
		newMessage.Lifetime = Max(MinimumLifetime, SecondsPerWord * Split(newMessage.GetText(), " ", messageWords));
	else
		newMessage.Lifetime = -1;

	newMessage.Reset();

	AddExistingElement(newMessage);
}

function ScrollMessages(int ScrollDelta)
{
	FirstLineOffset += ScrollDelta;

	FirstLineOffset = Clamp(FirstLineOffset, maxDisplayableLines - TotalLines, 0);

	SetNeedsLayout();
}

function UpdateMessageVisibility()
{
	local int i;
	local HUDMessage nextMessage;

	if(bScrollable)
		return;

	for(i = children.Length - MaxMessages; i >= 0; --i)
	{
		MessagePool.FreeObject(Children[i]);
		RemoveElementAt(i);
	}

	// check all the messages to see if they should be
	// still hanging around
	for(i = 0; i < children.Length; ++i)
	{
		nextMessage = HUDMessage(children[i]);
		nextMessage.UpdateVisibility();

		if(nextMessage.bVisible == false)
		{
			RemoveElementAt(i--);
			MessagePool.FreeObject(nextMessage);
		}
	}
}

function DoLayout(Canvas c)
{
	local int i, numLines, LineOffset;
	local HUDMessage nextMessage;
	local String Padding;

	super.DoLayout(c);

	TotalLines = 0;
	LineOffset = FirstLineOffset;

	if(bScrollable)
	{
		if(PaddingMessage == None)
		{
			PaddingMessage = HUDTextMessage(CreateHUDElement(class'TribesGUI.HUDTextMessage', ""));
			PaddingMessage.ParentElement = self;
		}
	
		if(children.Length == 0 || children[0] != PaddingMessage)
		{
			children.Insert(0, 1);
			children[0] = PaddingMessage;
		}
		PaddingMessage.bVisible = false;

		// check messages to ensure the first message
		// is only rendering from the correct line
		for(i = children.Length - 1; i >= 0; --i)
		{
			if(children[i] != PaddingMessage)
			{
				nextMessage = HUDMessage(children[i]);

				// if we are already over the limit, mark the message as irrelevant
				if(numLines >= maxDisplayableLines)
					nextMessage.bVisible = false;

				TotalLines += nextMessage.GetNumLines();

				if(LineOffset >= 0)
				{
					nextMessage.bVisible = true;
					numLines += nextMessage.GetNumLines();

					// doing this means that messages will only display from the 
					// first line which fits onto the display, this could mean none 
					// of the message gets displayed.
					if(numLines > maxDisplayableLines)
						nextMessage.SetFirstVisibleLine(numLines - maxDisplayableLines);
					else
						nextMessage.SetFirstVisibleLine(0);
				}
				else
					nextMessage.bVisible = false;

				LineOffset += nextMessage.GetNumLines();
			}
		}

		if(TotalLines < maxDisplayableLines)
		{
			for(i = 0; i < maxDisplayableLines - TotalLines; ++i)
				Padding $= " ¼";
			PaddingMessage.SetText(MessageStyles[EMessageType.MessageType_Global], Padding);
			PaddingMessage.bVisible = true;
		}
		else
		{
			PaddingMessage.bVisible = false;
		}

		// relayout to push any remaining labels up into the new space
		super.DoLayout(c);
	}
}

defaultproperties
{
	MaxDisplayableLines=6
	MessageFadeDuration=0.7
	SecondsPerWord=0.75
	MinimumLifetime=5

	MessageStyles(0)="GlobalMessage"
	MessageStyles(1)="AllyMessage"
	MessageStyles(2)="EnemyMessage"
	MessageStyles(3)="SubtitleMessage"
	MessageStyles(4)="SystemMessage"
	MessageStyles(5)="StatHighMessage"
	MessageStyles(6)="StatMediumMessage"
	MessageStyles(7)="StatLowMessage"
	MessageStyles(8)="StatPenaltyMessage"
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: st 16.4.2014 10:20:44.000 - Creation time: st 23.5.2018 00:10:44.370 - Created with UnCodeX