KF2-YetAnotherScoreboard/YAS/Classes/KFGUI_RightClickMenu.uc

163 lines
3.5 KiB
Ucode
Raw Normal View History

2022-09-03 17:26:40 +00:00
class KFGUI_RightClickMenu extends KFGUI_Clickable;
2021-06-12 20:11:37 +00:00
2020-01-10 13:14:11 +00:00
struct FRowItem
{
2021-06-13 02:54:35 +00:00
var string Text, ToolTip;
var bool bSplitter, bDisabled;
2020-01-10 13:14:11 +00:00
};
2021-06-13 03:17:40 +00:00
var array<FRowItem> ItemRows;
2021-06-13 02:54:35 +00:00
var int CurrentRow, OldRow;
2020-01-10 13:14:11 +00:00
var int EdgeSize;
var int OldSizeX;
var transient bool bDrawToolTip;
2021-06-13 02:54:35 +00:00
var Color BoxColor, OutlineColor;
2020-01-10 13:14:11 +00:00
2021-06-13 03:00:19 +00:00
function OpenMenu(KFGUI_Base Menu)
2020-01-10 13:14:11 +00:00
{
Owner = Menu.Owner;
InitMenu();
PlayMenuSound(MN_Dropdown);
GetInputFocus();
OldSizeX = 0;
2020-01-10 13:14:11 +00:00
}
final function ComputeSize()
{
2021-06-13 02:54:35 +00:00
local float XS, YS, XL, YL, Scalar;
local int i;
local string S;
2021-06-13 02:53:33 +00:00
if (OldSizeX == Owner.ScreenSize.X)
return;
2020-01-10 13:14:11 +00:00
2021-06-13 02:53:33 +00:00
if (ItemRows.Length == 0)
{
YS = 0;
XS = 50;
}
else
{
Canvas.Font = Owner.CurrentStyle.PickFont(Scalar);
2021-06-13 02:53:33 +00:00
for (i=0; i < ItemRows.Length; ++i)
{
2021-06-13 02:53:33 +00:00
if (ItemRows[i].bSplitter)
S = "----";
else S = ItemRows[i].Text;
2021-06-13 02:54:35 +00:00
Canvas.TextSize(S, XL, YL, Scalar, Scalar);
2021-06-13 02:54:35 +00:00
XS = FMax(XS, XL);
YS += YL;
}
}
XSize = (XS+(EdgeSize*12)) / Owner.ScreenSize.X;
YSize = (YS+(EdgeSize*4)) / Owner.ScreenSize.Y;
ComputePosition();
OldSizeX = Owner.ScreenSize.X;
2020-01-10 13:14:11 +00:00
}
function ComputePosition()
{
XPosition = float(Owner.MousePosition.X+4) / Owner.ScreenSize.X;
YPosition = float(Owner.MousePosition.Y+4) / Owner.ScreenSize.Y;
2021-06-13 02:53:33 +00:00
if ((XPosition+XSize) > 1.f)
YPosition = (float(Owner.MousePosition.X) / Owner.ScreenSize.X) - XSize; // Move to left side of mouse pointer.
2021-06-13 02:53:33 +00:00
if ((YPosition+YSize) > 1.f)
YPosition -= ((YPosition+YSize)-1.f); // Move up until fit on screen.
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
final function AddRow(string Text, bool bDisable, optional string AltToolTip)
2020-01-10 13:14:11 +00:00
{
local int i;
i = ItemRows.Length;
ItemRows.Length = i+1;
2021-06-13 02:53:33 +00:00
if (Text == "-")
ItemRows[i].bSplitter = true;
else
{
ItemRows[i].Text = Text;
ItemRows[i].ToolTip = AltToolTip;
ItemRows[i].bDisabled = bDisable;
}
2020-01-10 13:14:11 +00:00
}
function PreDraw()
{
ComputeSize();
Super.PreDraw();
2020-01-10 13:14:11 +00:00
}
function DrawMenu()
{
Owner.CurrentStyle.RenderRightClickMenu(Self);
2021-06-13 02:53:33 +00:00
if (bDrawToolTip)
{
2021-06-13 02:53:33 +00:00
if (OldRow != CurrentRow)
bDrawToolTip = false;
DrawToolTip();
}
2020-01-10 13:14:11 +00:00
}
function DrawToolTip()
{
2021-06-13 02:54:35 +00:00
local float X, Y,XL, YL, BoxW, BoxH, TextX, TextY, Scalar, CursorSize;
local string S;
Canvas.Reset();
Canvas.SetClip(float(Owner.ScreenSize.X), float(Owner.ScreenSize.Y));
S = ItemRows[CurrentRow].ToolTip;
Canvas.Font = Owner.CurrentStyle.PickFont(Scalar);
2021-06-13 02:54:35 +00:00
Canvas.TextSize(S, XL, YL, Scalar, Scalar);
CursorSize = Owner.CurrentStyle.ScreenScale(Owner.CursorSize);
X = Owner.MousePosition.X+CursorSize;
Y = Owner.MousePosition.Y+CursorSize;
BoxW = XL * 1.05f;
BoxH = YL * 1.25f;
2021-06-13 03:00:19 +00:00
while ((X + BoxW) > Canvas.ClipX)
{
X -= 0.01;
}
2021-06-13 02:54:35 +00:00
Owner.CurrentStyle.DrawOutlinedBox(X, Y, BoxW, BoxH, EdgeSize, MakeColor(5, 5,5, 255), MakeColor(115, 115, 115, 255));
TextX = X + (BoxW/2) - (XL/2) - (EdgeSize/2);
TextY = Y + (BoxH/2) - (YL/2) - (EdgeSize/2);
Canvas.DrawColor = class'HUD'.default.WhiteColor;
Canvas.SetPos(TextX, TextY);
2021-06-13 02:54:35 +00:00
Canvas.DrawText(S, ,Scalar, Scalar);
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
function HandleMouseClick(bool bRight)
2020-01-10 13:14:11 +00:00
{
2021-06-13 02:53:33 +00:00
if (CurrentRow >= 0 && (ItemRows[CurrentRow].bSplitter || ItemRows[CurrentRow].bDisabled))
return;
OnSelectedItem(CurrentRow);
PlayMenuSound(MN_ClickButton);
DropInputFocus();
2020-01-10 13:14:11 +00:00
}
function LostInputFocus()
{
OnBecameHidden(Self);
OldRow = -1;
CurrentRow = -1;
2020-01-10 13:14:11 +00:00
}
function NotifyMousePaused()
{
2021-06-13 02:53:33 +00:00
if (CurrentRow != -1 && ItemRows[CurrentRow].ToolTip != "")
bDrawToolTip = true;
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
Delegate OnSelectedItem(int Index);
Delegate OnBecameHidden(KFGUI_RightClickMenu M);
2020-01-10 13:14:11 +00:00
defaultproperties
{
CurrentRow=-1
OldRow=-1
bFocusedPostDrawItem=true
bHoverSound=false
EdgeSize=2
2021-06-13 02:54:35 +00:00
BoxColor=(R=5, G=5, B=5, A=200)
OutlineColor=(R=115, G=115, B=115, A=255)
2020-01-10 13:14:11 +00:00
}