KF2-YetAnotherScoreboard/YAS/Classes/KFGUI_FloatingWindow.uc

107 lines
2.6 KiB
Ucode
Raw Normal View History

2022-09-03 17:26:40 +00:00
class KFGUI_FloatingWindow extends KFGUI_Page
abstract;
2020-01-10 13:14:11 +00:00
var() string WindowTitle; // Title of this window.
var float DragOffset[2], OpenAnimSpeed;
var KFGUI_FloatingWindowHeader HeaderComp;
2021-06-13 02:54:35 +00:00
var bool bDragWindow, bUseAnimation;
2020-01-10 13:14:11 +00:00
var float WindowFadeInTime;
2021-06-13 02:54:35 +00:00
var transient float OpenStartTime, OpenEndTime;
2020-01-10 13:14:11 +00:00
function InitMenu()
{
Super.InitMenu();
HeaderComp = new (Self) class'KFGUI_FloatingWindowHeader';
AddComponent(HeaderComp);
2020-01-10 13:14:11 +00:00
}
function ShowMenu()
{
Super.ShowMenu();
OpenStartTime = GetPlayer().WorldInfo.RealTimeSeconds;
OpenEndTime = GetPlayer().WorldInfo.RealTimeSeconds + OpenAnimSpeed;
2020-01-10 13:14:11 +00:00
}
function DrawMenu()
{
local float TempSize;
2021-06-13 02:53:33 +00:00
if (bUseAnimation)
{
TempSize = `TimeSinceEx(GetPlayer(), OpenStartTime);
2021-06-13 02:53:33 +00:00
if (WindowFadeInTime - TempSize > 0 && FrameOpacity != default.FrameOpacity)
FrameOpacity = (1.f - ((WindowFadeInTime - TempSize) / WindowFadeInTime)) * default.FrameOpacity;
}
Owner.CurrentStyle.RenderFramedWindow(Self);
2021-06-13 02:53:33 +00:00
if (HeaderComp != None)
{
HeaderComp.CompPos[3] = Owner.CurrentStyle.DefaultHeight;
HeaderComp.YSize = HeaderComp.CompPos[3] / CompPos[3]; // Keep header height fit the window height.
}
2020-01-10 13:14:11 +00:00
}
2021-06-13 03:00:19 +00:00
function SetWindowDrag(bool bDrag)
2020-01-10 13:14:11 +00:00
{
bDragWindow = bDrag;
2021-06-13 02:53:33 +00:00
if (bDrag)
{
DragOffset[0] = Owner.MousePosition.X-CompPos[0];
DragOffset[1] = Owner.MousePosition.Y-CompPos[1];
}
2020-01-10 13:14:11 +00:00
}
function bool CaptureMouse()
{
local int i;
2021-06-13 02:53:33 +00:00
if (bDragWindow && HeaderComp != None ) // Always keep focus on window frame now!
{
MouseArea = HeaderComp;
return true;
}
2021-06-13 02:53:33 +00:00
for (i=0; i < Components.Length; i++)
{
2021-06-13 02:53:33 +00:00
if (Components[i].CaptureMouse())
{
MouseArea = Components[i];
return true;
}
}
MouseArea = None;
return Super(KFGUI_Base).CaptureMouse();
2020-01-10 13:14:11 +00:00
}
function PreDraw()
{
local float Frac, CenterX, CenterY;
2021-06-13 02:53:33 +00:00
if (bUseAnimation)
{
Frac = Owner.CurrentStyle.TimeFraction(OpenStartTime, OpenEndTime, GetPlayer().WorldInfo.RealTimeSeconds);
XSize = Lerp(default.XSize*0.75, default.XSize, Frac);
YSize = Lerp(default.YSize*0.75, default.YSize, Frac);
CenterX = (default.XPosition + default.XSize * 0.5) - ((default.XSize*0.75)/2);
CenterY = (default.YPosition + default.YSize * 0.5) - ((default.YSize*0.75)/2);
XPosition = Lerp(CenterX, default.XPosition, Frac);
YPosition = Lerp(CenterY, default.YPosition, Frac);
2021-06-13 02:53:33 +00:00
if (bDragWindow)
{
2021-06-13 02:54:35 +00:00
XPosition = FClamp(Owner.MousePosition.X-DragOffset[0], 0,InputPos[2]-CompPos[2]) / InputPos[2];
YPosition = FClamp(Owner.MousePosition.Y-DragOffset[1], 0,InputPos[3]-CompPos[3]) / InputPos[3];
}
}
Super.PreDraw();
2020-01-10 13:14:11 +00:00
}
defaultproperties
{
bUseAnimation=true
OpenAnimSpeed=0.05f
WindowFadeInTime=0.2f
2020-01-10 13:14:11 +00:00
}