KF2-YetAnotherScoreboard/YAS/Classes/GUIStyleBase.uc

877 lines
21 KiB
Ucode
Raw Normal View History

2022-09-03 17:26:40 +00:00
class GUIStyleBase extends Object
abstract;
2020-01-10 13:14:11 +00:00
var Texture2D ItemTex;
2021-06-13 03:17:40 +00:00
var array<Texture2D> BorderTextures, ArrowTextures, ButtonTextures, TabTextures, ItemBoxTextures, PerkBox, CheckBoxTextures, ProgressBarTextures, SliderTextures;
var Texture2D ScrollTexture, FavoriteIcon, BankNoteIcon;
2020-01-10 13:14:11 +00:00
var SoundCue MenuDown, MenuDrag, MenuEdit, MenuFade, MenuClick, MenuHover, MenuUp;
var() byte MaxFontScale;
var float DefaultHeight; // Default font text size.
var transient Canvas Canvas;
var transient KF2GUIController Owner;
2022-09-03 17:26:40 +00:00
var transient YAS_HUD HUDOwner;
2020-01-10 13:14:11 +00:00
var Font MainFont, NumberFont, InfiniteFont;
var Color BlurColor, BlurColor2;
2023-01-30 00:54:43 +00:00
var BoxPainter BoxPainter;
2021-06-13 10:53:19 +00:00
enum ECornerPosition
{
ECP_TopLeft,
ECP_TopRight,
ECP_BottomLeft,
ECP_BottomRight
};
enum ECornerShape
{
ECS_Corner,
ECS_BeveledCorner,
ECS_VerticalCorner,
ECS_HorisontalCorner
};
2020-01-10 13:14:11 +00:00
struct FColorInfo
{
var name Code;
var Color Color;
2020-01-10 13:14:11 +00:00
};
2021-06-13 03:17:40 +00:00
var array<FColorInfo> ColorCodes;
2020-01-10 13:14:11 +00:00
struct FTexturePreCache
{
var string Path;
var Texture2D Tex;
2020-01-10 13:14:11 +00:00
};
2021-06-13 03:17:40 +00:00
var array<FTexturePreCache> PrecachedTextures;
2020-01-10 13:14:11 +00:00
function InitStyle()
{
local FColorInfo ColorInfo;
2021-06-13 02:54:35 +00:00
ItemTex=Texture2D(DynamicLoadObject("UI_LevelChevrons_TEX.UI_LevelChevron_Icon_02", class'Texture2D'));
2021-06-13 02:53:33 +00:00
if (ItemTex == None)
ItemTex=Texture2D'EngineMaterials.DefaultWhiteGrid';
2023-01-30 00:54:43 +00:00
BoxPainter = new class'BoxPainterLib.BoxPainter';
NumberFont = Font(DynamicLoadObject("UI_Canvas_Fonts.Font_General", class'Font'));
BlurColor = MakeColor(60, 60, 60, 220);
BlurColor2 = MakeColor(40, 40, 40, 140);
ColorInfo.Code='Q';
2021-06-13 02:54:35 +00:00
ColorInfo.Color = MakeColor(0, 140, 0,255); // Dark Green
ColorCodes.AddItem(ColorInfo);
ColorInfo.Code='E';
2021-06-13 02:54:35 +00:00
ColorInfo.Color = MakeColor(210, 180, 140, 255); // Tan
ColorCodes.AddItem(ColorInfo);
ColorInfo.Code='R';
2021-06-13 02:54:35 +00:00
ColorInfo.Color = MakeColor(128, 0,0, 255); // Dark Red
ColorCodes.AddItem(ColorInfo);
ColorInfo.Code='T';
2021-06-13 02:54:35 +00:00
ColorInfo.Color = MakeColor(153, 102, 204, 255); // Purple
ColorCodes.AddItem(ColorInfo);
ColorInfo.Code='U';
2021-06-13 02:54:35 +00:00
ColorInfo.Color = MakeColor(128, 128, 128, 255); // Dark Gray
ColorCodes.AddItem(ColorInfo);
ColorInfo.Code='I';
2021-06-13 02:54:35 +00:00
ColorInfo.Color = MakeColor(255, 170, 0,255); // Orange
ColorCodes.AddItem(ColorInfo);
ColorInfo.Code='O';
2021-06-13 02:54:35 +00:00
ColorInfo.Color = MakeColor(255, 204, 153, 255); // Cream
ColorCodes.AddItem(ColorInfo);
ColorInfo.Code='P';
2021-06-13 02:54:35 +00:00
ColorInfo.Color = MakeColor(209, 216, 168, 255); // Olive
ColorCodes.AddItem(ColorInfo);
ColorInfo.Code='A';
2021-06-13 02:54:35 +00:00
ColorInfo.Color = MakeColor(204, 51, 51, 255); // Brick
ColorCodes.AddItem(ColorInfo);
ColorInfo.Code='S';
2021-06-13 02:54:35 +00:00
ColorInfo.Color = MakeColor(153, 102, 51, 255); // Brown
ColorCodes.AddItem(ColorInfo);
ColorInfo.Code='D';
2021-06-13 02:54:35 +00:00
ColorInfo.Color = MakeColor(0, 204, 0,255); // Green
ColorCodes.AddItem(ColorInfo);
ColorInfo.Code='F';
2021-06-13 02:54:35 +00:00
ColorInfo.Color = MakeColor(238, 238, 51, 255); // Yellow
ColorCodes.AddItem(ColorInfo);
ColorInfo.Code='G';
2021-06-13 02:54:35 +00:00
ColorInfo.Color = MakeColor(200, 0,0, 255); // Red
ColorCodes.AddItem(ColorInfo);
ColorInfo.Code='H';
2021-06-13 02:54:35 +00:00
ColorInfo.Color = MakeColor(153, 153, 255, 255); // Blue
ColorCodes.AddItem(ColorInfo);
ColorInfo.Code='J';
2021-06-13 02:54:35 +00:00
ColorInfo.Color = MakeColor(192, 192, 192, 255); // Silver
ColorCodes.AddItem(ColorInfo);
ColorInfo.Code='K';
2021-06-13 02:54:35 +00:00
ColorInfo.Color = MakeColor(255, 204, 0,255); // Gold
ColorCodes.AddItem(ColorInfo);
ColorInfo.Code='C';
2021-06-13 02:54:35 +00:00
ColorInfo.Color = MakeColor(255, 255, 255, 255); // White
ColorCodes.AddItem(ColorInfo);
ColorInfo.Code='V';
2021-06-13 02:54:35 +00:00
ColorInfo.Color = MakeColor(0, 191, 255, 255); // Sky Blue
ColorCodes.AddItem(ColorInfo);
ColorInfo.Code='B';
2021-06-13 02:54:35 +00:00
ColorInfo.Color = MakeColor(204, 204, 204, 255); // Gray
ColorCodes.AddItem(ColorInfo);
ColorInfo.Code='N';
2021-06-13 02:54:35 +00:00
ColorInfo.Color = MakeColor(0, 128, 255, 255); // Dark Sky Blue
ColorCodes.AddItem(ColorInfo);
ColorInfo.Code='M';
2021-06-13 02:54:35 +00:00
ColorInfo.Color = MakeColor(18, 18, 18, 255); // Black
ColorCodes.AddItem(ColorInfo);
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
function RenderFramedWindow(KFGUI_FloatingWindow P);
function RenderWindow(KFGUI_Page P);
function RenderToolTip(KFGUI_Tooltip TT);
function RenderButton(KFGUI_Button B);
function RenderScrollBar(KFGUI_ScrollBarBase S);
function RenderColumnHeader(KFGUI_ColumnTop C, float XPos, float Width, int Index, bool bFocus, bool bSort);
function RenderRightClickMenu(KFGUI_RightClickMenu C);
function RenderCheckbox(KFGUI_CheckBox C);
function RenderComboBox(KFGUI_ComboBox C);
function RenderComboList(KFGUI_ComboSelector C);
function Font PickFont(out float Scaler, optional bool bNumbersOnly, optional bool bInfinite)
2020-01-10 13:14:11 +00:00
{
Scaler = GetFontScaler();
2021-06-13 02:53:33 +00:00
if (bNumbersOnly)
return NumberFont;
2021-06-13 02:53:33 +00:00
else if (bInfinite)
return InfiniteFont;
return MainFont;
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
function PickDefaultFontSize(float YRes)
2020-01-10 13:14:11 +00:00
{
2021-06-13 02:54:35 +00:00
local int XL, YL;
local string S;
S="ABC";
2021-06-13 02:54:35 +00:00
PickFont(YRes).GetStringHeightAndWidth(S, YL, XL);
2020-01-10 13:14:11 +00:00
DefaultHeight=float(YL)*YRes;
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
final function float ScreenScale(float Size, optional float MaxRes=1080.f)
2020-01-10 13:14:11 +00:00
{
local float FillSizeX, FillSizeY;
GetFillScreenSize(FillSizeX, FillSizeY);
return Size * (FillSizeY / MaxRes);
2020-01-10 13:14:11 +00:00
}
2022-09-11 23:57:37 +00:00
final function float GetFontScaler()
2020-01-10 13:14:11 +00:00
{
2022-09-11 23:57:37 +00:00
local float FillSizeX, FillSizeY, Scaler;
GetFillScreenSize(FillSizeX, FillSizeY);
2022-09-11 23:57:37 +00:00
if (FillSizeY <= 1080.0f) { scaler = 0.750f; }
else if (FillSizeY <= 1440.0f) { scaler = 0.562f; }
else if (FillSizeY <= 2160.0f) { scaler = 0.377f; }
else { scaler = 0.190f; }
2022-09-11 23:57:37 +00:00
return FClamp(FillSizeY * scaler / 1080.f, 0.175f, 1.0f);
}
final function GetFillScreenSize(out float SizeX, out float SizeY)
{
local float Base, BaseX, BaseY;
BaseX = HUDOwner.SizeX / 16;
BaseY = HUDOwner.SizeY / 9;
Base = Min(BaseX, BaseY);
SizeX = Base * 16;
SizeY = Base * 9;
2020-01-10 13:14:11 +00:00
}
2022-09-11 21:23:24 +00:00
final function float PickEdgeSize(float DefaultSize = 8.0f)
{
local float FillSizeX, FillSizeY;
2022-09-11 21:23:24 +00:00
GetFillScreenSize(FillSizeX, FillSizeY);
2022-09-11 21:23:24 +00:00
return (FillSizeY / 1080.f) * DefaultSize;
}
2021-06-13 03:00:19 +00:00
final function DrawText(coerce string S)
2020-01-10 13:14:11 +00:00
{
local float Scale;
Canvas.Font=PickFont(Scale);
2021-06-13 02:54:35 +00:00
Canvas.DrawText(S, ,Scale, Scale);
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
final function DrawCenteredText(coerce string S, float X, float Y, optional float Scale=1.f, optional bool bVertical, optional bool bUseOutline)
2020-01-10 13:14:11 +00:00
{
2021-06-13 02:54:35 +00:00
local float XL, YL;
2020-01-10 13:14:11 +00:00
2021-06-13 02:54:35 +00:00
Canvas.TextSize(S, XL, YL);
2021-06-13 02:53:33 +00:00
if (bVertical)
2021-06-13 02:54:35 +00:00
Canvas.SetPos(X, Y-(YL*Scale*0.5));
else Canvas.SetPos(X-(XL*Scale*0.5), Y);
2021-06-13 02:53:33 +00:00
if (bUseOutline)
DrawTextShadow(S, Canvas.CurX, Canvas.CurY, 1, Scale);
2021-06-13 02:54:35 +00:00
else Canvas.DrawText(S, ,Scale, Scale);
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
final function string StripColorTags(coerce string S)
2020-01-10 13:14:11 +00:00
{
local int Pos;
Pos = InStr(S, "\\c");
2021-06-13 03:00:19 +00:00
while (Pos != INDEX_NONE)
{
2021-06-13 02:54:35 +00:00
S = Left(S, Pos) $ Mid(S, Pos+3);
Pos = InStr(S, "\\c");
}
return S;
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
final function DrawColoredText(coerce string S, float X, float Y, optional float Scale=1.f, optional bool bUseOutline)
2020-01-10 13:14:11 +00:00
{
2021-06-13 02:54:35 +00:00
local float XL, YL;
local int i, Index;
2021-06-13 07:29:12 +00:00
local array<string> SArray;
local string T, PrevT;
local Color TextColor;
2021-06-13 02:53:33 +00:00
if (InStr(S, "\\c") == INDEX_NONE)
{
2021-06-13 02:53:33 +00:00
if (bUseOutline)
DrawTextShadow(S, X, Y, 1, Scale);
else
{
2021-06-13 02:54:35 +00:00
Canvas.SetPos(X, Y);
Canvas.DrawText(S, ,Scale, Scale);
}
}
else
{
SArray = SplitString(S, "\\c");
2021-06-13 02:54:35 +00:00
PrevT = Left(S, InStr(S, "\\c"));
2021-06-13 02:53:33 +00:00
if (Len(PrevT) > 0)
{
2021-06-13 02:54:35 +00:00
Canvas.TextSize(PrevT, XL, YL, Scale, Scale);
2021-06-13 02:53:33 +00:00
if (bUseOutline)
DrawTextShadow(PrevT, X, Y, 1, Scale);
else
{
2021-06-13 02:54:35 +00:00
Canvas.SetPos(X, Y);
Canvas.DrawText(PrevT, ,Scale, Scale);
}
}
2021-06-13 02:53:33 +00:00
for (i=0; i < SArray.Length; i++)
{
T = SArray[i];
2021-06-13 02:53:33 +00:00
if (i > 0 || Left(S, 2)~="\\c")
{
Index = ColorCodes.Find('Code', name(Left(T, 1)));
2021-06-13 02:53:33 +00:00
if (Index != INDEX_NONE)
TextColor = ColorCodes[Index].Color;
else TextColor = class'HUD'.default.WhiteColor;
TextColor.A = Canvas.DrawColor.A;
T = Mid(T, 1);
}
Canvas.DrawColor = TextColor;
2021-06-13 02:54:35 +00:00
Canvas.TextSize(T, XL, YL, Scale, Scale);
2021-06-13 02:53:33 +00:00
if (bUseOutline)
DrawTextShadow(T, X, Y, 1, Scale);
else
{
2021-06-13 02:54:35 +00:00
Canvas.SetPos(X, Y);
Canvas.DrawText(T, ,Scale, Scale);
}
X += XL;
}
}
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
final function DrawTextBlurry(coerce string S, float X, float Y, optional float Scale=1.f)
2020-01-10 13:14:11 +00:00
{
local Color OldDrawColor;
OldDrawColor = Canvas.DrawColor;
BlurColor.A = OldDrawColor.A * 0.85;
BlurColor2.A = OldDrawColor.A * 0.55;
Canvas.DrawColor = BlurColor;
Canvas.SetPos(X + Owner.FontBlurX, Y + Owner.FontBlurY);
2021-06-13 02:54:35 +00:00
Canvas.DrawText(S, ,Scale, Scale);
Canvas.DrawColor = BlurColor2;
Canvas.SetPos(X + Owner.FontBlurX2, Y + Owner.FontBlurY2);
2021-06-13 02:54:35 +00:00
Canvas.DrawText(S, ,Scale, Scale);
Canvas.DrawColor = OldDrawColor;
Canvas.SetPos(X, Y);
2021-06-13 02:54:35 +00:00
Canvas.DrawText(S, ,Scale, Scale);
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
final function DrawTextOutline(coerce string S, float X, float Y, int Size, Color OutlineColor, optional float Scale=1.f, optional FontRenderInfo FRI)
2020-01-10 13:14:11 +00:00
{
local Color OldDrawColor;
local int XS, YS, Steps;
OldDrawColor = Canvas.DrawColor;
OutlineColor.A = OldDrawColor.A;
Size += 1;
Steps = (Size * 2) / 3;
if (Steps < 1 )
{
Steps = 1;
}
Canvas.DrawColor = OutlineColor;
for (XS = -Size; XS <= Size; XS+=Steps)
{
for (YS = -Size; YS <= Size; YS+=Steps)
{
Canvas.SetPos(X + XS, Y + YS);
2021-06-13 02:54:35 +00:00
Canvas.DrawText(S, , Scale, Scale, FRI);
}
}
Canvas.DrawColor = OldDrawColor;
Canvas.SetPos(X, Y);
2021-06-13 02:54:35 +00:00
Canvas.DrawText(S, , Scale, Scale, FRI);
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
final function DrawTextShadow(coerce string S, float X, float Y, float ShadowSize, optional float Scale=1.f)
2020-01-10 13:14:11 +00:00
{
local Color OldDrawColor;
OldDrawColor = Canvas.DrawColor;
Canvas.SetPos(X + ShadowSize, Y + ShadowSize);
Canvas.SetDrawColor(0, 0, 0, OldDrawColor.A);
2021-06-13 02:54:35 +00:00
Canvas.DrawText(S, , Scale, Scale);
Canvas.SetPos(X, Y);
Canvas.DrawColor = OldDrawColor;
2021-06-13 02:54:35 +00:00
Canvas.DrawText(S, , Scale, Scale);
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
final function DrawTexturedString(coerce string S, float X, float Y, optional float TextScaler=1.f, optional FontRenderInfo FRI, optional bool bUseOutline, optional bool bOnlyTexture)
2020-01-10 13:14:11 +00:00
{
local Texture2D Mat;
local string D;
local float XL, YL;
2021-06-13 02:54:35 +00:00
local int i, j;
local Color OrgC;
OrgC = Canvas.DrawColor;
Mat = FindNextTexture(S);
2021-06-13 03:00:19 +00:00
while (Mat != None)
{
2021-06-13 07:29:12 +00:00
i = InStr(S, "<TEXTURE");
j = InStr(S, ">");
2021-06-13 02:54:35 +00:00
D = Left(S, i);
S = Mid(S, j+2);
2021-06-13 02:53:33 +00:00
if (!bOnlyTexture)
{
2021-06-13 02:54:35 +00:00
Canvas.TextSize(StripColorTags(D), XL, YL, TextScaler, TextScaler);
DrawColoredText(D, X,Y, TextScaler, bUseOutline);
X += XL;
}
2021-06-13 02:54:35 +00:00
else Canvas.TextSize("W", XL, YL, TextScaler, TextScaler);
Canvas.DrawColor = class'HUD'.default.WhiteColor;
Canvas.DrawColor.A = OrgC.A;
2021-06-13 02:54:35 +00:00
Canvas.SetPos(X, Y+(Owner.HUDOwner.ScaledBorderSize/2));
Canvas.DrawRect(YL-Owner.HUDOwner.ScaledBorderSize, YL-Owner.HUDOwner.ScaledBorderSize, Mat);
X += YL-Owner.HUDOwner.ScaledBorderSize;
Canvas.DrawColor = OrgC;
Mat = FindNextTexture(S);
}
2021-06-13 02:54:35 +00:00
DrawColoredText(S, X,Y, TextScaler, bUseOutline);
2020-01-10 13:14:11 +00:00
}
2020-01-10 13:14:11 +00:00
final function Texture2D FindNextTexture(out string S)
{
local int i, j;
local string Path;
local Texture2D Tex;
local FTexturePreCache Cache;
Path = S;
2021-06-13 07:29:12 +00:00
i = InStr(Path, "<Icon>");
2021-06-13 02:53:33 +00:00
if (i == INDEX_NONE)
return None;
2021-06-13 07:29:12 +00:00
j = InStr(Path, " </Icon>");
S = Left(Path, i)$"<TEXTURE>"$Mid(Path, j+6);
Path = Mid(Path, i+6, j-(i+6));
i = PrecachedTextures.Find('Path', Path);
2021-06-13 02:53:33 +00:00
if (i != INDEX_NONE)
return PrecachedTextures[i].Tex;
Tex = Texture2D(FindObject(Path, class'Texture2D'));
2021-06-13 02:53:33 +00:00
if (Tex != None)
{
Cache.Path = Path;
Cache.Tex = Tex;
PrecachedTextures.AddItem(Cache);
return Tex;
}
Cache.Path = Path;
Cache.Tex = Texture2D(DynamicLoadObject(Path, class'Texture2D'));
PrecachedTextures.AddItem(Cache);
return Cache.Tex;
2020-01-10 13:14:11 +00:00
}
2020-01-10 13:14:11 +00:00
final function string StripTextureFromString(string S, optional bool bNoStringAdd)
{
local int i, j;
2021-06-13 03:00:19 +00:00
while (true)
{
2021-06-13 07:29:12 +00:00
i = InStr(S, "<Icon>");
2021-06-13 02:53:33 +00:00
if (i == INDEX_NONE)
break;
2020-01-10 13:14:11 +00:00
2021-06-13 07:29:12 +00:00
j = InStr(S, "</Icon>");
S = Left(S, i)$(bNoStringAdd ? "" : "W")$Mid(S, j+Len("</Icon>"));
}
return StripColorTags(S);
2020-01-10 13:14:11 +00:00
}
2020-01-10 13:14:11 +00:00
final function string GetTimeString(int Seconds)
{
local int Minutes, Hours;
local string Time;
2020-01-10 13:14:11 +00:00
2021-06-13 02:53:33 +00:00
if (Seconds > 3600)
{
Hours = Seconds / 3600;
Seconds -= Hours * 3600;
2020-01-10 13:14:11 +00:00
Time = Hours$":";
}
Minutes = Seconds / 60;
Seconds -= Minutes * 60;
2020-01-10 13:14:11 +00:00
2021-06-13 02:53:33 +00:00
if (Minutes >= 10)
Time = Time $ Minutes $ ":";
else Time = Time $ "0" $ Minutes $ ":";
2020-01-10 13:14:11 +00:00
2021-06-13 02:53:33 +00:00
if (Seconds >= 10)
Time = Time $ Seconds;
else Time = Time $ "0" $ Seconds;
2020-01-10 13:14:11 +00:00
return Time;
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
final function DrawCornerTexNU(int SizeX, int SizeY, byte Dir ) // Draw non-uniform corner.
2020-01-10 13:14:11 +00:00
{
2021-06-13 03:00:19 +00:00
switch (Dir)
{
case 0: // Up-left
2021-06-13 02:54:35 +00:00
Canvas.DrawTile(ItemTex, SizeX, SizeY, 77, 15, -66, 58);
break;
case 1: // Up-right
2021-06-13 02:54:35 +00:00
Canvas.DrawTile(ItemTex, SizeX, SizeY, 11, 15, 66, 58);
break;
case 2: // Down-left
2021-06-13 02:54:35 +00:00
Canvas.DrawTile(ItemTex, SizeX, SizeY, 77, 73, -66, -58);
break;
default: // Down-right
2021-06-13 02:54:35 +00:00
Canvas.DrawTile(ItemTex, SizeX, SizeY, 11, 73, 66, -58);
}
2020-01-10 13:14:11 +00:00
}
2022-09-11 21:23:24 +00:00
final function DrawCornerTex(float Size, byte Dir)
2020-01-10 13:14:11 +00:00
{
2021-06-13 03:00:19 +00:00
switch (Dir)
{
case 0: // Up-left
2021-06-13 02:54:35 +00:00
Canvas.DrawTile(ItemTex, Size, Size, 77, 15, -66, 58);
break;
case 1: // Up-right
2021-06-13 02:54:35 +00:00
Canvas.DrawTile(ItemTex, Size, Size, 11, 15, 66, 58);
break;
case 2: // Down-left
2021-06-13 02:54:35 +00:00
Canvas.DrawTile(ItemTex, Size, Size, 77, 73, -66, -58);
break;
default: // Down-right
2021-06-13 02:54:35 +00:00
Canvas.DrawTile(ItemTex, Size, Size, 11, 73, 66, -58);
}
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
final function DrawWhiteBox(float XS, float YS, optional bool bClip)
2020-01-10 13:14:11 +00:00
{
2021-06-13 02:54:35 +00:00
Canvas.DrawTile(ItemTex, XS, YS, 19, 45, 1,1, ,bClip);
2020-01-10 13:14:11 +00:00
}
2022-09-11 21:23:24 +00:00
final function DrawRectBox(float X, float Y, float Width, float Height, float Edge, optional byte Extrav)
{
2023-01-30 00:54:43 +00:00
if (BoxPainter.Canvas == None) BoxPainter.Canvas = Canvas;
if (BoxPainter.Canvas != None) BoxPainter.DrawBox(X, Y, Width, Height, Edge, Extrav);
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
final function DrawBoxHollow(float X, float Y, float Width, float Height, float Thickness)
2020-01-10 13:14:11 +00:00
{
Canvas.PreOptimizeDrawTiles(4, ItemTex);
2020-01-10 13:14:11 +00:00
Canvas.SetPos(X + Thickness, Y);
DrawWhiteBox(Width - Thickness * 2, Thickness);
2020-01-10 13:14:11 +00:00
Canvas.SetPos(X + Thickness, Y+Height-Thickness);
DrawWhiteBox(Width - Thickness * 2, Thickness);
2020-01-10 13:14:11 +00:00
Canvas.SetPos(X, Y);
DrawWhiteBox(Thickness, Height);
2020-01-10 13:14:11 +00:00
Canvas.SetPos(X + Width - Thickness, Y);
DrawWhiteBox(Thickness, Height);
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
final function DrawOutlinedBox(float X, float Y, float Width, float Height, float Thickness, Color BoxColor, Color OutlineColor)
2020-01-10 13:14:11 +00:00
{
Canvas.DrawColor = BoxColor;
Canvas.SetPos(X + Thickness, Y + Thickness);
DrawWhiteBox(Width - (Thickness*2), Height - (Thickness*2));
Canvas.DrawColor = OutlineColor;
DrawBoxHollow(X, Y, Width, Height, Thickness);
2020-01-10 13:14:11 +00:00
}
final function DrawBoxCorners(float BorderSize, float X, float Y, float W, float H, optional bool TopLeft, optional bool TopRight, optional bool BottomLeft, optional bool BottomRight)
{
// Top left
2021-06-13 02:54:35 +00:00
Canvas.SetPos(X, Y);
2021-06-13 02:53:33 +00:00
if (TopLeft)
2021-06-13 02:54:35 +00:00
DrawCornerTex(BorderSize, 0);
else DrawWhiteBox(BorderSize, BorderSize);
// Top right
2021-06-13 02:54:35 +00:00
Canvas.SetPos(X+W-BorderSize, Y);
2021-06-13 02:53:33 +00:00
if (TopRight)
2021-06-13 02:54:35 +00:00
DrawCornerTex(BorderSize, 1);
else DrawWhiteBox(BorderSize, BorderSize);
// Bottom left
2021-06-13 02:54:35 +00:00
Canvas.SetPos(X, Y+H-BorderSize);
2021-06-13 02:53:33 +00:00
if (BottomLeft)
2021-06-13 02:54:35 +00:00
DrawCornerTex(BorderSize, 2);
else DrawWhiteBox(BorderSize, BorderSize);
// Bottom right
2021-06-13 02:54:35 +00:00
Canvas.SetPos(X+W-BorderSize, Y+H-BorderSize);
2021-06-13 02:53:33 +00:00
if (BottomRight)
2021-06-13 02:54:35 +00:00
DrawCornerTex(BorderSize, 3);
else DrawWhiteBox(BorderSize, BorderSize);
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
final function DrawRoundedBox(float BorderSize, float X, float Y, float W, float H, Color BoxColor)
2020-01-10 13:14:11 +00:00
{
DrawRoundedBoxEx(BorderSize, X, Y, W, H, BoxColor, true, true, true, true);
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
final function DrawRoundedBoxEx(float BorderSize, float X, float Y, float W, float H, Color BoxColor, optional bool TopLeft, optional bool TopRight, optional bool BottomLeft, optional bool BottomRight)
2020-01-10 13:14:11 +00:00
{
Canvas.DrawColor = BoxColor;
2021-06-13 02:53:33 +00:00
if (BorderSize <= 0)
{
Canvas.SetPos(X, Y);
DrawWhiteBox(W, H);
return;
}
Canvas.PreOptimizeDrawTiles(7, ItemTex);
2020-01-10 13:14:11 +00:00
2021-06-13 02:54:35 +00:00
BorderSize = Min(FMin(BorderSize, (W)*0.5), (H)*0.5);
2020-01-10 13:14:11 +00:00
Canvas.SetPos(X + BorderSize, Y);
DrawWhiteBox(W - BorderSize * 2, H);
2020-01-10 13:14:11 +00:00
Canvas.SetPos(X, Y + BorderSize);
DrawWhiteBox(BorderSize, H - BorderSize * 2);
2020-01-10 13:14:11 +00:00
Canvas.SetPos(X + W - BorderSize, Y + BorderSize);
DrawWhiteBox(BorderSize, H - BorderSize * 2);
DrawBoxCorners(BorderSize, X, Y, W, H, TopLeft, TopRight, BottomLeft, BottomRight);
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
final function DrawRoundedBoxHollow(float BorderSize, float X, float Y, float W, float H, Color BoxColor)
2020-01-10 13:14:11 +00:00
{
DrawRoundedBoxHollowEx(BorderSize, X, Y, W, H, BoxColor, true, true, true, true);
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
final function DrawRoundedBoxHollowEx(float BorderSize, float X, float Y, float W, float H, Color BoxColor, optional bool TopLeft, optional bool TopRight, optional bool BottomLeft, optional bool BottomRight)
2020-01-10 13:14:11 +00:00
{
Canvas.PreOptimizeDrawTiles(8, ItemTex);
2021-06-13 02:54:35 +00:00
BorderSize = Min(FMin(BorderSize, (W)*0.5), (H)*0.5);
Canvas.DrawColor = BoxColor;
Canvas.SetPos(X + BorderSize, Y);
DrawWhiteBox(W - BorderSize * 2, BorderSize);
Canvas.SetPos(X + BorderSize, Y+H-BorderSize);
DrawWhiteBox(W - BorderSize * 2, BorderSize);
2020-01-10 13:14:11 +00:00
Canvas.SetPos(X, Y + BorderSize);
DrawWhiteBox(BorderSize, H - BorderSize * 2);
2020-01-10 13:14:11 +00:00
Canvas.SetPos(X + W - BorderSize, Y + BorderSize);
DrawWhiteBox(BorderSize, H - BorderSize * 2);
2020-01-10 13:14:11 +00:00
DrawBoxCorners(BorderSize, X, Y, W, H, TopLeft, TopRight, BottomLeft, BottomRight);
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
final function DrawRoundedBoxOutlined(float BorderSize, float X, float Y, float Width, float Height, Color BoxColor, Color OutlineColor)
2020-01-10 13:14:11 +00:00
{
Canvas.DrawColor = BoxColor;
Canvas.SetPos(X + BorderSize, Y + BorderSize);
DrawWhiteBox(Width - (BorderSize*2), Height - (BorderSize*2));
DrawRoundedBoxHollow(BorderSize, X, Y, Width, Height, OutlineColor);
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
final function DrawRoundedBoxOutlinedEx(float BorderSize, float X, float Y, float Width, float Height, Color BoxColor, Color OutlineColor, optional bool TopLeft, optional bool TopRight, optional bool BottomLeft, optional bool BottomRight)
2020-01-10 13:14:11 +00:00
{
Canvas.DrawColor = BoxColor;
Canvas.SetPos(X + BorderSize, Y + BorderSize);
DrawWhiteBox(Width - (BorderSize*2), Height - (BorderSize*2));
DrawRoundedBoxHollowEx(BorderSize, X, Y, Width, Height, OutlineColor, TopLeft, TopRight, BottomLeft, BottomRight);
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
final function DrawArrowBox(int Direction, float X, float Y, float Width, float Height)
2020-01-10 13:14:11 +00:00
{
local Texture2D DirectionMat;
2021-06-13 03:00:19 +00:00
switch (Direction)
{
case 0:
DirectionMat=ArrowTextures[`ARROW_UP];
break;
case 1:
DirectionMat=ArrowTextures[`ARROW_RIGHT];
break;
case 2:
DirectionMat=ArrowTextures[`ARROW_DOWN];
break;
case 3:
DirectionMat=ArrowTextures[`ARROW_LEFT];
break;
default:
DirectionMat=ArrowTextures[`ARROW_UP];
break;
}
2021-06-13 02:54:35 +00:00
DrawTileStretched(ScrollTexture, X,Y, Width, Height);
DrawTileStretched(DirectionMat, X,Y, Width, Height);
2020-01-10 13:14:11 +00:00
}
2022-09-12 02:34:44 +00:00
function DrawTexture(Texture2D Tex, float X, float Y, float W, float H, optional float UL, optional float VL)
2022-09-08 13:32:28 +00:00
{
Canvas.SetPos(X, Y);
2022-09-12 02:34:44 +00:00
Canvas.DrawTile(Tex, W, H, 0, 0, UL == 0.f ? float(Tex.SizeX) : UL, VL == 0.f ? float(Tex.SizeY) : VL);
2022-09-08 13:32:28 +00:00
}
2021-06-13 03:00:19 +00:00
final function DrawTileStretched(Texture Tex, float X, float Y, float XS, float YS)
2020-01-10 13:14:11 +00:00
{
2021-06-13 02:54:35 +00:00
local float mW, mH, MidX, MidY, SmallTileW, SmallTileH, fX, fY;
local int OptimizeTiles;
2021-06-13 02:53:33 +00:00
if (Tex == None ) Tex = Texture2D'EngineMaterials.DefaultDiffuse';
// Get the size of the image
mW = Tex.GetSurfaceWidth();
mH = Tex.GetSurfaceHeight();
// Get the midpoints of the image
MidX = int(mW/2);
MidY = int(mH/2);
// Grab info about the scaled image
SmallTileW = XS - mW;
SmallTileH = YS - mH;
// Optimized
OptimizeTiles = 4;
2021-06-13 02:53:33 +00:00
if (mW < XS)
OptimizeTiles += 2;
2021-06-13 02:53:33 +00:00
if (mH < YS)
OptimizeTiles += 2;
2021-06-13 02:53:33 +00:00
if ((mH < YS) && (mW < XS))
OptimizeTiles += 1;
Canvas.PreOptimizeDrawTiles(OptimizeTiles, Tex);
// Draw the spans first
// Top and Bottom
2021-06-13 02:53:33 +00:00
if (mW < XS)
{
fX = MidX;
2021-06-13 02:53:33 +00:00
if (mH > YS)
fY = YS/2;
else
fY = MidY;
2021-06-13 02:54:35 +00:00
Canvas.SetPos(X+fX, Y);
Canvas.DrawTile(Tex, SmallTileW, fY, MidX, 0,1, fY);
Canvas.SetPos(X+fX, Y+YS-fY);
Canvas.DrawTile(Tex, SmallTileW, fY, MidX, mH-fY, 1,fY);
}
else
fX = XS / 2;
// Left and Right
2021-06-13 02:53:33 +00:00
if (mH < YS)
{
fY = MidY;
2021-06-13 02:54:35 +00:00
Canvas.SetPos(X, Y+fY);
Canvas.DrawTile(Tex, fX, SmallTileH, 0,fY, fX, 1);
Canvas.SetPos(X+XS-fX, Y+fY);
Canvas.DrawTile(Tex, fX, SmallTileH, mW-fX, fY, fX, 1);
}
else
fY = YS / 2;
// Center
2021-06-13 02:53:33 +00:00
if ((mH < YS) && (mW < XS))
{
2021-06-13 02:54:35 +00:00
Canvas.SetPos(X+fX, Y+fY);
Canvas.DrawTile(Tex, SmallTileW, SmallTileH, fX, fY, 1,1);
}
// Draw the 4 corners.
2021-06-13 02:54:35 +00:00
Canvas.SetPos(X, Y);
Canvas.DrawTile(Tex, fX, fY, 0,0, fX, fY);
Canvas.SetPos(X+XS-fX, Y);
Canvas.DrawTile(Tex, fX, fY, mW-fX, 0,fX, fY);
Canvas.SetPos(X, Y+YS-fY);
Canvas.DrawTile(Tex, fX, fY, 0,mH-fY, fX, fY);
Canvas.SetPos(X+XS-fX, Y+YS-fY);
Canvas.DrawTile(Tex, fX, fY, mW-fX, mH-fY, fX, fY);
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
final function DrawTextJustified(byte Justification, float X1, float Y1, float X2, float Y2, coerce string S, optional float XS, optional float YS)
2020-01-10 13:14:11 +00:00
{
local float XL, YL;
local float CurY, CurX;
Canvas.TextSize(S, XL, YL, XS, YS);
CurY = ((Y2-Y1) / 2) - (YL/2);
2021-06-13 02:53:33 +00:00
if (Justification == 0)
{
CurX = 0;
}
2021-06-13 02:53:33 +00:00
else if (Justification == 1)
{
2021-06-13 02:53:33 +00:00
if (XL > X2-X1)
CurX = 0;
else CurX = ((X2-X1) / 2) - (XL/2);
}
2021-06-13 02:53:33 +00:00
else if (Justification == 2)
{
CurX = (X2-X1) - XL;
}
Canvas.SetPos(CurX, CurY);
2021-06-13 02:54:35 +00:00
Canvas.DrawText(S, ,XS, YS);
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
static final function float TimeFraction(float Start, float End, float Current)
2020-01-10 13:14:11 +00:00
{
return FClamp((Current - Start) / (End - Start), 0.f, 1.f);
2020-01-10 13:14:11 +00:00
}
static final function string LTrim(coerce string S)
{
while (Left(S, 1) == " ")
S = Right(S, Len(S) - 1);
return S;
2020-01-10 13:14:11 +00:00
}
static final function string RTrim(coerce string S)
{
while (Right(S, 1) == " ")
S = Left(S, Len(S) - 1);
return S;
2020-01-10 13:14:11 +00:00
}
static final function string Trim(coerce string S)
{
return LTrim(RTrim(S));
2020-01-10 13:14:11 +00:00
}
defaultproperties
{
// Font'UI_Canvas_Fonts.Font_Main'
2021-06-20 05:04:22 +00:00
//MainFont=Font'KFYAS_Assets.Font.KFMainFont'
//InfiniteFont=Font'KFYAS_Assets.Font.KFInfiniteFont'
2021-05-16 20:28:37 +00:00
MainFont=Font'UI_Canvas_Fonts.Font_Main'
NumberFont=Font'UI_Canvas_Fonts.Font_General'
2021-05-16 20:28:37 +00:00
InfiniteFont=Font'UI_Canvas_Fonts.Font_Main'
}