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

TribesGUI.HUDValueBar


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
// A bar that could be an energy bar or a health bar.
// The 'maximum value' of the bar is user-defined. 
class HUDValueBar extends HUDContainer
	native;

var() config HUDMaterial	emptyTexture	"Default Texture for the empty bar";
var() config HUDMaterial	fullTexture		"Default Texture for the full bar";

var() config float		barStartOffset	"X offset (in texture co-ords) of the start of the bar region";
var() config float		barEndOffset	"X offset (in texture co-ords) of the end of the bar region";

var() config float		value			"current value of the bar";
var() config float		maximumValue	"max value for the bar";

var() config HUDMaterial	activeEmptyTexture	"Texture for the empty bar";
var() config HUDMaterial	activeFullTexture	"Texture for the full bar";

var() config String			LabelConfigName		"Name of the config item for the label";
var() config int			MaxDisplayDigits	"Maximum number of digitd to display";
var HUDNumericTextureLabel	ValueLabel			"Value label";

var float barStart;			// will contain the offset from the start of the texture to the actual value region
var float barEnd;			// will contain the offset from the end of the texture to the end of the actual value region
var float barWidth;			// will contain the width of the actual bar region
var float ratio;			// current ratio of value/maximumValue
var bool bReverse;			// whether to reverse the direction of the value

CPPTEXT
{
	// Internal NativeRender function.
	virtual void RenderElement(UCanvas *canvas);

	void ClipToValue(UCanvas *canvas, FHUDMaterial mat, float clipRatio);
}

native function ClipToValue(Canvas C, HUDMaterial mat, float clipRatio);

function InitElement()
{
	super.InitElement();
	activeEmptyTexture = emptyTexture;
	activeFullTexture = fullTexture;

	if(LabelConfigName != "" && ValueLabel == None)
	{
		ValueLabel = HUDNumericTextureLabel(AddClonedElement("TribesGUI.HUDNumericTextureLabel", LabelConfigName));
	}
}

function UpdateData(ClientSideCharacter c)
{
	local String ValueString;
	local int IntValue, paddingCount, i;

	// calc the ratio
	CalculateRatio();

	// set the value of the label before it gets rendered
	if(ValueLabel != None)
	{
		IntValue = int(value);
		if(IntValue < value)
			IntValue += 1;
		ValueString $= IntValue;
		paddingCount = MaxDisplayDigits - Len(ValueString);
		for(i = 0; i < paddingCount; ++i)
			ValueString = "0" $ValueString;
		ValueLabel.SetDataString(valueString);
	}
}

//
// Calculates the current ratio
//
function CalculateRatio()
{
	if(value > maximumValue)
		ratio = 1;
	else
		ratio = value / maximumValue;

	if(bReverse)
		ratio = 1.0 - ratio;
}
/*
//
// Clips the passed cavas to the current ratio
//
function ClipToValue(Canvas canvas, HUDMaterial mat, float clipRatio)
{
	local float textureElementSizeRatio;
	
	if(mat.material == None)
		return;

	if(mat.coords.UL > 0)
		textureElementSizeRatio = Width / mat.coords.UL;
	else
		textureElementSizeRatio = Width / mat.material.GetUSize();

	// clip the texture for the full bar
	barStart = barStartOffset * textureElementSizeRatio;
	barEnd = barEndOffset * textureElementSizeRatio;
	barWidth = Width - (barStart + barEnd);
	C.ClipX = barStart + (clipRatio * barWidth);
}


//
// Renders the element
//
function RenderElement(Canvas C)
{
	local float oldClipX;

	super.RenderElement(C);


	// draw the empty bar
	RenderHUDMaterial(C, activeEmptyTexture, Width, Height);
	// DrawTile sets CurX, CurY
	C.CurX = 0;
	C.CurY = 0;

	// Clip to the current bar value
	oldClipX = C.ClipX;	
	ClipToValue(C, activeFullTexture, ratio);

	// draw the full bar, clipped to the ratio
	RenderHUDMaterial(C, activeFullTexture, Width, Height);
	// DrawTile sets CurX, CurY
	C.CurX = 0;
	C.CurY = 0;
	
	// return to the old clip
	C.ClipX = oldClipX;
}
*/
defaultproperties
{
	barStartOffset	= 0
	maximumValue	= 500
	MaxDisplayDigits = 3
}

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