KF2-YetAnotherScoreboard/YAS/Classes/ClassicStyle.uc

411 lines
10 KiB
Ucode
Raw Normal View History

2020-01-10 13:14:11 +00:00
Class ClassicStyle extends KF2Style;
2021-06-12 20:11:37 +00:00
`include(Build.uci)
`include(Logger.uci)
2021-06-13 03:00:19 +00:00
function RenderFramedWindow(KFGUI_FloatingWindow P)
2020-01-10 13:14:11 +00:00
{
2021-06-13 02:54:35 +00:00
local int XS, YS, TitleHeight;
local float XL, YL, FontScale;
XS = Canvas.ClipX-Canvas.OrgX;
YS = Canvas.ClipY-Canvas.OrgY;
TitleHeight = DefaultHeight;
2021-06-13 02:53:33 +00:00
if (P.bWindowFocused)
2021-06-13 02:54:35 +00:00
Canvas.SetDrawColor(105, 105, 105, 255);
else Canvas.SetDrawColor(85, 85, 85, P.FrameOpacity);
// Frame Header
Canvas.SetPos(0, 0);
2021-06-13 02:54:35 +00:00
Canvas.DrawTileStretched(TabTextures[`TAB_TOP], XS, TitleHeight, 0,0, 128, 16);
// Frame itself.
Canvas.SetPos(0, TitleHeight);
2021-06-13 02:54:35 +00:00
Canvas.DrawTileStretched(BorderTextures[`BOX_SMALL_SLIGHTTRANSPARENT], XS, YS-TitleHeight, 0,0, 128, 128);
// Title.
2021-06-13 02:53:33 +00:00
if (P.WindowTitle != "")
{
Canvas.Font = PickFont(FontScale);
2021-06-13 02:54:35 +00:00
Canvas.TextSize(P.WindowTitle, XL, YL, FontScale, FontScale);
Canvas.SetDrawColor(250, 250, 250, 255);
Canvas.SetPos((XS*0.5)-(XL*0.5), 0);
Canvas.DrawText(P.WindowTitle, ,FontScale, FontScale);
}
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
function RenderWindow(KFGUI_Page P)
2020-01-10 13:14:11 +00:00
{
2021-06-13 02:54:35 +00:00
local int XS, YS;
XS = Canvas.ClipX-Canvas.OrgX;
YS = Canvas.ClipY-Canvas.OrgY;
// Frame itself.
2021-06-13 02:53:33 +00:00
if (P.bWindowFocused)
2021-06-13 02:54:35 +00:00
Canvas.SetDrawColor(105, 105, 105, 255);
else Canvas.SetDrawColor(85, 85, 85, P.FrameOpacity);
Canvas.SetPos(0, 0);
2021-06-13 02:54:35 +00:00
Canvas.DrawTileStretched(BorderTextures[`BOX_SMALL_SLIGHTTRANSPARENT], XS, YS, 0,0, 128, 128);
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
function RenderToolTip(KFGUI_Tooltip TT)
2020-01-10 13:14:11 +00:00
{
local int i;
2021-06-13 02:54:35 +00:00
local float X, Y,XS, YS, TX, TY, TS, DefFontHeight;
Canvas.Font = PickFont(TS);
// First compute textbox size.
TY = DefaultHeight*TT.Lines.Length;
2021-06-13 02:53:33 +00:00
for (i=0; i < TT.Lines.Length; ++i)
{
2021-06-13 02:53:33 +00:00
if (TT.Lines[i] != "")
2021-06-13 02:54:35 +00:00
Canvas.TextSize(TT.Lines[i], XS, YS);
TX = FMax(XS, TX);
}
TX*=TS;
// Give some borders.
TX += TOOLTIP_BORDER*2;
TY += TOOLTIP_BORDER*2;
X = TT.CompPos[0];
Y = TT.CompPos[1]+24.f;
// Then check if too close to window edge, then move it to another pivot.
2021-06-13 02:53:33 +00:00
if ((X+TX) > TT.Owner.ScreenSize.X)
X = TT.Owner.ScreenSize.X-TX;
2021-06-13 02:53:33 +00:00
if ((Y+TY) > TT.Owner.ScreenSize.Y)
Y = TT.CompPos[1]-TY;
2021-06-13 02:53:33 +00:00
if (TT.CurrentAlpha < 255)
2021-06-13 02:54:35 +00:00
TT.CurrentAlpha = Min(TT.CurrentAlpha+25, 255);
// Reset clipping.
2021-06-13 02:54:35 +00:00
Canvas.SetOrigin(0, 0);
Canvas.SetClip(TT.Owner.ScreenSize.X, TT.Owner.ScreenSize.Y);
// Draw frame.
2021-06-13 02:54:35 +00:00
Canvas.SetDrawColor(115, 115, 115, TT.CurrentAlpha);
Canvas.SetPos(X-2, Y-2);
DrawBoxHollow(X-2, Y-2, TX+4, TY+4, 2);
Canvas.SetDrawColor(5, 5,5, TT.CurrentAlpha);
Canvas.SetPos(X, Y);
DrawWhiteBox(TX, TY);
DefFontHeight = DefaultHeight;
// Draw text.
2021-06-13 02:54:35 +00:00
Canvas.SetDrawColor(255, 255, 255, TT.CurrentAlpha);
X+=TOOLTIP_BORDER;
Y+=TOOLTIP_BORDER;
2021-06-13 02:53:33 +00:00
for (i=0; i < TT.Lines.Length; ++i)
{
2021-06-13 02:54:35 +00:00
Canvas.SetPos(X, Y);
Canvas.DrawText(TT.Lines[i], ,TS, TS, TT.TextFontInfo);
Y+=DefFontHeight;
}
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
function RenderScrollBar(KFGUI_ScrollBarBase S)
2020-01-10 13:14:11 +00:00
{
local float A;
local byte i;
2021-06-13 02:53:33 +00:00
if (S.bDisabled)
Canvas.SetDrawColor(5, 5, 5, 0);
2021-06-13 02:53:33 +00:00
else if (S.bFocused || S.bGrabbedScroller)
Canvas.SetDrawColor(15, 15, 15, 160);
else Canvas.SetDrawColor(15, 15, 15, 160);
Canvas.SetPos(0.f, 0.f);
2021-06-13 02:54:35 +00:00
Canvas.DrawTileStretched(BorderTextures[`BOX_INNERBORDER], S.CompPos[2], S.CompPos[3], 0,0, 128, 128);
2021-06-13 02:53:33 +00:00
if (S.bDisabled)
return;
2021-06-13 02:53:33 +00:00
if (S.bVertical)
i = 3;
else i = 2;
2021-06-13 02:54:35 +00:00
S.SliderScale = FMax(S.PageStep * (S.CompPos[i] - 32.f) / (S.MaxRange + S.PageStep), S.CalcButtonScale);
2021-06-13 02:53:33 +00:00
if (S.bGrabbedScroller)
{
// Track mouse.
2021-06-13 02:53:33 +00:00
if (S.bVertical)
A = S.Owner.MousePosition.Y - S.CompPos[1] - S.GrabbedOffset;
else A = S.Owner.MousePosition.X - S.CompPos[0] - S.GrabbedOffset;
A /= ((S.CompPos[i]-S.SliderScale) / float(S.MaxRange));
S.SetValue(A);
}
A = float(S.CurrentScroll) / float(S.MaxRange);
S.ButtonOffset = A*(S.CompPos[i]-S.SliderScale);
2021-06-13 02:53:33 +00:00
if (S.bGrabbedScroller)
2021-06-13 02:54:35 +00:00
Canvas.SetDrawColor(125, 125, 125, 200);
2021-06-13 02:53:33 +00:00
else if (S.bFocused)
2021-06-13 02:54:35 +00:00
Canvas.SetDrawColor(200, 200, 200, 200);
else Canvas.SetDrawColor(255, 255, 255, 200);
2021-06-13 02:53:33 +00:00
if (S.bVertical)
{
Canvas.SetPos(0.f, S.ButtonOffset);
2021-06-13 02:54:35 +00:00
Canvas.DrawTileStretched(ScrollTexture, S.CompPos[2], S.SliderScale, 0,0, 32, 32);
}
else
{
Canvas.SetPos(S.ButtonOffset, 0.f);
2021-06-13 02:54:35 +00:00
Canvas.DrawTileStretched(ScrollTexture, S.SliderScale, S.CompPos[3], 0,0, 32, 32);
}
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
function RenderCheckbox(KFGUI_CheckBox C)
2020-01-10 13:14:11 +00:00
{
local Texture CheckMark;
2021-06-13 02:54:35 +00:00
DrawTileStretched(ItemBoxTextures[`ITEMBOX_DISABLED], 0.f, 0.f, C.CompPos[2], C.CompPos[3]);
2021-06-13 02:53:33 +00:00
if (C.bChecked)
{
2021-06-13 02:53:33 +00:00
if (C.bDisabled)
CheckMark = CheckBoxTextures[`CHECKMARK_DISABLED];
2021-06-13 02:53:33 +00:00
else if (C.bFocused)
CheckMark = CheckBoxTextures[`CHECKMARK_HIGHLIGHTED];
else CheckMark = CheckBoxTextures[`CHECKMARK_NORMAL];
2021-06-13 02:54:35 +00:00
Canvas.SetDrawColor(255, 255, 255, 255);
Canvas.SetPos(0.f, 0.f);
Canvas.DrawTile(CheckMark, C.CompPos[2], C.CompPos[3], 0,0, CheckMark.GetSurfaceWidth(), CheckMark.GetSurfaceHeight());
}
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
function RenderComboBox(KFGUI_ComboBox C)
2020-01-10 13:14:11 +00:00
{
2021-06-13 02:53:33 +00:00
if (C.bDisabled)
2021-06-13 02:54:35 +00:00
Canvas.SetDrawColor(64, 64, 64, 255);
2021-06-13 02:53:33 +00:00
else if (C.bPressedDown)
2021-06-13 02:54:35 +00:00
Canvas.SetDrawColor(220, 220, 220, 255);
2021-06-13 02:53:33 +00:00
else if (C.bFocused)
2021-06-13 02:54:35 +00:00
Canvas.SetDrawColor(190, 190, 190, 255);
2021-06-13 02:54:35 +00:00
Canvas.SetPos(0.f, 0.f);
Canvas.DrawTileStretched(BorderTextures[`BOX_INNERBORDER], C.CompPos[2], C.CompPos[3], 0,0, 128, 128);
DrawArrowBox(3, C.CompPos[2]-32, 0.5f, 32, 32);
2021-06-13 02:53:33 +00:00
if (C.SelectedIndex < C.Values.Length && C.Values[C.SelectedIndex] != "")
{
2021-06-13 02:54:35 +00:00
Canvas.SetPos(C.BorderSize, (C.CompPos[3]-C.TextHeight)*0.5);
2021-06-13 02:53:33 +00:00
if (C.bDisabled)
Canvas.DrawColor = C.TextColor*0.5f;
else Canvas.DrawColor = C.TextColor;
2021-06-13 02:54:35 +00:00
Canvas.PushMaskRegion(Canvas.OrgX, Canvas.OrgY, Canvas.ClipX-C.BorderSize, Canvas.ClipY);
Canvas.DrawText(C.Values[C.SelectedIndex], ,C.TextScale, C.TextScale, C.TextFontInfo);
Canvas.PopMaskRegion();
}
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
function RenderComboList(KFGUI_ComboSelector C)
2020-01-10 13:14:11 +00:00
{
2021-06-13 02:54:35 +00:00
local float X, Y,YL, YP, Edge;
local int i;
local bool bCheckMouse;
// Draw background.
Edge = C.Combo.BorderSize;
Canvas.SetPos(0.f, 0.f);
2021-06-13 02:54:35 +00:00
Canvas.DrawTileStretched(BorderTextures[`BOX_SMALL_SLIGHTTRANSPARENT], C.CompPos[2], C.CompPos[3], 0,0, 128, 128);
// While rendering, figure out mouse focus row.
X = C.Owner.MousePosition.X - Canvas.OrgX;
Y = C.Owner.MousePosition.Y - Canvas.OrgY;
2021-06-13 02:53:33 +00:00
bCheckMouse = (X > 0.f && X < C.CompPos[2] && Y > 0.f && Y < C.CompPos[3]);
Canvas.Font = C.Combo.TextFont;
YL = C.Combo.TextHeight;
YP = Edge;
C.CurrentRow = -1;
2021-06-13 02:54:35 +00:00
Canvas.PushMaskRegion(Canvas.OrgX, Canvas.OrgY, Canvas.ClipX, Canvas.ClipY);
2021-06-13 02:53:33 +00:00
for (i=0; i < C.Combo.Values.Length; ++i)
{
2021-06-13 02:53:33 +00:00
if (bCheckMouse && Y >= YP && Y <= (YP+YL))
{
bCheckMouse = false;
C.CurrentRow = i;
2021-06-13 02:54:35 +00:00
Canvas.SetPos(4.f, YP);
Canvas.SetDrawColor(128, 48, 48, 255);
DrawWhiteBox(C.CompPos[2]-(Edge*2.f), YL);
}
2021-06-13 02:54:35 +00:00
Canvas.SetPos(Edge, YP);
2021-06-13 02:53:33 +00:00
if (i == C.Combo.SelectedIndex)
Canvas.DrawColor = C.Combo.SelectedTextColor;
else Canvas.DrawColor = C.Combo.TextColor;
2021-06-13 02:54:35 +00:00
Canvas.DrawText(C.Combo.Values[i], ,C.Combo.TextScale, C.Combo.TextScale, C.Combo.TextFontInfo);
YP+=YL;
}
Canvas.PopMaskRegion();
2021-06-13 02:53:33 +00:00
if (C.OldRow != C.CurrentRow)
{
C.OldRow = C.CurrentRow;
C.PlayMenuSound(MN_DropdownChange);
}
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
function RenderRightClickMenu(KFGUI_RightClickMenu C)
2020-01-10 13:14:11 +00:00
{
2021-06-13 02:54:35 +00:00
local float X, Y,XL, YL, YP, Edge, TextScale;
local int i;
local bool bCheckMouse;
local string S;
// Draw background.
Edge = C.EdgeSize;
2021-06-13 02:54:35 +00:00
DrawOutlinedBox(0.f, 0.f, C.CompPos[2], C.CompPos[3], Edge, C.BoxColor, C.OutlineColor);
// While rendering, figure out mouse focus row.
X = C.Owner.MousePosition.X - Canvas.OrgX;
Y = C.Owner.MousePosition.Y - Canvas.OrgY;
2021-06-13 02:53:33 +00:00
bCheckMouse = (X > 0.f && X < C.CompPos[2] && Y > 0.f && Y < C.CompPos[3]);
PickFont(TextScale);
YP = Edge*2;
C.CurrentRow = -1;
2021-06-13 02:54:35 +00:00
Canvas.PushMaskRegion(Canvas.OrgX, Canvas.OrgY, Canvas.ClipX, Canvas.ClipY);
2021-06-13 02:53:33 +00:00
for (i=0; i < C.ItemRows.Length; ++i)
{
2021-06-13 02:53:33 +00:00
if (C.ItemRows[i].bSplitter)
S = "-------";
else S = C.ItemRows[i].Text;
2021-06-13 02:54:35 +00:00
Canvas.TextSize(S, XL, YL, TextScale, TextScale);
2021-06-13 02:53:33 +00:00
if (bCheckMouse && Y >= YP && Y <= (YP+YL))
{
bCheckMouse = false;
C.CurrentRow = i;
2021-06-13 02:54:35 +00:00
Canvas.SetPos(Edge, YP);
Canvas.SetDrawColor(128, 0,0, 255);
DrawWhiteBox(C.CompPos[2]-(Edge*2.f), YL);
}
2021-06-13 02:54:35 +00:00
Canvas.SetPos(Edge*6, YP);
2021-06-13 02:53:33 +00:00
if (C.ItemRows[i].bSplitter)
2021-06-13 02:54:35 +00:00
Canvas.SetDrawColor(255, 255, 255, 255);
else
{
2021-06-13 02:53:33 +00:00
if (C.ItemRows[i].bDisabled)
2021-06-13 02:54:35 +00:00
Canvas.SetDrawColor(148, 148, 148, 255);
else Canvas.SetDrawColor(248, 248, 248, 255);
}
2021-06-13 02:54:35 +00:00
Canvas.DrawText(S, ,TextScale, TextScale);
YP+=YL;
}
Canvas.PopMaskRegion();
2021-06-13 02:53:33 +00:00
if (C.OldRow != C.CurrentRow)
{
C.OldRow = C.CurrentRow;
C.PlayMenuSound(MN_FocusHover);
}
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
function RenderButton(KFGUI_Button B)
2020-01-10 13:14:11 +00:00
{
2021-06-13 02:54:35 +00:00
local float XL, YL, TS, AX, AY, GamepadTexSize;
local Texture2D Mat, ButtonTex;
local bool bDrawOverride;
bDrawOverride = B.DrawOverride(Canvas, B);
2021-06-13 02:53:33 +00:00
if (!bDrawOverride)
{
2021-06-13 02:53:33 +00:00
if (B.bDisabled)
Mat = ButtonTextures[`BUTTON_DISABLED];
2021-06-13 02:53:33 +00:00
else if (B.bPressedDown)
Mat = ButtonTextures[`BUTTON_PRESSED];
2021-06-13 02:53:33 +00:00
else if (B.bFocused || B.bIsHighlighted)
Mat = ButtonTextures[`BUTTON_HIGHLIGHTED];
else Mat = ButtonTextures[`BUTTON_NORMAL];
2021-06-13 02:54:35 +00:00
Canvas.SetPos(0.f, 0.f);
Canvas.DrawTileStretched(Mat, B.CompPos[2], B.CompPos[3], 0,0, 32, 32);
2021-06-13 02:53:33 +00:00
if (B.OverlayTexture.Texture != None)
{
2021-06-13 02:54:35 +00:00
Canvas.SetPos(0.f, 0.f);
Canvas.DrawTile(B.OverlayTexture.Texture, B.CompPos[2], B.CompPos[3], B.OverlayTexture.U, B.OverlayTexture.V, B.OverlayTexture.UL, B.OverlayTexture.VL);
}
}
2021-06-13 02:53:33 +00:00
if (B.ButtonText != "")
{
Canvas.Font = MainFont;
GamepadTexSize = B.CompPos[3] / 1.25;
TS = GetFontScaler();
TS *= B.FontScale;
2021-06-13 03:00:19 +00:00
while (true)
{
2021-06-13 02:54:35 +00:00
Canvas.TextSize(B.ButtonText, XL, YL, TS, TS);
2021-06-13 02:53:33 +00:00
if (XL < (B.CompPos[2]*0.9) && YL < (B.CompPos[3]*0.9))
break;
TS -= 0.001;
}
2021-06-13 02:54:35 +00:00
Canvas.SetPos((B.CompPos[2]-XL)*0.5, (B.CompPos[3]-YL)*0.5);
2021-06-13 02:53:33 +00:00
if (B.bDisabled)
Canvas.DrawColor = B.TextColor*0.5f;
else Canvas.DrawColor = B.TextColor;
2021-06-13 02:54:35 +00:00
Canvas.DrawText(B.ButtonText, ,TS, TS, B.TextFontInfo);
2021-06-13 02:53:33 +00:00
if (B.GetUsingGamepad())
{
ButtonTex = Texture2D(DynamicLoadObject("UI_Controller."$B.GamepadButtonName$"_Asset", class'Texture2D'));
2021-06-13 02:53:33 +00:00
if (ButtonTex != None)
{
B.GetRealtivePos(AX, AY);
2021-06-13 03:00:19 +00:00
while ((Canvas.CurX-(GamepadTexSize*1.25)) < AX)
{
GamepadTexSize *= 0.95;
}
2021-06-13 03:00:19 +00:00
switch (ButtonTex.Name)
{
case 'XboxTypeS_A_Asset':
case 'XboxTypeS_B_Asset':
case 'XboxTypeS_X_Asset':
case 'XboxTypeS_Y_Asset':
Canvas.SetDrawColor(255, 255, 255, 145);
break;
default:
Canvas.SetDrawColor(0, 0, 0, 145);
break;
}
2021-06-13 02:54:35 +00:00
Canvas.SetPos(Canvas.CurX-(GamepadTexSize*1.25), (B.CompPos[3]-GamepadTexSize)*0.5);
Canvas.DrawRect(GamepadTexSize, GamepadTexSize, ButtonTex);
}
}
}
2020-01-10 13:14:11 +00:00
}
defaultproperties
{
}