KF2-YetAnotherScoreboard/YAS/Classes/KFGUI_TextScroll.uc

185 lines
3.6 KiB
Ucode
Raw Normal View History

2022-09-03 17:26:40 +00:00
class KFGUI_TextScroll extends KFGUI_TextField;
2021-06-12 20:11:37 +00:00
2020-01-10 13:14:11 +00:00
var float ScrollSpeed;
var transient float CharStartTime;
var transient bool bScrollCompleted, bTextDirty;
2021-06-13 03:17:40 +00:00
var transient array<bool> RowsCompleted;
2020-01-10 13:14:11 +00:00
var transient int MaxIndex, RowsDropped;
2021-06-13 03:00:19 +00:00
function SetText(string S)
2020-01-10 13:14:11 +00:00
{
Super.SetText(S);
MaxIndex = 0;
RowsCompleted.Length = 0;
RowsDropped = 0;
bScrollCompleted = false;
bTextDirty = true;
CharStartTime = GetPlayer().WorldInfo.TimeSeconds;
2020-01-10 13:14:11 +00:00
}
function DrawMenu()
{
2021-06-13 02:54:35 +00:00
local int i, j,k, SLen, CurrentIndex;
local float Y, DTime, XL, YL, MainY, MainX, CharTime;
local string MainString;
local Color MainTextColor;
local Texture CurrentCursor;
local ETextFieldStyles TextStyle;
2021-06-13 02:53:33 +00:00
if (bScrollCompleted)
{
Super.DrawMenu();
return;
}
2021-06-13 02:53:33 +00:00
if (Text == "")
return;
// Need to figure out best fitting font.
2021-06-13 02:53:33 +00:00
if (OldSize[0] != CompPos[2] || OldSize[1] != CompPos[3])
InitSize();
Canvas.Font = InitFont;
2021-06-13 02:53:33 +00:00
if (bShowScrollbar)
{
2021-06-13 02:54:35 +00:00
Canvas.SetClip(CompPos[0]+(CompPos[2]-ScrollWidth), CompPos[1]+CompPos[3]);
i = ScrollBar.GetValue();
}
else i = 0;
2021-06-13 02:53:33 +00:00
if (ScrollBar != None)
{
2021-06-13 02:53:33 +00:00
if (bTextDirty)
{
ScrollBar.bDisabled = true;
RowsCompleted.Length = Lines.Length;
bTextDirty = false;
}
2021-06-13 02:53:33 +00:00
if (RowsCompleted[Lines.Length-1])
{
ScrollBar.AddValue(1);
ScrollBar.bDisabled = false;
bScrollCompleted = true;
//Temp fix! The last line in the string seems to be skipped
AddText(LineSplitter);
return;
}
2021-06-13 02:53:33 +00:00
else if (MaxIndex != 0 && RowsCompleted[MaxIndex])
{
MaxIndex = 0;
ScrollBar.AddValue(1);
RowsDropped++;
i = ScrollBar.GetValue();
}
}
2021-06-13 02:53:33 +00:00
if (RowsDropped > 0)
{
2021-06-13 02:53:33 +00:00
for (i=0; i <= RowsDropped; ++i)
{
2021-06-13 02:53:33 +00:00
for (j=0; j < Lines[i].Text.Length; ++j)
{
2021-06-13 02:53:33 +00:00
for (k=0; k <= Len(Lines[i].Text[j].S); ++k)
{
CharTime += ScrollSpeed;
}
}
}
}
DTime = `TimeSinceEx(GetPlayer(), CharStartTime);
2021-06-13 02:53:33 +00:00
if (i < Lines.Length)
{
CurrentCursor = Owner.DefaultPens[GetCursorStyle()];
Y = Lines[i].Y;
2021-06-13 02:53:33 +00:00
for (i=i; i < Lines.Length; ++i)
{
2021-06-13 02:53:33 +00:00
if ((Lines[i].Y-Y+TextHeight) >= CompPos[3])
{
MaxIndex = i-1;
break;
}
2021-06-13 02:53:33 +00:00
if (Lines[i].Text.Length != 0)
{
2021-06-13 02:53:33 +00:00
for (j=0; j < Lines[i].Text.Length; ++j)
{
MainTextColor = Lines[i].Text[j].C;
2021-06-13 02:53:33 +00:00
if (MainTextColor.A == 0)
MainTextColor = TextColor;
TextStyle = Lines[i].Text[j].TextType;
MainX = Lines[i].Text[j].X;
MainY = Lines[i].Y-Y;
MainString = Lines[i].Text[j].S;
SLen = Len(MainString);
CurrentIndex = 0;
2021-06-13 02:53:33 +00:00
for (k=0; k <= SLen; ++k)
{
CharTime += ScrollSpeed;
Canvas.TextSize(Mid(MainString, 0, k), XL, YL, InitFontScale, InitFontScale);
2021-06-13 02:53:33 +00:00
if (CharTime > DTime)
{
2021-06-13 02:53:33 +00:00
if (CurrentIndex == k)
{
2021-06-13 02:54:35 +00:00
Canvas.SetDrawColor(255, 255, 255, 255);
Canvas.SetPos(MainX+XL, MainY);
Canvas.DrawTile(CurrentCursor, YL/2, YL, 0, 0, CurrentCursor.GetSurfaceWidth(), CurrentCursor.GetSurfaceHeight());
}
continue;
}
Canvas.DrawColor = GetColorFromStyle(MainTextColor, TextStyle);
2021-06-13 02:54:35 +00:00
Canvas.SetPos(MainX+XL, MainY);
Canvas.DrawText(Mid(MainString, k, 1), ,InitFontScale, InitFontScale, TextFontInfo);
CurrentIndex = k+1;
2021-06-13 02:53:33 +00:00
if (k >= SLen)
{
RowsCompleted[i] = true;
}
}
}
}
}
}
2020-01-10 13:14:11 +00:00
}
function bool CaptureMouse()
{
return (!bScrollCompleted && Super(KFGUI_MultiComponent).CaptureMouse()) || Super.CaptureMouse();
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
function MouseClick(bool bRight)
2020-01-10 13:14:11 +00:00
{
2021-06-13 02:53:33 +00:00
if (bScrollCompleted)
return;
2021-06-13 02:53:33 +00:00
if (ScrollBar != None)
ScrollBar.bDisabled = false;
bScrollCompleted = true;
//Temp fix! The last line in the string seems to be skipped
AddText(LineSplitter);
2020-01-10 13:14:11 +00:00
}
defaultproperties
{
ScrollSpeed=0.01
2020-01-10 13:14:11 +00:00
}